You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ry...@apache.org on 2020/01/28 09:43:30 UTC
[mynewt-nimble] 04/04: nimble/ll: Add hci set host supported
features
This is an automated email from the ASF dual-hosted git repository.
rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 96cabb982247b944b57d9f234de57c54380bb3e7
Author: Ćukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Thu Jan 2 11:06:33 2020 +0100
nimble/ll: Add hci set host supported features
With this patch, host is able to set features flags with HCI
command from Bluetooth v5.2
---
nimble/controller/include/controller/ble_ll.h | 71 ++++++++++++++++-----------
nimble/controller/src/ble_ll.c | 43 ++++++++++++++++
nimble/controller/src/ble_ll_hci.c | 5 ++
nimble/include/nimble/hci_common.h | 6 +++
4 files changed, 96 insertions(+), 29 deletions(-)
diff --git a/nimble/controller/include/controller/ble_ll.h b/nimble/controller/include/controller/ble_ll.h
index 99c0eba..d334044 100644
--- a/nimble/controller/include/controller/ble_ll.h
+++ b/nimble/controller/include/controller/ble_ll.h
@@ -199,34 +199,42 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats;
#define BLE_LL_STATE_SYNC (6)
/* LL Features */
-#define BLE_LL_FEAT_LE_ENCRYPTION (0x00000001)
-#define BLE_LL_FEAT_CONN_PARM_REQ (0x00000002)
-#define BLE_LL_FEAT_EXTENDED_REJ (0x00000004)
-#define BLE_LL_FEAT_SLAVE_INIT (0x00000008)
-#define BLE_LL_FEAT_LE_PING (0x00000010)
-#define BLE_LL_FEAT_DATA_LEN_EXT (0x00000020)
-#define BLE_LL_FEAT_LL_PRIVACY (0x00000040)
-#define BLE_LL_FEAT_EXT_SCAN_FILT (0x00000080)
-#define BLE_LL_FEAT_LE_2M_PHY (0x00000100)
-#define BLE_LL_FEAT_STABLE_MOD_ID_TX (0x00000200)
-#define BLE_LL_FEAT_STABLE_MOD_ID_RX (0x00000400)
-#define BLE_LL_FEAT_LE_CODED_PHY (0x00000800)
-#define BLE_LL_FEAT_EXT_ADV (0x00001000)
-#define BLE_LL_FEAT_PERIODIC_ADV (0x00002000)
-#define BLE_LL_FEAT_CSA2 (0x00004000)
-#define BLE_LL_FEAT_LE_POWER_CLASS_1 (0x00008000)
-#define BLE_LL_FEAT_MIN_USED_CHAN (0x00010000)
-#define BLE_LL_FEAT_CTE_REQ (0x00020000)
-#define BLE_LL_FEAT_CTE_RSP (0x00040000)
-#define BLE_LL_FEAT_CTE_TX (0x00080000)
-#define BLE_LL_FEAT_CTE_RX (0x00100000)
-#define BLE_LL_FEAT_CTE_AOD (0x00200000)
-#define BLE_LL_FEAT_CTE_AOA (0x00400000)
-#define BLE_LL_FEAT_CTE_RECV (0x00800000)
-#define BLE_LL_FEAT_SYNC_TRANS_SEND (0x01000000)
-#define BLE_LL_FEAT_SYNC_TRANS_RECV (0x02000000)
-#define BLE_LL_FEAT_SCA_UPDATE (0x04000000)
-#define BLE_LL_FEAT_REM_PKEY (0x08000000)
+#define BLE_LL_FEAT_LE_ENCRYPTION (0x0000000001)
+#define BLE_LL_FEAT_CONN_PARM_REQ (0x0000000002)
+#define BLE_LL_FEAT_EXTENDED_REJ (0x0000000004)
+#define BLE_LL_FEAT_SLAVE_INIT (0x0000000008)
+#define BLE_LL_FEAT_LE_PING (0x0000000010)
+#define BLE_LL_FEAT_DATA_LEN_EXT (0x0000000020)
+#define BLE_LL_FEAT_LL_PRIVACY (0x0000000040)
+#define BLE_LL_FEAT_EXT_SCAN_FILT (0x0000000080)
+#define BLE_LL_FEAT_LE_2M_PHY (0x0000000100)
+#define BLE_LL_FEAT_STABLE_MOD_ID_TX (0x0000000200)
+#define BLE_LL_FEAT_STABLE_MOD_ID_RX (0x0000000400)
+#define BLE_LL_FEAT_LE_CODED_PHY (0x0000000800)
+#define BLE_LL_FEAT_EXT_ADV (0x0000001000)
+#define BLE_LL_FEAT_PERIODIC_ADV (0x0000002000)
+#define BLE_LL_FEAT_CSA2 (0x0000004000)
+#define BLE_LL_FEAT_LE_POWER_CLASS_1 (0x0000008000)
+#define BLE_LL_FEAT_MIN_USED_CHAN (0x0000010000)
+#define BLE_LL_FEAT_CTE_REQ (0x0000020000)
+#define BLE_LL_FEAT_CTE_RSP (0x0000040000)
+#define BLE_LL_FEAT_CTE_TX (0x0000080000)
+#define BLE_LL_FEAT_CTE_RX (0x0000100000)
+#define BLE_LL_FEAT_CTE_AOD (0x0000200000)
+#define BLE_LL_FEAT_CTE_AOA (0x0000400000)
+#define BLE_LL_FEAT_CTE_RECV (0x0000800000)
+#define BLE_LL_FEAT_SYNC_TRANS_SEND (0x0001000000)
+#define BLE_LL_FEAT_SYNC_TRANS_RECV (0x0002000000)
+#define BLE_LL_FEAT_SCA_UPDATE (0x0004000000)
+#define BLE_LL_FEAT_REM_PKEY (0x0008000000)
+#define BLE_LL_FEAT_CIS_MASTER (0x0010000000)
+#define BLE_LL_FEAT_CIS_SLAVE (0x0020000000)
+#define BLE_LL_FEAT_ISO_BROADCASTER (0x0040000000)
+#define BLE_LL_FEAT_SYNC_RECV (0x0080000000)
+#define BLE_LL_FEAT_ISO_HOST_SUPPORT (0x0100000000)
+#define BLE_LL_FEAT_POWER_CTRL_REQ (0x0200000000)
+#define BLE_LL_FEAT_POWER_CHANGE_IND (0x0400000000)
+#define BLE_LL_FEAT_PATH_LOSS_MON (0x0800000000)
/* This is initial mask, so if feature exchange will not happen,
* but host will want to use this procedure, we will try. If not
@@ -234,9 +242,11 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats;
* Look at LL Features above to find out what is allowed
*/
#define BLE_LL_CONN_INITIAL_FEATURES (0x00000022)
-
#define BLE_LL_CONN_CLEAR_FEATURE(connsm, feature) (connsm->conn_features &= ~(feature))
+/* All the features which can be controlled by the Host */
+#define BLE_LL_HOST_CONTROLLED_FEATURES (BLE_LL_FEAT_ISO_HOST_SUPPORT)
+
/* LL timing */
#define BLE_LL_IFS (150) /* usecs */
#define BLE_LL_MAFS (300) /* usecs */
@@ -519,6 +529,9 @@ void ble_ll_wfr_timer_exp(void *arg);
/* Read set of features supported by the Link Layer */
uint64_t ble_ll_read_supp_features(void);
+/* Set host supported features */
+int ble_ll_set_host_feat(const uint8_t *cmdbuf, uint8_t len);
+
/* Read set of states supported by the Link Layer */
uint64_t ble_ll_read_supp_states(void);
diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 8b1fb98..996ad9c 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -247,6 +247,9 @@ uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
/** Our random address */
uint8_t g_random_addr[BLE_DEV_ADDR_LEN];
+/** Our supported features which can be controller by the host */
+uint64_t g_ble_ll_supported_host_features = 0;
+
static const uint16_t g_ble_ll_pdu_header_tx_time[BLE_PHY_NUM_MODE] =
{
[BLE_PHY_MODE_1M] =
@@ -1278,6 +1281,46 @@ ble_ll_read_supp_features(void)
}
/**
+ * Sets the features controlled by the host.
+ *
+ * @return HCI command status
+ */
+int
+ble_ll_set_host_feat(const uint8_t *cmdbuf, uint8_t len)
+{
+ const struct ble_hci_le_set_host_feat_cp *cmd = (const void *) cmdbuf;
+ uint64_t mask;
+
+ if (len != sizeof(*cmd)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ if (!SLIST_EMPTY(&g_ble_ll_conn_active_list)) {
+ return BLE_ERR_CMD_DISALLOWED;
+ }
+
+ if ((cmd->bit_num > 0x3F) || (cmd->val > 1)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ mask = (uint64_t)1 << (cmd->bit_num);
+ if (!(mask & BLE_LL_HOST_CONTROLLED_FEATURES)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ if (!(mask & g_ble_ll_supported_host_features)) {
+ return BLE_ERR_UNSUPPORTED;
+ }
+
+ if (cmd->val == 0) {
+ g_ble_ll_data.ll_supp_features &= ~(mask);
+ } else {
+ g_ble_ll_data.ll_supp_features |= mask;
+ }
+
+ return BLE_ERR_SUCCESS;
+}
+/**
* Flush a link layer packet queue.
*
* @param pktq
diff --git a/nimble/controller/src/ble_ll_hci.c b/nimble/controller/src/ble_ll_hci.c
index 50027ac..e90c42f 100644
--- a/nimble/controller/src/ble_ll_hci.c
+++ b/nimble/controller/src/ble_ll_hci.c
@@ -1144,6 +1144,11 @@ ble_ll_hci_le_cmd_proc(const uint8_t *cmdbuf, uint8_t len, uint16_t ocf,
rc = ble_ll_set_default_sync_transfer_params(cmdbuf, len);
break;
#endif
+#if MYNEWT_VAL(BLE_VERSION) >= 52
+ case BLE_HCI_OCF_LE_SET_HOST_FEAT:
+ rc = ble_ll_set_host_feat(cmdbuf, len);
+ break;
+#endif
default:
rc = BLE_ERR_UNKNOWN_HCI_CMD;
break;
diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h
index d138c81..c79abb3 100644
--- a/nimble/include/nimble/hci_common.h
+++ b/nimble/include/nimble/hci_common.h
@@ -825,6 +825,12 @@ struct ble_hci_le_set_default_periodic_sync_transfer_params_cp {
#define BLE_HCI_OCF_LE_GENERATE_DHKEY_V2 (0x005E)
#define BLE_HCI_OCF_LE_MODIFY_SCA (0x005F)
+#define BLE_HCI_OCF_LE_SET_HOST_FEAT (0x0074)
+struct ble_hci_le_set_host_feat_cp {
+ uint8_t bit_num;
+ uint8_t val;
+} __attribute__((packed));
+
/* Command Specific Definitions */
/* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */
#define BLE_HCI_CTLR_TO_HOST_FC_OFF (0)