Skip to content

Commit 9d8c05b

Browse files
committed
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
1 parent 1366dfb commit 9d8c05b

File tree

5 files changed

+72
-42
lines changed

5 files changed

+72
-42
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/btle/btle.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,27 @@ static void btle_handler(ble_evt_t *p_ble_evt)
224224
#endif
225225
gap.setConnectionHandle(handle);
226226
const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params));
227-
#if (NRF_SD_BLE_API_VERSION <= 2)
227+
228228
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
229+
#if (NRF_SD_BLE_API_VERSION <= 2)
229230
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
231+
232+
gap.processConnectionEvent(handle,
233+
role,
234+
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
235+
static_cast<BLEProtocol::AddressType_t>(own->addr_type), own->addr,
236+
params);
230237
#else
231-
const ble_gap_addr_t *peer = NULL; // @todo real implemantation pm_device_identities_list_set/get
232-
const ble_gap_addr_t *own = NULL;
233-
#endif
238+
Gap::AddressType_t addr_type;
239+
Gap::Address_t own_address;
240+
gap.getAddress(&addr_type, own_address);
241+
234242
gap.processConnectionEvent(handle,
235-
role,
236-
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
237-
static_cast<BLEProtocol::AddressType_t>(own->addr_type), own->addr,
238-
params);
243+
role,
244+
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
245+
addr_type, own_address,
246+
params);
247+
#endif
239248
break;
240249
}
241250

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.cpp

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
174174
return BLE_ERROR_PARAM_OUT_OF_RANGE;
175175
}
176176
uint32_t err;
177+
178+
ble_gap_adv_params_t adv_para = {0};
179+
177180
#if (NRF_SD_BLE_API_VERSION <= 2)
178181
/* Allocate the stack's whitelist statically */
179182
ble_gap_whitelist_t whitelist;
@@ -192,22 +195,21 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
192195
return error;
193196
}
194197
}
198+
199+
adv_para.p_whitelist = &whitelist;
195200
#else
196-
err = updateWhiteAndIdentityListInStack();
201+
err = updateWhiteAndIdentityListInStack(nRF5xGap::avdvertising_purpose);
197202

198203
if (err != BLE_ERROR_NONE) {
199204
return (ble_error_t)err;
200205
}
201206
#endif
202207
/* Start Advertising */
203-
ble_gap_adv_params_t adv_para = {0};
208+
204209

205210
adv_para.type = params.getAdvertisingType();
206211
adv_para.p_peer_addr = NULL; // Undirected advertisement
207212
adv_para.fp = advertisingPolicyMode;
208-
#if (NRF_SD_BLE_API_VERSION <= 2)
209-
adv_para.p_whitelist = &whitelist;
210-
#endif
211213
adv_para.interval = params.getIntervalInADVUnits(); // advertising interval (in units of 0.625 ms)
212214
adv_para.timeout = params.getTimeout();
213215

@@ -227,6 +229,9 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
227229
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
228230
ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
229231
{
232+
233+
ble_gap_scan_params_t scanParams;
234+
230235
#if (NRF_SD_BLE_API_VERSION <= 2)
231236
/* Allocate the stack's whitelist statically */
232237
ble_gap_whitelist_t whitelist;
@@ -245,26 +250,22 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
245250
return error;
246251
}
247252
}
253+
254+
scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */
255+
scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */
248256
#else
249-
uint32_t err = updateWhiteAndIdentityListInStack();
257+
uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::scan_connect_purpose);
250258

251259
if (err != BLE_ERROR_NONE) {
252260
return (ble_error_t)err;
253261
}
254-
#endif
255-
256-
ble_gap_scan_params_t scanParams;
257262

258-
scanParams.active = scanningParams.getActiveScanning(); /**< If 1, perform active scanning (scan requests). */
259-
#if (NRF_SD_BLE_API_VERSION <= 2)
260-
scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */
261-
scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */
262-
#else
263263
scanParams.use_whitelist = scanningPolicyMode;
264264
scanParams.adv_dir_report = 0;
265-
266-
267265
#endif
266+
267+
scanParams.active = scanningParams.getActiveScanning(); /**< If 1, perform active scanning (scan requests). */
268+
268269
scanParams.interval = scanningParams.getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
269270
scanParams.window = scanningParams.getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
270271
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,
333334
connParams.conn_sup_timeout = 600;
334335
}
335336

337+
ble_gap_scan_params_t scanParams;
338+
336339
#if (NRF_SD_BLE_API_VERSION <= 2)
337340
/* Allocate the stack's whitelist statically */
338341
ble_gap_whitelist_t whitelist;
@@ -351,23 +354,17 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
351354
return error;
352355
}
353356
}
357+
358+
scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */
359+
scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */
354360
#else
355-
uint32_t err = updateWhiteAndIdentityListInStack();
361+
uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::scan_connect_purpose);
356362

