NFC: Implement pn533 target mode polling loop
[deliverable/linux.git] / drivers / nfc / pn533.c
1 /*
2 * Copyright (C) 2011 Instituto Nokia de Tecnologia
3 *
4 * Authors:
5 * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
6 * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 #include <linux/device.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/usb.h>
29 #include <linux/nfc.h>
30 #include <linux/netdevice.h>
31 #include <net/nfc/nfc.h>
32
33 #define VERSION "0.1"
34
35 #define PN533_VENDOR_ID 0x4CC
36 #define PN533_PRODUCT_ID 0x2533
37
38 #define SCM_VENDOR_ID 0x4E6
39 #define SCL3711_PRODUCT_ID 0x5591
40
41 static const struct usb_device_id pn533_table[] = {
42 { USB_DEVICE(PN533_VENDOR_ID, PN533_PRODUCT_ID) },
43 { USB_DEVICE(SCM_VENDOR_ID, SCL3711_PRODUCT_ID) },
44 { }
45 };
46 MODULE_DEVICE_TABLE(usb, pn533_table);
47
48 /* frame definitions */
49 #define PN533_FRAME_TAIL_SIZE 2
50 #define PN533_FRAME_SIZE(f) (sizeof(struct pn533_frame) + f->datalen + \
51 PN533_FRAME_TAIL_SIZE)
52 #define PN533_FRAME_ACK_SIZE (sizeof(struct pn533_frame) + 1)
53 #define PN533_FRAME_CHECKSUM(f) (f->data[f->datalen])
54 #define PN533_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1])
55
56 /* start of frame */
57 #define PN533_SOF 0x00FF
58
59 /* frame identifier: in/out/error */
60 #define PN533_FRAME_IDENTIFIER(f) (f->data[0])
61 #define PN533_DIR_OUT 0xD4
62 #define PN533_DIR_IN 0xD5
63
64 /* PN533 Commands */
65 #define PN533_FRAME_CMD(f) (f->data[1])
66 #define PN533_FRAME_CMD_PARAMS_PTR(f) (&f->data[2])
67 #define PN533_FRAME_CMD_PARAMS_LEN(f) (f->datalen - 2)
68
69 #define PN533_CMD_GET_FIRMWARE_VERSION 0x02
70 #define PN533_CMD_RF_CONFIGURATION 0x32
71 #define PN533_CMD_IN_DATA_EXCHANGE 0x40
72 #define PN533_CMD_IN_LIST_PASSIVE_TARGET 0x4A
73 #define PN533_CMD_IN_ATR 0x50
74 #define PN533_CMD_IN_RELEASE 0x52
75 #define PN533_CMD_IN_JUMP_FOR_DEP 0x56
76
77 #define PN533_CMD_TG_INIT_AS_TARGET 0x8c
78
79 #define PN533_CMD_RESPONSE(cmd) (cmd + 1)
80
81 /* PN533 Return codes */
82 #define PN533_CMD_RET_MASK 0x3F
83 #define PN533_CMD_MI_MASK 0x40
84 #define PN533_CMD_RET_SUCCESS 0x00
85
86 struct pn533;
87
88 typedef int (*pn533_cmd_complete_t) (struct pn533 *dev, void *arg,
89 u8 *params, int params_len);
90
91 /* structs for pn533 commands */
92
93 /* PN533_CMD_GET_FIRMWARE_VERSION */
94 struct pn533_fw_version {
95 u8 ic;
96 u8 ver;
97 u8 rev;
98 u8 support;
99 };
100
101 /* PN533_CMD_RF_CONFIGURATION */
102 #define PN533_CFGITEM_MAX_RETRIES 0x05
103
104 #define PN533_CONFIG_MAX_RETRIES_NO_RETRY 0x00
105 #define PN533_CONFIG_MAX_RETRIES_ENDLESS 0xFF
106
107 struct pn533_config_max_retries {
108 u8 mx_rty_atr;
109 u8 mx_rty_psl;
110 u8 mx_rty_passive_act;
111 } __packed;
112
113 /* PN533_CMD_IN_LIST_PASSIVE_TARGET */
114
115 /* felica commands opcode */
116 #define PN533_FELICA_OPC_SENSF_REQ 0
117 #define PN533_FELICA_OPC_SENSF_RES 1
118 /* felica SENSF_REQ parameters */
119 #define PN533_FELICA_SENSF_SC_ALL 0xFFFF
120 #define PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE 0
121 #define PN533_FELICA_SENSF_RC_SYSTEM_CODE 1
122 #define PN533_FELICA_SENSF_RC_ADVANCED_PROTOCOL 2
123
124 /* type B initiator_data values */
125 #define PN533_TYPE_B_AFI_ALL_FAMILIES 0
126 #define PN533_TYPE_B_POLL_METHOD_TIMESLOT 0
127 #define PN533_TYPE_B_POLL_METHOD_PROBABILISTIC 1
128
129 union pn533_cmd_poll_initdata {
130 struct {
131 u8 afi;
132 u8 polling_method;
133 } __packed type_b;
134 struct {
135 u8 opcode;
136 __be16 sc;
137 u8 rc;
138 u8 tsn;
139 } __packed felica;
140 };
141
142 /* Poll modulations */
143 enum {
144 PN533_POLL_MOD_106KBPS_A,
145 PN533_POLL_MOD_212KBPS_FELICA,
146 PN533_POLL_MOD_424KBPS_FELICA,
147 PN533_POLL_MOD_106KBPS_JEWEL,
148 PN533_POLL_MOD_847KBPS_B,
149
150 __PN533_POLL_MOD_AFTER_LAST,
151 };
152 #define PN533_POLL_MOD_MAX (__PN533_POLL_MOD_AFTER_LAST - 1)
153
154 struct pn533_poll_modulations {
155 struct {
156 u8 maxtg;
157 u8 brty;
158 union pn533_cmd_poll_initdata initiator_data;
159 } __packed data;
160 u8 len;
161 };
162
163 const struct pn533_poll_modulations poll_mod[] = {
164 [PN533_POLL_MOD_106KBPS_A] = {
165 .data = {
166 .maxtg = 1,
167 .brty = 0,
168 },
169 .len = 2,
170 },
171 [PN533_POLL_MOD_212KBPS_FELICA] = {
172 .data = {
173 .maxtg = 1,
174 .brty = 1,
175 .initiator_data.felica = {
176 .opcode = PN533_FELICA_OPC_SENSF_REQ,
177 .sc = PN533_FELICA_SENSF_SC_ALL,
178 .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE,
179 .tsn = 0,
180 },
181 },
182 .len = 7,
183 },
184 [PN533_POLL_MOD_424KBPS_FELICA] = {
185 .data = {
186 .maxtg = 1,
187 .brty = 2,
188 .initiator_data.felica = {
189 .opcode = PN533_FELICA_OPC_SENSF_REQ,
190 .sc = PN533_FELICA_SENSF_SC_ALL,
191 .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE,
192 .tsn = 0,
193 },
194 },
195 .len = 7,
196 },
197 [PN533_POLL_MOD_106KBPS_JEWEL] = {
198 .data = {
199 .maxtg = 1,
200 .brty = 4,
201 },
202 .len = 2,
203 },
204 [PN533_POLL_MOD_847KBPS_B] = {
205 .data = {
206 .maxtg = 1,
207 .brty = 8,
208 .initiator_data.type_b = {
209 .afi = PN533_TYPE_B_AFI_ALL_FAMILIES,
210 .polling_method =
211 PN533_TYPE_B_POLL_METHOD_TIMESLOT,
212 },
213 },
214 .len = 3,
215 },
216 };
217
218 /* PN533_CMD_IN_ATR */
219
220 struct pn533_cmd_activate_param {
221 u8 tg;
222 u8 next;
223 } __packed;
224
225 struct pn533_cmd_activate_response {
226 u8 status;
227 u8 nfcid3t[10];
228 u8 didt;
229 u8 bst;
230 u8 brt;
231 u8 to;
232 u8 ppt;
233 /* optional */
234 u8 gt[];
235 } __packed;
236
237 /* PN533_CMD_IN_JUMP_FOR_DEP */
238 struct pn533_cmd_jump_dep {
239 u8 active;
240 u8 baud;
241 u8 next;
242 u8 gt[];
243 } __packed;
244
245 struct pn533_cmd_jump_dep_response {
246 u8 status;
247 u8 tg;
248 u8 nfcid3t[10];
249 u8 didt;
250 u8 bst;
251 u8 brt;
252 u8 to;
253 u8 ppt;
254 /* optional */
255 u8 gt[];
256 } __packed;
257
258
259 /* PN533_TG_INIT_AS_TARGET */
260 #define PN533_INIT_TARGET_PASSIVE 0x1
261 #define PN533_INIT_TARGET_DEP 0x2
262
263 struct pn533_cmd_init_target {
264 u8 mode;
265 u8 mifare[6];
266 u8 felica[18];
267 u8 nfcid3[10];
268 u8 gb_len;
269 u8 gb[];
270 } __packed;
271
272 struct pn533_cmd_init_target_response {
273 u8 mode;
274 u8 cmd[];
275 } __packed;
276
277 struct pn533 {
278 struct usb_device *udev;
279 struct usb_interface *interface;
280 struct nfc_dev *nfc_dev;
281
282 struct urb *out_urb;
283 int out_maxlen;
284 struct pn533_frame *out_frame;
285
286 struct urb *in_urb;
287 int in_maxlen;
288 struct pn533_frame *in_frame;
289
290 struct sk_buff_head resp_q;
291
292 struct workqueue_struct *wq;
293 struct work_struct cmd_work;
294 struct work_struct mi_work;
295 struct pn533_frame *wq_in_frame;
296 int wq_in_error;
297
298 pn533_cmd_complete_t cmd_complete;
299 void *cmd_complete_arg;
300 struct semaphore cmd_lock;
301 u8 cmd;
302
303 struct pn533_poll_modulations *poll_mod_active[PN533_POLL_MOD_MAX + 1];
304 u8 poll_mod_count;
305 u8 poll_mod_curr;
306 u32 poll_protocols;
307
308 u8 tgt_available_prots;
309 u8 tgt_active_prot;
310 };
311
312 struct pn533_frame {
313 u8 preamble;
314 __be16 start_frame;
315 u8 datalen;
316 u8 datalen_checksum;
317 u8 data[];
318 } __packed;
319
320 /* The rule: value + checksum = 0 */
321 static inline u8 pn533_checksum(u8 value)
322 {
323 return ~value + 1;
324 }
325
326 /* The rule: sum(data elements) + checksum = 0 */
327 static u8 pn533_data_checksum(u8 *data, int datalen)
328 {
329 u8 sum = 0;
330 int i;
331
332 for (i = 0; i < datalen; i++)
333 sum += data[i];
334
335 return pn533_checksum(sum);
336 }
337
338 /**
339 * pn533_tx_frame_ack - create a ack frame
340 * @frame: The frame to be set as ack
341 *
342 * Ack is different type of standard frame. As a standard frame, it has
343 * preamble and start_frame. However the checksum of this frame must fail,
344 * i.e. datalen + datalen_checksum must NOT be zero. When the checksum test
345 * fails and datalen = 0 and datalen_checksum = 0xFF, the frame is a ack.
346 * After datalen_checksum field, the postamble is placed.
347 */
348 static void pn533_tx_frame_ack(struct pn533_frame *frame)
349 {
350 frame->preamble = 0;
351 frame->start_frame = cpu_to_be16(PN533_SOF);
352 frame->datalen = 0;
353 frame->datalen_checksum = 0xFF;
354 /* data[0] is used as postamble */
355 frame->data[0] = 0;
356 }
357
358 static void pn533_tx_frame_init(struct pn533_frame *frame, u8 cmd)
359 {
360 frame->preamble = 0;
361 frame->start_frame = cpu_to_be16(PN533_SOF);
362 PN533_FRAME_IDENTIFIER(frame) = PN533_DIR_OUT;
363 PN533_FRAME_CMD(frame) = cmd;
364 frame->datalen = 2;
365 }
366
367 static void pn533_tx_frame_finish(struct pn533_frame *frame)
368 {
369 frame->datalen_checksum = pn533_checksum(frame->datalen);
370
371 PN533_FRAME_CHECKSUM(frame) =
372 pn533_data_checksum(frame->data, frame->datalen);
373
374 PN533_FRAME_POSTAMBLE(frame) = 0;
375 }
376
377 static bool pn533_rx_frame_is_valid(struct pn533_frame *frame)
378 {
379 u8 checksum;
380
381 if (frame->start_frame != cpu_to_be16(PN533_SOF))
382 return false;
383
384 checksum = pn533_checksum(frame->datalen);
385 if (checksum != frame->datalen_checksum)
386 return false;
387
388 checksum = pn533_data_checksum(frame->data, frame->datalen);
389 if (checksum != PN533_FRAME_CHECKSUM(frame))
390 return false;
391
392 return true;
393 }
394
395 static bool pn533_rx_frame_is_ack(struct pn533_frame *frame)
396 {
397 if (frame->start_frame != cpu_to_be16(PN533_SOF))
398 return false;
399
400 if (frame->datalen != 0 || frame->datalen_checksum != 0xFF)
401 return false;
402
403 return true;
404 }
405
406 static bool pn533_rx_frame_is_cmd_response(struct pn533_frame *frame, u8 cmd)
407 {
408 return (PN533_FRAME_CMD(frame) == PN533_CMD_RESPONSE(cmd));
409 }
410
411
412 static void pn533_wq_cmd_complete(struct work_struct *work)
413 {
414 struct pn533 *dev = container_of(work, struct pn533, cmd_work);
415 struct pn533_frame *in_frame;
416 int rc;
417
418 in_frame = dev->wq_in_frame;
419
420 if (dev->wq_in_error)
421 rc = dev->cmd_complete(dev, dev->cmd_complete_arg, NULL,
422 dev->wq_in_error);
423 else
424 rc = dev->cmd_complete(dev, dev->cmd_complete_arg,
425 PN533_FRAME_CMD_PARAMS_PTR(in_frame),
426 PN533_FRAME_CMD_PARAMS_LEN(in_frame));
427
428 if (rc != -EINPROGRESS)
429 up(&dev->cmd_lock);
430 }
431
432 static void pn533_recv_response(struct urb *urb)
433 {
434 struct pn533 *dev = urb->context;
435 struct pn533_frame *in_frame;
436
437 dev->wq_in_frame = NULL;
438
439 switch (urb->status) {
440 case 0:
441 /* success */
442 break;
443 case -ECONNRESET:
444 case -ENOENT:
445 case -ESHUTDOWN:
446 nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
447 " status: %d", urb->status);
448 dev->wq_in_error = urb->status;
449 goto sched_wq;
450 default:
451 nfc_dev_err(&dev->interface->dev, "Nonzero urb status received:"
452 " %d", urb->status);
453 dev->wq_in_error = urb->status;
454 goto sched_wq;
455 }
456
457 in_frame = dev->in_urb->transfer_buffer;
458
459 if (!pn533_rx_frame_is_valid(in_frame)) {
460 nfc_dev_err(&dev->interface->dev, "Received an invalid frame");
461 dev->wq_in_error = -EIO;
462 goto sched_wq;
463 }
464
465 if (!pn533_rx_frame_is_cmd_response(in_frame, dev->cmd)) {
466 nfc_dev_err(&dev->interface->dev, "The received frame is not "
467 "response to the last command");
468 dev->wq_in_error = -EIO;
469 goto sched_wq;
470 }
471
472 nfc_dev_dbg(&dev->interface->dev, "Received a valid frame");
473 dev->wq_in_error = 0;
474 dev->wq_in_frame = in_frame;
475
476 sched_wq:
477 queue_work(dev->wq, &dev->cmd_work);
478 }
479
480 static int pn533_submit_urb_for_response(struct pn533 *dev, gfp_t flags)
481 {
482 dev->in_urb->complete = pn533_recv_response;
483
484 return usb_submit_urb(dev->in_urb, flags);
485 }
486
487 static void pn533_recv_ack(struct urb *urb)
488 {
489 struct pn533 *dev = urb->context;
490 struct pn533_frame *in_frame;
491 int rc;
492
493 switch (urb->status) {
494 case 0:
495 /* success */
496 break;
497 case -ECONNRESET:
498 case -ENOENT:
499 case -ESHUTDOWN:
500 nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
501 " status: %d", urb->status);
502 dev->wq_in_error = urb->status;
503 goto sched_wq;
504 default:
505 nfc_dev_err(&dev->interface->dev, "Nonzero urb status received:"
506 " %d", urb->status);
507 dev->wq_in_error = urb->status;
508 goto sched_wq;
509 }
510
511 in_frame = dev->in_urb->transfer_buffer;
512
513 if (!pn533_rx_frame_is_ack(in_frame)) {
514 nfc_dev_err(&dev->interface->dev, "Received an invalid ack");
515 dev->wq_in_error = -EIO;
516 goto sched_wq;
517 }
518
519 nfc_dev_dbg(&dev->interface->dev, "Received a valid ack");
520
521 rc = pn533_submit_urb_for_response(dev, GFP_ATOMIC);
522 if (rc) {
523 nfc_dev_err(&dev->interface->dev, "usb_submit_urb failed with"
524 " result %d", rc);
525 dev->wq_in_error = rc;
526 goto sched_wq;
527 }
528
529 return;
530
531 sched_wq:
532 dev->wq_in_frame = NULL;
533 queue_work(dev->wq, &dev->cmd_work);
534 }
535
536 static int pn533_submit_urb_for_ack(struct pn533 *dev, gfp_t flags)
537 {
538 dev->in_urb->complete = pn533_recv_ack;
539
540 return usb_submit_urb(dev->in_urb, flags);
541 }
542
543 static int pn533_send_ack(struct pn533 *dev, gfp_t flags)
544 {
545 int rc;
546
547 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
548
549 pn533_tx_frame_ack(dev->out_frame);
550
551 dev->out_urb->transfer_buffer = dev->out_frame;
552 dev->out_urb->transfer_buffer_length = PN533_FRAME_ACK_SIZE;
553 rc = usb_submit_urb(dev->out_urb, flags);
554
555 return rc;
556 }
557
558 static int __pn533_send_cmd_frame_async(struct pn533 *dev,
559 struct pn533_frame *out_frame,
560 struct pn533_frame *in_frame,
561 int in_frame_len,
562 pn533_cmd_complete_t cmd_complete,
563 void *arg, gfp_t flags)
564 {
565 int rc;
566
567 nfc_dev_dbg(&dev->interface->dev, "Sending command 0x%x",
568 PN533_FRAME_CMD(out_frame));
569
570 dev->cmd = PN533_FRAME_CMD(out_frame);
571 dev->cmd_complete = cmd_complete;
572 dev->cmd_complete_arg = arg;
573
574 dev->out_urb->transfer_buffer = out_frame;
575 dev->out_urb->transfer_buffer_length =
576 PN533_FRAME_SIZE(out_frame);
577
578 dev->in_urb->transfer_buffer = in_frame;
579 dev->in_urb->transfer_buffer_length = in_frame_len;
580
581 rc = usb_submit_urb(dev->out_urb, flags);
582 if (rc)
583 return rc;
584
585 rc = pn533_submit_urb_for_ack(dev, flags);
586 if (rc)
587 goto error;
588
589 return 0;
590
591 error:
592 usb_unlink_urb(dev->out_urb);
593 return rc;
594 }
595
596 static int pn533_send_cmd_frame_async(struct pn533 *dev,
597 struct pn533_frame *out_frame,
598 struct pn533_frame *in_frame,
599 int in_frame_len,
600 pn533_cmd_complete_t cmd_complete,
601 void *arg, gfp_t flags)
602 {
603 int rc;
604
605 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
606
607 if (down_trylock(&dev->cmd_lock))
608 return -EBUSY;
609
610 rc = __pn533_send_cmd_frame_async(dev, out_frame, in_frame,
611 in_frame_len, cmd_complete, arg, flags);
612 if (rc)
613 goto error;
614
615 return 0;
616 error:
617 up(&dev->cmd_lock);
618 return rc;
619 }
620
621 struct pn533_sync_cmd_response {
622 int rc;
623 struct completion done;
624 };
625
626 static int pn533_sync_cmd_complete(struct pn533 *dev, void *_arg,
627 u8 *params, int params_len)
628 {
629 struct pn533_sync_cmd_response *arg = _arg;
630
631 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
632
633 arg->rc = 0;
634
635 if (params_len < 0) /* error */
636 arg->rc = params_len;
637
638 complete(&arg->done);
639
640 return 0;
641 }
642
643 static int pn533_send_cmd_frame_sync(struct pn533 *dev,
644 struct pn533_frame *out_frame,
645 struct pn533_frame *in_frame,
646 int in_frame_len)
647 {
648 int rc;
649 struct pn533_sync_cmd_response arg;
650
651 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
652
653 init_completion(&arg.done);
654
655 rc = pn533_send_cmd_frame_async(dev, out_frame, in_frame, in_frame_len,
656 pn533_sync_cmd_complete, &arg, GFP_KERNEL);
657 if (rc)
658 return rc;
659
660 wait_for_completion(&arg.done);
661
662 return arg.rc;
663 }
664
665 static void pn533_send_complete(struct urb *urb)
666 {
667 struct pn533 *dev = urb->context;
668
669 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
670
671 switch (urb->status) {
672 case 0:
673 /* success */
674 break;
675 case -ECONNRESET:
676 case -ENOENT:
677 case -ESHUTDOWN:
678 nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
679 " status: %d", urb->status);
680 break;
681 default:
682 nfc_dev_dbg(&dev->interface->dev, "Nonzero urb status received:"
683 " %d", urb->status);
684 }
685 }
686
687 struct pn533_target_type_a {
688 __be16 sens_res;
689 u8 sel_res;
690 u8 nfcid_len;
691 u8 nfcid_data[];
692 } __packed;
693
694
695 #define PN533_TYPE_A_SENS_RES_NFCID1(x) ((u8)((be16_to_cpu(x) & 0x00C0) >> 6))
696 #define PN533_TYPE_A_SENS_RES_SSD(x) ((u8)((be16_to_cpu(x) & 0x001F) >> 0))
697 #define PN533_TYPE_A_SENS_RES_PLATCONF(x) ((u8)((be16_to_cpu(x) & 0x0F00) >> 8))
698
699 #define PN533_TYPE_A_SENS_RES_SSD_JEWEL 0x00
700 #define PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL 0x0C
701
702 #define PN533_TYPE_A_SEL_PROT(x) (((x) & 0x60) >> 5)
703 #define PN533_TYPE_A_SEL_CASCADE(x) (((x) & 0x04) >> 2)
704
705 #define PN533_TYPE_A_SEL_PROT_MIFARE 0
706 #define PN533_TYPE_A_SEL_PROT_ISO14443 1
707 #define PN533_TYPE_A_SEL_PROT_DEP 2
708 #define PN533_TYPE_A_SEL_PROT_ISO14443_DEP 3
709
710 static bool pn533_target_type_a_is_valid(struct pn533_target_type_a *type_a,
711 int target_data_len)
712 {
713 u8 ssd;
714 u8 platconf;
715
716 if (target_data_len < sizeof(struct pn533_target_type_a))
717 return false;
718
719 /* The lenght check of nfcid[] and ats[] are not being performed because
720 the values are not being used */
721
722 /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
723 ssd = PN533_TYPE_A_SENS_RES_SSD(type_a->sens_res);
724 platconf = PN533_TYPE_A_SENS_RES_PLATCONF(type_a->sens_res);
725
726 if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
727 platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
728 (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
729 platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
730 return false;
731
732 /* Requirements 4.8.2.1, 4.8.2.3, 4.8.2.5 and 4.8.2.7 from NFC Forum */
733 if (PN533_TYPE_A_SEL_CASCADE(type_a->sel_res) != 0)
734 return false;
735
736 return true;
737 }
738
739 static int pn533_target_found_type_a(struct nfc_target *nfc_tgt, u8 *tgt_data,
740 int tgt_data_len)
741 {
742 struct pn533_target_type_a *tgt_type_a;
743
744 tgt_type_a = (struct pn533_target_type_a *) tgt_data;
745
746 if (!pn533_target_type_a_is_valid(tgt_type_a, tgt_data_len))
747 return -EPROTO;
748
749 switch (PN533_TYPE_A_SEL_PROT(tgt_type_a->sel_res)) {
750 case PN533_TYPE_A_SEL_PROT_MIFARE:
751 nfc_tgt->supported_protocols = NFC_PROTO_MIFARE_MASK;
752 break;
753 case PN533_TYPE_A_SEL_PROT_ISO14443:
754 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK;
755 break;
756 case PN533_TYPE_A_SEL_PROT_DEP:
757 nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
758 break;
759 case PN533_TYPE_A_SEL_PROT_ISO14443_DEP:
760 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK |
761 NFC_PROTO_NFC_DEP_MASK;
762 break;
763 }
764
765 nfc_tgt->sens_res = be16_to_cpu(tgt_type_a->sens_res);
766 nfc_tgt->sel_res = tgt_type_a->sel_res;
767 nfc_tgt->nfcid1_len = tgt_type_a->nfcid_len;
768 memcpy(nfc_tgt->nfcid1, tgt_type_a->nfcid_data, nfc_tgt->nfcid1_len);
769
770 return 0;
771 }
772
773 struct pn533_target_felica {
774 u8 pol_res;
775 u8 opcode;
776 u8 nfcid2[8];
777 u8 pad[8];
778 /* optional */
779 u8 syst_code[];
780 } __packed;
781
782 #define PN533_FELICA_SENSF_NFCID2_DEP_B1 0x01
783 #define PN533_FELICA_SENSF_NFCID2_DEP_B2 0xFE
784
785 static bool pn533_target_felica_is_valid(struct pn533_target_felica *felica,
786 int target_data_len)
787 {
788 if (target_data_len < sizeof(struct pn533_target_felica))
789 return false;
790
791 if (felica->opcode != PN533_FELICA_OPC_SENSF_RES)
792 return false;
793
794 return true;
795 }
796
797 static int pn533_target_found_felica(struct nfc_target *nfc_tgt, u8 *tgt_data,
798 int tgt_data_len)
799 {
800 struct pn533_target_felica *tgt_felica;
801
802 tgt_felica = (struct pn533_target_felica *) tgt_data;
803
804 if (!pn533_target_felica_is_valid(tgt_felica, tgt_data_len))
805 return -EPROTO;
806
807 if (tgt_felica->nfcid2[0] == PN533_FELICA_SENSF_NFCID2_DEP_B1 &&
808 tgt_felica->nfcid2[1] ==
809 PN533_FELICA_SENSF_NFCID2_DEP_B2)
810 nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
811 else
812 nfc_tgt->supported_protocols = NFC_PROTO_FELICA_MASK;
813
814 memcpy(nfc_tgt->sensf_res, &tgt_felica->opcode, 9);
815 nfc_tgt->sensf_res_len = 9;
816
817 return 0;
818 }
819
820 struct pn533_target_jewel {
821 __be16 sens_res;
822 u8 jewelid[4];
823 } __packed;
824
825 static bool pn533_target_jewel_is_valid(struct pn533_target_jewel *jewel,
826 int target_data_len)
827 {
828 u8 ssd;
829 u8 platconf;
830
831 if (target_data_len < sizeof(struct pn533_target_jewel))
832 return false;
833
834 /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
835 ssd = PN533_TYPE_A_SENS_RES_SSD(jewel->sens_res);
836 platconf = PN533_TYPE_A_SENS_RES_PLATCONF(jewel->sens_res);
837
838 if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
839 platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
840 (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
841 platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
842 return false;
843
844 return true;
845 }
846
847 static int pn533_target_found_jewel(struct nfc_target *nfc_tgt, u8 *tgt_data,
848 int tgt_data_len)
849 {
850 struct pn533_target_jewel *tgt_jewel;
851
852 tgt_jewel = (struct pn533_target_jewel *) tgt_data;
853
854 if (!pn533_target_jewel_is_valid(tgt_jewel, tgt_data_len))
855 return -EPROTO;
856
857 nfc_tgt->supported_protocols = NFC_PROTO_JEWEL_MASK;
858 nfc_tgt->sens_res = be16_to_cpu(tgt_jewel->sens_res);
859 nfc_tgt->nfcid1_len = 4;
860 memcpy(nfc_tgt->nfcid1, tgt_jewel->jewelid, nfc_tgt->nfcid1_len);
861
862 return 0;
863 }
864
865 struct pn533_type_b_prot_info {
866 u8 bitrate;
867 u8 fsci_type;
868 u8 fwi_adc_fo;
869 } __packed;
870
871 #define PN533_TYPE_B_PROT_FCSI(x) (((x) & 0xF0) >> 4)
872 #define PN533_TYPE_B_PROT_TYPE(x) (((x) & 0x0F) >> 0)
873 #define PN533_TYPE_B_PROT_TYPE_RFU_MASK 0x8
874
875 struct pn533_type_b_sens_res {
876 u8 opcode;
877 u8 nfcid[4];
878 u8 appdata[4];
879 struct pn533_type_b_prot_info prot_info;
880 } __packed;
881
882 #define PN533_TYPE_B_OPC_SENSB_RES 0x50
883
884 struct pn533_target_type_b {
885 struct pn533_type_b_sens_res sensb_res;
886 u8 attrib_res_len;
887 u8 attrib_res[];
888 } __packed;
889
890 static bool pn533_target_type_b_is_valid(struct pn533_target_type_b *type_b,
891 int target_data_len)
892 {
893 if (target_data_len < sizeof(struct pn533_target_type_b))
894 return false;
895
896 if (type_b->sensb_res.opcode != PN533_TYPE_B_OPC_SENSB_RES)
897 return false;
898
899 if (PN533_TYPE_B_PROT_TYPE(type_b->sensb_res.prot_info.fsci_type) &
900 PN533_TYPE_B_PROT_TYPE_RFU_MASK)
901 return false;
902
903 return true;
904 }
905
906 static int pn533_target_found_type_b(struct nfc_target *nfc_tgt, u8 *tgt_data,
907 int tgt_data_len)
908 {
909 struct pn533_target_type_b *tgt_type_b;
910
911 tgt_type_b = (struct pn533_target_type_b *) tgt_data;
912
913 if (!pn533_target_type_b_is_valid(tgt_type_b, tgt_data_len))
914 return -EPROTO;
915
916 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK;
917
918 return 0;
919 }
920
921 struct pn533_poll_response {
922 u8 nbtg;
923 u8 tg;
924 u8 target_data[];
925 } __packed;
926
927 static int pn533_target_found(struct pn533 *dev,
928 struct pn533_poll_response *resp, int resp_len)
929 {
930 int target_data_len;
931 struct nfc_target nfc_tgt;
932 int rc;
933
934 nfc_dev_dbg(&dev->interface->dev, "%s - modulation=%d", __func__,
935 dev->poll_mod_curr);
936
937 if (resp->tg != 1)
938 return -EPROTO;
939
940 memset(&nfc_tgt, 0, sizeof(struct nfc_target));
941
942 target_data_len = resp_len - sizeof(struct pn533_poll_response);
943
944 switch (dev->poll_mod_curr) {
945 case PN533_POLL_MOD_106KBPS_A:
946 rc = pn533_target_found_type_a(&nfc_tgt, resp->target_data,
947 target_data_len);
948 break;
949 case PN533_POLL_MOD_212KBPS_FELICA:
950 case PN533_POLL_MOD_424KBPS_FELICA:
951 rc = pn533_target_found_felica(&nfc_tgt, resp->target_data,
952 target_data_len);
953 break;
954 case PN533_POLL_MOD_106KBPS_JEWEL:
955 rc = pn533_target_found_jewel(&nfc_tgt, resp->target_data,
956 target_data_len);
957 break;
958 case PN533_POLL_MOD_847KBPS_B:
959 rc = pn533_target_found_type_b(&nfc_tgt, resp->target_data,
960 target_data_len);
961 break;
962 default:
963 nfc_dev_err(&dev->interface->dev, "Unknown current poll"
964 " modulation");
965 return -EPROTO;
966 }
967
968 if (rc)
969 return rc;
970
971 if (!(nfc_tgt.supported_protocols & dev->poll_protocols)) {
972 nfc_dev_dbg(&dev->interface->dev, "The target found does not"
973 " have the desired protocol");
974 return -EAGAIN;
975 }
976
977 nfc_dev_dbg(&dev->interface->dev, "Target found - supported protocols: "
978 "0x%x", nfc_tgt.supported_protocols);
979
980 dev->tgt_available_prots = nfc_tgt.supported_protocols;
981
982 nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1);
983
984 return 0;
985 }
986
987 static void pn533_poll_reset_mod_list(struct pn533 *dev)
988 {
989 dev->poll_mod_count = 0;
990 }
991
992 static void pn533_poll_add_mod(struct pn533 *dev, u8 mod_index)
993 {
994 dev->poll_mod_active[dev->poll_mod_count] =
995 (struct pn533_poll_modulations *) &poll_mod[mod_index];
996 dev->poll_mod_count++;
997 }
998
999 static void pn533_poll_create_mod_list(struct pn533 *dev, u32 protocols)
1000 {
1001 pn533_poll_reset_mod_list(dev);
1002
1003 if (protocols & NFC_PROTO_MIFARE_MASK
1004 || protocols & NFC_PROTO_ISO14443_MASK
1005 || protocols & NFC_PROTO_NFC_DEP_MASK)
1006 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_A);
1007
1008 if (protocols & NFC_PROTO_FELICA_MASK
1009 || protocols & NFC_PROTO_NFC_DEP_MASK) {
1010 pn533_poll_add_mod(dev, PN533_POLL_MOD_212KBPS_FELICA);
1011 pn533_poll_add_mod(dev, PN533_POLL_MOD_424KBPS_FELICA);
1012 }
1013
1014 if (protocols & NFC_PROTO_JEWEL_MASK)
1015 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_JEWEL);
1016
1017 if (protocols & NFC_PROTO_ISO14443_MASK)
1018 pn533_poll_add_mod(dev, PN533_POLL_MOD_847KBPS_B);
1019 }
1020
1021 static void pn533_start_poll_frame(struct pn533_frame *frame,
1022 struct pn533_poll_modulations *mod)
1023 {
1024
1025 pn533_tx_frame_init(frame, PN533_CMD_IN_LIST_PASSIVE_TARGET);
1026
1027 memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), &mod->data, mod->len);
1028 frame->datalen += mod->len;
1029
1030 pn533_tx_frame_finish(frame);
1031 }
1032
1033 static int pn533_start_poll_complete(struct pn533 *dev, void *arg,
1034 u8 *params, int params_len)
1035 {
1036 struct pn533_poll_response *resp;
1037 struct pn533_poll_modulations *next_mod;
1038 int rc;
1039
1040 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1041
1042 if (params_len == -ENOENT) {
1043 nfc_dev_dbg(&dev->interface->dev, "Polling operation has been"
1044 " stopped");
1045 goto stop_poll;
1046 }
1047
1048 if (params_len < 0) {
1049 nfc_dev_err(&dev->interface->dev, "Error %d when running poll",
1050 params_len);
1051 goto stop_poll;
1052 }
1053
1054 resp = (struct pn533_poll_response *) params;
1055 if (resp->nbtg) {
1056 rc = pn533_target_found(dev, resp, params_len);
1057
1058 /* We must stop the poll after a valid target found */
1059 if (rc == 0)
1060 goto stop_poll;
1061
1062 if (rc != -EAGAIN)
1063 nfc_dev_err(&dev->interface->dev, "The target found is"
1064 " not valid - continuing to poll");
1065 }
1066
1067 dev->poll_mod_curr = (dev->poll_mod_curr + 1) % dev->poll_mod_count;
1068
1069 next_mod = dev->poll_mod_active[dev->poll_mod_curr];
1070
1071 nfc_dev_dbg(&dev->interface->dev, "Polling next modulation (0x%x)",
1072 dev->poll_mod_curr);
1073
1074 pn533_start_poll_frame(dev->out_frame, next_mod);
1075
1076 /* Don't need to down the semaphore again */
1077 rc = __pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
1078 dev->in_maxlen, pn533_start_poll_complete,
1079 NULL, GFP_ATOMIC);
1080
1081 if (rc == -EPERM) {
1082 nfc_dev_dbg(&dev->interface->dev, "Cannot poll next modulation"
1083 " because poll has been stopped");
1084 goto stop_poll;
1085 }
1086
1087 if (rc) {
1088 nfc_dev_err(&dev->interface->dev, "Error %d when trying to poll"
1089 " next modulation", rc);
1090 goto stop_poll;
1091 }
1092
1093 /* Inform caller function to do not up the semaphore */
1094 return -EINPROGRESS;
1095
1096 stop_poll:
1097 pn533_poll_reset_mod_list(dev);
1098 dev->poll_protocols = 0;
1099 return 0;
1100 }
1101
1102 static int pn533_init_target_frame(struct pn533_frame *frame,
1103 u8 *gb, size_t gb_len)
1104 {
1105 struct pn533_cmd_init_target *cmd;
1106 size_t cmd_len;
1107
1108 cmd_len = sizeof(struct pn533_cmd_init_target) + gb_len + 1;
1109 cmd = kzalloc(cmd_len, GFP_KERNEL);
1110 if (cmd == NULL)
1111 return -ENOMEM;
1112
1113 pn533_tx_frame_init(frame, PN533_CMD_TG_INIT_AS_TARGET);
1114
1115 /* DEP support only */
1116 cmd->mode |= PN533_INIT_TARGET_DEP;
1117 get_random_bytes(cmd->nfcid3, 10);
1118 cmd->gb_len = gb_len;
1119 memcpy(cmd->gb, gb, gb_len);
1120 /* Len Tk */
1121 cmd->gb[gb_len] = 0;
1122
1123 memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), cmd, cmd_len);
1124 frame->datalen += cmd_len;
1125
1126 pn533_tx_frame_finish(frame);
1127
1128 return 0;
1129 }
1130
1131 static int pn533_init_target_complete(struct pn533 *dev, void *arg,
1132 u8 *params, int params_len)
1133 {
1134 struct pn533_cmd_init_target_response *resp;
1135
1136 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1137
1138 if (params_len < 0) {
1139 nfc_dev_err(&dev->interface->dev,
1140 "Error %d when starting as a target",
1141 params_len);
1142
1143 return params_len;
1144 }
1145
1146 resp = (struct pn533_cmd_init_target_response *) params;
1147
1148 nfc_dev_dbg(&dev->interface->dev, "Target mode 0x%x\n", resp->mode);
1149
1150 return 0;
1151 }
1152
1153 static int pn533_init_target(struct nfc_dev *nfc_dev, u32 protocols)
1154 {
1155 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1156 u8 *gb;
1157 size_t gb_len;
1158 int rc;
1159
1160 pn533_poll_reset_mod_list(dev);
1161
1162 gb = nfc_get_local_general_bytes(nfc_dev, &gb_len);
1163 if (gb == NULL)
1164 return -ENOMEM;
1165
1166 rc = pn533_init_target_frame(dev->out_frame, gb, gb_len);
1167 if (rc < 0)
1168 return rc;
1169
1170 rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
1171 dev->in_maxlen,
1172 pn533_init_target_complete,
1173 NULL, GFP_KERNEL);
1174
1175 if (rc)
1176 nfc_dev_err(&dev->interface->dev,
1177 "Error %d when trying to initiate as a target", rc);
1178
1179 dev->poll_mod_count++;
1180
1181 return rc;
1182 }
1183
1184 static int pn533_start_im_poll(struct nfc_dev *nfc_dev, u32 protocols)
1185 {
1186 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1187 struct pn533_poll_modulations *start_mod;
1188 int rc;
1189
1190 if (dev->poll_mod_count) {
1191 nfc_dev_err(&dev->interface->dev, "Polling operation already"
1192 " active");
1193 return -EBUSY;
1194 }
1195
1196 pn533_poll_create_mod_list(dev, protocols);
1197
1198 if (!dev->poll_mod_count) {
1199 nfc_dev_err(&dev->interface->dev, "No valid protocols"
1200 " specified");
1201 rc = -EINVAL;
1202 goto error;
1203 }
1204
1205 nfc_dev_dbg(&dev->interface->dev, "It will poll %d modulations types",
1206 dev->poll_mod_count);
1207
1208 dev->poll_mod_curr = 0;
1209 start_mod = dev->poll_mod_active[dev->poll_mod_curr];
1210
1211 pn533_start_poll_frame(dev->out_frame, start_mod);
1212
1213 rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
1214 dev->in_maxlen, pn533_start_poll_complete,
1215 NULL, GFP_KERNEL);
1216
1217 if (rc) {
1218 nfc_dev_err(&dev->interface->dev, "Error %d when trying to"
1219 " start poll", rc);
1220 goto error;
1221 }
1222
1223 dev->poll_protocols = protocols;
1224
1225 return 0;
1226
1227 error:
1228 pn533_poll_reset_mod_list(dev);
1229 return rc;
1230 }
1231
1232 static int pn533_start_poll(struct nfc_dev *nfc_dev,
1233 u32 im_protocols, u32 tm_protocols)
1234 {
1235 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1236
1237 nfc_dev_dbg(&dev->interface->dev,
1238 "%s: im protocols 0x%x tm protocols 0x%x",
1239 __func__, im_protocols, tm_protocols);
1240
1241 if (dev->tgt_active_prot) {
1242 nfc_dev_err(&dev->interface->dev,
1243 "Cannot poll with a target already activated");
1244 return -EBUSY;
1245 }
1246
1247 if (im_protocols)
1248 return pn533_start_im_poll(nfc_dev, im_protocols);
1249
1250 if (tm_protocols)
1251 return pn533_init_target(nfc_dev, tm_protocols);
1252
1253 return -EINVAL;
1254 }
1255
1256 static void pn533_stop_poll(struct nfc_dev *nfc_dev)
1257 {
1258 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1259
1260 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1261
1262 if (!dev->poll_mod_count) {
1263 nfc_dev_dbg(&dev->interface->dev, "Polling operation was not"
1264 " running");
1265 return;
1266 }
1267
1268 /* An ack will cancel the last issued command (poll) */
1269 pn533_send_ack(dev, GFP_KERNEL);
1270
1271 /* prevent pn533_start_poll_complete to issue a new poll meanwhile */
1272 usb_kill_urb(dev->in_urb);
1273 }
1274
1275 static int pn533_activate_target_nfcdep(struct pn533 *dev)
1276 {
1277 struct pn533_cmd_activate_param param;
1278 struct pn533_cmd_activate_response *resp;
1279 u16 gt_len;
1280 int rc;
1281
1282 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1283
1284 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_ATR);
1285
1286 param.tg = 1;
1287 param.next = 0;
1288 memcpy(PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame), &param,
1289 sizeof(struct pn533_cmd_activate_param));
1290 dev->out_frame->datalen += sizeof(struct pn533_cmd_activate_param);
1291
1292 pn533_tx_frame_finish(dev->out_frame);
1293
1294 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
1295 dev->in_maxlen);
1296 if (rc)
1297 return rc;
1298
1299 resp = (struct pn533_cmd_activate_response *)
1300 PN533_FRAME_CMD_PARAMS_PTR(dev->in_frame);
1301 rc = resp->status & PN533_CMD_RET_MASK;
1302 if (rc != PN533_CMD_RET_SUCCESS)
1303 return -EIO;
1304
1305 /* ATR_RES general bytes are located at offset 16 */
1306 gt_len = PN533_FRAME_CMD_PARAMS_LEN(dev->in_frame) - 16;
1307 rc = nfc_set_remote_general_bytes(dev->nfc_dev, resp->gt, gt_len);
1308
1309 return rc;
1310 }
1311
1312 static int pn533_activate_target(struct nfc_dev *nfc_dev,
1313 struct nfc_target *target, u32 protocol)
1314 {
1315 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1316 int rc;
1317
1318 nfc_dev_dbg(&dev->interface->dev, "%s - protocol=%u", __func__,
1319 protocol);
1320
1321 if (dev->poll_mod_count) {
1322 nfc_dev_err(&dev->interface->dev, "Cannot activate while"
1323 " polling");
1324 return -EBUSY;
1325 }
1326
1327 if (dev->tgt_active_prot) {
1328 nfc_dev_err(&dev->interface->dev, "There is already an active"
1329 " target");
1330 return -EBUSY;
1331 }
1332
1333 if (!dev->tgt_available_prots) {
1334 nfc_dev_err(&dev->interface->dev, "There is no available target"
1335 " to activate");
1336 return -EINVAL;
1337 }
1338
1339 if (!(dev->tgt_available_prots & (1 << protocol))) {
1340 nfc_dev_err(&dev->interface->dev, "The target does not support"
1341 " the requested protocol %u", protocol);
1342 return -EINVAL;
1343 }
1344
1345 if (protocol == NFC_PROTO_NFC_DEP) {
1346 rc = pn533_activate_target_nfcdep(dev);
1347 if (rc) {
1348 nfc_dev_err(&dev->interface->dev, "Error %d when"
1349 " activating target with"
1350 " NFC_DEP protocol", rc);
1351 return rc;
1352 }
1353 }
1354
1355 dev->tgt_active_prot = protocol;
1356 dev->tgt_available_prots = 0;
1357
1358 return 0;
1359 }
1360
1361 static void pn533_deactivate_target(struct nfc_dev *nfc_dev,
1362 struct nfc_target *target)
1363 {
1364 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1365 u8 tg;
1366 u8 status;
1367 int rc;
1368
1369 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1370
1371 if (!dev->tgt_active_prot) {
1372 nfc_dev_err(&dev->interface->dev, "There is no active target");
1373 return;
1374 }
1375
1376 dev->tgt_active_prot = 0;
1377
1378 skb_queue_purge(&dev->resp_q);
1379
1380 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_RELEASE);
1381
1382 tg = 1;
1383 memcpy(PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame), &tg, sizeof(u8));
1384 dev->out_frame->datalen += sizeof(u8);
1385
1386 pn533_tx_frame_finish(dev->out_frame);
1387
1388 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
1389 dev->in_maxlen);
1390 if (rc) {
1391 nfc_dev_err(&dev->interface->dev, "Error when sending release"
1392 " command to the controller");
1393 return;
1394 }
1395
1396 status = PN533_FRAME_CMD_PARAMS_PTR(dev->in_frame)[0];
1397 rc = status & PN533_CMD_RET_MASK;
1398 if (rc != PN533_CMD_RET_SUCCESS)
1399 nfc_dev_err(&dev->interface->dev, "Error 0x%x when releasing"
1400 " the target", rc);
1401
1402 return;
1403 }
1404
1405
1406 static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,
1407 u8 *params, int params_len)
1408 {
1409 struct pn533_cmd_jump_dep *cmd;
1410 struct pn533_cmd_jump_dep_response *resp;
1411 struct nfc_target nfc_target;
1412 u8 target_gt_len;
1413 int rc;
1414
1415 if (params_len == -ENOENT) {
1416 nfc_dev_dbg(&dev->interface->dev, "");
1417 return 0;
1418 }
1419
1420 if (params_len < 0) {
1421 nfc_dev_err(&dev->interface->dev,
1422 "Error %d when bringing DEP link up",
1423 params_len);
1424 return 0;
1425 }
1426
1427 if (dev->tgt_available_prots &&
1428 !(dev->tgt_available_prots & (1 << NFC_PROTO_NFC_DEP))) {
1429 nfc_dev_err(&dev->interface->dev,
1430 "The target does not support DEP");
1431 return -EINVAL;
1432 }
1433
1434 resp = (struct pn533_cmd_jump_dep_response *) params;
1435 cmd = (struct pn533_cmd_jump_dep *) arg;
1436 rc = resp->status & PN533_CMD_RET_MASK;
1437 if (rc != PN533_CMD_RET_SUCCESS) {
1438 nfc_dev_err(&dev->interface->dev,
1439 "Bringing DEP link up failed %d", rc);
1440 return 0;
1441 }
1442
1443 if (!dev->tgt_available_prots) {
1444 nfc_dev_dbg(&dev->interface->dev, "Creating new target");
1445
1446 nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
1447 nfc_target.nfcid1_len = 10;
1448 memcpy(nfc_target.nfcid1, resp->nfcid3t, nfc_target.nfcid1_len);
1449 rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1);
1450 if (rc)
1451 return 0;
1452
1453 dev->tgt_available_prots = 0;
1454 }
1455
1456 dev->tgt_active_prot = NFC_PROTO_NFC_DEP;
1457
1458 /* ATR_RES general bytes are located at offset 17 */
1459 target_gt_len = PN533_FRAME_CMD_PARAMS_LEN(dev->in_frame) - 17;
1460 rc = nfc_set_remote_general_bytes(dev->nfc_dev,
1461 resp->gt, target_gt_len);
1462 if (rc == 0)
1463 rc = nfc_dep_link_is_up(dev->nfc_dev,
1464 dev->nfc_dev->targets[0].idx,
1465 !cmd->active, NFC_RF_INITIATOR);
1466
1467 return 0;
1468 }
1469
1470 static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
1471 u8 comm_mode, u8* gb, size_t gb_len)
1472 {
1473 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1474 struct pn533_cmd_jump_dep *cmd;
1475 u8 cmd_len;
1476 int rc;
1477
1478 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1479
1480 if (dev->poll_mod_count) {
1481 nfc_dev_err(&dev->interface->dev,
1482 "Cannot bring the DEP link up while polling");
1483 return -EBUSY;
1484 }
1485
1486 if (dev->tgt_active_prot) {
1487 nfc_dev_err(&dev->interface->dev,
1488 "There is already an active target");
1489 return -EBUSY;
1490 }
1491
1492 cmd_len = sizeof(struct pn533_cmd_jump_dep) + gb_len;
1493 cmd = kzalloc(cmd_len, GFP_KERNEL);
1494 if (cmd == NULL)
1495 return -ENOMEM;
1496
1497 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_JUMP_FOR_DEP);
1498
1499 cmd->active = !comm_mode;
1500 cmd->baud = 0;
1501 if (gb != NULL && gb_len > 0) {
1502 cmd->next = 4; /* We have some Gi */
1503 memcpy(cmd->gt, gb, gb_len);
1504 } else {
1505 cmd->next = 0;
1506 }
1507
1508 memcpy(PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame), cmd, cmd_len);
1509 dev->out_frame->datalen += cmd_len;
1510
1511 pn533_tx_frame_finish(dev->out_frame);
1512
1513 rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
1514 dev->in_maxlen, pn533_in_dep_link_up_complete,
1515 cmd, GFP_KERNEL);
1516 if (rc)
1517 goto out;
1518
1519
1520 out:
1521 kfree(cmd);
1522
1523 return rc;
1524 }
1525
1526 static int pn533_dep_link_down(struct nfc_dev *nfc_dev)
1527 {
1528 pn533_deactivate_target(nfc_dev, 0);
1529
1530 return 0;
1531 }
1532
1533 #define PN533_CMD_DATAEXCH_HEAD_LEN (sizeof(struct pn533_frame) + 3)
1534 #define PN533_CMD_DATAEXCH_DATA_MAXLEN 262
1535
1536 static int pn533_data_exchange_tx_frame(struct pn533 *dev, struct sk_buff *skb)
1537 {
1538 int payload_len = skb->len;
1539 struct pn533_frame *out_frame;
1540 u8 tg;
1541
1542 nfc_dev_dbg(&dev->interface->dev, "%s - Sending %d bytes", __func__,
1543 payload_len);
1544
1545 if (payload_len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
1546 /* TODO: Implement support to multi-part data exchange */
1547 nfc_dev_err(&dev->interface->dev, "Data length greater than the"
1548 " max allowed: %d",
1549 PN533_CMD_DATAEXCH_DATA_MAXLEN);
1550 return -ENOSYS;
1551 }
1552
1553 skb_push(skb, PN533_CMD_DATAEXCH_HEAD_LEN);
1554 out_frame = (struct pn533_frame *) skb->data;
1555
1556 pn533_tx_frame_init(out_frame, PN533_CMD_IN_DATA_EXCHANGE);
1557
1558 tg = 1;
1559 memcpy(PN533_FRAME_CMD_PARAMS_PTR(out_frame), &tg, sizeof(u8));
1560 out_frame->datalen += sizeof(u8);
1561
1562 /* The data is already in the out_frame, just update the datalen */
1563 out_frame->datalen += payload_len;
1564
1565 pn533_tx_frame_finish(out_frame);
1566 skb_put(skb, PN533_FRAME_TAIL_SIZE);
1567
1568 return 0;
1569 }
1570
1571 struct pn533_data_exchange_arg {
1572 struct sk_buff *skb_resp;
1573 struct sk_buff *skb_out;
1574 data_exchange_cb_t cb;
1575 void *cb_context;
1576 };
1577
1578 static struct sk_buff *pn533_build_response(struct pn533 *dev)
1579 {
1580 struct sk_buff *skb, *tmp, *t;
1581 unsigned int skb_len = 0, tmp_len = 0;
1582
1583 nfc_dev_dbg(&dev->interface->dev, "%s\n", __func__);
1584
1585 if (skb_queue_empty(&dev->resp_q))
1586 return NULL;
1587
1588 if (skb_queue_len(&dev->resp_q) == 1) {
1589 skb = skb_dequeue(&dev->resp_q);
1590 goto out;
1591 }
1592
1593 skb_queue_walk_safe(&dev->resp_q, tmp, t)
1594 skb_len += tmp->len;
1595
1596 nfc_dev_dbg(&dev->interface->dev, "%s total length %d\n",
1597 __func__, skb_len);
1598
1599 skb = alloc_skb(skb_len, GFP_KERNEL);
1600 if (skb == NULL)
1601 goto out;
1602
1603 skb_put(skb, skb_len);
1604
1605 skb_queue_walk_safe(&dev->resp_q, tmp, t) {
1606 memcpy(skb->data + tmp_len, tmp->data, tmp->len);
1607 tmp_len += tmp->len;
1608 }
1609
1610 out:
1611 skb_queue_purge(&dev->resp_q);
1612
1613 return skb;
1614 }
1615
1616 static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg,
1617 u8 *params, int params_len)
1618 {
1619 struct pn533_data_exchange_arg *arg = _arg;
1620 struct sk_buff *skb = NULL, *skb_resp = arg->skb_resp;
1621 struct pn533_frame *in_frame = (struct pn533_frame *) skb_resp->data;
1622 int err = 0;
1623 u8 status;
1624 u8 cmd_ret;
1625
1626 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1627
1628 dev_kfree_skb(arg->skb_out);
1629
1630 if (params_len < 0) { /* error */
1631 err = params_len;
1632 goto error;
1633 }
1634
1635 status = params[0];
1636
1637 cmd_ret = status & PN533_CMD_RET_MASK;
1638 if (cmd_ret != PN533_CMD_RET_SUCCESS) {
1639 nfc_dev_err(&dev->interface->dev, "PN533 reported error %d when"
1640 " exchanging data", cmd_ret);
1641 err = -EIO;
1642 goto error;
1643 }
1644
1645 skb_put(skb_resp, PN533_FRAME_SIZE(in_frame));
1646 skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN);
1647 skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_SIZE);
1648 skb_queue_tail(&dev->resp_q, skb_resp);
1649
1650 if (status & PN533_CMD_MI_MASK) {
1651 queue_work(dev->wq, &dev->mi_work);
1652 return -EINPROGRESS;
1653 }
1654
1655 skb = pn533_build_response(dev);
1656 if (skb == NULL)
1657 goto error;
1658
1659 arg->cb(arg->cb_context, skb, 0);
1660 kfree(arg);
1661 return 0;
1662
1663 error:
1664 skb_queue_purge(&dev->resp_q);
1665 dev_kfree_skb(skb_resp);
1666 arg->cb(arg->cb_context, NULL, err);
1667 kfree(arg);
1668 return 0;
1669 }
1670
1671 static int pn533_data_exchange(struct nfc_dev *nfc_dev,
1672 struct nfc_target *target, struct sk_buff *skb,
1673 data_exchange_cb_t cb, void *cb_context)
1674 {
1675 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1676 struct pn533_frame *out_frame, *in_frame;
1677 struct pn533_data_exchange_arg *arg;
1678 struct sk_buff *skb_resp;
1679 int skb_resp_len;
1680 int rc;
1681
1682 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1683
1684 if (!dev->tgt_active_prot) {
1685 nfc_dev_err(&dev->interface->dev, "Cannot exchange data if"
1686 " there is no active target");
1687 rc = -EINVAL;
1688 goto error;
1689 }
1690
1691 rc = pn533_data_exchange_tx_frame(dev, skb);
1692 if (rc)
1693 goto error;
1694
1695 skb_resp_len = PN533_CMD_DATAEXCH_HEAD_LEN +
1696 PN533_CMD_DATAEXCH_DATA_MAXLEN +
1697 PN533_FRAME_TAIL_SIZE;
1698
1699 skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL);
1700 if (!skb_resp) {
1701 rc = -ENOMEM;
1702 goto error;
1703 }
1704
1705 in_frame = (struct pn533_frame *) skb_resp->data;
1706 out_frame = (struct pn533_frame *) skb->data;
1707
1708 arg = kmalloc(sizeof(struct pn533_data_exchange_arg), GFP_KERNEL);
1709 if (!arg) {
1710 rc = -ENOMEM;
1711 goto free_skb_resp;
1712 }
1713
1714 arg->skb_resp = skb_resp;
1715 arg->skb_out = skb;
1716 arg->cb = cb;
1717 arg->cb_context = cb_context;
1718
1719 rc = pn533_send_cmd_frame_async(dev, out_frame, in_frame, skb_resp_len,
1720 pn533_data_exchange_complete, arg,
1721 GFP_KERNEL);
1722 if (rc) {
1723 nfc_dev_err(&dev->interface->dev, "Error %d when trying to"
1724 " perform data_exchange", rc);
1725 goto free_arg;
1726 }
1727
1728 return 0;
1729
1730 free_arg:
1731 kfree(arg);
1732 free_skb_resp:
1733 kfree_skb(skb_resp);
1734 error:
1735 kfree_skb(skb);
1736 return rc;
1737 }
1738
1739 static void pn533_wq_mi_recv(struct work_struct *work)
1740 {
1741 struct pn533 *dev = container_of(work, struct pn533, mi_work);
1742 struct sk_buff *skb_cmd;
1743 struct pn533_data_exchange_arg *arg = dev->cmd_complete_arg;
1744 struct pn533_frame *out_frame, *in_frame;
1745 struct sk_buff *skb_resp;
1746 int skb_resp_len;
1747 int rc;
1748
1749 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1750
1751 /* This is a zero payload size skb */
1752 skb_cmd = alloc_skb(PN533_CMD_DATAEXCH_HEAD_LEN + PN533_FRAME_TAIL_SIZE,
1753 GFP_KERNEL);
1754 if (skb_cmd == NULL)
1755 goto error_cmd;
1756
1757 skb_reserve(skb_cmd, PN533_CMD_DATAEXCH_HEAD_LEN);
1758
1759 rc = pn533_data_exchange_tx_frame(dev, skb_cmd);
1760 if (rc)
1761 goto error_frame;
1762
1763 skb_resp_len = PN533_CMD_DATAEXCH_HEAD_LEN +
1764 PN533_CMD_DATAEXCH_DATA_MAXLEN +
1765 PN533_FRAME_TAIL_SIZE;
1766 skb_resp = alloc_skb(skb_resp_len, GFP_KERNEL);
1767 if (!skb_resp) {
1768 rc = -ENOMEM;
1769 goto error_frame;
1770 }
1771
1772 in_frame = (struct pn533_frame *) skb_resp->data;
1773 out_frame = (struct pn533_frame *) skb_cmd->data;
1774
1775 arg->skb_resp = skb_resp;
1776 arg->skb_out = skb_cmd;
1777
1778 rc = __pn533_send_cmd_frame_async(dev, out_frame, in_frame,
1779 skb_resp_len,
1780 pn533_data_exchange_complete,
1781 dev->cmd_complete_arg, GFP_KERNEL);
1782 if (!rc)
1783 return;
1784
1785 nfc_dev_err(&dev->interface->dev, "Error %d when trying to"
1786 " perform data_exchange", rc);
1787
1788 kfree_skb(skb_resp);
1789
1790 error_frame:
1791 kfree_skb(skb_cmd);
1792
1793 error_cmd:
1794 pn533_send_ack(dev, GFP_KERNEL);
1795
1796 kfree(arg);
1797
1798 up(&dev->cmd_lock);
1799 }
1800
1801 static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata,
1802 u8 cfgdata_len)
1803 {
1804 int rc;
1805 u8 *params;
1806
1807 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1808
1809 pn533_tx_frame_init(dev->out_frame, PN533_CMD_RF_CONFIGURATION);
1810
1811 params = PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame);
1812 params[0] = cfgitem;
1813 memcpy(&params[1], cfgdata, cfgdata_len);
1814 dev->out_frame->datalen += (1 + cfgdata_len);
1815
1816 pn533_tx_frame_finish(dev->out_frame);
1817
1818 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
1819 dev->in_maxlen);
1820
1821 return rc;
1822 }
1823
1824 struct nfc_ops pn533_nfc_ops = {
1825 .dev_up = NULL,
1826 .dev_down = NULL,
1827 .dep_link_up = pn533_dep_link_up,
1828 .dep_link_down = pn533_dep_link_down,
1829 .start_poll = pn533_start_poll,
1830 .stop_poll = pn533_stop_poll,
1831 .activate_target = pn533_activate_target,
1832 .deactivate_target = pn533_deactivate_target,
1833 .data_exchange = pn533_data_exchange,
1834 };
1835
1836 static int pn533_probe(struct usb_interface *interface,
1837 const struct usb_device_id *id)
1838 {
1839 struct pn533_fw_version *fw_ver;
1840 struct pn533 *dev;
1841 struct usb_host_interface *iface_desc;
1842 struct usb_endpoint_descriptor *endpoint;
1843 struct pn533_config_max_retries max_retries;
1844 int in_endpoint = 0;
1845 int out_endpoint = 0;
1846 int rc = -ENOMEM;
1847 int i;
1848 u32 protocols;
1849
1850 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1851 if (!dev)
1852 return -ENOMEM;
1853
1854 dev->udev = usb_get_dev(interface_to_usbdev(interface));
1855 dev->interface = interface;
1856 sema_init(&dev->cmd_lock, 1);
1857
1858 iface_desc = interface->cur_altsetting;
1859 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1860 endpoint = &iface_desc->endpoint[i].desc;
1861
1862 if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint)) {
1863 dev->in_maxlen = le16_to_cpu(endpoint->wMaxPacketSize);
1864 in_endpoint = endpoint->bEndpointAddress;
1865 }
1866
1867 if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint)) {
1868 dev->out_maxlen =
1869 le16_to_cpu(endpoint->wMaxPacketSize);
1870 out_endpoint = endpoint->bEndpointAddress;
1871 }
1872 }
1873
1874 if (!in_endpoint || !out_endpoint) {
1875 nfc_dev_err(&interface->dev, "Could not find bulk-in or"
1876 " bulk-out endpoint");
1877 rc = -ENODEV;
1878 goto error;
1879 }
1880
1881 dev->in_frame = kmalloc(dev->in_maxlen, GFP_KERNEL);
1882 dev->in_urb = usb_alloc_urb(0, GFP_KERNEL);
1883 dev->out_frame = kmalloc(dev->out_maxlen, GFP_KERNEL);
1884 dev->out_urb = usb_alloc_urb(0, GFP_KERNEL);
1885
1886 if (!dev->in_frame || !dev->out_frame ||
1887 !dev->in_urb || !dev->out_urb)
1888 goto error;
1889
1890 usb_fill_bulk_urb(dev->in_urb, dev->udev,
1891 usb_rcvbulkpipe(dev->udev, in_endpoint),
1892 NULL, 0, NULL, dev);
1893 usb_fill_bulk_urb(dev->out_urb, dev->udev,
1894 usb_sndbulkpipe(dev->udev, out_endpoint),
1895 NULL, 0,
1896 pn533_send_complete, dev);
1897
1898 INIT_WORK(&dev->cmd_work, pn533_wq_cmd_complete);
1899 INIT_WORK(&dev->mi_work, pn533_wq_mi_recv);
1900 dev->wq = alloc_workqueue("pn533",
1901 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_MEM_RECLAIM,
1902 1);
1903 if (dev->wq == NULL)
1904 goto error;
1905
1906 skb_queue_head_init(&dev->resp_q);
1907
1908 usb_set_intfdata(interface, dev);
1909
1910 pn533_tx_frame_init(dev->out_frame, PN533_CMD_GET_FIRMWARE_VERSION);
1911 pn533_tx_frame_finish(dev->out_frame);
1912
1913 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
1914 dev->in_maxlen);
1915 if (rc)
1916 goto destroy_wq;
1917
1918 fw_ver = (struct pn533_fw_version *)
1919 PN533_FRAME_CMD_PARAMS_PTR(dev->in_frame);
1920 nfc_dev_info(&dev->interface->dev, "NXP PN533 firmware ver %d.%d now"
1921 " attached", fw_ver->ver, fw_ver->rev);
1922
1923 protocols = NFC_PROTO_JEWEL_MASK
1924 | NFC_PROTO_MIFARE_MASK | NFC_PROTO_FELICA_MASK
1925 | NFC_PROTO_ISO14443_MASK
1926 | NFC_PROTO_NFC_DEP_MASK;
1927
1928 dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols,
1929 PN533_CMD_DATAEXCH_HEAD_LEN,
1930 PN533_FRAME_TAIL_SIZE);
1931 if (!dev->nfc_dev)
1932 goto destroy_wq;
1933
1934 nfc_set_parent_dev(dev->nfc_dev, &interface->dev);
1935 nfc_set_drvdata(dev->nfc_dev, dev);
1936
1937 rc = nfc_register_device(dev->nfc_dev);
1938 if (rc)
1939 goto free_nfc_dev;
1940
1941 max_retries.mx_rty_atr = PN533_CONFIG_MAX_RETRIES_ENDLESS;
1942 max_retries.mx_rty_psl = 2;
1943 max_retries.mx_rty_passive_act = PN533_CONFIG_MAX_RETRIES_NO_RETRY;
1944
1945 rc = pn533_set_configuration(dev, PN533_CFGITEM_MAX_RETRIES,
1946 (u8 *) &max_retries, sizeof(max_retries));
1947
1948 if (rc) {
1949 nfc_dev_err(&dev->interface->dev, "Error on setting MAX_RETRIES"
1950 " config");
1951 goto free_nfc_dev;
1952 }
1953
1954 return 0;
1955
1956 free_nfc_dev:
1957 nfc_free_device(dev->nfc_dev);
1958 destroy_wq:
1959 destroy_workqueue(dev->wq);
1960 error:
1961 kfree(dev->in_frame);
1962 usb_free_urb(dev->in_urb);
1963 kfree(dev->out_frame);
1964 usb_free_urb(dev->out_urb);
1965 kfree(dev);
1966 return rc;
1967 }
1968
1969 static void pn533_disconnect(struct usb_interface *interface)
1970 {
1971 struct pn533 *dev;
1972
1973 dev = usb_get_intfdata(interface);
1974 usb_set_intfdata(interface, NULL);
1975
1976 nfc_unregister_device(dev->nfc_dev);
1977 nfc_free_device(dev->nfc_dev);
1978
1979 usb_kill_urb(dev->in_urb);
1980 usb_kill_urb(dev->out_urb);
1981
1982 destroy_workqueue(dev->wq);
1983
1984 skb_queue_purge(&dev->resp_q);
1985
1986 kfree(dev->in_frame);
1987 usb_free_urb(dev->in_urb);
1988 kfree(dev->out_frame);
1989 usb_free_urb(dev->out_urb);
1990 kfree(dev);
1991
1992 nfc_dev_info(&interface->dev, "NXP PN533 NFC device disconnected");
1993 }
1994
1995 static struct usb_driver pn533_driver = {
1996 .name = "pn533",
1997 .probe = pn533_probe,
1998 .disconnect = pn533_disconnect,
1999 .id_table = pn533_table,
2000 };
2001
2002 module_usb_driver(pn533_driver);
2003
2004 MODULE_AUTHOR("Lauro Ramos Venancio <lauro.venancio@openbossa.org>,"
2005 " Aloisio Almeida Jr <aloisio.almeida@openbossa.org>");
2006 MODULE_DESCRIPTION("PN533 usb driver ver " VERSION);
2007 MODULE_VERSION(VERSION);
2008 MODULE_LICENSE("GPL");
This page took 0.131977 seconds and 6 git commands to generate.