mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-08-19 00:09:58 +00:00
host: add Pairing Complete GAP event
Added event to inform application via GAP event that peer completed pairing with reason code. This is required by SM/CEN/KDU/BI-02-C.
This commit is contained in:
committed by
Michał Narajowski
parent
338c81014e
commit
0c9bb5d050
@@ -137,6 +137,7 @@ struct hci_conn_update;
|
||||
#define BLE_GAP_EVENT_PERIODIC_TRANSFER 24
|
||||
#define BLE_GAP_EVENT_PATHLOSS_THRESHOLD 25
|
||||
#define BLE_GAP_EVENT_TRANSMIT_POWER 26
|
||||
#define BLE_GAP_EVENT_PARING_COMPLETE 27
|
||||
|
||||
/*** Reason codes for the subscribe GAP event. */
|
||||
|
||||
@@ -1023,6 +1024,24 @@ struct ble_gap_event {
|
||||
uint8_t delta;
|
||||
} transmit_power;
|
||||
#endif
|
||||
/**
|
||||
* Represents a received Pairing Complete message
|
||||
*
|
||||
* Valid for the following event types:
|
||||
* o BLE_GAP_EVENT_PARING_COMPLETE
|
||||
*/
|
||||
struct {
|
||||
/**
|
||||
* Indicates the result of the encryption state change attempt;
|
||||
* o 0: the encrypted state was successfully updated;
|
||||
* o BLE host error code: the encryption state change attempt
|
||||
* failed for the specified reason.
|
||||
*/
|
||||
int status;
|
||||
|
||||
/** The handle of the relevant connection. */
|
||||
uint16_t conn_handle;
|
||||
} pairing_complete;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BLE_SM_ERR_SUCCESS 0x00
|
||||
#define BLE_SM_ERR_PASSKEY 0x01
|
||||
#define BLE_SM_ERR_OOB 0x02
|
||||
#define BLE_SM_ERR_AUTHREQ 0x03
|
||||
@@ -41,7 +42,8 @@ extern "C" {
|
||||
#define BLE_SM_ERR_NUMCMP 0x0c
|
||||
#define BLE_SM_ERR_ALREADY 0x0d
|
||||
#define BLE_SM_ERR_CROSS_TRANS 0x0e
|
||||
#define BLE_SM_ERR_MAX_PLUS_1 0x0f
|
||||
#define BLE_SM_ERR_KEY_REJ 0x0f
|
||||
#define BLE_SM_ERR_MAX_PLUS_1 0x10
|
||||
|
||||
#define BLE_SM_PAIR_ALG_JW 0
|
||||
#define BLE_SM_PAIR_ALG_PASSKEY 1
|
||||
|
||||
@@ -5898,6 +5898,20 @@ ble_gap_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
ble_gap_pairing_complete_event(uint16_t conn_handle, int status)
|
||||
{
|
||||
#if NIMBLE_BLE_SM && NIMBLE_BLE_CONNECT
|
||||
struct ble_gap_event event;
|
||||
|
||||
memset(&event, 0, sizeof event);
|
||||
event.type = BLE_GAP_EVENT_PARING_COMPLETE;
|
||||
event.pairing_complete.conn_handle = conn_handle;
|
||||
event.pairing_complete.status = status;
|
||||
ble_gap_call_conn_event_cb(&event, conn_handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $rssi *
|
||||
*****************************************************************************/
|
||||
|
||||
@@ -135,6 +135,7 @@ void ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
|
||||
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_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp);
|
||||
void ble_gap_pairing_complete_event(uint16_t conn_handle, int status);
|
||||
int ble_gap_master_in_progress(void);
|
||||
|
||||
void ble_gap_preempt(void);
|
||||
|
||||
@@ -933,6 +933,12 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
|
||||
|
||||
ble_hs_unlock();
|
||||
|
||||
if (res->enc_cb &&
|
||||
res->app_status != BLE_HS_ENOTCONN) {
|
||||
/* Do not send this event on broken connection */
|
||||
ble_gap_pairing_complete_event(conn_handle, res->sm_err);
|
||||
}
|
||||
|
||||
if (proc == NULL) {
|
||||
break;
|
||||
}
|
||||
@@ -2053,6 +2059,8 @@ ble_sm_key_exch_success(struct ble_sm_proc *proc, struct ble_sm_result *res)
|
||||
res->app_status = 0;
|
||||
res->enc_cb = 1;
|
||||
res->bonded = bonded;
|
||||
|
||||
res->sm_err = BLE_SM_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2423,6 +2431,7 @@ ble_sm_fail_rx(uint16_t conn_handle, struct os_mbuf **om,
|
||||
cmd = (struct ble_sm_pair_fail *)(*om)->om_data;
|
||||
|
||||
res->app_status = BLE_HS_SM_PEER_ERR(cmd->reason);
|
||||
res->sm_err = cmd->reason;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user