summaryrefslogtreecommitdiff
path: root/halimpl/hal/phNxpNciHal_ext.cc
blob: d08ca3d3b3acc715957466025c95401478dab345 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
/*
 * Copyright (C) 2015-2019 NXP Semiconductors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "phNxpNciHal_nciParser.h"
#include <cutils/properties.h>
#include <log/log.h>
#include <phDal4Nfc_messageQueueLib.h>
#include <phDnldNfc.h>
#include <phNxpConfig.h>
#include <phNxpLog.h>
#include <phNxpNciHal.h>
#include <phNxpNciHal_Adaptation.h>
#include <phNxpNciHal_NfcDepSWPrio.h>
#include <phNxpNciHal_ext.h>
#include <phTmlNfc.h>
#include <EseAdaptation.h>

/* Timeout value to wait for response from PN548AD */
#define HAL_EXTNS_WRITE_RSP_TIMEOUT (2500)

#undef P2P_PRIO_LOGIC_HAL_IMP

/******************* Global variables *****************************************/
extern phNxpNciHal_Control_t nxpncihal_ctrl;
extern phNxpNciProfile_Control_t nxpprofile_ctrl;
extern phNxpNci_getCfg_info_t* mGetCfg_info;
extern EseAdaptation *gpEseAdapt;
extern uint32_t cleanup_timer;
uint8_t icode_detected = 0x00;
uint8_t icode_send_eof = 0x00;
static uint8_t ee_disc_done = 0x00;
uint8_t EnableP2P_PrioLogic = false;
extern bool bEnableMfcExtns;
extern bool bEnableMfcReader;
extern bool bDisableLegacyMfcExtns;
static uint32_t RfDiscID = 1;
static uint32_t RfProtocolType = 4;
/* NFCEE Set mode */
static uint8_t setEEModeDone = 0x00;

/* External global variable to get FW version from NCI response*/
extern uint32_t wFwVerRsp;
/* External global variable to get FW version from FW file*/
extern uint16_t wFwVer;
extern bool_t gParserCreated;
uint16_t fw_maj_ver;
uint16_t rom_version;
/* local buffer to store CORE_INIT response */
static uint32_t bCoreInitRsp[40];
static uint32_t iCoreInitRspLen;

static uint32_t bCoreRstNtf[40];
static uint32_t iCoreRstNtfLen;

extern uint32_t timeoutTimerId;
extern uint32_t gSvddSyncOff_Delay; /*default delay*/
tNfc_featureList nfcFL;

void phNxpNciHal_sendRfEvtToEseHal(uint8_t rfEvtType);

/************** HAL extension functions ***************************************/
static void hal_extns_write_rsp_timeout_cb(uint32_t TimerId, void* pContext);

/*Proprietary cmd sent to HAL to send reader mode flag
 * Last byte of 4 byte proprietary cmd data contains ReaderMode flag
 * If this flag is enabled, NFC-DEP protocol is modified to T3T protocol
 * if FrameRF interface is selected. This needs to be done as the FW
 * always sends Ntf for FrameRF with NFC-DEP even though FrameRF with T3T is
 * previously selected with DISCOVER_SELECT_CMD
 */
#define PROPRIETARY_CMD_FELICA_READER_MODE 0xFE
static uint8_t gFelicaReaderMode;
static NFCSTATUS phNxpNciHal_ext_process_nfc_init_rsp(uint8_t* p_ntf, uint16_t* p_len);

/*******************************************************************************
**
** Function         phNxpNciHal_ext_init
**
** Description      initialize extension function
**
*******************************************************************************/
void phNxpNciHal_ext_init(void) {
  icode_detected = 0x00;
  icode_send_eof = 0x00;
  setEEModeDone = 0x00;
  EnableP2P_PrioLogic = false;
}

/*******************************************************************************
**
** Function         phNxpNciHal_sendRfEvtToEseHal
**
** Description      send RF Events to Ese Hal.
**                  rfEvtType : 0x00 for RF OFF
**                            : 0X01 for RF ON
**
*******************************************************************************/
void phNxpNciHal_sendRfEvtToEseHal(uint8_t /* rfEvtType */ ) {
#ifdef ENABLE_ESE_CLIENT
  ese_nxp_IoctlInOutData_t inpOutData;
  gpEseAdapt = &EseAdaptation::GetInstance();
  gpEseAdapt->Initialize();
  uint8_t rf_state_update[] = {0x00};
  memset(&inpOutData, 0x00, sizeof(ese_nxp_IoctlInOutData_t));
  inpOutData.inp.data.nxpCmd.cmd_len = sizeof(rf_state_update);
  rf_state_update[0] = rfEvtType;
  memcpy(inpOutData.inp.data.nxpCmd.p_cmd, rf_state_update,
         sizeof(rf_state_update));
  inpOutData.inp.data_source = 2;
  if (gpEseAdapt != NULL)
        gpEseAdapt->HalNfccNtf(HAL_ESE_IOCTL_RF_STATUS_UPDATE, &inpOutData);
#endif
}

