diff options
author | John W. Linville <linville@tuxdriver.com> | 2013-11-04 14:51:28 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2013-11-04 14:51:28 -0500 |
commit | 87bc0728d462ae37841a550542829aa65a97e7c2 (patch) | |
tree | 266afb90f501b814c0a79f10a7afd86a6a33d631 /net/bluetooth/l2cap_sock.c | |
parent | f421436a591d34fa5279b54a96ac07d70250cc8d (diff) | |
parent | 01925efdf7e03b4b803b5c9f985163d687f7f017 (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next into for-davem
Conflicts:
drivers/net/wireless/brcm80211/brcmfmac/sdio_host.h
Diffstat (limited to 'net/bluetooth/l2cap_sock.c')
-rw-r--r-- | net/bluetooth/l2cap_sock.c | 86 |
1 files changed, 67 insertions, 19 deletions
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 9119898ef040..5ffd75e20bde 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c | |||
@@ -32,7 +32,8 @@ | |||
32 | #include <net/bluetooth/bluetooth.h> | 32 | #include <net/bluetooth/bluetooth.h> |
33 | #include <net/bluetooth/hci_core.h> | 33 | #include <net/bluetooth/hci_core.h> |
34 | #include <net/bluetooth/l2cap.h> | 34 | #include <net/bluetooth/l2cap.h> |
35 | #include <net/bluetooth/smp.h> | 35 | |
36 | #include "smp.h" | ||
36 | 37 | ||
37 | static struct bt_sock_list l2cap_sk_list = { | 38 | static struct bt_sock_list l2cap_sk_list = { |
38 | .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock) | 39 | .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock) |
@@ -68,6 +69,9 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) | |||
68 | if (la.l2_cid && la.l2_psm) | 69 | if (la.l2_cid && la.l2_psm) |
69 | return -EINVAL; | 70 | return -EINVAL; |
70 | 71 | ||
72 | if (!bdaddr_type_is_valid(la.l2_bdaddr_type)) | ||
73 | return -EINVAL; | ||
74 | |||
71 | lock_sock(sk); | 75 | lock_sock(sk); |
72 | 76 | ||
73 | if (sk->sk_state != BT_OPEN) { | 77 | if (sk->sk_state != BT_OPEN) { |
@@ -99,11 +103,20 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) | |||
99 | if (err < 0) | 103 | if (err < 0) |
100 | goto done; | 104 | goto done; |
101 | 105 | ||
102 | if (__le16_to_cpu(la.l2_psm) == L2CAP_PSM_SDP || | 106 | switch (chan->chan_type) { |
103 | __le16_to_cpu(la.l2_psm) == L2CAP_PSM_RFCOMM) | 107 | case L2CAP_CHAN_CONN_LESS: |
104 | chan->sec_level = BT_SECURITY_SDP; | 108 | if (__le16_to_cpu(la.l2_psm) == L2CAP_PSM_3DSP) |
109 | chan->sec_level = BT_SECURITY_SDP; | ||
110 | break; | ||
111 | case L2CAP_CHAN_CONN_ORIENTED: | ||
112 | if (__le16_to_cpu(la.l2_psm) == L2CAP_PSM_SDP || | ||
113 | __le16_to_cpu(la.l2_psm) == L2CAP_PSM_RFCOMM) | ||
114 | chan->sec_level = BT_SECURITY_SDP; | ||
115 | break; | ||
116 | } | ||
105 | 117 | ||
106 | bacpy(&bt_sk(sk)->src, &la.l2_bdaddr); | 118 | bacpy(&chan->src, &la.l2_bdaddr); |
119 | chan->src_type = la.l2_bdaddr_type; | ||
107 | 120 | ||
108 | chan->state = BT_BOUND; | 121 | chan->state = BT_BOUND; |
109 | sk->sk_state = BT_BOUND; | 122 | sk->sk_state = BT_BOUND; |
@@ -134,6 +147,15 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, | |||
134 | if (la.l2_cid && la.l2_psm) | 147 | if (la.l2_cid && la.l2_psm) |
135 | return -EINVAL; | 148 | return -EINVAL; |
136 | 149 | ||
150 | if (!bdaddr_type_is_valid(la.l2_bdaddr_type)) | ||
151 | return -EINVAL; | ||
152 | |||
153 | if (chan->src_type == BDADDR_BREDR && la.l2_bdaddr_type != BDADDR_BREDR) | ||
154 | return -EINVAL; | ||
155 | |||
156 | if (chan->src_type != BDADDR_BREDR && la.l2_bdaddr_type == BDADDR_BREDR) | ||
157 | return -EINVAL; | ||
158 | |||
137 | err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid), | 159 | err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid), |
138 | &la.l2_bdaddr, la.l2_bdaddr_type); | 160 | &la.l2_bdaddr, la.l2_bdaddr_type); |
139 | if (err) | 161 | if (err) |
@@ -265,12 +287,14 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, | |||
265 | 287 | ||
266 | if (peer) { | 288 | if (peer) { |
267 | la->l2_psm = chan->psm; | 289 | la->l2_psm = chan->psm; |
268 | bacpy(&la->l2_bdaddr, &bt_sk(sk)->dst); | 290 | bacpy(&la->l2_bdaddr, &chan->dst); |
269 | la->l2_cid = cpu_to_le16(chan->dcid); | 291 | la->l2_cid = cpu_to_le16(chan->dcid); |
292 | la->l2_bdaddr_type = chan->dst_type; | ||
270 | } else { | 293 | } else { |
271 | la->l2_psm = chan->sport; | 294 | la->l2_psm = chan->sport; |
272 | bacpy(&la->l2_bdaddr, &bt_sk(sk)->src); | 295 | bacpy(&la->l2_bdaddr, &chan->src); |
273 | la->l2_cid = cpu_to_le16(chan->scid); | 296 | la->l2_cid = cpu_to_le16(chan->scid); |
297 | la->l2_bdaddr_type = chan->src_type; | ||
274 | } | 298 | } |
275 | 299 | ||
276 | return 0; | 300 | return 0; |
@@ -660,10 +684,13 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, | |||
660 | break; | 684 | break; |
661 | } | 685 | } |
662 | 686 | ||
663 | if (opt) | 687 | if (opt) { |
664 | set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); | 688 | set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); |
665 | else | 689 | set_bit(FLAG_DEFER_SETUP, &chan->flags); |
690 | } else { | ||
666 | clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); | 691 | clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); |
692 | clear_bit(FLAG_DEFER_SETUP, &chan->flags); | ||
693 | } | ||
667 | break; | 694 | break; |
668 | 695 | ||
669 | case BT_FLUSHABLE: | 696 | case BT_FLUSHABLE: |
@@ -678,7 +705,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, | |||
678 | } | 705 | } |
679 | 706 | ||
680 | if (opt == BT_FLUSHABLE_OFF) { | 707 | if (opt == BT_FLUSHABLE_OFF) { |
681 | struct l2cap_conn *conn = chan->conn; | 708 | conn = chan->conn; |
682 | /* proceed further only when we have l2cap_conn and | 709 | /* proceed further only when we have l2cap_conn and |
683 | No Flush support in the LM */ | 710 | No Flush support in the LM */ |
684 | if (!conn || !lmp_no_flush_capable(conn->hcon->hdev)) { | 711 | if (!conn || !lmp_no_flush_capable(conn->hcon->hdev)) { |
@@ -964,13 +991,12 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan) | |||
964 | 991 | ||
965 | static int l2cap_sock_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb) | 992 | static int l2cap_sock_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb) |
966 | { | 993 | { |
967 | int err; | ||
968 | struct sock *sk = chan->data; | 994 | struct sock *sk = chan->data; |
969 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 995 | int err; |
970 | 996 | ||
971 | lock_sock(sk); | 997 | lock_sock(sk); |
972 | 998 | ||
973 | if (pi->rx_busy_skb) { | 999 | if (l2cap_pi(sk)->rx_busy_skb) { |
974 | err = -ENOMEM; | 1000 | err = -ENOMEM; |
975 | goto done; | 1001 | goto done; |
976 | } | 1002 | } |
@@ -986,9 +1012,9 @@ static int l2cap_sock_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb) | |||
986 | * acked and reassembled until there is buffer space | 1012 | * acked and reassembled until there is buffer space |
987 | * available. | 1013 | * available. |
988 | */ | 1014 | */ |
989 | if (err < 0 && pi->chan->mode == L2CAP_MODE_ERTM) { | 1015 | if (err < 0 && chan->mode == L2CAP_MODE_ERTM) { |
990 | pi->rx_busy_skb = skb; | 1016 | l2cap_pi(sk)->rx_busy_skb = skb; |
991 | l2cap_chan_busy(pi->chan, 1); | 1017 | l2cap_chan_busy(chan, 1); |
992 | err = 0; | 1018 | err = 0; |
993 | } | 1019 | } |
994 | 1020 | ||
@@ -1098,6 +1124,14 @@ static void l2cap_sock_defer_cb(struct l2cap_chan *chan) | |||
1098 | parent->sk_data_ready(parent, 0); | 1124 | parent->sk_data_ready(parent, 0); |
1099 | } | 1125 | } |
1100 | 1126 | ||
1127 | static void l2cap_sock_resume_cb(struct l2cap_chan *chan) | ||
1128 | { | ||
1129 | struct sock *sk = chan->data; | ||
1130 | |||
1131 | clear_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags); | ||
1132 | sk->sk_state_change(sk); | ||
1133 | } | ||
1134 | |||
1101 | static struct l2cap_ops l2cap_chan_ops = { | 1135 | static struct l2cap_ops l2cap_chan_ops = { |
1102 | .name = "L2CAP Socket Interface", | 1136 | .name = "L2CAP Socket Interface", |
1103 | .new_connection = l2cap_sock_new_connection_cb, | 1137 | .new_connection = l2cap_sock_new_connection_cb, |
@@ -1107,6 +1141,7 @@ static struct l2cap_ops l2cap_chan_ops = { | |||
1107 | .state_change = l2cap_sock_state_change_cb, | 1141 | .state_change = l2cap_sock_state_change_cb, |
1108 | .ready = l2cap_sock_ready_cb, | 1142 | .ready = l2cap_sock_ready_cb, |
1109 | .defer = l2cap_sock_defer_cb, | 1143 | .defer = l2cap_sock_defer_cb, |
1144 | .resume = l2cap_sock_resume_cb, | ||
1110 | .alloc_skb = l2cap_sock_alloc_skb_cb, | 1145 | .alloc_skb = l2cap_sock_alloc_skb_cb, |
1111 | }; | 1146 | }; |
1112 | 1147 | ||
@@ -1116,6 +1151,7 @@ static void l2cap_sock_destruct(struct sock *sk) | |||
1116 | 1151 | ||
1117 | if (l2cap_pi(sk)->chan) | 1152 | if (l2cap_pi(sk)->chan) |
1118 | l2cap_chan_put(l2cap_pi(sk)->chan); | 1153 | l2cap_chan_put(l2cap_pi(sk)->chan); |
1154 | |||
1119 | if (l2cap_pi(sk)->rx_busy_skb) { | 1155 | if (l2cap_pi(sk)->rx_busy_skb) { |
1120 | kfree_skb(l2cap_pi(sk)->rx_busy_skb); | 1156 | kfree_skb(l2cap_pi(sk)->rx_busy_skb); |
1121 | l2cap_pi(sk)->rx_busy_skb = NULL; | 1157 | l2cap_pi(sk)->rx_busy_skb = NULL; |
@@ -1125,10 +1161,22 @@ static void l2cap_sock_destruct(struct sock *sk) | |||
1125 | skb_queue_purge(&sk->sk_write_queue); | 1161 | skb_queue_purge(&sk->sk_write_queue); |
1126 | } | 1162 | } |
1127 | 1163 | ||
1164 | static void l2cap_skb_msg_name(struct sk_buff *skb, void *msg_name, | ||
1165 | int *msg_namelen) | ||
1166 | { | ||
1167 | struct sockaddr_l2 *la = (struct sockaddr_l2 *) msg_name; | ||
1168 | |||
1169 | memset(la, 0, sizeof(struct sockaddr_l2)); | ||
1170 | la->l2_family = AF_BLUETOOTH; | ||
1171 | la->l2_psm = bt_cb(skb)->psm; | ||
1172 | bacpy(&la->l2_bdaddr, &bt_cb(skb)->bdaddr); | ||
1173 | |||
1174 | *msg_namelen = sizeof(struct sockaddr_l2); | ||
1175 | } | ||
1176 | |||
1128 | static void l2cap_sock_init(struct sock *sk, struct sock *parent) | 1177 | static void l2cap_sock_init(struct sock *sk, struct sock *parent) |
1129 | { | 1178 | { |
1130 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1179 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
1131 | struct l2cap_chan *chan = pi->chan; | ||
1132 | 1180 | ||
1133 | BT_DBG("sk %p", sk); | 1181 | BT_DBG("sk %p", sk); |
1134 | 1182 | ||
@@ -1152,13 +1200,13 @@ static void l2cap_sock_init(struct sock *sk, struct sock *parent) | |||
1152 | 1200 | ||
1153 | security_sk_clone(parent, sk); | 1201 | security_sk_clone(parent, sk); |
1154 | } else { | 1202 | } else { |
1155 | |||
1156 | switch (sk->sk_type) { | 1203 | switch (sk->sk_type) { |
1157 | case SOCK_RAW: | 1204 | case SOCK_RAW: |
1158 | chan->chan_type = L2CAP_CHAN_RAW; | 1205 | chan->chan_type = L2CAP_CHAN_RAW; |
1159 | break; | 1206 | break; |
1160 | case SOCK_DGRAM: | 1207 | case SOCK_DGRAM: |
1161 | chan->chan_type = L2CAP_CHAN_CONN_LESS; | 1208 | chan->chan_type = L2CAP_CHAN_CONN_LESS; |
1209 | bt_sk(sk)->skb_msg_name = l2cap_skb_msg_name; | ||
1162 | break; | 1210 | break; |
1163 | case SOCK_SEQPACKET: | 1211 | case SOCK_SEQPACKET: |
1164 | case SOCK_STREAM: | 1212 | case SOCK_STREAM: |