Lines Matching refs:link

43 #define XACT_SEG_DATA(_seg) (&link.rx.buf->data[XACT_SEG_OFFSET(_seg)])
44 #define XACT_SEG_RECV(_seg) (link.rx.seg &= ~(1 << (_seg)))
123 static struct pb_adv link = { .rx = { .buf = &rx_buf } }; variable
134 if (atomic_test_and_clear_bit(link.flags, ADV_LINK_CLOSING)) { in buf_sent()
167 for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) { in free_segments()
168 struct net_buf *buf = link.tx.buf[i]; in free_segments()
174 link.tx.buf[i] = NULL; in free_segments()
195 (void)k_work_cancel_delayable(&link.tx.retransmit); in prov_clear_tx()
208 (void)k_work_cancel_delayable(&link.prot_timer); in reset_adv_link()
210 if (atomic_test_bit(link.flags, ADV_PROVISIONER)) { in reset_adv_link()
214 (void)memset(&link, 0, offsetof(struct pb_adv, tx.retransmit)); in reset_adv_link()
215 link.rx.id = XACT_ID_NVAL; in reset_adv_link()
218 link.id = 0; in reset_adv_link()
219 atomic_clear(link.flags); in reset_adv_link()
220 link.rx.id = XACT_ID_MAX; in reset_adv_link()
221 link.tx.id = XACT_ID_NVAL; in reset_adv_link()
224 link.tx.pending_ack = XACT_ID_NVAL; in reset_adv_link()
225 link.rx.buf = &rx_buf; in reset_adv_link()
226 net_buf_simple_reset(link.rx.buf); in reset_adv_link()
231 const struct prov_bearer_cb *cb = link.cb; in close_link()
232 void *cb_data = link.cb_data; in close_link()
255 BT_DBG("xact 0x%x complete", (uint8_t)link.tx.pending_ack); in ack_complete()
256 atomic_clear_bit(link.flags, ADV_ACK_PENDING); in ack_complete()
261 return atomic_test_bit(link.flags, ADV_ACK_PENDING); in ack_pending()
267 link.cb->error(&pb_adv, link.cb_data, err); in prov_failed()
268 atomic_set_bit(link.flags, ADV_LINK_INVALID); in prov_failed()
273 k_work_reschedule(&link.prot_timer, PROTOCOL_TIMEOUT); in prov_msg_recv()
275 if (!bt_mesh_fcs_check(link.rx.buf, link.rx.fcs)) { in prov_msg_recv()
280 gen_prov_ack_send(link.rx.id); in prov_msg_recv()
282 if (atomic_test_bit(link.flags, ADV_LINK_INVALID)) { in prov_msg_recv()
284 link.rx.buf->data[0]); in prov_msg_recv()
289 link.cb->recv(&pb_adv, link.cb_data, link.rx.buf); in prov_msg_recv()
294 if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) { in protocol_timeout()
300 link.rx.seg = 0U; in protocol_timeout()
314 bool pending = atomic_test_and_set_bit(link.flags, ADV_ACK_PENDING); in gen_prov_ack_send()
318 if (pending && link.tx.pending_ack == xact_id) { in gen_prov_ack_send()
325 atomic_clear_bit(link.flags, ADV_ACK_PENDING); in gen_prov_ack_send()
332 link.tx.pending_ack = xact_id; in gen_prov_ack_send()
336 net_buf_add_be32(buf, link.id); in gen_prov_ack_send()
350 if (!link.rx.seg && link.rx.id == rx->xact_id) { in gen_prov_cont()
359 if (!link.rx.seg && in gen_prov_cont()
360 next_transaction_id(link.rx.id) == rx->xact_id) { in gen_prov_cont()
363 link.rx.id = rx->xact_id; in gen_prov_cont()
365 net_buf_simple_reset(link.rx.buf); in gen_prov_cont()
367 link.rx.seg = SEG_NVAL; in gen_prov_cont()
368 link.rx.last_seg = SEG_NVAL; in gen_prov_cont()
371 } else if (rx->xact_id != link.rx.id) { in gen_prov_cont()
373 rx->xact_id, link.rx.id); in gen_prov_cont()
377 if (seg > link.rx.last_seg) { in gen_prov_cont()
383 if (!(link.rx.seg & BIT(seg))) { in gen_prov_cont()
396 if (seg == link.rx.last_seg && !(link.rx.seg & BIT(0))) { in gen_prov_cont()
399 expect_len = (link.rx.buf->len - 20U - in gen_prov_cont()
400 ((link.rx.last_seg - 1) * 23U)); in gen_prov_cont()
409 if (!link.rx.seg) { in gen_prov_cont()
418 if (!link.tx.buf[0]) { in gen_prov_ack()
422 if (rx->xact_id == link.tx.id) { in gen_prov_ack()
424 if (!atomic_test_bit(link.flags, ADV_LINK_CLOSING)) { in gen_prov_ack()
428 if (link.tx.cb) { in gen_prov_ack()
429 link.tx.cb(0, link.tx.cb_data); in gen_prov_ack()
438 if (rx->xact_id == link.rx.id) { in gen_prov_start()
439 if (!link.rx.seg) { in gen_prov_start()
448 if (!(link.rx.seg & BIT(0))) { in gen_prov_start()
452 } else if (rx->xact_id != next_transaction_id(link.rx.id)) { in gen_prov_start()
454 next_transaction_id(link.rx.id)); in gen_prov_start()
458 net_buf_simple_reset(link.rx.buf); in gen_prov_start()
459 link.rx.buf->len = net_buf_simple_pull_be16(buf); in gen_prov_start()
460 link.rx.id = rx->xact_id; in gen_prov_start()
461 link.rx.fcs = net_buf_simple_pull_u8(buf); in gen_prov_start()
464 START_LAST_SEG(rx->gpc), link.rx.buf->len, link.rx.fcs); in gen_prov_start()
466 if (link.rx.buf->len < 1) { in gen_prov_start()
472 if (link.rx.buf->len > link.rx.buf->size) { in gen_prov_start()
474 link.rx.buf->len); in gen_prov_start()
479 if (START_LAST_SEG(rx->gpc) > 0 && link.rx.buf->len <= 20U) { in gen_prov_start()
485 if (START_LAST_SEG(rx->gpc) != last_seg(link.rx.buf->len)) { in gen_prov_start()
487 last_seg(link.rx.buf->len)); in gen_prov_start()
494 link.rx.last_seg = START_LAST_SEG(rx->gpc); in gen_prov_start()
496 if ((link.rx.seg & BIT(0)) && in gen_prov_start()
497 (find_msb_set((~link.rx.seg) & SEG_NVAL) - 1 > link.rx.last_seg)) { in gen_prov_start()
503 if (link.rx.seg) { in gen_prov_start()
504 seg = link.rx.seg; in gen_prov_start()
507 link.rx.seg = seg & ((1 << (START_LAST_SEG(rx->gpc) + 1)) - 1); in gen_prov_start()
508 memcpy(link.rx.buf->data, buf->data, buf->len); in gen_prov_start()
511 if (!link.rx.seg) { in gen_prov_start()
525 if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) { in gen_prov_ctl()
532 if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) { in gen_prov_ctl()
567 if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE) && in gen_prov_recv()
584 for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) { in send_reliable()
585 struct net_buf *buf = link.tx.buf[i]; in send_reliable()
600 k_work_reschedule(&link.tx.retransmit, RETRANSMIT_TIMEOUT); in send_reliable()
607 if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) { in prov_retransmit()
612 if (k_uptime_get() - link.tx.start > TRANSACTION_TIMEOUT) { in prov_retransmit()
633 net_buf_add_be32(buf, link.id); in ctl_buf_create()
649 k_work_reschedule(&link.prot_timer, PROTOCOL_TIMEOUT); in bearer_ctl_send()
651 link.tx.start = k_uptime_get(); in bearer_ctl_send()
652 link.tx.buf[0] = buf; in bearer_ctl_send()
665 k_work_reschedule(&link.prot_timer, PROTOCOL_TIMEOUT); in bearer_ctl_send_unacked()
680 k_work_reschedule(&link.prot_timer, PROTOCOL_TIMEOUT); in prov_send_adv()
687 link.tx.id = next_transaction_id(link.tx.id); in prov_send_adv()
688 net_buf_add_be32(start, link.id); in prov_send_adv()
689 net_buf_add_u8(start, link.tx.id); in prov_send_adv()
695 link.tx.buf[0] = start; in prov_send_adv()
696 link.tx.cb = cb; in prov_send_adv()
697 link.tx.cb_data = cb_data; in prov_send_adv()
698 link.tx.start = k_uptime_get(); in prov_send_adv()
700 BT_DBG("xact_id: 0x%x len: %u", link.tx.id, msg->len); in prov_send_adv()
709 if (seg_id >= ARRAY_SIZE(link.tx.buf)) { in prov_send_adv()
721 link.tx.buf[seg_id] = buf; in prov_send_adv()
728 net_buf_add_be32(buf, link.id); in prov_send_adv()
729 net_buf_add_u8(buf, link.tx.id); in prov_send_adv()
755 if (atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) { in link_open()
757 if (link.id != rx->link_id) { in link_open()
773 link.id = rx->link_id; in link_open()
774 atomic_set_bit(link.flags, ADV_LINK_ACTIVE); in link_open()
775 net_buf_simple_reset(link.rx.buf); in link_open()
783 link.cb->link_opened(&pb_adv, link.cb_data); in link_open()
790 if (atomic_test_bit(link.flags, ADV_PROVISIONER)) { in link_ack()
791 if (atomic_test_and_set_bit(link.flags, ADV_LINK_ACK_RECVD)) { in link_ack()
797 link.cb->link_opened(&pb_adv, link.cb_data); in link_ack()
820 if (!link.cb) { in bt_mesh_pb_adv_recv()
833 if (atomic_test_bit(link.flags, ADV_LINK_ACTIVE) && link.id != rx.link_id) { in bt_mesh_pb_adv_recv()
855 if (atomic_test_and_set_bit(link.flags, ADV_LINK_ACTIVE)) { in prov_link_open()
859 atomic_set_bit(link.flags, ADV_PROVISIONER); in prov_link_open()
861 bt_rand(&link.id, sizeof(link.id)); in prov_link_open()
862 link.tx.id = XACT_ID_MAX; in prov_link_open()
863 link.rx.id = XACT_ID_NVAL; in prov_link_open()
864 link.cb = cb; in prov_link_open()
865 link.cb_data = cb_data; in prov_link_open()
867 net_buf_simple_reset(link.rx.buf); in prov_link_open()
882 if (atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) { in prov_link_accept()
886 link.rx.id = XACT_ID_MAX; in prov_link_accept()
887 link.tx.id = XACT_ID_NVAL; in prov_link_accept()
888 link.cb = cb; in prov_link_accept()
889 link.cb_data = cb_data; in prov_link_accept()
901 if (atomic_test_and_set_bit(link.flags, ADV_LINK_CLOSING)) { in prov_link_close()
911 k_work_init_delayable(&link.prot_timer, protocol_timeout); in pb_adv_init()
912 k_work_init_delayable(&link.tx.retransmit, prov_retransmit); in pb_adv_init()