/*******************************************************************************
**
** Function         phNxpNciHal_process_ext_rsp
**
** Description      Process extension function response
**
** Returns          NFCSTATUS_SUCCESS if success
**
*******************************************************************************/
NFCSTATUS phNxpNciHal_process_ext_rsp(uint8_t* p_ntf, uint16_t* p_len) {
  NFCSTATUS status = NFCSTATUS_SUCCESS;
  uint16_t rf_technology_length_param = 0;
#ifdef ENABLE_ESE_CLIENT
  gpEseAdapt = &EseAdaptation::GetInstance();
  gpEseAdapt->Initialize();
#endif
  /*parse and decode LxDebug Notifications*/
    if(p_ntf[0] == 0x6F && (p_ntf[1] == 0x35 || p_ntf[1] == 0x36))
    {
        if(gParserCreated)
            phNxpNciHal_parsePacket(p_ntf,*p_len);
    }

  if (p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && *p_len < 14) {
    if(*p_len <= 6) {
      android_errorWriteLog(0x534e4554, "118152591");
    }
    NXPLOG_NCIHAL_E("RF_INTF_ACTIVATED_NTF length error!");
    status = NFCSTATUS_FAILED;
    return status;
  }

  if (p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[4] == 0x03 &&
      p_ntf[5] == 0x05 && nxpprofile_ctrl.profile_type == EMV_CO_PROFILE) {
    p_ntf[4] = 0xFF;
    p_ntf[5] = 0xFF;
    p_ntf[6] = 0xFF;
    NXPLOG_NCIHAL_D("Nfc-Dep Detect in EmvCo profile - Restart polling");
  }

  if (p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[4] == 0x01 &&
      p_ntf[5] == 0x05 && p_ntf[6] == 0x02 && gFelicaReaderMode) {
    /*If FelicaReaderMode is enabled,Change Protocol to T3T from NFC-DEP
         * when FrameRF interface is selected*/
    p_ntf[5] = 0x03;
    NXPLOG_NCIHAL_D("FelicaReaderMode:Activity 1.1");
  }

#ifdef P2P_PRIO_LOGIC_HAL_IMP
  if (p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[4] == 0x02 &&
      p_ntf[5] == 0x04 && nxpprofile_ctrl.profile_type == NFC_FORUM_PROFILE) {
    EnableP2P_PrioLogic = true;
  }

  NXPLOG_NCIHAL_D("Is EnableP2P_PrioLogic: 0x0%X", EnableP2P_PrioLogic);
  if (phNxpDta_IsEnable() == false) {
    if ((icode_detected != 1) && (EnableP2P_PrioLogic == true)) {
      if (phNxpNciHal_NfcDep_comapre_ntf(p_ntf, *p_len) == NFCSTATUS_FAILED) {
        status = phNxpNciHal_NfcDep_rsp_ext(p_ntf, p_len);
        if (status != NFCSTATUS_INVALID_PARAMETER) {
          return status;
        }
      }
    }
  }
#endif

  status = NFCSTATUS_SUCCESS;

  if (bDisableLegacyMfcExtns && bEnableMfcExtns && p_ntf[0] == 0) {
    if (*p_len < NCI_HEADER_SIZE) {
      android_errorWriteLog(0x534e4554, "169258743");
      return NFCSTATUS_FAILED;
    }
    uint16_t extlen;
    extlen = *p_len - NCI_HEADER_SIZE;
    NxpMfcReaderInstance.AnalyzeMfcResp(&p_ntf[3], &extlen);
    p_ntf[2] = extlen;
    *p_len = extlen + NCI_HEADER_SIZE;
  }

  if (p_ntf[0] == 0x61 && p_ntf[1] == 0x05) {
    bEnableMfcExtns = false;
    if (bDisableLegacyMfcExtns && p_ntf[4] == 0x80 && p_ntf[5] == 0x80) {
      bEnableMfcExtns = true;
      NXPLOG_NCIHAL_D("NxpNci: RF Interface = Mifare Enable MifareExtns");
    }
    switch (p_ntf[4]) {
      case 0x00:
        NXPLOG_NCIHAL_D("NxpNci: RF Interface = NFCEE Direct RF");
        break;
      case 0x01:
        NXPLOG_NCIHAL_D("NxpNci: RF Interface = Frame RF");
        break;
      case 0x02:
        NXPLOG_NCIHAL_D("NxpNci: RF Interface = ISO-DEP");
        break;
      case 0x03:
        NXPLOG_NCIHAL_D("NxpNci: RF Interface = NFC-DEP");
        break;
      case 0x80:
        NXPLOG_NCIHAL_D("NxpNci: RF Interface = MIFARE");
        break;
      default:
        NXPLOG_NCIHAL_D("NxpNci: RF Interface = Unknown");
        break;
    }

    switch (p_ntf[5]) {
      case 0x01:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = T1T");
        phNxpDta_T1TEnable();
        break;
      case 0x02:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = T2T");
        break;
      case 0x03:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = T3T");
        break;
      case 0x04:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = ISO-DEP");
        break;
      case 0x05:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = NFC-DEP");
        break;
      case 0x06:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = 15693");
        break;
      case 0x80:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = MIFARE");
        break;
      case 0x81:
      case 0x8A:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = Kovio");
        break;
      default:
        NXPLOG_NCIHAL_D("NxpNci: Protocol = Unknown");
        break;
    }

    switch (p_ntf[6]) {
      case 0x00:
        NXPLOG_NCIHAL_D("NxpNci: Mode = A Passive Poll");
        break;
      case 0x01:
        NXPLOG_NCIHAL_D("NxpNci: Mode = B Passive Poll");
        break;
      case 0x02:
        NXPLOG_NCIHAL_D("NxpNci: Mode = F Passive Poll");
        break;
      case 0x03:
        NXPLOG_NCIHAL_D("NxpNci: Mode = A Active Poll");
        break;
      case 0x05:
        NXPLOG_NCIHAL_D("NxpNci: Mode = F Active Poll");
        break;
      case 0x06:
        NXPLOG_NCIHAL_D("NxpNci: Mode = 15693 Passive Poll");
        break;
      case 0x70:
      case 0x77:
        NXPLOG_NCIHAL_D("NxpNci: Mode = Kovio");
        break;
      case 0x80:
        NXPLOG_NCIHAL_D("NxpNci: Mode = A Passive Listen");
        break;
      case 0x81:
        NXPLOG_NCIHAL_D("NxpNci: Mode = B Passive Listen");
        break;
      case 0x82:
        NXPLOG_NCIHAL_D("NxpNci: Mode = F Passive Listen");
        break;
      case 0x83:
        NXPLOG_NCIHAL_D("NxpNci: Mode = A Active Listen");
        break;
      case 0x85:
        NXPLOG_NCIHAL_D("NxpNci: Mode = F Active Listen");
        break;
      case 0x86:
        NXPLOG_NCIHAL_D("NxpNci: Mode = 15693 Passive Listen");
        break;
      default:
        NXPLOG_NCIHAL_D("NxpNci: Mode = Unknown");
        break;
    }
  }

  status = phNxpNciHal_ext_process_nfc_init_rsp(p_ntf, p_len);
  if (status != NFCSTATUS_SUCCESS)
    return status;

  if (p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[2] == 0x15 &&
      p_ntf[4] == 0x01 && p_ntf[5] == 0x06 && p_ntf[6] == 0x06) {
    NXPLOG_NCIHAL_D("> Notification for ISO-15693");
    icode_detected = 0x01;
    p_ntf[21] = 0x01;
    p_ntf[22] = 0x01;
  } else if (icode_detected == 1 && icode_send_eof == 2) {
    icode_send_eof = 3;
  } else if (p_ntf[0] == 0x00 && p_ntf[1] == 0x00 && icode_detected == 1) {
    if (icode_send_eof == 3) {
      icode_send_eof = 0;
    }
    if(nxpncihal_ctrl.nci_info.nci_version != NCI_VERSION_2_0)
    {
#if 0 /* this is work around added initially. not required now */
      if (p_ntf[p_ntf[2] + 2] == 0x00) {
        NXPLOG_NCIHAL_D("> Data of ISO-15693");
        p_ntf[2]--;
        (*p_len)--;
      } else {
        p_ntf[p_ntf[2] + 2] |= 0x01;
      }
#endif
    }
  } else if (p_ntf[2] == 0x02 && p_ntf[1] == 0x00 && icode_detected == 1) {
    NXPLOG_NCIHAL_D("> ICODE EOF response do not send to upper layer");
  } else if (p_ntf[0] == 0x61 && p_ntf[1] == 0x06 && icode_detected == 1) {
    NXPLOG_NCIHAL_D("> Polling Loop Re-Started");
    icode_detected = 0;
    icode_send_eof = 0;
  } else if (*p_len == 4 && p_ntf[0] == 0x40 && p_ntf[1] == 0x02 &&
             p_ntf[2] == 0x01 && p_ntf[3] == 0x06) {
    NXPLOG_NCIHAL_D("> Deinit for LLCP set_config 0x%x 0x%x 0x%x", p_ntf[21],
                    p_ntf[22], p_ntf[23]);
    p_ntf[0] = 0x40;
    p_ntf[1] = 0x02;
    p_ntf[2] = 0x02;
    p_ntf[3] = 0x00;
    p_ntf[4] = 0x00;
    *p_len = 5;
  } else if (*p_len == 4 && p_ntf[0] == 0x61 && p_ntf[1] == 0x07) {
    unsigned long rf_update_enable = 0;
    if (GetNxpNumValue(NAME_RF_STATUS_UPDATE_ENABLE, &rf_update_enable,
                       sizeof(unsigned long))) {
      NXPLOG_NCIHAL_D("RF_STATUS_UPDATE_ENABLE : %lu", rf_update_enable);
    }
    if (rf_update_enable == 0x01) {
      phNxpNciHal_sendRfEvtToEseHal(p_ntf[3]);
    }
  } else if (p_ntf[0] == 0x61 && p_ntf[1] == 0x09) {
    unsigned long rf_update_enable = 0;
    if (GetNxpNumValue(NAME_RF_STATUS_UPDATE_ENABLE, &rf_update_enable,
                       sizeof(unsigned long))) {
      NXPLOG_NCIHAL_D("RF_STATUS_UPDATE_ENABLE : %lu", rf_update_enable);
    }
#ifdef ENABLE_ESE_CLIENT
    if (rf_update_enable == 0x01) {
      ese_nxp_IoctlInOutData_t inpOutData;
      memset(&inpOutData, 0x00, sizeof(ese_nxp_IoctlInOutData_t));
      inpOutData.inp.data.nxpCmd.cmd_len = p_ntf[2];
      memcpy(inpOutData.inp.data.nxpCmd.p_cmd, p_ntf + 3, p_ntf[2]);
      inpOutData.inp.data_source = 2;
      if (gpEseAdapt != NULL)
          gpEseAdapt->HalNfccNtf(HAL_ESE_IOCTL_RF_ACTION_NTF, &inpOutData);
    }
#endif
  }

if(nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT == true) {
  /*Handle NFCC2.0 in NCI2.0 Boot sequence*/
  /*After TML sent Hard Reset, we may or may not receive this notification*/
  if (p_ntf[0] == 0x60 && p_ntf[1] == 0x00 && p_ntf[2] == 0x09 &&
           p_ntf[3] == 0x01) {
    NXPLOG_NCIHAL_D("CORE_RESET_NTF 2 reason NFCC Powered ON received !");
  } else if (p_ntf[0] == 0x40 && p_ntf[1] == 0x00 && p_ntf[2] == 0x03 &&
             p_ntf[3] == 0x00 && p_ntf[4] == 0x10 && p_ntf[5] == 0x01 &&
             *p_len == 0x06) {
    NXPLOG_NCIHAL_D("CORE_RESET_RSP 1 received !");
  }
  /*After HAL sent Soft(NCI) Reset*/
  /*NCI2.0 Controller only will send with this response after receiving
     CORE_RESET_CMD*/
  else if (p_ntf[0] == 0x40 && p_ntf[1] == 0x00 && p_ntf[2] == 0x01 &&
           p_ntf[3] == 0x00 && *p_len == 0x04)  // if CORE_RST_RESPONSE ==
                                                // STATUS_OK received means
                                                // NCI2.0 controller else NCI1.0
  {
    NXPLOG_NCIHAL_D("CORE_RESET_RSP 2 received !");
    nxpncihal_ctrl.is_wait_for_ce_ntf = true;
  } else if (p_ntf[0] == 0x60 && p_ntf[1] == 0x00 && p_ntf[2] == 0x09 &&
             p_ntf[3] == 0x02 && nxpncihal_ctrl.is_wait_for_ce_ntf) {
    NXPLOG_NCIHAL_D("CORE_RESET_NTF 2 reason Command received !");
    if (*p_len < 3) {
      android_errorWriteLog(0x534e4554, "169258455");
      return NFCSTATUS_FAILED;
    }
    int len = p_ntf[2] + 2; /*include 2 byte header*/
    if(len != *p_len - 1) {
      NXPLOG_NCIHAL_E("phNxpNciHal_ext_process_nfc_init_rsp invalid NTF length");
      android_errorWriteLog(0x534e4554, "121263487");
      return NFCSTATUS_FAILED;
    }
    wFwVerRsp = (((uint32_t)p_ntf[len - 2]) << 16U) |
                (((uint32_t)p_ntf[len - 1]) << 8U) | p_ntf[len];
    iCoreRstNtfLen = *p_len;
    memcpy(bCoreRstNtf, p_ntf, *p_len);
    NXPLOG_NCIHAL_D("NxpNci> FW Version: %x.%x.%x", p_ntf[len - 2],
                    p_ntf[len - 1], p_ntf[len]);
    nxpncihal_ctrl.is_wait_for_ce_ntf = false;
    if (nxpncihal_ctrl.hal_ext_enabled == 1) {
      status = NFCSTATUS_FAILED;
      return status;
    }
  } else if (p_ntf[0] == 0x60 && p_ntf[1] == 0x00 && p_ntf[2] == 0x09 &&
             p_ntf[3] == 0x00 && nxpncihal_ctrl.is_wait_for_ce_ntf) {
    NXPLOG_NCIHAL_E("CORE_RESET_NTF 2 reason Unrecoverable error received !");
    phNxpNciHal_emergency_recovery();
  } else if (p_ntf[0] == 0x40 && p_ntf[1] == 0x01 &&
             nxpncihal_ctrl.is_wait_for_ce_ntf) {
    NXPLOG_NCIHAL_D("CORE_INIT_RSP 2 received !");
  }
  /*Retreive reset ntf reason code irrespective of NCI 1.0 or 2.0*/
  if (p_ntf[0] == 0x60 && p_ntf[1] == 0x00 ){
    if ( p_ntf[3] == FW_DBG_REASON_AVAILABLE)
      property_set("persist.vendor.nfc.core_reset_debug_info", "true");
  }
}

/*Handle NFCC2.0 in NCI1.0 Boot sequence*/
if (((nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT) &&
        ((p_ntf[0] == 0x40) && (p_ntf[1] == 0x01) &&
                !nxpncihal_ctrl.is_wait_for_ce_ntf)) ||
        ((!nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT) &&
                ((p_ntf[0] == 0x40) && (p_ntf[1] == 0x01)))) {
    if (nxpncihal_ctrl.nci_info.nci_version == NCI_VERSION_2_0) {
        NXPLOG_NCIHAL_D("CORE_INIT_RSP NCI2.0 received !");
    } else {
        NXPLOG_NCIHAL_D("CORE_INIT_RSP 1 received !");

        if(!nxpncihal_ctrl.hal_open_status && nxpncihal_ctrl.nci_info.nci_version != NCI_VERSION_2_0) {
            phNxpNciHal_configFeatureList(p_ntf,*p_len);
        }
        int len = p_ntf[2] + 2; /*include 2 byte header*/
        if(len != *p_len - 1) {
          NXPLOG_NCIHAL_E("phNxpNciHal_ext_process_nfc_init_rsp invalid NTF length");
          android_errorWriteLog(0x534e4554, "121263487");
          return NFCSTATUS_FAILED;
        }
        wFwVerRsp = (((uint32_t)p_ntf[len - 2]) << 16U) |
                (((uint32_t)p_ntf[len - 1]) << 8U) | p_ntf[len];
        if (wFwVerRsp == 0) status = NFCSTATUS_FAILED;
        iCoreInitRspLen = *p_len;
        memcpy(bCoreInitRsp, p_ntf, *p_len);
        fw_maj_ver = p_ntf[len - 1];
        rom_version = p_ntf[len - 2];
    }
}

  else if (p_ntf[0] == 0x42 && p_ntf[1] == 0x00 && ee_disc_done == 0x01) {
    NXPLOG_NCIHAL_D(
        "As done with the NFCEE discovery so setting it to zero  - "
        "NFCEE_DISCOVER_RSP");
    if (p_ntf[4] == 0x01) {
      p_ntf[4] = 0x00;

      ee_disc_done = 0x00;
    }
  } else if (p_ntf[0] == 0x61 && p_ntf[1] == 0x03 /*&& cleanup_timer!=0*/) {
    if (cleanup_timer != 0) {
      /* if RF Notification Type of RF_DISCOVER_NTF is Last Notification */
      if (0 == (*(p_ntf + 2 + (*(p_ntf + 2))))) {
        phNxpNciHal_select_RF_Discovery(RfDiscID, RfProtocolType);
        status = NFCSTATUS_FAILED;
        return status;
      } else {
        RfDiscID = p_ntf[3];
        RfProtocolType = p_ntf[4];
      }
      status = NFCSTATUS_FAILED;
      return status;
    }

  } else if (p_ntf[0] == 0x41 && p_ntf[1] == 0x04 && cleanup_timer != 0) {
    status = NFCSTATUS_FAILED;
    return status;
  }
  else if ((nfcFL.chipType == pn547C2) &&
          (p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[4] == 0x02 &&
                  p_ntf[5] == 0x80 && p_ntf[6] == 0x00)) {
      NXPLOG_NCIHAL_D(
              "Going through the iso-dep interface mifare protocol with sak value "
              "not equal to 0x20");
      rf_technology_length_param = p_ntf[9];
      if ((p_ntf[9 + rf_technology_length_param] & 0x20) != 0x20) {
          p_ntf[4] = 0x80;
      }
  }
  /*
  else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[4] == 0x01 && p_ntf[5]
  == 0x00 && p_ntf[6] == 0x01)
  {
      NXPLOG_NCIHAL_D("Picopass type 3-B with undefined protocol is not
  supported, disabling");
      p_ntf[4] = 0xFF;
      p_ntf[5] = 0xFF;
      p_ntf[6] = 0xFF;
  }*/

  return status;
}


