1
0
Fork 0

Fixes ACK number off-by-one

This commit is contained in:
Shawn Nock 2019-08-03 04:36:45 -05:00
parent 70c7a8f590
commit 9060e0d140
1 changed files with 9 additions and 15 deletions

View File

@ -129,7 +129,7 @@ static struct h5 {
struct k_fifo event_queue;
u8_t tx_win;
u8_t last_seen_seq_from_host;
u8_t next_expected_seq_from_host;
u8_t local_seq;
linkstate_t link_state;
@ -280,7 +280,7 @@ void h5_send(const u8_t *payload, u8_t type, int len)
h5_hdr_t hdr = {0};
/* Set ACK for outgoing packet and stop delayed work */
hdr.ack = h5.last_seen_seq_from_host;
hdr.ack = h5.next_expected_seq_from_host;
k_delayed_work_cancel(&ack_work);
LOG_INF("ACK'd %d", hdr.ack);
@ -468,8 +468,10 @@ void bt_uart_isr(struct device *unused)
if (buf->len > 0) {
net_buf_put(&h5.unprocessed_queue, buf);
buf = NULL;
}
slip_state = SLIP_NOSYNC;
} else {
slip_state = SLIP_SYNC;
}
} else {
net_buf_add_u8(buf, byte);
}
@ -548,19 +550,12 @@ 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;
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);
if (hdr.seq != h5.next_expected_seq_from_host) {
LOG_ERR("Seq expected %u got %u. Drop packet", h5.next_expected_seq_from_host, hdr.seq);
goto next;
}
k_delayed_work_submit(&ack_work, H5_RX_ACK_TIMEOUT);
h5.last_seen_seq_from_host = hdr.seq;
h5.next_expected_seq_from_host = next_seq(hdr.seq);
}
if (h5.link_state < ACTIVE && hdr.packet_type != HCI_3WIRE_LINK_PKT) {
@ -889,7 +884,7 @@ 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 = 0;
h5.next_expected_seq_from_host = 0;
h5.local_seq = 0;
h5.initializing = true;
LOG_DBG("Finished H5 configuration, tx_win %u: INIT -> ACTIVE", h5.tx_win);
@ -921,7 +916,6 @@ static linkstate_t do_active(struct net_buf *buf) {
// Presumably something from the controller
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
h5_send(buf->data, HCI_EVENT_PKT, buf->len);
k_yield();
} else {
LOG_HEXDUMP_ERR(buf->data, buf->len, "Unexpected buffer in host_queue");
}