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 2017/04/25 17:54:21 UTC

[6/7] incubator-mynewt-core git commit: nimble/hci: Add LE set PHY command

nimble/hci: Add LE set PHY command

With this command we can change prefered PHY for given connection


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/2210e7e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2210e7e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2210e7e1

Branch: refs/heads/bluetooth5
Commit: 2210e7e1de7a6c3c0e53380d290c763b9eacb6ab
Parents: 086c852
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Tue Apr 11 10:13:06 2017 +0200
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Wed Apr 19 11:04:09 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_hci_cmd.c   | 76 +++++++++++++++++++++++++++--
 net/nimble/host/src/ble_hs_hci_priv.h  |  3 ++
 net/nimble/include/nimble/hci_common.h |  3 ++
 3 files changed, 79 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2210e7e1/net/nimble/host/src/ble_hs_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_cmd.c b/net/nimble/host/src/ble_hs_hci_cmd.c
index 354adc1..30a7eac 100644
--- a/net/nimble/host/src/ble_hs_hci_cmd.c
+++ b/net/nimble/host/src/ble_hs_hci_cmd.c
@@ -1241,9 +1241,8 @@ ble_hs_hci_build_le_read_phy(uint16_t conn_handle, uint8_t *dst, int dst_len)
 }
 
 static int
-ble_hs_hci_cmd_body_le_set_default_phy(uint8_t tx_phys_mask,
-                                       uint8_t rx_phys_mask,
-                                       uint8_t *dst)
+ble_hs_hci_verify_le_phy_params(uint8_t tx_phys_mask, uint8_t rx_phys_mask,
+                                uint16_t phy_opts)
 {
     if (tx_phys_mask > (BLE_HCI_LE_PHY_1M_PREF_MASK |
                         BLE_HCI_LE_PHY_2M_PREF_MASK |
@@ -1257,6 +1256,24 @@ ble_hs_hci_cmd_body_le_set_default_phy(uint8_t tx_phys_mask,
         return BLE_ERR_INV_HCI_CMD_PARMS;
     }
 
+    if (phy_opts > BLE_HCI_LE_PHY_CODED_S8_PREF) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_le_set_default_phy(uint8_t tx_phys_mask,
+                                       uint8_t rx_phys_mask, uint8_t *dst)
+{
+    int rc;
+
+    rc = ble_hs_hci_verify_le_phy_params(tx_phys_mask, rx_phys_mask, 0);
+    if (rc !=0 ) {
+        return rc;
+    }
+
     if (tx_phys_mask == 0) {
         dst[0] |= BLE_HCI_LE_PHY_NO_TX_PREF_MASK;
     } else {
@@ -1294,6 +1311,59 @@ ble_hs_hci_build_le_set_default_phy(uint8_t tx_phys_mask, uint8_t rx_phys_mask,
 }
 
 static int
+ble_hs_hci_cmd_body_le_set_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
+                               uint8_t rx_phys_mask, uint16_t phy_opts,
+                               uint8_t *dst)
+{
+    int rc;
+
+    rc = ble_hs_hci_verify_le_phy_params(tx_phys_mask, rx_phys_mask, phy_opts);
+    if (rc != 0) {
+        return rc;
+    }
+
+    put_le16(dst, conn_handle);
+
+    if (tx_phys_mask == 0) {
+        dst[2] |= BLE_HCI_LE_PHY_NO_TX_PREF_MASK;
+    } else {
+        dst[3] = tx_phys_mask;
+    }
+
+    if (rx_phys_mask == 0){
+        dst[2] |= BLE_HCI_LE_PHY_NO_RX_PREF_MASK;
+    } else {
+        dst[4] = rx_phys_mask;
+    }
+
+    put_le16(dst + 5, phy_opts);
+
+    return 0;
+}
+
+/*
+ * OGF=0x08 OCF=0x0032
+ */
+int
+ble_hs_hci_build_le_set_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
+                            uint8_t rx_phys_mask, uint16_t phy_opts,
+                            uint8_t *dst, int dst_len)
+{
+
+    BLE_HS_DBG_ASSERT(
+        dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_SET_PHY_LEN);
+
+    memset(dst, 0, dst_len);
+
+    ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_PHY,
+                             BLE_HCI_LE_SET_PHY_LEN, dst);
+    dst += BLE_HCI_CMD_HDR_LEN;
+
+    return ble_hs_hci_cmd_body_le_set_phy(conn_handle, tx_phys_mask,
+                                          rx_phys_mask, phy_opts, dst);
+}
+
+static int
 ble_hs_hci_cmd_body_le_set_priv_mode(const uint8_t *addr, uint8_t addr_type,
                                      uint8_t priv_mode, uint8_t *dst)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2210e7e1/net/nimble/host/src/ble_hs_hci_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_priv.h b/net/nimble/host/src/ble_hs_hci_priv.h
index 38270a5..aff3b10 100644
--- a/net/nimble/host/src/ble_hs_hci_priv.h
+++ b/net/nimble/host/src/ble_hs_hci_priv.h
@@ -168,6 +168,9 @@ int ble_hs_hci_build_le_read_phy(uint16_t conn_handle, uint8_t *dst,
 int ble_hs_hci_build_le_set_default_phy(uint8_t tx_phys_mask,
                                         uint8_t rx_phys_mask,
                                         uint8_t *dst, int dst_len);
+int ble_hs_hci_build_le_set_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
+                                uint8_t rx_phys_mask, uint16_t phy_opts,
+                                uint8_t *dst, int dst_len);
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2210e7e1/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 5166946..689869e 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -431,6 +431,9 @@ extern "C" {
 
 /* --- LE set PHY (OCF 0x0032) */
 #define BLE_HCI_LE_SET_PHY_LEN                      (7)
+#define BLE_HCI_LE_PHY_CODED_ANY                    (0x0000)
+#define BLE_HCI_LE_PHY_CODED_S2_PREF                (0x0001)
+#define BLE_HCI_LE_PHY_CODED_S8_PREF                (0x0002)
 
 /* --- LE enhanced receiver test (OCF 0x0033) */
 #define BLE_HCI_LE_ENH_RCVR_TEST_LEN                (3)