Skip to content

Commit 45977f8

Browse files
committed
lib: peer_manager: refactor Kconfig options
* Renames the `PM_SERVICE_CHANGED_ENABLED`, `PM_PEER_RANKS_ENABLED`, `PM_LESC_ENABLED`, and `PM_RA_PROTECTION_ENABLED` kconfig options to align with Zephyr's coding style. * Improves prompts and descriptions of Kconfig options. * Moves secondary `PM_RA_PROTECTION` Kconfigs inside conditional block. * Removes explicit `default n`. * Fixes doxygen sections related to Kconfig options. * Refactors the Peer Manager to use the `#if defined` (or `#if !defined`) preprocessor pattern where appropriate.
1 parent b7b876a commit 45977f8

File tree

14 files changed

+106
-107
lines changed

14 files changed

+106
-107
lines changed

doc/nrf-bm/libraries/bluetooth/peer_manager.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The Security Dispatcher interfaces with the SoftDevice and the non-volatile stor
7373
LE Secure Connections support
7474
=============================
7575

76-
You can enable support for LE Secure Connections (LESC) pairing by setting the :kconfig:option:`CONFIG_PM_LESC_ENABLED` Kconfig option.
76+
You can enable support for LE Secure Connections (LESC) pairing by setting the :kconfig:option:`CONFIG_PM_LESC` Kconfig option.
7777
This functionality is disabled by default.
7878
In this mode, the Peer Manager handles internally all requests for Diffie-Hellman keys from the SoftDevice.
7979
When enabled, it is necessary to call the :c:func:`nrf_ble_lesc_request_handler` function in the main context of the application.
@@ -82,7 +82,7 @@ If there is any pending DH key request, the function will calculate the requeste
8282
Repeated pairing attempts protection
8383
====================================
8484

85-
You can enable protection against repeated pairing attempts by setting the :kconfig:option:`CONFIG_PM_RA_PROTECTION_ENABLED` Kconfig option.
85+
You can enable protection against repeated pairing attempts by setting the :kconfig:option:`CONFIG_PM_RA_PROTECTION` Kconfig option.
8686
This functionality is disabled by default.
8787
In this mode, the Peer Manager uses the timing module to keep track of peers that failed at the pairing procedure.
8888
Future pairing attempts from these peers are rejected for a certain period of time.
@@ -131,8 +131,8 @@ Set the :kconfig:option:`CONFIG_PEER_MANAGER` Kconfig option to enable the libra
131131

132132
Some features are disabled by default and can be optionally enabled:
133133

134-
* :kconfig:option:`CONFIG_PM_LESC_ENABLED` - Enables LESC support in Peer Manager.
135-
* :kconfig:option:`CONFIG_PM_RA_PROTECTION_ENABLED` - Enables protection against repeated pairing attempts in Peer Manager.
134+
* :kconfig:option:`CONFIG_PM_LESC` - Enables LESC support in Peer Manager.
135+
* :kconfig:option:`CONFIG_PM_RA_PROTECTION` - Enables protection against repeated pairing attempts in Peer Manager.
136136

137137
Initialization
138138
==============

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ Libraries
5757

5858
* Added missing Kconfig dependencies.
5959

60+
* :ref:`lib_peer_manager` library:
61+
62+
* Updated:
63+
64+
* The ``CONFIG_PM_SERVICE_CHANGED_ENABLED`` Kconfig option to :kconfig:option:`CONFIG_PM_SERVICE_CHANGED`.
65+
* The ``CONFIG_PM_PEER_RANKS_ENABLED`` Kconfig option to :kconfig:option:`CONFIG_PM_PEER_RANKS`.
66+
* The ``CONFIG_PM_LESC_ENABLED`` Kconfig option to :kconfig:option:`CONFIG_PM_LESC`.
67+
* The ``CONFIG_PM_RA_PROTECTION_ENABLED`` Kconfig option to :kconfig:option:`CONFIG_PM_RA_PROTECTION`.
68+
6069
Samples
6170
=======
6271

