mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-10-29 08:43:33 +00:00
NimBLE: Add ble_gap_pairing_req GAP event to accept or reject pairing request
This commit is contained in:
@@ -128,6 +128,7 @@ struct hci_conn_update;
|
|||||||
#define BLE_GAP_EVENT_PERIODIC_REPORT 21
|
#define BLE_GAP_EVENT_PERIODIC_REPORT 21
|
||||||
#define BLE_GAP_EVENT_PERIODIC_SYNC_LOST 22
|
#define BLE_GAP_EVENT_PERIODIC_SYNC_LOST 22
|
||||||
#define BLE_GAP_EVENT_SCAN_REQ_RCVD 23
|
#define BLE_GAP_EVENT_SCAN_REQ_RCVD 23
|
||||||
|
#define BLE_GAP_EVENT_PAIRING_REQUEST 24
|
||||||
|
|
||||||
/*** Reason codes for the subscribe GAP event. */
|
/*** Reason codes for the subscribe GAP event. */
|
||||||
|
|
||||||
@@ -428,6 +429,15 @@ struct ble_gap_disc_desc {
|
|||||||
ble_addr_t direct_addr;
|
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 {
|
struct ble_gap_repeat_pairing {
|
||||||
/** The handle of the relevant connection. */
|
/** The handle of the relevant connection. */
|
||||||
uint16_t conn_handle;
|
uint16_t conn_handle;
|
||||||
@@ -797,6 +807,20 @@ struct ble_gap_event {
|
|||||||
uint16_t conn_handle;
|
uint16_t conn_handle;
|
||||||
} identity_resolved;
|
} 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.
|
* Represents a peer's attempt to pair despite a bond already existing.
|
||||||
* The application has two options for handling this event type:
|
* The application has two options for handling this event type:
|
||||||
|
|||||||
@@ -5417,6 +5417,27 @@ ble_gap_identity_event(uint16_t conn_handle)
|
|||||||
ble_gap_call_conn_event_cb(&event, conn_handle);
|
ble_gap_call_conn_event_cb(&event, conn_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
int
|
||||||
ble_gap_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp)
|
ble_gap_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ void ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
|
|||||||
uint8_t prev_indicate, uint8_t cur_indicate);
|
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_mtu_event(uint16_t conn_handle, uint16_t cid, uint16_t mtu);
|
||||||
void ble_gap_identity_event(uint16_t conn_handle);
|
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_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp);
|
||||||
int ble_gap_master_in_progress(void);
|
int ble_gap_master_in_progress(void);
|
||||||
|
|
||||||
|
|||||||
@@ -847,6 +847,25 @@ ble_sm_read_bond(uint16_t conn_handle, struct ble_store_value_sec *out_bond)
|
|||||||
return rc;
|
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
|
* 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
|
* is queried about how to proceed: retry or ignore. The application should
|
||||||
@@ -1820,6 +1839,18 @@ ble_sm_pair_req_rx(uint16_t conn_handle, struct os_mbuf **om,
|
|||||||
|
|
||||||
ble_hs_unlock();
|
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
|
/* Check if there is storage capacity for a new bond. If there isn't, ask
|
||||||
* the application to make room.
|
* the application to make room.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user