2 * NCI based Driver for STMicroelectronics NFC Chip
4 * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include <linux/module.h>
20 #include <linux/nfc.h>
21 #include <linux/delay.h>
22 #include <net/nfc/nci.h>
23 #include <net/nfc/nci_core.h>
26 #include "st21nfcb_se.h"
28 struct st21nfcb_pipe_info
{
37 #define ST21NFCB_HOST_CONTROLLER_ID 0x00
38 #define ST21NFCB_TERMINAL_HOST_ID 0x01
39 #define ST21NFCB_UICC_HOST_ID 0x02
40 #define ST21NFCB_ESE_HOST_ID 0xc0
43 #define ST21NFCB_DEVICE_MGNT_GATE 0x01
44 #define ST21NFCB_APDU_READER_GATE 0xf0
45 #define ST21NFCB_CONNECTIVITY_GATE 0x41
48 #define ST21NFCB_DEVICE_MGNT_PIPE 0x02
50 /* Connectivity pipe only */
51 #define ST21NFCB_SE_COUNT_PIPE_UICC 0x01
52 /* Connectivity + APDU Reader pipe */
53 #define ST21NFCB_SE_COUNT_PIPE_EMBEDDED 0x02
55 #define ST21NFCB_SE_TO_HOT_PLUG 1000 /* msecs */
56 #define ST21NFCB_SE_TO_PIPES 2000
58 #define ST21NFCB_EVT_HOT_PLUG_IS_INHIBITED(x) (x->data[0] & 0x80)
60 #define NCI_HCI_APDU_PARAM_ATR 0x01
61 #define NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY 0x01
62 #define NCI_HCI_ADMIN_PARAM_WHITELIST 0x03
63 #define NCI_HCI_ADMIN_PARAM_HOST_LIST 0x04
65 #define ST21NFCB_EVT_SE_HARD_RESET 0x20
66 #define ST21NFCB_EVT_TRANSMIT_DATA 0x10
67 #define ST21NFCB_EVT_WTX_REQUEST 0x11
68 #define ST21NFCB_EVT_SE_SOFT_RESET 0x11
69 #define ST21NFCB_EVT_SE_END_OF_APDU_TRANSFER 0x21
70 #define ST21NFCB_EVT_HOT_PLUG 0x03
72 #define ST21NFCB_SE_MODE_OFF 0x00
73 #define ST21NFCB_SE_MODE_ON 0x01
75 #define ST21NFCB_EVT_CONNECTIVITY 0x10
76 #define ST21NFCB_EVT_TRANSACTION 0x12
78 #define ST21NFCB_DM_GETINFO 0x13
79 #define ST21NFCB_DM_GETINFO_PIPE_LIST 0x02
80 #define ST21NFCB_DM_GETINFO_PIPE_INFO 0x01
81 #define ST21NFCB_DM_PIPE_CREATED 0x02
82 #define ST21NFCB_DM_PIPE_OPEN 0x04
83 #define ST21NFCB_DM_RF_ACTIVE 0x80
84 #define ST21NFCB_DM_DISCONNECT 0x30
86 #define ST21NFCB_DM_IS_PIPE_OPEN(p) \
87 ((p & 0x0f) == (ST21NFCB_DM_PIPE_CREATED | ST21NFCB_DM_PIPE_OPEN))
89 #define ST21NFCB_ATR_DEFAULT_BWI 0x04
92 * WT = 2^BWI/10[s], convert into msecs and add a secure
93 * room by increasing by 2 this timeout
95 #define ST21NFCB_BWI_TO_TIMEOUT(x) ((1 << x) * 200)
96 #define ST21NFCB_ATR_GET_Y_FROM_TD(x) (x >> 4)
98 /* If TA is present bit 0 is set */
99 #define ST21NFCB_ATR_TA_PRESENT(x) (x & 0x01)
100 /* If TB is present bit 1 is set */
101 #define ST21NFCB_ATR_TB_PRESENT(x) (x & 0x02)
103 #define ST21NFCB_NUM_DEVICES 256
105 static DECLARE_BITMAP(dev_mask
, ST21NFCB_NUM_DEVICES
);
107 /* Here are the mandatory pipe for st21nfcb */
108 static struct nci_hci_gate st21nfcb_gates
[] = {
109 {NCI_HCI_ADMIN_GATE
, NCI_HCI_ADMIN_PIPE
,
110 ST21NFCB_HOST_CONTROLLER_ID
},
111 {NCI_HCI_LINK_MGMT_GATE
, NCI_HCI_LINK_MGMT_PIPE
,
112 ST21NFCB_HOST_CONTROLLER_ID
},
113 {ST21NFCB_DEVICE_MGNT_GATE
, ST21NFCB_DEVICE_MGNT_PIPE
,
114 ST21NFCB_HOST_CONTROLLER_ID
},
116 /* Secure element pipes are created by secure element host */
117 {ST21NFCB_CONNECTIVITY_GATE
, NCI_HCI_DO_NOT_OPEN_PIPE
,
118 ST21NFCB_HOST_CONTROLLER_ID
},
119 {ST21NFCB_APDU_READER_GATE
, NCI_HCI_DO_NOT_OPEN_PIPE
,
120 ST21NFCB_HOST_CONTROLLER_ID
},
123 static u8
st21nfcb_se_get_bwi(struct nci_dev
*ndev
)
127 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
129 /* Bits 8 to 5 of the first TB for T=1 encode BWI from zero to nine */
130 for (i
= 1; i
< ST21NFCB_ESE_MAX_LENGTH
; i
++) {
131 td
= ST21NFCB_ATR_GET_Y_FROM_TD(info
->se_info
.atr
[i
]);
132 if (ST21NFCB_ATR_TA_PRESENT(td
))
134 if (ST21NFCB_ATR_TB_PRESENT(td
)) {
136 return info
->se_info
.atr
[i
] >> 4;
139 return ST21NFCB_ATR_DEFAULT_BWI
;
142 static void st21nfcb_se_get_atr(struct nci_dev
*ndev
)
144 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
148 r
= nci_hci_get_param(ndev
, ST21NFCB_APDU_READER_GATE
,
149 NCI_HCI_APDU_PARAM_ATR
, &skb
);
153 if (skb
->len
<= ST21NFCB_ESE_MAX_LENGTH
) {
154 memcpy(info
->se_info
.atr
, skb
->data
, skb
->len
);
156 info
->se_info
.wt_timeout
=
157 ST21NFCB_BWI_TO_TIMEOUT(st21nfcb_se_get_bwi(ndev
));
162 int st21nfcb_hci_load_session(struct nci_dev
*ndev
)
165 struct sk_buff
*skb_pipe_list
, *skb_pipe_info
;
166 struct st21nfcb_pipe_info
*dm_pipe_info
;
167 u8 pipe_list
[] = { ST21NFCB_DM_GETINFO_PIPE_LIST
,
168 ST21NFCB_TERMINAL_HOST_ID
};
169 u8 pipe_info
[] = { ST21NFCB_DM_GETINFO_PIPE_INFO
,
170 ST21NFCB_TERMINAL_HOST_ID
, 0};
172 /* On ST21NFCB device pipes number are dynamics
173 * If pipes are already created, hci_dev_up will fail.
174 * Doing a clear all pipe is a bad idea because:
175 * - It does useless EEPROM cycling
176 * - It might cause issue for secure elements support
177 * (such as removing connectivity or APDU reader pipe)
178 * A better approach on ST21NFCB is to:
179 * - get a pipe list for each host.
180 * (eg: ST21NFCB_HOST_CONTROLLER_ID for now).
181 * (TODO Later on UICC HOST and eSE HOST)
182 * - get pipe information
183 * - match retrieved pipe list in st21nfcb_gates
184 * ST21NFCB_DEVICE_MGNT_GATE is a proprietary gate
185 * with ST21NFCB_DEVICE_MGNT_PIPE.
186 * Pipe can be closed and need to be open.
188 r
= nci_hci_connect_gate(ndev
, ST21NFCB_HOST_CONTROLLER_ID
,
189 ST21NFCB_DEVICE_MGNT_GATE
,
190 ST21NFCB_DEVICE_MGNT_PIPE
);
195 r
= nci_hci_send_cmd(ndev
, ST21NFCB_DEVICE_MGNT_GATE
,
196 ST21NFCB_DM_GETINFO
, pipe_list
, sizeof(pipe_list
),
201 /* Complete the existing gate_pipe table */
202 for (i
= 0; i
< skb_pipe_list
->len
; i
++) {
203 pipe_info
[2] = skb_pipe_list
->data
[i
];
204 r
= nci_hci_send_cmd(ndev
, ST21NFCB_DEVICE_MGNT_GATE
,
205 ST21NFCB_DM_GETINFO
, pipe_info
,
206 sizeof(pipe_info
), &skb_pipe_info
);
212 * Match pipe ID and gate ID
213 * Output format from ST21NFC_DM_GETINFO is:
214 * - pipe state (1byte)
215 * - source hid (1byte)
216 * - source gid (1byte)
217 * - destination hid (1byte)
218 * - destination gid (1byte)
220 dm_pipe_info
= (struct st21nfcb_pipe_info
*)skb_pipe_info
->data
;
221 if (dm_pipe_info
->dst_gate_id
== ST21NFCB_APDU_READER_GATE
&&
222 dm_pipe_info
->src_host_id
!= ST21NFCB_ESE_HOST_ID
) {
223 pr_err("Unexpected apdu_reader pipe on host %x\n",
224 dm_pipe_info
->src_host_id
);
228 for (j
= 0; (j
< ARRAY_SIZE(st21nfcb_gates
)) &&
229 (st21nfcb_gates
[j
].gate
!= dm_pipe_info
->dst_gate_id
); j
++)
232 if (j
< ARRAY_SIZE(st21nfcb_gates
) &&
233 st21nfcb_gates
[j
].gate
== dm_pipe_info
->dst_gate_id
&&
234 ST21NFCB_DM_IS_PIPE_OPEN(dm_pipe_info
->pipe_state
)) {
235 st21nfcb_gates
[j
].pipe
= pipe_info
[2];
237 ndev
->hci_dev
->gate2pipe
[st21nfcb_gates
[j
].gate
] =
238 st21nfcb_gates
[j
].pipe
;
239 ndev
->hci_dev
->pipes
[st21nfcb_gates
[j
].pipe
].gate
=
240 st21nfcb_gates
[j
].gate
;
241 ndev
->hci_dev
->pipes
[st21nfcb_gates
[j
].pipe
].host
=
242 dm_pipe_info
->src_host_id
;
246 memcpy(ndev
->hci_dev
->init_data
.gates
, st21nfcb_gates
,
247 sizeof(st21nfcb_gates
));
250 kfree_skb(skb_pipe_info
);
251 kfree_skb(skb_pipe_list
);
254 EXPORT_SYMBOL_GPL(st21nfcb_hci_load_session
);
256 static void st21nfcb_hci_admin_event_received(struct nci_dev
*ndev
,
257 u8 event
, struct sk_buff
*skb
)
259 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
262 case ST21NFCB_EVT_HOT_PLUG
:
263 if (info
->se_info
.se_active
) {
264 if (!ST21NFCB_EVT_HOT_PLUG_IS_INHIBITED(skb
)) {
265 del_timer_sync(&info
->se_info
.se_active_timer
);
266 info
->se_info
.se_active
= false;
267 complete(&info
->se_info
.req_completion
);
269 mod_timer(&info
->se_info
.se_active_timer
,
271 msecs_to_jiffies(ST21NFCB_SE_TO_PIPES
));
278 static int st21nfcb_hci_apdu_reader_event_received(struct nci_dev
*ndev
,
283 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
285 pr_debug("apdu reader gate event: %x\n", event
);
288 case ST21NFCB_EVT_TRANSMIT_DATA
:
289 del_timer_sync(&info
->se_info
.bwi_timer
);
290 info
->se_info
.bwi_active
= false;
291 info
->se_info
.cb(info
->se_info
.cb_context
,
292 skb
->data
, skb
->len
, 0);
294 case ST21NFCB_EVT_WTX_REQUEST
:
295 mod_timer(&info
->se_info
.bwi_timer
, jiffies
+
296 msecs_to_jiffies(info
->se_info
.wt_timeout
));
306 * <= 0: driver handled the event, skb consumed
307 * 1: driver does not handle the event, please do standard processing
309 static int st21nfcb_hci_connectivity_event_received(struct nci_dev
*ndev
,
314 struct device
*dev
= &ndev
->nfc_dev
->dev
;
315 struct nfc_evt_transaction
*transaction
;
317 pr_debug("connectivity gate event: %x\n", event
);
320 case ST21NFCB_EVT_CONNECTIVITY
:
323 case ST21NFCB_EVT_TRANSACTION
:
324 if (skb
->len
< NFC_MIN_AID_LENGTH
+ 2 &&
325 skb
->data
[0] != NFC_EVT_TRANSACTION_AID_TAG
)
328 transaction
= (struct nfc_evt_transaction
*)devm_kzalloc(dev
,
329 skb
->len
- 2, GFP_KERNEL
);
331 transaction
->aid_len
= skb
->data
[1];
332 memcpy(transaction
->aid
, &skb
->data
[2], skb
->data
[1]);
334 if (skb
->data
[transaction
->aid_len
+ 2] !=
335 NFC_EVT_TRANSACTION_PARAMS_TAG
)
338 transaction
->params_len
= skb
->data
[transaction
->aid_len
+ 3];
339 memcpy(transaction
->params
, skb
->data
+
340 transaction
->aid_len
+ 4, transaction
->params_len
);
342 r
= nfc_se_transaction(ndev
->nfc_dev
, host
, transaction
);
350 void st21nfcb_hci_event_received(struct nci_dev
*ndev
, u8 pipe
,
351 u8 event
, struct sk_buff
*skb
)
353 u8 gate
= ndev
->hci_dev
->pipes
[pipe
].gate
;
354 u8 host
= ndev
->hci_dev
->pipes
[pipe
].host
;
357 case NCI_HCI_ADMIN_GATE
:
358 st21nfcb_hci_admin_event_received(ndev
, event
, skb
);
360 case ST21NFCB_APDU_READER_GATE
:
361 st21nfcb_hci_apdu_reader_event_received(ndev
, event
, skb
);
363 case ST21NFCB_CONNECTIVITY_GATE
:
364 st21nfcb_hci_connectivity_event_received(ndev
, host
, event
,
369 EXPORT_SYMBOL_GPL(st21nfcb_hci_event_received
);
372 void st21nfcb_hci_cmd_received(struct nci_dev
*ndev
, u8 pipe
, u8 cmd
,
375 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
376 u8 gate
= ndev
->hci_dev
->pipes
[pipe
].gate
;
378 pr_debug("cmd: %x\n", cmd
);
381 case NCI_HCI_ANY_OPEN_PIPE
:
382 if (gate
!= ST21NFCB_APDU_READER_GATE
&&
383 ndev
->hci_dev
->pipes
[pipe
].host
!= ST21NFCB_UICC_HOST_ID
)
384 ndev
->hci_dev
->count_pipes
++;
386 if (ndev
->hci_dev
->count_pipes
==
387 ndev
->hci_dev
->expected_pipes
) {
388 del_timer_sync(&info
->se_info
.se_active_timer
);
389 info
->se_info
.se_active
= false;
390 ndev
->hci_dev
->count_pipes
= 0;
391 complete(&info
->se_info
.req_completion
);
396 EXPORT_SYMBOL_GPL(st21nfcb_hci_cmd_received
);
399 * Remarks: On some early st21nfcb firmware, nci_nfcee_mode_set(0)
402 static int st21nfcb_nci_control_se(struct nci_dev
*ndev
, u8 se_idx
,
405 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
407 struct sk_buff
*sk_host_list
;
411 case ST21NFCB_UICC_HOST_ID
:
412 ndev
->hci_dev
->count_pipes
= 0;
413 ndev
->hci_dev
->expected_pipes
= ST21NFCB_SE_COUNT_PIPE_UICC
;
415 case ST21NFCB_ESE_HOST_ID
:
416 ndev
->hci_dev
->count_pipes
= 0;
417 ndev
->hci_dev
->expected_pipes
= ST21NFCB_SE_COUNT_PIPE_EMBEDDED
;
424 * Wait for an EVT_HOT_PLUG in order to
425 * retrieve a relevant host list.
427 reinit_completion(&info
->se_info
.req_completion
);
428 r
= nci_nfcee_mode_set(ndev
, se_idx
, NCI_NFCEE_ENABLE
);
429 if (r
!= NCI_STATUS_OK
)
432 mod_timer(&info
->se_info
.se_active_timer
, jiffies
+
433 msecs_to_jiffies(ST21NFCB_SE_TO_HOT_PLUG
));
434 info
->se_info
.se_active
= true;
436 /* Ignore return value and check in any case the host_list */
437 wait_for_completion_interruptible(&info
->se_info
.req_completion
);
439 /* There might be some "collision" after receiving a HOT_PLUG event
440 * This may cause the CLF to not answer to the next hci command.
441 * There is no possible synchronization to prevent this.
442 * Adding a small delay is the only way to solve the issue.
444 usleep_range(3000, 5000);
446 r
= nci_hci_get_param(ndev
, NCI_HCI_ADMIN_GATE
,
447 NCI_HCI_ADMIN_PARAM_HOST_LIST
, &sk_host_list
);
448 if (r
!= NCI_HCI_ANY_OK
)
451 host_id
= sk_host_list
->data
[sk_host_list
->len
- 1];
452 kfree_skb(sk_host_list
);
453 if (state
== ST21NFCB_SE_MODE_ON
&& host_id
== se_idx
)
455 else if (state
== ST21NFCB_SE_MODE_OFF
&& host_id
!= se_idx
)
461 int st21nfcb_nci_disable_se(struct nci_dev
*ndev
, u32 se_idx
)
465 pr_debug("st21nfcb_nci_disable_se\n");
467 if (se_idx
== NFC_SE_EMBEDDED
) {
468 r
= nci_hci_send_event(ndev
, ST21NFCB_APDU_READER_GATE
,
469 ST21NFCB_EVT_SE_END_OF_APDU_TRANSFER
, NULL
, 0);
476 EXPORT_SYMBOL_GPL(st21nfcb_nci_disable_se
);
478 int st21nfcb_nci_enable_se(struct nci_dev
*ndev
, u32 se_idx
)
482 pr_debug("st21nfcb_nci_enable_se\n");
484 if (se_idx
== ST21NFCB_HCI_HOST_ID_ESE
) {
485 r
= nci_hci_send_event(ndev
, ST21NFCB_APDU_READER_GATE
,
486 ST21NFCB_EVT_SE_SOFT_RESET
, NULL
, 0);
493 EXPORT_SYMBOL_GPL(st21nfcb_nci_enable_se
);
495 static int st21nfcb_hci_network_init(struct nci_dev
*ndev
)
497 struct core_conn_create_dest_spec_params
*dest_params
;
498 struct dest_spec_params spec_params
;
499 struct nci_conn_info
*conn_info
;
503 kzalloc(sizeof(struct core_conn_create_dest_spec_params
) +
504 sizeof(struct dest_spec_params
), GFP_KERNEL
);
505 if (dest_params
== NULL
) {
510 dest_params
->type
= NCI_DESTINATION_SPECIFIC_PARAM_NFCEE_TYPE
;
511 dest_params
->length
= sizeof(struct dest_spec_params
);
512 spec_params
.id
= ndev
->hci_dev
->nfcee_id
;
513 spec_params
.protocol
= NCI_NFCEE_INTERFACE_HCI_ACCESS
;
514 memcpy(dest_params
->value
, &spec_params
, sizeof(struct dest_spec_params
));
515 r
= nci_core_conn_create(ndev
, NCI_DESTINATION_NFCEE
, 1,
516 sizeof(struct core_conn_create_dest_spec_params
) +
517 sizeof(struct dest_spec_params
),
519 if (r
!= NCI_STATUS_OK
)
520 goto free_dest_params
;
522 conn_info
= ndev
->hci_dev
->conn_info
;
524 goto free_dest_params
;
526 memcpy(ndev
->hci_dev
->init_data
.gates
, st21nfcb_gates
,
527 sizeof(st21nfcb_gates
));
530 * Session id must include the driver name + i2c bus addr
531 * persistent info to discriminate 2 identical chips
533 dev_num
= find_first_zero_bit(dev_mask
, ST21NFCB_NUM_DEVICES
);
534 if (dev_num
>= ST21NFCB_NUM_DEVICES
) {
536 goto free_dest_params
;
539 scnprintf(ndev
->hci_dev
->init_data
.session_id
,
540 sizeof(ndev
->hci_dev
->init_data
.session_id
),
541 "%s%2x", "ST21BH", dev_num
);
543 r
= nci_hci_dev_session_init(ndev
);
544 if (r
!= NCI_HCI_ANY_OK
)
547 r
= nci_nfcee_mode_set(ndev
, ndev
->hci_dev
->conn_info
->id
,
549 if (r
!= NCI_STATUS_OK
)
561 int st21nfcb_nci_discover_se(struct nci_dev
*ndev
)
567 pr_debug("st21nfcb_nci_discover_se\n");
569 r
= st21nfcb_hci_network_init(ndev
);
573 param
[0] = ST21NFCB_UICC_HOST_ID
;
574 param
[1] = ST21NFCB_HCI_HOST_ID_ESE
;
575 r
= nci_hci_set_param(ndev
, NCI_HCI_ADMIN_GATE
,
576 NCI_HCI_ADMIN_PARAM_WHITELIST
,
577 param
, sizeof(param
));
578 if (r
!= NCI_HCI_ANY_OK
)
581 r
= st21nfcb_nci_control_se(ndev
, ST21NFCB_UICC_HOST_ID
,
582 ST21NFCB_SE_MODE_ON
);
583 if (r
== ST21NFCB_UICC_HOST_ID
) {
584 nfc_add_se(ndev
->nfc_dev
, ST21NFCB_UICC_HOST_ID
, NFC_SE_UICC
);
588 /* Try to enable eSE in order to check availability */
589 r
= st21nfcb_nci_control_se(ndev
, ST21NFCB_HCI_HOST_ID_ESE
,
590 ST21NFCB_SE_MODE_ON
);
591 if (r
== ST21NFCB_HCI_HOST_ID_ESE
) {
592 nfc_add_se(ndev
->nfc_dev
, ST21NFCB_HCI_HOST_ID_ESE
,
595 st21nfcb_se_get_atr(ndev
);
600 EXPORT_SYMBOL_GPL(st21nfcb_nci_discover_se
);
602 int st21nfcb_nci_se_io(struct nci_dev
*ndev
, u32 se_idx
,
603 u8
*apdu
, size_t apdu_length
,
604 se_io_cb_t cb
, void *cb_context
)
606 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
611 case ST21NFCB_HCI_HOST_ID_ESE
:
612 info
->se_info
.cb
= cb
;
613 info
->se_info
.cb_context
= cb_context
;
614 mod_timer(&info
->se_info
.bwi_timer
, jiffies
+
615 msecs_to_jiffies(info
->se_info
.wt_timeout
));
616 info
->se_info
.bwi_active
= true;
617 return nci_hci_send_event(ndev
, ST21NFCB_APDU_READER_GATE
,
618 ST21NFCB_EVT_TRANSMIT_DATA
, apdu
,
624 EXPORT_SYMBOL(st21nfcb_nci_se_io
);
626 static void st21nfcb_se_wt_timeout(unsigned long data
)
629 * No answer from the secure element
630 * within the defined timeout.
631 * Let's send a reset request as recovery procedure.
632 * According to the situation, we first try to send a software reset
633 * to the secure element. If the next command is still not
634 * answering in time, we send to the CLF a secure element hardware
637 /* hardware reset managed through VCC_UICC_OUT power supply */
639 struct st21nfcb_nci_info
*info
= (struct st21nfcb_nci_info
*) data
;
643 info
->se_info
.bwi_active
= false;
645 if (!info
->se_info
.xch_error
) {
646 info
->se_info
.xch_error
= true;
647 nci_hci_send_event(info
->ndlc
->ndev
, ST21NFCB_APDU_READER_GATE
,
648 ST21NFCB_EVT_SE_SOFT_RESET
, NULL
, 0);
650 info
->se_info
.xch_error
= false;
651 nci_hci_send_event(info
->ndlc
->ndev
, ST21NFCB_DEVICE_MGNT_GATE
,
652 ST21NFCB_EVT_SE_HARD_RESET
, ¶m
, 1);
654 info
->se_info
.cb(info
->se_info
.cb_context
, NULL
, 0, -ETIME
);
657 static void st21nfcb_se_activation_timeout(unsigned long data
)
659 struct st21nfcb_nci_info
*info
= (struct st21nfcb_nci_info
*) data
;
663 info
->se_info
.se_active
= false;
665 complete(&info
->se_info
.req_completion
);
668 int st21nfcb_se_init(struct nci_dev
*ndev
)
670 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
672 init_completion(&info
->se_info
.req_completion
);
673 /* initialize timers */
674 init_timer(&info
->se_info
.bwi_timer
);
675 info
->se_info
.bwi_timer
.data
= (unsigned long)info
;
676 info
->se_info
.bwi_timer
.function
= st21nfcb_se_wt_timeout
;
677 info
->se_info
.bwi_active
= false;
679 init_timer(&info
->se_info
.se_active_timer
);
680 info
->se_info
.se_active_timer
.data
= (unsigned long)info
;
681 info
->se_info
.se_active_timer
.function
=
682 st21nfcb_se_activation_timeout
;
683 info
->se_info
.se_active
= false;
685 info
->se_info
.xch_error
= false;
687 info
->se_info
.wt_timeout
=
688 ST21NFCB_BWI_TO_TIMEOUT(ST21NFCB_ATR_DEFAULT_BWI
);
692 EXPORT_SYMBOL(st21nfcb_se_init
);
694 void st21nfcb_se_deinit(struct nci_dev
*ndev
)
696 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
698 if (info
->se_info
.bwi_active
)
699 del_timer_sync(&info
->se_info
.bwi_timer
);
700 if (info
->se_info
.se_active
)
701 del_timer_sync(&info
->se_info
.se_active_timer
);
703 info
->se_info
.se_active
= false;
704 info
->se_info
.bwi_active
= false;
706 EXPORT_SYMBOL(st21nfcb_se_deinit
);