Skip to content

Commit 1577fec

Browse files
pabigotjhedberg
authored andcommitted
Bluetooth: Mesh: proxy: update delayable work
Switch to the new API. Adds check for a pending buffer in the SAR timeout handler. Signed-off-by: Peter Bigot <[email protected]> Signed-off-by: Trond Einar Snekvik <[email protected]>
1 parent 3cba961 commit 1577fec

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

subsys/bluetooth/mesh/proxy.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static struct bt_mesh_proxy_client {
9696
#if defined(CONFIG_BT_MESH_GATT_PROXY)
9797
struct k_work send_beacons;
9898
#endif
99-
struct k_delayed_work sar_timer;
99+
struct k_work_delayable sar_timer;
100100
struct net_buf_simple buf;
101101
} clients[CONFIG_BT_MAX_CONN] = {
102102
[0 ... (CONFIG_BT_MAX_CONN - 1)] = {
@@ -132,15 +132,22 @@ static struct bt_mesh_proxy_client *find_client(struct bt_conn *conn)
132132

133133
static void proxy_sar_timeout(struct k_work *work)
134134
{
135-
struct bt_mesh_proxy_client *client;
135+
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
136+
struct bt_mesh_proxy_client *client =
137+
CONTAINER_OF(dwork, struct bt_mesh_proxy_client, sar_timer);
136138

137-
BT_WARN("Proxy SAR timeout");
139+
if (!client->conn) {
140+
return;
141+
}
138142

139-
client = CONTAINER_OF(work, struct bt_mesh_proxy_client, sar_timer);
140-
if (client->conn) {
141-
bt_conn_disconnect(client->conn,
142-
BT_HCI_ERR_REMOTE_USER_TERM_CONN);
143+
if (!client->buf.len) {
144+
BT_DBG("No pending Proxy SAR message");
145+
return;
143146
}
147+
148+
BT_WARN("Proxy SAR timeout");
149+
150+
bt_conn_disconnect(client->conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
144151
}
145152

146153
#if defined(CONFIG_BT_MESH_GATT_PROXY)
@@ -501,7 +508,7 @@ static ssize_t proxy_recv(struct bt_conn *conn,
501508
return -EINVAL;
502509
}
503510

504-
k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TIMEOUT);
511+
k_work_reschedule(&client->sar_timer, PROXY_SAR_TIMEOUT);
505512
client->msg_type = PDU_TYPE(data);
506513
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
507514
break;
@@ -517,7 +524,7 @@ static ssize_t proxy_recv(struct bt_conn *conn,
517524
return -EINVAL;
518525
}
519526

520-
k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TIMEOUT);
527+
k_work_reschedule(&client->sar_timer, PROXY_SAR_TIMEOUT);
521528
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
522529
break;
523530

@@ -532,7 +539,10 @@ static ssize_t proxy_recv(struct bt_conn *conn,
532539
return -EINVAL;
533540
}
534541

535-
k_delayed_work_cancel(&client->sar_timer);
542+
/* If this fails, the work handler exits early, as there's no
543+
* active SAR buffer.
544+
*/
545+
(void)k_work_cancel_delayable(&client->sar_timer);
536546
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
537547
proxy_complete_pdu(client);
538548
break;
@@ -592,7 +602,10 @@ static void proxy_disconnected(struct bt_conn *conn, uint8_t reason)
592602
bt_mesh_pb_gatt_close(conn);
593603
}
594604

595-
k_delayed_work_cancel(&client->sar_timer);
605+
/* If this fails, the work handler exits early, as
606+
* there's no active connection.
607+
*/
608+
(void)k_work_cancel_delayable(&client->sar_timer);
596609
bt_conn_unref(client->conn);
597610
client->conn = NULL;
598611
break;
@@ -1368,7 +1381,7 @@ int bt_mesh_proxy_init(void)
13681381
client->buf.size = CLIENT_BUF_SIZE;
13691382
client->buf.__buf = client_buf_data + (i * CLIENT_BUF_SIZE);
13701383

1371-
k_delayed_work_init(&client->sar_timer, proxy_sar_timeout);
1384+
k_work_init_delayable(&client->sar_timer, proxy_sar_timeout);
13721385
}
13731386

13741387
bt_conn_cb_register(&conn_callbacks);

0 commit comments

Comments
 (0)