/******************************************************************************
* Function         phNxpNciHal_ext_process_nfc_init_rsp
 *
 * Description      This function is used to process the HAL NFC core reset rsp
 *                  and ntf and core init rsp of NCI 1.0 or NCI2.0 and update NCI version.
 *                  It also handles error response such as core_reset_ntf with
 *                  error status in both NCI2.0 and NCI1.0.
 *
 * Returns          Returns NFCSTATUS_SUCCESS if parsing response is successful or
 *                  returns failure.
 *
******************************************************************************/
static NFCSTATUS phNxpNciHal_ext_process_nfc_init_rsp(uint8_t* p_ntf, uint16_t* p_len) {
   NFCSTATUS status = NFCSTATUS_SUCCESS;

    /* Parsing CORE_RESET_RSP and CORE_RESET_NTF to update NCI version.*/
    if(p_ntf == NULL || *p_len < 2) {
      return NFCSTATUS_FAILED;
    }
    if (p_ntf[0] == NCI_MT_RSP && ((p_ntf[1] & NCI_OID_MASK) == NCI_MSG_CORE_RESET)) {
      if (*p_len < 4) {
        android_errorWriteLog(0x534e4554, "169258455");
        return NFCSTATUS_FAILED;
      }
      if (p_ntf[2] == 0x01 && p_ntf[3] == 0x00) {
        NXPLOG_NCIHAL_D("CORE_RESET_RSP NCI2.0");
        if(nxpncihal_ctrl.hal_ext_enabled == TRUE) {
          nxpncihal_ctrl.nci_info.wait_for_ntf = TRUE;
        }
      } else if (p_ntf[2] == 0x03 && p_ntf[3] == 0x00) {
        if (*p_len < 5) {
          android_errorWriteLog(0x534e4554, "169258455");
          return NFCSTATUS_FAILED;
        }
        NXPLOG_NCIHAL_D("CORE_RESET_RSP NCI1.0");
        nxpncihal_ctrl.nci_info.nci_version = p_ntf[4];
      }
    } else if (p_ntf[0] == NCI_MT_NTF && ((p_ntf[1] & NCI_OID_MASK) == NCI_MSG_CORE_RESET)) {
        if (*p_len < 4) {
          android_errorWriteLog(0x534e4554, "169258455");
          return NFCSTATUS_FAILED;
        }
        if(p_ntf[3] == CORE_RESET_TRIGGER_TYPE_CORE_RESET_CMD_RECEIVED ) {
          if (*p_len < 6) {
            android_errorWriteLog(0x534e4554, "169258455");
            return NFCSTATUS_FAILED;
          }
          NXPLOG_NCIHAL_D("CORE_RESET_NTF NCI2.0 reason CORE_RESET_CMD received !");
          nxpncihal_ctrl.nci_info.nci_version  = p_ntf[5];
          phNxpNciHal_configFeatureList(p_ntf,*p_len);
          int len = p_ntf[2] + 2; /*include 2 byte header*/
          wFwVerRsp = (((uint32_t)p_ntf[len - 2])<< 16U)|
          (((uint32_t)p_ntf[len - 1])<< 8U)|p_ntf[len];
          fw_maj_ver = p_ntf[len - 1];
          rom_version = p_ntf[len - 2];
          NXPLOG_NCIHAL_D ("NxpNci> FW Version: %x.%x.%x", p_ntf[len-2], p_ntf[len-1], p_ntf[len]);
          } else {
            uint32_t i;
            char print_buffer[*p_len * 3 + 1];

            memset(print_buffer, 0, sizeof(print_buffer));
            for (i = 0; i < *p_len; i++) {
              snprintf(&print_buffer[i * 2], 3, "%02X", p_ntf[i]);
            }
            NXPLOG_NCIHAL_D("CORE_RESET_NTF received !");
            NXPLOG_NCIR_E("len = %3d > %s", *p_len, print_buffer);

            /*Retreive reset ntf reason code irrespective of NCI 1.0 or 2.0*/
            if (p_ntf[3] == FW_DBG_REASON_AVAILABLE)
              property_set("persist.vendor.nfc.core_reset_debug_info", "true");
        phNxpNciHal_emergency_recovery();
        status = NFCSTATUS_FAILED;
      } /* Parsing CORE_INIT_RSP*/
    } else if (p_ntf[0] == NCI_MT_RSP && ((p_ntf[1] & NCI_OID_MASK) == NCI_MSG_CORE_INIT)) {
      if (nxpncihal_ctrl.nci_info.nci_version == NCI_VERSION_2_0) {
        NXPLOG_NCIHAL_D("CORE_INIT_RSP NCI2.0 received !");
      } else {
        NXPLOG_NCIHAL_D("CORE_INIT_RSP NCI1.0 received !");
        int len = p_ntf[2] + 2; /*include 2 byte header*/
        wFwVerRsp = (((uint32_t)p_ntf[len - 2]) << 16U) |
                    (((uint32_t)p_ntf[len - 1]) << 8U) | p_ntf[len];
        if (wFwVerRsp == 0)
          status = NFCSTATUS_FAILED;
        iCoreInitRspLen = *p_len;
        memcpy(bCoreInitRsp, p_ntf, *p_len);
        NXPLOG_NCIHAL_D("NxpNci> FW Version: %x.%x.%x", p_ntf[len - 2],
                        p_ntf[len - 1], p_ntf[len]);
        fw_maj_ver = p_ntf[len - 1];
        rom_version = p_ntf[len - 2];
      }
    }
    return status;
}

