aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/l2cap_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/bluetooth/l2cap_core.c')
-rw-r--r--net/bluetooth/l2cap_core.c227
1 files changed, 77 insertions, 150 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 0c3446da1ec9..0cef67707838 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -223,38 +223,25 @@ static u16 l2cap_alloc_cid(struct l2cap_conn *conn)
223 return 0; 223 return 0;
224} 224}
225 225
226static void __l2cap_state_change(struct l2cap_chan *chan, int state) 226static void l2cap_state_change(struct l2cap_chan *chan, int state)
227{ 227{
228 BT_DBG("chan %p %s -> %s", chan, state_to_string(chan->state), 228 BT_DBG("chan %p %s -> %s", chan, state_to_string(chan->state),
229 state_to_string(state)); 229 state_to_string(state));
230 230
231 chan->state = state; 231 chan->state = state;
232 chan->ops->state_change(chan, state); 232 chan->ops->state_change(chan, state, 0);
233} 233}
234 234
235static void l2cap_state_change(struct l2cap_chan *chan, int state) 235static inline void l2cap_state_change_and_error(struct l2cap_chan *chan,
236 int state, int err)
236{ 237{
237 struct sock *sk = chan->sk; 238 chan->state = state;
238 239 chan->ops->state_change(chan, chan->state, err);
239 lock_sock(sk);
240 __l2cap_state_change(chan, state);
241 release_sock(sk);
242}
243
244static inline void __l2cap_chan_set_err(struct l2cap_chan *chan, int err)
245{
246 struct sock *sk = chan->sk;
247
248 sk->sk_err = err;
249} 240}
250 241
251static inline void l2cap_chan_set_err(struct l2cap_chan *chan, int err) 242static inline void l2cap_chan_set_err(struct l2cap_chan *chan, int err)
252{ 243{
253 struct sock *sk = chan->sk; 244 chan->ops->state_change(chan, chan->state, err);
254
255 lock_sock(sk);
256 __l2cap_chan_set_err(chan, err);
257 release_sock(sk);
258} 245}
259 246
260static void __set_retrans_timer(struct l2cap_chan *chan) 247static void __set_retrans_timer(struct l2cap_chan *chan)
@@ -645,8 +632,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
645 case BT_CONFIG: 632 case BT_CONFIG:
646 if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED && 633 if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
647 conn->hcon->type == ACL_LINK) { 634 conn->hcon->type == ACL_LINK) {
648 struct sock *sk = chan->sk; 635 __set_chan_timer(chan, chan->ops->get_sndtimeo(chan));
649 __set_chan_timer(chan, sk->sk_sndtimeo);
650 l2cap_send_disconn_req(chan, reason); 636 l2cap_send_disconn_req(chan, reason);
651 } else 637 } else
652 l2cap_chan_del(chan, reason); 638 l2cap_chan_del(chan, reason);
@@ -1230,7 +1216,6 @@ static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
1230 1216
1231static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err) 1217static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err)
1232{ 1218{
1233 struct sock *sk = chan->sk;
1234 struct l2cap_conn *conn = chan->conn; 1219 struct l2cap_conn *conn = chan->conn;
1235 struct l2cap_disconn_req req; 1220 struct l2cap_disconn_req req;
1236 1221
@@ -1253,10 +1238,7 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err)
1253 l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_DISCONN_REQ, 1238 l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_DISCONN_REQ,
1254 sizeof(req), &req); 1239 sizeof(req), &req);
1255 1240
1256 lock_sock(sk); 1241 l2cap_state_change_and_error(chan, BT_DISCONN, err);
1257 __l2cap_state_change(chan, BT_DISCONN);
1258 __l2cap_chan_set_err(chan, err);
1259 release_sock(sk);
1260} 1242}
1261 1243
1262/* ---- L2CAP connections ---- */ 1244/* ---- L2CAP connections ---- */
@@ -1300,20 +1282,16 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
1300 rsp.dcid = cpu_to_le16(chan->scid); 1282 rsp.dcid = cpu_to_le16(chan->scid);
1301 1283
1302 if (l2cap_chan_check_security(chan)) { 1284 if (l2cap_chan_check_security(chan)) {
1303 struct sock *sk = chan->sk;
1304
1305 lock_sock(sk);
1306 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { 1285 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
1307 rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND); 1286 rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND);
1308 rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHOR_PEND); 1287 rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHOR_PEND);
1309 chan->ops->defer(chan); 1288 chan->ops->defer(chan);
1310 1289
1311 } else { 1290 } else {
1312 __l2cap_state_change(chan, BT_CONFIG); 1291 l2cap_state_change(chan, BT_CONFIG);
1313 rsp.result = __constant_cpu_to_le16(L2CAP_CR_SUCCESS); 1292 rsp.result = __constant_cpu_to_le16(L2CAP_CR_SUCCESS);
1314 rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO); 1293 rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
1315 } 1294 }
1316 release_sock(sk);
1317 } else { 1295 } else {
1318 rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND); 1296 rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND);
1319 rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHEN_PEND); 1297 rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHEN_PEND);
@@ -1383,14 +1361,15 @@ static struct l2cap_chan *l2cap_global_chan_by_scid(int state, u16 cid,
1383 1361
1384static void l2cap_le_conn_ready(struct l2cap_conn *conn) 1362static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1385{ 1363{
1386 struct sock *parent; 1364 struct hci_conn *hcon = conn->hcon;
1387 struct l2cap_chan *chan, *pchan; 1365 struct l2cap_chan *chan, *pchan;
1366 u8 dst_type;
1388 1367
1389 BT_DBG(""); 1368 BT_DBG("");
1390 1369
1391 /* Check if we have socket listening on cid */ 1370 /* Check if we have socket listening on cid */
1392 pchan = l2cap_global_chan_by_scid(BT_LISTEN, L2CAP_CID_ATT, 1371 pchan = l2cap_global_chan_by_scid(BT_LISTEN, L2CAP_CID_ATT,
1393 &conn->hcon->src, &conn->hcon->dst); 1372 &hcon->src, &hcon->dst);
1394 if (!pchan) 1373 if (!pchan)
1395 return; 1374 return;
1396 1375
@@ -1398,9 +1377,13 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1398 if (__l2cap_get_chan_by_dcid(conn, L2CAP_CID_ATT)) 1377 if (__l2cap_get_chan_by_dcid(conn, L2CAP_CID_ATT))
1399 return; 1378 return;
1400 1379
1401 parent = pchan->sk; 1380 dst_type = bdaddr_type(hcon, hcon->dst_type);
1381
1382 /* If device is blocked, do not create a channel for it */
1383 if (hci_blacklist_lookup(hcon->hdev, &hcon->dst, dst_type))
1384 return;
1402 1385
1403 lock_sock(parent); 1386 l2cap_chan_lock(pchan);
1404 1387
1405 chan = pchan->ops->new_connection(pchan); 1388 chan = pchan->ops->new_connection(pchan);
1406 if (!chan) 1389 if (!chan)
@@ -1408,15 +1391,15 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1408 1391
1409 chan->dcid = L2CAP_CID_ATT; 1392 chan->dcid = L2CAP_CID_ATT;
1410 1393
1411 bacpy(&chan->src, &conn->hcon->src); 1394 bacpy(&chan->src, &hcon->src);
1412 bacpy(&chan->dst, &conn->hcon->dst); 1395 bacpy(&chan->dst, &hcon->dst);
1413 chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type); 1396 chan->src_type = bdaddr_type(hcon, hcon->src_type);
1414 chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type); 1397 chan->dst_type = dst_type;
1415 1398
1416 __l2cap_chan_add(conn, chan); 1399 __l2cap_chan_add(conn, chan);
1417 1400
1418clean: 1401clean:
1419 release_sock(parent); 1402 l2cap_chan_unlock(pchan);
1420} 1403}
1421 1404
1422static void l2cap_conn_ready(struct l2cap_conn *conn) 1405static void l2cap_conn_ready(struct l2cap_conn *conn)
@@ -1451,12 +1434,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
1451 l2cap_chan_ready(chan); 1434 l2cap_chan_ready(chan);
1452 1435
1453 } else if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { 1436 } else if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
1454 struct sock *sk = chan->sk; 1437 l2cap_chan_ready(chan);
1455 __clear_chan_timer(chan);
1456 lock_sock(sk);
1457 __l2cap_state_change(chan, BT_CONNECTED);
1458 sk->sk_state_change(sk);
1459 release_sock(sk);
1460 1438
1461 } else if (chan->state == BT_CONNECT) { 1439 } else if (chan->state == BT_CONNECT) {
1462 l2cap_do_start(chan); 1440 l2cap_do_start(chan);
@@ -1764,7 +1742,6 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
1764int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 1742int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
1765 bdaddr_t *dst, u8 dst_type) 1743 bdaddr_t *dst, u8 dst_type)
1766{ 1744{
1767 struct sock *sk = chan->sk;
1768 struct l2cap_conn *conn; 1745 struct l2cap_conn *conn;
1769 struct hci_conn *hcon; 1746 struct hci_conn *hcon;
1770 struct hci_dev *hdev; 1747 struct hci_dev *hdev;
@@ -1876,7 +1853,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
1876 hci_conn_drop(hcon); 1853 hci_conn_drop(hcon);
1877 1854
1878 l2cap_state_change(chan, BT_CONNECT); 1855 l2cap_state_change(chan, BT_CONNECT);
1879 __set_chan_timer(chan, sk->sk_sndtimeo); 1856 __set_chan_timer(chan, chan->ops->get_sndtimeo(chan));
1880 1857
1881 if (hcon->state == BT_CONNECTED) { 1858 if (hcon->state == BT_CONNECTED) {
1882 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { 1859 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
@@ -1896,38 +1873,6 @@ done:
1896 return err; 1873 return err;
1897} 1874}
1898 1875
1899int __l2cap_wait_ack(struct sock *sk)
1900{
1901 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
1902 DECLARE_WAITQUEUE(wait, current);
1903 int err = 0;
1904 int timeo = HZ/5;
1905
1906 add_wait_queue(sk_sleep(sk), &wait);
1907 set_current_state(TASK_INTERRUPTIBLE);
1908 while (chan->unacked_frames > 0 && chan->conn) {
1909 if (!timeo)
1910 timeo = HZ/5;
1911
1912 if (signal_pending(current)) {
1913 err = sock_intr_errno(timeo);
1914 break;
1915 }
1916
1917 release_sock(sk);
1918 timeo = schedule_timeout(timeo);
1919 lock_sock(sk);
1920 set_current_state(TASK_INTERRUPTIBLE);
1921
1922 err = sock_error(sk);
1923 if (err)
1924 break;
1925 }
1926 set_current_state(TASK_RUNNING);
1927 remove_wait_queue(sk_sleep(sk), &wait);
1928 return err;
1929}
1930
1931static void l2cap_monitor_timeout(struct work_struct *work) 1876static void l2cap_monitor_timeout(struct work_struct *work)
1932{ 1877{
1933 struct l2cap_chan *chan = container_of(work, struct l2cap_chan, 1878 struct l2cap_chan *chan = container_of(work, struct l2cap_chan,
@@ -2868,17 +2813,16 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
2868 mutex_lock(&conn->chan_lock); 2813 mutex_lock(&conn->chan_lock);
2869 2814
2870 list_for_each_entry(chan, &conn->chan_l, list) { 2815 list_for_each_entry(chan, &conn->chan_l, list) {
2871 struct sock *sk = chan->sk;
2872 if (chan->chan_type != L2CAP_CHAN_RAW) 2816 if (chan->chan_type != L2CAP_CHAN_RAW)
2873 continue; 2817 continue;
2874 2818
2875 /* Don't send frame to the socket it came from */ 2819 /* Don't send frame to the channel it came from */
2876 if (skb->sk == sk) 2820 if (bt_cb(skb)->chan == chan)
2877 continue; 2821 continue;
2822
2878 nskb = skb_clone(skb, GFP_KERNEL); 2823 nskb = skb_clone(skb, GFP_KERNEL);
2879 if (!nskb) 2824 if (!nskb)
2880 continue; 2825 continue;
2881
2882 if (chan->ops->recv(chan, nskb)) 2826 if (chan->ops->recv(chan, nskb))
2883 kfree_skb(nskb); 2827 kfree_skb(nskb);
2884 } 2828 }
@@ -3757,7 +3701,6 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
3757 struct l2cap_conn_req *req = (struct l2cap_conn_req *) data; 3701 struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;
3758 struct l2cap_conn_rsp rsp; 3702 struct l2cap_conn_rsp rsp;
3759 struct l2cap_chan *chan = NULL, *pchan; 3703 struct l2cap_chan *chan = NULL, *pchan;
3760 struct sock *parent, *sk = NULL;
3761 int result, status = L2CAP_CS_NO_INFO; 3704 int result, status = L2CAP_CS_NO_INFO;
3762 3705
3763 u16 dcid = 0, scid = __le16_to_cpu(req->scid); 3706 u16 dcid = 0, scid = __le16_to_cpu(req->scid);
@@ -3773,10 +3716,8 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
3773 goto sendresp; 3716 goto sendresp;
3774 } 3717 }
3775 3718
3776 parent = pchan->sk;
3777
3778 mutex_lock(&conn->chan_lock); 3719 mutex_lock(&conn->chan_lock);
3779 lock_sock(parent); 3720 l2cap_chan_lock(pchan);
3780 3721
3781 /* Check if the ACL is secure enough (if not SDP) */ 3722 /* Check if the ACL is secure enough (if not SDP) */
3782 if (psm != __constant_cpu_to_le16(L2CAP_PSM_SDP) && 3723 if (psm != __constant_cpu_to_le16(L2CAP_PSM_SDP) &&
@@ -3796,8 +3737,6 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
3796 if (!chan) 3737 if (!chan)
3797 goto response; 3738 goto response;
3798 3739
3799 sk = chan->sk;
3800
3801 /* For certain devices (ex: HID mouse), support for authentication, 3740 /* For certain devices (ex: HID mouse), support for authentication,
3802 * pairing and bonding is optional. For such devices, inorder to avoid 3741 * pairing and bonding is optional. For such devices, inorder to avoid
3803 * the ACL alive for too long after L2CAP disconnection, reset the ACL 3742 * the ACL alive for too long after L2CAP disconnection, reset the ACL
@@ -3817,14 +3756,14 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
3817 3756
3818 dcid = chan->scid; 3757 dcid = chan->scid;
3819 3758
3820 __set_chan_timer(chan, sk->sk_sndtimeo); 3759 __set_chan_timer(chan, chan->ops->get_sndtimeo(chan));
3821 3760
3822 chan->ident = cmd->ident; 3761 chan->ident = cmd->ident;
3823 3762
3824 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) { 3763 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) {
3825 if (l2cap_chan_check_security(chan)) { 3764 if (l2cap_chan_check_security(chan)) {
3826 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { 3765 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
3827 __l2cap_state_change(chan, BT_CONNECT2); 3766 l2cap_state_change(chan, BT_CONNECT2);
3828 result = L2CAP_CR_PEND; 3767 result = L2CAP_CR_PEND;
3829 status = L2CAP_CS_AUTHOR_PEND; 3768 status = L2CAP_CS_AUTHOR_PEND;
3830 chan->ops->defer(chan); 3769 chan->ops->defer(chan);
@@ -3834,27 +3773,27 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
3834 * physical link is up. 3773 * physical link is up.
3835 */ 3774 */
3836 if (amp_id == AMP_ID_BREDR) { 3775 if (amp_id == AMP_ID_BREDR) {
3837 __l2cap_state_change(chan, BT_CONFIG); 3776 l2cap_state_change(chan, BT_CONFIG);
3838 result = L2CAP_CR_SUCCESS; 3777 result = L2CAP_CR_SUCCESS;
3839 } else { 3778 } else {
3840 __l2cap_state_change(chan, BT_CONNECT2); 3779 l2cap_state_change(chan, BT_CONNECT2);
3841 result = L2CAP_CR_PEND; 3780 result = L2CAP_CR_PEND;
3842 } 3781 }
3843 status = L2CAP_CS_NO_INFO; 3782 status = L2CAP_CS_NO_INFO;
3844 } 3783 }
3845 } else { 3784 } else {
3846 __l2cap_state_change(chan, BT_CONNECT2); 3785 l2cap_state_change(chan, BT_CONNECT2);
3847 result = L2CAP_CR_PEND; 3786 result = L2CAP_CR_PEND;
3848 status = L2CAP_CS_AUTHEN_PEND; 3787 status = L2CAP_CS_AUTHEN_PEND;
3849 } 3788 }
3850 } else { 3789 } else {
3851 __l2cap_state_change(chan, BT_CONNECT2); 3790 l2cap_state_change(chan, BT_CONNECT2);
3852 result = L2CAP_CR_PEND; 3791 result = L2CAP_CR_PEND;
3853 status = L2CAP_CS_NO_INFO; 3792 status = L2CAP_CS_NO_INFO;
3854 } 3793 }
3855 3794
3856response: 3795response:
3857 release_sock(parent); 3796 l2cap_chan_unlock(pchan);
3858 mutex_unlock(&conn->chan_lock); 3797 mutex_unlock(&conn->chan_lock);
3859 3798
3860sendresp: 3799sendresp:
@@ -4010,6 +3949,18 @@ static void l2cap_send_efs_conf_rsp(struct l2cap_chan *chan, void *data,
4010 L2CAP_CONF_SUCCESS, flags), data); 3949 L2CAP_CONF_SUCCESS, flags), data);
4011} 3950}
4012 3951
3952static void cmd_reject_invalid_cid(struct l2cap_conn *conn, u8 ident,
3953 u16 scid, u16 dcid)
3954{
3955 struct l2cap_cmd_rej_cid rej;
3956
3957 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
3958 rej.scid = __cpu_to_le16(scid);
3959 rej.dcid = __cpu_to_le16(dcid);
3960
3961 l2cap_send_cmd(conn, ident, L2CAP_COMMAND_REJ, sizeof(rej), &rej);
3962}
3963
4013static inline int l2cap_config_req(struct l2cap_conn *conn, 3964static inline int l2cap_config_req(struct l2cap_conn *conn,
4014 struct l2cap_cmd_hdr *cmd, u16 cmd_len, 3965 struct l2cap_cmd_hdr *cmd, u16 cmd_len,
4015 u8 *data) 3966 u8 *data)
@@ -4029,18 +3980,14 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
4029 BT_DBG("dcid 0x%4.4x flags 0x%2.2x", dcid, flags); 3980 BT_DBG("dcid 0x%4.4x flags 0x%2.2x", dcid, flags);
4030 3981
4031 chan = l2cap_get_chan_by_scid(conn, dcid); 3982 chan = l2cap_get_chan_by_scid(conn, dcid);
4032 if (!chan) 3983 if (!chan) {
4033 return -EBADSLT; 3984 cmd_reject_invalid_cid(conn, cmd->ident, dcid, 0);
3985 return 0;
3986 }
4034 3987
4035 if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2) { 3988 if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2) {
4036 struct l2cap_cmd_rej_cid rej; 3989 cmd_reject_invalid_cid(conn, cmd->ident, chan->scid,
4037 3990 chan->dcid);
4038 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
4039 rej.scid = cpu_to_le16(chan->scid);
4040 rej.dcid = cpu_to_le16(chan->dcid);
4041
4042 l2cap_send_cmd(conn, cmd->ident, L2CAP_COMMAND_REJ,
4043 sizeof(rej), &rej);
4044 goto unlock; 3991 goto unlock;
4045 } 3992 }
4046 3993
@@ -4243,7 +4190,6 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
4243 struct l2cap_disconn_rsp rsp; 4190 struct l2cap_disconn_rsp rsp;
4244 u16 dcid, scid; 4191 u16 dcid, scid;
4245 struct l2cap_chan *chan; 4192 struct l2cap_chan *chan;
4246 struct sock *sk;
4247 4193
4248 if (cmd_len != sizeof(*req)) 4194 if (cmd_len != sizeof(*req))
4249 return -EPROTO; 4195 return -EPROTO;
@@ -4258,20 +4204,17 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
4258 chan = __l2cap_get_chan_by_scid(conn, dcid); 4204 chan = __l2cap_get_chan_by_scid(conn, dcid);
4259 if (!chan) { 4205 if (!chan) {
4260 mutex_unlock(&conn->chan_lock); 4206 mutex_unlock(&conn->chan_lock);
4261 return -EBADSLT; 4207 cmd_reject_invalid_cid(conn, cmd->ident, dcid, scid);
4208 return 0;
4262 } 4209 }
4263 4210
4264 l2cap_chan_lock(chan); 4211 l2cap_chan_lock(chan);
4265 4212
4266 sk = chan->sk;
4267
4268 rsp.dcid = cpu_to_le16(chan->scid); 4213 rsp.dcid = cpu_to_le16(chan->scid);
4269 rsp.scid = cpu_to_le16(chan->dcid); 4214 rsp.scid = cpu_to_le16(chan->dcid);
4270 l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp); 4215 l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp);
4271 4216
4272 lock_sock(sk); 4217 chan->ops->set_shutdown(chan);
4273 sk->sk_shutdown = SHUTDOWN_MASK;
4274 release_sock(sk);
4275 4218
4276 l2cap_chan_hold(chan); 4219 l2cap_chan_hold(chan);
4277 l2cap_chan_del(chan, ECONNRESET); 4220 l2cap_chan_del(chan, ECONNRESET);
@@ -4491,7 +4434,9 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,
4491 &conn->hcon->dst); 4434 &conn->hcon->dst);
4492 if (!hs_hcon) { 4435 if (!hs_hcon) {
4493 hci_dev_put(hdev); 4436 hci_dev_put(hdev);
4494 return -EBADSLT; 4437 cmd_reject_invalid_cid(conn, cmd->ident, chan->scid,
4438 chan->dcid);
4439 return 0;
4495 } 4440 }
4496 4441
4497 BT_DBG("mgr %p bredr_chan %p hs_hcon %p", mgr, chan, hs_hcon); 4442 BT_DBG("mgr %p bredr_chan %p hs_hcon %p", mgr, chan, hs_hcon);
@@ -4769,7 +4714,7 @@ static void l2cap_do_create(struct l2cap_chan *chan, int result,
4769 sizeof(rsp), &rsp); 4714 sizeof(rsp), &rsp);
4770 4715
4771 if (result == L2CAP_CR_SUCCESS) { 4716 if (result == L2CAP_CR_SUCCESS) {
4772 __l2cap_state_change(chan, BT_CONFIG); 4717 l2cap_state_change(chan, BT_CONFIG);
4773 set_bit(CONF_REQ_SENT, &chan->conf_state); 4718 set_bit(CONF_REQ_SENT, &chan->conf_state);
4774 l2cap_send_cmd(chan->conn, l2cap_get_ident(chan->conn), 4719 l2cap_send_cmd(chan->conn, l2cap_get_ident(chan->conn),
4775 L2CAP_CONF_REQ, 4720 L2CAP_CONF_REQ,
@@ -5347,20 +5292,6 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
5347 } 5292 }
5348} 5293}
5349 5294
5350static __le16 l2cap_err_to_reason(int err)
5351{
5352 switch (err) {
5353 case -EBADSLT:
5354 return __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
5355 case -EMSGSIZE:
5356 return __constant_cpu_to_le16(L2CAP_REJ_MTU_EXCEEDED);
5357 case -EINVAL:
5358 case -EPROTO:
5359 default:
5360 return __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
5361 }
5362}
5363
5364static inline void l2cap_le_sig_channel(struct l2cap_conn *conn, 5295static inline void l2cap_le_sig_channel(struct l2cap_conn *conn,
5365 struct sk_buff *skb) 5296 struct sk_buff *skb)
5366{ 5297{
@@ -5393,7 +5324,7 @@ static inline void l2cap_le_sig_channel(struct l2cap_conn *conn,
5393 5324
5394 BT_ERR("Wrong link type (%d)", err); 5325 BT_ERR("Wrong link type (%d)", err);
5395 5326
5396 rej.reason = l2cap_err_to_reason(err); 5327 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
5397 l2cap_send_cmd(conn, cmd->ident, L2CAP_COMMAND_REJ, 5328 l2cap_send_cmd(conn, cmd->ident, L2CAP_COMMAND_REJ,
5398 sizeof(rej), &rej); 5329 sizeof(rej), &rej);
5399 } 5330 }
@@ -5438,7 +5369,7 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
5438 5369
5439 BT_ERR("Wrong link type (%d)", err); 5370 BT_ERR("Wrong link type (%d)", err);
5440 5371
5441 rej.reason = l2cap_err_to_reason(err); 5372 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
5442 l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ, 5373 l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ,
5443 sizeof(rej), &rej); 5374 sizeof(rej), &rej);
5444 } 5375 }
@@ -6446,8 +6377,7 @@ static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
6446 if (hcon->type != ACL_LINK) 6377 if (hcon->type != ACL_LINK)
6447 goto drop; 6378 goto drop;
6448 6379
6449 chan = l2cap_global_chan_by_psm(0, psm, &conn->hcon->src, 6380 chan = l2cap_global_chan_by_psm(0, psm, &hcon->src, &hcon->dst);
6450 &conn->hcon->dst);
6451 if (!chan) 6381 if (!chan)
6452 goto drop; 6382 goto drop;
6453 6383
@@ -6460,7 +6390,7 @@ static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
6460 goto drop; 6390 goto drop;
6461 6391
6462 /* Store remote BD_ADDR and PSM for msg_name */ 6392 /* Store remote BD_ADDR and PSM for msg_name */
6463 bacpy(&bt_cb(skb)->bdaddr, &conn->hcon->dst); 6393 bacpy(&bt_cb(skb)->bdaddr, &hcon->dst);
6464 bt_cb(skb)->psm = psm; 6394 bt_cb(skb)->psm = psm;
6465 6395
6466 if (!chan->ops->recv(chan, skb)) 6396 if (!chan->ops->recv(chan, skb))
@@ -6480,12 +6410,15 @@ static void l2cap_att_channel(struct l2cap_conn *conn,
6480 goto drop; 6410 goto drop;
6481 6411
6482 chan = l2cap_global_chan_by_scid(BT_CONNECTED, L2CAP_CID_ATT, 6412 chan = l2cap_global_chan_by_scid(BT_CONNECTED, L2CAP_CID_ATT,
6483 &conn->hcon->src, &conn->hcon->dst); 6413 &hcon->src, &hcon->dst);
6484 if (!chan) 6414 if (!chan)
6485 goto drop; 6415 goto drop;
6486 6416
6487 BT_DBG("chan %p, len %d", chan, skb->len); 6417 BT_DBG("chan %p, len %d", chan, skb->len);
6488 6418
6419 if (hci_blacklist_lookup(hcon->hdev, &hcon->dst, hcon->dst_type))
6420 goto drop;
6421
6489 if (chan->imtu < skb->len) 6422 if (chan->imtu < skb->len)
6490 goto drop; 6423 goto drop;
6491 6424
@@ -6682,31 +6615,26 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
6682 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT); 6615 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
6683 } 6616 }
6684 } else if (chan->state == BT_CONNECT2) { 6617 } else if (chan->state == BT_CONNECT2) {
6685 struct sock *sk = chan->sk;
6686 struct l2cap_conn_rsp rsp; 6618 struct l2cap_conn_rsp rsp;
6687 __u16 res, stat; 6619 __u16 res, stat;
6688 6620
6689 lock_sock(sk);
6690
6691 if (!status) { 6621 if (!status) {
6692 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { 6622 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
6693 res = L2CAP_CR_PEND; 6623 res = L2CAP_CR_PEND;
6694 stat = L2CAP_CS_AUTHOR_PEND; 6624 stat = L2CAP_CS_AUTHOR_PEND;
6695 chan->ops->defer(chan); 6625 chan->ops->defer(chan);
6696 } else { 6626 } else {
6697 __l2cap_state_change(chan, BT_CONFIG); 6627 l2cap_state_change(chan, BT_CONFIG);
6698 res = L2CAP_CR_SUCCESS; 6628 res = L2CAP_CR_SUCCESS;
6699 stat = L2CAP_CS_NO_INFO; 6629 stat = L2CAP_CS_NO_INFO;
6700 } 6630 }
6701 } else { 6631 } else {
6702 __l2cap_state_change(chan, BT_DISCONN); 6632 l2cap_state_change(chan, BT_DISCONN);
6703 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT); 6633 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
6704 res = L2CAP_CR_SEC_BLOCK; 6634 res = L2CAP_CR_SEC_BLOCK;
6705 stat = L2CAP_CS_NO_INFO; 6635 stat = L2CAP_CS_NO_INFO;
6706 } 6636 }
6707 6637
6708 release_sock(sk);
6709
6710 rsp.scid = cpu_to_le16(chan->dcid); 6638 rsp.scid = cpu_to_le16(chan->dcid);
6711 rsp.dcid = cpu_to_le16(chan->scid); 6639 rsp.dcid = cpu_to_le16(chan->scid);
6712 rsp.result = cpu_to_le16(res); 6640 rsp.result = cpu_to_le16(res);
@@ -6880,12 +6808,11 @@ int __init l2cap_init(void)
6880 if (err < 0) 6808 if (err < 0)
6881 return err; 6809 return err;
6882 6810
6883 if (bt_debugfs) { 6811 if (IS_ERR_OR_NULL(bt_debugfs))
6884 l2cap_debugfs = debugfs_create_file("l2cap", 0444, bt_debugfs, 6812 return 0;
6885 NULL, &l2cap_debugfs_fops); 6813
6886 if (!l2cap_debugfs) 6814 l2cap_debugfs = debugfs_create_file("l2cap", 0444, bt_debugfs,
6887 BT_ERR("Failed to create L2CAP debug file"); 6815 NULL, &l2cap_debugfs_fops);
6888 }
6889 6816
6890 return 0; 6817 return 0;
6891} 6818}