Skip to content

Commit 8cc298c

Browse files
committed
Bluetooth: Controller: Introduce LL_ASSERT_DBG/ERR
Introduce development and fatal assertion classification in the Controller implementation. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent da74ae8 commit 8cc298c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+986
-964
lines changed

subsys/bluetooth/controller/hal/debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ void bt_ctlr_assert_handle(char *file, uint32_t line);
2727
BT_ASSERT_MSG(cond, fmt, ##__VA_ARGS__)
2828
#endif
2929

30+
#define LL_ASSERT_ERR(cond) LL_ASSERT(cond)
31+
#define LL_ASSERT_DBG(cond) LL_ASSERT(cond)
32+
3033
#if defined(CONFIG_BT_CTLR_ASSERT_VENDOR)
3134
#define LL_ASSERT_INFO1(cond, param) \
3235
BT_ASSERT_VND(cond, param, 0)

subsys/bluetooth/controller/hci/hci.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ static void le_df_connection_iq_report(struct node_rx_pdu *node_rx, struct net_b
31733173
phy_rx = lll->phy_rx;
31743174

31753175
/* Make sure the report is generated for connection on PHY UNCODED */
3176-
LL_ASSERT(phy_rx != PHY_CODED);
3176+
LL_ASSERT_DBG(phy_rx != PHY_CODED);
31773177
#else
31783178
phy_rx = PHY_1M;
31793179
#endif /* CONFIG_BT_CTLR_PHY */
@@ -4363,7 +4363,7 @@ static void le_cis_request(struct pdu_data *pdu_data,
43634363
* event.
43644364
*/
43654365
node = pdu_data;
4366-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
4366+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
43674367

43684368
req = node;
43694369
if (!(ll_feat_get() & BIT64(BT_LE_FEAT_BIT_ISO_CHANNELS)) ||
@@ -4410,7 +4410,7 @@ static void le_cis_established(struct pdu_data *pdu_data,
44104410
* event.
44114411
*/
44124412
node = pdu_data;
4413-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
4413+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
44144414

44154415
est = node;
44164416
sep->status = est->status;
@@ -4469,7 +4469,7 @@ static void le_per_adv_sync_transfer_received(struct pdu_data *pdu_data_rx,
44694469
* event.
44704470
*/
44714471
node = pdu_data_rx;
4472-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_past_received));
4472+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_past_received));
44734473

44744474
se = node;
44754475
sep->status = se->rx_sync.status;
@@ -5460,7 +5460,7 @@ static void vs_le_df_connection_iq_report(struct node_rx_pdu *node_rx, struct ne
54605460
phy_rx = lll->phy_rx;
54615461

54625462
/* Make sure the report is generated for connection on PHY UNCODED */
5463-
LL_ASSERT(phy_rx != PHY_CODED);
5463+
LL_ASSERT_DBG(phy_rx != PHY_CODED);
54645464
#else
54655465
phy_rx = PHY_1M;
54665466
#endif /* CONFIG_BT_CTLR_PHY */
@@ -6240,7 +6240,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
62406240

62416241
/* Start Fragmentation */
62426242
/* FIXME: need to ensure ISO-AL returns proper isoal_status.
6243-
* Currently there are cases where ISO-AL calls LL_ASSERT.
6243+
* Currently there are cases where ISO-AL calls LL_ASSERT_ERR.
62446244
*/
62456245
isoal_status_t isoal_status =
62466246
isoal_tx_sdu_fragment(stream->dp->source_hdl, &sdu_frag_tx);
@@ -6494,7 +6494,7 @@ static inline void le_dir_adv_report(struct pdu_adv *adv, struct net_buf *buf,
64946494
return;
64956495
}
64966496

6497-
LL_ASSERT(adv->type == PDU_ADV_TYPE_DIRECT_IND);
6497+
LL_ASSERT_DBG(adv->type == PDU_ADV_TYPE_DIRECT_IND);
64986498

64996499
#if CONFIG_BT_CTLR_DUP_FILTER_LEN > 0
65006500
if (dup_scan &&
@@ -6564,7 +6564,7 @@ static inline void le_mesh_scan_report(struct pdu_adv *adv,
65646564
uint32_t instant;
65656565
uint8_t chan;
65666566

6567-
LL_ASSERT(adv->type == PDU_ADV_TYPE_NONCONN_IND);
6567+
LL_ASSERT_DBG(adv->type == PDU_ADV_TYPE_NONCONN_IND);
65686568

65696569
/* Filter based on currently active Scan Filter */
65706570
if (sf_curr < ARRAY_SIZE(scan_filters) &&
@@ -7033,7 +7033,7 @@ static void ext_adv_pdu_frag(uint8_t evt_type, uint8_t phy, uint8_t sec_phy,
70337033
*data_len_total -= data_len_frag;
70347034

70357035
*evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
7036-
LL_ASSERT(*evt_buf);
7036+
LL_ASSERT_ERR(*evt_buf);
70377037

70387038
net_buf_frag_add(buf, *evt_buf);
70397039

@@ -7570,7 +7570,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
75707570
* event.
75717571
*/
75727572
evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
7573-
LL_ASSERT(evt_buf);
7573+
LL_ASSERT_ERR(evt_buf);
75747574

75757575
net_buf_frag_add(buf, evt_buf);
75767576

@@ -7666,7 +7666,7 @@ static void le_per_adv_sync_established(struct pdu_data *pdu_data,
76667666
* event.
76677667
*/
76687668
node = pdu_data;
7669-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_sync));
7669+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_sync));
76707670

76717671
se = node;
76727672
sep->status = se->status;
@@ -7946,7 +7946,7 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
79467946
data_status = BT_HCI_LE_ADV_EVT_TYPE_DATA_STATUS_PARTIAL;
79477947

79487948
evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
7949-
LL_ASSERT(evt_buf);
7949+
LL_ASSERT_ERR(evt_buf);
79507950

79517951
net_buf_frag_add(buf, evt_buf);
79527952

@@ -8002,7 +8002,7 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
80028002
*/
80038003
if (!evt_buf) {
80048004
evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
8005-
LL_ASSERT(evt_buf);
8005+
LL_ASSERT_ERR(evt_buf);
80068006

80078007
net_buf_frag_add(buf, evt_buf);
80088008
}
@@ -8087,7 +8087,7 @@ static void le_big_sync_established(struct pdu_data *pdu,
80878087
* established event.
80888088
*/
80898089
node = pdu;
8090-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_sync_iso));
8090+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_sync_iso));
80918091

80928092
se = node;
80938093
sep->status = se->status;
@@ -8391,7 +8391,7 @@ static void le_conn_complete(struct pdu_data *pdu_data, uint16_t handle,
83918391
* complete event.
83928392
*/
83938393
node = pdu_data;
8394-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_cc));
8394+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_cc));
83958395

