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; +} diff --git a/gatchat/gathdlc.h b/gatchat/gathdlc.h index 132e1a9e..95c389e0 100644 --- a/gatchat/gathdlc.h +++ b/gatchat/gathdlc.h @@ -55,6 +55,8 @@ void g_at_hdlc_set_recording(GAtHDLC *hdlc, const char *filename); GAtIO *g_at_hdlc_get_io(GAtHDLC *hdlc); +void g_at_hdlc_set_no_carrier_detect(GAtHDLC *hdlc, gboolean detect); + #ifdef __cplusplus } #endif