Fixes ACK number off-by-one
This commit is contained in:
parent
70c7a8f590
commit
9060e0d140
24
src/main.c
24
src/main.c
|
@ -129,7 +129,7 @@ static struct h5 {
|
||||||
struct k_fifo event_queue;
|
struct k_fifo event_queue;
|
||||||
|
|
||||||
u8_t tx_win;
|
u8_t tx_win;
|
||||||
u8_t last_seen_seq_from_host;
|
u8_t next_expected_seq_from_host;
|
||||||
u8_t local_seq;
|
u8_t local_seq;
|
||||||
|
|
||||||
linkstate_t link_state;
|
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};
|
h5_hdr_t hdr = {0};
|
||||||
|
|
||||||
/* Set ACK for outgoing packet and stop delayed work */
|
/* 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);
|
k_delayed_work_cancel(&ack_work);
|
||||||
|
|
||||||
LOG_INF("ACK'd %d", hdr.ack);
|
LOG_INF("ACK'd %d", hdr.ack);
|
||||||
|
@ -468,8 +468,10 @@ void bt_uart_isr(struct device *unused)
|
||||||
if (buf->len > 0) {
|
if (buf->len > 0) {
|
||||||
net_buf_put(&h5.unprocessed_queue, buf);
|
net_buf_put(&h5.unprocessed_queue, buf);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
slip_state = SLIP_NOSYNC;
|
||||||
|
} else {
|
||||||
|
slip_state = SLIP_SYNC;
|
||||||
}
|
}
|
||||||
slip_state = SLIP_SYNC;
|
|
||||||
} else {
|
} else {
|
||||||
net_buf_add_u8(buf, byte);
|
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,
|
LOG_DBG("Header: seq %d, ack %d, rel: %s, has_crc16: %s", hdr.seq, hdr.ack,
|
||||||
hdr.is_reliable ? "true" : "false",
|
hdr.is_reliable ? "true" : "false",
|
||||||
hdr.crc_after_payload ? "true" : "false");
|
hdr.crc_after_payload ? "true" : "false");
|
||||||
u8_t expected_seq;
|
if (hdr.seq != h5.next_expected_seq_from_host) {
|
||||||
if (h5.initializing) {
|
LOG_ERR("Seq expected %u got %u. Drop packet", h5.next_expected_seq_from_host, hdr.seq);
|
||||||
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;
|
goto next;
|
||||||
}
|
}
|
||||||
k_delayed_work_submit(&ack_work, H5_RX_ACK_TIMEOUT);
|
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) {
|
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;
|
return INIT;
|
||||||
case H5_CONFIG_RESPONSE:
|
case H5_CONFIG_RESPONSE:
|
||||||
h5.tx_win = conf_rsp[2] & 0x7;
|
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.local_seq = 0;
|
||||||
h5.initializing = true;
|
h5.initializing = true;
|
||||||
LOG_DBG("Finished H5 configuration, tx_win %u: INIT -> ACTIVE", h5.tx_win);
|
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
|
// Presumably something from the controller
|
||||||
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
|
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
|
||||||
h5_send(buf->data, HCI_EVENT_PKT, buf->len);
|
h5_send(buf->data, HCI_EVENT_PKT, buf->len);
|
||||||
k_yield();
|
|
||||||
} else {
|
} else {
|
||||||
LOG_HEXDUMP_ERR(buf->data, buf->len, "Unexpected buffer in host_queue");
|
LOG_HEXDUMP_ERR(buf->data, buf->len, "Unexpected buffer in host_queue");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue