You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/02/22 19:53:03 UTC

[mynewt-nimble] 04/05: nimble/ll: Add HCI VS command to control css

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

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

commit bf275cf3bacf934bd2fe676fce218ec4613246e5
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Feb 4 01:12:29 2022 +0100

    nimble/ll: Add HCI VS command to control css
    
    This adds hci vs command to control css parameters. The command has few
    sub-commands that allow to:
    - set slot duration and slots per period parameter
    - set slot allocation for next requested connection
    - set slot allocation for existing connection
    
    Reconfiguration of css parameters can only be done only if there are no
    active connections so we do not need to bother with moving existing
    connections around.
---
 nimble/controller/src/ble_ll_hci_vs.c | 133 ++++++++++++++++++++++++++++++++++
 nimble/controller/syscfg.yml          |   3 +
 nimble/include/nimble/hci_common.h    |  22 ++++++
 3 files changed, 158 insertions(+)

diff --git a/nimble/controller/src/ble_ll_hci_vs.c b/nimble/controller/src/ble_ll_hci_vs.c
index f2057ea..5049b39 100644
--- a/nimble/controller/src/ble_ll_hci_vs.c
+++ b/nimble/controller/src/ble_ll_hci_vs.c
@@ -134,11 +134,144 @@ ble_ll_hci_vs_set_tx_power(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen,
     return BLE_ERR_SUCCESS;
 }
 
