xref: /openbmc/linux/drivers/nfc/st-nci/st-nci.h (revision fbb6b31a)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * NCI based Driver for STMicroelectronics NFC Chip
4  *
5  * Copyright (C) 2014  STMicroelectronics SAS. All rights reserved.
6  */
7 
8 #ifndef __LOCAL_ST_NCI_H_
9 #define __LOCAL_ST_NCI_H_
10 
11 #include "ndlc.h"
12 
13 /* Define private flags: */
14 #define ST_NCI_RUNNING			1
15 
16 #define ST_NCI_CORE_PROP                0x01
17 #define ST_NCI_SET_NFC_MODE             0x02
18 
19 /*
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
24 
25 #define ST_NCI_DEVICE_MGNT_GATE		0x01
26 
27 #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
28 #define ST_NCI_FACTORY_MODE 2
29 
30 struct nci_mode_set_cmd {
31 	u8 cmd_type;
32 	u8 mode;
33 } __packed;
34 
35 struct nci_mode_set_rsp {
36 	u8 status;
37 } __packed;
38 
39 struct st_nci_se_status {
40 	bool is_ese_present;
41 	bool is_uicc_present;
42 };
43 
44 struct st_nci_se_info {
45 	struct st_nci_se_status *se_status;
46 	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 
62 /**
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.
84  * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity.
85  * @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  */
95 enum 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,
106 	LOOPBACK,
107 	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 
114 struct st_nci_info {
115 	struct llt_ndlc *ndlc;
116 	unsigned long flags;
117 
118 	struct st_nci_se_info se_info;
119 };
120 
121 void st_nci_remove(struct nci_dev *ndev);
122 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
123 		 int phy_tailroom, struct st_nci_se_status *se_status);
124 
125 int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
126 void st_nci_se_deinit(struct nci_dev *ndev);
127 
128 int st_nci_discover_se(struct nci_dev *ndev);
129 int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
130 int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
131 int 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);
134 int st_nci_hci_load_session(struct nci_dev *ndev);
135 void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
136 					u8 event, struct sk_buff *skb);
137 void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
138 						struct sk_buff *skb);
139 
140 int st_nci_vendor_cmds_init(struct nci_dev *ndev);
141 
142 #endif /* __LOCAL_ST_NCI_H_ */
143