blob: 8dfea26536c9d42a6bd9f7b64e3001737dbc4d89 [file] [log] [blame]
Thomas Gleixner1ccea772019-05-19 15:51:43 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Samuel Ortizd6469602011-12-14 16:43:12 +01002/*
3 * Copyright (C) 2011 Intel Corporation. All rights reserved.
Samuel Ortizd6469602011-12-14 16:43:12 +01004 */
5
6#define pr_fmt(fmt) "llcp: %s: " fmt, __func__
7
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/nfc.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010012#include <linux/sched/signal.h>
Samuel Ortizd6469602011-12-14 16:43:12 +010013
Samuel Ortiz30cc4582013-04-26 11:49:40 +020014#include "nfc.h"
Samuel Ortizd6469602011-12-14 16:43:12 +010015#include "llcp.h"
16
Samuel Ortizff353d82012-05-07 12:31:19 +020017static int sock_wait_state(struct sock *sk, int state, unsigned long timeo)
18{
19 DECLARE_WAITQUEUE(wait, current);
20 int err = 0;
21
22 pr_debug("sk %p", sk);
23
24 add_wait_queue(sk_sleep(sk), &wait);
25 set_current_state(TASK_INTERRUPTIBLE);
26
27 while (sk->sk_state != state) {
28 if (!timeo) {
29 err = -EINPROGRESS;
30 break;
31 }
32
33 if (signal_pending(current)) {
34 err = sock_intr_errno(timeo);
35 break;
36 }
37
38 release_sock(sk);
39 timeo = schedule_timeout(timeo);
40 lock_sock(sk);
41 set_current_state(TASK_INTERRUPTIBLE);
42
43 err = sock_error(sk);
44 if (err)
45 break;
46 }
47
48 __set_current_state(TASK_RUNNING);
49 remove_wait_queue(sk_sleep(sk), &wait);
50 return err;
51}
52
Samuel Ortizd6469602011-12-14 16:43:12 +010053static struct proto llcp_sock_proto = {
54 .name = "NFC_LLCP",
55 .owner = THIS_MODULE,
56 .obj_size = sizeof(struct nfc_llcp_sock),
57};
58
59static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
60{
61 struct sock *sk = sock->sk;
62 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
63 struct nfc_llcp_local *local;
64 struct nfc_dev *dev;
65 struct sockaddr_nfc_llcp llcp_addr;
66 int len, ret = 0;
67
Mateusz Jurczykf6a58852017-06-13 18:44:28 +020068 if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
69 addr->sa_family != AF_NFC)
Samuel Ortizd6469602011-12-14 16:43:12 +010070 return -EINVAL;
71
Samuel Ortizc66433d2012-06-29 12:03:55 +020072 pr_debug("sk %p addr %p family %d\n", sk, addr, addr->sa_family);
73
Samuel Ortizd6469602011-12-14 16:43:12 +010074 memset(&llcp_addr, 0, sizeof(llcp_addr));
75 len = min_t(unsigned int, sizeof(llcp_addr), alen);
76 memcpy(&llcp_addr, addr, len);
77
78 /* This is going to be a listening socket, dsap must be 0 */
79 if (llcp_addr.dsap != 0)
80 return -EINVAL;
81
82 lock_sock(sk);
83
84 if (sk->sk_state != LLCP_CLOSED) {
85 ret = -EBADFD;
86 goto error;
87 }
88
89 dev = nfc_get_device(llcp_addr.dev_idx);
90 if (dev == NULL) {
91 ret = -ENODEV;
92 goto error;
93 }
94
95 local = nfc_llcp_find_local(dev);
96 if (local == NULL) {
97 ret = -ENODEV;
98 goto put_dev;
99 }
100
101 llcp_sock->dev = dev;
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200102 llcp_sock->local = nfc_llcp_local_get(local);
Samuel Ortizd6469602011-12-14 16:43:12 +0100103 llcp_sock->nfc_protocol = llcp_addr.nfc_protocol;
104 llcp_sock->service_name_len = min_t(unsigned int,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100105 llcp_addr.service_name_len,
106 NFC_LLCP_MAX_SERVICE_NAME);
Samuel Ortizd6469602011-12-14 16:43:12 +0100107 llcp_sock->service_name = kmemdup(llcp_addr.service_name,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100108 llcp_sock->service_name_len,
109 GFP_KERNEL);
Samuel Ortizd6469602011-12-14 16:43:12 +0100110
111 llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock);
Samuel Ortiz8b7e8ed2012-06-22 15:32:20 +0200112 if (llcp_sock->ssap == LLCP_SAP_MAX) {
113 ret = -EADDRINUSE;
Samuel Ortizd6469602011-12-14 16:43:12 +0100114 goto put_dev;
Samuel Ortiz8b7e8ed2012-06-22 15:32:20 +0200115 }
Samuel Ortizd6469602011-12-14 16:43:12 +0100116
Samuel Ortizcbbf4722012-06-22 14:48:11 +0200117 llcp_sock->reserved_ssap = llcp_sock->ssap;
118
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200119 nfc_llcp_sock_link(&local->sockets, sk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100120
121 pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap);
122
123 sk->sk_state = LLCP_BOUND;
124
125put_dev:
126 nfc_put_device(dev);
127
128error:
129 release_sock(sk);
130 return ret;
131}
132
Thierry Escande44635232012-09-26 18:16:44 +0200133static int llcp_raw_sock_bind(struct socket *sock, struct sockaddr *addr,
134 int alen)
135{
136 struct sock *sk = sock->sk;
137 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
138 struct nfc_llcp_local *local;
139 struct nfc_dev *dev;
140 struct sockaddr_nfc_llcp llcp_addr;
141 int len, ret = 0;
142
Mateusz Jurczykf6a58852017-06-13 18:44:28 +0200143 if (!addr || alen < offsetofend(struct sockaddr, sa_family) ||
144 addr->sa_family != AF_NFC)
Thierry Escande44635232012-09-26 18:16:44 +0200145 return -EINVAL;
146
147 pr_debug("sk %p addr %p family %d\n", sk, addr, addr->sa_family);
148
149 memset(&llcp_addr, 0, sizeof(llcp_addr));
150 len = min_t(unsigned int, sizeof(llcp_addr), alen);
151 memcpy(&llcp_addr, addr, len);
152
153 lock_sock(sk);
154
155 if (sk->sk_state != LLCP_CLOSED) {
156 ret = -EBADFD;
157 goto error;
158 }
159
160 dev = nfc_get_device(llcp_addr.dev_idx);
161 if (dev == NULL) {
162 ret = -ENODEV;
163 goto error;
164 }
165
166 local = nfc_llcp_find_local(dev);
167 if (local == NULL) {
168 ret = -ENODEV;
169 goto put_dev;
170 }
171
172 llcp_sock->dev = dev;
173 llcp_sock->local = nfc_llcp_local_get(local);
174 llcp_sock->nfc_protocol = llcp_addr.nfc_protocol;
175
176 nfc_llcp_sock_link(&local->raw_sockets, sk);
177
178 sk->sk_state = LLCP_BOUND;
179
180put_dev:
181 nfc_put_device(dev);
182
183error:
184 release_sock(sk);
185 return ret;
186}
187
Samuel Ortizd6469602011-12-14 16:43:12 +0100188static int llcp_sock_listen(struct socket *sock, int backlog)
189{
190 struct sock *sk = sock->sk;
191 int ret = 0;
192
193 pr_debug("sk %p backlog %d\n", sk, backlog);
194
195 lock_sock(sk);
196
Szymon Janc874934f2012-10-04 15:15:51 +0200197 if ((sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM) ||
198 sk->sk_state != LLCP_BOUND) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100199 ret = -EBADFD;
200 goto error;
201 }
202
203 sk->sk_max_ack_backlog = backlog;
204 sk->sk_ack_backlog = 0;
205
206 pr_debug("Socket listening\n");
207 sk->sk_state = LLCP_LISTEN;
208
209error:
210 release_sock(sk);
211
212 return ret;
213}
214
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100215static int nfc_llcp_setsockopt(struct socket *sock, int level, int optname,
216 char __user *optval, unsigned int optlen)
217{
218 struct sock *sk = sock->sk;
219 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
220 u32 opt;
221 int err = 0;
222
223 pr_debug("%p optname %d\n", sk, optname);
224
225 if (level != SOL_NFC)
226 return -ENOPROTOOPT;
227
228 lock_sock(sk);
229
230 switch (optname) {
231 case NFC_LLCP_RW:
232 if (sk->sk_state == LLCP_CONNECTED ||
233 sk->sk_state == LLCP_BOUND ||
234 sk->sk_state == LLCP_LISTEN) {
235 err = -EINVAL;
236 break;
237 }
238
239 if (get_user(opt, (u32 __user *) optval)) {
240 err = -EFAULT;
241 break;
242 }
243
244 if (opt > LLCP_MAX_RW) {
245 err = -EINVAL;
246 break;
247 }
248
249 llcp_sock->rw = (u8) opt;
250
251 break;
252
253 case NFC_LLCP_MIUX:
254 if (sk->sk_state == LLCP_CONNECTED ||
255 sk->sk_state == LLCP_BOUND ||
256 sk->sk_state == LLCP_LISTEN) {
257 err = -EINVAL;
258 break;
259 }
260
261 if (get_user(opt, (u32 __user *) optval)) {
262 err = -EFAULT;
263 break;
264 }
265
266 if (opt > LLCP_MAX_MIUX) {
267 err = -EINVAL;
268 break;
269 }
270
Samuel Ortiz5eef6662013-03-20 16:06:12 +0100271 llcp_sock->miux = cpu_to_be16((u16) opt);
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100272
273 break;
274
275 default:
276 err = -ENOPROTOOPT;
277 break;
278 }
279
280 release_sock(sk);
281
Samuel Ortiz06d44f82013-02-22 11:38:05 +0100282 pr_debug("%p rw %d miux %d\n", llcp_sock,
283 llcp_sock->rw, llcp_sock->miux);
284
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100285 return err;
286}
287
288static int nfc_llcp_getsockopt(struct socket *sock, int level, int optname,
289 char __user *optval, int __user *optlen)
290{
Samuel Ortiz00e856d2013-03-20 16:36:13 +0100291 struct nfc_llcp_local *local;
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100292 struct sock *sk = sock->sk;
293 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
294 int len, err = 0;
Thierry Escande064f3702013-04-02 10:25:16 +0200295 u16 miux, remote_miu;
Samuel Ortiz00e856d2013-03-20 16:36:13 +0100296 u8 rw;
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100297
298 pr_debug("%p optname %d\n", sk, optname);
299
300 if (level != SOL_NFC)
301 return -ENOPROTOOPT;
302
303 if (get_user(len, optlen))
304 return -EFAULT;
305
Samuel Ortiz00e856d2013-03-20 16:36:13 +0100306 local = llcp_sock->local;
307 if (!local)
308 return -ENODEV;
309
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100310 len = min_t(u32, len, sizeof(u32));
311
312 lock_sock(sk);
313
314 switch (optname) {
315 case NFC_LLCP_RW:
Samuel Ortiz00e856d2013-03-20 16:36:13 +0100316 rw = llcp_sock->rw > LLCP_MAX_RW ? local->rw : llcp_sock->rw;
317 if (put_user(rw, (u32 __user *) optval))
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100318 err = -EFAULT;
319
320 break;
321
322 case NFC_LLCP_MIUX:
Samuel Ortiz00e856d2013-03-20 16:36:13 +0100323 miux = be16_to_cpu(llcp_sock->miux) > LLCP_MAX_MIUX ?
324 be16_to_cpu(local->miux) : be16_to_cpu(llcp_sock->miux);
325
326 if (put_user(miux, (u32 __user *) optval))
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100327 err = -EFAULT;
328
329 break;
330
Thierry Escande064f3702013-04-02 10:25:16 +0200331 case NFC_LLCP_REMOTE_MIU:
332 remote_miu = llcp_sock->remote_miu > LLCP_MAX_MIU ?
333 local->remote_miu : llcp_sock->remote_miu;
334
335 if (put_user(remote_miu, (u32 __user *) optval))
336 err = -EFAULT;
337
338 break;
339
340 case NFC_LLCP_REMOTE_LTO:
341 if (put_user(local->remote_lto / 10, (u32 __user *) optval))
342 err = -EFAULT;
343
344 break;
345
346 case NFC_LLCP_REMOTE_RW:
347 if (put_user(llcp_sock->remote_rw, (u32 __user *) optval))
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100348 err = -EFAULT;
349
350 break;
351
352 default:
353 err = -ENOPROTOOPT;
354 break;
355 }
356
357 release_sock(sk);
358
359 if (put_user(len, optlen))
360 return -EFAULT;
361
362 return err;
363}
364
Samuel Ortizd6469602011-12-14 16:43:12 +0100365void nfc_llcp_accept_unlink(struct sock *sk)
366{
367 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
368
369 pr_debug("state %d\n", sk->sk_state);
370
371 list_del_init(&llcp_sock->accept_queue);
372 sk_acceptq_removed(llcp_sock->parent);
373 llcp_sock->parent = NULL;
374
375 sock_put(sk);
376}
377
378void nfc_llcp_accept_enqueue(struct sock *parent, struct sock *sk)
379{
380 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
381 struct nfc_llcp_sock *llcp_sock_parent = nfc_llcp_sock(parent);
382
383 /* Lock will be free from unlink */
384 sock_hold(sk);
385
386 list_add_tail(&llcp_sock->accept_queue,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100387 &llcp_sock_parent->accept_queue);
Samuel Ortizd6469602011-12-14 16:43:12 +0100388 llcp_sock->parent = parent;
389 sk_acceptq_added(parent);
390}
391
392struct sock *nfc_llcp_accept_dequeue(struct sock *parent,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100393 struct socket *newsock)
Samuel Ortizd6469602011-12-14 16:43:12 +0100394{
395 struct nfc_llcp_sock *lsk, *n, *llcp_parent;
396 struct sock *sk;
397
398 llcp_parent = nfc_llcp_sock(parent);
399
400 list_for_each_entry_safe(lsk, n, &llcp_parent->accept_queue,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100401 accept_queue) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100402 sk = &lsk->sk;
403 lock_sock(sk);
404
405 if (sk->sk_state == LLCP_CLOSED) {
406 release_sock(sk);
407 nfc_llcp_accept_unlink(sk);
408 continue;
409 }
410
411 if (sk->sk_state == LLCP_CONNECTED || !newsock) {
Samuel Ortiz39a352a2013-03-26 14:35:57 +0100412 list_del_init(&lsk->accept_queue);
413 sock_put(sk);
414
Samuel Ortizd6469602011-12-14 16:43:12 +0100415 if (newsock)
416 sock_graft(sk, newsock);
417
418 release_sock(sk);
419
420 pr_debug("Returning sk state %d\n", sk->sk_state);
421
Samuel Ortizb141e812013-02-21 11:04:45 +0100422 sk_acceptq_removed(parent);
423
Samuel Ortizd6469602011-12-14 16:43:12 +0100424 return sk;
425 }
426
427 release_sock(sk);
428 }
429
430 return NULL;
431}
432
433static int llcp_sock_accept(struct socket *sock, struct socket *newsock,
David Howellscdfbabf2017-03-09 08:09:05 +0000434 int flags, bool kern)
Samuel Ortizd6469602011-12-14 16:43:12 +0100435{
436 DECLARE_WAITQUEUE(wait, current);
437 struct sock *sk = sock->sk, *new_sk;
438 long timeo;
439 int ret = 0;
440
441 pr_debug("parent %p\n", sk);
442
443 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
444
445 if (sk->sk_state != LLCP_LISTEN) {
446 ret = -EBADFD;
447 goto error;
448 }
449
450 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
451
452 /* Wait for an incoming connection. */
453 add_wait_queue_exclusive(sk_sleep(sk), &wait);
454 while (!(new_sk = nfc_llcp_accept_dequeue(sk, newsock))) {
455 set_current_state(TASK_INTERRUPTIBLE);
456
457 if (!timeo) {
458 ret = -EAGAIN;
459 break;
460 }
461
462 if (signal_pending(current)) {
463 ret = sock_intr_errno(timeo);
464 break;
465 }
466
467 release_sock(sk);
468 timeo = schedule_timeout(timeo);
469 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
470 }
471 __set_current_state(TASK_RUNNING);
472 remove_wait_queue(sk_sleep(sk), &wait);
473
474 if (ret)
475 goto error;
476
477 newsock->state = SS_CONNECTED;
478
479 pr_debug("new socket %p\n", new_sk);
480
481error:
482 release_sock(sk);
483
484 return ret;
485}
486
Samuel Ortiz12e5bdf2012-06-21 17:41:42 +0200487static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr,
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100488 int peer)
Samuel Ortizd6469602011-12-14 16:43:12 +0100489{
Samuel Ortizd6469602011-12-14 16:43:12 +0100490 struct sock *sk = sock->sk;
491 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
Samuel Ortiz12e5bdf2012-06-21 17:41:42 +0200492 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, llcp_addr, uaddr);
Samuel Ortizd6469602011-12-14 16:43:12 +0100493
Samuel Ortizfe3c0942012-07-05 17:43:08 +0200494 if (llcp_sock == NULL || llcp_sock->dev == NULL)
495 return -EBADFD;
496
Samuel Ortiz12e5bdf2012-06-21 17:41:42 +0200497 pr_debug("%p %d %d %d\n", sk, llcp_sock->target_idx,
498 llcp_sock->dsap, llcp_sock->ssap);
Samuel Ortizd6469602011-12-14 16:43:12 +0100499
Dan Carpenter5ffedc62013-04-22 20:24:52 +0000500 memset(llcp_addr, 0, sizeof(*llcp_addr));
Samuel Ortizd6469602011-12-14 16:43:12 +0100501
Cong Wang03c05352016-01-29 11:37:40 -0800502 lock_sock(sk);
503 if (!llcp_sock->dev) {
504 release_sock(sk);
505 return -EBADFD;
506 }
Dan Carpenter5ffedc62013-04-22 20:24:52 +0000507 llcp_addr->sa_family = AF_NFC;
Samuel Ortizd6469602011-12-14 16:43:12 +0100508 llcp_addr->dev_idx = llcp_sock->dev->idx;
Samuel Ortiz12e5bdf2012-06-21 17:41:42 +0200509 llcp_addr->target_idx = llcp_sock->target_idx;
Dan Carpenter5ffedc62013-04-22 20:24:52 +0000510 llcp_addr->nfc_protocol = llcp_sock->nfc_protocol;
Samuel Ortizd6469602011-12-14 16:43:12 +0100511 llcp_addr->dsap = llcp_sock->dsap;
512 llcp_addr->ssap = llcp_sock->ssap;
513 llcp_addr->service_name_len = llcp_sock->service_name_len;
514 memcpy(llcp_addr->service_name, llcp_sock->service_name,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100515 llcp_addr->service_name_len);
Cong Wang03c05352016-01-29 11:37:40 -0800516 release_sock(sk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100517
Denys Vlasenko9b2c45d2018-02-12 20:00:20 +0100518 return sizeof(struct sockaddr_nfc_llcp);
Samuel Ortizd6469602011-12-14 16:43:12 +0100519}
520
Al Viroade994f2017-07-03 00:01:49 -0400521static inline __poll_t llcp_accept_poll(struct sock *parent)
Samuel Ortizd6469602011-12-14 16:43:12 +0100522{
Axel Lin413df102014-11-06 18:20:41 +0800523 struct nfc_llcp_sock *llcp_sock, *parent_sock;
Samuel Ortizd6469602011-12-14 16:43:12 +0100524 struct sock *sk;
525
526 parent_sock = nfc_llcp_sock(parent);
527
Axel Lin413df102014-11-06 18:20:41 +0800528 list_for_each_entry(llcp_sock, &parent_sock->accept_queue,
529 accept_queue) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100530 sk = &llcp_sock->sk;
531
532 if (sk->sk_state == LLCP_CONNECTED)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800533 return EPOLLIN | EPOLLRDNORM;
Samuel Ortizd6469602011-12-14 16:43:12 +0100534 }
535
536 return 0;
537}
538
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700539static __poll_t llcp_sock_poll(struct file *file, struct socket *sock,
540 poll_table *wait)
Samuel Ortizd6469602011-12-14 16:43:12 +0100541{
542 struct sock *sk = sock->sk;
Al Viroade994f2017-07-03 00:01:49 -0400543 __poll_t mask = 0;
Samuel Ortizd6469602011-12-14 16:43:12 +0100544
545 pr_debug("%p\n", sk);
546
Karsten Graul89ab0662018-10-23 13:40:39 +0200547 sock_poll_wait(file, sock, wait);
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700548
Samuel Ortizd6469602011-12-14 16:43:12 +0100549 if (sk->sk_state == LLCP_LISTEN)
550 return llcp_accept_poll(sk);
551
552 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800553 mask |= EPOLLERR |
554 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
Samuel Ortizd6469602011-12-14 16:43:12 +0100555
556 if (!skb_queue_empty(&sk->sk_receive_queue))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800557 mask |= EPOLLIN | EPOLLRDNORM;
Samuel Ortizd6469602011-12-14 16:43:12 +0100558
559 if (sk->sk_state == LLCP_CLOSED)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800560 mask |= EPOLLHUP;
Samuel Ortizd6469602011-12-14 16:43:12 +0100561
Samuel Ortiz4260c132012-05-07 12:31:20 +0200562 if (sk->sk_shutdown & RCV_SHUTDOWN)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800563 mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM;
Samuel Ortiz4260c132012-05-07 12:31:20 +0200564
565 if (sk->sk_shutdown == SHUTDOWN_MASK)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800566 mask |= EPOLLHUP;
Samuel Ortiz4260c132012-05-07 12:31:20 +0200567
Samuel Ortizb4011232013-05-03 18:29:30 +0200568 if (sock_writeable(sk) && sk->sk_state == LLCP_CONNECTED)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800569 mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND;
Samuel Ortiz4260c132012-05-07 12:31:20 +0200570 else
Eric Dumazet9cd3e072015-11-29 20:03:10 -0800571 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
Samuel Ortiz4260c132012-05-07 12:31:20 +0200572
573 pr_debug("mask 0x%x\n", mask);
574
Samuel Ortizd6469602011-12-14 16:43:12 +0100575 return mask;
576}
577
578static int llcp_sock_release(struct socket *sock)
579{
580 struct sock *sk = sock->sk;
581 struct nfc_llcp_local *local;
582 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
Samuel Ortiz40c75f82012-03-05 01:03:51 +0100583 int err = 0;
Samuel Ortizd6469602011-12-14 16:43:12 +0100584
585 if (!sk)
586 return 0;
587
588 pr_debug("%p\n", sk);
589
590 local = llcp_sock->local;
Samuel Ortiz40c75f82012-03-05 01:03:51 +0100591 if (local == NULL) {
592 err = -ENODEV;
593 goto out;
594 }
Samuel Ortizd6469602011-12-14 16:43:12 +0100595
Samuel Ortizd6469602011-12-14 16:43:12 +0100596 lock_sock(sk);
597
598 /* Send a DISC */
599 if (sk->sk_state == LLCP_CONNECTED)
Thierry Escande58e3dd12013-06-04 11:34:50 +0200600 nfc_llcp_send_disconnect(llcp_sock);
Samuel Ortizd6469602011-12-14 16:43:12 +0100601
602 if (sk->sk_state == LLCP_LISTEN) {
603 struct nfc_llcp_sock *lsk, *n;
604 struct sock *accept_sk;
605
606 list_for_each_entry_safe(lsk, n, &llcp_sock->accept_queue,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100607 accept_queue) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100608 accept_sk = &lsk->sk;
609 lock_sock(accept_sk);
610
Thierry Escande58e3dd12013-06-04 11:34:50 +0200611 nfc_llcp_send_disconnect(lsk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100612 nfc_llcp_accept_unlink(accept_sk);
613
614 release_sock(accept_sk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100615 }
616 }
617
Samuel Ortizcbbf4722012-06-22 14:48:11 +0200618 if (llcp_sock->reserved_ssap < LLCP_SAP_MAX)
619 nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
Samuel Ortizd6469602011-12-14 16:43:12 +0100620
Samuel Ortizd6469602011-12-14 16:43:12 +0100621 release_sock(sk);
622
Thierry Escande17f7ae162013-06-04 11:34:51 +0200623 /* Keep this sock alive and therefore do not remove it from the sockets
624 * list until the DISC PDU has been actually sent. Otherwise we would
625 * reply with DM PDUs before sending the DISC one.
626 */
627 if (sk->sk_state == LLCP_DISCONNECTING)
628 return err;
629
Thierry Escande44635232012-09-26 18:16:44 +0200630 if (sock->type == SOCK_RAW)
631 nfc_llcp_sock_unlink(&local->raw_sockets, sk);
632 else
633 nfc_llcp_sock_unlink(&local->sockets, sk);
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200634
Samuel Ortiz40c75f82012-03-05 01:03:51 +0100635out:
Samuel Ortizd6469602011-12-14 16:43:12 +0100636 sock_orphan(sk);
637 sock_put(sk);
638
Samuel Ortiz40c75f82012-03-05 01:03:51 +0100639 return err;
Samuel Ortizd6469602011-12-14 16:43:12 +0100640}
641
642static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100643 int len, int flags)
Samuel Ortizd6469602011-12-14 16:43:12 +0100644{
645 struct sock *sk = sock->sk;
646 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
647 struct sockaddr_nfc_llcp *addr = (struct sockaddr_nfc_llcp *)_addr;
648 struct nfc_dev *dev;
649 struct nfc_llcp_local *local;
650 int ret = 0;
651
652 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
653
Mateusz Jurczyk608c4ad2017-05-24 12:26:20 +0200654 if (!addr || len < sizeof(*addr) || addr->sa_family != AF_NFC)
Samuel Ortizd6469602011-12-14 16:43:12 +0100655 return -EINVAL;
Samuel Ortizd6469602011-12-14 16:43:12 +0100656
Dave Jones32418cf2012-10-04 09:51:11 +0000657 if (addr->service_name_len == 0 && addr->dsap == 0)
Samuel Ortizd6469602011-12-14 16:43:12 +0100658 return -EINVAL;
Samuel Ortizd6469602011-12-14 16:43:12 +0100659
660 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100661 addr->target_idx, addr->nfc_protocol);
Samuel Ortizd6469602011-12-14 16:43:12 +0100662
663 lock_sock(sk);
664
665 if (sk->sk_state == LLCP_CONNECTED) {
666 ret = -EISCONN;
667 goto error;
668 }
669
670 dev = nfc_get_device(addr->dev_idx);
671 if (dev == NULL) {
672 ret = -ENODEV;
673 goto error;
674 }
675
676 local = nfc_llcp_find_local(dev);
677 if (local == NULL) {
678 ret = -ENODEV;
679 goto put_dev;
680 }
681
682 device_lock(&dev->dev);
683 if (dev->dep_link_up == false) {
684 ret = -ENOLINK;
685 device_unlock(&dev->dev);
686 goto put_dev;
687 }
688 device_unlock(&dev->dev);
689
690 if (local->rf_mode == NFC_RF_INITIATOR &&
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100691 addr->target_idx != local->target_idx) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100692 ret = -ENOLINK;
693 goto put_dev;
694 }
695
696 llcp_sock->dev = dev;
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200697 llcp_sock->local = nfc_llcp_local_get(local);
Samuel Ortizd6469602011-12-14 16:43:12 +0100698 llcp_sock->ssap = nfc_llcp_get_local_ssap(local);
699 if (llcp_sock->ssap == LLCP_SAP_MAX) {
700 ret = -ENOMEM;
701 goto put_dev;
702 }
Samuel Ortizcbbf4722012-06-22 14:48:11 +0200703
704 llcp_sock->reserved_ssap = llcp_sock->ssap;
705
Samuel Ortizd6469602011-12-14 16:43:12 +0100706 if (addr->service_name_len == 0)
707 llcp_sock->dsap = addr->dsap;
708 else
709 llcp_sock->dsap = LLCP_SAP_SDP;
710 llcp_sock->nfc_protocol = addr->nfc_protocol;
711 llcp_sock->service_name_len = min_t(unsigned int,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100712 addr->service_name_len,
713 NFC_LLCP_MAX_SERVICE_NAME);
Samuel Ortizd6469602011-12-14 16:43:12 +0100714 llcp_sock->service_name = kmemdup(addr->service_name,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100715 llcp_sock->service_name_len,
716 GFP_KERNEL);
Aditya Pakkid7737d42019-03-18 22:19:44 -0500717 if (!llcp_sock->service_name) {
718 ret = -ENOMEM;
719 goto sock_llcp_release;
720 }
Samuel Ortizd6469602011-12-14 16:43:12 +0100721
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200722 nfc_llcp_sock_link(&local->connecting_sockets, sk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100723
724 ret = nfc_llcp_send_connect(llcp_sock);
725 if (ret)
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200726 goto sock_unlink;
Samuel Ortizd6469602011-12-14 16:43:12 +0100727
Samuel Ortizb4011232013-05-03 18:29:30 +0200728 sk->sk_state = LLCP_CONNECTING;
729
Samuel Ortizff353d82012-05-07 12:31:19 +0200730 ret = sock_wait_state(sk, LLCP_CONNECTED,
731 sock_sndtimeo(sk, flags & O_NONBLOCK));
Samuel Ortizb4011232013-05-03 18:29:30 +0200732 if (ret && ret != -EINPROGRESS)
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200733 goto sock_unlink;
Samuel Ortizd6469602011-12-14 16:43:12 +0100734
735 release_sock(sk);
Samuel Ortizff353d82012-05-07 12:31:19 +0200736
Samuel Ortizb4011232013-05-03 18:29:30 +0200737 return ret;
Samuel Ortizd6469602011-12-14 16:43:12 +0100738
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200739sock_unlink:
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200740 nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
741
Aditya Pakkid7737d42019-03-18 22:19:44 -0500742sock_llcp_release:
743 nfc_llcp_put_ssap(local, llcp_sock->ssap);
744
Samuel Ortizd6469602011-12-14 16:43:12 +0100745put_dev:
746 nfc_put_device(dev);
747
748error:
749 release_sock(sk);
750 return ret;
751}
752
Ying Xue1b784142015-03-02 15:37:48 +0800753static int llcp_sock_sendmsg(struct socket *sock, struct msghdr *msg,
754 size_t len)
Samuel Ortiz53a0ac22012-03-05 01:03:37 +0100755{
756 struct sock *sk = sock->sk;
757 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
758 int ret;
759
760 pr_debug("sock %p sk %p", sock, sk);
761
762 ret = sock_error(sk);
763 if (ret)
764 return ret;
765
766 if (msg->msg_flags & MSG_OOB)
767 return -EOPNOTSUPP;
768
769 lock_sock(sk);
770
Samuel Ortizb874dec2012-10-16 15:04:10 +0200771 if (sk->sk_type == SOCK_DGRAM) {
Steffen Hurrle342dfc32014-01-17 22:53:15 +0100772 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, addr,
773 msg->msg_name);
Samuel Ortizb874dec2012-10-16 15:04:10 +0200774
775 if (msg->msg_namelen < sizeof(*addr)) {
776 release_sock(sk);
Samuel Ortizb874dec2012-10-16 15:04:10 +0200777 return -EINVAL;
778 }
779
780 release_sock(sk);
781
782 return nfc_llcp_send_ui_frame(llcp_sock, addr->dsap, addr->ssap,
783 msg, len);
784 }
785
Samuel Ortiz53a0ac22012-03-05 01:03:37 +0100786 if (sk->sk_state != LLCP_CONNECTED) {
787 release_sock(sk);
788 return -ENOTCONN;
789 }
790
791 release_sock(sk);
792
793 return nfc_llcp_send_i_frame(llcp_sock, msg, len);
794}
795
Ying Xue1b784142015-03-02 15:37:48 +0800796static int llcp_sock_recvmsg(struct socket *sock, struct msghdr *msg,
797 size_t len, int flags)
Samuel Ortizd6469602011-12-14 16:43:12 +0100798{
799 int noblock = flags & MSG_DONTWAIT;
800 struct sock *sk = sock->sk;
801 unsigned int copied, rlen;
802 struct sk_buff *skb, *cskb;
803 int err = 0;
804
805 pr_debug("%p %zu\n", sk, len);
806
807 lock_sock(sk);
808
809 if (sk->sk_state == LLCP_CLOSED &&
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100810 skb_queue_empty(&sk->sk_receive_queue)) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100811 release_sock(sk);
812 return 0;
813 }
814
815 release_sock(sk);
816
817 if (flags & (MSG_OOB))
818 return -EOPNOTSUPP;
819
820 skb = skb_recv_datagram(sk, flags, noblock, &err);
821 if (!skb) {
822 pr_err("Recv datagram failed state %d %d %d",
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100823 sk->sk_state, err, sock_error(sk));
Samuel Ortizd6469602011-12-14 16:43:12 +0100824
825 if (sk->sk_shutdown & RCV_SHUTDOWN)
826 return 0;
827
828 return err;
829 }
830
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100831 rlen = skb->len; /* real length of skb */
Samuel Ortizd6469602011-12-14 16:43:12 +0100832 copied = min_t(unsigned int, rlen, len);
833
834 cskb = skb;
David S. Miller51f3d022014-11-05 16:46:40 -0500835 if (skb_copy_datagram_msg(cskb, 0, msg, copied)) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100836 if (!(flags & MSG_PEEK))
837 skb_queue_head(&sk->sk_receive_queue, skb);
838 return -EFAULT;
839 }
840
Thierry Escande2c2d45b2012-11-27 15:44:24 +0100841 sock_recv_timestamp(msg, sk, skb);
842
Samuel Ortiz31ca61a2012-10-15 17:44:44 +0200843 if (sk->sk_type == SOCK_DGRAM && msg->msg_name) {
844 struct nfc_llcp_ui_cb *ui_cb = nfc_llcp_ui_skb_cb(skb);
Steffen Hurrle342dfc32014-01-17 22:53:15 +0100845 DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, sockaddr,
846 msg->msg_name);
Samuel Ortizfad2e372013-01-11 14:48:48 +0100847
848 msg->msg_namelen = sizeof(struct sockaddr_nfc_llcp);
Samuel Ortiz31ca61a2012-10-15 17:44:44 +0200849
850 pr_debug("Datagram socket %d %d\n", ui_cb->dsap, ui_cb->ssap);
851
Mathias Kraused26d6502013-04-07 01:51:58 +0000852 memset(sockaddr, 0, sizeof(*sockaddr));
Samuel Ortizfad2e372013-01-11 14:48:48 +0100853 sockaddr->sa_family = AF_NFC;
854 sockaddr->nfc_protocol = NFC_PROTO_NFC_DEP;
855 sockaddr->dsap = ui_cb->dsap;
856 sockaddr->ssap = ui_cb->ssap;
Samuel Ortiz31ca61a2012-10-15 17:44:44 +0200857 }
858
Samuel Ortizd6469602011-12-14 16:43:12 +0100859 /* Mark read part of skb as used */
860 if (!(flags & MSG_PEEK)) {
861
862 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
Samuel Ortiz31ca61a2012-10-15 17:44:44 +0200863 if (sk->sk_type == SOCK_STREAM ||
864 sk->sk_type == SOCK_DGRAM ||
865 sk->sk_type == SOCK_RAW) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100866 skb_pull(skb, copied);
867 if (skb->len) {
868 skb_queue_head(&sk->sk_receive_queue, skb);
869 goto done;
870 }
871 }
872
873 kfree_skb(skb);
874 }
875
876 /* XXX Queue backlogged skbs */
877
878done:
879 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
880 if (sk->sk_type == SOCK_SEQPACKET && (flags & MSG_TRUNC))
881 copied = rlen;
882
883 return copied;
884}
885
886static const struct proto_ops llcp_sock_ops = {
887 .family = PF_NFC,
888 .owner = THIS_MODULE,
889 .bind = llcp_sock_bind,
890 .connect = llcp_sock_connect,
891 .release = llcp_sock_release,
892 .socketpair = sock_no_socketpair,
893 .accept = llcp_sock_accept,
894 .getname = llcp_sock_getname,
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700895 .poll = llcp_sock_poll,
Samuel Ortizd6469602011-12-14 16:43:12 +0100896 .ioctl = sock_no_ioctl,
897 .listen = llcp_sock_listen,
898 .shutdown = sock_no_shutdown,
Samuel Ortiz26fd76c2013-02-22 10:53:25 +0100899 .setsockopt = nfc_llcp_setsockopt,
900 .getsockopt = nfc_llcp_getsockopt,
Samuel Ortiz53a0ac22012-03-05 01:03:37 +0100901 .sendmsg = llcp_sock_sendmsg,
Samuel Ortizd6469602011-12-14 16:43:12 +0100902 .recvmsg = llcp_sock_recvmsg,
903 .mmap = sock_no_mmap,
904};
905
Thierry Escande44635232012-09-26 18:16:44 +0200906static const struct proto_ops llcp_rawsock_ops = {
907 .family = PF_NFC,
908 .owner = THIS_MODULE,
909 .bind = llcp_raw_sock_bind,
910 .connect = sock_no_connect,
911 .release = llcp_sock_release,
912 .socketpair = sock_no_socketpair,
913 .accept = sock_no_accept,
914 .getname = llcp_sock_getname,
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700915 .poll = llcp_sock_poll,
Thierry Escande44635232012-09-26 18:16:44 +0200916 .ioctl = sock_no_ioctl,
917 .listen = sock_no_listen,
918 .shutdown = sock_no_shutdown,
919 .setsockopt = sock_no_setsockopt,
920 .getsockopt = sock_no_getsockopt,
921 .sendmsg = sock_no_sendmsg,
922 .recvmsg = llcp_sock_recvmsg,
923 .mmap = sock_no_mmap,
924};
925
Samuel Ortizd6469602011-12-14 16:43:12 +0100926static void llcp_sock_destruct(struct sock *sk)
927{
928 struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk);
929
930 pr_debug("%p\n", sk);
931
932 if (sk->sk_state == LLCP_CONNECTED)
933 nfc_put_device(llcp_sock->dev);
934
935 skb_queue_purge(&sk->sk_receive_queue);
936
937 nfc_llcp_sock_free(llcp_sock);
938
939 if (!sock_flag(sk, SOCK_DEAD)) {
940 pr_err("Freeing alive NFC LLCP socket %p\n", sk);
941 return;
942 }
943}
944
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500945struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp, int kern)
Samuel Ortizd6469602011-12-14 16:43:12 +0100946{
947 struct sock *sk;
948 struct nfc_llcp_sock *llcp_sock;
949
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500950 sk = sk_alloc(&init_net, PF_NFC, gfp, &llcp_sock_proto, kern);
Samuel Ortizd6469602011-12-14 16:43:12 +0100951 if (!sk)
952 return NULL;
953
954 llcp_sock = nfc_llcp_sock(sk);
955
956 sock_init_data(sock, sk);
957 sk->sk_state = LLCP_CLOSED;
958 sk->sk_protocol = NFC_SOCKPROTO_LLCP;
959 sk->sk_type = type;
960 sk->sk_destruct = llcp_sock_destruct;
961
962 llcp_sock->ssap = 0;
963 llcp_sock->dsap = LLCP_SAP_SDP;
Samuel Ortiz06d44f82013-02-22 11:38:05 +0100964 llcp_sock->rw = LLCP_MAX_RW + 1;
Samuel Ortiz5eef6662013-03-20 16:06:12 +0100965 llcp_sock->miux = cpu_to_be16(LLCP_MAX_MIUX + 1);
Samuel Ortizd6469602011-12-14 16:43:12 +0100966 llcp_sock->send_n = llcp_sock->send_ack_n = 0;
967 llcp_sock->recv_n = llcp_sock->recv_ack_n = 0;
968 llcp_sock->remote_ready = 1;
Samuel Ortizcbbf4722012-06-22 14:48:11 +0200969 llcp_sock->reserved_ssap = LLCP_SAP_MAX;
Thierry Escandeabd18d42013-04-02 10:25:15 +0200970 nfc_llcp_socket_remote_param_init(llcp_sock);
Samuel Ortizd6469602011-12-14 16:43:12 +0100971 skb_queue_head_init(&llcp_sock->tx_queue);
972 skb_queue_head_init(&llcp_sock->tx_pending_queue);
Samuel Ortizd6469602011-12-14 16:43:12 +0100973 INIT_LIST_HEAD(&llcp_sock->accept_queue);
974
975 if (sock != NULL)
976 sock->state = SS_UNCONNECTED;
977
978 return sk;
979}
980
981void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
982{
983 kfree(sock->service_name);
984
985 skb_queue_purge(&sock->tx_queue);
986 skb_queue_purge(&sock->tx_pending_queue);
Samuel Ortizd6469602011-12-14 16:43:12 +0100987
988 list_del_init(&sock->accept_queue);
Samuel Ortiz40c75f82012-03-05 01:03:51 +0100989
Samuel Ortizd6469602011-12-14 16:43:12 +0100990 sock->parent = NULL;
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200991
992 nfc_llcp_local_put(sock->local);
Samuel Ortizd6469602011-12-14 16:43:12 +0100993}
994
995static int llcp_sock_create(struct net *net, struct socket *sock,
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500996 const struct nfc_protocol *nfc_proto, int kern)
Samuel Ortizd6469602011-12-14 16:43:12 +0100997{
998 struct sock *sk;
999
1000 pr_debug("%p\n", sock);
1001
Thierry Escande44635232012-09-26 18:16:44 +02001002 if (sock->type != SOCK_STREAM &&
1003 sock->type != SOCK_DGRAM &&
1004 sock->type != SOCK_RAW)
Samuel Ortizd6469602011-12-14 16:43:12 +01001005 return -ESOCKTNOSUPPORT;
1006
Ori Nimron3a359792019-09-20 09:35:49 +02001007 if (sock->type == SOCK_RAW) {
1008 if (!capable(CAP_NET_RAW))
1009 return -EPERM;
Thierry Escande44635232012-09-26 18:16:44 +02001010 sock->ops = &llcp_rawsock_ops;
Ori Nimron3a359792019-09-20 09:35:49 +02001011 } else {
Thierry Escande44635232012-09-26 18:16:44 +02001012 sock->ops = &llcp_sock_ops;
Ori Nimron3a359792019-09-20 09:35:49 +02001013 }
Samuel Ortizd6469602011-12-14 16:43:12 +01001014
Eric W. Biederman11aa9c22015-05-08 21:09:13 -05001015 sk = nfc_llcp_sock_alloc(sock, sock->type, GFP_ATOMIC, kern);
Samuel Ortizd6469602011-12-14 16:43:12 +01001016 if (sk == NULL)
1017 return -ENOMEM;
1018
1019 return 0;
1020}
1021
1022static const struct nfc_protocol llcp_nfc_proto = {
1023 .id = NFC_SOCKPROTO_LLCP,
1024 .proto = &llcp_sock_proto,
1025 .owner = THIS_MODULE,
1026 .create = llcp_sock_create
1027};
1028
1029int __init nfc_llcp_sock_init(void)
1030{
1031 return nfc_proto_register(&llcp_nfc_proto);
1032}
1033
1034void nfc_llcp_sock_exit(void)
1035{
1036 nfc_proto_unregister(&llcp_nfc_proto);
1037}