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)