Skip to content

Commit

Permalink
nimble/host: Add support to unpair oldest peer without unpairing curr…
Browse files Browse the repository at this point in the history
…ent peer
  • Loading branch information
prasad-alatkar committed Apr 7, 2020
1 parent 618ede2 commit 286109e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nimble/host/include/host/ble_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,20 @@ int ble_gap_unpair(const ble_addr_t *peer_addr);
*/
int ble_gap_unpair_oldest_peer(void);

/**
* Similar to `ble_gap_unpair_oldest_peer()`, except it makes sure that current
* peer is not deleted.
*
* @param peer_addr Address of the current peer (not to be deleted)
*
* @return 0 on success;
* A BLE host HCI return code if the controller
* rejected the request;
* A BLE host core return code on unexpected
* error.
*/
int ble_gap_unpair_oldest_except_curr(const ble_addr_t *curr_peer);

#define BLE_GAP_PRIVATE_MODE_NETWORK 0
#define BLE_GAP_PRIVATE_MODE_DEVICE 1

Expand Down
35 changes: 35 additions & 0 deletions nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5605,6 +5605,41 @@ ble_gap_unpair_oldest_peer(void)
return 0;
}

int
ble_gap_unpair_oldest_except_curr(const ble_addr_t *curr_peer)
{
ble_addr_t oldest_peer_id_addr[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
int num_peers;
int rc, i;

rc = ble_store_util_bonded_peers(
&oldest_peer_id_addr[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
if (rc != 0) {
return rc;
}

if (num_peers == 0) {
return BLE_HS_ENOENT;
}

for (i = 0; i < num_peers; i++) {
if (memcmp(curr_peer, &oldest_peer_id_addr[i], sizeof (ble_addr_t)) != 0) {
break;
}
}

if (i < num_peers) {
rc = ble_gap_unpair(&oldest_peer_id_addr[i]);
if (rc != 0) {
return rc;
}
} else {
return BLE_HS_ENOMEM;
}

return 0;
}

void
ble_gap_passkey_event(uint16_t conn_handle,
struct ble_gap_passkey_params *passkey_params)
Expand Down

0 comments on commit 286109e

Please sign in to comment.