You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/01/11 16:07:28 UTC

[GitHub] michal-narajowski closed pull request #288: Host fixes needed for Bluetooth Tester application

michal-narajowski closed pull request #288: Host fixes needed for Bluetooth Tester application
URL: https://github.com/apache/mynewt-nimble/pull/288
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/include/host/ble_gatt.h b/nimble/host/include/host/ble_gatt.h
index c3725bce..6188f622 100644
--- a/nimble/host/include/host/ble_gatt.h
+++ b/nimble/host/include/host/ble_gatt.h
@@ -848,7 +848,8 @@ int ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
 
 typedef void (*ble_gatt_svc_foreach_fn)(const struct ble_gatt_svc_def *svc,
                                         uint16_t handle,
-                                        uint16_t end_group_handle);
+                                        uint16_t end_group_handle,
+                                        void *arg);
 
 /**
  * Prints dump of local GATT database. This is useful to log local state of
diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c
index b4cddb1c..3c7d0a2d 100644
--- a/nimble/host/src/ble_gap.c
+++ b/nimble/host/src/ble_gap.c
@@ -1448,8 +1448,18 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt, uint8_t instance)
     conn->bhc_our_rpa_addr.type = BLE_ADDR_RANDOM;
     memcpy(conn->bhc_our_rpa_addr.val, evt->local_rpa, 6);
 
-    conn->bhc_peer_rpa_addr.type = BLE_ADDR_RANDOM;
-    memcpy(conn->bhc_peer_rpa_addr.val, evt->peer_rpa, 6);
+    /* If peer RPA is not set in the event and peer address
+     * is RPA then store the peer RPA address so when the peer
+     * address is resolved, the RPA is not forgotten.
+     */
+    if (memcmp(BLE_ADDR_ANY->val, evt->peer_rpa, 6) == 0) {
+        if (BLE_ADDR_IS_RPA(&conn->bhc_peer_addr)) {
+            conn->bhc_peer_rpa_addr = conn->bhc_peer_addr;
+        }
+    } else {
+        conn->bhc_peer_rpa_addr.type = BLE_ADDR_RANDOM;
+        memcpy(conn->bhc_peer_rpa_addr.val, evt->peer_rpa, 6);
+    }
 
     ble_hs_lock();
 
diff --git a/nimble/host/src/ble_gatt_priv.h b/nimble/host/src/ble_gatt_priv.h
index 14b92cd4..a49e9368 100644
--- a/nimble/host/src/ble_gatt_priv.h
+++ b/nimble/host/src/ble_gatt_priv.h
@@ -178,10 +178,13 @@ int ble_gatts_send_next_indicate(uint16_t conn_handle);
 void ble_gatts_tx_notifications(void);
 void ble_gatts_bonding_restored(uint16_t conn_handle);
 void ble_gatts_connection_broken(uint16_t conn_handle);
-void ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb);
+void ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb, void *arg);
 int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
                             ble_gatt_register_fn *register_cb,
                             void *cb_arg);
+int ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t attr_handle,
+                             uint8_t op, uint16_t offset, struct os_mbuf **om,
+                             void *arg);
 
 /*** @misc. */
 int ble_gatts_conn_can_alloc(void);
diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c
index 7a53001f..f1a80ff7 100644
--- a/nimble/host/src/ble_gatts.c
+++ b/nimble/host/src/ble_gatts.c
@@ -733,7 +733,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
     return 0;
 }
 
-static int
+int
 ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t attr_handle,
                          uint8_t op, uint16_t offset, struct os_mbuf **om,
                          void *arg)
@@ -2083,14 +2083,14 @@ ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs)
 }
 
 void
-ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb)
+ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb, void *arg)
 {
     int i;
 
     for (i = 0; i < ble_gatts_num_svc_entries; i++) {
         cb(ble_gatts_svc_entries[i].svc,
            ble_gatts_svc_entries[i].handle,
-           ble_gatts_svc_entries[i].end_group_handle);
+           ble_gatts_svc_entries[i].end_group_handle, arg);
     }
 }
 
diff --git a/nimble/host/src/ble_gatts_lcl.c b/nimble/host/src/ble_gatts_lcl.c
index 747c5126..c524ef5b 100644
--- a/nimble/host/src/ble_gatts_lcl.c
+++ b/nimble/host/src/ble_gatts_lcl.c
@@ -133,9 +133,22 @@ ble_gatt_show_local_chr(const struct ble_gatt_svc_def *svc,
     }
 }
 
