Skip to content

extmod/modbluetooth: Fixes for bluekitchen/btstack. #11239

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

Merged
merged 15 commits into from
Apr 26, 2023

Conversation

jimmo
Copy link
Member

@jimmo jimmo commented Apr 11, 2023

This PR brings btstack functionality up to match NimBLE (excluding L2CAP channels). This needed to be done anyway, but is high priority for BLE on the Pico W (see #10739).

The three main fixes are:

  • Make indicate/notify behave identically, and match NimBLE.
  • Include the value handle in the read/write complete events for GATT client. (Previously btstack always gave 65535 as the handle).
  • Make central-initiated MTU exchange work on btstack.

Also

  • Update tests to pass on both. ble_characteristic.py, ble_descriptor.py,ble_gap_advertise.py, ble_gap_connect.py, ble_gap_device_name.py, ble_gattc_discover_services.py, ble_gatt_data_transfer.py, ble_mtu.py,ble_subscribe.py now run identically on both.
  • Updates documentation (mainly to remove btstack-specific limitations).
  • Some minor NimBLE fixes, e.g. for modbluetooth: Descriptor flag mapping #6864

TODO: More testing of btstack pairing/bonding.

This work was funded through GitHub Sponsors.

@github-actions
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
        rp2:    +0 +0.000% PICO

@jimmo
Copy link
Member Author

jimmo commented Apr 11, 2023

Include the value handle in the read/write complete events for GATT client. (Previously btstack always gave 65535 as the handle).

This is important to support aioble, which requires this to work (which is why aioble only previously worked on NimBLE).

See also micropython/micropython-lib#643 for a corresponding update to aioble related to other fixes.

@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Apr 12, 2023
@jimmo jimmo force-pushed the btstack-fixes branch 2 times, most recently from 514950c to 8bfc9a8 Compare April 13, 2023 04:27
@dpgeorge
Copy link
Member

I reverted the commit that changed run-multitests.py to poll stdin during wait(), because it breaks the CI. I'd prefer to fix that by making the unix port run scheduled code during mp_hal_stdin_rx_chr().

@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2023

Codecov Report

Merging #11239 (4478c0d) into master (b525f1c) will not change coverage.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##           master   #11239   +/-   ##
=======================================
  Coverage   98.50%   98.50%           
=======================================
  Files         155      155           
  Lines       20549    20549           
=======================================
  Hits        20241    20241           
  Misses        308      308           
Impacted Files Coverage Δ
ports/unix/mpconfigport.h 100.00% <ø> (ø)
py/gc.c 99.18% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dpgeorge
Copy link
Member

I also pushed a commit to tidy up a comment.

jimmo added 12 commits April 26, 2023 11:37
Makes gatts_notify and gatts_indicate work in the same way: by default they
send the DB value, but you can manually override the payload.

In other words, makes gatts_indicate work the same as gatts_notify.

Note: This removes support for queuing notifications and indications on
btstack when the ACL buffer is full. This functionality will be
reimplemented in a future commit.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This adds a mechanism to track a pending notify/indicate operation that
is deferred due to the send buffer being full. This uses a tracked alloc
that is passed as the content arg to the callback.

This replaces the previous mechanism that did this via the global pending
op queue, shared with client read/write ops.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This replaces the previous pending operation queue (that used to also be
shared with pending server notify/indicate ops) with a single pending
operation per connection. This allows the value handle to be correctly
passed to the Python-level events.

Also re-structure GATT client event handling to simplify the packet handler
functions.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
On unix, time.sleep is implemented as select(timeout=<time>) which means
that it does not run the poll hook during sleeping.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
btstack only supports central-initiated, so this allows us to have a test
that works on both (ble_mtu.py), and then another one for just the NimBLE
supported behavior (ble_mtu_peripheral.py).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
There was no event handler for central-initiated MTU exchange.

Fix truncation of notify/indicate to match NimBLE.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Obtaining the end_handle was added in cacc96d.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This allows gatts_write(..., send_update=True) to work, which will send
notifications/indications to subscribed clients.

btstack already created the CCCD but writes to it were ignored.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
The att_flags for descriptors does not use the same bitfield as for
characteristics. This was leading to NimBLE descriptors getting the wrong
flags set.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This is unused in the client, only needed in the server.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
jimmo added 3 commits April 26, 2023 11:37
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
 - Use HCI_TRACE macro consistently.
 - Use the same colour formatting.
 - Add a tool to convert to .pcap for Wireshark.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Even if the user doesn't call ble.gatts_register_services, always
provide the default services.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
@jimmo
Copy link
Member Author

jimmo commented Apr 26, 2023

I reverted the commit that changed run-multitests.py to poll stdin during wait(), because it breaks the CI. I'd prefer to fix that by making the unix port run scheduled code during mp_hal_stdin_rx_chr().

OK. I've squashed out the commit and the revert.

Also rebased the other changes.

@dpgeorge
Copy link
Member

OK, thanks for updating, looks good now!

@dpgeorge dpgeorge merged commit 67fb0be into micropython:master Apr 26, 2023
@dpgeorge
Copy link
Member

Merged!

jimmo added a commit to jimmo/micropython-lib that referenced this pull request Sep 14, 2023
In micropython/micropython#11239 we added support for passing data to
gatts_indicate (to make it match gatts_notify).

This adds the same to aioble.

Also update the documentation to mention this (and fix some mistakes and
add a few more examples).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
jimmo added a commit to jimmo/micropython-lib that referenced this pull request Sep 14, 2023
In micropython/micropython#11239 we added support for passing data to
gatts_indicate (to make it match gatts_notify).

This adds the same to aioble.

Also update the documentation to mention this (and fix some mistakes and
add a few more examples).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
jimmo added a commit to micropython/micropython-lib that referenced this pull request Oct 4, 2023
In micropython/micropython#11239 we added support for passing data to
gatts_indicate (to make it match gatts_notify).

This adds the same to aioble.

Also update the documentation to mention this (and fix some mistakes and
add a few more examples).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy