diff options
Diffstat (limited to 'net/nfc/llcp/sock.c')
-rw-r--r-- | net/nfc/llcp/sock.c | 90 |
1 files changed, 86 insertions, 4 deletions
diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c index 6e188d4020ba..40f056debf9a 100644 --- a/net/nfc/llcp/sock.c +++ b/net/nfc/llcp/sock.c | |||
@@ -142,6 +142,60 @@ error: | |||
142 | return ret; | 142 | return ret; |
143 | } | 143 | } |
144 | 144 | ||
145 | static int llcp_raw_sock_bind(struct socket *sock, struct sockaddr *addr, | ||
146 | int alen) | ||
147 | { | ||
148 | struct sock *sk = sock->sk; | ||
149 | struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk); | ||
150 | struct nfc_llcp_local *local; | ||
151 | struct nfc_dev *dev; | ||
152 | struct sockaddr_nfc_llcp llcp_addr; | ||
153 | int len, ret = 0; | ||
154 | |||
155 | if (!addr || addr->sa_family != AF_NFC) | ||
156 | return -EINVAL; | ||
157 | |||
158 | pr_debug("sk %p addr %p family %d\n", sk, addr, addr->sa_family); | ||
159 | |||
160 | memset(&llcp_addr, 0, sizeof(llcp_addr)); | ||
161 | len = min_t(unsigned int, sizeof(llcp_addr), alen); | ||
162 | memcpy(&llcp_addr, addr, len); | ||
163 | |||
164 | lock_sock(sk); | ||
165 | |||
166 | if (sk->sk_state != LLCP_CLOSED) { | ||
167 | ret = -EBADFD; | ||
168 | goto error; | ||
169 | } | ||
170 | |||
171 | dev = nfc_get_device(llcp_addr.dev_idx); | ||
172 | if (dev == NULL) { | ||
173 | ret = -ENODEV; | ||
174 | goto error; | ||
175 | } | ||
176 | |||
177 | local = nfc_llcp_find_local(dev); | ||
178 | if (local == NULL) { | ||
179 | ret = -ENODEV; | ||
180 | goto put_dev; | ||
181 | } | ||
182 | |||
183 | llcp_sock->dev = dev; | ||
184 | llcp_sock->local = nfc_llcp_local_get(local); | ||
185 | llcp_sock->nfc_protocol = llcp_addr.nfc_protocol; | ||
186 | |||
187 | nfc_llcp_sock_link(&local->raw_sockets, sk); | ||
188 | |||
189 | sk->sk_state = LLCP_BOUND; | ||
190 | |||
191 | put_dev: | ||
192 | nfc_put_device(dev); | ||
193 | |||
194 | error: | ||
195 | release_sock(sk); | ||
196 | return ret; | ||
197 | } | ||
198 | |||
145 | static int llcp_sock_listen(struct socket *sock, int backlog) | 199 | static int llcp_sock_listen(struct socket *sock, int backlog) |
146 | { | 200 | { |
147 | struct sock *sk = sock->sk; | 201 | struct sock *sk = sock->sk; |
@@ -418,7 +472,10 @@ static int llcp_sock_release(struct socket *sock) | |||
418 | 472 | ||
419 | release_sock(sk); | 473 | release_sock(sk); |
420 | 474 | ||
421 | nfc_llcp_sock_unlink(&local->sockets, sk); | 475 | if (sock->type == SOCK_RAW) |
476 | nfc_llcp_sock_unlink(&local->raw_sockets, sk); | ||
477 | else | ||
478 | nfc_llcp_sock_unlink(&local->sockets, sk); | ||
422 | 479 | ||
423 | out: | 480 | out: |
424 | sock_orphan(sk); | 481 | sock_orphan(sk); |
@@ -614,7 +671,7 @@ static int llcp_sock_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
614 | if (!(flags & MSG_PEEK)) { | 671 | if (!(flags & MSG_PEEK)) { |
615 | 672 | ||
616 | /* SOCK_STREAM: re-queue skb if it contains unreceived data */ | 673 | /* SOCK_STREAM: re-queue skb if it contains unreceived data */ |
617 | if (sk->sk_type == SOCK_STREAM) { | 674 | if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_RAW) { |
618 | skb_pull(skb, copied); | 675 | skb_pull(skb, copied); |
619 | if (skb->len) { | 676 | if (skb->len) { |
620 | skb_queue_head(&sk->sk_receive_queue, skb); | 677 | skb_queue_head(&sk->sk_receive_queue, skb); |
@@ -655,6 +712,26 @@ static const struct proto_ops llcp_sock_ops = { | |||
655 | .mmap = sock_no_mmap, | 712 | .mmap = sock_no_mmap, |
656 | }; | 713 | }; |
657 | 714 | ||
715 | static const struct proto_ops llcp_rawsock_ops = { | ||
716 | .family = PF_NFC, | ||
717 | .owner = THIS_MODULE, | ||
718 | .bind = llcp_raw_sock_bind, | ||
719 | .connect = sock_no_connect, | ||
720 | .release = llcp_sock_release, | ||
721 | .socketpair = sock_no_socketpair, | ||
722 | .accept = sock_no_accept, | ||
723 | .getname = llcp_sock_getname, | ||
724 | .poll = llcp_sock_poll, | ||
725 | .ioctl = sock_no_ioctl, | ||
726 | .listen = sock_no_listen, | ||
727 | .shutdown = sock_no_shutdown, | ||
728 | .setsockopt = sock_no_setsockopt, | ||
729 | .getsockopt = sock_no_getsockopt, | ||
730 | .sendmsg = sock_no_sendmsg, | ||
731 | .recvmsg = llcp_sock_recvmsg, | ||
732 | .mmap = sock_no_mmap, | ||
733 | }; | ||
734 | |||
658 | static void llcp_sock_destruct(struct sock *sk) | 735 | static void llcp_sock_destruct(struct sock *sk) |
659 | { | 736 | { |
660 | struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk); | 737 | struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk); |
@@ -732,10 +809,15 @@ static int llcp_sock_create(struct net *net, struct socket *sock, | |||
732 | 809 | ||
733 | pr_debug("%p\n", sock); | 810 | pr_debug("%p\n", sock); |
734 | 811 | ||
735 | if (sock->type != SOCK_STREAM && sock->type != SOCK_DGRAM) | 812 | if (sock->type != SOCK_STREAM && |
813 | sock->type != SOCK_DGRAM && | ||
814 | sock->type != SOCK_RAW) | ||
736 | return -ESOCKTNOSUPPORT; | 815 | return -ESOCKTNOSUPPORT; |
737 | 816 | ||
738 | sock->ops = &llcp_sock_ops; | 817 | if (sock->type == SOCK_RAW) |
818 | sock->ops = &llcp_rawsock_ops; | ||
819 | else | ||
820 | sock->ops = &llcp_sock_ops; | ||
739 | 821 | ||
740 | sk = nfc_llcp_sock_alloc(sock, sock->type, GFP_ATOMIC); | 822 | sk = nfc_llcp_sock_alloc(sock, sock->type, GFP_ATOMIC); |
741 | if (sk == NULL) | 823 | if (sk == NULL) |