Bluetooth: L2CAP: Add released callback

This adds a callback to indicate when the stack has released all
references to a given channel so the owner free up any resources
associated with that.

This is requires since EATT channels cannot rely on the destroy callback
as it does not use a fixed channel like ATT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2020-02-26 16:42:26 -08:00 committed by Johan Hedberg
commit 14d6c00b9b
2 changed files with 15 additions and 3 deletions

View file

@ -257,6 +257,13 @@ struct bt_l2cap_chan_ops {
* @param status The channel status
*/
void (*status)(struct bt_l2cap_chan *chan, atomic_t *status);
/* @brief Channel released callback
*
* If this callback is set it is called when the stack has release all
* references to the channel object.
*/
void (*released)(struct bt_l2cap_chan *chan);
};
/** @def BT_L2CAP_CHAN_SEND_RESERVE

View file

@ -239,14 +239,16 @@ void bt_l2cap_chan_set_state(struct bt_l2cap_chan *chan,
void bt_l2cap_chan_del(struct bt_l2cap_chan *chan)
{
const struct bt_l2cap_chan_ops *ops = chan->ops;
BT_DBG("conn %p chan %p", chan->conn, chan);
if (!chan->conn) {
goto destroy;
}
if (chan->ops->disconnected) {
chan->ops->disconnected(chan);
if (ops->disconnected) {
ops->disconnected(chan);
}
chan->conn = NULL;
@ -257,10 +259,13 @@ destroy:
bt_l2cap_chan_set_state(chan, BT_L2CAP_DISCONNECTED);
chan->psm = 0U;
#endif
if (chan->destroy) {
chan->destroy(chan);
}
if (ops->released) {
ops->released(chan);
}
}
static void l2cap_rtx_timeout(struct k_work *work)