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 = 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) {
112 goto sock_llcp_put_local;
114 llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock);
115 if (llcp_sock->ssap == LLCP_SAP_MAX) {
117 goto free_service_name;
120 llcp_sock->reserved_ssap = llcp_sock->ssap;
122 nfc_llcp_sock_link(&local->sockets, sk);
124 pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap);
126 sk->sk_state = LLCP_BOUND;
133 kfree(llcp_sock->service_name);
134 llcp_sock->service_name = NULL;
137 nfc_llcp_local_put(llcp_sock->local);
138 llcp_sock->local = NULL;
139 llcp_sock->dev = NULL;
149 static int llcp_raw_sock_bind(struct socket *sock, struct sockaddr *addr,
152 struct sock *sk = sock->sk;
153 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
154 struct nfc_llcp_local *local;
156 struct sockaddr_nfc_llcp llcp_addr;
159 if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
160 addr->sa_family != AF_NFC)
163 pr_debug("sk %p addr %p family %d\n", sk, addr, addr->sa_family);
165 memset(&llcp_addr, 0, sizeof(llcp_addr));
166 len = min_t(unsigned int, sizeof(llcp_addr), alen);
167 memcpy(&llcp_addr, addr, len);
171 if (sk->sk_state != LLCP_CLOSED) {
176 dev = nfc_get_device(llcp_addr.dev_idx);
182 local = nfc_llcp_find_local(dev);
188 llcp_sock->dev = dev;
189 llcp_sock->local = local;
190 llcp_sock->nfc_protocol = llcp_addr.nfc_protocol;
192 nfc_llcp_sock_link(&local->raw_sockets, sk);
194 sk->sk_state = LLCP_BOUND;
204 static int llcp_sock_listen(struct socket *sock, int backlog)
206 struct sock *sk = sock->sk;
209 pr_debug("sk %p backlog %d\n", sk, backlog);
213 if ((sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM) ||
214 sk->sk_state != LLCP_BOUND) {
219 sk->sk_max_ack_backlog = backlog;
220 sk->sk_ack_backlog = 0;
222 pr_debug("Socket listening\n");
223 sk->sk_state = LLCP_LISTEN;
231 static int nfc_llcp_setsockopt(struct socket *sock, int level, int optname,
232 sockptr_t optval, unsigned int optlen)
234 struct sock *sk = sock->sk;
235 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
239 pr_debug("%p optname %d\n", sk, optname);
241 if (level != SOL_NFC)
248 if (sk->sk_state == LLCP_CONNECTED ||
249 sk->sk_state == LLCP_BOUND ||
250 sk->sk_state == LLCP_LISTEN) {
255 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
260 if (opt > LLCP_MAX_RW) {
265 llcp_sock->rw = (u8) opt;
270 if (sk->sk_state == LLCP_CONNECTED ||
271 sk->sk_state == LLCP_BOUND ||
272 sk->sk_state == LLCP_LISTEN) {
277 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
282 if (opt > LLCP_MAX_MIUX) {
287 llcp_sock->miux = cpu_to_be16((u16) opt);
298 pr_debug("%p rw %d miux %d\n", llcp_sock,
299 llcp_sock->rw, llcp_sock->miux);
304 static int nfc_llcp_getsockopt(struct socket *sock, int level, int optname,
305 char __user *optval, int __user *optlen)
307 struct nfc_llcp_local *local;
308 struct sock *sk = sock->sk;
309 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
311 u16 miux, remote_miu;
314 pr_debug("%p optname %d\n", sk, optname);
316 if (level != SOL_NFC)
319 if (get_user(len, optlen))
322 local = llcp_sock->local;
326 len = min_t(u32, len, sizeof(u32));
332 rw = llcp_sock->rw > LLCP_MAX_RW ? local->rw : llcp_sock->rw;
333 if (put_user(rw, (u32 __user *) optval))
339 miux = be16_to_cpu(llcp_sock->miux) > LLCP_MAX_MIUX ?
340 be16_to_cpu(local->miux) : be16_to_cpu(llcp_sock->miux);
342 if (put_user(miux, (u32 __user *) optval))
347 case NFC_LLCP_REMOTE_MIU:
348 remote_miu = llcp_sock->remote_miu > LLCP_MAX_MIU ?
349 local->remote_miu : llcp_sock->remote_miu;
351 if (put_user(remote_miu, (u32 __user *) optval))
356 case NFC_LLCP_REMOTE_LTO:
357 if (put_user(local->remote_lto / 10, (u32 __user *) optval))
362 case NFC_LLCP_REMOTE_RW:
363 if (put_user(llcp_sock->remote_rw, (u32 __user *) optval))
375 if (put_user(len, optlen))
381 void nfc_llcp_accept_unlink(struct sock *sk)
383 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
385 pr_debug("state %d\n", sk->sk_state);
387 list_del_init(&llcp_sock->accept_queue);
388 sk_acceptq_removed(llcp_sock->parent);
389 llcp_sock->parent = NULL;
394 void nfc_llcp_accept_enqueue(struct sock *parent, struct sock *sk)
396 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
397 struct nfc_llcp_sock *llcp_sock_parent = nfc_llcp_sock(parent);
399 /* Lock will be free from unlink */
402 list_add_tail(&llcp_sock->accept_queue,
403 &llcp_sock_parent->accept_queue);
404 llcp_sock->parent = parent;
405 sk_acceptq_added(parent);
408 struct sock *nfc_llcp_accept_dequeue(struct sock *parent,
409 struct socket *newsock)
411 struct nfc_llcp_sock *lsk, *n, *llcp_parent;
414 llcp_parent = nfc_llcp_sock(parent);
416 list_for_each_entry_safe(lsk, n, &llcp_parent->accept_queue,
421 if (sk->sk_state == LLCP_CLOSED) {
423 nfc_llcp_accept_unlink(sk);
427 if (sk->sk_state == LLCP_CONNECTED || !newsock) {
428 list_del_init(&lsk->accept_queue);
432 sock_graft(sk, newsock);
436 pr_debug("Returning sk state %d\n", sk->sk_state);
438 sk_acceptq_removed(parent);
449 static int llcp_sock_accept(struct socket *sock, struct socket *newsock,
450 int flags, bool kern)
452 DECLARE_WAITQUEUE(wait, current);
453 struct sock *sk = sock->sk, *new_sk;
457 pr_debug("parent %p\n", sk);
459 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
461 if (sk->sk_state != LLCP_LISTEN) {
466 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
468 /* Wait for an incoming connection. */
469 add_wait_queue_exclusive(sk_sleep(sk), &wait);
470 while (!(new_sk = nfc_llcp_accept_dequeue(sk, newsock))) {
471 set_current_state(TASK_INTERRUPTIBLE);
478 if (signal_pending(current)) {
479 ret = sock_intr_errno(timeo);
484 timeo = schedule_timeout(timeo);
485 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
487 __set_current_state(TASK_RUNNING);
488 remove_wait_queue(sk_sleep(sk), &wait);
493 newsock->state = SS_CONNECTED;
495 pr_debug("new socket %p\n", new_sk);
503 static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr,
506 struct sock *sk = sock->sk;
507 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
508 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, llcp_addr, uaddr);
510 if (llcp_sock == NULL || llcp_sock->dev == NULL)
513 pr_debug("%p %d %d %d\n", sk, llcp_sock->target_idx,
514 llcp_sock->dsap, llcp_sock->ssap);
516 memset(llcp_addr, 0, sizeof(*llcp_addr));
519 if (!llcp_sock->dev) {
523 llcp_addr->sa_family = AF_NFC;
524 llcp_addr->dev_idx = llcp_sock->dev->idx;
525 llcp_addr->target_idx = llcp_sock->target_idx;
526 llcp_addr->nfc_protocol = llcp_sock->nfc_protocol;
527 llcp_addr->dsap = llcp_sock->dsap;
528 llcp_addr->ssap = llcp_sock->ssap;
529 llcp_addr->service_name_len = llcp_sock->service_name_len;
530 memcpy(llcp_addr->service_name, llcp_sock->service_name,
531 llcp_addr->service_name_len);
534 return sizeof(struct sockaddr_nfc_llcp);
537 static inline __poll_t llcp_accept_poll(struct sock *parent)
539 struct nfc_llcp_sock *llcp_sock, *parent_sock;
542 parent_sock = nfc_llcp_sock(parent);
544 list_for_each_entry(llcp_sock, &parent_sock->accept_queue,
548 if (sk->sk_state == LLCP_CONNECTED)
549 return EPOLLIN | EPOLLRDNORM;
555 static __poll_t llcp_sock_poll(struct file *file, struct socket *sock,
558 struct sock *sk = sock->sk;
561 pr_debug("%p\n", sk);
563 sock_poll_wait(file, sock, wait);
565 if (sk->sk_state == LLCP_LISTEN)
566 return llcp_accept_poll(sk);
568 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
570 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
572 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
573 mask |= EPOLLIN | EPOLLRDNORM;
575 if (sk->sk_state == LLCP_CLOSED)
578 if (sk->sk_shutdown & RCV_SHUTDOWN)
579 mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM;
581 if (sk->sk_shutdown == SHUTDOWN_MASK)
584 if (sock_writeable(sk) && sk->sk_state == LLCP_CONNECTED)
585 mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND;
587 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
589 pr_debug("mask 0x%x\n", mask);
594 static int llcp_sock_release(struct socket *sock)
596 struct sock *sk = sock->sk;
597 struct nfc_llcp_local *local;
598 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
604 pr_debug("%p\n", sk);
606 local = llcp_sock->local;
615 if (sk->sk_state == LLCP_CONNECTED)
616 nfc_llcp_send_disconnect(llcp_sock);
618 if (sk->sk_state == LLCP_LISTEN) {
619 struct nfc_llcp_sock *lsk, *n;
620 struct sock *accept_sk;
622 list_for_each_entry_safe(lsk, n, &llcp_sock->accept_queue,
624 accept_sk = &lsk->sk;
625 lock_sock(accept_sk);
627 nfc_llcp_send_disconnect(lsk);
628 nfc_llcp_accept_unlink(accept_sk);
630 release_sock(accept_sk);
634 if (sock->type == SOCK_RAW)
635 nfc_llcp_sock_unlink(&local->raw_sockets, sk);
637 nfc_llcp_sock_unlink(&local->sockets, sk);
639 if (llcp_sock->reserved_ssap < LLCP_SAP_MAX)
640 nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
651 static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
654 struct sock *sk = sock->sk;
655 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
656 struct sockaddr_nfc_llcp *addr = (struct sockaddr_nfc_llcp *)_addr;
658 struct nfc_llcp_local *local;
661 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
663 if (!addr || len < sizeof(*addr) || addr->sa_family != AF_NFC)
666 if (addr->service_name_len == 0 && addr->dsap == 0)
669 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
670 addr->target_idx, addr->nfc_protocol);
674 if (sk->sk_state == LLCP_CONNECTED) {
678 if (sk->sk_state == LLCP_CONNECTING) {
683 dev = nfc_get_device(addr->dev_idx);
689 local = nfc_llcp_find_local(dev);
695 device_lock(&dev->dev);
696 if (dev->dep_link_up == false) {
698 device_unlock(&dev->dev);
699 goto sock_llcp_put_local;
701 device_unlock(&dev->dev);
703 if (local->rf_mode == NFC_RF_INITIATOR &&
704 addr->target_idx != local->target_idx) {
706 goto sock_llcp_put_local;
709 llcp_sock->dev = dev;
710 llcp_sock->local = local;
711 llcp_sock->ssap = nfc_llcp_get_local_ssap(local);
712 if (llcp_sock->ssap == LLCP_SAP_MAX) {
714 goto sock_llcp_nullify;
717 llcp_sock->reserved_ssap = llcp_sock->ssap;
719 if (addr->service_name_len == 0)
720 llcp_sock->dsap = addr->dsap;
722 llcp_sock->dsap = LLCP_SAP_SDP;
723 llcp_sock->nfc_protocol = addr->nfc_protocol;
724 llcp_sock->service_name_len = min_t(unsigned int,
725 addr->service_name_len,
726 NFC_LLCP_MAX_SERVICE_NAME);
727 llcp_sock->service_name = kmemdup(addr->service_name,
728 llcp_sock->service_name_len,
730 if (!llcp_sock->service_name) {
732 goto sock_llcp_release;
735 nfc_llcp_sock_link(&local->connecting_sockets, sk);
737 ret = nfc_llcp_send_connect(llcp_sock);
741 sk->sk_state = LLCP_CONNECTING;
743 ret = sock_wait_state(sk, LLCP_CONNECTED,
744 sock_sndtimeo(sk, flags & O_NONBLOCK));
745 if (ret && ret != -EINPROGRESS)
753 nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
754 kfree(llcp_sock->service_name);
755 llcp_sock->service_name = NULL;
758 nfc_llcp_put_ssap(local, llcp_sock->ssap);
761 llcp_sock->local = NULL;
762 llcp_sock->dev = NULL;
765 nfc_llcp_local_put(local);
775 static int llcp_sock_sendmsg(struct socket *sock, struct msghdr *msg,
778 struct sock *sk = sock->sk;
779 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
782 pr_debug("sock %p sk %p", sock, sk);
784 ret = sock_error(sk);
788 if (msg->msg_flags & MSG_OOB)
793 if (!llcp_sock->local) {
798 if (sk->sk_type == SOCK_DGRAM) {
799 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, addr,
802 if (msg->msg_namelen < sizeof(*addr)) {
809 return nfc_llcp_send_ui_frame(llcp_sock, addr->dsap, addr->ssap,
813 if (sk->sk_state != LLCP_CONNECTED) {
820 return nfc_llcp_send_i_frame(llcp_sock, msg, len);
823 static int llcp_sock_recvmsg(struct socket *sock, struct msghdr *msg,
824 size_t len, int flags)
826 struct sock *sk = sock->sk;
827 unsigned int copied, rlen;
828 struct sk_buff *skb, *cskb;
831 pr_debug("%p %zu\n", sk, len);
835 if (sk->sk_state == LLCP_CLOSED &&
836 skb_queue_empty(&sk->sk_receive_queue)) {
843 if (flags & (MSG_OOB))
846 skb = skb_recv_datagram(sk, flags, &err);
848 pr_err("Recv datagram failed state %d %d %d",
849 sk->sk_state, err, sock_error(sk));
851 if (sk->sk_shutdown & RCV_SHUTDOWN)
857 rlen = skb->len; /* real length of skb */
858 copied = min_t(unsigned int, rlen, len);
861 if (skb_copy_datagram_msg(cskb, 0, msg, copied)) {
862 if (!(flags & MSG_PEEK))
863 skb_queue_head(&sk->sk_receive_queue, skb);
867 sock_recv_timestamp(msg, sk, skb);
869 if (sk->sk_type == SOCK_DGRAM && msg->msg_name) {
870 struct nfc_llcp_ui_cb *ui_cb = nfc_llcp_ui_skb_cb(skb);
871 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, sockaddr,
874 msg->msg_namelen = sizeof(struct sockaddr_nfc_llcp);
876 pr_debug("Datagram socket %d %d\n", ui_cb->dsap, ui_cb->ssap);
878 memset(sockaddr, 0, sizeof(*sockaddr));
879 sockaddr->sa_family = AF_NFC;
880 sockaddr->nfc_protocol = NFC_PROTO_NFC_DEP;
881 sockaddr->dsap = ui_cb->dsap;
882 sockaddr->ssap = ui_cb->ssap;
885 /* Mark read part of skb as used */
886 if (!(flags & MSG_PEEK)) {
888 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
889 if (sk->sk_type == SOCK_STREAM ||
890 sk->sk_type == SOCK_DGRAM ||
891 sk->sk_type == SOCK_RAW) {
892 skb_pull(skb, copied);
894 skb_queue_head(&sk->sk_receive_queue, skb);
902 /* XXX Queue backlogged skbs */
905 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
906 if (sk->sk_type == SOCK_SEQPACKET && (flags & MSG_TRUNC))
912 static const struct proto_ops llcp_sock_ops = {
914 .owner = THIS_MODULE,
915 .bind = llcp_sock_bind,
916 .connect = llcp_sock_connect,
917 .release = llcp_sock_release,
918 .socketpair = sock_no_socketpair,
919 .accept = llcp_sock_accept,
920 .getname = llcp_sock_getname,
921 .poll = llcp_sock_poll,
922 .ioctl = sock_no_ioctl,
923 .listen = llcp_sock_listen,
924 .shutdown = sock_no_shutdown,
925 .setsockopt = nfc_llcp_setsockopt,
926 .getsockopt = nfc_llcp_getsockopt,
927 .sendmsg = llcp_sock_sendmsg,
928 .recvmsg = llcp_sock_recvmsg,
929 .mmap = sock_no_mmap,
932 static const struct proto_ops llcp_rawsock_ops = {
934 .owner = THIS_MODULE,
935 .bind = llcp_raw_sock_bind,
936 .connect = sock_no_connect,
937 .release = llcp_sock_release,
938 .socketpair = sock_no_socketpair,
939 .accept = sock_no_accept,
940 .getname = llcp_sock_getname,
941 .poll = llcp_sock_poll,
942 .ioctl = sock_no_ioctl,
943 .listen = sock_no_listen,
944 .shutdown = sock_no_shutdown,
945 .sendmsg = sock_no_sendmsg,
946 .recvmsg = llcp_sock_recvmsg,
947 .mmap = sock_no_mmap,
950 static void llcp_sock_destruct(struct sock *sk)
952 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
954 pr_debug("%p\n", sk);
956 if (sk->sk_state == LLCP_CONNECTED)
957 nfc_put_device(llcp_sock->dev);
959 skb_queue_purge(&sk->sk_receive_queue);
961 nfc_llcp_sock_free(llcp_sock);
963 if (!sock_flag(sk, SOCK_DEAD)) {
964 pr_err("Freeing alive NFC LLCP socket %p\n", sk);
969 struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp, int kern)
972 struct nfc_llcp_sock *llcp_sock;
974 sk = sk_alloc(&init_net, PF_NFC, gfp, &llcp_sock_proto, kern);
978 llcp_sock = nfc_llcp_sock(sk);
980 sock_init_data(sock, sk);
981 sk->sk_state = LLCP_CLOSED;
982 sk->sk_protocol = NFC_SOCKPROTO_LLCP;
984 sk->sk_destruct = llcp_sock_destruct;
987 llcp_sock->dsap = LLCP_SAP_SDP;
988 llcp_sock->rw = LLCP_MAX_RW + 1;
989 llcp_sock->miux = cpu_to_be16(LLCP_MAX_MIUX + 1);
990 llcp_sock->send_n = llcp_sock->send_ack_n = 0;
991 llcp_sock->recv_n = llcp_sock->recv_ack_n = 0;
992 llcp_sock->remote_ready = 1;
993 llcp_sock->reserved_ssap = LLCP_SAP_MAX;
994 nfc_llcp_socket_remote_param_init(llcp_sock);
995 skb_queue_head_init(&llcp_sock->tx_queue);
996 skb_queue_head_init(&llcp_sock->tx_pending_queue);
997 INIT_LIST_HEAD(&llcp_sock->accept_queue);
1000 sock->state = SS_UNCONNECTED;
1005 void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
1007 kfree(sock->service_name);
1009 skb_queue_purge(&sock->tx_queue);
1010 skb_queue_purge(&sock->tx_pending_queue);
1012 list_del_init(&sock->accept_queue);
1014 sock->parent = NULL;
1016 nfc_llcp_local_put(sock->local);
1019 static int llcp_sock_create(struct net *net, struct socket *sock,
1020 const struct nfc_protocol *nfc_proto, int kern)
1024 pr_debug("%p\n", sock);
1026 if (sock->type != SOCK_STREAM &&
1027 sock->type != SOCK_DGRAM &&
1028 sock->type != SOCK_RAW)
1029 return -ESOCKTNOSUPPORT;
1031 if (sock->type == SOCK_RAW) {
1032 if (!capable(CAP_NET_RAW))
1034 sock->ops = &llcp_rawsock_ops;
1036 sock->ops = &llcp_sock_ops;
1039 sk = nfc_llcp_sock_alloc(sock, sock->type, GFP_ATOMIC, kern);
1046 static const struct nfc_protocol llcp_nfc_proto = {
1047 .id = NFC_SOCKPROTO_LLCP,
1048 .proto = &llcp_sock_proto,
1049 .owner = THIS_MODULE,
1050 .create = llcp_sock_create
1053 int __init nfc_llcp_sock_init(void)
1055 return nfc_proto_register(&llcp_nfc_proto);
1058 void nfc_llcp_sock_exit(void)
1060 nfc_proto_unregister(&llcp_nfc_proto);