Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Enable RPA for ESP32 NimBLE (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravibhagavandas authored Jun 30, 2020
1 parent 814b5b1 commit 44f2f1c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CONFIG_BLUEDROID_ENABLED=
CONFIG_NIMBLE_ENABLED=y
CONFIG_NIMBLE_MAX_CONNECTIONS=1
CONFIG_NIMBLE_MAX_BONDS=3
CONFIG_NIMBLE_MAX_CCCDS=10
CONFIG_NIMBLE_MAX_CCCDS=30
CONFIG_NIMBLE_L2CAP_COC_MAX_NUM=0
CONFIG_NIMBLE_PINNED_TO_CORE=0
CONFIG_NIMBLE_ROLE_CENTRAL=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CONFIG_BLUEDROID_ENABLED=
CONFIG_NIMBLE_ENABLED=y
CONFIG_NIMBLE_MAX_CONNECTIONS=1
CONFIG_NIMBLE_MAX_BONDS=3
CONFIG_NIMBLE_MAX_CCCDS=10
CONFIG_NIMBLE_MAX_CCCDS=30
CONFIG_NIMBLE_L2CAP_COC_MAX_NUM=0
CONFIG_NIMBLE_PINNED_TO_CORE=0
CONFIG_NIMBLE_ROLE_CENTRAL=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "nimble/nimble_port.h"
#include "nimble/nimble_port_freertos.h"
#include "host/util/util.h"
#include "host/ble_hs_pvcy.h"
#include "services/gap/ble_svc_gap.h"

#include "esp_log.h"
Expand Down Expand Up @@ -523,6 +524,19 @@ static void bleprph_on_sync( void )
xStatus = eBTStatusFail;
}

/**
* Configure Resolvable Private Address (RPA).
*/
if( xStatus == eBTStatusSuccess )
{
rc = ble_hs_pvcy_rpa_config( 1 );
if( rc != 0 )
{
ESP_LOGE( TAG, "Failed to enable RPA config, reason = %d\n", rc );
xStatus = eBTStatusFail;
}
}

/** If status is ok and callback is set, trigger the callback.
* If status is fail, no need to trig a callback as original call failed.
**/
Expand Down
24 changes: 14 additions & 10 deletions vendors/espressif/boards/esp32/ports/ble/nimble/iot_ble_hal_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ BTStatus_t prvToggleSecureConnectionOnlyMode( bool bEnable )
return xStatus;
}

void prvEnableRPA( void )
{
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ID | BLE_SM_PAIR_KEY_DIST_ENC;
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ID | BLE_SM_PAIR_KEY_DIST_ENC;
}


BTStatus_t prvBTBleAdapterInit( const BTBleAdapterCallbacks_t * pxCallbacks )
{
BTStatus_t xStatus = eBTStatusSuccess;
Expand Down Expand Up @@ -279,6 +286,11 @@ BTStatus_t prvBTBleAdapterInit( const BTBleAdapterCallbacks_t * pxCallbacks )
xStatus = prvToggleSecureConnectionOnlyMode( xProperties.bSecureConnectionOnly );
}

if( xStatus == eBTStatusSuccess )
{
prvEnableRPA();
}

if( pxCallbacks != NULL )
{
xBTBleAdapterCallbacks = *pxCallbacks;
Expand Down Expand Up @@ -415,17 +427,9 @@ BTStatus_t prvBTStartAdv( uint8_t ucAdapterIf )
{
int xESPStatus;
BTStatus_t xStatus = eBTStatusSuccess;
uint8_t own_addr_type;

/* Figure out address to use while advertising */
xESPStatus = ble_hs_id_infer_auto( xPrivacy, &own_addr_type );

if( xESPStatus != 0 )
{
xStatus = eBTStatusFail;
}

xESPStatus = ble_gap_adv_start( own_addr_type, NULL, lAdvDurationMS,
/* Set address type to always random as RPA is enabled. */
xESPStatus = ble_gap_adv_start( BLE_OWN_ADDR_RANDOM, NULL, lAdvDurationMS,
&xAdv_params, prvGAPeventHandler, NULL );

if( xESPStatus != 0 )
Expand Down

0 comments on commit 44f2f1c

Please sign in to comment.