blob: 7040106cb7f271edc3da63c8ad0f479e8d92847d [file] [log] [blame]
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001/*
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>
Ilan Elias55eb94f2011-09-18 11:19:34 +030031#include <net/nfc/nfc.h>
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -030032
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
Samuel Ortiz5c7b0532012-07-02 20:04:01 +020041#define SONY_VENDOR_ID 0x054c
42#define PASORI_PRODUCT_ID 0x02e1
43
Samuel Ortiz5c7b0532012-07-02 20:04:01 +020044#define PN533_DEVICE_STD 0x1
45#define PN533_DEVICE_PASORI 0x2
46
Samuel Ortiz01d719a2012-07-04 00:14:04 +020047#define PN533_ALL_PROTOCOLS (NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK |\
48 NFC_PROTO_FELICA_MASK | NFC_PROTO_ISO14443_MASK |\
49 NFC_PROTO_NFC_DEP_MASK |\
50 NFC_PROTO_ISO14443_B_MASK)
Samuel Ortiz5c7b0532012-07-02 20:04:01 +020051
52#define PN533_NO_TYPE_B_PROTOCOLS (NFC_PROTO_JEWEL_MASK | \
53 NFC_PROTO_MIFARE_MASK | \
54 NFC_PROTO_FELICA_MASK | \
Samuel Ortiz01d719a2012-07-04 00:14:04 +020055 NFC_PROTO_ISO14443_MASK | \
Samuel Ortiz5c7b0532012-07-02 20:04:01 +020056 NFC_PROTO_NFC_DEP_MASK)
57
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -030058static const struct usb_device_id pn533_table[] = {
Samuel Ortiz5c7b0532012-07-02 20:04:01 +020059 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
60 .idVendor = PN533_VENDOR_ID,
61 .idProduct = PN533_PRODUCT_ID,
62 .driver_info = PN533_DEVICE_STD,
63 },
64 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
65 .idVendor = SCM_VENDOR_ID,
66 .idProduct = SCL3711_PRODUCT_ID,
67 .driver_info = PN533_DEVICE_STD,
68 },
69 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
70 .idVendor = SONY_VENDOR_ID,
71 .idProduct = PASORI_PRODUCT_ID,
72 .driver_info = PN533_DEVICE_PASORI,
73 },
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -030074 { }
75};
76MODULE_DEVICE_TABLE(usb, pn533_table);
77
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +020078/* How much time we spend listening for initiators */
79#define PN533_LISTEN_TIME 2
80
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -030081/* frame definitions */
Waldemar Rymarkiewicz82dec342012-10-11 14:03:58 +020082#define PN533_NORMAL_FRAME_MAX_LEN 262 /* 6 (PREAMBLE, SOF, LEN, LCS, TFI)
83 254 (DATA)
84 2 (DCS, postamble) */
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +010085#define PN533_FRAME_HEADER_LEN (sizeof(struct pn533_frame) \
86 + 2) /* data[0] TFI, data[1] CC */
87#define PN533_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/
Waldemar Rymarkiewicz82dec342012-10-11 14:03:58 +020088
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -030089#define PN533_FRAME_SIZE(f) (sizeof(struct pn533_frame) + f->datalen + \
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +010090 PN533_FRAME_TAIL_LEN)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -030091#define PN533_FRAME_ACK_SIZE (sizeof(struct pn533_frame) + 1)
92#define PN533_FRAME_CHECKSUM(f) (f->data[f->datalen])
93#define PN533_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1])
94
95/* start of frame */
96#define PN533_SOF 0x00FF
97
98/* frame identifier: in/out/error */
99#define PN533_FRAME_IDENTIFIER(f) (f->data[0])
100#define PN533_DIR_OUT 0xD4
101#define PN533_DIR_IN 0xD5
102
103/* PN533 Commands */
104#define PN533_FRAME_CMD(f) (f->data[1])
105#define PN533_FRAME_CMD_PARAMS_PTR(f) (&f->data[2])
106#define PN533_FRAME_CMD_PARAMS_LEN(f) (f->datalen - 2)
107
108#define PN533_CMD_GET_FIRMWARE_VERSION 0x02
109#define PN533_CMD_RF_CONFIGURATION 0x32
110#define PN533_CMD_IN_DATA_EXCHANGE 0x40
Samuel Ortiz5c7b0532012-07-02 20:04:01 +0200111#define PN533_CMD_IN_COMM_THRU 0x42
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300112#define PN533_CMD_IN_LIST_PASSIVE_TARGET 0x4A
113#define PN533_CMD_IN_ATR 0x50
114#define PN533_CMD_IN_RELEASE 0x52
Samuel Ortiz361f3cb2011-12-14 16:43:11 +0100115#define PN533_CMD_IN_JUMP_FOR_DEP 0x56
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300116
Samuel Ortizad3823c2012-05-30 23:54:55 +0200117#define PN533_CMD_TG_INIT_AS_TARGET 0x8c
Samuel Ortiz103b34c2012-05-31 00:07:51 +0200118#define PN533_CMD_TG_GET_DATA 0x86
Samuel Ortizdadb06f2012-05-31 00:09:11 +0200119#define PN533_CMD_TG_SET_DATA 0x8e
Samuel Ortizad3823c2012-05-30 23:54:55 +0200120
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300121#define PN533_CMD_RESPONSE(cmd) (cmd + 1)
122
123/* PN533 Return codes */
124#define PN533_CMD_RET_MASK 0x3F
125#define PN533_CMD_MI_MASK 0x40
126#define PN533_CMD_RET_SUCCESS 0x00
127
128struct pn533;
129
130typedef int (*pn533_cmd_complete_t) (struct pn533 *dev, void *arg,
131 u8 *params, int params_len);
132
133/* structs for pn533 commands */
134
135/* PN533_CMD_GET_FIRMWARE_VERSION */
136struct pn533_fw_version {
137 u8 ic;
138 u8 ver;
139 u8 rev;
140 u8 support;
141};
142
143/* PN533_CMD_RF_CONFIGURATION */
Samuel Ortiz34a85bf2012-05-29 21:34:08 +0200144#define PN533_CFGITEM_TIMING 0x02
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300145#define PN533_CFGITEM_MAX_RETRIES 0x05
Samuel Ortiz5c7b0532012-07-02 20:04:01 +0200146#define PN533_CFGITEM_PASORI 0x82
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300147
Samuel Ortiz34a85bf2012-05-29 21:34:08 +0200148#define PN533_CONFIG_TIMING_102 0xb
149#define PN533_CONFIG_TIMING_204 0xc
150#define PN533_CONFIG_TIMING_409 0xd
151#define PN533_CONFIG_TIMING_819 0xe
152
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300153#define PN533_CONFIG_MAX_RETRIES_NO_RETRY 0x00
154#define PN533_CONFIG_MAX_RETRIES_ENDLESS 0xFF
155
156struct pn533_config_max_retries {
157 u8 mx_rty_atr;
158 u8 mx_rty_psl;
159 u8 mx_rty_passive_act;
160} __packed;
161
Samuel Ortiz34a85bf2012-05-29 21:34:08 +0200162struct pn533_config_timing {
163 u8 rfu;
164 u8 atr_res_timeout;
165 u8 dep_timeout;
166} __packed;
167
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300168/* PN533_CMD_IN_LIST_PASSIVE_TARGET */
169
170/* felica commands opcode */
171#define PN533_FELICA_OPC_SENSF_REQ 0
172#define PN533_FELICA_OPC_SENSF_RES 1
173/* felica SENSF_REQ parameters */
174#define PN533_FELICA_SENSF_SC_ALL 0xFFFF
175#define PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE 0
176#define PN533_FELICA_SENSF_RC_SYSTEM_CODE 1
177#define PN533_FELICA_SENSF_RC_ADVANCED_PROTOCOL 2
178
179/* type B initiator_data values */
180#define PN533_TYPE_B_AFI_ALL_FAMILIES 0
181#define PN533_TYPE_B_POLL_METHOD_TIMESLOT 0
182#define PN533_TYPE_B_POLL_METHOD_PROBABILISTIC 1
183
184union pn533_cmd_poll_initdata {
185 struct {
186 u8 afi;
187 u8 polling_method;
188 } __packed type_b;
189 struct {
190 u8 opcode;
191 __be16 sc;
192 u8 rc;
193 u8 tsn;
194 } __packed felica;
195};
196
197/* Poll modulations */
198enum {
199 PN533_POLL_MOD_106KBPS_A,
200 PN533_POLL_MOD_212KBPS_FELICA,
201 PN533_POLL_MOD_424KBPS_FELICA,
202 PN533_POLL_MOD_106KBPS_JEWEL,
203 PN533_POLL_MOD_847KBPS_B,
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +0200204 PN533_LISTEN_MOD,
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300205
206 __PN533_POLL_MOD_AFTER_LAST,
207};
208#define PN533_POLL_MOD_MAX (__PN533_POLL_MOD_AFTER_LAST - 1)
209
210struct pn533_poll_modulations {
211 struct {
212 u8 maxtg;
213 u8 brty;
214 union pn533_cmd_poll_initdata initiator_data;
215 } __packed data;
216 u8 len;
217};
218
219const struct pn533_poll_modulations poll_mod[] = {
220 [PN533_POLL_MOD_106KBPS_A] = {
221 .data = {
222 .maxtg = 1,
223 .brty = 0,
224 },
225 .len = 2,
226 },
227 [PN533_POLL_MOD_212KBPS_FELICA] = {
228 .data = {
229 .maxtg = 1,
230 .brty = 1,
231 .initiator_data.felica = {
232 .opcode = PN533_FELICA_OPC_SENSF_REQ,
233 .sc = PN533_FELICA_SENSF_SC_ALL,
234 .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE,
235 .tsn = 0,
236 },
237 },
238 .len = 7,
239 },
240 [PN533_POLL_MOD_424KBPS_FELICA] = {
241 .data = {
242 .maxtg = 1,
243 .brty = 2,
244 .initiator_data.felica = {
245 .opcode = PN533_FELICA_OPC_SENSF_REQ,
246 .sc = PN533_FELICA_SENSF_SC_ALL,
247 .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE,
248 .tsn = 0,
249 },
250 },
251 .len = 7,
252 },
253 [PN533_POLL_MOD_106KBPS_JEWEL] = {
254 .data = {
255 .maxtg = 1,
256 .brty = 4,
257 },
258 .len = 2,
259 },
260 [PN533_POLL_MOD_847KBPS_B] = {
261 .data = {
262 .maxtg = 1,
263 .brty = 8,
264 .initiator_data.type_b = {
265 .afi = PN533_TYPE_B_AFI_ALL_FAMILIES,
266 .polling_method =
267 PN533_TYPE_B_POLL_METHOD_TIMESLOT,
268 },
269 },
270 .len = 3,
271 },
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +0200272 [PN533_LISTEN_MOD] = {
273 .len = 0,
274 },
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300275};
276
277/* PN533_CMD_IN_ATR */
278
279struct pn533_cmd_activate_param {
280 u8 tg;
281 u8 next;
282} __packed;
283
284struct pn533_cmd_activate_response {
285 u8 status;
286 u8 nfcid3t[10];
287 u8 didt;
288 u8 bst;
289 u8 brt;
290 u8 to;
291 u8 ppt;
292 /* optional */
293 u8 gt[];
294} __packed;
295
Samuel Ortiz361f3cb2011-12-14 16:43:11 +0100296/* PN533_CMD_IN_JUMP_FOR_DEP */
297struct pn533_cmd_jump_dep {
298 u8 active;
299 u8 baud;
300 u8 next;
Samuel Ortizd7f33452012-05-29 21:45:21 +0200301 u8 data[];
Samuel Ortiz361f3cb2011-12-14 16:43:11 +0100302} __packed;
303
304struct pn533_cmd_jump_dep_response {
305 u8 status;
306 u8 tg;
307 u8 nfcid3t[10];
308 u8 didt;
309 u8 bst;
310 u8 brt;
311 u8 to;
312 u8 ppt;
313 /* optional */
314 u8 gt[];
315} __packed;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300316
Samuel Ortizad3823c2012-05-30 23:54:55 +0200317
318/* PN533_TG_INIT_AS_TARGET */
319#define PN533_INIT_TARGET_PASSIVE 0x1
320#define PN533_INIT_TARGET_DEP 0x2
321
Samuel Ortizfc40a8c2012-06-01 13:21:13 +0200322#define PN533_INIT_TARGET_RESP_FRAME_MASK 0x3
323#define PN533_INIT_TARGET_RESP_ACTIVE 0x1
324#define PN533_INIT_TARGET_RESP_DEP 0x4
325
Samuel Ortizad3823c2012-05-30 23:54:55 +0200326struct pn533_cmd_init_target {
327 u8 mode;
328 u8 mifare[6];
329 u8 felica[18];
330 u8 nfcid3[10];
331 u8 gb_len;
332 u8 gb[];
333} __packed;
334
335struct pn533_cmd_init_target_response {
336 u8 mode;
337 u8 cmd[];
338} __packed;
339
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300340struct pn533 {
341 struct usb_device *udev;
342 struct usb_interface *interface;
343 struct nfc_dev *nfc_dev;
344
345 struct urb *out_urb;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300346 struct pn533_frame *out_frame;
347
348 struct urb *in_urb;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300349 struct pn533_frame *in_frame;
350
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +0200351 struct sk_buff_head resp_q;
352
Samuel Ortiz4849f852012-04-10 19:43:17 +0200353 struct workqueue_struct *wq;
354 struct work_struct cmd_work;
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200355 struct work_struct cmd_complete_work;
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +0200356 struct work_struct poll_work;
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +0200357 struct work_struct mi_work;
Samuel Ortiz103b34c2012-05-31 00:07:51 +0200358 struct work_struct tg_work;
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +0200359 struct timer_list listen_timer;
Samuel Ortiz4849f852012-04-10 19:43:17 +0200360 struct pn533_frame *wq_in_frame;
361 int wq_in_error;
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +0200362 int cancel_listen;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300363
364 pn533_cmd_complete_t cmd_complete;
365 void *cmd_complete_arg;
Samuel Ortiz0201ed02012-05-31 17:56:46 +0200366 struct mutex cmd_lock;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300367 u8 cmd;
368
369 struct pn533_poll_modulations *poll_mod_active[PN533_POLL_MOD_MAX + 1];
370 u8 poll_mod_count;
371 u8 poll_mod_curr;
372 u32 poll_protocols;
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +0200373 u32 listen_protocols;
374
375 u8 *gb;
376 size_t gb_len;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300377
378 u8 tgt_available_prots;
379 u8 tgt_active_prot;
Samuel Ortiz51ad3042012-05-31 20:01:32 +0200380 u8 tgt_mode;
Samuel Ortiz5c7b0532012-07-02 20:04:01 +0200381
382 u32 device_type;
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200383
384 struct list_head cmd_queue;
385 u8 cmd_pending;
386};
387
388struct pn533_cmd {
389 struct list_head queue;
390 struct pn533_frame *out_frame;
391 struct pn533_frame *in_frame;
392 int in_frame_len;
393 pn533_cmd_complete_t cmd_complete;
394 void *arg;
395 gfp_t flags;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300396};
397
398struct pn533_frame {
399 u8 preamble;
400 __be16 start_frame;
401 u8 datalen;
402 u8 datalen_checksum;
403 u8 data[];
404} __packed;
405
406/* The rule: value + checksum = 0 */
407static inline u8 pn533_checksum(u8 value)
408{
409 return ~value + 1;
410}
411
412/* The rule: sum(data elements) + checksum = 0 */
413static u8 pn533_data_checksum(u8 *data, int datalen)
414{
415 u8 sum = 0;
416 int i;
417
418 for (i = 0; i < datalen; i++)
419 sum += data[i];
420
421 return pn533_checksum(sum);
422}
423
424/**
425 * pn533_tx_frame_ack - create a ack frame
426 * @frame: The frame to be set as ack
427 *
428 * Ack is different type of standard frame. As a standard frame, it has
429 * preamble and start_frame. However the checksum of this frame must fail,
430 * i.e. datalen + datalen_checksum must NOT be zero. When the checksum test
431 * fails and datalen = 0 and datalen_checksum = 0xFF, the frame is a ack.
432 * After datalen_checksum field, the postamble is placed.
433 */
434static void pn533_tx_frame_ack(struct pn533_frame *frame)
435{
436 frame->preamble = 0;
437 frame->start_frame = cpu_to_be16(PN533_SOF);
438 frame->datalen = 0;
439 frame->datalen_checksum = 0xFF;
440 /* data[0] is used as postamble */
441 frame->data[0] = 0;
442}
443
444static void pn533_tx_frame_init(struct pn533_frame *frame, u8 cmd)
445{
446 frame->preamble = 0;
447 frame->start_frame = cpu_to_be16(PN533_SOF);
448 PN533_FRAME_IDENTIFIER(frame) = PN533_DIR_OUT;
449 PN533_FRAME_CMD(frame) = cmd;
450 frame->datalen = 2;
451}
452
453static void pn533_tx_frame_finish(struct pn533_frame *frame)
454{
455 frame->datalen_checksum = pn533_checksum(frame->datalen);
456
457 PN533_FRAME_CHECKSUM(frame) =
458 pn533_data_checksum(frame->data, frame->datalen);
459
460 PN533_FRAME_POSTAMBLE(frame) = 0;
461}
462
463static bool pn533_rx_frame_is_valid(struct pn533_frame *frame)
464{
465 u8 checksum;
466
467 if (frame->start_frame != cpu_to_be16(PN533_SOF))
468 return false;
469
470 checksum = pn533_checksum(frame->datalen);
471 if (checksum != frame->datalen_checksum)
472 return false;
473
474 checksum = pn533_data_checksum(frame->data, frame->datalen);
475 if (checksum != PN533_FRAME_CHECKSUM(frame))
476 return false;
477
478 return true;
479}
480
481static bool pn533_rx_frame_is_ack(struct pn533_frame *frame)
482{
483 if (frame->start_frame != cpu_to_be16(PN533_SOF))
484 return false;
485
486 if (frame->datalen != 0 || frame->datalen_checksum != 0xFF)
487 return false;
488
489 return true;
490}
491
492static bool pn533_rx_frame_is_cmd_response(struct pn533_frame *frame, u8 cmd)
493{
494 return (PN533_FRAME_CMD(frame) == PN533_CMD_RESPONSE(cmd));
495}
496
Samuel Ortiz4849f852012-04-10 19:43:17 +0200497
498static void pn533_wq_cmd_complete(struct work_struct *work)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300499{
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200500 struct pn533 *dev = container_of(work, struct pn533, cmd_complete_work);
Samuel Ortiz4849f852012-04-10 19:43:17 +0200501 struct pn533_frame *in_frame;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300502 int rc;
503
Samuel Ortiz4849f852012-04-10 19:43:17 +0200504 in_frame = dev->wq_in_frame;
505
506 if (dev->wq_in_error)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300507 rc = dev->cmd_complete(dev, dev->cmd_complete_arg, NULL,
Samuel Ortiz4849f852012-04-10 19:43:17 +0200508 dev->wq_in_error);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300509 else
510 rc = dev->cmd_complete(dev, dev->cmd_complete_arg,
511 PN533_FRAME_CMD_PARAMS_PTR(in_frame),
512 PN533_FRAME_CMD_PARAMS_LEN(in_frame));
513
514 if (rc != -EINPROGRESS)
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200515 queue_work(dev->wq, &dev->cmd_work);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300516}
517
518static void pn533_recv_response(struct urb *urb)
519{
520 struct pn533 *dev = urb->context;
521 struct pn533_frame *in_frame;
522
Samuel Ortiz4849f852012-04-10 19:43:17 +0200523 dev->wq_in_frame = NULL;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300524
525 switch (urb->status) {
526 case 0:
527 /* success */
528 break;
529 case -ECONNRESET:
530 case -ENOENT:
531 case -ESHUTDOWN:
532 nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
533 " status: %d", urb->status);
Samuel Ortiz4849f852012-04-10 19:43:17 +0200534 dev->wq_in_error = urb->status;
535 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300536 default:
537 nfc_dev_err(&dev->interface->dev, "Nonzero urb status received:"
538 " %d", urb->status);
Samuel Ortiz4849f852012-04-10 19:43:17 +0200539 dev->wq_in_error = urb->status;
540 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300541 }
542
543 in_frame = dev->in_urb->transfer_buffer;
544
545 if (!pn533_rx_frame_is_valid(in_frame)) {
546 nfc_dev_err(&dev->interface->dev, "Received an invalid frame");
Samuel Ortiz4849f852012-04-10 19:43:17 +0200547 dev->wq_in_error = -EIO;
548 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300549 }
550
551 if (!pn533_rx_frame_is_cmd_response(in_frame, dev->cmd)) {
552 nfc_dev_err(&dev->interface->dev, "The received frame is not "
553 "response to the last command");
Samuel Ortiz4849f852012-04-10 19:43:17 +0200554 dev->wq_in_error = -EIO;
555 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300556 }
557
558 nfc_dev_dbg(&dev->interface->dev, "Received a valid frame");
Samuel Ortiz4849f852012-04-10 19:43:17 +0200559 dev->wq_in_error = 0;
560 dev->wq_in_frame = in_frame;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300561
Samuel Ortiz4849f852012-04-10 19:43:17 +0200562sched_wq:
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200563 queue_work(dev->wq, &dev->cmd_complete_work);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300564}
565
566static int pn533_submit_urb_for_response(struct pn533 *dev, gfp_t flags)
567{
568 dev->in_urb->complete = pn533_recv_response;
569
570 return usb_submit_urb(dev->in_urb, flags);
571}
572
573static void pn533_recv_ack(struct urb *urb)
574{
575 struct pn533 *dev = urb->context;
576 struct pn533_frame *in_frame;
577 int rc;
578
579 switch (urb->status) {
580 case 0:
581 /* success */
582 break;
583 case -ECONNRESET:
584 case -ENOENT:
585 case -ESHUTDOWN:
586 nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
587 " status: %d", urb->status);
Samuel Ortiz4849f852012-04-10 19:43:17 +0200588 dev->wq_in_error = urb->status;
589 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300590 default:
591 nfc_dev_err(&dev->interface->dev, "Nonzero urb status received:"
592 " %d", urb->status);
Samuel Ortiz4849f852012-04-10 19:43:17 +0200593 dev->wq_in_error = urb->status;
594 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300595 }
596
597 in_frame = dev->in_urb->transfer_buffer;
598
599 if (!pn533_rx_frame_is_ack(in_frame)) {
600 nfc_dev_err(&dev->interface->dev, "Received an invalid ack");
Samuel Ortiz4849f852012-04-10 19:43:17 +0200601 dev->wq_in_error = -EIO;
602 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300603 }
604
605 nfc_dev_dbg(&dev->interface->dev, "Received a valid ack");
606
607 rc = pn533_submit_urb_for_response(dev, GFP_ATOMIC);
608 if (rc) {
609 nfc_dev_err(&dev->interface->dev, "usb_submit_urb failed with"
610 " result %d", rc);
Samuel Ortiz4849f852012-04-10 19:43:17 +0200611 dev->wq_in_error = rc;
612 goto sched_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300613 }
614
615 return;
616
Samuel Ortiz4849f852012-04-10 19:43:17 +0200617sched_wq:
618 dev->wq_in_frame = NULL;
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200619 queue_work(dev->wq, &dev->cmd_complete_work);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300620}
621
622static int pn533_submit_urb_for_ack(struct pn533 *dev, gfp_t flags)
623{
624 dev->in_urb->complete = pn533_recv_ack;
625
626 return usb_submit_urb(dev->in_urb, flags);
627}
628
629static int pn533_send_ack(struct pn533 *dev, gfp_t flags)
630{
631 int rc;
632
633 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
634
635 pn533_tx_frame_ack(dev->out_frame);
636
637 dev->out_urb->transfer_buffer = dev->out_frame;
638 dev->out_urb->transfer_buffer_length = PN533_FRAME_ACK_SIZE;
639 rc = usb_submit_urb(dev->out_urb, flags);
640
641 return rc;
642}
643
644static int __pn533_send_cmd_frame_async(struct pn533 *dev,
645 struct pn533_frame *out_frame,
646 struct pn533_frame *in_frame,
647 int in_frame_len,
648 pn533_cmd_complete_t cmd_complete,
649 void *arg, gfp_t flags)
650{
651 int rc;
652
653 nfc_dev_dbg(&dev->interface->dev, "Sending command 0x%x",
654 PN533_FRAME_CMD(out_frame));
655
656 dev->cmd = PN533_FRAME_CMD(out_frame);
657 dev->cmd_complete = cmd_complete;
658 dev->cmd_complete_arg = arg;
659
660 dev->out_urb->transfer_buffer = out_frame;
661 dev->out_urb->transfer_buffer_length =
662 PN533_FRAME_SIZE(out_frame);
663
664 dev->in_urb->transfer_buffer = in_frame;
665 dev->in_urb->transfer_buffer_length = in_frame_len;
666
667 rc = usb_submit_urb(dev->out_urb, flags);
668 if (rc)
669 return rc;
670
671 rc = pn533_submit_urb_for_ack(dev, flags);
672 if (rc)
673 goto error;
674
675 return 0;
676
677error:
678 usb_unlink_urb(dev->out_urb);
679 return rc;
680}
681
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200682static void pn533_wq_cmd(struct work_struct *work)
683{
684 struct pn533 *dev = container_of(work, struct pn533, cmd_work);
685 struct pn533_cmd *cmd;
686
687 mutex_lock(&dev->cmd_lock);
688
689 if (list_empty(&dev->cmd_queue)) {
690 dev->cmd_pending = 0;
691 mutex_unlock(&dev->cmd_lock);
692 return;
693 }
694
695 cmd = list_first_entry(&dev->cmd_queue, struct pn533_cmd, queue);
696
Szymon Janc60ad07a2012-10-25 17:29:45 +0200697 list_del(&cmd->queue);
698
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200699 mutex_unlock(&dev->cmd_lock);
700
701 __pn533_send_cmd_frame_async(dev, cmd->out_frame, cmd->in_frame,
702 cmd->in_frame_len, cmd->cmd_complete,
703 cmd->arg, cmd->flags);
704
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200705 kfree(cmd);
706}
707
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300708static int pn533_send_cmd_frame_async(struct pn533 *dev,
709 struct pn533_frame *out_frame,
710 struct pn533_frame *in_frame,
711 int in_frame_len,
712 pn533_cmd_complete_t cmd_complete,
713 void *arg, gfp_t flags)
714{
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200715 struct pn533_cmd *cmd;
Szymon Jancee5e8d82012-09-27 09:16:54 +0200716 int rc = 0;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300717
718 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
719
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200720 mutex_lock(&dev->cmd_lock);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300721
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200722 if (!dev->cmd_pending) {
723 rc = __pn533_send_cmd_frame_async(dev, out_frame, in_frame,
724 in_frame_len, cmd_complete,
725 arg, flags);
726 if (!rc)
727 dev->cmd_pending = 1;
728
Szymon Jancee5e8d82012-09-27 09:16:54 +0200729 goto unlock;
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200730 }
731
732 nfc_dev_dbg(&dev->interface->dev, "%s Queueing command", __func__);
733
734 cmd = kzalloc(sizeof(struct pn533_cmd), flags);
Szymon Jancee5e8d82012-09-27 09:16:54 +0200735 if (!cmd) {
736 rc = -ENOMEM;
737 goto unlock;
738 }
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200739
740 INIT_LIST_HEAD(&cmd->queue);
741 cmd->out_frame = out_frame;
742 cmd->in_frame = in_frame;
743 cmd->in_frame_len = in_frame_len;
744 cmd->cmd_complete = cmd_complete;
745 cmd->arg = arg;
746 cmd->flags = flags;
747
748 list_add_tail(&cmd->queue, &dev->cmd_queue);
749
Szymon Jancee5e8d82012-09-27 09:16:54 +0200750unlock:
Samuel Ortiz5d50b362012-08-17 23:47:54 +0200751 mutex_unlock(&dev->cmd_lock);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300752
Szymon Jancee5e8d82012-09-27 09:16:54 +0200753 return rc;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300754}
755
756struct pn533_sync_cmd_response {
757 int rc;
758 struct completion done;
759};
760
761static int pn533_sync_cmd_complete(struct pn533 *dev, void *_arg,
762 u8 *params, int params_len)
763{
764 struct pn533_sync_cmd_response *arg = _arg;
765
766 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
767
768 arg->rc = 0;
769
770 if (params_len < 0) /* error */
771 arg->rc = params_len;
772
773 complete(&arg->done);
774
775 return 0;
776}
777
778static int pn533_send_cmd_frame_sync(struct pn533 *dev,
779 struct pn533_frame *out_frame,
780 struct pn533_frame *in_frame,
781 int in_frame_len)
782{
783 int rc;
784 struct pn533_sync_cmd_response arg;
785
786 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
787
788 init_completion(&arg.done);
789
790 rc = pn533_send_cmd_frame_async(dev, out_frame, in_frame, in_frame_len,
791 pn533_sync_cmd_complete, &arg, GFP_KERNEL);
792 if (rc)
793 return rc;
794
795 wait_for_completion(&arg.done);
796
797 return arg.rc;
798}
799
800static void pn533_send_complete(struct urb *urb)
801{
802 struct pn533 *dev = urb->context;
803
804 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
805
806 switch (urb->status) {
807 case 0:
808 /* success */
809 break;
810 case -ECONNRESET:
811 case -ENOENT:
812 case -ESHUTDOWN:
813 nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
814 " status: %d", urb->status);
815 break;
816 default:
817 nfc_dev_dbg(&dev->interface->dev, "Nonzero urb status received:"
818 " %d", urb->status);
819 }
820}
821
822struct pn533_target_type_a {
823 __be16 sens_res;
824 u8 sel_res;
825 u8 nfcid_len;
826 u8 nfcid_data[];
827} __packed;
828
829
830#define PN533_TYPE_A_SENS_RES_NFCID1(x) ((u8)((be16_to_cpu(x) & 0x00C0) >> 6))
831#define PN533_TYPE_A_SENS_RES_SSD(x) ((u8)((be16_to_cpu(x) & 0x001F) >> 0))
832#define PN533_TYPE_A_SENS_RES_PLATCONF(x) ((u8)((be16_to_cpu(x) & 0x0F00) >> 8))
833
834#define PN533_TYPE_A_SENS_RES_SSD_JEWEL 0x00
835#define PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL 0x0C
836
837#define PN533_TYPE_A_SEL_PROT(x) (((x) & 0x60) >> 5)
838#define PN533_TYPE_A_SEL_CASCADE(x) (((x) & 0x04) >> 2)
839
840#define PN533_TYPE_A_SEL_PROT_MIFARE 0
841#define PN533_TYPE_A_SEL_PROT_ISO14443 1
842#define PN533_TYPE_A_SEL_PROT_DEP 2
843#define PN533_TYPE_A_SEL_PROT_ISO14443_DEP 3
844
845static bool pn533_target_type_a_is_valid(struct pn533_target_type_a *type_a,
846 int target_data_len)
847{
848 u8 ssd;
849 u8 platconf;
850
851 if (target_data_len < sizeof(struct pn533_target_type_a))
852 return false;
853
854 /* The lenght check of nfcid[] and ats[] are not being performed because
855 the values are not being used */
856
857 /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
858 ssd = PN533_TYPE_A_SENS_RES_SSD(type_a->sens_res);
859 platconf = PN533_TYPE_A_SENS_RES_PLATCONF(type_a->sens_res);
860
861 if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
862 platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
863 (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
864 platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
865 return false;
866
867 /* Requirements 4.8.2.1, 4.8.2.3, 4.8.2.5 and 4.8.2.7 from NFC Forum */
868 if (PN533_TYPE_A_SEL_CASCADE(type_a->sel_res) != 0)
869 return false;
870
871 return true;
872}
873
874static int pn533_target_found_type_a(struct nfc_target *nfc_tgt, u8 *tgt_data,
875 int tgt_data_len)
876{
877 struct pn533_target_type_a *tgt_type_a;
878
879 tgt_type_a = (struct pn533_target_type_a *) tgt_data;
880
881 if (!pn533_target_type_a_is_valid(tgt_type_a, tgt_data_len))
882 return -EPROTO;
883
884 switch (PN533_TYPE_A_SEL_PROT(tgt_type_a->sel_res)) {
885 case PN533_TYPE_A_SEL_PROT_MIFARE:
886 nfc_tgt->supported_protocols = NFC_PROTO_MIFARE_MASK;
887 break;
888 case PN533_TYPE_A_SEL_PROT_ISO14443:
889 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK;
890 break;
891 case PN533_TYPE_A_SEL_PROT_DEP:
892 nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
893 break;
894 case PN533_TYPE_A_SEL_PROT_ISO14443_DEP:
895 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_MASK |
896 NFC_PROTO_NFC_DEP_MASK;
897 break;
898 }
899
900 nfc_tgt->sens_res = be16_to_cpu(tgt_type_a->sens_res);
901 nfc_tgt->sel_res = tgt_type_a->sel_res;
Samuel Ortizc3b1e1e2012-03-05 01:03:33 +0100902 nfc_tgt->nfcid1_len = tgt_type_a->nfcid_len;
903 memcpy(nfc_tgt->nfcid1, tgt_type_a->nfcid_data, nfc_tgt->nfcid1_len);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300904
905 return 0;
906}
907
908struct pn533_target_felica {
909 u8 pol_res;
910 u8 opcode;
911 u8 nfcid2[8];
912 u8 pad[8];
913 /* optional */
914 u8 syst_code[];
915} __packed;
916
917#define PN533_FELICA_SENSF_NFCID2_DEP_B1 0x01
918#define PN533_FELICA_SENSF_NFCID2_DEP_B2 0xFE
919
920static bool pn533_target_felica_is_valid(struct pn533_target_felica *felica,
921 int target_data_len)
922{
923 if (target_data_len < sizeof(struct pn533_target_felica))
924 return false;
925
926 if (felica->opcode != PN533_FELICA_OPC_SENSF_RES)
927 return false;
928
929 return true;
930}
931
932static int pn533_target_found_felica(struct nfc_target *nfc_tgt, u8 *tgt_data,
933 int tgt_data_len)
934{
935 struct pn533_target_felica *tgt_felica;
936
937 tgt_felica = (struct pn533_target_felica *) tgt_data;
938
939 if (!pn533_target_felica_is_valid(tgt_felica, tgt_data_len))
940 return -EPROTO;
941
942 if (tgt_felica->nfcid2[0] == PN533_FELICA_SENSF_NFCID2_DEP_B1 &&
943 tgt_felica->nfcid2[1] ==
944 PN533_FELICA_SENSF_NFCID2_DEP_B2)
945 nfc_tgt->supported_protocols = NFC_PROTO_NFC_DEP_MASK;
946 else
947 nfc_tgt->supported_protocols = NFC_PROTO_FELICA_MASK;
948
Samuel Ortiz79757542012-03-05 01:03:45 +0100949 memcpy(nfc_tgt->sensf_res, &tgt_felica->opcode, 9);
950 nfc_tgt->sensf_res_len = 9;
951
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300952 return 0;
953}
954
955struct pn533_target_jewel {
956 __be16 sens_res;
957 u8 jewelid[4];
958} __packed;
959
960static bool pn533_target_jewel_is_valid(struct pn533_target_jewel *jewel,
961 int target_data_len)
962{
963 u8 ssd;
964 u8 platconf;
965
966 if (target_data_len < sizeof(struct pn533_target_jewel))
967 return false;
968
969 /* Requirement 4.6.3.3 from NFC Forum Digital Spec */
970 ssd = PN533_TYPE_A_SENS_RES_SSD(jewel->sens_res);
971 platconf = PN533_TYPE_A_SENS_RES_PLATCONF(jewel->sens_res);
972
973 if ((ssd == PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
974 platconf != PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL) ||
975 (ssd != PN533_TYPE_A_SENS_RES_SSD_JEWEL &&
976 platconf == PN533_TYPE_A_SENS_RES_PLATCONF_JEWEL))
977 return false;
978
979 return true;
980}
981
982static int pn533_target_found_jewel(struct nfc_target *nfc_tgt, u8 *tgt_data,
983 int tgt_data_len)
984{
985 struct pn533_target_jewel *tgt_jewel;
986
987 tgt_jewel = (struct pn533_target_jewel *) tgt_data;
988
989 if (!pn533_target_jewel_is_valid(tgt_jewel, tgt_data_len))
990 return -EPROTO;
991
992 nfc_tgt->supported_protocols = NFC_PROTO_JEWEL_MASK;
993 nfc_tgt->sens_res = be16_to_cpu(tgt_jewel->sens_res);
Samuel Ortizd8dc1072012-03-05 01:03:46 +0100994 nfc_tgt->nfcid1_len = 4;
995 memcpy(nfc_tgt->nfcid1, tgt_jewel->jewelid, nfc_tgt->nfcid1_len);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -0300996
997 return 0;
998}
999
1000struct pn533_type_b_prot_info {
1001 u8 bitrate;
1002 u8 fsci_type;
1003 u8 fwi_adc_fo;
1004} __packed;
1005
1006#define PN533_TYPE_B_PROT_FCSI(x) (((x) & 0xF0) >> 4)
1007#define PN533_TYPE_B_PROT_TYPE(x) (((x) & 0x0F) >> 0)
1008#define PN533_TYPE_B_PROT_TYPE_RFU_MASK 0x8
1009
1010struct pn533_type_b_sens_res {
1011 u8 opcode;
1012 u8 nfcid[4];
1013 u8 appdata[4];
1014 struct pn533_type_b_prot_info prot_info;
1015} __packed;
1016
1017#define PN533_TYPE_B_OPC_SENSB_RES 0x50
1018
1019struct pn533_target_type_b {
1020 struct pn533_type_b_sens_res sensb_res;
1021 u8 attrib_res_len;
1022 u8 attrib_res[];
1023} __packed;
1024
1025static bool pn533_target_type_b_is_valid(struct pn533_target_type_b *type_b,
1026 int target_data_len)
1027{
1028 if (target_data_len < sizeof(struct pn533_target_type_b))
1029 return false;
1030
1031 if (type_b->sensb_res.opcode != PN533_TYPE_B_OPC_SENSB_RES)
1032 return false;
1033
1034 if (PN533_TYPE_B_PROT_TYPE(type_b->sensb_res.prot_info.fsci_type) &
1035 PN533_TYPE_B_PROT_TYPE_RFU_MASK)
1036 return false;
1037
1038 return true;
1039}
1040
1041static int pn533_target_found_type_b(struct nfc_target *nfc_tgt, u8 *tgt_data,
1042 int tgt_data_len)
1043{
1044 struct pn533_target_type_b *tgt_type_b;
1045
1046 tgt_type_b = (struct pn533_target_type_b *) tgt_data;
1047
1048 if (!pn533_target_type_b_is_valid(tgt_type_b, tgt_data_len))
1049 return -EPROTO;
1050
Samuel Ortiz01d719a2012-07-04 00:14:04 +02001051 nfc_tgt->supported_protocols = NFC_PROTO_ISO14443_B_MASK;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001052
1053 return 0;
1054}
1055
1056struct pn533_poll_response {
1057 u8 nbtg;
1058 u8 tg;
1059 u8 target_data[];
1060} __packed;
1061
1062static int pn533_target_found(struct pn533 *dev,
1063 struct pn533_poll_response *resp, int resp_len)
1064{
1065 int target_data_len;
1066 struct nfc_target nfc_tgt;
1067 int rc;
1068
1069 nfc_dev_dbg(&dev->interface->dev, "%s - modulation=%d", __func__,
1070 dev->poll_mod_curr);
1071
1072 if (resp->tg != 1)
1073 return -EPROTO;
1074
Samuel Ortiz98b3ac12012-03-05 01:03:39 +01001075 memset(&nfc_tgt, 0, sizeof(struct nfc_target));
1076
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001077 target_data_len = resp_len - sizeof(struct pn533_poll_response);
1078
1079 switch (dev->poll_mod_curr) {
1080 case PN533_POLL_MOD_106KBPS_A:
1081 rc = pn533_target_found_type_a(&nfc_tgt, resp->target_data,
1082 target_data_len);
1083 break;
1084 case PN533_POLL_MOD_212KBPS_FELICA:
1085 case PN533_POLL_MOD_424KBPS_FELICA:
1086 rc = pn533_target_found_felica(&nfc_tgt, resp->target_data,
1087 target_data_len);
1088 break;
1089 case PN533_POLL_MOD_106KBPS_JEWEL:
1090 rc = pn533_target_found_jewel(&nfc_tgt, resp->target_data,
1091 target_data_len);
1092 break;
1093 case PN533_POLL_MOD_847KBPS_B:
1094 rc = pn533_target_found_type_b(&nfc_tgt, resp->target_data,
1095 target_data_len);
1096 break;
1097 default:
1098 nfc_dev_err(&dev->interface->dev, "Unknown current poll"
1099 " modulation");
1100 return -EPROTO;
1101 }
1102
1103 if (rc)
1104 return rc;
1105
1106 if (!(nfc_tgt.supported_protocols & dev->poll_protocols)) {
1107 nfc_dev_dbg(&dev->interface->dev, "The target found does not"
1108 " have the desired protocol");
1109 return -EAGAIN;
1110 }
1111
1112 nfc_dev_dbg(&dev->interface->dev, "Target found - supported protocols: "
1113 "0x%x", nfc_tgt.supported_protocols);
1114
1115 dev->tgt_available_prots = nfc_tgt.supported_protocols;
1116
1117 nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1);
1118
1119 return 0;
1120}
1121
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001122static inline void pn533_poll_next_mod(struct pn533 *dev)
1123{
1124 dev->poll_mod_curr = (dev->poll_mod_curr + 1) % dev->poll_mod_count;
1125}
1126
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001127static void pn533_poll_reset_mod_list(struct pn533 *dev)
1128{
1129 dev->poll_mod_count = 0;
1130}
1131
1132static void pn533_poll_add_mod(struct pn533 *dev, u8 mod_index)
1133{
1134 dev->poll_mod_active[dev->poll_mod_count] =
1135 (struct pn533_poll_modulations *) &poll_mod[mod_index];
1136 dev->poll_mod_count++;
1137}
1138
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001139static void pn533_poll_create_mod_list(struct pn533 *dev,
1140 u32 im_protocols, u32 tm_protocols)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001141{
1142 pn533_poll_reset_mod_list(dev);
1143
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001144 if (im_protocols & NFC_PROTO_MIFARE_MASK
1145 || im_protocols & NFC_PROTO_ISO14443_MASK
1146 || im_protocols & NFC_PROTO_NFC_DEP_MASK)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001147 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_A);
1148
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001149 if (im_protocols & NFC_PROTO_FELICA_MASK
1150 || im_protocols & NFC_PROTO_NFC_DEP_MASK) {
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001151 pn533_poll_add_mod(dev, PN533_POLL_MOD_212KBPS_FELICA);
1152 pn533_poll_add_mod(dev, PN533_POLL_MOD_424KBPS_FELICA);
1153 }
1154
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001155 if (im_protocols & NFC_PROTO_JEWEL_MASK)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001156 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_JEWEL);
1157
Samuel Ortiz01d719a2012-07-04 00:14:04 +02001158 if (im_protocols & NFC_PROTO_ISO14443_B_MASK)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001159 pn533_poll_add_mod(dev, PN533_POLL_MOD_847KBPS_B);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001160
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001161 if (tm_protocols)
1162 pn533_poll_add_mod(dev, PN533_LISTEN_MOD);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001163}
1164
Waldemar Rymarkiewiczab34a182012-10-11 14:04:01 +02001165static int pn533_start_poll_complete(struct pn533 *dev, u8 *params, int params_len)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001166{
1167 struct pn533_poll_response *resp;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001168 int rc;
1169
1170 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1171
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001172 resp = (struct pn533_poll_response *) params;
1173 if (resp->nbtg) {
1174 rc = pn533_target_found(dev, resp, params_len);
1175
1176 /* We must stop the poll after a valid target found */
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001177 if (rc == 0) {
1178 pn533_poll_reset_mod_list(dev);
1179 return 0;
1180 }
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001181 }
1182
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001183 return -EAGAIN;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001184}
1185
Samuel Ortizad3823c2012-05-30 23:54:55 +02001186static int pn533_init_target_frame(struct pn533_frame *frame,
1187 u8 *gb, size_t gb_len)
1188{
1189 struct pn533_cmd_init_target *cmd;
1190 size_t cmd_len;
Samuel Ortiz51d9e802012-05-30 01:48:46 +02001191 u8 felica_params[18] = {0x1, 0xfe, /* DEP */
1192 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* random */
1193 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
1194 0xff, 0xff}; /* System code */
1195 u8 mifare_params[6] = {0x1, 0x1, /* SENS_RES */
1196 0x0, 0x0, 0x0,
1197 0x40}; /* SEL_RES for DEP */
Samuel Ortizad3823c2012-05-30 23:54:55 +02001198
1199 cmd_len = sizeof(struct pn533_cmd_init_target) + gb_len + 1;
1200 cmd = kzalloc(cmd_len, GFP_KERNEL);
1201 if (cmd == NULL)
1202 return -ENOMEM;
1203
1204 pn533_tx_frame_init(frame, PN533_CMD_TG_INIT_AS_TARGET);
1205
1206 /* DEP support only */
1207 cmd->mode |= PN533_INIT_TARGET_DEP;
Samuel Ortiz51d9e802012-05-30 01:48:46 +02001208
1209 /* Felica params */
1210 memcpy(cmd->felica, felica_params, 18);
1211 get_random_bytes(cmd->felica + 2, 6);
1212
1213 /* NFCID3 */
1214 memset(cmd->nfcid3, 0, 10);
1215 memcpy(cmd->nfcid3, cmd->felica, 8);
1216
1217 /* MIFARE params */
1218 memcpy(cmd->mifare, mifare_params, 6);
1219
1220 /* General bytes */
Samuel Ortizad3823c2012-05-30 23:54:55 +02001221 cmd->gb_len = gb_len;
1222 memcpy(cmd->gb, gb, gb_len);
Samuel Ortiz51d9e802012-05-30 01:48:46 +02001223
Samuel Ortizad3823c2012-05-30 23:54:55 +02001224 /* Len Tk */
1225 cmd->gb[gb_len] = 0;
1226
1227 memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), cmd, cmd_len);
Samuel Ortiz51d9e802012-05-30 01:48:46 +02001228
Samuel Ortizad3823c2012-05-30 23:54:55 +02001229 frame->datalen += cmd_len;
1230
1231 pn533_tx_frame_finish(frame);
1232
Samuel Ortiz51d9e802012-05-30 01:48:46 +02001233 kfree(cmd);
1234
Samuel Ortizad3823c2012-05-30 23:54:55 +02001235 return 0;
1236}
1237
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01001238#define PN533_CMD_DATAEXCH_HEAD_LEN 1
Samuel Ortiz103b34c2012-05-31 00:07:51 +02001239#define PN533_CMD_DATAEXCH_DATA_MAXLEN 262
1240static int pn533_tm_get_data_complete(struct pn533 *dev, void *arg,
1241 u8 *params, int params_len)
1242{
1243 struct sk_buff *skb_resp = arg;
1244 struct pn533_frame *in_frame = (struct pn533_frame *) skb_resp->data;
1245
1246 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1247
1248 if (params_len < 0) {
1249 nfc_dev_err(&dev->interface->dev,
1250 "Error %d when starting as a target",
1251 params_len);
1252
1253 return params_len;
1254 }
1255
1256 if (params_len > 0 && params[0] != 0) {
1257 nfc_tm_deactivated(dev->nfc_dev);
1258
Samuel Ortiz51ad3042012-05-31 20:01:32 +02001259 dev->tgt_mode = 0;
1260
Samuel Ortiz103b34c2012-05-31 00:07:51 +02001261 kfree_skb(skb_resp);
1262 return 0;
1263 }
1264
1265 skb_put(skb_resp, PN533_FRAME_SIZE(in_frame));
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01001266 skb_pull(skb_resp,
1267 PN533_FRAME_HEADER_LEN + PN533_CMD_DATAEXCH_HEAD_LEN);
1268 skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_LEN);
Samuel Ortiz103b34c2012-05-31 00:07:51 +02001269
1270 return nfc_tm_data_received(dev->nfc_dev, skb_resp);
1271}
1272
1273static void pn533_wq_tg_get_data(struct work_struct *work)
1274{
1275 struct pn533 *dev = container_of(work, struct pn533, tg_work);
1276 struct pn533_frame *in_frame;
1277 struct sk_buff *skb_resp;
1278 size_t skb_resp_len;
1279
1280 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1281
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01001282 skb_resp_len = PN533_FRAME_HEADER_LEN +
1283 PN533_CMD_DATAEXCH_HEAD_LEN +
1284 PN533_CMD_DATAEXCH_DATA_MAXLEN +
1285 PN533_FRAME_TAIL_LEN;
Samuel Ortiz103b34c2012-05-31 00:07:51 +02001286
1287 skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL);
1288 if (!skb_resp)
1289 return;
1290
1291 in_frame = (struct pn533_frame *)skb_resp->data;
1292
1293 pn533_tx_frame_init(dev->out_frame, PN533_CMD_TG_GET_DATA);
1294 pn533_tx_frame_finish(dev->out_frame);
1295
1296 pn533_send_cmd_frame_async(dev, dev->out_frame, in_frame,
1297 skb_resp_len,
1298 pn533_tm_get_data_complete,
1299 skb_resp, GFP_KERNEL);
1300
1301 return;
1302}
1303
Samuel Ortizfc40a8c2012-06-01 13:21:13 +02001304#define ATR_REQ_GB_OFFSET 17
Waldemar Rymarkiewiczab34a182012-10-11 14:04:01 +02001305static int pn533_init_target_complete(struct pn533 *dev, u8 *params, int params_len)
Samuel Ortizad3823c2012-05-30 23:54:55 +02001306{
1307 struct pn533_cmd_init_target_response *resp;
Samuel Ortizfc40a8c2012-06-01 13:21:13 +02001308 u8 frame, comm_mode = NFC_COMM_PASSIVE, *gb;
1309 size_t gb_len;
Samuel Ortiz103b34c2012-05-31 00:07:51 +02001310 int rc;
Samuel Ortizad3823c2012-05-30 23:54:55 +02001311
1312 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1313
1314 if (params_len < 0) {
1315 nfc_dev_err(&dev->interface->dev,
1316 "Error %d when starting as a target",
1317 params_len);
1318
1319 return params_len;
1320 }
1321
Samuel Ortizfc40a8c2012-06-01 13:21:13 +02001322 if (params_len < ATR_REQ_GB_OFFSET + 1)
1323 return -EINVAL;
1324
Samuel Ortizad3823c2012-05-30 23:54:55 +02001325 resp = (struct pn533_cmd_init_target_response *) params;
1326
Samuel Ortizfc40a8c2012-06-01 13:21:13 +02001327 nfc_dev_dbg(&dev->interface->dev, "Target mode 0x%x param len %d\n",
1328 resp->mode, params_len);
Samuel Ortizad3823c2012-05-30 23:54:55 +02001329
Samuel Ortizfc40a8c2012-06-01 13:21:13 +02001330 frame = resp->mode & PN533_INIT_TARGET_RESP_FRAME_MASK;
1331 if (frame == PN533_INIT_TARGET_RESP_ACTIVE)
1332 comm_mode = NFC_COMM_ACTIVE;
1333
1334 /* Again, only DEP */
1335 if ((resp->mode & PN533_INIT_TARGET_RESP_DEP) == 0)
1336 return -EOPNOTSUPP;
1337
1338 gb = resp->cmd + ATR_REQ_GB_OFFSET;
1339 gb_len = params_len - (ATR_REQ_GB_OFFSET + 1);
1340
Samuel Ortiz103b34c2012-05-31 00:07:51 +02001341 rc = nfc_tm_activated(dev->nfc_dev, NFC_PROTO_NFC_DEP_MASK,
1342 comm_mode, gb, gb_len);
1343 if (rc < 0) {
1344 nfc_dev_err(&dev->interface->dev,
1345 "Error when signaling target activation");
1346 return rc;
1347 }
1348
Samuel Ortiz51ad3042012-05-31 20:01:32 +02001349 dev->tgt_mode = 1;
1350
Samuel Ortiz103b34c2012-05-31 00:07:51 +02001351 queue_work(dev->wq, &dev->tg_work);
1352
1353 return 0;
Samuel Ortizad3823c2012-05-30 23:54:55 +02001354}
1355
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001356static void pn533_listen_mode_timer(unsigned long data)
Samuel Ortizfe7c5802012-05-15 15:57:06 +02001357{
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001358 struct pn533 *dev = (struct pn533 *) data;
1359
1360 nfc_dev_dbg(&dev->interface->dev, "Listen mode timeout");
1361
1362 /* An ack will cancel the last issued command (poll) */
1363 pn533_send_ack(dev, GFP_ATOMIC);
1364
1365 dev->cancel_listen = 1;
1366
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001367 pn533_poll_next_mod(dev);
1368
1369 queue_work(dev->wq, &dev->poll_work);
1370}
1371
1372static int pn533_poll_complete(struct pn533 *dev, void *arg,
1373 u8 *params, int params_len)
1374{
1375 struct pn533_poll_modulations *cur_mod;
Samuel Ortizad3823c2012-05-30 23:54:55 +02001376 int rc;
1377
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001378 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1379
1380 if (params_len == -ENOENT) {
1381 if (dev->poll_mod_count != 0)
1382 return 0;
1383
1384 nfc_dev_err(&dev->interface->dev,
1385 "Polling operation has been stopped");
1386
1387 goto stop_poll;
1388 }
1389
1390 if (params_len < 0) {
1391 nfc_dev_err(&dev->interface->dev,
1392 "Error %d when running poll", params_len);
1393
1394 goto stop_poll;
1395 }
1396
1397 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1398
1399 if (cur_mod->len == 0) {
1400 del_timer(&dev->listen_timer);
1401
Waldemar Rymarkiewiczab34a182012-10-11 14:04:01 +02001402 return pn533_init_target_complete(dev, params, params_len);
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001403 } else {
Waldemar Rymarkiewiczab34a182012-10-11 14:04:01 +02001404 rc = pn533_start_poll_complete(dev, params, params_len);
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001405 if (!rc)
1406 return rc;
1407 }
1408
1409 pn533_poll_next_mod(dev);
1410
1411 queue_work(dev->wq, &dev->poll_work);
1412
1413 return 0;
1414
1415stop_poll:
Samuel Ortizad3823c2012-05-30 23:54:55 +02001416 pn533_poll_reset_mod_list(dev);
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001417 dev->poll_protocols = 0;
1418 return 0;
1419}
Samuel Ortizad3823c2012-05-30 23:54:55 +02001420
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001421static void pn533_build_poll_frame(struct pn533 *dev,
1422 struct pn533_frame *frame,
1423 struct pn533_poll_modulations *mod)
1424{
1425 nfc_dev_dbg(&dev->interface->dev, "mod len %d\n", mod->len);
Samuel Ortizad3823c2012-05-30 23:54:55 +02001426
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001427 if (mod->len == 0) {
1428 /* Listen mode */
1429 pn533_init_target_frame(frame, dev->gb, dev->gb_len);
1430 } else {
1431 /* Polling mode */
1432 pn533_tx_frame_init(frame, PN533_CMD_IN_LIST_PASSIVE_TARGET);
1433
1434 memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), &mod->data, mod->len);
1435 frame->datalen += mod->len;
1436
1437 pn533_tx_frame_finish(frame);
1438 }
1439}
1440
1441static int pn533_send_poll_frame(struct pn533 *dev)
1442{
1443 struct pn533_poll_modulations *cur_mod;
1444 int rc;
1445
1446 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1447
1448 pn533_build_poll_frame(dev, dev->out_frame, cur_mod);
Samuel Ortizad3823c2012-05-30 23:54:55 +02001449
1450 rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01001451 PN533_NORMAL_FRAME_MAX_LEN,
1452 pn533_poll_complete,
1453 NULL, GFP_KERNEL);
Samuel Ortizad3823c2012-05-30 23:54:55 +02001454 if (rc)
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001455 nfc_dev_err(&dev->interface->dev, "Polling loop error %d", rc);
Samuel Ortizad3823c2012-05-30 23:54:55 +02001456
1457 return rc;
Samuel Ortizfe7c5802012-05-15 15:57:06 +02001458}
1459
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001460static void pn533_wq_poll(struct work_struct *work)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001461{
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001462 struct pn533 *dev = container_of(work, struct pn533, poll_work);
1463 struct pn533_poll_modulations *cur_mod;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001464 int rc;
1465
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001466 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1467
1468 nfc_dev_dbg(&dev->interface->dev,
1469 "%s cancel_listen %d modulation len %d",
1470 __func__, dev->cancel_listen, cur_mod->len);
1471
1472 if (dev->cancel_listen == 1) {
1473 dev->cancel_listen = 0;
1474 usb_kill_urb(dev->in_urb);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001475 }
1476
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001477 rc = pn533_send_poll_frame(dev);
1478 if (rc)
1479 return;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001480
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001481 if (cur_mod->len == 0 && dev->poll_mod_count > 1)
1482 mod_timer(&dev->listen_timer, jiffies + PN533_LISTEN_TIME * HZ);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001483
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001484 return;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001485}
1486
Samuel Ortizfe7c5802012-05-15 15:57:06 +02001487static int pn533_start_poll(struct nfc_dev *nfc_dev,
1488 u32 im_protocols, u32 tm_protocols)
1489{
1490 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1491
1492 nfc_dev_dbg(&dev->interface->dev,
1493 "%s: im protocols 0x%x tm protocols 0x%x",
1494 __func__, im_protocols, tm_protocols);
1495
1496 if (dev->tgt_active_prot) {
1497 nfc_dev_err(&dev->interface->dev,
1498 "Cannot poll with a target already activated");
1499 return -EBUSY;
1500 }
1501
Samuel Ortiz51ad3042012-05-31 20:01:32 +02001502 if (dev->tgt_mode) {
1503 nfc_dev_err(&dev->interface->dev,
1504 "Cannot poll while already being activated");
1505 return -EBUSY;
1506 }
1507
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001508 if (tm_protocols) {
1509 dev->gb = nfc_get_local_general_bytes(nfc_dev, &dev->gb_len);
1510 if (dev->gb == NULL)
1511 tm_protocols = 0;
1512 }
Samuel Ortizad3823c2012-05-30 23:54:55 +02001513
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001514 dev->poll_mod_curr = 0;
1515 pn533_poll_create_mod_list(dev, im_protocols, tm_protocols);
1516 dev->poll_protocols = im_protocols;
1517 dev->listen_protocols = tm_protocols;
Samuel Ortizad3823c2012-05-30 23:54:55 +02001518
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001519 return pn533_send_poll_frame(dev);
Samuel Ortizfe7c5802012-05-15 15:57:06 +02001520}
1521
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001522static void pn533_stop_poll(struct nfc_dev *nfc_dev)
1523{
1524 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1525
1526 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1527
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001528 del_timer(&dev->listen_timer);
1529
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001530 if (!dev->poll_mod_count) {
1531 nfc_dev_dbg(&dev->interface->dev, "Polling operation was not"
1532 " running");
1533 return;
1534 }
1535
1536 /* An ack will cancel the last issued command (poll) */
1537 pn533_send_ack(dev, GFP_KERNEL);
1538
1539 /* prevent pn533_start_poll_complete to issue a new poll meanwhile */
1540 usb_kill_urb(dev->in_urb);
Samuel Ortiz7c2a04a932012-05-21 16:20:01 +02001541
1542 pn533_poll_reset_mod_list(dev);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001543}
1544
1545static int pn533_activate_target_nfcdep(struct pn533 *dev)
1546{
1547 struct pn533_cmd_activate_param param;
1548 struct pn533_cmd_activate_response *resp;
Samuel Ortiz541d9202011-12-14 16:43:10 +01001549 u16 gt_len;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001550 int rc;
1551
1552 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1553
1554 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_ATR);
1555
1556 param.tg = 1;
1557 param.next = 0;
1558 memcpy(PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame), &param,
1559 sizeof(struct pn533_cmd_activate_param));
1560 dev->out_frame->datalen += sizeof(struct pn533_cmd_activate_param);
1561
1562 pn533_tx_frame_finish(dev->out_frame);
1563
1564 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01001565 PN533_NORMAL_FRAME_MAX_LEN);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001566 if (rc)
1567 return rc;
1568
1569 resp = (struct pn533_cmd_activate_response *)
1570 PN533_FRAME_CMD_PARAMS_PTR(dev->in_frame);
1571 rc = resp->status & PN533_CMD_RET_MASK;
1572 if (rc != PN533_CMD_RET_SUCCESS)
1573 return -EIO;
1574
Samuel Ortiz541d9202011-12-14 16:43:10 +01001575 /* ATR_RES general bytes are located at offset 16 */
1576 gt_len = PN533_FRAME_CMD_PARAMS_LEN(dev->in_frame) - 16;
1577 rc = nfc_set_remote_general_bytes(dev->nfc_dev, resp->gt, gt_len);
1578
1579 return rc;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001580}
1581
Eric Lapuyade90099432012-05-07 12:31:13 +02001582static int pn533_activate_target(struct nfc_dev *nfc_dev,
1583 struct nfc_target *target, u32 protocol)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001584{
1585 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1586 int rc;
1587
1588 nfc_dev_dbg(&dev->interface->dev, "%s - protocol=%u", __func__,
1589 protocol);
1590
1591 if (dev->poll_mod_count) {
1592 nfc_dev_err(&dev->interface->dev, "Cannot activate while"
1593 " polling");
1594 return -EBUSY;
1595 }
1596
1597 if (dev->tgt_active_prot) {
1598 nfc_dev_err(&dev->interface->dev, "There is already an active"
1599 " target");
1600 return -EBUSY;
1601 }
1602
1603 if (!dev->tgt_available_prots) {
1604 nfc_dev_err(&dev->interface->dev, "There is no available target"
1605 " to activate");
1606 return -EINVAL;
1607 }
1608
1609 if (!(dev->tgt_available_prots & (1 << protocol))) {
1610 nfc_dev_err(&dev->interface->dev, "The target does not support"
1611 " the requested protocol %u", protocol);
1612 return -EINVAL;
1613 }
1614
1615 if (protocol == NFC_PROTO_NFC_DEP) {
1616 rc = pn533_activate_target_nfcdep(dev);
1617 if (rc) {
1618 nfc_dev_err(&dev->interface->dev, "Error %d when"
1619 " activating target with"
1620 " NFC_DEP protocol", rc);
1621 return rc;
1622 }
1623 }
1624
1625 dev->tgt_active_prot = protocol;
1626 dev->tgt_available_prots = 0;
1627
1628 return 0;
1629}
1630
Eric Lapuyade90099432012-05-07 12:31:13 +02001631static void pn533_deactivate_target(struct nfc_dev *nfc_dev,
1632 struct nfc_target *target)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001633{
1634 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1635 u8 tg;
1636 u8 status;
1637 int rc;
1638
1639 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1640
1641 if (!dev->tgt_active_prot) {
1642 nfc_dev_err(&dev->interface->dev, "There is no active target");
1643 return;
1644 }
1645
1646 dev->tgt_active_prot = 0;
1647
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02001648 skb_queue_purge(&dev->resp_q);
1649
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001650 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_RELEASE);
1651
1652 tg = 1;
1653 memcpy(PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame), &tg, sizeof(u8));
1654 dev->out_frame->datalen += sizeof(u8);
1655
1656 pn533_tx_frame_finish(dev->out_frame);
1657
1658 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01001659 PN533_NORMAL_FRAME_MAX_LEN);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001660 if (rc) {
1661 nfc_dev_err(&dev->interface->dev, "Error when sending release"
1662 " command to the controller");
1663 return;
1664 }
1665
1666 status = PN533_FRAME_CMD_PARAMS_PTR(dev->in_frame)[0];
1667 rc = status & PN533_CMD_RET_MASK;
1668 if (rc != PN533_CMD_RET_SUCCESS)
1669 nfc_dev_err(&dev->interface->dev, "Error 0x%x when releasing"
1670 " the target", rc);
1671
1672 return;
1673}
1674
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001675
1676static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,
1677 u8 *params, int params_len)
1678{
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001679 struct pn533_cmd_jump_dep_response *resp;
1680 struct nfc_target nfc_target;
1681 u8 target_gt_len;
1682 int rc;
Waldemar Rymarkiewicz70418e62012-10-11 14:04:00 +02001683 struct pn533_cmd_jump_dep *cmd = (struct pn533_cmd_jump_dep *)arg;
1684 u8 active = cmd->active;
1685
1686 kfree(arg);
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001687
1688 if (params_len == -ENOENT) {
1689 nfc_dev_dbg(&dev->interface->dev, "");
1690 return 0;
1691 }
1692
1693 if (params_len < 0) {
1694 nfc_dev_err(&dev->interface->dev,
1695 "Error %d when bringing DEP link up",
1696 params_len);
1697 return 0;
1698 }
1699
1700 if (dev->tgt_available_prots &&
1701 !(dev->tgt_available_prots & (1 << NFC_PROTO_NFC_DEP))) {
1702 nfc_dev_err(&dev->interface->dev,
1703 "The target does not support DEP");
1704 return -EINVAL;
1705 }
1706
1707 resp = (struct pn533_cmd_jump_dep_response *) params;
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001708 rc = resp->status & PN533_CMD_RET_MASK;
1709 if (rc != PN533_CMD_RET_SUCCESS) {
1710 nfc_dev_err(&dev->interface->dev,
1711 "Bringing DEP link up failed %d", rc);
1712 return 0;
1713 }
1714
1715 if (!dev->tgt_available_prots) {
1716 nfc_dev_dbg(&dev->interface->dev, "Creating new target");
1717
1718 nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
Samuel Ortiz2fbabfa2012-03-05 01:03:47 +01001719 nfc_target.nfcid1_len = 10;
1720 memcpy(nfc_target.nfcid1, resp->nfcid3t, nfc_target.nfcid1_len);
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001721 rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1);
1722 if (rc)
1723 return 0;
1724
1725 dev->tgt_available_prots = 0;
1726 }
1727
1728 dev->tgt_active_prot = NFC_PROTO_NFC_DEP;
1729
1730 /* ATR_RES general bytes are located at offset 17 */
1731 target_gt_len = PN533_FRAME_CMD_PARAMS_LEN(dev->in_frame) - 17;
1732 rc = nfc_set_remote_general_bytes(dev->nfc_dev,
1733 resp->gt, target_gt_len);
1734 if (rc == 0)
1735 rc = nfc_dep_link_is_up(dev->nfc_dev,
1736 dev->nfc_dev->targets[0].idx,
Waldemar Rymarkiewicz70418e62012-10-11 14:04:00 +02001737 !active, NFC_RF_INITIATOR);
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001738
1739 return 0;
1740}
1741
Samuel Ortiz41a8ec42012-05-31 17:44:44 +02001742static int pn533_mod_to_baud(struct pn533 *dev)
1743{
1744 switch (dev->poll_mod_curr) {
1745 case PN533_POLL_MOD_106KBPS_A:
1746 return 0;
1747 case PN533_POLL_MOD_212KBPS_FELICA:
1748 return 1;
1749 case PN533_POLL_MOD_424KBPS_FELICA:
1750 return 2;
1751 default:
1752 return -EINVAL;
1753 }
1754}
1755
Samuel Ortizd7f33452012-05-29 21:45:21 +02001756#define PASSIVE_DATA_LEN 5
Eric Lapuyade90099432012-05-07 12:31:13 +02001757static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
Samuel Ortiz47807d32012-03-05 01:03:50 +01001758 u8 comm_mode, u8* gb, size_t gb_len)
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001759{
1760 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1761 struct pn533_cmd_jump_dep *cmd;
Samuel Ortizd7f33452012-05-29 21:45:21 +02001762 u8 cmd_len, *data_ptr;
1763 u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3};
Samuel Ortiz41a8ec42012-05-31 17:44:44 +02001764 int rc, baud;
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001765
1766 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1767
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001768 if (dev->poll_mod_count) {
1769 nfc_dev_err(&dev->interface->dev,
1770 "Cannot bring the DEP link up while polling");
1771 return -EBUSY;
1772 }
1773
1774 if (dev->tgt_active_prot) {
1775 nfc_dev_err(&dev->interface->dev,
1776 "There is already an active target");
1777 return -EBUSY;
1778 }
1779
Samuel Ortiz41a8ec42012-05-31 17:44:44 +02001780 baud = pn533_mod_to_baud(dev);
1781 if (baud < 0) {
1782 nfc_dev_err(&dev->interface->dev,
1783 "Invalid curr modulation %d", dev->poll_mod_curr);
1784 return baud;
1785 }
1786
Samuel Ortiz47807d32012-03-05 01:03:50 +01001787 cmd_len = sizeof(struct pn533_cmd_jump_dep) + gb_len;
Samuel Ortizd7f33452012-05-29 21:45:21 +02001788 if (comm_mode == NFC_COMM_PASSIVE)
1789 cmd_len += PASSIVE_DATA_LEN;
1790
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001791 cmd = kzalloc(cmd_len, GFP_KERNEL);
1792 if (cmd == NULL)
1793 return -ENOMEM;
1794
1795 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_JUMP_FOR_DEP);
1796
1797 cmd->active = !comm_mode;
Samuel Ortizd7f33452012-05-29 21:45:21 +02001798 cmd->next = 0;
Samuel Ortiz41a8ec42012-05-31 17:44:44 +02001799 cmd->baud = baud;
Samuel Ortizd7f33452012-05-29 21:45:21 +02001800 data_ptr = cmd->data;
1801 if (comm_mode == NFC_COMM_PASSIVE && cmd->baud > 0) {
1802 memcpy(data_ptr, passive_data, PASSIVE_DATA_LEN);
1803 cmd->next |= 1;
1804 data_ptr += PASSIVE_DATA_LEN;
1805 }
1806
Samuel Ortiz47807d32012-03-05 01:03:50 +01001807 if (gb != NULL && gb_len > 0) {
Samuel Ortizd7f33452012-05-29 21:45:21 +02001808 cmd->next |= 4; /* We have some Gi */
1809 memcpy(data_ptr, gb, gb_len);
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001810 } else {
1811 cmd->next = 0;
1812 }
1813
1814 memcpy(PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame), cmd, cmd_len);
1815 dev->out_frame->datalen += cmd_len;
1816
1817 pn533_tx_frame_finish(dev->out_frame);
1818
1819 rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01001820 PN533_NORMAL_FRAME_MAX_LEN,
1821 pn533_in_dep_link_up_complete, cmd,
1822 GFP_KERNEL);
Szymon Janc770f7502012-10-29 14:04:43 +01001823 if (rc < 0)
1824 kfree(cmd);
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001825
1826 return rc;
1827}
1828
1829static int pn533_dep_link_down(struct nfc_dev *nfc_dev)
1830{
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02001831 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1832
1833 pn533_poll_reset_mod_list(dev);
1834
Samuel Ortiz51ad3042012-05-31 20:01:32 +02001835 if (dev->tgt_mode || dev->tgt_active_prot) {
1836 pn533_send_ack(dev, GFP_KERNEL);
1837 usb_kill_urb(dev->in_urb);
1838 }
1839
1840 dev->tgt_active_prot = 0;
1841 dev->tgt_mode = 0;
1842
1843 skb_queue_purge(&dev->resp_q);
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01001844
1845 return 0;
1846}
1847
Samuel Ortizdadb06f2012-05-31 00:09:11 +02001848static int pn533_build_tx_frame(struct pn533 *dev, struct sk_buff *skb,
1849 bool target)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001850{
1851 int payload_len = skb->len;
1852 struct pn533_frame *out_frame;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001853 u8 tg;
1854
1855 nfc_dev_dbg(&dev->interface->dev, "%s - Sending %d bytes", __func__,
1856 payload_len);
1857
1858 if (payload_len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
1859 /* TODO: Implement support to multi-part data exchange */
1860 nfc_dev_err(&dev->interface->dev, "Data length greater than the"
1861 " max allowed: %d",
1862 PN533_CMD_DATAEXCH_DATA_MAXLEN);
1863 return -ENOSYS;
1864 }
1865
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01001866 skb_push(skb, PN533_FRAME_HEADER_LEN);
1867
Samuel Ortizdadb06f2012-05-31 00:09:11 +02001868 if (target == true) {
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02001869 switch (dev->device_type) {
Samuel Ortiza1fbbf12012-07-03 23:45:26 +02001870 case PN533_DEVICE_PASORI:
1871 if (dev->tgt_active_prot == NFC_PROTO_FELICA) {
Samuel Ortiza1fbbf12012-07-03 23:45:26 +02001872 out_frame = (struct pn533_frame *) skb->data;
1873 pn533_tx_frame_init(out_frame,
1874 PN533_CMD_IN_COMM_THRU);
1875
1876 break;
1877 }
1878
1879 default:
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02001880 skb_push(skb, PN533_CMD_DATAEXCH_HEAD_LEN);
1881 out_frame = (struct pn533_frame *) skb->data;
1882 pn533_tx_frame_init(out_frame,
1883 PN533_CMD_IN_DATA_EXCHANGE);
1884 tg = 1;
1885 memcpy(PN533_FRAME_CMD_PARAMS_PTR(out_frame),
1886 &tg, sizeof(u8));
1887 out_frame->datalen += sizeof(u8);
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02001888
1889 break;
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02001890 }
1891
Samuel Ortizdadb06f2012-05-31 00:09:11 +02001892 } else {
1893 skb_push(skb, PN533_CMD_DATAEXCH_HEAD_LEN - 1);
1894 out_frame = (struct pn533_frame *) skb->data;
1895 pn533_tx_frame_init(out_frame, PN533_CMD_TG_SET_DATA);
1896 }
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001897
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001898
1899 /* The data is already in the out_frame, just update the datalen */
1900 out_frame->datalen += payload_len;
1901
1902 pn533_tx_frame_finish(out_frame);
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01001903 skb_put(skb, PN533_FRAME_TAIL_LEN);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001904
1905 return 0;
1906}
1907
1908struct pn533_data_exchange_arg {
1909 struct sk_buff *skb_resp;
1910 struct sk_buff *skb_out;
1911 data_exchange_cb_t cb;
1912 void *cb_context;
1913};
1914
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02001915static struct sk_buff *pn533_build_response(struct pn533 *dev)
1916{
1917 struct sk_buff *skb, *tmp, *t;
1918 unsigned int skb_len = 0, tmp_len = 0;
1919
1920 nfc_dev_dbg(&dev->interface->dev, "%s\n", __func__);
1921
1922 if (skb_queue_empty(&dev->resp_q))
1923 return NULL;
1924
1925 if (skb_queue_len(&dev->resp_q) == 1) {
1926 skb = skb_dequeue(&dev->resp_q);
1927 goto out;
1928 }
1929
1930 skb_queue_walk_safe(&dev->resp_q, tmp, t)
1931 skb_len += tmp->len;
1932
1933 nfc_dev_dbg(&dev->interface->dev, "%s total length %d\n",
1934 __func__, skb_len);
1935
1936 skb = alloc_skb(skb_len, GFP_KERNEL);
1937 if (skb == NULL)
1938 goto out;
1939
1940 skb_put(skb, skb_len);
1941
1942 skb_queue_walk_safe(&dev->resp_q, tmp, t) {
1943 memcpy(skb->data + tmp_len, tmp->data, tmp->len);
1944 tmp_len += tmp->len;
1945 }
1946
1947out:
1948 skb_queue_purge(&dev->resp_q);
1949
1950 return skb;
1951}
1952
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001953static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg,
1954 u8 *params, int params_len)
1955{
1956 struct pn533_data_exchange_arg *arg = _arg;
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02001957 struct sk_buff *skb = NULL, *skb_resp = arg->skb_resp;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001958 struct pn533_frame *in_frame = (struct pn533_frame *) skb_resp->data;
1959 int err = 0;
1960 u8 status;
1961 u8 cmd_ret;
1962
1963 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1964
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02001965 dev_kfree_skb(arg->skb_out);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001966
1967 if (params_len < 0) { /* error */
1968 err = params_len;
1969 goto error;
1970 }
1971
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001972 status = params[0];
1973
1974 cmd_ret = status & PN533_CMD_RET_MASK;
1975 if (cmd_ret != PN533_CMD_RET_SUCCESS) {
1976 nfc_dev_err(&dev->interface->dev, "PN533 reported error %d when"
1977 " exchanging data", cmd_ret);
1978 err = -EIO;
1979 goto error;
1980 }
1981
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02001982 skb_put(skb_resp, PN533_FRAME_SIZE(in_frame));
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01001983 skb_pull(skb_resp, PN533_FRAME_HEADER_LEN);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001984 skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN);
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01001985 skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_LEN);
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02001986 skb_queue_tail(&dev->resp_q, skb_resp);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001987
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02001988 if (status & PN533_CMD_MI_MASK) {
1989 queue_work(dev->wq, &dev->mi_work);
1990 return -EINPROGRESS;
1991 }
1992
1993 skb = pn533_build_response(dev);
1994 if (skb == NULL)
1995 goto error;
1996
1997 arg->cb(arg->cb_context, skb, 0);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03001998 kfree(arg);
1999 return 0;
2000
2001error:
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002002 skb_queue_purge(&dev->resp_q);
2003 dev_kfree_skb(skb_resp);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002004 arg->cb(arg->cb_context, NULL, err);
2005 kfree(arg);
2006 return 0;
2007}
2008
Samuel Ortizbe9ae4c2012-05-16 15:55:48 +02002009static int pn533_transceive(struct nfc_dev *nfc_dev,
2010 struct nfc_target *target, struct sk_buff *skb,
2011 data_exchange_cb_t cb, void *cb_context)
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002012{
2013 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2014 struct pn533_frame *out_frame, *in_frame;
2015 struct pn533_data_exchange_arg *arg;
2016 struct sk_buff *skb_resp;
2017 int skb_resp_len;
2018 int rc;
2019
2020 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
2021
2022 if (!dev->tgt_active_prot) {
2023 nfc_dev_err(&dev->interface->dev, "Cannot exchange data if"
2024 " there is no active target");
2025 rc = -EINVAL;
2026 goto error;
2027 }
2028
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002029 rc = pn533_build_tx_frame(dev, skb, true);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002030 if (rc)
2031 goto error;
2032
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01002033 skb_resp_len = PN533_FRAME_HEADER_LEN +
2034 PN533_CMD_DATAEXCH_HEAD_LEN +
2035 PN533_CMD_DATAEXCH_DATA_MAXLEN +
2036 PN533_FRAME_TAIL_LEN;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002037
Samuel Ortiz7c7cd3b2011-12-14 16:43:06 +01002038 skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002039 if (!skb_resp) {
2040 rc = -ENOMEM;
2041 goto error;
2042 }
2043
2044 in_frame = (struct pn533_frame *) skb_resp->data;
2045 out_frame = (struct pn533_frame *) skb->data;
2046
2047 arg = kmalloc(sizeof(struct pn533_data_exchange_arg), GFP_KERNEL);
2048 if (!arg) {
2049 rc = -ENOMEM;
2050 goto free_skb_resp;
2051 }
2052
2053 arg->skb_resp = skb_resp;
2054 arg->skb_out = skb;
2055 arg->cb = cb;
2056 arg->cb_context = cb_context;
2057
2058 rc = pn533_send_cmd_frame_async(dev, out_frame, in_frame, skb_resp_len,
2059 pn533_data_exchange_complete, arg,
2060 GFP_KERNEL);
2061 if (rc) {
2062 nfc_dev_err(&dev->interface->dev, "Error %d when trying to"
2063 " perform data_exchange", rc);
2064 goto free_arg;
2065 }
2066
2067 return 0;
2068
2069free_arg:
2070 kfree(arg);
2071free_skb_resp:
2072 kfree_skb(skb_resp);
2073error:
2074 kfree_skb(skb);
2075 return rc;
2076}
2077
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002078static int pn533_tm_send_complete(struct pn533 *dev, void *arg,
2079 u8 *params, int params_len)
2080{
Thierry Escande5b412fd2012-11-15 18:24:28 +01002081 struct sk_buff *skb_out = arg;
2082
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002083 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
2084
Thierry Escande5b412fd2012-11-15 18:24:28 +01002085 dev_kfree_skb(skb_out);
2086
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002087 if (params_len < 0) {
2088 nfc_dev_err(&dev->interface->dev,
2089 "Error %d when sending data",
2090 params_len);
2091
2092 return params_len;
2093 }
2094
2095 if (params_len > 0 && params[0] != 0) {
2096 nfc_tm_deactivated(dev->nfc_dev);
2097
Samuel Ortiz51ad3042012-05-31 20:01:32 +02002098 dev->tgt_mode = 0;
2099
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002100 return 0;
2101 }
2102
2103 queue_work(dev->wq, &dev->tg_work);
2104
2105 return 0;
2106}
2107
2108static int pn533_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb)
2109{
2110 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
2111 struct pn533_frame *out_frame;
2112 int rc;
2113
2114 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
2115
2116 rc = pn533_build_tx_frame(dev, skb, false);
2117 if (rc)
2118 goto error;
2119
2120 out_frame = (struct pn533_frame *) skb->data;
2121
2122 rc = pn533_send_cmd_frame_async(dev, out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01002123 PN533_NORMAL_FRAME_MAX_LEN,
2124 pn533_tm_send_complete, skb,
2125 GFP_KERNEL);
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002126 if (rc) {
2127 nfc_dev_err(&dev->interface->dev,
2128 "Error %d when trying to send data", rc);
2129 goto error;
2130 }
2131
2132 return 0;
2133
2134error:
2135 kfree_skb(skb);
2136
2137 return rc;
2138}
2139
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002140static void pn533_wq_mi_recv(struct work_struct *work)
2141{
2142 struct pn533 *dev = container_of(work, struct pn533, mi_work);
2143 struct sk_buff *skb_cmd;
2144 struct pn533_data_exchange_arg *arg = dev->cmd_complete_arg;
2145 struct pn533_frame *out_frame, *in_frame;
2146 struct sk_buff *skb_resp;
2147 int skb_resp_len;
2148 int rc;
2149
2150 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
2151
2152 /* This is a zero payload size skb */
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01002153 skb_cmd = alloc_skb(PN533_FRAME_HEADER_LEN +
2154 PN533_CMD_DATAEXCH_HEAD_LEN +
2155 PN533_FRAME_TAIL_LEN,
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002156 GFP_KERNEL);
2157 if (skb_cmd == NULL)
2158 goto error_cmd;
2159
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01002160 skb_reserve(skb_cmd,
2161 PN533_FRAME_HEADER_LEN + PN533_CMD_DATAEXCH_HEAD_LEN);
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002162
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002163 rc = pn533_build_tx_frame(dev, skb_cmd, true);
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002164 if (rc)
2165 goto error_frame;
2166
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01002167 skb_resp_len = PN533_FRAME_HEADER_LEN +
2168 PN533_CMD_DATAEXCH_HEAD_LEN +
2169 PN533_CMD_DATAEXCH_DATA_MAXLEN +
2170 PN533_FRAME_TAIL_LEN;
2171
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002172 skb_resp = alloc_skb(skb_resp_len, GFP_KERNEL);
2173 if (!skb_resp) {
2174 rc = -ENOMEM;
2175 goto error_frame;
2176 }
2177
2178 in_frame = (struct pn533_frame *) skb_resp->data;
2179 out_frame = (struct pn533_frame *) skb_cmd->data;
2180
2181 arg->skb_resp = skb_resp;
2182 arg->skb_out = skb_cmd;
2183
2184 rc = __pn533_send_cmd_frame_async(dev, out_frame, in_frame,
2185 skb_resp_len,
2186 pn533_data_exchange_complete,
2187 dev->cmd_complete_arg, GFP_KERNEL);
2188 if (!rc)
2189 return;
2190
2191 nfc_dev_err(&dev->interface->dev, "Error %d when trying to"
2192 " perform data_exchange", rc);
2193
2194 kfree_skb(skb_resp);
2195
2196error_frame:
2197 kfree_skb(skb_cmd);
2198
2199error_cmd:
2200 pn533_send_ack(dev, GFP_KERNEL);
2201
2202 kfree(arg);
2203
Samuel Ortiz5d50b362012-08-17 23:47:54 +02002204 queue_work(dev->wq, &dev->cmd_work);
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002205}
2206
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002207static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata,
2208 u8 cfgdata_len)
2209{
2210 int rc;
2211 u8 *params;
2212
2213 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
2214
2215 pn533_tx_frame_init(dev->out_frame, PN533_CMD_RF_CONFIGURATION);
2216
2217 params = PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame);
2218 params[0] = cfgitem;
2219 memcpy(&params[1], cfgdata, cfgdata_len);
2220 dev->out_frame->datalen += (1 + cfgdata_len);
2221
2222 pn533_tx_frame_finish(dev->out_frame);
2223
2224 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01002225 PN533_NORMAL_FRAME_MAX_LEN);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002226
2227 return rc;
2228}
2229
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02002230static int pn533_fw_reset(struct pn533 *dev)
2231{
2232 int rc;
2233 u8 *params;
2234
2235 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
2236
2237 pn533_tx_frame_init(dev->out_frame, 0x18);
2238
2239 params = PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame);
2240 params[0] = 0x1;
2241 dev->out_frame->datalen += 1;
2242
2243 pn533_tx_frame_finish(dev->out_frame);
2244
2245 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01002246 PN533_NORMAL_FRAME_MAX_LEN);
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02002247
2248 return rc;
2249}
2250
2251static struct nfc_ops pn533_nfc_ops = {
Ilan Elias8b3fe7b2011-09-18 11:19:33 +03002252 .dev_up = NULL,
2253 .dev_down = NULL,
Samuel Ortiz361f3cb2011-12-14 16:43:11 +01002254 .dep_link_up = pn533_dep_link_up,
2255 .dep_link_down = pn533_dep_link_down,
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002256 .start_poll = pn533_start_poll,
2257 .stop_poll = pn533_stop_poll,
2258 .activate_target = pn533_activate_target,
2259 .deactivate_target = pn533_deactivate_target,
Samuel Ortizbe9ae4c2012-05-16 15:55:48 +02002260 .im_transceive = pn533_transceive,
Samuel Ortizdadb06f2012-05-31 00:09:11 +02002261 .tm_send = pn533_tm_send,
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002262};
2263
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02002264static int pn533_setup(struct pn533 *dev)
2265{
2266 struct pn533_config_max_retries max_retries;
2267 struct pn533_config_timing timing;
2268 u8 pasori_cfg[3] = {0x08, 0x01, 0x08};
2269 int rc;
2270
2271 switch (dev->device_type) {
2272 case PN533_DEVICE_STD:
2273 max_retries.mx_rty_atr = PN533_CONFIG_MAX_RETRIES_ENDLESS;
2274 max_retries.mx_rty_psl = 2;
2275 max_retries.mx_rty_passive_act =
2276 PN533_CONFIG_MAX_RETRIES_NO_RETRY;
2277
2278 timing.rfu = PN533_CONFIG_TIMING_102;
2279 timing.atr_res_timeout = PN533_CONFIG_TIMING_204;
2280 timing.dep_timeout = PN533_CONFIG_TIMING_409;
2281
2282 break;
2283
2284 case PN533_DEVICE_PASORI:
2285 max_retries.mx_rty_atr = 0x2;
2286 max_retries.mx_rty_psl = 0x1;
2287 max_retries.mx_rty_passive_act =
2288 PN533_CONFIG_MAX_RETRIES_NO_RETRY;
2289
2290 timing.rfu = PN533_CONFIG_TIMING_102;
2291 timing.atr_res_timeout = PN533_CONFIG_TIMING_102;
2292 timing.dep_timeout = PN533_CONFIG_TIMING_204;
2293
2294 break;
2295
2296 default:
2297 nfc_dev_err(&dev->interface->dev, "Unknown device type %d\n",
2298 dev->device_type);
2299 return -EINVAL;
2300 }
2301
2302 rc = pn533_set_configuration(dev, PN533_CFGITEM_MAX_RETRIES,
2303 (u8 *)&max_retries, sizeof(max_retries));
2304 if (rc) {
2305 nfc_dev_err(&dev->interface->dev,
2306 "Error on setting MAX_RETRIES config");
2307 return rc;
2308 }
2309
2310
2311 rc = pn533_set_configuration(dev, PN533_CFGITEM_TIMING,
2312 (u8 *)&timing, sizeof(timing));
2313 if (rc) {
2314 nfc_dev_err(&dev->interface->dev,
2315 "Error on setting RF timings");
2316 return rc;
2317 }
2318
2319 switch (dev->device_type) {
2320 case PN533_DEVICE_STD:
2321 break;
2322
2323 case PN533_DEVICE_PASORI:
2324 pn533_fw_reset(dev);
2325
2326 rc = pn533_set_configuration(dev, PN533_CFGITEM_PASORI,
2327 pasori_cfg, 3);
2328 if (rc) {
2329 nfc_dev_err(&dev->interface->dev,
2330 "Error while settings PASORI config");
2331 return rc;
2332 }
2333
2334 pn533_fw_reset(dev);
2335
2336 break;
2337 }
2338
2339 return 0;
2340}
2341
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002342static int pn533_probe(struct usb_interface *interface,
2343 const struct usb_device_id *id)
2344{
2345 struct pn533_fw_version *fw_ver;
2346 struct pn533 *dev;
2347 struct usb_host_interface *iface_desc;
2348 struct usb_endpoint_descriptor *endpoint;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002349 int in_endpoint = 0;
2350 int out_endpoint = 0;
2351 int rc = -ENOMEM;
2352 int i;
2353 u32 protocols;
2354
2355 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2356 if (!dev)
2357 return -ENOMEM;
2358
2359 dev->udev = usb_get_dev(interface_to_usbdev(interface));
2360 dev->interface = interface;
Samuel Ortiz0201ed02012-05-31 17:56:46 +02002361 mutex_init(&dev->cmd_lock);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002362
2363 iface_desc = interface->cur_altsetting;
2364 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
2365 endpoint = &iface_desc->endpoint[i].desc;
2366
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01002367 if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint))
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002368 in_endpoint = endpoint->bEndpointAddress;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002369
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01002370 if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint))
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002371 out_endpoint = endpoint->bEndpointAddress;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002372 }
2373
2374 if (!in_endpoint || !out_endpoint) {
2375 nfc_dev_err(&interface->dev, "Could not find bulk-in or"
2376 " bulk-out endpoint");
2377 rc = -ENODEV;
2378 goto error;
2379 }
2380
Waldemar Rymarkiewicz82dec342012-10-11 14:03:58 +02002381 dev->in_frame = kmalloc(PN533_NORMAL_FRAME_MAX_LEN, GFP_KERNEL);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002382 dev->in_urb = usb_alloc_urb(0, GFP_KERNEL);
Waldemar Rymarkiewicz82dec342012-10-11 14:03:58 +02002383 dev->out_frame = kmalloc(PN533_NORMAL_FRAME_MAX_LEN, GFP_KERNEL);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002384 dev->out_urb = usb_alloc_urb(0, GFP_KERNEL);
2385
2386 if (!dev->in_frame || !dev->out_frame ||
2387 !dev->in_urb || !dev->out_urb)
2388 goto error;
2389
2390 usb_fill_bulk_urb(dev->in_urb, dev->udev,
2391 usb_rcvbulkpipe(dev->udev, in_endpoint),
2392 NULL, 0, NULL, dev);
2393 usb_fill_bulk_urb(dev->out_urb, dev->udev,
2394 usb_sndbulkpipe(dev->udev, out_endpoint),
2395 NULL, 0,
2396 pn533_send_complete, dev);
2397
Samuel Ortiz5d50b362012-08-17 23:47:54 +02002398 INIT_WORK(&dev->cmd_work, pn533_wq_cmd);
2399 INIT_WORK(&dev->cmd_complete_work, pn533_wq_cmd_complete);
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002400 INIT_WORK(&dev->mi_work, pn533_wq_mi_recv);
Samuel Ortiz103b34c2012-05-31 00:07:51 +02002401 INIT_WORK(&dev->tg_work, pn533_wq_tg_get_data);
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02002402 INIT_WORK(&dev->poll_work, pn533_wq_poll);
Tejun Heo58637c92012-08-22 16:28:46 -07002403 dev->wq = alloc_ordered_workqueue("pn533", 0);
Samuel Ortiz4849f852012-04-10 19:43:17 +02002404 if (dev->wq == NULL)
2405 goto error;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002406
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02002407 init_timer(&dev->listen_timer);
2408 dev->listen_timer.data = (unsigned long) dev;
2409 dev->listen_timer.function = pn533_listen_mode_timer;
2410
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002411 skb_queue_head_init(&dev->resp_q);
2412
Samuel Ortiz5d50b362012-08-17 23:47:54 +02002413 INIT_LIST_HEAD(&dev->cmd_queue);
2414
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002415 usb_set_intfdata(interface, dev);
2416
2417 pn533_tx_frame_init(dev->out_frame, PN533_CMD_GET_FIRMWARE_VERSION);
2418 pn533_tx_frame_finish(dev->out_frame);
2419
2420 rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
Waldemar Rymarkiewicz8d25ca72012-11-26 14:18:30 +01002421 PN533_NORMAL_FRAME_MAX_LEN);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002422 if (rc)
Samuel Ortiz4849f852012-04-10 19:43:17 +02002423 goto destroy_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002424
2425 fw_ver = (struct pn533_fw_version *)
2426 PN533_FRAME_CMD_PARAMS_PTR(dev->in_frame);
2427 nfc_dev_info(&dev->interface->dev, "NXP PN533 firmware ver %d.%d now"
2428 " attached", fw_ver->ver, fw_ver->rev);
2429
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02002430 dev->device_type = id->driver_info;
2431 switch (dev->device_type) {
2432 case PN533_DEVICE_STD:
2433 protocols = PN533_ALL_PROTOCOLS;
2434 break;
2435
2436 case PN533_DEVICE_PASORI:
2437 protocols = PN533_NO_TYPE_B_PROTOCOLS;
2438 break;
2439
2440 default:
2441 nfc_dev_err(&dev->interface->dev, "Unknown device type %d\n",
2442 dev->device_type);
2443 rc = -EINVAL;
2444 goto destroy_wq;
2445 }
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002446
Samuel Ortize8753042011-08-19 15:47:11 +02002447 dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols,
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01002448 PN533_FRAME_HEADER_LEN +
Samuel Ortize8753042011-08-19 15:47:11 +02002449 PN533_CMD_DATAEXCH_HEAD_LEN,
Waldemar Rymarkiewiczb1bb2902012-11-26 14:18:32 +01002450 PN533_FRAME_TAIL_LEN);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002451 if (!dev->nfc_dev)
Samuel Ortiz4849f852012-04-10 19:43:17 +02002452 goto destroy_wq;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002453
2454 nfc_set_parent_dev(dev->nfc_dev, &interface->dev);
2455 nfc_set_drvdata(dev->nfc_dev, dev);
2456
2457 rc = nfc_register_device(dev->nfc_dev);
2458 if (rc)
2459 goto free_nfc_dev;
2460
Samuel Ortiz5c7b0532012-07-02 20:04:01 +02002461 rc = pn533_setup(dev);
2462 if (rc)
Samuel Ortiz9f2f8ba2012-05-29 21:28:58 +02002463 goto unregister_nfc_dev;
Samuel Ortiz34a85bf2012-05-29 21:34:08 +02002464
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002465 return 0;
2466
Samuel Ortiz9f2f8ba2012-05-29 21:28:58 +02002467unregister_nfc_dev:
2468 nfc_unregister_device(dev->nfc_dev);
2469
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002470free_nfc_dev:
2471 nfc_free_device(dev->nfc_dev);
Samuel Ortiz9f2f8ba2012-05-29 21:28:58 +02002472
Samuel Ortiz4849f852012-04-10 19:43:17 +02002473destroy_wq:
2474 destroy_workqueue(dev->wq);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002475error:
2476 kfree(dev->in_frame);
2477 usb_free_urb(dev->in_urb);
2478 kfree(dev->out_frame);
2479 usb_free_urb(dev->out_urb);
2480 kfree(dev);
2481 return rc;
2482}
2483
2484static void pn533_disconnect(struct usb_interface *interface)
2485{
2486 struct pn533 *dev;
Samuel Ortiz5d50b362012-08-17 23:47:54 +02002487 struct pn533_cmd *cmd, *n;
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002488
2489 dev = usb_get_intfdata(interface);
2490 usb_set_intfdata(interface, NULL);
2491
2492 nfc_unregister_device(dev->nfc_dev);
2493 nfc_free_device(dev->nfc_dev);
2494
2495 usb_kill_urb(dev->in_urb);
2496 usb_kill_urb(dev->out_urb);
2497
Samuel Ortiz4849f852012-04-10 19:43:17 +02002498 destroy_workqueue(dev->wq);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002499
Samuel Ortiz6ff73fd2012-04-10 19:43:18 +02002500 skb_queue_purge(&dev->resp_q);
2501
Samuel Ortiz6fbbdc12012-05-30 17:20:25 +02002502 del_timer(&dev->listen_timer);
2503
Samuel Ortiz5d50b362012-08-17 23:47:54 +02002504 list_for_each_entry_safe(cmd, n, &dev->cmd_queue, queue) {
2505 list_del(&cmd->queue);
2506 kfree(cmd);
2507 }
2508
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002509 kfree(dev->in_frame);
2510 usb_free_urb(dev->in_urb);
2511 kfree(dev->out_frame);
2512 usb_free_urb(dev->out_urb);
2513 kfree(dev);
2514
Dan Carpenter276556d2011-07-08 10:21:15 +03002515 nfc_dev_info(&interface->dev, "NXP PN533 NFC device disconnected");
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002516}
2517
2518static struct usb_driver pn533_driver = {
2519 .name = "pn533",
2520 .probe = pn533_probe,
2521 .disconnect = pn533_disconnect,
2522 .id_table = pn533_table,
2523};
2524
Greg Kroah-Hartmanfe748482011-11-18 09:52:10 -08002525module_usb_driver(pn533_driver);
Aloisio Almeida Jrc46ee382011-07-01 19:31:37 -03002526
2527MODULE_AUTHOR("Lauro Ramos Venancio <lauro.venancio@openbossa.org>,"
2528 " Aloisio Almeida Jr <aloisio.almeida@openbossa.org>");
2529MODULE_DESCRIPTION("PN533 usb driver ver " VERSION);
2530MODULE_VERSION(VERSION);
2531MODULE_LICENSE("GPL");