treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / nfc / pn533 / pn533.c
blob346e084387f7d125a48df07ade33ef0689f69239
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Driver for NXP PN533 NFC Chip - core functions
5 * Copyright (C) 2011 Instituto Nokia de Tecnologia
6 * Copyright (C) 2012-2013 Tieto Poland
7 */
9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/nfc.h>
14 #include <linux/netdevice.h>
15 #include <net/nfc/nfc.h>
16 #include "pn533.h"
18 #define VERSION "0.3"
20 /* How much time we spend listening for initiators */
21 #define PN533_LISTEN_TIME 2
22 /* Delay between each poll frame (ms) */
23 #define PN533_POLL_INTERVAL 10
25 /* structs for pn533 commands */
27 /* PN533_CMD_GET_FIRMWARE_VERSION */
28 struct pn533_fw_version {
29 u8 ic;
30 u8 ver;
31 u8 rev;
32 u8 support;
35 /* PN533_CMD_RF_CONFIGURATION */
36 #define PN533_CFGITEM_RF_FIELD 0x01
37 #define PN533_CFGITEM_TIMING 0x02
38 #define PN533_CFGITEM_MAX_RETRIES 0x05
39 #define PN533_CFGITEM_PASORI 0x82
41 #define PN533_CFGITEM_RF_FIELD_AUTO_RFCA 0x2
42 #define PN533_CFGITEM_RF_FIELD_ON 0x1
43 #define PN533_CFGITEM_RF_FIELD_OFF 0x0
45 #define PN533_CONFIG_TIMING_102 0xb
46 #define PN533_CONFIG_TIMING_204 0xc
47 #define PN533_CONFIG_TIMING_409 0xd
48 #define PN533_CONFIG_TIMING_819 0xe
50 #define PN533_CONFIG_MAX_RETRIES_NO_RETRY 0x00
51 #define PN533_CONFIG_MAX_RETRIES_ENDLESS 0xFF
53 struct pn533_config_max_retries {
54 u8 mx_rty_atr;
55 u8 mx_rty_psl;
56 u8 mx_rty_passive_act;
57 } __packed;
59 struct pn533_config_timing {
60 u8 rfu;
61 u8 atr_res_timeout;
62 u8 dep_timeout;
63 } __packed;
65 /* PN533_CMD_IN_LIST_PASSIVE_TARGET */
67 /* felica commands opcode */
68 #define PN533_FELICA_OPC_SENSF_REQ 0
69 #define PN533_FELICA_OPC_SENSF_RES 1
70 /* felica SENSF_REQ parameters */
71 #define PN533_FELICA_SENSF_SC_ALL 0xFFFF
72 #define PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE 0
73 #define PN533_FELICA_SENSF_RC_SYSTEM_CODE 1
74 #define PN533_FELICA_SENSF_RC_ADVANCED_PROTOCOL 2
76 /* type B initiator_data values */
77 #define PN533_TYPE_B_AFI_ALL_FAMILIES 0
78 #define PN533_TYPE_B_POLL_METHOD_TIMESLOT 0
79 #define PN533_TYPE_B_POLL_METHOD_PROBABILISTIC 1
81 union pn533_cmd_poll_initdata {
82 struct {
83 u8 afi;
84 u8 polling_method;
85 } __packed type_b;
86 struct {
87 u8 opcode;
88 __be16 sc;
89 u8 rc;
90 u8 tsn;
91 } __packed felica;
94 struct pn533_poll_modulations {
95 struct {
96 u8 maxtg;
97 u8 brty;
98 union pn533_cmd_poll_initdata initiator_data;
99 } __packed data;
100 u8 len;
103 static const struct pn533_poll_modulations poll_mod[] = {
104 [PN533_POLL_MOD_106KBPS_A] = {
105 .data = {
106 .maxtg = 1,
107 .brty = 0,
109 .len = 2,
111 [PN533_POLL_MOD_212KBPS_FELICA] = {
112 .data = {
113 .maxtg = 1,
114 .brty = 1,
115 .initiator_data.felica = {
116 .opcode = PN533_FELICA_OPC_SENSF_REQ,
117 .sc = PN533_FELICA_SENSF_SC_ALL,
118 .rc = PN533_FELICA_SENSF_RC_SYSTEM_CODE,
119 .tsn = 0x03,
122 .len = 7,
124 [PN533_POLL_MOD_424KBPS_FELICA] = {
125 .data = {
126 .maxtg = 1,
127 .brty = 2,
128 .initiator_data.felica = {
129 .opcode = PN533_FELICA_OPC_SENSF_REQ,
130 .sc = PN533_FELICA_SENSF_SC_ALL,
131 .rc = PN533_FELICA_SENSF_RC_SYSTEM_CODE,
132 .tsn = 0x03,
135 .len = 7,
137 [PN533_POLL_MOD_106KBPS_JEWEL] = {
138 .data = {
139 .maxtg = 1,
140 .brty = 4,
142 .len = 2,
144 [PN533_POLL_MOD_847KBPS_B] = {
145 .data = {
146 .maxtg = 1,
147 .brty = 8,
148 .initiator_data.type_b = {
149 .afi = PN533_TYPE_B_AFI_ALL_FAMILIES,
150 .polling_method =
151 PN533_TYPE_B_POLL_METHOD_TIMESLOT,
154 .len = 3,
156 [PN533_LISTEN_MOD] = {
157 .len = 0,
161 /* PN533_CMD_IN_ATR */
163 struct pn533_cmd_activate_response {
164 u8 status;
165 u8 nfcid3t[10];
166 u8 didt;
167 u8 bst;
168 u8 brt;
169 u8 to;
170 u8 ppt;
171 /* optional */
172 u8 gt[];
173 } __packed;
175 struct pn533_cmd_jump_dep_response {
176 u8 status;
177 u8 tg;
178 u8 nfcid3t[10];
179 u8 didt;
180 u8 bst;
181 u8 brt;
182 u8 to;
183 u8 ppt;
184 /* optional */
185 u8 gt[];
186 } __packed;
188 struct pn532_autopoll_resp {
189 u8 type;
190 u8 ln;
191 u8 tg;
192 u8 tgdata[];
195 /* PN532_CMD_IN_AUTOPOLL */
196 #define PN532_AUTOPOLL_POLLNR_INFINITE 0xff
197 #define PN532_AUTOPOLL_PERIOD 0x03 /* in units of 150 ms */
199 #define PN532_AUTOPOLL_TYPE_GENERIC_106 0x00
200 #define PN532_AUTOPOLL_TYPE_GENERIC_212 0x01
201 #define PN532_AUTOPOLL_TYPE_GENERIC_424 0x02
202 #define PN532_AUTOPOLL_TYPE_JEWEL 0x04
203 #define PN532_AUTOPOLL_TYPE_MIFARE 0x10
204 #define PN532_AUTOPOLL_TYPE_FELICA212 0x11
205 #define PN532_AUTOPOLL_TYPE_FELICA424 0x12
206 #define PN532_AUTOPOLL_TYPE_ISOA 0x20
207 #define PN532_AUTOPOLL_TYPE_ISOB 0x23
208 #define PN532_AUTOPOLL_TYPE_DEP_PASSIVE_106 0x40
209 #define PN532_AUTOPOLL_TYPE_DEP_PASSIVE_212 0x41
210 #define PN532_AUTOPOLL_TYPE_DEP_PASSIVE_424 0x42
211 #define PN532_AUTOPOLL_TYPE_DEP_ACTIVE_106 0x80
212 #define PN532_AUTOPOLL_TYPE_DEP_ACTIVE_212 0x81
213 #define PN532_AUTOPOLL_TYPE_DEP_ACTIVE_424 0x82
215 /* PN533_TG_INIT_AS_TARGET */
216 #define PN533_INIT_TARGET_PASSIVE 0x1
217 #define PN533_INIT_TARGET_DEP 0x2
219 #define PN533_INIT_TARGET_RESP_FRAME_MASK 0x3
220 #define PN533_INIT_TARGET_RESP_ACTIVE 0x1
221 #define PN533_INIT_TARGET_RESP_DEP 0x4
223 /* The rule: value(high byte) + value(low byte) + checksum = 0 */
224 static inline u8 pn533_ext_checksum(u16 value)
226 return ~(u8)(((value & 0xFF00) >> 8) + (u8)(value & 0xFF)) + 1;
229 /* The rule: value + checksum = 0 */
230 static inline u8 pn533_std_checksum(u8 value)
232 return ~value + 1;
235 /* The rule: sum(data elements) + checksum = 0 */
236 static u8 pn533_std_data_checksum(u8 *data, int datalen)
238 u8 sum = 0;
239 int i;
241 for (i = 0; i < datalen; i++)
242 sum += data[i];
244 return pn533_std_checksum(sum);
247 static void pn533_std_tx_frame_init(void *_frame, u8 cmd_code)
249 struct pn533_std_frame *frame = _frame;
251 frame->preamble = 0;
252 frame->start_frame = cpu_to_be16(PN533_STD_FRAME_SOF);
253 PN533_STD_FRAME_IDENTIFIER(frame) = PN533_STD_FRAME_DIR_OUT;
254 PN533_FRAME_CMD(frame) = cmd_code;
255 frame->datalen = 2;
258 static void pn533_std_tx_frame_finish(void *_frame)
260 struct pn533_std_frame *frame = _frame;
262 frame->datalen_checksum = pn533_std_checksum(frame->datalen);
264 PN533_STD_FRAME_CHECKSUM(frame) =
265 pn533_std_data_checksum(frame->data, frame->datalen);
267 PN533_STD_FRAME_POSTAMBLE(frame) = 0;
270 static void pn533_std_tx_update_payload_len(void *_frame, int len)
272 struct pn533_std_frame *frame = _frame;
274 frame->datalen += len;
277 static bool pn533_std_rx_frame_is_valid(void *_frame, struct pn533 *dev)
279 u8 checksum;
280 struct pn533_std_frame *stdf = _frame;
282 if (stdf->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF))
283 return false;
285 if (likely(!PN533_STD_IS_EXTENDED(stdf))) {
286 /* Standard frame code */
287 dev->ops->rx_header_len = PN533_STD_FRAME_HEADER_LEN;
289 checksum = pn533_std_checksum(stdf->datalen);
290 if (checksum != stdf->datalen_checksum)
291 return false;
293 checksum = pn533_std_data_checksum(stdf->data, stdf->datalen);
294 if (checksum != PN533_STD_FRAME_CHECKSUM(stdf))
295 return false;
296 } else {
297 /* Extended */
298 struct pn533_ext_frame *eif = _frame;
300 dev->ops->rx_header_len = PN533_EXT_FRAME_HEADER_LEN;
302 checksum = pn533_ext_checksum(be16_to_cpu(eif->datalen));
303 if (checksum != eif->datalen_checksum)
304 return false;
306 /* check data checksum */
307 checksum = pn533_std_data_checksum(eif->data,
308 be16_to_cpu(eif->datalen));
309 if (checksum != PN533_EXT_FRAME_CHECKSUM(eif))
310 return false;
313 return true;
316 bool pn533_rx_frame_is_ack(void *_frame)
318 struct pn533_std_frame *frame = _frame;
320 if (frame->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF))
321 return false;
323 if (frame->datalen != 0 || frame->datalen_checksum != 0xFF)
324 return false;
326 return true;
328 EXPORT_SYMBOL_GPL(pn533_rx_frame_is_ack);
330 static inline int pn533_std_rx_frame_size(void *frame)
332 struct pn533_std_frame *f = frame;
334 /* check for Extended Information frame */
335 if (PN533_STD_IS_EXTENDED(f)) {
336 struct pn533_ext_frame *eif = frame;
338 return sizeof(struct pn533_ext_frame)
339 + be16_to_cpu(eif->datalen) + PN533_STD_FRAME_TAIL_LEN;
342 return sizeof(struct pn533_std_frame) + f->datalen +
343 PN533_STD_FRAME_TAIL_LEN;
346 static u8 pn533_std_get_cmd_code(void *frame)
348 struct pn533_std_frame *f = frame;
349 struct pn533_ext_frame *eif = frame;
351 if (PN533_STD_IS_EXTENDED(f))
352 return PN533_FRAME_CMD(eif);
353 else
354 return PN533_FRAME_CMD(f);
357 bool pn533_rx_frame_is_cmd_response(struct pn533 *dev, void *frame)
359 return (dev->ops->get_cmd_code(frame) ==
360 PN533_CMD_RESPONSE(dev->cmd->code));
362 EXPORT_SYMBOL_GPL(pn533_rx_frame_is_cmd_response);
365 static struct pn533_frame_ops pn533_std_frame_ops = {
366 .tx_frame_init = pn533_std_tx_frame_init,
367 .tx_frame_finish = pn533_std_tx_frame_finish,
368 .tx_update_payload_len = pn533_std_tx_update_payload_len,
369 .tx_header_len = PN533_STD_FRAME_HEADER_LEN,
370 .tx_tail_len = PN533_STD_FRAME_TAIL_LEN,
372 .rx_is_frame_valid = pn533_std_rx_frame_is_valid,
373 .rx_frame_size = pn533_std_rx_frame_size,
374 .rx_header_len = PN533_STD_FRAME_HEADER_LEN,
375 .rx_tail_len = PN533_STD_FRAME_TAIL_LEN,
377 .max_payload_len = PN533_STD_FRAME_MAX_PAYLOAD_LEN,
378 .get_cmd_code = pn533_std_get_cmd_code,
381 static void pn533_build_cmd_frame(struct pn533 *dev, u8 cmd_code,
382 struct sk_buff *skb)
384 /* payload is already there, just update datalen */
385 int payload_len = skb->len;
386 struct pn533_frame_ops *ops = dev->ops;
389 skb_push(skb, ops->tx_header_len);
390 skb_put(skb, ops->tx_tail_len);
392 ops->tx_frame_init(skb->data, cmd_code);
393 ops->tx_update_payload_len(skb->data, payload_len);
394 ops->tx_frame_finish(skb->data);
397 static int pn533_send_async_complete(struct pn533 *dev)
399 struct pn533_cmd *cmd = dev->cmd;
400 struct sk_buff *resp;
401 int status, rc = 0;
403 if (!cmd) {
404 dev_dbg(dev->dev, "%s: cmd not set\n", __func__);
405 goto done;
408 dev_kfree_skb(cmd->req);
410 status = cmd->status;
411 resp = cmd->resp;
413 if (status < 0) {
414 rc = cmd->complete_cb(dev, cmd->complete_cb_context,
415 ERR_PTR(status));
416 dev_kfree_skb(resp);
417 goto done;
420 /* when no response is set we got interrupted */
421 if (!resp)
422 resp = ERR_PTR(-EINTR);
424 if (!IS_ERR(resp)) {
425 skb_pull(resp, dev->ops->rx_header_len);
426 skb_trim(resp, resp->len - dev->ops->rx_tail_len);
429 rc = cmd->complete_cb(dev, cmd->complete_cb_context, resp);
431 done:
432 kfree(cmd);
433 dev->cmd = NULL;
434 return rc;
437 static int __pn533_send_async(struct pn533 *dev, u8 cmd_code,
438 struct sk_buff *req,
439 pn533_send_async_complete_t complete_cb,
440 void *complete_cb_context)
442 struct pn533_cmd *cmd;
443 int rc = 0;
445 dev_dbg(dev->dev, "Sending command 0x%x\n", cmd_code);
447 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
448 if (!cmd)
449 return -ENOMEM;
451 cmd->code = cmd_code;
452 cmd->req = req;
453 cmd->complete_cb = complete_cb;
454 cmd->complete_cb_context = complete_cb_context;
456 pn533_build_cmd_frame(dev, cmd_code, req);
458 mutex_lock(&dev->cmd_lock);
460 if (!dev->cmd_pending) {
461 dev->cmd = cmd;
462 rc = dev->phy_ops->send_frame(dev, req);
463 if (rc) {
464 dev->cmd = NULL;
465 goto error;
468 dev->cmd_pending = 1;
469 goto unlock;
472 dev_dbg(dev->dev, "%s Queueing command 0x%x\n",
473 __func__, cmd_code);
475 INIT_LIST_HEAD(&cmd->queue);
476 list_add_tail(&cmd->queue, &dev->cmd_queue);
478 goto unlock;
480 error:
481 kfree(cmd);
482 unlock:
483 mutex_unlock(&dev->cmd_lock);
484 return rc;
487 static int pn533_send_data_async(struct pn533 *dev, u8 cmd_code,
488 struct sk_buff *req,
489 pn533_send_async_complete_t complete_cb,
490 void *complete_cb_context)
492 int rc;
494 rc = __pn533_send_async(dev, cmd_code, req, complete_cb,
495 complete_cb_context);
497 return rc;
500 static int pn533_send_cmd_async(struct pn533 *dev, u8 cmd_code,
501 struct sk_buff *req,
502 pn533_send_async_complete_t complete_cb,
503 void *complete_cb_context)
505 int rc;
507 rc = __pn533_send_async(dev, cmd_code, req, complete_cb,
508 complete_cb_context);
510 return rc;
514 * pn533_send_cmd_direct_async
516 * The function sends a piority cmd directly to the chip omitting the cmd
517 * queue. It's intended to be used by chaining mechanism of received responses
518 * where the host has to request every single chunk of data before scheduling
519 * next cmd from the queue.
521 static int pn533_send_cmd_direct_async(struct pn533 *dev, u8 cmd_code,
522 struct sk_buff *req,
523 pn533_send_async_complete_t complete_cb,
524 void *complete_cb_context)
526 struct pn533_cmd *cmd;
527 int rc;
529 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
530 if (!cmd)
531 return -ENOMEM;
533 cmd->code = cmd_code;
534 cmd->req = req;
535 cmd->complete_cb = complete_cb;
536 cmd->complete_cb_context = complete_cb_context;
538 pn533_build_cmd_frame(dev, cmd_code, req);
540 dev->cmd = cmd;
541 rc = dev->phy_ops->send_frame(dev, req);
542 if (rc < 0) {
543 dev->cmd = NULL;
544 kfree(cmd);
547 return rc;
550 static void pn533_wq_cmd_complete(struct work_struct *work)
552 struct pn533 *dev = container_of(work, struct pn533, cmd_complete_work);
553 int rc;
555 rc = pn533_send_async_complete(dev);
556 if (rc != -EINPROGRESS)
557 queue_work(dev->wq, &dev->cmd_work);
560 static void pn533_wq_cmd(struct work_struct *work)
562 struct pn533 *dev = container_of(work, struct pn533, cmd_work);
563 struct pn533_cmd *cmd;
564 int rc;
566 mutex_lock(&dev->cmd_lock);
568 if (list_empty(&dev->cmd_queue)) {
569 dev->cmd_pending = 0;
570 mutex_unlock(&dev->cmd_lock);
571 return;
574 cmd = list_first_entry(&dev->cmd_queue, struct pn533_cmd, queue);
576 list_del(&cmd->queue);
578 mutex_unlock(&dev->cmd_lock);
580 dev->cmd = cmd;
581 rc = dev->phy_ops->send_frame(dev, cmd->req);
582 if (rc < 0) {
583 dev->cmd = NULL;
584 dev_kfree_skb(cmd->req);
585 kfree(cmd);
586 return;
591 struct pn533_sync_cmd_response {
592 struct sk_buff *resp;
593 struct completion done;
596 static int pn533_send_sync_complete(struct pn533 *dev, void *_arg,
597 struct sk_buff *resp)
599 struct pn533_sync_cmd_response *arg = _arg;
601 arg->resp = resp;
602 complete(&arg->done);
604 return 0;
607 /* pn533_send_cmd_sync
609 * Please note the req parameter is freed inside the function to
610 * limit a number of return value interpretations by the caller.
612 * 1. negative in case of error during TX path -> req should be freed
614 * 2. negative in case of error during RX path -> req should not be freed
615 * as it's been already freed at the beginning of RX path by
616 * async_complete_cb.
618 * 3. valid pointer in case of succesfult RX path
620 * A caller has to check a return value with IS_ERR macro. If the test pass,
621 * the returned pointer is valid.
624 static struct sk_buff *pn533_send_cmd_sync(struct pn533 *dev, u8 cmd_code,
625 struct sk_buff *req)
627 int rc;
628 struct pn533_sync_cmd_response arg;
630 init_completion(&arg.done);
632 rc = pn533_send_cmd_async(dev, cmd_code, req,
633 pn533_send_sync_complete, &arg);
634 if (rc) {
635 dev_kfree_skb(req);
636 return ERR_PTR(rc);
639 wait_for_completion(&arg.done);
641 return arg.resp;
644 static struct sk_buff *pn533_alloc_skb(struct pn533 *dev, unsigned int size)
646 struct sk_buff *skb;
648 skb = alloc_skb(dev->ops->tx_header_len +
649 size +
650 dev->ops->tx_tail_len, GFP_KERNEL);
652 if (skb)
653 skb_reserve(skb, dev->ops->tx_header_len);
655 return skb;
658 struct pn533_target_type_a {
659 __be16 sens_res;
660 u8 sel_res;
661 u8 nfcid_len;
662 u8 nfcid_data[];
663 } __packed;
666 #define PN533_TYPE_A_SENS_RES_NFCID1(x) ((u8)((be16_to_cpu(x) & 0x00C0) >> 6))
667 #define PN533_TYPE_A_SENS_RES_SSD(x) ((u8)((be16_to_cpu(x) & 0x001F) >> 0))
668 #define PN533_TYPE_A_SENS_RES_PLATCONF(x) ((u8)((be16_to_cpu(x) & 0x0F00) >> 8))
670 #define PN533_TYPE_A_SENS_RES_SSD_JEWEL 0x00
671 #define PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL 0x0C
673 #define PN533_TYPE_A_SEL_PROT(x) (((x) & 0x60) >> 5)
674 #define PN533_TYPE_A_SEL_CASCADE(x) (((x) & 0x04) >> 2)
676 #define PN533_TYPE_A_SEL_PROT_MIFARE 0
677 #define PN533_TYPE_A_SEL_PROT_ISO14443 1
678 #define PN533_TYPE_A_SEL_PROT_DEP 2
679 #define PN533_TYPE_A_SEL_PROT_ISO14443_DEP 3
681 static bool pn533_target_type_a_is_valid(struct pn533_target_type_a *type_a,
682 int target_data_len)
684 u8 ssd;
685 u8 platconf;
687 if (target_data_len < sizeof(struct pn533_target_type_a))
688 return false;
691 * The length check of nfcid[] and ats[] are not being performed because
692 * the values are not being used
695 /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
696 ssd = PN533_TYPE_A_SENS_RES_SSD(type_a->sens_res);
697 platconf = PN533_TYPE_A_SENS_RES_PLATCONF(type_a->sens_res);
699 if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
700 platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
701 (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
702 platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
703 return false;
705 /* Requirements 4.8.2.1, 4.8.2.3, 4.8.2.5 and 4.8.2.7 from NFC Forum */
706 if (PN533_TYPE_A_SEL_CASCADE(type_a->sel_res) != 0)
707 return false;
709 return true;
712 static int pn533_target_found_type_a(struct nfc_target *nfc_tgt, u8 *tgt_data,
713 int tgt_data_len)
715 struct pn533_target_type_a *tgt_type_a;
717 tgt_type_a = (struct pn533_target_type_a *)tgt_data;
719 if (!pn533_target_type_a_is_valid(tgt_type_a, tgt_data_len))
720 return -EPROTO;
722 switch (PN533_TYPE_A_SEL_PROT(tgt_type_a->sel_res)) {
723 case PN533_TYPE_A_SEL_PROT_MIFARE:
724 nfc_tgt->supported_protocols = NFC_PROTO_MIFARE_MASK;
725 break;
726 case PN533_TYPE_A_SEL_PROT_ISO14443:
727 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK;
728 break;
729 case PN533_TYPE_A_SEL_PROT_DEP:
730 nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
731 break;
732 case PN533_TYPE_A_SEL_PROT_ISO14443_DEP:
733 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK |
734 NFC_PROTO_NFC_DEP_MASK;
735 break;
738 nfc_tgt->sens_res = be16_to_cpu(tgt_type_a->sens_res);
739 nfc_tgt->sel_res = tgt_type_a->sel_res;
740 nfc_tgt->nfcid1_len = tgt_type_a->nfcid_len;
741 memcpy(nfc_tgt->nfcid1, tgt_type_a->nfcid_data, nfc_tgt->nfcid1_len);
743 return 0;
746 struct pn533_target_felica {
747 u8 pol_res;
748 u8 opcode;
749 u8 nfcid2[NFC_NFCID2_MAXSIZE];
750 u8 pad[8];
751 /* optional */
752 u8 syst_code[];
753 } __packed;
755 #define PN533_FELICA_SENSF_NFCID2_DEP_B1 0x01
756 #define PN533_FELICA_SENSF_NFCID2_DEP_B2 0xFE
758 static bool pn533_target_felica_is_valid(struct pn533_target_felica *felica,
759 int target_data_len)
761 if (target_data_len < sizeof(struct pn533_target_felica))
762 return false;
764 if (felica->opcode != PN533_FELICA_OPC_SENSF_RES)
765 return false;
767 return true;
770 static int pn533_target_found_felica(struct nfc_target *nfc_tgt, u8 *tgt_data,
771 int tgt_data_len)
773 struct pn533_target_felica *tgt_felica;
775 tgt_felica = (struct pn533_target_felica *)tgt_data;
777 if (!pn533_target_felica_is_valid(tgt_felica, tgt_data_len))
778 return -EPROTO;
780 if ((tgt_felica->nfcid2[0] == PN533_FELICA_SENSF_NFCID2_DEP_B1) &&
781 (tgt_felica->nfcid2[1] == PN533_FELICA_SENSF_NFCID2_DEP_B2))
782 nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
783 else
784 nfc_tgt->supported_protocols = NFC_PROTO_FELICA_MASK;
786 memcpy(nfc_tgt->sensf_res, &tgt_felica->opcode, 9);
787 nfc_tgt->sensf_res_len = 9;
789 memcpy(nfc_tgt->nfcid2, tgt_felica->nfcid2, NFC_NFCID2_MAXSIZE);
790 nfc_tgt->nfcid2_len = NFC_NFCID2_MAXSIZE;
792 return 0;
795 struct pn533_target_jewel {
796 __be16 sens_res;
797 u8 jewelid[4];
798 } __packed;
800 static bool pn533_target_jewel_is_valid(struct pn533_target_jewel *jewel,
801 int target_data_len)
803 u8 ssd;
804 u8 platconf;
806 if (target_data_len < sizeof(struct pn533_target_jewel))
807 return false;
809 /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
810 ssd = PN533_TYPE_A_SENS_RES_SSD(jewel->sens_res);
811 platconf = PN533_TYPE_A_SENS_RES_PLATCONF(jewel->sens_res);
813 if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
814 platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
815 (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
816 platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
817 return false;
819 return true;
822 static int pn533_target_found_jewel(struct nfc_target *nfc_tgt, u8 *tgt_data,
823 int tgt_data_len)
825 struct pn533_target_jewel *tgt_jewel;
827 tgt_jewel = (struct pn533_target_jewel *)tgt_data;
829 if (!pn533_target_jewel_is_valid(tgt_jewel, tgt_data_len))
830 return -EPROTO;
832 nfc_tgt->supported_protocols = NFC_PROTO_JEWEL_MASK;
833 nfc_tgt->sens_res = be16_to_cpu(tgt_jewel->sens_res);
834 nfc_tgt->nfcid1_len = 4;
835 memcpy(nfc_tgt->nfcid1, tgt_jewel->jewelid, nfc_tgt->nfcid1_len);
837 return 0;
840 struct pn533_type_b_prot_info {
841 u8 bitrate;
842 u8 fsci_type;
843 u8 fwi_adc_fo;
844 } __packed;
846 #define PN533_TYPE_B_PROT_FCSI(x) (((x) & 0xF0) >> 4)
847 #define PN533_TYPE_B_PROT_TYPE(x) (((x) & 0x0F) >> 0)
848 #define PN533_TYPE_B_PROT_TYPE_RFU_MASK 0x8
850 struct pn533_type_b_sens_res {
851 u8 opcode;
852 u8 nfcid[4];
853 u8 appdata[4];
854 struct pn533_type_b_prot_info prot_info;
855 } __packed;
857 #define PN533_TYPE_B_OPC_SENSB_RES 0x50
859 struct pn533_target_type_b {
860 struct pn533_type_b_sens_res sensb_res;
861 u8 attrib_res_len;
862 u8 attrib_res[];
863 } __packed;
865 static bool pn533_target_type_b_is_valid(struct pn533_target_type_b *type_b,
866 int target_data_len)
868 if (target_data_len < sizeof(struct pn533_target_type_b))
869 return false;
871 if (type_b->sensb_res.opcode != PN533_TYPE_B_OPC_SENSB_RES)
872 return false;
874 if (PN533_TYPE_B_PROT_TYPE(type_b->sensb_res.prot_info.fsci_type) &
875 PN533_TYPE_B_PROT_TYPE_RFU_MASK)
876 return false;
878 return true;
881 static int pn533_target_found_type_b(struct nfc_target *nfc_tgt, u8 *tgt_data,
882 int tgt_data_len)
884 struct pn533_target_type_b *tgt_type_b;
886 tgt_type_b = (struct pn533_target_type_b *)tgt_data;
888 if (!pn533_target_type_b_is_valid(tgt_type_b, tgt_data_len))
889 return -EPROTO;
891 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_B_MASK;
893 return 0;
896 static void pn533_poll_reset_mod_list(struct pn533 *dev);
897 static int pn533_target_found(struct pn533 *dev, u8 tg, u8 *tgdata,
898 int tgdata_len)
900 struct nfc_target nfc_tgt;
901 int rc;
903 dev_dbg(dev->dev, "%s: modulation=%d\n",
904 __func__, dev->poll_mod_curr);
906 if (tg != 1)
907 return -EPROTO;
909 memset(&nfc_tgt, 0, sizeof(struct nfc_target));
911 switch (dev->poll_mod_curr) {
912 case PN533_POLL_MOD_106KBPS_A:
913 rc = pn533_target_found_type_a(&nfc_tgt, tgdata, tgdata_len);
914 break;
915 case PN533_POLL_MOD_212KBPS_FELICA:
916 case PN533_POLL_MOD_424KBPS_FELICA:
917 rc = pn533_target_found_felica(&nfc_tgt, tgdata, tgdata_len);
918 break;
919 case PN533_POLL_MOD_106KBPS_JEWEL:
920 rc = pn533_target_found_jewel(&nfc_tgt, tgdata, tgdata_len);
921 break;
922 case PN533_POLL_MOD_847KBPS_B:
923 rc = pn533_target_found_type_b(&nfc_tgt, tgdata, tgdata_len);
924 break;
925 default:
926 nfc_err(dev->dev,
927 "Unknown current poll modulation\n");
928 return -EPROTO;
931 if (rc)
932 return rc;
934 if (!(nfc_tgt.supported_protocols & dev->poll_protocols)) {
935 dev_dbg(dev->dev,
936 "The Tg found doesn't have the desired protocol\n");
937 return -EAGAIN;
940 dev_dbg(dev->dev,
941 "Target found - supported protocols: 0x%x\n",
942 nfc_tgt.supported_protocols);
944 dev->tgt_available_prots = nfc_tgt.supported_protocols;
946 pn533_poll_reset_mod_list(dev);
947 nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1);
949 return 0;
952 static inline void pn533_poll_next_mod(struct pn533 *dev)
954 dev->poll_mod_curr = (dev->poll_mod_curr + 1) % dev->poll_mod_count;
957 static void pn533_poll_reset_mod_list(struct pn533 *dev)
959 dev->poll_mod_count = 0;
962 static void pn533_poll_add_mod(struct pn533 *dev, u8 mod_index)
964 dev->poll_mod_active[dev->poll_mod_count] =
965 (struct pn533_poll_modulations *)&poll_mod[mod_index];
966 dev->poll_mod_count++;
969 static void pn533_poll_create_mod_list(struct pn533 *dev,
970 u32 im_protocols, u32 tm_protocols)
972 pn533_poll_reset_mod_list(dev);
974 if ((im_protocols & NFC_PROTO_MIFARE_MASK) ||
975 (im_protocols & NFC_PROTO_ISO14443_MASK) ||
976 (im_protocols & NFC_PROTO_NFC_DEP_MASK))
977 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_A);
979 if (im_protocols & NFC_PROTO_FELICA_MASK ||
980 im_protocols & NFC_PROTO_NFC_DEP_MASK) {
981 pn533_poll_add_mod(dev, PN533_POLL_MOD_212KBPS_FELICA);
982 pn533_poll_add_mod(dev, PN533_POLL_MOD_424KBPS_FELICA);
985 if (im_protocols & NFC_PROTO_JEWEL_MASK)
986 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_JEWEL);
988 if (im_protocols & NFC_PROTO_ISO14443_B_MASK)
989 pn533_poll_add_mod(dev, PN533_POLL_MOD_847KBPS_B);
991 if (tm_protocols)
992 pn533_poll_add_mod(dev, PN533_LISTEN_MOD);
995 static int pn533_start_poll_complete(struct pn533 *dev, struct sk_buff *resp)
997 u8 nbtg, tg, *tgdata;
998 int rc, tgdata_len;
1000 /* Toggle the DEP polling */
1001 if (dev->poll_protocols & NFC_PROTO_NFC_DEP_MASK)
1002 dev->poll_dep = 1;
1004 nbtg = resp->data[0];
1005 tg = resp->data[1];
1006 tgdata = &resp->data[2];
1007 tgdata_len = resp->len - 2; /* nbtg + tg */
1009 if (nbtg) {
1010 rc = pn533_target_found(dev, tg, tgdata, tgdata_len);
1012 /* We must stop the poll after a valid target found */
1013 if (rc == 0)
1014 return 0;
1017 return -EAGAIN;
1020 static struct sk_buff *pn533_alloc_poll_tg_frame(struct pn533 *dev)
1022 struct sk_buff *skb;
1023 u8 *felica, *nfcid3;
1025 u8 *gbytes = dev->gb;
1026 size_t gbytes_len = dev->gb_len;
1028 u8 felica_params[18] = {0x1, 0xfe, /* DEP */
1029 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* random */
1030 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
1031 0xff, 0xff}; /* System code */
1033 u8 mifare_params[6] = {0x1, 0x1, /* SENS_RES */
1034 0x0, 0x0, 0x0,
1035 0x40}; /* SEL_RES for DEP */
1037 unsigned int skb_len = 36 + /*
1038 * mode (1), mifare (6),
1039 * felica (18), nfcid3 (10), gb_len (1)
1041 gbytes_len +
1042 1; /* len Tk*/
1044 skb = pn533_alloc_skb(dev, skb_len);
1045 if (!skb)
1046 return NULL;
1048 /* DEP support only */
1049 skb_put_u8(skb, PN533_INIT_TARGET_DEP);
1051 /* MIFARE params */
1052 skb_put_data(skb, mifare_params, 6);
1054 /* Felica params */
1055 felica = skb_put_data(skb, felica_params, 18);
1056 get_random_bytes(felica + 2, 6);
1058 /* NFCID3 */
1059 nfcid3 = skb_put_zero(skb, 10);
1060 memcpy(nfcid3, felica, 8);
1062 /* General bytes */
1063 skb_put_u8(skb, gbytes_len);
1065 skb_put_data(skb, gbytes, gbytes_len);
1067 /* Len Tk */
1068 skb_put_u8(skb, 0);
1070 return skb;
1073 static void pn533_wq_tm_mi_recv(struct work_struct *work);
1074 static struct sk_buff *pn533_build_response(struct pn533 *dev);
1076 static int pn533_tm_get_data_complete(struct pn533 *dev, void *arg,
1077 struct sk_buff *resp)
1079 struct sk_buff *skb;
1080 u8 status, ret, mi;
1081 int rc;
1083 dev_dbg(dev->dev, "%s\n", __func__);
1085 if (IS_ERR(resp)) {
1086 skb_queue_purge(&dev->resp_q);
1087 return PTR_ERR(resp);
1090 status = resp->data[0];
1092 ret = status & PN533_CMD_RET_MASK;
1093 mi = status & PN533_CMD_MI_MASK;
1095 skb_pull(resp, sizeof(status));
1097 if (ret != PN533_CMD_RET_SUCCESS) {
1098 rc = -EIO;
1099 goto error;
1102 skb_queue_tail(&dev->resp_q, resp);
1104 if (mi) {
1105 queue_work(dev->wq, &dev->mi_tm_rx_work);
1106 return -EINPROGRESS;
1109 skb = pn533_build_response(dev);
1110 if (!skb) {
1111 rc = -EIO;
1112 goto error;
1115 return nfc_tm_data_received(dev->nfc_dev, skb);
1117 error:
1118 nfc_tm_deactivated(dev->nfc_dev);
1119 dev->tgt_mode = 0;
1120 skb_queue_purge(&dev->resp_q);
1121 dev_kfree_skb(resp);
1123 return rc;
1126 static void pn533_wq_tm_mi_recv(struct work_struct *work)
1128 struct pn533 *dev = container_of(work, struct pn533, mi_tm_rx_work);
1129 struct sk_buff *skb;
1130 int rc;
1132 dev_dbg(dev->dev, "%s\n", __func__);
1134 skb = pn533_alloc_skb(dev, 0);
1135 if (!skb)
1136 return;
1138 rc = pn533_send_cmd_direct_async(dev,
1139 PN533_CMD_TG_GET_DATA,
1140 skb,
1141 pn533_tm_get_data_complete,
1142 NULL);
1144 if (rc < 0)
1145 dev_kfree_skb(skb);
1148 static int pn533_tm_send_complete(struct pn533 *dev, void *arg,
1149 struct sk_buff *resp);
1150 static void pn533_wq_tm_mi_send(struct work_struct *work)
1152 struct pn533 *dev = container_of(work, struct pn533, mi_tm_tx_work);
1153 struct sk_buff *skb;
1154 int rc;
1156 dev_dbg(dev->dev, "%s\n", __func__);
1158 /* Grab the first skb in the queue */
1159 skb = skb_dequeue(&dev->fragment_skb);
1160 if (skb == NULL) { /* No more data */
1161 /* Reset the queue for future use */
1162 skb_queue_head_init(&dev->fragment_skb);
1163 goto error;
1166 /* last entry - remove MI bit */
1167 if (skb_queue_len(&dev->fragment_skb) == 0) {
1168 rc = pn533_send_cmd_direct_async(dev, PN533_CMD_TG_SET_DATA,
1169 skb, pn533_tm_send_complete, NULL);
1170 } else
1171 rc = pn533_send_cmd_direct_async(dev,
1172 PN533_CMD_TG_SET_META_DATA,
1173 skb, pn533_tm_send_complete, NULL);
1175 if (rc == 0) /* success */
1176 return;
1178 dev_err(dev->dev,
1179 "Error %d when trying to perform set meta data_exchange", rc);
1181 dev_kfree_skb(skb);
1183 error:
1184 dev->phy_ops->send_ack(dev, GFP_KERNEL);
1185 queue_work(dev->wq, &dev->cmd_work);
1188 static void pn533_wq_tg_get_data(struct work_struct *work)
1190 struct pn533 *dev = container_of(work, struct pn533, tg_work);
1191 struct sk_buff *skb;
1192 int rc;
1194 dev_dbg(dev->dev, "%s\n", __func__);
1196 skb = pn533_alloc_skb(dev, 0);
1197 if (!skb)
1198 return;
1200 rc = pn533_send_data_async(dev, PN533_CMD_TG_GET_DATA, skb,
1201 pn533_tm_get_data_complete, NULL);
1203 if (rc < 0)
1204 dev_kfree_skb(skb);
1207 #define ATR_REQ_GB_OFFSET 17
1208 static int pn533_init_target_complete(struct pn533 *dev, struct sk_buff *resp)
1210 u8 mode, *cmd, comm_mode = NFC_COMM_PASSIVE, *gb;
1211 size_t gb_len;
1212 int rc;
1214 dev_dbg(dev->dev, "%s\n", __func__);
1216 if (resp->len < ATR_REQ_GB_OFFSET + 1)
1217 return -EINVAL;
1219 mode = resp->data[0];
1220 cmd = &resp->data[1];
1222 dev_dbg(dev->dev, "Target mode 0x%x len %d\n",
1223 mode, resp->len);
1225 if ((mode & PN533_INIT_TARGET_RESP_FRAME_MASK) ==
1226 PN533_INIT_TARGET_RESP_ACTIVE)
1227 comm_mode = NFC_COMM_ACTIVE;
1229 if ((mode & PN533_INIT_TARGET_RESP_DEP) == 0) /* Only DEP supported */
1230 return -EOPNOTSUPP;
1232 gb = cmd + ATR_REQ_GB_OFFSET;
1233 gb_len = resp->len - (ATR_REQ_GB_OFFSET + 1);
1235 rc = nfc_tm_activated(dev->nfc_dev, NFC_PROTO_NFC_DEP_MASK,
1236 comm_mode, gb, gb_len);
1237 if (rc < 0) {
1238 nfc_err(dev->dev,
1239 "Error when signaling target activation\n");
1240 return rc;
1243 dev->tgt_mode = 1;
1244 queue_work(dev->wq, &dev->tg_work);
1246 return 0;
1249 static void pn533_listen_mode_timer(struct timer_list *t)
1251 struct pn533 *dev = from_timer(dev, t, listen_timer);
1253 dev_dbg(dev->dev, "Listen mode timeout\n");
1255 dev->cancel_listen = 1;
1257 pn533_poll_next_mod(dev);
1259 queue_delayed_work(dev->wq, &dev->poll_work,
1260 msecs_to_jiffies(PN533_POLL_INTERVAL));
1263 static int pn533_rf_complete(struct pn533 *dev, void *arg,
1264 struct sk_buff *resp)
1266 int rc = 0;
1268 dev_dbg(dev->dev, "%s\n", __func__);
1270 if (IS_ERR(resp)) {
1271 rc = PTR_ERR(resp);
1273 nfc_err(dev->dev, "RF setting error %d\n", rc);
1275 return rc;
1278 queue_delayed_work(dev->wq, &dev->poll_work,
1279 msecs_to_jiffies(PN533_POLL_INTERVAL));
1281 dev_kfree_skb(resp);
1282 return rc;
1285 static void pn533_wq_rf(struct work_struct *work)
1287 struct pn533 *dev = container_of(work, struct pn533, rf_work);
1288 struct sk_buff *skb;
1289 int rc;
1291 dev_dbg(dev->dev, "%s\n", __func__);
1293 skb = pn533_alloc_skb(dev, 2);
1294 if (!skb)
1295 return;
1297 skb_put_u8(skb, PN533_CFGITEM_RF_FIELD);
1298 skb_put_u8(skb, PN533_CFGITEM_RF_FIELD_AUTO_RFCA);
1300 rc = pn533_send_cmd_async(dev, PN533_CMD_RF_CONFIGURATION, skb,
1301 pn533_rf_complete, NULL);
1302 if (rc < 0) {
1303 dev_kfree_skb(skb);
1304 nfc_err(dev->dev, "RF setting error %d\n", rc);
1308 static int pn533_poll_dep_complete(struct pn533 *dev, void *arg,
1309 struct sk_buff *resp)
1311 struct pn533_cmd_jump_dep_response *rsp;
1312 struct nfc_target nfc_target;
1313 u8 target_gt_len;
1314 int rc;
1316 if (IS_ERR(resp))
1317 return PTR_ERR(resp);
1319 rsp = (struct pn533_cmd_jump_dep_response *)resp->data;
1321 rc = rsp->status & PN533_CMD_RET_MASK;
1322 if (rc != PN533_CMD_RET_SUCCESS) {
1323 /* Not target found, turn radio off */
1324 queue_work(dev->wq, &dev->rf_work);
1326 dev_kfree_skb(resp);
1327 return 0;
1330 dev_dbg(dev->dev, "Creating new target");
1332 nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
1333 nfc_target.nfcid1_len = 10;
1334 memcpy(nfc_target.nfcid1, rsp->nfcid3t, nfc_target.nfcid1_len);
1335 rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1);
1336 if (rc)
1337 goto error;
1339 dev->tgt_available_prots = 0;
1340 dev->tgt_active_prot = NFC_PROTO_NFC_DEP;
1342 /* ATR_RES general bytes are located at offset 17 */
1343 target_gt_len = resp->len - 17;
1344 rc = nfc_set_remote_general_bytes(dev->nfc_dev,
1345 rsp->gt, target_gt_len);
1346 if (!rc) {
1347 rc = nfc_dep_link_is_up(dev->nfc_dev,
1348 dev->nfc_dev->targets[0].idx,
1349 0, NFC_RF_INITIATOR);
1351 if (!rc)
1352 pn533_poll_reset_mod_list(dev);
1354 error:
1355 dev_kfree_skb(resp);
1356 return rc;
1359 #define PASSIVE_DATA_LEN 5
1360 static int pn533_poll_dep(struct nfc_dev *nfc_dev)
1362 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1363 struct sk_buff *skb;
1364 int rc, skb_len;
1365 u8 *next, nfcid3[NFC_NFCID3_MAXSIZE];
1366 u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3};
1368 dev_dbg(dev->dev, "%s", __func__);
1370 if (!dev->gb) {
1371 dev->gb = nfc_get_local_general_bytes(nfc_dev, &dev->gb_len);
1373 if (!dev->gb || !dev->gb_len) {
1374 dev->poll_dep = 0;
1375 queue_work(dev->wq, &dev->rf_work);
1379 skb_len = 3 + dev->gb_len; /* ActPass + BR + Next */
1380 skb_len += PASSIVE_DATA_LEN;
1382 /* NFCID3 */
1383 skb_len += NFC_NFCID3_MAXSIZE;
1384 nfcid3[0] = 0x1;
1385 nfcid3[1] = 0xfe;
1386 get_random_bytes(nfcid3 + 2, 6);
1388 skb = pn533_alloc_skb(dev, skb_len);
1389 if (!skb)
1390 return -ENOMEM;
1392 skb_put_u8(skb, 0x01); /* Active */
1393 skb_put_u8(skb, 0x02); /* 424 kbps */
1395 next = skb_put(skb, 1); /* Next */
1396 *next = 0;
1398 /* Copy passive data */
1399 skb_put_data(skb, passive_data, PASSIVE_DATA_LEN);
1400 *next |= 1;
1402 /* Copy NFCID3 (which is NFCID2 from SENSF_RES) */
1403 skb_put_data(skb, nfcid3, NFC_NFCID3_MAXSIZE);
1404 *next |= 2;
1406 skb_put_data(skb, dev->gb, dev->gb_len);
1407 *next |= 4; /* We have some Gi */
1409 rc = pn533_send_cmd_async(dev, PN533_CMD_IN_JUMP_FOR_DEP, skb,
1410 pn533_poll_dep_complete, NULL);
1412 if (rc < 0)
1413 dev_kfree_skb(skb);
1415 return rc;
1418 static int pn533_autopoll_complete(struct pn533 *dev, void *arg,
1419 struct sk_buff *resp)
1421 struct pn532_autopoll_resp *apr;
1422 struct nfc_target nfc_tgt;
1423 u8 nbtg;
1424 int rc;
1426 if (IS_ERR(resp)) {
1427 rc = PTR_ERR(resp);
1429 nfc_err(dev->dev, "%s autopoll complete error %d\n",
1430 __func__, rc);
1432 if (rc == -ENOENT) {
1433 if (dev->poll_mod_count != 0)
1434 return rc;
1435 goto stop_poll;
1436 } else if (rc < 0) {
1437 nfc_err(dev->dev,
1438 "Error %d when running autopoll\n", rc);
1439 goto stop_poll;
1443 nbtg = resp->data[0];
1444 if ((nbtg > 2) || (nbtg <= 0))
1445 return -EAGAIN;
1447 apr = (struct pn532_autopoll_resp *)&resp->data[1];
1448 while (nbtg--) {
1449 memset(&nfc_tgt, 0, sizeof(struct nfc_target));
1450 switch (apr->type) {
1451 case PN532_AUTOPOLL_TYPE_ISOA:
1452 dev_dbg(dev->dev, "ISOA\n");
1453 rc = pn533_target_found_type_a(&nfc_tgt, apr->tgdata,
1454 apr->ln - 1);
1455 break;
1456 case PN532_AUTOPOLL_TYPE_FELICA212:
1457 case PN532_AUTOPOLL_TYPE_FELICA424:
1458 dev_dbg(dev->dev, "FELICA\n");
1459 rc = pn533_target_found_felica(&nfc_tgt, apr->tgdata,
1460 apr->ln - 1);
1461 break;
1462 case PN532_AUTOPOLL_TYPE_JEWEL:
1463 dev_dbg(dev->dev, "JEWEL\n");
1464 rc = pn533_target_found_jewel(&nfc_tgt, apr->tgdata,
1465 apr->ln - 1);
1466 break;
1467 case PN532_AUTOPOLL_TYPE_ISOB:
1468 dev_dbg(dev->dev, "ISOB\n");
1469 rc = pn533_target_found_type_b(&nfc_tgt, apr->tgdata,
1470 apr->ln - 1);
1471 break;
1472 case PN532_AUTOPOLL_TYPE_MIFARE:
1473 dev_dbg(dev->dev, "Mifare\n");
1474 rc = pn533_target_found_type_a(&nfc_tgt, apr->tgdata,
1475 apr->ln - 1);
1476 break;
1477 default:
1478 nfc_err(dev->dev,
1479 "Unknown current poll modulation\n");
1480 rc = -EPROTO;
1483 if (rc)
1484 goto done;
1486 if (!(nfc_tgt.supported_protocols & dev->poll_protocols)) {
1487 nfc_err(dev->dev,
1488 "The Tg found doesn't have the desired protocol\n");
1489 rc = -EAGAIN;
1490 goto done;
1493 dev->tgt_available_prots = nfc_tgt.supported_protocols;
1494 apr = (struct pn532_autopoll_resp *)
1495 (apr->tgdata + (apr->ln - 1));
1498 pn533_poll_reset_mod_list(dev);
1499 nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1);
1501 done:
1502 dev_kfree_skb(resp);
1503 return rc;
1505 stop_poll:
1506 nfc_err(dev->dev, "autopoll operation has been stopped\n");
1508 pn533_poll_reset_mod_list(dev);
1509 dev->poll_protocols = 0;
1510 return rc;
1513 static int pn533_poll_complete(struct pn533 *dev, void *arg,
1514 struct sk_buff *resp)
1516 struct pn533_poll_modulations *cur_mod;
1517 int rc;
1519 dev_dbg(dev->dev, "%s\n", __func__);
1521 if (IS_ERR(resp)) {
1522 rc = PTR_ERR(resp);
1524 nfc_err(dev->dev, "%s Poll complete error %d\n",
1525 __func__, rc);
1527 if (rc == -ENOENT) {
1528 if (dev->poll_mod_count != 0)
1529 return rc;
1530 goto stop_poll;
1531 } else if (rc < 0) {
1532 nfc_err(dev->dev,
1533 "Error %d when running poll\n", rc);
1534 goto stop_poll;
1538 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1540 if (cur_mod->len == 0) { /* Target mode */
1541 del_timer(&dev->listen_timer);
1542 rc = pn533_init_target_complete(dev, resp);
1543 goto done;
1546 /* Initiator mode */
1547 rc = pn533_start_poll_complete(dev, resp);
1548 if (!rc)
1549 goto done;
1551 if (!dev->poll_mod_count) {
1552 dev_dbg(dev->dev, "Polling has been stopped\n");
1553 goto done;
1556 pn533_poll_next_mod(dev);
1557 /* Not target found, turn radio off */
1558 queue_work(dev->wq, &dev->rf_work);
1560 done:
1561 dev_kfree_skb(resp);
1562 return rc;
1564 stop_poll:
1565 nfc_err(dev->dev, "Polling operation has been stopped\n");
1567 pn533_poll_reset_mod_list(dev);
1568 dev->poll_protocols = 0;
1569 return rc;
1572 static struct sk_buff *pn533_alloc_poll_in_frame(struct pn533 *dev,
1573 struct pn533_poll_modulations *mod)
1575 struct sk_buff *skb;
1577 skb = pn533_alloc_skb(dev, mod->len);
1578 if (!skb)
1579 return NULL;
1581 skb_put_data(skb, &mod->data, mod->len);
1583 return skb;
1586 static int pn533_send_poll_frame(struct pn533 *dev)
1588 struct pn533_poll_modulations *mod;
1589 struct sk_buff *skb;
1590 int rc;
1591 u8 cmd_code;
1593 mod = dev->poll_mod_active[dev->poll_mod_curr];
1595 dev_dbg(dev->dev, "%s mod len %d\n",
1596 __func__, mod->len);
1598 if ((dev->poll_protocols & NFC_PROTO_NFC_DEP_MASK) && dev->poll_dep) {
1599 dev->poll_dep = 0;
1600 return pn533_poll_dep(dev->nfc_dev);
1603 if (mod->len == 0) { /* Listen mode */
1604 cmd_code = PN533_CMD_TG_INIT_AS_TARGET;
1605 skb = pn533_alloc_poll_tg_frame(dev);
1606 } else { /* Polling mode */
1607 cmd_code = PN533_CMD_IN_LIST_PASSIVE_TARGET;
1608 skb = pn533_alloc_poll_in_frame(dev, mod);
1611 if (!skb) {
1612 nfc_err(dev->dev, "Failed to allocate skb\n");
1613 return -ENOMEM;
1616 rc = pn533_send_cmd_async(dev, cmd_code, skb, pn533_poll_complete,
1617 NULL);
1618 if (rc < 0) {
1619 dev_kfree_skb(skb);
1620 nfc_err(dev->dev, "Polling loop error %d\n", rc);
1623 return rc;
1626 static void pn533_wq_poll(struct work_struct *work)
1628 struct pn533 *dev = container_of(work, struct pn533, poll_work.work);
1629 struct pn533_poll_modulations *cur_mod;
1630 int rc;
1632 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1634 dev_dbg(dev->dev,
1635 "%s cancel_listen %d modulation len %d\n",
1636 __func__, dev->cancel_listen, cur_mod->len);
1638 if (dev->cancel_listen == 1) {
1639 dev->cancel_listen = 0;
1640 dev->phy_ops->abort_cmd(dev, GFP_ATOMIC);
1643 rc = pn533_send_poll_frame(dev);
1644 if (rc)
1645 return;
1647 if (cur_mod->len == 0 && dev->poll_mod_count > 1)
1648 mod_timer(&dev->listen_timer, jiffies + PN533_LISTEN_TIME * HZ);
1651 static int pn533_start_poll(struct nfc_dev *nfc_dev,
1652 u32 im_protocols, u32 tm_protocols)
1654 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1655 struct pn533_poll_modulations *cur_mod;
1656 struct sk_buff *skb;
1657 u8 rand_mod;
1658 int rc;
1660 dev_dbg(dev->dev,
1661 "%s: im protocols 0x%x tm protocols 0x%x\n",
1662 __func__, im_protocols, tm_protocols);
1664 if (dev->tgt_active_prot) {
1665 nfc_err(dev->dev,
1666 "Cannot poll with a target already activated\n");
1667 return -EBUSY;
1670 if (dev->tgt_mode) {
1671 nfc_err(dev->dev,
1672 "Cannot poll while already being activated\n");
1673 return -EBUSY;
1676 if (tm_protocols) {
1677 dev->gb = nfc_get_local_general_bytes(nfc_dev, &dev->gb_len);
1678 if (dev->gb == NULL)
1679 tm_protocols = 0;
1682 dev->poll_protocols = im_protocols;
1683 dev->listen_protocols = tm_protocols;
1684 if (dev->device_type == PN533_DEVICE_PN532_AUTOPOLL) {
1685 skb = pn533_alloc_skb(dev, 4 + 6);
1686 if (!skb)
1687 return -ENOMEM;
1689 *((u8 *)skb_put(skb, sizeof(u8))) =
1690 PN532_AUTOPOLL_POLLNR_INFINITE;
1691 *((u8 *)skb_put(skb, sizeof(u8))) = PN532_AUTOPOLL_PERIOD;
1693 if ((im_protocols & NFC_PROTO_MIFARE_MASK) &&
1694 (im_protocols & NFC_PROTO_ISO14443_MASK) &&
1695 (im_protocols & NFC_PROTO_NFC_DEP_MASK))
1696 *((u8 *)skb_put(skb, sizeof(u8))) =
1697 PN532_AUTOPOLL_TYPE_GENERIC_106;
1698 else {
1699 if (im_protocols & NFC_PROTO_MIFARE_MASK)
1700 *((u8 *)skb_put(skb, sizeof(u8))) =
1701 PN532_AUTOPOLL_TYPE_MIFARE;
1703 if (im_protocols & NFC_PROTO_ISO14443_MASK)
1704 *((u8 *)skb_put(skb, sizeof(u8))) =
1705 PN532_AUTOPOLL_TYPE_ISOA;
1707 if (im_protocols & NFC_PROTO_NFC_DEP_MASK) {
1708 *((u8 *)skb_put(skb, sizeof(u8))) =
1709 PN532_AUTOPOLL_TYPE_DEP_PASSIVE_106;
1710 *((u8 *)skb_put(skb, sizeof(u8))) =
1711 PN532_AUTOPOLL_TYPE_DEP_PASSIVE_212;
1712 *((u8 *)skb_put(skb, sizeof(u8))) =
1713 PN532_AUTOPOLL_TYPE_DEP_PASSIVE_424;
1717 if (im_protocols & NFC_PROTO_FELICA_MASK ||
1718 im_protocols & NFC_PROTO_NFC_DEP_MASK) {
1719 *((u8 *)skb_put(skb, sizeof(u8))) =
1720 PN532_AUTOPOLL_TYPE_FELICA212;
1721 *((u8 *)skb_put(skb, sizeof(u8))) =
1722 PN532_AUTOPOLL_TYPE_FELICA424;
1725 if (im_protocols & NFC_PROTO_JEWEL_MASK)
1726 *((u8 *)skb_put(skb, sizeof(u8))) =
1727 PN532_AUTOPOLL_TYPE_JEWEL;
1729 if (im_protocols & NFC_PROTO_ISO14443_B_MASK)
1730 *((u8 *)skb_put(skb, sizeof(u8))) =
1731 PN532_AUTOPOLL_TYPE_ISOB;
1733 if (tm_protocols)
1734 *((u8 *)skb_put(skb, sizeof(u8))) =
1735 PN532_AUTOPOLL_TYPE_DEP_ACTIVE_106;
1737 rc = pn533_send_cmd_async(dev, PN533_CMD_IN_AUTOPOLL, skb,
1738 pn533_autopoll_complete, NULL);
1740 if (rc < 0)
1741 dev_kfree_skb(skb);
1742 else
1743 dev->poll_mod_count++;
1745 return rc;
1748 pn533_poll_create_mod_list(dev, im_protocols, tm_protocols);
1750 /* Do not always start polling from the same modulation */
1751 get_random_bytes(&rand_mod, sizeof(rand_mod));
1752 rand_mod %= dev->poll_mod_count;
1753 dev->poll_mod_curr = rand_mod;
1755 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1757 rc = pn533_send_poll_frame(dev);
1759 /* Start listen timer */
1760 if (!rc && cur_mod->len == 0 && dev->poll_mod_count > 1)
1761 mod_timer(&dev->listen_timer, jiffies + PN533_LISTEN_TIME * HZ);
1763 return rc;
1766 static void pn533_stop_poll(struct nfc_dev *nfc_dev)
1768 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1770 del_timer(&dev->listen_timer);
1772 if (!dev->poll_mod_count) {
1773 dev_dbg(dev->dev,
1774 "Polling operation was not running\n");
1775 return;
1778 dev->phy_ops->abort_cmd(dev, GFP_KERNEL);
1779 flush_delayed_work(&dev->poll_work);
1780 pn533_poll_reset_mod_list(dev);
1783 static int pn533_activate_target_nfcdep(struct pn533 *dev)
1785 struct pn533_cmd_activate_response *rsp;
1786 u16 gt_len;
1787 int rc;
1788 struct sk_buff *skb;
1789 struct sk_buff *resp;
1791 dev_dbg(dev->dev, "%s\n", __func__);
1793 skb = pn533_alloc_skb(dev, sizeof(u8) * 2); /*TG + Next*/
1794 if (!skb)
1795 return -ENOMEM;
1797 skb_put_u8(skb, 1); /* TG */
1798 skb_put_u8(skb, 0); /* Next */
1800 resp = pn533_send_cmd_sync(dev, PN533_CMD_IN_ATR, skb);
1801 if (IS_ERR(resp))
1802 return PTR_ERR(resp);
1804 rsp = (struct pn533_cmd_activate_response *)resp->data;
1805 rc = rsp->status & PN533_CMD_RET_MASK;
1806 if (rc != PN533_CMD_RET_SUCCESS) {
1807 nfc_err(dev->dev,
1808 "Target activation failed (error 0x%x)\n", rc);
1809 dev_kfree_skb(resp);
1810 return -EIO;
1813 /* ATR_RES general bytes are located at offset 16 */
1814 gt_len = resp->len - 16;
1815 rc = nfc_set_remote_general_bytes(dev->nfc_dev, rsp->gt, gt_len);
1817 dev_kfree_skb(resp);
1818 return rc;
1821 static int pn533_activate_target(struct nfc_dev *nfc_dev,
1822 struct nfc_target *target, u32 protocol)
1824 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1825 int rc;
1827 dev_dbg(dev->dev, "%s: protocol=%u\n", __func__, protocol);
1829 if (dev->poll_mod_count) {
1830 nfc_err(dev->dev,
1831 "Cannot activate while polling\n");
1832 return -EBUSY;
1835 if (dev->tgt_active_prot) {
1836 nfc_err(dev->dev,
1837 "There is already an active target\n");
1838 return -EBUSY;
1841 if (!dev->tgt_available_prots) {
1842 nfc_err(dev->dev,
1843 "There is no available target to activate\n");
1844 return -EINVAL;
1847 if (!(dev->tgt_available_prots & (1 << protocol))) {
1848 nfc_err(dev->dev,
1849 "Target doesn't support requested proto %u\n",
1850 protocol);
1851 return -EINVAL;
1854 if (protocol == NFC_PROTO_NFC_DEP) {
1855 rc = pn533_activate_target_nfcdep(dev);
1856 if (rc) {
1857 nfc_err(dev->dev,
1858 "Activating target with DEP failed %d\n", rc);
1859 return rc;
1863 dev->tgt_active_prot = protocol;
1864 dev->tgt_available_prots = 0;
1866 return 0;
1869 static int pn533_deactivate_target_complete(struct pn533 *dev, void *arg,
1870 struct sk_buff *resp)
1872 int rc = 0;
1874 dev_dbg(dev->dev, "%s\n", __func__);
1876 if (IS_ERR(resp)) {
1877 rc = PTR_ERR(resp);
1879 nfc_err(dev->dev, "Target release error %d\n", rc);
1881 return rc;
1884 rc = resp->data[0] & PN533_CMD_RET_MASK;
1885 if (rc != PN533_CMD_RET_SUCCESS)
1886 nfc_err(dev->dev,
1887 "Error 0x%x when releasing the target\n", rc);
1889 dev_kfree_skb(resp);
1890 return rc;
1893 static void pn533_deactivate_target(struct nfc_dev *nfc_dev,
1894 struct nfc_target *target, u8 mode)
1896 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1897 struct sk_buff *skb;
1898 int rc;
1900 dev_dbg(dev->dev, "%s\n", __func__);
1902 if (!dev->tgt_active_prot) {
1903 nfc_err(dev->dev, "There is no active target\n");
1904 return;
1907 dev->tgt_active_prot = 0;
1908 skb_queue_purge(&dev->resp_q);
1910 skb = pn533_alloc_skb(dev, sizeof(u8));
1911 if (!skb)
1912 return;
1914 skb_put_u8(skb, 1); /* TG*/
1916 rc = pn533_send_cmd_async(dev, PN533_CMD_IN_RELEASE, skb,
1917 pn533_deactivate_target_complete, NULL);
1918 if (rc < 0) {
1919 dev_kfree_skb(skb);
1920 nfc_err(dev->dev, "Target release error %d\n", rc);
1925 static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,
1926 struct sk_buff *resp)
1928 struct pn533_cmd_jump_dep_response *rsp;
1929 u8 target_gt_len;
1930 int rc;
1931 u8 active = *(u8 *)arg;
1933 kfree(arg);
1935 if (IS_ERR(resp))
1936 return PTR_ERR(resp);
1938 if (dev->tgt_available_prots &&
1939 !(dev->tgt_available_prots & (1 << NFC_PROTO_NFC_DEP))) {
1940 nfc_err(dev->dev,
1941 "The target does not support DEP\n");
1942 rc = -EINVAL;
1943 goto error;
1946 rsp = (struct pn533_cmd_jump_dep_response *)resp->data;
1948 rc = rsp->status & PN533_CMD_RET_MASK;
1949 if (rc != PN533_CMD_RET_SUCCESS) {
1950 nfc_err(dev->dev,
1951 "Bringing DEP link up failed (error 0x%x)\n", rc);
1952 goto error;
1955 if (!dev->tgt_available_prots) {
1956 struct nfc_target nfc_target;
1958 dev_dbg(dev->dev, "Creating new target\n");
1960 nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
1961 nfc_target.nfcid1_len = 10;
1962 memcpy(nfc_target.nfcid1, rsp->nfcid3t, nfc_target.nfcid1_len);
1963 rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1);
1964 if (rc)
1965 goto error;
1967 dev->tgt_available_prots = 0;
1970 dev->tgt_active_prot = NFC_PROTO_NFC_DEP;
1972 /* ATR_RES general bytes are located at offset 17 */
1973 target_gt_len = resp->len - 17;
1974 rc = nfc_set_remote_general_bytes(dev->nfc_dev,
1975 rsp->gt, target_gt_len);
1976 if (rc == 0)
1977 rc = nfc_dep_link_is_up(dev->nfc_dev,
1978 dev->nfc_dev->targets[0].idx,
1979 !active, NFC_RF_INITIATOR);
1981 error:
1982 dev_kfree_skb(resp);
1983 return rc;
1986 static int pn533_rf_field(struct nfc_dev *nfc_dev, u8 rf);
1987 static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
1988 u8 comm_mode, u8 *gb, size_t gb_len)
1990 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1991 struct sk_buff *skb;
1992 int rc, skb_len;
1993 u8 *next, *arg, nfcid3[NFC_NFCID3_MAXSIZE];
1994 u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3};
1996 dev_dbg(dev->dev, "%s\n", __func__);
1998 if (dev->poll_mod_count) {
1999 nfc_err(dev->dev,
2000 "Cannot bring the DEP link up while polling\n");
2001 return -EBUSY;
2004 if (dev->tgt_active_prot) {
2005 nfc_err(dev->dev,
2006 "There is already an active target\n");
2007 return -EBUSY;
2010 skb_len = 3 + gb_len; /* ActPass + BR + Next */
2011 skb_len += PASSIVE_DATA_LEN;
2013 /* NFCID3 */
2014 skb_len += NFC_NFCID3_MAXSIZE;
2015 if (target && !target->nfcid2_len) {
2016 nfcid3[0] = 0x1;
2017 nfcid3[1] = 0xfe;
2018 get_random_bytes(nfcid3 + 2, 6);
2021 skb = pn533_alloc_skb(dev, skb_len);
2022 if (!skb)
2023 return -ENOMEM;
2025 skb_put_u8(skb, !comm_mode); /* ActPass */
2026 skb_put_u8(skb, 0x02); /* 424 kbps */
2028 next = skb_put(skb, 1); /* Next */
2029 *next = 0;
2031 /* Copy passive data */
2032 skb_put_data(skb, passive_data, PASSIVE_DATA_LEN);
2033 *next |= 1;
2035 /* Copy NFCID3 (which is NFCID2 from SENSF_RES) */
2036 if (target && target->nfcid2_len)
2037 memcpy(skb_put(skb, NFC_NFCID3_MAXSIZE), target->nfcid2,
2038 target->nfcid2_len);
2039 else
2040 skb_put_data(skb, nfcid3, NFC_NFCID3_MAXSIZE);
2041 *next |= 2;
2043 if (gb != NULL && gb_len > 0) {
2044 skb_put_data(skb, gb, gb_len);
2045 *next |= 4; /* We have some Gi */
2046 } else {
2047 *next = 0;
2050 arg = kmalloc(sizeof(*arg), GFP_KERNEL);
2051 if (!arg) {
2052 dev_kfree_skb(skb);
2053 return -ENOMEM;
2056 *arg = !comm_mode;
2058 pn533_rf_field(dev->nfc_dev, 0);
2060 rc = pn533_send_cmd_async(dev, PN533_CMD_IN_JUMP_FOR_DEP, skb,
2061 pn533_in_dep_link_up_complete, arg);
2063 if (rc < 0) {
2064 dev_kfree_skb(skb);
2065 kfree(arg);
2068 return rc;
2071 static int pn533_dep_link_down(struct nfc_dev *nfc_dev)
2073 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2075 dev_dbg(dev->dev, "%s\n", __func__);
2077 pn533_poll_reset_mod_list(dev);
2079 if (dev->tgt_mode || dev->tgt_active_prot)
2080 dev->phy_ops->abort_cmd(dev, GFP_KERNEL);
2082 dev->tgt_active_prot = 0;
2083 dev->tgt_mode = 0;
2085 skb_queue_purge(&dev->resp_q);
2087 return 0;
2090 struct pn533_data_exchange_arg {
2091 data_exchange_cb_t cb;
2092 void *cb_context;
2095 static struct sk_buff *pn533_build_response(struct pn533 *dev)
2097 struct sk_buff *skb, *tmp, *t;
2098 unsigned int skb_len = 0, tmp_len = 0;
2100 dev_dbg(dev->dev, "%s\n", __func__);
2102 if (skb_queue_empty(&dev->resp_q))
2103 return NULL;
2105 if (skb_queue_len(&dev->resp_q) == 1) {
2106 skb = skb_dequeue(&dev->resp_q);
2107 goto out;
2110 skb_queue_walk_safe(&dev->resp_q, tmp, t)
2111 skb_len += tmp->len;
2113 dev_dbg(dev->dev, "%s total length %d\n",
2114 __func__, skb_len);
2116 skb = alloc_skb(skb_len, GFP_KERNEL);
2117 if (skb == NULL)
2118 goto out;
2120 skb_put(skb, skb_len);
2122 skb_queue_walk_safe(&dev->resp_q, tmp, t) {
2123 memcpy(skb->data + tmp_len, tmp->data, tmp->len);
2124 tmp_len += tmp->len;
2127 out:
2128 skb_queue_purge(&dev->resp_q);
2130 return skb;
2133 static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg,
2134 struct sk_buff *resp)
2136 struct pn533_data_exchange_arg *arg = _arg;
2137 struct sk_buff *skb;
2138 int rc = 0;
2139 u8 status, ret, mi;
2141 dev_dbg(dev->dev, "%s\n", __func__);
2143 if (IS_ERR(resp)) {
2144 rc = PTR_ERR(resp);
2145 goto _error;
2148 status = resp->data[0];
2149 ret = status & PN533_CMD_RET_MASK;
2150 mi = status & PN533_CMD_MI_MASK;
2152 skb_pull(resp, sizeof(status));
2154 if (ret != PN533_CMD_RET_SUCCESS) {
2155 nfc_err(dev->dev,
2156 "Exchanging data failed (error 0x%x)\n", ret);
2157 rc = -EIO;
2158 goto error;
2161 skb_queue_tail(&dev->resp_q, resp);
2163 if (mi) {
2164 dev->cmd_complete_mi_arg = arg;
2165 queue_work(dev->wq, &dev->mi_rx_work);
2166 return -EINPROGRESS;
2169 /* Prepare for the next round */
2170 if (skb_queue_len(&dev->fragment_skb) > 0) {
2171 dev->cmd_complete_dep_arg = arg;
2172 queue_work(dev->wq, &dev->mi_tx_work);
2174 return -EINPROGRESS;
2177 skb = pn533_build_response(dev);
2178 if (!skb) {
2179 rc = -ENOMEM;
2180 goto error;
2183 arg->cb(arg->cb_context, skb, 0);
2184 kfree(arg);
2185 return 0;
2187 error:
2188 dev_kfree_skb(resp);
2189 _error:
2190 skb_queue_purge(&dev->resp_q);
2191 arg->cb(arg->cb_context, NULL, rc);
2192 kfree(arg);
2193 return rc;
2197 * Receive an incoming pn533 frame. skb contains only header and payload.
2198 * If skb == NULL, it is a notification that the link below is dead.
2200 void pn533_recv_frame(struct pn533 *dev, struct sk_buff *skb, int status)
2202 if (!dev->cmd)
2203 goto sched_wq;
2205 dev->cmd->status = status;
2207 if (status != 0) {
2208 dev_dbg(dev->dev, "%s: Error received: %d\n", __func__, status);
2209 goto sched_wq;
2212 if (skb == NULL) {
2213 pr_err("NULL Frame -> link is dead\n");
2214 goto sched_wq;
2217 if (pn533_rx_frame_is_ack(skb->data)) {
2218 dev_dbg(dev->dev, "%s: Received ACK frame\n", __func__);
2219 dev_kfree_skb(skb);
2220 return;
2223 print_hex_dump_debug("PN533 RX: ", DUMP_PREFIX_NONE, 16, 1, skb->data,
2224 dev->ops->rx_frame_size(skb->data), false);
2226 if (!dev->ops->rx_is_frame_valid(skb->data, dev)) {
2227 nfc_err(dev->dev, "Received an invalid frame\n");
2228 dev->cmd->status = -EIO;
2229 } else if (!pn533_rx_frame_is_cmd_response(dev, skb->data)) {
2230 nfc_err(dev->dev, "It it not the response to the last command\n");
2231 dev->cmd->status = -EIO;
2234 dev->cmd->resp = skb;
2236 sched_wq:
2237 queue_work(dev->wq, &dev->cmd_complete_work);
2239 EXPORT_SYMBOL(pn533_recv_frame);
2241 /* Split the Tx skb into small chunks */
2242 static int pn533_fill_fragment_skbs(struct pn533 *dev, struct sk_buff *skb)
2244 struct sk_buff *frag;
2245 int frag_size;
2247 do {
2248 /* Remaining size */
2249 if (skb->len > PN533_CMD_DATAFRAME_MAXLEN)
2250 frag_size = PN533_CMD_DATAFRAME_MAXLEN;
2251 else
2252 frag_size = skb->len;
2254 /* Allocate and reserve */
2255 frag = pn533_alloc_skb(dev, frag_size);
2256 if (!frag) {
2257 skb_queue_purge(&dev->fragment_skb);
2258 break;
2261 if (!dev->tgt_mode) {
2262 /* Reserve the TG/MI byte */
2263 skb_reserve(frag, 1);
2265 /* MI + TG */
2266 if (frag_size == PN533_CMD_DATAFRAME_MAXLEN)
2267 *(u8 *)skb_push(frag, sizeof(u8)) =
2268 (PN533_CMD_MI_MASK | 1);
2269 else
2270 *(u8 *)skb_push(frag, sizeof(u8)) = 1; /* TG */
2273 skb_put_data(frag, skb->data, frag_size);
2275 /* Reduce the size of incoming buffer */
2276 skb_pull(skb, frag_size);
2278 /* Add this to skb_queue */
2279 skb_queue_tail(&dev->fragment_skb, frag);
2281 } while (skb->len > 0);
2283 dev_kfree_skb(skb);
2285 return skb_queue_len(&dev->fragment_skb);
2288 static int pn533_transceive(struct nfc_dev *nfc_dev,
2289 struct nfc_target *target, struct sk_buff *skb,
2290 data_exchange_cb_t cb, void *cb_context)
2292 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2293 struct pn533_data_exchange_arg *arg = NULL;
2294 int rc;
2296 dev_dbg(dev->dev, "%s\n", __func__);
2298 if (!dev->tgt_active_prot) {
2299 nfc_err(dev->dev,
2300 "Can't exchange data if there is no active target\n");
2301 rc = -EINVAL;
2302 goto error;
2305 arg = kmalloc(sizeof(*arg), GFP_KERNEL);
2306 if (!arg) {
2307 rc = -ENOMEM;
2308 goto error;
2311 arg->cb = cb;
2312 arg->cb_context = cb_context;
2314 switch (dev->device_type) {
2315 case PN533_DEVICE_PASORI:
2316 if (dev->tgt_active_prot == NFC_PROTO_FELICA) {
2317 rc = pn533_send_data_async(dev, PN533_CMD_IN_COMM_THRU,
2318 skb,
2319 pn533_data_exchange_complete,
2320 arg);
2322 break;
2324 /* fall through */
2325 default:
2326 /* jumbo frame ? */
2327 if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
2328 rc = pn533_fill_fragment_skbs(dev, skb);
2329 if (rc <= 0)
2330 goto error;
2332 skb = skb_dequeue(&dev->fragment_skb);
2333 if (!skb) {
2334 rc = -EIO;
2335 goto error;
2337 } else {
2338 *(u8 *)skb_push(skb, sizeof(u8)) = 1; /* TG */
2341 rc = pn533_send_data_async(dev, PN533_CMD_IN_DATA_EXCHANGE,
2342 skb, pn533_data_exchange_complete,
2343 arg);
2345 break;
2348 if (rc < 0) /* rc from send_async */
2349 goto error;
2351 return 0;
2353 error:
2354 kfree(arg);
2355 dev_kfree_skb(skb);
2356 return rc;
2359 static int pn533_tm_send_complete(struct pn533 *dev, void *arg,
2360 struct sk_buff *resp)
2362 u8 status;
2364 dev_dbg(dev->dev, "%s\n", __func__);
2366 if (IS_ERR(resp))
2367 return PTR_ERR(resp);
2369 status = resp->data[0];
2371 /* Prepare for the next round */
2372 if (skb_queue_len(&dev->fragment_skb) > 0) {
2373 queue_work(dev->wq, &dev->mi_tm_tx_work);
2374 return -EINPROGRESS;
2376 dev_kfree_skb(resp);
2378 if (status != 0) {
2379 nfc_tm_deactivated(dev->nfc_dev);
2381 dev->tgt_mode = 0;
2383 return 0;
2386 queue_work(dev->wq, &dev->tg_work);
2388 return 0;
2391 static int pn533_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb)
2393 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2394 int rc;
2396 dev_dbg(dev->dev, "%s\n", __func__);
2398 /* let's split in multiple chunks if size's too big */
2399 if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
2400 rc = pn533_fill_fragment_skbs(dev, skb);
2401 if (rc <= 0)
2402 goto error;
2404 /* get the first skb */
2405 skb = skb_dequeue(&dev->fragment_skb);
2406 if (!skb) {
2407 rc = -EIO;
2408 goto error;
2411 rc = pn533_send_data_async(dev, PN533_CMD_TG_SET_META_DATA, skb,
2412 pn533_tm_send_complete, NULL);
2413 } else {
2414 /* Send th skb */
2415 rc = pn533_send_data_async(dev, PN533_CMD_TG_SET_DATA, skb,
2416 pn533_tm_send_complete, NULL);
2419 error:
2420 if (rc < 0) {
2421 dev_kfree_skb(skb);
2422 skb_queue_purge(&dev->fragment_skb);
2425 return rc;
2428 static void pn533_wq_mi_recv(struct work_struct *work)
2430 struct pn533 *dev = container_of(work, struct pn533, mi_rx_work);
2431 struct sk_buff *skb;
2432 int rc;
2434 dev_dbg(dev->dev, "%s\n", __func__);
2436 skb = pn533_alloc_skb(dev, PN533_CMD_DATAEXCH_HEAD_LEN);
2437 if (!skb)
2438 goto error;
2440 switch (dev->device_type) {
2441 case PN533_DEVICE_PASORI:
2442 if (dev->tgt_active_prot == NFC_PROTO_FELICA) {
2443 rc = pn533_send_cmd_direct_async(dev,
2444 PN533_CMD_IN_COMM_THRU,
2445 skb,
2446 pn533_data_exchange_complete,
2447 dev->cmd_complete_mi_arg);
2449 break;
2451 /* fall through */
2452 default:
2453 skb_put_u8(skb, 1); /*TG*/
2455 rc = pn533_send_cmd_direct_async(dev,
2456 PN533_CMD_IN_DATA_EXCHANGE,
2457 skb,
2458 pn533_data_exchange_complete,
2459 dev->cmd_complete_mi_arg);
2461 break;
2464 if (rc == 0) /* success */
2465 return;
2467 nfc_err(dev->dev,
2468 "Error %d when trying to perform data_exchange\n", rc);
2470 dev_kfree_skb(skb);
2471 kfree(dev->cmd_complete_mi_arg);
2473 error:
2474 dev->phy_ops->send_ack(dev, GFP_KERNEL);
2475 queue_work(dev->wq, &dev->cmd_work);
2478 static void pn533_wq_mi_send(struct work_struct *work)
2480 struct pn533 *dev = container_of(work, struct pn533, mi_tx_work);
2481 struct sk_buff *skb;
2482 int rc;
2484 dev_dbg(dev->dev, "%s\n", __func__);
2486 /* Grab the first skb in the queue */
2487 skb = skb_dequeue(&dev->fragment_skb);
2489 if (skb == NULL) { /* No more data */
2490 /* Reset the queue for future use */
2491 skb_queue_head_init(&dev->fragment_skb);
2492 goto error;
2495 switch (dev->device_type) {
2496 case PN533_DEVICE_PASORI:
2497 if (dev->tgt_active_prot != NFC_PROTO_FELICA) {
2498 rc = -EIO;
2499 break;
2502 rc = pn533_send_cmd_direct_async(dev, PN533_CMD_IN_COMM_THRU,
2503 skb,
2504 pn533_data_exchange_complete,
2505 dev->cmd_complete_dep_arg);
2507 break;
2509 default:
2510 /* Still some fragments? */
2511 rc = pn533_send_cmd_direct_async(dev,
2512 PN533_CMD_IN_DATA_EXCHANGE,
2513 skb,
2514 pn533_data_exchange_complete,
2515 dev->cmd_complete_dep_arg);
2517 break;
2520 if (rc == 0) /* success */
2521 return;
2523 nfc_err(dev->dev,
2524 "Error %d when trying to perform data_exchange\n", rc);
2526 dev_kfree_skb(skb);
2527 kfree(dev->cmd_complete_dep_arg);
2529 error:
2530 dev->phy_ops->send_ack(dev, GFP_KERNEL);
2531 queue_work(dev->wq, &dev->cmd_work);
2534 static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata,
2535 u8 cfgdata_len)
2537 struct sk_buff *skb;
2538 struct sk_buff *resp;
2539 int skb_len;
2541 dev_dbg(dev->dev, "%s\n", __func__);
2543 skb_len = sizeof(cfgitem) + cfgdata_len; /* cfgitem + cfgdata */
2545 skb = pn533_alloc_skb(dev, skb_len);
2546 if (!skb)
2547 return -ENOMEM;
2549 skb_put_u8(skb, cfgitem);
2550 skb_put_data(skb, cfgdata, cfgdata_len);
2552 resp = pn533_send_cmd_sync(dev, PN533_CMD_RF_CONFIGURATION, skb);
2553 if (IS_ERR(resp))
2554 return PTR_ERR(resp);
2556 dev_kfree_skb(resp);
2557 return 0;
2560 static int pn533_get_firmware_version(struct pn533 *dev,
2561 struct pn533_fw_version *fv)
2563 struct sk_buff *skb;
2564 struct sk_buff *resp;
2566 skb = pn533_alloc_skb(dev, 0);
2567 if (!skb)
2568 return -ENOMEM;
2570 resp = pn533_send_cmd_sync(dev, PN533_CMD_GET_FIRMWARE_VERSION, skb);
2571 if (IS_ERR(resp))
2572 return PTR_ERR(resp);
2574 fv->ic = resp->data[0];
2575 fv->ver = resp->data[1];
2576 fv->rev = resp->data[2];
2577 fv->support = resp->data[3];
2579 dev_kfree_skb(resp);
2580 return 0;
2583 static int pn533_pasori_fw_reset(struct pn533 *dev)
2585 struct sk_buff *skb;
2586 struct sk_buff *resp;
2588 dev_dbg(dev->dev, "%s\n", __func__);
2590 skb = pn533_alloc_skb(dev, sizeof(u8));
2591 if (!skb)
2592 return -ENOMEM;
2594 skb_put_u8(skb, 0x1);
2596 resp = pn533_send_cmd_sync(dev, 0x18, skb);
2597 if (IS_ERR(resp))
2598 return PTR_ERR(resp);
2600 dev_kfree_skb(resp);
2602 return 0;
2605 static int pn533_rf_field(struct nfc_dev *nfc_dev, u8 rf)
2607 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2608 u8 rf_field = !!rf;
2609 int rc;
2611 rf_field |= PN533_CFGITEM_RF_FIELD_AUTO_RFCA;
2613 rc = pn533_set_configuration(dev, PN533_CFGITEM_RF_FIELD,
2614 (u8 *)&rf_field, 1);
2615 if (rc) {
2616 nfc_err(dev->dev, "Error on setting RF field\n");
2617 return rc;
2620 return rc;
2623 static int pn532_sam_configuration(struct nfc_dev *nfc_dev)
2625 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2626 struct sk_buff *skb;
2627 struct sk_buff *resp;
2629 skb = pn533_alloc_skb(dev, 1);
2630 if (!skb)
2631 return -ENOMEM;
2633 skb_put_u8(skb, 0x01);
2635 resp = pn533_send_cmd_sync(dev, PN533_CMD_SAM_CONFIGURATION, skb);
2636 if (IS_ERR(resp))
2637 return PTR_ERR(resp);
2639 dev_kfree_skb(resp);
2640 return 0;
2643 static int pn533_dev_up(struct nfc_dev *nfc_dev)
2645 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2646 int rc;
2648 if (dev->phy_ops->dev_up) {
2649 rc = dev->phy_ops->dev_up(dev);
2650 if (rc)
2651 return rc;
2654 if ((dev->device_type == PN533_DEVICE_PN532) ||
2655 (dev->device_type == PN533_DEVICE_PN532_AUTOPOLL)) {
2656 rc = pn532_sam_configuration(nfc_dev);
2658 if (rc)
2659 return rc;
2662 return pn533_rf_field(nfc_dev, 1);
2665 static int pn533_dev_down(struct nfc_dev *nfc_dev)
2667 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2668 int ret;
2670 ret = pn533_rf_field(nfc_dev, 0);
2671 if (dev->phy_ops->dev_down && !ret)
2672 ret = dev->phy_ops->dev_down(dev);
2674 return ret;
2677 static struct nfc_ops pn533_nfc_ops = {
2678 .dev_up = pn533_dev_up,
2679 .dev_down = pn533_dev_down,
2680 .dep_link_up = pn533_dep_link_up,
2681 .dep_link_down = pn533_dep_link_down,
2682 .start_poll = pn533_start_poll,
2683 .stop_poll = pn533_stop_poll,
2684 .activate_target = pn533_activate_target,
2685 .deactivate_target = pn533_deactivate_target,
2686 .im_transceive = pn533_transceive,
2687 .tm_send = pn533_tm_send,
2690 static int pn533_setup(struct pn533 *dev)
2692 struct pn533_config_max_retries max_retries;
2693 struct pn533_config_timing timing;
2694 u8 pasori_cfg[3] = {0x08, 0x01, 0x08};
2695 int rc;
2697 switch (dev->device_type) {
2698 case PN533_DEVICE_STD:
2699 case PN533_DEVICE_PASORI:
2700 case PN533_DEVICE_ACR122U:
2701 case PN533_DEVICE_PN532:
2702 case PN533_DEVICE_PN532_AUTOPOLL:
2703 max_retries.mx_rty_atr = 0x2;
2704 max_retries.mx_rty_psl = 0x1;
2705 max_retries.mx_rty_passive_act =
2706 PN533_CONFIG_MAX_RETRIES_NO_RETRY;
2708 timing.rfu = PN533_CONFIG_TIMING_102;
2709 timing.atr_res_timeout = PN533_CONFIG_TIMING_102;
2710 timing.dep_timeout = PN533_CONFIG_TIMING_204;
2712 break;
2714 default:
2715 nfc_err(dev->dev, "Unknown device type %d\n",
2716 dev->device_type);
2717 return -EINVAL;
2720 rc = pn533_set_configuration(dev, PN533_CFGITEM_MAX_RETRIES,
2721 (u8 *)&max_retries, sizeof(max_retries));
2722 if (rc) {
2723 nfc_err(dev->dev,
2724 "Error on setting MAX_RETRIES config\n");
2725 return rc;
2729 rc = pn533_set_configuration(dev, PN533_CFGITEM_TIMING,
2730 (u8 *)&timing, sizeof(timing));
2731 if (rc) {
2732 nfc_err(dev->dev, "Error on setting RF timings\n");
2733 return rc;
2736 switch (dev->device_type) {
2737 case PN533_DEVICE_STD:
2738 case PN533_DEVICE_PN532:
2739 case PN533_DEVICE_PN532_AUTOPOLL:
2740 break;
2742 case PN533_DEVICE_PASORI:
2743 pn533_pasori_fw_reset(dev);
2745 rc = pn533_set_configuration(dev, PN533_CFGITEM_PASORI,
2746 pasori_cfg, 3);
2747 if (rc) {
2748 nfc_err(dev->dev,
2749 "Error while settings PASORI config\n");
2750 return rc;
2753 pn533_pasori_fw_reset(dev);
2755 break;
2758 return 0;
2761 int pn533_finalize_setup(struct pn533 *dev)
2764 struct pn533_fw_version fw_ver;
2765 int rc;
2767 memset(&fw_ver, 0, sizeof(fw_ver));
2769 rc = pn533_get_firmware_version(dev, &fw_ver);
2770 if (rc) {
2771 nfc_err(dev->dev, "Unable to get FW version\n");
2772 return rc;
2775 nfc_info(dev->dev, "NXP PN5%02X firmware ver %d.%d now attached\n",
2776 fw_ver.ic, fw_ver.ver, fw_ver.rev);
2778 rc = pn533_setup(dev);
2779 if (rc)
2780 return rc;
2782 return 0;
2784 EXPORT_SYMBOL_GPL(pn533_finalize_setup);
2786 struct pn533 *pn53x_common_init(u32 device_type,
2787 enum pn533_protocol_type protocol_type,
2788 void *phy,
2789 struct pn533_phy_ops *phy_ops,
2790 struct pn533_frame_ops *fops,
2791 struct device *dev)
2793 struct pn533 *priv;
2794 int rc = -ENOMEM;
2796 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
2797 if (!priv)
2798 return ERR_PTR(-ENOMEM);
2800 priv->phy = phy;
2801 priv->phy_ops = phy_ops;
2802 priv->dev = dev;
2803 if (fops != NULL)
2804 priv->ops = fops;
2805 else
2806 priv->ops = &pn533_std_frame_ops;
2808 priv->protocol_type = protocol_type;
2809 priv->device_type = device_type;
2811 mutex_init(&priv->cmd_lock);
2813 INIT_WORK(&priv->cmd_work, pn533_wq_cmd);
2814 INIT_WORK(&priv->cmd_complete_work, pn533_wq_cmd_complete);
2815 INIT_WORK(&priv->mi_rx_work, pn533_wq_mi_recv);
2816 INIT_WORK(&priv->mi_tx_work, pn533_wq_mi_send);
2817 INIT_WORK(&priv->tg_work, pn533_wq_tg_get_data);
2818 INIT_WORK(&priv->mi_tm_rx_work, pn533_wq_tm_mi_recv);
2819 INIT_WORK(&priv->mi_tm_tx_work, pn533_wq_tm_mi_send);
2820 INIT_DELAYED_WORK(&priv->poll_work, pn533_wq_poll);
2821 INIT_WORK(&priv->rf_work, pn533_wq_rf);
2822 priv->wq = alloc_ordered_workqueue("pn533", 0);
2823 if (priv->wq == NULL)
2824 goto error;
2826 timer_setup(&priv->listen_timer, pn533_listen_mode_timer, 0);
2828 skb_queue_head_init(&priv->resp_q);
2829 skb_queue_head_init(&priv->fragment_skb);
2831 INIT_LIST_HEAD(&priv->cmd_queue);
2832 return priv;
2834 error:
2835 kfree(priv);
2836 return ERR_PTR(rc);
2838 EXPORT_SYMBOL_GPL(pn53x_common_init);
2840 void pn53x_common_clean(struct pn533 *priv)
2842 struct pn533_cmd *cmd, *n;
2844 flush_delayed_work(&priv->poll_work);
2845 destroy_workqueue(priv->wq);
2847 skb_queue_purge(&priv->resp_q);
2849 del_timer(&priv->listen_timer);
2851 list_for_each_entry_safe(cmd, n, &priv->cmd_queue, queue) {
2852 list_del(&cmd->queue);
2853 kfree(cmd);
2856 kfree(priv);
2858 EXPORT_SYMBOL_GPL(pn53x_common_clean);
2860 int pn532_i2c_nfc_alloc(struct pn533 *priv, u32 protocols,
2861 struct device *parent)
2863 priv->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols,
2864 priv->ops->tx_header_len +
2865 PN533_CMD_DATAEXCH_HEAD_LEN,
2866 priv->ops->tx_tail_len);
2867 if (!priv->nfc_dev)
2868 return -ENOMEM;
2870 nfc_set_parent_dev(priv->nfc_dev, parent);
2871 nfc_set_drvdata(priv->nfc_dev, priv);
2872 return 0;
2874 EXPORT_SYMBOL_GPL(pn532_i2c_nfc_alloc);
2876 int pn53x_register_nfc(struct pn533 *priv, u32 protocols,
2877 struct device *parent)
2879 int rc;
2881 rc = pn532_i2c_nfc_alloc(priv, protocols, parent);
2882 if (rc)
2883 return rc;
2885 rc = nfc_register_device(priv->nfc_dev);
2886 if (rc)
2887 nfc_free_device(priv->nfc_dev);
2889 return rc;
2891 EXPORT_SYMBOL_GPL(pn53x_register_nfc);
2893 void pn53x_unregister_nfc(struct pn533 *priv)
2895 nfc_unregister_device(priv->nfc_dev);
2896 nfc_free_device(priv->nfc_dev);
2898 EXPORT_SYMBOL_GPL(pn53x_unregister_nfc);
2900 MODULE_AUTHOR("Lauro Ramos Venancio <lauro.venancio@openbossa.org>");
2901 MODULE_AUTHOR("Aloisio Almeida Jr <aloisio.almeida@openbossa.org>");
2902 MODULE_AUTHOR("Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>");
2903 MODULE_DESCRIPTION("PN533 driver ver " VERSION);
2904 MODULE_VERSION(VERSION);
2905 MODULE_LICENSE("GPL");