Skip to content

Commit ff73938

Browse files
HaavardReiPavelVPV
authored andcommitted
[nrf fromtree] Bluetooth: Mesh: Disable prov bearers on link
Previously, PB-GATT unprovisioned advs would continue being sent if a device is provisioned or in the process of being provisioned (an active provisioning link) over PB-ADV. This commit introduces the `link_cancel` callback for the `prov_bearer` struct. When a provisioning link is established over a prov bearer, all other (active) prov bearers will be suspended through this callback, and re-enabled when the link is closed. An exception is made for PB-REMOTE, which can utilize the other bearers. The call to `bt_mesh_pb_gatt_srv_disable` in settings.c is removed. This is called in `mesh_commit`, and is not needed as this is only used during boot, at which point the Mesh provisioning service has not yet been enabled/registered, meaning the function does nothing. Signed-off-by: Håvard Reierstad <[email protected]> (cherry picked from commit 200628e) Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent b76e60f commit ff73938

File tree

6 files changed

+89
-8
lines changed

6 files changed

+89
-8
lines changed

subsys/bluetooth/mesh/pb_adv.c

+7
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,12 @@ static int prov_link_accept(const struct prov_bearer_cb *cb, void *cb_data)
10711071
return 0;
10721072
}
10731073

1074+
static void prov_link_cancel(void)
1075+
{
1076+
bt_mesh_beacon_disable();
1077+
bt_mesh_scan_disable();
1078+
}
1079+
10741080
static void prov_link_close(enum prov_bearer_link_status status)
10751081
{
10761082
int err;
@@ -1109,6 +1115,7 @@ const struct prov_bearer bt_mesh_pb_adv = {
11091115
.type = BT_MESH_PROV_ADV,
11101116
.link_open = prov_link_open,
11111117
.link_accept = prov_link_accept,
1118+
.link_cancel = prov_link_cancel,
11121119
.link_close = prov_link_close,
11131120
.send = prov_send_adv,
11141121
.clear_tx = prov_clear_tx,

subsys/bluetooth/mesh/pb_gatt.c

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ static int link_accept(const struct prov_bearer_cb *cb, void *cb_data)
198198

199199
return 0;
200200
}
201+
202+
static void link_cancel(void)
203+
{
204+
(void)bt_mesh_pb_gatt_srv_disable();
205+
}
201206
#endif
202207

203208
static void buf_send_end(struct bt_conn *conn, void *user_data)
@@ -246,6 +251,7 @@ const struct prov_bearer bt_mesh_pb_gatt = {
246251
#endif
247252
#if defined(CONFIG_BT_MESH_PB_GATT)
248253
.link_accept = link_accept,
254+
.link_cancel = link_cancel,
249255
#endif
250256
.send = buf_send,
251257
.clear_tx = clear_tx,

subsys/bluetooth/mesh/prov_bearer.h

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ struct prov_bearer {
7676
*/
7777
int (*link_accept)(const struct prov_bearer_cb *cb, void *cb_data);
7878

79+
/** @brief Disable link establishment as a provisionee.
80+
*
81+
* Stops accepting link open messages and sending unprovisioned beacons.
82+
*/
83+
void (*link_cancel)(void);
84+
7985
/** @brief Send a packet on an established link.
8086
*
8187
* @param buf Payload buffer. Requires @ref

subsys/bluetooth/mesh/provisionee.c

+63-4
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,24 @@ static void prov_confirm(const uint8_t *data)
468468
send_confirm();
469469
}
470470

471-
static inline bool is_pb_gatt(void)
471+
static bool is_pb_gatt(void)
472472
{
473473
return bt_mesh_prov_link.bearer &&
474474
bt_mesh_prov_link.bearer->type == BT_MESH_PROV_GATT;
475475
}
476476

477+
static bool is_pb_adv(void)
478+
{
479+
return bt_mesh_prov_link.bearer &&
480+
bt_mesh_prov_link.bearer->type == BT_MESH_PROV_ADV;
481+
}
482+
483+
static bool is_pb_remote(void)
484+
{
485+
return bt_mesh_prov_link.bearer &&
486+
bt_mesh_prov_link.bearer->type == BT_MESH_PROV_REMOTE;
487+
}
488+
477489
static bool refresh_is_valid(const uint8_t *netkey, uint16_t net_idx,
478490
uint32_t iv_index)
479491
{
@@ -641,6 +653,8 @@ static void local_input_complete(void)
641653
}
642654
}
643655

656+
static bt_mesh_prov_bearer_t active_bearers;
657+
644658
static void prov_link_closed(enum prov_bearer_link_status status)
645659
{
646660
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) &&
@@ -657,6 +671,28 @@ static void prov_link_closed(enum prov_bearer_link_status status)
657671
}
658672

659673
bt_mesh_prov_reset_state();
674+
675+
/* Restore provisioning bearers stopped in prov_link_opened. If the device was provisioned,
676+
* only re-enable the PB-Remote bearer.
677+
*/
678+
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && !is_pb_remote() &&
679+
(active_bearers & BT_MESH_PROV_REMOTE)) {
680+
pb_remote_srv.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
681+
}
682+
683+
if (bt_mesh_is_provisioned()) {
684+
return;
685+
}
686+
687+
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && !is_pb_gatt() &&
688+
(active_bearers & BT_MESH_PROV_GATT)) {
689+
bt_mesh_pb_gatt.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
690+
}
691+
692+
if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && !is_pb_adv() &&
693+
(active_bearers & BT_MESH_PROV_ADV)) {
694+
bt_mesh_pb_adv.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
695+
}
660696
}
661697

