From e266a5e220cfbb42fd3df7584415ed09cca5a035 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 9 Aug 2011 20:00:58 -0700 Subject: [PATCH] gatchat: Fix marker handling within HDLC support --- gatchat/gathdlc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c index f50c1f5c..3c207dce 100644 --- a/gatchat/gathdlc.c +++ b/gatchat/gathdlc.c @@ -89,15 +89,15 @@ static inline void hdlc_record(GAtHDLC *hdlc, gboolean in, unsigned char id; int err; - if (len == 0) - return; - g_at_util_debug_hexdump(in, data, length, hdlc->debugf, hdlc->debug_data); if (hdlc->record_fd < 0) return; + if (length == 0) + return; + gettimeofday(&now, NULL); ts = htonl(now.tv_sec & 0xffffffff); @@ -562,12 +562,19 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size) if (hdlc->start_frame_marker == TRUE) { /* Protocol requires 0x7e as start marker */ + if (pos + 1 > avail) + return FALSE; + *buf++ = HDLC_FLAG; pos++; + + if (pos == wrap) + buf = ring_buffer_write_ptr(write_buffer, pos); } else if (hdlc->wakeup_sent == FALSE) { /* Write an initial 0x7e as wakeup character */ *buf++ = HDLC_FLAG; pos++; + hdlc->wakeup_sent = TRUE; }