+
+#if MYNEWT_VAL(BLE_LL_HCI_VS_CONN_STRICT_SCHED)
+static int
+ble_ll_hci_vs_css_configure(const uint8_t *cmdbuf, uint8_t cmdlen,
+                            uint8_t *rspbuf, uint8_t *rsplen)
+{
+    const struct ble_hci_vs_css_configure_cp *cmd = (const void *)cmdbuf;
+    uint32_t slot_us;
+    uint32_t period_slots;
+
+    if (cmdlen != sizeof(*cmd)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    if (!SLIST_EMPTY(&g_ble_ll_conn_active_list)) {
+        return BLE_ERR_CTLR_BUSY;
+    }
+
+    slot_us = le32toh(cmd->slot_us);
+    period_slots = le32toh(cmd->period_slots);
+
+    if (slot_us % BLE_LL_CONN_ITVL_USECS) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    if ((slot_us == 0) || (period_slots == 0)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    ble_ll_sched_css_set_params(slot_us, period_slots);
+
+    return BLE_ERR_SUCCESS;
+}
+
+static int
+ble_ll_hci_vs_css_set_next_slot(const uint8_t *cmdbuf, uint8_t cmdlen,
+                                uint8_t *rspbuf, uint8_t *rsplen)
+{
+    const struct ble_hci_vs_css_set_next_slot_cp *cmd = (const void *)cmdbuf;
+    uint16_t slot_idx;
+
+    if (cmdlen != sizeof(*cmd)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    slot_idx = le16toh(cmd->slot_idx);
+    if ((slot_idx >= ble_ll_sched_css_get_period_slots()) &&
+        (slot_idx != BLE_LL_CONN_CSS_NO_SLOT)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    if (ble_ll_conn_css_is_slot_busy(slot_idx)) {
+        return BLE_ERR_CTLR_BUSY;
+    }
+
+    ble_ll_conn_css_set_next_slot(slot_idx);
+
+    return BLE_ERR_SUCCESS;
+}
+
+static int
+ble_ll_hci_vs_css_set_conn_slot(const uint8_t *cmdbuf, uint8_t cmdlen,
+                                uint8_t *rspbuf, uint8_t *rsplen)
+{
+    const struct ble_hci_vs_css_set_conn_slot_cp *cmd = (const void *)cmdbuf;
+    struct ble_ll_conn_sm *connsm;
+    uint16_t conn_handle;
+    uint16_t slot_idx;
+
+    if (cmdlen != sizeof(*cmd)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    slot_idx = le16toh(cmd->slot_idx);
+    if ((slot_idx >= ble_ll_sched_css_get_period_slots()) &&
+        (slot_idx != BLE_LL_CONN_CSS_NO_SLOT)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    if (ble_ll_conn_css_is_slot_busy(slot_idx)) {
+        return BLE_ERR_CTLR_BUSY;
+    }
+
+    conn_handle = le16toh(cmd->conn_handle);
+    connsm = ble_ll_conn_find_active_conn(conn_handle);
+    if (!connsm) {
+        return BLE_ERR_UNK_CONN_ID;
+    }
+
+    if (connsm->css_slot_idx_pending != BLE_LL_CONN_CSS_NO_SLOT) {
+        return BLE_ERR_DIFF_TRANS_COLL;
+    }
+
+    if (connsm->css_slot_idx == slot_idx) {
+        return BLE_ERR_CMD_DISALLOWED;
+    }
+
+    if (ble_ll_conn_css_move(connsm, slot_idx) < 0) {
+        return BLE_ERR_CTLR_BUSY;
+    }
+
+    return BLE_ERR_SUCCESS;
+}
+
+static int
+ble_ll_hci_vs_css(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen,
+                  uint8_t *rspbuf, uint8_t *rsplen)
+{
+    const struct ble_hci_vs_css_cp *cmd = (const void *)cmdbuf;
+
+    if (cmdlen < sizeof(*cmd)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    *rsplen = 0;
+
+    switch (cmd->opcode) {
+    case BLE_HCI_VS_CSS_OP_CONFIGURE:
+        return ble_ll_hci_vs_css_configure(cmdbuf, cmdlen, rspbuf, rsplen);
+    case BLE_HCI_VS_CSS_OP_SET_NEXT_SLOT:
+        return ble_ll_hci_vs_css_set_next_slot(cmdbuf, cmdlen, rspbuf, rsplen);
+    case BLE_HCI_VS_CSS_OP_SET_CONN_SLOT:
+        return ble_ll_hci_vs_css_set_conn_slot(cmdbuf, cmdlen, rspbuf, rsplen);
+    }
+
+    return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+#endif
+
 static struct ble_ll_hci_vs_cmd g_ble_ll_hci_vs_cmds[] = {
     BLE_LL_HCI_VS_CMD(BLE_HCI_OCF_VS_RD_STATIC_ADDR,
                       ble_ll_hci_vs_rd_static_addr),
     BLE_LL_HCI_VS_CMD(BLE_HCI_OCF_VS_SET_TX_PWR,
             ble_ll_hci_vs_set_tx_power),
+#if MYNEWT_VAL(BLE_LL_HCI_VS_CONN_STRICT_SCHED)
+    BLE_LL_HCI_VS_CMD(BLE_HCI_OCF_VS_CSS,
+                      ble_ll_hci_vs_css),
+#endif
 };
 
 static struct ble_ll_hci_vs_cmd *
diff --git a/nimble/controller/syscfg.yml b/nimble/controller/syscfg.yml
index de6b5ea..8f08dd7 100644
--- a/nimble/controller/syscfg.yml
+++ b/nimble/controller/syscfg.yml
@@ -363,6 +363,9 @@ syscfg.defs:
         description: >
             Enables support for vendor-specific HCI commands.
         value: MYNEWT_VAL(BLE_HCI_VS)
+    BLE_LL_HCI_VS_CONN_STRICT_SCHED:
+        description: xxx
+        value: 0
 
     BLE_LL_HCI_VS_EVENT_ON_ASSERT:
         description: >
diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h
index 32d06b6..8faebe4 100644
--- a/nimble/include/nimble/hci_common.h
+++ b/nimble/include/nimble/hci_common.h
@@ -1079,6 +1079,28 @@ struct ble_hci_vs_set_tx_pwr_rp {
     int8_t tx_power;
 } __attribute__((packed));
 
+#define BLE_HCI_OCF_VS_CSS                              (0x0003)
+struct ble_hci_vs_css_cp {
+    uint8_t opcode;
+} __attribute__((packed));
+#define BLE_HCI_VS_CSS_OP_CONFIGURE                     0x01
+struct ble_hci_vs_css_configure_cp {
+    uint8_t opcode;
+    uint32_t slot_us;
+    uint32_t period_slots;
+} __attribute__((packed));
+#define BLE_HCI_VS_CSS_OP_SET_NEXT_SLOT                 0x02
+struct ble_hci_vs_css_set_next_slot_cp {
+    uint8_t opcode;
+    uint16_t slot_idx;
+} __attribute__((packed));
+#define BLE_HCI_VS_CSS_OP_SET_CONN_SLOT                 0x03
+struct ble_hci_vs_css_set_conn_slot_cp {
+    uint8_t opcode;
+    uint16_t conn_handle;
+    uint16_t slot_idx;
+} __attribute__((packed));
+
 /* Command Specific Definitions */
 /* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */
 #define BLE_HCI_CTLR_TO_HOST_FC_OFF         (0)