1 /*
2 * Copyright (C) 2010 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 /*!
18 * =========================================================================== *
19 * *
20 * *
21 * \file phHciNfc.c *
22 * \brief HCI Interface Source for the HCI Management. *
23 * *
24 * *
25 * Project: NFC-FRI-1.1 *
26 * *
27 * $Date: Thu Apr 22 17:49:47 2010 $ *
28 * $Author: ing04880 $ *
29 * $Revision: 1.90 $ *
30 * $Aliases: NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
31 * *
32 * =========================================================================== *
33 */
34
35
36 /*
37 ################################################################################
38 ***************************** Header File Inclusion ****************************
39 ################################################################################
40 */
41
42 #include <phNfcConfig.h>
43 #include <phNfcCompId.h>
44 #include <phNfcIoctlCode.h>
45 #include <phHciNfc.h>
46 #include <phHciNfc_Sequence.h>
47 #include <phHciNfc_RFReader.h>
48 #include <phHciNfc_LinkMgmt.h>
49 #ifdef ENABLE_P2P
50 #include <phHciNfc_NfcIPMgmt.h>
51 #endif
52 #include <phHciNfc_Emulation.h>
53 #include <phHciNfc_SWP.h>
54 #include <phHciNfc_DevMgmt.h>
55 #include <phOsalNfc.h>
56
57 /**/
58
59 /*
60 *************************** Static Function Declaration **************************
61 */
62
63
64 static
65 NFCSTATUS
66 phHciNfc_Config_Emulation (
67 void *psHciHandle,
68 void *pHwRef,
69 phHal_sEmulationCfg_t *pEmulationConfig
70
71 );
72
73
74 /*
75 *************************** Function Definitions **************************
76 */
77
78
79 /*!
80 * \brief Initialises the HCI Interface
81 *
82 * This function initialises the resources for the HCI Command and
83 * Response Mechanism
84 */
85
86 NFCSTATUS
phHciNfc_Initialise(void * psHciHandle,void * pHwRef,phHciNfc_Init_t init_mode,phHal_sHwConfig_t * pHwConfig,pphNfcIF_Notification_CB_t pHalNotify,void * psContext,phNfcLayer_sCfg_t * psHciLayerCfg)87 phHciNfc_Initialise (
88 void *psHciHandle,
89 void *pHwRef,
90 phHciNfc_Init_t init_mode,
91 phHal_sHwConfig_t *pHwConfig,
92 pphNfcIF_Notification_CB_t pHalNotify,
93 void *psContext,
94 phNfcLayer_sCfg_t *psHciLayerCfg
95 )
96 {
97 phHciNfc_sContext_t *psHciContext = NULL;
98 phNfcIF_sReference_t hciReference = { NULL, 0, 0 };
99 phNfcIF_sCallBack_t if_callback = { NULL, NULL, NULL, NULL };
100 phNfc_sLowerIF_t *plower_if = NULL;
101 NFCSTATUS status = NFCSTATUS_SUCCESS;
102 uint8_t lower_index=0;
103
104 if( (NULL == psHciHandle) || (NULL == pHwRef) || (NULL == pHalNotify)
105 || (NULL== psContext) || (NULL == psHciLayerCfg) || (NULL == pHwConfig)
106 )
107 {
108 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
109 }
110 else if ( NULL != *(phHciNfc_sContext_t **)psHciHandle )
111 {
112 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_ALREADY_INITIALISED );
113 }
114 else
115 {
116 /* Create the memory for HCI Context */
117 psHciContext = (phHciNfc_sContext_t *)
118 phOsalNfc_GetMemory(sizeof(phHciNfc_sContext_t));
119
120 if(psHciContext != NULL)
121 {
122 (void)memset((void *)psHciContext,0,
123 sizeof(phHciNfc_sContext_t));
124
125 psHciContext->hci_state.cur_state = hciState_Reset;
126 psHciContext->hci_mode = hciMode_Reset;
127 psHciContext->p_hw_ref = pHwRef;
128 psHciContext->host_rf_type = phHal_eUnknown_DevType;
129 HCI_PRINT("HCI Initialisation in Progress.... \n");
130
131 #ifdef ESTABLISH_SESSION
132 /*(void)memcpy(((phHal_sHwReference_t *)pHwRef)->session_id,
133 DEFAULT_SESSION, (sizeof(DEFAULT_SESSION) > 0x01) ?
134 sizeof(DEFAULT_SESSION):
135 sizeof(((phHal_sHwReference_t *)pHwRef)->session_id));*/
136 (void)memcpy(pHwConfig->session_id,
137 DEFAULT_SESSION, ((sizeof(DEFAULT_SESSION) > 0x01)
138 && (sizeof(DEFAULT_SESSION) <= 0x08 )) ?
139 sizeof(DEFAULT_SESSION):
140 sizeof(pHwConfig->session_id));
141 #endif
142 HCI_DEBUG("Sizeof Default Session %u\n",sizeof(DEFAULT_SESSION));
143 psHciContext->p_upper_notify = pHalNotify;
144 psHciContext->p_upper_context = psContext;
145
146 if_callback.pif_ctxt = psHciContext ;
147 if_callback.send_complete = &phHciNfc_Send_Complete;
148 if_callback.receive_complete= &phHciNfc_Receive_Complete;
149 if_callback.notify = &phHciNfc_Notify_Event;
150 plower_if = hciReference.plower_if = &(psHciContext->lower_interface);
151 *((phHciNfc_sContext_t **)psHciHandle) = psHciContext;
152 psHciContext->init_mode = init_mode;
153 psHciContext->p_hci_layer = psHciLayerCfg ;
154 lower_index = psHciLayerCfg->layer_index - 1;
155
156 if(NULL != psHciLayerCfg->layer_next->layer_registry)
157 {
158 status = psHciLayerCfg->layer_next->layer_registry(
159 &hciReference, if_callback,
160 (void *)&psHciLayerCfg[lower_index]);
161 HCI_DEBUG("HCI Lower Layer Register, Status = %02X\n",status);
162 }
163 if( (NFCSTATUS_SUCCESS == status) && (NULL != plower_if->init) )
164 {
165 status = phHciNfc_FSM_Update ( psHciContext,
166 hciState_Initialise
167 );
168 if(NFCSTATUS_SUCCESS == status)
169 {
170 psHciContext->hci_seq = ADMIN_INIT_SEQ;
171 psHciContext->target_release = FALSE;
172 psHciContext->config_type = POLL_LOOP_CFG;
173 psHciContext->p_config_params = pHwConfig ;
174 status = plower_if->init((void *)plower_if->pcontext,
175 (void *)psHciContext->p_hw_ref);
176 HCI_DEBUG("HCI Lower Layer Initialisation, Status = %02X\n",status);
177 if( NFCSTATUS_PENDING != status )
178 {
179 /* Roll Back the State Machine to its Original State */
180 phHciNfc_FSM_Rollback ( psHciContext );
181 }
182 }
183 else
184 {
185 /* TODO: Handle Initialisation in the Invalid State */
186 }
187 }/* End of Lower Layer Init */
188 } /* End of Status Check for Memory */
189 else
190 {
191 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
192
193 HCI_PRINT("HCI Context Memory Allocation Failed\n");
194 }
195
196 }
197 return status;
198 }
199
200
201 /*!
202 * \brief Release of the HCI Interface .
203 *
204 * This function Closes all the open pipes and frees all the resources used by
205 * HCI Layer
206 */
207
208 NFCSTATUS
phHciNfc_Release(void * psHciHandle,void * pHwRef,pphNfcIF_Notification_CB_t pHalReleaseCB,void * psContext)209 phHciNfc_Release (
210 void *psHciHandle,
211 void *pHwRef,
212 pphNfcIF_Notification_CB_t pHalReleaseCB,
213 void *psContext
214 )
215 {
216 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
217 NFCSTATUS status = NFCSTATUS_SUCCESS;
218
219 if( (NULL == psHciHandle)
220 || (NULL == pHwRef)
221 )
222 {
223 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
224 }
225 /* This Scenario Forces the HCI and the lower layers
226 * to release its Resources
227 */
228 else if ( NULL == pHalReleaseCB )
229 {
230 /* Release the lower layer Resources */
231 phHciNfc_Release_Lower( psHciContext, pHwRef );
232 /* Release the HCI layer Resources */
233 phHciNfc_Release_Resources( &psHciContext );
234 }
235 else if ( NULL == psContext )
236 {
237 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
238 }
239 else
240 {
241 HCI_PRINT("HCI Release in Progress.... \n");
242 psHciContext->p_hw_ref = pHwRef;
243 status = phHciNfc_FSM_Update ( psHciContext, hciState_Release );
244 if ((NFCSTATUS_SUCCESS == status)
245 #ifdef NXP_HCI_SHUTDOWN_OVERRIDE
246 || (NFCSTATUS_INVALID_STATE == PHNFCSTATUS(status))
247 #endif
248 )
249 {
250 psHciContext->p_upper_notify = pHalReleaseCB;
251 psHciContext->p_upper_context = psContext;
252 /* psHciContext->hci_seq = EMULATION_REL_SEQ;*/
253 /* psHciContext->hci_seq = READER_MGMT_REL_SEQ; */
254 if (HCI_SELF_TEST != psHciContext->init_mode)
255 {
256 psHciContext->hci_seq = PL_STOP_SEQ;
257 }
258 else
259 {
260 psHciContext->hci_seq = ADMIN_REL_SEQ;
261 }
262
263 #ifdef NXP_HCI_SHUTDOWN_OVERRIDE
264 if (NFCSTATUS_SUCCESS != status)
265 {
266 psHciContext->hci_state.next_state = (uint8_t) hciState_Release;
267 status = NFCSTATUS_PENDING;
268 }
269 else
270 #endif
271 {
272 status = phHciNfc_Release_Sequence(psHciContext,pHwRef);
273 }
274
275 if( NFCSTATUS_PENDING != status )
276 {
277 /* Roll Back the State Machine to its Original State */
278 phHciNfc_FSM_Rollback ( psHciContext );
279 }
280 }
281 else
282 {
283 /* TODO: Return appropriate Error */
284 }
285
286 }
287
288 return status;
289 }
290
291 #if 0
292 /*!
293 * \brief Interface to Starts the RF Device Discovery.
294 *
295 * This function Starts the Discovery Wheel.
296 */
297
298
299 NFCSTATUS
300 phHciNfc_Start_Discovery (
301 void *psHciHandle,
302 void *pHwRef
303 )
304 {
305 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
306 NFCSTATUS status = NFCSTATUS_SUCCESS;
307
308 if ( (NULL == psHciHandle)
309 || (NULL == pHwRef)
310 )
311 {
312 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
313 }
314 else
315 {
316 status = phHciNfc_ReaderMgmt_Enable_Discovery( psHciContext, pHwRef );
317 }
318
319 return status;
320 }
321
322
323 /*!
324 * \brief Interface to Stop the RF Device Discovery.
325 *
326 * This function Stops the Discovery Wheel.
327 */
328
329
330 NFCSTATUS
331 phHciNfc_Stop_Discovery (
332 void *psHciHandle,
333 void *pHwRef
334 )
335 {
336 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
337 NFCSTATUS status = NFCSTATUS_SUCCESS;
338
339 if ( (NULL == psHciHandle)
340 || (NULL == pHwRef)
341 )
342 {
343 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
344 }
345 else
346 {
347 status = phHciNfc_ReaderMgmt_Disable_Discovery( psHciContext, pHwRef );
348 }
349
350 return status;
351 }
352
353
354 #endif
355
356 /*!
357 * \brief Interface to Configure the Device With the appropriate
358 * Configuration Parameters .
359 *
360 * This function configures the Devices with the provided
361 * configuration attributes.
362 */
363
364
365 NFCSTATUS
phHciNfc_Configure(void * psHciHandle,void * pHwRef,phHal_eConfigType_t config_type,phHal_uConfig_t * pConfig)366 phHciNfc_Configure (
367 void *psHciHandle,
368 void *pHwRef,
369 phHal_eConfigType_t config_type,
370 phHal_uConfig_t *pConfig
371 )
372 {
373 NFCSTATUS status = NFCSTATUS_SUCCESS;
374
375 if( (NULL == psHciHandle)
376 || (NULL == pHwRef)
377 || (NULL == pConfig)
378 )
379 {
380 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
381 }
382 else
383 {
384 switch(config_type)
385 {
386 case NFC_P2P_CONFIG:
387 {
388 #ifdef ENABLE_P2P
389 phHciNfc_sContext_t *psHciContext =
390 ((phHciNfc_sContext_t *)psHciHandle);
391 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
392
393 if (NFCSTATUS_SUCCESS == status)
394 {
395 psHciContext->config_type = NFC_GENERAL_CFG;
396 psHciContext->p_config_params = &(pConfig->nfcIPConfig);
397 psHciContext->hci_seq = INITIATOR_GENERAL_SEQ;
398 status = phHciNfc_NfcIP_SetATRInfo( psHciHandle,
399 pHwRef, NFCIP_INITIATOR,
400 &(pConfig->nfcIPConfig));
401 if( NFCSTATUS_PENDING != status )
402 {
403 /* Roll Back the State Machine to its Original State */
404 phHciNfc_FSM_Rollback ( psHciContext );
405 }
406 else
407 {
408 psHciContext->hci_seq = TARGET_GENERAL_SEQ;
409 }
410 }
411 #else
412 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
413
414 #endif
415 break;
416 }
417 case NFC_EMULATION_CONFIG:
418 {
419 status = phHciNfc_Config_Emulation( psHciHandle,
420 pHwRef, &(pConfig->emuConfig));
421 break;
422 }
423 case NFC_SE_PROTECTION_CONFIG:
424 {
425 phHciNfc_sContext_t *psHciContext =
426 ((phHciNfc_sContext_t *)psHciHandle);
427 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
428
429 if (NFCSTATUS_SUCCESS == status)
430 {
431 psHciContext->config_type = SWP_PROTECT_CFG;
432 psHciContext->p_config_params = &(pConfig->protectionConfig);
433 psHciContext->hci_seq = HCI_END_SEQ;
434 status = phHciNfc_SWP_Protection( psHciHandle,
435 pHwRef, pConfig->protectionConfig.mode);
436 if( NFCSTATUS_PENDING != status )
437 {
438 /* Roll Back the State Machine to its Original State */
439 phHciNfc_FSM_Rollback ( psHciContext );
440 }
441 }
442 break;
443 }
444 default:
445 {
446 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
447 break;
448 }
449 }/* End of the Configuration Switch */
450 }
451
452 return status;
453 }
454
455
456 /*!
457 * \brief Interface to Configure the RF Device Discovery using
458 * HCI Polling Loop Gate .
459 *
460 * This function configures the HCI Polling Loop Gate with the provided
461 * configuration attributes.
462 */
463
464 NFCSTATUS
phHciNfc_Config_Discovery(void * psHciHandle,void * pHwRef,phHal_sADD_Cfg_t * pPollConfig)465 phHciNfc_Config_Discovery (
466 void *psHciHandle,
467 void *pHwRef,
468 phHal_sADD_Cfg_t *pPollConfig
469 )
470 {
471 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
472 NFCSTATUS status = NFCSTATUS_SUCCESS;
473
474 if( (NULL == psHciHandle)
475 || (NULL == pHwRef)
476 || (NULL == pPollConfig)
477 )
478 {
479 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
480 }
481 else
482 {
483 psHciContext->p_hw_ref = pHwRef;
484 HCI_PRINT("HCI Poll Configuration .... \n");
485 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
486
487 if (NFCSTATUS_SUCCESS == status)
488 {
489 #if 0
490 if(pPollConfig->PollDevInfo.PollEnabled)
491 {
492 psHciContext->hci_seq = PL_DURATION_SEQ;
493 }
494 else
495 {
496 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
497 /* psHciContext->hci_seq = (pPollConfig->NfcIP_Mode != 0 )?
498 PL_CONFIG_PHASE_SEQ:
499 READER_DISABLE_SEQ; */
500 }
501 #endif
502 psHciContext->hci_seq = PL_DURATION_SEQ;
503 psHciContext->config_type = POLL_LOOP_CFG;
504 psHciContext->p_config_params = pPollConfig;
505 status = phHciNfc_PollLoop_Sequence( psHciContext, pHwRef );
506
507 if( NFCSTATUS_PENDING != status )
508 {
509 /* Roll Back the State Machine to its Original State */
510 phHciNfc_FSM_Rollback ( psHciContext );
511 }
512 }
513 else
514 {
515 /* TODO: Return appropriate Error */
516 }
517 }
518 return status;
519 }
520
521 /*!
522 * \brief Interface to Restart the RF Device Discovery.
523 *
524 * This function restarts the Discovery Wheel.
525 */
526
527
528 NFCSTATUS
phHciNfc_Restart_Discovery(void * psHciHandle,void * pHwRef,uint8_t re_poll)529 phHciNfc_Restart_Discovery (
530 void *psHciHandle,
531 void *pHwRef,
532 uint8_t re_poll
533 )
534 {
535 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
536 NFCSTATUS status = NFCSTATUS_SUCCESS;
537 phHal_eRemDevType_t target_type = phHal_eUnknown_DevType;
538
539 if ( (NULL == psHciHandle)
540 || (NULL == pHwRef)
541 )
542 {
543 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
544 }
545 else
546 {
547 psHciContext->p_hw_ref = pHwRef;
548
549 /* To be back in the Poll State to Re-Poll the Target */
550 status = phHciNfc_FSM_Update ( psHciContext, hciState_Initialise );
551 if (NFCSTATUS_SUCCESS == status)
552 {
553 switch (psHciContext->host_rf_type)
554 {
555 case phHal_eISO14443_A_PCD:
556 {
557 target_type = phHal_eISO14443_A_PICC;
558 break;
559 }
560 case phHal_eNfcIP1_Initiator:
561 {
562 target_type = phHal_eNfcIP1_Target;
563 break;
564 }
565 #ifdef TYPE_B
566 case phHal_eISO14443_B_PCD:
567 {
568 target_type = phHal_eISO14443_B_PICC;
569 break;
570 }
571 #endif
572 #ifdef TYPE_FELICA
573 case phHal_eFelica_PCD:
574 {
575 target_type = phHal_eFelica_PICC;
576 break;
577 }
578 #endif
579 #ifdef TYPE_JEWEL
580 case phHal_eJewel_PCD:
581 {
582 target_type = phHal_eJewel_PICC;
583 break;
584 }
585 #endif
586 #ifdef TYPE_ISO15693
587 case phHal_eISO15693_PCD:
588 {
589 target_type = phHal_eISO15693_PICC;
590 break;
591 }
592 #endif /* #ifdef TYPE_ISO15693 */
593 #ifndef TYPE_B
594 case phHal_eISO14443_B_PCD:
595 #endif
596 #ifndef TYPE_FELICA
597 case phHal_eFelica_PCD:
598 #endif
599 #ifndef TYPE_JEWEL
600 case phHal_eJewel_PCD:
601 #endif
602 #ifndef TYPE_B_PRIME
603 case phHal_eISO14443_BPrime_PCD:
604 #endif
605 {
606 /* Roll Back the State Machine to its Original State */
607 phHciNfc_FSM_Rollback ( psHciContext );
608 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
609 break;
610 }
611 case phHal_eUnknown_DevType:
612 default:
613 {
614 /* Roll Back the State Machine to its Original State */
615 phHciNfc_FSM_Rollback ( psHciContext );
616 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
617 break;
618 }
619 }/* End of the Remote Target Type Switch */
620 if( NFCSTATUS_SUCCESS == status )
621 {
622 status = phHciNfc_ReaderMgmt_Deselect(
623 psHciContext, pHwRef, target_type, re_poll);
624 if( NFCSTATUS_PENDING != status )
625 {
626 /* Roll Back the State Machine to its Original State */
627 phHciNfc_FSM_Rollback ( psHciContext );
628 }
629 else
630 {
631 psHciContext->host_rf_type = phHal_eUnknown_DevType;
632 }
633 }
634 }
635 else
636 {
637 /* TODO: Return appropriate Error */
638 }
639 }
640
641 return status;
642 }
643
644
645
646 /*!
647 * \brief Interface to Configure the device to emulation as
648 * the tag, smart tag or p2p target .
649 *
650 * This function configures the HCI Polling Loop Gate with the provided
651 * configuration attributes.
652 */
653
654 static
655 NFCSTATUS
phHciNfc_Config_Emulation(void * psHciHandle,void * pHwRef,phHal_sEmulationCfg_t * pEmulationCfg)656 phHciNfc_Config_Emulation (
657 void *psHciHandle,
658 void *pHwRef,
659 phHal_sEmulationCfg_t *pEmulationCfg
660 )
661 {
662 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
663 NFCSTATUS status = NFCSTATUS_SUCCESS;
664
665 if( (NULL == psHciHandle)
666 || (NULL == pHwRef)
667 || (NULL == pEmulationCfg)
668 )
669 {
670 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
671 }
672 else
673 {
674 psHciContext->p_hw_ref = pHwRef;
675
676 HCI_PRINT("HCI Configure Emulation .... \n");
677 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
678
679 if (NFCSTATUS_SUCCESS == status)
680 {
681 psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
682 psHciContext->p_config_params = pEmulationCfg;
683 switch( pEmulationCfg->emuType )
684 {
685 case NFC_SMARTMX_EMULATION:
686 {
687 psHciContext->config_type = SMX_WI_CFG;
688 status = phHciNfc_Emulation_Cfg(psHciContext,
689 pHwRef, SMX_WI_CFG);
690 break;
691 }
692 case NFC_UICC_EMULATION:
693 {
694 psHciContext->config_type = UICC_SWP_CFG;
695 psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
696 (void)phHciNfc_SWP_Update_Sequence(
697 psHciContext, CONFIG_SEQ );
698 status = phHciNfc_EmulationCfg_Sequence(
699 psHciContext, pHwRef);
700 break;
701 }
702 case NFC_HOST_CE_A_EMULATION:
703 case NFC_HOST_CE_B_EMULATION:
704 #if defined(HOST_EMULATION)
705 {
706 if(TRUE == pEmulationCfg->config.
707 hostEmuCfg_A.enableEmulation)
708 {
709 psHciContext->hci_seq = ADMIN_CE_SEQ;
710 }
711 status = phHciNfc_EmulationCfg_Sequence(
712 psHciContext, pHwRef);
713 break;
714 }
715 #endif
716 default:
717 {
718 break;
719 }
720
721 } /* End of Config Switch */
722 if( NFCSTATUS_PENDING != status )
723 {
724 /* Roll Back the State Machine to its Original State */
725 phHciNfc_FSM_Rollback ( psHciContext );
726 }
727 }
728 else
729 {
730 /* TODO: Return appropriate Error */
731 }
732 }
733
734 return status;
735 }
736
737 NFCSTATUS
phHciNfc_Switch_SwpMode(void * psHciHandle,void * pHwRef,phHal_eSWP_Mode_t swp_mode)738 phHciNfc_Switch_SwpMode (
739 void *psHciHandle,
740 void *pHwRef,
741 phHal_eSWP_Mode_t swp_mode /* ,
742 void *pSwpCfg */
743 )
744 {
745 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
746 NFCSTATUS status = NFCSTATUS_SUCCESS;
747
748 if( (NULL == psHciHandle)
749 || (NULL == pHwRef)
750 )
751 {
752 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
753 }
754 else
755 {
756 psHciContext->p_hw_ref = pHwRef;
757
758 HCI_PRINT("HCI SWP Switch .... ");
759 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
760 if (NFCSTATUS_SUCCESS == status)
761 {
762 psHciContext->config_type = SWP_EVT_CFG;
763 status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef ,
764 (uint8_t) swp_mode );
765
766 /* Send the Success Status as this is an event */
767 status = ((status == NFCSTATUS_SUCCESS)?
768 NFCSTATUS_PENDING : status);
769
770 if( NFCSTATUS_PENDING != status )
771 {
772 /* Roll Back the State Machine to its Original State */
773 phHciNfc_FSM_Rollback ( psHciContext );
774
775 HCI_PRINT(" Execution Error \n");
776 }
777 else
778 {
779 HCI_PRINT(" Successful \n");
780 }
781 }
782 else
783 {
784 HCI_PRINT(" Not allowed - Invalid State \n");
785 /* TODO: Return appropriate Error */
786 }
787 }
788
789 return status;
790 }
791
792
793
794 /*!
795 * \brief Interface to Switch the Mode of the SmartMx from Virtual/Wired
796 * to the other mode.
797 *
798 * This function switches the mode of the SmartMX connected through WI(S2C)
799 * Interface to virtual/wired mode.
800 */
801
802
803 NFCSTATUS
phHciNfc_Switch_SmxMode(void * psHciHandle,void * pHwRef,phHal_eSmartMX_Mode_t smx_mode,phHal_sADD_Cfg_t * pPollConfig)804 phHciNfc_Switch_SmxMode (
805 void *psHciHandle,
806 void *pHwRef,
807 phHal_eSmartMX_Mode_t smx_mode,
808 phHal_sADD_Cfg_t *pPollConfig
809 )
810 {
811 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
812 NFCSTATUS status = NFCSTATUS_SUCCESS;
813
814 if( (NULL == psHciHandle)
815 || (NULL == pHwRef)
816 || (NULL == pPollConfig)
817 )
818 {
819 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
820 }
821 else
822 {
823 psHciContext->p_hw_ref = pHwRef;
824
825 HCI_PRINT("HCI Smart MX Mode Switch .... \n");
826 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
827
828 if (NFCSTATUS_SUCCESS == status)
829 {
830 psHciContext->hci_seq = READER_DISABLE_SEQ;
831 if ( (eSmartMx_Wired == psHciContext->smx_mode)
832 && ( hciState_Connect == psHciContext->hci_state.cur_state)
833 &&( eSmartMx_Wired != smx_mode)
834 )
835 {
836 /* Workaround: For Wired Mode Disconnect
837 All the statemachine updates should be done only with the
838 Statemachine API and should not be overridden.
839 */
840 psHciContext->hci_state.cur_state = hciState_Disconnect;
841 }
842 psHciContext->config_type = SMX_WI_MODE;
843 psHciContext->smx_mode = smx_mode;
844 psHciContext->p_config_params = pPollConfig;
845 status = phHciNfc_SmartMx_Mode_Sequence( psHciContext, pHwRef );
846 if( NFCSTATUS_PENDING != status )
847 {
848 /* Roll Back the State Machine to its Original State */
849 phHciNfc_FSM_Rollback ( psHciContext );
850 }
851 }
852 else
853 {
854 /* TODO: Return appropriate Error */
855 }
856 }
857
858 return status;
859 }
860
861
862 /*!
863 * \brief Interface to Select the Next Remote Target Discovered during the
864 * discovery sequence using the particular HCI Reader Gate .
865 *
866 *
867 * This function Selects and Activates the next Remote Target
868 * Detected using the particular HCI Reader Gate.
869 */
870
871
872
873 NFCSTATUS
phHciNfc_Select_Next_Target(void * psHciHandle,void * pHwRef)874 phHciNfc_Select_Next_Target (
875 void *psHciHandle,
876 void *pHwRef
877 )
878 {
879 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
880 NFCSTATUS status = NFCSTATUS_SUCCESS;
881
882 if( (NULL == psHciHandle)
883 || (NULL == pHwRef)
884 )
885 {
886 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
887 }
888 else
889 {
890 psHciContext->p_hw_ref = pHwRef;
891 status = phHciNfc_FSM_Update ( psHciContext, hciState_Select );
892 if (NFCSTATUS_SUCCESS == status)
893 {
894 psHciContext->hci_seq = READER_SELECT_SEQ;
895 status = phHciNfc_ReaderMgmt_Activate_Next( psHciContext, pHwRef );
896 if( NFCSTATUS_PENDING != status )
897 {
898 /* Roll Back the State Machine to its Original State */
899 phHciNfc_FSM_Rollback ( psHciContext );
900 }
901 }
902 else
903 {
904 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
905 }
906 }
907
908 return status;
909
910 }
911
912
913 /*!
914 * \brief Interface to Connect the Remote Target Discovered during the
915 * discovery sequence using the particular HCI Reader Gate .
916 *
917 *
918 * This function connects the Remote Target Detected using the particular
919 * HCI Reader Gate with the appropriate configuration setup.
920 */
921
922
923 NFCSTATUS
phHciNfc_Connect(void * psHciHandle,void * pHwRef,phHal_sRemoteDevInformation_t * p_target_info)924 phHciNfc_Connect (
925 void *psHciHandle,
926 void *pHwRef,
927 phHal_sRemoteDevInformation_t *p_target_info
928 )
929 {
930 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
931 NFCSTATUS status = NFCSTATUS_SUCCESS;
932 /* phHal_eRemDevType_t target_type = phHal_eUnknown_DevType; */
933
934 if( (NULL == psHciHandle)
935 || (NULL == pHwRef)
936 || (NULL == p_target_info)
937 )
938 {
939 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
940 }
941 else
942 {
943 psHciContext->p_hw_ref = pHwRef;
944 status = phHciNfc_FSM_Update ( psHciContext, hciState_Connect );
945 if (NFCSTATUS_SUCCESS == status)
946 {
947 psHciContext->hci_seq = READER_SELECT_SEQ;
948 switch (p_target_info->RemDevType)
949 {
950 case phHal_eISO14443_A_PICC:
951 case phHal_eISO14443_4A_PICC:
952 case phHal_eMifare_PICC:
953 case phHal_eISO14443_3A_PICC:
954 #ifdef ENABLE_P2P
955 case phHal_eNfcIP1_Target:
956 #endif
957 #ifdef TYPE_B
958 case phHal_eISO14443_B_PICC:
959 case phHal_eISO14443_4B_PICC:
960 #endif
961 #ifdef TYPE_FELICA
962 case phHal_eFelica_PICC:
963 #endif
964 #ifdef TYPE_JEWEL
965 case phHal_eJewel_PICC:
966 #endif
967 #ifdef TYPE_ISO15693
968 case phHal_eISO15693_PICC:
969 #endif /* #ifdef TYPE_ISO15693 */
970
971 {
972 psHciContext->p_target_info = p_target_info;
973 status = phHciNfc_ReaderMgmt_Select(
974 psHciContext, pHwRef,
975 p_target_info->RemDevType );
976 break;
977 }
978 #ifndef TYPE_B_PRIME
979 case phHal_eISO14443_BPrime_PICC:
980 #endif
981 case phHal_eUnknown_DevType:
982 default:
983 {
984 /* Roll Back the State Machine to its Original State */
985 phHciNfc_FSM_Rollback ( psHciContext );
986 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
987 break;
988 }
989 }/* End of the Remote Target Type Switch */
990 if( NFCSTATUS_PENDING != status )
991 {
992 /* Roll Back the State Machine to its Original State */
993 phHciNfc_FSM_Rollback ( psHciContext );
994 }
995 }
996 else
997 {
998 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
999 }
1000
1001 } /* End of the HCI Handle Validation */
1002
1003 return status;
1004 }
1005
1006
1007 /*!
1008 * \brief Interface to Reactivate the Remote Targets Discovered during the
1009 * discovery sequence using the particular HCI Reader Gate .
1010 *
1011 *
1012 * This function reactivates the Remote Target Detected using the particular
1013 * HCI Reader Gate with the appropriate configuration setup.
1014 */
1015
1016
1017 NFCSTATUS
phHciNfc_Reactivate(void * psHciHandle,void * pHwRef,phHal_sRemoteDevInformation_t * p_target_info)1018 phHciNfc_Reactivate (
1019 void *psHciHandle,
1020 void *pHwRef,
1021 phHal_sRemoteDevInformation_t *p_target_info
1022 )
1023 {
1024 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1025 NFCSTATUS status = NFCSTATUS_SUCCESS;
1026 /* phHal_eRemDevType_t target_type = phHal_eUnknown_DevType; */
1027
1028 if( (NULL == psHciHandle)
1029 || (NULL == pHwRef)
1030 || (NULL == p_target_info)
1031 )
1032 {
1033 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1034 }
1035 else
1036 {
1037 psHciContext->p_hw_ref = pHwRef;
1038 status = phHciNfc_FSM_Update ( psHciContext, hciState_Reactivate );
1039 if (NFCSTATUS_SUCCESS == status)
1040 {
1041 psHciContext->hci_seq = READER_REACTIVATE_SEQ;
1042 switch (p_target_info->RemDevType)
1043 {
1044 case phHal_eISO14443_A_PICC:
1045 case phHal_eISO14443_4A_PICC:
1046 case phHal_eMifare_PICC:
1047 case phHal_eISO14443_3A_PICC:
1048 {
1049 psHciContext->host_rf_type = phHal_eISO14443_A_PCD;
1050 break;
1051 }
1052 case phHal_eNfcIP1_Target:
1053 {
1054 psHciContext->host_rf_type = phHal_eNfcIP1_Initiator;
1055 break;
1056 }
1057 #ifdef TYPE_B
1058 case phHal_eISO14443_4B_PICC:
1059 case phHal_eISO14443_B_PICC:
1060 {
1061 psHciContext->host_rf_type = phHal_eISO14443_B_PCD;
1062 break;
1063 }
1064 #endif
1065 #ifdef TYPE_FELICA
1066 case phHal_eFelica_PICC:
1067 {
1068 psHciContext->host_rf_type = phHal_eFelica_PCD;
1069 break;
1070 }
1071 #endif
1072 #ifdef TYPE_B_PRIME
1073 case phHal_eISO14443_BPrime_PICC:
1074 #endif
1075 /* Reactivate for Jewel is not Supported */
1076 case phHal_eJewel_PICC:
1077 case phHal_eUnknown_DevType:
1078 default:
1079 {
1080 /* Roll Back the State Machine to its Original State */
1081 phHciNfc_FSM_Rollback ( psHciContext );
1082 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1083 break;
1084 }
1085 }/* End of the Remote Target Type Switch */
1086 }
1087 else
1088 {
1089 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1090 }
1091
1092 if(NFCSTATUS_SUCCESS == status )
1093 {
1094 psHciContext->p_target_info = p_target_info;
1095 status = phHciNfc_ReaderMgmt_Reactivate(
1096 psHciContext, pHwRef, p_target_info->RemDevType );
1097 if( NFCSTATUS_PENDING != status )
1098 {
1099 /* Roll Back the State Machine to its Original State */
1100 phHciNfc_FSM_Rollback ( psHciContext );
1101 }
1102 }
1103 } /* End of the HCI Handle Validation */
1104
1105
1106 return status;
1107 }
1108
1109
1110 /*!
1111 * \brief Interface to Disconnect the selected target.
1112 *
1113 * This function disconnects the remote target selected.
1114 */
1115
1116
1117 NFCSTATUS
phHciNfc_Disconnect(void * psHciHandle,void * pHwRef,uint8_t re_poll)1118 phHciNfc_Disconnect (
1119 void *psHciHandle,
1120 void *pHwRef,
1121 uint8_t re_poll
1122 )
1123 {
1124 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1125 NFCSTATUS status = NFCSTATUS_SUCCESS;
1126 phHal_eRemDevType_t target_type = phHal_eUnknown_DevType;
1127 /* phHal_eSmartMX_Mode_t smx_mode = (phHal_eSmartMX_Mode_t)type; */
1128 static uint8_t repoll=0;
1129
1130
1131 if( (NULL == psHciHandle)
1132 || (NULL == pHwRef)
1133 || ( NULL == psHciContext->p_target_info)
1134 )
1135 {
1136 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1137 }
1138 else
1139 {
1140 psHciContext->p_hw_ref = pHwRef;
1141 repoll = re_poll;
1142 psHciContext->p_config_params = &repoll;
1143 /* psHciContext->hci_seq = HCI_END_SEQ; */
1144
1145 /* To be back in the Poll State to Re-Poll the Target */
1146 status = phHciNfc_FSM_Update ( psHciContext, hciState_Disconnect );
1147 if (NFCSTATUS_SUCCESS == status)
1148 {
1149 psHciContext->hci_seq = READER_UICC_DISPATCH_SEQ;
1150 target_type = psHciContext->p_target_info->RemDevType;
1151 switch (target_type)
1152 {
1153 case phHal_eMifare_PICC:
1154 case phHal_eISO14443_A_PICC:
1155 case phHal_eISO14443_4A_PICC:
1156 case phHal_eISO14443_3A_PICC:
1157 case phHal_eNfcIP1_Target:
1158 #ifdef TYPE_B
1159 case phHal_eISO14443_B_PICC:
1160 case phHal_eISO14443_4B_PICC:
1161 #endif
1162 #ifdef TYPE_FELICA
1163 case phHal_eFelica_PICC:
1164 #endif
1165 #ifdef TYPE_JEWEL
1166 case phHal_eJewel_PICC:
1167 #endif
1168 #ifdef TYPE_ISO15693
1169 case phHal_eISO15693_PICC:
1170 #endif /* #ifdef TYPE_ISO15693 */
1171
1172 {
1173 status = phHciNfc_Disconnect_Sequence(
1174 psHciContext, pHwRef );
1175 break;
1176 }
1177 #ifndef TYPE_B
1178 case phHal_eISO14443_B_PICC:
1179 case phHal_eISO14443_4B_PICC:
1180 #endif
1181 #ifndef TYPE_FELICA
1182 case phHal_eFelica_PICC:
1183 #endif
1184 #ifndef TYPE_JEWEL
1185 case phHal_eJewel_PICC:
1186 #endif
1187 #ifndef TYPE_B_PRIME
1188 case phHal_eISO14443_BPrime_PICC:
1189 #endif
1190 {
1191 /* Roll Back the State Machine to its Original State */
1192 phHciNfc_FSM_Rollback ( psHciContext );
1193 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1194 break;
1195 }
1196 case phHal_eUnknown_DevType:
1197 default:
1198 {
1199 /* Roll Back the State Machine to its Original State */
1200 phHciNfc_FSM_Rollback ( psHciContext );
1201 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1202 break;
1203 }
1204 }/* End of the Remote Target Type Switch */
1205 if( NFCSTATUS_PENDING != status )
1206 {
1207 /* Roll Back the State Machine to its Original State */
1208 phHciNfc_FSM_Rollback ( psHciContext );
1209 }
1210 }
1211 else
1212 {
1213 /* TODO: Return appropriate Error */
1214 }
1215 } /* End of the HCI Handle Validation */
1216
1217 return status;
1218 }
1219
1220 /*!
1221 * \brief Interface to exchange the data to/from
1222 * the selected target.
1223 *
1224 * This function sends and receives the data to/from
1225 * the selected remote target.
1226 */
1227
1228 NFCSTATUS
phHciNfc_Exchange_Data(void * psHciHandle,void * pHwRef,phHal_sRemoteDevInformation_t * p_target_info,phHciNfc_XchgInfo_t * p_xchg_info)1229 phHciNfc_Exchange_Data (
1230 void *psHciHandle,
1231 void *pHwRef,
1232 phHal_sRemoteDevInformation_t *p_target_info,
1233 phHciNfc_XchgInfo_t *p_xchg_info
1234 )
1235 {
1236 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1237 NFCSTATUS status = NFCSTATUS_SUCCESS;
1238
1239 if( (NULL == psHciHandle)
1240 || (NULL == pHwRef)
1241 || (NULL == p_target_info)
1242 || (NULL == p_xchg_info)
1243 )
1244 {
1245 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1246 }
1247 else if (p_target_info != psHciContext->p_target_info )
1248 {
1249 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_REMOTE_DEVICE);
1250 }
1251 else
1252 {
1253 psHciContext->p_hw_ref = pHwRef;
1254 status = phHciNfc_FSM_Update ( psHciContext, hciState_Transact );
1255 if (NFCSTATUS_SUCCESS == status)
1256 {
1257 switch (p_target_info->RemDevType)
1258 {
1259 case phHal_eMifare_PICC:
1260 case phHal_eISO14443_A_PICC:
1261 case phHal_eISO14443_4A_PICC:
1262 case phHal_eISO14443_3A_PICC:
1263 #ifdef TYPE_B
1264 case phHal_eISO14443_B_PICC:
1265 case phHal_eISO14443_4B_PICC:
1266 #endif
1267 #ifdef TYPE_FELICA
1268 case phHal_eFelica_PICC:
1269 #endif
1270 #ifdef TYPE_JEWEL
1271 case phHal_eJewel_PICC:
1272 #endif
1273 #ifdef TYPE_ISO15693
1274 case phHal_eISO15693_PICC:
1275 #endif /* #ifdef TYPE_ISO15693 */
1276 {
1277 psHciContext->p_xchg_info = p_xchg_info;
1278 status = phHciNfc_ReaderMgmt_Exchange_Data(
1279 psHciContext, pHwRef, p_xchg_info );
1280 break;
1281 }
1282 #ifndef TYPE_B
1283 case phHal_eISO14443_B_PICC:
1284 case phHal_eISO14443_4B_PICC:
1285 #endif
1286 #ifndef TYPE_FELICA
1287 case phHal_eFelica_PICC:
1288 #endif
1289 #ifndef TYPE_JEWEL
1290 case phHal_eJewel_PICC:
1291 #endif
1292 case phHal_eNfcIP1_Target:
1293 #ifndef TYPE_B_PRIME
1294 case phHal_eISO14443_BPrime_PICC:
1295 #endif
1296 {
1297 /* Roll Back the State Machine to its Original State */
1298 phHciNfc_FSM_Rollback ( psHciContext );
1299 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1300 break;
1301 }
1302 case phHal_eUnknown_DevType:
1303 default:
1304 {
1305 /* Roll Back the State Machine to its Original State */
1306 phHciNfc_FSM_Rollback ( psHciContext );
1307 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1308 break;
1309 }
1310
1311 }/* End of the Remote Target Type Switch */
1312 if( NFCSTATUS_PENDING != status )
1313 {
1314 /* Roll Back the State Machine to its Original State */
1315 phHciNfc_FSM_Rollback ( psHciContext );
1316 }
1317 }
1318 else
1319 {
1320 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1321 }
1322 } /* End of the HCI Handle Validation */
1323
1324 return status;
1325 }
1326
1327 /*!
1328 * \brief Interface to Send the data to/from
1329 * the selected NfcIP.
1330 *
1331 * This function sends and receives the data to/from
1332 * the selected remote target.
1333 */
1334
1335 NFCSTATUS
phHciNfc_Send_Data(void * psHciHandle,void * pHwRef,phHal_sRemoteDevInformation_t * p_remote_dev_info,phHciNfc_XchgInfo_t * p_send_param)1336 phHciNfc_Send_Data (
1337 void *psHciHandle,
1338 void *pHwRef,
1339 phHal_sRemoteDevInformation_t *p_remote_dev_info,
1340 phHciNfc_XchgInfo_t *p_send_param
1341 )
1342 {
1343 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1344 NFCSTATUS status = NFCSTATUS_SUCCESS;
1345
1346 if( (NULL == psHciHandle)
1347 || (NULL == pHwRef)
1348 || (NULL == p_send_param)
1349 )
1350 {
1351 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1352 }
1353 else
1354 {
1355 psHciContext->p_hw_ref = pHwRef;
1356 status = phHciNfc_FSM_Update ( psHciContext, hciState_Transact );
1357 if (NFCSTATUS_SUCCESS == status)
1358 {
1359 switch (psHciContext->host_rf_type)
1360 {
1361 case phHal_eISO14443_A_PICC:
1362 case phHal_eISO14443_B_PICC:
1363 case phHal_eISO14443_4A_PICC:
1364 case phHal_eISO14443_4B_PICC:
1365 {
1366 break;
1367 }
1368 #ifdef ENABLE_P2P
1369 case phHal_eNfcIP1_Initiator:
1370 {
1371 if (p_remote_dev_info !=
1372 psHciContext->p_target_info )
1373 {
1374 status = PHNFCSTVAL(CID_NFC_HCI,
1375 NFCSTATUS_INVALID_REMOTE_DEVICE);
1376 }
1377 else
1378 {
1379 psHciContext->p_xchg_info = p_send_param;
1380 status = phHciNfc_NfcIP_Send_Data( psHciContext,
1381 pHwRef, p_send_param );
1382 }
1383 break;
1384 }
1385 case phHal_eNfcIP1_Target:
1386 {
1387 psHciContext->p_xchg_info = p_send_param;
1388 status = phHciNfc_NfcIP_Send_Data( psHciContext,
1389 pHwRef, p_send_param );
1390 break;
1391 }
1392 #endif
1393 #ifdef TYPE_B_PRIME
1394 case phHal_eISO14443_BPrime_PCD:
1395 case phHal_eFelica_PCD:
1396 {
1397 /* Roll Back the State Machine to its Original State */
1398 phHciNfc_FSM_Rollback ( psHciContext );
1399 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1400 break;
1401 }
1402 #endif
1403 case phHal_eUnknown_DevType:
1404 default:
1405 {
1406 /* Roll Back the State Machine to its Original State */
1407 phHciNfc_FSM_Rollback ( psHciContext );
1408 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1409 break;
1410 }
1411
1412 }/* End of the Remote Target Type Switch */
1413 #if defined( ENABLE_P2P ) || defined (TYPE_B_PRIME)
1414 if( NFCSTATUS_PENDING != status )
1415 #endif
1416 {
1417 /* Roll Back the State Machine to its Original State */
1418 phHciNfc_FSM_Rollback ( psHciContext );
1419 }
1420 }
1421 else
1422 {
1423 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1424 }
1425 } /* End of the HCI Handle Validation */
1426
1427 return status;
1428
1429 }
1430
1431 #if 0
1432
1433 /*!
1434 * \brief Interface to Send the data from
1435 * the selected NfcIP.
1436 *
1437 * This function sends and receives the data to/from
1438 * the selected remote target.
1439 */
1440
1441 NFCSTATUS
1442 phHciNfc_Receive_Data (
1443 void *psHciHandle,
1444 void *pHwRef,
1445 uint8_t *p_data,
1446 uint8_t length
1447 )
1448 {
1449 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1450 NFCSTATUS status = NFCSTATUS_SUCCESS;
1451
1452 if( (NULL == psHciHandle)
1453 || (NULL == pHwRef)
1454 )
1455 {
1456 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1457 }
1458 else
1459 {
1460 if (NFCSTATUS_SUCCESS == status)
1461 {
1462 status = phHciNfc_Receive(psHciHandle, pHwRef, p_data, length);
1463 if( NFCSTATUS_PENDING != status )
1464 {
1465 /* Roll Back the State Machine to its Original State */
1466 phHciNfc_FSM_Rollback ( psHciContext );
1467 }
1468 }
1469 }
1470 return status;
1471
1472 }
1473
1474 #endif
1475
1476 /*!
1477 * \brief Interface to Check for the presence of
1478 * the selected target in the field .
1479 *
1480 * This function checks the presence of the
1481 * the selected remote target in the field .
1482 */
1483
1484
1485
1486 NFCSTATUS
phHciNfc_Presence_Check(void * psHciHandle,void * pHwRef)1487 phHciNfc_Presence_Check (
1488 void *psHciHandle,
1489 void *pHwRef
1490 )
1491 {
1492 NFCSTATUS status = NFCSTATUS_SUCCESS;
1493 phHciNfc_sContext_t *psHciContext =
1494 ((phHciNfc_sContext_t *)psHciHandle);
1495 phHal_eRemDevType_t target_type = phHal_eUnknown_DevType;
1496
1497 if( (NULL == psHciContext)
1498 || (NULL == pHwRef)
1499 )
1500 {
1501 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1502 }
1503 else
1504 {
1505 psHciContext->p_hw_ref = pHwRef;
1506 status = phHciNfc_FSM_Update ( psHciContext, hciState_Presence );
1507 if (NFCSTATUS_SUCCESS == status)
1508 {
1509 target_type = psHciContext->p_target_info->RemDevType;
1510 switch (target_type)
1511 {
1512 case phHal_eISO14443_A_PICC:
1513 case phHal_eMifare_PICC:
1514 case phHal_eISO14443_4A_PICC:
1515 case phHal_eISO14443_3A_PICC:
1516 #ifdef TYPE_B
1517 case phHal_eISO14443_B_PICC:
1518 case phHal_eISO14443_4B_PICC:
1519 #endif
1520 #ifdef TYPE_FELICA
1521 case phHal_eFelica_PICC:
1522 #endif
1523 #ifdef TYPE_JEWEL
1524 case phHal_eJewel_PICC:
1525 #endif
1526 #ifdef TYPE_ISO15693
1527 case phHal_eISO15693_PICC:
1528 #endif /* #ifdef TYPE_ISO15693 */
1529 #ifdef ENABLE_P2P
1530 case phHal_eNfcIP1_Target:
1531 #endif
1532 {
1533 status = phHciNfc_ReaderMgmt_Presence_Check(
1534 psHciContext, pHwRef );
1535 break;
1536 }
1537 #ifdef TYPE_B_PRIME
1538 case phHal_eISO14443_BPrime_PICC:
1539 #endif
1540 #ifndef TYPE_B
1541 case phHal_eISO14443_B_PICC:
1542 case phHal_eISO14443_4B_PICC:
1543 #endif
1544 #ifndef TYPE_FELICA
1545 case phHal_eFelica_PICC:
1546 #endif
1547 #ifndef TYPE_JEWEL
1548 case phHal_eJewel_PICC:
1549 #endif
1550 case phHal_eUnknown_DevType:
1551 {
1552 /* Roll Back the State Machine to its Original State */
1553 phHciNfc_FSM_Rollback ( psHciContext );
1554 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1555 break;
1556 }
1557 default:
1558 {
1559 /* Roll Back the State Machine to its Original State */
1560 phHciNfc_FSM_Rollback ( psHciContext );
1561 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1562 break;
1563 }
1564
1565 }/* End of the Remote Target Type Switch */
1566 if( NFCSTATUS_PENDING != status )
1567 {
1568 /* Roll Back the State Machine to its Original State */
1569 phHciNfc_FSM_Rollback ( psHciContext );
1570 }
1571 }
1572 else
1573 {
1574 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1575 }
1576 } /* End of the HCI Handle Validation */
1577
1578 return status;
1579 }
1580
1581 NFCSTATUS
phHciNfc_PRBS_Test(void * psHciHandle,void * pHwRef,uint32_t test_type,phNfc_sData_t * test_param)1582 phHciNfc_PRBS_Test (
1583 void *psHciHandle,
1584 void *pHwRef,
1585 uint32_t test_type,
1586 phNfc_sData_t *test_param
1587 )
1588 {
1589 NFCSTATUS status = NFCSTATUS_SUCCESS;
1590 phHciNfc_sContext_t *psHciContext =
1591 ((phHciNfc_sContext_t *)psHciHandle);
1592
1593 if( (NULL == psHciContext)
1594 || (NULL == pHwRef)
1595 || (test_type != DEVMGMT_PRBS_TEST)
1596 )
1597 {
1598 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1599 }
1600 else
1601 {
1602 psHciContext->p_hw_ref = pHwRef;
1603 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1604 if (NFCSTATUS_SUCCESS == status)
1605 {
1606 status = phHciNfc_DevMgmt_Test(psHciContext, pHwRef,
1607 (uint8_t)(test_type & DEVMGMT_TEST_MASK), test_param);
1608 if( NFCSTATUS_PENDING != status )
1609 {
1610 /* Roll Back the State Machine to its Original State */
1611 phHciNfc_FSM_Rollback ( psHciContext );
1612 }
1613 }
1614 }
1615 return status;
1616 }
1617
1618
1619 NFCSTATUS
phHciNfc_System_Test(void * psHciHandle,void * pHwRef,uint32_t test_type,phNfc_sData_t * test_param)1620 phHciNfc_System_Test (
1621 void *psHciHandle,
1622 void *pHwRef,
1623 uint32_t test_type,
1624 phNfc_sData_t *test_param
1625 )
1626 {
1627 NFCSTATUS status = NFCSTATUS_SUCCESS;
1628 phHciNfc_sContext_t *psHciContext =
1629 ((phHciNfc_sContext_t *)psHciHandle);
1630 static phNfc_sData_t test_result;
1631 static uint8_t gpio_status = 0;
1632
1633 if( (NULL == psHciContext)
1634 || (NULL == pHwRef)
1635 )
1636 {
1637 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1638 }
1639 else
1640 {
1641 psHciContext->p_hw_ref = pHwRef;
1642 status = phHciNfc_FSM_Update ( psHciContext, hciState_Test );
1643 if (NFCSTATUS_SUCCESS == status)
1644 {
1645 if (test_type != NFC_GPIO_READ)
1646 {
1647 status = phHciNfc_DevMgmt_Test(psHciContext, pHwRef,
1648 (uint8_t)(test_type & DEVMGMT_TEST_MASK), test_param);
1649 }
1650 else
1651 {
1652 test_result.buffer = &gpio_status;
1653 status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef,
1654 (uint16_t)NFC_GPIO_READ, test_result.buffer);
1655
1656 }
1657 if( NFCSTATUS_PENDING != status )
1658 {
1659 /* Roll Back the State Machine to its Original State */
1660 phHciNfc_FSM_Rollback ( psHciContext );
1661 }
1662 }
1663 }
1664
1665 return status;
1666 }
1667
1668
1669 NFCSTATUS
phHciNfc_System_Configure(void * psHciHandle,void * pHwRef,uint32_t config_type,uint8_t config_value)1670 phHciNfc_System_Configure (
1671 void *psHciHandle,
1672 void *pHwRef,
1673 uint32_t config_type,
1674 uint8_t config_value
1675 )
1676 {
1677 NFCSTATUS status = NFCSTATUS_SUCCESS;
1678 phHciNfc_sContext_t *psHciContext =
1679 ((phHciNfc_sContext_t *)psHciHandle);
1680
1681 if( (NULL == psHciContext)
1682 || (NULL == pHwRef)
1683 )
1684 {
1685 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1686 }
1687 else
1688 {
1689 psHciContext->p_hw_ref = pHwRef;
1690 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1691 if (NFCSTATUS_SUCCESS == status)
1692 {
1693 status = phHciNfc_DevMgmt_Configure(psHciContext, pHwRef,
1694 (uint16_t)config_type, config_value);
1695
1696 if( NFCSTATUS_PENDING != status )
1697 {
1698 /* Roll Back the State Machine to its Original State */
1699 phHciNfc_FSM_Rollback ( psHciContext );
1700 }
1701 }
1702 }
1703 return status;
1704 }
1705
1706 NFCSTATUS
phHciNfc_System_Get_Info(void * psHciHandle,void * pHwRef,uint32_t config_type,uint8_t * p_config_value)1707 phHciNfc_System_Get_Info(
1708 void *psHciHandle,
1709 void *pHwRef,
1710 uint32_t config_type,
1711 uint8_t *p_config_value
1712 )
1713 {
1714 NFCSTATUS status = NFCSTATUS_SUCCESS;
1715 phHciNfc_sContext_t *psHciContext =
1716 ((phHciNfc_sContext_t *)psHciHandle);
1717
1718 if( (NULL == psHciContext)
1719 || (NULL == pHwRef)
1720 || (NULL == p_config_value)
1721 )
1722 {
1723 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1724 }
1725 else
1726 {
1727 psHciContext->p_hw_ref = pHwRef;
1728 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1729 if (NFCSTATUS_SUCCESS == status)
1730 {
1731 status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef,
1732 (uint16_t)config_type, p_config_value);
1733
1734 if( NFCSTATUS_PENDING != status )
1735 {
1736 /* Roll Back the State Machine to its Original State */
1737 phHciNfc_FSM_Rollback ( psHciContext );
1738 }
1739 }
1740 }
1741
1742 return status;
1743 }
1744
1745
1746 NFCSTATUS
phHciNfc_Get_Link_Status(void * psHciHandle,void * pHwRef)1747 phHciNfc_Get_Link_Status(
1748 void *psHciHandle,
1749 void *pHwRef
1750 )
1751 {
1752 NFCSTATUS status = NFCSTATUS_SUCCESS;
1753 phHciNfc_sContext_t *psHciContext =
1754 ((phHciNfc_sContext_t *)psHciHandle);
1755
1756 if( (NULL == psHciContext)
1757 || (NULL == pHwRef)
1758 )
1759 {
1760 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1761 }
1762 else
1763 {
1764 psHciContext->p_hw_ref = pHwRef;
1765 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1766 if (NFCSTATUS_SUCCESS == status)
1767 {
1768 status = phHciNfc_LinkMgmt_Open(psHciContext, pHwRef);
1769
1770 if( NFCSTATUS_PENDING != status )
1771 {
1772 /* Roll Back the State Machine to its Original State */
1773 phHciNfc_FSM_Rollback ( psHciContext );
1774 }
1775 }
1776 }
1777
1778 return status;
1779 }
1780
1781
1782
1783