1 // SPDX-License-Identifier: GPL-2.0-only
3 * HCI based Driver for Inside Secure microread NFC Chip
5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
11 #include <linux/delay.h>
12 #include <linux/slab.h>
13 #include <linux/crc-ccitt.h>
15 #include <linux/nfc.h>
16 #include <net/nfc/nfc.h>
17 #include <net/nfc/hci.h>
18 #include <net/nfc/llc.h>
20 #include "microread.h"
22 /* Proprietary gates, events, commands and registers */
24 #define MICROREAD_GATE_ID_ADM NFC_HCI_ADMIN_GATE
25 #define MICROREAD_GATE_ID_MGT 0x01
26 #define MICROREAD_GATE_ID_OS 0x02
27 #define MICROREAD_GATE_ID_TESTRF 0x03
28 #define MICROREAD_GATE_ID_LOOPBACK NFC_HCI_LOOPBACK_GATE
29 #define MICROREAD_GATE_ID_IDT NFC_HCI_ID_MGMT_GATE
30 #define MICROREAD_GATE_ID_LMS NFC_HCI_LINK_MGMT_GATE
33 #define MICROREAD_GATE_ID_MREAD_GEN 0x10
34 #define MICROREAD_GATE_ID_MREAD_ISO_B NFC_HCI_RF_READER_B_GATE
35 #define MICROREAD_GATE_ID_MREAD_NFC_T1 0x12
36 #define MICROREAD_GATE_ID_MREAD_ISO_A NFC_HCI_RF_READER_A_GATE
37 #define MICROREAD_GATE_ID_MREAD_NFC_T3 0x14
38 #define MICROREAD_GATE_ID_MREAD_ISO_15_3 0x15
39 #define MICROREAD_GATE_ID_MREAD_ISO_15_2 0x16
40 #define MICROREAD_GATE_ID_MREAD_ISO_B_3 0x17
41 #define MICROREAD_GATE_ID_MREAD_BPRIME 0x18
42 #define MICROREAD_GATE_ID_MREAD_ISO_A_3 0x19
45 #define MICROREAD_GATE_ID_MCARD_GEN 0x20
46 #define MICROREAD_GATE_ID_MCARD_ISO_B 0x21
47 #define MICROREAD_GATE_ID_MCARD_BPRIME 0x22
48 #define MICROREAD_GATE_ID_MCARD_ISO_A 0x23
49 #define MICROREAD_GATE_ID_MCARD_NFC_T3 0x24
50 #define MICROREAD_GATE_ID_MCARD_ISO_15_3 0x25
51 #define MICROREAD_GATE_ID_MCARD_ISO_15_2 0x26
52 #define MICROREAD_GATE_ID_MCARD_ISO_B_2 0x27
53 #define MICROREAD_GATE_ID_MCARD_ISO_CUSTOM 0x28
54 #define MICROREAD_GATE_ID_SECURE_ELEMENT 0x2F
57 #define MICROREAD_GATE_ID_P2P_GEN 0x30
58 #define MICROREAD_GATE_ID_P2P_TARGET 0x31
59 #define MICROREAD_PAR_P2P_TARGET_MODE 0x01
60 #define MICROREAD_PAR_P2P_TARGET_GT 0x04
61 #define MICROREAD_GATE_ID_P2P_INITIATOR 0x32
62 #define MICROREAD_PAR_P2P_INITIATOR_GI 0x01
63 #define MICROREAD_PAR_P2P_INITIATOR_GT 0x03
65 /* Those pipes are created/opened by default in the chip */
66 #define MICROREAD_PIPE_ID_LMS 0x00
67 #define MICROREAD_PIPE_ID_ADMIN 0x01
68 #define MICROREAD_PIPE_ID_MGT 0x02
69 #define MICROREAD_PIPE_ID_OS 0x03
70 #define MICROREAD_PIPE_ID_HDS_LOOPBACK 0x04
71 #define MICROREAD_PIPE_ID_HDS_IDT 0x05
72 #define MICROREAD_PIPE_ID_HDS_MCARD_ISO_B 0x08
73 #define MICROREAD_PIPE_ID_HDS_MCARD_ISO_BPRIME 0x09
74 #define MICROREAD_PIPE_ID_HDS_MCARD_ISO_A 0x0A
75 #define MICROREAD_PIPE_ID_HDS_MCARD_ISO_15_3 0x0B
76 #define MICROREAD_PIPE_ID_HDS_MCARD_ISO_15_2 0x0C
77 #define MICROREAD_PIPE_ID_HDS_MCARD_NFC_T3 0x0D
78 #define MICROREAD_PIPE_ID_HDS_MCARD_ISO_B_2 0x0E
79 #define MICROREAD_PIPE_ID_HDS_MCARD_CUSTOM 0x0F
80 #define MICROREAD_PIPE_ID_HDS_MREAD_ISO_B 0x10
81 #define MICROREAD_PIPE_ID_HDS_MREAD_NFC_T1 0x11
82 #define MICROREAD_PIPE_ID_HDS_MREAD_ISO_A 0x12
83 #define MICROREAD_PIPE_ID_HDS_MREAD_ISO_15_3 0x13
84 #define MICROREAD_PIPE_ID_HDS_MREAD_ISO_15_2 0x14
85 #define MICROREAD_PIPE_ID_HDS_MREAD_NFC_T3 0x15
86 #define MICROREAD_PIPE_ID_HDS_MREAD_ISO_B_3 0x16
87 #define MICROREAD_PIPE_ID_HDS_MREAD_BPRIME 0x17
88 #define MICROREAD_PIPE_ID_HDS_MREAD_ISO_A_3 0x18
89 #define MICROREAD_PIPE_ID_HDS_MREAD_GEN 0x1B
90 #define MICROREAD_PIPE_ID_HDS_STACKED_ELEMENT 0x1C
91 #define MICROREAD_PIPE_ID_HDS_INSTANCES 0x1D
92 #define MICROREAD_PIPE_ID_HDS_TESTRF 0x1E
93 #define MICROREAD_PIPE_ID_HDS_P2P_TARGET 0x1F
94 #define MICROREAD_PIPE_ID_HDS_P2P_INITIATOR 0x20
97 #define MICROREAD_EVT_MREAD_DISCOVERY_OCCURED NFC_HCI_EVT_TARGET_DISCOVERED
98 #define MICROREAD_EVT_MREAD_CARD_FOUND 0x3D
99 #define MICROREAD_EMCF_A_ATQA 0
100 #define MICROREAD_EMCF_A_SAK 2
101 #define MICROREAD_EMCF_A_LEN 3
102 #define MICROREAD_EMCF_A_UID 4
103 #define MICROREAD_EMCF_A3_ATQA 0
104 #define MICROREAD_EMCF_A3_SAK 2
105 #define MICROREAD_EMCF_A3_LEN 3
106 #define MICROREAD_EMCF_A3_UID 4
107 #define MICROREAD_EMCF_B_UID 0
108 #define MICROREAD_EMCF_T1_ATQA 0
109 #define MICROREAD_EMCF_T1_UID 4
110 #define MICROREAD_EMCF_T3_UID 0
111 #define MICROREAD_EVT_MREAD_DISCOVERY_START NFC_HCI_EVT_READER_REQUESTED
112 #define MICROREAD_EVT_MREAD_DISCOVERY_START_SOME 0x3E
113 #define MICROREAD_EVT_MREAD_DISCOVERY_STOP NFC_HCI_EVT_END_OPERATION
114 #define MICROREAD_EVT_MREAD_SIM_REQUESTS 0x3F
115 #define MICROREAD_EVT_MCARD_EXCHANGE NFC_HCI_EVT_TARGET_DISCOVERED
116 #define MICROREAD_EVT_P2P_INITIATOR_EXCHANGE_TO_RF 0x20
117 #define MICROREAD_EVT_P2P_INITIATOR_EXCHANGE_FROM_RF 0x21
118 #define MICROREAD_EVT_MCARD_FIELD_ON 0x11
119 #define MICROREAD_EVT_P2P_TARGET_ACTIVATED 0x13
120 #define MICROREAD_EVT_P2P_TARGET_DEACTIVATED 0x12
121 #define MICROREAD_EVT_MCARD_FIELD_OFF 0x14
124 #define MICROREAD_CMD_MREAD_EXCHANGE 0x10
125 #define MICROREAD_CMD_MREAD_SUBSCRIBE 0x3F
128 #define MICROREAD_ELT_ID_HDS NFC_HCI_TERMINAL_HOST_ID
129 #define MICROREAD_ELT_ID_SIM NFC_HCI_UICC_HOST_ID
130 #define MICROREAD_ELT_ID_SE1 0x03
131 #define MICROREAD_ELT_ID_SE2 0x04
132 #define MICROREAD_ELT_ID_SE3 0x05
134 static struct nfc_hci_gate microread_gates
[] = {
135 {MICROREAD_GATE_ID_ADM
, MICROREAD_PIPE_ID_ADMIN
},
136 {MICROREAD_GATE_ID_LOOPBACK
, MICROREAD_PIPE_ID_HDS_LOOPBACK
},
137 {MICROREAD_GATE_ID_IDT
, MICROREAD_PIPE_ID_HDS_IDT
},
138 {MICROREAD_GATE_ID_LMS
, MICROREAD_PIPE_ID_LMS
},
139 {MICROREAD_GATE_ID_MREAD_ISO_B
, MICROREAD_PIPE_ID_HDS_MREAD_ISO_B
},
140 {MICROREAD_GATE_ID_MREAD_ISO_A
, MICROREAD_PIPE_ID_HDS_MREAD_ISO_A
},
141 {MICROREAD_GATE_ID_MREAD_ISO_A_3
, MICROREAD_PIPE_ID_HDS_MREAD_ISO_A_3
},
142 {MICROREAD_GATE_ID_MGT
, MICROREAD_PIPE_ID_MGT
},
143 {MICROREAD_GATE_ID_OS
, MICROREAD_PIPE_ID_OS
},
144 {MICROREAD_GATE_ID_MREAD_NFC_T1
, MICROREAD_PIPE_ID_HDS_MREAD_NFC_T1
},
145 {MICROREAD_GATE_ID_MREAD_NFC_T3
, MICROREAD_PIPE_ID_HDS_MREAD_NFC_T3
},
146 {MICROREAD_GATE_ID_P2P_TARGET
, MICROREAD_PIPE_ID_HDS_P2P_TARGET
},
147 {MICROREAD_GATE_ID_P2P_INITIATOR
, MICROREAD_PIPE_ID_HDS_P2P_INITIATOR
}
150 /* Largest headroom needed for outgoing custom commands */
151 #define MICROREAD_CMDS_HEADROOM 2
152 #define MICROREAD_CMD_TAILROOM 2
154 struct microread_info
{
155 struct nfc_phy_ops
*phy_ops
;
158 struct nfc_hci_dev
*hdev
;
161 data_exchange_cb_t async_cb
;
162 void *async_cb_context
;
165 static int microread_open(struct nfc_hci_dev
*hdev
)
167 struct microread_info
*info
= nfc_hci_get_clientdata(hdev
);
169 return info
->phy_ops
->enable(info
->phy_id
);
172 static void microread_close(struct nfc_hci_dev
*hdev
)
174 struct microread_info
*info
= nfc_hci_get_clientdata(hdev
);
176 info
->phy_ops
->disable(info
->phy_id
);
179 static int microread_hci_ready(struct nfc_hci_dev
*hdev
)
185 r
= nfc_hci_send_cmd(hdev
, MICROREAD_GATE_ID_MREAD_ISO_A
,
186 MICROREAD_CMD_MREAD_SUBSCRIBE
, param
, 1, NULL
);
190 r
= nfc_hci_send_cmd(hdev
, MICROREAD_GATE_ID_MREAD_ISO_A_3
,
191 MICROREAD_CMD_MREAD_SUBSCRIBE
, NULL
, 0, NULL
);
198 r
= nfc_hci_send_cmd(hdev
, MICROREAD_GATE_ID_MREAD_ISO_B
,
199 MICROREAD_CMD_MREAD_SUBSCRIBE
, param
, 3, NULL
);
203 r
= nfc_hci_send_cmd(hdev
, MICROREAD_GATE_ID_MREAD_NFC_T1
,
204 MICROREAD_CMD_MREAD_SUBSCRIBE
, NULL
, 0, NULL
);
212 r
= nfc_hci_send_cmd(hdev
, MICROREAD_GATE_ID_MREAD_NFC_T3
,
213 MICROREAD_CMD_MREAD_SUBSCRIBE
, param
, 4, NULL
);
218 static int microread_xmit(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
)
220 struct microread_info
*info
= nfc_hci_get_clientdata(hdev
);
222 return info
->phy_ops
->write(info
->phy_id
, skb
);
225 static int microread_start_poll(struct nfc_hci_dev
*hdev
,
226 u32 im_protocols
, u32 tm_protocols
)
236 if (im_protocols
& NFC_PROTO_ISO14443_MASK
)
237 param
[0] |= (1 << 2);
239 if (im_protocols
& NFC_PROTO_ISO14443_B_MASK
)
242 if (im_protocols
& NFC_PROTO_MIFARE_MASK
)
245 if (im_protocols
& NFC_PROTO_JEWEL_MASK
)
246 param
[0] |= (1 << 1);
248 if (im_protocols
& NFC_PROTO_FELICA_MASK
)
249 param
[0] |= (1 << 5);
251 if (im_protocols
& NFC_PROTO_NFC_DEP_MASK
)
252 param
[1] |= (1 << 1);
254 if ((im_protocols
| tm_protocols
) & NFC_PROTO_NFC_DEP_MASK
) {
255 hdev
->gb
= nfc_get_local_general_bytes(hdev
->ndev
,
257 if (hdev
->gb
== NULL
|| hdev
->gb_len
== 0) {
258 im_protocols
&= ~NFC_PROTO_NFC_DEP_MASK
;
259 tm_protocols
&= ~NFC_PROTO_NFC_DEP_MASK
;
263 r
= nfc_hci_send_event(hdev
, MICROREAD_GATE_ID_MREAD_ISO_A
,
264 MICROREAD_EVT_MREAD_DISCOVERY_STOP
, NULL
, 0);
269 r
= nfc_hci_set_param(hdev
, MICROREAD_GATE_ID_P2P_TARGET
,
270 MICROREAD_PAR_P2P_TARGET_MODE
, &mode
, 1);
274 if (im_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
275 r
= nfc_hci_set_param(hdev
, MICROREAD_GATE_ID_P2P_INITIATOR
,
276 MICROREAD_PAR_P2P_INITIATOR_GI
,
277 hdev
->gb
, hdev
->gb_len
);
282 if (tm_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
283 r
= nfc_hci_set_param(hdev
, MICROREAD_GATE_ID_P2P_TARGET
,
284 MICROREAD_PAR_P2P_TARGET_GT
,
285 hdev
->gb
, hdev
->gb_len
);
290 r
= nfc_hci_set_param(hdev
, MICROREAD_GATE_ID_P2P_TARGET
,
291 MICROREAD_PAR_P2P_TARGET_MODE
, &mode
, 1);
296 return nfc_hci_send_event(hdev
, MICROREAD_GATE_ID_MREAD_ISO_A
,
297 MICROREAD_EVT_MREAD_DISCOVERY_START_SOME
,
301 static int microread_dep_link_up(struct nfc_hci_dev
*hdev
,
302 struct nfc_target
*target
, u8 comm_mode
,
303 u8
*gb
, size_t gb_len
)
305 struct sk_buff
*rgb_skb
= NULL
;
308 r
= nfc_hci_get_param(hdev
, target
->hci_reader_gate
,
309 MICROREAD_PAR_P2P_INITIATOR_GT
, &rgb_skb
);
313 if (rgb_skb
->len
== 0 || rgb_skb
->len
> NFC_GB_MAXSIZE
) {
318 r
= nfc_set_remote_general_bytes(hdev
->ndev
, rgb_skb
->data
,
321 r
= nfc_dep_link_is_up(hdev
->ndev
, target
->idx
, comm_mode
,
329 static int microread_dep_link_down(struct nfc_hci_dev
*hdev
)
331 return nfc_hci_send_event(hdev
, MICROREAD_GATE_ID_P2P_INITIATOR
,
332 MICROREAD_EVT_MREAD_DISCOVERY_STOP
, NULL
, 0);
335 static int microread_target_from_gate(struct nfc_hci_dev
*hdev
, u8 gate
,
336 struct nfc_target
*target
)
339 case MICROREAD_GATE_ID_P2P_INITIATOR
:
340 target
->supported_protocols
= NFC_PROTO_NFC_DEP_MASK
;
349 static int microread_complete_target_discovered(struct nfc_hci_dev
*hdev
,
351 struct nfc_target
*target
)
356 #define MICROREAD_CB_TYPE_READER_ALL 1
358 static void microread_im_transceive_cb(void *context
, struct sk_buff
*skb
,
361 struct microread_info
*info
= context
;
363 switch (info
->async_cb_type
) {
364 case MICROREAD_CB_TYPE_READER_ALL
:
369 info
->async_cb(info
->async_cb_context
, NULL
,
374 if (skb
->data
[skb
->len
- 1] != 0) {
375 err
= nfc_hci_result_to_errno(
376 skb
->data
[skb
->len
- 1]);
378 info
->async_cb(info
->async_cb_context
, NULL
,
383 skb_trim(skb
, skb
->len
- 1); /* RF Error ind. */
385 info
->async_cb(info
->async_cb_context
, skb
, err
);
396 * <= 0: driver handled the data exchange
397 * 1: driver doesn't especially handle, please do standard processing
399 static int microread_im_transceive(struct nfc_hci_dev
*hdev
,
400 struct nfc_target
*target
,
401 struct sk_buff
*skb
, data_exchange_cb_t cb
,
404 struct microread_info
*info
= nfc_hci_get_clientdata(hdev
);
408 pr_info("data exchange to gate 0x%x\n", target
->hci_reader_gate
);
410 if (target
->hci_reader_gate
== MICROREAD_GATE_ID_P2P_INITIATOR
) {
411 *(u8
*)skb_push(skb
, 1) = 0;
413 return nfc_hci_send_event(hdev
, target
->hci_reader_gate
,
414 MICROREAD_EVT_P2P_INITIATOR_EXCHANGE_TO_RF
,
415 skb
->data
, skb
->len
);
418 switch (target
->hci_reader_gate
) {
419 case MICROREAD_GATE_ID_MREAD_ISO_A
:
422 case MICROREAD_GATE_ID_MREAD_ISO_A_3
:
425 case MICROREAD_GATE_ID_MREAD_ISO_B
:
428 case MICROREAD_GATE_ID_MREAD_NFC_T1
:
431 crc
= crc_ccitt(0xffff, skb
->data
, skb
->len
);
433 skb_put_u8(skb
, crc
& 0xff);
434 skb_put_u8(skb
, crc
>> 8);
436 case MICROREAD_GATE_ID_MREAD_NFC_T3
:
440 pr_info("Abort im_transceive to invalid gate 0x%x\n",
441 target
->hci_reader_gate
);
445 *(u8
*)skb_push(skb
, 1) = control_bits
;
447 info
->async_cb_type
= MICROREAD_CB_TYPE_READER_ALL
;
449 info
->async_cb_context
= cb_context
;
451 return nfc_hci_send_cmd_async(hdev
, target
->hci_reader_gate
,
452 MICROREAD_CMD_MREAD_EXCHANGE
,
454 microread_im_transceive_cb
, info
);
457 static int microread_tm_send(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
)
461 r
= nfc_hci_send_event(hdev
, MICROREAD_GATE_ID_P2P_TARGET
,
462 MICROREAD_EVT_MCARD_EXCHANGE
,
463 skb
->data
, skb
->len
);
470 static void microread_target_discovered(struct nfc_hci_dev
*hdev
, u8 gate
,
473 struct nfc_target
*targets
;
476 pr_info("target discovered to gate 0x%x\n", gate
);
478 targets
= kzalloc(sizeof(struct nfc_target
), GFP_KERNEL
);
479 if (targets
== NULL
) {
484 targets
->hci_reader_gate
= gate
;
487 case MICROREAD_GATE_ID_MREAD_ISO_A
:
488 targets
->supported_protocols
=
489 nfc_hci_sak_to_protocol(skb
->data
[MICROREAD_EMCF_A_SAK
]);
491 be16_to_cpu(*(u16
*)&skb
->data
[MICROREAD_EMCF_A_ATQA
]);
492 targets
->sel_res
= skb
->data
[MICROREAD_EMCF_A_SAK
];
493 targets
->nfcid1_len
= skb
->data
[MICROREAD_EMCF_A_LEN
];
494 if (targets
->nfcid1_len
> sizeof(targets
->nfcid1
)) {
498 memcpy(targets
->nfcid1
, &skb
->data
[MICROREAD_EMCF_A_UID
],
499 targets
->nfcid1_len
);
501 case MICROREAD_GATE_ID_MREAD_ISO_A_3
:
502 targets
->supported_protocols
=
503 nfc_hci_sak_to_protocol(skb
->data
[MICROREAD_EMCF_A3_SAK
]);
505 be16_to_cpu(*(u16
*)&skb
->data
[MICROREAD_EMCF_A3_ATQA
]);
506 targets
->sel_res
= skb
->data
[MICROREAD_EMCF_A3_SAK
];
507 targets
->nfcid1_len
= skb
->data
[MICROREAD_EMCF_A3_LEN
];
508 if (targets
->nfcid1_len
> sizeof(targets
->nfcid1
)) {
512 memcpy(targets
->nfcid1
, &skb
->data
[MICROREAD_EMCF_A3_UID
],
513 targets
->nfcid1_len
);
515 case MICROREAD_GATE_ID_MREAD_ISO_B
:
516 targets
->supported_protocols
= NFC_PROTO_ISO14443_B_MASK
;
517 memcpy(targets
->nfcid1
, &skb
->data
[MICROREAD_EMCF_B_UID
], 4);
518 targets
->nfcid1_len
= 4;
520 case MICROREAD_GATE_ID_MREAD_NFC_T1
:
521 targets
->supported_protocols
= NFC_PROTO_JEWEL_MASK
;
523 le16_to_cpu(*(u16
*)&skb
->data
[MICROREAD_EMCF_T1_ATQA
]);
524 memcpy(targets
->nfcid1
, &skb
->data
[MICROREAD_EMCF_T1_UID
], 4);
525 targets
->nfcid1_len
= 4;
527 case MICROREAD_GATE_ID_MREAD_NFC_T3
:
528 targets
->supported_protocols
= NFC_PROTO_FELICA_MASK
;
529 memcpy(targets
->nfcid1
, &skb
->data
[MICROREAD_EMCF_T3_UID
], 8);
530 targets
->nfcid1_len
= 8;
533 pr_info("discard target discovered to gate 0x%x\n", gate
);
537 r
= nfc_targets_found(hdev
->ndev
, targets
, 1);
546 pr_err("Failed to handle discovered target err=%d\n", r
);
549 static int microread_event_received(struct nfc_hci_dev
*hdev
, u8 pipe
,
550 u8 event
, struct sk_buff
*skb
)
553 u8 gate
= hdev
->pipes
[pipe
].gate
;
556 pr_info("Microread received event 0x%x to gate 0x%x\n", event
, gate
);
559 case MICROREAD_EVT_MREAD_CARD_FOUND
:
560 microread_target_discovered(hdev
, gate
, skb
);
563 case MICROREAD_EVT_P2P_INITIATOR_EXCHANGE_FROM_RF
:
569 if (skb
->data
[skb
->len
- 1]) {
574 skb_trim(skb
, skb
->len
- 1);
576 r
= nfc_tm_data_received(hdev
->ndev
, skb
);
579 case MICROREAD_EVT_MCARD_FIELD_ON
:
580 case MICROREAD_EVT_MCARD_FIELD_OFF
:
584 case MICROREAD_EVT_P2P_TARGET_ACTIVATED
:
585 r
= nfc_tm_activated(hdev
->ndev
, NFC_PROTO_NFC_DEP_MASK
,
586 NFC_COMM_PASSIVE
, skb
->data
,
592 case MICROREAD_EVT_MCARD_EXCHANGE
:
598 if (skb
->data
[skb
->len
-1]) {
603 skb_trim(skb
, skb
->len
- 1);
605 r
= nfc_tm_data_received(hdev
->ndev
, skb
);
608 case MICROREAD_EVT_P2P_TARGET_DEACTIVATED
:
612 r
= nfc_hci_set_param(hdev
, MICROREAD_GATE_ID_P2P_TARGET
,
613 MICROREAD_PAR_P2P_TARGET_MODE
, &mode
, 1);
617 r
= nfc_hci_send_event(hdev
, gate
,
618 MICROREAD_EVT_MREAD_DISCOVERY_STOP
, NULL
,
629 static struct nfc_hci_ops microread_hci_ops
= {
630 .open
= microread_open
,
631 .close
= microread_close
,
632 .hci_ready
= microread_hci_ready
,
633 .xmit
= microread_xmit
,
634 .start_poll
= microread_start_poll
,
635 .dep_link_up
= microread_dep_link_up
,
636 .dep_link_down
= microread_dep_link_down
,
637 .target_from_gate
= microread_target_from_gate
,
638 .complete_target_discovered
= microread_complete_target_discovered
,
639 .im_transceive
= microread_im_transceive
,
640 .tm_send
= microread_tm_send
,
641 .check_presence
= NULL
,
642 .event_received
= microread_event_received
,
645 int microread_probe(void *phy_id
, struct nfc_phy_ops
*phy_ops
, char *llc_name
,
646 int phy_headroom
, int phy_tailroom
, int phy_payload
,
647 struct nfc_hci_dev
**hdev
)
649 struct microread_info
*info
;
650 unsigned long quirks
= 0;
652 struct nfc_hci_init_data init_data
;
655 info
= kzalloc(sizeof(struct microread_info
), GFP_KERNEL
);
661 info
->phy_ops
= phy_ops
;
662 info
->phy_id
= phy_id
;
664 init_data
.gate_count
= ARRAY_SIZE(microread_gates
);
665 memcpy(init_data
.gates
, microread_gates
, sizeof(microread_gates
));
667 strcpy(init_data
.session_id
, "MICROREA");
669 set_bit(NFC_HCI_QUIRK_SHORT_CLEAR
, &quirks
);
671 protocols
= NFC_PROTO_JEWEL_MASK
|
672 NFC_PROTO_MIFARE_MASK
|
673 NFC_PROTO_FELICA_MASK
|
674 NFC_PROTO_ISO14443_MASK
|
675 NFC_PROTO_ISO14443_B_MASK
|
676 NFC_PROTO_NFC_DEP_MASK
;
678 info
->hdev
= nfc_hci_allocate_device(µread_hci_ops
, &init_data
,
679 quirks
, protocols
, llc_name
,
681 MICROREAD_CMDS_HEADROOM
,
683 MICROREAD_CMD_TAILROOM
,
686 pr_err("Cannot allocate nfc hdev\n");
691 nfc_hci_set_clientdata(info
->hdev
, info
);
693 r
= nfc_hci_register_device(info
->hdev
);
702 nfc_hci_free_device(info
->hdev
);
710 EXPORT_SYMBOL(microread_probe
);
712 void microread_remove(struct nfc_hci_dev
*hdev
)
714 struct microread_info
*info
= nfc_hci_get_clientdata(hdev
);
716 nfc_hci_unregister_device(hdev
);
717 nfc_hci_free_device(hdev
);
720 EXPORT_SYMBOL(microread_remove
);
722 MODULE_LICENSE("GPL");
723 MODULE_DESCRIPTION(DRIVER_DESC
);