83968396
cc = node;
83978397
status = cc->status;
@@ -8528,7 +8528,7 @@ static void le_conn_update_complete(struct pdu_data *pdu_data, uint16_t handle,
85288528
* update complete event.
85298529
*/
85308530
node = pdu_data;
8531-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_cu));
8531+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_cu));
85328532

85338533
cu = node;
85348534
sep->status = cu->status;
@@ -8763,7 +8763,7 @@ static void encode_control(struct node_rx_pdu *node_rx,
87638763
#elif defined(CONFIG_BT_CTLR_VS_SCAN_REQ_RX)
87648764
le_vs_scan_req_received(pdu_data, node_rx, buf);
87658765
#else
8766-
LL_ASSERT(0);
8766+
LL_ASSERT_DBG(0);
87678767
#endif /* CONFIG_BT_CTLR_ADV_EXT */
87688768
break;
87698769
#endif /* CONFIG_BT_CTLR_SCAN_REQ_NOTIFY */
@@ -8896,7 +8896,7 @@ static void encode_control(struct node_rx_pdu *node_rx,
88968896
#endif /* CONFIG_BT_CTLR_USER_EVT_RANGE > 0 */
88978897

88988898
default:
8899-
LL_ASSERT(0);
8899+
LL_ASSERT_DBG(0);
89008900
return;
89018901
}
89028902
}
@@ -9124,7 +9124,7 @@ static void encode_data_ctrl(struct node_rx_pdu *node_rx,
91249124
break;
91259125

91269126
default:
9127-
LL_ASSERT(0);
9127+
LL_ASSERT_DBG(0);
91289128
return;
91299129
}
91309130
}
@@ -9155,20 +9155,20 @@ void hci_acl_encode(struct node_rx_pdu *node_rx, struct net_buf *buf)
91559155
memcpy(data, pdu_data->lldata, pdu_data->len);
91569156
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
91579157
if (hci_hbuf_total > 0) {
9158-
LL_ASSERT((hci_hbuf_sent - hci_hbuf_acked) <
9158+
LL_ASSERT_DBG((hci_hbuf_sent - hci_hbuf_acked) <
91599159
hci_hbuf_total);
91609160
hci_hbuf_sent++;
91619161
/* Note: This requires linear handle values starting
91629162
* from 0
91639163
*/
9164-
LL_ASSERT(handle < ARRAY_SIZE(hci_hbuf_pend));
9164+
LL_ASSERT_DBG(handle < ARRAY_SIZE(hci_hbuf_pend));
91659165
hci_hbuf_pend[handle]++;
91669166
}
91679167
#endif /* CONFIG_BT_HCI_ACL_FLOW_CONTROL */
91689168
break;
91699169

91709170
default:
9171-
LL_ASSERT(0);
9171+
LL_ASSERT_DBG(0);
91729172
break;
91739173
}
91749174
}

