aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/l2cap_core.c
diff options
context:
space:
mode:
authorJames Morris <james.l.morris@oracle.com>2014-11-19 05:32:12 -0500
committerJames Morris <james.l.morris@oracle.com>2014-11-19 05:32:12 -0500
commitb10778a00d40b3d9fdaaf5891e802794781ff71c (patch)
tree6ba4cbac86eecedc3f30650e7f764ecf00c83898 /net/bluetooth/l2cap_core.c
parent594081ee7145cc30a3977cb4e218f81213b63dc5 (diff)
parentbfe01a5ba2490f299e1d2d5508cbbbadd897bbe9 (diff)
Merge commit 'v3.17' into next
Diffstat (limited to 'net/bluetooth/l2cap_core.c')
-rw-r--r--net/bluetooth/l2cap_core.c174
1 files changed, 93 insertions, 81 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 323f23cd2c37..46547b920f88 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -40,14 +40,13 @@
40#include "smp.h" 40#include "smp.h"
41#include "a2mp.h" 41#include "a2mp.h"
42#include "amp.h" 42#include "amp.h"
43#include "6lowpan.h"
44 43
45#define LE_FLOWCTL_MAX_CREDITS 65535 44#define LE_FLOWCTL_MAX_CREDITS 65535
46 45
47bool disable_ertm; 46bool disable_ertm;
48 47
49static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN | L2CAP_FEAT_UCD; 48static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN | L2CAP_FEAT_UCD;
50static u8 l2cap_fixed_chan[8] = { L2CAP_FC_L2CAP | L2CAP_FC_CONNLESS, }; 49static u8 l2cap_fixed_chan[8] = { L2CAP_FC_SIG_BREDR | L2CAP_FC_CONNLESS, };
51 50
52static LIST_HEAD(chan_list); 51static LIST_HEAD(chan_list);
53static DEFINE_RWLOCK(chan_list_lock); 52static DEFINE_RWLOCK(chan_list_lock);
@@ -205,6 +204,7 @@ done:
205 write_unlock(&chan_list_lock); 204 write_unlock(&chan_list_lock);
206 return err; 205 return err;
207} 206}
207EXPORT_SYMBOL_GPL(l2cap_add_psm);
208 208
209int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid) 209int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid)
210{ 210{
@@ -437,6 +437,7 @@ struct l2cap_chan *l2cap_chan_create(void)
437 437
438 return chan; 438 return chan;
439} 439}
440EXPORT_SYMBOL_GPL(l2cap_chan_create);
440 441
441static void l2cap_chan_destroy(struct kref *kref) 442static void l2cap_chan_destroy(struct kref *kref)
442{ 443{
@@ -464,6 +465,7 @@ void l2cap_chan_put(struct l2cap_chan *c)
464 465
465 kref_put(&c->kref, l2cap_chan_destroy); 466 kref_put(&c->kref, l2cap_chan_destroy);
466} 467}
468EXPORT_SYMBOL_GPL(l2cap_chan_put);
467 469
468void l2cap_chan_set_defaults(struct l2cap_chan *chan) 470void l2cap_chan_set_defaults(struct l2cap_chan *chan)
469{ 471{
@@ -482,6 +484,7 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan)
482 484
483 set_bit(FLAG_FORCE_ACTIVE, &chan->flags); 485 set_bit(FLAG_FORCE_ACTIVE, &chan->flags);
484} 486}
487EXPORT_SYMBOL_GPL(l2cap_chan_set_defaults);
485 488
486static void l2cap_le_flowctl_init(struct l2cap_chan *chan) 489static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
487{ 490{
@@ -614,6 +617,7 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
614 617
615 return; 618 return;
616} 619}
620EXPORT_SYMBOL_GPL(l2cap_chan_del);
617 621
618void l2cap_conn_update_id_addr(struct hci_conn *hcon) 622void l2cap_conn_update_id_addr(struct hci_conn *hcon)
619{ 623{
@@ -717,6 +721,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
717 break; 721 break;
718 } 722 }
719} 723}
724EXPORT_SYMBOL(l2cap_chan_close);
720 725
721static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan) 726static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
722{ 727{
@@ -770,7 +775,7 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
770} 775}
771 776
772/* Service level security */ 777/* Service level security */
773int l2cap_chan_check_security(struct l2cap_chan *chan) 778int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator)
774{ 779{
775 struct l2cap_conn *conn = chan->conn; 780 struct l2cap_conn *conn = chan->conn;
776 __u8 auth_type; 781 __u8 auth_type;
@@ -780,7 +785,8 @@ int l2cap_chan_check_security(struct l2cap_chan *chan)
780 785
781 auth_type = l2cap_get_auth_type(chan); 786 auth_type = l2cap_get_auth_type(chan);
782 787
783 return hci_conn_security(conn->hcon, chan->sec_level, auth_type); 788 return hci_conn_security(conn->hcon, chan->sec_level, auth_type,
789 initiator);
784} 790}
785 791
786static u8 l2cap_get_ident(struct l2cap_conn *conn) 792static u8 l2cap_get_ident(struct l2cap_conn *conn)
@@ -793,14 +799,14 @@ static u8 l2cap_get_ident(struct l2cap_conn *conn)
793 * 200 - 254 are used by utilities like l2ping, etc. 799 * 200 - 254 are used by utilities like l2ping, etc.
794 */ 800 */
795 801
796 spin_lock(&conn->lock); 802 mutex_lock(&conn->ident_lock);
797 803
798 if (++conn->tx_ident > 128) 804 if (++conn->tx_ident > 128)
799 conn->tx_ident = 1; 805 conn->tx_ident = 1;
800 806
801 id = conn->tx_ident; 807 id = conn->tx_ident;
802 808
803 spin_unlock(&conn->lock); 809 mutex_unlock(&conn->ident_lock);
804 810
805 return id; 811 return id;
806} 812}
@@ -1273,7 +1279,7 @@ static void l2cap_do_start(struct l2cap_chan *chan)
1273 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) 1279 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE))
1274 return; 1280 return;
1275 1281
1276 if (l2cap_chan_check_security(chan) && 1282 if (l2cap_chan_check_security(chan, true) &&
1277 __l2cap_no_conn_pending(chan)) { 1283 __l2cap_no_conn_pending(chan)) {
1278 l2cap_start_connection(chan); 1284 l2cap_start_connection(chan);
1279 } 1285 }
@@ -1352,7 +1358,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
1352 } 1358 }
1353 1359
1354 if (chan->state == BT_CONNECT) { 1360 if (chan->state == BT_CONNECT) {
1355 if (!l2cap_chan_check_security(chan) || 1361 if (!l2cap_chan_check_security(chan, true) ||
1356 !__l2cap_no_conn_pending(chan)) { 1362 !__l2cap_no_conn_pending(chan)) {
1357 l2cap_chan_unlock(chan); 1363 l2cap_chan_unlock(chan);
1358 continue; 1364 continue;
@@ -1374,7 +1380,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
1374 rsp.scid = cpu_to_le16(chan->dcid); 1380 rsp.scid = cpu_to_le16(chan->dcid);
1375 rsp.dcid = cpu_to_le16(chan->scid); 1381 rsp.dcid = cpu_to_le16(chan->scid);
1376 1382
1377 if (l2cap_chan_check_security(chan)) { 1383 if (l2cap_chan_check_security(chan, false)) {
1378 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { 1384 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
1379 rsp.result = cpu_to_le16(L2CAP_CR_PEND); 1385 rsp.result = cpu_to_le16(L2CAP_CR_PEND);
1380 rsp.status = cpu_to_le16(L2CAP_CS_AUTHOR_PEND); 1386 rsp.status = cpu_to_le16(L2CAP_CS_AUTHOR_PEND);
@@ -1455,13 +1461,12 @@ static struct l2cap_chan *l2cap_global_chan_by_scid(int state, u16 cid,
1455static void l2cap_le_conn_ready(struct l2cap_conn *conn) 1461static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1456{ 1462{
1457 struct hci_conn *hcon = conn->hcon; 1463 struct hci_conn *hcon = conn->hcon;
1464 struct hci_dev *hdev = hcon->hdev;
1458 struct l2cap_chan *chan, *pchan; 1465 struct l2cap_chan *chan, *pchan;
1459 u8 dst_type; 1466 u8 dst_type;
1460 1467
1461 BT_DBG(""); 1468 BT_DBG("");
1462 1469
1463 bt_6lowpan_add_conn(conn);
1464
1465 /* Check if we have socket listening on cid */ 1470 /* Check if we have socket listening on cid */
1466 pchan = l2cap_global_chan_by_scid(BT_LISTEN, L2CAP_CID_ATT, 1471 pchan = l2cap_global_chan_by_scid(BT_LISTEN, L2CAP_CID_ATT,
1467 &hcon->src, &hcon->dst); 1472 &hcon->src, &hcon->dst);
@@ -1475,9 +1480,28 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1475 dst_type = bdaddr_type(hcon, hcon->dst_type); 1480 dst_type = bdaddr_type(hcon, hcon->dst_type);
1476 1481
1477 /* If device is blocked, do not create a channel for it */ 1482 /* If device is blocked, do not create a channel for it */
1478 if (hci_blacklist_lookup(hcon->hdev, &hcon->dst, dst_type)) 1483 if (hci_bdaddr_list_lookup(&hdev->blacklist, &hcon->dst, dst_type))
1479 return; 1484 return;
1480 1485
1486 /* For LE slave connections, make sure the connection interval
1487 * is in the range of the minium and maximum interval that has
1488 * been configured for this connection. If not, then trigger
1489 * the connection update procedure.
1490 */
1491 if (hcon->role == HCI_ROLE_SLAVE &&
1492 (hcon->le_conn_interval < hcon->le_conn_min_interval ||
1493 hcon->le_conn_interval > hcon->le_conn_max_interval)) {
1494 struct l2cap_conn_param_update_req req;
1495
1496 req.min = cpu_to_le16(hcon->le_conn_min_interval);
1497 req.max = cpu_to_le16(hcon->le_conn_max_interval);
1498 req.latency = cpu_to_le16(hcon->le_conn_latency);
1499 req.to_multiplier = cpu_to_le16(hcon->le_supv_timeout);
1500
1501 l2cap_send_cmd(conn, l2cap_get_ident(conn),
1502 L2CAP_CONN_PARAM_UPDATE_REQ, sizeof(req), &req);
1503 }
1504
1481 l2cap_chan_lock(pchan); 1505 l2cap_chan_lock(pchan);
1482 1506
1483 chan = pchan->ops->new_connection(pchan); 1507 chan = pchan->ops->new_connection(pchan);
@@ -2118,7 +2142,8 @@ static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
2118 struct sk_buff **frag; 2142 struct sk_buff **frag;
2119 int sent = 0; 2143 int sent = 0;
2120 2144
2121 if (memcpy_fromiovec(skb_put(skb, count), msg->msg_iov, count)) 2145 if (chan->ops->memcpy_fromiovec(chan, skb_put(skb, count),
2146 msg->msg_iov, count))
2122 return -EFAULT; 2147 return -EFAULT;
2123 2148
2124 sent += count; 2149 sent += count;
@@ -2131,18 +2156,17 @@ static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
2131 2156
2132 count = min_t(unsigned int, conn->mtu, len); 2157 count = min_t(unsigned int, conn->mtu, len);
2133 2158
2134 tmp = chan->ops->alloc_skb(chan, count, 2159 tmp = chan->ops->alloc_skb(chan, 0, count,
2135 msg->msg_flags & MSG_DONTWAIT); 2160 msg->msg_flags & MSG_DONTWAIT);
2136 if (IS_ERR(tmp)) 2161 if (IS_ERR(tmp))
2137 return PTR_ERR(tmp); 2162 return PTR_ERR(tmp);
2138 2163
2139 *frag = tmp; 2164 *frag = tmp;
2140 2165
2141 if (memcpy_fromiovec(skb_put(*frag, count), msg->msg_iov, count)) 2166 if (chan->ops->memcpy_fromiovec(chan, skb_put(*frag, count),
2167 msg->msg_iov, count))
2142 return -EFAULT; 2168 return -EFAULT;
2143 2169
2144 (*frag)->priority = skb->priority;
2145
2146 sent += count; 2170 sent += count;
2147 len -= count; 2171 len -= count;
2148 2172
@@ -2156,26 +2180,23 @@ static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
2156} 2180}
2157 2181
2158static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, 2182static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan,
2159 struct msghdr *msg, size_t len, 2183 struct msghdr *msg, size_t len)
2160 u32 priority)
2161{ 2184{
2162 struct l2cap_conn *conn = chan->conn; 2185 struct l2cap_conn *conn = chan->conn;
2163 struct sk_buff *skb; 2186 struct sk_buff *skb;
2164 int err, count, hlen = L2CAP_HDR_SIZE + L2CAP_PSMLEN_SIZE; 2187 int err, count, hlen = L2CAP_HDR_SIZE + L2CAP_PSMLEN_SIZE;
2165 struct l2cap_hdr *lh; 2188 struct l2cap_hdr *lh;
2166 2189
2167 BT_DBG("chan %p psm 0x%2.2x len %zu priority %u", chan, 2190 BT_DBG("chan %p psm 0x%2.2x len %zu", chan,
2168 __le16_to_cpu(chan->psm), len, priority); 2191 __le16_to_cpu(chan->psm), len);
2169 2192
2170 count = min_t(unsigned int, (conn->mtu - hlen), len); 2193 count = min_t(unsigned int, (conn->mtu - hlen), len);
2171 2194
2172 skb = chan->ops->alloc_skb(chan, count + hlen, 2195 skb = chan->ops->alloc_skb(chan, hlen, count,
2173 msg->msg_flags & MSG_DONTWAIT); 2196 msg->msg_flags & MSG_DONTWAIT);
2174 if (IS_ERR(skb)) 2197 if (IS_ERR(skb))
2175 return skb; 2198 return skb;
2176 2199
2177 skb->priority = priority;
2178
2179 /* Create L2CAP header */ 2200 /* Create L2CAP header */
2180 lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE); 2201 lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
2181 lh->cid = cpu_to_le16(chan->dcid); 2202 lh->cid = cpu_to_le16(chan->dcid);
@@ -2191,8 +2212,7 @@ static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan,
2191} 2212}
2192 2213
2193static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, 2214static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan,
2194 struct msghdr *msg, size_t len, 2215 struct msghdr *msg, size_t len)
2195 u32 priority)
2196{ 2216{
2197 struct l2cap_conn *conn = chan->conn; 2217 struct l2cap_conn *conn = chan->conn;
2198 struct sk_buff *skb; 2218 struct sk_buff *skb;
@@ -2203,13 +2223,11 @@ static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan,
2203 2223
2204 count = min_t(unsigned int, (conn->mtu - L2CAP_HDR_SIZE), len); 2224 count = min_t(unsigned int, (conn->mtu - L2CAP_HDR_SIZE), len);
2205 2225
2206 skb = chan->ops->alloc_skb(chan, count + L2CAP_HDR_SIZE, 2226 skb = chan->ops->alloc_skb(chan, L2CAP_HDR_SIZE, count,
2207 msg->msg_flags & MSG_DONTWAIT); 2227 msg->msg_flags & MSG_DONTWAIT);
2208 if (IS_ERR(skb)) 2228 if (IS_ERR(skb))
2209 return skb; 2229 return skb;
2210 2230
2211 skb->priority = priority;
2212
2213 /* Create L2CAP header */ 2231 /* Create L2CAP header */
2214 lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE); 2232 lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
2215 lh->cid = cpu_to_le16(chan->dcid); 2233 lh->cid = cpu_to_le16(chan->dcid);
@@ -2247,7 +2265,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
2247 2265
2248 count = min_t(unsigned int, (conn->mtu - hlen), len); 2266 count = min_t(unsigned int, (conn->mtu - hlen), len);
2249 2267
2250 skb = chan->ops->alloc_skb(chan, count + hlen, 2268 skb = chan->ops->alloc_skb(chan, hlen, count,
2251 msg->msg_flags & MSG_DONTWAIT); 2269 msg->msg_flags & MSG_DONTWAIT);
2252 if (IS_ERR(skb)) 2270 if (IS_ERR(skb))
2253 return skb; 2271 return skb;
@@ -2368,7 +2386,7 @@ static struct sk_buff *l2cap_create_le_flowctl_pdu(struct l2cap_chan *chan,
2368 2386
2369 count = min_t(unsigned int, (conn->mtu - hlen), len); 2387 count = min_t(unsigned int, (conn->mtu - hlen), len);
2370 2388
2371 skb = chan->ops->alloc_skb(chan, count + hlen, 2389 skb = chan->ops->alloc_skb(chan, hlen, count,
2372 msg->msg_flags & MSG_DONTWAIT); 2390 msg->msg_flags & MSG_DONTWAIT);
2373 if (IS_ERR(skb)) 2391 if (IS_ERR(skb))
2374 return skb; 2392 return skb;
@@ -2430,8 +2448,7 @@ static int l2cap_segment_le_sdu(struct l2cap_chan *chan,
2430 return 0; 2448 return 0;
2431} 2449}
2432 2450
2433int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 2451int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
2434 u32 priority)
2435{ 2452{
2436 struct sk_buff *skb; 2453 struct sk_buff *skb;
2437 int err; 2454 int err;
@@ -2442,7 +2459,7 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
2442 2459
2443 /* Connectionless channel */ 2460 /* Connectionless channel */
2444 if (chan->chan_type == L2CAP_CHAN_CONN_LESS) { 2461 if (chan->chan_type == L2CAP_CHAN_CONN_LESS) {
2445 skb = l2cap_create_connless_pdu(chan, msg, len, priority); 2462 skb = l2cap_create_connless_pdu(chan, msg, len);
2446 if (IS_ERR(skb)) 2463 if (IS_ERR(skb))
2447 return PTR_ERR(skb); 2464 return PTR_ERR(skb);
2448 2465
@@ -2499,7 +2516,7 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
2499 return -EMSGSIZE; 2516 return -EMSGSIZE;
2500 2517
2501 /* Create a basic PDU */ 2518 /* Create a basic PDU */
2502 skb = l2cap_create_basic_pdu(chan, msg, len, priority); 2519 skb = l2cap_create_basic_pdu(chan, msg, len);
2503 if (IS_ERR(skb)) 2520 if (IS_ERR(skb))
2504 return PTR_ERR(skb); 2521 return PTR_ERR(skb);
2505 2522
@@ -2562,6 +2579,7 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
2562 2579
2563 return err; 2580 return err;
2564} 2581}
2582EXPORT_SYMBOL_GPL(l2cap_chan_send);
2565 2583
2566static void l2cap_send_srej(struct l2cap_chan *chan, u16 txseq) 2584static void l2cap_send_srej(struct l2cap_chan *chan, u16 txseq)
2567{ 2585{
@@ -3217,6 +3235,9 @@ done:
3217 3235
3218 switch (chan->mode) { 3236 switch (chan->mode) {
3219 case L2CAP_MODE_BASIC: 3237 case L2CAP_MODE_BASIC:
3238 if (disable_ertm)
3239 break;
3240
3220 if (!(chan->conn->feat_mask & L2CAP_FEAT_ERTM) && 3241 if (!(chan->conn->feat_mask & L2CAP_FEAT_ERTM) &&
3221 !(chan->conn->feat_mask & L2CAP_FEAT_STREAMING)) 3242 !(chan->conn->feat_mask & L2CAP_FEAT_STREAMING))
3222 break; 3243 break;
@@ -3829,7 +3850,7 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
3829 chan->ident = cmd->ident; 3850 chan->ident = cmd->ident;
3830 3851
3831 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) { 3852 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) {
3832 if (l2cap_chan_check_security(chan)) { 3853 if (l2cap_chan_check_security(chan, false)) {
3833 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { 3854 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
3834 l2cap_state_change(chan, BT_CONNECT2); 3855 l2cap_state_change(chan, BT_CONNECT2);
3835 result = L2CAP_CR_PEND; 3856 result = L2CAP_CR_PEND;
@@ -5197,27 +5218,6 @@ static inline int l2cap_move_channel_confirm_rsp(struct l2cap_conn *conn,
5197 return 0; 5218 return 0;
5198} 5219}
5199 5220
5200static inline int l2cap_check_conn_param(u16 min, u16 max, u16 latency,
5201 u16 to_multiplier)
5202{
5203 u16 max_latency;
5204
5205 if (min > max || min < 6 || max > 3200)
5206 return -EINVAL;
5207
5208 if (to_multiplier < 10 || to_multiplier > 3200)
5209 return -EINVAL;
5210
5211 if (max >= to_multiplier * 8)
5212 return -EINVAL;
5213
5214 max_latency = (to_multiplier * 8 / max) - 1;
5215 if (latency > 499 || latency > max_latency)
5216 return -EINVAL;
5217
5218 return 0;
5219}
5220
5221static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn, 5221static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
5222 struct l2cap_cmd_hdr *cmd, 5222 struct l2cap_cmd_hdr *cmd,
5223 u16 cmd_len, u8 *data) 5223 u16 cmd_len, u8 *data)
@@ -5228,7 +5228,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
5228 u16 min, max, latency, to_multiplier; 5228 u16 min, max, latency, to_multiplier;
5229 int err; 5229 int err;
5230 5230
5231 if (!(hcon->link_mode & HCI_LM_MASTER)) 5231 if (hcon->role != HCI_ROLE_MASTER)
5232 return -EINVAL; 5232 return -EINVAL;
5233 5233
5234 if (cmd_len != sizeof(struct l2cap_conn_param_update_req)) 5234 if (cmd_len != sizeof(struct l2cap_conn_param_update_req))
@@ -5245,7 +5245,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
5245 5245
5246 memset(&rsp, 0, sizeof(rsp)); 5246 memset(&rsp, 0, sizeof(rsp));
5247 5247
5248 err = l2cap_check_conn_param(min, max, latency, to_multiplier); 5248 err = hci_check_conn_params(min, max, latency, to_multiplier);
5249 if (err) 5249 if (err)
5250 rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED); 5250 rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED);
5251 else 5251 else
@@ -5254,8 +5254,16 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
5254 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONN_PARAM_UPDATE_RSP, 5254 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONN_PARAM_UPDATE_RSP,
5255 sizeof(rsp), &rsp); 5255 sizeof(rsp), &rsp);
5256 5256
5257 if (!err) 5257 if (!err) {
5258 hci_le_conn_update(hcon, min, max, latency, to_multiplier); 5258 u8 store_hint;
5259
5260 store_hint = hci_le_conn_update(hcon, min, max, latency,
5261 to_multiplier);
5262 mgmt_new_conn_param(hcon->hdev, &hcon->dst, hcon->dst_type,
5263 store_hint, min, max, latency,
5264 to_multiplier);
5265
5266 }
5259 5267
5260 return 0; 5268 return 0;
5261} 5269}
@@ -6879,9 +6887,6 @@ static void l2cap_att_channel(struct l2cap_conn *conn,
6879 6887
6880 BT_DBG("chan %p, len %d", chan, skb->len); 6888 BT_DBG("chan %p, len %d", chan, skb->len);
6881 6889
6882 if (hci_blacklist_lookup(hcon->hdev, &hcon->dst, hcon->dst_type))
6883 goto drop;
6884
6885 if (chan->imtu < skb->len) 6890 if (chan->imtu < skb->len)
6886 goto drop; 6891 goto drop;
6887 6892
@@ -6914,6 +6919,16 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
6914 return; 6919 return;
6915 } 6920 }
6916 6921
6922 /* Since we can't actively block incoming LE connections we must
6923 * at least ensure that we ignore incoming data from them.
6924 */
6925 if (hcon->type == LE_LINK &&
6926 hci_bdaddr_list_lookup(&hcon->hdev->blacklist, &hcon->dst,
6927 bdaddr_type(hcon, hcon->dst_type))) {
6928 kfree_skb(skb);
6929 return;
6930 }
6931
6917 BT_DBG("len %d, cid 0x%4.4x", len, cid); 6932 BT_DBG("len %d, cid 0x%4.4x", len, cid);
6918 6933
6919 switch (cid) { 6934 switch (cid) {
@@ -6940,10 +6955,6 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
6940 l2cap_conn_del(conn->hcon, EACCES); 6955 l2cap_conn_del(conn->hcon, EACCES);
6941 break; 6956 break;
6942 6957
6943 case L2CAP_FC_6LOWPAN:
6944 bt_6lowpan_recv(conn, skb);
6945 break;
6946
6947 default: 6958 default:
6948 l2cap_data_channel(conn, cid, skb); 6959 l2cap_data_channel(conn, cid, skb);
6949 break; 6960 break;
@@ -6974,7 +6985,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
6974 if (!hchan) 6985 if (!hchan)
6975 return NULL; 6986 return NULL;
6976 6987
6977 conn = kzalloc(sizeof(struct l2cap_conn), GFP_KERNEL); 6988 conn = kzalloc(sizeof(*conn), GFP_KERNEL);
6978 if (!conn) { 6989 if (!conn) {
6979 hci_chan_del(hchan); 6990 hci_chan_del(hchan);
6980 return NULL; 6991 return NULL;
@@ -7006,7 +7017,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
7006 conn->hs_enabled = test_bit(HCI_HS_ENABLED, 7017 conn->hs_enabled = test_bit(HCI_HS_ENABLED,
7007 &hcon->hdev->dev_flags); 7018 &hcon->hdev->dev_flags);
7008 7019
7009 spin_lock_init(&conn->lock); 7020 mutex_init(&conn->ident_lock);
7010 mutex_init(&conn->chan_lock); 7021 mutex_init(&conn->chan_lock);
7011 7022
7012 INIT_LIST_HEAD(&conn->chan_l); 7023 INIT_LIST_HEAD(&conn->chan_l);
@@ -7042,7 +7053,6 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7042 struct l2cap_conn *conn; 7053 struct l2cap_conn *conn;
7043 struct hci_conn *hcon; 7054 struct hci_conn *hcon;
7044 struct hci_dev *hdev; 7055 struct hci_dev *hdev;
7045 __u8 auth_type;
7046 int err; 7056 int err;
7047 7057
7048 BT_DBG("%pMR -> %pMR (type %u) psm 0x%2.2x", &chan->src, dst, 7058 BT_DBG("%pMR -> %pMR (type %u) psm 0x%2.2x", &chan->src, dst,
@@ -7084,7 +7094,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7084 break; 7094 break;
7085 /* fall through */ 7095 /* fall through */
7086 default: 7096 default:
7087 err = -ENOTSUPP; 7097 err = -EOPNOTSUPP;
7088 goto done; 7098 goto done;
7089 } 7099 }
7090 7100
@@ -7118,9 +7128,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7118 chan->psm = psm; 7128 chan->psm = psm;
7119 chan->dcid = cid; 7129 chan->dcid = cid;
7120 7130
7121 auth_type = l2cap_get_auth_type(chan);
7122
7123 if (bdaddr_type_is_le(dst_type)) { 7131 if (bdaddr_type_is_le(dst_type)) {
7132 u8 role;
7133
7124 /* Convert from L2CAP channel address type to HCI address type 7134 /* Convert from L2CAP channel address type to HCI address type
7125 */ 7135 */
7126 if (dst_type == BDADDR_LE_PUBLIC) 7136 if (dst_type == BDADDR_LE_PUBLIC)
@@ -7128,9 +7138,15 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7128 else 7138 else
7129 dst_type = ADDR_LE_DEV_RANDOM; 7139 dst_type = ADDR_LE_DEV_RANDOM;
7130 7140
7141 if (test_bit(HCI_ADVERTISING, &hdev->dev_flags))
7142 role = HCI_ROLE_SLAVE;
7143 else
7144 role = HCI_ROLE_MASTER;
7145
7131 hcon = hci_connect_le(hdev, dst, dst_type, chan->sec_level, 7146 hcon = hci_connect_le(hdev, dst, dst_type, chan->sec_level,
7132 auth_type); 7147 HCI_LE_CONN_TIMEOUT, role);
7133 } else { 7148 } else {
7149 u8 auth_type = l2cap_get_auth_type(chan);
7134 hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type); 7150 hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type);
7135 } 7151 }
7136 7152
@@ -7176,7 +7192,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7176 if (hcon->state == BT_CONNECTED) { 7192 if (hcon->state == BT_CONNECTED) {
7177 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { 7193 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
7178 __clear_chan_timer(chan); 7194 __clear_chan_timer(chan);
7179 if (l2cap_chan_check_security(chan)) 7195 if (l2cap_chan_check_security(chan, true))
7180 l2cap_state_change(chan, BT_CONNECTED); 7196 l2cap_state_change(chan, BT_CONNECTED);
7181 } else 7197 } else
7182 l2cap_do_start(chan); 7198 l2cap_do_start(chan);
@@ -7190,6 +7206,7 @@ done:
7190 hci_dev_put(hdev); 7206 hci_dev_put(hdev);
7191 return err; 7207 return err;
7192} 7208}
7209EXPORT_SYMBOL_GPL(l2cap_chan_connect);
7193 7210
7194/* ---- L2CAP interface with lower layer (HCI) ---- */ 7211/* ---- L2CAP interface with lower layer (HCI) ---- */
7195 7212
@@ -7252,8 +7269,6 @@ void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
7252{ 7269{
7253 BT_DBG("hcon %p reason %d", hcon, reason); 7270 BT_DBG("hcon %p reason %d", hcon, reason);
7254 7271
7255 bt_6lowpan_del_conn(hcon->l2cap_data);
7256
7257 l2cap_conn_del(hcon, bt_to_errno(reason)); 7272 l2cap_conn_del(hcon, bt_to_errno(reason));
7258} 7273}
7259 7274
@@ -7536,14 +7551,11 @@ int __init l2cap_init(void)
7536 debugfs_create_u16("l2cap_le_default_mps", 0644, bt_debugfs, 7551 debugfs_create_u16("l2cap_le_default_mps", 0644, bt_debugfs,
7537 &le_default_mps); 7552 &le_default_mps);
7538 7553
7539 bt_6lowpan_init();
7540
7541 return 0; 7554 return 0;
7542} 7555}
7543 7556
7544void l2cap_exit(void) 7557void l2cap_exit(void)
7545{ 7558{
7546 bt_6lowpan_cleanup();
7547 debugfs_remove(l2cap_debugfs); 7559 debugfs_remove(l2cap_debugfs);
7548 l2cap_cleanup_sockets(); 7560 l2cap_cleanup_sockets();
7549} 7561}