@@ -96,7 +96,7 @@ static struct bt_mesh_proxy_client {
96
96
#if defined(CONFIG_BT_MESH_GATT_PROXY )
97
97
struct k_work send_beacons ;
98
98
#endif
99
- struct k_delayed_work sar_timer ;
99
+ struct k_work_delayable sar_timer ;
100
100
struct net_buf_simple buf ;
101
101
} clients [CONFIG_BT_MAX_CONN ] = {
102
102
[0 ... (CONFIG_BT_MAX_CONN - 1 )] = {
@@ -132,15 +132,22 @@ static struct bt_mesh_proxy_client *find_client(struct bt_conn *conn)
132
132
133
133
static void proxy_sar_timeout (struct k_work * work )
134
134
{
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 );
136
138
137
- BT_WARN ("Proxy SAR timeout" );
139
+ if (!client -> conn ) {
140
+ return ;
141
+ }
138
142
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 ;
143
146
}
147
+
148
+ BT_WARN ("Proxy SAR timeout" );
149
+
150
+ bt_conn_disconnect (client -> conn , BT_HCI_ERR_REMOTE_USER_TERM_CONN );
144
151
}
145
152
146
153
#if defined(CONFIG_BT_MESH_GATT_PROXY )
@@ -501,7 +508,7 @@ static ssize_t proxy_recv(struct bt_conn *conn,
501
508
return - EINVAL ;
502
509
}
503
510
504
- k_delayed_work_submit (& client -> sar_timer , PROXY_SAR_TIMEOUT );
511
+ k_work_reschedule (& client -> sar_timer , PROXY_SAR_TIMEOUT );
505
512
client -> msg_type = PDU_TYPE (data );
506
513
net_buf_simple_add_mem (& client -> buf , data + 1 , len - 1 );
507
514
break ;
@@ -517,7 +524,7 @@ static ssize_t proxy_recv(struct bt_conn *conn,
517
524
return - EINVAL ;
518
525
}
519
526
520
- k_delayed_work_submit (& client -> sar_timer , PROXY_SAR_TIMEOUT );
527
+ k_work_reschedule (& client -> sar_timer , PROXY_SAR_TIMEOUT );
521
528
net_buf_simple_add_mem (& client -> buf , data + 1 , len - 1 );
522
529
break ;
523
530
@@ -532,7 +539,10 @@ static ssize_t proxy_recv(struct bt_conn *conn,
532
539
return - EINVAL ;
533
540
}
534
541
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 );
536
546
net_buf_simple_add_mem (& client -> buf , data + 1 , len - 1 );
537
547
proxy_complete_pdu (client );
538
548
break ;
@@ -592,7 +602,10 @@ static void proxy_disconnected(struct bt_conn *conn, uint8_t reason)
592
602
bt_mesh_pb_gatt_close (conn );
593
603
}
594
604
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 );
596
609
bt_conn_unref (client -> conn );
597
610
client -> conn = NULL ;
598
611
break ;
@@ -1368,7 +1381,7 @@ int bt_mesh_proxy_init(void)
1368
1381
client -> buf .size = CLIENT_BUF_SIZE ;
1369
1382
client -> buf .__buf = client_buf_data + (i * CLIENT_BUF_SIZE );
1370
1383
1371
- k_delayed_work_init (& client -> sar_timer , proxy_sar_timeout );
1384
+ k_work_init_delayable (& client -> sar_timer , proxy_sar_timeout );
1372
1385
}
1373
1386
1374
1387
bt_conn_cb_register (& conn_callbacks );
0 commit comments