Skip to content

Commit ee413a2

Browse files
committed
Bluetooth: Increase size of max advertising received (now ~120b on high MTU builds)
nRF52840: Fix crash if receiving >32b of advertisement data
1 parent c3b26eb commit ee413a2

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

libs/bluetooth/bluetooth.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ extern volatile uint16_t m_central_conn_handles[CENTRAL_
245245
typedef struct {
246246
ble_gap_addr_t peer_addr;
247247
int8_t rssi; /**< Received Signal Strength Indication in dBm of the last packet received. */
248-
uint8_t dlen; /**< Advertising or scan response data length. */
249-
uint8_t data[BLE_GAP_ADV_MAX_SIZE]; /**< Advertising or scan response data. */
248+
uint8_t dlen; /**< Advertising or scan response data length. */
249+
uint8_t data[IOEVENT_MAX_LEN-10]; /**< Advertising or scan response data - ensure we can *just* fit it in our BLE buffer */
250250
} BLEAdvReportData;
251251

252252
/** Initialise the BLE stack */

libs/bluetooth/bluetooth_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ bool jsble_exec_pending_common(BLEPending blep, uint16_t data, unsigned char *bu
413413
}
414414
case BLEP_ADV_REPORT: {
415415
BLEAdvReportData *p_adv = (BLEAdvReportData *)buffer;
416-
size_t len = sizeof(BLEAdvReportData) + p_adv->dlen - BLE_GAP_ADV_MAX_SIZE;
416+
size_t len = sizeof(BLEAdvReportData) + p_adv->dlen - sizeof(adv.data);
417417
if (bufferLen != len) {
418418
#ifndef RELEASE
419419
jsiConsolePrintf("BLEP_ADV %d %d %d\n", bufferLen,len,p_adv->dlen);

targets/esp32/BLE/esp32_gap_func.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
126126
espbtaddr_TO_bleaddr(param->scan_rst.bda, param->scan_rst.ble_addr_type, &adv.peer_addr);
127127
adv.rssi = param->scan_rst.rssi;
128128
adv.dlen = param->scan_rst.adv_data_len;
129-
if (adv.dlen > BLE_GAP_ADV_MAX_SIZE) adv.dlen = BLE_GAP_ADV_MAX_SIZE;
129+
if (adv.dlen > sizeof(adv.data)) adv.dlen = sizeof(adv.data);
130130
memcpy(adv.data, param->scan_rst.ble_adv, adv.dlen);
131-
size_t len = sizeof(BLEAdvReportData) + adv.dlen - BLE_GAP_ADV_MAX_SIZE;
131+
size_t len = sizeof(BLEAdvReportData) + adv.dlen - sizeof(adv.data);
132132
jsble_queue_pending_buf(BLEP_ADV_REPORT, 0, (char*)&adv, len);
133133
break;
134134
}

targets/nrf5x/bluetooth.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,10 +1559,11 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context) {
15591559
adv.dlen = p_adv->dlen;
15601560
memcpy(adv.data, p_adv->data, adv.dlen);
15611561
#else
1562-
adv.dlen = p_adv->data.len;
1562+
adv.dlen = (p_adv->data.len > sizeof(adv.data)) ? sizeof(adv.data) : p_adv->data.len;
15631563
memcpy(adv.data, p_adv->data.p_data, adv.dlen);
15641564
#endif
1565-
size_t len = sizeof(BLEAdvReportData) + adv.dlen - BLE_GAP_ADV_MAX_SIZE/*BLEAdvReportData contans uint8_t[BLE_GAP_ADV_MAX_SIZE]*/;
1565+
// FIXME: We might be getting *more* advertising data than we can push to our event queue, because we're limited by IOEVENT_MAX_LEN - I guess we could add >1 packet and decode it?
1566+
size_t len = sizeof(BLEAdvReportData) + adv.dlen - sizeof(adv.data)/* We don't want to add all of BLEAdvReportData if there isn't that much data */;
15661567
jsble_queue_pending_buf(BLEP_ADV_REPORT, 0, (char*)&adv, len);
15671568
#if NRF_SD_BLE_API_VERSION>5
15681569
// On new APIs we need to continue scanning

0 commit comments

Comments
 (0)