1 /* 2 * Copyright 2019-2024 NXP 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <hardware/nfc.h> 18 19 #include "phNfcStatus.h" 20 #include "phNxpConfig.h" 21 #include "phNxpLog.h" 22 23 #define NCI_PACKET_LEN_INDEX 2 24 #define NCI_PACKET_TLV_INDEX 3 25 /*Below are NCI get config response index values for each RF register*/ 26 #define DLMA_ID_TX_ENTRY_INDEX 12 27 #define RF_CM_TX_UNDERSHOOT_INDEX 5 28 #define PHONEOFF_TECH_DISABLE_INDEX 8 29 #define ISO_DEP_MERGE_SAK_INDEX 8 30 #define INITIAL_TX_PHASE_INDEX 8 31 #define LPDET_THRESHOLD_INDEX 11 32 #define NFCLD_THRESHOLD_INDEX 13 33 #define RF_PATTERN_CHK_INDEX 8 34 #define GUARD_TIMEOUT_TX2RX_INDEX 8 35 #define REG_A085_DATA_INDEX 8 36 37 /*Below are A085 RF register bitpostions*/ 38 #define CN_TRANSIT_BLK_NUM_CHECK_ENABLE_BIT_POS 6 39 #define MIFARE_NACK_TO_RATS_ENABLE_BIT_POS 13 40 #define MIFARE_MUTE_TO_RATS_ENABLE_BIT_POS 9 41 #define CN_TRANSIT_CMA_BYPASSMODE_ENABLE_BIT_POS 23 42 #define CHINA_TIANJIN_RF_ENABLE_BIT_POS 28 43 44 #define NCI_GET_CMD_TLV_INDEX1 4 45 #define NCI_GET_CMD_TLV_INDEX2 5 46 #define NCI_GET_RES_STATUS_INDEX 3 47 #define NCI_GET_RES_TLV_INDEX 4 48 49 #define BYTE0_SHIFT_MASK 0x000000FF 50 #define BYTE1_SHIFT_MASK 0x0000FF00 51 #define BYTE2_SHIFT_MASK 0x00FF0000 52 #define BYTE3_SHIFT_MASK 0xFF000000 53 54 /****************************************************************************** 55 ** Function phNxpNciHal_ioctlIf 56 ** 57 ** Description This function shall be called from HAL when libnfc-nci 58 ** calls phNxpNciHal_ioctl() to perform any IOCTL operation 59 ** 60 ** Returns return 0 on success and -1 on fail, 61 ******************************************************************************/ 62 int phNxpNciHal_ioctlIf(long arg, void* p_data); 63 64 /******************************************************************************* 65 ** 66 ** Function phNxpNciHal_getSystemProperty 67 ** 68 ** Description It shall be used to get property value of the given Key 69 ** 70 ** Parameters string key 71 ** 72 ** Returns It returns the property value of the key 73 *******************************************************************************/ 74 string phNxpNciHal_getSystemProperty(string key); 75 76 /******************************************************************************* 77 ** 78 ** Function phNxpNciHal_setSystemProperty 79 ** 80 ** Description It shall be used to save/chage value to system property 81 ** based on provided key. 82 ** 83 ** Parameters string key, string value 84 ** 85 ** Returns true if success, false if fail 86 *******************************************************************************/ 87 bool phNxpNciHal_setSystemProperty(string key, string value); 88 89 /******************************************************************************* 90 ** 91 ** Function phNxpNciHal_getNxpConfig 92 ** 93 ** Description It shall be used to read config values from the 94 *libnfc-nxp.conf 95 ** 96 ** Parameters nxpConfigs config 97 ** 98 ** Returns void 99 *******************************************************************************/ 100 string phNxpNciHal_getNxpConfigIf(); 101 102 /******************************************************************************* 103 ** 104 ** Function phNxpNciHal_resetEse 105 ** 106 ** Description It shall be used to to reset eSE by proprietary command. 107 ** 108 ** Parameters None 109 ** 110 ** Returns status of eSE reset response 111 *******************************************************************************/ 112 NFCSTATUS phNxpNciHal_resetEse(uint64_t resetType); 113 114 /****************************************************************************** 115 ** Function phNxpNciHal_setNxpTransitConfig 116 ** 117 ** Description This function overwrite libnfc-nxpTransit.conf file 118 ** with transitConfValue. 119 ** 120 ** Returns bool. 121 ** 122 *******************************************************************************/ 123 bool phNxpNciHal_setNxpTransitConfig(char* transitConfValue); 124 125 /******************************************************************************* 126 ** 127 ** Function: phNxpNciHal_CheckFwRegFlashRequired() 128 ** 129 ** Description: Updates FW and Reg configurations if required 130 ** 131 ** Returns: status 132 ** 133 ********************************************************************************/ 134 int phNxpNciHal_CheckFwRegFlashRequired(uint8_t* fw_update_req, 135 uint8_t* rf_update_req, 136 uint8_t skipEEPROMRead); 137 138 /****************************************************************************** 139 * Function phNxpNciHal_txNfccClockSetCmd 140 * 141 * Description This function is called after successful download 142 * to apply the clock setting provided in config file 143 * 144 * Returns void. 145 * 146 ******************************************************************************/ 147 void phNxpNciHal_txNfccClockSetCmd(void); 148 149 /******************************************************************************* 150 ** 151 ** Function: property_get_intf() 152 ** 153 ** Description: Gets property value for the input property name 154 ** 155 ** Parameters propName: Name of the property whichs value need to get 156 ** valueStr: output value of the property. 157 ** defaultStr: default value of the property if value is not 158 ** there this will be set to output value. 159 ** 160 ** Returns: actual length of the property value 161 ** 162 ********************************************************************************/ 163 int property_get_intf(const char* propName, char* valueStr, 164 const char* defaultStr); 165 166 /******************************************************************************* 167 ** 168 ** Function: property_set_intf() 169 ** 170 ** Description: Sets property value for the input property name 171 ** 172 ** Parameters propName: Name of the property whichs value need to set 173 ** valueStr: value of the property. 174 ** 175 ** Returns: returns 0 on success, < 0 on failure 176 ** 177 ********************************************************************************/ 178 int property_set_intf(const char* propName, const char* valueStr); 179 180 /******************************************************************************* 181 ** 182 ** Function: phNxpNciHal_GetNfcGpiosStatus() 183 ** 184 ** Description: Sets the gpios status flag byte 185 ** 186 ** Parameters gpiostatus: flag byte 187 ** 188 ** Returns: returns 0 on success, < 0 on failure 189 ** 190 ********************************************************************************/ 191 NFCSTATUS phNxpNciHal_GetNfcGpiosStatus(uint32_t* gpiosstatus); 192 193 /******************************************************************************* 194 ** 195 ** Function: phNxpNciHal_Abort() 196 ** 197 ** Description: This function shall be used to trigger the abort 198 ** 199 ** Parameters None 200 ** 201 ** Returns: returns 0 on success, < 0 on failure 202 ** 203 ********************************************************************************/ 204 bool phNxpNciHal_Abort(); 205 206 #undef PROPERTY_VALUE_MAX 207 #define PROPERTY_VALUE_MAX 92 208 #define property_get(a, b, c) property_get_intf(a, b, c) 209 #define property_set(a, b) property_set_intf(a, b) 210