You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2022/06/29 11:56:40 UTC

[mynewt-nimble] branch master updated: Support for read and write suggested datalen cmds

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d4d4f0d5 Support for read and write suggested datalen cmds
d4d4f0d5 is described below

commit d4d4f0d5f4b3c42f38778097488d0be880e8914a
Author: Onkar <on...@espressif.com>
AuthorDate: Fri Apr 29 12:02:02 2022 +0530

    Support for read and write suggested datalen cmds
---
 nimble/host/include/host/ble_gap.h | 54 +++++++++++++++++++++++++++++++-----
 nimble/host/src/ble_gap.c          | 24 ++++++++++++++--
 nimble/host/src/ble_hs_hci_priv.h  |  4 +++
 nimble/host/src/ble_hs_hci_util.c  | 56 ++++++++++++++++++++++++++++++++++++++
 nimble/include/nimble/hci_common.h |  6 ++++
 5 files changed, 134 insertions(+), 10 deletions(-)

diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h
index d27b7f82..83aacacd 100644
--- a/nimble/host/include/host/ble_gap.h
+++ b/nimble/host/include/host/ble_gap.h
@@ -1889,17 +1889,57 @@ int ble_gap_update_params(uint16_t conn_handle,
  * Configure LE Data Length in controller (OGF = 0x08, OCF = 0x0022).
  *
  * @param conn_handle      Connection handle.
- * @param tx_octets        The preferred value of payload octets that the Controller
- *                         should use for a new connection (Range
- *                         0x001B-0x00FB).
- * @param tx_time          The preferred maximum number of microseconds that the local Controller
- *                         should use to transmit a single link layer packet
- *                         (Range 0x0148-0x4290).
+ * @param tx_octets        The preferred value of payload octets that the
+ *                         Controller should use for a new connection
+ *                         (Range 0x001B-0x00FB).
+ * @param tx_time          The preferred maximum number of microseconds that
+ *                         the local Controller should use to transmit a single
+ *                         link layer packet (Range 0x0148-0x4290).
  *
  * @return                 0 on success,
  *                         other error code on failure.
  */
-int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time);
+int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
+                         uint16_t tx_time);
+
+/**
+ * Read LE Suggested Default Data Length in controller
+ * (OGF = 0x08, OCF = 0x0024).
+ *
+ * @param out_sugg_max_tx_octets    The Host's suggested value for the
+ *                                  Controller's maximum transmitted number of
+ *                                  payload octets in LL Data PDUs to be used
+ *                                  for new connections. (Range 0x001B-0x00FB).
+ * @param out_sugg_max_tx_time      The Host's suggested value for the
+ *                                  Controller's maximum packet transmission
+ *                                  time for packets containing LL Data PDUs to
+ *                                  be used for new connections.
+ *                                  (Range 0x0148-0x4290).
+ *
+ * @return                          0 on success,
+ *                                  other error code on failure.
+ */
+int ble_gap_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
+                                   uint16_t *out_sugg_max_tx_time);
+
+/**
+ * Configure LE Suggested Default Data Length in controller
+ * (OGF = 0x08, OCF = 0x0024).
+ *
+ * @param sugg_max_tx_octets    The Host's suggested value for the Controller's
+ *                              maximum transmitted number of payload octets in
+ *                              LL Data PDUs to be used for new connections.
+ *                              (Range 0x001B-0x00FB).
+ * @param sugg_max_tx_time      The Host's suggested value for the Controller's
+ *                              maximum packet transmission time for packets
+ *                              containing LL Data PDUs to be used for new
+ *                              connections. (Range 0x0148-0x4290).
+ *
+ * @return                      0 on success,
+ *                              other error code on failure.
+ */
+int ble_gap_write_sugg_def_data_len(uint16_t sugg_max_tx_octets,
+                                    uint16_t sugg_max_tx_time);
 
 /**
  * Initiates the GAP security procedure.
diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c
index 113a972d..ed959957 100644
--- a/nimble/host/src/ble_gap.c
+++ b/nimble/host/src/ble_gap.c
@@ -5590,14 +5590,32 @@ done:
 #endif
 }
 
-int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time)
+int
+ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
+                     uint16_t tx_time)
 {
     return ble_hs_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
 }
 
+int
+ble_gap_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
+                               uint16_t *out_sugg_max_tx_time)
+{
+    return ble_hs_hci_util_read_sugg_def_data_len(out_sugg_max_tx_octets,
+                                                  out_sugg_max_tx_time);
+}
+
+int
+ble_gap_write_sugg_def_data_len(uint16_t sugg_max_tx_octets,
+                                uint16_t sugg_max_tx_time)
+{
+    return ble_hs_hci_util_write_sugg_def_data_len(sugg_max_tx_octets,
+                                                   sugg_max_tx_time);
+}
+
 /*****************************************************************************
- * $security                                                                 *
- *****************************************************************************/
+* $security                                                                  *
+*****************************************************************************/
 int
 ble_gap_security_initiate(uint16_t conn_handle)
 {
diff --git a/nimble/host/src/ble_hs_hci_priv.h b/nimble/host/src/ble_hs_hci_priv.h
index 47f32008..9ff4c6f0 100644
--- a/nimble/host/src/ble_hs_hci_priv.h
+++ b/nimble/host/src/ble_hs_hci_priv.h
@@ -103,6 +103,10 @@ int ble_hs_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
 int ble_hs_hci_util_set_random_addr(const uint8_t *addr);
 int ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
                                  uint16_t tx_time);
