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.
This commit is contained in:
Andrzej Kaczmarek
2022-02-22 02:18:45 +01:00
parent 3923f1bb1e
commit 045c3d19cd
@@ -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;