Skip to content

Commit 218f7c1

Browse files
bluetooth: subsys: samples: clarify BMS auth code Kconfig scope
The BMS authorization code configuration has been aligned with its actual usage by making it sample‑specific. CONFIG_BLE_BMS_AUTHORIZATION_CODE (and BLE_BMS_AUTHORIZATION_CODE) was previously defined at the BMS library level even though it is only used by the BLE BMS sample. This change clarifies the configuration scope and avoids confusion for users by ensuring the authorization code setting is defined and documented where it is actually applied. Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
1 parent 28e42b8 commit 218f7c1

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

samples/bluetooth/ble_bms/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ config APP_BLE_BMS_PEERS_TO_DELETE_ON_DISCONNECT_MAX
1414
int "Maximum number of peers to delete upon a peer disconnect"
1515
default 10
1616

17+
config APP_BLE_BMS_USE_AUTHORIZATION_CODE
18+
bool "Use authorization code"
19+
default y
20+
21+
config APP_BLE_BMS_AUTHORIZATION_CODE
22+
string "Authorization code"
23+
default "ABCD"
24+
1725
module=APP_BLE_BMS
1826
module-str=BLE Bond Management Service Sample
1927
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

samples/bluetooth/ble_bms/README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ Testing
106106
#. Reconnect the devices and verify that the connection security is not updated.
107107
#. Bond both devices again.
108108
#. Write ``06 41 42 43 44`` to the Bond Management Service Control Point Characteristic.
109-
``06`` is the command to delete all bonds on the server, followed by the authorization code ``ABCD``.
109+
``06`` is the command to delete all bonds on the server, followed by the authorization code ``ABCD`` (ASCII ``41 42 43 44``).
110110
#. Disconnect the device to trigger the bond deletion procedures.
111111
#. Delete the bond information of the central device again.
112112
#. Reconnect the devices again and verify that the connection security is not updated.
113+
114+
.. note::
115+
The default authorization code ``ABCD`` (ASCII ``41 42 43 44``) is configurable through the :kconfig:option:`CONFIG_APP_BLE_BMS_AUTHORIZATION_CODE` Kconfig option. The maximum allowed length is :c:macro:`BLE_BMS_AUTH_CODE_MAX_LEN` (127 bytes), which comes from the BMS control point definition.
116+
117+
Authorization codes up to **127 bytes** are supported. You may configure the code to any value within this limit as needed.
118+
119+
If this security feature is not required, it can be enabled or disabled using the :kconfig:option:`CONFIG_APP_BLE_BMS_USE_AUTHORIZATION_CODE` Kconfig option. After changing the configuration, rebuild the sample and test how bond deletion behaves with or without an authorization code.

samples/bluetooth/ble_bms/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,10 @@ void bms_evt_handler(struct ble_bms *bms, struct ble_bms_evt *evt)
433433
break;
434434
case BLE_BMS_EVT_AUTH:
435435
LOG_DBG("Authorization request.");
436-
#if defined(CONFIG_BLE_BMS_USE_AUTHORIZATION_CODE)
437-
if ((evt->auth.auth_code.len != strlen(CONFIG_BLE_BMS_AUTHORIZATION_CODE)) ||
438-
(memcmp(CONFIG_BLE_BMS_AUTHORIZATION_CODE, evt->auth.auth_code.code,
439-
strlen(CONFIG_BLE_BMS_AUTHORIZATION_CODE)) != 0)) {
436+
#if defined(CONFIG_APP_BLE_BMS_USE_AUTHORIZATION_CODE)
437+
if ((evt->auth.auth_code.len != strlen(CONFIG_APP_BLE_BMS_AUTHORIZATION_CODE)) ||
438+
(memcmp(CONFIG_APP_BLE_BMS_AUTHORIZATION_CODE, evt->auth.auth_code.code,
439+
strlen(CONFIG_APP_BLE_BMS_AUTHORIZATION_CODE)) != 0)) {
440440
is_authorized = false;
441441
}
442442
#endif
@@ -594,7 +594,7 @@ int main(void)
594594

595595
struct ble_bms_config bms_cfg = {
596596
.evt_handler = bms_evt_handler,
597-
#if defined(CONFIG_BLE_BMS_USE_AUTHORIZATION_CODE)
597+
#if defined(CONFIG_APP_BLE_BMS_USE_AUTHORIZATION_CODE)
598598
/* Do not require auth to delete requesting. */
599599
.feature.delete_requesting = true,
600600
.feature.delete_all_auth = true,

subsys/bluetooth/services/ble_bms/Kconfig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ menuconfig BLE_BMS
1212

1313
if BLE_BMS
1414

15-
config BLE_BMS_USE_AUTHORIZATION_CODE
16-
bool "Use authorization code"
17-
default y
18-
19-
config BLE_BMS_AUTHORIZATION_CODE
20-
string "Authorization code"
21-
default "ABCD"
22-
2315
module=BLE_BMS
2416
module-str=BLE_BMS
2517
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

0 commit comments

Comments
 (0)