+static void
+ble_gatt_show_local_inc_svc(const struct ble_gatt_svc_def *svc, char *uuid_buf)
+{
+    const struct ble_gatt_svc_def *inc_svc;
+
+    console_printf("%" FIELD_INDENT "s %" FIELD_NAME_LEN "s ", " ", "includes");
+    for (inc_svc = *svc->includes; inc_svc; ++inc_svc) {
+            console_printf("%s ", ble_uuid_to_str(inc_svc->uuid, uuid_buf));
+    }
+    console_printf("\n");
+}
+
 static void
 ble_gatt_show_local_svc(const struct ble_gatt_svc_def *svc,
-                        uint16_t handle, uint16_t end_group_handle)
+                        uint16_t handle, uint16_t end_group_handle,
+                        void *arg)
 {
     char uuid_buf[BLE_UUID_STR_LEN];
     char flags_buf[BLE_CHR_FLAGS_STR_LEN];
@@ -152,6 +165,9 @@ ble_gatt_show_local_svc(const struct ble_gatt_svc_def *svc,
     console_printf("%" FIELD_INDENT "s %" FIELD_NAME_LEN "s "
                    "%d\n", " ", "end_handle",
                    end_group_handle);
+    if (svc->includes) {
+        ble_gatt_show_local_inc_svc(svc, uuid_buf);
+    }
     ble_gatt_show_local_chr(svc, handle+1,
                             uuid_buf, flags_buf);
 }
@@ -159,6 +175,6 @@ ble_gatt_show_local_svc(const struct ble_gatt_svc_def *svc,
 void
 ble_gatts_show_local(void)
 {
-    ble_gatts_lcl_svc_foreach(ble_gatt_show_local_svc);
+    ble_gatts_lcl_svc_foreach(ble_gatt_show_local_svc, NULL);
 }
 
diff --git a/nimble/host/src/ble_hs_conn.c b/nimble/host/src/ble_hs_conn.c
index 00fa4f8c..2e23da3b 100644
--- a/nimble/host/src/ble_hs_conn.c
+++ b/nimble/host/src/ble_hs_conn.c
@@ -300,8 +300,14 @@ ble_hs_conn_find_by_addr(const ble_addr_t *addr)
     }
 
     SLIST_FOREACH(conn, &ble_hs_conns, bhc_next) {
-        if (ble_addr_cmp(&conn->bhc_peer_addr, addr) == 0) {
-            return conn;
+        if (BLE_ADDR_IS_RPA(addr)) {
+            if (ble_addr_cmp(&conn->bhc_peer_rpa_addr, addr) == 0) {
+                return conn;
+            }
+        } else {
+            if (ble_addr_cmp(&conn->bhc_peer_addr, addr) == 0) {
+                return conn;
+            }
         }
     }
 
diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c
index 09b33bf5..d0d464dc 100644
--- a/nimble/host/src/ble_sm.c
+++ b/nimble/host/src/ble_sm.c
@@ -524,15 +524,14 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
         memcpy(peer_addr.val, proc->peer_keys.addr, sizeof peer_addr.val);
 
         conn->bhc_peer_addr = peer_addr;
+
         /* Update identity address in conn.
-         * If peer's address was an RPA, we store it as RPA since peer's address
-         * will not be an identity address. The peer's address type has to be
+         * If peer's rpa address is set then it means that the peer's address
+         * is an identity address. The peer's address type has to be
          * set as 'ID' to allow resolve 'id' and 'ota' addresses properly in
          * conn info.
          */
-        if (BLE_ADDR_IS_RPA(&conn->bhc_peer_addr)) {
-            conn->bhc_peer_rpa_addr = conn->bhc_peer_addr;
-
+        if (memcmp(BLE_ADDR_ANY->val, &conn->bhc_peer_rpa_addr.val, 6) != 0) {
             switch (peer_addr.type) {
             case BLE_ADDR_PUBLIC:
             case BLE_ADDR_PUBLIC_ID:
@@ -544,9 +543,9 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
                 conn->bhc_peer_addr.type = BLE_ADDR_RANDOM_ID;
                 break;
             }
-        }
 
-        identity_ev = 1;
+            identity_ev = 1;
+        }
     } else {
         peer_addr = conn->bhc_peer_addr;
         peer_addr.type = ble_hs_misc_addr_type_to_id(conn->bhc_peer_addr.type);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services