You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/06/07 14:41:08 UTC

[01/12] incubator-mynewt-core git commit: bletiny - allow peer addr in undirected adv.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/upf54 5f55e6465 -> ae861d030


bletiny - allow peer addr in undirected adv.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/05bb9171
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/05bb9171
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/05bb9171

Branch: refs/heads/upf54
Commit: 05bb917145a175823077f4b83a35dea60120276f
Parents: 88a1ea7
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:23:18 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:09 2016 +0800

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/05bb9171/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index c9e38a9..178aeca 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -297,20 +297,17 @@ cmd_adv(int argc, char **argv)
         return -1;
     }
 
-    if (conn == BLE_GAP_CONN_MODE_DIR) {
-        addr_type = parse_arg_kv_default
-                ("peer_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC);
-        if (addr_type == -1) {
-            return -1;
-        }
+    addr_type = parse_arg_kv_default
+            ("peer_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC);
+    if (addr_type == -1) {
+        return -1;
+    }
 
-        rc = parse_arg_mac("addr", peer_addr);
-        if (rc != 0) {
-            return rc;
-        }
-    } else {
-        addr_type = BLE_ADDR_TYPE_PUBLIC;
+    rc = parse_arg_mac("peer_addr", peer_addr);
+    if (rc == ENOENT) {
         memset(peer_addr, 0, sizeof peer_addr);
+    } else if (rc != 0) {
+        return rc;
     }
 
     peer_addr_type = addr_type;


[03/12] incubator-mynewt-core git commit: BLE Host - Don't change enc status on SMP timeout.

Posted by cc...@apache.org.
BLE Host - Don't change enc status on SMP timeout.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/88a1ea7b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/88a1ea7b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/88a1ea7b

Branch: refs/heads/upf54
Commit: 88a1ea7bc52b1fb9fa09a56576b7fba6febfb65e
Parents: b0eebf9
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 08:07:48 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:09 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/88a1ea7b/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index f4b384b..32c2583 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2034,9 +2034,11 @@ ble_sm_heartbeat(void)
 
     /* Notify application of each failure and free the corresponding procedure
      * object.
+     * XXX: Mark connection as tainted; don't allow any subsequent SMP
+     * procedures without reconnect.
      */
     while ((proc = STAILQ_FIRST(&exp_list)) != NULL) {
-        ble_sm_enc_event(proc, BLE_HS_ETIMEOUT, 0);
+        ble_sm_enc_event(proc, BLE_HS_ETIMEOUT, BLE_SM_ENC_STATE_NO_CHANGE);
 
         STAILQ_REMOVE_HEAD(&exp_list, next);
         ble_sm_proc_free(proc);


[05/12] incubator-mynewt-core git commit: BLE Host - Fix for encryption key refresh.

Posted by cc...@apache.org.
BLE Host - Fix for encryption key refresh.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a056e9f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a056e9f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a056e9f7

Branch: refs/heads/upf54
Commit: a056e9f702e35e218729b6aa9433c83dd5535d0d
Parents: d9b89ec
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 07:59:54 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:09 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a056e9f7/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 72c891c..f4b384b 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -991,6 +991,8 @@ ble_sm_enc_key_refresh_rx(struct hci_encrypt_key_refresh *evt)
     struct ble_sm_proc *proc;
     int do_key_exchange;
 
+    memset(&res, 0, sizeof res);
+
     ble_hs_lock();
     proc = ble_sm_proc_find(evt->connection_handle,
                             BLE_SM_PROC_STATE_ENC_START, -1, NULL);


[02/12] incubator-mynewt-core git commit: BLE Host - enable key rfrsh & param req events.

Posted by cc...@apache.org.
BLE Host - enable key rfrsh & param req events.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d9b89ec1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d9b89ec1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d9b89ec1

Branch: refs/heads/upf54
Commit: d9b89ec1f415f5a88936be68ffacd71f41a3feb0
Parents: 5f55e64
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 07:58:08 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:09 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_startup.c | 58 ++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d9b89ec1/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index d0f96a2..a517f03 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -83,8 +83,17 @@ ble_hs_startup_le_set_evmask_tx(void)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN];
     int rc;
 
-    /* [ Default event set ]. */
-    host_hci_cmd_build_le_set_event_mask(0x000000000000021f, buf, sizeof buf);
+    /**
+     * Enable the following LE events:
+     *     0x0000000000000001 LE Connection Complete Event
+     *     0x0000000000000002 LE Advertising Report Event
+     *     0x0000000000000004 LE Connection Update Complete Event
+     *     0x0000000000000008 LE Read Remote Used Features Complete Event
+     *     0x0000000000000010 LE Long Term Key Request Event
+     *     0x0000000000000020 LE Remote Connection Parameter Request Event
+     *     0x0000000000000200 LE Enhanced Connection Complete Event
+     */
+    host_hci_cmd_build_le_set_event_mask(0x000000000000023f, buf, sizeof buf);
     rc = ble_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;
@@ -99,8 +108,49 @@ ble_hs_startup_set_evmask_tx(void)
     uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN];
     int rc;
 
-    /* [ Default event set | LE-meta event ]. */
-    host_hci_cmd_build_set_event_mask(0x20001fffffffffff, buf, sizeof buf);
+    /**
+     * Enable the following events:
+     *     0x0000000000000001 Inquiry Complete Event
+     *     0x0000000000000002 Inquiry Result Event
+     *     0x0000000000000004 Connection Complete Event
+     *     0x0000000000000008 Connection Request Event
+     *     0x0000000000000010 Disconnection Complete Event
+     *     0x0000000000000020 Authentication Complete Event
+     *     0x0000000000000040 Remote Name Request Complete Event
+     *     0x0000000000000080 Encryption Change Event
+     *     0x0000000000000100 Change Connection Link Key Complete Event
+     *     0x0000000000000200 Master Link Key Complete Event
+     *     0x0000000000000400 Read Remote Supported Features Complete Event
+     *     0x0000000000000800 Read Remote Version Information Complete Event
+     *     0x0000000000001000 QoS Setup Complete Event
+     *     0x0000000000002000 Reserved
+     *     0x0000000000004000 Reserved
+     *     0x0000000000008000 Hardware Error Event
+     *     0x0000000000010000 Flush Occurred Event
+     *     0x0000000000020000 Role Change Event
+     *     0x0000000000040000 Reserved
+     *     0x0000000000080000 Mode Change Event
+     *     0x0000000000100000 Return Link Keys Event
+     *     0x0000000000200000 PIN Code Request Event
+     *     0x0000000000400000 Link Key Request Event
+     *     0x0000000000800000 Link Key Notification Event
+     *     0x0000000001000000 Loopback Command Event
+     *     0x0000000002000000 Data Buffer Overflow Event
+     *     0x0000000004000000 Max Slots Change Event
+     *     0x0000000008000000 Read Clock Offset Complete Event
+     *     0x0000000010000000 Connection Packet Type Changed Event
+     *     0x0000000020000000 QoS Violation Event
+     *     0x0000000040000000 Page Scan Mode Change Event [deprecated]
+     *     0x0000000080000000 Page Scan Repetition Mode Change Event
+     *     0x0000000100000000 Flow Specification Complete Event
+     *     0x0000000200000000 Inquiry Result with RSSI Event
+     *     0x0000000400000000 Read Remote Extended Features Complete Event
+     *     0x0000080000000000 Synchronous Connection Complete Event
+     *     0x0000100000000000 Synchronous Connection Changed Event
+     *     0x0000800000000000 Encryption Key Refresh Complete Event
+     *     0x2000000000000000 LE Meta-Event
+     */
+    host_hci_cmd_build_set_event_mask(0x20009fffffffffff, buf, sizeof buf);
     rc = ble_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;


[07/12] incubator-mynewt-core git commit: BLE Host - set data length HCI command.

Posted by cc...@apache.org.
BLE Host - set data length HCI command.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5ee73b1d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5ee73b1d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5ee73b1d

Branch: refs/heads/upf54
Commit: 5ee73b1d98d259525d6e551a0a6b3a9b305cfcf9
Parents: 0894dac
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:37:01 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:34 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/include/host/host_hci.h |  3 +
 net/nimble/host/src/ble_hci_util.c      | 35 ++++++++++
 net/nimble/host/src/ble_hci_util_priv.h |  2 +
 net/nimble/host/src/host_hci_cmd.c      | 99 ++++++++++++++++++++++------
 net/nimble/include/nimble/hci_common.h  |  5 ++
 5 files changed, 125 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ee73b1d/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
index f31fa8f..12da775 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -96,6 +96,9 @@ uint16_t host_hci_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc);
 int host_hci_data_rx(struct os_mbuf *om);
 int host_hci_data_tx(struct ble_hs_conn *connection, struct os_mbuf *om);
 
+int host_hci_cmd_build_set_data_len(uint16_t connection_handle,
+                                    uint16_t tx_octets, uint16_t tx_time,
+                                    uint8_t *dst, int dst_len);
 int host_hci_cmd_add_device_to_resolving_list(
                                     struct hci_add_dev_to_resolving_list *padd,
                                     uint8_t *dst, int dst_len);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ee73b1d/net/nimble/host/src/ble_hci_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util.c b/net/nimble/host/src/ble_hci_util.c
index b32826f..8310e27 100644
--- a/net/nimble/host/src/ble_hci_util.c
+++ b/net/nimble/host/src/ble_hci_util.c
@@ -122,3 +122,38 @@ ble_hs_util_set_random_addr(uint8_t *addr)
     rc = ble_hci_cmd_tx_empty_ack(buf);
     return rc;
 }
