Skip to content

Commit 190ff63

Browse files
bluetooth: mesh: update le pair responder model with BT_APP_PASSKEY
BT_FIXED_PASSKEY is depracated so wee need to aling the le pair responder model with the new Kconfig BT_APP_PASSKEY usage. Adding bt_mesh_le_pair_resp_passkey_get to be able to retreive the passkey set randomly or by app. Signed-off-by: alperen sener <[email protected]>
1 parent 97c8465 commit 190ff63

File tree

6 files changed

+382
-235
lines changed

6 files changed

+382
-235
lines changed

doc/nrf/libraries/bluetooth/mesh/vnd/images/bt_mesh_le_pair_resp.svg

Lines changed: 344 additions & 210 deletions
Loading

doc/nrf/libraries/bluetooth/mesh/vnd/le_pair_resp.rst

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@ LE Pairing Responder
77
:local:
88
:depth: 2
99

10-
The LE Pairing Responder model is a vendor model.
10+
The LE Pairing Responder model is a vendor model and it requires :kconfig:option:`CONFIG_BT_APP_PASSKEY` option to be enabled.
1111
This model can be used to hand over a passkey that will authenticate a Bluetooth LE connection over a mesh network when it is not possible to use other pairing methods.
1212

13-
Before the pairing is initiated, an initiator should send an LE Pairing message with Passkey Reset sub-opcode to set a new passkey for the next pairing request.
13+
Before the pairing is initiated, an initiator should send an LE Pairing message with Passkey Reset sub-opcode. This will trigger random passkey generation by LE Pairing Responder model or return the passkey set by the app using :c:func:`bt_mesh_le_pair_resp_passkey_set` function.
1414
The passkey returned in the LE Pairing message with the Passkey Status sub-opcode should be used for the next pairing.
1515

16-
The passkey is generated using the :c:func:`bt_rand` function and set to the host using the :c:func:`bt_passkey_set` function.
17-
The latter requires the :kconfig:option:`CONFIG_BT_FIXED_PASSKEY` option to be enabled.
18-
19-
.. note::
20-
The warning generated by the :kconfig:option:`CONFIG_BT_FIXED_PASSKEY` option should be disregarded as long as the application always invalidates the previously used passkey by calling the :c:func:`bt_mesh_le_pair_resp_passkey_invalidate` function regardless of the pairing result (see below).
21-
22-
This model requires an application to only enable the display capability for the LE pairing by setting the :c:member:`bt_conn_auth_cb.pairing_display` callback.
23-
After every pairing request, the application must invalidate the previously used passkey by calling the :c:func:`bt_mesh_le_pair_resp_passkey_invalidate` function.
24-
This function can be called from callbacks :c:member:`bt_conn_auth_info_cb.pairing_complete` and :c:member:`bt_conn_auth_info_cb.pairing_failed`.
25-
See the :file:`samples/bluetooth/mesh/common/smp_bt_auth.c` file for the reference.
16+
This model requires an application to only enable the display capability for the LE pairing by setting the :c:member:`bt_conn_auth_cb.pairing_display` callback. The application must also set the :c:member:`bt_conn_auth_cb.app_passkey` callback to use the passkey generated by LE Pairing Responder model.
17+
After every pairing request, the application must invalidate the previously used passkey by calling the :c:func:`bt_mesh_le_pair_resp_passkey_invalidate` function or calling :c:func:`bt_mesh_le_pair_resp_passkey_set` with :ref:`BT_PASSKEY_RAND` value.
18+
Those functions can be called from callbacks :c:member:`bt_conn_auth_info_cb.pairing_complete` and :c:member:`bt_conn_auth_info_cb.pairing_failed`. See the :file:`samples/bluetooth/mesh/common/smp_bt_auth.c` file for the reference.
2619

2720
.. figure:: images/bt_mesh_le_pair_resp.svg
2821
:alt: Diagram of interaction between an Initiator and the LE Pairing Responder model

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ Bluetooth Mesh
163163
* Deprecated the :kconfig:option:`CONFIG_BT_MESH_NLC_PERF_CONF` and :kconfig:option:`CONFIG_BT_MESH_NLC_PERF_DEFAULT` Kconfig options.
164164
Existing configurations continue to work but you should migrate to individual profile options.
165165

166+
* Update the LE Pairing Responder model:
167+
168+
* Deprecated the :kconfig:option:`CONFIG_BT_FIXED_PASSKEY` option in favor of the new and supported :kconfig:option:`CONFIG_BT_APP_PASSKEY` option.
169+
166170
DECT NR+
167171
--------
168172

@@ -386,6 +390,8 @@ Bluetooth Mesh samples
386390
* Updated the :makevar:`FILE_SUFFIX` make variable to use more descriptive suffixes for external flash configurations.
387391
The new suffixes are ``_dfu_ext_flash`` for external flash DFU storage and ``_ext_flash_settings`` for external flash settings storage.
388392

