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