@@ -99,6 +99,20 @@ static void free_tx_meta_data(struct l2cap_tx_meta_data *data)
99
99
100
100
static sys_slist_t servers ;
101
101
102
+ static void l2cap_tx_buf_destroy (struct bt_conn * conn , struct net_buf * buf , int err )
103
+ {
104
+ struct l2cap_tx_meta_data * data = l2cap_tx_meta_data (buf );
105
+ bt_conn_tx_cb_t cb = data -> cb ;
106
+ void * cb_user_data = data -> user_data ;
107
+
108
+ free_tx_meta_data (data );
109
+ net_buf_unref (buf );
110
+
111
+ /* Make sure to call associated callback, if any */
112
+ if (cb ) {
113
+ cb (conn , cb_user_data , err );
114
+ }
115
+ }
102
116
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
103
117
104
118
/* L2CAP signalling channel specific context */
@@ -933,7 +947,7 @@ static void l2cap_chan_tx_process(struct k_work *work)
933
947
*/
934
948
k_work_schedule (& ch -> tx_work , K_MSEC (CONFIG_BT_L2CAP_RESCHED_MS ));
935
949
} else {
936
- net_buf_unref ( buf );
950
+ l2cap_tx_buf_destroy ( ch -> chan . conn , buf , sent );
937
951
}
938
952
break ;
939
953
}
@@ -986,13 +1000,13 @@ static void l2cap_chan_destroy(struct bt_l2cap_chan *chan)
986
1000
}
987
1001
988
1002
if (le_chan -> tx_buf ) {
989
- net_buf_unref ( le_chan -> tx_buf );
1003
+ l2cap_tx_buf_destroy ( chan -> conn , le_chan -> tx_buf , - ESHUTDOWN );
990
1004
le_chan -> tx_buf = NULL ;
991
1005
}
992
1006
993
1007
/* Remove buffers on the TX queue */
994
1008
while ((buf = net_buf_get (& le_chan -> tx_queue , K_NO_WAIT ))) {
995
- net_buf_unref ( buf );
1009
+ l2cap_tx_buf_destroy ( chan -> conn , buf , - ESHUTDOWN );
996
1010
}
997
1011
998
1012
/* Remove buffers on the RX queue */
@@ -1912,6 +1926,9 @@ static void l2cap_chan_sdu_sent(struct bt_conn *conn, void *user_data, int err)
1912
1926
chan = bt_l2cap_le_lookup_tx_cid (conn , cid );
1913
1927
if (!chan ) {
1914
1928
/* Received SDU sent callback for disconnected channel */
1929
+ if (cb ) {
1930
+ cb (conn , cb_user_data , - ESHUTDOWN );
1931
+ }
1915
1932
return ;
1916
1933
}
1917
1934
@@ -2259,13 +2276,13 @@ static void l2cap_chan_shutdown(struct bt_l2cap_chan *chan)
2259
2276
2260
2277
/* Cleanup outstanding request */
2261
2278
if (le_chan -> tx_buf ) {
2262
- net_buf_unref ( le_chan -> tx_buf );
2279
+ l2cap_tx_buf_destroy ( chan -> conn , le_chan -> tx_buf , - ESHUTDOWN );
2263
2280
le_chan -> tx_buf = NULL ;
2264
2281
}
2265
2282
2266
2283
/* Remove buffers on the TX queue */
2267
2284
while ((buf = net_buf_get (& le_chan -> tx_queue , K_NO_WAIT ))) {
2268
- net_buf_unref ( buf );
2285
+ l2cap_tx_buf_destroy ( chan -> conn , buf , - ESHUTDOWN );
2269
2286
}
2270
2287
2271
2288
/* Remove buffers on the RX queue */
0 commit comments