Skip to content

nimble/host: add BLE_SM_SEC_REQ_AUTO_PAIR - #2287

Closed
tonywestonuk wants to merge 1 commit into
apache:masterfrom
tonywestonuk:sm-sec-req-auto-pair
Closed

tonywestonuk wants to merge 1 commit into
apache:masterfrom
tonywestonuk:sm-sec-req-auto-pair

Conversation

@tonywestonuk

Copy link
Copy Markdown

When a peer sends a Security Request and no keys are stored for it, the host immediately replies with a Pairing Request from inside ble_sm_sec_req_rx(). Some peripherals (e.g. the Okida OT-2000 BLE module used in older Glen Dimplex/Stoves ovens) send a Security Request as soon as the connection is established and do not respond to a Pairing Request sent that early; pairing then times out. The same devices pair fine when the central initiates pairing a moment later, which the Core Spec allows (Vol 3, Part H, 2.4.6: the central may initiate pairing in response to a Security Request, it is not required to).

Add a syscfg setting BLE_SM_SEC_REQ_AUTO_PAIR (default 1, stock behaviour) mirrored in ble_hs_cfg.sm_sec_req_auto_pair. When cleared, a Security Request from a peer with no stored keys is accepted but no Pairing Request is sent; the application initiates pairing itself with ble_gap_security_initiate(). Store errors other than BLE_HS_ENOENT are still propagated. Peers with stored keys are unaffected.

When a peer sends a Security Request and no keys are stored for it, the
host immediately replies with a Pairing Request from inside
ble_sm_sec_req_rx(). Some peripherals (e.g. the Okida OT-2000 BLE module
used in older Glen Dimplex/Stoves ovens) send a Security Request as soon
as the connection is established and do not respond to a Pairing Request
sent that early; pairing then times out. The same devices pair fine when
the central initiates pairing a moment later, which the Core Spec allows
(Vol 3, Part H, 2.4.6: the central may initiate pairing in response to a
Security Request, it is not required to).

Add a syscfg setting BLE_SM_SEC_REQ_AUTO_PAIR (default 1, stock
behaviour) mirrored in ble_hs_cfg.sm_sec_req_auto_pair. When cleared, a
Security Request from a peer with no stored keys is accepted but no
Pairing Request is sent; the application initiates pairing itself with
ble_gap_security_initiate(). Store errors other than BLE_HS_ENOENT are
still propagated. Peers with stored keys are unaffected.

@sjanc sjanc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I'm not sure if this is correct approach.
Unlike what commit message states, spec requires central (shall) to start pairing after receiving Security Request

If this is for IOP issue with specific device, I'd rather suggest to allow delaying sending Pairing Request by specified delay. Specification doesn't forbid that from what I can see (however I'd suggest to keep this delay low, likely way below 30s). This should be under opt-in MYNEWT_VAL() option.

You may also make this timer one-shot per connection, where this would delay Pairing Request only if connection was established less than specified time before.

@tonywestonuk

Copy link
Copy Markdown
Author

Thanks @sjanc, good catch! You're right, I misread the spec there.

I'll give your delay idea a go. First I'll check how long this oven actually needs, then update the PR with an opt-in, one-shot-per-connection delay. I'll report back soon 🙂

@tonywestonuk

Copy link
Copy Markdown
Author

Thanks again @sjanc. I've done the measurement, and it turns out no host change is needed.

Setup: ESP32-C3 with NimBLE-Arduino 2.5.1, 50 ms connection interval, SMP PDUs timestamped in ble_sm_rx/ble_sm_tx. When the Pairing Request was sent immediately from ble_sm_sec_req_rx, pairing failed 0/8. Sending it from the app 2–1000 ms after the Security Request worked 28/28. But the peer's Pairing Response reached the host every time, including the failures. The real bug was in the Arduino wrapper: BLE_GAP_EVENT_CONNECT waits for the remote features read, so BLE_GAP_EVENT_PASSKEY_ACTION can arrive before it, and NimBLEClient dropped it. Fixed there in h2zero/NimBLE-Arduino#1214. Stock NimBLE now pairs 6/6.

So I'm closing this. Thanks for pushing back; it led to the actual bug.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants