1 // SPDX-License-Identifier: GPL-2.0-only
3 * Secure Element driver for STMicroelectronics NFC NCI chip
5 * Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
8 #include <linux/module.h>
10 #include <linux/delay.h>
11 #include <net/nfc/nci.h>
12 #include <net/nfc/nci_core.h>
16 struct st_nci_pipe_info {
25 #define ST_NCI_HOST_CONTROLLER_ID 0x00
26 #define ST_NCI_TERMINAL_HOST_ID 0x01
27 #define ST_NCI_UICC_HOST_ID 0x02
28 #define ST_NCI_ESE_HOST_ID 0xc0
31 #define ST_NCI_APDU_READER_GATE 0xf0
32 #define ST_NCI_CONNECTIVITY_GATE 0x41
35 #define ST_NCI_DEVICE_MGNT_PIPE 0x02
37 /* Connectivity pipe only */
38 #define ST_NCI_SE_COUNT_PIPE_UICC 0x01
39 /* Connectivity + APDU Reader pipe */
40 #define ST_NCI_SE_COUNT_PIPE_EMBEDDED 0x02
42 #define ST_NCI_SE_TO_HOT_PLUG 1000 /* msecs */
43 #define ST_NCI_SE_TO_PIPES 2000
45 #define ST_NCI_EVT_HOT_PLUG_IS_INHIBITED(x) (x->data[0] & 0x80)
47 #define NCI_HCI_APDU_PARAM_ATR 0x01
48 #define NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY 0x01
49 #define NCI_HCI_ADMIN_PARAM_WHITELIST 0x03
50 #define NCI_HCI_ADMIN_PARAM_HOST_LIST 0x04
52 #define ST_NCI_EVT_SE_HARD_RESET 0x20
53 #define ST_NCI_EVT_TRANSMIT_DATA 0x10
54 #define ST_NCI_EVT_WTX_REQUEST 0x11
55 #define ST_NCI_EVT_SE_SOFT_RESET 0x11
56 #define ST_NCI_EVT_SE_END_OF_APDU_TRANSFER 0x21
57 #define ST_NCI_EVT_HOT_PLUG 0x03
59 #define ST_NCI_SE_MODE_OFF 0x00
60 #define ST_NCI_SE_MODE_ON 0x01
62 #define ST_NCI_EVT_CONNECTIVITY 0x10
63 #define ST_NCI_EVT_TRANSACTION 0x12
65 #define ST_NCI_DM_GETINFO 0x13
66 #define ST_NCI_DM_GETINFO_PIPE_LIST 0x02
67 #define ST_NCI_DM_GETINFO_PIPE_INFO 0x01
68 #define ST_NCI_DM_PIPE_CREATED 0x02
69 #define ST_NCI_DM_PIPE_OPEN 0x04
70 #define ST_NCI_DM_RF_ACTIVE 0x80
71 #define ST_NCI_DM_DISCONNECT 0x30
73 #define ST_NCI_DM_IS_PIPE_OPEN(p) \
74 ((p & 0x0f) == (ST_NCI_DM_PIPE_CREATED | ST_NCI_DM_PIPE_OPEN))
76 #define ST_NCI_ATR_DEFAULT_BWI 0x04
79 * WT = 2^BWI/10[s], convert into msecs and add a secure
80 * room by increasing by 2 this timeout
82 #define ST_NCI_BWI_TO_TIMEOUT(x) ((1 << x) * 200)
83 #define ST_NCI_ATR_GET_Y_FROM_TD(x) (x >> 4)
85 /* If TA is present bit 0 is set */
86 #define ST_NCI_ATR_TA_PRESENT(x) (x & 0x01)
87 /* If TB is present bit 1 is set */
88 #define ST_NCI_ATR_TB_PRESENT(x) (x & 0x02)
90 #define ST_NCI_NUM_DEVICES 256
92 static DECLARE_BITMAP(dev_mask, ST_NCI_NUM_DEVICES);
94 /* Here are the mandatory pipe for st_nci */
95 static struct nci_hci_gate st_nci_gates[] = {
96 {NCI_HCI_ADMIN_GATE, NCI_HCI_ADMIN_PIPE,
97 ST_NCI_HOST_CONTROLLER_ID},
98 {NCI_HCI_LINK_MGMT_GATE, NCI_HCI_LINK_MGMT_PIPE,
99 ST_NCI_HOST_CONTROLLER_ID},
100 {ST_NCI_DEVICE_MGNT_GATE, ST_NCI_DEVICE_MGNT_PIPE,
101 ST_NCI_HOST_CONTROLLER_ID},
103 {NCI_HCI_IDENTITY_MGMT_GATE, NCI_HCI_INVALID_PIPE,
104 ST_NCI_HOST_CONTROLLER_ID},
106 /* Secure element pipes are created by secure element host */
107 {ST_NCI_CONNECTIVITY_GATE, NCI_HCI_DO_NOT_OPEN_PIPE,
108 ST_NCI_HOST_CONTROLLER_ID},
109 {ST_NCI_APDU_READER_GATE, NCI_HCI_DO_NOT_OPEN_PIPE,
110 ST_NCI_HOST_CONTROLLER_ID},
113 static u8 st_nci_se_get_bwi(struct nci_dev *ndev)
117 struct st_nci_info *info = nci_get_drvdata(ndev);
119 /* Bits 8 to 5 of the first TB for T=1 encode BWI from zero to nine */
120 for (i = 1; i < ST_NCI_ESE_MAX_LENGTH; i++) {
121 td = ST_NCI_ATR_GET_Y_FROM_TD(info->se_info.atr[i]);
122 if (ST_NCI_ATR_TA_PRESENT(td))
124 if (ST_NCI_ATR_TB_PRESENT(td)) {
126 return info->se_info.atr[i] >> 4;
129 return ST_NCI_ATR_DEFAULT_BWI;
132 static void st_nci_se_get_atr(struct nci_dev *ndev)
134 struct st_nci_info *info = nci_get_drvdata(ndev);
138 r = nci_hci_get_param(ndev, ST_NCI_APDU_READER_GATE,
139 NCI_HCI_APDU_PARAM_ATR, &skb);
143 if (skb->len <= ST_NCI_ESE_MAX_LENGTH) {
144 memcpy(info->se_info.atr, skb->data, skb->len);
146 info->se_info.wt_timeout =
147 ST_NCI_BWI_TO_TIMEOUT(st_nci_se_get_bwi(ndev));
152 int st_nci_hci_load_session(struct nci_dev *ndev)
155 struct sk_buff *skb_pipe_list, *skb_pipe_info;
156 struct st_nci_pipe_info *dm_pipe_info;
157 u8 pipe_list[] = { ST_NCI_DM_GETINFO_PIPE_LIST,
158 ST_NCI_TERMINAL_HOST_ID};
159 u8 pipe_info[] = { ST_NCI_DM_GETINFO_PIPE_INFO,
160 ST_NCI_TERMINAL_HOST_ID, 0};
162 /* On ST_NCI device pipes number are dynamics
163 * If pipes are already created, hci_dev_up will fail.
164 * Doing a clear all pipe is a bad idea because:
165 * - It does useless EEPROM cycling
166 * - It might cause issue for secure elements support
167 * (such as removing connectivity or APDU reader pipe)
168 * A better approach on ST_NCI is to:
169 * - get a pipe list for each host.
170 * (eg: ST_NCI_HOST_CONTROLLER_ID for now).
171 * (TODO Later on UICC HOST and eSE HOST)
172 * - get pipe information
173 * - match retrieved pipe list in st_nci_gates
174 * ST_NCI_DEVICE_MGNT_GATE is a proprietary gate
175 * with ST_NCI_DEVICE_MGNT_PIPE.
176 * Pipe can be closed and need to be open.
178 r = nci_hci_connect_gate(ndev, ST_NCI_HOST_CONTROLLER_ID,
179 ST_NCI_DEVICE_MGNT_GATE,
180 ST_NCI_DEVICE_MGNT_PIPE);
185 r = nci_hci_send_cmd(ndev, ST_NCI_DEVICE_MGNT_GATE,
186 ST_NCI_DM_GETINFO, pipe_list, sizeof(pipe_list),
191 /* Complete the existing gate_pipe table */
192 for (i = 0; i < skb_pipe_list->len; i++) {
193 pipe_info[2] = skb_pipe_list->data[i];
194 r = nci_hci_send_cmd(ndev, ST_NCI_DEVICE_MGNT_GATE,
195 ST_NCI_DM_GETINFO, pipe_info,
196 sizeof(pipe_info), &skb_pipe_info);
202 * Match pipe ID and gate ID
203 * Output format from ST21NFC_DM_GETINFO is:
204 * - pipe state (1byte)
205 * - source hid (1byte)
206 * - source gid (1byte)
207 * - destination hid (1byte)
208 * - destination gid (1byte)
210 dm_pipe_info = (struct st_nci_pipe_info *)skb_pipe_info->data;
211 if (dm_pipe_info->dst_gate_id == ST_NCI_APDU_READER_GATE &&
212 dm_pipe_info->src_host_id == ST_NCI_UICC_HOST_ID) {
213 pr_err("Unexpected apdu_reader pipe on host %x\n",
214 dm_pipe_info->src_host_id);
215 kfree_skb(skb_pipe_info);
219 for (j = 3; (j < ARRAY_SIZE(st_nci_gates)) &&
220 (st_nci_gates[j].gate != dm_pipe_info->dst_gate_id); j++)
223 if (j < ARRAY_SIZE(st_nci_gates) &&
224 st_nci_gates[j].gate == dm_pipe_info->dst_gate_id &&
225 ST_NCI_DM_IS_PIPE_OPEN(dm_pipe_info->pipe_state)) {
226 ndev->hci_dev->init_data.gates[j].pipe = pipe_info[2];
228 ndev->hci_dev->gate2pipe[st_nci_gates[j].gate] =
230 ndev->hci_dev->pipes[pipe_info[2]].gate =
231 st_nci_gates[j].gate;
232 ndev->hci_dev->pipes[pipe_info[2]].host =
233 dm_pipe_info->src_host_id;
235 kfree_skb(skb_pipe_info);
239 * 3 gates have a well known pipe ID. Only NCI_HCI_LINK_MGMT_GATE
240 * is not yet open at this stage.
242 r = nci_hci_connect_gate(ndev, ST_NCI_HOST_CONTROLLER_ID,
243 NCI_HCI_LINK_MGMT_GATE,
244 NCI_HCI_LINK_MGMT_PIPE);
246 kfree_skb(skb_pipe_list);
249 EXPORT_SYMBOL_GPL(st_nci_hci_load_session);
251 static void st_nci_hci_admin_event_received(struct nci_dev *ndev,
252 u8 event, struct sk_buff *skb)
254 struct st_nci_info *info = nci_get_drvdata(ndev);
257 case ST_NCI_EVT_HOT_PLUG:
258 if (info->se_info.se_active) {
259 if (!ST_NCI_EVT_HOT_PLUG_IS_INHIBITED(skb)) {
260 del_timer_sync(&info->se_info.se_active_timer);
261 info->se_info.se_active = false;
262 complete(&info->se_info.req_completion);
264 mod_timer(&info->se_info.se_active_timer,
266 msecs_to_jiffies(ST_NCI_SE_TO_PIPES));
271 nfc_err(&ndev->nfc_dev->dev, "Unexpected event on admin gate\n");
275 static int st_nci_hci_apdu_reader_event_received(struct nci_dev *ndev,
279 struct st_nci_info *info = nci_get_drvdata(ndev);
281 pr_debug("apdu reader gate event: %x\n", event);
284 case ST_NCI_EVT_TRANSMIT_DATA:
285 del_timer_sync(&info->se_info.bwi_timer);
286 info->se_info.bwi_active = false;
287 info->se_info.cb(info->se_info.cb_context,
288 skb->data, skb->len, 0);
290 case ST_NCI_EVT_WTX_REQUEST:
291 mod_timer(&info->se_info.bwi_timer, jiffies +
292 msecs_to_jiffies(info->se_info.wt_timeout));
295 nfc_err(&ndev->nfc_dev->dev, "Unexpected event on apdu reader gate\n");
305 * <= 0: driver handled the event, skb consumed
306 * 1: driver does not handle the event, please do standard processing
308 static int st_nci_hci_connectivity_event_received(struct nci_dev *ndev,
313 struct device *dev = &ndev->nfc_dev->dev;
314 struct nfc_evt_transaction *transaction;
316 pr_debug("connectivity gate event: %x\n", event);
319 case ST_NCI_EVT_CONNECTIVITY:
320 r = nfc_se_connectivity(ndev->nfc_dev, host);
322 case ST_NCI_EVT_TRANSACTION:
323 /* According to specification etsi 102 622
324 * 11.2.2.4 EVT_TRANSACTION Table 52
325 * Description Tag Length
327 * PARAMETERS 82 0 to 255
329 if (skb->len < NFC_MIN_AID_LENGTH + 2 &&
330 skb->data[0] != NFC_EVT_TRANSACTION_AID_TAG)
333 transaction = devm_kzalloc(dev, skb->len - 2, GFP_KERNEL);
337 transaction->aid_len = skb->data[1];
338 memcpy(transaction->aid, &skb->data[2], transaction->aid_len);
340 /* Check next byte is PARAMETERS tag (82) */
341 if (skb->data[transaction->aid_len + 2] !=
342 NFC_EVT_TRANSACTION_PARAMS_TAG)
345 transaction->params_len = skb->data[transaction->aid_len + 3];
346 memcpy(transaction->params, skb->data +
347 transaction->aid_len + 4, transaction->params_len);
349 r = nfc_se_transaction(ndev->nfc_dev, host, transaction);
352 nfc_err(&ndev->nfc_dev->dev, "Unexpected event on connectivity gate\n");
359 void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
360 u8 event, struct sk_buff *skb)
362 u8 gate = ndev->hci_dev->pipes[pipe].gate;
363 u8 host = ndev->hci_dev->pipes[pipe].host;
366 case NCI_HCI_ADMIN_GATE:
367 st_nci_hci_admin_event_received(ndev, event, skb);
369 case ST_NCI_APDU_READER_GATE:
370 st_nci_hci_apdu_reader_event_received(ndev, event, skb);
372 case ST_NCI_CONNECTIVITY_GATE:
373 st_nci_hci_connectivity_event_received(ndev, host, event, skb);
377 EXPORT_SYMBOL_GPL(st_nci_hci_event_received);
379 void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
382 struct st_nci_info *info = nci_get_drvdata(ndev);
383 u8 gate = ndev->hci_dev->pipes[pipe].gate;
385 pr_debug("cmd: %x\n", cmd);
388 case NCI_HCI_ANY_OPEN_PIPE:
389 if (gate != ST_NCI_APDU_READER_GATE &&
390 ndev->hci_dev->pipes[pipe].host != ST_NCI_UICC_HOST_ID)
391 ndev->hci_dev->count_pipes++;
393 if (ndev->hci_dev->count_pipes ==
394 ndev->hci_dev->expected_pipes) {
395 del_timer_sync(&info->se_info.se_active_timer);
396 info->se_info.se_active = false;
397 ndev->hci_dev->count_pipes = 0;
398 complete(&info->se_info.req_completion);
403 EXPORT_SYMBOL_GPL(st_nci_hci_cmd_received);
405 static int st_nci_control_se(struct nci_dev *ndev, u8 se_idx,
408 struct st_nci_info *info = nci_get_drvdata(ndev);
410 struct sk_buff *sk_host_list;
414 case ST_NCI_UICC_HOST_ID:
415 ndev->hci_dev->count_pipes = 0;
416 ndev->hci_dev->expected_pipes = ST_NCI_SE_COUNT_PIPE_UICC;
418 case ST_NCI_ESE_HOST_ID:
419 ndev->hci_dev->count_pipes = 0;
420 ndev->hci_dev->expected_pipes = ST_NCI_SE_COUNT_PIPE_EMBEDDED;
427 * Wait for an EVT_HOT_PLUG in order to
428 * retrieve a relevant host list.
430 reinit_completion(&info->se_info.req_completion);
431 r = nci_nfcee_mode_set(ndev, se_idx, state);
432 if (r != NCI_STATUS_OK)
435 mod_timer(&info->se_info.se_active_timer, jiffies +
436 msecs_to_jiffies(ST_NCI_SE_TO_HOT_PLUG));
437 info->se_info.se_active = true;
439 /* Ignore return value and check in any case the host_list */
440 wait_for_completion_interruptible(&info->se_info.req_completion);
442 /* There might be some "collision" after receiving a HOT_PLUG event
443 * This may cause the CLF to not answer to the next hci command.
444 * There is no possible synchronization to prevent this.
445 * Adding a small delay is the only way to solve the issue.
447 if (info->se_info.se_status->is_ese_present &&
448 info->se_info.se_status->is_uicc_present)
449 usleep_range(15000, 20000);
451 r = nci_hci_get_param(ndev, NCI_HCI_ADMIN_GATE,
452 NCI_HCI_ADMIN_PARAM_HOST_LIST, &sk_host_list);
453 if (r != NCI_HCI_ANY_OK)
456 for (i = 0; i < sk_host_list->len &&
457 sk_host_list->data[i] != se_idx; i++)
459 host_id = sk_host_list->data[i];
460 kfree_skb(sk_host_list);
461 if (state == ST_NCI_SE_MODE_ON && host_id == se_idx)
463 else if (state == ST_NCI_SE_MODE_OFF && host_id != se_idx)
469 int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx)
474 * According to upper layer, se_idx == NFC_SE_UICC when
475 * info->se_info.se_status->is_uicc_enable is true should never happen
478 r = st_nci_control_se(ndev, se_idx, ST_NCI_SE_MODE_OFF);
480 /* Do best effort to release SWP */
481 if (se_idx == NFC_SE_EMBEDDED) {
482 r = nci_hci_send_event(ndev, ST_NCI_APDU_READER_GATE,
483 ST_NCI_EVT_SE_END_OF_APDU_TRANSFER,
491 EXPORT_SYMBOL_GPL(st_nci_disable_se);
493 int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx)
498 * According to upper layer, se_idx == NFC_SE_UICC when
499 * info->se_info.se_status->is_uicc_enable is true should never happen.
502 r = st_nci_control_se(ndev, se_idx, ST_NCI_SE_MODE_ON);
503 if (r == ST_NCI_ESE_HOST_ID) {
504 st_nci_se_get_atr(ndev);
505 r = nci_hci_send_event(ndev, ST_NCI_APDU_READER_GATE,
506 ST_NCI_EVT_SE_SOFT_RESET, NULL, 0);
511 * The activation procedure failed, the secure element
512 * is not connected. Remove from the list.
514 nfc_remove_se(ndev->nfc_dev, se_idx);
520 EXPORT_SYMBOL_GPL(st_nci_enable_se);
522 static int st_nci_hci_network_init(struct nci_dev *ndev)
524 struct st_nci_info *info = nci_get_drvdata(ndev);
525 struct core_conn_create_dest_spec_params *dest_params;
526 struct dest_spec_params spec_params;
527 struct nci_conn_info *conn_info;
531 kzalloc(sizeof(struct core_conn_create_dest_spec_params) +
532 sizeof(struct dest_spec_params), GFP_KERNEL);
533 if (dest_params == NULL)
536 dest_params->type = NCI_DESTINATION_SPECIFIC_PARAM_NFCEE_TYPE;
537 dest_params->length = sizeof(struct dest_spec_params);
538 spec_params.id = ndev->hci_dev->nfcee_id;
539 spec_params.protocol = NCI_NFCEE_INTERFACE_HCI_ACCESS;
540 memcpy(dest_params->value, &spec_params,
541 sizeof(struct dest_spec_params));
542 r = nci_core_conn_create(ndev, NCI_DESTINATION_NFCEE, 1,
543 sizeof(struct core_conn_create_dest_spec_params) +
544 sizeof(struct dest_spec_params),
546 if (r != NCI_STATUS_OK)
547 goto free_dest_params;
549 conn_info = ndev->hci_dev->conn_info;
551 goto free_dest_params;
553 ndev->hci_dev->init_data.gate_count = ARRAY_SIZE(st_nci_gates);
554 memcpy(ndev->hci_dev->init_data.gates, st_nci_gates,
555 sizeof(st_nci_gates));
558 * Session id must include the driver name + i2c bus addr
559 * persistent info to discriminate 2 identical chips
561 dev_num = find_first_zero_bit(dev_mask, ST_NCI_NUM_DEVICES);
562 if (dev_num >= ST_NCI_NUM_DEVICES) {
564 goto free_dest_params;
567 scnprintf(ndev->hci_dev->init_data.session_id,
568 sizeof(ndev->hci_dev->init_data.session_id),
569 "%s%2x", "ST21BH", dev_num);
571 r = nci_hci_dev_session_init(ndev);
572 if (r != NCI_HCI_ANY_OK)
573 goto free_dest_params;
576 * In factory mode, we prevent secure elements activation
577 * by disabling nfcee on the current HCI connection id.
578 * HCI will be used here only for proprietary commands.
580 if (test_bit(ST_NCI_FACTORY_MODE, &info->flags))
581 r = nci_nfcee_mode_set(ndev,
582 ndev->hci_dev->conn_info->dest_params->id,
585 r = nci_nfcee_mode_set(ndev,
586 ndev->hci_dev->conn_info->dest_params->id,
594 int st_nci_discover_se(struct nci_dev *ndev)
599 struct st_nci_info *info = nci_get_drvdata(ndev);
601 r = st_nci_hci_network_init(ndev);
605 if (test_bit(ST_NCI_FACTORY_MODE, &info->flags))
608 if (info->se_info.se_status->is_uicc_present)
609 white_list[wl_size++] = ST_NCI_UICC_HOST_ID;
610 if (info->se_info.se_status->is_ese_present)
611 white_list[wl_size++] = ST_NCI_ESE_HOST_ID;
614 r = nci_hci_set_param(ndev, NCI_HCI_ADMIN_GATE,
615 NCI_HCI_ADMIN_PARAM_WHITELIST,
616 white_list, wl_size);
617 if (r != NCI_HCI_ANY_OK)
621 if (info->se_info.se_status->is_uicc_present) {
622 nfc_add_se(ndev->nfc_dev, ST_NCI_UICC_HOST_ID, NFC_SE_UICC);
626 if (info->se_info.se_status->is_ese_present) {
627 nfc_add_se(ndev->nfc_dev, ST_NCI_ESE_HOST_ID, NFC_SE_EMBEDDED);
633 EXPORT_SYMBOL_GPL(st_nci_discover_se);
635 int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
636 u8 *apdu, size_t apdu_length,
637 se_io_cb_t cb, void *cb_context)
639 struct st_nci_info *info = nci_get_drvdata(ndev);
644 case ST_NCI_ESE_HOST_ID:
645 info->se_info.cb = cb;
646 info->se_info.cb_context = cb_context;
647 mod_timer(&info->se_info.bwi_timer, jiffies +
648 msecs_to_jiffies(info->se_info.wt_timeout));
649 info->se_info.bwi_active = true;
650 return nci_hci_send_event(ndev, ST_NCI_APDU_READER_GATE,
651 ST_NCI_EVT_TRANSMIT_DATA, apdu,
657 EXPORT_SYMBOL(st_nci_se_io);
659 static void st_nci_se_wt_timeout(struct timer_list *t)
662 * No answer from the secure element
663 * within the defined timeout.
664 * Let's send a reset request as recovery procedure.
665 * According to the situation, we first try to send a software reset
666 * to the secure element. If the next command is still not
667 * answering in time, we send to the CLF a secure element hardware
670 /* hardware reset managed through VCC_UICC_OUT power supply */
672 struct st_nci_info *info = from_timer(info, t, se_info.bwi_timer);
676 info->se_info.bwi_active = false;
678 if (!info->se_info.xch_error) {
679 info->se_info.xch_error = true;
680 nci_hci_send_event(info->ndlc->ndev, ST_NCI_APDU_READER_GATE,
681 ST_NCI_EVT_SE_SOFT_RESET, NULL, 0);
683 info->se_info.xch_error = false;
684 nci_hci_send_event(info->ndlc->ndev, ST_NCI_DEVICE_MGNT_GATE,
685 ST_NCI_EVT_SE_HARD_RESET, ¶m, 1);
687 info->se_info.cb(info->se_info.cb_context, NULL, 0, -ETIME);
690 static void st_nci_se_activation_timeout(struct timer_list *t)
692 struct st_nci_info *info = from_timer(info, t,
693 se_info.se_active_timer);
697 info->se_info.se_active = false;
699 complete(&info->se_info.req_completion);
702 int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status)
704 struct st_nci_info *info = nci_get_drvdata(ndev);
706 init_completion(&info->se_info.req_completion);
707 /* initialize timers */
708 timer_setup(&info->se_info.bwi_timer, st_nci_se_wt_timeout, 0);
709 info->se_info.bwi_active = false;
711 timer_setup(&info->se_info.se_active_timer,
712 st_nci_se_activation_timeout, 0);
713 info->se_info.se_active = false;
715 info->se_info.xch_error = false;
717 info->se_info.wt_timeout =
718 ST_NCI_BWI_TO_TIMEOUT(ST_NCI_ATR_DEFAULT_BWI);
720 info->se_info.se_status = se_status;
724 EXPORT_SYMBOL(st_nci_se_init);
726 void st_nci_se_deinit(struct nci_dev *ndev)
728 struct st_nci_info *info = nci_get_drvdata(ndev);
730 if (info->se_info.bwi_active)
731 del_timer_sync(&info->se_info.bwi_timer);
732 if (info->se_info.se_active)
733 del_timer_sync(&info->se_info.se_active_timer);
735 info->se_info.se_active = false;
736 info->se_info.bwi_active = false;
738 EXPORT_SYMBOL(st_nci_se_deinit);