You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@mynewt.apache.org by "sjanc (via GitHub)" <gi...@apache.org> on 2026/10/27 21:10:30 UTC
Re: [PR] nimble/ll: Fix BIGInfo report parsing [mynewt-nimble]
sjanc commented on code in PR #2219:
URL: https://github.com/apache/mynewt-nimble/pull/2219#discussion_r4394191666
##########
nimble/controller/src/ble_ll_sync.c:
##########
@@ -673,64 +678,122 @@ ble_ll_sync_send_truncated_per_adv_rpt(struct ble_ll_sync_sm *sm, uint8_t *evbuf
}
#if MYNEWT_VAL(BLE_LL_PERIODIC_ADV_SYNC_BIGINFO_REPORTS)
-static void
+static uint8_t
+ble_ll_sync_biginfo_phy_get(const uint8_t *biginfo)
+{
+ switch (biginfo[27] >> 5) {
+ case 0:
+ return BLE_PHY_1M;
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_2M_PHY)
+ case 1:
+ return BLE_PHY_2M;
+#endif
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY)
+ case 2:
+ return BLE_PHY_CODED;
+#endif
+ default:
+ return 0x00;
+ }
+}
+
+static bool
ble_ll_sync_parse_biginfo_to_ev(struct ble_hci_ev_le_subev_biginfo_adv_report *ev,
const uint8_t *biginfo, uint8_t biginfo_len)
{
uint32_t fields_buf;
+ uint32_t sdu_interval;
+ uint16_t iso_interval;
+ uint16_t max_sdu;
+ uint8_t max_pdu;
+ uint8_t framing_mode;
+ uint8_t framed;
fields_buf = get_le32(&biginfo[0]);
- ev->iso_interval = (fields_buf >> 15) & 0x0FFF;
+ iso_interval = (fields_buf >> 15) & 0x0FFF;
ev->bis_cnt = (fields_buf >> 27) & 0x1F;
+ if (iso_interval < BLE_LL_SYNC_BIGINFO_ISO_ITVL_MIN ||
+ iso_interval > BLE_LL_SYNC_BIGINFO_ISO_ITVL_MAX || ev->bis_cnt == 0) {
+ return false;
+ }
+ ev->iso_interval = htole16(iso_interval);
fields_buf = get_le32(&biginfo[4]);
ev->nse = fields_buf & 0x1F;
ev->bn = (fields_buf >> 5) & 0x07;
ev->pto = (fields_buf >> 28) & 0x0F;
+ if (ev->nse == 0 || ev->bn == 0) {
+ return false;
+ }
fields_buf = get_le32(&biginfo[8]);
ev->irc = (fields_buf >> 20) & 0x0F;
- ev->max_pdu = (fields_buf >> 24) & 0xFF;
+ max_pdu = (fields_buf >> 24) & 0xFF;
+ if (ev->irc == 0 || max_pdu == 0 || max_pdu > BLE_LL_SYNC_BIGINFO_MAX_PDU_MAX) {
+ return false;
+ }
+ ev->max_pdu = htole16(max_pdu);
fields_buf = get_le32(&biginfo[17]);
- ev->sdu_interval[0] = fields_buf & 0xFF;
- ev->sdu_interval[1] = (fields_buf >> 8) & 0xFF;
- ev->sdu_interval[2] = (fields_buf >> 16) & 0x0F;
- ev->max_sdu = (fields_buf >> 20) & 0x0FFF;
-
- ev->phy = (biginfo[27] >> 5) & 0x07;
-
- ev->framing = (biginfo[32] >> 7) & 0x01;
+ sdu_interval = fields_buf & 0x0FFFFF;
+ max_sdu = (fields_buf >> 20) & 0x0FFF;
+ if (sdu_interval < BLE_LL_SYNC_BIGINFO_SDU_ITVL_MIN || max_sdu == 0) {
+ return false;
+ }
+ put_le24(ev->sdu_interval, sdu_interval);
+ ev->max_sdu = htole16(max_sdu);
+
+ ev->phy = ble_ll_sync_biginfo_phy_get(biginfo);
+ if (ev->phy == 0) {
+ /* Core 6.0 | Vol 6, Part B, 4.4.5.2
+ * If the PHY field of the BIGInfo specifies a PHY that the Link Layer does not support or is
+ * reserved for future use, the Link Layer shall ignore the BIGInfo, shall not report the
+ * BIGInfo to the Host, and shall not enter the Synchronization state for the BIG specified
+ * in the BIGinfo.
+ */
+ return false;
+ }
- if (biginfo_len == BLE_LL_SYNC_BIGINFO_LEN_ENC) {
- ev->encryption = 1;
+ framing_mode = biginfo[12] >> 7;
+ framed = biginfo[32] >> 7;
+ if (!framed) {
+ ev->framing = BLE_HCI_ISO_FRAMING_UNFRAMED;
+ } else if (framing_mode) {
+ ev->framing = BLE_HCI_ISO_FRAMING_FRAMED_UNSEGMENTED;
} else {
- ev->encryption = 0;
+ ev->framing = BLE_HCI_ISO_FRAMING_FRAMED_SEGMENTABLE;
}
+
+ ev->encryption = biginfo_len == BLE_LL_SYNC_BIGINFO_LEN_ENC;
+
+ return true;
}
static void
ble_ll_sync_send_biginfo_adv_rpt(struct ble_ll_sync_sm *sm, const uint8_t *biginfo, uint8_t biginfo_len)
{
- struct ble_hci_ev_le_subev_biginfo_adv_report *ev;
+ struct ble_hci_ev_le_subev_biginfo_adv_report ev = { 0 };
Review Comment:
I'm not sure I like this extra copying, why not just free allocated buffer (ble_transport_free) on parsing error?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org