1 /* 2 * NCI based Driver for STMicroelectronics NFC Chip 3 * 4 * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __LOCAL_ST_NCI_H_ 20 #define __LOCAL_ST_NCI_H_ 21 22 #include "ndlc.h" 23 24 /* Define private flags: */ 25 #define ST_NCI_RUNNING 1 26 27 #define ST_NCI_CORE_PROP 0x01 28 #define ST_NCI_SET_NFC_MODE 0x02 29 30 /* 31 * ref ISO7816-3 chap 8.1. the initial character TS is followed by a 32 * sequence of at most 32 characters. 33 */ 34 #define ST_NCI_ESE_MAX_LENGTH 33 35 36 #define ST_NCI_DEVICE_MGNT_GATE 0x01 37 38 #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */ 39 #define ST_NCI_FACTORY_MODE 2 40 41 struct nci_mode_set_cmd { 42 u8 cmd_type; 43 u8 mode; 44 } __packed; 45 46 struct nci_mode_set_rsp { 47 u8 status; 48 } __packed; 49 50 struct st_nci_se_status { 51 bool is_ese_present; 52 bool is_uicc_present; 53 }; 54 55 struct st_nci_se_info { 56 struct st_nci_se_status *se_status; 57 u8 atr[ST_NCI_ESE_MAX_LENGTH]; 58 struct completion req_completion; 59 60 struct timer_list bwi_timer; 61 int wt_timeout; /* in msecs */ 62 bool bwi_active; 63 64 struct timer_list se_active_timer; 65 bool se_active; 66 67 bool xch_error; 68 69 se_io_cb_t cb; 70 void *cb_context; 71 }; 72 73 /** 74 * enum nfc_vendor_cmds - supported nfc vendor commands 75 * 76 * @FACTORY_MODE: Allow to set the driver into a mode where no secure element 77 * are activated. It does not consider any NFC_ATTR_VENDOR_DATA. 78 * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command. 79 * It does not consider any NFC_ATTR_VENDOR_DATA. 80 * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example 81 * RF trimmings or low level drivers configurations (I2C, SPI, SWP). 82 * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing 83 * table following RF technology, CLF mode or protocol. 84 * @HCI_DM_GET_INFO: Allow to retrieve CLF information. 85 * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low 86 * level drivers configurations or RF trimmings. 87 * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete 88 * packet can be more than 8KB. 89 * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF 90 * configuration changes without CLF power off. 91 * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the 92 * white list). 93 * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF 94 * technology. When using this command to anti-collision is done. 95 * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity. 96 * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the 97 * CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum. 98 * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a 99 * specific CLF command as there is no GPIO for this. 100 * @HCI_DM_FWUPD_END: Allow to complete firmware update. 101 * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the 102 * CLF antenna to a reference value. 103 * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data 104 * received during a NCI_CORE_INIT_CMD. 105 */ 106 enum nfc_vendor_cmds { 107 FACTORY_MODE, 108 HCI_CLEAR_ALL_PIPES, 109 HCI_DM_PUT_DATA, 110 HCI_DM_UPDATE_AID, 111 HCI_DM_GET_INFO, 112 HCI_DM_GET_DATA, 113 HCI_DM_DIRECT_LOAD, 114 HCI_DM_RESET, 115 HCI_GET_PARAM, 116 HCI_DM_FIELD_GENERATOR, 117 LOOPBACK, 118 HCI_DM_FWUPD_START, 119 HCI_DM_FWUPD_END, 120 HCI_DM_VDC_MEASUREMENT_VALUE, 121 HCI_DM_VDC_VALUE_COMPARISON, 122 MANUFACTURER_SPECIFIC, 123 }; 124 125 struct st_nci_info { 126 struct llt_ndlc *ndlc; 127 unsigned long flags; 128 129 struct st_nci_se_info se_info; 130 }; 131 132 void st_nci_remove(struct nci_dev *ndev); 133 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom, 134 int phy_tailroom, struct st_nci_se_status *se_status); 135 136 int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status); 137 void st_nci_se_deinit(struct nci_dev *ndev); 138 139 int st_nci_discover_se(struct nci_dev *ndev); 140 int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx); 141 int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx); 142 int st_nci_se_io(struct nci_dev *ndev, u32 se_idx, 143 u8 *apdu, size_t apdu_length, 144 se_io_cb_t cb, void *cb_context); 145 int st_nci_hci_load_session(struct nci_dev *ndev); 146 void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe, 147 u8 event, struct sk_buff *skb); 148 void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd, 149 struct sk_buff *skb); 150 151 int st_nci_vendor_cmds_init(struct nci_dev *ndev); 152 153 #endif /* __LOCAL_ST_NCI_H_ */ 154