Protocol constant cleanup + NimBLE callback race fix (stacked on #107)#108
Merged
Conversation
…dit #1-3,6) The Bluedroid->NimBLE migration left heavyweight, state-mutating work running inline inside the ESP32 server callbacks on the NimBLE host task, racing the Arduino loop() task. Make the callbacks flag-only and service the flags from loop(), mirroring the existing bleRestartAdvertisingPending pattern. - onDisconnect: EPD session teardown (bbepSleep/delay/SPI.end + rail cut), partial + pipe cleanup, and resetPipeWriteState() ran on the host task while loop() streamed SPI via bbepWriteData and processed pipe frames. The only guard (epdRefreshInProgress) covered the refresh phase, not streaming. Now sets bleDisconnectCleanupPending; serviced by serviceBleDisconnectCleanup() in loop() (preserving the epdRefreshInProgress deferral), run before the advertising restart. (#1 critical, #2 high, OpenDisplay#6 medium) - onConnect: updatemsdata() polled I2C and mutated the shared advertisement vector that loop() also drives on its 60s cadence -> heap corruption. Now sets msdUpdatePending; loop() calls updatemsdata(). (#3 high) - updatemsdata(): drop the connected-branch that rebuilt *advertisementData but never pushed it via setAdvertisementData() -- dead work, no behavior change. All ESP32-guarded; nRF/Bluefruit path untouched. Builds clean on esp32-s3-N16R8, esp32-c3-N16, nrf52840custom. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Follow-up to the header vendoring (3f09f6d): sweep the remaining hand-coded protocol literals across the BLE command handlers and use the constants from the vendored opendisplay_protocol.h. Value-for-value, no wire-behavior change; all CI envs build clean. - encryption.cpp: auth-status frames -> RESP_ACK/RESP_AUTHENTICATE + AUTH_STATUS_*; CCM envelope sizes -> BLE_CMD_HEADER_SIZE/ ENCRYPTION_NONCE_SIZE/ENCRYPTION_TAG_SIZE (handshake nonces left as-is). - communication.cpp: handler response codes -> RESP_* (incl. RESP_AUTH_REQUIRED); config limits -> CONFIG_CHUNK_SIZE*/ MAX_CONFIG_CHUNKS/MAX_RESPONSE_DATA_SIZE; envelope sizes. - device_control.cpp / buzzer_control.cpp: LED, deep-sleep, and buzzer ack/nack frames -> RESP_*. - display_service.cpp: direct-write/refresh frames -> RESP_DIRECT_WRITE_*; pipe-start errors -> OD_ERR_PIPE_START_*; deleted the local ERR_* shadow copies of OD_ERR_PARTIAL_* in favor of the canonical names. Pipe/partial-write opcode-echo bytes (0x76/0x80/0x81/0x82), the pipe data-phase error codes, and the START response-flags bit stay raw with TODO(protocol) markers: the canonical header defines no RESP_* mirror or data-phase error namespace for them yet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
davelee98
force-pushed
the
debug/v2.2-audit
branch
from
July 18, 2026 13:45
7c6df0b to
b83d824
Compare
davelee98
marked this pull request as ready for review
July 18, 2026 13:46
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.
What this adds on top of #107
1.
fix(ble): defer NimBLE onConnect/onDisconnect work to loop()(0e7bf79)Moves connect/disconnect handling out of the NimBLE callback context into
loop()to resolve races surfaced in the NimBLE migration audit (#1–3, 6).2.
Replace protocol magic numbers with canonical named constants(7c6df0b)Follow-up to the header vendoring: sweeps the remaining hand-coded protocol literals across the BLE command handlers and uses the constants from the vendored
opendisplay_protocol.h. Value-for-value — no wire-behavior change.RESP_ACK/RESP_AUTHENTICATE+AUTH_STATUS_*; CCM envelope sizes →BLE_CMD_HEADER_SIZE/ENCRYPTION_NONCE_SIZE/ENCRYPTION_TAG_SIZE(handshake nonces left as-is).RESP_*(incl.RESP_AUTH_REQUIRED); config limits →CONFIG_CHUNK_SIZE*/MAX_CONFIG_CHUNKS/MAX_RESPONSE_DATA_SIZE; envelope sizes.RESP_*.RESP_DIRECT_WRITE_*; pipe-start errors →OD_ERR_PIPE_START_*; deleted the localERR_*shadow copies ofOD_ERR_PARTIAL_*in favor of the canonical names.Documented header gaps (
TODO(protocol))Left raw with in-code
TODO(protocol)markers because the canonical header has no constant for them yet: pipe/partial opcode-echo bytes (0x76/0x80/0x81/0x82), the pipe data-phase error codes, and the START response-flags bit. Each TODO names the constant to add upstream inopendisplay-protocol.Verification
nrf52840custom,esp32-s3-N16R8,esp32-c3-N16.sync_protocol_header.py --check).🤖 Generated with Claude Code