357363
if (err != BLE_ERROR_NONE) {
358364
return (ble_error_t)err;
359365
}
360366
#endif
361367

362-
ble_gap_scan_params_t scanParams;
363-
#if (NRF_SD_BLE_API_VERSION <= 2)
364-
scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */
365-
scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */
366-
#else
367-
scanParams.use_whitelist = scanningPolicyMode;
368-
scanParams.adv_dir_report = 0;
369-
#endif
370-
371368
if (scanParamsIn != NULL) {
372369
scanParams.active = scanParamsIn->getActiveScanning(); /**< If 1, perform active scanning (scan requests). */
373370
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)
10201017
#if (NRF_SD_BLE_API_VERSION >= 3)
10211018

10221019
/**
1023-
* Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy).
1020+
* Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy) for SoftDevice.
10241021
*
1025-
* Created setting are intended to be used to configure SoftDevices.
1022+
* Gap::setWhitelist provide base for prepartion of this settings.
1023+
* This funtion matches resolvabele addreses (pased by Gap::setWhitelist) to IRK datas in boonds table.
1024+
* Therefore resovable addresses instead of being passed to the whitelist (intended to be passed to Softdevice)
1025+
* are passed to the identities list (intended to be passed to Softdevice).
10261026
*
10271027
* @param[out] gapAdrHelper Reference to the struct for storing settings.
10281028
*/
@@ -1158,13 +1158,21 @@ ble_error_t nRF5xGap::apllyWhiteIdentityList(GapWhiteAndIdentityList_t &gapAdrHe
11581158
}
11591159
}
11601160

1161-
ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack(void)
1161+
ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack(whiteAndIdentityListPurpose_t purpose)
11621162
{
11631163
GapWhiteAndIdentityList_t whiteAndIdentityList;
11641164
uint32_t err;
1165+
bool provide_settings;
1166+
1167+
if (purpose == nRF5xGap::avdvertising_purpose) {
1168+
provide_settings = (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) ? true : false;
1169+
} else { //it must be nRF5xGap::scan_connect_purpose
1170+
provide_settings = (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) ? true : false;
1171+
}
1172+
11651173

11661174
/* Add missing IRKs to nRF5xGap's whitelist from the bond table held by the Peer Manager */
1167-
if (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) {
1175+
if (provide_settings) {
11681176
err = getStackWhiteIdentityList(whiteAndIdentityList);
11691177

11701178
if (err != BLE_ERROR_NONE) {

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xGap.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class nRF5xGap : public Gap
150150
#endif
151151

152152
#if (NRF_SD_BLE_API_VERSION >= 3)
153+
/* internal type for pasing whitelist and identities list */
153154
typedef struct
154155
{
155156
ble_gap_addr_t addr[YOTTA_CFG_WHITELIST_MAX_SIZE];
@@ -161,9 +162,19 @@ class nRF5xGap : public Gap
161162
uint32_t identities_cnt;
162163
} GapWhiteAndIdentityList_t;
163164

165+
/* purpouse of updation the whitelist and identities settings */
166+
enum whiteAndIdentityListPurpose_t
167+
{
168+
scan_connect_purpose = 0,
169+
avdvertising_purpose
170+
} whiteAndIdentityListPurpose;
171+
172+
/* Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy).*/
164173
ble_error_t getStackWhiteIdentityList(GapWhiteAndIdentityList_t &whiteAndIdentityList);
174+
/* Fuction for apllying setting of the whitelist-feature and identiti-reseolv-feature (privacy).*/
165175
ble_error_t apllyWhiteIdentityList(GapWhiteAndIdentityList_t &whiteAndIdentityList);
166-
ble_error_t updateWhiteAndIdentityListInStack(void);
176+
/* Fuction which incorportes 2 above f. together */
177+
ble_error_t updateWhiteAndIdentityListInStack(whiteAndIdentityListPurpose_t purpose);
167178
#endif
168179

169180
private:

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/source/nRF5xSecurityManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class nRF5xSecurityManager : public SecurityManager
5757
*
5858
* @return
5959
* BLE_ERROR_NONE if successful.
60+
*
61+
* @todo check whether remove this function (because it is never called)
6062
*/
6163
virtual ble_error_t getAddressesFromBondTable(Gap::Whitelist_t &addresses) const {
6264
uint8_t i;

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/porting_tools/replace_headers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def replace_header(in_path):
4040
print fn
4141

4242

43-
pathes = ["C:/mbed/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk",
44-
"C:/mbed/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52832\sdk",
45-
"C:/mbed/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840\sdk"]
43+
pathes = ["..\\sdk",
44+
"..\\TARGET_MCU_NRF52832\\sdk",
45+
"..\\TARGET_MCU_NRF52840\\sdk"]
4646

4747
for path in pathes:
4848
replace_header(path)

0 commit comments

Comments
 (0)