Commit 0ce43ce6 authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Simplify l2cap_chan initialization for LE CoC

The values in l2cap_chan that are used for actually transmitting data
only need to be initialized right after we've received an L2CAP Connect
Request or just before we send one. The only thing that we need to
initialize though bind() and connect() is the chan->mode value. This way
all other initializations can be done in the l2cap_le_flowctl_init
function (which now becomes private to l2cap_core.c) and the
l2cap_le_flowctl_start function can be completely removed.

Also, since the l2cap_sock_init function initializes the imtu and omtu
to adequate values these do not need to be part of l2cap_le_flowctl_init.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent f15b8ecf
...@@ -873,7 +873,6 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, ...@@ -873,7 +873,6 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
void l2cap_chan_busy(struct l2cap_chan *chan, int busy); void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
int l2cap_chan_check_security(struct l2cap_chan *chan); int l2cap_chan_check_security(struct l2cap_chan *chan);
void l2cap_chan_set_defaults(struct l2cap_chan *chan); void l2cap_chan_set_defaults(struct l2cap_chan *chan);
void l2cap_le_flowctl_init(struct l2cap_chan *chan);
int l2cap_ertm_init(struct l2cap_chan *chan); int l2cap_ertm_init(struct l2cap_chan *chan);
void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
......
...@@ -498,11 +498,11 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan) ...@@ -498,11 +498,11 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan)
set_bit(FLAG_FORCE_ACTIVE, &chan->flags); set_bit(FLAG_FORCE_ACTIVE, &chan->flags);
} }
void l2cap_le_flowctl_init(struct l2cap_chan *chan) static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
{ {
chan->imtu = L2CAP_DEFAULT_MTU; chan->sdu = NULL;
chan->omtu = L2CAP_LE_MIN_MTU; chan->sdu_last_frag = NULL;
chan->mode = L2CAP_MODE_LE_FLOWCTL; chan->sdu_len = 0;
chan->tx_credits = 0; chan->tx_credits = 0;
chan->rx_credits = le_max_credits; chan->rx_credits = le_max_credits;
...@@ -510,6 +510,8 @@ void l2cap_le_flowctl_init(struct l2cap_chan *chan) ...@@ -510,6 +510,8 @@ void l2cap_le_flowctl_init(struct l2cap_chan *chan)
chan->mps = chan->imtu; chan->mps = chan->imtu;
else else
chan->mps = L2CAP_LE_DEFAULT_MPS; chan->mps = L2CAP_LE_DEFAULT_MPS;
skb_queue_head_init(&chan->tx_q);
} }
void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
...@@ -1208,31 +1210,14 @@ static void l2cap_move_done(struct l2cap_chan *chan) ...@@ -1208,31 +1210,14 @@ static void l2cap_move_done(struct l2cap_chan *chan)
} }
} }
static void l2cap_le_flowctl_start(struct l2cap_chan *chan)
{
chan->sdu = NULL;
chan->sdu_last_frag = NULL;
chan->sdu_len = 0;
if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
chan->mps = chan->imtu;
else
chan->mps = le_default_mps;
skb_queue_head_init(&chan->tx_q);
if (!chan->tx_credits)
chan->ops->suspend(chan);
}
static void l2cap_chan_ready(struct l2cap_chan *chan) static void l2cap_chan_ready(struct l2cap_chan *chan)
{ {
/* This clears all conf flags, including CONF_NOT_COMPLETE */ /* This clears all conf flags, including CONF_NOT_COMPLETE */
chan->conf_state = 0; chan->conf_state = 0;
__clear_chan_timer(chan); __clear_chan_timer(chan);
if (chan->mode == L2CAP_MODE_LE_FLOWCTL) if (chan->mode == L2CAP_MODE_LE_FLOWCTL && !chan->tx_credits)
l2cap_le_flowctl_start(chan); chan->ops->suspend(chan);
chan->state = BT_CONNECTED; chan->state = BT_CONNECTED;
...@@ -1909,7 +1894,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, ...@@ -1909,7 +1894,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
switch (chan->mode) { switch (chan->mode) {
case L2CAP_MODE_BASIC: case L2CAP_MODE_BASIC:
break;
case L2CAP_MODE_LE_FLOWCTL: case L2CAP_MODE_LE_FLOWCTL:
l2cap_le_flowctl_init(chan);
break; break;
case L2CAP_MODE_ERTM: case L2CAP_MODE_ERTM:
case L2CAP_MODE_STREAMING: case L2CAP_MODE_STREAMING:
...@@ -5663,6 +5650,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, ...@@ -5663,6 +5650,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
goto response_unlock; goto response_unlock;
} }
l2cap_le_flowctl_init(chan);
bacpy(&chan->src, &conn->hcon->src); bacpy(&chan->src, &conn->hcon->src);
bacpy(&chan->dst, &conn->hcon->dst); bacpy(&chan->dst, &conn->hcon->dst);
chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type); chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
......
...@@ -153,7 +153,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) ...@@ -153,7 +153,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
chan->src_type = la.l2_bdaddr_type; chan->src_type = la.l2_bdaddr_type;
if (chan->psm && bdaddr_type_is_le(chan->src_type)) if (chan->psm && bdaddr_type_is_le(chan->src_type))
l2cap_le_flowctl_init(chan); chan->mode = L2CAP_MODE_LE_FLOWCTL;
chan->state = BT_BOUND; chan->state = BT_BOUND;
sk->sk_state = BT_BOUND; sk->sk_state = BT_BOUND;
...@@ -226,7 +226,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, ...@@ -226,7 +226,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
} }
if (chan->psm && bdaddr_type_is_le(chan->src_type)) if (chan->psm && bdaddr_type_is_le(chan->src_type))
l2cap_le_flowctl_init(chan); chan->mode = L2CAP_MODE_LE_FLOWCTL;
err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid), err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
&la.l2_bdaddr, la.l2_bdaddr_type); &la.l2_bdaddr, la.l2_bdaddr_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment