Skip to content

Commit a5444f0

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 0c84cc5 commit a5444f0

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

+1025
-1003
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
@@ -3222,7 +3222,7 @@ static void le_df_connection_iq_report(struct node_rx_pdu *node_rx, struct net_b
32223222
phy_rx = lll->phy_rx;
32233223

32243224
/* Make sure the report is generated for connection on PHY UNCODED */
3225-
LL_ASSERT(phy_rx != PHY_CODED);
3225+
LL_ASSERT_DBG(phy_rx != PHY_CODED);
32263226
#else
32273227
phy_rx = PHY_1M;
32283228
#endif /* CONFIG_BT_CTLR_PHY */
@@ -4412,7 +4412,7 @@ static void le_cis_request(struct pdu_data *pdu_data,
44124412
* event.
44134413
*/
44144414
node = pdu_data;
4415-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
4415+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
44164416

44174417
req = node;
44184418
if (!(ll_feat_get() & BIT64(BT_LE_FEAT_BIT_ISO_CHANNELS)) ||
@@ -4459,7 +4459,7 @@ static void le_cis_established(struct pdu_data *pdu_data,
44594459
* event.
44604460
*/
44614461
node = pdu_data;
4462-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
4462+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_estab));
44634463

44644464
est = node;
44654465
sep->status = est->status;
@@ -4518,7 +4518,7 @@ static void le_per_adv_sync_transfer_received(struct pdu_data *pdu_data_rx,
45184518
* event.
45194519
*/
45204520
node = pdu_data_rx;
4521-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_past_received));
4521+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_past_received));
45224522

45234523
se = node;
45244524
sep->status = se->rx_sync.status;
@@ -5520,7 +5520,7 @@ static void vs_le_df_connection_iq_report(struct node_rx_pdu *node_rx, struct ne
55205520
phy_rx = lll->phy_rx;
55215521

55225522
/* Make sure the report is generated for connection on PHY UNCODED */
5523-
LL_ASSERT(phy_rx != PHY_CODED);
5523+
LL_ASSERT_DBG(phy_rx != PHY_CODED);
55245524
#else
55255525
phy_rx = PHY_1M;
55265526
#endif /* CONFIG_BT_CTLR_PHY */
@@ -6300,7 +6300,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
63006300

63016301
/* Start Fragmentation */
63026302
/* FIXME: need to ensure ISO-AL returns proper isoal_status.
6303-
* Currently there are cases where ISO-AL calls LL_ASSERT.
6303+
* Currently there are cases where ISO-AL calls LL_ASSERT_ERR.
63046304
*/
63056305
isoal_status_t isoal_status =
63066306
isoal_tx_sdu_fragment(stream->dp->source_hdl, &sdu_frag_tx);
@@ -6554,7 +6554,7 @@ static inline void le_dir_adv_report(struct pdu_adv *adv, struct net_buf *buf,
65546554
return;
65556555
}
65566556

6557-
LL_ASSERT(adv->type == PDU_ADV_TYPE_DIRECT_IND);
6557+
LL_ASSERT_DBG(adv->type == PDU_ADV_TYPE_DIRECT_IND);
65586558

65596559
#if CONFIG_BT_CTLR_DUP_FILTER_LEN > 0
65606560
if (dup_scan &&
@@ -6624,7 +6624,7 @@ static inline void le_mesh_scan_report(struct pdu_adv *adv,
66246624
uint32_t instant;
66256625
uint8_t chan;
66266626

6627-
LL_ASSERT(adv->type == PDU_ADV_TYPE_NONCONN_IND);
6627+
LL_ASSERT_DBG(adv->type == PDU_ADV_TYPE_NONCONN_IND);
66286628

66296629
/* Filter based on currently active Scan Filter */
66306630
if (sf_curr < ARRAY_SIZE(scan_filters) &&
@@ -7093,7 +7093,7 @@ static void ext_adv_pdu_frag(uint8_t evt_type, uint8_t phy, uint8_t sec_phy,
70937093
*data_len_total -= data_len_frag;
70947094

70957095
*evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
7096-
LL_ASSERT(*evt_buf);
7096+
LL_ASSERT_ERR(*evt_buf);
70977097

70987098
net_buf_frag_add(buf, *evt_buf);
70997099

@@ -7630,7 +7630,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
76307630
* event.
76317631
*/
76327632
evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
7633-
LL_ASSERT(evt_buf);
7633+
LL_ASSERT_ERR(evt_buf);
76347634

76357635
net_buf_frag_add(buf, evt_buf);
76367636

@@ -7726,7 +7726,7 @@ static void le_per_adv_sync_established(struct pdu_data *pdu_data,
77267726
* event.
77277727
*/
77287728
node = pdu_data;
7729-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_sync));
7729+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_sync));
77307730

77317731
se = node;
77327732
sep->status = se->status;
@@ -8006,7 +8006,7 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
80068006
data_status = BT_HCI_LE_ADV_EVT_TYPE_DATA_STATUS_PARTIAL;
80078007

80088008
evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
8009-
LL_ASSERT(evt_buf);
8009+
LL_ASSERT_ERR(evt_buf);
80108010

80118011
net_buf_frag_add(buf, evt_buf);
80128012

@@ -8062,7 +8062,7 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
80628062
*/
80638063
if (!evt_buf) {
80648064
evt_buf = bt_buf_get_rx(BT_BUF_EVT, BUF_GET_TIMEOUT);
8065-
LL_ASSERT(evt_buf);
8065+
LL_ASSERT_ERR(evt_buf);
80668066

80678067
net_buf_frag_add(buf, evt_buf);
80688068
}
@@ -8147,7 +8147,7 @@ static void le_big_sync_established(struct pdu_data *pdu,
81478147
* established event.
81488148
*/
81498149
node = pdu;
8150-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_sync_iso));
8150+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_sync_iso));
81518151

