Skip to contentSkip to conversation

Fix Uplink data transfer in RawIP mode

RFC New Carlos Pargada 1 participant 1 message Feb 2, 2011

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Fix Uplink data transfer in RawIP mode

Fix Uplink Data transfer in RawIP mode with IFW Modem

Change Data flow from stream mode to PAcket mode between GatRawIP and GatMux.

---
 gatchat/gatio.c    |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 gatchat/gatio.h    |    1 +
 gatchat/gatrawip.c |   75 ++++++++++++++++++++++++++++++---------
 3 files changed, 155 insertions(+), 19 deletions(-)
gatchat/gatio.c +96 -2
index 9d44a78..5ad640d 100644
@@ -77,7 +77,7 @@ static void read_watcher_destroy_notify(gpointer user_data)
 		io->user_disconnect(io->user_disconnect_data);
 }
 
-static gboolean received_data(GIOChannel *channel, GIOCondition cond,
+static gboolean stream_received_data(GIOChannel *channel, GIOCondition cond,
 				gpointer data)
 {
 	unsigned char *buf;
@@ -132,6 +132,51 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
 	return TRUE;
 }
 
+static gboolean packet_received_data(GIOChannel *channel, GIOCondition cond,
+				gpointer data)
+{
+	unsigned char *buf;
+	GAtIO *io = data;
+	GIOStatus status;
+	gsize rbytes;
+	gsize toread;		
+
+				
+	if (cond & G_IO_NVAL)
+		return FALSE;
+		
+	toread= 3000;
+	rbytes = 0;
+		
+	ring_buffer_reset(io->buf);
+	buf = ring_buffer_write_ptr(io->buf, 0);
+		
+	if (buf == NULL)
+		return FALSE;
+
+	status = g_io_channel_read_chars(channel, (char *) buf,
+						toread, &rbytes, NULL);
+	
+	if (status == G_IO_STATUS_ERROR)
+		return FALSE;
+	
+	if (rbytes > 0)
+		ring_buffer_write_advance(io->buf, rbytes);
+
+
+	
+	if (rbytes > 0 && io->read_handler)
+		io->read_handler(io->buf, io->read_data);	
+	
+	if (cond & (G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	if (rbytes == 0 && status != G_IO_STATUS_AGAIN)
+		return FALSE;	
+	
+	return TRUE;
+}
+				
 gsize g_at_io_write(GAtIO *io, const gchar *data, gsize count)
 {
 	GIOStatus status;
@@ -175,6 +220,50 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond,
 
 }
 
+static GAtIO *create_packet_io(GIOChannel *channel, GIOFlags flags)
+{
+	GAtIO *io;
+
+	if (channel == NULL)
+		return NULL;
+
+	io = g_try_new0(GAtIO, 1);
+	
+	if (io == NULL)
+		return io;
+		
+	io->ref_count = 1;
+	io->debugf = NULL;
+	
+	
+	io->max_read_attempts = 1;
+	io->use_write_watch = TRUE;
+			
+	io->buf = ring_buffer_new(3000);
+
+	if (!io->buf)
+		goto error;
+
+	if (!g_at_util_setup_io(channel, flags))
+		goto error;	
+	
+	io->channel = channel;
+	io->read_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				packet_received_data, io,
+				read_watcher_destroy_notify);
+	
+	return io;
+
+error:
+	if (io->buf)
+		ring_buffer_free(io->buf);
+
+	g_free(io);
+
+	return NULL;							
+}
+
 static GAtIO *create_io(GIOChannel *channel, GIOFlags flags)
 {
 	GAtIO *io;
@@ -208,7 +297,7 @@ static GAtIO *create_io(GIOChannel *channel, GIOFlags flags)
 	io->channel = channel;
 	io->read_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
 				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
-				received_data, io,
+				stream_received_data, io,
 				read_watcher_destroy_notify);
 
 	return io;
@@ -222,6 +311,11 @@ error:
 	return NULL;
 }
 
+GAtIO *g_raw_io_new(GIOChannel *channel)
+{
+	return create_packet_io(channel, G_IO_FLAG_NONBLOCK);
+}
+
 GAtIO *g_at_io_new(GIOChannel *channel)
 {
 	return create_io(channel, G_IO_FLAG_NONBLOCK);
gatchat/gatio.h +1 -0
index 5a9f9f9..4b8bc00 100644
@@ -37,6 +37,7 @@ struct ring_buffer;
 typedef void (*GAtIOReadFunc)(struct ring_buffer *buffer, gpointer user_data);
 typedef gboolean (*GAtIOWriteFunc)(gpointer user_data);
 
+GAtIO *g_raw_io_new(GIOChannel *channel);
 GAtIO *g_at_io_new(GIOChannel *channel);
 GAtIO *g_at_io_new_blocking(GIOChannel *channel);
 
gatchat/gatrawip.c +58 -17

120 lines not on this page · raw message

Signature · 13 lines
1.6.6.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.