1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2011 Intel Corporation. All rights reserved.
6 #define pr_fmt(fmt) "llcp: %s: " fmt, __func__
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/nfc.h>
12 #include <linux/sched/signal.h>
17 static int sock_wait_state(struct sock *sk, int state, unsigned long timeo)
19 DECLARE_WAITQUEUE(wait, current);
22 pr_debug("sk %p", sk);
24 add_wait_queue(sk_sleep(sk), &wait);
25 set_current_state(TASK_INTERRUPTIBLE);
27 while (sk->sk_state != state) {
33 if (signal_pending(current)) {
34 err = sock_intr_errno(timeo);
39 timeo = schedule_timeout(timeo);
41 set_current_state(TASK_INTERRUPTIBLE);
48 __set_current_state(TASK_RUNNING);
49 remove_wait_queue(sk_sleep(sk), &wait);
53 static struct proto llcp_sock_proto = {
56 .obj_size = sizeof(struct nfc_llcp_sock),
59 static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
61 struct sock *sk = sock->sk;
62 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
63 struct nfc_llcp_local *local;
65 struct sockaddr_nfc_llcp llcp_addr;
68 if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
69 addr->sa_family != AF_NFC)
72 pr_debug("sk %p addr %p family %d\n", sk, addr, addr->sa_family);
74 memset(&llcp_addr, 0, sizeof(llcp_addr));
75 len = min_t(unsigned int, sizeof(llcp_addr), alen);
76 memcpy(&llcp_addr, addr, len);
78 /* This is going to be a listening socket, dsap must be 0 */
79 if (llcp_addr.dsap != 0)
84 if (sk->sk_state != LLCP_CLOSED) {
89 dev = nfc_get_device(llcp_addr.dev_idx);
95 local = nfc_llcp_find_local(dev);
101 llcp_sock->dev = dev;
102 llcp_sock->local = nfc_llcp_local_get(local);
103 llcp_sock->nfc_protocol = llcp_addr.nfc_protocol;
104 llcp_sock->service_name_len = min_t(unsigned int,
105 llcp_addr.service_name_len,
106 NFC_LLCP_MAX_SERVICE_NAME);
107 llcp_sock->service_name = kmemdup(llcp_addr.service_name,
108 llcp_sock->service_name_len,
110 if (!llcp_sock->service_name) {
111 nfc_llcp_local_put(llcp_sock->local);
112 llcp_sock->local = NULL;
113 llcp_sock->dev = NULL;
117 llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock);
118 if (llcp_sock->ssap == LLCP_SAP_MAX) {
119 nfc_llcp_local_put(llcp_sock->local);
120 llcp_sock->local = NULL;
121 kfree(llcp_sock->service_name);
122 llcp_sock->service_name = NULL;
123 llcp_sock->dev = NULL;
128 llcp_sock->reserved_ssap = llcp_sock->ssap;
130 nfc_llcp_sock_link(&local->sockets, sk);
132 pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap);
134 sk->sk_state = LLCP_BOUND;
144 static int llcp_raw_sock_bind(struct socket *sock, struct sockaddr *addr,
147 struct sock *sk = sock->sk;
148 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
149 struct nfc_llcp_local *local;
151 struct sockaddr_nfc_llcp llcp_addr;
154 if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
155 addr->sa_family != AF_NFC)
158 pr_debug("sk %p addr %p family %d\n", sk, addr, addr->sa_family);
160 memset(&llcp_addr, 0, sizeof(llcp_addr));
161 len = min_t(unsigned int, sizeof(llcp_addr), alen);
162 memcpy(&llcp_addr, addr, len);
166 if (sk->sk_state != LLCP_CLOSED) {
171 dev = nfc_get_device(llcp_addr.dev_idx);
177 local = nfc_llcp_find_local(dev);
183 llcp_sock->dev = dev;
184 llcp_sock->local = nfc_llcp_local_get(local);
185 llcp_sock->nfc_protocol = llcp_addr.nfc_protocol;
187 nfc_llcp_sock_link(&local->raw_sockets, sk);
189 sk->sk_state = LLCP_BOUND;
199 static int llcp_sock_listen(struct socket *sock, int backlog)
201 struct sock *sk = sock->sk;
204 pr_debug("sk %p backlog %d\n", sk, backlog);
208 if ((sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM) ||
209 sk->sk_state != LLCP_BOUND) {
214 sk->sk_max_ack_backlog = backlog;
215 sk->sk_ack_backlog = 0;
217 pr_debug("Socket listening\n");
218 sk->sk_state = LLCP_LISTEN;
226 static int nfc_llcp_setsockopt(struct socket *sock, int level, int optname,
227 sockptr_t optval, unsigned int optlen)
229 struct sock *sk = sock->sk;
230 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
234 pr_debug("%p optname %d\n", sk, optname);
236 if (level != SOL_NFC)
243 if (sk->sk_state == LLCP_CONNECTED ||
244 sk->sk_state == LLCP_BOUND ||
245 sk->sk_state == LLCP_LISTEN) {
250 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
255 if (opt > LLCP_MAX_RW) {
260 llcp_sock->rw = (u8) opt;
265 if (sk->sk_state == LLCP_CONNECTED ||
266 sk->sk_state == LLCP_BOUND ||
267 sk->sk_state == LLCP_LISTEN) {
272 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
277 if (opt > LLCP_MAX_MIUX) {
282 llcp_sock->miux = cpu_to_be16((u16) opt);
293 pr_debug("%p rw %d miux %d\n", llcp_sock,
294 llcp_sock->rw, llcp_sock->miux);
299 static int nfc_llcp_getsockopt(struct socket *sock, int level, int optname,
300 char __user *optval, int __user *optlen)
302 struct nfc_llcp_local *local;
303 struct sock *sk = sock->sk;
304 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
306 u16 miux, remote_miu;
309 pr_debug("%p optname %d\n", sk, optname);
311 if (level != SOL_NFC)
314 if (get_user(len, optlen))
317 local = llcp_sock->local;
321 len = min_t(u32, len, sizeof(u32));
327 rw = llcp_sock->rw > LLCP_MAX_RW ? local->rw : llcp_sock->rw;
328 if (put_user(rw, (u32 __user *) optval))
334 miux = be16_to_cpu(llcp_sock->miux) > LLCP_MAX_MIUX ?
335 be16_to_cpu(local->miux) : be16_to_cpu(llcp_sock->miux);
337 if (put_user(miux, (u32 __user *) optval))
342 case NFC_LLCP_REMOTE_MIU:
343 remote_miu = llcp_sock->remote_miu > LLCP_MAX_MIU ?
344 local->remote_miu : llcp_sock->remote_miu;
346 if (put_user(remote_miu, (u32 __user *) optval))
351 case NFC_LLCP_REMOTE_LTO:
352 if (put_user(local->remote_lto / 10, (u32 __user *) optval))
357 case NFC_LLCP_REMOTE_RW:
358 if (put_user(llcp_sock->remote_rw, (u32 __user *) optval))
370 if (put_user(len, optlen))
376 void nfc_llcp_accept_unlink(struct sock *sk)
378 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
380 pr_debug("state %d\n", sk->sk_state);
382 list_del_init(&llcp_sock->accept_queue);
383 sk_acceptq_removed(llcp_sock->parent);
384 llcp_sock->parent = NULL;
389 void nfc_llcp_accept_enqueue(struct sock *parent, struct sock *sk)
391 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
392 struct nfc_llcp_sock *llcp_sock_parent = nfc_llcp_sock(parent);
394 /* Lock will be free from unlink */
397 list_add_tail(&llcp_sock->accept_queue,
398 &llcp_sock_parent->accept_queue);
399 llcp_sock->parent = parent;
400 sk_acceptq_added(parent);
403 struct sock *nfc_llcp_accept_dequeue(struct sock *parent,
404 struct socket *newsock)
406 struct nfc_llcp_sock *lsk, *n, *llcp_parent;
409 llcp_parent = nfc_llcp_sock(parent);
411 list_for_each_entry_safe(lsk, n, &llcp_parent->accept_queue,
416 if (sk->sk_state == LLCP_CLOSED) {
418 nfc_llcp_accept_unlink(sk);
422 if (sk->sk_state == LLCP_CONNECTED || !newsock) {
423 list_del_init(&lsk->accept_queue);
427 sock_graft(sk, newsock);
431 pr_debug("Returning sk state %d\n", sk->sk_state);
433 sk_acceptq_removed(parent);
444 static int llcp_sock_accept(struct socket *sock, struct socket *newsock,
445 int flags, bool kern)
447 DECLARE_WAITQUEUE(wait, current);
448 struct sock *sk = sock->sk, *new_sk;
452 pr_debug("parent %p\n", sk);
454 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
456 if (sk->sk_state != LLCP_LISTEN) {
461 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
463 /* Wait for an incoming connection. */
464 add_wait_queue_exclusive(sk_sleep(sk), &wait);
465 while (!(new_sk = nfc_llcp_accept_dequeue(sk, newsock))) {
466 set_current_state(TASK_INTERRUPTIBLE);
473 if (signal_pending(current)) {
474 ret = sock_intr_errno(timeo);
479 timeo = schedule_timeout(timeo);
480 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
482 __set_current_state(TASK_RUNNING);
483 remove_wait_queue(sk_sleep(sk), &wait);
488 newsock->state = SS_CONNECTED;
490 pr_debug("new socket %p\n", new_sk);
498 static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr,
501 struct sock *sk = sock->sk;
502 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
503 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, llcp_addr, uaddr);
505 if (llcp_sock == NULL || llcp_sock->dev == NULL)
508 pr_debug("%p %d %d %d\n", sk, llcp_sock->target_idx,
509 llcp_sock->dsap, llcp_sock->ssap);
511 memset(llcp_addr, 0, sizeof(*llcp_addr));
514 if (!llcp_sock->dev) {
518 llcp_addr->sa_family = AF_NFC;
519 llcp_addr->dev_idx = llcp_sock->dev->idx;
520 llcp_addr->target_idx = llcp_sock->target_idx;
521 llcp_addr->nfc_protocol = llcp_sock->nfc_protocol;
522 llcp_addr->dsap = llcp_sock->dsap;
523 llcp_addr->ssap = llcp_sock->ssap;
524 llcp_addr->service_name_len = llcp_sock->service_name_len;
525 memcpy(llcp_addr->service_name, llcp_sock->service_name,
526 llcp_addr->service_name_len);
529 return sizeof(struct sockaddr_nfc_llcp);
532 static inline __poll_t llcp_accept_poll(struct sock *parent)
534 struct nfc_llcp_sock *llcp_sock, *parent_sock;
537 parent_sock = nfc_llcp_sock(parent);
539 list_for_each_entry(llcp_sock, &parent_sock->accept_queue,
543 if (sk->sk_state == LLCP_CONNECTED)
544 return EPOLLIN | EPOLLRDNORM;
550 static __poll_t llcp_sock_poll(struct file *file, struct socket *sock,
553 struct sock *sk = sock->sk;
556 pr_debug("%p\n", sk);
558 sock_poll_wait(file, sock, wait);
560 if (sk->sk_state == LLCP_LISTEN)
561 return llcp_accept_poll(sk);
563 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
565 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
567 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
568 mask |= EPOLLIN | EPOLLRDNORM;
570 if (sk->sk_state == LLCP_CLOSED)
573 if (sk->sk_shutdown & RCV_SHUTDOWN)
574 mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM;
576 if (sk->sk_shutdown == SHUTDOWN_MASK)
579 if (sock_writeable(sk) && sk->sk_state == LLCP_CONNECTED)
580 mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND;
582 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
584 pr_debug("mask 0x%x\n", mask);
589 static int llcp_sock_release(struct socket *sock)
591 struct sock *sk = sock->sk;
592 struct nfc_llcp_local *local;
593 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
599 pr_debug("%p\n", sk);
601 local = llcp_sock->local;
610 if (sk->sk_state == LLCP_CONNECTED)
611 nfc_llcp_send_disconnect(llcp_sock);
613 if (sk->sk_state == LLCP_LISTEN) {
614 struct nfc_llcp_sock *lsk, *n;
615 struct sock *accept_sk;
617 list_for_each_entry_safe(lsk, n, &llcp_sock->accept_queue,
619 accept_sk = &lsk->sk;
620 lock_sock(accept_sk);
622 nfc_llcp_send_disconnect(lsk);
623 nfc_llcp_accept_unlink(accept_sk);
625 release_sock(accept_sk);
629 if (llcp_sock->reserved_ssap < LLCP_SAP_MAX)
630 nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
634 /* Keep this sock alive and therefore do not remove it from the sockets
635 * list until the DISC PDU has been actually sent. Otherwise we would
636 * reply with DM PDUs before sending the DISC one.
638 if (sk->sk_state == LLCP_DISCONNECTING)
641 if (sock->type == SOCK_RAW)
642 nfc_llcp_sock_unlink(&local->raw_sockets, sk);
644 nfc_llcp_sock_unlink(&local->sockets, sk);
653 static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
656 struct sock *sk = sock->sk;
657 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
658 struct sockaddr_nfc_llcp *addr = (struct sockaddr_nfc_llcp *)_addr;
660 struct nfc_llcp_local *local;
663 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
665 if (!addr || len < sizeof(*addr) || addr->sa_family != AF_NFC)
668 if (addr->service_name_len == 0 && addr->dsap == 0)
671 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
672 addr->target_idx, addr->nfc_protocol);
676 if (sk->sk_state == LLCP_CONNECTED) {
680 if (sk->sk_state == LLCP_CONNECTING) {
685 dev = nfc_get_device(addr->dev_idx);
691 local = nfc_llcp_find_local(dev);
697 device_lock(&dev->dev);
698 if (dev->dep_link_up == false) {
700 device_unlock(&dev->dev);
703 device_unlock(&dev->dev);
705 if (local->rf_mode == NFC_RF_INITIATOR &&
706 addr->target_idx != local->target_idx) {
711 llcp_sock->dev = dev;
712 llcp_sock->local = nfc_llcp_local_get(local);
713 llcp_sock->ssap = nfc_llcp_get_local_ssap(local);
714 if (llcp_sock->ssap == LLCP_SAP_MAX) {
715 nfc_llcp_local_put(llcp_sock->local);
716 llcp_sock->local = NULL;
721 llcp_sock->reserved_ssap = llcp_sock->ssap;
723 if (addr->service_name_len == 0)
724 llcp_sock->dsap = addr->dsap;
726 llcp_sock->dsap = LLCP_SAP_SDP;
727 llcp_sock->nfc_protocol = addr->nfc_protocol;
728 llcp_sock->service_name_len = min_t(unsigned int,
729 addr->service_name_len,
730 NFC_LLCP_MAX_SERVICE_NAME);
731 llcp_sock->service_name = kmemdup(addr->service_name,
732 llcp_sock->service_name_len,
734 if (!llcp_sock->service_name) {
736 goto sock_llcp_release;
739 nfc_llcp_sock_link(&local->connecting_sockets, sk);
741 ret = nfc_llcp_send_connect(llcp_sock);
745 sk->sk_state = LLCP_CONNECTING;
747 ret = sock_wait_state(sk, LLCP_CONNECTED,
748 sock_sndtimeo(sk, flags & O_NONBLOCK));
749 if (ret && ret != -EINPROGRESS)
757 nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
758 kfree(llcp_sock->service_name);
759 llcp_sock->service_name = NULL;
762 nfc_llcp_put_ssap(local, llcp_sock->ssap);
763 nfc_llcp_local_put(llcp_sock->local);
764 llcp_sock->local = NULL;
774 static int llcp_sock_sendmsg(struct socket *sock, struct msghdr *msg,
777 struct sock *sk = sock->sk;
778 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
781 pr_debug("sock %p sk %p", sock, sk);
783 ret = sock_error(sk);
787 if (msg->msg_flags & MSG_OOB)
792 if (sk->sk_type == SOCK_DGRAM) {
793 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, addr,
796 if (msg->msg_namelen < sizeof(*addr)) {
803 return nfc_llcp_send_ui_frame(llcp_sock, addr->dsap, addr->ssap,
807 if (sk->sk_state != LLCP_CONNECTED) {
814 return nfc_llcp_send_i_frame(llcp_sock, msg, len);
817 static int llcp_sock_recvmsg(struct socket *sock, struct msghdr *msg,
818 size_t len, int flags)
820 int noblock = flags & MSG_DONTWAIT;
821 struct sock *sk = sock->sk;
822 unsigned int copied, rlen;
823 struct sk_buff *skb, *cskb;
826 pr_debug("%p %zu\n", sk, len);
830 if (sk->sk_state == LLCP_CLOSED &&
831 skb_queue_empty(&sk->sk_receive_queue)) {
838 if (flags & (MSG_OOB))
841 skb = skb_recv_datagram(sk, flags, noblock, &err);
843 pr_err("Recv datagram failed state %d %d %d",
844 sk->sk_state, err, sock_error(sk));
846 if (sk->sk_shutdown & RCV_SHUTDOWN)
852 rlen = skb->len; /* real length of skb */
853 copied = min_t(unsigned int, rlen, len);
856 if (skb_copy_datagram_msg(cskb, 0, msg, copied)) {
857 if (!(flags & MSG_PEEK))
858 skb_queue_head(&sk->sk_receive_queue, skb);
862 sock_recv_timestamp(msg, sk, skb);
864 if (sk->sk_type == SOCK_DGRAM && msg->msg_name) {
865 struct nfc_llcp_ui_cb *ui_cb = nfc_llcp_ui_skb_cb(skb);
866 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, sockaddr,
869 msg->msg_namelen = sizeof(struct sockaddr_nfc_llcp);
871 pr_debug("Datagram socket %d %d\n", ui_cb->dsap, ui_cb->ssap);
873 memset(sockaddr, 0, sizeof(*sockaddr));
874 sockaddr->sa_family = AF_NFC;
875 sockaddr->nfc_protocol = NFC_PROTO_NFC_DEP;
876 sockaddr->dsap = ui_cb->dsap;
877 sockaddr->ssap = ui_cb->ssap;
880 /* Mark read part of skb as used */
881 if (!(flags & MSG_PEEK)) {
883 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
884 if (sk->sk_type == SOCK_STREAM ||
885 sk->sk_type == SOCK_DGRAM ||
886 sk->sk_type == SOCK_RAW) {
887 skb_pull(skb, copied);
889 skb_queue_head(&sk->sk_receive_queue, skb);
897 /* XXX Queue backlogged skbs */
900 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
901 if (sk->sk_type == SOCK_SEQPACKET && (flags & MSG_TRUNC))
907 static const struct proto_ops llcp_sock_ops = {
909 .owner = THIS_MODULE,
910 .bind = llcp_sock_bind,
911 .connect = llcp_sock_connect,
912 .release = llcp_sock_release,
913 .socketpair = sock_no_socketpair,
914 .accept = llcp_sock_accept,
915 .getname = llcp_sock_getname,
916 .poll = llcp_sock_poll,
917 .ioctl = sock_no_ioctl,
918 .listen = llcp_sock_listen,
919 .shutdown = sock_no_shutdown,
920 .setsockopt = nfc_llcp_setsockopt,
921 .getsockopt = nfc_llcp_getsockopt,
922 .sendmsg = llcp_sock_sendmsg,
923 .recvmsg = llcp_sock_recvmsg,
924 .mmap = sock_no_mmap,
927 static const struct proto_ops llcp_rawsock_ops = {
929 .owner = THIS_MODULE,
930 .bind = llcp_raw_sock_bind,
931 .connect = sock_no_connect,
932 .release = llcp_sock_release,
933 .socketpair = sock_no_socketpair,
934 .accept = sock_no_accept,
935 .getname = llcp_sock_getname,
936 .poll = llcp_sock_poll,
937 .ioctl = sock_no_ioctl,
938 .listen = sock_no_listen,
939 .shutdown = sock_no_shutdown,
940 .sendmsg = sock_no_sendmsg,
941 .recvmsg = llcp_sock_recvmsg,
942 .mmap = sock_no_mmap,
945 static void llcp_sock_destruct(struct sock *sk)
947 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
949 pr_debug("%p\n", sk);
951 if (sk->sk_state == LLCP_CONNECTED)
952 nfc_put_device(llcp_sock->dev);
954 skb_queue_purge(&sk->sk_receive_queue);
956 nfc_llcp_sock_free(llcp_sock);
958 if (!sock_flag(sk, SOCK_DEAD)) {
959 pr_err("Freeing alive NFC LLCP socket %p\n", sk);
964 struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp, int kern)
967 struct nfc_llcp_sock *llcp_sock;
969 sk = sk_alloc(&init_net, PF_NFC, gfp, &llcp_sock_proto, kern);
973 llcp_sock = nfc_llcp_sock(sk);
975 sock_init_data(sock, sk);
976 sk->sk_state = LLCP_CLOSED;
977 sk->sk_protocol = NFC_SOCKPROTO_LLCP;
979 sk->sk_destruct = llcp_sock_destruct;
982 llcp_sock->dsap = LLCP_SAP_SDP;
983 llcp_sock->rw = LLCP_MAX_RW + 1;
984 llcp_sock->miux = cpu_to_be16(LLCP_MAX_MIUX + 1);
985 llcp_sock->send_n = llcp_sock->send_ack_n = 0;
986 llcp_sock->recv_n = llcp_sock->recv_ack_n = 0;
987 llcp_sock->remote_ready = 1;
988 llcp_sock->reserved_ssap = LLCP_SAP_MAX;
989 nfc_llcp_socket_remote_param_init(llcp_sock);
990 skb_queue_head_init(&llcp_sock->tx_queue);
991 skb_queue_head_init(&llcp_sock->tx_pending_queue);
992 INIT_LIST_HEAD(&llcp_sock->accept_queue);
995 sock->state = SS_UNCONNECTED;
1000 void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
1002 kfree(sock->service_name);
1004 skb_queue_purge(&sock->tx_queue);
1005 skb_queue_purge(&sock->tx_pending_queue);
1007 list_del_init(&sock->accept_queue);
1009 sock->parent = NULL;
1011 nfc_llcp_local_put(sock->local);
1014 static int llcp_sock_create(struct net *net, struct socket *sock,
1015 const struct nfc_protocol *nfc_proto, int kern)
1019 pr_debug("%p\n", sock);
1021 if (sock->type != SOCK_STREAM &&
1022 sock->type != SOCK_DGRAM &&
1023 sock->type != SOCK_RAW)
1024 return -ESOCKTNOSUPPORT;
1026 if (sock->type == SOCK_RAW) {
1027 if (!capable(CAP_NET_RAW))
1029 sock->ops = &llcp_rawsock_ops;
1031 sock->ops = &llcp_sock_ops;
1034 sk = nfc_llcp_sock_alloc(sock, sock->type, GFP_ATOMIC, kern);
1041 static const struct nfc_protocol llcp_nfc_proto = {
1042 .id = NFC_SOCKPROTO_LLCP,
1043 .proto = &llcp_sock_proto,
1044 .owner = THIS_MODULE,
1045 .create = llcp_sock_create
1048 int __init nfc_llcp_sock_init(void)
1050 return nfc_proto_register(&llcp_nfc_proto);
1053 void nfc_llcp_sock_exit(void)
1055 nfc_proto_unregister(&llcp_nfc_proto);