uint32_t conn_mw_ble_gap_device_identities_set(uint8_t const * const p_rx_buf, uint32_t rx_buf_len, uint8_t * const p_tx_buf, uint32_t * const p_tx_buf_len) { SER_ASSERT_NOT_NULL(p_rx_buf); SER_ASSERT_NOT_NULL(p_tx_buf); SER_ASSERT_NOT_NULL(p_tx_buf_len); uint32_t err_code = NRF_SUCCESS; uint32_t sd_err_code; uint8_t length; ble_gap_id_key_t id_key_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; ble_gap_id_key_t * p_id_key_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; ble_gap_irk_t irk_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; ble_gap_irk_t * p_irk_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; for (uint8_t i = 0; i < BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; ++i) { p_id_key_array[i] = &id_key_array[i]; p_irk_array[i] = &irk_array[i]; } ble_gap_id_key_t * * pp_id_keys = p_id_key_array; ble_gap_irk_t * * pp_local_irks = p_irk_array; err_code = ble_gap_device_identities_set_req_dec(p_rx_buf, rx_buf_len, &pp_id_keys, &pp_local_irks, &length); SER_ASSERT(err_code == NRF_SUCCESS, err_code); sd_err_code = sd_ble_gap_device_identities_set((ble_gap_id_key_t const * *) pp_id_keys, (ble_gap_irk_t const * *) pp_local_irks, length); err_code = ble_gap_device_identities_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
ret_code_t im_device_identities_list_set(pm_peer_id_t const * p_peers, uint32_t peer_cnt) { #if (NRF_SD_BLE_API_VERSION == 3) ret_code_t ret; pm_peer_data_t peer_data; pm_peer_data_bonding_t bond_data; ble_gap_id_key_t keys[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; ble_gap_id_key_t const * key_ptrs[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; if ((p_peers == NULL) || (peer_cnt == 0)) { // Clear the device identities list. return sd_ble_gap_device_identities_set(NULL, NULL, 0); } peer_data.p_bonding_data = &bond_data; uint32_t const buf_size = sizeof(bond_data); memset(keys, 0x00, sizeof(keys)); for (uint32_t i = 0; i < BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; i++) { key_ptrs[i] = &keys[i]; } for (uint32_t i = 0; i < peer_cnt; i++) { memset(&bond_data, 0x00, sizeof(bond_data)); // Read peer data from flash. ret = pds_peer_data_read(p_peers[i], PM_PEER_DATA_ID_BONDING, &peer_data, &buf_size); if ((ret == NRF_ERROR_NOT_FOUND) || (ret == NRF_ERROR_INVALID_PARAM)) { // Peer data coulnd't be found in flash or peer ID is not valid. return NRF_ERROR_NOT_FOUND; } uint8_t const addr_type = bond_data.peer_id.id_addr_info.addr_type; if ((addr_type != BLE_GAP_ADDR_TYPE_PUBLIC) && (addr_type != BLE_GAP_ADDR_TYPE_RANDOM_STATIC)) { // The address shared by the peer during bonding can't be whitelisted. return BLE_ERROR_GAP_INVALID_BLE_ADDR; } // Copy data to the buffer. memcpy(&keys[i], &bond_data.peer_id, sizeof(ble_gap_id_key_t)); } return sd_ble_gap_device_identities_set(key_ptrs, NULL, peer_cnt); #else return NRF_ERROR_NOT_SUPPORTED; #endif }