+int ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
+                                           uint16_t *out_sugg_max_tx_time);
+int ble_hs_hci_util_write_sugg_def_data_len(uint16_t sugg_max_tx_octets,
+                                            uint16_t sugg_max_tx_time);
 int ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
                                    struct hci_data_hdr *out_hdr);
 int ble_hs_hci_evt_process(struct ble_hci_ev *ev);
diff --git a/nimble/host/src/ble_hs_hci_util.c b/nimble/host/src/ble_hs_hci_util.c
index 996e0fc1..14e55d52 100644
--- a/nimble/host/src/ble_hs_hci_util.c
+++ b/nimble/host/src/ble_hs_hci_util.c
@@ -157,6 +157,62 @@ ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
     return 0;
 }
 
+int
+ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
+                                       uint16_t *out_sugg_max_tx_time)
+{
+    struct ble_hci_le_rd_sugg_def_data_len_rp rsp;
+    int rc;
+
+    rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
+                                      BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN),
+                           NULL, 0, &rsp, sizeof(rsp));
+    if (rc != 0) {
+        return rc;
+    }
+
+    *out_sugg_max_tx_octets = le16toh(rsp.max_tx_octets);
+    *out_sugg_max_tx_time = le16toh(rsp.max_tx_time);
+
+    if (*out_sugg_max_tx_octets < BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN ||
+        *out_sugg_max_tx_octets > BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX) {
+        BLE_HS_LOG(WARN,
+                   "received suggested maximum tx octets is out of range\n");
+    }
+
+    if (*out_sugg_max_tx_time < BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN ||
+        *out_sugg_max_tx_time > BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX) {
+        BLE_HS_LOG(WARN,
+                   "received suggested maximum tx time is out of range\n");
+    }
+
+    return 0;
+}
+
+int
+ble_hs_hci_util_write_sugg_def_data_len(uint16_t sugg_max_tx_octets,
+                                        uint16_t sugg_max_tx_time)
+{
+    struct ble_hci_le_wr_sugg_def_data_len_cp cmd;
+
+    if (sugg_max_tx_octets < BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN ||
+        sugg_max_tx_octets > BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX) {
+        return BLE_HS_EINVAL;
+    }
+
+    if (sugg_max_tx_time < BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN ||
+        sugg_max_tx_time > BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX) {
+        return BLE_HS_EINVAL;
+    }
+
+    cmd.max_tx_octets = htole16(sugg_max_tx_octets);
+    cmd.max_tx_time = htole16(sugg_max_tx_time);
+
+    return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
+                                        BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN),
+                             &cmd, sizeof(cmd), NULL, 0);
+}
+
 int
 ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
                                struct hci_data_hdr *out_hdr)
diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h
index 881fe745..17fa7627 100644
--- a/nimble/include/nimble/hci_common.h
+++ b/nimble/include/nimble/hci_common.h
@@ -1320,6 +1320,12 @@ struct ble_hci_le_set_transmit_power_report_enable_cp {
 #define BLE_HCI_SET_DATALEN_TX_TIME_MIN     (0x0148)
 #define BLE_HCI_SET_DATALEN_TX_TIME_MAX     (0x4290)
 
+/* --- LE read/write suggested default data length (OCF 0x0023 and 0x0024) */
+#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN      (0x001b)
+#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX      (0x00fb)
+#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN        (0x0148)
+#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX        (0x4290)
+
 /* --- LE read maximum default PHY (OCF 0x0030) */
 #define BLE_HCI_LE_PHY_1M                   (1)
 #define BLE_HCI_LE_PHY_2M                   (2)