You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/03/03 14:04:52 UTC
[mynewt-nimble] 04/04: babblesim/edtt: Workaround EDTT not consuming cs/cc
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 045c3d19cd5dfd4a6601ef814c41aea9dfdc0879
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Feb 22 02:18:45 2022 +0100
babblesim/edtt: Workaround EDTT not consuming cs/cc
It seems that sometimes EDTT can send a command before cs/cc is consumed
by get_event and this triggers an error since cmd buffer is reused for
cs/cc and thus it will be queued as an event on edtt_q_event.
Not sure if this is an EDTT issue/feature or smth on our side, for now
we can workaround this by simply creating a copy of cs/cc which can be
safely enqueued on edtt_q_event waiting to be consumed and freed by
get_event while original cmd buffer is freed as soon as cs/cc is
processed.
---
babblesim/edtt/hci_transport/src/ble_hci_edtt.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/babblesim/edtt/hci_transport/src/ble_hci_edtt.c b/babblesim/edtt/hci_transport/src/ble_hci_edtt.c
index d1ff77b..36db846 100644
--- a/babblesim/edtt/hci_transport/src/ble_hci_edtt.c
+++ b/babblesim/edtt/hci_transport/src/ble_hci_edtt.c
@@ -330,10 +330,12 @@ ble_hci_trans_buf_free(uint8_t *buf)
} else if (os_memblock_from(&ble_hci_edtt_evt_lo_pool, buf)) {
rc = os_memblock_put(&ble_hci_edtt_evt_lo_pool, buf);
assert(rc == 0);
- } else {
+ } else if (os_memblock_from(&ble_hci_edtt_cmd_pool, buf)) {
assert(os_memblock_from(&ble_hci_edtt_cmd_pool, buf));
rc = os_memblock_put(&ble_hci_edtt_cmd_pool, buf);
assert(rc == 0);
+ } else {
+ free(buf);
}
}
@@ -545,6 +547,19 @@ queue_data(struct os_mbuf *om)
return pkt;
}
+
+static void *
+dup_complete_evt(void *evt)
+{
+ struct ble_hci_ev *evt_copy;
+
+ evt_copy = calloc(1, BLE_HCI_TRANS_CMD_SZ);
+ memcpy(evt_copy, evt, BLE_HCI_TRANS_CMD_SZ);
+ ble_hci_trans_buf_free((void *)evt);
+
+ return evt_copy;
+}
+
/**
* @brief Thread to service events and ACL data packets from the HCI input queue
*/
@@ -568,10 +583,12 @@ service_events(void *arg)
/* Prepare and send EDTT events */
switch (evt->opcode) {
case BLE_HCI_EVCODE_COMMAND_COMPLETE:
+ evt = dup_complete_evt(evt);
queue_event(evt);
command_complete(evt);
break;
case BLE_HCI_EVCODE_COMMAND_STATUS:
+ evt = dup_complete_evt(evt);
queue_event(evt);
command_status(evt);
break;