/******************************************************************************
 * Function         phNxpNciHal_process_ext_cmd_rsp
 *
 * Description      This function process the extension command response. It
 *                  also checks the received response to expected response.
 *
 * Returns          returns NFCSTATUS_SUCCESS if response is as expected else
 *                  returns failure.
 *
 ******************************************************************************/
static NFCSTATUS phNxpNciHal_process_ext_cmd_rsp(uint16_t cmd_len,
                                                 uint8_t* p_cmd) {
  NFCSTATUS status = NFCSTATUS_FAILED;
  uint16_t data_written = 0;
  uint8_t get_cfg_value_index = 0x07, get_cfg_value_len = 0x00,
          get_cfg_type = 0x05;
  /* Create the local semaphore */
  if (phNxpNciHal_init_cb_data(&nxpncihal_ctrl.ext_cb_data, NULL) !=
      NFCSTATUS_SUCCESS) {
    NXPLOG_NCIHAL_D("Create ext_cb_data failed");
    return NFCSTATUS_FAILED;
  }

  nxpncihal_ctrl.ext_cb_data.status = NFCSTATUS_SUCCESS;

  /* Send ext command */
  data_written = phNxpNciHal_write_unlocked(cmd_len, p_cmd);
  if (data_written != cmd_len) {
    NXPLOG_NCIHAL_D("phNxpNciHal_write failed for hal ext");
    goto clean_and_return;
  }

  /* Start timer */
  status = phOsalNfc_Timer_Start(timeoutTimerId, HAL_EXTNS_WRITE_RSP_TIMEOUT,
                                 &hal_extns_write_rsp_timeout_cb, NULL);
  if (NFCSTATUS_SUCCESS == status) {
    NXPLOG_NCIHAL_D("Response timer started");
  } else {
    NXPLOG_NCIHAL_E("Response timer not started!!!");
    status = NFCSTATUS_FAILED;
    goto clean_and_return;
  }

  /* Wait for rsp */
  NXPLOG_NCIHAL_D("Waiting after ext cmd sent");
  if (SEM_WAIT(nxpncihal_ctrl.ext_cb_data)) {
    NXPLOG_NCIHAL_E("p_hal_ext->ext_cb_data.sem semaphore error");
    goto clean_and_return;
  }

  /* Stop Timer */
  status = phOsalNfc_Timer_Stop(timeoutTimerId);

  if (NFCSTATUS_SUCCESS == status) {
    NXPLOG_NCIHAL_D("Response timer stopped");
  } else {
    NXPLOG_NCIHAL_E("Response timer stop ERROR!!!");
    status = NFCSTATUS_FAILED;
    goto clean_and_return;
  }
    /* No NTF expected for OMAPI command */
  if(p_cmd[0] == 0x2F && p_cmd[1] == 0x1 &&  p_cmd[2] == 0x01) {
    nxpncihal_ctrl.nci_info.wait_for_ntf = FALSE;
  }
  /* Start timer to wait for NTF*/
  if (nxpncihal_ctrl.nci_info.wait_for_ntf == TRUE) {
    status = phOsalNfc_Timer_Start(timeoutTimerId, HAL_EXTNS_WRITE_RSP_TIMEOUT,
      &hal_extns_write_rsp_timeout_cb, NULL);
    if (NFCSTATUS_SUCCESS == status) {
      NXPLOG_NCIHAL_D("Response timer started");
    } else {
      NXPLOG_NCIHAL_E("Response timer not started!!!");
      status = NFCSTATUS_FAILED;
      goto clean_and_return;
    }
    if (SEM_WAIT(nxpncihal_ctrl.ext_cb_data)) {
      NXPLOG_NCIHAL_E("p_hal_ext->ext_cb_data.sem semaphore error");
      /* Stop Timer */
      status = phOsalNfc_Timer_Stop(timeoutTimerId);
      goto clean_and_return;
    }
    status = phOsalNfc_Timer_Stop(timeoutTimerId);
    if (NFCSTATUS_SUCCESS == status) {
      NXPLOG_NCIHAL_D("Response timer stopped");
    } else {
      NXPLOG_NCIHAL_E("Response timer stop ERROR!!!");
      status = NFCSTATUS_FAILED;
      goto clean_and_return;
    }
  }

  NXPLOG_NCIHAL_E("nxpncihal_ctrl.ext_cb_data.status 0x%x",
                  nxpncihal_ctrl.ext_cb_data.status);

  if (nxpncihal_ctrl.ext_cb_data.status != NFCSTATUS_SUCCESS &&
      p_cmd[0] == 0x40 && p_cmd[1] == 0x00 && p_cmd[2] == 0x03 &&
      p_cmd[3] != 0x00) {
    NXPLOG_NCIHAL_E("Core Reset Syntax Error status=0x%x",
                    nxpncihal_ctrl.ext_cb_data.status);
    status = NFCSTATUS_FAILED;
    goto clean_and_return;
  }

  if (nxpncihal_ctrl.ext_cb_data.status != NFCSTATUS_SUCCESS &&
      p_cmd[0] != 0x2F && p_cmd[1] != 0x1 && p_cmd[2] == 0x01) {
    NXPLOG_NCIHAL_E(
        "Callback Status is failed!! Timer Expired!! Couldn't read it! 0x%x",
        nxpncihal_ctrl.ext_cb_data.status);
    status = NFCSTATUS_FAILED;
    goto clean_and_return;
  }

  NXPLOG_NCIHAL_D("Checking response");

  if ((mGetCfg_info != NULL) && (mGetCfg_info->isGetcfg == true) &&
      (nxpncihal_ctrl.p_rx_data[0] == 0x40) &&
      (nxpncihal_ctrl.p_rx_data[1] == 0x03) &&
      (nxpncihal_ctrl.p_rx_data[3] == NFCSTATUS_SUCCESS)) {
    get_cfg_value_len = nxpncihal_ctrl.rx_data_len - get_cfg_value_index;
    switch (nxpncihal_ctrl.p_rx_data[get_cfg_type]) {
      case TOTAL_DURATION:
        memcpy(&mGetCfg_info->total_duration,
               nxpncihal_ctrl.p_rx_data + get_cfg_value_index,
               get_cfg_value_len);
        mGetCfg_info->total_duration_len = get_cfg_value_len;
        break;

      case ATR_REQ_GEN_BYTES_POLL:
        memcpy(&mGetCfg_info->atr_req_gen_bytes,
               nxpncihal_ctrl.p_rx_data + get_cfg_value_index,
               get_cfg_value_len);
        mGetCfg_info->atr_req_gen_bytes_len = (uint8_t)get_cfg_value_len;
        break;

      case ATR_REQ_GEN_BYTES_LIS:
        memcpy(&mGetCfg_info->atr_res_gen_bytes,
               nxpncihal_ctrl.p_rx_data + get_cfg_value_index,
               get_cfg_value_len);
        mGetCfg_info->atr_res_gen_bytes_len = (uint8_t)get_cfg_value_len;
        break;

      case LEN_WT:
        memcpy(&mGetCfg_info->pmid_wt,
               nxpncihal_ctrl.p_rx_data + get_cfg_value_index,
               get_cfg_value_len);
        mGetCfg_info->pmid_wt_len = (uint8_t)get_cfg_value_len;
        ;
        break;
      default:
        // do nothing
        break;
    }
  }

  status = NFCSTATUS_SUCCESS;

clean_and_return:
  phNxpNciHal_cleanup_cb_data(&nxpncihal_ctrl.ext_cb_data);
  nxpncihal_ctrl.nci_info.wait_for_ntf = FALSE;
  return status;
}

/******************************************************************************
 * Function         phNxpNciHal_write_ext
 *
 * Description      This function inform the status of phNxpNciHal_open
 *                  function to libnfc-nci.
 *
 * Returns          It return NFCSTATUS_SUCCESS then continue with send else
 *                  sends NFCSTATUS_FAILED direct response is prepared and
 *                  do not send anything to NFCC.
 *
 ******************************************************************************/

NFCSTATUS phNxpNciHal_write_ext(uint16_t* cmd_len, uint8_t* p_cmd_data,
                                uint16_t* rsp_len, uint8_t* p_rsp_data) {
  NFCSTATUS status = NFCSTATUS_SUCCESS;

  phNxpNciHal_NfcDep_cmd_ext(p_cmd_data, cmd_len);

  if (phNxpDta_IsEnable() == true) {
    status = phNxpNHal_DtaUpdate(cmd_len, p_cmd_data, rsp_len, p_rsp_data);
  }

  if (p_cmd_data[0] == PROPRIETARY_CMD_FELICA_READER_MODE &&
      p_cmd_data[1] == PROPRIETARY_CMD_FELICA_READER_MODE &&
      p_cmd_data[2] == PROPRIETARY_CMD_FELICA_READER_MODE) {
    NXPLOG_NCIHAL_D("Received proprietary command to set Felica Reader mode:%d",
                    p_cmd_data[3]);
    gFelicaReaderMode = p_cmd_data[3];
    /* frame the dummy response */
    *rsp_len = 4;
    p_rsp_data[0] = 0x40;
    p_rsp_data[1] = 0x03;
    p_rsp_data[2] = 0x01;
    p_rsp_data[3] = 0x00;
    status = NFCSTATUS_FAILED;
  } else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
             p_cmd_data[2] == 0x05 && p_cmd_data[3] == 0x01 &&
             p_cmd_data[4] == 0xA0 && p_cmd_data[5] == 0x44 &&
             p_cmd_data[6] == 0x01 && p_cmd_data[7] == 0x01) {
    nxpprofile_ctrl.profile_type = EMV_CO_PROFILE;
    NXPLOG_NCIHAL_D("EMV_CO_PROFILE mode - Enabled");
    status = NFCSTATUS_SUCCESS;
  } else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
             p_cmd_data[2] == 0x05 && p_cmd_data[3] == 0x01 &&
             p_cmd_data[4] == 0xA0 && p_cmd_data[5] == 0x44 &&
             p_cmd_data[6] == 0x01 && p_cmd_data[7] == 0x00) {
    NXPLOG_NCIHAL_D("NFC_FORUM_PROFILE mode - Enabled");
    nxpprofile_ctrl.profile_type = NFC_FORUM_PROFILE;
    status = NFCSTATUS_SUCCESS;
  }
  else if ((nfcFL.eseFL._ESE_SVDD_SYNC) &&
          (p_cmd_data[0] == 0x2F && p_cmd_data[1] == 0x31 &&
                  p_cmd_data[2] == 0x01 && p_cmd_data[3] == 0x00)) {
    NXPLOG_NCIHAL_D("SVDD Sync Off Command - delay it by %d ms",
                    gSvddSyncOff_Delay);
    usleep(gSvddSyncOff_Delay * 1000);
  }
  if (nxpprofile_ctrl.profile_type == EMV_CO_PROFILE) {
    if (p_cmd_data[0] == 0x21 && p_cmd_data[1] == 0x06 &&
        p_cmd_data[2] == 0x01 && p_cmd_data[3] == 0x03) {
#if 0
            //Needs clarification whether to keep it or not
            NXPLOG_NCIHAL_D ("EmvCo Poll mode - RF Deactivate discard");
            phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
            *rsp_len = 4;
            p_rsp_data[0] = 0x41;
            p_rsp_data[1] = 0x06;
            p_rsp_data[2] = 0x01;
            p_rsp_data[3] = 0x00;
            phNxpNciHal_print_packet("RECV", p_rsp_data, 4);
            status = NFCSTATUS_FAILED;
#endif
    } else if (p_cmd_data[0] == 0x21 && p_cmd_data[1] == 0x03) {
      NXPLOG_NCIHAL_D("EmvCo Poll mode - Discover map only for A and B");
      p_cmd_data[2] = 0x05;
      p_cmd_data[3] = 0x02;
      p_cmd_data[4] = 0x00;
      p_cmd_data[5] = 0x01;
      p_cmd_data[6] = 0x01;
      p_cmd_data[7] = 0x01;
      *cmd_len = 8;
    }
  }

  if (bEnableMfcReader && p_cmd_data[0] == 0x21 && p_cmd_data[1] == 0x00 &&
      p_cmd_data[2] != 0x04 && p_cmd_data[6] != 0x83) {
    NXPLOG_NCIHAL_D("Going through extns - Adding Mifare in RF Discovery");
    p_cmd_data[2] += 3;
    p_cmd_data[3] += 1;
    p_cmd_data[*cmd_len] = 0x80;
    p_cmd_data[*cmd_len + 1] = 0x01;
    p_cmd_data[*cmd_len + 2] = 0x80;
    *cmd_len += 3;
    status = NFCSTATUS_SUCCESS;
    bEnableMfcExtns = false;
    NXPLOG_NCIHAL_D(
        "Going through extns - Adding Mifare in RF Discovery - END");
  } else if (p_cmd_data[3] == 0x81 && p_cmd_data[4] == 0x01 &&
             p_cmd_data[5] == 0x03) {
    NXPLOG_NCIHAL_D("> Going through the set host list");
    if(nfcFL.chipType != pn547C2) {
        *cmd_len = 8;

        p_cmd_data[2] = 0x05;
        p_cmd_data[6] = 0x02;
        p_cmd_data[7] = 0xC0;
    } else {
        *cmd_len = 7;

        p_cmd_data[2] = 0x04;
        p_cmd_data[6] = 0xC0;
    }
    status = NFCSTATUS_SUCCESS;
  } else if (icode_detected) {
    if ((p_cmd_data[3] & 0x40) == 0x40 &&
        (p_cmd_data[4] == 0x21 || p_cmd_data[4] == 0x22 ||
         p_cmd_data[4] == 0x24 || p_cmd_data[4] == 0x27 ||
         p_cmd_data[4] == 0x28 || p_cmd_data[4] == 0x29 ||
         p_cmd_data[4] == 0x2a)) {
      NXPLOG_NCIHAL_D("> Send EOF set");
      icode_send_eof = 1;
    }

    if (p_cmd_data[3] == 0x20 || p_cmd_data[3] == 0x24 ||
        p_cmd_data[3] == 0x60) {
      NXPLOG_NCIHAL_D("> NFC ISO_15693 Proprietary CMD ");
      p_cmd_data[3] += 0x02;
    }
  } else if (p_cmd_data[0] == 0x21 && p_cmd_data[1] == 0x03) {
    NXPLOG_NCIHAL_D("> Polling Loop Started");
    icode_detected = 0;
    icode_send_eof = 0;
  }
  // 22000100
  else if (p_cmd_data[0] == 0x22 && p_cmd_data[1] == 0x00 &&
           p_cmd_data[2] == 0x01 && p_cmd_data[3] == 0x00) {
    // ee_disc_done = 0x01;//Reader Over SWP event getting
    *rsp_len = 0x05;
    p_rsp_data[0] = 0x42;
    p_rsp_data[1] = 0x00;
    p_rsp_data[2] = 0x02;
    p_rsp_data[3] = 0x00;
    p_rsp_data[4] = 0x00;
    phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
    status = NFCSTATUS_FAILED;
  }
  // 2002 0904 3000 3100 3200 5000
  else if ((p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) &&
           ((p_cmd_data[2] == 0x09 && p_cmd_data[3] == 0x04) /*||
            (p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04)*/
            )) {
    *cmd_len += 0x01;
    p_cmd_data[2] += 0x01;
    p_cmd_data[9] = 0x01;
    p_cmd_data[10] = 0x40;
    p_cmd_data[11] = 0x50;
    p_cmd_data[12] = 0x00;

    NXPLOG_NCIHAL_D("> Dirty Set Config ");
    //        phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
  }
  //    20020703300031003200
  //    2002 0301 3200
  else if ((p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) &&
           ((p_cmd_data[2] == 0x07 && p_cmd_data[3] == 0x03) ||
            (p_cmd_data[2] == 0x03 && p_cmd_data[3] == 0x01 &&
             p_cmd_data[4] == 0x32))) {
    NXPLOG_NCIHAL_D("> Dirty Set Config ");
    phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    *rsp_len = 5;
    p_rsp_data[0] = 0x40;
    p_rsp_data[1] = 0x02;
    p_rsp_data[2] = 0x02;
    p_rsp_data[3] = 0x00;
    p_rsp_data[4] = 0x00;

    phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
    status = NFCSTATUS_FAILED;
  }

  // 2002 0D04 300104 310100 320100 500100
  // 2002 0401 320100
  else if ((p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) &&
           (
               /*(p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04)*/
               (p_cmd_data[2] == 0x04 && p_cmd_data[3] == 0x01 &&
                p_cmd_data[4] == 0x32 && p_cmd_data[5] == 0x00))) {
    //        p_cmd_data[12] = 0x40;

    NXPLOG_NCIHAL_D("> Dirty Set Config ");
    phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    p_cmd_data[6] = 0x60;

    phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
    //        status = NFCSTATUS_FAILED;
  }
