You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2022/08/25 13:17:57 UTC

[mynewt-nimble] branch master updated (338c8101 -> f7ebfaf9)

This is an automated email from the ASF dual-hosted git repository.

naraj pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


    from 338c8101 host/ble_gap.c: Fix failure to run callback on finished scan
     new 0c9bb5d0 host: add Pairing Complete GAP event
     new f7ebfaf9 apps/bttester: handle GAP Pairing Complete event

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 apps/bttester/src/bttester.h       |  7 +++++++
 apps/bttester/src/gap.c            | 35 ++++++++++++++++++++++++++++++++++-
 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           |  8 ++++++++
 7 files changed, 86 insertions(+), 2 deletions(-)


[mynewt-nimble] 02/02: apps/bttester: handle GAP Pairing Complete event

Posted by na...@apache.org.
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 f7ebfaf95b44013c8ab938edbab2bf98bebc7d8b
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Wed Sep 22 14:34:05 2021 +0200

    apps/bttester: handle GAP Pairing Complete event
    
    Send event when peer fails pairing procedure with reason code.
    This is required by SM/CEN/KDU/BI-02-C.
---
 apps/bttester/src/bttester.h |  7 +++++++
 apps/bttester/src/gap.c      | 35 ++++++++++++++++++++++++++++++++++-
 nimble/host/src/ble_sm.c     |  1 -
 3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index 7bcd789c..4aa34b3c 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -418,6 +418,13 @@ struct gap_bond_lost_ev {
     uint8_t address[6];
 } __packed;
 
+#define GAP_EV_SEC_PAIRING_FAILED	0x8c
+struct gap_sec_pairing_failed_ev {
+    uint8_t address_type;
+    uint8_t address[6];
+    uint8_t reason;
+} __packed;
+
 /* GATT Service */
 /* commands */
 #define GATT_READ_SUPPORTED_COMMANDS	0x01
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index e2136093..24ef4ab3 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -980,6 +980,31 @@ static void le_identity_resolved(uint16_t conn_handle)
 		    CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
 }
 
+static void le_pairing_failed(uint16_t conn_handle, int reason)
+{
+    struct ble_gap_conn_desc desc;
+    struct gap_sec_pairing_failed_ev ev;
+    int rc;
+
+    SYS_LOG_DBG("");
+
+    rc = ble_gap_conn_find(conn_handle, &desc);
+    if (rc) {
+        return;
+    }
+
+    peer_id_addr = desc.peer_id_addr;
+    peer_ota_addr = desc.peer_ota_addr;
+
+    ev.address_type = desc.peer_ota_addr.type;
+    memcpy(ev.address, desc.peer_ota_addr.val, sizeof(ev.address));
+
+    ev.reason = reason;
+
+    tester_send(BTP_SERVICE_ID_GAP, GAP_EV_SEC_PAIRING_FAILED,
+                CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
+}
+
 static void le_conn_param_update(struct ble_gap_conn_desc *desc)
 {
 	struct gap_conn_param_update_ev ev;
@@ -1262,7 +1287,15 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
 			event->conn_update_req.peer_params->supervision_timeout == REJECT_SUPERVISION_TIMEOUT) {
 			return EINVAL;
 		}
-
+    case BLE_GAP_EVENT_PARING_COMPLETE:
+        console_printf("received pairing complete: "
+                       "conn_handle=%d status=%d\n",
+                       event->pairing_complete.conn_handle,
+                       event->pairing_complete.status);
+        if (event->pairing_complete.status != BLE_SM_ERR_SUCCESS) {
+    	    le_pairing_failed(event->pairing_complete.conn_handle, event->pairing_complete.status);
+        }
+        break;
 	default:
 		break;
 	}
diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c
index 71b9f769..5188effe 100644
--- a/nimble/host/src/ble_sm.c
+++ b/nimble/host/src/ble_sm.c
@@ -2059,7 +2059,6 @@ 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;
 }
 


[mynewt-nimble] 01/02: host: add Pairing Complete GAP event

Posted by na...@apache.org.
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 <kr...@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;
     }
 }