aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo F. Padovan <padovan@profusion.mobi>2011-04-13 19:23:55 -0400
committerGustavo F. Padovan <padovan@profusion.mobi>2011-04-28 00:10:00 -0400
commit8c1d787be4b62d2d1b6f04953eca4bcf7c839d44 (patch)
treee2a35c5cb81cc5109c13c2747b039fa05ea55a6e
parentfe4128e0aabc3c748786c00da21e6eff9d3aeddb (diff)
Bluetooth: Move conn to struct l2cap_chan
There is no need to the socket deal directly with the channel, most of the time it cares about the channel only. Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r--include/net/bluetooth/l2cap.h7
-rw-r--r--net/bluetooth/l2cap_core.c92
-rw-r--r--net/bluetooth/l2cap_sock.c12
-rw-r--r--net/bluetooth/rfcomm/core.c8
-rw-r--r--net/bluetooth/rfcomm/sock.c5
5 files changed, 59 insertions, 65 deletions
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index fd199cda752c..3de90a91a4e4 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -284,6 +284,9 @@ struct srej_list {
284 284
285struct l2cap_chan { 285struct l2cap_chan {
286 struct sock *sk; 286 struct sock *sk;
287
288 struct l2cap_conn *conn;
289
287 __le16 psm; 290 __le16 psm;
288 __u16 dcid; 291 __u16 dcid;
289 __u16 scid; 292 __u16 scid;
@@ -385,8 +388,6 @@ struct l2cap_conn {
385 388
386struct l2cap_pinfo { 389struct l2cap_pinfo {
387 struct bt_sock bt; 390 struct bt_sock bt;
388
389 struct l2cap_conn *conn;
390 struct l2cap_chan *chan; 391 struct l2cap_chan *chan;
391}; 392};
392 393
@@ -447,7 +448,7 @@ int l2cap_init_sockets(void);
447void l2cap_cleanup_sockets(void); 448void l2cap_cleanup_sockets(void);
448 449
449void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data); 450void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data);
450void __l2cap_connect_rsp_defer(struct sock *sk); 451void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
451int __l2cap_wait_ack(struct sock *sk); 452int __l2cap_wait_ack(struct sock *sk);
452 453
453struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 454struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index dd726bdd6e02..8562ac1ba947 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -169,7 +169,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
169 169
170 conn->disc_reason = 0x13; 170 conn->disc_reason = 0x13;
171 171
172 l2cap_pi(sk)->conn = conn; 172 chan->conn = conn;
173 173
174 if (sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) { 174 if (sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) {
175 if (conn->hcon->type == LE_LINK) { 175 if (conn->hcon->type == LE_LINK) {
@@ -204,7 +204,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
204void l2cap_chan_del(struct l2cap_chan *chan, int err) 204void l2cap_chan_del(struct l2cap_chan *chan, int err)
205{ 205{
206 struct sock *sk = chan->sk; 206 struct sock *sk = chan->sk;
207 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 207 struct l2cap_conn *conn = chan->conn;
208 struct sock *parent = bt_sk(sk)->parent; 208 struct sock *parent = bt_sk(sk)->parent;
209 209
210 l2cap_sock_clear_timer(sk); 210 l2cap_sock_clear_timer(sk);
@@ -218,7 +218,7 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
218 write_unlock_bh(&conn->chan_lock); 218 write_unlock_bh(&conn->chan_lock);
219 __sock_put(sk); 219 __sock_put(sk);
220 220
221 l2cap_pi(sk)->conn = NULL; 221 chan->conn = NULL;
222 hci_conn_put(conn->hcon); 222 hci_conn_put(conn->hcon);
223 } 223 }
224 224
@@ -296,7 +296,7 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
296/* Service level security */ 296/* Service level security */
297static inline int l2cap_check_security(struct l2cap_chan *chan) 297static inline int l2cap_check_security(struct l2cap_chan *chan)
298{ 298{
299 struct l2cap_conn *conn = l2cap_pi(chan->sk)->conn; 299 struct l2cap_conn *conn = chan->conn;
300 __u8 auth_type; 300 __u8 auth_type;
301 301
302 auth_type = l2cap_get_auth_type(chan); 302 auth_type = l2cap_get_auth_type(chan);
@@ -349,7 +349,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
349 struct sk_buff *skb; 349 struct sk_buff *skb;
350 struct l2cap_hdr *lh; 350 struct l2cap_hdr *lh;
351 struct l2cap_pinfo *pi = l2cap_pi(chan->sk); 351 struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
352 struct l2cap_conn *conn = pi->conn; 352 struct l2cap_conn *conn = chan->conn;
353 struct sock *sk = (struct sock *)pi; 353 struct sock *sk = (struct sock *)pi;
354 int count, hlen = L2CAP_HDR_SIZE + 2; 354 int count, hlen = L2CAP_HDR_SIZE + 2;
355 u8 flags; 355 u8 flags;
@@ -394,7 +394,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
394 else 394 else
395 flags = ACL_START; 395 flags = ACL_START;
396 396
397 hci_send_acl(pi->conn->hcon, skb, flags); 397 hci_send_acl(chan->conn->hcon, skb, flags);
398} 398}
399 399
400static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u16 control) 400static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u16 control)
@@ -417,8 +417,7 @@ static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan)
417 417
418static void l2cap_do_start(struct l2cap_chan *chan) 418static void l2cap_do_start(struct l2cap_chan *chan)
419{ 419{
420 struct sock *sk = chan->sk; 420 struct l2cap_conn *conn = chan->conn;
421 struct l2cap_conn *conn = l2cap_pi(sk)->conn;
422 421
423 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT) { 422 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT) {
424 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) 423 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE))
@@ -920,12 +919,13 @@ done:
920 919
921int __l2cap_wait_ack(struct sock *sk) 920int __l2cap_wait_ack(struct sock *sk)
922{ 921{
922 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
923 DECLARE_WAITQUEUE(wait, current); 923 DECLARE_WAITQUEUE(wait, current);
924 int err = 0; 924 int err = 0;
925 int timeo = HZ/5; 925 int timeo = HZ/5;
926 926
927 add_wait_queue(sk_sleep(sk), &wait); 927 add_wait_queue(sk_sleep(sk), &wait);
928 while ((l2cap_pi(sk)->chan->unacked_frames > 0 && l2cap_pi(sk)->conn)) { 928 while ((chan->unacked_frames > 0 && chan->conn)) {
929 set_current_state(TASK_INTERRUPTIBLE); 929 set_current_state(TASK_INTERRUPTIBLE);
930 930
931 if (!timeo) 931 if (!timeo)
@@ -958,7 +958,7 @@ static void l2cap_monitor_timeout(unsigned long arg)
958 958
959 bh_lock_sock(sk); 959 bh_lock_sock(sk);
960 if (chan->retry_count >= chan->remote_max_tx) { 960 if (chan->retry_count >= chan->remote_max_tx) {
961 l2cap_send_disconn_req(l2cap_pi(sk)->conn, chan, ECONNABORTED); 961 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
962 bh_unlock_sock(sk); 962 bh_unlock_sock(sk);
963 return; 963 return;
964 } 964 }
@@ -1008,8 +1008,7 @@ static void l2cap_drop_acked_frames(struct l2cap_chan *chan)
1008 1008
1009void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb) 1009void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb)
1010{ 1010{
1011 struct sock *sk = chan->sk; 1011 struct hci_conn *hcon = chan->conn->hcon;
1012 struct hci_conn *hcon = l2cap_pi(sk)->conn->hcon;
1013 u16 flags; 1012 u16 flags;
1014 1013
1015 BT_DBG("chan %p, skb %p len %d", chan, skb, skb->len); 1014 BT_DBG("chan %p, skb %p len %d", chan, skb, skb->len);
@@ -1045,8 +1044,6 @@ void l2cap_streaming_send(struct l2cap_chan *chan)
1045 1044
1046static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq) 1045static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq)
1047{ 1046{
1048 struct sock *sk = chan->sk;
1049 struct l2cap_pinfo *pi = l2cap_pi(sk);
1050 struct sk_buff *skb, *tx_skb; 1047 struct sk_buff *skb, *tx_skb;
1051 u16 control, fcs; 1048 u16 control, fcs;
1052 1049
@@ -1065,7 +1062,7 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq)
1065 1062
1066 if (chan->remote_max_tx && 1063 if (chan->remote_max_tx &&
1067 bt_cb(skb)->retries == chan->remote_max_tx) { 1064 bt_cb(skb)->retries == chan->remote_max_tx) {
1068 l2cap_send_disconn_req(pi->conn, chan, ECONNABORTED); 1065 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
1069 return; 1066 return;
1070 } 1067 }
1071 1068
@@ -1096,7 +1093,6 @@ int l2cap_ertm_send(struct l2cap_chan *chan)
1096{ 1093{
1097 struct sk_buff *skb, *tx_skb; 1094 struct sk_buff *skb, *tx_skb;
1098 struct sock *sk = chan->sk; 1095 struct sock *sk = chan->sk;
1099 struct l2cap_pinfo *pi = l2cap_pi(sk);
1100 u16 control, fcs; 1096 u16 control, fcs;
1101 int nsent = 0; 1097 int nsent = 0;
1102 1098
@@ -1107,7 +1103,7 @@ int l2cap_ertm_send(struct l2cap_chan *chan)
1107 1103
1108 if (chan->remote_max_tx && 1104 if (chan->remote_max_tx &&
1109 bt_cb(skb)->retries == chan->remote_max_tx) { 1105 bt_cb(skb)->retries == chan->remote_max_tx) {
1110 l2cap_send_disconn_req(pi->conn, chan, ECONNABORTED); 1106 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
1111 break; 1107 break;
1112 } 1108 }
1113 1109
@@ -1203,7 +1199,7 @@ static void l2cap_send_srejtail(struct l2cap_chan *chan)
1203 1199
1204static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, int len, int count, struct sk_buff *skb) 1200static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, int len, int count, struct sk_buff *skb)
1205{ 1201{
1206 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 1202 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
1207 struct sk_buff **frag; 1203 struct sk_buff **frag;
1208 int err, sent = 0; 1204 int err, sent = 0;
1209 1205
@@ -1236,7 +1232,7 @@ static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, in
1236struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len) 1232struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
1237{ 1233{
1238 struct sock *sk = chan->sk; 1234 struct sock *sk = chan->sk;
1239 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 1235 struct l2cap_conn *conn = chan->conn;
1240 struct sk_buff *skb; 1236 struct sk_buff *skb;
1241 int err, count, hlen = L2CAP_HDR_SIZE + 2; 1237 int err, count, hlen = L2CAP_HDR_SIZE + 2;
1242 struct l2cap_hdr *lh; 1238 struct l2cap_hdr *lh;
@@ -1266,7 +1262,7 @@ struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct msghdr
1266struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len) 1262struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
1267{ 1263{
1268 struct sock *sk = chan->sk; 1264 struct sock *sk = chan->sk;
1269 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 1265 struct l2cap_conn *conn = chan->conn;
1270 struct sk_buff *skb; 1266 struct sk_buff *skb;
1271 int err, count, hlen = L2CAP_HDR_SIZE; 1267 int err, count, hlen = L2CAP_HDR_SIZE;
1272 struct l2cap_hdr *lh; 1268 struct l2cap_hdr *lh;
@@ -1295,7 +1291,7 @@ struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, struct msghdr *m
1295struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len, u16 control, u16 sdulen) 1291struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len, u16 control, u16 sdulen)
1296{ 1292{
1297 struct sock *sk = chan->sk; 1293 struct sock *sk = chan->sk;
1298 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 1294 struct l2cap_conn *conn = chan->conn;
1299 struct sk_buff *skb; 1295 struct sk_buff *skb;
1300 int err, count, hlen = L2CAP_HDR_SIZE + 2; 1296 int err, count, hlen = L2CAP_HDR_SIZE + 2;
1301 struct l2cap_hdr *lh; 1297 struct l2cap_hdr *lh;
@@ -1611,7 +1607,6 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask)
1611 1607
1612static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data) 1608static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
1613{ 1609{
1614 struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
1615 struct l2cap_conf_req *req = data; 1610 struct l2cap_conf_req *req = data;
1616 struct l2cap_conf_rfc rfc = { .mode = chan->mode }; 1611 struct l2cap_conf_rfc rfc = { .mode = chan->mode };
1617 void *ptr = req->data; 1612 void *ptr = req->data;
@@ -1629,7 +1624,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
1629 1624
1630 /* fall through */ 1625 /* fall through */
1631 default: 1626 default:
1632 chan->mode = l2cap_select_mode(rfc.mode, pi->conn->feat_mask); 1627 chan->mode = l2cap_select_mode(rfc.mode, chan->conn->feat_mask);
1633 break; 1628 break;
1634 } 1629 }
1635 1630
@@ -1639,8 +1634,8 @@ done:
1639 1634
1640 switch (chan->mode) { 1635 switch (chan->mode) {
1641 case L2CAP_MODE_BASIC: 1636 case L2CAP_MODE_BASIC:
1642 if (!(pi->conn->feat_mask & L2CAP_FEAT_ERTM) && 1637 if (!(chan->conn->feat_mask & L2CAP_FEAT_ERTM) &&
1643 !(pi->conn->feat_mask & L2CAP_FEAT_STREAMING)) 1638 !(chan->conn->feat_mask & L2CAP_FEAT_STREAMING))
1644 break; 1639 break;
1645 1640
1646 rfc.mode = L2CAP_MODE_BASIC; 1641 rfc.mode = L2CAP_MODE_BASIC;
@@ -1661,13 +1656,13 @@ done:
1661 rfc.retrans_timeout = 0; 1656 rfc.retrans_timeout = 0;
1662 rfc.monitor_timeout = 0; 1657 rfc.monitor_timeout = 0;
1663 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE); 1658 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
1664 if (L2CAP_DEFAULT_MAX_PDU_SIZE > pi->conn->mtu - 10) 1659 if (L2CAP_DEFAULT_MAX_PDU_SIZE > chan->conn->mtu - 10)
1665 rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10); 1660 rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
1666 1661
1667 l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc), 1662 l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
1668 (unsigned long) &rfc); 1663 (unsigned long) &rfc);
1669 1664
1670 if (!(pi->conn->feat_mask & L2CAP_FEAT_FCS)) 1665 if (!(chan->conn->feat_mask & L2CAP_FEAT_FCS))
1671 break; 1666 break;
1672 1667
1673 if (chan->fcs == L2CAP_FCS_NONE || 1668 if (chan->fcs == L2CAP_FCS_NONE ||
@@ -1684,13 +1679,13 @@ done:
1684 rfc.retrans_timeout = 0; 1679 rfc.retrans_timeout = 0;
1685 rfc.monitor_timeout = 0; 1680 rfc.monitor_timeout = 0;
1686 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE); 1681 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
1687 if (L2CAP_DEFAULT_MAX_PDU_SIZE > pi->conn->mtu - 10) 1682 if (L2CAP_DEFAULT_MAX_PDU_SIZE > chan->conn->mtu - 10)
1688 rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10); 1683 rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
1689 1684
1690 l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc), 1685 l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
1691 (unsigned long) &rfc); 1686 (unsigned long) &rfc);
1692 1687
1693 if (!(pi->conn->feat_mask & L2CAP_FEAT_FCS)) 1688 if (!(chan->conn->feat_mask & L2CAP_FEAT_FCS))
1694 break; 1689 break;
1695 1690
1696 if (chan->fcs == L2CAP_FCS_NONE || 1691 if (chan->fcs == L2CAP_FCS_NONE ||
@@ -1709,7 +1704,6 @@ done:
1709 1704
1710static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data) 1705static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
1711{ 1706{
1712 struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
1713 struct l2cap_conf_rsp *rsp = data; 1707 struct l2cap_conf_rsp *rsp = data;
1714 void *ptr = rsp->data; 1708 void *ptr = rsp->data;
1715 void *req = chan->conf_req; 1709 void *req = chan->conf_req;
@@ -1769,7 +1763,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
1769 case L2CAP_MODE_ERTM: 1763 case L2CAP_MODE_ERTM:
1770 if (!(chan->conf_state & L2CAP_CONF_STATE2_DEVICE)) { 1764 if (!(chan->conf_state & L2CAP_CONF_STATE2_DEVICE)) {
1771 chan->mode = l2cap_select_mode(rfc.mode, 1765 chan->mode = l2cap_select_mode(rfc.mode,
1772 pi->conn->feat_mask); 1766 chan->conn->feat_mask);
1773 break; 1767 break;
1774 } 1768 }
1775 1769
@@ -1814,8 +1808,8 @@ done:
1814 chan->remote_tx_win = rfc.txwin_size; 1808 chan->remote_tx_win = rfc.txwin_size;
1815 chan->remote_max_tx = rfc.max_transmit; 1809 chan->remote_max_tx = rfc.max_transmit;
1816 1810
1817 if (le16_to_cpu(rfc.max_pdu_size) > pi->conn->mtu - 10) 1811 if (le16_to_cpu(rfc.max_pdu_size) > chan->conn->mtu - 10)
1818 rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10); 1812 rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
1819 1813
1820 chan->remote_mps = le16_to_cpu(rfc.max_pdu_size); 1814 chan->remote_mps = le16_to_cpu(rfc.max_pdu_size);
1821 1815
@@ -1832,8 +1826,8 @@ done:
1832 break; 1826 break;
1833 1827
1834 case L2CAP_MODE_STREAMING: 1828 case L2CAP_MODE_STREAMING:
1835 if (le16_to_cpu(rfc.max_pdu_size) > pi->conn->mtu - 10) 1829 if (le16_to_cpu(rfc.max_pdu_size) > chan->conn->mtu - 10)
1836 rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10); 1830 rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
1837 1831
1838 chan->remote_mps = le16_to_cpu(rfc.max_pdu_size); 1832 chan->remote_mps = le16_to_cpu(rfc.max_pdu_size);
1839 1833
@@ -1943,15 +1937,12 @@ static int l2cap_build_conf_rsp(struct l2cap_chan *chan, void *data, u16 result,
1943 return ptr - data; 1937 return ptr - data;
1944} 1938}
1945 1939
1946void __l2cap_connect_rsp_defer(struct sock *sk) 1940void __l2cap_connect_rsp_defer(struct l2cap_chan *chan)
1947{ 1941{
1948 struct l2cap_conn_rsp rsp; 1942 struct l2cap_conn_rsp rsp;
1949 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 1943 struct l2cap_conn *conn = chan->conn;
1950 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
1951 u8 buf[128]; 1944 u8 buf[128];
1952 1945
1953 sk->sk_state = BT_CONFIG;
1954
1955 rsp.scid = cpu_to_le16(chan->dcid); 1946 rsp.scid = cpu_to_le16(chan->dcid);
1956 rsp.dcid = cpu_to_le16(chan->scid); 1947 rsp.dcid = cpu_to_le16(chan->scid);
1957 rsp.result = cpu_to_le16(L2CAP_CR_SUCCESS); 1948 rsp.result = cpu_to_le16(L2CAP_CR_SUCCESS);
@@ -2856,7 +2847,6 @@ static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb,
2856 2847
2857static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u16 control) 2848static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u16 control)
2858{ 2849{
2859 struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
2860 struct sk_buff *_skb; 2850 struct sk_buff *_skb;
2861 int err; 2851 int err;
2862 2852
@@ -2957,7 +2947,7 @@ drop:
2957 chan->sdu = NULL; 2947 chan->sdu = NULL;
2958 2948
2959disconnect: 2949disconnect:
2960 l2cap_send_disconn_req(pi->conn, chan, ECONNRESET); 2950 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
2961 kfree_skb(skb); 2951 kfree_skb(skb);
2962 return 0; 2952 return 0;
2963} 2953}
@@ -3018,7 +3008,7 @@ static void l2cap_busy_work(struct work_struct *work)
3018 3008
3019 if (n_tries++ > L2CAP_LOCAL_BUSY_TRIES) { 3009 if (n_tries++ > L2CAP_LOCAL_BUSY_TRIES) {
3020 err = -EBUSY; 3010 err = -EBUSY;
3021 l2cap_send_disconn_req(l2cap_pi(sk)->conn, chan, EBUSY); 3011 l2cap_send_disconn_req(chan->conn, chan, EBUSY);
3022 break; 3012 break;
3023 } 3013 }
3024 3014
@@ -3236,7 +3226,6 @@ static void l2cap_send_srejframe(struct l2cap_chan *chan, u8 tx_seq)
3236 3226
3237static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_control, struct sk_buff *skb) 3227static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_control, struct sk_buff *skb)
3238{ 3228{
3239 struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
3240 u8 tx_seq = __get_txseq(rx_control); 3229 u8 tx_seq = __get_txseq(rx_control);
3241 u8 req_seq = __get_reqseq(rx_control); 3230 u8 req_seq = __get_reqseq(rx_control);
3242 u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT; 3231 u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT;
@@ -3267,7 +3256,7 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
3267 3256
3268 /* invalid tx_seq */ 3257 /* invalid tx_seq */
3269 if (tx_seq_offset >= chan->tx_win) { 3258 if (tx_seq_offset >= chan->tx_win) {
3270 l2cap_send_disconn_req(pi->conn, chan, ECONNRESET); 3259 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
3271 goto drop; 3260 goto drop;
3272 } 3261 }
3273 3262
@@ -3534,7 +3523,6 @@ static inline int l2cap_data_channel_sframe(struct l2cap_chan *chan, u16 rx_cont
3534static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb) 3523static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
3535{ 3524{
3536 struct l2cap_chan *chan = l2cap_pi(sk)->chan; 3525 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
3537 struct l2cap_pinfo *pi = l2cap_pi(sk);
3538 u16 control; 3526 u16 control;
3539 u8 req_seq; 3527 u8 req_seq;
3540 int len, next_tx_seq_offset, req_seq_offset; 3528 int len, next_tx_seq_offset, req_seq_offset;
@@ -3558,7 +3546,7 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
3558 len -= 2; 3546 len -= 2;
3559 3547
3560 if (len > chan->mps) { 3548 if (len > chan->mps) {
3561 l2cap_send_disconn_req(pi->conn, chan, ECONNRESET); 3549 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
3562 goto drop; 3550 goto drop;
3563 } 3551 }
3564 3552
@@ -3574,13 +3562,13 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
3574 3562
3575 /* check for invalid req-seq */ 3563 /* check for invalid req-seq */
3576 if (req_seq_offset > next_tx_seq_offset) { 3564 if (req_seq_offset > next_tx_seq_offset) {
3577 l2cap_send_disconn_req(pi->conn, chan, ECONNRESET); 3565 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
3578 goto drop; 3566 goto drop;
3579 } 3567 }
3580 3568
3581 if (__is_iframe(control)) { 3569 if (__is_iframe(control)) {
3582 if (len < 0) { 3570 if (len < 0) {
3583 l2cap_send_disconn_req(pi->conn, chan, ECONNRESET); 3571 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
3584 goto drop; 3572 goto drop;
3585 } 3573 }
3586 3574
@@ -3588,7 +3576,7 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
3588 } else { 3576 } else {
3589 if (len != 0) { 3577 if (len != 0) {
3590 BT_ERR("%d", len); 3578 BT_ERR("%d", len);
3591 l2cap_send_disconn_req(pi->conn, chan, ECONNRESET); 3579 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
3592 goto drop; 3580 goto drop;
3593 } 3581 }
3594 3582
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index f5a27737c151..61d93f6c36c8 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -455,8 +455,8 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __us
455 break; 455 break;
456 } 456 }
457 457
458 cinfo.hci_handle = l2cap_pi(sk)->conn->hcon->handle; 458 cinfo.hci_handle = chan->conn->hcon->handle;
459 memcpy(cinfo.dev_class, l2cap_pi(sk)->conn->hcon->dev_class, 3); 459 memcpy(cinfo.dev_class, chan->conn->hcon->dev_class, 3);
460 460
461 len = min_t(unsigned int, len, sizeof(cinfo)); 461 len = min_t(unsigned int, len, sizeof(cinfo));
462 if (copy_to_user(optval, (char *) &cinfo, len)) 462 if (copy_to_user(optval, (char *) &cinfo, len))
@@ -690,7 +690,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
690 } 690 }
691 691
692 if (opt == BT_FLUSHABLE_OFF) { 692 if (opt == BT_FLUSHABLE_OFF) {
693 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 693 struct l2cap_conn *conn = chan->conn;
694 /* proceed futher only when we have l2cap_conn and 694 /* proceed futher only when we have l2cap_conn and
695 No Flush support in the LM */ 695 No Flush support in the LM */
696 if (!conn || !lmp_no_flush_capable(conn->hcon->hdev)) { 696 if (!conn || !lmp_no_flush_capable(conn->hcon->hdev)) {
@@ -823,7 +823,9 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct ms
823 lock_sock(sk); 823 lock_sock(sk);
824 824
825 if (sk->sk_state == BT_CONNECT2 && bt_sk(sk)->defer_setup) { 825 if (sk->sk_state == BT_CONNECT2 && bt_sk(sk)->defer_setup) {
826 __l2cap_connect_rsp_defer(sk); 826 sk->sk_state = BT_CONFIG;
827
828 __l2cap_connect_rsp_defer(l2cap_pi(sk)->chan);
827 release_sock(sk); 829 release_sock(sk);
828 return 0; 830 return 0;
829 } 831 }
@@ -878,8 +880,8 @@ static void l2cap_sock_cleanup_listen(struct sock *parent)
878 880
879void __l2cap_sock_close(struct sock *sk, int reason) 881void __l2cap_sock_close(struct sock *sk, int reason)
880{ 882{
881 struct l2cap_conn *conn = l2cap_pi(sk)->conn;
882 struct l2cap_chan *chan = l2cap_pi(sk)->chan; 883 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
884 struct l2cap_conn *conn = chan->conn;
883 885
884 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket); 886 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
885 887
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index fdd8f5ab18c1..121a5c13b989 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -232,6 +232,8 @@ static int rfcomm_l2sock_create(struct socket **sock)
232static inline int rfcomm_check_security(struct rfcomm_dlc *d) 232static inline int rfcomm_check_security(struct rfcomm_dlc *d)
233{ 233{
234 struct sock *sk = d->session->sock->sk; 234 struct sock *sk = d->session->sock->sk;
235 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
236
235 __u8 auth_type; 237 __u8 auth_type;
236 238
237 switch (d->sec_level) { 239 switch (d->sec_level) {
@@ -246,8 +248,7 @@ static inline int rfcomm_check_security(struct rfcomm_dlc *d)
246 break; 248 break;
247 } 249 }
248 250
249 return hci_conn_security(l2cap_pi(sk)->conn->hcon, d->sec_level, 251 return hci_conn_security(conn->hcon, d->sec_level, auth_type);
250 auth_type);
251} 252}
252 253
253static void rfcomm_session_timeout(unsigned long arg) 254static void rfcomm_session_timeout(unsigned long arg)
@@ -1241,6 +1242,7 @@ static int rfcomm_recv_disc(struct rfcomm_session *s, u8 dlci)
1241void rfcomm_dlc_accept(struct rfcomm_dlc *d) 1242void rfcomm_dlc_accept(struct rfcomm_dlc *d)
1242{ 1243{
1243 struct sock *sk = d->session->sock->sk; 1244 struct sock *sk = d->session->sock->sk;
1245 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
1244 1246
1245 BT_DBG("dlc %p", d); 1247 BT_DBG("dlc %p", d);
1246 1248
@@ -1254,7 +1256,7 @@ void rfcomm_dlc_accept(struct rfcomm_dlc *d)
1254 rfcomm_dlc_unlock(d); 1256 rfcomm_dlc_unlock(d);
1255 1257
1256 if (d->role_switch) 1258 if (d->role_switch)
1257 hci_conn_switch_role(l2cap_pi(sk)->conn->hcon, 0x00); 1259 hci_conn_switch_role(conn->hcon, 0x00);
1258 1260
1259 rfcomm_send_msc(d->session, 1, d->dlci, d->v24_sig); 1261 rfcomm_send_msc(d->session, 1, d->dlci, d->v24_sig);
1260} 1262}
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 66cc1f0c3df8..386cfaffd4b7 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -743,6 +743,7 @@ static int rfcomm_sock_getsockopt_old(struct socket *sock, int optname, char __u
743 struct sock *sk = sock->sk; 743 struct sock *sk = sock->sk;
744 struct sock *l2cap_sk; 744 struct sock *l2cap_sk;
745 struct rfcomm_conninfo cinfo; 745 struct rfcomm_conninfo cinfo;
746 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
746 int len, err = 0; 747 int len, err = 0;
747 u32 opt; 748 u32 opt;
748 749
@@ -787,8 +788,8 @@ static int rfcomm_sock_getsockopt_old(struct socket *sock, int optname, char __u
787 788
788 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk; 789 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
789 790
790 cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle; 791 cinfo.hci_handle = conn->hcon->handle;
791 memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3); 792 memcpy(cinfo.dev_class, conn->hcon->dev_class, 3);
792 793
793 len = min_t(unsigned int, len, sizeof(cinfo)); 794 len = min_t(unsigned int, len, sizeof(cinfo));
794 if (copy_to_user(optval, (char *) &cinfo, len)) 795 if (copy_to_user(optval, (char *) &cinfo, len))