r295 - trunk/software/gsm0710muxd/src

smartphones-commits at linuxtogo.org smartphones-commits at linuxtogo.org
Sat May 3 13:30:18 CEST 2008


Author: emdete
Date: 2008-05-03 13:30:12 +0200 (Sat, 03 May 2008)
New Revision: 295

Modified:
   trunk/software/gsm0710muxd/src/gsm0710muxd.c
Log:
reduce startup delay
retry channel allocation if not acked by modem


Modified: trunk/software/gsm0710muxd/src/gsm0710muxd.c
===================================================================
--- trunk/software/gsm0710muxd/src/gsm0710muxd.c	2008-05-02 23:13:11 UTC (rev 294)
+++ trunk/software/gsm0710muxd/src/gsm0710muxd.c	2008-05-03 11:30:12 UTC (rev 295)
@@ -200,7 +200,7 @@
 static unsigned char close_channel_cmd[] = { GSM0710_CONTROL_CLD | GSM0710_CR, GSM0710_EA | (0 << 1) };
 static unsigned char test_channel_cmd[] = { GSM0710_CONTROL_TEST | GSM0710_CR, GSM0710_EA | (6 << 1), 'P', 'I', 'N', 'G', '\r', '\n', };
 //static unsigned char psc_channel_cmd[] = { GSM0710_CONTROL_PSC | GSM0710_CR, GSM0710_EA | (0 << 1), };
-static unsigned char wakeup_sequence[] = { GSM0710_FRAME_FLAG, };
+static unsigned char wakeup_sequence[] = { GSM0710_FRAME_FLAG, GSM0710_FRAME_FLAG, };
 // crc table from gsm0710 spec
 static const unsigned char r_crctable[] = {//reversed, 8-bit, poly=0x07
 	0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED,
@@ -228,6 +228,7 @@
 	0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD,
 	0x2C, 0x5E, 0xCF, };
 // config stuff
+static char* revision = "$Rev$";
 static int no_daemon = 1;
 static int pin_code = -1;
 static int use_ping = 0;
@@ -561,45 +562,51 @@
 	if (condition == G_IO_IN)
 	{
 		unsigned char buf[4096];
-	//information from virtual port
-		if (channel->remaining > 0)
-		{
-			memcpy(buf, channel->tmp, channel->remaining);
-			free(channel->tmp);
-		}
+		//information from virtual port
 		int len = read(channel->fd, buf + channel->remaining, sizeof(buf) - channel->remaining);
-		if (len > 0)
-			channel->remaining = handle_channel_data(buf, len + channel->remaining, channel->id);
-		LOG(LOG_DEBUG, "Data from channel %d, %d bytes", channel->id, len);
-		if (len < 0)
+		if (!channel->opened)
 		{
-	// dropped connection
-			LOG(LOG_INFO, "Logical channel %d for %s closed", channel->id, channel->origin);
-			if (cmux_mode)
-				write_frame(channel->id, NULL, 0, GSM0710_CONTROL_CLD | GSM0710_CR);
-			else
-				write_frame(channel->id, close_channel_cmd, 2, GSM0710_TYPE_UIH);
-			logical_channel_close(channel);
+			LOG(LOG_WARNING, "Write to a channel which wasn't acked to be open.");
+			write_frame(channel->id, NULL, 0, GSM0710_TYPE_SABM | GSM0710_PF);
 			LOG(LOG_DEBUG, "Leave");
-			return FALSE;
+			return TRUE;
 		}
-	//copy remaining bytes from last packet into tmp
-		if (channel->remaining > 0)
+		if (len >= 0)
 		{
-			channel->tmp = malloc(channel->remaining);
-			memcpy(channel->tmp, buf + sizeof(buf) - channel->remaining, channel->remaining);
+			LOG(LOG_DEBUG, "Data from channel %d, %d bytes", channel->id, len);
+			if (channel->remaining > 0)
+			{
+				memcpy(buf, channel->tmp, channel->remaining);
+				free(channel->tmp);
+				channel->tmp = NULL;
+			}
+			if (len + channel->remaining > 0)
+				channel->remaining = handle_channel_data(buf, len + channel->remaining, channel->id);
+			//copy remaining bytes from last packet into tmp
+			if (channel->remaining > 0)
+			{
+				channel->tmp = malloc(channel->remaining);
+				memcpy(channel->tmp, buf + sizeof(buf) - channel->remaining, channel->remaining);
+			}
+			LOG(LOG_DEBUG, "Leave");
+			return TRUE;
 		}
-		LOG(LOG_DEBUG, "Leave");
-		return TRUE;
+		// dropped connection
+		if (cmux_mode)
+			write_frame(channel->id, NULL, 0, GSM0710_CONTROL_CLD | GSM0710_CR);
+		else
+			write_frame(channel->id, close_channel_cmd, 2, GSM0710_TYPE_UIH);
+		logical_channel_close(channel);
+		LOG(LOG_INFO, "Logical channel %d for %s closed", channel->id, channel->origin);
 	}
 	else if (condition == G_IO_HUP)
 	{
-		LOG(LOG_INFO, "Logical channel %d for %s closed", channel->id, channel->origin);
 		if (cmux_mode)
 			write_frame(channel->id, NULL, 0, GSM0710_CONTROL_CLD | GSM0710_CR);
 		else
 			write_frame(channel->id, close_channel_cmd, 2, GSM0710_TYPE_UIH);
 		logical_channel_close(channel);
+		LOG(LOG_INFO, "Logical channel %d for %s closed", channel->id, channel->origin);
 	}
 	LOG(LOG_DEBUG, "Leave");
 	return FALSE;
