summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/btstack/modbluetooth_btstack.c
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: 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>
* 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: 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/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: 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/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/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: Add stub functions for passkey, l2cap bindings.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/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.
* extmod/modbluetooth: Refactor stack/hci/driver/port bindings.Jim Mussared2020-09-08
| | | | | | | Previously the interaction between the different layers of the Bluetooth stack was different on each port and each stack. This commit defines common interfaces between them and implements them for cyw43, btstack, nimble, stm32, unix.
* extmod/modbluetooth: Rename logging macro to be just DEBUG_printf.Jim Mussared2020-09-08
| | | | | And prefix the debug message with "btstack:" or "nimble:", depending on the context. Also use correct format specifier for %zu.
* extmod/bluetooth: Support active scanning in BLE.gap_scan().Andrew Leech2020-08-26
| | | | | | This adds an additional optional parameter to gap_scan() to select active scanning, where scan responses are returned as well as normal scan results. This parameter is False by default which retains the existing behaviour.
* extmod/btstack: Implement GAP scan duration_ms parameter.Jim Mussared2020-08-26
| | | | | This commit makes scanning work when duration_ms is set to zero. Prior to this it would not work with duration_ms set to zero.
* extmod/modbluetooth: Add event for "indicate acknowledgement".Jim Mussared2020-07-20
| | | | | | | | | | | | This commit adds the IRQ_GATTS_INDICATE_DONE BLE event which will be raised with the status of gatts_indicate (unlike notify, indications require acknowledgement). An example of its use is added to ble_temperature.py, and to the multitests in ble_characteristic.py. Implemented for btstack and nimble bindings, tested in both directions between unix/btstack and pybd/nimble.
* extmod/modbluetooth: Fix so it builds in peripheral-only mode.Jim Mussared2020-07-20
|
* docs/library: Add gatts_indicate() doc to ubluetooth.rst.Jim Mussared2020-07-18
| | | | | Also clarify behavior of `gatts_notify` and add some TODOs about adding an event for indication acknowledgement.
* extmod/btstack: Schedule notify/indicate/write ops for bg completion.Jim Mussared2020-07-18
| | | | | | | | | | | | | | | | | | | | | | | | The goal of this commit is to allow using ble.gatts_notify() at any time, even if the stack is not ready to send the notification right now. It also addresses the same issue for ble.gatts_indicate() and ble.gattc_write() (without response). In addition this commit fixes the case where the buffer passed to write-with-response wasn't copied, meaning it could be modified by the caller, affecting the in-progress write. The changes are: - gatts_notify/indicate will now run in the background if the ACL buffer is currently full, meaning that notify/indicate can be called at any time. - gattc_write(mode=0) (no response) will now allow for one outstanding write. - gattc_write(mode=1) (with response) will now copy the buffer so that it can't be modified by the caller while the write is in progress. All four paths also now track the buffer while the operation is in progress, which prevents the GC free'ing the buffer while it's still needed.
* tools/codeformat.py: Include extmod/{btstack,nimble} in code formatting.Damien George2020-06-18
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/modbluetooth: Implement read done event.Jim Mussared2020-06-05
| | | | | | On btstack there's no status associated with the read result, it comes through as a separate event. This allows you to detect read failures or timeouts.
* extmod/modbluetooth: Allow discovery of svc/char by uuid.Jim Mussared2020-06-05
| | | | | In most situations this is a more efficient way of going straight to the service and characteristic you need.
* extmod/modbluetooth: Add discover complete events for svc/char/desc.Jim Mussared2020-06-05
| | | | | Without this it's difficult to implement a state machine correctly if the desired services are not found.
* extmod/modbluetooth: Add support for changing the GAP device name.Damien George2020-05-11
| | | | | | | | | | | | | | This commit allows the user to set/get the GAP device name used by service 0x1800, characteristic 0x2a00. The usage is: BLE.config(gap_name="myname") print(BLE.config("gap_name")) As part of this change the compile-time setting MICROPY_PY_BLUETOOTH_DEFAULT_NAME is renamed to MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME to emphasise its link to GAP and this new "gap_name" config value. And the default value of this for the NimBLE bindings is changed from "PYBD" to "MPY NIMBLE" to be more generic.
* extmod/modbluetooth: Fix sign compare and unused variable warnings.Jim Mussared2020-04-29
|