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/11/02 14:24:07 UTC

[mynewt-nimble] branch master updated (36406e05 -> ae414aa5)

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

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


    from 36406e05 nimble/ll/css: Fix scheduling 1st conn event
     new 98a683e1 nimble/host: Add support for enabling controller DTM
     new 183dbf49 nimble/ll: Add helper for checking if controller is busy
     new 50a993f1 nimble/ll: Use common helper for checking if allowed to set TX power
     new 5a9b202a nimble/ll: Don't allow to enable DTM if controller is busy
     new ae414aa5 nimble/ll: Disallow HCI commands if DTM test is enabled

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nimble/controller/src/ble_ll.c                     | 46 ++++++++++++++
 nimble/controller/src/ble_ll_dtm.c                 | 10 ++-
 nimble/controller/src/ble_ll_dtm_priv.h            |  1 +
 nimble/controller/src/ble_ll_hci.c                 | 18 +++++-
 nimble/controller/src/ble_ll_hci_vs.c              | 54 +---------------
 nimble/controller/src/ble_ll_priv.h                |  5 ++
 .../gatt/ble_svc_gatt.h => include/host/ble_dtm.h} | 25 +++++---
 nimble/host/src/ble_dtm.c                          | 71 ++++++++++++++++++++++
 8 files changed, 167 insertions(+), 63 deletions(-)
 copy nimble/host/{services/gatt/include/services/gatt/ble_svc_gatt.h => include/host/ble_dtm.h} (68%)
 create mode 100644 nimble/host/src/ble_dtm.c


[mynewt-nimble] 03/05: nimble/ll: Use common helper for checking if allowed to set TX power

Posted by ja...@apache.org.
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

commit 50a993f1b8ebe224da905d24644435f7c7a842c1
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Fri Oct 28 09:53:12 2022 +0200

    nimble/ll: Use common helper for checking if allowed to set TX power
    
    No need for local helper.
---
 nimble/controller/src/ble_ll_hci_vs.c | 54 ++---------------------------------
 1 file changed, 2 insertions(+), 52 deletions(-)

diff --git a/nimble/controller/src/ble_ll_hci_vs.c b/nimble/controller/src/ble_ll_hci_vs.c
index 9f7fb185..3f373c42 100644
--- a/nimble/controller/src/ble_ll_hci_vs.c
+++ b/nimble/controller/src/ble_ll_hci_vs.c
@@ -57,56 +57,6 @@ ble_ll_hci_vs_rd_static_addr(uint16_t ocf,
     return BLE_ERR_SUCCESS;
 }
 
-/* disallow changing TX power if there is any radio activity
- * note: we could allow to change it if there is no TX activity (eg only
- * passive scan or sync) but lets just keep this simple for now
- */
-static int
-ble_ll_hci_vs_is_controller_busy(void)
-{
-#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
-    struct ble_ll_conn_sm *cur;
-    int i = 0;
-#endif
-
-#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV) && MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
-    if (ble_ll_sync_enabled()) {
-        return 1;
-    }
-#endif
-
-#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER)
-    if (ble_ll_adv_enabled()) {
-        return 1;
-    }
-#endif
-
-#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
-    if (ble_ll_scan_enabled()) {
-        return 1;
-    }
-#endif
-
-#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
-    if (g_ble_ll_conn_create_sm.connsm) {
-        return 1;
-    }
-#endif
-
-#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
-    STAILQ_FOREACH(cur, &g_ble_ll_conn_free_list, free_stqe) {
-        i++;
-    }
-
-    /* check if all connection objects are free */
-    if (i < MYNEWT_VAL(BLE_MAX_CONNECTIONS)) {
-        return 1;
-    }
-#endif
-
-    return 0;
-}
-
 static int
 ble_ll_hci_vs_set_tx_power(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen,
                            uint8_t *rspbuf, uint8_t *rsplen)
