2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4 Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org>
5 Copyright (C) 2010 Google Inc.
6 Copyright (C) 2011 ProFUSION Embedded Systems
8 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License version 2 as
12 published by the Free Software Foundation;
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
17 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
18 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
24 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
25 SOFTWARE IS DISCLAIMED.
28 /* Bluetooth L2CAP sockets. */
30 #include <linux/module.h>
31 #include <linux/export.h>
32 #include <linux/filter.h>
33 #include <linux/sched/signal.h>
35 #include <net/bluetooth/bluetooth.h>
36 #include <net/bluetooth/hci_core.h>
37 #include <net/bluetooth/l2cap.h>
41 static struct bt_sock_list l2cap_sk_list = {
42 .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock)
45 static const struct proto_ops l2cap_sock_ops;
46 static void l2cap_sock_init(struct sock *sk, struct sock *parent);
47 static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
48 int proto, gfp_t prio, int kern);
49 static void l2cap_sock_cleanup_listen(struct sock *parent);
51 bool l2cap_is_socket(struct socket *sock)
53 return sock && sock->ops == &l2cap_sock_ops;
55 EXPORT_SYMBOL(l2cap_is_socket);
57 static int l2cap_validate_bredr_psm(u16 psm)
59 /* PSM must be odd and lsb of upper byte must be 0 */
60 if ((psm & 0x0101) != 0x0001)
63 /* Restrict usage of well-known PSMs */
64 if (psm < L2CAP_PSM_DYN_START && !capable(CAP_NET_BIND_SERVICE))
70 static int l2cap_validate_le_psm(u16 psm)
72 /* Valid LE_PSM ranges are defined only until 0x00ff */
73 if (psm > L2CAP_PSM_LE_DYN_END)
76 /* Restrict fixed, SIG assigned PSM values to CAP_NET_BIND_SERVICE */
77 if (psm < L2CAP_PSM_LE_DYN_START && !capable(CAP_NET_BIND_SERVICE))
83 static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
85 struct sock *sk = sock->sk;
86 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
87 struct sockaddr_l2 la;
92 if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
93 addr->sa_family != AF_BLUETOOTH)
96 memset(&la, 0, sizeof(la));
97 len = min_t(unsigned int, sizeof(la), alen);
98 memcpy(&la, addr, len);
100 if (la.l2_cid && la.l2_psm)
103 if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
106 if (bdaddr_type_is_le(la.l2_bdaddr_type)) {
107 /* We only allow ATT user space socket */
109 la.l2_cid != cpu_to_le16(L2CAP_CID_ATT))
115 if (sk->sk_state != BT_OPEN) {
121 __u16 psm = __le16_to_cpu(la.l2_psm);
123 if (la.l2_bdaddr_type == BDADDR_BREDR)
124 err = l2cap_validate_bredr_psm(psm);
126 err = l2cap_validate_le_psm(psm);
132 bacpy(&chan->src, &la.l2_bdaddr);
133 chan->src_type = la.l2_bdaddr_type;
136 err = l2cap_add_scid(chan, __le16_to_cpu(la.l2_cid));
138 err = l2cap_add_psm(chan, &la.l2_bdaddr, la.l2_psm);
143 switch (chan->chan_type) {
144 case L2CAP_CHAN_CONN_LESS:
145 if (__le16_to_cpu(la.l2_psm) == L2CAP_PSM_3DSP)
146 chan->sec_level = BT_SECURITY_SDP;
148 case L2CAP_CHAN_CONN_ORIENTED:
149 if (__le16_to_cpu(la.l2_psm) == L2CAP_PSM_SDP ||
150 __le16_to_cpu(la.l2_psm) == L2CAP_PSM_RFCOMM)
151 chan->sec_level = BT_SECURITY_SDP;
154 chan->sec_level = BT_SECURITY_SDP;
156 case L2CAP_CHAN_FIXED:
157 /* Fixed channels default to the L2CAP core not holding a
158 * hci_conn reference for them. For fixed channels mapping to
159 * L2CAP sockets we do want to hold a reference so set the
160 * appropriate flag to request it.
162 set_bit(FLAG_HOLD_HCI_CONN, &chan->flags);
166 /* Use L2CAP_MODE_LE_FLOWCTL (CoC) in case of LE address and
167 * L2CAP_MODE_EXT_FLOWCTL (ECRED) has not been set.
169 if (chan->psm && bdaddr_type_is_le(chan->src_type) &&
170 chan->mode != L2CAP_MODE_EXT_FLOWCTL)
171 chan->mode = L2CAP_MODE_LE_FLOWCTL;
173 chan->state = BT_BOUND;
174 sk->sk_state = BT_BOUND;
181 static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
184 struct sock *sk = sock->sk;
185 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
186 struct sockaddr_l2 la;
193 zapped = sock_flag(sk, SOCK_ZAPPED);
199 if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
200 addr->sa_family != AF_BLUETOOTH)
203 memset(&la, 0, sizeof(la));
204 len = min_t(unsigned int, sizeof(la), alen);
205 memcpy(&la, addr, len);
207 if (la.l2_cid && la.l2_psm)
210 if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
213 /* Check that the socket wasn't bound to something that
214 * conflicts with the address given to connect(). If chan->src
215 * is BDADDR_ANY it means bind() was never used, in which case
216 * chan->src_type and la.l2_bdaddr_type do not need to match.
218 if (chan->src_type == BDADDR_BREDR && bacmp(&chan->src, BDADDR_ANY) &&
219 bdaddr_type_is_le(la.l2_bdaddr_type)) {
220 /* Old user space versions will try to incorrectly bind
221 * the ATT socket using BDADDR_BREDR. We need to accept
222 * this and fix up the source address type only when
223 * both the source CID and destination CID indicate
224 * ATT. Anything else is an invalid combination.
226 if (chan->scid != L2CAP_CID_ATT ||
227 la.l2_cid != cpu_to_le16(L2CAP_CID_ATT))
230 /* We don't have the hdev available here to make a
231 * better decision on random vs public, but since all
232 * user space versions that exhibit this issue anyway do
233 * not support random local addresses assuming public
234 * here is good enough.
236 chan->src_type = BDADDR_LE_PUBLIC;
239 if (chan->src_type != BDADDR_BREDR && la.l2_bdaddr_type == BDADDR_BREDR)
242 if (bdaddr_type_is_le(la.l2_bdaddr_type)) {
243 /* We only allow ATT user space socket */
245 la.l2_cid != cpu_to_le16(L2CAP_CID_ATT))
249 /* Use L2CAP_MODE_LE_FLOWCTL (CoC) in case of LE address and
250 * L2CAP_MODE_EXT_FLOWCTL (ECRED) has not been set.
252 if (chan->psm && bdaddr_type_is_le(chan->src_type) &&
253 chan->mode != L2CAP_MODE_EXT_FLOWCTL)
254 chan->mode = L2CAP_MODE_LE_FLOWCTL;
256 err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
257 &la.l2_bdaddr, la.l2_bdaddr_type);
263 err = bt_sock_wait_state(sk, BT_CONNECTED,
264 sock_sndtimeo(sk, flags & O_NONBLOCK));
271 static int l2cap_sock_listen(struct socket *sock, int backlog)
273 struct sock *sk = sock->sk;
274 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
277 BT_DBG("sk %p backlog %d", sk, backlog);
281 if (sk->sk_state != BT_BOUND) {
286 if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM) {
291 switch (chan->mode) {
292 case L2CAP_MODE_BASIC:
293 case L2CAP_MODE_LE_FLOWCTL:
295 case L2CAP_MODE_EXT_FLOWCTL:
301 case L2CAP_MODE_ERTM:
302 case L2CAP_MODE_STREAMING:
311 sk->sk_max_ack_backlog = backlog;
312 sk->sk_ack_backlog = 0;
314 /* Listening channels need to use nested locking in order not to
315 * cause lockdep warnings when the created child channels end up
316 * being locked in the same thread as the parent channel.
318 atomic_set(&chan->nesting, L2CAP_NESTING_PARENT);
320 chan->state = BT_LISTEN;
321 sk->sk_state = BT_LISTEN;
328 static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,
329 int flags, bool kern)
331 DEFINE_WAIT_FUNC(wait, woken_wake_function);
332 struct sock *sk = sock->sk, *nsk;
336 lock_sock_nested(sk, L2CAP_NESTING_PARENT);
338 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
340 BT_DBG("sk %p timeo %ld", sk, timeo);
342 /* Wait for an incoming connection. (wake-one). */
343 add_wait_queue_exclusive(sk_sleep(sk), &wait);
345 if (sk->sk_state != BT_LISTEN) {
350 nsk = bt_accept_dequeue(sk, newsock);
359 if (signal_pending(current)) {
360 err = sock_intr_errno(timeo);
366 timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, timeo);
368 lock_sock_nested(sk, L2CAP_NESTING_PARENT);
370 remove_wait_queue(sk_sleep(sk), &wait);
375 newsock->state = SS_CONNECTED;
377 BT_DBG("new socket %p", nsk);
384 static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr,
387 struct sockaddr_l2 *la = (struct sockaddr_l2 *) addr;
388 struct sock *sk = sock->sk;
389 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
391 BT_DBG("sock %p, sk %p", sock, sk);
393 if (peer && sk->sk_state != BT_CONNECTED &&
394 sk->sk_state != BT_CONNECT && sk->sk_state != BT_CONNECT2 &&
395 sk->sk_state != BT_CONFIG)
398 memset(la, 0, sizeof(struct sockaddr_l2));
399 addr->sa_family = AF_BLUETOOTH;
401 la->l2_psm = chan->psm;
404 bacpy(&la->l2_bdaddr, &chan->dst);
405 la->l2_cid = cpu_to_le16(chan->dcid);
406 la->l2_bdaddr_type = chan->dst_type;
408 bacpy(&la->l2_bdaddr, &chan->src);
409 la->l2_cid = cpu_to_le16(chan->scid);
410 la->l2_bdaddr_type = chan->src_type;
413 return sizeof(struct sockaddr_l2);
416 static int l2cap_get_mode(struct l2cap_chan *chan)
418 switch (chan->mode) {
419 case L2CAP_MODE_BASIC:
420 return BT_MODE_BASIC;
421 case L2CAP_MODE_ERTM:
423 case L2CAP_MODE_STREAMING:
424 return BT_MODE_STREAMING;
425 case L2CAP_MODE_LE_FLOWCTL:
426 return BT_MODE_LE_FLOWCTL;
427 case L2CAP_MODE_EXT_FLOWCTL:
428 return BT_MODE_EXT_FLOWCTL;
434 static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,
435 char __user *optval, int __user *optlen)
437 struct sock *sk = sock->sk;
438 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
439 struct l2cap_options opts;
440 struct l2cap_conninfo cinfo;
446 if (get_user(len, optlen))
453 /* LE sockets should use BT_SNDMTU/BT_RCVMTU, but since
454 * legacy ATT code depends on getsockopt for
455 * L2CAP_OPTIONS we need to let this pass.
457 if (bdaddr_type_is_le(chan->src_type) &&
458 chan->scid != L2CAP_CID_ATT) {
463 /* Only BR/EDR modes are supported here */
464 switch (chan->mode) {
465 case L2CAP_MODE_BASIC:
466 case L2CAP_MODE_ERTM:
467 case L2CAP_MODE_STREAMING:
477 memset(&opts, 0, sizeof(opts));
478 opts.imtu = chan->imtu;
479 opts.omtu = chan->omtu;
480 opts.flush_to = chan->flush_to;
481 opts.mode = chan->mode;
482 opts.fcs = chan->fcs;
483 opts.max_tx = chan->max_tx;
484 opts.txwin_size = chan->tx_win;
486 BT_DBG("mode 0x%2.2x", chan->mode);
488 len = min_t(unsigned int, len, sizeof(opts));
489 if (copy_to_user(optval, (char *) &opts, len))
495 switch (chan->sec_level) {
496 case BT_SECURITY_LOW:
499 case BT_SECURITY_MEDIUM:
500 opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT;
502 case BT_SECURITY_HIGH:
503 opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT |
506 case BT_SECURITY_FIPS:
507 opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT |
508 L2CAP_LM_SECURE | L2CAP_LM_FIPS;
515 if (test_bit(FLAG_ROLE_SWITCH, &chan->flags))
516 opt |= L2CAP_LM_MASTER;
518 if (test_bit(FLAG_FORCE_RELIABLE, &chan->flags))
519 opt |= L2CAP_LM_RELIABLE;
521 if (put_user(opt, (u32 __user *) optval))
527 if (sk->sk_state != BT_CONNECTED &&
528 !(sk->sk_state == BT_CONNECT2 &&
529 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) {
534 memset(&cinfo, 0, sizeof(cinfo));
535 cinfo.hci_handle = chan->conn->hcon->handle;
536 memcpy(cinfo.dev_class, chan->conn->hcon->dev_class, 3);
538 len = min_t(unsigned int, len, sizeof(cinfo));
539 if (copy_to_user(optval, (char *) &cinfo, len))
553 static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,
554 char __user *optval, int __user *optlen)
556 struct sock *sk = sock->sk;
557 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
558 struct bt_security sec;
561 int len, mode, err = 0;
565 if (level == SOL_L2CAP)
566 return l2cap_sock_getsockopt_old(sock, optname, optval, optlen);
568 if (level != SOL_BLUETOOTH)
571 if (get_user(len, optlen))
578 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
579 chan->chan_type != L2CAP_CHAN_FIXED &&
580 chan->chan_type != L2CAP_CHAN_RAW) {
585 memset(&sec, 0, sizeof(sec));
587 sec.level = chan->conn->hcon->sec_level;
589 if (sk->sk_state == BT_CONNECTED)
590 sec.key_size = chan->conn->hcon->enc_key_size;
592 sec.level = chan->sec_level;
595 len = min_t(unsigned int, len, sizeof(sec));
596 if (copy_to_user(optval, (char *) &sec, len))
602 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
607 if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags),
608 (u32 __user *) optval))
614 if (put_user(test_bit(FLAG_FLUSHABLE, &chan->flags),
615 (u32 __user *) optval))
621 if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM
622 && sk->sk_type != SOCK_RAW) {
627 pwr.force_active = test_bit(FLAG_FORCE_ACTIVE, &chan->flags);
629 len = min_t(unsigned int, len, sizeof(pwr));
630 if (copy_to_user(optval, (char *) &pwr, len))
635 case BT_CHANNEL_POLICY:
636 if (put_user(chan->chan_policy, (u32 __user *) optval))
641 if (!bdaddr_type_is_le(chan->src_type)) {
646 if (sk->sk_state != BT_CONNECTED) {
651 if (put_user(chan->omtu, (u16 __user *) optval))
656 if (!bdaddr_type_is_le(chan->src_type)) {
661 if (put_user(chan->imtu, (u16 __user *) optval))
666 if (sk->sk_state != BT_CONNECTED) {
671 phys = hci_conn_get_phy(chan->conn->hcon);
673 if (put_user(phys, (u32 __user *) optval))
683 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
688 mode = l2cap_get_mode(chan);
694 if (put_user(mode, (u8 __user *) optval))
707 static bool l2cap_valid_mtu(struct l2cap_chan *chan, u16 mtu)
709 switch (chan->scid) {
711 if (mtu < L2CAP_LE_MIN_MTU)
716 if (mtu < L2CAP_DEFAULT_MIN_MTU)
723 static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
724 sockptr_t optval, unsigned int optlen)
726 struct sock *sk = sock->sk;
727 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
728 struct l2cap_options opts;
738 if (bdaddr_type_is_le(chan->src_type)) {
743 if (sk->sk_state == BT_CONNECTED) {
748 opts.imtu = chan->imtu;
749 opts.omtu = chan->omtu;
750 opts.flush_to = chan->flush_to;
751 opts.mode = chan->mode;
752 opts.fcs = chan->fcs;
753 opts.max_tx = chan->max_tx;
754 opts.txwin_size = chan->tx_win;
756 len = min_t(unsigned int, sizeof(opts), optlen);
757 if (copy_from_sockptr(&opts, optval, len)) {
762 if (opts.txwin_size > L2CAP_DEFAULT_EXT_WINDOW) {
767 if (!l2cap_valid_mtu(chan, opts.imtu)) {
772 /* Only BR/EDR modes are supported here */
774 case L2CAP_MODE_BASIC:
775 clear_bit(CONF_STATE2_DEVICE, &chan->conf_state);
777 case L2CAP_MODE_ERTM:
778 case L2CAP_MODE_STREAMING:
790 chan->mode = opts.mode;
792 BT_DBG("mode 0x%2.2x", chan->mode);
794 chan->imtu = opts.imtu;
795 chan->omtu = opts.omtu;
796 chan->fcs = opts.fcs;
797 chan->max_tx = opts.max_tx;
798 chan->tx_win = opts.txwin_size;
799 chan->flush_to = opts.flush_to;
803 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
808 if (opt & L2CAP_LM_FIPS) {
813 if (opt & L2CAP_LM_AUTH)
814 chan->sec_level = BT_SECURITY_LOW;
815 if (opt & L2CAP_LM_ENCRYPT)
816 chan->sec_level = BT_SECURITY_MEDIUM;
817 if (opt & L2CAP_LM_SECURE)
818 chan->sec_level = BT_SECURITY_HIGH;
820 if (opt & L2CAP_LM_MASTER)
821 set_bit(FLAG_ROLE_SWITCH, &chan->flags);
823 clear_bit(FLAG_ROLE_SWITCH, &chan->flags);
825 if (opt & L2CAP_LM_RELIABLE)
826 set_bit(FLAG_FORCE_RELIABLE, &chan->flags);
828 clear_bit(FLAG_FORCE_RELIABLE, &chan->flags);
840 static int l2cap_set_mode(struct l2cap_chan *chan, u8 mode)
844 if (bdaddr_type_is_le(chan->src_type))
846 mode = L2CAP_MODE_BASIC;
847 clear_bit(CONF_STATE2_DEVICE, &chan->conf_state);
850 if (!disable_ertm || bdaddr_type_is_le(chan->src_type))
852 mode = L2CAP_MODE_ERTM;
854 case BT_MODE_STREAMING:
855 if (!disable_ertm || bdaddr_type_is_le(chan->src_type))
857 mode = L2CAP_MODE_STREAMING;
859 case BT_MODE_LE_FLOWCTL:
860 if (!bdaddr_type_is_le(chan->src_type))
862 mode = L2CAP_MODE_LE_FLOWCTL;
864 case BT_MODE_EXT_FLOWCTL:
865 /* TODO: Add support for ECRED PDUs to BR/EDR */
866 if (!bdaddr_type_is_le(chan->src_type))
868 mode = L2CAP_MODE_EXT_FLOWCTL;
879 static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
880 sockptr_t optval, unsigned int optlen)
882 struct sock *sk = sock->sk;
883 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
884 struct bt_security sec;
886 struct l2cap_conn *conn;
894 if (level == SOL_L2CAP)
895 return l2cap_sock_setsockopt_old(sock, optname, optval, optlen);
897 if (level != SOL_BLUETOOTH)
904 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
905 chan->chan_type != L2CAP_CHAN_FIXED &&
906 chan->chan_type != L2CAP_CHAN_RAW) {
911 sec.level = BT_SECURITY_LOW;
913 len = min_t(unsigned int, sizeof(sec), optlen);
914 if (copy_from_sockptr(&sec, optval, len)) {
919 if (sec.level < BT_SECURITY_LOW ||
920 sec.level > BT_SECURITY_FIPS) {
925 chan->sec_level = sec.level;
932 /* change security for LE channels */
933 if (chan->scid == L2CAP_CID_ATT) {
934 if (smp_conn_security(conn->hcon, sec.level)) {
939 set_bit(FLAG_PENDING_SECURITY, &chan->flags);
940 sk->sk_state = BT_CONFIG;
941 chan->state = BT_CONFIG;
943 /* or for ACL link */
944 } else if ((sk->sk_state == BT_CONNECT2 &&
945 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) ||
946 sk->sk_state == BT_CONNECTED) {
947 if (!l2cap_chan_check_security(chan, true))
948 set_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
950 sk->sk_state_change(sk);
957 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
962 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
968 set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
969 set_bit(FLAG_DEFER_SETUP, &chan->flags);
971 clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
972 clear_bit(FLAG_DEFER_SETUP, &chan->flags);
977 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
982 if (opt > BT_FLUSHABLE_ON) {
987 if (opt == BT_FLUSHABLE_OFF) {
989 /* proceed further only when we have l2cap_conn and
990 No Flush support in the LM */
991 if (!conn || !lmp_no_flush_capable(conn->hcon->hdev)) {
998 set_bit(FLAG_FLUSHABLE, &chan->flags);
1000 clear_bit(FLAG_FLUSHABLE, &chan->flags);
1004 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
1005 chan->chan_type != L2CAP_CHAN_RAW) {
1010 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
1012 len = min_t(unsigned int, sizeof(pwr), optlen);
1013 if (copy_from_sockptr(&pwr, optval, len)) {
1018 if (pwr.force_active)
1019 set_bit(FLAG_FORCE_ACTIVE, &chan->flags);
1021 clear_bit(FLAG_FORCE_ACTIVE, &chan->flags);
1024 case BT_CHANNEL_POLICY:
1025 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
1030 if (opt > BT_CHANNEL_POLICY_AMP_PREFERRED) {
1035 if (chan->mode != L2CAP_MODE_ERTM &&
1036 chan->mode != L2CAP_MODE_STREAMING) {
1041 chan->chan_policy = (u8) opt;
1043 if (sk->sk_state == BT_CONNECTED &&
1044 chan->move_role == L2CAP_MOVE_ROLE_NONE)
1045 l2cap_move_start(chan);
1050 if (!bdaddr_type_is_le(chan->src_type)) {
1055 /* Setting is not supported as it's the remote side that
1062 if (!bdaddr_type_is_le(chan->src_type)) {
1067 if (chan->mode == L2CAP_MODE_LE_FLOWCTL &&
1068 sk->sk_state == BT_CONNECTED) {
1073 if (copy_from_sockptr(&mtu, optval, sizeof(u16))) {
1078 if (chan->mode == L2CAP_MODE_EXT_FLOWCTL &&
1079 sk->sk_state == BT_CONNECTED)
1080 err = l2cap_chan_reconfigure(chan, mtu);
1087 if (!enable_ecred) {
1092 BT_DBG("sk->sk_state %u", sk->sk_state);
1094 if (sk->sk_state != BT_BOUND) {
1099 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
1104 if (copy_from_sockptr(&mode, optval, sizeof(u8))) {
1109 BT_DBG("mode %u", mode);
1111 err = l2cap_set_mode(chan, mode);
1115 BT_DBG("mode 0x%2.2x", chan->mode);
1128 static int l2cap_sock_sendmsg(struct socket *sock, struct msghdr *msg,
1131 struct sock *sk = sock->sk;
1132 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
1135 BT_DBG("sock %p, sk %p", sock, sk);
1137 err = sock_error(sk);
1141 if (msg->msg_flags & MSG_OOB)
1144 if (sk->sk_state != BT_CONNECTED)
1148 err = bt_sock_wait_ready(sk, msg->msg_flags);
1153 l2cap_chan_lock(chan);
1154 err = l2cap_chan_send(chan, msg, len);
1155 l2cap_chan_unlock(chan);
1160 static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg,
1161 size_t len, int flags)
1163 struct sock *sk = sock->sk;
1164 struct l2cap_pinfo *pi = l2cap_pi(sk);
1169 if (sk->sk_state == BT_CONNECT2 && test_bit(BT_SK_DEFER_SETUP,
1170 &bt_sk(sk)->flags)) {
1171 if (pi->chan->mode == L2CAP_MODE_EXT_FLOWCTL) {
1172 sk->sk_state = BT_CONNECTED;
1173 pi->chan->state = BT_CONNECTED;
1174 __l2cap_ecred_conn_rsp_defer(pi->chan);
1175 } else if (bdaddr_type_is_le(pi->chan->src_type)) {
1176 sk->sk_state = BT_CONNECTED;
1177 pi->chan->state = BT_CONNECTED;
1178 __l2cap_le_connect_rsp_defer(pi->chan);
1180 sk->sk_state = BT_CONFIG;
1181 pi->chan->state = BT_CONFIG;
1182 __l2cap_connect_rsp_defer(pi->chan);
1191 if (sock->type == SOCK_STREAM)
1192 err = bt_sock_stream_recvmsg(sock, msg, len, flags);
1194 err = bt_sock_recvmsg(sock, msg, len, flags);
1196 if (pi->chan->mode != L2CAP_MODE_ERTM)
1199 /* Attempt to put pending rx data in the socket buffer */
1203 if (!test_bit(CONN_LOCAL_BUSY, &pi->chan->conn_state))
1206 if (pi->rx_busy_skb) {
1207 if (!__sock_queue_rcv_skb(sk, pi->rx_busy_skb))
1208 pi->rx_busy_skb = NULL;
1213 /* Restore data flow when half of the receive buffer is
1214 * available. This avoids resending large numbers of
1217 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf >> 1)
1218 l2cap_chan_busy(pi->chan, 0);
1225 /* Kill socket (only if zapped and orphan)
1226 * Must be called on unlocked socket, with l2cap channel lock.
1228 static void l2cap_sock_kill(struct sock *sk)
1230 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket)
1233 BT_DBG("sk %p state %s", sk, state_to_string(sk->sk_state));
1235 /* Kill poor orphan */
1237 l2cap_chan_put(l2cap_pi(sk)->chan);
1238 sock_set_flag(sk, SOCK_DEAD);
1242 static int __l2cap_wait_ack(struct sock *sk, struct l2cap_chan *chan)
1244 DECLARE_WAITQUEUE(wait, current);
1246 int timeo = L2CAP_WAIT_ACK_POLL_PERIOD;
1247 /* Timeout to prevent infinite loop */
1248 unsigned long timeout = jiffies + L2CAP_WAIT_ACK_TIMEOUT;
1250 add_wait_queue(sk_sleep(sk), &wait);
1251 set_current_state(TASK_INTERRUPTIBLE);
1253 BT_DBG("Waiting for %d ACKs, timeout %04d ms",
1254 chan->unacked_frames, time_after(jiffies, timeout) ? 0 :
1255 jiffies_to_msecs(timeout - jiffies));
1258 timeo = L2CAP_WAIT_ACK_POLL_PERIOD;
1260 if (signal_pending(current)) {
1261 err = sock_intr_errno(timeo);
1266 timeo = schedule_timeout(timeo);
1268 set_current_state(TASK_INTERRUPTIBLE);
1270 err = sock_error(sk);
1274 if (time_after(jiffies, timeout)) {
1279 } while (chan->unacked_frames > 0 &&
1280 chan->state == BT_CONNECTED);
1282 set_current_state(TASK_RUNNING);
1283 remove_wait_queue(sk_sleep(sk), &wait);
1287 static int l2cap_sock_shutdown(struct socket *sock, int how)
1289 struct sock *sk = sock->sk;
1290 struct l2cap_chan *chan;
1291 struct l2cap_conn *conn;
1294 BT_DBG("sock %p, sk %p, how %d", sock, sk, how);
1296 /* 'how' parameter is mapped to sk_shutdown as follows:
1297 * SHUT_RD (0) --> RCV_SHUTDOWN (1)
1298 * SHUT_WR (1) --> SEND_SHUTDOWN (2)
1299 * SHUT_RDWR (2) --> SHUTDOWN_MASK (3)
1308 if ((sk->sk_shutdown & how) == how)
1309 goto shutdown_already;
1311 BT_DBG("Handling sock shutdown");
1313 /* prevent sk structure from being freed whilst unlocked */
1316 chan = l2cap_pi(sk)->chan;
1317 /* prevent chan structure from being freed whilst unlocked */
1318 l2cap_chan_hold(chan);
1320 BT_DBG("chan %p state %s", chan, state_to_string(chan->state));
1322 if (chan->mode == L2CAP_MODE_ERTM &&
1323 chan->unacked_frames > 0 &&
1324 chan->state == BT_CONNECTED) {
1325 err = __l2cap_wait_ack(sk, chan);
1327 /* After waiting for ACKs, check whether shutdown
1328 * has already been actioned to close the L2CAP
1329 * link such as by l2cap_disconnection_req().
1331 if ((sk->sk_shutdown & how) == how)
1332 goto shutdown_matched;
1335 /* Try setting the RCV_SHUTDOWN bit, return early if SEND_SHUTDOWN
1338 if ((how & RCV_SHUTDOWN) && !(sk->sk_shutdown & RCV_SHUTDOWN)) {
1339 sk->sk_shutdown |= RCV_SHUTDOWN;
1340 if ((sk->sk_shutdown & how) == how)
1341 goto shutdown_matched;
1344 sk->sk_shutdown |= SEND_SHUTDOWN;
1347 l2cap_chan_lock(chan);
1350 /* prevent conn structure from being freed */
1351 l2cap_conn_get(conn);
1352 l2cap_chan_unlock(chan);
1355 /* mutex lock must be taken before l2cap_chan_lock() */
1356 mutex_lock(&conn->chan_lock);
1358 l2cap_chan_lock(chan);
1359 l2cap_chan_close(chan, 0);
1360 l2cap_chan_unlock(chan);
1363 mutex_unlock(&conn->chan_lock);
1364 l2cap_conn_put(conn);
1369 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
1370 !(current->flags & PF_EXITING))
1371 err = bt_sock_wait_state(sk, BT_CLOSED,
1375 l2cap_chan_put(chan);
1379 if (!err && sk->sk_err)
1384 BT_DBG("Sock shutdown complete err: %d", err);
1389 static int l2cap_sock_release(struct socket *sock)
1391 struct sock *sk = sock->sk;
1393 struct l2cap_chan *chan;
1395 BT_DBG("sock %p, sk %p", sock, sk);
1400 l2cap_sock_cleanup_listen(sk);
1401 bt_sock_unlink(&l2cap_sk_list, sk);
1403 err = l2cap_sock_shutdown(sock, SHUT_RDWR);
1404 chan = l2cap_pi(sk)->chan;
1406 l2cap_chan_hold(chan);
1407 l2cap_chan_lock(chan);
1410 l2cap_sock_kill(sk);
1412 l2cap_chan_unlock(chan);
1413 l2cap_chan_put(chan);
1418 static void l2cap_sock_cleanup_listen(struct sock *parent)
1422 BT_DBG("parent %p state %s", parent,
1423 state_to_string(parent->sk_state));
1425 /* Close not yet accepted channels */
1426 while ((sk = bt_accept_dequeue(parent, NULL))) {
1427 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
1429 BT_DBG("child chan %p state %s", chan,
1430 state_to_string(chan->state));
1432 l2cap_chan_hold(chan);
1433 l2cap_chan_lock(chan);
1435 __clear_chan_timer(chan);
1436 l2cap_chan_close(chan, ECONNRESET);
1437 l2cap_sock_kill(sk);
1439 l2cap_chan_unlock(chan);
1440 l2cap_chan_put(chan);
1444 static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan)
1446 struct sock *sk, *parent = chan->data;
1450 /* Check for backlog size */
1451 if (sk_acceptq_is_full(parent)) {
1452 BT_DBG("backlog full %d", parent->sk_ack_backlog);
1453 release_sock(parent);
1457 sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP,
1460 release_sock(parent);
1464 bt_sock_reclassify_lock(sk, BTPROTO_L2CAP);
1466 l2cap_sock_init(sk, parent);
1468 bt_accept_enqueue(parent, sk, false);
1470 release_sock(parent);
1472 return l2cap_pi(sk)->chan;
1475 static int l2cap_sock_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
1477 struct sock *sk = chan->data;
1482 if (l2cap_pi(sk)->rx_busy_skb) {
1487 if (chan->mode != L2CAP_MODE_ERTM &&
1488 chan->mode != L2CAP_MODE_STREAMING) {
1489 /* Even if no filter is attached, we could potentially
1490 * get errors from security modules, etc.
1492 err = sk_filter(sk, skb);
1497 err = __sock_queue_rcv_skb(sk, skb);
1499 /* For ERTM, handle one skb that doesn't fit into the recv
1500 * buffer. This is important to do because the data frames
1501 * have already been acked, so the skb cannot be discarded.
1503 * Notify the l2cap core that the buffer is full, so the
1504 * LOCAL_BUSY state is entered and no more frames are
1505 * acked and reassembled until there is buffer space
1508 if (err < 0 && chan->mode == L2CAP_MODE_ERTM) {
1509 l2cap_pi(sk)->rx_busy_skb = skb;
1510 l2cap_chan_busy(chan, 1);
1520 static void l2cap_sock_close_cb(struct l2cap_chan *chan)
1522 struct sock *sk = chan->data;
1527 l2cap_sock_kill(sk);
1530 static void l2cap_sock_teardown_cb(struct l2cap_chan *chan, int err)
1532 struct sock *sk = chan->data;
1533 struct sock *parent;
1538 BT_DBG("chan %p state %s", chan, state_to_string(chan->state));
1540 /* This callback can be called both for server (BT_LISTEN)
1541 * sockets as well as "normal" ones. To avoid lockdep warnings
1542 * with child socket locking (through l2cap_sock_cleanup_listen)
1543 * we need separation into separate nesting levels. The simplest
1544 * way to accomplish this is to inherit the nesting level used
1547 lock_sock_nested(sk, atomic_read(&chan->nesting));
1549 parent = bt_sk(sk)->parent;
1551 switch (chan->state) {
1557 l2cap_sock_cleanup_listen(sk);
1558 sk->sk_state = BT_CLOSED;
1559 chan->state = BT_CLOSED;
1563 sk->sk_state = BT_CLOSED;
1564 chan->state = BT_CLOSED;
1569 bt_accept_unlink(sk);
1570 parent->sk_data_ready(parent);
1572 sk->sk_state_change(sk);
1579 /* Only zap after cleanup to avoid use after free race */
1580 sock_set_flag(sk, SOCK_ZAPPED);
1584 static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state,
1587 struct sock *sk = chan->data;
1589 sk->sk_state = state;
1595 static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan,
1596 unsigned long hdr_len,
1597 unsigned long len, int nb)
1599 struct sock *sk = chan->data;
1600 struct sk_buff *skb;
1603 l2cap_chan_unlock(chan);
1604 skb = bt_skb_send_alloc(sk, hdr_len + len, nb, &err);
1605 l2cap_chan_lock(chan);
1608 return ERR_PTR(err);
1610 /* Channel lock is released before requesting new skb and then
1611 * reacquired thus we need to recheck channel state.
1613 if (chan->state != BT_CONNECTED) {
1615 return ERR_PTR(-ENOTCONN);
1618 skb->priority = sk->sk_priority;
1620 bt_cb(skb)->l2cap.chan = chan;
1625 static void l2cap_sock_ready_cb(struct l2cap_chan *chan)
1627 struct sock *sk = chan->data;
1628 struct sock *parent;
1632 parent = bt_sk(sk)->parent;
1634 BT_DBG("sk %p, parent %p", sk, parent);
1636 sk->sk_state = BT_CONNECTED;
1637 sk->sk_state_change(sk);
1640 parent->sk_data_ready(parent);
1645 static void l2cap_sock_defer_cb(struct l2cap_chan *chan)
1647 struct sock *parent, *sk = chan->data;
1651 parent = bt_sk(sk)->parent;
1653 parent->sk_data_ready(parent);
1658 static void l2cap_sock_resume_cb(struct l2cap_chan *chan)
1660 struct sock *sk = chan->data;
1662 if (test_and_clear_bit(FLAG_PENDING_SECURITY, &chan->flags)) {
1663 sk->sk_state = BT_CONNECTED;
1664 chan->state = BT_CONNECTED;
1667 clear_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
1668 sk->sk_state_change(sk);
1671 static void l2cap_sock_set_shutdown_cb(struct l2cap_chan *chan)
1673 struct sock *sk = chan->data;
1676 sk->sk_shutdown = SHUTDOWN_MASK;
1680 static long l2cap_sock_get_sndtimeo_cb(struct l2cap_chan *chan)
1682 struct sock *sk = chan->data;
1684 return sk->sk_sndtimeo;
1687 static struct pid *l2cap_sock_get_peer_pid_cb(struct l2cap_chan *chan)
1689 struct sock *sk = chan->data;
1691 return sk->sk_peer_pid;
1694 static void l2cap_sock_suspend_cb(struct l2cap_chan *chan)
1696 struct sock *sk = chan->data;
1698 set_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
1699 sk->sk_state_change(sk);
1702 static int l2cap_sock_filter(struct l2cap_chan *chan, struct sk_buff *skb)
1704 struct sock *sk = chan->data;
1706 switch (chan->mode) {
1707 case L2CAP_MODE_ERTM:
1708 case L2CAP_MODE_STREAMING:
1709 return sk_filter(sk, skb);
1715 static const struct l2cap_ops l2cap_chan_ops = {
1716 .name = "L2CAP Socket Interface",
1717 .new_connection = l2cap_sock_new_connection_cb,
1718 .recv = l2cap_sock_recv_cb,
1719 .close = l2cap_sock_close_cb,
1720 .teardown = l2cap_sock_teardown_cb,
1721 .state_change = l2cap_sock_state_change_cb,
1722 .ready = l2cap_sock_ready_cb,
1723 .defer = l2cap_sock_defer_cb,
1724 .resume = l2cap_sock_resume_cb,
1725 .suspend = l2cap_sock_suspend_cb,
1726 .set_shutdown = l2cap_sock_set_shutdown_cb,
1727 .get_sndtimeo = l2cap_sock_get_sndtimeo_cb,
1728 .get_peer_pid = l2cap_sock_get_peer_pid_cb,
1729 .alloc_skb = l2cap_sock_alloc_skb_cb,
1730 .filter = l2cap_sock_filter,
1733 static void l2cap_sock_destruct(struct sock *sk)
1735 BT_DBG("sk %p", sk);
1737 if (l2cap_pi(sk)->chan) {
1738 l2cap_pi(sk)->chan->data = NULL;
1739 l2cap_chan_put(l2cap_pi(sk)->chan);
1742 if (l2cap_pi(sk)->rx_busy_skb) {
1743 kfree_skb(l2cap_pi(sk)->rx_busy_skb);
1744 l2cap_pi(sk)->rx_busy_skb = NULL;
1747 skb_queue_purge(&sk->sk_receive_queue);
1748 skb_queue_purge(&sk->sk_write_queue);
1751 static void l2cap_skb_msg_name(struct sk_buff *skb, void *msg_name,
1754 DECLARE_SOCKADDR(struct sockaddr_l2 *, la, msg_name);
1756 memset(la, 0, sizeof(struct sockaddr_l2));
1757 la->l2_family = AF_BLUETOOTH;
1758 la->l2_psm = bt_cb(skb)->l2cap.psm;
1759 bacpy(&la->l2_bdaddr, &bt_cb(skb)->l2cap.bdaddr);
1761 *msg_namelen = sizeof(struct sockaddr_l2);
1764 static void l2cap_sock_init(struct sock *sk, struct sock *parent)
1766 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
1768 BT_DBG("sk %p", sk);
1771 struct l2cap_chan *pchan = l2cap_pi(parent)->chan;
1773 sk->sk_type = parent->sk_type;
1774 bt_sk(sk)->flags = bt_sk(parent)->flags;
1776 chan->chan_type = pchan->chan_type;
1777 chan->imtu = pchan->imtu;
1778 chan->omtu = pchan->omtu;
1779 chan->conf_state = pchan->conf_state;
1780 chan->mode = pchan->mode;
1781 chan->fcs = pchan->fcs;
1782 chan->max_tx = pchan->max_tx;
1783 chan->tx_win = pchan->tx_win;
1784 chan->tx_win_max = pchan->tx_win_max;
1785 chan->sec_level = pchan->sec_level;
1786 chan->flags = pchan->flags;
1787 chan->tx_credits = pchan->tx_credits;
1788 chan->rx_credits = pchan->rx_credits;
1790 if (chan->chan_type == L2CAP_CHAN_FIXED) {
1791 chan->scid = pchan->scid;
1792 chan->dcid = pchan->scid;
1795 security_sk_clone(parent, sk);
1797 switch (sk->sk_type) {
1799 chan->chan_type = L2CAP_CHAN_RAW;
1802 chan->chan_type = L2CAP_CHAN_CONN_LESS;
1803 bt_sk(sk)->skb_msg_name = l2cap_skb_msg_name;
1805 case SOCK_SEQPACKET:
1807 chan->chan_type = L2CAP_CHAN_CONN_ORIENTED;
1811 chan->imtu = L2CAP_DEFAULT_MTU;
1813 if (!disable_ertm && sk->sk_type == SOCK_STREAM) {
1814 chan->mode = L2CAP_MODE_ERTM;
1815 set_bit(CONF_STATE2_DEVICE, &chan->conf_state);
1817 chan->mode = L2CAP_MODE_BASIC;
1820 l2cap_chan_set_defaults(chan);
1823 /* Default config options */
1824 chan->flush_to = L2CAP_DEFAULT_FLUSH_TO;
1827 chan->ops = &l2cap_chan_ops;
1830 static struct proto l2cap_proto = {
1832 .owner = THIS_MODULE,
1833 .obj_size = sizeof(struct l2cap_pinfo)
1836 static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
1837 int proto, gfp_t prio, int kern)
1840 struct l2cap_chan *chan;
1842 sk = bt_sock_alloc(net, sock, &l2cap_proto, proto, prio, kern);
1846 sk->sk_destruct = l2cap_sock_destruct;
1847 sk->sk_sndtimeo = L2CAP_CONN_TIMEOUT;
1849 chan = l2cap_chan_create();
1855 l2cap_chan_hold(chan);
1857 l2cap_pi(sk)->chan = chan;
1862 static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
1867 BT_DBG("sock %p", sock);
1869 sock->state = SS_UNCONNECTED;
1871 if (sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM &&
1872 sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
1873 return -ESOCKTNOSUPPORT;
1875 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
1878 sock->ops = &l2cap_sock_ops;
1880 sk = l2cap_sock_alloc(net, sock, protocol, GFP_ATOMIC, kern);
1884 l2cap_sock_init(sk, NULL);
1885 bt_sock_link(&l2cap_sk_list, sk);
1889 static const struct proto_ops l2cap_sock_ops = {
1890 .family = PF_BLUETOOTH,
1891 .owner = THIS_MODULE,
1892 .release = l2cap_sock_release,
1893 .bind = l2cap_sock_bind,
1894 .connect = l2cap_sock_connect,
1895 .listen = l2cap_sock_listen,
1896 .accept = l2cap_sock_accept,
1897 .getname = l2cap_sock_getname,
1898 .sendmsg = l2cap_sock_sendmsg,
1899 .recvmsg = l2cap_sock_recvmsg,
1900 .poll = bt_sock_poll,
1901 .ioctl = bt_sock_ioctl,
1902 .gettstamp = sock_gettstamp,
1903 .mmap = sock_no_mmap,
1904 .socketpair = sock_no_socketpair,
1905 .shutdown = l2cap_sock_shutdown,
1906 .setsockopt = l2cap_sock_setsockopt,
1907 .getsockopt = l2cap_sock_getsockopt
1910 static const struct net_proto_family l2cap_sock_family_ops = {
1911 .family = PF_BLUETOOTH,
1912 .owner = THIS_MODULE,
1913 .create = l2cap_sock_create,
1916 int __init l2cap_init_sockets(void)
1920 BUILD_BUG_ON(sizeof(struct sockaddr_l2) > sizeof(struct sockaddr));
1922 err = proto_register(&l2cap_proto, 0);
1926 err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops);
1928 BT_ERR("L2CAP socket registration failed");
1932 err = bt_procfs_init(&init_net, "l2cap", &l2cap_sk_list,
1935 BT_ERR("Failed to create L2CAP proc file");
1936 bt_sock_unregister(BTPROTO_L2CAP);
1940 BT_INFO("L2CAP socket layer initialized");
1945 proto_unregister(&l2cap_proto);
1949 void l2cap_cleanup_sockets(void)
1951 bt_procfs_cleanup(&init_net, "l2cap");
1952 bt_sock_unregister(BTPROTO_L2CAP);
1953 proto_unregister(&l2cap_proto);