This is an automated email from the ASF dual-hosted git repository. naraj pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 0c9bb5d050212711bf924f2262dded535a442c79 Author: Krzysztof Kopyściński <krzysztof.kopyscin...@codecoup.pl> AuthorDate: Wed Sep 22 14:32:13 2021 +0200 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. --- nimble/host/include/host/ble_gap.h | 19 +++++++++++++++++++ nimble/host/include/host/ble_sm.h | 4 +++- nimble/host/src/ble_gap.c | 14 ++++++++++++++ nimble/host/src/ble_gap_priv.h | 1 + nimble/host/src/ble_sm.c | 9 +++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index 83aacacd..5ff34f58 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -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; }; }; diff --git a/nimble/host/include/host/ble_sm.h b/nimble/host/include/host/ble_sm.h index ceebb856..ff381cf2 100644 --- a/nimble/host/include/host/ble_sm.h +++ b/nimble/host/include/host/ble_sm.h @@ -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 diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 289ad591..0dcf9358 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -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 * *****************************************************************************/ diff --git a/nimble/host/src/ble_gap_priv.h b/nimble/host/src/ble_gap_priv.h index ca85db3d..06c4d16b 100644 --- a/nimble/host/src/ble_gap_priv.h +++ b/nimble/host/src/ble_gap_priv.h @@ -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); diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c index 0339e3eb..71b9f769 100644 --- a/nimble/host/src/ble_sm.c +++ b/nimble/host/src/ble_sm.c @@ -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; } }