summaryrefslogtreecommitdiffstats
path: root/gatchat/gathdlc.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2011-02-28 14:24:39 -0600
committerDenis Kenzior <denkenz@gmail.com>2011-02-28 16:13:56 -0600
commit0dc8e5e588d7f12a9836582bf8b41a31572a7271 (patch)
tree8f3e6429d6ce373ea213621acd75db8b89395826 /gatchat/gathdlc.c
parentef2c133281e3d5c474da190b84d9de38da32802c (diff)
downloadofono-0dc8e5e588d7f12a9836582bf8b41a31572a7271.tar.bz2
gathdlc: Try to detect no carrier conditions
Sometimes we receive the no carrier embedded in a stream following the PPP packets. This might be due to write scheduling on the remote side or read scheduling locally. Try not to consume the no carrier condition and assume the previous hdlc frames will result in closing of the ppp stack.
Diffstat (limited to 'gatchat/gathdlc.c')
-rw-r--r--gatchat/gathdlc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c
index 00576022..6c39e6c0 100644
--- a/gatchat/gathdlc.c
+++ b/gatchat/gathdlc.c
@@ -65,6 +65,7 @@ struct _GAtHDLC {
int record_fd;
gboolean in_read_handler;
gboolean destroyed;
+ gboolean no_carrier_detect;
};
static void hdlc_record(int fd, gboolean in, guint8 *data, guint16 length)
@@ -140,6 +141,16 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
hdlc->in_read_handler = TRUE;
while (pos < len) {
+ /*
+ * We try to detect NO CARRIER conditions here. We
+ * (ab) use the fact that a HDLC_FLAG must be followed
+ * by the Address or Protocol fields, depending on whether
+ * ACFC is enabled.
+ */
+ if (hdlc->no_carrier_detect &&
+ hdlc->decode_offset == 0 && *buf == '\r')
+ break;
+
if (hdlc->decode_escape == TRUE) {
unsigned char val = *buf ^ HDLC_TRANS;
@@ -435,3 +446,11 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size)
return TRUE;
}
+
+void g_at_hdlc_set_no_carrier_detect(GAtHDLC *hdlc, gboolean detect)
+{
+ if (hdlc == NULL)
+ return;
+
+ hdlc->no_carrier_detect = detect;
+}