2 * Copyright (C) 2011 Intel Corporation. All rights reserved.
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.
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.
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.
20 #define pr_fmt(fmt) "llcp: %s: " fmt, __func__
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/list.h>
25 #include <linux/nfc.h>
30 static u8 llcp_magic
[3] = {0x46, 0x66, 0x6d};
32 static struct list_head llcp_devices
;
34 static void nfc_llcp_socket_release(struct nfc_llcp_local
*local
)
36 struct nfc_llcp_sock
*parent
, *s
, *n
;
37 struct sock
*sk
, *parent_sk
;
41 mutex_lock(&local
->socket_lock
);
43 for (i
= 0; i
< LLCP_MAX_SAP
; i
++) {
44 parent
= local
->sockets
[i
];
48 /* Release all child sockets */
49 list_for_each_entry_safe(s
, n
, &parent
->list
, list
) {
55 if (sk
->sk_state
== LLCP_CONNECTED
)
56 nfc_put_device(s
->dev
);
58 sk
->sk_state
= LLCP_CLOSED
;
59 sock_set_flag(sk
, SOCK_DEAD
);
64 parent_sk
= &parent
->sk
;
68 if (parent_sk
->sk_state
== LLCP_LISTEN
) {
69 struct nfc_llcp_sock
*lsk
, *n
;
70 struct sock
*accept_sk
;
72 list_for_each_entry_safe(lsk
, n
, &parent
->accept_queue
,
77 nfc_llcp_accept_unlink(accept_sk
);
79 accept_sk
->sk_state
= LLCP_CLOSED
;
80 sock_set_flag(accept_sk
, SOCK_DEAD
);
82 release_sock(accept_sk
);
84 sock_orphan(accept_sk
);
88 if (parent_sk
->sk_state
== LLCP_CONNECTED
)
89 nfc_put_device(parent
->dev
);
91 parent_sk
->sk_state
= LLCP_CLOSED
;
92 sock_set_flag(parent_sk
, SOCK_DEAD
);
94 release_sock(parent_sk
);
97 mutex_unlock(&local
->socket_lock
);
100 static void nfc_llcp_timeout_work(struct work_struct
*work
)
102 struct nfc_llcp_local
*local
= container_of(work
, struct nfc_llcp_local
,
105 nfc_dep_link_down(local
->dev
);
108 static void nfc_llcp_symm_timer(unsigned long data
)
110 struct nfc_llcp_local
*local
= (struct nfc_llcp_local
*) data
;
112 pr_err("SYMM timeout\n");
114 queue_work(local
->timeout_wq
, &local
->timeout_work
);
117 struct nfc_llcp_local
*nfc_llcp_find_local(struct nfc_dev
*dev
)
119 struct nfc_llcp_local
*local
, *n
;
121 list_for_each_entry_safe(local
, n
, &llcp_devices
, list
)
122 if (local
->dev
== dev
)
125 pr_debug("No device found\n");
130 static char *wks
[] = {
138 static int nfc_llcp_wks_sap(char *service_name
, size_t service_name_len
)
142 pr_debug("%s\n", service_name
);
144 if (service_name
== NULL
)
147 num_wks
= ARRAY_SIZE(wks
);
149 for (sap
= 0 ; sap
< num_wks
; sap
++) {
150 if (wks
[sap
] == NULL
)
153 if (strncmp(wks
[sap
], service_name
, service_name_len
) == 0)
160 u8
nfc_llcp_get_sdp_ssap(struct nfc_llcp_local
*local
,
161 struct nfc_llcp_sock
*sock
)
163 mutex_lock(&local
->sdp_lock
);
165 if (sock
->service_name
!= NULL
&& sock
->service_name_len
> 0) {
166 int ssap
= nfc_llcp_wks_sap(sock
->service_name
,
167 sock
->service_name_len
);
170 pr_debug("WKS %d\n", ssap
);
172 /* This is a WKS, let's check if it's free */
173 if (local
->local_wks
& BIT(ssap
)) {
174 mutex_unlock(&local
->sdp_lock
);
179 set_bit(BIT(ssap
), &local
->local_wks
);
180 mutex_unlock(&local
->sdp_lock
);
186 * This is not a well known service,
187 * we should try to find a local SDP free spot
189 ssap
= find_first_zero_bit(&local
->local_sdp
, LLCP_SDP_NUM_SAP
);
190 if (ssap
== LLCP_SDP_NUM_SAP
) {
191 mutex_unlock(&local
->sdp_lock
);
196 pr_debug("SDP ssap %d\n", LLCP_WKS_NUM_SAP
+ ssap
);
198 set_bit(BIT(ssap
), &local
->local_sdp
);
199 mutex_unlock(&local
->sdp_lock
);
201 return LLCP_WKS_NUM_SAP
+ ssap
;
203 } else if (sock
->ssap
!= 0) {
204 if (sock
->ssap
< LLCP_WKS_NUM_SAP
) {
205 if (!(local
->local_wks
& BIT(sock
->ssap
))) {
206 set_bit(BIT(sock
->ssap
), &local
->local_wks
);
207 mutex_unlock(&local
->sdp_lock
);
212 } else if (sock
->ssap
< LLCP_SDP_NUM_SAP
) {
213 if (!(local
->local_sdp
&
214 BIT(sock
->ssap
- LLCP_WKS_NUM_SAP
))) {
215 set_bit(BIT(sock
->ssap
- LLCP_WKS_NUM_SAP
),
217 mutex_unlock(&local
->sdp_lock
);
224 mutex_unlock(&local
->sdp_lock
);
229 u8
nfc_llcp_get_local_ssap(struct nfc_llcp_local
*local
)
233 mutex_lock(&local
->sdp_lock
);
235 local_ssap
= find_first_zero_bit(&local
->local_sap
, LLCP_LOCAL_NUM_SAP
);
236 if (local_ssap
== LLCP_LOCAL_NUM_SAP
) {
237 mutex_unlock(&local
->sdp_lock
);
241 set_bit(BIT(local_ssap
), &local
->local_sap
);
243 mutex_unlock(&local
->sdp_lock
);
245 return local_ssap
+ LLCP_LOCAL_SAP_OFFSET
;
248 void nfc_llcp_put_ssap(struct nfc_llcp_local
*local
, u8 ssap
)
253 if (ssap
< LLCP_WKS_NUM_SAP
) {
255 sdp
= &local
->local_wks
;
256 } else if (ssap
< LLCP_LOCAL_NUM_SAP
) {
257 local_ssap
= ssap
- LLCP_WKS_NUM_SAP
;
258 sdp
= &local
->local_sdp
;
259 } else if (ssap
< LLCP_MAX_SAP
) {
260 local_ssap
= ssap
- LLCP_LOCAL_NUM_SAP
;
261 sdp
= &local
->local_sap
;
266 mutex_lock(&local
->sdp_lock
);
268 clear_bit(1 << local_ssap
, sdp
);
270 mutex_unlock(&local
->sdp_lock
);
273 u8
*nfc_llcp_general_bytes(struct nfc_dev
*dev
, u8
*general_bytes_len
)
275 struct nfc_llcp_local
*local
;
277 local
= nfc_llcp_find_local(dev
);
279 *general_bytes_len
= 0;
283 *general_bytes_len
= local
->gb_len
;
288 static int nfc_llcp_build_gb(struct nfc_llcp_local
*local
)
290 u8
*gb_cur
, *version_tlv
, version
, version_length
;
291 u8
*lto_tlv
, lto
, lto_length
;
292 u8
*wks_tlv
, wks_length
;
295 version
= LLCP_VERSION_11
;
296 version_tlv
= nfc_llcp_build_tlv(LLCP_TLV_VERSION
, &version
,
298 gb_len
+= version_length
;
302 lto_tlv
= nfc_llcp_build_tlv(LLCP_TLV_VERSION
, <o
, 1, <o_length
);
303 gb_len
+= lto_length
;
305 pr_debug("Local wks 0x%lx\n", local
->local_wks
);
306 wks_tlv
= nfc_llcp_build_tlv(LLCP_TLV_WKS
, (u8
*)&local
->local_wks
, 2,
308 gb_len
+= wks_length
;
310 gb_len
+= ARRAY_SIZE(llcp_magic
);
312 if (gb_len
> NFC_MAX_GT_LEN
) {
319 memcpy(gb_cur
, llcp_magic
, ARRAY_SIZE(llcp_magic
));
320 gb_cur
+= ARRAY_SIZE(llcp_magic
);
322 memcpy(gb_cur
, version_tlv
, version_length
);
323 gb_cur
+= version_length
;
325 memcpy(gb_cur
, lto_tlv
, lto_length
);
326 gb_cur
+= lto_length
;
328 memcpy(gb_cur
, wks_tlv
, wks_length
);
329 gb_cur
+= wks_length
;
334 local
->gb_len
= gb_len
;
339 int nfc_llcp_set_remote_gb(struct nfc_dev
*dev
, u8
*gb
, u8 gb_len
)
341 struct nfc_llcp_local
*local
= nfc_llcp_find_local(dev
);
344 pr_err("No LLCP device\n");
348 memset(local
->remote_gb
, 0, NFC_MAX_GT_LEN
);
349 memcpy(local
->remote_gb
, gb
, gb_len
);
350 local
->remote_gb_len
= gb_len
;
352 if (local
->remote_gb
== NULL
||
353 local
->remote_gb_len
== 0)
356 if (memcmp(local
->remote_gb
, llcp_magic
, 3)) {
357 pr_err("MAC does not support LLCP\n");
361 return nfc_llcp_parse_tlv(local
,
362 &local
->remote_gb
[3], local
->remote_gb_len
- 3);
365 static void nfc_llcp_tx_work(struct work_struct
*work
)
367 struct nfc_llcp_local
*local
= container_of(work
, struct nfc_llcp_local
,
371 skb
= skb_dequeue(&local
->tx_queue
);
373 pr_debug("Sending pending skb\n");
374 nfc_data_exchange(local
->dev
, local
->target_idx
,
375 skb
, nfc_llcp_recv
, local
);
377 nfc_llcp_send_symm(local
->dev
);
380 mod_timer(&local
->link_timer
,
381 jiffies
+ msecs_to_jiffies(local
->remote_lto
));
384 static u8
nfc_llcp_dsap(struct sk_buff
*pdu
)
386 return (pdu
->data
[0] & 0xfc) >> 2;
389 static u8
nfc_llcp_ptype(struct sk_buff
*pdu
)
391 return ((pdu
->data
[0] & 0x03) << 2) | ((pdu
->data
[1] & 0xc0) >> 6);
394 static u8
nfc_llcp_ssap(struct sk_buff
*pdu
)
396 return pdu
->data
[1] & 0x3f;
399 static u8
nfc_llcp_ns(struct sk_buff
*pdu
)
401 return pdu
->data
[2] >> 4;
404 static u8
nfc_llcp_nr(struct sk_buff
*pdu
)
406 return pdu
->data
[2] & 0xf;
409 static void nfc_llcp_set_nrns(struct nfc_llcp_sock
*sock
, struct sk_buff
*pdu
)
411 pdu
->data
[2] = (sock
->send_n
<< 4) | ((sock
->recv_n
- 1) % 16);
412 sock
->send_n
= (sock
->send_n
+ 1) % 16;
413 sock
->recv_ack_n
= (sock
->recv_n
- 1) % 16;
416 static struct nfc_llcp_sock
*nfc_llcp_sock_get(struct nfc_llcp_local
*local
,
419 struct nfc_llcp_sock
*sock
, *llcp_sock
, *n
;
421 if (ssap
== 0 && dsap
== 0)
424 mutex_lock(&local
->socket_lock
);
425 sock
= local
->sockets
[ssap
];
427 mutex_unlock(&local
->socket_lock
);
431 pr_debug("root dsap %d (%d)\n", sock
->dsap
, dsap
);
433 if (sock
->dsap
== dsap
) {
434 sock_hold(&sock
->sk
);
435 mutex_unlock(&local
->socket_lock
);
439 list_for_each_entry_safe(llcp_sock
, n
, &sock
->list
, list
) {
440 pr_debug("llcp_sock %p sk %p dsap %d\n", llcp_sock
,
441 &llcp_sock
->sk
, llcp_sock
->dsap
);
442 if (llcp_sock
->dsap
== dsap
) {
443 sock_hold(&llcp_sock
->sk
);
444 mutex_unlock(&local
->socket_lock
);
449 pr_err("Could not find socket for %d %d\n", ssap
, dsap
);
451 mutex_unlock(&local
->socket_lock
);
456 static void nfc_llcp_sock_put(struct nfc_llcp_sock
*sock
)
461 static u8
*nfc_llcp_connect_sn(struct sk_buff
*skb
, size_t *sn_len
)
463 u8
*tlv
= &skb
->data
[2], type
, length
;
464 size_t tlv_array_len
= skb
->len
- LLCP_HEADER_SIZE
, offset
= 0;
466 while (offset
< tlv_array_len
) {
470 pr_debug("type 0x%x length %d\n", type
, length
);
472 if (type
== LLCP_TLV_SN
) {
477 offset
+= length
+ 2;
484 static void nfc_llcp_recv_connect(struct nfc_llcp_local
*local
,
487 struct sock
*new_sk
, *parent
;
488 struct nfc_llcp_sock
*sock
, *new_sock
;
489 u8 dsap
, ssap
, bound_sap
, reason
;
491 dsap
= nfc_llcp_dsap(skb
);
492 ssap
= nfc_llcp_ssap(skb
);
494 pr_debug("%d %d\n", dsap
, ssap
);
496 nfc_llcp_parse_tlv(local
, &skb
->data
[LLCP_HEADER_SIZE
],
497 skb
->len
- LLCP_HEADER_SIZE
);
499 if (dsap
!= LLCP_SAP_SDP
) {
502 mutex_lock(&local
->socket_lock
);
503 sock
= local
->sockets
[dsap
];
505 mutex_unlock(&local
->socket_lock
);
506 reason
= LLCP_DM_NOBOUND
;
510 sock_hold(&sock
->sk
);
511 mutex_unlock(&local
->socket_lock
);
513 lock_sock(&sock
->sk
);
515 if (sock
->dsap
== LLCP_SAP_SDP
&&
516 sock
->sk
.sk_state
== LLCP_LISTEN
)
522 sn
= nfc_llcp_connect_sn(skb
, &sn_len
);
524 reason
= LLCP_DM_NOBOUND
;
528 pr_debug("Service name length %zu\n", sn_len
);
530 mutex_lock(&local
->socket_lock
);
531 for (bound_sap
= 0; bound_sap
< LLCP_LOCAL_SAP_OFFSET
;
533 sock
= local
->sockets
[bound_sap
];
537 if (sock
->service_name
== NULL
||
538 sock
->service_name_len
== 0)
541 if (sock
->service_name_len
!= sn_len
)
544 if (sock
->dsap
== LLCP_SAP_SDP
&&
545 sock
->sk
.sk_state
== LLCP_LISTEN
&&
546 !memcmp(sn
, sock
->service_name
, sn_len
)) {
547 pr_debug("Found service name at SAP %d\n",
549 sock_hold(&sock
->sk
);
550 mutex_unlock(&local
->socket_lock
);
552 lock_sock(&sock
->sk
);
557 mutex_unlock(&local
->socket_lock
);
560 reason
= LLCP_DM_NOBOUND
;
566 if (sk_acceptq_is_full(parent
)) {
567 reason
= LLCP_DM_REJ
;
568 release_sock(&sock
->sk
);
573 new_sk
= nfc_llcp_sock_alloc(NULL
, parent
->sk_type
,
575 if (new_sk
== NULL
) {
576 reason
= LLCP_DM_REJ
;
577 release_sock(&sock
->sk
);
582 new_sock
= nfc_llcp_sock(new_sk
);
583 new_sock
->dev
= local
->dev
;
584 new_sock
->local
= local
;
585 new_sock
->nfc_protocol
= sock
->nfc_protocol
;
586 new_sock
->ssap
= bound_sap
;
587 new_sock
->dsap
= ssap
;
588 new_sock
->parent
= parent
;
590 pr_debug("new sock %p sk %p\n", new_sock
, &new_sock
->sk
);
592 list_add_tail(&new_sock
->list
, &sock
->list
);
594 nfc_llcp_accept_enqueue(&sock
->sk
, new_sk
);
596 nfc_get_device(local
->dev
->idx
);
598 new_sk
->sk_state
= LLCP_CONNECTED
;
600 /* Wake the listening processes */
601 parent
->sk_data_ready(parent
, 0);
604 nfc_llcp_send_cc(new_sock
);
606 release_sock(&sock
->sk
);
613 nfc_llcp_send_dm(local
, dsap
, ssap
, reason
);
619 static void nfc_llcp_recv_hdlc(struct nfc_llcp_local
*local
,
622 struct nfc_llcp_sock
*llcp_sock
;
624 u8 dsap
, ssap
, ptype
, ns
, nr
;
626 ptype
= nfc_llcp_ptype(skb
);
627 dsap
= nfc_llcp_dsap(skb
);
628 ssap
= nfc_llcp_ssap(skb
);
629 ns
= nfc_llcp_ns(skb
);
630 nr
= nfc_llcp_nr(skb
);
632 pr_debug("%d %d R %d S %d\n", dsap
, ssap
, nr
, ns
);
634 llcp_sock
= nfc_llcp_sock_get(local
, dsap
, ssap
);
635 if (llcp_sock
== NULL
) {
636 nfc_llcp_send_dm(local
, dsap
, ssap
, LLCP_DM_NOCONN
);
642 if (sk
->sk_state
== LLCP_CLOSED
) {
644 nfc_llcp_sock_put(llcp_sock
);
647 if (ns
== llcp_sock
->recv_n
)
648 llcp_sock
->recv_n
= (llcp_sock
->recv_n
+ 1) % 16;
650 pr_err("Received out of sequence I PDU\n");
652 /* Pass the payload upstream */
653 if (ptype
== LLCP_PDU_I
) {
654 pr_debug("I frame, queueing on %p\n", &llcp_sock
->sk
);
656 skb_pull(skb
, LLCP_HEADER_SIZE
+ LLCP_SEQUENCE_SIZE
);
657 if (sock_queue_rcv_skb(&llcp_sock
->sk
, skb
)) {
658 pr_err("receive queue is full\n");
659 skb_queue_head(&llcp_sock
->tx_backlog_queue
, skb
);
663 /* Remove skbs from the pending queue */
664 if (llcp_sock
->send_ack_n
!= nr
) {
665 struct sk_buff
*s
, *tmp
;
667 llcp_sock
->send_ack_n
= nr
;
669 skb_queue_walk_safe(&llcp_sock
->tx_pending_queue
, s
, tmp
)
670 if (nfc_llcp_ns(s
) <= nr
) {
671 skb_unlink(s
, &llcp_sock
->tx_pending_queue
);
676 /* Queue some I frames for transmission */
677 while (llcp_sock
->remote_ready
&&
678 skb_queue_len(&llcp_sock
->tx_pending_queue
) <= local
->remote_rw
) {
679 struct sk_buff
*pdu
, *pending_pdu
;
681 pdu
= skb_dequeue(&llcp_sock
->tx_queue
);
685 /* Update N(S)/N(R) */
686 nfc_llcp_set_nrns(llcp_sock
, pdu
);
688 pending_pdu
= skb_clone(pdu
, GFP_KERNEL
);
690 skb_queue_tail(&local
->tx_queue
, pdu
);
691 skb_queue_tail(&llcp_sock
->tx_pending_queue
, pending_pdu
);
695 nfc_llcp_sock_put(llcp_sock
);
698 static void nfc_llcp_recv_disc(struct nfc_llcp_local
*local
,
701 struct nfc_llcp_sock
*llcp_sock
;
705 dsap
= nfc_llcp_dsap(skb
);
706 ssap
= nfc_llcp_ssap(skb
);
708 llcp_sock
= nfc_llcp_sock_get(local
, dsap
, ssap
);
709 if (llcp_sock
== NULL
) {
710 nfc_llcp_send_dm(local
, dsap
, ssap
, LLCP_DM_NOCONN
);
716 if (sk
->sk_state
== LLCP_CLOSED
) {
718 nfc_llcp_sock_put(llcp_sock
);
722 if (sk
->sk_state
== LLCP_CONNECTED
) {
723 nfc_put_device(local
->dev
);
724 sk
->sk_state
= LLCP_CLOSED
;
725 sk
->sk_state_change(sk
);
728 nfc_llcp_send_dm(local
, dsap
, ssap
, LLCP_DM_DISC
);
731 nfc_llcp_sock_put(llcp_sock
);
734 static void nfc_llcp_recv_cc(struct nfc_llcp_local
*local
,
737 struct nfc_llcp_sock
*llcp_sock
;
741 dsap
= nfc_llcp_dsap(skb
);
742 ssap
= nfc_llcp_ssap(skb
);
744 llcp_sock
= nfc_llcp_sock_get(local
, dsap
, ssap
);
746 if (llcp_sock
== NULL
)
747 llcp_sock
= nfc_llcp_sock_get(local
, dsap
, LLCP_SAP_SDP
);
749 if (llcp_sock
== NULL
) {
750 pr_err("Invalid CC\n");
751 nfc_llcp_send_dm(local
, dsap
, ssap
, LLCP_DM_NOCONN
);
756 llcp_sock
->dsap
= ssap
;
758 nfc_llcp_parse_tlv(local
, &skb
->data
[LLCP_HEADER_SIZE
],
759 skb
->len
- LLCP_HEADER_SIZE
);
761 nfc_llcp_sock_put(llcp_sock
);
764 static void nfc_llcp_rx_work(struct work_struct
*work
)
766 struct nfc_llcp_local
*local
= container_of(work
, struct nfc_llcp_local
,
768 u8 dsap
, ssap
, ptype
;
771 skb
= local
->rx_pending
;
773 pr_debug("No pending SKB\n");
777 ptype
= nfc_llcp_ptype(skb
);
778 dsap
= nfc_llcp_dsap(skb
);
779 ssap
= nfc_llcp_ssap(skb
);
781 pr_debug("ptype 0x%x dsap 0x%x ssap 0x%x\n", ptype
, dsap
, ssap
);
788 case LLCP_PDU_CONNECT
:
789 pr_debug("CONNECT\n");
790 nfc_llcp_recv_connect(local
, skb
);
795 nfc_llcp_recv_disc(local
, skb
);
800 nfc_llcp_recv_cc(local
, skb
);
805 pr_debug("I frame\n");
806 nfc_llcp_recv_hdlc(local
, skb
);
811 queue_work(local
->tx_wq
, &local
->tx_work
);
812 kfree_skb(local
->rx_pending
);
813 local
->rx_pending
= NULL
;
818 void nfc_llcp_recv(void *data
, struct sk_buff
*skb
, int err
)
820 struct nfc_llcp_local
*local
= (struct nfc_llcp_local
*) data
;
822 pr_debug("Received an LLCP PDU\n");
824 pr_err("err %d", err
);
828 local
->rx_pending
= skb_get(skb
);
829 del_timer(&local
->link_timer
);
830 queue_work(local
->rx_wq
, &local
->rx_work
);
835 void nfc_llcp_mac_is_down(struct nfc_dev
*dev
)
837 struct nfc_llcp_local
*local
;
839 local
= nfc_llcp_find_local(dev
);
843 /* Close and purge all existing sockets */
844 nfc_llcp_socket_release(local
);
847 void nfc_llcp_mac_is_up(struct nfc_dev
*dev
, u32 target_idx
,
848 u8 comm_mode
, u8 rf_mode
)
850 struct nfc_llcp_local
*local
;
852 pr_debug("rf mode %d\n", rf_mode
);
854 local
= nfc_llcp_find_local(dev
);
858 local
->target_idx
= target_idx
;
859 local
->comm_mode
= comm_mode
;
860 local
->rf_mode
= rf_mode
;
862 if (rf_mode
== NFC_RF_INITIATOR
) {
863 pr_debug("Queueing Tx work\n");
865 queue_work(local
->tx_wq
, &local
->tx_work
);
867 mod_timer(&local
->link_timer
,
868 jiffies
+ msecs_to_jiffies(local
->remote_lto
));
872 int nfc_llcp_register_device(struct nfc_dev
*ndev
)
874 struct device
*dev
= &ndev
->dev
;
875 struct nfc_llcp_local
*local
;
879 local
= kzalloc(sizeof(struct nfc_llcp_local
), GFP_KERNEL
);
884 INIT_LIST_HEAD(&local
->list
);
885 mutex_init(&local
->sdp_lock
);
886 mutex_init(&local
->socket_lock
);
887 init_timer(&local
->link_timer
);
888 local
->link_timer
.data
= (unsigned long) local
;
889 local
->link_timer
.function
= nfc_llcp_symm_timer
;
891 skb_queue_head_init(&local
->tx_queue
);
892 INIT_WORK(&local
->tx_work
, nfc_llcp_tx_work
);
893 snprintf(name
, sizeof(name
), "%s_llcp_tx_wq", dev_name(dev
));
894 local
->tx_wq
= alloc_workqueue(name
,
895 WQ_NON_REENTRANT
| WQ_UNBOUND
| WQ_MEM_RECLAIM
, 1);
896 if (local
->tx_wq
== NULL
) {
901 local
->rx_pending
= NULL
;
902 INIT_WORK(&local
->rx_work
, nfc_llcp_rx_work
);
903 snprintf(name
, sizeof(name
), "%s_llcp_rx_wq", dev_name(dev
));
904 local
->rx_wq
= alloc_workqueue(name
,
905 WQ_NON_REENTRANT
| WQ_UNBOUND
| WQ_MEM_RECLAIM
, 1);
906 if (local
->rx_wq
== NULL
) {
911 INIT_WORK(&local
->timeout_work
, nfc_llcp_timeout_work
);
912 snprintf(name
, sizeof(name
), "%s_llcp_timeout_wq", dev_name(dev
));
913 local
->timeout_wq
= alloc_workqueue(name
,
914 WQ_NON_REENTRANT
| WQ_UNBOUND
| WQ_MEM_RECLAIM
, 1);
915 if (local
->timeout_wq
== NULL
) {
920 nfc_llcp_build_gb(local
);
922 local
->remote_miu
= LLCP_DEFAULT_MIU
;
923 local
->remote_lto
= LLCP_DEFAULT_LTO
;
924 local
->remote_rw
= LLCP_DEFAULT_RW
;
926 list_add(&llcp_devices
, &local
->list
);
931 destroy_workqueue(local
->rx_wq
);
934 destroy_workqueue(local
->tx_wq
);
942 void nfc_llcp_unregister_device(struct nfc_dev
*dev
)
944 struct nfc_llcp_local
*local
= nfc_llcp_find_local(dev
);
947 pr_debug("No such device\n");
951 list_del(&local
->list
);
952 nfc_llcp_socket_release(local
);
953 del_timer_sync(&local
->link_timer
);
954 skb_queue_purge(&local
->tx_queue
);
955 destroy_workqueue(local
->tx_wq
);
956 destroy_workqueue(local
->rx_wq
);
957 kfree_skb(local
->rx_pending
);
961 int __init
nfc_llcp_init(void)
963 INIT_LIST_HEAD(&llcp_devices
);
965 return nfc_llcp_sock_init();
968 void nfc_llcp_exit(void)
970 nfc_llcp_sock_exit();