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
|
/*
* Copyright (C) 2010-2014 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.
*/
/*
* Download Component
* Download Interface routines implementation
*/
#include <dlfcn.h>
#include <phDnldNfc_Internal.h>
#include <phNxpConfig.h>
#include <phNxpLog.h>
#include <phTmlNfc.h>
static void*
pFwLibHandle; /* Global firmware lib handle used in this file only */
uint16_t wMwVer = 0; /* Middleware version no */
uint16_t wFwVer = 0; /* Firmware version no */
#if (NFC_NXP_CHIP_TYPE != PN547C2)
uint8_t gRecFWDwnld; // flag set to true to indicate dummy FW download
#endif
static pphDnldNfc_DlContext_t gpphDnldContext = NULL; /* Download contex */
static pphDnldNfc_RspCb_t UserCb; /* Upper layer call back function */
static void* UserCtxt; /* Pointer to upper layer context */
#undef EEPROM_Read_Mem_IMP
/* Function prototype declaration */
static void phDnldNfc_ReadComplete(void* pContext, NFCSTATUS status,
void* pInfo);
/*******************************************************************************
**
** Function phDnldNfc_Reset
**
** Description Performs a soft reset of the download module
**
** Parameters pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - reset request to NFCC is successful
** NFCSTATUS_FAILED - reset request failed due to internal
** error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_Reset(pphDnldNfc_RspCb_t pNotify, void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pNotify) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTNone;
(gpphDnldContext->tCmdId) = PH_DL_CMD_RESET;
(gpphDnldContext->tRspBuffInfo.pBuff) = NULL;
(gpphDnldContext->tRspBuffInfo.wLen) = 0;
(gpphDnldContext->tUserData.pBuff) = NULL;
(gpphDnldContext->tUserData.wLen) = 0;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventReset);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("Reset Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("Reset Request Failed!!");
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_GetVersion
**
** Description Retrieves Hardware version, ROM Code version, Protected Data
** version, Trim data version, User data version, and Firmware
** version information
**
** Parameters pVersionInfo - response buffer which gets updated with
** complete version info from NFCC
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - GetVersion request to NFCC is successful
** NFCSTATUS_FAILED - GetVersion request failed due to internal
** error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_GetVersion(pphDnldNfc_Buff_t pVersionInfo,
pphDnldNfc_RspCb_t pNotify, void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pVersionInfo) || (NULL == pNotify) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if ((NULL != pVersionInfo->pBuff) && (0 != pVersionInfo->wLen)) {
(gpphDnldContext->tRspBuffInfo.pBuff) = pVersionInfo->pBuff;
(gpphDnldContext->tRspBuffInfo.wLen) = pVersionInfo->wLen;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTNone;
(gpphDnldContext->tCmdId) = PH_DL_CMD_GETVERSION;
(gpphDnldContext->tUserData.pBuff) = NULL;
(gpphDnldContext->tUserData.wLen) = 0;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventGetVer);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("GetVersion Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("GetVersion Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Invalid Buff Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_GetSessionState
**
** Description Retrieves the current session state of NFCC
**
** Parameters pSession - response buffer which gets updated with complete
** version info from NFCC
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - GetSessionState request to NFCC is
** successful
** NFCSTATUS_FAILED - GetSessionState request failed due to
** internal error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_GetSessionState(pphDnldNfc_Buff_t pSession,
pphDnldNfc_RspCb_t pNotify,
void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pSession) || (NULL == pNotify) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if ((NULL != pSession->pBuff) && (0 != pSession->wLen)) {
(gpphDnldContext->tRspBuffInfo.pBuff) = pSession->pBuff;
(gpphDnldContext->tRspBuffInfo.wLen) = pSession->wLen;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTNone;
(gpphDnldContext->tCmdId) = PH_DL_CMD_GETSESSIONSTATE;
(gpphDnldContext->tUserData.pBuff) = NULL;
(gpphDnldContext->tUserData.wLen) = 0;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus =
phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventGetSesnSt);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("GetSessionState Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("GetSessionState Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Invalid Buff Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_CheckIntegrity
**
** Description Inspects the integrity of EEPROM and FLASH contents of the
** NFCC, provides CRC for each section
** NOTE: The user data section CRC is valid only after fresh
** download
**
** Parameters bChipVer - current ChipVersion for including additional
** parameters in request payload
** pCRCData - response buffer which gets updated with
** respective section CRC status and CRC bytes from
** NFCC
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - CheckIntegrity request is successful
** NFCSTATUS_FAILED - CheckIntegrity request failed due to
** internal error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_CheckIntegrity(uint8_t bChipVer, pphDnldNfc_Buff_t pCRCData,
pphDnldNfc_RspCb_t pNotify, void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pNotify) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if ((PHDNLDNFC_HWVER_MRA2_1 == bChipVer) ||
(PHDNLDNFC_HWVER_MRA2_2 == bChipVer)
#if (NFC_NXP_CHIP_TYPE == PN551)
|| (PHDNLDNFC_HWVER_PN551_MRA1_0 == bChipVer)
#elif (NFC_NXP_CHIP_TYPE == PN548C2)
|| (PHDNLDNFC_HWVER_PN548AD_MRA1_0 == bChipVer)
#elif (NFC_NXP_CHIP_TYPE == PN553)
|| (PHDNLDNFC_HWVER_PN553_MRA1_0 == bChipVer) ||
(PHDNLDNFC_HWVER_PN553_MRA1_0_UPDATED & bChipVer)
#endif
) {
(gpphDnldContext->FrameInp.Type) = phDnldNfc_ChkIntg;
} else {
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTNone;
}
if ((NULL != pCRCData->pBuff) && (0 != pCRCData->wLen)) {
(gpphDnldContext->tRspBuffInfo.pBuff) = pCRCData->pBuff;
(gpphDnldContext->tRspBuffInfo.wLen) = pCRCData->wLen;
(gpphDnldContext->tCmdId) = PH_DL_CMD_CHECKINTEGRITY;
(gpphDnldContext->tUserData.pBuff) = NULL;
(gpphDnldContext->tUserData.wLen) = 0;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus =
phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventIntegChk);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("CheckIntegrity Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("CheckIntegrity Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Invalid Buff Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_ReadLog
**
** Description Retrieves log data from EEPROM
**
** Parameters pData - response buffer which gets updated with data from
** EEPROM
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - Read request to NFCC is successful
** NFCSTATUS_FAILED - Read request failed due to internal error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_ReadLog(pphDnldNfc_Buff_t pData, pphDnldNfc_RspCb_t pNotify,
void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pNotify) || (NULL == pData) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if ((NULL != pData->pBuff) && (0 != pData->wLen)) {
(gpphDnldContext->tCmdId) = PH_DL_CMD_READ;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTRead;
(gpphDnldContext->FrameInp.dwAddr) = PHDNLDNFC_EEPROM_LOG_START_ADDR;
(gpphDnldContext->tRspBuffInfo.pBuff) = pData->pBuff;
(gpphDnldContext->tRspBuffInfo.wLen) = pData->wLen;
(gpphDnldContext->tUserData.pBuff) = NULL;
(gpphDnldContext->tUserData.wLen) = 0;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
memset(&(gpphDnldContext->tRWInfo), 0,
sizeof(gpphDnldContext->tRWInfo));
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventRead);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("Read Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("Read Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Invalid Buff Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_Write
**
** Description Writes requested data of length len to desired EEPROM/FLASH
** address
**
** Parameters bRecoverSeq - flag to indicate whether recover sequence data
** needs to be written or not
** pData - data buffer to write into EEPROM/FLASH by user
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - Write request to NFCC is successful
** NFCSTATUS_FAILED - Write request failed due to internal
** error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_Write(bool_t bRecoverSeq, pphDnldNfc_Buff_t pData,
pphDnldNfc_RspCb_t pNotify, void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
uint8_t* pImgPtr = NULL;
uint16_t wLen = 0;
phDnldNfc_Buff_t tImgBuff;
if ((NULL == pNotify) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if (NULL != pData) {
pImgPtr = pData->pBuff;
wLen = pData->wLen;
} else {
if (bRecoverSeq == false) {
pImgPtr = (uint8_t*)gpphDnldContext->nxp_nfc_fw;
wLen = gpphDnldContext->nxp_nfc_fw_len;
} else {
if (PH_DL_STATUS_PLL_ERROR == (gpphDnldContext->tLastStatus)) {
wStatus = phDnldNfc_LoadRecInfo();
} else if (PH_DL_STATUS_SIGNATURE_ERROR ==
(gpphDnldContext->tLastStatus)) {
wStatus = phDnldNfc_LoadPKInfo();
} else {
}
if (NFCSTATUS_SUCCESS == wStatus) {
pImgPtr = (uint8_t*)gpphDnldContext->nxp_nfc_fwp;
wLen = gpphDnldContext->nxp_nfc_fwp_len;
} else {
NXPLOG_FWDNLD_E("Platform Recovery Image extraction Failed!!");
pImgPtr = NULL;
wLen = 0;
}
}
}
if ((NULL != pImgPtr) && (0 != wLen)) {
tImgBuff.pBuff = pImgPtr;
tImgBuff.wLen = wLen;
(gpphDnldContext->tCmdId) = PH_DL_CMD_WRITE;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTWrite;
(gpphDnldContext->tRspBuffInfo.pBuff) = NULL;
(gpphDnldContext->tRspBuffInfo.wLen) = 0;
(gpphDnldContext->tUserData.pBuff) = pImgPtr;
(gpphDnldContext->tUserData.wLen) = wLen;
(gpphDnldContext->bResendLastFrame) = false;
memset(&(gpphDnldContext->tRWInfo), 0,
sizeof(gpphDnldContext->tRWInfo));
(gpphDnldContext->tRWInfo.bFirstWrReq) = true;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventWrite);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("Write Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("Write Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Download Image Primitives extraction failed!!");
wStatus = NFCSTATUS_FAILED;
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_Log
**
** Description Provides a full page free write to EEPROM
**
** Parameters pData - data buffer to write into EEPROM/FLASH by user
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - Write request to NFCC is successful
** NFCSTATUS_FAILED - Write request failed due to internal
** error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific error
**
*******************************************************************************/
NFCSTATUS phDnldNfc_Log(pphDnldNfc_Buff_t pData, pphDnldNfc_RspCb_t pNotify,
void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pNotify) || (NULL == pData) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if ((NULL != (pData->pBuff)) &&
((0 != (pData->wLen) && (PHDNLDNFC_MAX_LOG_SIZE >= (pData->wLen))))) {
(gpphDnldContext->tCmdId) = PH_DL_CMD_LOG;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTLog;
(gpphDnldContext->tRspBuffInfo.pBuff) = NULL;
(gpphDnldContext->tRspBuffInfo.wLen) = 0;
(gpphDnldContext->tUserData.pBuff) = (pData->pBuff);
(gpphDnldContext->tUserData.wLen) = (pData->wLen);
memset(&(gpphDnldContext->tRWInfo), 0,
sizeof(gpphDnldContext->tRWInfo));
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventLog);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("Log Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("Log Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Invalid Input Parameters for Log!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_Force
**
** Description Used as an emergency recovery procedure for NFCC due to
** corrupt settings of system platform specific parameters by
** the host
**
** Parameters pInputs - input buffer which contains clk src & clk freq
** settings for desired platform
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - Emergency Recovery request is successful
** NFCSTATUS_FAILED - Emergency Recovery failed due to internal
** error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_Force(pphDnldNfc_Buff_t pInputs, pphDnldNfc_RspCb_t pNotify,
void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
uint8_t bClkSrc = 0x00, bClkFreq = 0x00;
uint8_t bPldVal[3] = {
0x11, 0x00, 0x00}; /* default values to be used if input not provided */
if ((NULL == pNotify) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
(gpphDnldContext->tCmdId) = PH_DL_CMD_FORCE;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTForce;
(gpphDnldContext->tRspBuffInfo.pBuff) = NULL;
(gpphDnldContext->tRspBuffInfo.wLen) = 0;
if ((0 != (pInputs->wLen)) || (NULL != (pInputs->pBuff))) {
if (CLK_SRC_XTAL == (pInputs->pBuff[0])) {
bClkSrc = phDnldNfc_ClkSrcXtal;
} else if (CLK_SRC_PLL == (pInputs->pBuff[0])) {
bClkSrc = phDnldNfc_ClkSrcPLL;
if (CLK_FREQ_13MHZ == (pInputs->pBuff[1])) {
bClkFreq = phDnldNfc_ClkFreq_13Mhz;
} else if (CLK_FREQ_19_2MHZ == (pInputs->pBuff[1])) {
bClkFreq = phDnldNfc_ClkFreq_19_2Mhz;
} else if (CLK_FREQ_24MHZ == (pInputs->pBuff[1])) {
bClkFreq = phDnldNfc_ClkFreq_24Mhz;
} else if (CLK_FREQ_26MHZ == (pInputs->pBuff[1])) {
bClkFreq = phDnldNfc_ClkFreq_26Mhz;
} else if (CLK_FREQ_38_4MHZ == (pInputs->pBuff[1])) {
bClkFreq = phDnldNfc_ClkFreq_38_4Mhz;
} else if (CLK_FREQ_52MHZ == (pInputs->pBuff[1])) {
bClkFreq = phDnldNfc_ClkFreq_52Mhz;
} else {
NXPLOG_FWDNLD_E(
"Invalid Clk Frequency !! Using default value of 19.2Mhz..");
bClkFreq = phDnldNfc_ClkFreq_19_2Mhz;
}
} else if (CLK_SRC_PADDIRECT == (pInputs->pBuff[0])) {
bClkSrc = phDnldNfc_ClkSrcPad;
} else {
NXPLOG_FWDNLD_E("Invalid Clk src !! Using default value of PLL..");
bClkSrc = phDnldNfc_ClkSrcPLL;
}
bPldVal[0] = 0U;
bPldVal[0] = ((bClkSrc << 3U) | bClkFreq);
} else {
NXPLOG_FWDNLD_E("Clk src inputs not provided!! Using default values..");
}
(gpphDnldContext->tUserData.pBuff) = bPldVal;
(gpphDnldContext->tUserData.wLen) = sizeof(bPldVal);
memset(&(gpphDnldContext->tRWInfo), 0, sizeof(gpphDnldContext->tRWInfo));
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventForce);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("Force Command Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("Force Command Request Failed!!");
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_SetHwDevHandle
**
** Description Stores the HwDev handle to download context. The handle is
** required for subsequent operations
**
** Parameters None
**
** Returns None -
**
*******************************************************************************/
void phDnldNfc_SetHwDevHandle(void) {
pphDnldNfc_DlContext_t psDnldContext = NULL;
if (NULL == gpphDnldContext) {
NXPLOG_FWDNLD_D("Allocating Mem for Dnld Context..");
/* Create the memory for Download Mgmt Context */
psDnldContext =
(pphDnldNfc_DlContext_t)malloc(sizeof(phDnldNfc_DlContext_t));
if (psDnldContext != NULL) {
(void)memset((void*)psDnldContext, 0, sizeof(phDnldNfc_DlContext_t));
gpphDnldContext = psDnldContext;
} else {
NXPLOG_FWDNLD_E("Error Allocating Mem for Dnld Context..")
}
} else {
(void)memset((void*)gpphDnldContext, 0, sizeof(phDnldNfc_DlContext_t));
}
return;
}
/*******************************************************************************
**
** Function phDnldNfc_ReSetHwDevHandle
**
** Description Frees the HwDev handle to download context.
**
** Parameters None
**
** Returns None -
**
*******************************************************************************/
void phDnldNfc_ReSetHwDevHandle(void) {
if (gpphDnldContext != NULL) {
NXPLOG_FWDNLD_E("Freeing Mem for Dnld Context..")
free(gpphDnldContext);
gpphDnldContext = NULL;
}
}
/*******************************************************************************
**
** Function phDnldNfc_RawReq
**
** Description Sends raw frame request to NFCC.
** It is currently used for sending an NCI RESET cmd after
** doing a production key update
**
** Parameters pFrameData - input buffer, contains raw frame packet to be
** sent to NFCC
** pRspData - response buffer received from NFCC
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - GetSessionState request to NFCC is
** successful
** NFCSTATUS_FAILED - GetSessionState request failed due to
** internal error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_RawReq(pphDnldNfc_Buff_t pFrameData,
pphDnldNfc_Buff_t pRspData,
pphDnldNfc_RspCb_t pNotify, void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pFrameData) || (NULL == pNotify) || (NULL == pRspData) ||
(NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Raw Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if (((NULL != pFrameData->pBuff) && (0 != pFrameData->wLen)) &&
((NULL != pRspData->pBuff) && (0 != pRspData->wLen))) {
(gpphDnldContext->tRspBuffInfo.pBuff) = pRspData->pBuff;
(gpphDnldContext->tRspBuffInfo.wLen) = pRspData->wLen;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTRaw;
(gpphDnldContext->tCmdId) = PH_DL_CMD_NONE;
(gpphDnldContext->tUserData.pBuff) = pFrameData->pBuff;
(gpphDnldContext->tUserData.wLen) = pFrameData->wLen;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventRaw);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("RawFrame Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("RawFrame Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Invalid Buff Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
}
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_InitImgInfo
**
** Description Extracts image information and stores it in respective
** variables, to be used internally for write operation
**
** Parameters None
**
** Returns NFC status
**
*******************************************************************************/
NFCSTATUS phDnldNfc_InitImgInfo(void) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
uint8_t* pImageInfo = NULL;
uint16_t ImageInfoLen = 0;
char fwFileName[256];
char fwpathName[256];
char* pathName = NULL;
/* if memory is not allocated then allocate memory for download context
* structure */
phDnldNfc_SetHwDevHandle();
/*Read Firmware file name from config file*/
if (GetNxpStrValue(NAME_NXP_FW_NAME, fwFileName, sizeof(fwFileName)) ==
true) {
strcpy(fwpathName, FW_DLL_ROOT_DIR);
strncat(fwpathName, fwFileName, strlen(fwFileName));
pathName = fwpathName;
}
/* load the library and get the image info pointer */
#if (NFC_NXP_CHIP_TYPE != PN547C2)
if (gRecFWDwnld == true)
wStatus = phDnldNfc_LoadRecoveryFW(pathName, &pImageInfo, &ImageInfoLen);
else
#endif
wStatus = phDnldNfc_LoadFW(pathName, &pImageInfo, &ImageInfoLen);
NXPLOG_FWDNLD_E("FW Image Length - ImageInfoLen %d", ImageInfoLen);
NXPLOG_FWDNLD_E("FW Image Info Pointer - pImageInfo %p", pImageInfo);
if ((pImageInfo == NULL) || (ImageInfoLen == 0)) {
NXPLOG_FWDNLD_E(
"Image extraction Failed - invalid imginfo or imginfolen!!");
wStatus = NFCSTATUS_FAILED;
}
if (wStatus != NFCSTATUS_SUCCESS) {
NXPLOG_FWDNLD_E("Error loading libpn54x_fw !!\n");
}
/* get the MW version */
if (NFCSTATUS_SUCCESS == wStatus) {
// NXPLOG_FWDNLD_D("MW Major Version Num - %x",NXP_MW_VERSION_MAJ);
// NXPLOG_FWDNLD_D("MW Minor Version Num - %x",NXP_MW_VERSION_MIN);
wMwVer = (((uint16_t)(NXP_MW_VERSION_MAJ) << 8U) | (NXP_MW_VERSION_MIN));
}
if (NFCSTATUS_SUCCESS == wStatus) {
gpphDnldContext->nxp_nfc_fw = (uint8_t*)pImageInfo;
gpphDnldContext->nxp_nfc_fw_len = ImageInfoLen;
if ((NULL != gpphDnldContext->nxp_nfc_fw) &&
(0 != gpphDnldContext->nxp_nfc_fw_len)) {
NXPLOG_FWDNLD_E("FW Major Version Num - %x",
gpphDnldContext->nxp_nfc_fw[5]);
NXPLOG_FWDNLD_E("FW Minor Version Num - %x",
gpphDnldContext->nxp_nfc_fw[4]);
NXPLOG_FWDNLD_E("FW Image Length - %d", ImageInfoLen);
NXPLOG_FWDNLD_E("FW Image Info Pointer - %p", pImageInfo);
/* get the FW version */
wFwVer = (((uint16_t)(gpphDnldContext->nxp_nfc_fw[5]) << 8U) |
(gpphDnldContext->nxp_nfc_fw[4]));
wStatus = NFCSTATUS_SUCCESS;
} else {
NXPLOG_FWDNLD_E("Image details extraction Failed!!");
wStatus = NFCSTATUS_FAILED;
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_LoadRecInfo
**
** Description Extracts recovery sequence image information and stores it
** in respective variables, to be used internally for write
** operation
**
** Parameters None
**
** Returns NFC status
**
*******************************************************************************/
NFCSTATUS phDnldNfc_LoadRecInfo(void) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
uint8_t* pImageInfo = NULL;
uint16_t ImageInfoLen = 0;
/* if memory is not allocated then allocate memory for donwload context
* structure */
phDnldNfc_SetHwDevHandle();
#if (NFC_NXP_CHIP_TYPE != PN547C2)
if (gRecFWDwnld == true)
wStatus =
phDnldNfc_LoadRecoveryFW(PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen);
else
#endif
wStatus = phDnldNfc_LoadFW(PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen);
if ((pImageInfo == NULL) || (ImageInfoLen == 0)) {
NXPLOG_FWDNLD_E(
"Image extraction Failed - invalid imginfo or imginfolen!!");
wStatus = NFCSTATUS_FAILED;
}
/* load the PLL recovery image library */
if (wStatus != NFCSTATUS_SUCCESS) {
NXPLOG_FWDNLD_E("Error loading libpn54x_fw_platform !!\n");
}
if (NFCSTATUS_SUCCESS == wStatus) {
/* fetch the PLL recovery image pointer and the image length */
gpphDnldContext->nxp_nfc_fwp = (uint8_t*)pImageInfo;
gpphDnldContext->nxp_nfc_fwp_len = ImageInfoLen;
if ((NULL != gpphDnldContext->nxp_nfc_fwp) &&
(0 != gpphDnldContext->nxp_nfc_fwp_len)) {
NXPLOG_FWDNLD_D("Recovery Image Length - %d", ImageInfoLen);
NXPLOG_FWDNLD_D("Recovery Image Info Pointer - %p", pImageInfo);
wStatus = NFCSTATUS_SUCCESS;
} else {
NXPLOG_FWDNLD_E("Recovery Image details extraction Failed!!");
wStatus = NFCSTATUS_FAILED;
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_LoadPKInfo
**
** Description Extracts production sequence image information and stores it
** in respective variables, to be used internally for write
** operation
**
** Parameters None
**
** Returns NFC status
**
*******************************************************************************/
NFCSTATUS phDnldNfc_LoadPKInfo(void) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
uint8_t* pImageInfo = NULL;
uint16_t ImageInfoLen = 0;
/* if memory is not allocated then allocate memory for donwload context
* structure */
phDnldNfc_SetHwDevHandle();
/* load the PKU image library */
#if (NFC_NXP_CHIP_TYPE != PN547C2)
if (gRecFWDwnld == true)
wStatus =
phDnldNfc_LoadRecoveryFW(PKU_LIB_PATH, &pImageInfo, &ImageInfoLen);
else
#endif
wStatus = phDnldNfc_LoadFW(PKU_LIB_PATH, &pImageInfo, &ImageInfoLen);
if ((pImageInfo == NULL) || (ImageInfoLen == 0)) {
NXPLOG_FWDNLD_E(
"Image extraction Failed - invalid imginfo or imginfolen!!");
wStatus = NFCSTATUS_FAILED;
}
if (wStatus != NFCSTATUS_SUCCESS) {
NXPLOG_FWDNLD_E("Error loading libpn54x_fw_pku !!\n");
}
if (NFCSTATUS_SUCCESS == wStatus) {
/* fetch the PKU image pointer and the image length */
gpphDnldContext->nxp_nfc_fwp = (uint8_t*)pImageInfo;
gpphDnldContext->nxp_nfc_fwp_len = ImageInfoLen;
if ((NULL != gpphDnldContext->nxp_nfc_fwp) &&
(0 != gpphDnldContext->nxp_nfc_fwp_len)) {
NXPLOG_FWDNLD_D("PKU Image Length - %d", ImageInfoLen);
NXPLOG_FWDNLD_D("PKU Image Info Pointer - %p", pImageInfo);
wStatus = NFCSTATUS_SUCCESS;
} else {
NXPLOG_FWDNLD_E("PKU Image details extraction Failed!!");
wStatus = NFCSTATUS_FAILED;
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_CloseFwLibHandle
**
** Description Closes previously opened fw library handle as part of
** dynamic loader processing
**
** Parameters None
**
** Returns None
**
*******************************************************************************/
void phDnldNfc_CloseFwLibHandle(void) {
NFCSTATUS wStatus;
wStatus = phDnldNfc_UnloadFW();
if (wStatus != NFCSTATUS_SUCCESS) {
NXPLOG_FWDNLD_E("free library FAILED !!\n");
} else {
NXPLOG_FWDNLD_E("free library SUCCESS !!\n");
}
return;
}
/*******************************************************************************
**
** Function phDnldNfc_LoadFW
**
** Description Load the firmware version form firmware lib
**
** Parameters pathName - Firmware image path
** pImgInfo - Firmware image handle
** pImgInfoLen - Firmware image length
**
** Returns NFC status
**
*******************************************************************************/
NFCSTATUS phDnldNfc_LoadFW(const char* pathName, uint8_t** pImgInfo,
uint16_t* pImgInfoLen) {
void* pImageInfo = NULL;
void* pImageInfoLen = NULL;
if (pathName == NULL) {
#if (NFC_NXP_CHIP_TYPE == PN548C2)
pathName = "/system/vendor/firmware/libpn548ad_fw.so";
#elif (NFC_NXP_CHIP_TYPE == PN551)
pathName = "/system/vendor/firmware/libpn551_fw.so";
#elif (NFC_NXP_CHIP_TYPE == PN553)
pathName = "/system/vendor/firmware/libpn553_fw.so";
#else
pathName = "/system/vendor/firmware/libpn547_fw.so";
#endif
}
/* check if the handle is not NULL then free the library */
if (pFwLibHandle != NULL) {
phDnldNfc_UnloadFW();
pFwLibHandle = NULL;
}
/* load the DLL file */
pFwLibHandle = dlopen(pathName, RTLD_LAZY);
NXPLOG_FWDNLD_D("@@@%s", pathName);
/* if library load failed then handle will be NULL */
if (pFwLibHandle == NULL) {
NXPLOG_FWDNLD_E(
"NULL handler : unable to load the library file, specify correct path");
return NFCSTATUS_FAILED;
}
dlerror(); /* Clear any existing error */
/* load the address of download image pointer and image size */
pImageInfo = (void*)dlsym(pFwLibHandle, "gphDnldNfc_DlSeq");
if (dlerror() || (NULL == pImageInfo)) {
NXPLOG_FWDNLD_E("Problem loading symbol : gphDnldNfc_DlSeq");
return NFCSTATUS_FAILED;
}
(*pImgInfo) = (*(uint8_t**)pImageInfo);
pImageInfoLen = (void*)dlsym(pFwLibHandle, "gphDnldNfc_DlSeqSz");
if (dlerror() || (NULL == pImageInfoLen)) {
NXPLOG_FWDNLD_E("Problem loading symbol : gphDnldNfc_DlSeqSz");
return NFCSTATUS_FAILED;
}
(*pImgInfoLen) = (uint16_t)(*((uint16_t*)pImageInfoLen));
return NFCSTATUS_SUCCESS;
}
#if (NFC_NXP_CHIP_TYPE != PN547C2)
/*******************************************************************************
**
** Function phDnldNfc_LoadRecoveryFW
**
** Description Load the dummy firmware version form firmware lib for
** recovery. This will change the FW version of the NFCC
** firmware and enable flashing of firmware of same version.
**
** Parameters pathName - Firmware image path
** pImgInfo - Firmware image handle
** pImgInfoLen - Firmware image length
**
** Returns NFCSTATUS
**
*******************************************************************************/
NFCSTATUS phDnldNfc_LoadRecoveryFW(const char* pathName, uint8_t** pImgInfo,
uint16_t* pImgInfoLen) {
void* pImageInfo = NULL;
void* pImageInfoLen = NULL;
/* check for path name */
if (pathName == NULL) {
#if (NFC_NXP_CHIP_TYPE == PN548C2)
pathName = "/system/vendor/firmware/libpn548ad_fw.so";
#elif (NFC_NXP_CHIP_TYPE == PN551)
pathName = "/system/vendor/firmware/libpn551_fw.so";
#elif (NFC_NXP_CHIP_TYPE == PN553)
pathName = "/system/vendor/firmware/libpn553_fw.so";
#else
pathName = "/system/vendor/firmware/libpn547_fw.so";
#endif
}
/* check if the handle is not NULL then free the library */
if (pFwLibHandle != NULL) {
phDnldNfc_UnloadFW();
pFwLibHandle = NULL;
}
/* load the DLL file */
pFwLibHandle = dlopen(pathName, RTLD_LAZY);
NXPLOG_FWDNLD_D("phDnldNfc_LoadRecoveryFW %s ", pathName);
/* if library load failed then handle will be NULL */
if (pFwLibHandle == NULL) {
NXPLOG_FWDNLD_E(
"NULL handler : unable to load the library file, specify correct path");
return NFCSTATUS_FAILED;
}
dlerror(); /* Clear any existing error */
/* load the address of download image pointer and image size */
pImageInfo = (void*)dlsym(pFwLibHandle, "gphDnldNfc_DummyDlSeq");
if (dlerror() || (NULL == pImageInfo)) {
NXPLOG_FWDNLD_E("Problem loading symbol : gphDnldNfc_DummyDlSeq");
return NFCSTATUS_FAILED;
}
(*pImgInfo) = (*(uint8_t**)pImageInfo);
pImageInfoLen = (void*)dlsym(pFwLibHandle, "gphDnldNfc_DlSeqDummyFwSz");
if (dlerror() || (NULL == pImageInfoLen)) {
NXPLOG_FWDNLD_E("Problem loading symbol : gphDnldNfc_DlSeqDummyFwSz");
return NFCSTATUS_FAILED;
}
(*pImgInfoLen) = (uint16_t)(*((uint16_t*)pImageInfoLen));
return NFCSTATUS_SUCCESS;
}
#endif
/*******************************************************************************
**
** Function phDnldNfc_UnloadFW
**
** Description Deinit the firmware handle
**
** Parameters None
**
** Returns NFC status
**
*******************************************************************************/
NFCSTATUS phDnldNfc_UnloadFW(void) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
int32_t status;
/* check if the handle is not NULL then free the library */
if (pFwLibHandle != NULL) {
status = dlclose(pFwLibHandle);
pFwLibHandle = NULL;
dlerror(); /* Clear any existing error */
if (status != 0) {
wStatus = NFCSTATUS_FAILED;
NXPLOG_FWDNLD_E("Free library file failed");
}
}
return wStatus;
}
#ifdef EEPROM_Read_Mem_IMP
/*******************************************************************************
**
** Function phDnldNfc_ReadMem
**
** Description Dumps the contents of EEPROM. The handle is required for
** subsequent operations
**
** Parameters pHwRef - pointer to the hardware device
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - request to NFCC is successful
** NFCSTATUS_FAILED - request failed due to internal error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_ReadMem(void* pHwRef, pphDnldNfc_RspCb_t pNotify,
void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
uint32_t wAddr = 0x2011C0; /* eeprom platform specific area start address */
uint32_t wRdAddr = 0;
uint8_t* pAddr;
static uint8_t bRdData[3519]; /* buffer to hold the read data */
static phDnldNfc_Buff_t Data;
if ((NULL == pNotify) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
/* Call Tml Ioctl to enable download mode */
wStatus = phTmlNfc_IoCtl(phTmlNfc_e_EnableDownloadMode);
if (NFCSTATUS_SUCCESS == wStatus) {
/* Set the obtained device handle to download module */
phDnldNfc_SetHwDevHandle();
} else {
wStatus = NFCSTATUS_FAILED;
}
if (NFCSTATUS_SUCCESS == wStatus) {
pAddr = (uint8_t*)&wAddr;
wRdAddr = (pAddr[3]);
wRdAddr <<= 8;
wRdAddr |= (pAddr[2]);
wRdAddr <<= 8;
wRdAddr |= (pAddr[1]);
wRdAddr <<= 8;
wRdAddr |= (pAddr[0]);
Data.pBuff = bRdData;
Data.wLen = sizeof(bRdData);
UserCb = pNotify;
UserCtxt = pContext;
wStatus = phDnldNfc_Read(&Data, wRdAddr,
(pphDnldNfc_RspCb_t)phDnldNfc_ReadComplete,
gpphDnldContext);
} else {
Data.pBuff = NULL;
Data.wLen = 0;
wStatus = NFCSTATUS_FAILED;
}
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("Read Request submitted successfully..");
} else {
NXPLOG_FWDNLD_E("Read Request submission failed!!");
}
}
return wStatus;
}
/*******************************************************************************
**
** Function phDnldNfc_ReadComplete
**
** Description Read complete
**
** Parameters pContext - caller layer context
** status - status of the transaction
** pInfo - transaction info
**
** Returns None
**
*******************************************************************************/
static void phDnldNfc_ReadComplete(void* pContext, NFCSTATUS status,
void* pInfo) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
UNUSED(pContext);
/* Call Tml Ioctl to enable/restore normal mode */
wStatus = phTmlNfc_IoCtl(phTmlNfc_e_EnableNormalMode);
if (NFCSTATUS_SUCCESS == wStatus) {
NXPLOG_FWDNLD_D("Read Done!!");
}
UserCb(&UserCtxt, status, pInfo);
return;
}
/*******************************************************************************
**
** Function phDnldNfc_Read
**
** Description Retrieves requested data of specified length from desired
** EEPROM address
**
** Parameters pData - response buffer which gets updated with data from
** EEPROM
** dwRdAddr - EEPROM address for data read
** pNotify - notify caller after getting response
** pContext - caller context
**
** Returns NFC status:
** NFCSTATUS_SUCCESS - Read request to NFCC is successful
** NFCSTATUS_FAILED - Read request failed due to internal error
** NFCSTATUS_NOT_ALLOWED - command not allowed
** Other command specific errors
**
*******************************************************************************/
NFCSTATUS phDnldNfc_Read(pphDnldNfc_Buff_t pData, uint32_t dwRdAddr,
pphDnldNfc_RspCb_t pNotify, void* pContext) {
NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
if ((NULL == pNotify) || (NULL == pData) || (NULL == pContext)) {
NXPLOG_FWDNLD_E("Invalid Input Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
} else {
if (phDnldNfc_TransitionIdle != gpphDnldContext->tDnldInProgress) {
NXPLOG_FWDNLD_E("Dnld Cmd Request in Progress..Cannot Continue!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_BUSY);
} else {
if ((NULL != pData->pBuff) && (0 != pData->wLen)) {
(gpphDnldContext->tCmdId) = PH_DL_CMD_READ;
(gpphDnldContext->FrameInp.Type) = phDnldNfc_FTRead;
(gpphDnldContext->FrameInp.dwAddr) = dwRdAddr;
(gpphDnldContext->tRspBuffInfo.pBuff) = pData->pBuff;
(gpphDnldContext->tRspBuffInfo.wLen) = pData->wLen;
(gpphDnldContext->tUserData.pBuff) = NULL;
(gpphDnldContext->tUserData.wLen) = 0;
(gpphDnldContext->UserCb) = pNotify;
(gpphDnldContext->UserCtxt) = pContext;
memset(&(gpphDnldContext->tRWInfo), 0,
sizeof(gpphDnldContext->tRWInfo));
wStatus = phDnldNfc_CmdHandler(gpphDnldContext, phDnldNfc_EventRead);
if (NFCSTATUS_PENDING == wStatus) {
NXPLOG_FWDNLD_D("Read Request submitted successfully");
} else {
NXPLOG_FWDNLD_E("Read Request Failed!!");
}
} else {
NXPLOG_FWDNLD_E("Invalid Buff Parameters!!");
wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
}
}
}
return wStatus;
}
#endif
|