• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012-2014 NXP Semiconductors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifdef NXP_HW_SELF_TEST
18 
19 
20 #include <phNxpNciHal_SelfTest.h>
21 #include <phNxpLog.h>
22 #include <pthread.h>
23 #include <phOsalNfc_Timer.h>
24 #include <phNxpConfig.h>
25 
26 #define HAL_WRITE_RSP_TIMEOUT   (2000)   /* Timeout value to wait for response from PN54X */
27 #define HAL_WRITE_MAX_RETRY     (10)
28 
29 /******************* Structures and definitions *******************************/
30 
31 typedef uint8_t (*st_validator_t)(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
32 
33 phAntenna_St_Resp_t phAntenna_resp;
34 
35 typedef struct nci_test_data
36 {
37     nci_data_t cmd;
38     nci_data_t exp_rsp;
39     nci_data_t exp_ntf;
40     st_validator_t rsp_validator;
41     st_validator_t ntf_validator;
42 
43 }nci_test_data_t;
44 
45 /******************* Global variables *****************************************/
46 
47 static int thread_running = 0;
48 static uint32_t timeoutTimerId = 0;
49 static int hal_write_timer_fired = 0;
50 
51 /* TML Context */
52 extern phTmlNfc_Context_t *gpphTmlNfc_Context;
53 
54 /* Global HAL Ref */
55 extern phNxpNciHal_Control_t nxpncihal_ctrl;
56 
57 /* Driver parameters */
58 phLibNfc_sConfig_t   gDrvCfg;
59 
60 NFCSTATUS gtxldo_status = NFCSTATUS_FAILED;
61 NFCSTATUS gagc_value_status = NFCSTATUS_FAILED;
62 NFCSTATUS gagc_nfcld_status = NFCSTATUS_FAILED;
63 NFCSTATUS gagc_differential_status = NFCSTATUS_FAILED;
64 
65 
66 static uint8_t st_validator_testEquals(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
67 static uint8_t st_validator_null(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
68 static uint8_t st_validator_testSWP1_vltg(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
69 static uint8_t st_validator_testAntenna_Txldo(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
70 static uint8_t st_validator_testAntenna_AgcVal(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
71 static uint8_t st_validator_testAntenna_AgcVal_FixedNfcLd(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
72 static uint8_t st_validator_testAntenna_AgcVal_Differential(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
73 
74 #if(NFC_NXP_CHIP_TYPE != PN547C2)
75 NFCSTATUS phNxpNciHal_getPrbsCmd (phNxpNfc_PrbsType_t prbs_type, phNxpNfc_PrbsHwType_t hw_prbs_type,
76         uint8_t tech, uint8_t bitrate, uint8_t *prbs_cmd, uint8_t prbs_cmd_len);
77 #else
78 NFCSTATUS phNxpNciHal_getPrbsCmd (uint8_t tech, uint8_t bitrate, uint8_t *prbs_cmd, uint8_t prbs_cmd_len);
79 #endif
80 /* Test data to validate SWP line 2*/
81 static nci_test_data_t swp2_test_data[] = {
82     {
83         {
84             0x04, {0x20, 0x00, 0x01, 0x00} /* cmd */
85         },
86         {
87 #if(NFC_NXP_CHIP_TYPE != PN547C2)
88             0x06, {0x40, 0x00, 0x03, 0x00, 0x11, 0x00} /* exp_rsp */
89 #else
90             0x06, {0x40, 0x00, 0x03, 0x00, 0x10, 0x00} /* exp_rsp */
91 #endif
92         },
93         {
94             0x00, {0x00} /* ext_ntf */
95         },
96         st_validator_testEquals, /* validator */
97         st_validator_null
98     },
99     {
100         {
101 #if(NFC_NXP_CHIP_TYPE != PN547C2)
102             0x05, {0x20,0x01,0x02,0x00,0x00} /* cmd */
103 #else
104             0x03, {0x20,0x01,0x00}
105 #endif
106         },
107         {
108 #if(NFC_NXP_CHIP_TYPE != PN547C2)
109             0x4, {0x40,0x01,0x19,0x00 } /* exp_rsp */
110 #else
111             0x4, {0x40,0x01,0x17,0x00 }
112 #endif
113         },
114         {
115             0x00, {0x00} /* ext_ntf */
116         },
117         st_validator_testEquals, /* validator */
118         st_validator_null
119     },
120     {
121         {
122             0x03, {0x2F,0x02,0x00} /* cmd */
123         },
124         {
125             0x04, {0x4F,0x02,0x05,0x00} /* exp_rsp */
126         },
127         {
128             0x00, {0x00} /* ext_ntf */
129         },
130         st_validator_testEquals, /* validator */
131         st_validator_null
132     },
133     {
134         {
135             0x04, {0x2F,0x3E,0x01,0x01} /* cmd */
136         },
137         {
138             0x04, {0x4F,0x3E,0x01,0x00} /* exp_rsp */
139         },
140         {
141             0x04, {0x6F,0x3E,0x02,0x00} /* ext_ntf */
142         },
143         st_validator_testEquals, /* validator */
144         st_validator_testEquals
145     },
146 
147 };
148 
149 /* Test data to validate SWP line 1*/
150 static nci_test_data_t swp1_test_data[] = {
151 
152     {
153         {
154             0x04, {0x20, 0x00, 0x01, 0x00} /* cmd */
155         },
156         {
157 #if(NFC_NXP_CHIP_TYPE != PN547C2)
158             0x06, {0x40, 0x00, 0x03, 0x00, 0x11, 0x00} /* exp_rsp */
159 #else
160             0x06, {0x40, 0x00, 0x03, 0x00, 0x10, 0x00} /* exp_rsp */
161 #endif
162         },
163         {
164             0x00, {0x00} /* ext_ntf */
165         },
166         st_validator_testEquals, /* validator */
167         st_validator_null
168     },
169     {
170         {
171 #if(NFC_NXP_CHIP_TYPE != PN547C2)
172             0x05, {0x20,0x01,0x02,0x00,0x00} /* cmd */
173 #else
174             0x03, {0x20,0x01,0x00}
175 #endif
176         },
177         {
178 #if(NFC_NXP_CHIP_TYPE != PN547C2)
179             0x4, {0x40,0x01,0x19,0x00 } /* exp_rsp */
180 #else
181             0x4, {0x40,0x01,0x17,0x00 }
182 #endif
183         },
184         {
185             0x00, {0x00} /* ext_ntf */
186         },
187         st_validator_testEquals, /* validator */
188         st_validator_null
189     },
190     {
191         {
192             0x03, {0x2F,0x02,0x00} /* cmd */
193         },
194         {
195             0x04, {0x4F,0x02,0x05,0x00} /* exp_rsp */
196         },
197         {
198             0x00, {0x00} /* ext_ntf */
199         },
200         st_validator_testEquals, /* validator */
201         st_validator_null
202     },
203     {
204         {
205             0x04, {0x2F,0x3E,0x01,0x00} /* cmd */
206         },
207         {
208             0x04, {0x4F,0x3E,0x01,0x00} /* exp_rsp */
209         },
210         {
211             0x04, {0x6F,0x3E,0x02,0x00} /* ext_ntf */
212         },
213 
214         st_validator_testEquals, /* validator */
215         st_validator_testSWP1_vltg
216     },
217 };
218 
219 static nci_test_data_t prbs_test_data[] = {
220     {
221         {
222             0x04, {0x20,0x00,0x01,0x00} /* cmd */
223         },
224         {
225 #if(NFC_NXP_CHIP_TYPE != PN547C2)
226             0x06, {0x40,0x00,0x03,0x00,0x11,0x00} /* exp_rsp */
227 #else
228             0x06, {0x40,0x00,0x03,0x00,0x10,0x00} /* exp_rsp */
229 #endif
230         },
231         {
232             0x00, {0x00} /* ext_ntf */
233         },
234         st_validator_testEquals, /* validator */
235         st_validator_null
236     },
237     {
238         {
239 #if(NFC_NXP_CHIP_TYPE != PN547C2)
240             0x05, {0x20,0x01,0x02,0x00,0x00} /* cmd */
241 #else
242             0x03, {0x20,0x01,0x00} /* cmd */
243 #endif
244         },
245         {
246 #if(NFC_NXP_CHIP_TYPE != PN547C2)
247             0x4, {0x40,0x01,0x19,0x00 } /* exp_rsp */
248 #else
249             0x4, {0x40,0x01,0x17,0x00 } /* exp_rsp */
250 #endif
251         },
252         {
253             0x00, {0x00} /* ext_ntf */
254         },
255         st_validator_testEquals, /* validator */
256         st_validator_null
257 #if(NFC_NXP_CHIP_TYPE != PN547C2)
258     },
259     {
260         {
261             0x04, {0x2F,0x00,0x01,0x00} /* cmd */
262         },
263         {
264             0x04, {0x4F,0x00,0x01,0x00} /* exp_rsp */
265         },
266         {
267             0x00, {0x00} /* ext_ntf */
268         },
269         st_validator_testEquals, /* validator */
270         st_validator_null
271 #endif
272     }
273 };
274 
275 /* for rf field test, first requires to disable the standby mode */
276 static nci_test_data_t rf_field_on_test_data[] = {
277     {
278         {
279             0x04, {0x20,0x00,0x01,0x00} /* cmd */
280         },
281         {
282 #if(NFC_NXP_CHIP_TYPE != PN547C2)
283             0x06, {0x40,0x00,0x03,0x00,0x11,0x00} /* exp_rsp */
284 #else
285             0x06, {0x40,0x00,0x03,0x00,0x10,0x00} /* exp_rsp */
286 #endif
287         },
288         {
289             0x00, {0x00} /* ext_ntf */
290         },
291         st_validator_testEquals, /* validator */
292         st_validator_null
293     },
294     {
295         {
296 #if(NFC_NXP_CHIP_TYPE != PN547C2)
297             0x05, {0x20,0x01,0x02,0x00,0x00} /* cmd */
298 #else
299             0x03, {0x20,0x01,0x00} /* cmd */
300 #endif
301         },
302         {
303 #if(NFC_NXP_CHIP_TYPE != PN547C2)
304             0x4, {0x40,0x01,0x19,0x00 } /* exp_rsp */
305 #else
306             0x4, {0x40,0x01,0x17,0x00 } /* exp_rsp */
307 #endif
308         },
309         {
310             0x00, {0x00} /* ext_ntf */
311         },
312         st_validator_testEquals, /* validator */
313         st_validator_null
314     },
315 #if(NFC_NXP_CHIP_TYPE != PN547C2)
316     {
317          {
318             0x03, {0x2F,0x02,0x00} /* cmd */
319          },
320          {
321             0x04, {0x4F,0x02,0x05,0x00} /* exp_rsp */
322          },
323          {
324             0x00, {0x00} /* ext_ntf */
325          },
326          st_validator_testEquals, /* validator */
327          st_validator_null
328     },
329     {
330          {
331             0x04, {0x2F,0x00,0x01,0x00} /* cmd */
332          },
333          {
334             0x04, {0x4F,0x00,0x01,0x00} /* exp_rsp */
335          },
336          {
337             0x00, {0x00} /* ext_ntf */
338          },
339          st_validator_testEquals, /* validator */
340          st_validator_null
341     },
342 #endif
343     {
344         {
345 #if(NFC_NXP_CHIP_TYPE != PN547C2)
346             0x05, {0x2F,0x3D,0x02,0x20,0x01} /* cmd */
347 #else
348             0x08, {0x2F,0x3D,0x05,0x20,0x01,0x00,0x00,0x00} /* cmd */
349 #endif
350         },
351         {
352             0x04, {0x4F,0x3D,0x05,0x00} /* exp_rsp */
353         },
354         {
355             0x00, {0x00} /* ext_ntf */
356         },
357         st_validator_testEquals, /* validator */
358         st_validator_null
359 #if(NFC_NXP_CHIP_TYPE != PN547C2)
360     },
361     {
362         {
363             0x04, {0x2F,0x00,0x01,0x01} /* cmd */
364         },
365         {
366             0x04, {0x4F,0x00,0x01,0x00} /* exp_rsp */
367         },
368         {
369             0x00, {0x00} /* ext_ntf */
370         },
371         st_validator_testEquals, /* validator */
372         st_validator_null
373 #endif
374     }
375 };
376 
377 static nci_test_data_t rf_field_off_test_data[] = {
378     {
379         {
380             0x04, {0x20,0x00,0x01,0x00} /* cmd */
381         },
382         {
383 #if(NFC_NXP_CHIP_TYPE != PN547C2)
384             0x06, {0x40,0x00,0x03,0x00,0x11,0x00} /* exp_rsp */
385 #else
386             0x06, {0x40,0x00,0x03,0x00,0x10,0x00} /* exp_rsp */
387 #endif
388         },
389         {
390             0x00, {0x00} /* ext_ntf */
391         },
392         st_validator_testEquals, /* validator */
393         st_validator_null
394     },
395     {
396         {
397 #if(NFC_NXP_CHIP_TYPE != PN547C2)
398             0x05, {0x20,0x01,0x02,0x00,0x00} /* cmd */
399 #else
400             0x03, {0x20,0x01,0x00} /* cmd */
401 #endif
402         },
403         {
404 #if(NFC_NXP_CHIP_TYPE != PN547C2)
405             0x4, {0x40,0x01,0x19,0x00 } /* exp_rsp */
406 #else
407             0x4, {0x40,0x01,0x17,0x00 } /* exp_rsp */
408 #endif
409         },
410         {
411             0x00, {0x00} /* ext_ntf */
412         },
413         st_validator_testEquals, /* validator */
414         st_validator_null
415     },
416 #if(NFC_NXP_CHIP_TYPE != PN547C2)
417     {
418         {
419             0x03, {0x2F,0x02,0x00} /* cmd */
420         },
421         {
422             0x04, {0x4F,0x02,0x05,0x00} /* exp_rsp */
423         },
424         {
425             0x00, {0x00} /* ext_ntf */
426         },
427         st_validator_testEquals, /* validator */
428         st_validator_null
429      },
430      {
431         {
432              0x04, {0x2F,0x00,0x01,0x00} /* cmd */
433         },
434         {
435              0x04, {0x4F,0x00,0x01,0x00} /* exp_rsp */
436         },
437         {
438              0x00, {0x00} /* ext_ntf */
439         },
440         st_validator_testEquals, /* validator */
441         st_validator_null
442      },
443 #endif
444      {
445         {
446 #if(NFC_NXP_CHIP_TYPE != PN547C2)
447             0x05, {0x2F,0x3D,0x02,0x20,0x00} /* cmd */
448 #else
449             0x08, {0x2F,0x3D,0x05,0x20,0x00,0x00,0x00,0x00} /* cmd */
450 #endif
451         },
452         {
453             0x04, {0x4F,0x3D,0x05,0x00} /* exp_rsp */
454         },
455         {
456             0x00, {0x00} /* ext_ntf */
457         },
458         st_validator_testEquals, /* validator */
459         st_validator_null
460 #if(NFC_NXP_CHIP_TYPE != PN547C2)
461      },
462      {
463         {
464             0x04, {0x2F,0x00,0x01,0x01} /* cmd */
465         },
466         {
467             0x04, {0x4F,0x00,0x01,0x00} /* exp_rsp */
468         },
469         {
470             0x00, {0x00} /* ext_ntf */
471         },
472         st_validator_testEquals, /* validator */
473         st_validator_null
474 #endif
475      }
476 };
477 
478 /* Download pin test data 1 */
479 static nci_test_data_t download_pin_test_data1[] = {
480     {
481         {
482             0x04, {0x20, 0x00, 0x01, 0x00} /* cmd */
483         },
484         {
485 #if(NFC_NXP_CHIP_TYPE != PN547C2)
486             0x06, {0x40, 0x00, 0x03, 0x00, 0x11, 0x00} /* exp_rsp */
487 #else
488             0x06, {0x40, 0x00, 0x03, 0x00, 0x10, 0x00} /* exp_rsp */
489 #endif
490         },
491         {
492             0x00, {0x00} /* ext_ntf */
493         },
494         st_validator_testEquals, /* validator */
495         st_validator_null
496     },
497 };
498 
499 /* Download pin test data 2 */
500 static nci_test_data_t download_pin_test_data2[] = {
501     {
502         {
503             0x08, {0x00, 0x04, 0xD0, 0x11, 0x00, 0x00, 0x5B, 0x46} /* cmd */
504         },
505         {
506             0x08, {0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x87, 0x16} /* exp_rsp */
507         },
508         {
509             0x00, {0x00} /* ext_ntf */
510         },
511         st_validator_testEquals, /* validator */
512         st_validator_null
513     },
514 };
515 /* Antenna self test data*/
516 static nci_test_data_t antenna_self_test_data[] = {
517     {
518         {
519             0x04, {0x20,0x00,0x01,0x00} /* cmd */
520         },
521         {
522 #if(NFC_NXP_CHIP_TYPE != PN547C2)
523             0x06, {0x40,0x00,0x03,0x00,0x11,0x00} /* exp_rsp */
524 #else
525             0x06, {0x40,0x00,0x03,0x00,0x10,0x00} /* exp_rsp */
526 #endif
527         },
528         {
529             0x00, {0x00} /* ext_ntf */
530         },
531         st_validator_testEquals, /* validator */
532         st_validator_null
533     },
534     {
535         {
536 #if(NFC_NXP_CHIP_TYPE != PN547C2)
537             0x05, {0x20,0x01,0x02,0x00,0x00} /* cmd */
538 #else
539             0x03, {0x20,0x01,0x00} /* cmd */
540 #endif
541         },
542         {
543 #if(NFC_NXP_CHIP_TYPE != PN547C2)
544             0x4, {0x40,0x01,0x19,0x00 } /* exp_rsp */
545 #else
546             0x4, {0x40,0x01,0x17,0x00 } /* exp_rsp */
547 #endif
548         },
549         {
550             0x00, {0x00} /* ext_ntf */
551         },
552         st_validator_testEquals, /* validator */
553         st_validator_null
554     },
555     {
556         {
557             0x03, {0x2F,0x02,0x00} /* cmd */
558         },
559         {
560             0x04, {0x4F,0x02,0x05,0x00} /* exp_rsp */
561         },
562         {
563             0x00, {0x00} /* ext_ntf */
564         },
565         st_validator_testEquals, /* validator */
566         st_validator_null
567     },
568 #if(NFC_NXP_CHIP_TYPE != PN547C2)
569     {
570         {
571             0x04, {0x2F,0x00,0x01,0x00} /* cmd */
572         },
573         {
574             0x04, {0x4F,0x00,0x01,0x00} /* exp_rsp */
575         },
576         {
577             0x00, {0x00} /* ext_ntf */
578         },
579         st_validator_testEquals, /* validator */
580         st_validator_null
581     },
582 #endif
583     {
584         {
585             0x05, {0x2F, 0x3D, 0x02, 0x01, 0x80} /* TxLDO cureent measurement cmd */
586         },
587         {
588             0x03, {0x4F, 0x3D, 05} /* exp_rsp */
589         },
590         {
591             0x00, {0x00} /* ext_ntf */
592         },
593         st_validator_testAntenna_Txldo,
594         st_validator_null
595     },
596     {
597         {
598 #if(NFC_NXP_CHIP_TYPE != PN547C2)
599             0x07, {0x2F, 0x3D, 0x04, 0x02, 0xC8, 0x60, 0x03} /* AGC measurement cmd */
600 #else
601             0x07, {0x2F, 0x3D, 0x04, 0x02, 0xCD, 0x60, 0x03} /* AGC measurement cmd */
602 #endif
603         },
604         {
605             0x03, {0x4F, 0x3D, 05} /* exp_rsp */
606         },
607         {
608             0x00, {0x00} /* ext_ntf */
609         },
610         st_validator_testAntenna_AgcVal,
611         st_validator_null
612     },
613     {
614         {
615             0x07, {0x2F, 0x3D, 0x04, 0x04, 0x20, 0x08, 0x20} /* AGC with NFCLD measurement cmd */
616         },
617         {
618             0x03, {0x4F, 0x3D, 05} /* exp_rsp */
619         },
620         {
621             0x00, {0x00} /* ext_ntf */
622         },
623         st_validator_testAntenna_AgcVal_FixedNfcLd,
624         st_validator_null
625     },
626     {
627         {
628             0x07, {0x2F, 0x3D, 0x04, 0x08, 0x8C, 0x60, 0x03} /* AGC with NFCLD measurement cmd */
629         },
630         {
631             0x03, {0x4F, 0x3D, 05} /* exp_rsp */
632         },
633         {
634             0x00, {0x00} /* ext_ntf */
635         },
636         st_validator_testAntenna_AgcVal_Differential,
637         st_validator_null
638 #if(NFC_NXP_CHIP_TYPE != PN547C2)
639     },
640     {
641         {
642             0x04, {0x2F,0x00,0x01,0x01} /* cmd */
643         },
644         {
645             0x04, {0x4F,0x00,0x01,0x00} /* exp_rsp */
646         },
647         {
648             0x00, {0x00} /* ext_ntf */
649         },
650         st_validator_testEquals, /* validator */
651         st_validator_null
652 #endif
653     }
654 };
655 
656 
657 /************** Self test functions ***************************************/
658 
659 static uint8_t st_validator_testEquals(nci_data_t *exp, phTmlNfc_TransactInfo_t *act);
660 static void hal_write_cb(void *pContext, phTmlNfc_TransactInfo_t *pInfo);
661 static void hal_write_rsp_timeout_cb(uint32_t TimerId, void *pContext);
662 static void hal_read_cb(void *pContext, phTmlNfc_TransactInfo_t *pInfo);
663 
664 /*******************************************************************************
665 **
666 ** Function         st_validator_null
667 **
668 ** Description      Null Validator
669 **
670 ** Returns          One
671 **
672 *******************************************************************************/
st_validator_null(nci_data_t * exp,phTmlNfc_TransactInfo_t * act)673 static uint8_t st_validator_null(nci_data_t *exp, phTmlNfc_TransactInfo_t *act)
674 {
675     UNUSED(exp);
676     UNUSED(act);
677     return 1;
678 }
679 
680 /*******************************************************************************
681 **
682 ** Function         st_validator_testSWP1_vltg
683 **
684 ** Description      Validator function to validate swp1 connection.
685 **
686 ** Returns          One if successful otherwise Zero.
687 **
688 *******************************************************************************/
st_validator_testSWP1_vltg(nci_data_t * exp,phTmlNfc_TransactInfo_t * act)689 static uint8_t st_validator_testSWP1_vltg(nci_data_t *exp, phTmlNfc_TransactInfo_t *act)
690 {
691     uint8_t result = 0;
692 
693     if(NULL == exp || NULL == act)
694     {
695         return result;
696     }
697 
698     if( (act->wLength == 0x05) &&
699             (memcmp(exp->p_data,act->pBuff,exp->len) == 0))
700     {
701         if(act->pBuff[4] == 0x01 || act->pBuff[4] == 0x02)
702         {
703             result = 1;
704         }
705     }
706 
707     return result;
708 }
709 
710 /*******************************************************************************
711 **
712 ** Function         st_validator_testAntenna_Txldo
713 **
714 ** Description      Validator function to validate Antenna TxLDO current measurement.
715 **
716 ** Returns          One if successful otherwise Zero.
717 **
718 *******************************************************************************/
st_validator_testAntenna_Txldo(nci_data_t * exp,phTmlNfc_TransactInfo_t * act)719 static uint8_t st_validator_testAntenna_Txldo(nci_data_t *exp, phTmlNfc_TransactInfo_t *act)
720 {
721     uint8_t result = 0;
722     uint8_t mesuredrange =0;
723     long measured_val = 0;
724     int tolerance = 0;
725 
726     if(NULL == exp || NULL == act)
727     {
728         return result;
729     }
730 
731     NXPLOG_NCIHAL_D("st_validator_testAntenna_Txldo = 0x%x", act->pBuff[3]);
732     if (0x05 == act->pBuff[2])
733     {
734         if (NFCSTATUS_SUCCESS == act->pBuff[3])
735         {
736             result = 1;
737             NXPLOG_NCIHAL_D("Antenna: TxLDO current measured raw value in mA : 0x%x", act->pBuff[4]);
738             if(0x00 == act->pBuff[5])
739             {
740                 NXPLOG_NCIHAL_D("Measured range : 0x00 = 50 - 100 mA");
741                 measured_val = ((0.40 * act->pBuff[4]) + 50);
742                 NXPLOG_NCIHAL_D("TxLDO current absolute value in mA = %ld", measured_val);
743             }
744             else
745             {
746                 NXPLOG_NCIHAL_D("Measured range : 0x01 = 20 - 70 mA");
747                 measured_val = ((0.40 * act->pBuff[4]) + 20);
748                 NXPLOG_NCIHAL_D("TxLDO current absolute value in mA = %ld", measured_val);
749             }
750 
751             tolerance = (phAntenna_resp.wTxdoMeasuredRangeMax  *
752                          phAntenna_resp.wTxdoMeasuredTolerance)/100;
753             if ((measured_val <= phAntenna_resp.wTxdoMeasuredRangeMax + tolerance))
754             {
755                 tolerance = (phAntenna_resp.wTxdoMeasuredRangeMin *
756                              phAntenna_resp.wTxdoMeasuredTolerance)/100;
757                 if((measured_val >= phAntenna_resp.wTxdoMeasuredRangeMin - tolerance))
758                 {
759                     gtxldo_status = NFCSTATUS_SUCCESS;
760                     NXPLOG_NCIHAL_E("Test Antenna Response for TxLDO measurement PASS");
761                 }
762                 else
763                 {
764                     gtxldo_status = NFCSTATUS_FAILED;
765                     NXPLOG_NCIHAL_E("Test Antenna Response for TxLDO measurement FAIL");
766                 }
767             }
768             else
769             {
770                 gtxldo_status = NFCSTATUS_FAILED;
771                 NXPLOG_NCIHAL_E("Test Antenna Response for TxLDO measurement FAIL");
772             }
773         }
774         else
775         {
776             gtxldo_status = NFCSTATUS_FAILED;
777             NXPLOG_NCIHAL_E("Test Antenna Response for TxLDO measurement failed: Invalid status");
778         }
779 
780     }
781     else
782     {
783         gtxldo_status = NFCSTATUS_FAILED;
784         NXPLOG_NCIHAL_E("Test Antenna Response for TxLDO measurement failed: Invalid payload length");
785     }
786 
787     return result;
788 }
789 
790 /*******************************************************************************
791 **
792 ** Function         st_validator_testAntenna_AgcVal
793 **
794 ** Description      Validator function reads AGC value of antenna and print the info
795 **
796 ** Returns          One if successful otherwise Zero.
797 **
798 *******************************************************************************/
st_validator_testAntenna_AgcVal(nci_data_t * exp,phTmlNfc_TransactInfo_t * act)799 static uint8_t st_validator_testAntenna_AgcVal(nci_data_t *exp, phTmlNfc_TransactInfo_t *act)
800 {
801     uint8_t result = 0;
802     int agc_tolerance = 0;
803     long agc_val = 0;
804 
805     if(NULL == exp || NULL == act)
806     {
807         return result;
808     }
809 
810     if (0x05 == act->pBuff[2])
811     {
812         if (NFCSTATUS_SUCCESS == act->pBuff[3])
813         {
814             result = 1;
815             agc_tolerance = (phAntenna_resp.wAgcValue * phAntenna_resp.wAgcValueTolerance)/100;
816             agc_val =  ((act->pBuff[5] << 8) | (act->pBuff[4]));
817             NXPLOG_NCIHAL_D("AGC value : %ld", agc_val);
818             if(((phAntenna_resp.wAgcValue - agc_tolerance) <= agc_val) &&
819                (agc_val <= (phAntenna_resp.wAgcValue + agc_tolerance)))
820             {
821                 gagc_value_status = NFCSTATUS_SUCCESS;
822                 NXPLOG_NCIHAL_E("Test Antenna Response for AGC Values  PASS");
823             }
824             else
825             {
826                 gagc_value_status = NFCSTATUS_FAILED;
827                 NXPLOG_NCIHAL_E("Test Antenna Response for AGC Values  FAIL");
828             }
829         }
830         else
831         {
832             gagc_value_status = NFCSTATUS_FAILED;
833             NXPLOG_NCIHAL_E("Test Antenna Response for AGC Values  FAIL");
834         }
835     }
836     else
837     {
838         gagc_value_status = NFCSTATUS_FAILED;
839         NXPLOG_NCIHAL_E("Test Antenna Response for AGC value failed: Invalid payload length");
840     }
841 
842     return result;
843 }
844 /*******************************************************************************
845 **
846 ** Function         st_validator_testAntenna_AgcVal_FixedNfcLd
847 **
848 ** Description      Validator function reads and print AGC value of
849 **                  antenna with fixed NFCLD
850 **
851 ** Returns          One if successful otherwise Zero.
852 **
853 *******************************************************************************/
st_validator_testAntenna_AgcVal_FixedNfcLd(nci_data_t * exp,phTmlNfc_TransactInfo_t * act)854 static uint8_t st_validator_testAntenna_AgcVal_FixedNfcLd(nci_data_t *exp, phTmlNfc_TransactInfo_t *act)
855 {
856     uint8_t result = 0;
857     int agc_nfcld_tolerance = 0;
858     long agc_nfcld = 0;
859 
860     if(NULL == exp || NULL == act)
861     {
862         return result;
863     }
864 
865     if(0x05 == act->pBuff[2])
866     {
867         if(NFCSTATUS_SUCCESS == act->pBuff[3])
868         {
869             result = 1;
870             agc_nfcld_tolerance = (phAntenna_resp.wAgcValuewithfixedNFCLD *
871                                    phAntenna_resp.wAgcValuewithfixedNFCLDTolerance)/100;
872             agc_nfcld =  ((act->pBuff[5] << 8) | (act->pBuff[4]));
873             NXPLOG_NCIHAL_D("AGC value with Fixed Nfcld  : %ld", agc_nfcld);
874 
875             if(((phAntenna_resp.wAgcValuewithfixedNFCLD - agc_nfcld_tolerance) <= agc_nfcld) &&
876               (agc_nfcld <= (phAntenna_resp.wAgcValuewithfixedNFCLD + agc_nfcld_tolerance)))
877             {
878                 gagc_nfcld_status = NFCSTATUS_SUCCESS;
879                 NXPLOG_NCIHAL_E("Test Antenna Response for AGC value with fixed NFCLD PASS");
880             }
881             else
882             {
883                 gagc_nfcld_status =  NFCSTATUS_FAILED;
884                 NXPLOG_NCIHAL_E("Test Antenna Response for AGC value with fixed NFCLD FAIL");
885             }
886         }
887         else
888         {
889             gagc_nfcld_status =  NFCSTATUS_FAILED;
890             NXPLOG_NCIHAL_E("Test Antenna Response for AGC value with fixed NFCLD failed: Invalid status");
891         }
892     }
893     else
894     {
895         gagc_nfcld_status =  NFCSTATUS_FAILED;
896         NXPLOG_NCIHAL_E("Test Antenna Response for AGC value with fixed NFCLD failed: Invalid payload length");
897     }
898 
899     return result;
900 }
901 
902 /*******************************************************************************
903 **
904 ** Function         st_validator_testAntenna_AgcVal_Differential
905 **
906 ** Description      Reads the AGC value with open/short RM from buffer and print
907 **
908 ** Returns          One if successful otherwise Zero.
909 **
910 *******************************************************************************/
st_validator_testAntenna_AgcVal_Differential(nci_data_t * exp,phTmlNfc_TransactInfo_t * act)911 static uint8_t st_validator_testAntenna_AgcVal_Differential(nci_data_t *exp, phTmlNfc_TransactInfo_t *act)
912 {
913     uint8_t result = 0;
914     int agc_toleranceopne1 = 0;
915     int agc_toleranceopne2 = 0;
916     long agc_differentialOpne1 = 0;
917     long agc_differentialOpne2 = 0;
918 
919     if(NULL == exp || NULL == act)
920     {
921         return result;
922     }
923 
924     if (0x05 == act->pBuff[2])
925     {
926         if (NFCSTATUS_SUCCESS == act->pBuff[3])
927         {
928             result = 1;
929             agc_toleranceopne1=(phAntenna_resp.wAgcDifferentialWithOpen1 *
930                                 phAntenna_resp.wAgcDifferentialWithOpenTolerance1)/100;
931             agc_toleranceopne2=(phAntenna_resp.wAgcDifferentialWithOpen2 *
932                                 phAntenna_resp.wAgcDifferentialWithOpenTolerance2)/100;
933             agc_differentialOpne1 =  ((act->pBuff[5] << 8) | (act->pBuff[4]));
934             agc_differentialOpne2 =  ((act->pBuff[7] << 8) | (act->pBuff[6]));
935             NXPLOG_NCIHAL_D("AGC value differential Opne 1  : %ld", agc_differentialOpne1);
936             NXPLOG_NCIHAL_D("AGC value differentialOpne  2 : %ld", agc_differentialOpne2);
937 
938             if(((agc_differentialOpne1 >= phAntenna_resp.wAgcDifferentialWithOpen1 - agc_toleranceopne1) &&
939                (agc_differentialOpne1 <= phAntenna_resp.wAgcDifferentialWithOpen1 + agc_toleranceopne1)) &&
940                ((agc_differentialOpne2 >= phAntenna_resp.wAgcDifferentialWithOpen2 - agc_toleranceopne2) &&
941                (agc_differentialOpne2 <= phAntenna_resp.wAgcDifferentialWithOpen2 + agc_toleranceopne2)))
942             {
943                 gagc_differential_status = NFCSTATUS_SUCCESS;
944                 NXPLOG_NCIHAL_E("Test Antenna Response for AGC Differential Open PASS");
945             }
946             else
947             {
948                 gagc_differential_status = NFCSTATUS_FAILED;
949                 NXPLOG_NCIHAL_E("Test Antenna Response for AGC Differential Open  FAIL");
950             }
951         }
952         else
953         {
954             NXPLOG_NCIHAL_E("Test Antenna Response for AGC Differential failed: Invalid status");
955             gagc_differential_status = NFCSTATUS_FAILED;
956         }
957 
958     }
959     else
960     {
961         NXPLOG_NCIHAL_E("Test Antenna Response for AGC Differential failed: Invalid payload length");
962         gagc_differential_status = NFCSTATUS_FAILED;
963     }
964 
965     return result;
966 }
967 /*******************************************************************************
968 **
969 ** Function         st_validator_testEquals
970 **
971 ** Description      Validator function to validate for equality between actual
972 **                  and expected values.
973 **
974 ** Returns          One if successful otherwise Zero.
975 **
976 *******************************************************************************/
st_validator_testEquals(nci_data_t * exp,phTmlNfc_TransactInfo_t * act)977 static uint8_t st_validator_testEquals(nci_data_t *exp, phTmlNfc_TransactInfo_t *act)
978 {
979     uint8_t result = 0;
980 
981     if(NULL == exp || NULL == act)
982     {
983         return result;
984     }
985     if(exp->len <= act->wLength &&
986             (memcmp(exp->p_data,act->pBuff,exp->len) == 0))
987     {
988         result = 1;
989     }
990 
991     return result;
992 }
993 
994 /*******************************************************************************
995 **
996 ** Function         hal_write_rsp_timeout_cb
997 **
998 ** Description      Callback function for hal write response timer.
999 **
1000 ** Returns          None
1001 **
1002 *******************************************************************************/
hal_write_rsp_timeout_cb(uint32_t timerId,void * pContext)1003 static void hal_write_rsp_timeout_cb(uint32_t timerId, void *pContext)
1004 {
1005     UNUSED(timerId);
1006     NXPLOG_NCIHAL_E("hal_write_rsp_timeout_cb - write timeout!!!");
1007     hal_write_timer_fired = 1;
1008     hal_read_cb(pContext,NULL);
1009 }
1010 
1011 /*******************************************************************************
1012 **
1013 ** Function         hal_write_cb
1014 **
1015 ** Description      Callback function for hal write.
1016 **
1017 ** Returns          None
1018 **
1019 *******************************************************************************/
hal_write_cb(void * pContext,phTmlNfc_TransactInfo_t * pInfo)1020 static void hal_write_cb(void *pContext, phTmlNfc_TransactInfo_t *pInfo)
1021 {
1022     phNxpNciHal_Sem_t *p_cb_data = (phNxpNciHal_Sem_t*) pContext;
1023 
1024     if (pInfo->wStatus == NFCSTATUS_SUCCESS)
1025     {
1026         NXPLOG_NCIHAL_D("write successful status = 0x%x", pInfo->wStatus);
1027     }
1028     else
1029     {
1030         NXPLOG_NCIHAL_E("write error status = 0x%x", pInfo->wStatus);
1031     }
1032 
1033     p_cb_data->status = pInfo->wStatus;
1034     SEM_POST(p_cb_data);
1035 
1036     return;
1037 }
1038 
1039 /*******************************************************************************
1040 **
1041 ** Function         hal_read_cb
1042 **
1043 ** Description      Callback function for hal read.
1044 **
1045 ** Returns          None
1046 **
1047 *******************************************************************************/
hal_read_cb(void * pContext,phTmlNfc_TransactInfo_t * pInfo)1048 static void hal_read_cb(void *pContext, phTmlNfc_TransactInfo_t *pInfo)
1049 {
1050     phNxpNciHal_Sem_t *p_cb_data = (phNxpNciHal_Sem_t*) pContext;
1051     NFCSTATUS status;
1052     if(hal_write_timer_fired == 1)
1053     {
1054         NXPLOG_NCIHAL_D("hal_read_cb - response timeout occurred");
1055 
1056         hal_write_timer_fired = 0;
1057         p_cb_data->status = NFCSTATUS_RESPONSE_TIMEOUT;
1058         status = phTmlNfc_ReadAbort();
1059     }
1060     else
1061     {
1062         NFCSTATUS status = phOsalNfc_Timer_Stop(timeoutTimerId);
1063 
1064         if (NFCSTATUS_SUCCESS == status)
1065         {
1066             NXPLOG_NCIHAL_D("Response timer stopped");
1067         }
1068         else
1069         {
1070             NXPLOG_NCIHAL_E("Response timer stop ERROR!!!");
1071             p_cb_data->status  = NFCSTATUS_FAILED;
1072         }
1073         if (pInfo == NULL)
1074         {
1075             NXPLOG_NCIHAL_E ("Empty TransactInfo");
1076             p_cb_data->status  = NFCSTATUS_FAILED;
1077         }
1078         else
1079         {
1080             if (pInfo->wStatus == NFCSTATUS_SUCCESS)
1081             {
1082                 NXPLOG_NCIHAL_D ("hal_read_cb successful status = 0x%x", pInfo->wStatus);
1083                 p_cb_data->status = NFCSTATUS_SUCCESS;
1084             }
1085             else
1086             {
1087                 NXPLOG_NCIHAL_E ("hal_read_cb error status = 0x%x", pInfo->wStatus);
1088                 p_cb_data->status = NFCSTATUS_FAILED;
1089             }
1090 
1091             p_cb_data->status = pInfo->wStatus;
1092             nci_test_data_t *test_data = (nci_test_data_t*) p_cb_data->pContext;
1093 
1094             if (test_data->exp_rsp.len == 0)
1095             {
1096                 /* Compare the actual notification with expected notification.*/
1097                 if(test_data->ntf_validator (&(test_data->exp_ntf), pInfo) == 1 )
1098                 {
1099                     p_cb_data->status = NFCSTATUS_SUCCESS;
1100                 }
1101                 else
1102                 {
1103                     p_cb_data->status = NFCSTATUS_FAILED;
1104                 }
1105             }
1106 
1107             /* Compare the actual response with expected response.*/
1108             else if (test_data->rsp_validator (&(test_data->exp_rsp), pInfo) == 1)
1109             {
1110                 p_cb_data->status = NFCSTATUS_SUCCESS;
1111             }
1112             else
1113             {
1114                 p_cb_data->status = NFCSTATUS_FAILED;
1115             }
1116 
1117             test_data->exp_rsp.len = 0;
1118         }
1119     }
1120 
1121     SEM_POST (p_cb_data);
1122 
1123     return;
1124 }
1125 
1126 /*******************************************************************************
1127 **
1128 ** Function         phNxpNciHal_test_rx_thread
1129 **
1130 ** Description      Thread to fetch and process messages from message queue.
1131 **
1132 ** Returns          NULL
1133 **
1134 *******************************************************************************/
phNxpNciHal_test_rx_thread(void * arg)1135 static void *phNxpNciHal_test_rx_thread(void *arg)
1136 {
1137     phLibNfc_Message_t msg;
1138     UNUSED(arg);
1139     NXPLOG_NCIHAL_D("Self test thread started");
1140 
1141     thread_running = 1;
1142 
1143     while (thread_running == 1)
1144     {
1145         /* Fetch next message from the NFC stack message queue */
1146         if (phDal4Nfc_msgrcv(gDrvCfg.nClientId,
1147                 &msg, 0, 0) == -1)
1148         {
1149             NXPLOG_NCIHAL_E("Received bad message");
1150             continue;
1151         }
1152 
1153         if(thread_running == 0)
1154         {
1155             break;
1156         }
1157 
1158         switch (msg.eMsgType)
1159         {
1160             case PH_LIBNFC_DEFERREDCALL_MSG:
1161             {
1162                 phLibNfc_DeferredCall_t *deferCall =
1163                         (phLibNfc_DeferredCall_t *) (msg.pMsgData);
1164 
1165                 REENTRANCE_LOCK();
1166                 deferCall->pCallback(deferCall->pParameter);
1167                 REENTRANCE_UNLOCK();
1168 
1169                 break;
1170             }
1171         }
1172     }
1173 
1174     NXPLOG_NCIHAL_D("Self test thread stopped");
1175 
1176     return NULL;
1177 }
1178 
1179 /*******************************************************************************
1180 **
1181 ** Function         phNxpNciHal_readLocked
1182 **
1183 ** Description      Reads response and notification from NFCC and waits for
1184 **                  read completion, for a definitive timeout value.
1185 **
1186 ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED,
1187 **                  NFCSTATUS_RESPONSE_TIMEOUT in case of timeout.
1188 **
1189 *******************************************************************************/
phNxpNciHal_readLocked(nci_test_data_t * pData)1190 static NFCSTATUS phNxpNciHal_readLocked(nci_test_data_t *pData )
1191 {
1192     NFCSTATUS status = NFCSTATUS_SUCCESS;
1193     phNxpNciHal_Sem_t cb_data;
1194     uint16_t read_len = 16;
1195     /* RX Buffer */
1196     uint32_t rx_data[NCI_MAX_DATA_LEN];
1197 
1198     /* Create the local semaphore */
1199     if (phNxpNciHal_init_cb_data(&cb_data, pData) != NFCSTATUS_SUCCESS)
1200     {
1201         NXPLOG_NCIHAL_D("phTmlNfc_Read Create cb data failed");
1202         status = NFCSTATUS_FAILED;
1203         goto clean_and_return;
1204     }
1205 
1206     /* call read pending */
1207     status = phTmlNfc_Read(
1208             (uint8_t *) rx_data,
1209             (uint16_t) read_len,
1210             (pphTmlNfc_TransactCompletionCb_t) &hal_read_cb,
1211             &cb_data);
1212 
1213     if (status != NFCSTATUS_PENDING)
1214     {
1215         NXPLOG_NCIHAL_E("TML Read status error status = %x", status);
1216         status = NFCSTATUS_FAILED;
1217         goto clean_and_return;
1218     }
1219 
1220     status = phOsalNfc_Timer_Start(timeoutTimerId,
1221             HAL_WRITE_RSP_TIMEOUT,
1222             &hal_write_rsp_timeout_cb,
1223             &cb_data);
1224 
1225     if (NFCSTATUS_SUCCESS == status)
1226     {
1227         NXPLOG_NCIHAL_D("Response timer started");
1228     }
1229     else
1230     {
1231         NXPLOG_NCIHAL_E("Response timer not started");
1232         status = NFCSTATUS_FAILED;
1233         goto clean_and_return;
1234     }
1235 
1236     /* Wait for callback response */
1237     if (SEM_WAIT(cb_data))
1238     {
1239         NXPLOG_NCIHAL_E("phTmlNfc_Read semaphore error");
1240         status = NFCSTATUS_FAILED;
1241         goto clean_and_return;
1242     }
1243 
1244     if(cb_data.status == NFCSTATUS_RESPONSE_TIMEOUT)
1245     {
1246         NXPLOG_NCIHAL_E("Response timeout!!!");
1247         status = NFCSTATUS_RESPONSE_TIMEOUT;
1248         goto clean_and_return;
1249 
1250     }
1251 
1252     if (cb_data.status != NFCSTATUS_SUCCESS)
1253     {
1254         NXPLOG_NCIHAL_E("phTmlNfc_Read failed  ");
1255         status = NFCSTATUS_FAILED;
1256         goto clean_and_return;
1257     }
1258 
1259     clean_and_return:
1260     phNxpNciHal_cleanup_cb_data(&cb_data);
1261 
1262     return status;
1263 }
1264 
1265 /*******************************************************************************
1266 **
1267 ** Function         phNxpNciHal_writeLocked
1268 **
1269 ** Description      Send command to NFCC and waits for cmd write completion, for
1270 **                  a definitive timeout value.
1271 **
1272 ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED,
1273 **                  NFCSTATUS_RESPONSE_TIMEOUT in case of timeout.
1274 **
1275 *******************************************************************************/
phNxpNciHal_writeLocked(nci_test_data_t * pData)1276 static NFCSTATUS phNxpNciHal_writeLocked(nci_test_data_t *pData )
1277 {
1278     NFCSTATUS status = NFCSTATUS_SUCCESS;
1279 
1280     phNxpNciHal_Sem_t cb_data;
1281     int retryCnt = 0;
1282 
1283     /* Create the local semaphore */
1284     if (phNxpNciHal_init_cb_data(&cb_data, NULL) != NFCSTATUS_SUCCESS)
1285     {
1286         NXPLOG_NCIHAL_D("phTmlNfc_Write Create cb data failed");
1287         goto clean_and_return;
1288     }
1289 
1290 retry:
1291     status = phTmlNfc_Write(pData->cmd.p_data, pData->cmd.len,
1292             (pphTmlNfc_TransactCompletionCb_t) &hal_write_cb, &cb_data);
1293 
1294     if (status != NFCSTATUS_PENDING)
1295     {
1296         NXPLOG_NCIHAL_E("phTmlNfc_Write status error");
1297         goto clean_and_return;
1298     }
1299 
1300     /* Wait for callback response */
1301     if (SEM_WAIT(cb_data))
1302     {
1303         NXPLOG_NCIHAL_E("write_unlocked semaphore error");
1304         status = NFCSTATUS_FAILED;
1305         goto clean_and_return;
1306     }
1307 
1308     if (cb_data.status != NFCSTATUS_SUCCESS && retryCnt < HAL_WRITE_MAX_RETRY)
1309     {
1310         retryCnt++;
1311         NXPLOG_NCIHAL_E("write_unlocked failed - PN54X Maybe in Standby Mode - Retry %d",retryCnt);
1312         goto retry;
1313     }
1314 
1315     status = cb_data.status;
1316 
1317 clean_and_return:
1318     phNxpNciHal_cleanup_cb_data(&cb_data);
1319 
1320     return status;
1321 }
1322 
1323 /*******************************************************************************
1324 **
1325 ** Function         phNxpNciHal_performTest
1326 **
1327 ** Description      Performs a single cycle of command,response and
1328 **                  notification.
1329 **
1330 ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED,
1331 **
1332 *******************************************************************************/
phNxpNciHal_performTest(nci_test_data_t * pData)1333 NFCSTATUS phNxpNciHal_performTest(nci_test_data_t *pData )
1334 {
1335     NFCSTATUS status = NFCSTATUS_SUCCESS;
1336 
1337     if(NULL == pData)
1338     {
1339         return NFCSTATUS_FAILED;
1340     }
1341 
1342     CONCURRENCY_LOCK();
1343 
1344     status = phNxpNciHal_writeLocked(pData);
1345 
1346     if(status == NFCSTATUS_RESPONSE_TIMEOUT)
1347     {
1348         goto clean_and_return;
1349     }
1350     if(status != NFCSTATUS_SUCCESS)
1351     {
1352         goto clean_and_return;
1353     }
1354 
1355     status = phNxpNciHal_readLocked(pData);
1356 
1357     if(status != NFCSTATUS_SUCCESS)
1358     {
1359         goto clean_and_return;
1360     }
1361 
1362     if(0 != pData->exp_ntf.len)
1363     {
1364         status = phNxpNciHal_readLocked(pData);
1365 
1366         if(status != NFCSTATUS_SUCCESS)
1367         {
1368             goto clean_and_return;
1369         }
1370     }
1371 
1372 clean_and_return:
1373     CONCURRENCY_UNLOCK();
1374     return status;
1375 }
1376 
1377 /*******************************************************************************
1378  **
1379  ** Function         phNxpNciHal_TestMode_open
1380  **
1381  ** Description      It opens the physical connection with NFCC (PN54X) and
1382  **                  creates required client thread for operation.
1383  **
1384  ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
1385  **
1386  *******************************************************************************/
phNxpNciHal_TestMode_open(void)1387 NFCSTATUS phNxpNciHal_TestMode_open (void)
1388 {
1389     /* Thread */
1390     pthread_t test_rx_thread;
1391 
1392     phOsalNfc_Config_t tOsalConfig;
1393     phTmlNfc_Config_t tTmlConfig;
1394     char *nfc_dev_node = NULL;
1395     const uint16_t max_len = 260;
1396     NFCSTATUS status = NFCSTATUS_SUCCESS;
1397     uint16_t read_len = 255;
1398     int8_t ret_val = 0x00;
1399     /* initialize trace level */
1400     phNxpLog_InitializeLogLevel();
1401 
1402     if (phNxpNciHal_init_monitor() == NULL)
1403     {
1404         NXPLOG_NCIHAL_E("Init monitor failed");
1405         return NFCSTATUS_FAILED;
1406     }
1407 
1408     CONCURRENCY_LOCK();
1409 
1410     memset(&tOsalConfig, 0x00, sizeof(tOsalConfig));
1411     memset(&tTmlConfig, 0x00, sizeof(tTmlConfig));
1412 
1413     /* Read the nfc device node name */
1414     nfc_dev_node = (char*) malloc (max_len * sizeof (char*));
1415     if (nfc_dev_node == NULL)
1416     {
1417         NXPLOG_NCIHAL_E ("malloc of nfc_dev_node failed ");
1418         goto clean_and_return;
1419     }
1420     else if (!GetNxpStrValue (NAME_NXP_NFC_DEV_NODE, nfc_dev_node, sizeof (nfc_dev_node)))
1421     {
1422         NXPLOG_NCIHAL_E ("Invalid nfc device node name keeping the default device node /dev/pn544");
1423         strcpy (nfc_dev_node, "/dev/pn544");
1424     }
1425 
1426     gDrvCfg.nClientId = phDal4Nfc_msgget(0, 0600);
1427     gDrvCfg.nLinkType = ENUM_LINK_TYPE_I2C;/* For PN54X */
1428     tTmlConfig.pDevName = (int8_t *) nfc_dev_node;
1429     tOsalConfig.dwCallbackThreadId = (uintptr_t) gDrvCfg.nClientId;
1430     tOsalConfig.pLogFile = NULL;
1431     tTmlConfig.dwGetMsgThreadId = (uintptr_t) gDrvCfg.nClientId;
1432     nxpncihal_ctrl.gDrvCfg.nClientId = (uintptr_t) gDrvCfg.nClientId;
1433 
1434     /* Initialize TML layer */
1435     status = phTmlNfc_Init(&tTmlConfig);
1436     if (status != NFCSTATUS_SUCCESS)
1437     {
1438         NXPLOG_NCIHAL_E("phTmlNfc_Init Failed");
1439         goto clean_and_return;
1440     }
1441     else
1442     {
1443         if (nfc_dev_node != NULL)
1444         {
1445             free (nfc_dev_node);
1446             nfc_dev_node = NULL;
1447         }
1448     }
1449 
1450     pthread_attr_t attr;
1451     pthread_attr_init (&attr);
1452     pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
1453     ret_val = pthread_create (&test_rx_thread, &attr,
1454             phNxpNciHal_test_rx_thread, NULL);
1455     pthread_attr_destroy (&attr);
1456     if (ret_val != 0)
1457     {
1458         NXPLOG_NCIHAL_E("pthread_create failed");
1459         phTmlNfc_Shutdown();
1460         goto clean_and_return;
1461     }
1462 
1463     timeoutTimerId = phOsalNfc_Timer_Create();
1464 
1465     if(timeoutTimerId == 0xFFFF)
1466     {
1467         NXPLOG_NCIHAL_E("phOsalNfc_Timer_Create failed");
1468     }
1469     else
1470     {
1471         NXPLOG_NCIHAL_D("phOsalNfc_Timer_Create SUCCESS");
1472     }
1473     CONCURRENCY_UNLOCK();
1474 
1475     return NFCSTATUS_SUCCESS;
1476 
1477 clean_and_return:
1478     CONCURRENCY_UNLOCK ();
1479     if (nfc_dev_node != NULL)
1480     {
1481         free (nfc_dev_node);
1482         nfc_dev_node = NULL;
1483     }
1484     phNxpNciHal_cleanup_monitor ();
1485     return NFCSTATUS_FAILED;
1486 }
1487 
1488 /*******************************************************************************
1489  **
1490  ** Function         phNxpNciHal_TestMode_close
1491  **
1492  ** Description      This function close the NFCC interface and free all
1493  **                  resources.
1494  **
1495  ** Returns          None.
1496  **
1497  *******************************************************************************/
1498 
phNxpNciHal_TestMode_close()1499 void phNxpNciHal_TestMode_close ()
1500 {
1501 
1502     NFCSTATUS status = NFCSTATUS_SUCCESS;
1503 
1504     CONCURRENCY_LOCK();
1505 
1506     if (NULL != gpphTmlNfc_Context->pDevHandle)
1507     {
1508         /* Abort any pending read and write */
1509         status = phTmlNfc_ReadAbort();
1510         status = phTmlNfc_WriteAbort();
1511 
1512         phOsalNfc_Timer_Cleanup();
1513 
1514         status = phTmlNfc_Shutdown();
1515 
1516         NXPLOG_NCIHAL_D("phNxpNciHal_close return status = %d", status);
1517 
1518         thread_running = 0;
1519 
1520         phDal4Nfc_msgrelease(gDrvCfg.nClientId);
1521 
1522         status = phOsalNfc_Timer_Delete(timeoutTimerId);
1523     }
1524 
1525     CONCURRENCY_UNLOCK();
1526 
1527     phNxpNciHal_cleanup_monitor();
1528 
1529     /* Return success always */
1530     return;
1531 }
1532 
1533 /*******************************************************************************
1534  **
1535  ** Function         phNxpNciHal_SwpTest
1536  **
1537  ** Description      Test function to validate the SWP line. SWP line number is
1538  **                  is sent as parameter to the API.
1539  **
1540  ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
1541  **
1542  *******************************************************************************/
1543 
phNxpNciHal_SwpTest(uint8_t swp_line)1544 NFCSTATUS phNxpNciHal_SwpTest(uint8_t swp_line)
1545 {
1546     NFCSTATUS status = NFCSTATUS_SUCCESS;
1547     int len = 0;
1548     int cnt = 0;
1549 
1550     NXPLOG_NCIHAL_D("phNxpNciHal_SwpTest - start\n");
1551 
1552     if(swp_line == 0x01)
1553     {
1554         len = (sizeof(swp1_test_data)/sizeof(swp1_test_data[0]));
1555 
1556         for(cnt = 0; cnt < len; cnt++)
1557         {
1558             status = phNxpNciHal_performTest(&(swp1_test_data[cnt]));
1559             if(status == NFCSTATUS_RESPONSE_TIMEOUT ||
1560                     status == NFCSTATUS_FAILED
1561             )
1562             {
1563                 break;
1564             }
1565         }
1566     }
1567     else if(swp_line == 0x02)
1568     {
1569         len = (sizeof(swp2_test_data)/sizeof(swp2_test_data[0]));
1570 
1571         for(cnt = 0; cnt < len; cnt++)
1572         {
1573             status = phNxpNciHal_performTest(&(swp2_test_data[cnt]));
1574             if(status == NFCSTATUS_RESPONSE_TIMEOUT ||
1575                     status == NFCSTATUS_FAILED
1576             )
1577             {
1578                 break;
1579             }
1580         }
1581     }
1582     else
1583     {
1584         status = NFCSTATUS_FAILED;
1585     }
1586 
1587     if( status == NFCSTATUS_SUCCESS)
1588     {
1589         NXPLOG_NCIHAL_D("phNxpNciHal_SwpTest - SUCCESSS\n");
1590     }
1591     else
1592     {
1593         NXPLOG_NCIHAL_D("phNxpNciHal_SwpTest - FAILED\n");
1594     }
1595 
1596     NXPLOG_NCIHAL_D("phNxpNciHal_SwpTest - end\n");
1597 
1598     return status;
1599 }
1600 
1601 /*******************************************************************************
1602  **
1603  ** Function         phNxpNciHal_PrbsTestStart
1604  **
1605  ** Description      Test function start RF generation for RF technology and bit
1606  **                  rate. RF technology and bit rate are sent as parameter to
1607  **                  the API.
1608  **
1609  ** Returns          NFCSTATUS_SUCCESS if RF generation successful,
1610  **                  otherwise NFCSTATUS_FAILED.
1611  **
1612  *******************************************************************************/
1613 
1614 #if(NFC_NXP_CHIP_TYPE != PN547C2)
phNxpNciHal_PrbsTestStart(phNxpNfc_PrbsType_t prbs_type,phNxpNfc_PrbsHwType_t hw_prbs_type,phNxpNfc_Tech_t tech,phNxpNfc_Bitrate_t bitrate)1615 NFCSTATUS phNxpNciHal_PrbsTestStart (phNxpNfc_PrbsType_t prbs_type, phNxpNfc_PrbsHwType_t hw_prbs_type,
1616         phNxpNfc_Tech_t tech, phNxpNfc_Bitrate_t bitrate)
1617 #else
1618 NFCSTATUS phNxpNciHal_PrbsTestStart (phNxpNfc_Tech_t tech, phNxpNfc_Bitrate_t bitrate)
1619 #endif
1620 {
1621     NFCSTATUS status = NFCSTATUS_FAILED;
1622 
1623     nci_test_data_t prbs_cmd_data;
1624 
1625 #if(NFC_NXP_CHIP_TYPE != PN547C2)
1626     uint8_t rsp_cmd_info[] = {0x4F, 0x30, 0x01, 0x00};
1627     prbs_cmd_data.cmd.len = 0x09;
1628 #else
1629     uint8_t rsp_cmd_info[] = {0x4F, 0x30, 0x01, 0x00};
1630     prbs_cmd_data.cmd.len = 0x07;
1631 #endif
1632 
1633     memcpy(prbs_cmd_data.exp_rsp.p_data, &rsp_cmd_info[0], sizeof(rsp_cmd_info));
1634     prbs_cmd_data.exp_rsp.len = sizeof(rsp_cmd_info);
1635 
1636     //prbs_cmd_data.exp_rsp.len = 0x00;
1637     prbs_cmd_data.exp_ntf.len = 0x00;
1638     prbs_cmd_data.rsp_validator = st_validator_testEquals;
1639     prbs_cmd_data.ntf_validator = st_validator_null;
1640 
1641     uint8_t len = 0;
1642     uint8_t cnt = 0;
1643 
1644 //    [NCI] -> [0x2F 0x30 0x04 0x00 0x00 0x01 0xFF]
1645 
1646 #if(NFC_NXP_CHIP_TYPE != PN547C2)
1647     status = phNxpNciHal_getPrbsCmd(prbs_type, hw_prbs_type, tech, bitrate,
1648             prbs_cmd_data.cmd.p_data,prbs_cmd_data.cmd.len);
1649 #else
1650     status = phNxpNciHal_getPrbsCmd(tech, bitrate,prbs_cmd_data.cmd.p_data,prbs_cmd_data.cmd.len);
1651 #endif
1652 
1653     if( status == NFCSTATUS_FAILED)
1654     {
1655         //Invalid Param.
1656         NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStart - INVALID_PARAM\n");
1657 
1658         goto clean_and_return;
1659     }
1660 
1661     len = (sizeof(prbs_test_data)/sizeof(prbs_test_data[0]));
1662 
1663     for(cnt = 0; cnt < len; cnt++)
1664     {
1665         status = phNxpNciHal_performTest(&(prbs_test_data[cnt]));
1666         if(status == NFCSTATUS_RESPONSE_TIMEOUT ||
1667                 status == NFCSTATUS_FAILED
1668         )
1669         {
1670             break;
1671         }
1672     }
1673 
1674     /* Ignoring status, as there will be no response - Applicable till FW version 8.1.1*/
1675     status = phNxpNciHal_performTest(&prbs_cmd_data);
1676     clean_and_return:
1677 
1678     if( status == NFCSTATUS_SUCCESS)
1679     {
1680         NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStart - SUCCESSS\n");
1681     }
1682     else
1683     {
1684         NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStart - FAILED\n");
1685     }
1686 
1687     NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStart - end\n");
1688 
1689     return status;
1690 }
1691 
1692 /*******************************************************************************
1693  **
1694  ** Function         phNxpNciHal_PrbsTestStop
1695  **
1696  ** Description      Test function stop RF generation for RF technology started
1697  **                  by phNxpNciHal_PrbsTestStart.
1698  **
1699  ** Returns          NFCSTATUS_SUCCESS if operation successful,
1700  **                  otherwise NFCSTATUS_FAILED.
1701  **
1702  *******************************************************************************/
1703 
phNxpNciHal_PrbsTestStop()1704 NFCSTATUS phNxpNciHal_PrbsTestStop ()
1705 {
1706     NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - Start\n");
1707 
1708     NFCSTATUS status = NFCSTATUS_SUCCESS;
1709 
1710     status = phTmlNfc_IoCtl(phTmlNfc_e_ResetDevice);
1711 
1712     if(NFCSTATUS_SUCCESS == status)
1713     {
1714         NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - SUCCESS\n");
1715     }
1716     else
1717     {
1718         NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - FAILED\n");
1719 
1720     }
1721     NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - end\n");
1722 
1723     return status;
1724 }
1725 
1726 /*******************************************************************************
1727 **
1728 ** Function         phNxpNciHal_getPrbsCmd
1729 **
1730 ** Description      Test function frames the PRBS command.
1731 **
1732 ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
1733 **
1734 *******************************************************************************/
1735 #if(NFC_NXP_CHIP_TYPE != PN547C2)
phNxpNciHal_getPrbsCmd(phNxpNfc_PrbsType_t prbs_type,phNxpNfc_PrbsHwType_t hw_prbs_type,uint8_t tech,uint8_t bitrate,uint8_t * prbs_cmd,uint8_t prbs_cmd_len)1736 NFCSTATUS phNxpNciHal_getPrbsCmd (phNxpNfc_PrbsType_t prbs_type, phNxpNfc_PrbsHwType_t hw_prbs_type,
1737         uint8_t tech, uint8_t bitrate, uint8_t *prbs_cmd, uint8_t prbs_cmd_len)
1738 #else
1739 NFCSTATUS phNxpNciHal_getPrbsCmd (uint8_t tech, uint8_t bitrate, uint8_t *prbs_cmd, uint8_t prbs_cmd_len)
1740 #endif
1741 {
1742     NFCSTATUS status = NFCSTATUS_SUCCESS;
1743     int position_tech_param = 0;
1744     int position_bit_param = 0;
1745 
1746     NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - tech 0x%x bitrate = 0x%x", tech, bitrate);
1747     if(NULL == prbs_cmd ||
1748 #if(NFC_NXP_CHIP_TYPE != PN547C2)
1749             prbs_cmd_len != 0x09)
1750 #else
1751             prbs_cmd_len != 0x07)
1752 #endif
1753     {
1754         return status;
1755     }
1756 
1757     prbs_cmd[0] = 0x2F;
1758     prbs_cmd[1] = 0x30;
1759 #if(NFC_NXP_CHIP_TYPE != PN547C2)
1760     prbs_cmd[2] = 0x06;
1761     prbs_cmd[3] = (uint8_t)prbs_type;
1762     //0xFF Error value used for validation.
1763     prbs_cmd[4] = (uint8_t)hw_prbs_type;
1764     prbs_cmd[5] = 0xFF;//TECH
1765     prbs_cmd[6] = 0xFF;//BITRATE
1766     prbs_cmd[7] = 0x01;
1767     prbs_cmd[8] = 0xFF;
1768     position_tech_param = 5;
1769     position_bit_param = 6;
1770 #else
1771     prbs_cmd[2] = 0x04;
1772     //0xFF Error value used for validation.
1773     prbs_cmd[3] = 0xFF;//TECH
1774     //0xFF Error value used for validation.
1775     prbs_cmd[4] = 0xFF;//BITRATE
1776     prbs_cmd[5] = 0x01;
1777     prbs_cmd[6] = 0xFF;
1778     position_tech_param = 3;
1779     position_bit_param = 4;
1780 #endif
1781 
1782     switch (tech) {
1783         case NFC_RF_TECHNOLOGY_A:
1784             NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - NFC_RF_TECHNOLOGY_A");
1785             prbs_cmd[position_tech_param] = 0x00;
1786             break;
1787         case NFC_RF_TECHNOLOGY_B:
1788             NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - NFC_RF_TECHNOLOGY_B");
1789             prbs_cmd[position_tech_param] = 0x01;
1790             break;
1791         case NFC_RF_TECHNOLOGY_F:
1792             NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - NFC_RF_TECHNOLOGY_F");
1793             prbs_cmd[position_tech_param] = 0x02;
1794             break;
1795         default:
1796             break;
1797     }
1798 
1799     switch (bitrate)
1800     {
1801         case NFC_BIT_RATE_106:
1802             NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_106");
1803             if(prbs_cmd[position_tech_param] != 0x02)
1804             {
1805                 prbs_cmd[position_bit_param] = 0x00;
1806             }
1807             break;
1808         case NFC_BIT_RATE_212:
1809             NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_212");
1810             prbs_cmd[position_bit_param] = 0x01;
1811             break;
1812         case NFC_BIT_RATE_424:
1813             NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_424");
1814             prbs_cmd[position_bit_param] = 0x02;
1815             break;
1816         case NFC_BIT_RATE_848:
1817             NXPLOG_NCIHAL_D("phNxpNciHal_getPrbsCmd - NFC_BIT_RATE_848");
1818             if(prbs_cmd[position_tech_param] != 0x02)
1819             {
1820                 prbs_cmd[position_bit_param] = 0x03;
1821             }
1822             break;
1823         default:
1824             break;
1825     }
1826 
1827     if(prbs_cmd[position_tech_param] == 0xFF || prbs_cmd[position_bit_param] == 0xFF)
1828     {
1829         //Invalid Param.
1830         status = NFCSTATUS_FAILED;
1831     }
1832 
1833     return status;
1834 }
1835 
1836 /*******************************************************************************
1837 **
1838 ** Function         phNxpNciHal_RfFieldTest
1839 **
1840 ** Description      Test function performs RF filed test.
1841 **
1842 ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
1843 **
1844 *******************************************************************************/
phNxpNciHal_RfFieldTest(uint8_t on)1845 NFCSTATUS phNxpNciHal_RfFieldTest (uint8_t on)
1846 {
1847     NFCSTATUS status = NFCSTATUS_SUCCESS;
1848     int len = 0;
1849     int cnt = 0;
1850 
1851     NXPLOG_NCIHAL_D("phNxpNciHal_RfFieldTest - start %x\n",on);
1852 
1853     if(on == 0x01)
1854     {
1855         len = (sizeof(rf_field_on_test_data)/sizeof(rf_field_on_test_data[0]));
1856 
1857         for(cnt = 0; cnt < len; cnt++)
1858         {
1859             status = phNxpNciHal_performTest(&(rf_field_on_test_data[cnt]));
1860             if(status == NFCSTATUS_RESPONSE_TIMEOUT || status == NFCSTATUS_FAILED)
1861             {
1862                 break;
1863             }
1864         }
1865     }
1866     else if(on == 0x00)
1867     {
1868         len = (sizeof(rf_field_off_test_data)/sizeof(rf_field_off_test_data[0]));
1869 
1870         for(cnt = 0; cnt < len; cnt++)
1871         {
1872             status = phNxpNciHal_performTest(&(rf_field_off_test_data[cnt]));
1873             if(status == NFCSTATUS_RESPONSE_TIMEOUT || status == NFCSTATUS_FAILED)
1874             {
1875                 break;
1876             }
1877         }
1878     }
1879     else
1880     {
1881         status = NFCSTATUS_FAILED;
1882     }
1883 
1884     if( status == NFCSTATUS_SUCCESS)
1885     {
1886         NXPLOG_NCIHAL_D("phNxpNciHal_RfFieldTest - SUCCESSS\n");
1887     }
1888     else
1889     {
1890         NXPLOG_NCIHAL_D("phNxpNciHal_RfFieldTest - FAILED\n");
1891     }
1892 
1893     NXPLOG_NCIHAL_D("phNxpNciHal_RfFieldTest - end\n");
1894 
1895     return status;
1896 }
1897 
1898 /*******************************************************************************
1899  **
1900  ** Function         phNxpNciHal_AntennaTest
1901  **
1902  ** Description
1903  **
1904  ** Returns
1905  **
1906  *******************************************************************************/
phNxpNciHal_AntennaTest()1907 NFCSTATUS phNxpNciHal_AntennaTest ()
1908 {
1909     NFCSTATUS status = NFCSTATUS_FAILED;
1910 
1911     return status;
1912 }
1913 
1914 /*******************************************************************************
1915 **
1916 ** Function         phNxpNciHal_DownloadPinTest
1917 **
1918 ** Description      Test function to validate the FW download pin connection.
1919 **
1920 ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
1921 **
1922 *******************************************************************************/
phNxpNciHal_DownloadPinTest(void)1923 NFCSTATUS phNxpNciHal_DownloadPinTest(void)
1924 {
1925     NFCSTATUS status = NFCSTATUS_FAILED;
1926     int len = 0;
1927     int cnt = 0;
1928 
1929     NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - start\n");
1930 
1931     len = (sizeof(download_pin_test_data1)/sizeof(download_pin_test_data1[0]));
1932 
1933     for(cnt = 0; cnt < len; cnt++)
1934     {
1935         status = phNxpNciHal_performTest(&(download_pin_test_data1[cnt]));
1936         if(status == NFCSTATUS_RESPONSE_TIMEOUT || status == NFCSTATUS_FAILED)
1937         {
1938             break;
1939         }
1940     }
1941 
1942     if (status != NFCSTATUS_SUCCESS)
1943     {
1944         NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - FAILED\n");
1945         return status;
1946     }
1947 
1948     status = NFCSTATUS_FAILED;
1949     status = phTmlNfc_IoCtl(phTmlNfc_e_EnableDownloadMode);
1950     if (NFCSTATUS_SUCCESS != status)
1951     {
1952         NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - FAILED\n");
1953         return status;
1954     }
1955 
1956     status = NFCSTATUS_FAILED;
1957     len = (sizeof(download_pin_test_data2)/sizeof(download_pin_test_data2[0]));
1958 
1959      for(cnt = 0; cnt < len; cnt++)
1960      {
1961          status = phNxpNciHal_performTest(&(download_pin_test_data2[cnt]));
1962          if(status == NFCSTATUS_RESPONSE_TIMEOUT || status == NFCSTATUS_FAILED)
1963          {
1964              break;
1965          }
1966      }
1967 
1968     if( status == NFCSTATUS_SUCCESS)
1969     {
1970         NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - SUCCESSS\n");
1971     }
1972     else
1973     {
1974         NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - FAILED\n");
1975     }
1976 
1977     NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - end\n");
1978 
1979     return status;
1980 }
1981 /*******************************************************************************
1982 **
1983 ** Function         phNxpNciHal_AntennaSelfTest
1984 **
1985 ** Description      Test function to validate the Antenna's discrete
1986 **                  components connection.
1987 **
1988 ** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED.
1989 **
1990 *******************************************************************************/
phNxpNciHal_AntennaSelfTest(phAntenna_St_Resp_t * phAntenna_St_Resp)1991 NFCSTATUS phNxpNciHal_AntennaSelfTest(phAntenna_St_Resp_t * phAntenna_St_Resp )
1992 {
1993     NFCSTATUS status = NFCSTATUS_FAILED;
1994     NFCSTATUS antenna_st_status = NFCSTATUS_FAILED;
1995     int len = 0;
1996     int cnt = 0;
1997 
1998     NXPLOG_NCIHAL_D("phNxpNciHal_AntennaSelfTest - start\n");
1999     memcpy(&phAntenna_resp, phAntenna_St_Resp, sizeof(phAntenna_St_Resp_t));
2000     len = (sizeof(antenna_self_test_data)/sizeof(antenna_self_test_data[0]));
2001 
2002     for(cnt = 0; cnt < len; cnt++)
2003     {
2004         status = phNxpNciHal_performTest(&(antenna_self_test_data[cnt]));
2005         if(status == NFCSTATUS_RESPONSE_TIMEOUT || status == NFCSTATUS_FAILED)
2006         {
2007             NXPLOG_NCIHAL_E("phNxpNciHal_AntennaSelfTest: commnad execution - FAILED\n");
2008             break;
2009         }
2010     }
2011 
2012     if(status == NFCSTATUS_SUCCESS)
2013     {
2014         if((gtxldo_status == NFCSTATUS_SUCCESS) && (gagc_value_status == NFCSTATUS_SUCCESS) &&
2015            (gagc_nfcld_status == NFCSTATUS_SUCCESS) && (gagc_differential_status == NFCSTATUS_SUCCESS))
2016         {
2017             antenna_st_status = NFCSTATUS_SUCCESS;
2018             NXPLOG_NCIHAL_D("phNxpNciHal_AntennaSelfTest - SUCESS\n");
2019         }
2020         else
2021         {
2022             NXPLOG_NCIHAL_D("phNxpNciHal_AntennaSelfTest - FAILED\n");
2023         }
2024     }
2025     else
2026     {
2027         NXPLOG_NCIHAL_D("phNxpNciHal_AntennaSelfTest - FAILED\n");
2028     }
2029 
2030     NXPLOG_NCIHAL_D("phNxpNciHal_AntennaSelfTest - end\n");
2031 
2032     return antenna_st_status;
2033 }
2034 
2035 #endif /*#ifdef NXP_HW_SELF_TEST*/
2036