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