Skip to content

Commit bb1f316

Browse files
nvlsianpuadbridge
authored andcommitted
Changes from CR. - fix typso, renaming, repharse commnets. - fix alghoritm of white/id lists setup functions in nRF5xGap class.
1 parent f7aa6e5 commit bb1f316

File tree

3 files changed

+74
-67
lines changed

3 files changed

+74
-67
lines changed

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

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
198198

199199
adv_para.p_whitelist = &whitelist;
200200
#else
201-
err = updateWhiteAndIdentityListInStack(nRF5xGap::avdvertising_purpose);
201+
err = updateWhiteAndIdentityListInStack(nRF5xGap::purpose_avdvertising);
202202

203203
if (err != BLE_ERROR_NONE) {
204204
return (ble_error_t)err;
@@ -254,7 +254,7 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
254254
scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */
255255
scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */
256256
#else
257-
uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::scan_connect_purpose);
257+
uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::purpose_scan_connect);
258258

259259
if (err != BLE_ERROR_NONE) {
260260
return (ble_error_t)err;
@@ -358,19 +358,20 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
358358
scanParams.selective = scanningPolicyMode; /**< If 1, ignore unknown devices (non whitelisted). */
359359
scanParams.p_whitelist = &whitelist; /**< Pointer to whitelist, NULL if none is given. */
360360
#else
361-
uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::scan_connect_purpose);
361+
uint32_t err = updateWhiteAndIdentityListInStack(nRF5xGap::purpose_scan_connect);
362362

363363
if (err != BLE_ERROR_NONE) {
364364
return (ble_error_t)err;
365365
}
366366

367367
scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0;
368368

