rymanluk closed pull request #27: nimble/ll: Fix for not mixing BT5.0 and 
legacy HCI commands
URL: https://github.com/apache/mynewt-nimble/pull/27
 
 
   

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/nimble/controller/src/ble_ll_hci.c 
b/nimble/controller/src/ble_ll_hci.c
index 7459746a..eb216e87 100644
--- a/nimble/controller/src/ble_ll_hci.c
+++ b/nimble/controller/src/ble_ll_hci.c
@@ -48,6 +48,18 @@ static uint8_t 
g_ble_ll_hci_le_event_mask[BLE_HCI_SET_LE_EVENT_MASK_LEN];
 static uint8_t g_ble_ll_hci_event_mask[BLE_HCI_SET_EVENT_MASK_LEN];
 static uint8_t g_ble_ll_hci_event_mask2[BLE_HCI_SET_EVENT_MASK_LEN];
 
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+enum {
+    BT5_NOT_CONFIGURED,
+    BT5_DISABLED,
+    BT5_ENABLED
+};
+/* If host start uses BT 5.0 commands, he should stick to it.
+ * Same is valid for legacy commands
+ */
+uint8_t g_ble_ll_bt5_usage = BT5_NOT_CONFIGURED;
+#endif
+
 /**
  * ll hci get num cmd pkts
  *
@@ -624,6 +636,41 @@ ble_ll_ext_adv_set_remove(uint8_t *cmd)
     return ble_ll_adv_remove(cmd[0]);
 }
 
+static bool
+ble_ll_is_valid_bt5_usage(uint8_t ocf)
+{
+    switch(ocf) {
+    case BLE_HCI_OCF_LE_CREATE_CONN:
+    case BLE_HCI_OCF_LE_SET_ADV_PARAMS:
+    case BLE_HCI_OCF_LE_SET_ADV_ENABLE:
+    case BLE_HCI_OCF_LE_SET_SCAN_PARAMS:
+    case BLE_HCI_OCF_LE_SET_SCAN_ENABLE:
+    case BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA:
+        /* For legacy commands make sure BT5 commands was not used before */
+        if (g_ble_ll_bt5_usage == BT5_ENABLED) {
+            return false;
+        }
+        g_ble_ll_bt5_usage = BT5_DISABLED;
+        break;
+    case BLE_HCI_OCF_LE_EXT_CREATE_CONN:
+    case BLE_HCI_OCF_LE_SET_EXT_ADV_DATA:
+    case BLE_HCI_OCF_LE_SET_EXT_ADV_ENABLE:
+    case BLE_HCI_OCF_LE_SET_EXT_ADV_PARAM:
+    case BLE_HCI_OCF_LE_SET_EXT_SCAN_ENABLE:
+    case BLE_HCI_OCF_LE_SET_EXT_SCAN_PARAM:
+    case BLE_HCI_OCF_LE_SET_EXT_SCAN_RSP_DATA:
+        /* For BT5 commands make sure legacy commands was not used before */
+        if (g_ble_ll_bt5_usage == BT5_DISABLED) {
+            return false;
+        }
+        g_ble_ll_bt5_usage = BT5_ENABLED;
+        break;
+    default:
+        break;
+    }
+
+    return true;
+}
 #endif
 
 /**
@@ -660,6 +707,13 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, 
uint8_t *rsplen)
         goto ll_hci_le_cmd_exit;
     }
 
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+    if (!ble_ll_is_valid_bt5_usage(ocf)) {
+        rc = BLE_ERR_CMD_DISALLOWED;
+        goto ll_hci_le_cmd_exit;
+    }
+#endif
+
     /*
      * The command response pointer points into the same buffer as the
      * command data itself. That is fine, as each command reads all the data


 

----------------------------------------------------------------
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