Skip to content

Commit 3f68692

Browse files
LingaoMcfriedt
authored andcommitted
Bluetooth: Mesh: Reflact disconnect logic to separate roles
remove section ordering to use code more readable. Signed-off-by: Lingao Meng <[email protected]>
1 parent 22b234c commit 3f68692

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

subsys/bluetooth/mesh/pb_gatt_srv.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void gatt_connected(struct bt_conn *conn, uint8_t err)
8484
struct bt_conn_info info;
8585

8686
bt_conn_get_info(conn, &info);
87-
if (info.role != BT_CONN_ROLE_SLAVE ||
87+
if (info.role != BT_CONN_ROLE_PERIPHERAL ||
8888
!service_registered || bt_mesh_is_provisioned()) {
8989
return;
9090
}
@@ -99,7 +99,7 @@ static void gatt_disconnected(struct bt_conn *conn, uint8_t reason)
9999
struct bt_conn_info info;
100100

101101
bt_conn_get_info(conn, &info);
102-
if (info.role != BT_CONN_ROLE_SLAVE ||
102+
if (info.role != BT_CONN_ROLE_PERIPHERAL ||
103103
!service_registered) {
104104
return;
105105
}
@@ -108,14 +108,8 @@ static void gatt_disconnected(struct bt_conn *conn, uint8_t reason)
108108

109109
bt_mesh_pb_gatt_close(conn);
110110

111-
if (!bt_mesh_is_provisioned()) {
112-
return;
113-
}
114-
115-
(void)bt_mesh_pb_gatt_disable();
116-
117-
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
118-
(void)bt_mesh_proxy_gatt_enable();
111+
if (bt_mesh_is_provisioned()) {
112+
(void)bt_mesh_pb_gatt_disable();
119113
}
120114
}
121115

@@ -304,10 +298,7 @@ int bt_mesh_pb_gatt_adv_start(void)
304298
return err;
305299
}
306300

307-
/* Add `_2` suffix forces this callback to be called
308-
* after proxy_srv's conn_cb.
309-
*/
310-
BT_CONN_CB_DEFINE(conn_callbacks_2) = {
301+
BT_CONN_CB_DEFINE(conn_callbacks) = {
311302
.connected = gatt_connected,
312303
.disconnected = gatt_disconnected,
313304
};

subsys/bluetooth/mesh/proxy_srv.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,12 @@ static void gatt_disconnected(struct bt_conn *conn, uint8_t reason)
861861
struct bt_mesh_proxy_client *client;
862862

863863
bt_conn_get_info(conn, &info);
864-
if (info.role != BT_CONN_ROLE_PERIPHERAL ||
865-
!service_registered) {
864+
if (info.role != BT_CONN_ROLE_PERIPHERAL) {
865+
return;
866+
}
867+
868+
if (!service_registered && bt_mesh_is_provisioned()) {
869+
(void)bt_mesh_proxy_gatt_enable();
866870
return;
867871
}
868872

@@ -900,10 +904,7 @@ int bt_mesh_proxy_adv_start(void)
900904
return gatt_proxy_advertise(next_sub());
901905
}
902906

903-
/* Add `_1` suffix forces proxy conn_cb to precede pb_gatt conn_cb.
904-
* As we may register proxy services in pb_gatt disconnect cb.
905-
*/
906-
BT_CONN_CB_DEFINE(conn_callbacks_1) = {
907+
BT_CONN_CB_DEFINE(conn_callbacks) = {
907908
.connected = gatt_connected,
908909
.disconnected = gatt_disconnected,
909910
};

0 commit comments

Comments
 (0)