blob: 9ab17ec50ce764344fa2b3e62df7fb8147a59071 [file] [log] [blame]
Samuel Ortizd6469602011-12-14 16:43:12 +01001/*
2 * Copyright (C) 2011 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#define pr_fmt(fmt) "llcp: %s: " fmt, __func__
21
22#include <linux/init.h>
23#include <linux/kernel.h>
24#include <linux/list.h>
25#include <linux/nfc.h>
26
27#include "../nfc.h"
28#include "llcp.h"
29
30static u8 llcp_magic[3] = {0x46, 0x66, 0x6d};
31
32static struct list_head llcp_devices;
33
Samuel Ortiza69f32a2012-05-04 17:04:19 +020034void nfc_llcp_sock_link(struct llcp_sock_list *l, struct sock *sk)
35{
36 write_lock(&l->lock);
37 sk_add_node(sk, &l->head);
38 write_unlock(&l->lock);
39}
40
41void nfc_llcp_sock_unlink(struct llcp_sock_list *l, struct sock *sk)
42{
43 write_lock(&l->lock);
44 sk_del_node_init(sk);
45 write_unlock(&l->lock);
46}
47
Samuel Ortiz4d22ea12012-06-22 14:40:34 +020048static void nfc_llcp_socket_release(struct nfc_llcp_local *local, bool listen)
Samuel Ortizd6469602011-12-14 16:43:12 +010049{
Samuel Ortiza69f32a2012-05-04 17:04:19 +020050 struct sock *sk;
51 struct hlist_node *node, *tmp;
52 struct nfc_llcp_sock *llcp_sock;
Samuel Ortizd6469602011-12-14 16:43:12 +010053
Samuel Ortiza69f32a2012-05-04 17:04:19 +020054 write_lock(&local->sockets.lock);
Samuel Ortizd6469602011-12-14 16:43:12 +010055
Samuel Ortiza69f32a2012-05-04 17:04:19 +020056 sk_for_each_safe(sk, node, tmp, &local->sockets.head) {
57 llcp_sock = nfc_llcp_sock(sk);
Samuel Ortizd6469602011-12-14 16:43:12 +010058
Samuel Ortiza69f32a2012-05-04 17:04:19 +020059 lock_sock(sk);
Samuel Ortizd6469602011-12-14 16:43:12 +010060
Samuel Ortiza69f32a2012-05-04 17:04:19 +020061 if (sk->sk_state == LLCP_CONNECTED)
62 nfc_put_device(llcp_sock->dev);
Samuel Ortizd6469602011-12-14 16:43:12 +010063
Samuel Ortiza69f32a2012-05-04 17:04:19 +020064 if (sk->sk_state == LLCP_LISTEN) {
Samuel Ortizd6469602011-12-14 16:43:12 +010065 struct nfc_llcp_sock *lsk, *n;
66 struct sock *accept_sk;
67
Samuel Ortiza69f32a2012-05-04 17:04:19 +020068 list_for_each_entry_safe(lsk, n, &llcp_sock->accept_queue,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +010069 accept_queue) {
Samuel Ortizd6469602011-12-14 16:43:12 +010070 accept_sk = &lsk->sk;
71 lock_sock(accept_sk);
72
73 nfc_llcp_accept_unlink(accept_sk);
74
75 accept_sk->sk_state = LLCP_CLOSED;
Samuel Ortizd6469602011-12-14 16:43:12 +010076
77 release_sock(accept_sk);
78
79 sock_orphan(accept_sk);
80 }
Samuel Ortiz4d22ea12012-06-22 14:40:34 +020081
82 if (listen == true) {
83 release_sock(sk);
84 continue;
85 }
Samuel Ortizd6469602011-12-14 16:43:12 +010086 }
87
Samuel Ortiza69f32a2012-05-04 17:04:19 +020088 sk->sk_state = LLCP_CLOSED;
Samuel Ortizd6469602011-12-14 16:43:12 +010089
Samuel Ortiza69f32a2012-05-04 17:04:19 +020090 release_sock(sk);
Samuel Ortizd6469602011-12-14 16:43:12 +010091
Samuel Ortiza69f32a2012-05-04 17:04:19 +020092 sock_orphan(sk);
Samuel Ortiz40c75f82012-03-05 01:03:51 +010093
Samuel Ortiza69f32a2012-05-04 17:04:19 +020094 sk_del_node_init(sk);
Samuel Ortizd6469602011-12-14 16:43:12 +010095 }
96
Samuel Ortiza69f32a2012-05-04 17:04:19 +020097 write_unlock(&local->sockets.lock);
Samuel Ortizd6469602011-12-14 16:43:12 +010098}
99
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200100struct nfc_llcp_local *nfc_llcp_local_get(struct nfc_llcp_local *local)
101{
102 kref_get(&local->ref);
103
104 return local;
105}
106
107static void local_release(struct kref *ref)
108{
109 struct nfc_llcp_local *local;
110
111 local = container_of(ref, struct nfc_llcp_local, ref);
112
113 list_del(&local->list);
Samuel Ortiz4d22ea12012-06-22 14:40:34 +0200114 nfc_llcp_socket_release(local, false);
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200115 del_timer_sync(&local->link_timer);
116 skb_queue_purge(&local->tx_queue);
117 destroy_workqueue(local->tx_wq);
118 destroy_workqueue(local->rx_wq);
Samuel Ortiz07922bb2012-05-31 17:29:15 +0200119 destroy_workqueue(local->timeout_wq);
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200120 kfree_skb(local->rx_pending);
121 kfree(local);
122}
123
124int nfc_llcp_local_put(struct nfc_llcp_local *local)
125{
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200126 WARN_ON(local == NULL);
127
128 if (local == NULL)
129 return 0;
130
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200131 return kref_put(&local->ref, local_release);
132}
133
Samuel Ortizd6469602011-12-14 16:43:12 +0100134static void nfc_llcp_timeout_work(struct work_struct *work)
135{
136 struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100137 timeout_work);
Samuel Ortizd6469602011-12-14 16:43:12 +0100138
139 nfc_dep_link_down(local->dev);
140}
141
142static void nfc_llcp_symm_timer(unsigned long data)
143{
144 struct nfc_llcp_local *local = (struct nfc_llcp_local *) data;
145
146 pr_err("SYMM timeout\n");
147
148 queue_work(local->timeout_wq, &local->timeout_work);
149}
150
151struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev)
152{
153 struct nfc_llcp_local *local, *n;
154
155 list_for_each_entry_safe(local, n, &llcp_devices, list)
156 if (local->dev == dev)
157 return local;
158
159 pr_debug("No device found\n");
160
161 return NULL;
162}
163
164static char *wks[] = {
165 NULL,
166 NULL, /* SDP */
167 "urn:nfc:sn:ip",
168 "urn:nfc:sn:obex",
169 "urn:nfc:sn:snep",
170};
171
172static int nfc_llcp_wks_sap(char *service_name, size_t service_name_len)
173{
174 int sap, num_wks;
175
176 pr_debug("%s\n", service_name);
177
178 if (service_name == NULL)
179 return -EINVAL;
180
181 num_wks = ARRAY_SIZE(wks);
182
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100183 for (sap = 0; sap < num_wks; sap++) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100184 if (wks[sap] == NULL)
185 continue;
186
187 if (strncmp(wks[sap], service_name, service_name_len) == 0)
188 return sap;
189 }
190
191 return -EINVAL;
192}
193
194u8 nfc_llcp_get_sdp_ssap(struct nfc_llcp_local *local,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100195 struct nfc_llcp_sock *sock)
Samuel Ortizd6469602011-12-14 16:43:12 +0100196{
197 mutex_lock(&local->sdp_lock);
198
199 if (sock->service_name != NULL && sock->service_name_len > 0) {
200 int ssap = nfc_llcp_wks_sap(sock->service_name,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100201 sock->service_name_len);
Samuel Ortizd6469602011-12-14 16:43:12 +0100202
203 if (ssap > 0) {
204 pr_debug("WKS %d\n", ssap);
205
206 /* This is a WKS, let's check if it's free */
207 if (local->local_wks & BIT(ssap)) {
208 mutex_unlock(&local->sdp_lock);
209
210 return LLCP_SAP_MAX;
211 }
212
Samuel Ortiz1762c172012-03-05 01:03:38 +0100213 set_bit(ssap, &local->local_wks);
Samuel Ortizd6469602011-12-14 16:43:12 +0100214 mutex_unlock(&local->sdp_lock);
215
216 return ssap;
217 }
218
219 /*
220 * This is not a well known service,
221 * we should try to find a local SDP free spot
222 */
223 ssap = find_first_zero_bit(&local->local_sdp, LLCP_SDP_NUM_SAP);
224 if (ssap == LLCP_SDP_NUM_SAP) {
225 mutex_unlock(&local->sdp_lock);
226
227 return LLCP_SAP_MAX;
228 }
229
230 pr_debug("SDP ssap %d\n", LLCP_WKS_NUM_SAP + ssap);
231
Samuel Ortiz1762c172012-03-05 01:03:38 +0100232 set_bit(ssap, &local->local_sdp);
Samuel Ortizd6469602011-12-14 16:43:12 +0100233 mutex_unlock(&local->sdp_lock);
234
235 return LLCP_WKS_NUM_SAP + ssap;
236
Samuel Ortizebbb16d2012-06-22 17:15:20 +0200237 } else if (sock->ssap != 0 && sock->ssap < LLCP_WKS_NUM_SAP) {
238 if (!test_bit(sock->ssap, &local->local_wks)) {
239 set_bit(sock->ssap, &local->local_wks);
240 mutex_unlock(&local->sdp_lock);
Samuel Ortizd6469602011-12-14 16:43:12 +0100241
Samuel Ortizebbb16d2012-06-22 17:15:20 +0200242 return sock->ssap;
Samuel Ortizd6469602011-12-14 16:43:12 +0100243 }
244 }
245
246 mutex_unlock(&local->sdp_lock);
247
248 return LLCP_SAP_MAX;
249}
250
251u8 nfc_llcp_get_local_ssap(struct nfc_llcp_local *local)
252{
253 u8 local_ssap;
254
255 mutex_lock(&local->sdp_lock);
256
257 local_ssap = find_first_zero_bit(&local->local_sap, LLCP_LOCAL_NUM_SAP);
258 if (local_ssap == LLCP_LOCAL_NUM_SAP) {
259 mutex_unlock(&local->sdp_lock);
260 return LLCP_SAP_MAX;
261 }
262
Samuel Ortiz1762c172012-03-05 01:03:38 +0100263 set_bit(local_ssap, &local->local_sap);
Samuel Ortizd6469602011-12-14 16:43:12 +0100264
265 mutex_unlock(&local->sdp_lock);
266
267 return local_ssap + LLCP_LOCAL_SAP_OFFSET;
268}
269
270void nfc_llcp_put_ssap(struct nfc_llcp_local *local, u8 ssap)
271{
272 u8 local_ssap;
273 unsigned long *sdp;
274
275 if (ssap < LLCP_WKS_NUM_SAP) {
276 local_ssap = ssap;
277 sdp = &local->local_wks;
278 } else if (ssap < LLCP_LOCAL_NUM_SAP) {
279 local_ssap = ssap - LLCP_WKS_NUM_SAP;
280 sdp = &local->local_sdp;
281 } else if (ssap < LLCP_MAX_SAP) {
282 local_ssap = ssap - LLCP_LOCAL_NUM_SAP;
283 sdp = &local->local_sap;
284 } else {
285 return;
286 }
287
288 mutex_lock(&local->sdp_lock);
289
Samuel Ortiz1762c172012-03-05 01:03:38 +0100290 clear_bit(local_ssap, sdp);
Samuel Ortizd6469602011-12-14 16:43:12 +0100291
292 mutex_unlock(&local->sdp_lock);
293}
294
Samuel Ortizd6469602011-12-14 16:43:12 +0100295static int nfc_llcp_build_gb(struct nfc_llcp_local *local)
296{
297 u8 *gb_cur, *version_tlv, version, version_length;
298 u8 *lto_tlv, lto, lto_length;
299 u8 *wks_tlv, wks_length;
Samuel Ortiz56d58762012-04-10 19:43:19 +0200300 u8 *miux_tlv, miux_length;
301 __be16 miux;
Samuel Ortizd6469602011-12-14 16:43:12 +0100302 u8 gb_len = 0;
303
304 version = LLCP_VERSION_11;
305 version_tlv = nfc_llcp_build_tlv(LLCP_TLV_VERSION, &version,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100306 1, &version_length);
Samuel Ortizd6469602011-12-14 16:43:12 +0100307 gb_len += version_length;
308
309 /* 1500 ms */
310 lto = 150;
Samuel Ortiz91b0ade2012-04-10 19:43:20 +0200311 lto_tlv = nfc_llcp_build_tlv(LLCP_TLV_LTO, &lto, 1, &lto_length);
Samuel Ortizd6469602011-12-14 16:43:12 +0100312 gb_len += lto_length;
313
314 pr_debug("Local wks 0x%lx\n", local->local_wks);
315 wks_tlv = nfc_llcp_build_tlv(LLCP_TLV_WKS, (u8 *)&local->local_wks, 2,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100316 &wks_length);
Samuel Ortizd6469602011-12-14 16:43:12 +0100317 gb_len += wks_length;
318
Samuel Ortiz56d58762012-04-10 19:43:19 +0200319 miux = cpu_to_be16(LLCP_MAX_MIUX);
320 miux_tlv = nfc_llcp_build_tlv(LLCP_TLV_MIUX, (u8 *)&miux, 0,
321 &miux_length);
322 gb_len += miux_length;
323
Samuel Ortizd6469602011-12-14 16:43:12 +0100324 gb_len += ARRAY_SIZE(llcp_magic);
325
326 if (gb_len > NFC_MAX_GT_LEN) {
327 kfree(version_tlv);
328 return -EINVAL;
329 }
330
331 gb_cur = local->gb;
332
333 memcpy(gb_cur, llcp_magic, ARRAY_SIZE(llcp_magic));
334 gb_cur += ARRAY_SIZE(llcp_magic);
335
336 memcpy(gb_cur, version_tlv, version_length);
337 gb_cur += version_length;
338
339 memcpy(gb_cur, lto_tlv, lto_length);
340 gb_cur += lto_length;
341
342 memcpy(gb_cur, wks_tlv, wks_length);
343 gb_cur += wks_length;
344
Samuel Ortiz56d58762012-04-10 19:43:19 +0200345 memcpy(gb_cur, miux_tlv, miux_length);
346 gb_cur += miux_length;
347
Samuel Ortizd6469602011-12-14 16:43:12 +0100348 kfree(version_tlv);
349 kfree(lto_tlv);
350
351 local->gb_len = gb_len;
352
353 return 0;
354}
355
Samuel Ortizb8e7a062012-06-22 02:04:53 +0200356u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len)
357{
358 struct nfc_llcp_local *local;
359
360 local = nfc_llcp_find_local(dev);
361 if (local == NULL) {
362 *general_bytes_len = 0;
363 return NULL;
364 }
365
366 nfc_llcp_build_gb(local);
367
368 *general_bytes_len = local->gb_len;
369
370 return local->gb;
371}
372
Samuel Ortizd6469602011-12-14 16:43:12 +0100373int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len)
374{
375 struct nfc_llcp_local *local = nfc_llcp_find_local(dev);
376
377 if (local == NULL) {
378 pr_err("No LLCP device\n");
379 return -ENODEV;
380 }
381
382 memset(local->remote_gb, 0, NFC_MAX_GT_LEN);
383 memcpy(local->remote_gb, gb, gb_len);
384 local->remote_gb_len = gb_len;
385
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100386 if (local->remote_gb == NULL || local->remote_gb_len == 0)
Samuel Ortizd6469602011-12-14 16:43:12 +0100387 return -ENODEV;
388
389 if (memcmp(local->remote_gb, llcp_magic, 3)) {
390 pr_err("MAC does not support LLCP\n");
391 return -EINVAL;
392 }
393
Samuel Ortiz7a06e582012-05-07 22:03:34 +0200394 return nfc_llcp_parse_gb_tlv(local,
395 &local->remote_gb[3],
396 local->remote_gb_len - 3);
Samuel Ortizd6469602011-12-14 16:43:12 +0100397}
398
Samuel Ortizd6469602011-12-14 16:43:12 +0100399static u8 nfc_llcp_dsap(struct sk_buff *pdu)
400{
401 return (pdu->data[0] & 0xfc) >> 2;
402}
403
404static u8 nfc_llcp_ptype(struct sk_buff *pdu)
405{
406 return ((pdu->data[0] & 0x03) << 2) | ((pdu->data[1] & 0xc0) >> 6);
407}
408
409static u8 nfc_llcp_ssap(struct sk_buff *pdu)
410{
411 return pdu->data[1] & 0x3f;
412}
413
414static u8 nfc_llcp_ns(struct sk_buff *pdu)
415{
416 return pdu->data[2] >> 4;
417}
418
419static u8 nfc_llcp_nr(struct sk_buff *pdu)
420{
421 return pdu->data[2] & 0xf;
422}
423
424static void nfc_llcp_set_nrns(struct nfc_llcp_sock *sock, struct sk_buff *pdu)
425{
Samuel Ortiz279cf172012-04-10 19:43:14 +0200426 pdu->data[2] = (sock->send_n << 4) | (sock->recv_n);
Samuel Ortizd6469602011-12-14 16:43:12 +0100427 sock->send_n = (sock->send_n + 1) % 16;
428 sock->recv_ack_n = (sock->recv_n - 1) % 16;
429}
430
Samuel Ortiz84457962012-05-30 17:48:29 +0200431static void nfc_llcp_tx_work(struct work_struct *work)
432{
433 struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local,
434 tx_work);
435 struct sk_buff *skb;
436 struct sock *sk;
437 struct nfc_llcp_sock *llcp_sock;
438
439 skb = skb_dequeue(&local->tx_queue);
440 if (skb != NULL) {
441 sk = skb->sk;
442 llcp_sock = nfc_llcp_sock(sk);
443 if (llcp_sock != NULL) {
444 int ret;
445
446 pr_debug("Sending pending skb\n");
447 print_hex_dump(KERN_DEBUG, "LLCP Tx: ",
448 DUMP_PREFIX_OFFSET, 16, 1,
449 skb->data, skb->len, true);
450
451 ret = nfc_data_exchange(local->dev, local->target_idx,
452 skb, nfc_llcp_recv, local);
453
454 if (!ret && nfc_llcp_ptype(skb) == LLCP_PDU_I) {
455 skb = skb_get(skb);
456 skb_queue_tail(&llcp_sock->tx_pending_queue,
457 skb);
458 }
459 } else {
460 nfc_llcp_send_symm(local->dev);
461 }
462 } else {
463 nfc_llcp_send_symm(local->dev);
464 }
465
466 mod_timer(&local->link_timer,
467 jiffies + msecs_to_jiffies(2 * local->remote_lto));
468}
469
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200470static struct nfc_llcp_sock *nfc_llcp_connecting_sock_get(struct nfc_llcp_local *local,
471 u8 ssap)
472{
473 struct sock *sk;
474 struct nfc_llcp_sock *llcp_sock;
475 struct hlist_node *node;
476
477 read_lock(&local->connecting_sockets.lock);
478
479 sk_for_each(sk, node, &local->connecting_sockets.head) {
480 llcp_sock = nfc_llcp_sock(sk);
481
Samuel Ortiz5a0f6f32012-05-21 11:44:42 +0200482 if (llcp_sock->ssap == ssap) {
483 sock_hold(&llcp_sock->sk);
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200484 goto out;
Samuel Ortiz5a0f6f32012-05-21 11:44:42 +0200485 }
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200486 }
487
488 llcp_sock = NULL;
489
490out:
491 read_unlock(&local->connecting_sockets.lock);
492
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200493 return llcp_sock;
494}
495
Samuel Ortizd6469602011-12-14 16:43:12 +0100496static struct nfc_llcp_sock *nfc_llcp_sock_get(struct nfc_llcp_local *local,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100497 u8 ssap, u8 dsap)
Samuel Ortizd6469602011-12-14 16:43:12 +0100498{
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200499 struct sock *sk;
500 struct hlist_node *node;
501 struct nfc_llcp_sock *llcp_sock;
Samuel Ortizd6469602011-12-14 16:43:12 +0100502
Samuel Ortizff353d82012-05-07 12:31:19 +0200503 pr_debug("ssap dsap %d %d\n", ssap, dsap);
504
Samuel Ortizd6469602011-12-14 16:43:12 +0100505 if (ssap == 0 && dsap == 0)
506 return NULL;
507
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200508 read_lock(&local->sockets.lock);
509
510 llcp_sock = NULL;
511
512 sk_for_each(sk, node, &local->sockets.head) {
513 llcp_sock = nfc_llcp_sock(sk);
514
515 if (llcp_sock->ssap == ssap &&
516 llcp_sock->dsap == dsap)
517 break;
518 }
519
520 read_unlock(&local->sockets.lock);
521
522 if (llcp_sock == NULL)
Samuel Ortizd6469602011-12-14 16:43:12 +0100523 return NULL;
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200524
525 sock_hold(&llcp_sock->sk);
526
527 return llcp_sock;
528}
529
530static struct nfc_llcp_sock *nfc_llcp_sock_get_sn(struct nfc_llcp_local *local,
531 u8 *sn, size_t sn_len)
532{
533 struct sock *sk;
534 struct hlist_node *node;
535 struct nfc_llcp_sock *llcp_sock;
536
537 pr_debug("sn %zd\n", sn_len);
538
539 if (sn == NULL || sn_len == 0)
540 return NULL;
541
542 read_lock(&local->sockets.lock);
543
544 llcp_sock = NULL;
545
546 sk_for_each(sk, node, &local->sockets.head) {
547 llcp_sock = nfc_llcp_sock(sk);
548
549 if (llcp_sock->sk.sk_state != LLCP_LISTEN)
550 continue;
551
552 if (llcp_sock->service_name == NULL ||
553 llcp_sock->service_name_len == 0)
554 continue;
555
556 if (llcp_sock->service_name_len != sn_len)
557 continue;
558
559 if (memcmp(sn, llcp_sock->service_name, sn_len) == 0)
560 break;
Samuel Ortizd6469602011-12-14 16:43:12 +0100561 }
562
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200563 read_unlock(&local->sockets.lock);
Samuel Ortizd6469602011-12-14 16:43:12 +0100564
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200565 if (llcp_sock == NULL)
566 return NULL;
Samuel Ortizd6469602011-12-14 16:43:12 +0100567
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200568 sock_hold(&llcp_sock->sk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100569
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200570 return llcp_sock;
Samuel Ortizd6469602011-12-14 16:43:12 +0100571}
572
573static void nfc_llcp_sock_put(struct nfc_llcp_sock *sock)
574{
575 sock_put(&sock->sk);
576}
577
578static u8 *nfc_llcp_connect_sn(struct sk_buff *skb, size_t *sn_len)
579{
580 u8 *tlv = &skb->data[2], type, length;
581 size_t tlv_array_len = skb->len - LLCP_HEADER_SIZE, offset = 0;
582
583 while (offset < tlv_array_len) {
584 type = tlv[0];
585 length = tlv[1];
586
587 pr_debug("type 0x%x length %d\n", type, length);
588
589 if (type == LLCP_TLV_SN) {
590 *sn_len = length;
591 return &tlv[2];
592 }
593
594 offset += length + 2;
595 tlv += length + 2;
596 }
597
598 return NULL;
599}
600
601static void nfc_llcp_recv_connect(struct nfc_llcp_local *local,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100602 struct sk_buff *skb)
Samuel Ortizd6469602011-12-14 16:43:12 +0100603{
604 struct sock *new_sk, *parent;
605 struct nfc_llcp_sock *sock, *new_sock;
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200606 u8 dsap, ssap, reason;
Samuel Ortizd6469602011-12-14 16:43:12 +0100607
608 dsap = nfc_llcp_dsap(skb);
609 ssap = nfc_llcp_ssap(skb);
610
611 pr_debug("%d %d\n", dsap, ssap);
612
Samuel Ortizd6469602011-12-14 16:43:12 +0100613 if (dsap != LLCP_SAP_SDP) {
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200614 sock = nfc_llcp_sock_get(local, dsap, LLCP_SAP_SDP);
615 if (sock == NULL || sock->sk.sk_state != LLCP_LISTEN) {
Samuel Ortizd6469602011-12-14 16:43:12 +0100616 reason = LLCP_DM_NOBOUND;
617 goto fail;
618 }
Samuel Ortizd6469602011-12-14 16:43:12 +0100619 } else {
620 u8 *sn;
621 size_t sn_len;
622
623 sn = nfc_llcp_connect_sn(skb, &sn_len);
624 if (sn == NULL) {
625 reason = LLCP_DM_NOBOUND;
626 goto fail;
627 }
628
629 pr_debug("Service name length %zu\n", sn_len);
630
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200631 sock = nfc_llcp_sock_get_sn(local, sn, sn_len);
632 if (sock == NULL) {
633 reason = LLCP_DM_NOBOUND;
634 goto fail;
Samuel Ortizd6469602011-12-14 16:43:12 +0100635 }
Samuel Ortizd6469602011-12-14 16:43:12 +0100636 }
637
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200638 lock_sock(&sock->sk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100639
Samuel Ortizd6469602011-12-14 16:43:12 +0100640 parent = &sock->sk;
641
642 if (sk_acceptq_is_full(parent)) {
643 reason = LLCP_DM_REJ;
644 release_sock(&sock->sk);
645 sock_put(&sock->sk);
646 goto fail;
647 }
648
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100649 new_sk = nfc_llcp_sock_alloc(NULL, parent->sk_type, GFP_ATOMIC);
Samuel Ortizd6469602011-12-14 16:43:12 +0100650 if (new_sk == NULL) {
651 reason = LLCP_DM_REJ;
652 release_sock(&sock->sk);
653 sock_put(&sock->sk);
654 goto fail;
655 }
656
657 new_sock = nfc_llcp_sock(new_sk);
658 new_sock->dev = local->dev;
Samuel Ortizc7aa1222012-05-04 11:24:16 +0200659 new_sock->local = nfc_llcp_local_get(local);
Samuel Ortiz93d7e492012-05-14 17:37:32 +0200660 new_sock->miu = local->remote_miu;
Samuel Ortizd6469602011-12-14 16:43:12 +0100661 new_sock->nfc_protocol = sock->nfc_protocol;
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200662 new_sock->ssap = sock->ssap;
Samuel Ortizd6469602011-12-14 16:43:12 +0100663 new_sock->dsap = ssap;
Samuel Ortiz025f1522012-06-18 21:38:09 +0200664 new_sock->target_idx = local->target_idx;
Samuel Ortizd6469602011-12-14 16:43:12 +0100665 new_sock->parent = parent;
666
Samuel Ortiz7a06e582012-05-07 22:03:34 +0200667 nfc_llcp_parse_connection_tlv(new_sock, &skb->data[LLCP_HEADER_SIZE],
668 skb->len - LLCP_HEADER_SIZE);
669
Samuel Ortizd6469602011-12-14 16:43:12 +0100670 pr_debug("new sock %p sk %p\n", new_sock, &new_sock->sk);
671
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200672 nfc_llcp_sock_link(&local->sockets, new_sk);
Samuel Ortizd6469602011-12-14 16:43:12 +0100673
674 nfc_llcp_accept_enqueue(&sock->sk, new_sk);
675
676 nfc_get_device(local->dev->idx);
677
678 new_sk->sk_state = LLCP_CONNECTED;
679
680 /* Wake the listening processes */
681 parent->sk_data_ready(parent, 0);
682
683 /* Send CC */
684 nfc_llcp_send_cc(new_sock);
685
686 release_sock(&sock->sk);
687 sock_put(&sock->sk);
688
689 return;
690
691fail:
692 /* Send DM */
693 nfc_llcp_send_dm(local, dsap, ssap, reason);
694
695 return;
696
697}
698
Samuel Ortizd094afa2012-03-05 01:03:42 +0100699int nfc_llcp_queue_i_frames(struct nfc_llcp_sock *sock)
Samuel Ortiz4722d2b2012-03-05 01:03:35 +0100700{
Samuel Ortizd094afa2012-03-05 01:03:42 +0100701 int nr_frames = 0;
Samuel Ortiz4722d2b2012-03-05 01:03:35 +0100702 struct nfc_llcp_local *local = sock->local;
703
704 pr_debug("Remote ready %d tx queue len %d remote rw %d",
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100705 sock->remote_ready, skb_queue_len(&sock->tx_pending_queue),
Samuel Ortiz7a06e582012-05-07 22:03:34 +0200706 sock->rw);
Samuel Ortiz4722d2b2012-03-05 01:03:35 +0100707
708 /* Try to queue some I frames for transmission */
709 while (sock->remote_ready &&
Samuel Ortiz7a06e582012-05-07 22:03:34 +0200710 skb_queue_len(&sock->tx_pending_queue) < sock->rw) {
Samuel Ortiz84457962012-05-30 17:48:29 +0200711 struct sk_buff *pdu;
Samuel Ortiz4722d2b2012-03-05 01:03:35 +0100712
713 pdu = skb_dequeue(&sock->tx_queue);
714 if (pdu == NULL)
715 break;
716
717 /* Update N(S)/N(R) */
718 nfc_llcp_set_nrns(sock, pdu);
719
Samuel Ortiz4722d2b2012-03-05 01:03:35 +0100720 skb_queue_tail(&local->tx_queue, pdu);
Samuel Ortizd094afa2012-03-05 01:03:42 +0100721 nr_frames++;
Samuel Ortiz4722d2b2012-03-05 01:03:35 +0100722 }
Samuel Ortizd094afa2012-03-05 01:03:42 +0100723
724 return nr_frames;
Samuel Ortiz4722d2b2012-03-05 01:03:35 +0100725}
726
Samuel Ortizd6469602011-12-14 16:43:12 +0100727static void nfc_llcp_recv_hdlc(struct nfc_llcp_local *local,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100728 struct sk_buff *skb)
Samuel Ortizd6469602011-12-14 16:43:12 +0100729{
730 struct nfc_llcp_sock *llcp_sock;
731 struct sock *sk;
732 u8 dsap, ssap, ptype, ns, nr;
733
734 ptype = nfc_llcp_ptype(skb);
735 dsap = nfc_llcp_dsap(skb);
736 ssap = nfc_llcp_ssap(skb);
737 ns = nfc_llcp_ns(skb);
738 nr = nfc_llcp_nr(skb);
739
740 pr_debug("%d %d R %d S %d\n", dsap, ssap, nr, ns);
741
742 llcp_sock = nfc_llcp_sock_get(local, dsap, ssap);
743 if (llcp_sock == NULL) {
744 nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN);
745 return;
746 }
747
748 sk = &llcp_sock->sk;
749 lock_sock(sk);
750 if (sk->sk_state == LLCP_CLOSED) {
751 release_sock(sk);
752 nfc_llcp_sock_put(llcp_sock);
753 }
754
Samuel Ortizd6469602011-12-14 16:43:12 +0100755 /* Pass the payload upstream */
756 if (ptype == LLCP_PDU_I) {
757 pr_debug("I frame, queueing on %p\n", &llcp_sock->sk);
758
Samuel Ortiz53aef922012-03-05 01:03:36 +0100759 if (ns == llcp_sock->recv_n)
760 llcp_sock->recv_n = (llcp_sock->recv_n + 1) % 16;
761 else
762 pr_err("Received out of sequence I PDU\n");
763
Samuel Ortizd6469602011-12-14 16:43:12 +0100764 skb_pull(skb, LLCP_HEADER_SIZE + LLCP_SEQUENCE_SIZE);
765 if (sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
766 pr_err("receive queue is full\n");
767 skb_queue_head(&llcp_sock->tx_backlog_queue, skb);
768 }
769 }
770
771 /* Remove skbs from the pending queue */
772 if (llcp_sock->send_ack_n != nr) {
773 struct sk_buff *s, *tmp;
774
775 llcp_sock->send_ack_n = nr;
776
Samuel Ortiz84457962012-05-30 17:48:29 +0200777 /* Remove and free all skbs until ns == nr */
778 skb_queue_walk_safe(&llcp_sock->tx_pending_queue, s, tmp) {
779 skb_unlink(s, &llcp_sock->tx_pending_queue);
780 kfree_skb(s);
781
782 if (nfc_llcp_ns(s) == nr)
783 break;
784 }
785
786 /* Re-queue the remaining skbs for transmission */
787 skb_queue_reverse_walk_safe(&llcp_sock->tx_pending_queue,
788 s, tmp) {
789 skb_unlink(s, &llcp_sock->tx_pending_queue);
790 skb_queue_head(&local->tx_queue, s);
791 }
Samuel Ortizd6469602011-12-14 16:43:12 +0100792 }
793
Samuel Ortiz53aef922012-03-05 01:03:36 +0100794 if (ptype == LLCP_PDU_RR)
795 llcp_sock->remote_ready = true;
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100796 else if (ptype == LLCP_PDU_RNR)
Samuel Ortiz53aef922012-03-05 01:03:36 +0100797 llcp_sock->remote_ready = false;
798
Samuel Ortiz56af2562012-05-30 18:06:11 +0200799 if (nfc_llcp_queue_i_frames(llcp_sock) == 0 && ptype == LLCP_PDU_I)
Samuel Ortizd094afa2012-03-05 01:03:42 +0100800 nfc_llcp_send_rr(llcp_sock);
Samuel Ortizd6469602011-12-14 16:43:12 +0100801
802 release_sock(sk);
803 nfc_llcp_sock_put(llcp_sock);
804}
805
806static void nfc_llcp_recv_disc(struct nfc_llcp_local *local,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100807 struct sk_buff *skb)
Samuel Ortizd6469602011-12-14 16:43:12 +0100808{
809 struct nfc_llcp_sock *llcp_sock;
810 struct sock *sk;
811 u8 dsap, ssap;
812
813 dsap = nfc_llcp_dsap(skb);
814 ssap = nfc_llcp_ssap(skb);
815
816 llcp_sock = nfc_llcp_sock_get(local, dsap, ssap);
817 if (llcp_sock == NULL) {
818 nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN);
819 return;
820 }
821
822 sk = &llcp_sock->sk;
823 lock_sock(sk);
824 if (sk->sk_state == LLCP_CLOSED) {
825 release_sock(sk);
826 nfc_llcp_sock_put(llcp_sock);
827 }
828
Samuel Ortizd6469602011-12-14 16:43:12 +0100829 if (sk->sk_state == LLCP_CONNECTED) {
830 nfc_put_device(local->dev);
831 sk->sk_state = LLCP_CLOSED;
832 sk->sk_state_change(sk);
833 }
834
835 nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_DISC);
836
837 release_sock(sk);
838 nfc_llcp_sock_put(llcp_sock);
839}
840
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100841static void nfc_llcp_recv_cc(struct nfc_llcp_local *local, struct sk_buff *skb)
Samuel Ortizd6469602011-12-14 16:43:12 +0100842{
843 struct nfc_llcp_sock *llcp_sock;
Samuel Ortizff353d82012-05-07 12:31:19 +0200844 struct sock *sk;
Samuel Ortizd6469602011-12-14 16:43:12 +0100845 u8 dsap, ssap;
846
Samuel Ortizd6469602011-12-14 16:43:12 +0100847 dsap = nfc_llcp_dsap(skb);
848 ssap = nfc_llcp_ssap(skb);
849
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200850 llcp_sock = nfc_llcp_connecting_sock_get(local, dsap);
Samuel Ortizd6469602011-12-14 16:43:12 +0100851 if (llcp_sock == NULL) {
852 pr_err("Invalid CC\n");
853 nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN);
854
855 return;
856 }
857
Samuel Ortizff353d82012-05-07 12:31:19 +0200858 sk = &llcp_sock->sk;
Samuel Ortizd6469602011-12-14 16:43:12 +0100859
Samuel Ortiza69f32a2012-05-04 17:04:19 +0200860 /* Unlink from connecting and link to the client array */
861 nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
862 nfc_llcp_sock_link(&local->sockets, sk);
863 llcp_sock->dsap = ssap;
864
Samuel Ortiz7a06e582012-05-07 22:03:34 +0200865 nfc_llcp_parse_connection_tlv(llcp_sock, &skb->data[LLCP_HEADER_SIZE],
866 skb->len - LLCP_HEADER_SIZE);
Samuel Ortizd6469602011-12-14 16:43:12 +0100867
Samuel Ortizff353d82012-05-07 12:31:19 +0200868 sk->sk_state = LLCP_CONNECTED;
869 sk->sk_state_change(sk);
870
Samuel Ortizd6469602011-12-14 16:43:12 +0100871 nfc_llcp_sock_put(llcp_sock);
872}
873
874static void nfc_llcp_rx_work(struct work_struct *work)
875{
876 struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100877 rx_work);
Samuel Ortizd6469602011-12-14 16:43:12 +0100878 u8 dsap, ssap, ptype;
879 struct sk_buff *skb;
880
881 skb = local->rx_pending;
882 if (skb == NULL) {
883 pr_debug("No pending SKB\n");
884 return;
885 }
886
887 ptype = nfc_llcp_ptype(skb);
888 dsap = nfc_llcp_dsap(skb);
889 ssap = nfc_llcp_ssap(skb);
890
891 pr_debug("ptype 0x%x dsap 0x%x ssap 0x%x\n", ptype, dsap, ssap);
892
Samuel Ortiz4be646e2012-04-10 19:43:13 +0200893 if (ptype != LLCP_PDU_SYMM)
894 print_hex_dump(KERN_DEBUG, "LLCP Rx: ", DUMP_PREFIX_OFFSET,
895 16, 1, skb->data, skb->len, true);
896
Samuel Ortizd6469602011-12-14 16:43:12 +0100897 switch (ptype) {
898 case LLCP_PDU_SYMM:
899 pr_debug("SYMM\n");
900 break;
901
902 case LLCP_PDU_CONNECT:
903 pr_debug("CONNECT\n");
904 nfc_llcp_recv_connect(local, skb);
905 break;
906
907 case LLCP_PDU_DISC:
908 pr_debug("DISC\n");
909 nfc_llcp_recv_disc(local, skb);
910 break;
911
912 case LLCP_PDU_CC:
913 pr_debug("CC\n");
914 nfc_llcp_recv_cc(local, skb);
915 break;
916
917 case LLCP_PDU_I:
918 case LLCP_PDU_RR:
Samuel Ortiz53aef922012-03-05 01:03:36 +0100919 case LLCP_PDU_RNR:
Samuel Ortizd6469602011-12-14 16:43:12 +0100920 pr_debug("I frame\n");
921 nfc_llcp_recv_hdlc(local, skb);
922 break;
923
924 }
925
926 queue_work(local->tx_wq, &local->tx_work);
927 kfree_skb(local->rx_pending);
928 local->rx_pending = NULL;
929
930 return;
931}
932
933void nfc_llcp_recv(void *data, struct sk_buff *skb, int err)
934{
935 struct nfc_llcp_local *local = (struct nfc_llcp_local *) data;
936
937 pr_debug("Received an LLCP PDU\n");
938 if (err < 0) {
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100939 pr_err("err %d\n", err);
Samuel Ortizd6469602011-12-14 16:43:12 +0100940 return;
941 }
942
943 local->rx_pending = skb_get(skb);
944 del_timer(&local->link_timer);
945 queue_work(local->rx_wq, &local->rx_work);
946
947 return;
948}
949
Samuel Ortiz73167ce2012-05-31 00:05:50 +0200950int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb)
951{
952 struct nfc_llcp_local *local;
953
954 local = nfc_llcp_find_local(dev);
955 if (local == NULL)
956 return -ENODEV;
957
958 local->rx_pending = skb_get(skb);
959 del_timer(&local->link_timer);
960 queue_work(local->rx_wq, &local->rx_work);
961
962 return 0;
963}
964
Samuel Ortizd6469602011-12-14 16:43:12 +0100965void nfc_llcp_mac_is_down(struct nfc_dev *dev)
966{
967 struct nfc_llcp_local *local;
968
969 local = nfc_llcp_find_local(dev);
970 if (local == NULL)
971 return;
972
973 /* Close and purge all existing sockets */
Samuel Ortiz4d22ea12012-06-22 14:40:34 +0200974 nfc_llcp_socket_release(local, true);
Samuel Ortizd6469602011-12-14 16:43:12 +0100975}
976
977void nfc_llcp_mac_is_up(struct nfc_dev *dev, u32 target_idx,
978 u8 comm_mode, u8 rf_mode)
979{
980 struct nfc_llcp_local *local;
981
982 pr_debug("rf mode %d\n", rf_mode);
983
984 local = nfc_llcp_find_local(dev);
985 if (local == NULL)
986 return;
987
988 local->target_idx = target_idx;
989 local->comm_mode = comm_mode;
990 local->rf_mode = rf_mode;
991
992 if (rf_mode == NFC_RF_INITIATOR) {
993 pr_debug("Queueing Tx work\n");
994
995 queue_work(local->tx_wq, &local->tx_work);
996 } else {
997 mod_timer(&local->link_timer,
Samuel Ortiz427a2eb2012-03-05 01:03:52 +0100998 jiffies + msecs_to_jiffies(local->remote_lto));
Samuel Ortizd6469602011-12-14 16:43:12 +0100999 }
1000}
1001
1002int nfc_llcp_register_device(struct nfc_dev *ndev)
1003{
1004 struct device *dev = &ndev->dev;
1005 struct nfc_llcp_local *local;
1006 char name[32];
1007 int err;
1008
1009 local = kzalloc(sizeof(struct nfc_llcp_local), GFP_KERNEL);
1010 if (local == NULL)
1011 return -ENOMEM;
1012
1013 local->dev = ndev;
1014 INIT_LIST_HEAD(&local->list);
Samuel Ortizc7aa1222012-05-04 11:24:16 +02001015 kref_init(&local->ref);
Samuel Ortizd6469602011-12-14 16:43:12 +01001016 mutex_init(&local->sdp_lock);
Samuel Ortizd6469602011-12-14 16:43:12 +01001017 init_timer(&local->link_timer);
1018 local->link_timer.data = (unsigned long) local;
1019 local->link_timer.function = nfc_llcp_symm_timer;
1020
1021 skb_queue_head_init(&local->tx_queue);
1022 INIT_WORK(&local->tx_work, nfc_llcp_tx_work);
1023 snprintf(name, sizeof(name), "%s_llcp_tx_wq", dev_name(dev));
Samuel Ortiz427a2eb2012-03-05 01:03:52 +01001024 local->tx_wq =
1025 alloc_workqueue(name,
1026 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_MEM_RECLAIM,
1027 1);
Samuel Ortizd6469602011-12-14 16:43:12 +01001028 if (local->tx_wq == NULL) {
1029 err = -ENOMEM;
1030 goto err_local;
1031 }
1032
1033 local->rx_pending = NULL;
1034 INIT_WORK(&local->rx_work, nfc_llcp_rx_work);
1035 snprintf(name, sizeof(name), "%s_llcp_rx_wq", dev_name(dev));
Samuel Ortiz427a2eb2012-03-05 01:03:52 +01001036 local->rx_wq =
1037 alloc_workqueue(name,
1038 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_MEM_RECLAIM,
1039 1);
Samuel Ortizd6469602011-12-14 16:43:12 +01001040 if (local->rx_wq == NULL) {
1041 err = -ENOMEM;
1042 goto err_tx_wq;
1043 }
1044
1045 INIT_WORK(&local->timeout_work, nfc_llcp_timeout_work);
1046 snprintf(name, sizeof(name), "%s_llcp_timeout_wq", dev_name(dev));
Samuel Ortiz427a2eb2012-03-05 01:03:52 +01001047 local->timeout_wq =
1048 alloc_workqueue(name,
1049 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_MEM_RECLAIM,
1050 1);
Samuel Ortizd6469602011-12-14 16:43:12 +01001051 if (local->timeout_wq == NULL) {
1052 err = -ENOMEM;
1053 goto err_rx_wq;
1054 }
1055
Samuel Ortiza69f32a2012-05-04 17:04:19 +02001056 local->sockets.lock = __RW_LOCK_UNLOCKED(local->sockets.lock);
1057 local->connecting_sockets.lock = __RW_LOCK_UNLOCKED(local->connecting_sockets.lock);
1058
Samuel Ortizd6469602011-12-14 16:43:12 +01001059 nfc_llcp_build_gb(local);
1060
1061 local->remote_miu = LLCP_DEFAULT_MIU;
1062 local->remote_lto = LLCP_DEFAULT_LTO;
Samuel Ortizd6469602011-12-14 16:43:12 +01001063
1064 list_add(&llcp_devices, &local->list);
1065
1066 return 0;
1067
1068err_rx_wq:
1069 destroy_workqueue(local->rx_wq);
1070
1071err_tx_wq:
1072 destroy_workqueue(local->tx_wq);
1073
1074err_local:
1075 kfree(local);
1076
1077 return 0;
1078}
1079
1080void nfc_llcp_unregister_device(struct nfc_dev *dev)
1081{
1082 struct nfc_llcp_local *local = nfc_llcp_find_local(dev);
1083
1084 if (local == NULL) {
1085 pr_debug("No such device\n");
1086 return;
1087 }
1088
Samuel Ortizc7aa1222012-05-04 11:24:16 +02001089 nfc_llcp_local_put(local);
Samuel Ortizd6469602011-12-14 16:43:12 +01001090}
1091
1092int __init nfc_llcp_init(void)
1093{
1094 INIT_LIST_HEAD(&llcp_devices);
1095
1096 return nfc_llcp_sock_init();
1097}
1098
1099void nfc_llcp_exit(void)
1100{
1101 nfc_llcp_sock_exit();
1102}