+
+int
+ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
+                          uint16_t tx_time)
+{
+
+    uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN];
+    uint8_t params[BLE_HCI_SET_DATALEN_ACK_PARAM_LEN];
+    uint16_t params_conn_handle;
+    uint8_t params_len;
+    int rc;
+
+    rc = host_hci_cmd_build_set_data_len(conn_handle, tx_octets, tx_time, buf,
+                                         sizeof buf);
+    if (rc != 0) {
+        return BLE_HS_HCI_ERR(rc);
+    }
+
+    rc = ble_hci_cmd_tx(buf, params, BLE_HCI_SET_DATALEN_ACK_PARAM_LEN,
+                        &params_len);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (params_len != BLE_HCI_SET_DATALEN_ACK_PARAM_LEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    params_conn_handle = le16toh(params + 0);
+    if (params_conn_handle != conn_handle) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ee73b1d/net/nimble/host/src/ble_hci_util_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util_priv.h b/net/nimble/host/src/ble_hci_util_priv.h
index 898296a..f445514 100644
--- a/net/nimble/host/src/ble_hci_util_priv.h
+++ b/net/nimble/host/src/ble_hci_util_priv.h
@@ -24,5 +24,7 @@ int ble_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
 int ble_hci_util_rand(void *dst, int len);
 int ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
 int ble_hs_util_set_random_addr(uint8_t *addr);
+int ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
+                              uint16_t tx_time);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ee73b1d/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index 16b6d0a..06b5c01 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -929,6 +929,9 @@ host_hci_cmd_body_le_start_encrypt(struct hci_start_encrypt *cmd, uint8_t *dst)
     memcpy(dst + 12, cmd->long_term_key, sizeof cmd->long_term_key);
 }
 
+/*
+ * OGF=0x08 OCF=0x0019
+ */
 void
 host_hci_cmd_build_le_start_encrypt(struct hci_start_encrypt *cmd,
                                     uint8_t *dst, int dst_len)
@@ -972,6 +975,56 @@ host_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len)
 }
 
 static int
+host_hci_cmd_body_set_data_len(uint16_t connection_handle, uint16_t tx_octets,
+                               uint16_t tx_time, uint8_t *dst)
+{
+
+    if (tx_octets < BLE_HCI_SET_DATALEN_TX_OCTETS_MIN ||
+        tx_octets > BLE_HCI_SET_DATALEN_TX_OCTETS_MAX) {
+
+        return BLE_HS_EINVAL;
+    }
+
+    if (tx_time < BLE_HCI_SET_DATALEN_TX_TIME_MIN ||
+        tx_time > BLE_HCI_SET_DATALEN_TX_TIME_MAX) {
+
+        return BLE_HS_EINVAL;
+    }
+
+    htole16(dst + 0, connection_handle);
+    htole16(dst + 2, tx_octets);
+    htole16(dst + 4, tx_time);
+
+    return 0;
+}
+
+/*
+ * OGF=0x08 OCF=0x0022
+ */
+int
+host_hci_cmd_build_set_data_len(uint16_t connection_handle,
+                                uint16_t tx_octets, uint16_t tx_time,
+                                uint8_t *dst, int dst_len)
+{
+    int rc;
+
+    BLE_HS_DBG_ASSERT(
+        dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN);
+
+    host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DATA_LEN,
+                       BLE_HCI_SET_DATALEN_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    rc = host_hci_cmd_body_set_data_len(connection_handle, tx_octets, tx_time,
+                                        dst);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}
+
+static int
 host_hci_cmd_body_add_device_to_resolving_list(uint8_t addr_type,
                                                uint8_t *addr,
                                                uint8_t *peer_irk,
@@ -990,11 +1043,14 @@ host_hci_cmd_body_add_device_to_resolving_list(uint8_t addr_type,
     return 0;
 }
 
+/*
+ * OGF=0x08 OCF=0x0027
+ */
 int
 host_hci_cmd_add_device_to_resolving_list(
-                                struct hci_add_dev_to_resolving_list *padd,
-                                uint8_t *dst,
-                                int dst_len)
+    struct hci_add_dev_to_resolving_list *padd,
+    uint8_t *dst,
+    int dst_len)
 {
     int rc;
 
@@ -1113,9 +1169,9 @@ host_hci_cmd_read_peer_resolvable_address(uint8_t peer_identity_addr_type,
 }
 
 static int
-host_hci_cmd_body_read_local_resolvable_address(uint8_t local_identity_addr_type,
-                                                uint8_t *local_identity_addr,
-                                                uint8_t *dst)
+host_hci_cmd_body_read_local_resolvable_address(
+    uint8_t local_identity_addr_type, uint8_t *local_identity_addr,
+    uint8_t *dst)
 {
     if (local_identity_addr_type > BLE_ADDR_TYPE_RANDOM) {
         return BLE_ERR_INV_HCI_CMD_PARMS;
@@ -1126,11 +1182,14 @@ host_hci_cmd_body_read_local_resolvable_address(uint8_t local_identity_addr_type
     return 0;
 }
 
+/*
+ * OGF=0x08 OCF=0x002c
+ */
 int
 host_hci_cmd_read_local_resolvable_address(uint8_t local_identity_addr_type,
-                                          uint8_t *local_identity_addr,
-                                          uint8_t *dst,
-                                          int dst_len)
+                                           uint8_t *local_identity_addr,
+                                           uint8_t *dst,
+                                           int dst_len)
 {
     int rc;
 
@@ -1162,10 +1221,12 @@ host_hci_cmd_body_set_addr_resolution_enable(uint8_t enable,
     return 0;
 }
 
+/*
+ * OGF=0x08 OCF=0x002d
+ */
 int
-host_hci_cmd_set_addr_resolution_enable(uint8_t enable,
-                                          uint8_t *dst,
-                                          int dst_len)
+host_hci_cmd_set_addr_resolution_enable(uint8_t enable, uint8_t *dst,
+                                        int dst_len)
 {
     int rc;
 
@@ -1195,10 +1256,13 @@ host_hci_cmd_body_set_resolvable_private_address_timeout(uint16_t timeout,
     return 0;
 }
 
+/*
+ * OGF=0x08 OCF=0x002e
+ */
 int
 host_hci_cmd_set_resolvable_private_address_timeout(uint16_t timeout,
-                                                      uint8_t *dst,
-                                                      int dst_len)
+                                                    uint8_t *dst,
+                                                    int dst_len)
 {
     int rc;
 
@@ -1217,17 +1281,14 @@ host_hci_cmd_set_resolvable_private_address_timeout(uint16_t timeout,
 }
 
 static int
-host_hci_cmd_body_set_random_addr(struct hci_rand_addr *paddr,
-                                uint8_t *dst)
+host_hci_cmd_body_set_random_addr(struct hci_rand_addr *paddr, uint8_t *dst)
 {
     memcpy(dst, paddr->addr, BLE_DEV_ADDR_LEN);
     return 0;
 }
 
 int
-host_hci_cmd_set_random_addr(uint8_t *addr,
-                              uint8_t *dst,
-                              int dst_len)
+host_hci_cmd_set_random_addr(uint8_t *addr, uint8_t *dst, int dst_len)
 {
     struct hci_rand_addr r_addr;
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ee73b1d/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 280f65a..962df49 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -333,6 +333,11 @@
 
 /* --- LE set data length (OCF 0x0022) */
 #define BLE_HCI_SET_DATALEN_LEN             (6)
+#define BLE_HCI_SET_DATALEN_ACK_PARAM_LEN   (2)  /* No status byte. */
+#define BLE_HCI_SET_DATALEN_TX_OCTETS_MIN   (0x001b)
+#define BLE_HCI_SET_DATALEN_TX_OCTETS_MAX   (0x00fb)
+#define BLE_HCI_SET_DATALEN_TX_TIME_MIN     (0x0148)
+#define BLE_HCI_SET_DATALEN_TX_TIME_MAX     (0x0848)
 
 /* --- LE read suggested default data length (OCF 0x0023) */
 #define BLE_HCI_RD_SUGG_DATALEN_RSPLEN      (4)


[08/12] incubator-mynewt-core git commit: Increase max_conns and max_sm_procs for UPF.

Posted by cc...@apache.org.
Increase max_conns and max_sm_procs for UPF.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c57853c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c57853c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c57853c9

Branch: refs/heads/upf54
Commit: c57853c97b56da0eea01af756f3fcd68d94794f5
Parents: c7345cc
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:44:56 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:34 2016 +0800

----------------------------------------------------------------------
 apps/bletiny/src/main.c                | 1 +
 net/nimble/include/nimble/nimble_opt.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c57853c9/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index e9c5b9b..c6c93eb 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1630,6 +1630,7 @@ main(void)
     cfg.max_gattc_procs = 2;
     cfg.max_l2cap_chans = NIMBLE_OPT(MAX_CONNECTIONS) * 3;
     cfg.max_l2cap_sig_procs = 2;
+    cfg.max_l2cap_sm_procs = 2,
     cfg.store_read_cb = store_read;
     cfg.store_write_cb = store_write;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c57853c9/net/nimble/include/nimble/nimble_opt.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/nimble_opt.h b/net/nimble/include/nimble/nimble_opt.h
index 4aad463..5739e39 100644
--- a/net/nimble/include/nimble/nimble_opt.h
+++ b/net/nimble/include/nimble/nimble_opt.h
@@ -23,7 +23,7 @@
 /** HOST / CONTROLLER: Maximum number of concurrent connections. */
 
 #ifndef NIMBLE_OPT_MAX_CONNECTIONS
-#define NIMBLE_OPT_MAX_CONNECTIONS              1
+#define NIMBLE_OPT_MAX_CONNECTIONS              2
 #endif
 
 


[06/12] incubator-mynewt-core git commit: bletiny - add "datalen" command.

Posted by cc...@apache.org.
bletiny - add "datalen" command.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/0894dacb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0894dacb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0894dacb

Branch: refs/heads/upf54
Commit: 0894dacb2fa181bfcfa1172eeb4bcf2be39e330c
Parents: 05bb917
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:27:47 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:34 2016 +0800

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  2 ++
 apps/bletiny/src/cmd.c     | 39 ++++++++++++++++++++++++++++++++++++++-
 apps/bletiny/src/main.c    |  9 +++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0894dacb/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index c5c5921..6ca6d77 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -169,6 +169,8 @@ int bletiny_set_adv_data(struct ble_hs_adv_fields *adv_fields);
 int bletiny_update_conn(uint16_t conn_handle,
                          struct ble_gap_upd_params *params);
 void bletiny_chrup(uint16_t attr_handle);
+int bletiny_datalen(uint16_t conn_handle, uint16_t tx_octets,
+                    uint16_t tx_time);
 int bletiny_l2cap_update(uint16_t conn_handle,
                           struct ble_l2cap_sig_update_params *params);
 int bletiny_sec_start(uint16_t conn_handle);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0894dacb/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 178aeca..9a3fe14 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -454,7 +454,7 @@ cmd_conn(int argc, char **argv)
 }
 
 /*****************************************************************************
- * $connect                                                                  *
+ * $chrup                                                                    *
  *****************************************************************************/
 
 static int
@@ -474,6 +474,42 @@ cmd_chrup(int argc, char **argv)
 }
 
 /*****************************************************************************
+ * $datalen                                                                  *
+ *****************************************************************************/
+
+static int
+cmd_datalen(int argc, char **argv)
+{
+    uint16_t conn_handle;
+    uint16_t tx_octets;
+    uint16_t tx_time;
+    int rc;
+
+    conn_handle = parse_arg_uint16("conn", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    tx_octets = parse_arg_long("octets", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    tx_time = parse_arg_long("time", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bletiny_datalen(conn_handle, tx_octets, tx_time);
+    if (rc != 0) {
+        console_printf("error setting data length; rc=%d\n", rc);
+        return rc;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************
  * $discover                                                                 *
  *****************************************************************************/
 
@@ -2064,6 +2100,7 @@ static struct cmd_entry cmd_b_entries[] = {
     { "adv",        cmd_adv },
     { "conn",       cmd_conn },
     { "chrup",      cmd_chrup },
+    { "datalen",    cmd_datalen },
     { "disc",       cmd_disc },
     { "find",       cmd_find },
     { "l2cap",      cmd_l2cap },

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0894dacb/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index ca80c74..f10d00a 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1371,6 +1371,15 @@ bletiny_chrup(uint16_t attr_handle)
 }
 
 int
+bletiny_datalen(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time)
+{
+    int rc;
+
+    rc = ble_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
+    return rc;
+}
+
+int
 bletiny_l2cap_update(uint16_t conn_handle,
                      struct ble_l2cap_sig_update_params *params)
 {


[04/12] incubator-mynewt-core git commit: BLE Host - More log cleanup.

Posted by cc...@apache.org.
BLE Host - More log cleanup.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b0eebf9e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b0eebf9e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b0eebf9e

Branch: refs/heads/upf54
Commit: b0eebf9efbdefa557bda73666424d747b06040f0
Parents: a056e9f
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 08:00:04 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:09 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c |  9 +++++----
 net/nimble/host/src/ble_hs_priv.h | 24 ++++++++++++------------
 2 files changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0eebf9e/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 210d421..8508240 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -440,7 +440,8 @@ ble_att_svr_tx_error_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
     rsp.baep_error_code = error_code;
 
     ble_att_error_rsp_write(dst, BLE_ATT_ERROR_RSP_SZ, &rsp);
-    BLE_ATT_LOG_CMD(1, "error rsp", conn_handle, ble_att_error_rsp_log, &rsp);
+    BLE_ATT_LOG_CMD(1, "error rsp", conn->bhc_handle,
+                    ble_att_error_rsp_log, &rsp);
 
     rc = ble_l2cap_tx(conn, chan, txom);
     txom = NULL;
@@ -1510,7 +1511,6 @@ ble_att_svr_build_read_blob_rsp(void *attr_data, int attr_len, uint16_t mtu,
         goto done;
     }
 
-    BLE_ATT_LOG_EMPTY_CMD(1, "read blob rsp", conn_handle);
     rc = 0;
 
 done:
@@ -1575,6 +1575,7 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
         err_handle = req.babq_handle;
         goto done;
     }
+    BLE_ATT_LOG_EMPTY_CMD(1, "read blob rsp", conn_handle);
 
     rc = 0;
 
@@ -2086,7 +2087,6 @@ ble_att_svr_build_write_rsp(struct os_mbuf **out_txom, uint8_t *att_err)
 
     *dst = BLE_ATT_OP_WRITE_RSP;
 
-    BLE_ATT_LOG_EMPTY_CMD(1, "write rsp", conn_handle);
     rc = 0;
 
 done:
@@ -2142,6 +2142,7 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
         err_handle = req.bawq_handle;
         goto done;
     }
+    BLE_ATT_LOG_EMPTY_CMD(1, "write rsp", conn_handle);
 
     rc = 0;
 
@@ -2687,7 +2688,6 @@ ble_att_svr_build_indicate_rsp(struct os_mbuf **out_txom)
     }
 
     ble_att_indicate_rsp_write(dst, BLE_ATT_INDICATE_RSP_SZ);
-    BLE_ATT_LOG_EMPTY_CMD(1, "indicate rsp", conn_handle);
 
     rc = 0;
 
@@ -2744,6 +2744,7 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
     if (rc != 0) {
         goto done;
     }
+    BLE_ATT_LOG_EMPTY_CMD(1, "indicate rsp", conn_handle);
 
     rc = 0;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0eebf9e/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 70f0de8..ba74b92 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -127,20 +127,20 @@ void ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb);
 
 #if LOG_LEVEL <= LOG_LEVEL_DEBUG
 
-#define BLE_HS_LOG_CMD(is_tx, cmd_type, cmd_name, conn_handle,          \
-                       log_cb, cmd) do                                  \
-{                                                                       \
-    BLE_HS_LOG(DEBUG, "%sed %s command: %s; conn=%d",                   \
-               is_tx ? "tx" : "rx", cmd_type, cmd_name);                \
-    (log_cb)(cmd);                                                      \
-    BLE_HS_LOG(DEBUG, "\n");                                            \
+#define BLE_HS_LOG_CMD(is_tx, cmd_type, cmd_name, conn_handle,                \
+                       log_cb, cmd) do                                        \
+{                                                                             \
+    BLE_HS_LOG(DEBUG, "%sed %s command: %s; conn=%d ",                        \
+               (is_tx) ? "tx" : "rx", (cmd_type), (cmd_name), (conn_handle)); \
+    (log_cb)(cmd);                                                            \
+    BLE_HS_LOG(DEBUG, "\n");                                                  \
 } while (0)
 
-#define BLE_HS_LOG_EMPTY_CMD(is_tx, cmd_type, cmd_name, conn_handle) do \
-{                                                                       \
-    BLE_HS_LOG(DEBUG, "%sed %s command: %s; conn=%d",                   \
-               is_tx ? "tx" : "rx", cmd_type, cmd_name);                \
-    BLE_HS_LOG(DEBUG, "\n");                                            \
+#define BLE_HS_LOG_EMPTY_CMD(is_tx, cmd_type, cmd_name, conn_handle) do       \
+{                                                                             \
+    BLE_HS_LOG(DEBUG, "%sed %s command: %s; conn=%d ",                        \
+               (is_tx) ? "tx" : "rx", (cmd_type), (cmd_name), (conn_handle)); \
+    BLE_HS_LOG(DEBUG, "\n");                                                  \
 } while (0)
 
 #else


[09/12] incubator-mynewt-core git commit: BLE Host - Enable data-length-change event by dflt

Posted by cc...@apache.org.
BLE Host - Enable data-length-change event by dflt


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c7345ccb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c7345ccb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c7345ccb

Branch: refs/heads/upf54
Commit: c7345ccbf11f7acd04387b061e50f1e0b7991558
Parents: 12c296a
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:43:57 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:34 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_startup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c7345ccb/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index a517f03..310c5b8 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -91,9 +91,10 @@ ble_hs_startup_le_set_evmask_tx(void)
      *     0x0000000000000008 LE Read Remote Used Features Complete Event
      *     0x0000000000000010 LE Long Term Key Request Event
      *     0x0000000000000020 LE Remote Connection Parameter Request Event
+     *     0x0000000000000040 LE Data Length Change Event
      *     0x0000000000000200 LE Enhanced Connection Complete Event
      */
-    host_hci_cmd_build_le_set_event_mask(0x000000000000023f, buf, sizeof buf);
+    host_hci_cmd_build_le_set_event_mask(0x000000000000027f, buf, sizeof buf);
     rc = ble_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;


[12/12] incubator-mynewt-core git commit: BLE Host - Always use effective addrs during SMP.

Posted by cc...@apache.org.
BLE Host - Always use effective addrs during SMP.

Prior to this change, SM procedures used identity addresses as inputs
into the crypto functions.  Now we always use the effective address (RPA
is one is being used, else public or random static).


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ae861d03
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ae861d03
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ae861d03

Branch: refs/heads/upf54
Commit: ae861d0306843f846b9b5c1442bc9c9eca8f70d9
Parents: 54850a3
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 22:38:48 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:34 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_store.h |  4 +++
 net/nimble/host/src/ble_gap.c            |  3 ++
 net/nimble/host/src/ble_hs_conn.c        | 52 +++++++++++++++++++++++++++
 net/nimble/host/src/ble_hs_conn_priv.h   |  4 +++
 net/nimble/host/src/ble_hs_misc.c        | 18 ++++++++++
 net/nimble/host/src/ble_hs_priv.h        |  2 ++
 net/nimble/host/src/ble_sm.c             | 21 ++++++-----
 net/nimble/host/src/ble_store.c          | 11 ++++++
 8 files changed, 107 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/include/host/ble_store.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_store.h b/net/nimble/host/include/host/ble_store.h
index 8af689c..e5b51aa 100644
--- a/net/nimble/host/include/host/ble_store.h
+++ b/net/nimble/host/include/host/ble_store.h
@@ -37,6 +37,10 @@
 struct ble_store_key_sec {
     /**
      * Key by peer identity address;
+     * Valid peer_addr_type values;
+     *    o BLE_ADDR_TYPE_PUBLIC
+     *    o BLE_ADDR_TYPE_RANDOM
+     *    o BLE_STORE_ADDR_TYPE_NONE
      * peer_addr_type=BLE_STORE_ADDR_TYPE_NONE means don't key off peer.
      */
     uint8_t peer_addr[6];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index abf4401..6fcd20a 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -916,6 +916,9 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
         ble_gap_slave.op = BLE_GAP_OP_NULL;
     }
 
+    memcpy(conn->our_rpa_addr, evt->local_rpa, 6);
+    memcpy(conn->peer_rpa_addr, evt->local_rpa, 6);
+
     ble_gap_conn_to_snapshot(conn, &snap);
 
     ble_hs_atomic_conn_insert(conn);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 2883f30..84081b4 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -31,6 +31,8 @@ static struct os_mempool ble_hs_conn_pool;
 
 static os_membuf_t *ble_hs_conn_elem_mem;
 
+static const uint8_t ble_hs_conn_null_addr[6];
+
 int
 ble_hs_conn_can_alloc(void)
 {
@@ -313,6 +315,56 @@ ble_hs_conn_first(void)
     return SLIST_FIRST(&ble_hs_conns);
 }
 
+void
+ble_hs_conn_peer_effective_addr(struct ble_hs_conn *conn, uint8_t *out_addr)
+{
+    switch (conn->bhc_addr_type) {
+    case BLE_ADDR_TYPE_PUBLIC:
+    case BLE_ADDR_TYPE_RANDOM:
+        memcpy(out_addr, conn->bhc_addr, 6);
+        break;
+
+    case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
+    case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
+        memcpy(out_addr, conn->peer_rpa_addr, 6);
+        break;
+
+    default:
+        BLE_HS_DBG_ASSERT(0);
+        break;
+    }
+}
+
+void
+ble_hs_conn_our_effective_addr(struct ble_hs_conn *conn,
+                               uint8_t *out_addr_type, uint8_t *out_addr)
+{
+    uint8_t ident_addr_type;
+    uint8_t *ident_addr;
+
+    ident_addr = bls_hs_priv_get_local_identity_addr(&ident_addr_type);
+
+    if (memcmp(conn->our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
+        *out_addr_type = ident_addr_type;
+        memcpy(out_addr, ident_addr, 6);
+    } else {
+        switch (ident_addr_type) {
+        case BLE_ADDR_TYPE_PUBLIC:
+            *out_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
+            break;
+
+        case BLE_ADDR_TYPE_RANDOM:
+            *out_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
+            break;
+
+        default:
+            BLE_HS_DBG_ASSERT(0);
+        }
+
+        memcpy(out_addr, conn->our_rpa_addr, 6);
+    }
+}
+
 static void
 ble_hs_conn_free_mem(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 963b200..9e3fbf2 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -75,6 +75,10 @@ struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
                                              uint16_t cid);
 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);
+void ble_hs_conn_peer_effective_addr(struct ble_hs_conn *conn,
+                                     uint8_t *out_addr);
+void ble_hs_conn_our_effective_addr(struct ble_hs_conn *conn,
+                                    uint8_t *out_addr_type, uint8_t *out_addr);
 int ble_hs_conn_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 82941d6..29438ea 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -161,3 +161,21 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
 
     return rc;
 }
+
+uint8_t
+ble_hs_misc_addr_type_to_ident(uint8_t addr_type)
+{
+    switch (addr_type) {
+    case BLE_ADDR_TYPE_PUBLIC:
+    case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
+         return BLE_ADDR_TYPE_PUBLIC;
+
+    case BLE_ADDR_TYPE_RANDOM:
+    case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
+         return BLE_ADDR_TYPE_RANDOM;
+
+    default:
+        BLE_HS_DBG_ASSERT(0);
+        return BLE_ADDR_TYPE_PUBLIC;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index ba74b92..582fff0 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -85,6 +85,7 @@ int ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
 int ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
                                     struct ble_hs_conn **out_conn,
                                     struct ble_l2cap_chan **out_chan);
+uint8_t ble_hs_misc_addr_type_to_ident(uint8_t addr_type);
 
 void ble_hs_cfg_init(struct ble_hs_cfg *cfg);
 
@@ -107,6 +108,7 @@ int ble_hs_priv_set_nrpa(void);
 void ble_hs_priv_get_nrpa(uint8_t *addr);
 void ble_hs_priv_update_identity(uint8_t *addr);
 void ble_hs_priv_update_irk(uint8_t *irk);
+uint8_t *bls_hs_priv_get_local_identity_addr(uint8_t *type);
 void bls_hs_priv_copy_local_identity_addr(uint8_t *pdst, uint8_t* addr_type);
 uint8_t *ble_hs_priv_get_local_irk(void);
 int ble_keycache_remove_irk_entry(uint8_t addr_type, uint8_t *addr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 7e6ed1f..58cd22a 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -520,6 +520,7 @@ ble_sm_addrs(struct ble_sm_proc *proc, uint8_t *out_iat, uint8_t *out_ia,
              uint8_t *out_rat, uint8_t *out_ra)
 {
     struct ble_hs_conn *conn;
+    uint8_t our_addr_type;
 
     conn = ble_hs_conn_find(proc->conn_handle);
     if (conn == NULL) {
@@ -527,13 +528,17 @@ ble_sm_addrs(struct ble_sm_proc *proc, uint8_t *out_iat, uint8_t *out_ia,
     }
 
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
-        bls_hs_priv_copy_local_identity_addr(out_ia, out_iat);
-        *out_rat = conn->bhc_addr_type;
-        memcpy(out_ra, conn->bhc_addr, 6);
+        ble_hs_conn_our_effective_addr(conn, &our_addr_type, out_ia);
+        *out_iat = ble_hs_misc_addr_type_to_ident(our_addr_type);
+
+        ble_hs_conn_peer_effective_addr(conn, out_ra);
+        *out_rat = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
     } else {
-        bls_hs_priv_copy_local_identity_addr(out_ra, out_rat);
-        *out_iat = conn->bhc_addr_type;
-        memcpy(out_ia, conn->bhc_addr, 6);
+        ble_hs_conn_our_effective_addr(conn, &our_addr_type, out_ra);
+        *out_rat = ble_hs_misc_addr_type_to_ident(our_addr_type);
+
+        ble_hs_conn_peer_effective_addr(conn, out_ia);
+        *out_iat = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
     }
 
     return 0;
@@ -558,7 +563,7 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
         peer_addr_type = proc->peer_keys.addr_type;
         memcpy(peer_addr, proc->peer_keys.addr, sizeof peer_addr);
     } else {
-        peer_addr_type = conn->bhc_addr_type;
+        peer_addr_type = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
         memcpy(peer_addr, conn->bhc_addr, sizeof peer_addr);
     }
 
@@ -2141,7 +2146,7 @@ ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
     /* Make sure a procedure isn't already in progress for this connection. */
     ble_hs_lock();
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE,
-                                  -1, NULL);
+                            -1, NULL);
     if (proc != NULL) {
         res.app_status = BLE_HS_EALREADY;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae861d03/net/nimble/host/src/ble_store.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_store.c b/net/nimble/host/src/ble_store.c
index 7db7b4a..a2de0ea 100644
--- a/net/nimble/host/src/ble_store.c
+++ b/net/nimble/host/src/ble_store.c
@@ -73,6 +73,10 @@ ble_store_read_slv_sec(struct ble_store_key_sec *key_sec,
     union ble_store_key *store_key;
     int rc;
 
+    BLE_HS_DBG_ASSERT(key_sec->peer_addr_type == BLE_ADDR_TYPE_PUBLIC ||
+                      key_sec->peer_addr_type == BLE_ADDR_TYPE_RANDOM ||
+                      key_sec->peer_addr_type == BLE_STORE_ADDR_TYPE_NONE);
+
     store_key = (void *)key_sec;
     store_value = (void *)value_sec;
     rc = ble_store_read(BLE_STORE_OBJ_TYPE_SLV_SEC, store_key, store_value);
@@ -87,6 +91,9 @@ ble_store_persist_sec(int obj_type, struct ble_store_value_sec *value_sec)
     union ble_store_key *store_key;
     int rc;
 
+    BLE_HS_DBG_ASSERT(value_sec->peer_addr_type == BLE_ADDR_TYPE_PUBLIC ||
+                      value_sec->peer_addr_type == BLE_ADDR_TYPE_RANDOM);
+
     /* If the value contains no keys, delete the corresponding entry.
      * Otherwise, write it.
      */
@@ -122,6 +129,10 @@ ble_store_read_mst_sec(struct ble_store_key_sec *key_sec,
     union ble_store_key *store_key;
     int rc;
 
+    BLE_HS_DBG_ASSERT(key_sec->peer_addr_type == BLE_ADDR_TYPE_PUBLIC ||
+                      key_sec->peer_addr_type == BLE_ADDR_TYPE_RANDOM ||
+                      key_sec->peer_addr_type == BLE_STORE_ADDR_TYPE_NONE);
+
     store_key = (void *)key_sec;
     store_value = (void *)value_sec;
     rc = ble_store_read(BLE_STORE_OBJ_TYPE_MST_SEC, store_key, store_value);


[10/12] incubator-mynewt-core git commit: BLE Host - persist irk properly when ltk not xchgd

Posted by cc...@apache.org.
BLE Host - persist irk properly when ltk not xchgd

This change addresses a bug that occurred when IRKs are exchanged during
SM key exchange, but LTKs are not exchanged.  Under these conditions,
the peer's address was not correctly associated with the persisted IRK.
The result was that subsequent IRK lookups would fail.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/54850a3c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/54850a3c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/54850a3c

Branch: refs/heads/upf54
Commit: 54850a3caf0cdf7cfd4191b0445ec9b19f336e99
Parents: c57853c
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 22:34:07 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:34 2016 +0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/54850a3c/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 32c2583..7e6ed1f 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -473,9 +473,10 @@ ble_sm_fill_store_value(uint8_t peer_addr_type, uint8_t *peer_addr,
 {
     memset(value_sec, 0, sizeof *value_sec);
 
+    value_sec->peer_addr_type = peer_addr_type;
+    memcpy(value_sec->peer_addr, peer_addr, sizeof value_sec->peer_addr);
+
     if (keys->ediv_rand_valid && keys->ltk_valid) {
-        value_sec->peer_addr_type = peer_addr_type;
-        memcpy(value_sec->peer_addr, peer_addr, sizeof value_sec->peer_addr);
         value_sec->ediv = keys->ediv;
         value_sec->rand_num = keys->rand_val;
 


[11/12] incubator-mynewt-core git commit: bletiny - Read correct mst/slv ltk for sec restart

Posted by cc...@apache.org.
bletiny - Read correct mst/slv ltk for sec restart


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/12c296ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/12c296ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/12c296ad

Branch: refs/heads/upf54
Commit: 12c296ad76f9b6a4549e58ccb9ee6ea32dad544e
Parents: 5ee73b1
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:42:48 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 7 22:40:34 2016 +0800

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/12c296ad/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index f10d00a..e9c5b9b 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -52,6 +52,7 @@
  */
 #include "../src/ble_hs_conn_priv.h"
 #include "../src/ble_hci_util_priv.h"
+#include "../src/ble_hs_atomic_priv.h"
 
 #define BSWAP16(x)  ((uint16_t)(((x) << 8) | (((x) & 0xff00) >> 8)))
 
@@ -1417,6 +1418,7 @@ bletiny_sec_restart(uint16_t conn_handle,
     struct ble_store_value_sec value_sec;
     struct ble_store_key_sec key_sec;
     struct ble_gap_conn_desc desc;
+    ble_hs_conn_flags_t conn_flags;
     int rc;
 
     if (ltk == NULL) {
@@ -1430,7 +1432,15 @@ bletiny_sec_restart(uint16_t conn_handle,
         key_sec.peer_addr_type = desc.peer_addr_type;
         memcpy(key_sec.peer_addr, desc.peer_addr, 6);
 
-        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
+        if (rc != 0) {
+            return rc;
+        }
+        if (conn_flags & BLE_HS_CONN_F_MASTER) {
+            rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        } else {
+            rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        }
         if (rc != 0) {
             return rc;
         }