Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/NimBLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,18 @@ void NimBLEDevice::setSecurityAuth(uint8_t auth_req) {
* * 0x03 BLE_HS_IO_NO_INPUT_OUTPUT NoInputNoOutput IO capability
* * 0x04 BLE_HS_IO_KEYBOARD_DISPLAY KeyboardDisplay Only IO capability
*/
/**
* @brief Set whether a Security Request from a peer we have no keys for
* automatically sends a Pairing Request.
* @param [in] enable true (default): pair immediately. false: ignore the
* request; the application pairs via NimBLEClient::secureConnection().
* @details Some peripherals never answer a Pairing Request sent in the same
* instant as their own Security Request.
*/
void NimBLEDevice::setSecurityAutoPairOnSecReq(bool enable) {
ble_hs_cfg.sm_sec_req_auto_pair = enable;
} // setSecurityAutoPairOnSecReq

void NimBLEDevice::setSecurityIOCap(uint8_t iocap) {
ble_hs_cfg.sm_io_cap = iocap;
} // setSecurityIOCap
Expand Down
1 change: 1 addition & 0 deletions src/NimBLEDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class NimBLEDevice {
static void setSecurityAuth(bool bonding, bool mitm, bool sc);
static void setSecurityAuth(uint8_t auth);
static void setSecurityIOCap(uint8_t iocap);
static void setSecurityAutoPairOnSecReq(bool enable);
static void setSecurityInitKey(uint8_t initKey);
static void setSecurityRespKey(uint8_t respKey);
static void setSecurityPasskey(uint32_t passKey);
Expand Down
10 changes: 10 additions & 0 deletions src/nimble/nimble/host/include/host/ble_hs.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ struct ble_hs_cfg {
*/
unsigned sm_keypress:1;

/** @brief Security Manager - auto-pair on Security Request
*
* If set (default), a Security Request from a peer we have no keys for
* immediately triggers a Pairing Request. If clear, it is ignored and the
* application initiates pairing (ble_gap_security_initiate). Some
* peripherals never answer a Pairing Request sent in the same instant as
* their Security Request. Peers we have keys for are unaffected.
*/
unsigned sm_sec_req_auto_pair:1;

/** @brief Security Manager Local Key Distribution Mask */
uint8_t sm_our_key_dist;

Expand Down
1 change: 1 addition & 0 deletions src/nimble/nimble/host/src/ble_hs_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct ble_hs_cfg ble_hs_cfg = {
.sm_mitm = MYNEWT_VAL(BLE_SM_MITM),
.sm_sc = MYNEWT_VAL(BLE_SM_SC),
.sm_keypress = MYNEWT_VAL(BLE_SM_KEYPRESS),
.sm_sec_req_auto_pair = MYNEWT_VAL(BLE_SM_SEC_REQ_AUTO_PAIR),
.sm_our_key_dist = MYNEWT_VAL(BLE_SM_OUR_KEY_DIST),
.sm_their_key_dist = MYNEWT_VAL(BLE_SM_THEIR_KEY_DIST),
};
11 changes: 10 additions & 1 deletion src/nimble/nimble/host/src/ble_sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,16 @@ ble_sm_sec_req_rx(uint16_t conn_handle, struct os_mbuf **om,
}
}
} else {
/* no keys present, start pairing */
/* no keys present: start pairing, unless the application wants to
* initiate pairing itself. In that case only a clean "no keys"
* result is ignored; store errors are propagated.
*/
if (!ble_hs_cfg.sm_sec_req_auto_pair) {
if (res->app_status == BLE_HS_ENOENT) {
res->app_status = 0;
}
return;
}
Comment thread
tonywestonuk marked this conversation as resolved.
start_pairing = true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/syscfg/syscfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@
#define MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS (0)
#endif

#ifndef MYNEWT_VAL_BLE_SM_SEC_REQ_AUTO_PAIR
#define MYNEWT_VAL_BLE_SM_SEC_REQ_AUTO_PAIR (1)
#endif

#ifndef MYNEWT_VAL_BLE_SM_SC_ONLY
#define MYNEWT_VAL_BLE_SM_SC_ONLY (0)
#endif
Expand Down