#if 0
    else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) &&
                 ((p_cmd_data[2] == 0x09 && p_cmd_data[3] == 0x04) ||
                     (p_cmd_data[2] == 0x0B && p_cmd_data[3] == 0x05) ||
                     (p_cmd_data[2] == 0x07 && p_cmd_data[3] == 0x02) ||
                     (p_cmd_data[2] == 0x0A && p_cmd_data[3] == 0x03) ||
                     (p_cmd_data[2] == 0x0A && p_cmd_data[3] == 0x04) ||
                     (p_cmd_data[2] == 0x05 && p_cmd_data[3] == 0x02))
             )
    {
        NXPLOG_NCIHAL_D ("> Dirty Set Config ");
        phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
        *rsp_len = 5;
        p_rsp_data[0] = 0x40;
        p_rsp_data[1] = 0x02;
        p_rsp_data[2] = 0x02;
        p_rsp_data[3] = 0x00;
        p_rsp_data[4] = 0x00;

        phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
        status = NFCSTATUS_FAILED;
    }

    else if((p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) &&
           ((p_cmd_data[3] == 0x00) ||
           ((*cmd_len >= 0x06) && (p_cmd_data[5] == 0x00)))) /*If the length of the first param id is zero don't allow*/
    {
        NXPLOG_NCIHAL_D ("> Dirty Set Config ");
        phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
        *rsp_len = 5;
        p_rsp_data[0] = 0x40;
        p_rsp_data[1] = 0x02;
        p_rsp_data[2] = 0x02;
        p_rsp_data[3] = 0x00;
        p_rsp_data[4] = 0x00;

        phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
        status = NFCSTATUS_FAILED;
    }
#endif
  else if ((wFwVerRsp & 0x0000FFFF) == wFwVer) {
    /* skip CORE_RESET and CORE_INIT from Brcm */
    if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x00 &&
        p_cmd_data[2] == 0x01 && p_cmd_data[3] == 0x01) {
      //            *rsp_len = 6;
      //
      //            NXPLOG_NCIHAL_D("> Going - core reset optimization");
      //
      //            p_rsp_data[0] = 0x40;
      //            p_rsp_data[1] = 0x00;
      //            p_rsp_data[2] = 0x03;
      //            p_rsp_data[3] = 0x00;
      //            p_rsp_data[4] = 0x10;
      //            p_rsp_data[5] = 0x01;
      //
      //            status = NFCSTATUS_FAILED;
      //            NXPLOG_NCIHAL_D("> Going - core reset optimization - END");
    }
    /* CORE_INIT */
    else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x01 &&
             p_cmd_data[2] == 0x00) {
      //            NXPLOG_NCIHAL_D("> Going - core init optimization");
      //            *rsp_len = iCoreInitRspLen;
      //            memcpy(p_rsp_data, bCoreInitRsp, iCoreInitRspLen);
      //            status = NFCSTATUS_FAILED;
      //            NXPLOG_NCIHAL_D("> Going - core init optimization - END");
    }
  }

  if ((nfcFL.chipType == pn548C2) &&
          (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02)) {
      uint8_t temp;
      uint8_t* p = p_cmd_data + 4;
      uint8_t* end = p_cmd_data + *cmd_len;
      while (p < end) {
          if (*p == 0x53)  // LF_T3T_FLAGS
          {
              NXPLOG_NCIHAL_D("> Going through workaround - LF_T3T_FLAGS swap");
              temp = *(p + 3);
              *(p + 3) = *(p + 2);
              *(p + 2) = temp;
              NXPLOG_NCIHAL_D("> Going through workaround - LF_T3T_FLAGS - End");
              status = NFCSTATUS_SUCCESS;
              break;
          }
          if (*p == 0xA0) {
              p += *(p + 2) + 3;
          } else {
              p += *(p + 1) + 2;
          }
      }
  }

  return status;
}

/******************************************************************************
 * Function         phNxpNciHal_send_ext_cmd
 *
 * Description      This function send the extension command to NFCC. No
 *                  response is checked by this function but it waits for
 *                  the response to come.
 *
 * Returns          Returns NFCSTATUS_SUCCESS if sending cmd is successful and
 *                  response is received.
 *
 ******************************************************************************/