subsys/bluetooth/controller/hci/hci_driver.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,20 @@ isoal_status_t sink_sdu_alloc_hci(const struct isoal_sink *sink_ctx,
9191
const struct isoal_pdu_rx *valid_pdu,
9292
struct isoal_sdu_buffer *sdu_buffer)
9393
{
94+
struct net_buf *buf;
95+
9496
ARG_UNUSED(sink_ctx);
9597
ARG_UNUSED(valid_pdu); /* TODO copy valid pdu into netbuf ? */
9698

97-
struct net_buf *buf = bt_buf_get_rx(BT_BUF_ISO_IN, K_FOREVER);
99+
buf = bt_buf_get_rx(BT_BUF_ISO_IN, K_FOREVER);
100+
LL_ASSERT_ERR(buf);
98101

99-
if (buf) {
100-
/* Increase reserved space for headers */
101-
net_buf_reset(buf);
102-
net_buf_reserve(buf, BT_BUF_RESERVE + SDU_HCI_HDR_SIZE);
103-
104-
sdu_buffer->dbuf = buf;
105-
sdu_buffer->size = net_buf_tailroom(buf);
106-
} else {
107-
LL_ASSERT(0);
108-
}
102+
/* Increase reserved space for headers */
103+
net_buf_reset(buf);
104+
net_buf_reserve(buf, BT_BUF_RESERVE + SDU_HCI_HDR_SIZE);
105+
106+
sdu_buffer->dbuf = buf;
107+
sdu_buffer->size = net_buf_tailroom(buf);
109108

110109
return ISOAL_STATUS_OK;
111110
}
@@ -212,11 +211,13 @@ isoal_status_t sink_sdu_write_hci(void *dbuf,
212211
const uint8_t *pdu_payload,
213212
const size_t consume_len)
214213
{
214+
struct net_buf *buf;
215+
215216
ARG_UNUSED(sdu_written);
216217

217-
struct net_buf *buf = (struct net_buf *) dbuf;
218+
buf = (struct net_buf *) dbuf;
219+
LL_ASSERT_ERR(buf);
218220

219-
LL_ASSERT(buf);
220221
net_buf_add_mem(buf, pdu_payload, consume_len);
221222

222223
return ISOAL_STATUS_OK;
@@ -364,7 +365,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
364365
LOG_DBG("Num Complete: 0x%04x:%u", handle, num_cmplt);
365366

366367
err = bt_recv_prio(dev, buf);
367-
LL_ASSERT(err == 0);
368+
LL_ASSERT_DBG(err == 0);
368369

369370
k_yield();
370371
#endif /* CONFIG_BT_CONN || CONFIG_BT_CTLR_ADV_ISO */
@@ -392,7 +393,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
392393
}
393394

394395
err = bt_recv_prio(dev, buf);
395-
LL_ASSERT(err == 0);
396+
LL_ASSERT_DBG(err == 0);
396397

