Skip to content

extmod/bluetooth: Add gap_unpair() for all BLE backends.#24

Draft
andrewleech wants to merge 1 commit intoreview/gap-unpairfrom
pr/gap-unpair
Draft

extmod/bluetooth: Add gap_unpair() for all BLE backends.#24
andrewleech wants to merge 1 commit intoreview/gap-unpairfrom
pr/gap-unpair

Conversation

@andrewleech
Copy link
Owner

Summary

There's no way to programmatically remove bonding keys in the current BLE API. Tests that pair/bond need to clear stale keys on startup to avoid failures from leftover state, and applications that manage multiple bonds need per-peer removal.

This adds BLE.gap_unpair() with two forms: no-arg clears all bonds, two-arg (addr_type, addr) removes a specific peer. Implemented for NimBLE (ble_gap_terminate + ble_store_util_delete_peer) and BTstack (gap_delete_bonding). The Zephyr backend already has a dormant implementation that activates when the Zephyr BLE integration lands.

Testing

  • ble_gap_unpair.py test added: connects, pairs with bonding, disconnects, then calls per-address gap_unpair() on both sides.
  • gap_unpair() no-arg calls added to ble_gap_pair.py, ble_gap_pair_bond.py, and ble_subscribe.py startup to clear stale bonds.
  • Tested on PYBD-SF6W (NimBLE).

Generative AI

I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the description above.

Add mp_bluetooth_gap_unpair() to the common bluetooth API, with
implementations for NimBLE, BTstack, and Zephyr BLE backends. Allows
applications to programmatically remove bonding information for a
specific peer.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Code size report:

Reference:  rp2/modules/rp2.py: Don't corrupt globals on asm_pio() exception. [c3ca843]
Comparison: extmod/bluetooth: Add gap_unpair() for all BLE backends. [merge of a32cee1]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:  +240 +0.014% ESP32_GENERIC[incl +32(data)]
     mimxrt:    +0 +0.000% TEENSY40
        rp2:   +72 +0.008% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants