-
Couldn't load subscription status.
- Fork 1.1k
Provide incoming HCI buffer for BTstack #2165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide incoming HCI buffer for BTstack #2165
Conversation
|
I changed the branch to develop |
|
I've got no idea why this was assigned to me (I have no BTstack knowledge), so assigning to Peter instead. |
|
Oops - I should get this in. Will just run a quick test. |
|
@kilograham Can we merge this? |
|
Also i don't understand this at all - maybe a comment about what the various ranges of the buffer are used for (particularly the 4 vs the PREBUFFER - why are they not one and the same, and where alignment comes into play) |
9f64051 to
a8648cc
Compare
|
I have improved the documentation and merged the CYW43 packet header buffer with BTstack's pre-buffer, by asserting that HCI_INCOMING_PRE_BUFFER_SIZE is >= CYW43_PACKET_HEADER_SIZE (4). It's better to read now. However, the build fails for me with "#error HCI_INCOMING_PRE_BUFFER_SIZE not defined or smaller than 4 (CYW43_PACKET_HEADER_SIZE) bytes. Please update btstack_config.h". @peterharperuk Could you try to find out, where HCI_INCOMING_PRE_BUFFER_SIZE is set? |
431be34 to
6426636
Compare
As far as I can see, it's coming from btstack/src/hci.h |
|
@peterharperuk Does it compile for you? Also: where is support for Classic and/or LE defined? If Classic would be defined, then HCI_INCOMING_PRE_BUFFER_SIZE should be (16 - HCI_ACL_HEADER_SIZE - 4) = 8, which is larger than 4. I wasn't able to compile this as it seems to have picked up the value 2 from the #else branch - without Classic. |
|
If you link to pico_btstack_classic it defines ENABLE_CLASSIC and if you link to pico_btstack_ble it defines ENABLE_BLE. Most of the examples are linking to both. https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_btstack/CMakeLists.txt#L107 Let me do some more testing. We haven't updated btstack to v1.6.2, we're still using v1.6.1. Should we update? |
|
Interesting. So, how does btstack_hci_transport_cyw43.c know which HCI_INCOMING_PRE_BUFFER_SIZE to use? Is it part of pico_btstack_classic as well as pico_btstack_ble. If in doubt, we can just use a rather large HCI_INCOMING_PRE_BUFFER_SIZE, e.g. 16, for . btstack_hci_transport_cyw43. We don't plan on increasing the pre-buffer and just did a larger rewrite of the GATT Client logic, which is a big user of HCI_INCOMING_PRE_BUFFER_SIZE. Yes, you should update to master (1.6.2 + one additional fix). |
|
There's only on version of btstack_hci_transport_cyw43.c. So if you link to classic you get 8. If you ONLY link to ble you get 2. If you link to both you get 8? Is that wrong? I'm fine with us adding a set number to be safe. I thought your change was ok though? |
|
btstack_hci_transport_cyw43.c should use whatever hci.h choses based on ENABLE_CLASSIC or not. (I don't understand the pico-sdk build system. I generally assume that a particular .c file is only compiled once into an .o file (by this having a fixed value for HCI_INCOMING_PRE_BUFFER_SIZE) and then I don't understand how an example can link to pico_btstack_classic as well as pico_btstack_ble at the same time). |
|
Everything is a cmake interface library in the sdk https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries |
6426636 to
c88df1c
Compare
|
@peterharperuk Thanks. Interesting, I need to revisit my concept of "library". Didn't know it could set defines for the main project (which totally makes sense if you start to thing about it). Anyway. There's a new force-pushed version. It validates the size of the outgoing buffer and throws an error if needed, as the outgoing buffer is owned by hci.c. For the incoming buffer, which we need to provide, it increases it if needed. By this, pico-sdk should compile with the current (older) BTstack version as well as newer ones (v1.6.2 will require a larger pre-buffer for LE examples). |
|
Tested with 1.6.1 and 1.6.2 #2202 |
The current driver reserves a larger buffer for the BTstack Pre-Buffer in memory, but does not use it when receiving an HCI packet from CYW43 driver. As some BTstack events will use this buffer, this causes an out-of-bound write / crash with BTstack v1.6.2 or higher.
Note: the 4-byte CYW43 header implicitly provided a 3-byte pre-buffer, which worked for BTstack v1.6.1 and earlier. In BTstack v1.6.2, the pre-buffer was increased which causes this bug to unhide.
This replaces #2157 (comment)