397398
/* bt_recv_prio would not release normal evt
398399
* buf.
@@ -470,7 +471,7 @@ static void node_rx_recv(const struct device *dev)
470471
#if defined(CONFIG_BT_CONN) || defined(CONFIG_BT_CTLR_ADV_ISO)
471472
struct net_buf *buf;
472473

473-
LL_ASSERT(node_rx == NULL);
474+
LL_ASSERT_DBG(node_rx == NULL);
474475

475476
buf = bt_buf_get_evt(BT_HCI_EVT_NUM_COMPLETED_PACKETS,
476477
false, K_FOREVER);
@@ -482,7 +483,7 @@ static void node_rx_recv(const struct device *dev)
482483
k_yield();
483484

484485
#else /* !CONFIG_BT_CONN && !CONFIG_BT_CTLR_ADV_ISO */
485-
LL_ASSERT(0);
486+
LL_ASSERT_DBG(0);
486487
#endif /* !CONFIG_BT_CONN && !CONFIG_BT_CTLR_ADV_ISO */
487488

488489
num_cmplt = ll_rx_get((void *)&node_rx, &handle);
@@ -588,7 +589,7 @@ static inline struct net_buf *encode_node(struct node_rx_pdu *node_rx,
588589
isoal_rx_pdu_recombine(dp->sink_hdl, &pckt_meta);
589590

590591
/* TODO handle err */
591-
LL_ASSERT(err == ISOAL_STATUS_OK);
592+
LL_ASSERT_ERR(err == ISOAL_STATUS_OK);
592593
}
593594
}
594595
#endif /* CONFIG_BT_CTLR_CONN_ISO */
@@ -612,13 +613,13 @@ static inline struct net_buf *encode_node(struct node_rx_pdu *node_rx,
612613
isoal_rx.pdu = (void *)node_rx->pdu;
613614
err = isoal_rx_pdu_recombine(stream->dp->sink_hdl, &isoal_rx);
614615

615-
LL_ASSERT(err == ISOAL_STATUS_OK ||
616-
err == ISOAL_STATUS_ERR_SDU_ALLOC);
616+
LL_ASSERT_ERR(err == ISOAL_STATUS_OK ||
617+
err == ISOAL_STATUS_ERR_SDU_ALLOC);
617618
}
618619
#endif /* CONFIG_BT_CTLR_SYNC_ISO */
619620

620621
} else {
621-
LL_ASSERT(0);
622+
LL_ASSERT_DBG(0);
622623
}
623624

624625
node_rx->hdr.next = NULL;
@@ -629,7 +630,7 @@ static inline struct net_buf *encode_node(struct node_rx_pdu *node_rx,
629630
#endif /* CONFIG_BT_CTLR_SYNC_ISO || CONFIG_BT_CTLR_CONN_ISO */
630631

631632
default:
632-
LL_ASSERT(0);
633+
LL_ASSERT_DBG(0);
633634
break;
634635
}
635636

@@ -667,7 +668,7 @@ static inline struct net_buf *process_node(struct node_rx_pdu *node_rx)
667668
}
668669
break;
669670
default:
670-
LL_ASSERT(0);
671+
LL_ASSERT_DBG(0);
671672
break;
672673
}
673674
}
@@ -740,7 +741,7 @@ static inline struct net_buf *process_hbuf(struct node_rx_pdu *n)
740741
case HCI_CLASS_EVT_DISCARDABLE:
741742
case HCI_CLASS_EVT_REQUIRED:
742743
default:
743-
LL_ASSERT(0);
744+
LL_ASSERT_DBG(0);
744745
break;
745746
}
746747

@@ -822,7 +823,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
822823
int err;
823824

824825
err = k_poll(events, ARRAY_SIZE(events), K_FOREVER);
825-
LL_ASSERT(err == 0 || err == -EINTR);
826+
LL_ASSERT_ERR(err == 0 || err == -EINTR);
826827

827828
if (false) {
828829

@@ -834,7 +835,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
834835
#if !defined(CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE)
835836
} else if (events[EVENT_SEM].state == K_POLL_STATE_SEM_AVAILABLE) {
836837
err = k_sem_take(events[EVENT_SEM].sem, K_NO_WAIT);
837-
LL_ASSERT(err == 0);
838+
LL_ASSERT_DBG(err == 0);
838839

839840
node_rx_recv(dev);
840841
#endif /* !CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE */
@@ -1046,7 +1047,7 @@ static int hci_driver_close(const struct device *dev)
10461047

10471048
/* Resetting the LL stops all roles */
10481049
err = ll_deinit();
1049-
LL_ASSERT(!err);
1050+
LL_ASSERT_DBG(!err);
10501051

10511052
#if defined(CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE)
10521053
/* Abort prio RX thread */

0 commit comments

Comments
 (0)