@@ -118,7 +68,7 @@ ble_ll_hci_vs_set_tx_power(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen,
         return BLE_ERR_INV_HCI_CMD_PARMS;
     }
 
-    if (ble_ll_hci_vs_is_controller_busy()) {
+    if (ble_ll_is_busy()) {
         return BLE_ERR_CMD_DISALLOWED;
     }
 
@@ -367,7 +317,7 @@ ble_ll_hci_vs_set_antenna(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen,
         return BLE_ERR_INV_HCI_CMD_PARMS;
     }
 
-    if (ble_ll_hci_vs_is_controller_busy()) {
+    if (ble_ll_is_busy()) {
         return BLE_ERR_CMD_DISALLOWED;
     }
 


[mynewt-nimble] 04/05: nimble/ll: Don't allow to enable DTM if controller is busy

Posted by ja...@apache.org.
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

commit 5a9b202a0d0ead9bc03adcd83addbe9bf72c2f81
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Fri Oct 28 09:53:54 2022 +0200

    nimble/ll: Don't allow to enable DTM if controller is busy
    
    DTM disables whitening and should not be mixed with any normal
    BLE traffic.
---
 nimble/controller/src/ble_ll_dtm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/nimble/controller/src/ble_ll_dtm.c b/nimble/controller/src/ble_ll_dtm.c
index 2a32ccca..352a380a 100644
--- a/nimble/controller/src/ble_ll_dtm.c
+++ b/nimble/controller/src/ble_ll_dtm.c
@@ -483,7 +483,7 @@ ble_ll_dtm_tx_test(uint8_t tx_chan, uint8_t len, uint8_t packet_payload,
 {
     uint8_t phy_mode;
 
-    if (g_ble_ll_dtm_ctx.active) {
+    if (g_ble_ll_dtm_ctx.active || ble_ll_is_busy()) {
         return BLE_ERR_CTLR_BUSY;
     }
 
@@ -585,7 +585,7 @@ ble_ll_dtm_rx_test(uint8_t rx_chan, uint8_t hci_phy)
 {
     uint8_t phy_mode;
 
-    if (g_ble_ll_dtm_ctx.active) {
+    if (g_ble_ll_dtm_ctx.active || ble_ll_is_busy()) {
         return BLE_ERR_CTLR_BUSY;
     }
 


[mynewt-nimble] 01/05: nimble/host: Add support for enabling controller DTM

Posted by ja...@apache.org.
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

commit 98a683e1b4f3d8c8847ad5790c2e16b11899c5ee
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Wed Oct 26 13:07:03 2022 +0200

    nimble/host: Add support for enabling controller DTM
    
    This allows to controll DTM from application.
---
 nimble/host/include/host/ble_dtm.h | 49 ++++++++++++++++++++++++++
 nimble/host/src/ble_dtm.c          | 71 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)

diff --git a/nimble/host/include/host/ble_dtm.h b/nimble/host/include/host/ble_dtm.h
new file mode 100644
index 00000000..e340a306
--- /dev/null
+++ b/nimble/host/include/host/ble_dtm.h
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_DTM_
+#define H_BLE_DTM_
+
+#include <inttypes.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ble_dtm_rx_params {
+    uint8_t channel;
+    uint8_t phy;
+    uint8_t modulation_index;
+};
+
+int ble_dtm_rx_start(const struct ble_dtm_rx_params *params);
+
+struct ble_dtm_tx_params {
+    uint8_t channel;
+    uint8_t test_data_len;
+    uint8_t payload;
+    uint8_t phy;
+};
+int ble_dtm_tx_start(const struct ble_dtm_tx_params *params);
+
+int ble_dtm_stop(uint16_t *num_packets);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/nimble/host/src/ble_dtm.c b/nimble/host/src/ble_dtm.c
new file mode 100644
index 00000000..d88bee27
--- /dev/null
+++ b/nimble/host/src/ble_dtm.c
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <nimble/hci_common.h>
+#include <host/ble_dtm.h>
+#include <os/endian.h>
+#include "ble_hs_hci_priv.h"
+
+int
+ble_dtm_rx_start(const struct ble_dtm_rx_params *params)
+{
+    struct ble_hci_le_rx_test_v2_cp cmd;
+
+    cmd.rx_chan = params->channel;
+    cmd.phy = params->phy;
+    cmd.index = params->modulation_index;
+
+    return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
+                                        BLE_HCI_OCF_LE_RX_TEST_V2),
+                             &cmd, sizeof(cmd), NULL, 0);
+}
+
+int
+ble_dtm_tx_start(const struct ble_dtm_tx_params *params)
+{
+    struct ble_hci_le_tx_test_v2_cp cmd;
+
+    cmd.tx_chan = params->channel;
+    cmd.test_data_len = params->test_data_len;
+    cmd.payload = params->payload;
+    cmd.phy = params->phy;
+
+    return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
+                                        BLE_HCI_OCF_LE_TX_TEST_V2),
+                             &cmd, sizeof(cmd), NULL, 0);
+}
+
+int
+ble_dtm_stop(uint16_t *num_packets)
+{
+    struct ble_hci_le_test_end_rp rsp;
+    int rc;
+
+    rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
+                                      BLE_HCI_OCF_LE_TEST_END),
+                           NULL, 0, &rsp, sizeof(rsp));
+
+    if (rc) {
+        *num_packets = 0;
+    } else {
+        *num_packets = le16toh(rsp.num_packets);
+    }
+
+    return rc;
+}


[mynewt-nimble] 05/05: nimble/ll: Disallow HCI commands if DTM test is enabled

Posted by ja...@apache.org.
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

commit ae414aa597a0da5591cbb37b7c48f2f82f755cc9
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Fri Oct 28 10:13:40 2022 +0200

    nimble/ll: Disallow HCI commands if DTM test is enabled
    
    If DTM is enabled we should not allow for other activities. To keep
    things simple just disallow all commands except LE Test End and Reset.
---
 nimble/controller/src/ble_ll_dtm.c      |  6 ++++++
 nimble/controller/src/ble_ll_dtm_priv.h |  1 +
 nimble/controller/src/ble_ll_hci.c      | 18 +++++++++++++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/nimble/controller/src/ble_ll_dtm.c b/nimble/controller/src/ble_ll_dtm.c
index 352a380a..705d5b25 100644
--- a/nimble/controller/src/ble_ll_dtm.c
+++ b/nimble/controller/src/ble_ll_dtm.c
@@ -705,6 +705,12 @@ ble_ll_dtm_reset(void)
     ble_ll_dtm_ctx_free(&g_ble_ll_dtm_ctx);
 }
 
+int
+ble_ll_dtm_enabled(void)
+{
+    return g_ble_ll_dtm_ctx.active;
+}
+
 void
 ble_ll_dtm_init(void)
 {
diff --git a/nimble/controller/src/ble_ll_dtm_priv.h b/nimble/controller/src/ble_ll_dtm_priv.h
index e04af07b..1e0e2c6f 100644
--- a/nimble/controller/src/ble_ll_dtm_priv.h
+++ b/nimble/controller/src/ble_ll_dtm_priv.h
@@ -37,4 +37,5 @@ int ble_ll_dtm_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr);
 void ble_ll_dtm_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr);
 void ble_ll_dtm_wfr_timer_exp(void);
 void ble_ll_dtm_reset(void);
+int ble_ll_dtm_enabled(void);
 #endif
diff --git a/nimble/controller/src/ble_ll_hci.c b/nimble/controller/src/ble_ll_hci.c
index 79d90e50..dc95f0de 100644
--- a/nimble/controller/src/ble_ll_hci.c
+++ b/nimble/controller/src/ble_ll_hci.c
@@ -1756,6 +1756,22 @@ ble_ll_hci_cmd_proc(struct ble_npl_event *ev)
     /* Assume response length is zero */
     rsplen = 0;
 
