Przeglądaj źródła

Merge branch 'nimble/misc_host_flow_ctrl_changes' into 'master'

NimBLE: Misc fixes in NimBLE host flow control and `blecent` example

See merge request espressif/esp-idf!7042
Mahavir Jain 6 lat temu
rodzic
commit
9ee50266cc

+ 31 - 0
components/bt/host/nimble/Kconfig.in

@@ -216,6 +216,37 @@ config BT_NIMBLE_HCI_EVT_LO_BUF_COUNT
         low-priority event buffers, then an incoming advertising report will
         get dropped
 
+config BT_NIMBLE_HS_FLOW_CTRL
+    bool "Enable Host Flow control"
+    depends on BT_NIMBLE_ENABLED
+    default y
+    help
+        Enable Host Flow control
+
+config BT_NIMBLE_HS_FLOW_CTRL_ITVL
+    int "Host Flow control interval"
+    depends on BT_NIMBLE_HS_FLOW_CTRL
+    default 1000
+    help
+        Host flow control interval in msecs
+
+config BT_NIMBLE_HS_FLOW_CTRL_THRESH
+    int "Host Flow control threshold"
+    depends on BT_NIMBLE_HS_FLOW_CTRL
+    default 2
+    help
+        Host flow control threshold, if the number of free buffers are at or
+        below this threshold, send an immediate number-of-completed-packets
+        event
+
+config BT_NIMBLE_HS_FLOW_CTRL_TX_ON_DISCONNECT
+    bool "Host Flow control on disconnect"
+    depends on BT_NIMBLE_HS_FLOW_CTRL
+    default y
+    help
+        Enable this option to send number-of-completed-packets event to
+        controller after disconnection
+
 menuconfig BT_NIMBLE_MESH
     bool "Enable BLE mesh functionality"
     select BT_NIMBLE_SM_SC

+ 1 - 1
components/bt/host/nimble/nimble

@@ -1 +1 @@
-Subproject commit f7a993a441d713e5cc52006659c8b8d23f4343ed
+Subproject commit c6fa32fcc6e73f91e4637be98fc5c1785bdc1b2d

+ 7 - 3
components/bt/host/nimble/port/include/esp_nimble_cfg.h

@@ -452,19 +452,23 @@
 #endif
 
 #ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL
+#ifdef CONFIG_BT_NIMBLE_HS_FLOW_CTRL
+#define MYNEWT_VAL_BLE_HS_FLOW_CTRL (1)
+#else
 #define MYNEWT_VAL_BLE_HS_FLOW_CTRL (0)
 #endif
+#endif
 
 #ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL
-#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL (1000)
+#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL CONFIG_BT_NIMBLE_HS_FLOW_CTRL_ITVL
 #endif
 
 #ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH
-#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH (2)
+#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH CONFIG_BT_NIMBLE_HS_FLOW_CTRL_THRESH
 #endif
 
 #ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT
-#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT (0)
+#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT CONFIG_BT_NIMBLE_FLOW_CTRL_TX_ON_DISCONNECT
 #endif
 
 #ifndef MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS

+ 11 - 3
examples/bluetooth/nimble/blecent/main/main.c

@@ -319,6 +319,7 @@ blecent_should_connect(const struct ble_gap_disc_desc *disc)
 static void
 blecent_connect_if_interesting(const struct ble_gap_disc_desc *disc)
 {
+    uint8_t own_addr_type;
     int rc;
 
     /* Don't do anything if we don't care about this advertiser. */
@@ -333,16 +334,23 @@ blecent_connect_if_interesting(const struct ble_gap_disc_desc *disc)
         return;
     }
 
+    /* Figure out address to use for connect (no privacy for now) */
+    rc = ble_hs_id_infer_auto(0, &own_addr_type);
+    if (rc != 0) {
+        MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
+        return;
+    }
+
     /* Try to connect the the advertiser.  Allow 30 seconds (30000 ms) for
      * timeout.
      */
 
-    rc = ble_gap_connect(BLE_OWN_ADDR_PUBLIC, &disc->addr, 30000, NULL,
+    rc = ble_gap_connect(own_addr_type, &disc->addr, 30000, NULL,
                          blecent_gap_event, NULL);
     if (rc != 0) {
         MODLOG_DFLT(ERROR, "Error: Failed to connect to device; addr_type=%d "
-                    "addr=%s\n",
-                    disc->addr.type, addr_str(disc->addr.val));
+                    "addr=%s; rc=%d\n",
+                    disc->addr.type, addr_str(disc->addr.val), rc);
         return;
     }
 }