393+
* Updated the sample to use the :kconfig:option:`CONFIG_BT_APP_PASSKEY` option instead of the deprecated :kconfig:option:`CONFIG_BT_FIXED_PASSKEY` option.
394+
389395
* :ref:`ble_mesh_dfu_target` sample:
390396

391397
* Added:

include/bluetooth/mesh/vnd/le_pair_resp.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern "C" {
3535
/* @brief Invalidate previously used passkey.
3636
*
3737
* A user must call this function when a pairing request completes regardless of the status.
38+
*
3839
*/
3940
void bt_mesh_le_pair_resp_passkey_invalidate(void);
4041

@@ -43,11 +44,23 @@ void bt_mesh_le_pair_resp_passkey_invalidate(void);
4344
* By default, passkeys will be randomly generated on every new request. This function allows to use
4445
* pre-defined passkey instead.
4546
*
46-
* @params passkey Passkey to use for the pairing, or @ref BT_PASSKEY_INVALID to use randomly
47+
* @params passkey Passkey to use for the pairing, or @ref BT_PASSKEY_RAND to use randomly
4748
* generated passkey again.
4849
*/
4950
void bt_mesh_le_pair_resp_passkey_set(uint32_t passkey);
5051

52+
/** @brief Get passkey to be used in the very next pairing.
53+
*
54+
* This function will return the passkey set by the @ref bt_mesh_le_pair_resp_passkey_set function or it will return
55+
* a randomly generated passkey by the Reset message.
56+
*
57+
* If the passkey has never been set or the Reset message has never been received, @ref BT_PASSKEY_RAND will be returned.
58+
*
59+
* @return Passkey to be used in the very next pairing;
60+
* @ref BT_PASSKEY_RAND if passkey is not set.
61+
*/
62+
const uint32_t bt_mesh_le_pair_resp_passkey_get(void);
63+
5164
/** @cond INTERNAL_HIDDEN */
5265

5366
extern const struct bt_mesh_model_op _bt_mesh_le_pair_resp_op[];

subsys/bluetooth/mesh/vnd/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ config BT_MESH_DM_SRV_REFLECTOR_RANGING_WINDOW_US
8585
endif # BT_MESH_DM_SRV
8686

8787
config BT_MESH_LE_PAIR_RESP
88-
bool "LE Pairing Responder model"
88+
bool "LE Pairing Responder model [EXPERIMENTAL]"
8989
select BT_MESH_VENDOR_MODELS
9090
select EXPERIMENTAL
91-
depends on BT_FIXED_PASSKEY
91+
depends on BT_APP_PASSKEY
9292
depends on BT_SMP_SC_ONLY
9393
help
9494
Enable the LE Pairing Responder model. The LE Pairing Responder model is used to generate

subsys/bluetooth/mesh/vnd/le_pair_resp.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,27 @@ LOG_MODULE_REGISTER(bt_mesh_le_pair_resp);
2424
#define STATUS_PASSKEY_SET 0x00
2525
#define STATUS_PASSKEY_NOT_SET 0x01
2626

27-
static uint32_t predefined_passkey = BT_PASSKEY_INVALID;
27+
static uint32_t predefined_passkey = BT_PASSKEY_RAND;
2828

2929
static int handle_reset(const struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
3030
struct net_buf_simple *buf)
3131
{
3232
uint32_t passkey;
3333
uint8_t status = STATUS_PASSKEY_SET;
34-
int err;
3534

3635
if (buf->len != 0) {
3736
return -EINVAL;
3837
}
3938

4039
BT_MESH_MODEL_BUF_DEFINE(rsp, BT_MESH_LE_PAIR_OP, 5);
4140

42-
if (predefined_passkey != BT_PASSKEY_INVALID) {
41+
if (predefined_passkey != BT_PASSKEY_RAND) {
4342
passkey = predefined_passkey;
4443
} else {
4544
passkey = sys_rand32_get() % 1000000;
46-
}
47-
48-
err = bt_passkey_set(passkey);
49-
if (err) {
50-
LOG_ERR("Unable to set passkey (err: %d)", err);
51-
status = STATUS_PASSKEY_NOT_SET;
45+
/* Overwrite the predefined passkey with the randomly generated passkey.
46+
So the le pair responder can use the randomly generated passkey for the next pairing request.*/
47+
predefined_passkey = passkey;
5248
}
5349

5450
bt_mesh_model_msg_init(&rsp, BT_MESH_LE_PAIR_OP);
@@ -112,10 +108,15 @@ const struct bt_mesh_model_cb _bt_mesh_le_pair_resp_cb = {
112108

113109
void bt_mesh_le_pair_resp_passkey_invalidate(void)
114110
{
115-
(void)bt_passkey_set(BT_PASSKEY_INVALID);
111+
predefined_passkey = BT_PASSKEY_RAND;
116112
}
117113

118114
void bt_mesh_le_pair_resp_passkey_set(uint32_t passkey)
119115
{
120116
predefined_passkey = passkey;
121117
}
118+
119+
const uint32_t bt_mesh_le_pair_resp_passkey_get(void)
120+
{
121+
return predefined_passkey;
122+
}

0 commit comments

Comments
 (0)