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 #pragma once
18 
19 #include <phNxpNciHal_ext.h>
20 
21 #include <vector>
22 
23 #include "phNfcStatus.h"
24 
25 #define AUTONOMOUS_SCREEN_OFF_LOCK_MASK 0x20
26 #define SWITCH_OFF_MASK 0x02
27 #define NCI_GET_CONFI_MIN_LEN 0x04
28 #define NXP_MAX_RETRY_COUNT 0x03
29 typedef struct {
30   uint8_t autonomous_mode;
31   uint8_t guard_timer_value;
32 } nxp_nfc_config_ext_t;
33 extern nxp_nfc_config_ext_t config_ext;
34 
35 /*
36  * Add needed GPIO status to read into two bits each
37  * INVALID(-2)
38  * GPIO_SET(1)
39  * GPIO_RESET(0)
40  */
41 typedef struct {
42   int irq : 2;
43   int ven : 2;
44   int fw_dwl : 2;
45 } platform_gpios_t;
46 
47 /*
48  * platform_gpios_status --> decoded gpio status flag bits
49  * gpios_status_data    -->  encoded gpio status flag bytes
50  */
51 union {
52   uint32_t gpios_status_data;
53   platform_gpios_t platform_gpios_status;
54 } gpios_data;
55 
56 /*******************************************************************************
57 **
58 ** Function         phNxpNciHal_getExtVendorConfig()
59 **
60 ** Description      this function gets and updates the extension params
61 **
62 *******************************************************************************/
63 void phNxpNciHal_getExtVendorConfig();
64 
65 /******************************************************************************
66  * Function         phNxpNciHal_updateAutonomousPwrState
67  *
68  * Description      This function can be used to update autonomous pwr state.
69  *                  num: value to check  switch off bit is set or not.
70  *
71  * Returns          uint8_t
72  *
73  ******************************************************************************/
74 uint8_t phNxpNciHal_updateAutonomousPwrState(uint8_t num);
75 /******************************************************************************
76  * Function         phNxpNciHal_setAutonomousMode
77  *
78  * Description      This function can be used to set NFCC in autonomous mode
79  *
80  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
81  *
82  ******************************************************************************/
83 NFCSTATUS phNxpNciHal_setAutonomousMode();
84 
85 /******************************************************************************
86  * Function         phNxpNciHal_setGuardTimer
87  *
88  * Description      This function can be used to set Guard timer
89  *
90  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
91  *
92  ******************************************************************************/
93 NFCSTATUS phNxpNciHal_setGuardTimer();
94 
95 /*****************************************************************************
96  * Function         phNxpNciHal_send_get_cfg
97  *
98  * Description      This function is called to get the configurations from
99  * EEPROM
100  *
101  * Params           cmd_get_cfg, Buffer to GET command
102  *                  cmd_len,     Length of the command
103  * Returns          SUCCESS/FAILURE
104  *
105  *
106  *****************************************************************************/
107 NFCSTATUS phNxpNciHal_send_get_cfg(const uint8_t* cmd_get_cfg, long cmd_len);
108 
109 /*****************************************************************************
110  * Function         phNxpNciHal_configure_merge_sak
111  *
112  * Description      This function is called to apply iso_dep sak merge settings
113  *                  as per the config option NAME_NXP_ISO_DEP_MERGE_SAK
114  *
115  * Params           None
116 
117  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
118  *
119  *****************************************************************************/
120 NFCSTATUS phNxpNciHal_configure_merge_sak();
121 /******************************************************************************
122  * Function         phNxpNciHal_setSrdtimeout
123  *
124  * Description      This function can be used to set srd SRD Timeout.
125  *
126  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS or
127  *                  NFCSTATUS_FEATURE_NOT_SUPPORTED
128  *
129  ******************************************************************************/
130 NFCSTATUS phNxpNciHal_setSrdtimeout();
131 /******************************************************************************
132  * Function         phNxpNciHal_set_uicc_hci_params
133  *
134  * Description      This will update value of uicc session status to store flag
135  *                  to eeprom
136  *
137  * Parameters       value - this value will be updated to eeprom flag.
138  *
139  * Returns          status of the write
140  *
141  ******************************************************************************/
142 NFCSTATUS
143 phNxpNciHal_set_uicc_hci_params(vector<uint8_t>& ptr, uint8_t bufflen,
144                                 phNxpNci_EEPROM_request_type_t uiccType);
145 /******************************************************************************
146  * Function         phNxpNciHal_get_uicc_hci_params
147  *
148  * Description      This will read the value of fw download status flag
149  *                  from eeprom
150  *
151  * Parameters       value - this parameter will be updated with the flag
152  *                  value from eeprom.
153  *
154  * Returns          status of the read
155  *
156  ******************************************************************************/
157 NFCSTATUS
158 phNxpNciHal_get_uicc_hci_params(vector<uint8_t>& ptr, uint8_t bufflen,
159                                 phNxpNci_EEPROM_request_type_t uiccType);
160 
161 /******************************************************************************
162  * Function         phNxpNciHal_setExtendedFieldMode
163  *
164  * Description      This function can be used to set nfcc extended field mode
165  *
166  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS or
167  *                  NFCSTATUS_FEATURE_NOT_SUPPORTED
168  *
169  ******************************************************************************/
170 NFCSTATUS phNxpNciHal_setExtendedFieldMode();
171 
172 /*******************************************************************************
173 **
174 ** Function         phNxpNciHal_configGPIOControl()
175 **
176 ** Description      Helper function to configure GPIO control
177 **
178 ** Parameters       gpioControl - Byte array with first two bytes are used to
179 **                  configure gpio for specific functionality (ex:ULPDET,
180 **                  GPIO LEVEL ...) and 3rd byte indicates the level of GPIO
181 **                  to be set.
182 **                  len        - Len of byte array
183 **
184 ** Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
185 *******************************************************************************/
186 NFCSTATUS phNxpNciHal_configGPIOControl(uint8_t gpioControl[], uint8_t len);
187 
188 /*******************************************************************************
189 **
190 ** Function         phNxpNciHal_decodeGpioStatus()
191 **
192 ** Description      this function decodes gpios status of the nfc pins
193 **
194 *******************************************************************************/
195 void phNxpNciHal_decodeGpioStatus(void);
196 
197 /******************************************************************************
198  **
199  ** Function         phNxpNciHal_setDCDCConfig()
200  **
201  ** Description      Sets DCDC On/Off
202  **
203  *****************************************************************************/
204 void phNxpNciHal_setDCDCConfig(void);
205 
206 /*******************************************************************************
207 **
208 ** Function         phNxpNciHal_isVendorSpecificCommand()
209 **
210 ** Description      this function checks vendor specific command or not
211 **
212 ** Returns          true if the command is vendor specific otherwise false
213 *******************************************************************************/
214 bool phNxpNciHal_isVendorSpecificCommand(uint16_t data_len,
215                                          const uint8_t* p_data);
216 
217 /*******************************************************************************
218 **
219 ** Function         phNxpNciHal_handleVendorSpecificCommand()
220 **
221 ** Description      This handles the vendor specific command
222 **
223 ** Returns          It returns number of bytes received.
224 *******************************************************************************/
225 int phNxpNciHal_handleVendorSpecificCommand(uint16_t data_len,
226                                             const uint8_t* p_data);
227 
228 /*******************************************************************************
229 **
230 ** Function         phNxpNciHal_vendorSpecificCallback()
231 **
232 ** Params           oid, opcode, data
233 ** Description      This function sends response to Vendor Specific commands
234 **
235 *******************************************************************************/
236 void phNxpNciHal_vendorSpecificCallback(int oid, int opcode,
237                                         vector<uint8_t> data);
238 
239 /*******************************************************************************
240 **
241 ** Function         phNxpNciHal_isObserveModeSupported()
242 **
243 ** Description      check's the observe mode supported or not based on the
244 **                  config value
245 **
246 ** Returns          bool: true if supported, otherwise false
247 *******************************************************************************/
248 bool phNxpNciHal_isObserveModeSupported();
249