summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-04-01 20:18:49 -0700
committerMarcel Holtmann <marcel@holtmann.org>2010-04-01 20:18:49 -0700
commitcdc1e3c31b74adc010efd9dddd7502806ff0e555 (patch)
treecf3cea9f18b07cf045170929a2565f71005e1140
parentdabac98cb4cab2a2447c95e68dceaf2a7762f684 (diff)
downloadofono-cdc1e3c31b74adc010efd9dddd7502806ff0e555.tar.bz2
Check FCS while unstuffing the byte stream
-rw-r--r--gatchat/ppp.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/gatchat/ppp.c b/gatchat/ppp.c
index 6312daba..887a6308 100644
--- a/gatchat/ppp.c
+++ b/gatchat/ppp.c
@@ -217,9 +217,8 @@ static void ppp_recv(GAtPPP *ppp, struct frame_buffer *frame)
static struct frame_buffer *ppp_decode(GAtPPP *ppp, guint8 *frame)
{
guint8 *data;
- guint pos = 0;
- int i = 0;
- int len;
+ guint pos;
+ int i;
guint16 fcs;
struct frame_buffer *fb;
@@ -229,7 +228,10 @@ static struct frame_buffer *ppp_decode(GAtPPP *ppp, guint8 *frame)
data = fb->bytes;
/* skip the first flag char */
- pos++;
+ pos = 1;
+
+ fcs = PPPINITFCS16;
+ i = 0;
/* TBD - how to deal with recv_accm */
while (frame[pos] != PPP_FLAG_SEQ) {
@@ -240,21 +242,20 @@ static struct frame_buffer *ppp_decode(GAtPPP *ppp, guint8 *frame)
data[i] = frame[pos] ^ 0x20;
} else
data[i] = frame[pos];
+
+ fcs = ppp_fcs(fcs, data[i]);
+
i++; pos++;
}
- len = i;
- fb->len = len;
+ fb->len = i;
/* see if we have a good FCS */
- fcs = PPPINITFCS16;
- for (i = 0; i < len; i++)
- fcs = ppp_fcs(fcs, data[i]);
-
if (fcs != PPPGOODFCS16) {
g_free(fb);
return NULL;
}
+
return fb;
}