1 /****************************************************************************** 2 * 3 * Copyright 2018 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 #ifndef _PHNXPSPILIB_H_ 19 #define _PHNXPSPILIB_H_ 20 21 #include <phNxpEseFeatures.h> 22 #include <phNxpEse_Api.h> 23 24 /* Macro to enable SPM Module */ 25 #define SPM_INTEGRATED 26 //#undef SPM_INTEGRATED 27 #ifdef SPM_INTEGRATED 28 #include "../spm/phNxpEse_Spm.h" 29 #endif 30 31 /********************* Definitions and structures *****************************/ 32 33 typedef enum { 34 ESE_STATUS_CLOSE = 0x00, 35 ESE_STATUS_BUSY, 36 ESE_STATUS_RECOVERY, 37 ESE_STATUS_IDLE, 38 ESE_STATUS_OPEN, 39 } phNxpEse_LibStatus; 40 41 typedef enum { 42 PN67T_POWER_SCHEME = 0x01, 43 PN80T_LEGACY_SCHEME, 44 PN80T_EXT_PMU_SCHEME, 45 } phNxpEse_PowerScheme; 46 47 /* Macros definition */ 48 #define MAX_DATA_LEN 260 49 #define SECOND_TO_MILLISECOND(X) X * 1000 50 #define CONVERT_TO_PERCENTAGE(X, Y) X* Y / 100 51 #define ADDITIONAL_SECURE_TIME_PERCENTAGE 5 52 #ifdef NXP_ESE_JCOP_DWNLD_PROTECTION 53 #define ESE_JCOP_OS_DWNLD_RETRY_CNT \ 54 10 /* Maximum retry count for ESE JCOP OS Dwonload*/ 55 #endif 56 #ifdef NXP_NFCC_SPI_FW_DOWNLOAD_SYNC 57 #define ESE_FW_DWNLD_RETRY_CNT 10 /* Maximum retry count for FW Dwonload*/ 58 #endif 59 60 /* Secure timer values F1, F2, F3 */ 61 typedef struct phNxpEse_SecureTimer { 62 unsigned int secureTimer1; 63 unsigned int secureTimer2; 64 unsigned int secureTimer3; 65 } phNxpEse_SecureTimer_t; 66 67 /* JCOP download states */ 68 typedef enum jcop_dwnld_state { 69 #ifdef NXP_ESE_JCOP_DWNLD_PROTECTION 70 JCP_DWNLD_IDLE = SPM_STATE_JCOP_DWNLD, /* jcop dwnld is not ongoing*/ 71 #endif 72 JCP_DWNLD_INIT = 0x8010, /* jcop dwonload init state*/ 73 JCP_DWNLD_START = 0x8020, /* download started */ 74 JCP_SPI_DWNLD_COMPLETE = 0x8040, /* jcop download complete in spi interface*/ 75 JCP_DWP_DWNLD_COMPLETE = 0x8080, /* jcop download complete */ 76 } phNxpEse_JcopDwnldState; 77 78 /* SPI Control structure */ 79 typedef struct phNxpEse_Context { 80 phNxpEse_LibStatus EseLibStatus; /* Indicate if Ese Lib is open or closed */ 81 void* pDevHandle; 82 83 uint8_t p_read_buff[MAX_DATA_LEN]; 84 uint16_t cmd_len; 85 uint8_t p_cmd_data[MAX_DATA_LEN]; 86 87 bool spm_power_state; 88 uint8_t pwr_scheme; 89 phNxpEse_initParams initParams; 90 phNxpEse_SecureTimer_t secureTimerParams; 91 } phNxpEse_Context_t; 92 93 ESESTATUS phNxpEse_WriteFrame(uint32_t data_len, const uint8_t* p_data); 94 ESESTATUS phNxpEse_read(uint32_t* data_len, uint8_t** pp_data); 95 96 #endif /* _PHNXPSPILIB_H_ */ 97