feat(nimble): Added host config to enable or disable SC Only mode during runtime

This commit is contained in:
Sumeet Singh
2024-11-28 12:33:01 +05:30
committed by Rahul Tank
parent d29bed90d6
commit 36d16f1e59
4 changed files with 12 additions and 3 deletions
+8
View File
@@ -315,6 +315,14 @@ struct ble_hs_cfg {
*/
unsigned sm_sc:1;
/** @brief Security Manager - Enable/Disable Secure Connections Only flag
*
* If set, this will enforce P-256 elliptic curve encryption algorithm
* during pairing.
* It will force the max key size to be used during pairing.
*/
unsigned sm_sc_only:1;
/** @brief Security Manager Key Press Notification flag
*
* Currently unsupported and should not be set.
+1 -1
View File
@@ -325,7 +325,7 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
/* In SC Only mode all characteristics requiring security
* require it on level 4
*/
if (MYNEWT_VAL(BLE_SM_SC_ONLY)) {
if (ble_hs_cfg.sm_sc_only) {
if (!sec_state.authenticated ||
!sec_state.encrypted) {
*out_att_err = BLE_ATT_ERR_INSUFFICIENT_AUTHEN;
+1
View File
@@ -27,6 +27,7 @@ struct ble_hs_cfg ble_hs_cfg = {
.sm_bonding = MYNEWT_VAL(BLE_SM_BONDING),
.sm_mitm = MYNEWT_VAL(BLE_SM_MITM),
.sm_sc = MYNEWT_VAL(BLE_SM_SC),
.sm_sc_only = MYNEWT_VAL(BLE_SM_SC_ONLY),
.sm_keypress = MYNEWT_VAL(BLE_SM_KEYPRESS),
.sm_our_key_dist = MYNEWT_VAL(BLE_SM_OUR_KEY_DIST),
.sm_their_key_dist = MYNEWT_VAL(BLE_SM_THEIR_KEY_DIST),
+2 -2
View File
@@ -1930,7 +1930,7 @@ ble_sm_pair_req_rx(uint16_t conn_handle, struct os_mbuf **om,
} else if (req->max_enc_key_size > BLE_SM_PAIR_KEY_SZ_MAX) {
res->sm_err = BLE_SM_ERR_INVAL;
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_INVAL);
} else if (MYNEWT_VAL(BLE_SM_SC_ONLY)) {
} else if (ble_hs_cfg.sm_sc_only) {
/* Fail if Secure Connections Only mode is on and remote does not
* meet key size requirements - MITM was checked in last step.
* Fail if SC is not supported by peer or key size is too small
@@ -2005,7 +2005,7 @@ ble_sm_pair_rsp_rx(uint16_t conn_handle, struct os_mbuf **om,
} else if (rsp->max_enc_key_size > BLE_SM_PAIR_KEY_SZ_MAX) {
res->sm_err = BLE_SM_ERR_INVAL;
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_INVAL);
} else if (MYNEWT_VAL(BLE_SM_SC_ONLY) && (rsp->max_enc_key_size != BLE_SM_PAIR_KEY_SZ_MAX)) {
} else if (ble_hs_cfg.sm_sc_only && (rsp->max_enc_key_size != BLE_SM_PAIR_KEY_SZ_MAX)) {
/* Fail if Secure Connections Only mode is on and remote does not meet
* key size requirements - MITM was checked in last step
*/