rymanluk closed pull request #807: nimble/mesh: Improve advertising interval
URL: https://github.com/apache/mynewt-core/pull/807
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/net/nimble/host/mesh/src/adv.c b/net/nimble/host/mesh/src/adv.c
index b4b3adebb..40259e6ad 100644
--- a/net/nimble/host/mesh/src/adv.c
+++ b/net/nimble/host/mesh/src/adv.c
@@ -36,6 +36,8 @@
 #define ADV_INT_DEFAULT  K_MSEC(100)
 #define ADV_INT_FAST     K_MSEC(20)
 
+static s32_t adv_int_min =  ADV_INT_DEFAULT;
+
 /* TinyCrypt PRNG consumes a lot of stack space, so we need to have
  * an increased call stack whenever it's used.
  */
@@ -87,8 +89,6 @@ static inline void adv_send(struct os_mbuf *buf)
 {
        const struct bt_mesh_send_cb *cb = BT_MESH_ADV(buf)->cb;
        void *cb_data = BT_MESH_ADV(buf)->cb_data;
-       /* XXX: For BT5 we could have better adv interval */
-       const s32_t adv_int_min =  ADV_INT_DEFAULT;
        struct ble_gap_adv_params param = { 0 };
        u16_t duration, adv_int;
        struct bt_mesh_adv *adv = BT_MESH_ADV(buf);
@@ -311,6 +311,11 @@ void bt_mesh_adv_init(void)
        os_task_init(&adv_task, "mesh_adv", adv_thread, NULL,
                     MYNEWT_VAL(BLE_MESH_ADV_TASK_PRIO), OS_WAIT_FOREVER, 
pstack,
                     ADV_STACK_SIZE);
+
+       /* For BT5 controllers we can have fast advertising interval */
+       if (ble_hs_hci_get_hci_version() >= BLE_HCI_VER_BCS_5_0) {
+           adv_int_min = ADV_INT_FAST;
+       }
 }
 
 int
diff --git a/net/nimble/host/src/ble_hs_hci.c b/net/nimble/host/src/ble_hs_hci.c
index 72bbeb38d..ec88462b9 100644
--- a/net/nimble/host/src/ble_hs_hci.c
+++ b/net/nimble/host/src/ble_hs_hci.c
@@ -37,6 +37,7 @@ static uint8_t *ble_hs_hci_ack;
 static uint16_t ble_hs_hci_buf_sz;
 static uint8_t ble_hs_hci_max_pkts;
 static uint32_t ble_hs_hci_sup_feat;
+static uint8_t ble_hs_hci_version;
 
 /**
  * The number of available ACL transmit buffers on the controller.  This
@@ -546,6 +547,18 @@ ble_hs_hci_get_le_supported_feat(void)
     return ble_hs_hci_sup_feat;
 }
 
+void
+ble_hs_hci_set_hci_version(uint8_t hci_version)
+{
+    ble_hs_hci_version = hci_version;
+}
+
+uint8_t
+ble_hs_hci_get_hci_version(void)
+{
+    return ble_hs_hci_version;
+}
+
 void
 ble_hs_hci_init(void)
 {
diff --git a/net/nimble/host/src/ble_hs_hci_priv.h 
b/net/nimble/host/src/ble_hs_hci_priv.h
index 57ab99458..24ced0a36 100644
--- a/net/nimble/host/src/ble_hs_hci_priv.h
+++ b/net/nimble/host/src/ble_hs_hci_priv.h
@@ -80,6 +80,8 @@ void ble_hs_hci_init(void);
 
 void ble_hs_hci_set_le_supported_feat(uint32_t feat);
 uint32_t ble_hs_hci_get_le_supported_feat(void);
+void ble_hs_hci_set_hci_version(uint8_t hci_version);
+uint8_t ble_hs_hci_get_hci_version(void);
 
 #if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
 typedef int ble_hs_hci_phony_ack_fn(uint8_t *ack, int ack_buf_len);
diff --git a/net/nimble/host/src/ble_hs_startup.c 
b/net/nimble/host/src/ble_hs_startup.c
index 7e2151c06..4ad6694dd 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -23,6 +23,33 @@
 #include "host/ble_hs_hci.h"
 #include "ble_hs_priv.h"
 
+static int
+ble_hs_startup_le_read_local_ver_tx(void)
+{
+    uint8_t ack_params[BLE_HCI_RD_LOC_VER_INFO_RSPLEN];
+    uint8_t ack_params_len;
+    uint8_t hci_version;
+    int rc;
+
+    rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_INFO_PARAMS,
+                                      BLE_HCI_OCF_IP_RD_LOCAL_VER),
+                           NULL,0, ack_params, sizeof ack_params,
+                           &ack_params_len);
+    if (rc != 0) {
+        return rc;
+    }
+
+    if (ack_params_len != BLE_HCI_RD_LOC_VER_INFO_RSPLEN) {
+        return BLE_HS_ECONTROLLER;
+    }
+
+    /* For now we are interested only in HCI Version */
+    hci_version = ack_params[0];
+    ble_hs_hci_set_hci_version(hci_version);
+
+    return 0;
+}
+
 static int
 ble_hs_startup_le_read_sup_f_tx(void)
 {
@@ -251,6 +278,11 @@ ble_hs_startup_go(void)
         return rc;
     }
 
+    rc = ble_hs_startup_le_read_local_ver_tx();
+    if (rc != 0) {
+        return rc;
+    }
+
     /* XXX: Read local supported commands. */
     /* XXX: Read local supported features. */
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to