662698
static void prov_link_opened(void)
@@ -665,6 +701,22 @@ static void prov_link_opened(void)
665701
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && bt_mesh_is_provisioned()) {
666702
atomic_set_bit(bt_mesh_prov_link.flags, REPROVISION);
667703
}
704+
705+
/* Stop other provisioning bearers for the duration of the prov link. */
706+
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && is_pb_adv() &&
707+
(active_bearers & BT_MESH_PROV_GATT)) {
708+
bt_mesh_pb_gatt.link_cancel();
709+
}
710+
711+
if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && is_pb_gatt() &&
712+
(active_bearers & BT_MESH_PROV_ADV)) {
713+
bt_mesh_pb_adv.link_cancel();
714+
}
715+
716+
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && !is_pb_remote() &&
717+
(active_bearers & BT_MESH_PROV_REMOTE)) {
718+
pb_remote_srv.link_cancel();
719+
}
668720
}
669721

670722
static const struct bt_mesh_prov_role role_device = {
@@ -717,6 +769,7 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
717769

718770
role_init:
719771
bt_mesh_prov_link.role = &role_device;
772+
active_bearers |= bearers;
720773

721774
return 0;
722775
}
@@ -733,14 +786,20 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
733786

734787
if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) &&
735788
(bearers & BT_MESH_PROV_ADV)) {
736-
bt_mesh_beacon_disable();
737-
bt_mesh_scan_disable();
789+
bt_mesh_pb_adv.link_cancel();
738790
}
739791

740792
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) &&
741793
(bearers & BT_MESH_PROV_GATT)) {
742-
(void)bt_mesh_pb_gatt_srv_disable();
794+
bt_mesh_pb_gatt.link_cancel();
795+
}
796+
797+
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) &&
798+
(bearers & BT_MESH_PROV_REMOTE)) {
799+
pb_remote_srv.link_cancel();
743800
}
744801

802+
active_bearers &= ~bearers;
803+
745804
return 0;
746805
}

subsys/bluetooth/mesh/rpr_srv.c

+7
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,12 @@ static int node_refresh_link_accept(const struct prov_bearer_cb *cb,
13591359
return 0;
13601360
}
13611361

1362+
static void node_refresh_link_cancel(void)
1363+
{
1364+
srv.refresh.cb = NULL;
1365+
srv.refresh.cb_data = NULL;
1366+
}
1367+
13621368
static void node_refresh_tx_complete(int err, void *cb_data)
13631369
{
13641370
if (err) {
@@ -1408,6 +1414,7 @@ const struct prov_bearer pb_remote_srv = {
14081414
.type = BT_MESH_PROV_REMOTE,
14091415

14101416
.link_accept = node_refresh_link_accept,
1417+
.link_cancel = node_refresh_link_cancel,
14111418
.send = node_refresh_buf_send,
14121419
.clear_tx = node_refresh_clear_tx,
14131420
};

subsys/bluetooth/mesh/settings.c

-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ static int mesh_commit(void)
104104
return 0;
105105
}
106106

107-
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
108-
(void)bt_mesh_pb_gatt_srv_disable();
109-
}
110-
111107
bt_mesh_net_settings_commit();
112108
bt_mesh_model_settings_commit();
113109

0 commit comments

Comments
 (0)