From 70c7a8f590c8d4cb9d3d4734cd70b47086a065c4 Mon Sep 17 00:00:00 2001 From: Shawn Nock Date: Fri, 2 Aug 2019 16:03:45 -0400 Subject: [PATCH] Works around weird initial rules for H5 state machine (initial ack must be 0?) --- src/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index e9647c3..751ebfd 100644 --- a/src/main.c +++ b/src/main.c @@ -140,6 +140,7 @@ static struct h5 { PAYLOAD, END, } rx_state; + bool initializing; } h5; //static u8_t unack_queue_len; @@ -547,7 +548,13 @@ static void unproc_thread(void) { LOG_DBG("Header: seq %d, ack %d, rel: %s, has_crc16: %s", hdr.seq, hdr.ack, hdr.is_reliable ? "true" : "false", hdr.crc_after_payload ? "true" : "false"); - u8_t expected_seq = next_seq(h5.last_seen_seq_from_host); + u8_t expected_seq; + if (h5.initializing) { + expected_seq = 0; + h5.initializing = false; + } else { + expected_seq = next_seq(h5.last_seen_seq_from_host); + } if (hdr.seq != expected_seq) { LOG_ERR("Seq expected %u got %u. Drop packet", expected_seq, hdr.seq); goto next; @@ -882,8 +889,9 @@ static linkstate_t do_init(struct net_buf const *buf) { return INIT; case H5_CONFIG_RESPONSE: h5.tx_win = conf_rsp[2] & 0x7; - h5.last_seen_seq_from_host = 7; + h5.last_seen_seq_from_host = 0; h5.local_seq = 0; + h5.initializing = true; LOG_DBG("Finished H5 configuration, tx_win %u: INIT -> ACTIVE", h5.tx_win); return ACTIVE; default: