From 63aef01e6b9f97e619813abd86392efcebc5e96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Rymanowski?= Date: Tue, 5 Sep 2017 11:37:03 +0200 Subject: [PATCH] nimble/mesh: Clear link TX when ACK arrived on it Without this fix there is an issue when doing PB-ADV provisioning with PTS. We keep retransmitting Public Key which is ACKed by PTS and this leads to transaction timeout as PTS does not send confirm probably because it keep receiving PK from us. This patch also makes sure that transaction id is between 0x80 - 0xFF X-Original-Commit: d957d9a96003fdf40850bcf18ab598d0b682c076 --- nimble/host/mesh/src/prov.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/nimble/host/mesh/src/prov.c b/nimble/host/mesh/src/prov.c index 51b648bfb..bce3dc173 100644 --- a/nimble/host/mesh/src/prov.c +++ b/nimble/host/mesh/src/prov.c @@ -145,6 +145,9 @@ struct prov_link { /* Start timestamp of the transaction */ s64_t start; + /* Transaction id*/ + u8_t id; + /* Pending outgoing buffer(s) */ struct os_mbuf *buf[3]; @@ -358,11 +361,21 @@ static u8_t last_seg(u8_t len) return 1 + (len / CONT_PAYLOAD_MAX); } +static inline u8_t next_transaction_id(void) +{ + if (link.tx.id != 0 && link.tx.id != 0xFF) { + return ++link.tx.id; + } + + link.tx.id = 0x80; + return link.tx.id; +} + static int prov_send_adv(struct os_mbuf *msg) { - static u8_t id = 0x80; struct os_mbuf *start, *buf; u8_t seg_len, seg_id; + u8_t xact_id; BT_DBG("prov_send_adv len %u: %s", msg->om_len, bt_hex(msg->om_data, msg->om_len)); @@ -373,8 +386,9 @@ static int prov_send_adv(struct os_mbuf *msg) return -ENOBUFS; } + xact_id = next_transaction_id(); net_buf_add_be32(start, link.id); - net_buf_add_u8(start, id); + net_buf_add_u8(start, xact_id); net_buf_add_u8(start, GPC_START(last_seg(msg->om_len))); net_buf_add_be16(start, msg->om_len); @@ -409,14 +423,12 @@ static int prov_send_adv(struct os_mbuf *msg) bt_hex(msg->om_data, seg_len)); net_buf_add_be32(buf, link.id); - net_buf_add_u8(buf, id); + net_buf_add_u8(buf, xact_id); net_buf_add_u8(buf, GPC_CONT(seg_id)); net_buf_add_mem(buf, msg->om_data, seg_len); net_buf_simple_pull(msg, seg_len); } - id++; - send_reliable(); return 0; @@ -1283,6 +1295,14 @@ static void gen_prov_cont(struct prov_rx *rx, struct os_mbuf *buf) static void gen_prov_ack(struct prov_rx *rx, struct os_mbuf *buf) { BT_DBG("len %u", buf->om_len); + + if (!link.tx.buf[0]) { + return; + } + + if (rx->xact_id == link.tx.id) { + prov_clear_tx(); + } } static void gen_prov_start(struct prov_rx *rx, struct os_mbuf *buf)