0001
0002
0003
0004
0005
0006 #ifndef __LOCAL_ST21NFCA_H_
0007 #define __LOCAL_ST21NFCA_H_
0008
0009 #include <net/nfc/hci.h>
0010 #include <linux/skbuff.h>
0011 #include <linux/workqueue.h>
0012
0013 #define HCI_MODE 0
0014
0015
0016 #define ST21NFCA_SOF_EOF_LEN 2
0017
0018
0019 #define ST21NFCA_HCI_LLC_LEN 1
0020
0021
0022
0023
0024
0025 #define ST21NFCA_HCI_LLC_CRC 4
0026
0027 #define ST21NFCA_HCI_LLC_LEN_CRC (ST21NFCA_SOF_EOF_LEN + \
0028 ST21NFCA_HCI_LLC_LEN + \
0029 ST21NFCA_HCI_LLC_CRC)
0030 #define ST21NFCA_HCI_LLC_MIN_SIZE (1 + ST21NFCA_HCI_LLC_LEN_CRC)
0031
0032
0033 #define ST21NFCA_HCI_LLC_MAX_PAYLOAD 29
0034 #define ST21NFCA_HCI_LLC_MAX_SIZE (ST21NFCA_HCI_LLC_LEN_CRC + 1 + \
0035 ST21NFCA_HCI_LLC_MAX_PAYLOAD)
0036
0037
0038 #define ST21NFCA_WR_XCHG_DATA 0x10
0039
0040 #define ST21NFCA_DEVICE_MGNT_GATE 0x01
0041 #define ST21NFCA_RF_READER_F_GATE 0x14
0042 #define ST21NFCA_RF_CARD_F_GATE 0x24
0043 #define ST21NFCA_APDU_READER_GATE 0xf0
0044 #define ST21NFCA_CONNECTIVITY_GATE 0x41
0045
0046
0047
0048
0049
0050 #define ST21NFCA_ESE_MAX_LENGTH 33
0051 #define ST21NFCA_ESE_HOST_ID 0xc0
0052
0053 #define DRIVER_DESC "HCI NFC driver for ST21NFCA"
0054
0055 #define ST21NFCA_HCI_MODE 0
0056 #define ST21NFCA_NUM_DEVICES 256
0057
0058 #define ST21NFCA_VENDOR_OUI 0x0080E1
0059 #define ST21NFCA_FACTORY_MODE 2
0060
0061 struct st21nfca_se_status {
0062 bool is_ese_present;
0063 bool is_uicc_present;
0064 };
0065
0066 enum st21nfca_state {
0067 ST21NFCA_ST_COLD,
0068 ST21NFCA_ST_READY,
0069 };
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 enum nfc_vendor_cmds {
0097 FACTORY_MODE,
0098 HCI_CLEAR_ALL_PIPES,
0099 HCI_DM_PUT_DATA,
0100 HCI_DM_UPDATE_AID,
0101 HCI_DM_GET_INFO,
0102 HCI_DM_GET_DATA,
0103 HCI_DM_LOAD,
0104 HCI_DM_RESET,
0105 HCI_GET_PARAM,
0106 HCI_DM_FIELD_GENERATOR,
0107 HCI_LOOPBACK,
0108 };
0109
0110 struct st21nfca_vendor_info {
0111 struct completion req_completion;
0112 struct sk_buff *rx_skb;
0113 };
0114
0115 struct st21nfca_dep_info {
0116 struct sk_buff *tx_pending;
0117 struct work_struct tx_work;
0118 u8 curr_nfc_dep_pni;
0119 u32 idx;
0120 u8 to;
0121 u8 did;
0122 u8 bsi;
0123 u8 bri;
0124 u8 lri;
0125 } __packed;
0126
0127 struct st21nfca_se_info {
0128 u8 atr[ST21NFCA_ESE_MAX_LENGTH];
0129 struct completion req_completion;
0130
0131 struct timer_list bwi_timer;
0132 int wt_timeout;
0133 bool bwi_active;
0134
0135 struct timer_list se_active_timer;
0136 bool se_active;
0137 int expected_pipes;
0138 int count_pipes;
0139
0140 bool xch_error;
0141
0142 se_io_cb_t cb;
0143 void *cb_context;
0144 struct work_struct timeout_work;
0145 };
0146
0147 struct st21nfca_hci_info {
0148 const struct nfc_phy_ops *phy_ops;
0149 void *phy_id;
0150
0151 struct nfc_hci_dev *hdev;
0152 struct st21nfca_se_status *se_status;
0153
0154 enum st21nfca_state state;
0155
0156 struct mutex info_lock;
0157
0158 int async_cb_type;
0159 data_exchange_cb_t async_cb;
0160 void *async_cb_context;
0161
0162 struct st21nfca_dep_info dep_info;
0163 struct st21nfca_se_info se_info;
0164 struct st21nfca_vendor_info vendor_info;
0165 };
0166
0167 int st21nfca_hci_probe(void *phy_id, const struct nfc_phy_ops *phy_ops,
0168 char *llc_name, int phy_headroom, int phy_tailroom,
0169 int phy_payload, struct nfc_hci_dev **hdev,
0170 struct st21nfca_se_status *se_status);
0171 void st21nfca_hci_remove(struct nfc_hci_dev *hdev);
0172
0173 int st21nfca_dep_event_received(struct nfc_hci_dev *hdev,
0174 u8 event, struct sk_buff *skb);
0175 int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb);
0176
0177 int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len);
0178 int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb);
0179 void st21nfca_dep_init(struct nfc_hci_dev *hdev);
0180 void st21nfca_dep_deinit(struct nfc_hci_dev *hdev);
0181
0182 int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
0183 u8 event, struct sk_buff *skb);
0184 int st21nfca_apdu_reader_event_received(struct nfc_hci_dev *hdev,
0185 u8 event, struct sk_buff *skb);
0186
0187 int st21nfca_hci_discover_se(struct nfc_hci_dev *hdev);
0188 int st21nfca_hci_enable_se(struct nfc_hci_dev *hdev, u32 se_idx);
0189 int st21nfca_hci_disable_se(struct nfc_hci_dev *hdev, u32 se_idx);
0190 int st21nfca_hci_se_io(struct nfc_hci_dev *hdev, u32 se_idx,
0191 u8 *apdu, size_t apdu_length,
0192 se_io_cb_t cb, void *cb_context);
0193
0194 void st21nfca_se_init(struct nfc_hci_dev *hdev);
0195 void st21nfca_se_deinit(struct nfc_hci_dev *hdev);
0196
0197 int st21nfca_hci_loopback_event_received(struct nfc_hci_dev *ndev, u8 event,
0198 struct sk_buff *skb);
0199 int st21nfca_vendor_cmds_init(struct nfc_hci_dev *ndev);
0200
0201 #endif