NFCSTATUS phNxpNciHal_send_ext_cmd(uint16_t cmd_len, uint8_t* p_cmd) {
  NFCSTATUS status = NFCSTATUS_FAILED;

  HAL_ENABLE_EXT();
  nxpncihal_ctrl.cmd_len = cmd_len;
  memcpy(nxpncihal_ctrl.p_cmd_data, p_cmd, cmd_len);
  status = phNxpNciHal_process_ext_cmd_rsp(nxpncihal_ctrl.cmd_len,
                                           nxpncihal_ctrl.p_cmd_data);
  HAL_DISABLE_EXT();

  return status;
}

/******************************************************************************
 * Function         phNxpNciHal_send_ext_cmd_ntf
 *
 * Description      This function send the extension command to NFCC. No
 *                  response is checked by this function but it waits for
 *                  the response. Also it can wait for notification
 *
 * Returns          Returns NFCSTATUS_SUCCESS if sending cmd is successful and
 *                  response is received followed by notification.
 *
 ******************************************************************************/
NFCSTATUS phNxpNciHal_send_ext_cmd_ntf(uint16_t cmd_len, uint8_t* p_cmd) {
  NFCSTATUS status = NFCSTATUS_FAILED;

  HAL_ENABLE_EXT();
  nxpncihal_ctrl.cmd_len = cmd_len;
  memcpy(nxpncihal_ctrl.p_cmd_data, p_cmd, cmd_len);
  status = phNxpNciHal_process_ext_cmd_rsp(nxpncihal_ctrl.cmd_len,
                                           nxpncihal_ctrl.p_cmd_data);
  if (NFCSTATUS_FAILED != status) {
    /* Create the local semaphore */
    if (phNxpNciHal_init_cb_data(&nxpncihal_ctrl.ext_cb_data, NULL) !=
        NFCSTATUS_SUCCESS) {
      NXPLOG_NCIHAL_D("Create ext_cb_data failed");
      return NFCSTATUS_FAILED;
    }

    /* By default callback data status set success.
     * This will be set failed by timer callback
     * when timeout is there */
    nxpncihal_ctrl.ext_cb_data.status = NFCSTATUS_SUCCESS;

    /*check whether to wait for notification*/
    if (phNxpNciHal_check_wait_for_ntf()) {
      /* Start timer after writing the data*/
      status =
          phOsalNfc_Timer_Start(timeoutTimerId, HAL_EXTNS_WRITE_RSP_TIMEOUT,
                                &hal_extns_write_rsp_timeout_cb, NULL);
      if (NFCSTATUS_SUCCESS == status) {
        NXPLOG_NCIHAL_D("Response timer started");
      } else {
        NXPLOG_NCIHAL_E("Response timer not started!!!");
        status = NFCSTATUS_FAILED;
        goto clean_and_return;
      }

      /* Wait for notification */
      NXPLOG_NCIHAL_D("Waiting for notification...");
      if (SEM_WAIT(nxpncihal_ctrl.ext_cb_data)) {
        NXPLOG_NCIHAL_E("p_hal_ext->ext_cb_data.sem semaphore error");
        goto clean_and_return;
      }

      /* Stop Timer */
      status = phOsalNfc_Timer_Stop(timeoutTimerId);
      if (NFCSTATUS_SUCCESS == status) {
        NXPLOG_NCIHAL_D("Response timer stopped");
      } else {
        NXPLOG_NCIHAL_E("Response timer stop ERROR!!!");
        status = NFCSTATUS_FAILED;
        goto clean_and_return;
      }

      /*Checking the status if timeout happens*/
      if (nxpncihal_ctrl.ext_cb_data.status != NFCSTATUS_SUCCESS) {
        NXPLOG_NCIHAL_E(
            "Callback Status is failed!! Timer Expired!! Couldn't read it! "
            "0x%x",
            nxpncihal_ctrl.ext_cb_data.status);
        status = NFCSTATUS_FAILED;
        goto clean_and_return;
      }

      NXPLOG_NCIHAL_D("Checking notification...");
      status = NFCSTATUS_SUCCESS;

    clean_and_return:
      phNxpNciHal_cleanup_cb_data(&nxpncihal_ctrl.ext_cb_data);
    }
  }

  HAL_DISABLE_EXT();

  return status;
}

/******************************************************************************
 * Function         phNxpNciHal_check_wait_for_ntf
 *
 * Description      This function checks the condition provided by the user to
 *                  wait for notification or not.
 *
 * Returns          Returns true/false.
 *
 ******************************************************************************/
bool_t phNxpNciHal_check_wait_for_ntf() {
  bool_t status;
  if (nxpncihal_ctrl.is_wait_for_ce_ntf) {
    status = true;
  } else {
    status = false;
  }
  return status;
}

/******************************************************************************
 * Function         hal_extns_write_rsp_timeout_cb
 *
 * Description      Timer call back function
 *
 * Returns          None
 *
 ******************************************************************************/
static void hal_extns_write_rsp_timeout_cb(uint32_t timerId, void* pContext) {
  UNUSED(timerId);
  UNUSED(pContext);
  NXPLOG_NCIHAL_D("hal_extns_write_rsp_timeout_cb - write timeout!!!");
  nxpncihal_ctrl.ext_cb_data.status = NFCSTATUS_FAILED;
  usleep(1);
  sem_post(&(nxpncihal_ctrl.syncSpiNfc));
  SEM_POST(&(nxpncihal_ctrl.ext_cb_data));

  return;
}

/*******************************************************************************
 **
 ** Function:        request_EEPROM()
 **
 ** Description:     get and set EEPROM data
 **                  In case of request_modes GET_EEPROM_DATA or
 *SET_EEPROM_DATA,
 **                   1.caller has to pass the buffer and the length of data
 *required
 **                     to be read/written.
 **                   2.Type of information required to be read/written
 **                     (Example - EEPROM_RF_CFG)
 **
 ** Returns:         Returns NFCSTATUS_SUCCESS if sending cmd is successful and
 **                  status failed if not succesful
 **
 *******************************************************************************/
