Skip to content

extmod/modbluetooth: Add gap_unpair command. - #7845

Open
andrewleech wants to merge 1 commit into
micropython:masterfrom
andrewleech:unpair
Open

andrewleech wants to merge 1 commit into
micropython:masterfrom
andrewleech:unpair

Conversation

@andrewleech

@andrewleech andrewleech commented Sep 23, 2021 •

Copy link
Copy Markdown
Contributor

This function deletes the pairing details from the DB on both the application and the radio, so can be used to free up IRK slots on the radio.

Note: this only works on nimble as pairing/bonding has not been fully implemented on other stacks.

Background

In my application, we have a stm327f765 chip running micropython, with a build of the official nimble uart/hci application running on a separate nrf52810 (https://github.com/apache/mynewt-nimble/tree/master/apps/blehci)

We use this with aioble and paring/bonding.

It's been found that this nimble hci radio only has buffer/storage for 4 RPA / IRK addressing lookups, so if you've got more devices than this stored in the pairing/bonding database, any new devices that come along and try to pair/bond seem to work initially, but upon disconnect/reconnect the pairing details are lost.
Also, if you've got more devices than this stored in the bond database, with the current inplementation of aioble the fact these are stored in a dict/json file means the order is not strictly controlled, so you can't know for certain which devices keys will be loaded first/last into the radio - which ever ones don't fit can fail to connect correctly.

As part of work to provide some control over this issue by allowing an application to limit the number of devices bonded, this gap_unpair() function is needed to remove keys from the ble stack / radio.

@codecov-commenter

codecov-commenter commented Sep 23, 2021 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.46%. Comparing base (2dc2e30) to head (b428fb8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7845      +/-   ##
==========================================
- Coverage   98.46%   98.46%   -0.01%     
==========================================
  Files         176      176              
  Lines       22784    22784              
==========================================
- Hits        22435    22434       -1     
- Misses        349      350       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@andrewleech
andrewleech force-pushed the unpair branch 2 times, most recently from de857fc to ae8b7f9 Compare September 27, 2021 07:57
@andrewleech andrewleech changed the title Draft: extmod/modbluetooth: Add gap_unpair command. extmod/modbluetooth: Add gap_unpair command. Sep 28, 2021
@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Oct 15, 2021
@andrewleech
andrewleech force-pushed the unpair branch 2 times, most recently from 97e6a24 to ccb33c3 Compare August 24, 2022 10:10
RetiredWizard pushed a commit to RetiredWizard/micropython that referenced this pull request Apr 16, 2023
@projectgus

Copy link
Copy Markdown
Contributor

This is an automated heads-up that we've just merged a Pull Request
that removes the STATIC macro from MicroPython's C API.

See #13763

A search suggests this PR might apply the STATIC macro to some C code. If it
does, then next time you rebase the PR (or merge from master) then you should
please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if
you have any questions about this.

@andrewleech
andrewleech force-pushed the unpair branch 2 times, most recently from 01fc245 to 0999f14 Compare May 9, 2025 00:22
@github-actions

github-actions Bot commented May 9, 2025 •

Copy link
Copy Markdown

Code size report:

Reference:  nrf: Add support for VfsRom filesystem. [6105520]
Comparison: extmod/modbluetooth: Use static instead of STATIC macro. [merge of 64ea800]
  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
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@andrewleech

Copy link
Copy Markdown
Contributor Author

Added tests/multi_bluetooth/ble_gap_unpair.py multitest to verify the gap_unpair functionality.

Testing:

  • Tested on NUCLEO-WB55 (STM32WB55RGV6) and PYBD-SF6W (STM32F767IIK)
  • Both devices running NimBLE stack
  • Test validates pairing/bonding followed by unpair operation
  • Verified with role permutations (both devices as peripheral/central)
  • All test permutations pass

The test captures bond keys from _IRQ_SET_SECRET events during pairing, then calls gap_unpair() with each captured key to verify the unpair operation completes without error.

This function removes pairing/bonding information from the bond
database, freeing up IRK slots. Implemented for both NimBLE and
BTstack backends.

Includes multi_bluetooth test and documentation.

Signed-off-by: Andrew Leech <[email protected]>
Signed-off-by: Andrew Leech <[email protected]>
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.

6 participants