summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/btstack
Commit message (Collapse)AuthorAge
* all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton2024-03-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/btstack: Reset pending_value_handle before calling read-done cb.Damien George2024-02-12
| | | | | | | | | | | | | Similar to the previous commit but for MP_BLUETOOTH_IRQ_GATTC_READ_DONE: the pending_value_handle needs to be reset before calling mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ handler, which may in turn call back into BTstack to perform an action like a write. In that case the pending_value_handle will need to be available for the write/read/etc to proceed. Fixes issue #13634. Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Reset pending_value_handle before calling write-done cb.Damien George2024-02-09
| | | | | | | | | | | | The pending_value_handle needs to be freed and reset before calling mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ handler, which may in turn call back into BTstack to perform an action like a write. In that case the pending_value_handle will need to be available for the write/read/etc to proceed. Fixes issue #13611. Signed-off-by: Damien George <damien@micropython.org>
* extmod: Switch to use new event functions.Angus Gratton2023-12-08
| | | | | | | | | See previous commit for details of these functions. As of this commit, these still call the old hook macros on all ports. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/btstack/btstack_hci_uart: Trigger a poll after UART data is sent.Damien George2023-09-29
| | | | | | | | | | | | | Prior to this commit, BTstack would only be notified of sent UART data when the mp_bluetooth_hci_poll() function was called for some other reason, eg because of incoming data over UART. This is highly suboptimal. With this commit, BTstack is now notified immediately after UART data has been sent out. This improves the multi_bluetooth/perf_gatt_char_write.py performance test by about a factor of 10x for write-without-response, and about 4x for write-with-response (tested on LEGO_HUB_NO6 as instance1). Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Fix marking of static addresses in set_random_address.Peter Harper2023-06-14
| | | | | | Marking address as static was not applied to all code paths. Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Add cmake support for BTstack.Peter Harper2023-06-14
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack/modbluetooth_btstack: Add default services.Jim Mussared2023-04-26
| | | | | | | 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>
* extmod/btstack: Add support for CCCD to allow client subscriptions.Jim Mussared2023-04-26
| | | | | | | | | 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>
* extmod/btstack: Fix MTU handling.Jim Mussared2023-04-26
| | | | | | | | 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>
* extmod/btstack: Include value handle in client read/write events.Jim Mussared2023-04-26
| | | | | | | | | | | | 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>
* extmod/btstack: Fix indicate/notify queuing.Jim Mussared2023-04-26
| | | | | | | | | | | 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>
* extmod/modbluetooth: Merge gatts_notify/indicate implementation.Jim Mussared2023-04-26
| | | | | | | | | | | | | 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>
* extmod/btstack: Switch to use hci_dump_init instead of hci_dump_open.Damien George2023-04-22
| | | | | | | The latter is no longer available in the version of BTstack now in use by this repository. Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Allow the BTstack config to be overridden by a board.Damien George2022-11-11
| | | | | | | If a board defines MICROPY_BLUETOOTH_BTSTACK_CONFIG_FILE as the path to a header file, then that file will be used for the BTstack config. Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Update BTstack bindings to work with latest BTstack.Damien George2022-10-22
| | | | | | | | | | | | | | | | | | | The following multi-tests pass (eg with PYBD_SF6+LEGO_HUB_NO6): ble_gap_advertise.py ble_gap_connect.py ble_gap_device_name.py ble_gattc_discover_services.py ble_gatt_data_transfer.py perf_gatt_char_write.py perf_gatt_notify.py stress_log_filesystem.py These are the same tests that passed prior to this BTstack update. Also tested on the unix port using H4 transport. Signed-off-by: Damien George <damien@micropython.org>
* extmod: Make extmod.mk self-contained.Jim Mussared2022-10-11
| | | | | | | | | | | | | | | | | This makes it so that all a port needs to do is set the relevant variables and "include extmod.mk" and doesn't need to worry about adding anything to OBJ, CFLAGS, SRC_QSTR, etc. Make all extmod variables (src, flags, etc) private to extmod.mk. Also move common/shared, extmod-related fragments (e.g. wiznet, cyw43, bluetooth) into extmod.mk. Now that SRC_MOD, CFLAGS_MOD, CXXFLAGS_MOD are unused by both extmod.mk (and user-C-modules in a previous commit), remove all uses of them from port makefiles. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/extmod.mk: Make extmod.mk handle GIT_SUBMODULES.Jim Mussared2022-10-11
| | | | | | | | | | This applies to nimble, btstack, axtls, mbedtls, lwip. Rather than having the ports individually manage GIT_SUBMODULES for these components, make extmod.mk append them when the relevant feature is enabled. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Replace def_handle with end_handle in char IRQ.Jim Mussared2022-09-09
| | | | | | | | | | | | | | | This is technically a breaking change, but: a) We need the end handle to do descriptor discovery properly. b) We have no possible use for the existing definition handle in the characteristic result IRQ. None of the methods can use it, and therefore no existing code should be using it in a way that changing it to a different integer value should break. Unfortunately NimBLE doesn't make it easy to get the end handle, so also implement a mechanism to use the following characteristic to calculate the previous characteristic's end handle. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/btstack: Fix descriptor discovery handle range and events.Damien George2022-07-20
| | | | | | | | | | | | | | | | | | This fixes two problems with the BTstack implementation of descriptor discovery: - The call to gatt_client_discover_characteristic_descriptors needs to have value_handle set to the starting handle (actually characteristic handle) to start the search from. - The BTstack event for a descriptor query result is GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT. With this change the test tests/multi_bluetooth/ble_subscribe.py now passes when BTstack is instance1 (for BTstack to pass as instance0 requires gatts_write to support sending an update on BTstack). Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Use MP_REGISTER_ROOT_POINTER().David Lechner2022-07-18
| | | | | | | | This uses MP_REGISTER_ROOT_POINTER() to register bluetooth_btstack_root_pointers and removes the same from all mpconfigport.h. Signed-off-by: David Lechner <david@pybricks.com>
* extmod/modbluetooth: Support gap_connect(None) to cancel a connection.Jonathan Hogg2021-12-01
| | | | Allow cancellation of in-progress peripheral connections.
* extmod/modbluetooth: Add connection interval to gap_connect.Jim Mussared2021-10-26
| | | | | | This forwards through directly to the NimBLE and BTStack connect functions. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Add send_update arg to gatts_write.Jim Mussared2021-08-14
| | | | | | | | This allows the write to trigger a notification or indication, but only to subscribed clients. This is different to gatts_notify/gatts_indicate, which will unconditionally notify/indicate. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/btstack/btstack.mk: Use -Wno-implicit-fallthrough, not =0.Damien George2021-07-17
| | | | | | | | | | | In 2ae3c890bd923b4c39bba3d2e2f2d75eca5dcc06, -Wimplicit-fallthrough=0 was added to get the build to pass. This option is equivalent to -Wno-implicit-fallthrough, and the latter is compatible with clang (while the former is not). Fixes issue #7546. Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Check that BLE is active before performing operations.Damien George2021-06-23
| | | | | | Otherwise it can easily lead to a hard crash. Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Add missing call to mp_bluetooth_hci_uart_deinit.Damien George2021-06-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* stm32: Provide a custom BTstack runloop that integrates with soft timer.Damien George2021-06-23
| | | | | | | It reschedules the BT HCI poll soft timer so that it is called exactly when the next timer expires. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modbluetooth: Separate enabling of "client" from "central".Jim Mussared2021-02-19
| | | | | | | | | | | | | | | | | | Previously, the MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE macro controlled enabling both the central mode and the GATT client functionality (because usually the two go together). This commits adds a new MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT macro that separately enables the GATT client functionality. This defaults to MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE. This also fixes a bug in the NimBLE bindings where a notification or indication would not be received by a peripheral (acting as client) as gap_event_cb wasn't handling it. Now both central_gap_event_cb and peripheral_gap_event_cb share the same common handler for these events. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/btstack: Use MICROPY_HW_BLE_UART_BAUDRATE for first UART init.Damien George2021-02-17
| | | | | | Otherwise the UART may be left in a state at baudrate=0. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modbluetooth: Allow NimBLE to use Zephyr static address.Jim Mussared2021-02-17
| | | | | | Zephyr controllers can be queried for a static address (computed from the device ID). BlueKitchen already supports this, but make them both use the same macro to enable the feature.
* extmod/btstack: Enable SYNC_EVENTS, PAIRING_BONDING by default.Damien George2021-02-12
| | | | | | Synchronous events work on stm32 and unix ports. Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Add stub functions for passkey, l2cap bindings.Damien George2021-02-12
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/btstack: Add HCI trace debugging option in btstack_hci_uart.Damien George2021-02-12
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/modbluetooth: Add gap_pair(conn_handle) func to intiate pairing.Jim Mussared2020-12-02
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Allow configuration of pairing/bonding parameters.Jim Mussared2020-12-02
| | | | | | This allows setting the security and MITM-protection requirements. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Add _IRQ_ENCRYPTION_UPDATE event.Andrew Leech2020-12-02
| | | | | | | This allows the application to be notified if any of encrypted, authenticated and bonded state change, as well as the encryption key size. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Allow setting char/desc enc/auth options.Andrew Leech2020-12-02
| | | | | | | | | | | | This widens the characteristic/descriptor flags to 16-bit, to allow setting encryption/authentication requirements. Sets the required flags for NimBLE and btstack implementations. The BLE.FLAG_* constants will eventually be deprecated in favour of copy and paste Python constants (like the IRQs). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Add _IRQ_CONNECTION_UPDATE event.Andrew Leech2020-12-02
| | | | | | | This allows the application to be notified of changes to the connection interval, connection latency and supervision timeout. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Re-instate optional no-ringbuf modbluetooth.Jim Mussared2020-11-13
| | | | | | | | | | | | | This requires that the event handlers are called from non-interrupt context (i.e. the MicroPython scheduler). This will allow the BLE stack (e.g. NimBLE) to run from the scheduler rather than an IRQ like PENDSV, and therefore be able to invoke Python callbacks directly/synchronously. This allows writing Python BLE handlers for events that require immediate response such as _IRQ_READ_REQUEST (which was previous a hard IRQ) and future events relating to pairing/bonding. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Combine gattc-data-available callbacks into one.Jim Mussared2020-11-13
| | | | | | | | | | | Instead of having the stack indicate a "start", "data"..., "end", pass through the data in one callback as an array of chunks of data. This is because the upcoming non-ringbuffer modbluetooth implementation cannot buffer the data in the ringbuffer and requires instead a single callback with all the data, to pass to the Python callback. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Make UUID type accessible outside modbluetooth.c.Jim Mussared2020-11-13
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/btstack/btstack.mk: Add -Wimplicit-fallthrough=0.Jim Mussared2020-11-05
| | | | | | | This is needed since -Wextra was added to the build in bef412789ea93c521bd9c2dddc22b9b3484da574 Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modbluetooth: Implement MTU.Jim Mussared2020-09-18
|
* extmod/btstack: Detect HCI UART init failure.Jim Mussared2020-09-08
|
* extmod/btstack: Add btstack support for _IRQ_GATTS_READ_REQUEST.Andrew Leech2020-09-08
|
* extmod/modbluetooth: Allow using mp_hal_get_mac as a static address.Jim Mussared2020-09-08
| | | | | | | | | | Generally a controller should either have its own public address hardcoded, or loaded by the driver (e.g. cywbt43). However, for a controller that has no public address where you still want a long-term stable address, this allows you to use a static address generated by the port. Typically on STM32 this will be an LAA, but a board might override this.
* extmod/modbluetooth: Implement configuration of address modes.Jim Mussared2020-09-08
| | | | | | Changes `BLE.config('mac')` to return a tuple (addr_mode, addr). Adds `BLE.config(addr_mode=...)` to set the addressing mode.
* unix: Implement BLE H4 HCI UART for btstack/nimble.Jim Mussared2020-09-08
| | | | | | | | | | | | This commit adds support for using Bluetooth on the unix port via a H4 serial interface (distinct from a USB dongle), with both BTstack and NimBLE Bluetooth stacks. Note that MICROPY_PY_BLUETOOTH is now disabled for the coverage variant. Prior to this commit Bluetooth was anyway not being built on Travis because libusb was not detected. But now that bluetooth works in H4 mode it will be built, and will lead to a large decrease in coverage because Bluetooth tests cannot be run on Travis.