mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [07/12] incubator-mynewt-core git commit: BLE Host - set data length HCI command.
Date Tue, 07 Jun 2016 14:41:14 GMT
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 <ccollins@apache.org>
Authored: Tue Jun 7 18:37:01 2016 +0800
Committer: Christopher Collins <ccollins@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)


Mime
View raw message