Skip to content

Commit 3cba961

Browse files
pabigotjhedberg
authored andcommitted
Bluetooth: Mesh: pb_gatt: update delayable work
Switch to the new API. Adds a link check to the protocol timeout to ensure the link is still active. Signed-off-by: Peter Bigot <[email protected]> Signed-off-by: Trond Einar Snekvik <[email protected]>
1 parent 45e5914 commit 3cba961

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

subsys/bluetooth/mesh/pb_gatt.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct prov_link {
2222
const struct prov_bearer_cb *cb;
2323
void *cb_data;
2424
struct net_buf_simple *rx_buf;
25-
struct k_delayed_work prot_timer;
25+
struct k_work_delayable prot_timer;
2626
};
2727

2828
static struct prov_link link;
@@ -34,7 +34,8 @@ static void reset_state(void)
3434
link.conn = NULL;
3535
}
3636

37-
k_delayed_work_cancel(&link.prot_timer);
37+
/* If this fails, the protocol timeout handler will exit early. */
38+
(void)k_work_cancel_delayable(&link.prot_timer);
3839

3940
link.rx_buf = bt_mesh_proxy_get_buf();
4041
}
@@ -51,8 +52,12 @@ static void link_closed(enum prov_bearer_link_status status)
5152

5253
static void protocol_timeout(struct k_work *work)
5354
{
54-
BT_DBG("Protocol timeout");
55+
if (!link.conn) {
56+
/* Already disconnected */
57+
return;
58+
}
5559

60+
BT_DBG("Protocol timeout");
5661
link_closed(PROV_BEARER_LINK_STATUS_TIMEOUT);
5762
}
5863

@@ -70,7 +75,7 @@ int bt_mesh_pb_gatt_recv(struct bt_conn *conn, struct net_buf_simple *buf)
7075
return -EINVAL;
7176
}
7277

73-
k_delayed_work_submit(&link.prot_timer, PROTOCOL_TIMEOUT);
78+
k_work_reschedule(&link.prot_timer, PROTOCOL_TIMEOUT);
7479

7580
link.cb->recv(&pb_gatt, link.cb_data, buf);
7681

@@ -86,7 +91,7 @@ int bt_mesh_pb_gatt_open(struct bt_conn *conn)
8691
}
8792

8893
link.conn = bt_conn_ref(conn);
89-
k_delayed_work_submit(&link.prot_timer, PROTOCOL_TIMEOUT);
94+
k_work_reschedule(&link.prot_timer, PROTOCOL_TIMEOUT);
9095

9196
link.cb->link_opened(&pb_gatt, link.cb_data);
9297

@@ -125,7 +130,7 @@ static int buf_send(struct net_buf_simple *buf, prov_bearer_send_complete_t cb,
125130
return -ENOTCONN;
126131
}
127132

128-
k_delayed_work_submit(&link.prot_timer, PROTOCOL_TIMEOUT);
133+
k_work_reschedule(&link.prot_timer, PROTOCOL_TIMEOUT);
129134

130135
return bt_mesh_proxy_send(link.conn, BT_MESH_PROXY_PROV, buf);
131136
}
@@ -137,7 +142,7 @@ static void clear_tx(void)
137142

138143
void pb_gatt_init(void)
139144
{
140-
k_delayed_work_init(&link.prot_timer, protocol_timeout);
145+
k_work_init_delayable(&link.prot_timer, protocol_timeout);
141146
}
142147

143148
void pb_gatt_reset(void)

0 commit comments

Comments
 (0)