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


The following commit(s) were added to refs/heads/master by this push:
     new e97cab2  nimble/host: Fix checking for NOP in ble_hs_hci_rx_evt
e97cab2 is described below

commit e97cab2174642599953a279e96b94a400b028b91
Author: Szymon Janc <[email protected]>
AuthorDate: Thu Jan 23 15:18:04 2020 +0100

    nimble/host: Fix checking for NOP in ble_hs_hci_rx_evt
    
    NOP can be sent as Command Complete or Command Status. Those events
    don't have opcode field in same place so old code was not checking
    proper bytes. It looks like this never worked for Command Status case.
---
 nimble/host/src/ble_hs_hci.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/nimble/host/src/ble_hs_hci.c b/nimble/host/src/ble_hs_hci.c
index 1376b84..a334a74 100644
--- a/nimble/host/src/ble_hs_hci.c
+++ b/nimble/host/src/ble_hs_hci.c
@@ -356,21 +356,20 @@ ble_hs_hci_rx_ack(uint8_t *ack_ev)
 int
 ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
 {
+    struct ble_hci_ev *ev = (void *) hci_ev;
+    struct ble_hci_ev_command_complete *cmd_complete = (void *) ev->data;
+    struct ble_hci_ev_command_status *cmd_status = (void *) ev->data;
     int enqueue;
 
     BLE_HS_DBG_ASSERT(hci_ev != NULL);
 
-    switch (hci_ev[0]) {
+    switch (ev->opcode) {
     case BLE_HCI_EVCODE_COMMAND_COMPLETE:
+        enqueue = (cmd_complete->opcode == BLE_HCI_OPCODE_NOP);
+        break;
     case BLE_HCI_EVCODE_COMMAND_STATUS:
-        if (hci_ev[3] == 0 && hci_ev[4] == 0) {
-            enqueue = 1;
-        } else {
-            ble_hs_hci_rx_ack(hci_ev);
-            enqueue = 0;
-        }
+        enqueue = (cmd_status->opcode == BLE_HCI_OPCODE_NOP);
         break;
-
     default:
         enqueue = 1;
         break;
@@ -378,6 +377,8 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
 
     if (enqueue) {
         ble_hs_enqueue_hci_event(hci_ev);
+    } else {
+        ble_hs_hci_rx_ack(hci_ev);
     }
 
     return 0;

Reply via email to