Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright (C) 2011  Intel Corporation. All rights reserved.
0004  */
0005 
0006 #ifndef __NET_HCI_H
0007 #define __NET_HCI_H
0008 
0009 #include <linux/skbuff.h>
0010 
0011 #include <net/nfc/nfc.h>
0012 
0013 struct nfc_hci_dev;
0014 
0015 struct nfc_hci_ops {
0016     int (*open) (struct nfc_hci_dev *hdev);
0017     void (*close) (struct nfc_hci_dev *hdev);
0018     int (*load_session) (struct nfc_hci_dev *hdev);
0019     int (*hci_ready) (struct nfc_hci_dev *hdev);
0020     /*
0021      * xmit must always send the complete buffer before
0022      * returning. Returned result must be 0 for success
0023      * or negative for failure.
0024      */
0025     int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb);
0026     int (*start_poll) (struct nfc_hci_dev *hdev,
0027                u32 im_protocols, u32 tm_protocols);
0028     void (*stop_poll) (struct nfc_hci_dev *hdev);
0029     int (*dep_link_up)(struct nfc_hci_dev *hdev, struct nfc_target *target,
0030                u8 comm_mode, u8 *gb, size_t gb_len);
0031     int (*dep_link_down)(struct nfc_hci_dev *hdev);
0032     int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate,
0033                  struct nfc_target *target);
0034     int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate,
0035                        struct nfc_target *target);
0036     int (*im_transceive) (struct nfc_hci_dev *hdev,
0037                   struct nfc_target *target, struct sk_buff *skb,
0038                   data_exchange_cb_t cb, void *cb_context);
0039     int (*tm_send)(struct nfc_hci_dev *hdev, struct sk_buff *skb);
0040     int (*check_presence)(struct nfc_hci_dev *hdev,
0041                   struct nfc_target *target);
0042     int (*event_received)(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
0043                   struct sk_buff *skb);
0044     void (*cmd_received)(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
0045                 struct sk_buff *skb);
0046     int (*fw_download)(struct nfc_hci_dev *hdev, const char *firmware_name);
0047     int (*discover_se)(struct nfc_hci_dev *dev);
0048     int (*enable_se)(struct nfc_hci_dev *dev, u32 se_idx);
0049     int (*disable_se)(struct nfc_hci_dev *dev, u32 se_idx);
0050     int (*se_io)(struct nfc_hci_dev *dev, u32 se_idx,
0051               u8 *apdu, size_t apdu_length,
0052               se_io_cb_t cb, void *cb_context);
0053 };
0054 
0055 /* Pipes */
0056 #define NFC_HCI_DO_NOT_CREATE_PIPE  0x81
0057 #define NFC_HCI_INVALID_PIPE    0x80
0058 #define NFC_HCI_INVALID_GATE    0xFF
0059 #define NFC_HCI_INVALID_HOST    0x80
0060 #define NFC_HCI_LINK_MGMT_PIPE  0x00
0061 #define NFC_HCI_ADMIN_PIPE  0x01
0062 
0063 struct nfc_hci_gate {
0064     u8 gate;
0065     u8 pipe;
0066 };
0067 
0068 struct nfc_hci_pipe {
0069     u8 gate;
0070     u8 dest_host;
0071 };
0072 
0073 #define NFC_HCI_MAX_CUSTOM_GATES    50
0074 /*
0075  * According to specification 102 622 chapter 4.4 Pipes,
0076  * the pipe identifier is 7 bits long.
0077  */
0078 #define NFC_HCI_MAX_PIPES       128
0079 struct nfc_hci_init_data {
0080     u8 gate_count;
0081     struct nfc_hci_gate gates[NFC_HCI_MAX_CUSTOM_GATES];
0082     char session_id[9];
0083 };
0084 
0085 typedef int (*xmit) (struct sk_buff *skb, void *cb_data);
0086 
0087 #define NFC_HCI_MAX_GATES       256
0088 
0089 /*
0090  * These values can be specified by a driver to indicate it requires some
0091  * adaptation of the HCI standard.
0092  *
0093  * NFC_HCI_QUIRK_SHORT_CLEAR - send HCI_ADM_CLEAR_ALL_PIPE cmd with no params
0094  */
0095 enum {
0096     NFC_HCI_QUIRK_SHORT_CLEAR   = 0,
0097 };
0098 
0099 struct nfc_hci_dev {
0100     struct nfc_dev *ndev;
0101 
0102     u32 max_data_link_payload;
0103 
0104     bool shutting_down;
0105 
0106     struct mutex msg_tx_mutex;
0107 
0108     struct list_head msg_tx_queue;
0109 
0110     struct work_struct msg_tx_work;
0111 
0112     struct timer_list cmd_timer;
0113     struct hci_msg *cmd_pending_msg;
0114 
0115     struct sk_buff_head rx_hcp_frags;
0116 
0117     struct work_struct msg_rx_work;
0118 
0119     struct sk_buff_head msg_rx_queue;
0120 
0121     const struct nfc_hci_ops *ops;
0122 
0123     struct nfc_llc *llc;
0124 
0125     struct nfc_hci_init_data init_data;
0126 
0127     void *clientdata;
0128 
0129     u8 gate2pipe[NFC_HCI_MAX_GATES];
0130     struct nfc_hci_pipe pipes[NFC_HCI_MAX_PIPES];
0131 
0132     u8 sw_romlib;
0133     u8 sw_patch;
0134     u8 sw_flashlib_major;
0135     u8 sw_flashlib_minor;
0136 
0137     u8 hw_derivative;
0138     u8 hw_version;
0139     u8 hw_mpw;
0140     u8 hw_software;
0141     u8 hw_bsid;
0142 
0143     int async_cb_type;
0144     data_exchange_cb_t async_cb;
0145     void *async_cb_context;
0146 
0147     u8 *gb;
0148     size_t gb_len;
0149 
0150     unsigned long quirks;
0151 };
0152 
0153 /* hci device allocation */
0154 struct nfc_hci_dev *nfc_hci_allocate_device(const struct nfc_hci_ops *ops,
0155                         struct nfc_hci_init_data *init_data,
0156                         unsigned long quirks,
0157                         u32 protocols,
0158                         const char *llc_name,
0159                         int tx_headroom,
0160                         int tx_tailroom,
0161                         int max_link_payload);
0162 void nfc_hci_free_device(struct nfc_hci_dev *hdev);
0163 
0164 int nfc_hci_register_device(struct nfc_hci_dev *hdev);
0165 void nfc_hci_unregister_device(struct nfc_hci_dev *hdev);
0166 
0167 void nfc_hci_set_clientdata(struct nfc_hci_dev *hdev, void *clientdata);
0168 void *nfc_hci_get_clientdata(struct nfc_hci_dev *hdev);
0169 
0170 static inline int nfc_hci_set_vendor_cmds(struct nfc_hci_dev *hdev,
0171                       const struct nfc_vendor_cmd *cmds,
0172                       int n_cmds)
0173 {
0174     return nfc_set_vendor_cmds(hdev->ndev, cmds, n_cmds);
0175 }
0176 
0177 void nfc_hci_driver_failure(struct nfc_hci_dev *hdev, int err);
0178 
0179 int nfc_hci_result_to_errno(u8 result);
0180 void nfc_hci_reset_pipes(struct nfc_hci_dev *dev);
0181 void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev *hdev, u8 host);
0182 
0183 /* Host IDs */
0184 #define NFC_HCI_HOST_CONTROLLER_ID  0x00
0185 #define NFC_HCI_TERMINAL_HOST_ID    0x01
0186 #define NFC_HCI_UICC_HOST_ID        0x02
0187 
0188 /* Host Controller Gates and registry indexes */
0189 #define NFC_HCI_ADMIN_GATE 0x00
0190 #define NFC_HCI_ADMIN_SESSION_IDENTITY  0x01
0191 #define NFC_HCI_ADMIN_MAX_PIPE      0x02
0192 #define NFC_HCI_ADMIN_WHITELIST     0x03
0193 #define NFC_HCI_ADMIN_HOST_LIST     0x04
0194 
0195 #define NFC_HCI_LOOPBACK_GATE       0x04
0196 
0197 #define NFC_HCI_ID_MGMT_GATE        0x05
0198 #define NFC_HCI_ID_MGMT_VERSION_SW  0x01
0199 #define NFC_HCI_ID_MGMT_VERSION_HW  0x03
0200 #define NFC_HCI_ID_MGMT_VENDOR_NAME 0x04
0201 #define NFC_HCI_ID_MGMT_MODEL_ID    0x05
0202 #define NFC_HCI_ID_MGMT_HCI_VERSION 0x02
0203 #define NFC_HCI_ID_MGMT_GATES_LIST  0x06
0204 
0205 #define NFC_HCI_LINK_MGMT_GATE      0x06
0206 #define NFC_HCI_LINK_MGMT_REC_ERROR 0x01
0207 
0208 #define NFC_HCI_RF_READER_B_GATE            0x11
0209 #define NFC_HCI_RF_READER_B_PUPI            0x03
0210 #define NFC_HCI_RF_READER_B_APPLICATION_DATA        0x04
0211 #define NFC_HCI_RF_READER_B_AFI             0x02
0212 #define NFC_HCI_RF_READER_B_HIGHER_LAYER_RESPONSE   0x01
0213 #define NFC_HCI_RF_READER_B_HIGHER_LAYER_DATA       0x05
0214 
0215 #define NFC_HCI_RF_READER_A_GATE        0x13
0216 #define NFC_HCI_RF_READER_A_UID         0x02
0217 #define NFC_HCI_RF_READER_A_ATQA        0x04
0218 #define NFC_HCI_RF_READER_A_APPLICATION_DATA    0x05
0219 #define NFC_HCI_RF_READER_A_SAK         0x03
0220 #define NFC_HCI_RF_READER_A_FWI_SFGT        0x06
0221 #define NFC_HCI_RF_READER_A_DATARATE_MAX    0x01
0222 
0223 #define NFC_HCI_TYPE_A_SEL_PROT(x)      (((x) & 0x60) >> 5)
0224 #define NFC_HCI_TYPE_A_SEL_PROT_MIFARE      0
0225 #define NFC_HCI_TYPE_A_SEL_PROT_ISO14443    1
0226 #define NFC_HCI_TYPE_A_SEL_PROT_DEP     2
0227 #define NFC_HCI_TYPE_A_SEL_PROT_ISO14443_DEP    3
0228 
0229 /* Generic events */
0230 #define NFC_HCI_EVT_HCI_END_OF_OPERATION    0x01
0231 #define NFC_HCI_EVT_POST_DATA           0x02
0232 #define NFC_HCI_EVT_HOT_PLUG            0x03
0233 
0234 /* Generic commands */
0235 #define NFC_HCI_ANY_SET_PARAMETER   0x01
0236 #define NFC_HCI_ANY_GET_PARAMETER   0x02
0237 #define NFC_HCI_ANY_OPEN_PIPE       0x03
0238 #define NFC_HCI_ANY_CLOSE_PIPE      0x04
0239 
0240 /* Reader RF gates events */
0241 #define NFC_HCI_EVT_READER_REQUESTED    0x10
0242 #define NFC_HCI_EVT_END_OPERATION   0x11
0243 
0244 /* Reader Application gate events */
0245 #define NFC_HCI_EVT_TARGET_DISCOVERED   0x10
0246 
0247 /* receiving messages from lower layer */
0248 void nfc_hci_resp_received(struct nfc_hci_dev *hdev, u8 result,
0249                struct sk_buff *skb);
0250 void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
0251               struct sk_buff *skb);
0252 void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
0253                 struct sk_buff *skb);
0254 void nfc_hci_recv_frame(struct nfc_hci_dev *hdev, struct sk_buff *skb);
0255 
0256 /* connecting to gates and sending hci instructions */
0257 int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate,
0258              u8 pipe);
0259 int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate);
0260 int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev);
0261 int nfc_hci_get_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
0262               struct sk_buff **skb);
0263 int nfc_hci_set_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
0264               const u8 *param, size_t param_len);
0265 int nfc_hci_send_cmd(struct nfc_hci_dev *hdev, u8 gate, u8 cmd,
0266              const u8 *param, size_t param_len, struct sk_buff **skb);
0267 int nfc_hci_send_cmd_async(struct nfc_hci_dev *hdev, u8 gate, u8 cmd,
0268                const u8 *param, size_t param_len,
0269                data_exchange_cb_t cb, void *cb_context);
0270 int nfc_hci_send_event(struct nfc_hci_dev *hdev, u8 gate, u8 event,
0271                const u8 *param, size_t param_len);
0272 int nfc_hci_target_discovered(struct nfc_hci_dev *hdev, u8 gate);
0273 u32 nfc_hci_sak_to_protocol(u8 sak);
0274 
0275 #endif /* __NET_HCI_H */