aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2013-12-05 07:55:33 -0500
committerMarcel Holtmann <marcel@holtmann.org>2013-12-05 10:05:36 -0500
commit0ce43ce60d5e0c079d33be1fe33ba92828c7e5da (patch)
treef7cb56f1ffe4717ab5f807b0d85df03ba4c62669 /net
parentf15b8ecf9895941ef50134ff604be8bd2c6b1b78 (diff)
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: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/l2cap_core.c35
-rw-r--r--net/bluetooth/l2cap_sock.c4
2 files changed, 14 insertions, 25 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 8e9e883874ce..6e6f308af036 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -498,11 +498,11 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan)
498 set_bit(FLAG_FORCE_ACTIVE, &chan->flags); 498 set_bit(FLAG_FORCE_ACTIVE, &chan->flags);
499} 499}
500 500
501void l2cap_le_flowctl_init(struct l2cap_chan *chan) 501static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
502{ 502{
503 chan->imtu = L2CAP_DEFAULT_MTU; 503 chan->sdu = NULL;
504 chan->omtu = L2CAP_LE_MIN_MTU; 504 chan->sdu_last_frag = NULL;
505 chan->mode = L2CAP_MODE_LE_FLOWCTL; 505 chan->sdu_len = 0;
506 chan->tx_credits = 0; 506 chan->tx_credits = 0;
507 chan->rx_credits = le_max_credits; 507 chan->rx_credits = le_max_credits;
508 508
@@ -510,6 +510,8 @@ void l2cap_le_flowctl_init(struct l2cap_chan *chan)
510 chan->mps = chan->imtu; 510 chan->mps = chan->imtu;
511 else 511 else
512 chan->mps = L2CAP_LE_DEFAULT_MPS; 512 chan->mps = L2CAP_LE_DEFAULT_MPS;
513
514 skb_queue_head_init(&chan->tx_q);
513} 515}
514 516
515void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) 517void __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 } 1210 }
1209} 1211}
1210 1212
1211static void l2cap_le_flowctl_start(struct l2cap_chan *chan)
1212{
1213 chan->sdu = NULL;
1214 chan->sdu_last_frag = NULL;
1215 chan->sdu_len = 0;
1216
1217 if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
1218 chan->mps = chan->imtu;
1219 else
1220 chan->mps = le_default_mps;
1221
1222 skb_queue_head_init(&chan->tx_q);
1223
1224 if (!chan->tx_credits)
1225 chan->ops->suspend(chan);
1226}
1227
1228static void l2cap_chan_ready(struct l2cap_chan *chan) 1213static void l2cap_chan_ready(struct l2cap_chan *chan)
1229{ 1214{
1230 /* This clears all conf flags, including CONF_NOT_COMPLETE */ 1215 /* This clears all conf flags, including CONF_NOT_COMPLETE */
1231 chan->conf_state = 0; 1216 chan->conf_state = 0;
1232 __clear_chan_timer(chan); 1217 __clear_chan_timer(chan);
1233 1218
1234 if (chan->mode == L2CAP_MODE_LE_FLOWCTL) 1219 if (chan->mode == L2CAP_MODE_LE_FLOWCTL && !chan->tx_credits)
1235 l2cap_le_flowctl_start(chan); 1220 chan->ops->suspend(chan);
1236 1221
1237 chan->state = BT_CONNECTED; 1222 chan->state = BT_CONNECTED;
1238 1223
@@ -1909,7 +1894,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
1909 1894
1910 switch (chan->mode) { 1895 switch (chan->mode) {
1911 case L2CAP_MODE_BASIC: 1896 case L2CAP_MODE_BASIC:
1897 break;
1912 case L2CAP_MODE_LE_FLOWCTL: 1898 case L2CAP_MODE_LE_FLOWCTL:
1899 l2cap_le_flowctl_init(chan);
1913 break; 1900 break;
1914 case L2CAP_MODE_ERTM: 1901 case L2CAP_MODE_ERTM:
1915 case L2CAP_MODE_STREAMING: 1902 case L2CAP_MODE_STREAMING:
@@ -5663,6 +5650,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
5663 goto response_unlock; 5650 goto response_unlock;
5664 } 5651 }
5665 5652
5653 l2cap_le_flowctl_init(chan);
5654
5666 bacpy(&chan->src, &conn->hcon->src); 5655 bacpy(&chan->src, &conn->hcon->src);
5667 bacpy(&chan->dst, &conn->hcon->dst); 5656 bacpy(&chan->dst, &conn->hcon->dst);
5668 chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type); 5657 chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 88fa9c07c503..e7806e6d282c 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -153,7 +153,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
153 chan->src_type = la.l2_bdaddr_type; 153 chan->src_type = la.l2_bdaddr_type;
154 154
155 if (chan->psm && bdaddr_type_is_le(chan->src_type)) 155 if (chan->psm && bdaddr_type_is_le(chan->src_type))
156 l2cap_le_flowctl_init(chan); 156 chan->mode = L2CAP_MODE_LE_FLOWCTL;
157 157
158 chan->state = BT_BOUND; 158 chan->state = BT_BOUND;
159 sk->sk_state = BT_BOUND; 159 sk->sk_state = BT_BOUND;
@@ -226,7 +226,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
226 } 226 }
227 227
228 if (chan->psm && bdaddr_type_is_le(chan->src_type)) 228 if (chan->psm && bdaddr_type_is_le(chan->src_type))
229 l2cap_le_flowctl_init(chan); 229 chan->mode = L2CAP_MODE_LE_FLOWCTL;
230 230
231 err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid), 231 err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
232 &la.l2_bdaddr, la.l2_bdaddr_type); 232 &la.l2_bdaddr, la.l2_bdaddr_type);