Bluetooth: ATT: Use k_mem_slab for connection context
This uses k_mem_slab APIs to allocate/free ATT context instead of custom array. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
aa7013b9bd
commit
708c8bae54
1 changed files with 15 additions and 19 deletions
|
@ -86,7 +86,8 @@ struct bt_att {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct bt_att bt_req_pool[CONFIG_BT_MAX_CONN];
|
K_MEM_SLAB_DEFINE(att_slab, sizeof(struct bt_att),
|
||||||
|
CONFIG_BT_MAX_CONN, 16);
|
||||||
static struct bt_att_req cancel;
|
static struct bt_att_req cancel;
|
||||||
|
|
||||||
static void att_req_destroy(struct bt_att_req *req)
|
static void att_req_destroy(struct bt_att_req *req)
|
||||||
|
@ -2126,6 +2127,8 @@ static void att_timeout(struct k_work *work)
|
||||||
/* Consider the channel disconnected */
|
/* Consider the channel disconnected */
|
||||||
bt_gatt_disconnected(ch->chan.conn);
|
bt_gatt_disconnected(ch->chan.conn);
|
||||||
ch->chan.conn = NULL;
|
ch->chan.conn = NULL;
|
||||||
|
|
||||||
|
k_mem_slab_free(&att_slab, (void **)&att);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_att_connected(struct bt_l2cap_chan *chan)
|
static void bt_att_connected(struct bt_l2cap_chan *chan)
|
||||||
|
@ -2157,6 +2160,8 @@ static void bt_att_disconnected(struct bt_l2cap_chan *chan)
|
||||||
att_reset(att);
|
att_reset(att);
|
||||||
|
|
||||||
bt_gatt_disconnected(ch->chan.conn);
|
bt_gatt_disconnected(ch->chan.conn);
|
||||||
|
|
||||||
|
k_mem_slab_free(&att_slab, (void **)&att);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_SMP)
|
#if defined(CONFIG_BT_SMP)
|
||||||
|
@ -2207,7 +2212,6 @@ static void bt_att_encrypt_change(struct bt_l2cap_chan *chan,
|
||||||
|
|
||||||
static int bt_att_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
static int bt_att_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
static const struct bt_l2cap_chan_ops ops = {
|
static const struct bt_l2cap_chan_ops ops = {
|
||||||
.connected = bt_att_connected,
|
.connected = bt_att_connected,
|
||||||
.disconnected = bt_att_disconnected,
|
.disconnected = bt_att_disconnected,
|
||||||
|
@ -2216,29 +2220,21 @@ static int bt_att_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||||
.encrypt_change = bt_att_encrypt_change,
|
.encrypt_change = bt_att_encrypt_change,
|
||||||
#endif /* CONFIG_BT_SMP */
|
#endif /* CONFIG_BT_SMP */
|
||||||
};
|
};
|
||||||
|
struct bt_att *att;
|
||||||
|
|
||||||
BT_DBG("conn %p handle %u", conn, conn->handle);
|
BT_DBG("conn %p handle %u", conn, conn->handle);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(bt_req_pool); i++) {
|
if (k_mem_slab_alloc(&att_slab, (void **)&att, K_NO_WAIT)) {
|
||||||
struct bt_att *att = &bt_req_pool[i];
|
BT_ERR("No available ATT context for conn %p", conn);
|
||||||
|
return -ENOMEM;
|
||||||
if (att->chan.chan.conn) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)memset(att, 0, sizeof(*att));
|
|
||||||
att->chan.chan.ops = &ops;
|
|
||||||
k_sem_init(&att->tx_sem, CONFIG_BT_ATT_TX_MAX,
|
|
||||||
CONFIG_BT_ATT_TX_MAX);
|
|
||||||
|
|
||||||
*chan = &att->chan.chan;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_ERR("No available ATT context for conn %p", conn);
|
(void)memset(att, 0, sizeof(*att));
|
||||||
|
att->chan.chan.ops = &ops;
|
||||||
|
k_sem_init(&att->tx_sem, CONFIG_BT_ATT_TX_MAX, CONFIG_BT_ATT_TX_MAX);
|
||||||
|
*chan = &att->chan.chan;
|
||||||
|
|
||||||
return -ENOMEM;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_L2CAP_CHANNEL_DEFINE(att_fixed_chan, BT_L2CAP_CID_ATT, bt_att_accept);
|
BT_L2CAP_CHANNEL_DEFINE(att_fixed_chan, BT_L2CAP_CID_ATT, bt_att_accept);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue