1 /****************************************************************************** 2 * 3 * Copyright 2022,2023 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #include <stdint.h> 20 21 #include <string> 22 #ifndef NXP_FEATURES_H 23 #define NXP_FEATURES_H 24 25 #define STRMAX_2 100 26 27 /*FW ROM CODE VERSION*/ 28 #define FW_MOBILE_ROM_VERSION_PN551 0x10 29 #define FW_MOBILE_ROM_VERSION_PN553 0x11 30 #define FW_MOBILE_ROM_VERSION_PN557 0x12 31 #define FW_MOBILE_ROM_VERSION_SN100U 0x01 32 #define FW_MOBILE_ROM_VERSION_SN220U 0x01 33 #define FW_MOBILE_ROM_VERSION_SN300U 0x02 34 35 /*FW Major VERSION Code*/ 36 #define FW_MOBILE_MAJOR_NUMBER_PN553 0x01 37 #define FW_MOBILE_MAJOR_NUMBER_PN551 0x05 38 #define FW_MOBILE_MAJOR_NUMBER_PN48AD 0x01 39 #define FW_MOBILE_MAJOR_NUMBER_PN81A 0x02 40 #define FW_MOBILE_MAJOR_NUMBER_PN557 0x01 41 #define FW_MOBILE_MAJOR_NUMBER_PN557_V2 0x21 42 #define FW_MOBILE_MAJOR_NUMBER_SN100U 0x010 43 #define FW_MOBILE_MAJOR_NUMBER_SN220U 0x01 44 #define FW_MOBILE_MAJOR_NUMBER_SN300U 0x20 45 46 #define NCI_CMD_RSP_SUCCESS_SW1 0x60 47 #define NCI_CMD_RSP_SUCCESS_SW2 0x00 48 #define FW_DL_RSP_FIRST_BYTE 0x00 49 50 /* Supported EE */ 51 #define EE_T4T_SUPPORTED 1 52 #define EE_UICC1_SUPPORTED 1 53 #define EE_UICC2_SUPPORTED 1 54 #define EE_UICC3_SUPPORTED 1 55 #define EE_ESE_SUPPORTED 1 56 #define EE_EUICC1_SUPPORTED 1 57 #define EE_EUICC2_SUPPORTED 1 58 59 #define JCOP_VER_3_3 3 60 #define JCOP_VER_4_0 4 61 #ifndef FW_LIB_ROOT_DIR 62 #if (defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)) 63 #define FW_LIB_ROOT_DIR "/vendor/lib64/" 64 #else 65 #define FW_LIB_ROOT_DIR "/vendor/lib/" 66 #endif 67 #endif 68 #ifndef FW_BIN_ROOT_DIR 69 #define FW_BIN_ROOT_DIR "/vendor/firmware/" 70 #endif 71 #ifndef FW_LIB_EXTENSION 72 #define FW_LIB_EXTENSION ".so" 73 #endif 74 #ifndef FW_BIN_EXTENSION 75 #define FW_BIN_EXTENSION ".bin" 76 #endif 77 using namespace std; 78 typedef enum { 79 NFCC_DWNLD_WITH_VEN_RESET, 80 NFCC_DWNLD_WITH_NCI_CMD 81 } tNFCC_DnldType; 82 83 typedef enum { 84 HW_PN553_A0 = 0x40, 85 HW_PN553_B0 = 0x41, 86 HW_PN80T_A0 = 0x50, 87 HW_PN80T_B0 = 0x51, // PN553 B0 + P73 88 HW_PN551 = 0x98, 89 HW_PN67T_A0 = 0xA8, 90 HW_PN67T_B0 = 0x08, 91 HW_PN548C2_A0 = 0x28, 92 HW_PN548C2_B0 = 0x48, 93 HW_PN66T_A0 = 0x18, 94 HW_PN66T_B0 = 0x58, 95 HW_SN100U_A0 = 0xA0, 96 HW_SN100U_A2 = 0xA2, 97 HW_PN560_V1 = 0xCA, 98 HW_PN560_V2 = 0xCB, 99 HW_SN300U = 0xD3 100 } tNFC_HWVersion; 101 102 typedef enum { 103 DEFAULT_CHIP_TYPE = 0x00, 104 pn547C2 = 0x01, 105 pn65T, 106 pn548C2, 107 pn66T, 108 pn551, 109 pn67T, 110 pn553, 111 pn80T, 112 pn557, 113 pn81T, 114 sn100u, 115 sn220u, 116 pn560, 117 sn300u 118 } tNFC_chipType; 119 120 typedef struct { 121 /*Flags common to all chip types*/ 122 uint8_t _NFCC_I2C_READ_WRITE_IMPROVEMENT : 1; 123 uint8_t _NFCC_MIFARE_TIANJIN : 1; 124 uint8_t _NFCC_SPI_FW_DOWNLOAD_SYNC : 1; 125 uint8_t _NFCEE_REMOVED_NTF_RECOVERY : 1; 126 uint8_t _NFCC_FORCE_FW_DOWNLOAD : 1; 127 uint8_t _NFA_EE_MAX_EE_SUPPORTED : 3; 128 uint8_t _NFCC_DWNLD_MODE : 1; 129 } tNfc_nfccFeatureList; 130 131 typedef struct { 132 uint8_t nfcNxpEse : 1; 133 tNFC_chipType chipType; 134 std::string _FW_LIB_PATH; 135 std::string _FW_BIN_PATH; 136 uint16_t _PHDNLDNFC_USERDATA_EEPROM_OFFSET; 137 uint16_t _PHDNLDNFC_USERDATA_EEPROM_LEN; 138 uint8_t _FW_MOBILE_MAJOR_NUMBER; 139 tNfc_nfccFeatureList nfccFL; 140 } tNfc_featureList; 141 142 extern tNfc_featureList nfcFL; 143 #define GET_FW_ROM_VERSION_NCI_RESP(msg, msg_len) (msg[msg_len - 3]) 144 #define GET_FW_MAJOR_VERSION_NCI_RESP(msg, msg_len) (msg[msg_len - 2]) 145 #define GET_HW_VERSION_NCI_RESP(msg, msg_len) (msg[msg_len - 4]) 146 #define IS_CHIP_TYPE_GE(cType) (nfcFL.chipType >= cType) 147 #define IS_CHIP_TYPE_EQ(cType) (nfcFL.chipType == cType) 148 #define IS_CHIP_TYPE_LE(cType) (nfcFL.chipType <= cType) 149 #define IS_CHIP_TYPE_L(cType) (nfcFL.chipType < cType) 150 #define IS_CHIP_TYPE_NE(cType) (nfcFL.chipType != cType) 151 152 #define CONFIGURE_FEATURELIST(chipType) \ 153 { \ 154 nfcFL.chipType = chipType; \ 155 switch (chipType) { \ 156 case pn81T: \ 157 nfcFL.chipType = pn557; \ 158 nfcFL.nfcNxpEse = true; \ 159 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 160 break; \ 161 case pn80T: \ 162 nfcFL.chipType = pn553; \ 163 nfcFL.nfcNxpEse = true; \ 164 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 165 break; \ 166 case pn67T: \ 167 nfcFL.chipType = pn551; \ 168 nfcFL.nfcNxpEse = true; \ 169 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 170 break; \ 171 case pn66T: \ 172 nfcFL.chipType = pn548C2; \ 173 nfcFL.nfcNxpEse = true; \ 174 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 175 break; \ 176 case pn65T: \ 177 nfcFL.chipType = pn547C2; \ 178 nfcFL.nfcNxpEse = true; \ 179 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 180 break; \ 181 case sn100u: \ 182 nfcFL.chipType = sn100u; \ 183 nfcFL.nfcNxpEse = true; \ 184 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 185 break; \ 186 case sn220u: \ 187 nfcFL.chipType = sn220u; \ 188 nfcFL.nfcNxpEse = true; \ 189 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 190 break; \ 191 case sn300u: \ 192 nfcFL.chipType = sn300u; \ 193 nfcFL.nfcNxpEse = true; \ 194 CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 195 break; \ 196 default: \ 197 nfcFL.nfcNxpEse = false; \ 198 CONFIGURE_FEATURELIST_NFCC(chipType) \ 199 } \ 200 } 201 202 #define CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ 203 { \ 204 switch (chipType) { \ 205 case pn81T: \ 206 CONFIGURE_FEATURELIST_NFCC(pn557) \ 207 nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = true; \ 208 nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = \ 209 EE_T4T_SUPPORTED + EE_UICC1_SUPPORTED + EE_UICC2_SUPPORTED + \ 210 EE_ESE_SUPPORTED; \ 211 break; \ 212 case sn100u: \ 213 CONFIGURE_FEATURELIST_NFCC(sn100u) \ 214 nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = true; \ 215 nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = \ 216 EE_T4T_SUPPORTED + EE_UICC1_SUPPORTED + EE_UICC2_SUPPORTED + \ 217 EE_UICC3_SUPPORTED + EE_ESE_SUPPORTED; \ 218 break; \ 219 case sn220u: \ 220 CONFIGURE_FEATURELIST_NFCC(sn220u) \ 221 nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = true; \ 222 nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = \ 223 EE_T4T_SUPPORTED + EE_UICC1_SUPPORTED + EE_UICC2_SUPPORTED + \ 224 EE_ESE_SUPPORTED; \ 225 break; \ 226 case sn300u: \ 227 CONFIGURE_FEATURELIST_NFCC(sn300u) \ 228 nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = true; \ 229 nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = \ 230 EE_T4T_SUPPORTED + EE_UICC1_SUPPORTED + EE_UICC2_SUPPORTED + \ 231 EE_ESE_SUPPORTED + EE_EUICC1_SUPPORTED + EE_EUICC2_SUPPORTED; \ 232 break; \ 233 default: \ 234 break; \ 235 } \ 236 } 237 238 #define CONFIGURE_FEATURELIST_NFCC(chipType) \ 239 { \ 240 nfcFL._PHDNLDNFC_USERDATA_EEPROM_OFFSET = 0x023CU; \ 241 nfcFL._PHDNLDNFC_USERDATA_EEPROM_LEN = 0x0C80U; \ 242 nfcFL._FW_MOBILE_MAJOR_NUMBER = FW_MOBILE_MAJOR_NUMBER_PN48AD; \ 243 nfcFL.nfccFL._NFCC_DWNLD_MODE = NFCC_DWNLD_WITH_VEN_RESET; \ 244 switch (chipType) { \ 245 case pn557: \ 246 nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ 247 STRCPY_FW("libpn557_fw") \ 248 STRCPY_FW_BIN("pn557") \ 249 break; \ 250 case sn100u: \ 251 nfcFL.nfccFL._NFCC_DWNLD_MODE = NFCC_DWNLD_WITH_NCI_CMD; \ 252 nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ 253 nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = false; \ 254 nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = true; \ 255 nfcFL._FW_MOBILE_MAJOR_NUMBER = FW_MOBILE_MAJOR_NUMBER_SN100U; \ 256 STRCPY_FW("libsn100u_fw") \ 257 STRCPY_FW_BIN("sn100u") \ 258 break; \ 259 case sn220u: \ 260 nfcFL.nfccFL._NFCC_DWNLD_MODE = NFCC_DWNLD_WITH_NCI_CMD; \ 261 nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ 262 nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = false; \ 263 nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = true; \ 264 nfcFL._FW_MOBILE_MAJOR_NUMBER = FW_MOBILE_MAJOR_NUMBER_SN220U; \ 265 STRCPY_FW("libsn220u_fw") \ 266 STRCPY_FW_BIN("sn220u") \ 267 break; \ 268 case pn560: \ 269 nfcFL.nfccFL._NFCC_DWNLD_MODE = NFCC_DWNLD_WITH_NCI_CMD; \ 270 nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ 271 nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = false; \ 272 nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = true; \ 273 nfcFL._FW_MOBILE_MAJOR_NUMBER = FW_MOBILE_MAJOR_NUMBER_SN220U; \ 274 STRCPY_FW("libpn560_fw") \ 275 STRCPY_FW_BIN("pn560") \ 276 break; \ 277 case sn300u: \ 278 nfcFL.nfccFL._NFCC_DWNLD_MODE = NFCC_DWNLD_WITH_NCI_CMD; \ 279 nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ 280 nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = false; \ 281 nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = true; \ 282 nfcFL._FW_MOBILE_MAJOR_NUMBER = FW_MOBILE_MAJOR_NUMBER_SN300U; \ 283 STRCPY_FW("libsn300u_fw") \ 284 STRCPY_FW_BIN("sn300u") \ 285 break; \ 286 default: \ 287 nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = true; \ 288 break; \ 289 } \ 290 } 291 292 #define STRCPY_FW_BIN(str) \ 293 { \ 294 nfcFL._FW_BIN_PATH.clear(); \ 295 nfcFL._FW_BIN_PATH.append(FW_BIN_ROOT_DIR); \ 296 nfcFL._FW_BIN_PATH.append(str); \ 297 nfcFL._FW_BIN_PATH.append(FW_BIN_EXTENSION); \ 298 } 299 #define STRCPY_FW(str1) \ 300 { \ 301 nfcFL._FW_LIB_PATH.clear(); \ 302 nfcFL._FW_LIB_PATH.append(FW_LIB_ROOT_DIR); \ 303 nfcFL._FW_LIB_PATH.append(str1); \ 304 nfcFL._FW_LIB_PATH.append(FW_LIB_EXTENSION); \ 305 } 306 #endif 307