From 3a969c6748340ecbdb15216183a2baeca34c2073 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Tue, 31 Jan 2017 13:08:09 +0100 Subject: [PATCH] introduce API update to (v3.x.x and further)in BLE_GAP_EVT_CONNECTED service. whitelist and identiti list settings provider now takes into account scaner filter po0licy and advertise r filter policy --- .../TARGET_NRF5_SDK13/source/btle/btle.cpp | 27 +++++--- .../TARGET_NRF5_SDK13/source/nRF5xGap.cpp | 68 +++++++++++-------- .../TARGET_NRF5_SDK13/source/nRF5xGap.h | 13 +++- .../source/nRF5xSecurityManager.h | 2 + .../porting_tools/replace_headers.py | 6 +- 5 files changed, 73 insertions(+), 43 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/btle/btle.cpp index f05aa03c80..83004f1251 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/btle/btle.cpp @@ -224,18 +224,27 @@ static void btle_handler(ble_evt_t *p_ble_evt) #endif gap.setConnectionHandle(handle); const Gap::ConnectionParams_t *params = reinterpret_cast(&(p_ble_evt->evt.gap_evt.params.connected.conn_params)); -#if (NRF_SD_BLE_API_VERSION <= 2) + const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr; +#if (NRF_SD_BLE_API_VERSION <= 2) const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr; -#else - const ble_gap_addr_t *peer = NULL; // @todo real implemantation pm_device_identities_list_set/get - const ble_gap_addr_t *own = NULL; -#endif + gap.processConnectionEvent(handle, - role, - static_cast(peer->addr_type), peer->addr, - static_cast(own->addr_type), own->addr, - params); + role, + static_cast(peer->addr_type), peer->addr, + static_cast(own->addr_type), own->addr, + params); +#else + Gap::AddressType_t addr_type; + Gap::Address_t own_address; + gap.getAddress(&addr_type, own_address); + + gap.processConnectionEvent(handle, + role, + static_cast(peer->addr_type), peer->addr, + addr_type, own_address, + params); +#endif break; } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.cpp index e5f23f62b4..36cfea8dc7 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.cpp @@ -174,6 +174,9 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms) return BLE_ERROR_PARAM_OUT_OF_RANGE; } uint32_t err; + + ble_gap_adv_params_t adv_para = {0}; + #if (NRF_SD_BLE_API_VERSION <= 2) /* Allocate the stack's whitelist statically */ ble_gap_whitelist_t whitelist; @@ -192,22 +195,21 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms) return error; } } + + adv_para.p_whitelist = &whitelist; #else - err = updateWhiteAndIdentityListInStack(); + err = updateWhiteAndIdentityListInStack(nRF5xGap::avdvertising_purpose); if (err != BLE_ERROR_NONE) { return (ble_error_t)err; } #endif /* Start Advertising */ - ble_gap_adv_params_t adv_para = {0}; + adv_para.type = params.getAdvertisingType(); adv_para.p_peer_addr = NULL; // Undirected advertisement adv_para.fp = advertisingPolicyMode; -#if (NRF_SD_BLE_API_VERSION <= 2) - adv_para.p_whitelist = &whitelist; -#endif adv_para.interval = params.getIntervalInADVUnits(); // advertising interval (in units of 0.625 ms) adv_para.timeout = params.getTimeout(); @@ -227,6 +229,9 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms) #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams) { + + ble_gap_scan_params_t scanParams; + #if (NRF_SD_BLE_API_VERSION <= 2) /* Allocate the stack's whitelist statically */ ble_gap_whitelist_t whitelist; @@ -245,26 +250,22 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams) return error; } } + + scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */ + scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */ #else - uint32_t err = updateWhiteAndIdentityListInStack(); + uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::scan_connect_purpose); if (err != BLE_ERROR_NONE) { return (ble_error_t)err; } -#endif - ble_gap_scan_params_t scanParams; - - scanParams.active = scanningParams.getActiveScanning(); /**< If 1, perform active scanning (scan requests). */ -#if (NRF_SD_BLE_API_VERSION <= 2) - scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */ - scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */ -#else scanParams.use_whitelist = scanningPolicyMode; scanParams.adv_dir_report = 0; - - #endif + + scanParams.active = scanningParams.getActiveScanning(); /**< If 1, perform active scanning (scan requests). */ + scanParams.interval = scanningParams.getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */ scanParams.window = scanningParams.getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */ scanParams.timeout = scanningParams.getTimeout(); /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */ @@ -333,6 +334,8 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr, connParams.conn_sup_timeout = 600; } + ble_gap_scan_params_t scanParams; + #if (NRF_SD_BLE_API_VERSION <= 2) /* Allocate the stack's whitelist statically */ ble_gap_whitelist_t whitelist; @@ -351,23 +354,17 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr, return error; } } + + scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */ + scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */ #else - uint32_t err = updateWhiteAndIdentityListInStack(); + uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::scan_connect_purpose); if (err != BLE_ERROR_NONE) { return (ble_error_t)err; } #endif - ble_gap_scan_params_t scanParams; -#if (NRF_SD_BLE_API_VERSION <= 2) - scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */ - scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */ -#else - scanParams.use_whitelist = scanningPolicyMode; - scanParams.adv_dir_report = 0; -#endif - if (scanParamsIn != NULL) { scanParams.active = scanParamsIn->getActiveScanning(); /**< If 1, perform active scanning (scan requests). */ scanParams.interval = scanParamsIn->getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */ @@ -1020,9 +1017,12 @@ ble_error_t nRF5xGap::generateStackWhitelist(ble_gap_whitelist_t &whitelist) #if (NRF_SD_BLE_API_VERSION >= 3) /** - * Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy). + * Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy) for SoftDevice. * - * Created setting are intended to be used to configure SoftDevices. + * Gap::setWhitelist provide base for prepartion of this settings. + * This funtion matches resolvabele addreses (pased by Gap::setWhitelist) to IRK datas in boonds table. + * Therefore resovable addresses instead of being passed to the whitelist (intended to be passed to Softdevice) + * are passed to the identities list (intended to be passed to Softdevice). * * @param[out] gapAdrHelper Reference to the struct for storing settings. */ @@ -1158,13 +1158,21 @@ ble_error_t nRF5xGap::apllyWhiteIdentityList(GapWhiteAndIdentityList_t &gapAdrHe } } -ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack(void) +ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack(whiteAndIdentityListPurpose_t purpose) { GapWhiteAndIdentityList_t whiteAndIdentityList; uint32_t err; + bool provide_settings; + + if (purpose == nRF5xGap::avdvertising_purpose) { + provide_settings = (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) ? true : false; + } else { //it must be nRF5xGap::scan_connect_purpose + provide_settings = (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) ? true : false; + } + /* Add missing IRKs to nRF5xGap's whitelist from the bond table held by the Peer Manager */ - if (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) { + if (provide_settings) { err = getStackWhiteIdentityList(whiteAndIdentityList); if (err != BLE_ERROR_NONE) { diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.h index fc91068828..b4f465a12d 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.h @@ -150,6 +150,7 @@ private: #endif #if (NRF_SD_BLE_API_VERSION >= 3) + /* internal type for pasing whitelist and identities list */ typedef struct { ble_gap_addr_t addr[YOTTA_CFG_WHITELIST_MAX_SIZE]; @@ -161,9 +162,19 @@ private: uint32_t identities_cnt; } GapWhiteAndIdentityList_t; + /* purpouse of updation the whitelist and identities settings */ + enum whiteAndIdentityListPurpose_t + { + scan_connect_purpose = 0, + avdvertising_purpose + } whiteAndIdentityListPurpose; + + /* Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy).*/ ble_error_t getStackWhiteIdentityList(GapWhiteAndIdentityList_t &whiteAndIdentityList); + /* Fuction for apllying setting of the whitelist-feature and identiti-reseolv-feature (privacy).*/ ble_error_t apllyWhiteIdentityList(GapWhiteAndIdentityList_t &whiteAndIdentityList); - ble_error_t updateWhiteAndIdentityListInStack(void); + /* Fuction which incorportes 2 above f. together */ + ble_error_t updateWhiteAndIdentityListInStack(whiteAndIdentityListPurpose_t purpose); #endif private: diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xSecurityManager.h index 4d1bc51d78..1b675806d9 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xSecurityManager.h @@ -57,6 +57,8 @@ public: * * @return * BLE_ERROR_NONE if successful. + * + * @todo check whether remove this function (because it is never called) */ virtual ble_error_t getAddressesFromBondTable(Gap::Whitelist_t &addresses) const { uint8_t i; diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/porting_tools/replace_headers.py b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/porting_tools/replace_headers.py index 6e13fd632d..1c985f6335 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/porting_tools/replace_headers.py +++ b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/porting_tools/replace_headers.py @@ -40,9 +40,9 @@ def replace_header(in_path): print fn -pathes = ["C:/mbed/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk", - "C:/mbed/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52832\sdk", - "C:/mbed/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840\sdk"] +pathes = ["..\\sdk", + "..\\TARGET_MCU_NRF52832\\sdk", + "..\\TARGET_MCU_NRF52840\\sdk"] for path in pathes: replace_header(path)