81528152
se = node;
81538153
sep->status = se->status;
@@ -8451,7 +8451,7 @@ static void le_conn_complete(struct pdu_data *pdu_data, uint16_t handle,
84518451
* complete event.
84528452
*/
84538453
node = pdu_data;
8454-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_cc));
8454+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_cc));
84558455

84568456
cc = node;
84578457
status = cc->status;
@@ -8588,7 +8588,7 @@ static void le_conn_update_complete(struct pdu_data *pdu_data, uint16_t handle,
85888588
* update complete event.
85898589
*/
85908590
node = pdu_data;
8591-
LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_cu));
8591+
LL_ASSERT_DBG(IS_PTR_ALIGNED(node, struct node_rx_cu));
85928592

85938593
cu = node;
85948594
sep->status = cu->status;
@@ -8845,7 +8845,7 @@ static void encode_control(struct node_rx_pdu *node_rx,
88458845
#elif defined(CONFIG_BT_CTLR_VS_SCAN_REQ_RX)
88468846
le_vs_scan_req_received(pdu_data, node_rx, buf);
88478847
#else
8848-
LL_ASSERT(0);
8848+
LL_ASSERT_DBG(0);
88498849
#endif /* CONFIG_BT_CTLR_ADV_EXT */
88508850
break;
88518851
#endif /* CONFIG_BT_CTLR_SCAN_REQ_NOTIFY */
@@ -8984,7 +8984,7 @@ static void encode_control(struct node_rx_pdu *node_rx,
89848984
#endif /* CONFIG_BT_CTLR_USER_EVT_RANGE > 0 */
89858985

89868986
default:
8987-
LL_ASSERT(0);
8987+
LL_ASSERT_DBG(0);
89888988
return;
89898989
}
89908990
}
@@ -9212,7 +9212,7 @@ static void encode_data_ctrl(struct node_rx_pdu *node_rx,
92129212
break;
92139213

92149214
default:
9215-
LL_ASSERT(0);
9215+
LL_ASSERT_DBG(0);
92169216
return;
92179217
}
92189218
}
@@ -9243,20 +9243,20 @@ void hci_acl_encode(struct node_rx_pdu *node_rx, struct net_buf *buf)
92439243
memcpy(data, pdu_data->lldata, pdu_data->len);
92449244
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
92459245
if (hci_hbuf_total > 0) {
9246-
LL_ASSERT((hci_hbuf_sent - hci_hbuf_acked) <
9246+
LL_ASSERT_DBG((hci_hbuf_sent - hci_hbuf_acked) <
92479247
hci_hbuf_total);
92489248
hci_hbuf_sent++;
92499249
/* Note: This requires linear handle values starting
92509250
* from 0
92519251
*/
9252-
LL_ASSERT(handle < ARRAY_SIZE(hci_hbuf_pend));
9252+
LL_ASSERT_DBG(handle < ARRAY_SIZE(hci_hbuf_pend));
92539253
hci_hbuf_pend[handle]++;
92549254
}
92559255
#endif /* CONFIG_BT_HCI_ACL_FLOW_CONTROL */
92569256
break;
92579257

92589258
default:
9259-
LL_ASSERT(0);
9259+
LL_ASSERT_DBG(0);
92609260
break;
92619261
}
92629262
}

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);
@@ -589,7 +590,7 @@ static inline struct net_buf *encode_node(struct node_rx_pdu *node_rx,
589590
isoal_rx_pdu_recombine(dp->sink_hdl, &pckt_meta);
590591

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

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

621622
} else {
622-
LL_ASSERT(0);
623+
LL_ASSERT_DBG(0);
623624
}
624625

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

632633
default:
633-
LL_ASSERT(0);
634+
LL_ASSERT_DBG(0);
634635
break;
635636
}
636637

@@ -668,7 +669,7 @@ static inline struct net_buf *process_node(struct node_rx_pdu *node_rx)
668669
}
669670
break;
670671
default:
671-
LL_ASSERT(0);
672+
LL_ASSERT_DBG(0);
672673
break;
673674
}
674675
}
@@ -741,7 +742,7 @@ static inline struct net_buf *process_hbuf(struct node_rx_pdu *n)
741742
case HCI_CLASS_EVT_DISCARDABLE:
742743
case HCI_CLASS_EVT_REQUIRED:
743744
default:
744-
LL_ASSERT(0);
745+
LL_ASSERT_DBG(0);
745746
break;
746747
}
747748

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

825826
err = k_poll(events, ARRAY_SIZE(events), K_FOREVER);
826-
LL_ASSERT(err == 0 || err == -EINTR);
827+
LL_ASSERT_ERR(err == 0 || err == -EINTR);
827828

828829
if (false) {
829830

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

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

10481049
/* Resetting the LL stops all roles */
10491050
err = ll_deinit();
1050-
LL_ASSERT(!err);
1051+
LL_ASSERT_DBG(!err);
10511052

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

0 commit comments

Comments
 (0)