diff --git a/subsys/bluetooth/host/mesh/prov.c b/subsys/bluetooth/host/mesh/prov.c index 9bc2fe4bf1a..b60e73ae762 100644 --- a/subsys/bluetooth/host/mesh/prov.c +++ b/subsys/bluetooth/host/mesh/prov.c @@ -150,6 +150,9 @@ struct prov_link { /* Start timestamp of the transaction */ s64_t start; + /* Transaction id*/ + u8_t id; + /* Pending outgoing buffer(s) */ struct net_buf *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 net_buf_simple *msg) { - static u8_t id = 0x80; struct net_buf *start, *buf; u8_t seg_len, seg_id; + u8_t xact_id; BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len)); @@ -373,8 +386,9 @@ static int prov_send_adv(struct net_buf_simple *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->len))); net_buf_add_be16(start, msg->len); @@ -409,14 +423,12 @@ static int prov_send_adv(struct net_buf_simple *msg) bt_hex(msg->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->data, seg_len); net_buf_simple_pull(msg, seg_len); } - id++; - send_reliable(); return 0; @@ -1264,6 +1276,14 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) static void gen_prov_ack(struct prov_rx *rx, struct net_buf_simple *buf) { BT_DBG("len %u", buf->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 net_buf_simple *buf)