All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/6] gathdlc: add mechanism to detect ppp suspension from DUN client.
@ 2011-03-15  9:19 Guillaume Zajac
  2011-03-17 20:13 ` Denis Kenzior
  0 siblings, 1 reply; 5+ messages in thread
From: Guillaume Zajac @ 2011-03-15  9:19 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2441 bytes --]

---
 gatchat/gathdlc.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c
index 6c39e6c..38606b8 100644
--- a/gatchat/gathdlc.c
+++ b/gatchat/gathdlc.c
@@ -66,6 +66,10 @@ struct _GAtHDLC {
 	gboolean in_read_handler;
 	gboolean destroyed;
 	gboolean no_carrier_detect;
+	GAtSuspendFunc suspend_func;
+	gpointer suspend_data;
+	guint cmpt;
+	guint suspend_timeout;
 };
 
 static void hdlc_record(int fd, gboolean in, guint8 *data, guint16 length)
@@ -128,6 +132,34 @@ guint32 g_at_hdlc_get_recv_accm(GAtHDLC *hdlc)
 	return hdlc->recv_accm;
 }
 
+void g_at_hdlc_set_suspend_function(GAtHDLC *hdlc, GAtSuspendFunc func,
+							gpointer user_data)
+{
+	if (hdlc == NULL)
+		return;
+
+	hdlc->suspend_func = func;
+	hdlc->suspend_data = user_data;
+}
+
+static gboolean susp_timeout_cb(gpointer user_data)
+{
+	GAtHDLC *hdlc = user_data;
+
+	hdlc->cmpt = 0;
+
+	return FALSE;
+}
+
+static void hdlc_suspend(GAtHDLC *hdlc)
+{
+	g_at_io_set_write_handler(hdlc->io, NULL, NULL);
+	g_at_io_set_read_handler(hdlc->io, NULL, NULL);
+
+	if (hdlc->suspend_func)
+		hdlc->suspend_func(hdlc->suspend_data);
+}
+
 static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
 {
 	GAtHDLC *hdlc = user_data;
@@ -151,6 +183,21 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
 				hdlc->decode_offset == 0 && *buf == '\r')
 			break;
 
+		/* We detect the '+' character to suspend data call if
+		 * 3 '+' are detected in less than 500 milliseconds
+		 */
+		if (*buf == '+') {
+			if (hdlc->cmpt == 0)
+				hdlc->suspend_timeout = g_timeout_add (500,
+							susp_timeout_cb, hdlc);
+			hdlc->cmpt++;
+			if (hdlc->cmpt == 3)
+				goto suspend;
+		}
+		else {
+			hdlc->cmpt = 0;
+		}
+
 		if (hdlc->decode_escape == TRUE) {
 			unsigned char val = *buf ^ HDLC_TRANS;
 
@@ -195,6 +242,15 @@ out:
 
 	if (hdlc->destroyed)
 		g_free(hdlc);
+
+	return;
+
+suspend:
+	g_source_remove(hdlc->suspend_timeout);
+
+	ring_buffer_reset(rbuf);
+
+	hdlc_suspend(hdlc);
 }
 
 GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
@@ -236,6 +292,8 @@ GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
 	hdlc->io = g_at_io_ref(io);
 	g_at_io_set_read_handler(hdlc->io, new_bytes, hdlc);
 
+	hdlc->cmpt = 0;
+
 	return hdlc;
 
 error:
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-03-22  8:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-15  9:19 [PATCH 3/6] gathdlc: add mechanism to detect ppp suspension from DUN client Guillaume Zajac
2011-03-17 20:13 ` Denis Kenzior
2011-03-21 14:17   ` Guillaume Zajac
2011-03-21 18:57     ` Denis Kenzior
2011-03-22  8:57       ` Guillaume Zajac

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.