369-
if (addr.addr_type == ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE || addr.addr_type == ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) {
369+
if ((addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE)
370+
|| (addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE)) {
370371
/* If a device is using Resolvable Private Addresses Section 1.3.2.2 (Core spec v4.2 volume 6 part B),
371372
it shall also have an Identity Address that is either a Public or Random Static address type.”
372-
For connecting a static address must be provided by the application to the softdevice.
373-
The softdevice will resolve the address and connect to the right device if present. */
373+
To establish a connection, a static address must be provided by the application to the SoftDevice.
374+
The SoftDevice resolves the address and connects to the right device if it is available. */
374375
addr.addr_id_peer = 1;
375376
addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC;
376377
} else {
@@ -1031,35 +1032,27 @@ ble_error_t nRF5xGap::generateStackWhitelist(ble_gap_whitelist_t &whitelist)
10311032
#if (NRF_SD_BLE_API_VERSION >= 3)
10321033

10331034
/**
1034-
* Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy) for SoftDevice.
1035+
* Function for preparing settings of the whitelist feature and the identity-resolving feature (privacy) for the SoftDevice.
10351036
*
1036-
* Gap::setWhitelist provide base for prepartion of this settings.
1037-
* This funtion matches resolvabele addreses (pased by Gap::setWhitelist) to IRK datas in boonds table.
1038-
* Therefore resovable addresses instead of being passed to the whitelist (intended to be passed to Softdevice)
1039-
* are passed to the identities list (intended to be passed to Softdevice).
1037+
* Gap::setWhitelist provides the base for preparation of these settings.
1038+
* This function matches resolvable addresses (passed by Gap::setWhitelist) to IRK data in bonds table.
1039+
* Therefore resolvable addresses instead of being passed to the whitelist (intended to be passed to the Softdevice)
1040+
* are passed to the identities list (intended to be passed to the Softdevice).
10401041
*
10411042
* @param[out] gapAdrHelper Reference to the struct for storing settings.
10421043
*/
10431044

10441045
ble_error_t nRF5xGap::getStackWhiteIdentityList(GapWhiteAndIdentityList_t &gapAdrHelper)
10451046
{
1046-
uint32_t peers_to_check = pm_peer_count();
10471047
pm_peer_id_t peer_id;
10481048

10491049
ret_code_t ret;
10501050

10511051
pm_peer_data_bonding_t bond_data;
1052-
pm_peer_data_t peer_data;
1053-
uint32_t const buf_size = sizeof(bond_data);
10541052

1055-
memset(&peer_data, 0x00, sizeof(peer_data));
1056-
peer_data.p_bonding_data = &bond_data;
1053+
uint8_t irk_found[YOTTA_CFG_WHITELIST_MAX_SIZE];
10571054

1058-
1059-
1060-
uint8_t irk_fund[YOTTA_CFG_WHITELIST_MAX_SIZE];
1061-
1062-
memset(irk_fund, 0x00, sizeof(irk_fund));
1055+
memset(irk_found, 0x00, sizeof(irk_found));
10631056

10641057

10651058
gapAdrHelper.identities_cnt = 0;
@@ -1074,26 +1067,25 @@ ble_error_t nRF5xGap::getStackWhiteIdentityList(GapWhiteAndIdentityList_t &gapAd
10741067
* For every private resolvable address in the bond table check if
10751068
* there is maching address in th provided whitelist.
10761069
*/
1077-
while ((peer_id != PM_PEER_ID_INVALID) && (peers_to_check--))
1070+
while (peer_id != PM_PEER_ID_INVALID)
10781071
{
10791072
memset(&bond_data, 0x00, sizeof(bond_data));
10801073

10811074
// Read peer data from flash.
1082-
ret = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_BONDING,
1083-
&peer_data, &buf_size);
1075+
ret = pm_peer_data_bonding_load(peer_id, &bond_data);
10841076

10851077

10861078
if ((ret == NRF_ERROR_NOT_FOUND) || (ret == NRF_ERROR_INVALID_PARAM))
10871079
{
1088-
// Peer data coulnd't be found in flash or peer ID is not valid.
1080+
// Peer data could not be found in flash or peer ID is not valid.
10891081
return BLE_ERROR_UNSPECIFIED;
10901082
}
10911083

10921084
if ( bond_data.peer_ble_id.id_addr_info.addr_type == BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE)
10931085
{
10941086
for (uint8_t i = 0; i < whitelistAddressesSize; ++i)
10951087
{
1096-
if (!irk_fund[i])
1088+
if (!irk_found[i])
10971089
{
10981090
if (whitelistAddresses[i].addr_type == BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE)
10991091
{
@@ -1102,11 +1094,10 @@ ble_error_t nRF5xGap::getStackWhiteIdentityList(GapWhiteAndIdentityList_t &gapAd
11021094
if (securityManager.matchAddressAndIrk(&whitelistAddresses[i], &bond_data.peer_ble_id.id_info))
11031095
{
11041096
// Copy data to the buffer.
1105-
memcpy(&gapAdrHelper.identity[i], &bond_data.peer_ble_id, sizeof(ble_gap_id_key_t));
1106-
gapAdrHelper.pp_identities[i] = &gapAdrHelper.identity[i];
1097+
memcpy(&gapAdrHelper.identities[i], &bond_data.peer_ble_id, sizeof(ble_gap_id_key_t));
11071098
gapAdrHelper.identities_cnt++;
11081099

1109-
irk_fund[i] = 1; // don't look at this address again
1100+
irk_found[i] = 1; // don't look at this address again
11101101
}
11111102
}
11121103
}
@@ -1117,39 +1108,52 @@ ble_error_t nRF5xGap::getStackWhiteIdentityList(GapWhiteAndIdentityList_t &gapAd
11171108
peer_id = pm_next_peer_id_get(peer_id);
11181109
}
11191110

1120-
gapAdrHelper.addr_cnt = 0;
1111+
gapAdrHelper.addrs_cnt = 0;
11211112

11221113
/**
1123-
* Bulida whitelist from the rest of addresses (explicite addressess6)
1114+
* Build whitelist from the rest of addresses (explicit addresses)
11241115
*/
11251116
for (uint8_t i = 0; i < whitelistAddressesSize; ++i)
11261117
{
1127-
if (!irk_fund[i])
1118+
if (!irk_found[i])
11281119
{
1129-
memcpy(&gapAdrHelper.addr[i], &bond_data.peer_ble_id.id_addr_info, sizeof(ble_gap_addr_t));
1130-
gapAdrHelper.pp_addr[i] = &gapAdrHelper.addr[i];
1131-
gapAdrHelper.addr_cnt++;
1120+
memcpy(&gapAdrHelper.addrs[i], &whitelistAddresses[i], sizeof(ble_gap_addr_t));
1121+
gapAdrHelper.addrs_cnt++;
11321122
}
11331123
}
11341124

11351125
return BLE_ERROR_NONE;
11361126
}
11371127

1138-
ble_error_t nRF5xGap::apllyWhiteIdentityList(GapWhiteAndIdentityList_t &gapAdrHelper)
1128+
ble_error_t nRF5xGap::applyWhiteIdentityList(GapWhiteAndIdentityList_t &gapAdrHelper)
11391129
{
11401130
uint32_t retc;
11411131

11421132
if (gapAdrHelper.identities_cnt == 0) {
11431133
retc = sd_ble_gap_device_identities_set(NULL, NULL, 0);
11441134
} else {
1145-
retc = sd_ble_gap_device_identities_set(gapAdrHelper.pp_identities, NULL /* Don't use local IRKs*/,gapAdrHelper.identities_cnt);
1135+
ble_gap_id_key_t * pp_identities[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
1136+
1137+
for (uint32_t i = 0; i < gapAdrHelper.identities_cnt; ++i)
1138+
{
1139+
pp_identities[i] = &gapAdrHelper.identities[i];
1140+
}
1141+
1142+
retc = sd_ble_gap_device_identities_set(pp_identities, NULL /* Don't use local IRKs*/,gapAdrHelper.identities_cnt);
11461143
}
11471144

11481145
if (retc == NRF_SUCCESS) {
1149-
if (gapAdrHelper.addr_cnt == 0) {
1146+
if (gapAdrHelper.addrs_cnt == 0) {
11501147
retc = sd_ble_gap_whitelist_set(NULL, 0);
11511148
} else {
1152-
retc = sd_ble_gap_whitelist_set(gapAdrHelper.pp_addr, gapAdrHelper.addr_cnt);
1149+
ble_gap_addr_t * pp_addrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
1150+
1151+
for (uint32_t i = 0; i < gapAdrHelper.addrs_cnt; ++i)
1152+
{
1153+
pp_addrs[i] = &gapAdrHelper.addrs[i];
1154+
}
1155+
1156+
retc = sd_ble_gap_whitelist_set(pp_addrs, gapAdrHelper.addrs_cnt);
11531157
}
11541158
}
11551159

@@ -1178,9 +1182,9 @@ ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack(whiteAndIdentityListPurp
11781182
uint32_t err;
11791183
bool provide_settings;
11801184

1181-
if (purpose == nRF5xGap::avdvertising_purpose) {
1185+
if (purpose == nRF5xGap::purpose_avdvertising) {
11821186
provide_settings = (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) ? true : false;
1183-
} else { //it must be nRF5xGap::scan_connect_purpose
1187+
} else { //It must be nRF5xGap::purpose_scan_connect.
11841188
provide_settings = (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) ? true : false;
11851189
}
11861190

@@ -1193,11 +1197,11 @@ ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack(whiteAndIdentityListPurp
11931197
return (ble_error_t)err;
11941198
}
11951199
} else {
1196-
whiteAndIdentityList.addr_cnt = 0;
1200+
whiteAndIdentityList.addrs_cnt = 0;
11971201
whiteAndIdentityList.identities_cnt = 0;
11981202
}
11991203

12001204

1201-
return apllyWhiteIdentityList(whiteAndIdentityList);
1205+
return applyWhiteIdentityList(whiteAndIdentityList);
12021206
}
1203-
#endif
1207+
#endif

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,30 +150,33 @@ class nRF5xGap : public Gap
150150
#endif
151151

152152
#if (NRF_SD_BLE_API_VERSION >= 3)
153-
/* internal type for pasing whitelist and identities list */
153+
/* internal type for passing a whitelist and a identities list. */
154154
typedef struct
155155
{
156-
ble_gap_addr_t addr[YOTTA_CFG_WHITELIST_MAX_SIZE];
157-
ble_gap_addr_t * pp_addr[YOTTA_CFG_WHITELIST_MAX_SIZE];
158-
uint32_t addr_cnt;
156+
ble_gap_addr_t addrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
157+
uint32_t addrs_cnt;
159158

160-
ble_gap_id_key_t identity[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
161-
ble_gap_id_key_t * pp_identities[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
159+
ble_gap_id_key_t identities[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
162160
uint32_t identities_cnt;
163161
} GapWhiteAndIdentityList_t;
164162

165-
/* purpouse of updation the whitelist and identities settings */
163+
/* purpose of updating the whitelist and identities settings. */
166164
enum whiteAndIdentityListPurpose_t
167165
{
168-
scan_connect_purpose = 0,
169-
avdvertising_purpose
166+
purpose_scan_connect = 0,
167+
purpose_avdvertising
170168
} whiteAndIdentityListPurpose;
171169

172-
/* Fuction for preparing setting of the whitelist-feature and identiti-reseolv-feature (privacy).*/
170+
/* Function for preparing setting of the whitelist feature and the identity-resolving feature (privacy).*/
173171
ble_error_t getStackWhiteIdentityList(GapWhiteAndIdentityList_t &whiteAndIdentityList);
174-
/* Fuction for apllying setting of the whitelist-feature and identiti-reseolv-feature (privacy).*/
175-
ble_error_t apllyWhiteIdentityList(GapWhiteAndIdentityList_t &whiteAndIdentityList);
176-
/* Fuction which incorportes 2 above f. together */
172+
173+
/* Function for applying setting of the whitelist feature and identity-resolving feature (privacy).*/
174+
ble_error_t applyWhiteIdentityList(GapWhiteAndIdentityList_t &whiteAndIdentityList);
175+
176+
/* Function for introducing whitelist feature and the identity-resolving feature setting into SoftDevice.
177+
*
178+
* Introduced settings are comply which scanning or advertising policies.
179+
* This function incorporates getStackWhiteIdentityList and applyWhiteIdentityList together. */
177180
ble_error_t updateWhiteAndIdentityListInStack(whiteAndIdentityListPurpose_t purpose);
178181
#endif
179182

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/ble/peer_manager/id_manager.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,30 +284,30 @@ bool im_address_resolve(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_i
284284
* 4.2 section 3.H.2.2.2.
285285
*
286286
* @detail BLE uses a hash function to calculate the first half of a resolvable address
287-
* from the second half of the address and an irk. This function will use the ECB
288-
* periferal to hash these data acording to the Bluetooth core specification.
287+
* from the second half of the address and an IRK. This function uses the ECB
288+
* peripheral to hash this data according to the Bluetooth core specification.
289289
*
290-
* @note The ECB expect little endian input and output.
291-
* This function expect big endian and will reverse the data as necessary.
290+
* @note The ECB expects little endian input and output.
291+
* This function expects big endian and will reverse the data as necessary.
292292
*
293293
* @param[in] p_k The key used in the hash function.
294-
* For address resolution this is should be the irk.
294+
* For address resolution this must be the IRK.
295295
* The array must have a length of 16.
296296
* @param[in] p_r The rand used in the hash function. For generating a new address
297297
* this would be a random number. For resolving a resolvable address
298298
* this would be the last half of the address being resolved.
299299
* The array must have a length of 3.
300300
* @param[out] p_local_hash The result of the hash operation. For address resolution this
301301
* will match the first half of the address being resolved if and only
302-
* if the irk used in the hash function is the same one used to generate
302+
* if the irk used in the hash function is the same one that was used to generate
303303
* the address.
304304
* The array must have a length of 16.
305305
*
306306
* @note ====IMPORTANT====
307-
* This is a special modification to the original nRF5x SDK required by the mbed BLE API
308-
* to be able to generate BLE private resolvable addresses. This function is used by
309-
* the BLE API implementation for nRF5xSecurityManager::getAddressFromBondTable() in the
310-
* ble-nrf52832 yotta module.
307+
* This is a special modification to the original nRF5 SDK. It is required by the mbed BLE API
308+
* to generate BLE private resolvable addresses. This function is used by
309+
* the BLE API implementation for nRF5xSecurityManager::getAddressFromBondTable() in the target's
310+
* BLE implementation.
311311
* =================
312312
*/
313313
void ah(uint8_t const * p_k, uint8_t const * p_r, uint8_t * p_local_hash);

0 commit comments

Comments
 (0)