NFCSTATUS request_EEPROM(phNxpNci_EEPROM_info_t* mEEPROM_info) {
  NXPLOG_NCIHAL_D(
      "%s Enter  request_type : 0x%02x,  request_mode : 0x%02x,  bufflen : "
      "0x%02x",
      __func__, mEEPROM_info->request_type, mEEPROM_info->request_mode,
      mEEPROM_info->bufflen);
  NFCSTATUS status = NFCSTATUS_FAILED;
  uint8_t retry_cnt = 0;
  uint8_t getCfgStartIndex = 0x08;
  uint8_t setCfgStartIndex = 0x07;
  uint8_t memIndex = 0x00;
  uint8_t fieldLen = 0x01;  // Memory field len 1bytes
  char addr[2] = {0};
  uint8_t cur_value = 0, len = 5;
  uint8_t b_position = 0;
  bool_t update_req = false;
  uint8_t set_cfg_cmd_len = 0;
  uint8_t* set_cfg_eeprom, *base_addr;

  mEEPROM_info->update_mode = BITWISE;

  switch (mEEPROM_info->request_type) {
    case EEPROM_RF_CFG:
      memIndex = 0x00;
      fieldLen = 0x20;
      len = fieldLen + 4;  // 4 - numParam+2add+val
      addr[0] = 0xA0;
      addr[1] = 0x14;
      mEEPROM_info->update_mode = BYTEWISE;
      break;

    case EEPROM_FW_DWNLD:
      fieldLen = 0x20;
      memIndex = 0x0C;
      len = fieldLen + 4;
      addr[0] = 0xA0;
      addr[1] = 0x0F;
      break;

    case EEPROM_WIREDMODE_RESUME_TIMEOUT:
      mEEPROM_info->update_mode = BYTEWISE;
      memIndex = 0x00;
      fieldLen = 0x04;
      len = fieldLen + 4;
      addr[0] = 0xA0;
      addr[1] = 0xFC;
      break;

    case EEPROM_ESE_SVDD_POWER:
      b_position = 0;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0xF2;
      break;
    case EEPROM_ESE_POWER_EXT_PMU:
      mEEPROM_info->update_mode = BYTEWISE;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0xD7;
      break;

    case EEPROM_PROP_ROUTING:
      b_position = 7;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0x98;
      break;

    case EEPROM_ESE_SESSION_ID:
      b_position = 0;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0xEB;
      break;

    case EEPROM_SWP1_INTF:
      b_position = 0;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0xEC;
      break;

    case EEPROM_SWP1A_INTF:
      b_position = 0;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0xD4;
      break;
    case EEPROM_SWP2_INTF:
      b_position = 0;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0xED;
      break;
    case EEPROM_NDEF_INTF_CFG:
      b_position = 0x00;
      memIndex = 0x00;
      addr[0] = 0xA0;
      addr[1] = 0x95;
      break;
    default:
      ALOGE("No valid request information found");
      break;
  }

  uint8_t get_cfg_eeprom[6] = {
      0x20,    0x03,  // get_cfg header
      0x03,           // len of following value
      0x01,           // Num Parameters
      addr[0],        // First byte of Address
      addr[1]         // Second byte of Address
  };

  uint8_t set_cfg_cmd_hdr[7] = {
      0x20,    0x02,  // set_cfg header
      len,            // len of following value
      0x01,           // Num Param
      addr[0],        // First byte of Address
      addr[1],        // Second byte of Address
      fieldLen        // Data len
  };

  set_cfg_cmd_len = sizeof(set_cfg_cmd_hdr) + fieldLen;
  set_cfg_eeprom = (uint8_t*)malloc(set_cfg_cmd_len);
  if (set_cfg_eeprom == NULL) {
    ALOGE("memory allocation failed");
    return status;
  }
  base_addr = set_cfg_eeprom;
  memset(set_cfg_eeprom, 0, set_cfg_cmd_len);
  memcpy(set_cfg_eeprom, set_cfg_cmd_hdr, sizeof(set_cfg_cmd_hdr));

retryget:
  status = phNxpNciHal_send_ext_cmd(sizeof(get_cfg_eeprom), get_cfg_eeprom);
  if (status == NFCSTATUS_SUCCESS) {
    status = nxpncihal_ctrl.p_rx_data[3];
    if (status != NFCSTATUS_SUCCESS) {
      ALOGE("failed to get requested memory address");
    } else if (mEEPROM_info->request_mode == GET_EEPROM_DATA) {
      memcpy(mEEPROM_info->buffer,
             nxpncihal_ctrl.p_rx_data + getCfgStartIndex + memIndex,
             mEEPROM_info->bufflen);
    } else if (mEEPROM_info->request_mode == SET_EEPROM_DATA) {
      // Clear the buffer first
      memset(set_cfg_eeprom + setCfgStartIndex, 0x00,
             (set_cfg_cmd_len - setCfgStartIndex));

      // copy get config data into set_cfg_eeprom
      memcpy(set_cfg_eeprom + setCfgStartIndex,
             nxpncihal_ctrl.p_rx_data + getCfgStartIndex, fieldLen);
      if (mEEPROM_info->update_mode == BITWISE) {
        cur_value =
            (set_cfg_eeprom[setCfgStartIndex + memIndex] >> b_position) & 0x01;
        if (cur_value != mEEPROM_info->buffer[0]) {
          update_req = true;
          if (mEEPROM_info->buffer[0] == 1) {
            set_cfg_eeprom[setCfgStartIndex + memIndex] |= (1 << b_position);
          } else if (mEEPROM_info->buffer[0] == 0) {
            set_cfg_eeprom[setCfgStartIndex + memIndex] &= (~(1 << b_position));
          }
        }
      } else if (mEEPROM_info->update_mode == BYTEWISE) {
        if (memcmp(set_cfg_eeprom + setCfgStartIndex + memIndex,
                   mEEPROM_info->buffer, mEEPROM_info->bufflen)) {
          update_req = true;
          memcpy(set_cfg_eeprom + setCfgStartIndex + memIndex,
                 mEEPROM_info->buffer, mEEPROM_info->bufflen);
        }
      } else {
        ALOGE("%s, invalid update mode", __func__);
      }

      if (update_req) {
      // do set config
      retryset:
        status = phNxpNciHal_send_ext_cmd(set_cfg_cmd_len, set_cfg_eeprom);
        if (status != NFCSTATUS_SUCCESS && retry_cnt < 3) {
          retry_cnt++;
          ALOGE("Set Cfg Retry cnt=%x", retry_cnt);
          goto retryset;
        }
      } else {
        ALOGD("%s: values are same no update required", __func__);
      }
    }
  } else if (retry_cnt < 3) {
    retry_cnt++;
    ALOGE("Get Cfg Retry cnt=%x", retry_cnt);
    goto retryget;
  }

  if (base_addr != NULL) {
    free(base_addr);
    base_addr = NULL;
  }
  retry_cnt = 0;
  return status;
}
/******************************************************************************
 * Function         phNxpNciHal_send_ese_hal_cmd
 *
 * Description      This function send the extension command to NFCC. No
 *                  response is checked by this function but it waits for
 *                  the response to come.
 *
 * Returns          Returns NFCSTATUS_SUCCESS if sending cmd is successful and
 *                  response is received.
 *
 ******************************************************************************/
NFCSTATUS phNxpNciHal_send_ese_hal_cmd(uint16_t cmd_len, uint8_t* p_cmd) {
  NFCSTATUS status = NFCSTATUS_FAILED;
  nxpncihal_ctrl.cmd_len = cmd_len;
  memcpy(nxpncihal_ctrl.p_cmd_data, p_cmd, cmd_len);
  status = phNxpNciHal_process_ext_cmd_rsp(nxpncihal_ctrl.cmd_len,
                                              nxpncihal_ctrl.p_cmd_data);
  return status;
}
/*******************************************************************************
 **
 ** Function:        phNxpNciHal_CheckFwRegFlashRequired()
 **
 ** Description:     Updates FW and Reg configurations if required
 **
 ** Returns:         status
 **
 ********************************************************************************/
int phNxpNciHal_CheckFwRegFlashRequired(uint8_t* fw_update_req,
                                        uint8_t* rf_update_req) {
  int status = NFCSTATUS_OK;
  UNUSED(rf_update_req);
  NXPLOG_NCIHAL_D("phNxpNciHal_CheckFwRegFlashRequired() : enter");
  status = phDnldNfc_InitImgInfo();
  NXPLOG_NCIHAL_E("FW version of the libpn5xx.so binary = 0x%x", wFwVer);
  NXPLOG_NCIHAL_E("FW version found on the device = 0x%x", wFwVerRsp);
  /* Consider for each chip type */
  if (status == NFCSTATUS_SUCCESS)
    *fw_update_req = (((wFwVerRsp & 0x0000FFFF) != wFwVer) ? true : false);
  else
    *fw_update_req = false;

  if (false == *fw_update_req) {
    NXPLOG_NCIHAL_D("FW update not required");
    phDnldNfc_ReSetHwDevHandle();
  }

  NXPLOG_NCIHAL_D("phNxpNciHal_CheckFwRegFlashRequired() : exit - status = %x ",
                  status);
  return status;
}
/******************************************************************************
 * Function         phNxpNciHal_conf_nfc_forum_mode
 *
 * Description      If NFCC is not in Nfc Forum mode, then this function will
 *                  configure it back to the Nfc Forum mode.
 *
 * Returns          none
 *
 ******************************************************************************/
void phNxpNciHal_conf_nfc_forum_mode() {
  uint8_t cmd_get_emvcocfg[] = {0x20, 0x03, 0x03, 0x01, 0xA0, 0x44};
  uint8_t cmd_reset_emvcocfg[8];
  long cmdlen = 8;
  long retlen = 0;

  if (GetNxpByteArrayValue(NAME_NXP_PROP_RESET_EMVCO_CMD,
                           (char *)cmd_reset_emvcocfg, cmdlen, &retlen)) {
  }
  if (retlen != cmdlen) {
    NXPLOG_NCIHAL_E("%s: command is not Valid", __func__);
    return;
  }
  /* Update the flag address from the Nxp config file */
  cmd_get_emvcocfg[4] = cmd_reset_emvcocfg[4];
  cmd_get_emvcocfg[5] = cmd_reset_emvcocfg[5];

  if (NFCSTATUS_SUCCESS ==
      phNxpNciHal_send_ext_cmd(sizeof(cmd_get_emvcocfg), cmd_get_emvcocfg)) {
    if (NFCSTATUS_SUCCESS == nxpncihal_ctrl.p_rx_data[3]) {
      if (0x01 & nxpncihal_ctrl.p_rx_data[8]) {
        if (NFCSTATUS_SUCCESS ==
            phNxpNciHal_send_ext_cmd(sizeof(cmd_reset_emvcocfg),
                                     cmd_reset_emvcocfg)) {
          return;
        }
      } else {
        return;
      }
    }
  }
  NXPLOG_NCIHAL_E("%s: failed!!", __func__);
  return;
}