+#if MYNEWT_VAL(BLE_LL_DTM)
+    /* if DTM test is enabled disallow any command other than LE Test End or
+     * HCI Reset
+     */
+    if (ble_ll_dtm_enabled()) {
+        switch (opcode) {
+        case BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_TEST_END):
+        case BLE_HCI_OP(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET):
+            break;
+        default:
+            rc = BLE_ERR_CMD_DISALLOWED;
+            goto send_cc_cs;
+        }
+    }
+#endif
+
 #if MYNEWT_VAL(BLE_LL_HBD_FAKE_DUAL_MODE)
     rc = ble_ll_hci_cmd_fake_dual_mode(opcode, cmd->data, cmd->length,
                                        rspbuf, &rsplen);
@@ -1798,7 +1814,7 @@ ble_ll_hci_cmd_proc(struct ble_npl_event *ev)
         rc += (BLE_ERR_MAX + 1);
     }
 
-#if MYNEWT_VAL(BLE_LL_HBD_FAKE_DUAL_MODE)
+#if MYNEWT_VAL(BLE_LL_HBD_FAKE_DUAL_MODE) || MYNEWT_VAL(BLE_LL_DTM)
 send_cc_cs:
 #endif
     /* If no response is generated, we free the buffers */


[mynewt-nimble] 02/05: nimble/ll: Add helper for checking if controller is busy

Posted by ja...@apache.org.
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

commit 183dbf49b3d5db059f5efc60ffde229bb3d5f147
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Fri Oct 28 09:51:48 2022 +0200

    nimble/ll: Add helper for checking if controller is busy
    
    ble_ll_is_busy() returns 1 if there is anything related to radio
    activity happening in LL (scanning, advertising, connections etc).
---
 nimble/controller/src/ble_ll.c      | 46 +++++++++++++++++++++++++++++++++++++
 nimble/controller/src/ble_ll_priv.h |  5 ++++
 2 files changed, 51 insertions(+)

diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 9384a46c..aa91d213 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -2061,3 +2061,49 @@ ble_ll_tx_power_set(int tx_power)
 #endif
     ble_phy_tx_power_set(tx_power);
 }
+
+int
+ble_ll_is_busy(void)
+{
+#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
+    struct ble_ll_conn_sm *cur;
+    int i = 0;
+#endif
+
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV) && MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
+    if (ble_ll_sync_enabled()) {
+        return 1;
+    }
+#endif
+
+#if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER)
+    if (ble_ll_adv_enabled()) {
+        return 1;
+    }
+#endif
+
+#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
+    if (ble_ll_scan_enabled()) {
+        return 1;
+    }
+#endif
+
+#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
+    if (g_ble_ll_conn_create_sm.connsm) {
+        return 1;
+    }
+#endif
+
+#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
+    STAILQ_FOREACH(cur, &g_ble_ll_conn_free_list, free_stqe) {
+        i++;
+    }
+
+    /* check if all connection objects are free */
+    if (i < MYNEWT_VAL(BLE_MAX_CONNECTIONS)) {
+        return 1;
+    }
+#endif
+
+    return 0;
+}
diff --git a/nimble/controller/src/ble_ll_priv.h b/nimble/controller/src/ble_ll_priv.h
index 1ee30882..0a41509b 100644
--- a/nimble/controller/src/ble_ll_priv.h
+++ b/nimble/controller/src/ble_ll_priv.h
@@ -47,6 +47,11 @@ ble_ll_rx_gain(void)
     return gain;
 }
 
+/* if there is any radio related activity enabled
+ * (scanning, advertising, connection etc)
+ */
+int ble_ll_is_busy(void);
+
 #ifdef MYNEWT
 
 #include "syscfg/syscfg.h"