include/bluetooth/peer_manager/peer_manager.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ uint32_t pm_conn_sec_params_reply(uint16_t conn_handle, ble_gap_sec_params_t *p_
200200
* PM_EVT_SERVICE_CHANGED_IND_CONFIRMED when the peer sends its confirmation. Peers that
201201
* are not subscribed to the service changed indication when this function is called do not
202202
* receive an indication, and no events are sent to the user. Likewise, if the service
203-
* changed characteristic is not present in the local database, or if the @ref
204-
* PM_SERVICE_CHANGED_ENABLED is set to 0, no indications are sent peers, and no events are
205-
* sent to the user.
203+
* changed characteristic is not present in the local database, or if the
204+
* @c CONFIG_PM_SERVICE_CHANGED Kconfig option is disabled, no indications are sent peers,
205+
* and no events are sent to the user.
206206
*/
207207
void pm_local_database_has_changed(void);
208208

@@ -241,15 +241,16 @@ bool pm_sec_is_sufficient(uint16_t conn_handle, pm_conn_sec_status_t *p_sec_stat
241241
*
242242
* @note The key must continue to reside in application memory as it is not copied by Peer Manager.
243243
*
244-
* @note This function is deprecated. LESC keys are now handled internally if @ref PM_LESC_ENABLED
245-
* is true. If @ref PM_LESC_ENABLED is false, this function works as before.
244+
* @note This function is deprecated. LESC keys are now handled internally if the @c CONFIG_PM_LESC
245+
* Kconfig option is enabled. If the @c CONFIG_PM_LESC Kconfig option is disabled, this
246+
* function works as before.
246247
*
247248
* @param[in] p_public_key The public key to use for all subsequent LESC operations.
248249
*
249250
* @retval NRF_SUCCESS If pairing was initiated successfully.
250251
* @retval NRF_ERROR_INVALID_STATE If the Peer Manager is not initialized.
251-
* @retval NRF_ERROR_FORBIDDEN If LESC module support is enabled (see @ref
252-
* PM_LESC_ENABLED).
252+
* @retval NRF_ERROR_FORBIDDEN If LESC module support is enabled (see the
253+
* @c CONFIG_PM_LESC Kconfig option).
253254
*/
254255
uint32_t pm_lesc_public_key_set(ble_gap_lesc_p256_pk_t *p_public_key);
255256

@@ -772,8 +773,8 @@ uint32_t pm_peers_delete(void);
772773
* @retval NRF_ERROR_NOT_FOUND If no peer with stored peer rank was found.
773774
* @retval NRF_ERROR_INVALID_STATE If the Peer Manager is not initialized.
774775
* @retval NRF_ERROR_INTERNAL If an internal error occurred.
775-
* @retval NRF_ERROR_NOT_SUPPORTED If peer rank functionality has been disabled via the @ref
776-
* PM_PEER_RANKS_ENABLED configuration option.
776+
* @retval NRF_ERROR_NOT_SUPPORTED If peer rank functionality has been disabled via the
777+
* @c CONFIG_PM_PEER_RANKS Kconfig option.
777778
*/
778779
uint32_t pm_peer_ranks_get(pm_peer_id_t *p_highest_ranked_peer, uint32_t *p_highest_rank,
779780
pm_peer_id_t *p_lowest_ranked_peer, uint32_t *p_lowest_rank);
@@ -807,8 +808,8 @@ uint32_t pm_peer_ranks_get(pm_peer_id_t *p_highest_ranked_peer, uint32_t *p_high
807808
* around to 0. To fix this, manually update all ranks to smaller
808809
* values, while still keeping their order.
809810
* @retval NRF_ERROR_INTERNAL If an internal error occurred.
810-
* @retval NRF_ERROR_NOT_SUPPORTED If peer rank functionality has been disabled via the @ref
811-
* PM_PEER_RANKS_ENABLED configuration option.
811+
* @retval NRF_ERROR_NOT_SUPPORTED If peer rank functionality has been disabled via the
812+
* @c CONFIG_PM_PEER_RANKS Kconfig option.
812813
*/
813814
uint32_t pm_peer_rank_highest(pm_peer_id_t peer_id);
814815

lib/peer_manager/Kconfig

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,40 @@ menuconfig PEER_MANAGER
1818
if PEER_MANAGER
1919

2020
config PM_BM_ZMS_SECTOR_SIZE
21-
int "Sector size"
21+
int "BM_ZMS sector size"
2222
default 1024
2323

2424
config PM_BLE_OBSERVER_PRIO
25-
int "Priority with which BLE events are dispatched to the Peer Manager module."
25+
int "BLE events priority"
2626
default 1
2727
help
2828
Priority with which BLE events are dispatched to the Peer Manager module.
2929

3030
config PM_MAX_REGISTRANTS
31-
int "Number of event handlers that can be registered."
31+
int "Maximum number of event handlers that can be registered"
3232
default 3
33-
help
34-
Number of event handlers that can be registered.
3533

3634
config PM_FLASH_BUFFERS
37-
int "Number of internal buffers for flash operations."
35+
int "Number of internal buffers for non-volatile storage operations"
3836
default 4
3937
help
40-
Number of internal buffers for flash operations.
41-
Decrease this value to lower RAM usage.
38+
Decrease this value to reduce RAM usage.
4239

43-
config PM_SERVICE_CHANGED_ENABLED
44-
bool "Enable/disable the service changed management for GATT server in Peer Manager."
40+
config PM_SERVICE_CHANGED
41+
bool "Service changed management for GATT server"
4542
default y
4643
help
47-
Enable/disable the service changed management for GATT server in Peer Manager.
48-
If not using a GATT server, or using a server without a service changed characteristic,
49-
disable this to save code space.
44+
Disable this option to reduce memory usage if not using a GATT server, or using a server
45+
without a service changed characteristic.
5046

51-
config PM_PEER_RANKS_ENABLED
52-
bool "Enable/disable the peer rank management in Peer Manager."
47+
config PM_PEER_RANKS
48+
bool "Peer rank management"
5349
default y
5450
help
55-
Enable/disable the peer rank management in Peer Manager.
56-
Set this to false to save code space if not using the peer rank API.
51+
Disable this option to reduce memory usage if not using the peer rank API.
5752

58-
config PM_LESC_ENABLED
59-
bool "Enable/disable LESC support in Peer Manager."
60-
default n
53+
config PM_LESC
54+
bool "LE Secure Connections (LESC) support"
6155
depends on PSA_WANT_ALG_ECDH
6256
depends on PSA_WANT_GENERATE_RANDOM
6357
depends on PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE
@@ -68,16 +62,14 @@ config PM_LESC_ENABLED
6862
MBEDTLS_ENABLE_HEAP
6963

7064
help
71-
Enable/disable LESC support in Peer Manager.
72-
If set to true, you need to call nrf_ble_lesc_request_handler() in the main loop to
73-
respond to LESC-related BLE events. If LESC support is not required, set this to false to
74-
save code space.
65+
If enabled, you need to call nrf_ble_lesc_request_handler() in the main loop to
66+
respond to LESC-related BLE events. If LESC support is not required, disable this option
67+
to reduce memory usage.
7568

76-
if PM_LESC_ENABLED
69+
if PM_LESC
7770

7871
config PM_LESC_GENERATE_NEW_KEYS
7972
bool "Generate new LESC key pair after every pairing attempt"
80-
default n
8173
help
8274
New LESC keys are generated on the auth status event.
8375

@@ -87,45 +79,42 @@ config PM_LESC_PRIVATE_KEY_EXPORT
8779
Export private key.
8880
This is for for debugging purposes only and is not to be used in production!
8981

90-
endif # PM_LESC_ENABLED
82+
endif # PM_LESC
9183

92-
config PM_RA_PROTECTION_ENABLED
93-
bool "Enable/disable protection against repeated pairing attempts in Peer Manager."
94-
default n
84+
config PM_RA_PROTECTION
85+
bool "Protection against repeated pairing attempts"
9586
help
96-
Enable/disable protection against repeated pairing attempts in Peer Manager.
87+
Enable protection against repeated Bluetooth pairing attempts from the same device.
88+
Offending peers will be temporarily blacklisted with increasing backoff times to
89+
prevent pairing spam or brute-force attacks.
90+
91+
if PM_RA_PROTECTION
9792

9893
config PM_RA_PROTECTION_TRACKED_PEERS_NUM
99-
int "Maximum number of peers whose authorization status can be tracked."
94+
int "Maximum number of peers whose authorization status can be tracked"
10095
default 8
101-
help
102-
Maximum number of peers whose authorization status can be tracked.
10396

10497
config PM_RA_PROTECTION_MIN_WAIT_INTERVAL
105-
int "Minimum waiting interval (in ms) before a new pairing attempt can be initiated."
98+
int "Minimum waiting interval (in ms) before a new pairing attempt can be initiated"
10699
default 4000
107-
help
108-
Minimum waiting interval (in ms) before a new pairing attempt can be initiated.
109100

110101
config PM_RA_PROTECTION_MAX_WAIT_INTERVAL
111-
int "Maximum waiting interval (in ms) before a new pairing attempt can be initiated."
102+
int "Maximum waiting interval (in ms) before a new pairing attempt can be initiated"
112103
default 64000
113-
help
114-
Maximum waiting interval (in ms) before a new pairing attempt can be initiated.
115104

116105
config PM_RA_PROTECTION_REWARD_PERIOD
117-
int "Reward period (in ms)."
106+
int "Reward period (in ms)"
118107
default 10000
119108
help
120-
Reward period (in ms).
121109
The waiting interval is gradually decreased when no new failed pairing attempts are made
122110
during reward period.
123111

112+
endif # PM_RA_PROTECTION
113+
124114
config PM_HANDLER_SEC_DELAY_MS
125-
int "Delay before starting security."
115+
int "Delay before starting security"
126116
default 0
127117
help
128-
Delay before starting security.
129118
This might be necessary for interoperability reasons, especially as peripheral.
130119

131120
module=PEER_MANAGER

lib/peer_manager/modules/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ zephyr_library_sources(auth_status_tracker.c)
88
zephyr_library_sources(gatt_cache_manager.c)
99
zephyr_library_sources(gatts_cache_manager.c)
1010
zephyr_library_sources(id_manager.c)
11-
zephyr_library_sources_ifdef(CONFIG_PM_LESC_ENABLED nrf_ble_lesc.c)
11+
zephyr_library_sources_ifdef(CONFIG_PM_LESC nrf_ble_lesc.c)
1212
zephyr_library_sources(peer_data_storage.c)
1313
zephyr_library_sources(peer_database.c)
1414
zephyr_library_sources(peer_id.c)

lib/peer_manager/modules/gatt_cache_manager.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ static int m_flag_car_handle_queried;
127127
*/
128128
static int m_flag_car_value_queried;
129129

130-
#ifdef CONFIG_PM_SERVICE_CHANGED_ENABLED
131-
BUILD_ASSERT(IS_ENABLED(CONFIG_PM_SERVICE_CHANGED_ENABLED) ||
130+
#ifdef CONFIG_PM_SERVICE_CHANGED
131+
BUILD_ASSERT(IS_ENABLED(CONFIG_PM_SERVICE_CHANGED) ||
132132
!IS_ENABLED(CONFIG_NRF_SDH_BLE_SERVICE_CHANGED),
133-
"CONFIG_PM_SERVICE_CHANGED_ENABLED should be enabled "
133+
"CONFIG_PM_SERVICE_CHANGED should be enabled "
134134
"if NRF_SDH_BLE_SERVICE_CHANGED is enabled.");
135135
#else
136-
#define CONFIG_PM_SERVICE_CHANGED_ENABLED 1
136+
#define CONFIG_PM_SERVICE_CHANGED 1
137137
#endif
138138

139139
/**
@@ -310,7 +310,7 @@ static bool local_db_update_in_evt(uint16_t conn_handle)
310310
return success;
311311
}
312312

313-
#if CONFIG_PM_SERVICE_CHANGED_ENABLED
313+
#if defined(CONFIG_PM_SERVICE_CHANGED)
314314

315315
/**
316316
* @brief Function for getting the value of the CCCD for the service changed characteristic.
@@ -450,7 +450,7 @@ static void db_update_pending_handle(uint16_t conn_handle, void *p_context)
450450
}
451451
}
452452

453-
#if CONFIG_PM_SERVICE_CHANGED_ENABLED
453+
#if defined(CONFIG_PM_SERVICE_CHANGED)
454454
static void sc_send_pending_handle(uint16_t conn_handle, void *p_context)
455455
{
456456
ARG_UNUSED(p_context);
@@ -529,7 +529,7 @@ void gcm_im_evt_handler(pm_evt_t *p_event)
529529
switch (p_event->evt_id) {
530530
case PM_EVT_BONDED_PEER_CONNECTED:
531531
local_db_apply_in_evt(p_event->conn_handle);
532-
#if (CONFIG_PM_SERVICE_CHANGED_ENABLED == 1)
532+
#if defined(CONFIG_PM_SERVICE_CHANGED)
533533
service_changed_needed(p_event->conn_handle);
534534
#endif
535535
car_update_needed(p_event->conn_handle);
@@ -561,7 +561,7 @@ void gcm_pdb_evt_handler(pm_evt_t *p_event)
561561
break;
562562
}
563563

564-
#if CONFIG_PM_SERVICE_CHANGED_ENABLED
564+
#if defined(CONFIG_PM_SERVICE_CHANGED)
565565
case PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING: {
566566
uint32_t err_code;
567567
bool service_changed_pending = false;
@@ -676,7 +676,7 @@ void gcm_ble_evt_handler(ble_evt_t const *p_ble_evt)
676676
local_db_apply_in_evt(conn_handle);
677677
break;
678678

679-
#if CONFIG_PM_SERVICE_CHANGED_ENABLED
679+
#if defined(CONFIG_PM_SERVICE_CHANGED)
680680
case BLE_GATTS_EVT_SC_CONFIRM: {
681681
pm_evt_t event = {
682682
.evt_id = PM_EVT_SERVICE_CHANGED_IND_CONFIRMED,
@@ -779,7 +779,7 @@ void gcm_ble_evt_handler(ble_evt_t const *p_ble_evt)
779779
}
780780

781781
apply_pending_flags_check();
782-
#if CONFIG_PM_SERVICE_CHANGED_ENABLED
782+
#if defined(CONFIG_PM_SERVICE_CHANGED)
783783
service_changed_pending_flags_check();
784784
#endif
785785
}
@@ -794,7 +794,7 @@ uint32_t gcm_local_db_cache_update(uint16_t conn_handle)
794794
return NRF_SUCCESS;
795795
}
796796

797-
#if CONFIG_PM_SERVICE_CHANGED_ENABLED
797+
#if defined(CONFIG_PM_SERVICE_CHANGED)
798798
void gcm_local_database_has_changed(void)
799799
{
800800
gscm_local_database_has_changed();

lib/peer_manager/modules/gatts_cache_manager.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
LOG_MODULE_DECLARE(peer_manager, CONFIG_PEER_MANAGER_LOG_LEVEL);
2323

24-
#if !defined(CONFIG_PM_SERVICE_CHANGED_ENABLED) || (CONFIG_PM_SERVICE_CHANGED_ENABLED == 1)
24+
#if defined(CONFIG_PM_SERVICE_CHANGED)
2525

2626
/* The number of registered event handlers. */
2727
#define GSCM_EVENT_HANDLERS_CNT ARRAY_SIZE(m_evt_handlers)
@@ -49,11 +49,11 @@ static void internal_state_reset(void)
4949
m_module_initialized = false;
5050
m_current_sc_store_peer_id = PM_PEER_ID_INVALID;
5151

52-
/* If CONFIG_PM_SERVICE_CHANGED_ENABLED is 0, this variable is unused. */
52+
/* If CONFIG_PM_SERVICE_CHANGED is 0, this variable is unused. */
5353
UNUSED_VARIABLE(m_current_sc_store_peer_id);
5454
}
5555

56-
#if !defined(CONFIG_PM_SERVICE_CHANGED_ENABLED) || (CONFIG_PM_SERVICE_CHANGED_ENABLED == 1)
56+
#if defined(CONFIG_PM_SERVICE_CHANGED)
5757
static void evt_send(pm_evt_t *p_gscm_evt)
5858
{
5959
p_gscm_evt->conn_handle = im_conn_handle_get(p_gscm_evt->peer_id);
@@ -319,7 +319,7 @@ uint32_t gscm_local_db_cache_apply(uint16_t conn_handle)
319319
return err_code;
320320
}
321321

322-
#if !defined(CONFIG_PM_SERVICE_CHANGED_ENABLED) || (CONFIG_PM_SERVICE_CHANGED_ENABLED == 1)
322+
#if defined(CONFIG_PM_SERVICE_CHANGED)
323323
void gscm_local_database_has_changed(void)
324324
{
325325
NRF_PM_DEBUG_CHECK(m_module_initialized);

lib/peer_manager/modules/peer_database.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ LOG_MODULE_DECLARE(peer_manager, CONFIG_PEER_MANAGER_LOG_LEVEL);
3838
/* Peer Database event handlers in other Peer Manager submodules. */
3939
extern void pm_pdb_evt_handler(pm_evt_t *p_event);
4040
extern void sm_pdb_evt_handler(pm_evt_t *p_event);
41-
#if !defined(CONFIG_PM_SERVICE_CHANGED_ENABLED) || (CONFIG_PM_SERVICE_CHANGED_ENABLED == 1)
41+
#if defined(CONFIG_PM_SERVICE_CHANGED)
4242
extern void gscm_pdb_evt_handler(pm_evt_t *p_event);
4343
#endif
4444
extern void gcm_pdb_evt_handler(pm_evt_t *p_event);
@@ -50,7 +50,7 @@ extern void gcm_pdb_evt_handler(pm_evt_t *p_event);
5050
static pm_evt_handler_internal_t const m_evt_handlers[] = {
5151
pm_pdb_evt_handler,
5252
sm_pdb_evt_handler,
53-
#if !defined(CONFIG_PM_SERVICE_CHANGED_ENABLED) || (CONFIG_PM_SERVICE_CHANGED_ENABLED == 1)
53+
#if defined(CONFIG_PM_SERVICE_CHANGED)
5454
gscm_pdb_evt_handler,
5555
#endif
5656
gcm_pdb_evt_handler,

0 commit comments

Comments
 (0)