blob: 5286071e52cf6fed14ec975d1e676f33280311a7 [file] [log] [blame]
Thomas Gleixner46fe7772019-05-31 01:09:57 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Christophe Ricard35630df2014-05-25 22:35:38 +02002/*
3 * NCI based Driver for STMicroelectronics NFC Chip
4 *
5 * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
Christophe Ricard35630df2014-05-25 22:35:38 +02006 */
7
Christophe Ricarded06aeef2015-06-09 22:26:05 +02008#ifndef __LOCAL_ST_NCI_H_
9#define __LOCAL_ST_NCI_H_
Christophe Ricard35630df2014-05-25 22:35:38 +020010
Christophe Ricard35630df2014-05-25 22:35:38 +020011#include "ndlc.h"
12
13/* Define private flags: */
Christophe Ricarded06aeef2015-06-09 22:26:05 +020014#define ST_NCI_RUNNING 1
Christophe Ricard35630df2014-05-25 22:35:38 +020015
Christophe Ricarded06aeef2015-06-09 22:26:05 +020016#define ST_NCI_CORE_PROP 0x01
17#define ST_NCI_SET_NFC_MODE 0x02
Christophe Ricard41fc2f52015-06-06 13:16:52 +020018
Christophe Ricardf5876622015-10-26 05:55:22 +010019/*
20 * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
21 * sequence of at most 32 characters.
22 */
23#define ST_NCI_ESE_MAX_LENGTH 33
Christophe Ricardf5876622015-10-26 05:55:22 +010024
Christophe Ricardb1fa4dc2015-10-25 22:54:36 +010025#define ST_NCI_DEVICE_MGNT_GATE 0x01
26
27#define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
28#define ST_NCI_FACTORY_MODE 2
29
Christophe Ricard41fc2f52015-06-06 13:16:52 +020030struct nci_mode_set_cmd {
31 u8 cmd_type;
32 u8 mode;
33} __packed;
Christophe Ricarddbd70b42015-06-06 13:16:47 +020034
35struct nci_mode_set_rsp {
36 u8 status;
37} __packed;
38
Christophe Ricard3648dc62015-10-25 22:54:39 +010039struct st_nci_se_status {
40 bool is_ese_present;
41 bool is_uicc_present;
42};
43
Christophe Ricardf5876622015-10-26 05:55:22 +010044struct st_nci_se_info {
Christophe Ricard3648dc62015-10-25 22:54:39 +010045 struct st_nci_se_status *se_status;
Christophe Ricardf5876622015-10-26 05:55:22 +010046 u8 atr[ST_NCI_ESE_MAX_LENGTH];
47 struct completion req_completion;
48
49 struct timer_list bwi_timer;
50 int wt_timeout; /* in msecs */
51 bool bwi_active;
52
53 struct timer_list se_active_timer;
54 bool se_active;
55
56 bool xch_error;
57
58 se_io_cb_t cb;
59 void *cb_context;
60};
61
Christophe Ricardb1fa4dc2015-10-25 22:54:36 +010062/**
63 * enum nfc_vendor_cmds - supported nfc vendor commands
64 *
65 * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
66 * are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
67 * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
68 * It does not consider any NFC_ATTR_VENDOR_DATA.
69 * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
70 * RF trimmings or low level drivers configurations (I2C, SPI, SWP).
71 * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
72 * table following RF technology, CLF mode or protocol.
73 * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
74 * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
75 * level drivers configurations or RF trimmings.
76 * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
77 * packet can be more than 8KB.
78 * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
79 * configuration changes without CLF power off.
80 * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
81 * white list).
82 * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
83 * technology. When using this command to anti-collision is done.
Christophe Ricard3aacd7f2016-04-30 09:12:53 +020084 * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity.
Christophe Ricardb1fa4dc2015-10-25 22:54:36 +010085 * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
86 * CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
87 * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
88 * specific CLF command as there is no GPIO for this.
89 * @HCI_DM_FWUPD_END: Allow to complete firmware update.
90 * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
91 * CLF antenna to a reference value.
92 * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
93 * received during a NCI_CORE_INIT_CMD.
94 */
95enum nfc_vendor_cmds {
96 FACTORY_MODE,
97 HCI_CLEAR_ALL_PIPES,
98 HCI_DM_PUT_DATA,
99 HCI_DM_UPDATE_AID,
100 HCI_DM_GET_INFO,
101 HCI_DM_GET_DATA,
102 HCI_DM_DIRECT_LOAD,
103 HCI_DM_RESET,
104 HCI_GET_PARAM,
105 HCI_DM_FIELD_GENERATOR,
Christophe Ricard3aacd7f2016-04-30 09:12:53 +0200106 LOOPBACK,
Christophe Ricardb1fa4dc2015-10-25 22:54:36 +0100107 HCI_DM_FWUPD_START,
108 HCI_DM_FWUPD_END,
109 HCI_DM_VDC_MEASUREMENT_VALUE,
110 HCI_DM_VDC_VALUE_COMPARISON,
111 MANUFACTURER_SPECIFIC,
112};
113
Christophe Ricarded06aeef2015-06-09 22:26:05 +0200114struct st_nci_info {
Christophe Ricard35630df2014-05-25 22:35:38 +0200115 struct llt_ndlc *ndlc;
116 unsigned long flags;
Christophe Ricard3648dc62015-10-25 22:54:39 +0100117
Christophe Ricarded06aeef2015-06-09 22:26:05 +0200118 struct st_nci_se_info se_info;
Christophe Ricard35630df2014-05-25 22:35:38 +0200119};
120
Christophe Ricarded06aeef2015-06-09 22:26:05 +0200121void st_nci_remove(struct nci_dev *ndev);
122int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
Christophe Ricard3648dc62015-10-25 22:54:39 +0100123 int phy_tailroom, struct st_nci_se_status *se_status);
Christophe Ricard35630df2014-05-25 22:35:38 +0200124
Christophe Ricard3648dc62015-10-25 22:54:39 +0100125int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
Christophe Ricardf5876622015-10-26 05:55:22 +0100126void st_nci_se_deinit(struct nci_dev *ndev);
127
128int st_nci_discover_se(struct nci_dev *ndev);
129int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
130int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
131int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
132 u8 *apdu, size_t apdu_length,
133 se_io_cb_t cb, void *cb_context);
134int st_nci_hci_load_session(struct nci_dev *ndev);
135void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
136 u8 event, struct sk_buff *skb);
137void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
138 struct sk_buff *skb);
139
Christophe Ricardb1fa4dc2015-10-25 22:54:36 +0100140int st_nci_vendor_cmds_init(struct nci_dev *ndev);
141
Christophe Ricarded06aeef2015-06-09 22:26:05 +0200142#endif /* __LOCAL_ST_NCI_H_ */