Repository navigation
Conversation
GATT client reads and writes passed ATT error codes from the peer to
`raise_zephyr_error()`, which expects a negative errno, so they came out as
`OSError` with a negative number. They now go through a new
`check_gattc_status()`, which maps the same ATT errors as espressif and
nordic:
- 0x02, 0x03: `BluetoothError("read not permitted")` / `"write not permitted"`
- 0x05: `SecurityError("Insufficient authentication")`
- 0x08: `SecurityError("Insufficient authorization")`
- 0x0C, 0x0F: `SecurityError("Insufficient encryption")`
- 0x0D: `ValueError("Invalid length")`
- other ATT errors: "Unknown gatt error: 0x00xx"
Zephyr reports a disconnect during the request, and other local failures,
as `BT_ATT_ERR_UNLIKELY`. So the connection state is checked first, and a
dropped connection raises `ConnectionError`. Each request holds a reference
on the `bt_conn` so the check is safe after a disconnect.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannewt
approved these changes
Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Diagnosis and code by Claude, reviewed by @dhalbert.
Error reporting
OSError(-N), where N was the ATT error code.check_gattc_status()function now maps the same ATT errors as espressif: report GATT ATT errors as specific exceptions #11550 and nordic: report GATT write errors and map more ATT errors #11553 into readable exception messages:BluetoothError: read not permittedBluetoothError: write not permittedSecurityError: Insufficient authenticationSecurityError: Insufficient authorizationSecurityError: Insufficient encryptionValueError: Invalid lengthBluetoothError: Unknown gatt error: 0x00xxBT_ATT_ERR_UNLIKELY(0x0E). Socheck_gattc_status()checks the connection first and raisesConnectionErrorif it dropped.bt_connuntil that check, so it is safe after a disconnect.Testing
nRF54LM20 DK with this PR as central, Feather nRF52840 on nordic with #11553 as peripheral:
NO_ACCESS, unpaired read ofENCRYPT_NO_MITM, over-length write tofixed_lengthread not permitted,write not permitted,Insufficient authentication,Invalid lengthConnectionError, then no problemsble_uart_echo_client.pyfrom the BLE library examplespytest tests/bsim -k nrf5340