1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2011 Intel Corporation. All rights reserved.
9 #include <linux/skbuff.h>
11 #include <net/nfc/nfc.h>
16 int (*open
) (struct nfc_hci_dev
*hdev
);
17 void (*close
) (struct nfc_hci_dev
*hdev
);
18 int (*load_session
) (struct nfc_hci_dev
*hdev
);
19 int (*hci_ready
) (struct nfc_hci_dev
*hdev
);
21 * xmit must always send the complete buffer before
22 * returning. Returned result must be 0 for success
23 * or negative for failure.
25 int (*xmit
) (struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
);
26 int (*start_poll
) (struct nfc_hci_dev
*hdev
,
27 u32 im_protocols
, u32 tm_protocols
);
28 void (*stop_poll
) (struct nfc_hci_dev
*hdev
);
29 int (*dep_link_up
)(struct nfc_hci_dev
*hdev
, struct nfc_target
*target
,
30 u8 comm_mode
, u8
*gb
, size_t gb_len
);
31 int (*dep_link_down
)(struct nfc_hci_dev
*hdev
);
32 int (*target_from_gate
) (struct nfc_hci_dev
*hdev
, u8 gate
,
33 struct nfc_target
*target
);
34 int (*complete_target_discovered
) (struct nfc_hci_dev
*hdev
, u8 gate
,
35 struct nfc_target
*target
);
36 int (*im_transceive
) (struct nfc_hci_dev
*hdev
,
37 struct nfc_target
*target
, struct sk_buff
*skb
,
38 data_exchange_cb_t cb
, void *cb_context
);
39 int (*tm_send
)(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
);
40 int (*check_presence
)(struct nfc_hci_dev
*hdev
,
41 struct nfc_target
*target
);
42 int (*event_received
)(struct nfc_hci_dev
*hdev
, u8 pipe
, u8 event
,
44 void (*cmd_received
)(struct nfc_hci_dev
*hdev
, u8 pipe
, u8 cmd
,
46 int (*fw_download
)(struct nfc_hci_dev
*hdev
, const char *firmware_name
);
47 int (*discover_se
)(struct nfc_hci_dev
*dev
);
48 int (*enable_se
)(struct nfc_hci_dev
*dev
, u32 se_idx
);
49 int (*disable_se
)(struct nfc_hci_dev
*dev
, u32 se_idx
);
50 int (*se_io
)(struct nfc_hci_dev
*dev
, u32 se_idx
,
51 u8
*apdu
, size_t apdu_length
,
52 se_io_cb_t cb
, void *cb_context
);
56 #define NFC_HCI_DO_NOT_CREATE_PIPE 0x81
57 #define NFC_HCI_INVALID_PIPE 0x80
58 #define NFC_HCI_INVALID_GATE 0xFF
59 #define NFC_HCI_INVALID_HOST 0x80
60 #define NFC_HCI_LINK_MGMT_PIPE 0x00
61 #define NFC_HCI_ADMIN_PIPE 0x01
73 #define NFC_HCI_MAX_CUSTOM_GATES 50
75 * According to specification 102 622 chapter 4.4 Pipes,
76 * the pipe identifier is 7 bits long.
78 #define NFC_HCI_MAX_PIPES 128
79 struct nfc_hci_init_data
{
81 struct nfc_hci_gate gates
[NFC_HCI_MAX_CUSTOM_GATES
];
85 typedef int (*xmit
) (struct sk_buff
*skb
, void *cb_data
);
87 #define NFC_HCI_MAX_GATES 256
90 * These values can be specified by a driver to indicate it requires some
91 * adaptation of the HCI standard.
93 * NFC_HCI_QUIRK_SHORT_CLEAR - send HCI_ADM_CLEAR_ALL_PIPE cmd with no params
96 NFC_HCI_QUIRK_SHORT_CLEAR
= 0,
100 struct nfc_dev
*ndev
;
102 u32 max_data_link_payload
;
106 struct mutex msg_tx_mutex
;
108 struct list_head msg_tx_queue
;
110 struct work_struct msg_tx_work
;
112 struct timer_list cmd_timer
;
113 struct hci_msg
*cmd_pending_msg
;
115 struct sk_buff_head rx_hcp_frags
;
117 struct work_struct msg_rx_work
;
119 struct sk_buff_head msg_rx_queue
;
121 struct nfc_hci_ops
*ops
;
125 struct nfc_hci_init_data init_data
;
129 u8 gate2pipe
[NFC_HCI_MAX_GATES
];
130 struct nfc_hci_pipe pipes
[NFC_HCI_MAX_PIPES
];
134 u8 sw_flashlib_major
;
135 u8 sw_flashlib_minor
;
144 data_exchange_cb_t async_cb
;
145 void *async_cb_context
;
150 unsigned long quirks
;
153 /* hci device allocation */
154 struct nfc_hci_dev
*nfc_hci_allocate_device(struct nfc_hci_ops
*ops
,
155 struct nfc_hci_init_data
*init_data
,
156 unsigned long quirks
,
158 const char *llc_name
,
161 int max_link_payload
);
162 void nfc_hci_free_device(struct nfc_hci_dev
*hdev
);
164 int nfc_hci_register_device(struct nfc_hci_dev
*hdev
);
165 void nfc_hci_unregister_device(struct nfc_hci_dev
*hdev
);
167 void nfc_hci_set_clientdata(struct nfc_hci_dev
*hdev
, void *clientdata
);
168 void *nfc_hci_get_clientdata(struct nfc_hci_dev
*hdev
);
170 static inline int nfc_hci_set_vendor_cmds(struct nfc_hci_dev
*hdev
,
171 struct nfc_vendor_cmd
*cmds
,
174 return nfc_set_vendor_cmds(hdev
->ndev
, cmds
, n_cmds
);
177 void nfc_hci_driver_failure(struct nfc_hci_dev
*hdev
, int err
);
179 int nfc_hci_result_to_errno(u8 result
);
180 void nfc_hci_reset_pipes(struct nfc_hci_dev
*dev
);
181 void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev
*hdev
, u8 host
);
184 #define NFC_HCI_HOST_CONTROLLER_ID 0x00
185 #define NFC_HCI_TERMINAL_HOST_ID 0x01
186 #define NFC_HCI_UICC_HOST_ID 0x02
188 /* Host Controller Gates and registry indexes */
189 #define NFC_HCI_ADMIN_GATE 0x00
190 #define NFC_HCI_ADMIN_SESSION_IDENTITY 0x01
191 #define NFC_HCI_ADMIN_MAX_PIPE 0x02
192 #define NFC_HCI_ADMIN_WHITELIST 0x03
193 #define NFC_HCI_ADMIN_HOST_LIST 0x04
195 #define NFC_HCI_LOOPBACK_GATE 0x04
197 #define NFC_HCI_ID_MGMT_GATE 0x05
198 #define NFC_HCI_ID_MGMT_VERSION_SW 0x01
199 #define NFC_HCI_ID_MGMT_VERSION_HW 0x03
200 #define NFC_HCI_ID_MGMT_VENDOR_NAME 0x04
201 #define NFC_HCI_ID_MGMT_MODEL_ID 0x05
202 #define NFC_HCI_ID_MGMT_HCI_VERSION 0x02
203 #define NFC_HCI_ID_MGMT_GATES_LIST 0x06
205 #define NFC_HCI_LINK_MGMT_GATE 0x06
206 #define NFC_HCI_LINK_MGMT_REC_ERROR 0x01
208 #define NFC_HCI_RF_READER_B_GATE 0x11
209 #define NFC_HCI_RF_READER_B_PUPI 0x03
210 #define NFC_HCI_RF_READER_B_APPLICATION_DATA 0x04
211 #define NFC_HCI_RF_READER_B_AFI 0x02
212 #define NFC_HCI_RF_READER_B_HIGHER_LAYER_RESPONSE 0x01
213 #define NFC_HCI_RF_READER_B_HIGHER_LAYER_DATA 0x05
215 #define NFC_HCI_RF_READER_A_GATE 0x13
216 #define NFC_HCI_RF_READER_A_UID 0x02
217 #define NFC_HCI_RF_READER_A_ATQA 0x04
218 #define NFC_HCI_RF_READER_A_APPLICATION_DATA 0x05
219 #define NFC_HCI_RF_READER_A_SAK 0x03
220 #define NFC_HCI_RF_READER_A_FWI_SFGT 0x06
221 #define NFC_HCI_RF_READER_A_DATARATE_MAX 0x01
223 #define NFC_HCI_TYPE_A_SEL_PROT(x) (((x) & 0x60) >> 5)
224 #define NFC_HCI_TYPE_A_SEL_PROT_MIFARE 0
225 #define NFC_HCI_TYPE_A_SEL_PROT_ISO14443 1
226 #define NFC_HCI_TYPE_A_SEL_PROT_DEP 2
227 #define NFC_HCI_TYPE_A_SEL_PROT_ISO14443_DEP 3
230 #define NFC_HCI_EVT_HCI_END_OF_OPERATION 0x01
231 #define NFC_HCI_EVT_POST_DATA 0x02
232 #define NFC_HCI_EVT_HOT_PLUG 0x03
234 /* Generic commands */
235 #define NFC_HCI_ANY_SET_PARAMETER 0x01
236 #define NFC_HCI_ANY_GET_PARAMETER 0x02
237 #define NFC_HCI_ANY_OPEN_PIPE 0x03
238 #define NFC_HCI_ANY_CLOSE_PIPE 0x04
240 /* Reader RF gates events */
241 #define NFC_HCI_EVT_READER_REQUESTED 0x10
242 #define NFC_HCI_EVT_END_OPERATION 0x11
244 /* Reader Application gate events */
245 #define NFC_HCI_EVT_TARGET_DISCOVERED 0x10
247 /* receiving messages from lower layer */
248 void nfc_hci_resp_received(struct nfc_hci_dev
*hdev
, u8 result
,
249 struct sk_buff
*skb
);
250 void nfc_hci_cmd_received(struct nfc_hci_dev
*hdev
, u8 pipe
, u8 cmd
,
251 struct sk_buff
*skb
);
252 void nfc_hci_event_received(struct nfc_hci_dev
*hdev
, u8 pipe
, u8 event
,
253 struct sk_buff
*skb
);
254 void nfc_hci_recv_frame(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
);
256 /* connecting to gates and sending hci instructions */
257 int nfc_hci_connect_gate(struct nfc_hci_dev
*hdev
, u8 dest_host
, u8 dest_gate
,
259 int nfc_hci_disconnect_gate(struct nfc_hci_dev
*hdev
, u8 gate
);
260 int nfc_hci_disconnect_all_gates(struct nfc_hci_dev
*hdev
);
261 int nfc_hci_get_param(struct nfc_hci_dev
*hdev
, u8 gate
, u8 idx
,
262 struct sk_buff
**skb
);
263 int nfc_hci_set_param(struct nfc_hci_dev
*hdev
, u8 gate
, u8 idx
,
264 const u8
*param
, size_t param_len
);
265 int nfc_hci_send_cmd(struct nfc_hci_dev
*hdev
, u8 gate
, u8 cmd
,
266 const u8
*param
, size_t param_len
, struct sk_buff
**skb
);
267 int nfc_hci_send_cmd_async(struct nfc_hci_dev
*hdev
, u8 gate
, u8 cmd
,
268 const u8
*param
, size_t param_len
,
269 data_exchange_cb_t cb
, void *cb_context
);
270 int nfc_hci_send_event(struct nfc_hci_dev
*hdev
, u8 gate
, u8 event
,
271 const u8
*param
, size_t param_len
);
272 int nfc_hci_target_discovered(struct nfc_hci_dev
*hdev
, u8 gate
);
273 u32
nfc_hci_sak_to_protocol(u8 sak
);
275 #endif /* __NET_HCI_H */