Skip to content

Commit

Permalink
bluetooth: Add BLE scan compatible option for legacy device
Browse files Browse the repository at this point in the history
Allow connection to legacy peripheral device that do not support
a Window offset parameter of 0 in the Link Layer CONNECT_IND packet.
  • Loading branch information
SPRESENSE committed Dec 2, 2024
1 parent ab1502b commit e57be0e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sdk/modules/bluetooth/hal/nrf52/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ config NRF52_LESC
This option enables LE secure connection feature of nRF52.
LE secure connection is the safer pairing method,
but nrf52 needs more memory because mbedtls or micro-ecc is required.

config NRF52_SCAN_COMPAT_MODE
bool "Enable scan compatible mode"
default n
---help---
Enable interoperability with devices that do not support a value of
0 for the WinOffset parameter in the Link Layer CONNECT_IND packet.
This applies to a limited set of legacy peripheral devices.

endif # NRF52_LE

endif # BLUETOOTH_NRF52
24 changes: 24 additions & 0 deletions sdk/modules/bluetooth/hal/nrf52/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,21 @@ static int8_t ble_gap_scan_tx_power = 0;
uint8_t bleAdvReportBuffer[BLE_GAP_SCAN_BUFFER_EXTENDED_MIN];
#endif

int BLE_GapSetScanCompatMode(bool enable)
{
int ret = BLE_SUCCESS;
int errCode = 0;
ble_opt_t opt;

memset(&opt, 0x0, sizeof(opt));
opt.gap_opt.compat_mode_1.enable = enable ? 1 : 0;

errCode = sd_ble_opt_set(BLE_GAP_OPT_COMPAT_MODE_1, &opt);
ret = bleConvertErrorCode((uint32_t)errCode);

return ret;
}

int BLE_GapSetScanParam(struct ble_scan_param_s *scanParam)
{
if(scanParam == NULL) {
Expand Down Expand Up @@ -635,6 +650,15 @@ int BLE_GapStartScan(void)
gapMem.scanParams.window = SCAN_WINDOW;
gapMem.scanParams.timeout = SCAN_TIMEOUT;
}

#ifdef CONFIG_NRF52_SCAN_COMPAT_MODE
/* Allow connection to legacy peripheral device that do not support
* a Window offset parameter of 0.
*/

BLE_GapSetScanCompatMode(true);
#endif

#if NRF_SD_BLE_API_VERSION > 5
/* Always use the fixed value. */

Expand Down
18 changes: 18 additions & 0 deletions sdk/modules/bluetooth/hal/nrf52/include/ble/ble_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,24 @@ int BLE_GapExchangePairingFeature(BLE_GapConnHandle connHandle,
BLE_GapPairingFeature *ownFeature,
const BLE_GapPairingFeature *peerFeature);

/**@brief Set scan compatible mode option
* @details Allow connection to legacy peripheral device that do not support
* a Window offset parameter of 0. This enables compatibility mode 1
* option for nrf52 softdevice.
*
* @param[in] enable: enable if true, disable if false (default: disable)
* @return 0: success
*
* @par Blocking
* Yes
* @par Context
* Task
* @par Reentrant
* No
*
*/
int BLE_GapSetScanCompatMode(bool enable);

/**@brief Set scan parameter
* @details This call allows the application to set scan paramter, use the default scan parameter
* (interval:200, window:20, timeout:60) if the call of this API is failed or not call this API.
Expand Down

0 comments on commit e57be0e

Please sign in to comment.