NimBLE: Add ble_gap_pairing_req GAP event to accept or reject pairing request

This commit is contained in:
Prasad Alatkar
2019-10-18 15:30:28 +05:30
committed by Kewal M. Shah
parent c691e80043
commit 5318896e09
4 changed files with 77 additions and 0 deletions
+24
View File
@@ -140,6 +140,7 @@ struct hci_conn_update;
#define BLE_GAP_EVENT_SCAN_REQ_RCVD 23
#define BLE_GAP_EVENT_PERIODIC_TRANSFER 24
#define BLE_GAP_EVENT_REATTEMPT_COUNT 25
#define BLE_GAP_EVENT_PAIRING_REQUEST 26
/*** Reason codes for the subscribe GAP event. */
@@ -440,6 +441,15 @@ struct ble_gap_disc_desc {
ble_addr_t direct_addr;
};
struct ble_gap_pairing_req {
uint16_t conn_handle;
/** Properties of the existing pairing request */
uint8_t io_cap;
uint8_t oob_data_flag;
uint8_t authreq;
uint8_t max_enc_key_size;
};
struct ble_gap_repeat_pairing {
/** The handle of the relevant connection. */
uint16_t conn_handle;
@@ -809,6 +819,20 @@ struct ble_gap_event {
uint16_t conn_handle;
} identity_resolved;
/**
* Represents a pairing request from peer.
*
* Valid for following event types:
* o BLE_GAP_EVENT_PAIRING_REQUEST
* The application can accept or reject pairing request. For accepting
* the application should return 0 and for rejecting the request the
* application should provide appropriate error return code,
* e.g. BLE_SM_ERR_AUTHREQ
* o Accept : Return 0
* o Reject : Return appropriate error BLE_SM_*
*/
struct ble_gap_pairing_req pairing_req;
/**
* Represents a peer's attempt to pair despite a bond already existing.
* The application has two options for handling this event type:
+21
View File
@@ -6145,6 +6145,27 @@ ble_gap_identity_event(uint16_t conn_handle)
#endif
}
int
ble_gap_pairing_req_event(const struct ble_gap_pairing_req *req)
{
#if !NIMBLE_BLE_SM
return 0;
#endif
struct ble_gap_event event;
int rc;
memset(&event, 0, sizeof event);
event.type = BLE_GAP_EVENT_PAIRING_REQUEST;
event.pairing_req.io_cap = req->io_cap;
event.pairing_req.oob_data_flag = req->oob_data_flag;
event.pairing_req.authreq = req->authreq;
event.pairing_req.max_enc_key_size = req->max_enc_key_size;
rc = ble_gap_call_conn_event_cb(&event, req->conn_handle);
return rc;
}
int
ble_gap_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp)
{
+1
View File
@@ -129,6 +129,7 @@ void ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
uint8_t prev_indicate, uint8_t cur_indicate);
void ble_gap_mtu_event(uint16_t conn_handle, uint16_t cid, uint16_t mtu);
void ble_gap_identity_event(uint16_t conn_handle);
int ble_gap_pairing_req_event(const struct ble_gap_pairing_req *req);
int ble_gap_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp);
int ble_gap_master_in_progress(void);
+31
View File
@@ -875,6 +875,25 @@ ble_sm_read_bond(uint16_t conn_handle, struct ble_store_value_sec *out_bond)
return rc;
}
/**
* The application is queried about pairing request, depending upon the
* application's response the pairing request is accepted or rejected
*/
static int
ble_sm_pairing_req(uint16_t conn_handle, struct ble_sm_pair_cmd *req)
{
struct ble_gap_pairing_req pair_req;
int rc;
pair_req.conn_handle = conn_handle;
pair_req.io_cap = req->io_cap;
pair_req.oob_data_flag = req->oob_data_flag;
pair_req.authreq = req->authreq;
pair_req.max_enc_key_size = req->max_enc_key_size;
return ble_gap_pairing_req_event(&pair_req);
}
/**
* Checks if the specified peer is already bonded. If it is, the application
* is queried about how to proceed: retry or ignore. The application should
@@ -1830,6 +1849,18 @@ ble_sm_pair_req_rx(uint16_t conn_handle, struct os_mbuf **om,
ble_hs_unlock();
/* Ask the application to provide response if pairing is to be accepted or
* not
*/
rc = ble_sm_pairing_req(conn_handle, req);
if (rc != 0) {
/* The app indicated that the pairing request should be rejected. */
res->sm_err = rc;
res->app_status = BLE_HS_SM_US_ERR(rc);
return;
}
/* Check if there is storage capacity for a new bond. If there isn't, ask
* the application to make room.
*/