• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2018-2019 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 <phNxpEse_Api.h>
22 
23 /* Macro to enable SPM Module */
24 #define SPM_INTEGRATED
25 //#undef SPM_INTEGRATED
26 #ifdef SPM_INTEGRATED
27 #include "../spm/phNxpEse_Spm.h"
28 #endif
29 
30 /********************* Definitions and structures *****************************/
31 
32 typedef enum {
33   ESE_STATUS_CLOSE = 0x00,
34   ESE_STATUS_BUSY,
35   ESE_STATUS_RECOVERY,
36   ESE_STATUS_IDLE,
37   ESE_STATUS_OPEN,
38 } phNxpEse_LibStatus;
39 
40 typedef enum {
41   PN67T_POWER_SCHEME = 0x01,
42   PN80T_LEGACY_SCHEME,
43   PN80T_EXT_PMU_SCHEME,
44 } phNxpEse_PowerScheme;
45 
46 typedef enum {
47   END_POINT_ESE = 0, /*!< eSE services */
48   END_POINT_EUICC,   /*!< UICC services*/
49   MAX_END_POINTS
50 } phNxpEse_EndPoint;
51 
52 /* Macros definition */
53 #define MAX_DATA_LEN 780
54 #define SECOND_TO_MILLISECOND(X) X * 1000
55 #define CONVERT_TO_PERCENTAGE(X, Y) X* Y / 100
56 #define ADDITIONAL_SECURE_TIME_PERCENTAGE 5
57 #define ESE_JCOP_OS_DWNLD_RETRY_CNT \
58   10 /* Maximum retry count for ESE JCOP OS Dwonload*/
59 #define ESE_FW_DWNLD_RETRY_CNT 10 /* Maximum retry count for FW Dwonload*/
60 
61 /*!
62  * \brief  Secure timer values F1, F2, F3
63  *
64  *
65  */
66 typedef struct phNxpEse_SecureTimer {
67   unsigned int secureTimer1; /*!< Secure timer 1 value */
68   unsigned int secureTimer2; /*!< Secure timer 2 value */
69   unsigned int secureTimer3; /*!< Secure timer 3 value */
70 } phNxpEse_SecureTimer_t;
71 
72 typedef enum nadInfoTx {
73   ESE_NAD_TX = 0x5A,  /*!< R-frame Acknowledgement frame indicator */
74   EUICC_NAD_TX = 0x4B /*!< R-frame Negative-Acknowledgement frame indicator */
75 } nadInfoTx_t;
76 
77 /*!
78  * \brief R-Frame types used in 7816-3 protocol stack
79  */
80 typedef enum nadInfoRx {
81   ESE_NAD_RX = 0xA5,  /*!< R-frame Acknowledgement frame indicator */
82   EUICC_NAD_RX = 0xB4 /*!< R-frame Negative-Acknowledgement frame indicator */
83 } nadInfoRx_t;
84 
85 /*!
86  * \brief  Node address Info structure
87  *
88  *
89  */
90 typedef struct phNxpEseNadInfo {
91   nadInfoTx_t nadTx; /*!< nod address for tx */
92   nadInfoRx_t nadRx; /*!< nod address for rx */
93 } phNxpEseNadInfo_t;
94 
95 /* JCOP download states */
96 typedef enum jcop_dwnld_state {
97   JCP_DWNLD_IDLE = SPM_STATE_JCOP_DWNLD, /* jcop dwnld is not ongoing*/
98   JCP_DWNLD_INIT = 0x8010,               /* jcop dwonload init state*/
99   JCP_DWNLD_START = 0x8020,              /* download started */
100   JCP_SPI_DWNLD_COMPLETE = 0x8040, /* jcop download complete in spi interface*/
101   JCP_DWP_DWNLD_COMPLETE = 0x8080, /* jcop download complete */
102 } phNxpEse_JcopDwnldState;
103 
104 /*!
105  * \brief  SPI Control structure
106  *
107  *
108  */
109 typedef struct phNxpEse_Context {
110   void* pDevHandle;                /*!<device handle */
111   long nadPollingRetryTime;        /*!<polling retry for nod address */
112   long invalidFrame_Rnack_Delay;   /*!<delay before retrying when rnack is
113                                       received */
114   phNxpEse_LibStatus EseLibStatus; /*!<Indicate if Ese Lib is open or closed */
115   phNxpEse_initParams initParams;  /*!<init params */
116   phNxpEse_SecureTimer_t secureTimerParams; /*!<secure timer params */
117   phNxpEseNadInfo_t nadInfo;                /*!<nad info */
118   uint8_t p_read_buff[MAX_DATA_LEN];        /*!<read buffer */
119   uint8_t p_cmd_data[MAX_DATA_LEN];         /*!<cmd  buffer */
120   uint16_t cmd_len;                         /*!<cmd buffer length */
121   uint8_t pwr_scheme;                       /*!<eSE power scheme */
122   uint8_t endPointInfo;                     /*!<info end point*/
123   bool rnack_sent;                          /*!<rnack send info */
124   bool spm_power_state;                     /*!<spm_power_state */
125   NotifyWtxReq* fPtr_WtxNtf; /*!< Wait extension callback notification*/
126 } phNxpEse_Context_t;
127 
128 /* Timeout value to wait for response from
129    Note: Timeout value updated from 1000 to 2000 to fix the JCOP delay (WTX)*/
130 #define HAL_EXTNS_WRITE_RSP_TIMEOUT (2000)
131 
132 #define SPILIB_CMD_CODE_LEN_BYTE_OFFSET (2U)
133 #define SPILIB_CMD_CODE_BYTE_LEN (3U)
134 
135 static nadInfoTx_t nadInfoTx_ptr[MAX_END_POINTS] = {ESE_NAD_TX, EUICC_NAD_TX};
136 
137 static nadInfoRx_t nadInfoRx_ptr[MAX_END_POINTS] = {ESE_NAD_RX, EUICC_NAD_RX};
138 ESESTATUS phNxpEse_WriteFrame(uint32_t data_len, uint8_t* p_data);
139 ESESTATUS phNxpEse_read(uint32_t* data_len, uint8_t** pp_data);
140 void phNxpEse_setOsVersion(phNxpEse_OsVersion_t chipType);
141 
142 #endif /* _PHNXPSPILIB_H_ */
143