1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef __LOCAL_ST21NFCA_H_
18#define __LOCAL_ST21NFCA_H_
19
20#include <net/nfc/hci.h>
21#include <linux/skbuff.h>
22#include <linux/workqueue.h>
23
24#define HCI_MODE 0
25
26
27#define ST21NFCA_SOF_EOF_LEN 2
28
29
30#define ST21NFCA_HCI_LLC_LEN 1
31
32
33
34
35
36#define ST21NFCA_HCI_LLC_CRC 4
37
38#define ST21NFCA_HCI_LLC_LEN_CRC (ST21NFCA_SOF_EOF_LEN + \
39 ST21NFCA_HCI_LLC_LEN + \
40 ST21NFCA_HCI_LLC_CRC)
41#define ST21NFCA_HCI_LLC_MIN_SIZE (1 + ST21NFCA_HCI_LLC_LEN_CRC)
42
43
44#define ST21NFCA_HCI_LLC_MAX_PAYLOAD 29
45#define ST21NFCA_HCI_LLC_MAX_SIZE (ST21NFCA_HCI_LLC_LEN_CRC + 1 + \
46 ST21NFCA_HCI_LLC_MAX_PAYLOAD)
47
48
49#define ST21NFCA_WR_XCHG_DATA 0x10
50
51#define ST21NFCA_DEVICE_MGNT_GATE 0x01
52#define ST21NFCA_RF_READER_F_GATE 0x14
53#define ST21NFCA_RF_CARD_F_GATE 0x24
54#define ST21NFCA_APDU_READER_GATE 0xf0
55#define ST21NFCA_CONNECTIVITY_GATE 0x41
56
57
58
59
60
61#define ST21NFCA_ESE_MAX_LENGTH 33
62#define ST21NFCA_ESE_HOST_ID 0xc0
63
64#define DRIVER_DESC "HCI NFC driver for ST21NFCA"
65
66#define ST21NFCA_HCI_MODE 0
67#define ST21NFCA_NUM_DEVICES 256
68
69#define ST21NFCA_VENDOR_OUI 0x0080E1
70#define ST21NFCA_FACTORY_MODE 2
71
72struct st21nfca_se_status {
73 bool is_ese_present;
74 bool is_uicc_present;
75};
76
77enum st21nfca_state {
78 ST21NFCA_ST_COLD,
79 ST21NFCA_ST_READY,
80};
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107enum nfc_vendor_cmds {
108 FACTORY_MODE,
109 HCI_CLEAR_ALL_PIPES,
110 HCI_DM_PUT_DATA,
111 HCI_DM_UPDATE_AID,
112 HCI_DM_GET_INFO,
113 HCI_DM_GET_DATA,
114 HCI_DM_LOAD,
115 HCI_DM_RESET,
116 HCI_GET_PARAM,
117 HCI_DM_FIELD_GENERATOR,
118 HCI_LOOPBACK,
119};
120
121struct st21nfca_vendor_info {
122 struct completion req_completion;
123 struct sk_buff *rx_skb;
124};
125
126struct st21nfca_dep_info {
127 struct sk_buff *tx_pending;
128 struct work_struct tx_work;
129 u8 curr_nfc_dep_pni;
130 u32 idx;
131 u8 to;
132 u8 did;
133 u8 bsi;
134 u8 bri;
135 u8 lri;
136} __packed;
137
138struct st21nfca_se_info {
139 u8 atr[ST21NFCA_ESE_MAX_LENGTH];
140 struct completion req_completion;
141
142 struct timer_list bwi_timer;
143 int wt_timeout;
144 bool bwi_active;
145
146 struct timer_list se_active_timer;
147 bool se_active;
148 int expected_pipes;
149 int count_pipes;
150
151 bool xch_error;
152
153 se_io_cb_t cb;
154 void *cb_context;
155};
156
157struct st21nfca_hci_info {
158 struct nfc_phy_ops *phy_ops;
159 void *phy_id;
160
161 struct nfc_hci_dev *hdev;
162 struct st21nfca_se_status *se_status;
163
164 enum st21nfca_state state;
165
166 struct mutex info_lock;
167
168 int async_cb_type;
169 data_exchange_cb_t async_cb;
170 void *async_cb_context;
171
172 struct st21nfca_dep_info dep_info;
173 struct st21nfca_se_info se_info;
174 struct st21nfca_vendor_info vendor_info;
175};
176
177int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops,
178 char *llc_name, int phy_headroom, int phy_tailroom,
179 int phy_payload, struct nfc_hci_dev **hdev,
180 struct st21nfca_se_status *se_status);
181void st21nfca_hci_remove(struct nfc_hci_dev *hdev);
182
183int st21nfca_dep_event_received(struct nfc_hci_dev *hdev,
184 u8 event, struct sk_buff *skb);
185int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb);
186
187int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len);
188int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb);
189void st21nfca_dep_init(struct nfc_hci_dev *hdev);
190void st21nfca_dep_deinit(struct nfc_hci_dev *hdev);
191
192int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
193 u8 event, struct sk_buff *skb);
194int st21nfca_apdu_reader_event_received(struct nfc_hci_dev *hdev,
195 u8 event, struct sk_buff *skb);
196
197int st21nfca_hci_discover_se(struct nfc_hci_dev *hdev);
198int st21nfca_hci_enable_se(struct nfc_hci_dev *hdev, u32 se_idx);
199int st21nfca_hci_disable_se(struct nfc_hci_dev *hdev, u32 se_idx);
200int st21nfca_hci_se_io(struct nfc_hci_dev *hdev, u32 se_idx,
201 u8 *apdu, size_t apdu_length,
202 se_io_cb_t cb, void *cb_context);
203
204void st21nfca_se_init(struct nfc_hci_dev *hdev);
205void st21nfca_se_deinit(struct nfc_hci_dev *hdev);
206
207int st21nfca_hci_loopback_event_received(struct nfc_hci_dev *ndev, u8 event,
208 struct sk_buff *skb);
209int st21nfca_vendor_cmds_init(struct nfc_hci_dev *ndev);
210
211#endif
212