@@ -624,7 +631,7 @@
 		{
 			LOG(LOG_INFO, "power on");
 			serial.state = MUX_STATE_OPENING;
-			serial.g_source_watchdog = g_timeout_add_seconds(5, watchdog, &serial); // let the dog watch every 5 sec
+			watchdog(&serial);
 		}
 		else
 			LOG(LOG_WARNING, "power on request received but was already on");
@@ -1385,9 +1392,9 @@
 				LOG(LOG_DEBUG, "Frame is UA");
 				if (channellist[frame->channel].opened)
 				{
+					SYSCHECK(logical_channel_close(channellist+frame->channel));
 					LOG(LOG_INFO, "Logical channel %d for %s closed",
 						frame->channel, channellist[frame->channel].origin);
-					SYSCHECK(logical_channel_close(channellist+frame->channel));
 				}
 				else
 				{
@@ -1406,9 +1413,9 @@
 			case GSM0710_TYPE_DM:
 				if (channellist[frame->channel].opened)
 				{
+					SYSCHECK(logical_channel_close(channellist+frame->channel));
 					LOG(LOG_INFO, "DM received, so the channel %d for %s was already closed",
 						frame->channel, channellist[frame->channel].origin);
-					SYSCHECK(logical_channel_close(channellist+frame->channel));
 				}
 				else
 				{
@@ -1429,8 +1436,8 @@
 					write_frame(frame->channel, NULL, 0, GSM0710_TYPE_UA | GSM0710_PF);
 					if (frame->channel == 0)
 					{
+						serial.state = MUX_STATE_CLOSING;				
 						LOG(LOG_INFO, "Control channel closed");
-						serial.state = MUX_STATE_CLOSING;				
 					}
 					else
 						LOG(LOG_INFO, "Logical channel %d for %s closed", frame->channel, channellist[frame->channel].origin);
@@ -1708,10 +1715,9 @@
 //multiplexer close down command doesn't work with benqM22a module, use: write_frame(0, NULL, 0, GSM0710_TYPE_DISC | GSM0710_PF);
 				else
 					write_frame(i, close_channel_cmd, 2, GSM0710_TYPE_UIH);
-				channellist[i].opened = 0;
+				SYSCHECK(logical_channel_close(channellist+i));
 			}
 			LOG(LOG_INFO, "Logical channel %d closed", channellist[i].id);
-			SYSCHECK(logical_channel_close(channellist+i));
 		}
 	}
 	if (serial.fd >= 0)
@@ -1741,6 +1747,8 @@
 	case MUX_STATE_OPENING:
 		if (open_serial_device(serial) < 0)
 			LOG(LOG_WARNING, "Could not open all devices and start muxer");
+		serial->g_source_watchdog = g_timeout_add_seconds(5, watchdog, data); // let the dog watch every 5 sec
+		LOG(LOG_INFO, "Watchdog started");
 	case MUX_STATE_INITILIZING:
 		if (start_muxer(serial) < 0)
 			LOG(LOG_WARNING, "Could not open all devices and start muxer errno=%d", errno);
@@ -1908,7 +1916,6 @@
 	else
 		openlog(argv[0], LOG_NDELAY | LOG_PID, LOG_LOCAL0);
 	SYSCHECK(dbus_init());
-	LOG(LOG_DEBUG, "Malloc buffers");
 //allocate memory for data structures
 	if ((serial.in_buf = gsm0710_buffer_init()) == NULL
 	 || (serial.adv_frame_buf = (unsigned char*)malloc((cmux_N1 + 3) * 2 + 2)) == NULL)
@@ -1916,10 +1923,10 @@
 		LOG(LOG_ALERT, "Out of memory");
 		exit(-1);
 	}
+	LOG(LOG_DEBUG, "%s %s starting", *argv, revision);
 //Initialize modem and virtual ports
 	serial.state = MUX_STATE_OPENING;
-	serial.g_source_watchdog = g_timeout_add_seconds(5, watchdog, &serial); // let the dog watch every 5 sec
-	LOG(LOG_INFO, "Watchdog started - initilization follows");
+	watchdog(&serial);
 //start waiting for input and forwarding it back and forth --
 	main_loop = g_main_loop_new(NULL, FALSE);
 	g_main_loop_run(main_loop); // will/may be terminated in signal_treatment




More information about the Smartphones-commits mailing list