summaryrefslogtreecommitdiffstats
path: root/gatchat/gathdlc.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-04-27 23:25:28 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-04-28 17:27:35 -0500
commit7c6c72f558709d59da590d9b7d3f631d17b43abe (patch)
treeb07c0cf4ccaca80872086d8aa987b29f543bdff3 /gatchat/gathdlc.c
parente088f3c2bb1c859d732af1bdfa46cc24120c97ab (diff)
downloadofono-7c6c72f558709d59da590d9b7d3f631d17b43abe.tar.bz2
gathdlc: Support transmit ACCM
Diffstat (limited to 'gatchat/gathdlc.c')
-rw-r--r--gatchat/gathdlc.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c
index ee27c6de..ebb693c1 100644
--- a/gatchat/gathdlc.c
+++ b/gatchat/gathdlc.c
@@ -53,6 +53,7 @@ struct _GAtHDLC {
guint decode_offset;
guint16 decode_fcs;
gboolean decode_escape;
+ guint32 xmit_accm[8];
GAtReceiveFunc receive_func;
gpointer receive_data;
GAtDebugFunc debugf;
@@ -176,6 +177,9 @@ GAtHDLC *g_at_hdlc_new(GIOChannel *channel)
hdlc->decode_escape = FALSE;
hdlc->max_read_attempts = 8;
+ hdlc->xmit_accm[0] = ~0U;
+ hdlc->xmit_accm[3] = 0x60000000; /* 0x7d, 0x7e */
+
hdlc->read_buffer = ring_buffer_new(BUFFER_SIZE);
if (!hdlc->read_buffer)
goto error;
@@ -321,6 +325,24 @@ static void wakeup_write(GAtHDLC *hdlc)
can_write_data, hdlc, write_watch_destroy);
}
+void g_at_hdlc_set_xmit_accm(GAtHDLC *hdlc, guint32 accm)
+{
+ if (hdlc == NULL)
+ return;
+
+ hdlc->xmit_accm[0] = accm;
+}
+
+guint32 g_at_hdlc_get_xmit_accm(GAtHDLC *hdlc)
+{
+ if (hdlc == NULL)
+ return 0;
+
+ return hdlc->xmit_accm[0];
+}
+
+#define NEED_ESCAPE(xmit_accm, c) xmit_accm[c >> 5] & (1 << (c & 0x1f))
+
gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size)
{
unsigned int avail = ring_buffer_avail(hdlc->write_buffer);
@@ -342,7 +364,7 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size)
fcs = HDLC_FCS(fcs, data[i]);
*buf = data[i++] ^ HDLC_TRANS;
escape = FALSE;
- } else if (data[i] == HDLC_FLAG || data[i] == HDLC_ESCAPE) {
+ } else if (NEED_ESCAPE(hdlc->xmit_accm, data[i])) {
*buf = HDLC_ESCAPE;
escape = TRUE;
} else {
@@ -370,7 +392,7 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size)
if (escape == TRUE) {
*buf = tail[i++] ^ HDLC_TRANS;
escape = FALSE;
- } else if (tail[i] == HDLC_FLAG || tail[i] == HDLC_ESCAPE) {
+ } else if (NEED_ESCAPE(hdlc->xmit_accm, tail[i])) {
*buf = HDLC_ESCAPE;
escape = TRUE;
} else {