aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-11-14 19:34:30 +0100
committerHarald Welte <laforge@gnumonks.org>2016-11-14 19:34:30 +0100
commit90fb78580423c18dc03ef5cad9c2ce607ad90760 (patch)
tree15b2007196c2e275024217341ac2dc2cc77b6745 /src
parentd83c51379b52d3bd94db57de046ba674377b4386 (diff)
hdlc: Add some more comments to the code [cosmetic]
Diffstat (limited to 'src')
-rw-r--r--src/hdlc.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/hdlc.c b/src/hdlc.c
index 1768dfd..0a53a27 100644
--- a/src/hdlc.c
+++ b/src/hdlc.c
@@ -22,8 +22,11 @@ static const ubit_t five_ones[] = { 1,1,1,1,1 };
static int append_bit(struct hdlc_proc *hdlc, uint8_t bit, int ignore)
{
+ /* we always add the bit to the history */
memmove(hdlc->history+1, hdlc->history, sizeof(hdlc->history)-1);
hdlc->history[0] = bit;
+
+ /* if it is a to-be-discarded bit, we bail out */
if (ignore)
return -1;
@@ -51,21 +54,32 @@ static int process_hdlc_bit(struct hdlc_proc *hdlc, uint8_t bit)
switch (hdlc->state) {
case STATE_FLAG_WAIT_ZERO:
+ /* we've received 6 consecutive '1' just before and are
+ * waiting for the final '0' to end the flag character */
if (bit == 0) {
+ /* it was a zero, flag character detected */
DEBUGP("F ");
flag = 1;
+ /* we're now inside the payload state */
hdlc->state = STATE_PAYLOAD;
} else {
+ /* if we received yet another '1', we re-start
+ * from the beginning */
hdlc->state = STATE_INIT;
}
ignore = 1;
hdlc->num_bits = 0;
break;
- default:
+ case STATE_PAYLOAD:
+ case STATE_INIT:
if (!memcmp(five_ones, hdlc->history, sizeof(five_ones))) {
+ /* five consecutive ones in the history */
if (bit == 1) {
- //DEBUGP("F ");
+ /* one more '1' was received -> we wait
+ * for a zero at the end of the flag
+ * character 0x7E */
hdlc->state = STATE_FLAG_WAIT_ZERO;
+ /* discard bit */
ignore = 1;
} else {
/* discard bit */