1 /******************************************************************************
2  *
3  *  Copyright 2020-2021 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 #pragma once
19 
20 /* Basic type definitions */
21 #include <phNxpEsePal.h>
22 
23 /*!
24  * \brief Start of frame marker
25  */
26 #define SEND_PACKET_SOF 0x5A
27 /*!
28  * \brief ESE Poll timeout (max 2 seconds)
29  */
30 #define ESE_POLL_TIMEOUT (2 * 1000)
31 /*!
32  * \brief ESE Max Poll retry count
33  */
34 
35 #define ESE_NAD_POLLING_MAX (2000)
36 
37 /*!
38  * \brief ESE wakeup delay in case of write error retry
39  */
40 
41 #define WAKE_UP_DELAY_USECS 100
42 
43 #define GET_WAKE_UP_DELAY()                                          \
44   ((GET_CHIP_OS_VERSION() != OS_VERSION_4_0) ? (WAKE_UP_DELAY_USECS) \
45                                              : (10 * WAKE_UP_DELAY_USECS))
46 
47 /*!
48  * \brief ESE wakeup delay in case of write error retry
49  */
50 
51 #define NAD_POLLING_SCALER 1
52 
53 /*!
54  * \brief ESE wakeup delay in case of write error retry
55  */
56 #define CHAINED_PKT_SCALER 1
57 /*!
58  * \brief Magic type specific to the ESE device driver
59  */
60 #define P61_MAGIC 0xEA
61 
62 /*!
63  * \brief IOCTL number to set ESE PWR
64  */
65 #define P61_SET_PWR _IOW(P61_MAGIC, 0x01, long)
66 /*!
67  * \brief IOCTL number to set debug state
68  */
69 #define P61_SET_DBG _IOW(P61_MAGIC, 0x02, long)
70 /*!
71  * \brief IOCTL number to enable poll mode
72  */
73 #define P61_SET_POLL _IOW(P61_MAGIC, 0x03, long)
74 /*!
75  * \brief SPI Request NFCC to enable p61 power, only in param
76  *         Only for SPI
77  *         level 1 = Enable power
78  *         level 0 = Disable power
79  */
80 #define P61_SET_SPM_PWR _IOW(P61_MAGIC, 0x04, long)
81 
82 /*!
83  * \brief SPI or DWP can call this ioctl to get the current
84  *         power state of P61
85  *
86  */
87 #define P61_GET_SPM_STATUS _IOR(P61_MAGIC, 0x05, long)
88 /*!
89  * \brief IOCTL to add throughput measurement source code in device driver
90  *
91  */
92 #define P61_SET_THROUGHPUT _IOW(P61_MAGIC, 0x06, long)
93 /*!
94  * \brief IOCTL to get the ESE access
95  *
96  */
97 #define P61_GET_ESE_ACCESS _IOW(P61_MAGIC, 0x07, long)
98 /*!
99  * \brief IOCTL to set the power scheme
100  *
101  */
102 #define P61_SET_POWER_SCHEME _IOW(P61_MAGIC, 0x08, long)
103 /*!
104  * \brief This function is used to set the ESE jcop
105  *  download state.
106  */
107 #define P61_SET_DWNLD_STATUS _IOW(P61_MAGIC, 0x09, long)
108 
109 /*!
110  * \brief This function is used to set disable ESE GPIO
111  *  state On&Off
112  */
113 #define P61_INHIBIT_PWR_CNTRL _IOW(P61_MAGIC, 0x0A, long)
114 /*!
115  * \brief IOCTL to set the GPIO for the eSE to distinguish
116  *        the logical interface
117  */
118 #define ESE_SET_TRUSTED_ACCESS _IOW(P61_MAGIC, 0x0B, long)
119 
120 /*!
121  * \brief IOCTL to perform the eSE COLD_RESET  via NFC driver.
122  */
123 #define ESE_PERFORM_COLD_RESET _IOW(P61_MAGIC, 0x0C, long)
124 /*!
125  * \brief IOCTL to enable/disable GPIO/COLD reset protection.
126  */
127 #define PERFORM_RESET_PROTECTION _IOW(P61_MAGIC, 0x0D, long)
128 
129 class EseTransport {
130  public:
131   virtual void Close(void* pDevHandle) = 0;
132   virtual ESESTATUS OpenAndConfigure(pphPalEse_Config_t pConfig) = 0;
133   virtual int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead) = 0;
134   virtual int Write(void* pDevHandle, uint8_t* pBuffer,
135                     int nNbBytesToWrite) = 0;
136   virtual ESESTATUS Ioctl(phPalEse_ControlCode_t eControlCode, void* pDevHandle,
137                           long level) = 0;
~EseTransport()138   virtual ~EseTransport(){};
139 };
140