• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019-2023 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 #include "phNxpNciHal_extOperations.h"
18 
19 #include <phNxpLog.h>
20 #include <phTmlNfc.h>
21 
22 #include "phNfcCommon.h"
23 #include "phNxpNciHal_IoctlOperations.h"
24 
25 #define NCI_HEADER_SIZE 3
26 #define NCI_SE_CMD_LEN 4
27 nxp_nfc_config_ext_t config_ext;
28 static vector<uint8_t> uicc1HciParams(0);
29 static vector<uint8_t> uicc2HciParams(0);
30 static vector<uint8_t> uiccHciCeParams(0);
31 extern phNxpNciHal_Control_t nxpncihal_ctrl;
32 extern NFCSTATUS phNxpNciHal_ext_send_sram_config_to_flash();
33 
34 /*******************************************************************************
35 **
36 ** Function         phNxpNciHal_getExtVendorConfig()
37 **
38 ** Description      this function gets and updates the extension params
39 **
40 *******************************************************************************/
phNxpNciHal_getExtVendorConfig()41 void phNxpNciHal_getExtVendorConfig() {
42   unsigned long num = 0;
43   memset(&config_ext, 0x00, sizeof(nxp_nfc_config_ext_t));
44 
45   if ((GetNxpNumValue(NAME_NXP_AUTONOMOUS_ENABLE, &num, sizeof(num)))) {
46     config_ext.autonomous_mode = (uint8_t)num;
47   }
48   if ((GetNxpNumValue(NAME_NXP_GUARD_TIMER_VALUE, &num, sizeof(num)))) {
49     config_ext.guard_timer_value = (uint8_t)num;
50   }
51 }
52 
53 /******************************************************************************
54  * Function         phNxpNciHal_updateAutonomousPwrState
55  *
56  * Description      This function can be used to update autonomous pwr state.
57  *                  num: value to check  switch off bit is set or not.
58  *
59  * Returns          uint8_t
60  *
61  ******************************************************************************/
phNxpNciHal_updateAutonomousPwrState(uint8_t num)62 uint8_t phNxpNciHal_updateAutonomousPwrState(uint8_t num) {
63   if ((config_ext.autonomous_mode == true) &&
64       ((num & SWITCH_OFF_MASK) == SWITCH_OFF_MASK)) {
65     num = (num | AUTONOMOUS_SCREEN_OFF_LOCK_MASK);
66   }
67   return num;
68 }
69 /******************************************************************************
70  * Function         phNxpNciHal_setAutonomousMode
71  *
72  * Description      This function can be used to set NFCC in autonomous mode
73  *
74  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
75  *                  or NFCSTATUS_FEATURE_NOT_SUPPORTED
76  *
77  ******************************************************************************/
phNxpNciHal_setAutonomousMode()78 NFCSTATUS phNxpNciHal_setAutonomousMode() {
79   if (IS_CHIP_TYPE_L(sn100u)) {
80     NXPLOG_NCIHAL_D("%s : Not applicable for chipType %d", __func__,
81                     nfcFL.chipType);
82     return NFCSTATUS_SUCCESS;
83   }
84   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
85   uint8_t autonomous_mode_value = 0x01;
86   if (config_ext.autonomous_mode == true) autonomous_mode_value = 0x02;
87 
88   mEEPROM_info.request_mode = SET_EEPROM_DATA;
89   mEEPROM_info.buffer = (uint8_t*)&autonomous_mode_value;
90   mEEPROM_info.bufflen = sizeof(autonomous_mode_value);
91   mEEPROM_info.request_type = EEPROM_AUTONOMOUS_MODE;
92 
93   return request_EEPROM(&mEEPROM_info);
94 }
95 /******************************************************************************
96  * Function         phNxpNciHal_setGuardTimer
97  *
98  * Description      This function can be used to set nfcc Guard timer
99  *
100  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
101  *
102  ******************************************************************************/
phNxpNciHal_setGuardTimer()103 NFCSTATUS phNxpNciHal_setGuardTimer() {
104   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
105   NFCSTATUS status = NFCSTATUS_FEATURE_NOT_SUPPORTED;
106 
107   if (IS_CHIP_TYPE_GE(sn100u)) {
108     if (config_ext.autonomous_mode != true) config_ext.guard_timer_value = 0x00;
109 
110     mEEPROM_info.request_mode = SET_EEPROM_DATA;
111     mEEPROM_info.buffer = &config_ext.guard_timer_value;
112     mEEPROM_info.bufflen = sizeof(config_ext.guard_timer_value);
113     mEEPROM_info.request_type = EEPROM_GUARD_TIMER;
114 
115     status = request_EEPROM(&mEEPROM_info);
116   }
117   return status;
118 }
119 
120 /******************************************************************************
121  * Function         get_system_property_se_type
122  *
123  * Description      This will read NFCEE status from system properties
124  *                  and returns status.
125  *
126  * Returns          NFCEE enabled(0x01)/disabled(0x00)
127  *
128  ******************************************************************************/
get_system_property_se_type(uint8_t se_type)129 static int8_t get_system_property_se_type(uint8_t se_type) {
130   int8_t retVal = -1;
131   char valueStr[PROPERTY_VALUE_MAX] = {0};
132   if (se_type >= NUM_SE_TYPES) return retVal;
133   int len = 0;
134   switch (se_type) {
135     case SE_TYPE_ESE:
136       len = property_get("nfc.product.support.ese", valueStr, "");
137       break;
138     case SE_TYPE_UICC:
139       len = property_get("nfc.product.support.uicc", valueStr, "");
140       break;
141     case SE_TYPE_UICC2:
142       len = property_get("nfc.product.support.uicc2", valueStr, "");
143       break;
144   }
145   if (strlen(valueStr) == 0 || len <= 0) {
146     return retVal;
147   }
148   retVal = atoi(valueStr);
149   return retVal;
150 }
151 
152 /******************************************************************************
153  * Function         phNxpNciHal_read_and_update_se_state
154  *
155  * Description      This will read NFCEE status from system properties
156  *                  and update to NFCC to enable/disable.
157  *
158  * Returns          none
159  *
160  ******************************************************************************/
phNxpNciHal_read_and_update_se_state()161 void phNxpNciHal_read_and_update_se_state() {
162   NFCSTATUS status = NFCSTATUS_FAILED;
163   int16_t i = 0;
164   int8_t val = -1;
165   int16_t num_se = 0;
166   uint8_t retry_cnt = 0;
167   int8_t values[NUM_SE_TYPES];
168 
169   for (i = 0; i < NUM_SE_TYPES; i++) {
170     val = get_system_property_se_type(i);
171     switch (i) {
172       case SE_TYPE_ESE:
173         NXPLOG_NCIHAL_D("Get property : SUPPORT_ESE %d", val);
174         values[SE_TYPE_ESE] = val;
175         if (val > -1) {
176           num_se++;
177         }
178         break;
179       case SE_TYPE_UICC:
180         NXPLOG_NCIHAL_D("Get property : SUPPORT_UICC %d", val);
181         values[SE_TYPE_UICC] = val;
182         if (val > -1) {
183           num_se++;
184         }
185         break;
186       case SE_TYPE_UICC2:
187         values[SE_TYPE_UICC2] = val;
188         if (val > -1) {
189           num_se++;
190         }
191         NXPLOG_NCIHAL_D("Get property : SUPPORT_UICC2 %d", val);
192         break;
193     }
194   }
195   if (num_se < 1) {
196     return;
197   }
198   uint8_t set_cfg_cmd[NCI_HEADER_SIZE + 1 +
199                       (num_se * NCI_SE_CMD_LEN)];  // 1 for Number of Argument
200   uint8_t* index = &set_cfg_cmd[0];
201   *index++ = NCI_MT_CMD;
202   *index++ = NXP_CORE_SET_CONFIG_CMD;
203   *index++ = (num_se * NCI_SE_CMD_LEN) + 1;
204   *index++ = num_se;
205   for (i = 0; i < NUM_SE_TYPES; i++) {
206     switch (i) {
207       case SE_TYPE_ESE:
208         if (values[SE_TYPE_ESE] > -1) {
209           *index++ = 0xA0;
210           *index++ = 0xED;
211           *index++ = 0x01;
212           *index++ = values[SE_TYPE_ESE];
213         }
214         break;
215       case SE_TYPE_UICC:
216         if (values[SE_TYPE_UICC] > -1) {
217           *index++ = 0xA0;
218           *index++ = 0xEC;
219           *index++ = 0x01;
220           *index++ = values[SE_TYPE_UICC];
221         }
222         break;
223       case SE_TYPE_UICC2:
224         if (values[SE_TYPE_UICC2] > -1) {
225           *index++ = 0xA0;
226           *index++ = 0xD4;
227           *index++ = 0x01;
228           *index++ = values[SE_TYPE_UICC2];
229         }
230         break;
231     }
232   }
233 
234   while (status != NFCSTATUS_SUCCESS && retry_cnt < 3) {
235     status = phNxpNciHal_send_ext_cmd(sizeof(set_cfg_cmd), set_cfg_cmd);
236     retry_cnt++;
237     NXPLOG_NCIHAL_E("Get Cfg Retry cnt=%x", retry_cnt);
238   }
239 }
240 
241 /******************************************************************************
242  * Function         phNxpNciHal_read_fw_dw_status
243  *
244  * Description      This will read the value of fw download status flag
245  *                  from eeprom
246  *
247  * Parameters       value - this parameter will be updated with the flag
248  *                  value from eeprom.
249  *
250  * Returns          status of the read
251  *
252  ******************************************************************************/
phNxpNciHal_read_fw_dw_status(uint8_t & value)253 NFCSTATUS phNxpNciHal_read_fw_dw_status(uint8_t& value) {
254   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
255   mEEPROM_info.buffer = &value;
256   mEEPROM_info.bufflen = sizeof(value);
257   mEEPROM_info.request_type = EEPROM_FW_DWNLD;
258   mEEPROM_info.request_mode = GET_EEPROM_DATA;
259   return request_EEPROM(&mEEPROM_info);
260 }
261 
262 /******************************************************************************
263  * Function         phNxpNciHal_write_fw_dw_status
264  *
265  * Description      This will update value of fw download status flag
266  *                  to eeprom
267  *
268  * Parameters       value - this value will be updated to eeprom flag.
269  *
270  * Returns          status of the write
271  *
272  ******************************************************************************/
phNxpNciHal_write_fw_dw_status(uint8_t value)273 NFCSTATUS phNxpNciHal_write_fw_dw_status(uint8_t value) {
274   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
275   mEEPROM_info.buffer = &value;
276   mEEPROM_info.bufflen = sizeof(value);
277   mEEPROM_info.request_type = EEPROM_FW_DWNLD;
278   mEEPROM_info.request_mode = SET_EEPROM_DATA;
279   return request_EEPROM(&mEEPROM_info);
280 }
281 
282 /******************************************************************************
283  * Function         phNxpNciHal_save_uicc_params
284  *
285  * Description      This will read the UICC HCI param values
286  *                  from eeprom and store in global variable
287  *
288  * Returns          status of the read
289  *
290  ******************************************************************************/
phNxpNciHal_save_uicc_params()291 NFCSTATUS phNxpNciHal_save_uicc_params() {
292   if (IS_CHIP_TYPE_L(sn220u)) {
293     NXPLOG_NCIHAL_E("%s Not supported", __func__);
294     return NFCSTATUS_SUCCESS;
295   }
296 
297   NFCSTATUS status = NFCSTATUS_FAILED;
298 
299   /* Getting UICC2 CL params */
300   uicc1HciParams.resize(0xFF);
301   status = phNxpNciHal_get_uicc_hci_params(
302       uicc1HciParams, uicc1HciParams.size(), EEPROM_UICC1_SESSION_ID);
303   if (status != NFCSTATUS_SUCCESS) {
304     NXPLOG_NCIHAL_E("%s: Save UICC1 CLPP failed .", __func__);
305   }
306 
307   /* Getting UICC2 CL params */
308   uicc2HciParams.resize(0xFF);
309   status = phNxpNciHal_get_uicc_hci_params(
310       uicc2HciParams, uicc2HciParams.size(), EEPROM_UICC2_SESSION_ID);
311   if (status != NFCSTATUS_SUCCESS) {
312     NXPLOG_NCIHAL_E("%s: Save UICC2 CLPP failed .", __func__);
313   }
314 
315   /* Get UICC CE HCI State */
316   uiccHciCeParams.resize(0xFF);
317   status = phNxpNciHal_get_uicc_hci_params(
318       uiccHciCeParams, uiccHciCeParams.size(), EEPROM_UICC_HCI_CE_STATE);
319   if (status != NFCSTATUS_SUCCESS) {
320     NXPLOG_NCIHAL_E("%s: Save UICC_HCI_CE_STATE failed .", __func__);
321   }
322   return status;
323 }
324 
325 /******************************************************************************
326  * Function         phNxpNciHal_restore_uicc_params
327  *
328  * Description      This will set the UICC HCI param values
329  *                  back to eeprom from global variable
330  *
331  * Returns          status of the read
332  *
333  ******************************************************************************/
phNxpNciHal_restore_uicc_params()334 NFCSTATUS phNxpNciHal_restore_uicc_params() {
335   if (IS_CHIP_TYPE_L(sn220u)) {
336     NXPLOG_NCIHAL_E("%s Not supported", __func__);
337     return NFCSTATUS_SUCCESS;
338   }
339 
340   NFCSTATUS status = NFCSTATUS_FAILED;
341   if (uicc1HciParams.size() > 0) {
342     status = phNxpNciHal_set_uicc_hci_params(
343         uicc1HciParams, uicc1HciParams.size(), EEPROM_UICC1_SESSION_ID);
344     if (status != NFCSTATUS_SUCCESS) {
345       NXPLOG_NCIHAL_E("%s: Restore UICC1 CLPP failed .", __func__);
346     } else {
347       uicc1HciParams.resize(0);
348     }
349   }
350   if (uicc2HciParams.size() > 0) {
351     status = phNxpNciHal_set_uicc_hci_params(
352         uicc2HciParams, uicc2HciParams.size(), EEPROM_UICC2_SESSION_ID);
353     if (status != NFCSTATUS_SUCCESS) {
354       NXPLOG_NCIHAL_E("%s: Restore UICC2 CLPP failed .", __func__);
355     } else {
356       uicc2HciParams.resize(0);
357     }
358   }
359   if (uiccHciCeParams.size() > 0) {
360     status = phNxpNciHal_set_uicc_hci_params(
361         uiccHciCeParams, uiccHciCeParams.size(), EEPROM_UICC_HCI_CE_STATE);
362     if (status != NFCSTATUS_SUCCESS) {
363       NXPLOG_NCIHAL_E("%s: Restore UICC_HCI_CE_STATE failed .", __func__);
364     } else {
365       uiccHciCeParams.resize(0);
366     }
367   }
368   return status;
369 }
370 
371 /******************************************************************************
372  * Function         phNxpNciHal_get_uicc_hci_params
373  *
374  * Description      This will read the UICC HCI param values
375  *                  from eeprom
376  *
377  * Parameters       value - this parameter will be updated with the flag
378  *                  value from eeprom.
379  *
380  * Returns          status of the read
381  *
382  ******************************************************************************/
383 NFCSTATUS
phNxpNciHal_get_uicc_hci_params(vector<uint8_t> & ptr,uint8_t bufflen,phNxpNci_EEPROM_request_type_t uiccType)384 phNxpNciHal_get_uicc_hci_params(vector<uint8_t>& ptr, uint8_t bufflen,
385                                 phNxpNci_EEPROM_request_type_t uiccType) {
386   if (IS_CHIP_TYPE_L(sn220u)) {
387     NXPLOG_NCIHAL_E("%s Not supported", __func__);
388     return NFCSTATUS_SUCCESS;
389   }
390   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
391   mEEPROM_info.buffer = &ptr[0];
392   mEEPROM_info.bufflen = bufflen;
393   mEEPROM_info.request_type = uiccType;
394   mEEPROM_info.request_mode = GET_EEPROM_DATA;
395   NFCSTATUS status = request_EEPROM(&mEEPROM_info);
396   ptr.resize(mEEPROM_info.bufflen);
397   return status;
398 }
399 
400 /******************************************************************************
401  * Function         phNxpNciHal_set_uicc_hci_params
402  *
403  * Description      This will update the UICC HCI param values
404  *                  to eeprom
405  *
406  * Parameters       value - this value will be updated to eeprom flag.
407  *
408  * Returns          status of the write
409  *
410  *****************************************************************************/
411 NFCSTATUS
phNxpNciHal_set_uicc_hci_params(vector<uint8_t> & ptr,uint8_t bufflen,phNxpNci_EEPROM_request_type_t uiccType)412 phNxpNciHal_set_uicc_hci_params(vector<uint8_t>& ptr, uint8_t bufflen,
413                                 phNxpNci_EEPROM_request_type_t uiccType) {
414   if (IS_CHIP_TYPE_L(sn220u)) {
415     NXPLOG_NCIHAL_E("%s Not supported", __func__);
416     return NFCSTATUS_SUCCESS;
417   }
418   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
419   mEEPROM_info.buffer = &ptr[0];
420   mEEPROM_info.bufflen = bufflen;
421   mEEPROM_info.request_type = uiccType;
422   mEEPROM_info.request_mode = SET_EEPROM_DATA;
423   return request_EEPROM(&mEEPROM_info);
424 }
425 
426 /*****************************************************************************
427  * Function         phNxpNciHal_send_get_cfg
428  *
429  * Description      This function is called to get the configurations from
430  * EEPROM
431  *
432  * Params           cmd_get_cfg, Buffer to get the get command
433  *                  cmd_len,     Length of the command
434  * Returns          SUCCESS/FAILURE
435  *
436  *
437  *****************************************************************************/
phNxpNciHal_send_get_cfg(const uint8_t * cmd_get_cfg,long cmd_len)438 NFCSTATUS phNxpNciHal_send_get_cfg(const uint8_t* cmd_get_cfg, long cmd_len) {
439   NXPLOG_NCIHAL_D("%s Enter", __func__);
440   NFCSTATUS status = NFCSTATUS_FAILED;
441   uint8_t retry_cnt = 0;
442 
443   if (cmd_get_cfg == NULL || cmd_len <= NCI_GET_CONFI_MIN_LEN) {
444     NXPLOG_NCIHAL_E("%s invalid command..! returning... ", __func__);
445     return status;
446   }
447 
448   do {
449     status = phNxpNciHal_send_ext_cmd(cmd_len, (uint8_t*)cmd_get_cfg);
450   } while ((status != NFCSTATUS_SUCCESS) &&
451            (retry_cnt++ < NXP_MAX_RETRY_COUNT));
452 
453   NXPLOG_NCIHAL_D("%s status : 0x%02X", __func__, status);
454   return status;
455 }
456 
457 /*****************************************************************************
458  * Function         phNxpNciHal_configure_merge_sak
459  *
460  * Description      This function is called to apply iso_dep sak merge settings
461  *                  as per the config option NAME_NXP_ISO_DEP_MERGE_SAK
462  *
463  * Params           None
464 
465  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
466  *
467  *****************************************************************************/
phNxpNciHal_configure_merge_sak()468 NFCSTATUS phNxpNciHal_configure_merge_sak() {
469   if (IS_CHIP_TYPE_L(sn100u)) {
470     NXPLOG_NCIHAL_D("%s : Not applicable for chipType %d", __func__,
471                     nfcFL.chipType);
472     return NFCSTATUS_SUCCESS;
473   }
474   long retlen = 0;
475   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
476   NXPLOG_NCIHAL_D("Performing ISODEP sak merge settings");
477   uint8_t val = 0;
478 
479   if (!GetNxpNumValue(NAME_NXP_ISO_DEP_MERGE_SAK, (void*)&retlen,
480                       sizeof(retlen))) {
481     retlen = 0x01;
482     NXPLOG_NCIHAL_D(
483         "ISO_DEP_MERGE_SAK not found. default shall be enabled : 0x%02lx",
484         retlen);
485   }
486   val = (uint8_t)retlen;
487   mEEPROM_info.buffer = &val;
488   mEEPROM_info.bufflen = sizeof(val);
489   mEEPROM_info.request_type = EEPROM_ISODEP_MERGE_SAK;
490   mEEPROM_info.request_mode = SET_EEPROM_DATA;
491   return request_EEPROM(&mEEPROM_info);
492 }
493 #if (NXP_SRD == TRUE)
494 /******************************************************************************
495  * Function         phNxpNciHal_setSrdtimeout
496  *
497  * Description      This function can be used to set srd SRD Timeout.
498  *
499  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS or
500  *                  NFCSTATUS_FEATURE_NOT_SUPPORTED
501  *
502  ******************************************************************************/
phNxpNciHal_setSrdtimeout()503 NFCSTATUS phNxpNciHal_setSrdtimeout() {
504   long retlen = 0;
505   uint8_t* buffer = nullptr;
506   long bufflen = 260;
507   const int NXP_SRD_TIMEOUT_BUF_LEN = 2;
508   const uint16_t TIMEOUT_MASK = 0xFFFF;
509   const uint16_t MAX_TIMEOUT_VALUE = 0xFD70;
510   uint16_t isValid_timeout;
511   uint8_t timeout_buffer[NXP_SRD_TIMEOUT_BUF_LEN];
512   NFCSTATUS status = NFCSTATUS_FEATURE_NOT_SUPPORTED;
513   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
514 
515   NXPLOG_NCIHAL_D("Performing SRD Timeout settings");
516 
517   buffer = (uint8_t*)malloc(bufflen * sizeof(uint8_t));
518   if (NULL == buffer) {
519     return NFCSTATUS_FAILED;
520   }
521   memset(buffer, 0x00, bufflen);
522   if (GetNxpByteArrayValue(NAME_NXP_SRD_TIMEOUT, (char*)buffer, bufflen,
523                            &retlen)) {
524     if (retlen == NXP_SRD_TIMEOUT_BUF_LEN) {
525       isValid_timeout = ((buffer[1] << 8) & TIMEOUT_MASK);
526       isValid_timeout = (isValid_timeout | buffer[0]);
527       if (isValid_timeout > MAX_TIMEOUT_VALUE) {
528         /*if timeout is setting more than 18hrs
529          * than setting to MAX limit 0xFD70*/
530         buffer[0] = 0x70;
531         buffer[1] = 0xFD;
532       }
533       memcpy(&timeout_buffer, buffer, NXP_SRD_TIMEOUT_BUF_LEN);
534       mEEPROM_info.buffer = timeout_buffer;
535       mEEPROM_info.bufflen = sizeof(timeout_buffer);
536       mEEPROM_info.request_type = EEPROM_SRD_TIMEOUT;
537       mEEPROM_info.request_mode = SET_EEPROM_DATA;
538       status = request_EEPROM(&mEEPROM_info);
539     }
540   }
541   if (buffer != NULL) {
542     free(buffer);
543     buffer = NULL;
544   }
545 
546   return status;
547 }
548 #endif
549 
550 /******************************************************************************
551  * Function         phNxpNciHal_setExtendedFieldMode
552  *
553  * Description      This function can be used to set nfcc extended field mode
554  *
555  * Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS or
556  *                  NFCSTATUS_FEATURE_NOT_SUPPORTED
557  *
558  ******************************************************************************/
phNxpNciHal_setExtendedFieldMode()559 NFCSTATUS phNxpNciHal_setExtendedFieldMode() {
560   const uint8_t enable_val = 0x01;
561   const uint8_t disable_val = 0x00;
562   uint8_t extended_field_mode = disable_val;
563   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
564   NFCSTATUS status = NFCSTATUS_FEATURE_NOT_SUPPORTED;
565 
566   if (IS_CHIP_TYPE_GE(sn100u) &&
567       GetNxpNumValue(NAME_NXP_EXTENDED_FIELD_DETECT_MODE, &extended_field_mode,
568                      sizeof(extended_field_mode))) {
569     if (extended_field_mode == enable_val ||
570         extended_field_mode == disable_val) {
571       mEEPROM_info.buffer = &extended_field_mode;
572       mEEPROM_info.bufflen = sizeof(extended_field_mode);
573       mEEPROM_info.request_type = EEPROM_EXT_FIELD_DETECT_MODE;
574       mEEPROM_info.request_mode = SET_EEPROM_DATA;
575       status = request_EEPROM(&mEEPROM_info);
576     } else {
577       NXPLOG_NCIHAL_E("Invalid Extended Field Mode in config");
578     }
579   }
580   return status;
581 }
582 
583 /*******************************************************************************
584 **
585 ** Function         phNxpNciHal_configGPIOControl()
586 **
587 ** Description      Helper function to configure GPIO control
588 **
589 ** Parameters       gpioControl - Byte array with first two bytes are used to
590 **                  configure gpio for specific functionality (ex:ULPDET,
591 **                  GPIO LEVEL ...) and 3rd byte indicates the level of GPIO
592 **                  to be set.
593 **                  len        - Len of byte array
594 **
595 ** Returns          NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
596 *******************************************************************************/
phNxpNciHal_configGPIOControl(uint8_t gpioCtrl[],uint8_t len)597 NFCSTATUS phNxpNciHal_configGPIOControl(uint8_t gpioCtrl[], uint8_t len) {
598   NFCSTATUS status = NFCSTATUS_SUCCESS;
599 
600   if (len == 0) {
601     return NFCSTATUS_INVALID_PARAMETER;
602   }
603   if (nfcFL.chipType <= sn100u) {
604     NXPLOG_NCIHAL_D("%s : Not applicable for chipType %d", __func__,
605                     nfcFL.chipType);
606     return status;
607   }
608   phNxpNci_EEPROM_info_t mEEPROM_info = {.request_mode = 0};
609 
610   mEEPROM_info.request_mode = SET_EEPROM_DATA;
611   mEEPROM_info.buffer = (uint8_t*)gpioCtrl;
612   // First two bytes decides purpose of GPIO config
613   // LIKE ULPDET, GPIO CTRL
614   mEEPROM_info.bufflen = 2;
615   mEEPROM_info.request_type = EEPROM_CONF_GPIO_CTRL;
616 
617   status = request_EEPROM(&mEEPROM_info);
618   if (status != NFCSTATUS_SUCCESS) {
619     NXPLOG_NCIHAL_D("%s : Failed to Enable GPIO ctrl", __func__);
620     return status;
621   }
622   if (len >= 3) {
623     mEEPROM_info.request_mode = SET_EEPROM_DATA;
624     mEEPROM_info.buffer = gpioCtrl + 2;
625     // Last byte contains bitmask of GPIO 2/3 values.
626     mEEPROM_info.bufflen = 1;
627     mEEPROM_info.request_type = EEPROM_SET_GPIO_VALUE;
628 
629     status = request_EEPROM(&mEEPROM_info);
630     if (status != NFCSTATUS_SUCCESS) {
631       NXPLOG_NCIHAL_D("%s : Failed to set GPIO ctrl", __func__);
632     }
633   }
634   return status;
635 }
636 
637 /*******************************************************************************
638 **
639 ** Function         phNxpNciHal_decodeGpioStatus()
640 **
641 ** Description      this function decodes gpios status of the nfc pins
642 **
643 *******************************************************************************/
phNxpNciHal_decodeGpioStatus(void)644 void phNxpNciHal_decodeGpioStatus(void) {
645   NFCSTATUS status = NFCSTATUS_SUCCESS;
646   status = phNxpNciHal_GetNfcGpiosStatus(&gpios_data.gpios_status_data);
647   if (status != NFCSTATUS_SUCCESS) {
648     NXPLOG_NCIHAL_E("Get Gpio Status: Failed");
649   } else {
650     NXPLOG_NCIR_D("%s: NFC_IRQ = %d NFC_VEN = %d NFC_FW_DWL =%d", __func__,
651                   gpios_data.platform_gpios_status.irq,
652                   gpios_data.platform_gpios_status.ven,
653                   gpios_data.platform_gpios_status.fw_dwl);
654   }
655 }
656