2 * Copyright (C) 2010 NXP Semiconductors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * =========================================================================== *
22 * \brief HCI Interface Source for the HCI Management. *
25 * Project: NFC-FRI-1.1 *
27 * $Date: Thu Apr 22 17:49:47 2010 $ *
28 * $Author: ing04880 $ *
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 $
32 * =========================================================================== *
37 ################################################################################
38 ***************************** Header File Inclusion ****************************
39 ################################################################################
42 #include <phNfcConfig.h>
43 #include <phNfcCompId.h>
44 #include <phNfcIoctlCode.h>
46 #include <phHciNfc_Sequence.h>
47 #include <phHciNfc_RFReader.h>
48 #include <phHciNfc_LinkMgmt.h>
50 #include <phHciNfc_NfcIPMgmt.h>
52 #include <phHciNfc_Emulation.h>
53 #include <phHciNfc_SWP.h>
54 #include <phHciNfc_DevMgmt.h>
55 #include <phOsalNfc.h>
60 *************************** Static Function Declaration **************************
66 phHciNfc_Config_Emulation (
69 phHal_sEmulationCfg_t *pEmulationConfig
75 *************************** Function Definitions **************************
80 * \brief Initialises the HCI Interface
82 * This function initialises the resources for the HCI Command and
90 phHciNfc_Init_t init_mode,
91 phHal_sHwConfig_t *pHwConfig,
92 pphNfcIF_Notification_CB_t pHalNotify,
94 phNfcLayer_sCfg_t *psHciLayerCfg
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;
104 if( (NULL == psHciHandle) || (NULL == pHwRef) || (NULL == pHalNotify)
105 || (NULL== psContext) || (NULL == psHciLayerCfg) || (NULL == pHwConfig)
108 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
110 else if ( NULL != *(phHciNfc_sContext_t **)psHciHandle )
112 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_ALREADY_INITIALISED );
116 /* Create the memory for HCI Context */
117 psHciContext = (phHciNfc_sContext_t *)
118 phOsalNfc_GetMemory(sizeof(phHciNfc_sContext_t));
120 if(psHciContext != NULL)
122 (void)memset((void *)psHciContext,0,
123 sizeof(phHciNfc_sContext_t));
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");
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));
142 HCI_DEBUG("Sizeof Default Session %u\n",sizeof(DEFAULT_SESSION));
143 psHciContext->p_upper_notify = pHalNotify;
144 psHciContext->p_upper_context = psContext;
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;
156 if(NULL != psHciLayerCfg->layer_next->layer_registry)
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);
163 if( (NFCSTATUS_SUCCESS == status) && (NULL != plower_if->init) )
165 status = phHciNfc_FSM_Update ( psHciContext,
168 if(NFCSTATUS_SUCCESS == status)
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 )
179 /* Roll Back the State Machine to its Original State */
180 phHciNfc_FSM_Rollback ( psHciContext );
185 /* TODO: Handle Initialisation in the Invalid State */
187 }/* End of Lower Layer Init */
188 } /* End of Status Check for Memory */
191 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
193 HCI_PRINT("HCI Context Memory Allocation Failed\n");
202 * \brief Release of the HCI Interface .
204 * This function Closes all the open pipes and frees all the resources used by
212 pphNfcIF_Notification_CB_t pHalReleaseCB,
216 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
217 NFCSTATUS status = NFCSTATUS_SUCCESS;
219 if( (NULL == psHciHandle)
223 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
225 /* This Scenario Forces the HCI and the lower layers
226 * to release its Resources
228 else if ( NULL == pHalReleaseCB )
230 /* Release the lower layer Resources */
231 phHciNfc_Release_Lower( psHciContext, pHwRef );
232 /* Release the HCI layer Resources */
233 phHciNfc_Release_Resources( &psHciContext );
235 else if ( NULL == psContext )
237 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
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))
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)
256 psHciContext->hci_seq = PL_STOP_SEQ;
260 psHciContext->hci_seq = ADMIN_REL_SEQ;
263 #ifdef NXP_HCI_SHUTDOWN_OVERRIDE
264 if (NFCSTATUS_SUCCESS != status)
266 psHciContext->hci_state.next_state = (uint8_t) hciState_Release;
267 status = NFCSTATUS_PENDING;
272 status = phHciNfc_Release_Sequence(psHciContext,pHwRef);
275 if( NFCSTATUS_PENDING != status )
277 /* Roll Back the State Machine to its Original State */
278 phHciNfc_FSM_Rollback ( psHciContext );
283 /* TODO: Return appropriate Error */
293 * \brief Interface to Starts the RF Device Discovery.
295 * This function Starts the Discovery Wheel.
300 phHciNfc_Start_Discovery (
305 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
306 NFCSTATUS status = NFCSTATUS_SUCCESS;
308 if ( (NULL == psHciHandle)
312 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
316 status = phHciNfc_ReaderMgmt_Enable_Discovery( psHciContext, pHwRef );
324 * \brief Interface to Stop the RF Device Discovery.
326 * This function Stops the Discovery Wheel.
331 phHciNfc_Stop_Discovery (
336 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
337 NFCSTATUS status = NFCSTATUS_SUCCESS;
339 if ( (NULL == psHciHandle)
343 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
347 status = phHciNfc_ReaderMgmt_Disable_Discovery( psHciContext, pHwRef );
357 * \brief Interface to Configure the Device With the appropriate
358 * Configuration Parameters .
360 * This function configures the Devices with the provided
361 * configuration attributes.
369 phHal_eConfigType_t config_type,
370 phHal_uConfig_t *pConfig
373 NFCSTATUS status = NFCSTATUS_SUCCESS;
375 if( (NULL == psHciHandle)
380 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
389 phHciNfc_sContext_t *psHciContext =
390 ((phHciNfc_sContext_t *)psHciHandle);
391 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
393 if (NFCSTATUS_SUCCESS == status)
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 )
403 /* Roll Back the State Machine to its Original State */
404 phHciNfc_FSM_Rollback ( psHciContext );
408 psHciContext->hci_seq = TARGET_GENERAL_SEQ;
412 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
417 case NFC_EMULATION_CONFIG:
419 status = phHciNfc_Config_Emulation( psHciHandle,
420 pHwRef, &(pConfig->emuConfig));
423 case NFC_SE_PROTECTION_CONFIG:
425 phHciNfc_sContext_t *psHciContext =
426 ((phHciNfc_sContext_t *)psHciHandle);
427 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
429 if (NFCSTATUS_SUCCESS == status)
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 )
438 /* Roll Back the State Machine to its Original State */
439 phHciNfc_FSM_Rollback ( psHciContext );
446 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
449 }/* End of the Configuration Switch */
457 * \brief Interface to Configure the RF Device Discovery using
458 * HCI Polling Loop Gate .
460 * This function configures the HCI Polling Loop Gate with the provided
461 * configuration attributes.
465 phHciNfc_Config_Discovery (
468 phHal_sADD_Cfg_t *pPollConfig
471 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
472 NFCSTATUS status = NFCSTATUS_SUCCESS;
474 if( (NULL == psHciHandle)
476 || (NULL == pPollConfig)
479 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
483 psHciContext->p_hw_ref = pHwRef;
484 HCI_PRINT("HCI Poll Configuration .... \n");
485 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
487 if (NFCSTATUS_SUCCESS == status)
490 if(pPollConfig->PollDevInfo.PollEnabled)
492 psHciContext->hci_seq = PL_DURATION_SEQ;
496 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
497 /* psHciContext->hci_seq = (pPollConfig->NfcIP_Mode != 0 )?
499 READER_DISABLE_SEQ; */
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 );
507 if( NFCSTATUS_PENDING != status )
509 /* Roll Back the State Machine to its Original State */
510 phHciNfc_FSM_Rollback ( psHciContext );
515 /* TODO: Return appropriate Error */
522 * \brief Interface to Restart the RF Device Discovery.
524 * This function restarts the Discovery Wheel.
529 phHciNfc_Restart_Discovery (
535 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
536 NFCSTATUS status = NFCSTATUS_SUCCESS;
537 phHal_eRemDevType_t target_type = phHal_eUnknown_DevType;
539 if ( (NULL == psHciHandle)
543 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
547 psHciContext->p_hw_ref = pHwRef;
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)
553 switch (psHciContext->host_rf_type)
555 case phHal_eISO14443_A_PCD:
557 target_type = phHal_eISO14443_A_PICC;
560 case phHal_eNfcIP1_Initiator:
562 target_type = phHal_eNfcIP1_Target;
566 case phHal_eISO14443_B_PCD:
568 target_type = phHal_eISO14443_B_PICC;
573 case phHal_eFelica_PCD:
575 target_type = phHal_eFelica_PICC;
580 case phHal_eJewel_PCD:
582 target_type = phHal_eJewel_PICC;
587 case phHal_eISO15693_PCD:
589 target_type = phHal_eISO15693_PICC;
592 #endif /* #ifdef TYPE_ISO15693 */
594 case phHal_eISO14443_B_PCD:
597 case phHal_eFelica_PCD:
600 case phHal_eJewel_PCD:
603 case phHal_eISO14443_BPrime_PCD:
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);
611 case phHal_eUnknown_DevType:
614 /* Roll Back the State Machine to its Original State */
615 phHciNfc_FSM_Rollback ( psHciContext );
616 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
619 }/* End of the Remote Target Type Switch */
620 if( NFCSTATUS_SUCCESS == status )
622 status = phHciNfc_ReaderMgmt_Deselect(
623 psHciContext, pHwRef, target_type, re_poll);
624 if( NFCSTATUS_PENDING != status )
626 /* Roll Back the State Machine to its Original State */
627 phHciNfc_FSM_Rollback ( psHciContext );
631 psHciContext->host_rf_type = phHal_eUnknown_DevType;
637 /* TODO: Return appropriate Error */
647 * \brief Interface to Configure the device to emulation as
648 * the tag, smart tag or p2p target .
650 * This function configures the HCI Polling Loop Gate with the provided
651 * configuration attributes.
656 phHciNfc_Config_Emulation (
659 phHal_sEmulationCfg_t *pEmulationCfg
662 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
663 NFCSTATUS status = NFCSTATUS_SUCCESS;
665 if( (NULL == psHciHandle)
667 || (NULL == pEmulationCfg)
670 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
674 psHciContext->p_hw_ref = pHwRef;
676 HCI_PRINT("HCI Configure Emulation .... \n");
677 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
679 if (NFCSTATUS_SUCCESS == status)
681 psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
682 psHciContext->p_config_params = pEmulationCfg;
683 switch( pEmulationCfg->emuType )
685 case NFC_SMARTMX_EMULATION:
687 psHciContext->config_type = SMX_WI_CFG;
688 status = phHciNfc_Emulation_Cfg(psHciContext,
692 case NFC_UICC_EMULATION:
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);
702 case NFC_HOST_CE_A_EMULATION:
703 case NFC_HOST_CE_B_EMULATION:
704 #if defined(HOST_EMULATION)
706 if(TRUE == pEmulationCfg->config.
707 hostEmuCfg_A.enableEmulation)
709 psHciContext->hci_seq = ADMIN_CE_SEQ;
711 status = phHciNfc_EmulationCfg_Sequence(
712 psHciContext, pHwRef);
721 } /* End of Config Switch */
722 if( NFCSTATUS_PENDING != status )
724 /* Roll Back the State Machine to its Original State */
725 phHciNfc_FSM_Rollback ( psHciContext );
730 /* TODO: Return appropriate Error */
738 phHciNfc_Switch_SwpMode (
741 phHal_eSWP_Mode_t swp_mode /* ,
745 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
746 NFCSTATUS status = NFCSTATUS_SUCCESS;
748 if( (NULL == psHciHandle)
752 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
756 psHciContext->p_hw_ref = pHwRef;
758 HCI_PRINT("HCI SWP Switch .... ");
759 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
760 if (NFCSTATUS_SUCCESS == status)
762 psHciContext->config_type = SWP_EVT_CFG;
763 status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef ,
764 (uint8_t) swp_mode );
766 /* Send the Success Status as this is an event */
767 status = ((status == NFCSTATUS_SUCCESS)?
768 NFCSTATUS_PENDING : status);
770 if( NFCSTATUS_PENDING != status )
772 /* Roll Back the State Machine to its Original State */
773 phHciNfc_FSM_Rollback ( psHciContext );
775 HCI_PRINT(" Execution Error \n");
779 HCI_PRINT(" Successful \n");
784 HCI_PRINT(" Not allowed - Invalid State \n");
785 /* TODO: Return appropriate Error */
795 * \brief Interface to Switch the Mode of the SmartMx from Virtual/Wired
798 * This function switches the mode of the SmartMX connected through WI(S2C)
799 * Interface to virtual/wired mode.
804 phHciNfc_Switch_SmxMode (
807 phHal_eSmartMX_Mode_t smx_mode,
808 phHal_sADD_Cfg_t *pPollConfig
811 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
812 NFCSTATUS status = NFCSTATUS_SUCCESS;
814 if( (NULL == psHciHandle)
816 || (NULL == pPollConfig)
819 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
823 psHciContext->p_hw_ref = pHwRef;
825 HCI_PRINT("HCI Smart MX Mode Switch .... \n");
826 status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
828 if (NFCSTATUS_SUCCESS == status)
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)
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.
840 psHciContext->hci_state.cur_state = hciState_Disconnect;
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 )
848 /* Roll Back the State Machine to its Original State */
849 phHciNfc_FSM_Rollback ( psHciContext );
854 /* TODO: Return appropriate Error */
863 * \brief Interface to Select the Next Remote Target Discovered during the
864 * discovery sequence using the particular HCI Reader Gate .
867 * This function Selects and Activates the next Remote Target
868 * Detected using the particular HCI Reader Gate.
874 phHciNfc_Select_Next_Target (
879 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
880 NFCSTATUS status = NFCSTATUS_SUCCESS;
882 if( (NULL == psHciHandle)
886 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
890 psHciContext->p_hw_ref = pHwRef;
891 status = phHciNfc_FSM_Update ( psHciContext, hciState_Select );
892 if (NFCSTATUS_SUCCESS == status)
894 psHciContext->hci_seq = READER_SELECT_SEQ;
895 status = phHciNfc_ReaderMgmt_Activate_Next( psHciContext, pHwRef );
896 if( NFCSTATUS_PENDING != status )
898 /* Roll Back the State Machine to its Original State */
899 phHciNfc_FSM_Rollback ( psHciContext );
904 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
914 * \brief Interface to Connect the Remote Target Discovered during the
915 * discovery sequence using the particular HCI Reader Gate .
918 * This function connects the Remote Target Detected using the particular
919 * HCI Reader Gate with the appropriate configuration setup.
927 phHal_sRemoteDevInformation_t *p_target_info
930 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
931 NFCSTATUS status = NFCSTATUS_SUCCESS;
932 /* phHal_eRemDevType_t target_type = phHal_eUnknown_DevType; */
934 if( (NULL == psHciHandle)
936 || (NULL == p_target_info)
939 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
943 psHciContext->p_hw_ref = pHwRef;
944 status = phHciNfc_FSM_Update ( psHciContext, hciState_Connect );
945 if (NFCSTATUS_SUCCESS == status)
947 psHciContext->hci_seq = READER_SELECT_SEQ;
948 switch (p_target_info->RemDevType)
950 case phHal_eISO14443_A_PICC:
951 case phHal_eISO14443_4A_PICC:
952 case phHal_eMifare_PICC:
953 case phHal_eISO14443_3A_PICC:
955 case phHal_eNfcIP1_Target:
958 case phHal_eISO14443_B_PICC:
959 case phHal_eISO14443_4B_PICC:
962 case phHal_eFelica_PICC:
965 case phHal_eJewel_PICC:
968 case phHal_eISO15693_PICC:
969 #endif /* #ifdef TYPE_ISO15693 */
972 psHciContext->p_target_info = p_target_info;
973 status = phHciNfc_ReaderMgmt_Select(
974 psHciContext, pHwRef,
975 p_target_info->RemDevType );
979 case phHal_eISO14443_BPrime_PICC:
981 case phHal_eUnknown_DevType:
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);
989 }/* End of the Remote Target Type Switch */
990 if( NFCSTATUS_PENDING != status )
992 /* Roll Back the State Machine to its Original State */
993 phHciNfc_FSM_Rollback ( psHciContext );
998 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1001 } /* End of the HCI Handle Validation */
1008 * \brief Interface to Reactivate the Remote Targets Discovered during the
1009 * discovery sequence using the particular HCI Reader Gate .
1012 * This function reactivates the Remote Target Detected using the particular
1013 * HCI Reader Gate with the appropriate configuration setup.
1018 phHciNfc_Reactivate (
1021 phHal_sRemoteDevInformation_t *p_target_info
1024 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1025 NFCSTATUS status = NFCSTATUS_SUCCESS;
1026 /* phHal_eRemDevType_t target_type = phHal_eUnknown_DevType; */
1028 if( (NULL == psHciHandle)
1030 || (NULL == p_target_info)
1033 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1037 psHciContext->p_hw_ref = pHwRef;
1038 status = phHciNfc_FSM_Update ( psHciContext, hciState_Reactivate );
1039 if (NFCSTATUS_SUCCESS == status)
1041 psHciContext->hci_seq = READER_REACTIVATE_SEQ;
1042 switch (p_target_info->RemDevType)
1044 case phHal_eISO14443_A_PICC:
1045 case phHal_eISO14443_4A_PICC:
1046 case phHal_eMifare_PICC:
1047 case phHal_eISO14443_3A_PICC:
1049 psHciContext->host_rf_type = phHal_eISO14443_A_PCD;
1052 case phHal_eNfcIP1_Target:
1054 psHciContext->host_rf_type = phHal_eNfcIP1_Initiator;
1058 case phHal_eISO14443_4B_PICC:
1059 case phHal_eISO14443_B_PICC:
1061 psHciContext->host_rf_type = phHal_eISO14443_B_PCD;
1066 case phHal_eFelica_PICC:
1068 psHciContext->host_rf_type = phHal_eFelica_PCD;
1073 case phHal_eISO14443_BPrime_PICC:
1075 /* Reactivate for Jewel is not Supported */
1076 case phHal_eJewel_PICC:
1077 case phHal_eUnknown_DevType:
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);
1085 }/* End of the Remote Target Type Switch */
1089 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1092 if(NFCSTATUS_SUCCESS == status )
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 )
1099 /* Roll Back the State Machine to its Original State */
1100 phHciNfc_FSM_Rollback ( psHciContext );
1103 } /* End of the HCI Handle Validation */
1111 * \brief Interface to Disconnect the selected target.
1113 * This function disconnects the remote target selected.
1118 phHciNfc_Disconnect (
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;
1131 if( (NULL == psHciHandle)
1133 || ( NULL == psHciContext->p_target_info)
1136 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1140 psHciContext->p_hw_ref = pHwRef;
1142 psHciContext->p_config_params = &repoll;
1143 /* psHciContext->hci_seq = HCI_END_SEQ; */
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)
1149 psHciContext->hci_seq = READER_UICC_DISPATCH_SEQ;
1150 target_type = psHciContext->p_target_info->RemDevType;
1151 switch (target_type)
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:
1159 case phHal_eISO14443_B_PICC:
1160 case phHal_eISO14443_4B_PICC:
1163 case phHal_eFelica_PICC:
1166 case phHal_eJewel_PICC:
1168 #ifdef TYPE_ISO15693
1169 case phHal_eISO15693_PICC:
1170 #endif /* #ifdef TYPE_ISO15693 */
1173 status = phHciNfc_Disconnect_Sequence(
1174 psHciContext, pHwRef );
1178 case phHal_eISO14443_B_PICC:
1179 case phHal_eISO14443_4B_PICC:
1182 case phHal_eFelica_PICC:
1185 case phHal_eJewel_PICC:
1187 #ifndef TYPE_B_PRIME
1188 case phHal_eISO14443_BPrime_PICC:
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);
1196 case phHal_eUnknown_DevType:
1199 /* Roll Back the State Machine to its Original State */
1200 phHciNfc_FSM_Rollback ( psHciContext );
1201 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1204 }/* End of the Remote Target Type Switch */
1205 if( NFCSTATUS_PENDING != status )
1207 /* Roll Back the State Machine to its Original State */
1208 phHciNfc_FSM_Rollback ( psHciContext );
1213 /* TODO: Return appropriate Error */
1215 } /* End of the HCI Handle Validation */
1221 * \brief Interface to exchange the data to/from
1222 * the selected target.
1224 * This function sends and receives the data to/from
1225 * the selected remote target.
1229 phHciNfc_Exchange_Data (
1232 phHal_sRemoteDevInformation_t *p_target_info,
1233 phHciNfc_XchgInfo_t *p_xchg_info
1236 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1237 NFCSTATUS status = NFCSTATUS_SUCCESS;
1239 if( (NULL == psHciHandle)
1241 || (NULL == p_target_info)
1242 || (NULL == p_xchg_info)
1245 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1247 else if (p_target_info != psHciContext->p_target_info )
1249 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_REMOTE_DEVICE);
1253 psHciContext->p_hw_ref = pHwRef;
1254 status = phHciNfc_FSM_Update ( psHciContext, hciState_Transact );
1255 if (NFCSTATUS_SUCCESS == status)
1257 switch (p_target_info->RemDevType)
1259 case phHal_eMifare_PICC:
1260 case phHal_eISO14443_A_PICC:
1261 case phHal_eISO14443_4A_PICC:
1262 case phHal_eISO14443_3A_PICC:
1264 case phHal_eISO14443_B_PICC:
1265 case phHal_eISO14443_4B_PICC:
1268 case phHal_eFelica_PICC:
1271 case phHal_eJewel_PICC:
1273 #ifdef TYPE_ISO15693
1274 case phHal_eISO15693_PICC:
1275 #endif /* #ifdef TYPE_ISO15693 */
1277 psHciContext->p_xchg_info = p_xchg_info;
1278 status = phHciNfc_ReaderMgmt_Exchange_Data(
1279 psHciContext, pHwRef, p_xchg_info );
1283 case phHal_eISO14443_B_PICC:
1284 case phHal_eISO14443_4B_PICC:
1287 case phHal_eFelica_PICC:
1290 case phHal_eJewel_PICC:
1292 case phHal_eNfcIP1_Target:
1293 #ifndef TYPE_B_PRIME
1294 case phHal_eISO14443_BPrime_PICC:
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);
1302 case phHal_eUnknown_DevType:
1305 /* Roll Back the State Machine to its Original State */
1306 phHciNfc_FSM_Rollback ( psHciContext );
1307 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1311 }/* End of the Remote Target Type Switch */
1312 if( NFCSTATUS_PENDING != status )
1314 /* Roll Back the State Machine to its Original State */
1315 phHciNfc_FSM_Rollback ( psHciContext );
1320 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1322 } /* End of the HCI Handle Validation */
1328 * \brief Interface to Send the data to/from
1329 * the selected NfcIP.
1331 * This function sends and receives the data to/from
1332 * the selected remote target.
1336 phHciNfc_Send_Data (
1339 phHal_sRemoteDevInformation_t *p_remote_dev_info,
1340 phHciNfc_XchgInfo_t *p_send_param
1343 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1344 NFCSTATUS status = NFCSTATUS_SUCCESS;
1346 if( (NULL == psHciHandle)
1348 || (NULL == p_send_param)
1351 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1355 psHciContext->p_hw_ref = pHwRef;
1356 status = phHciNfc_FSM_Update ( psHciContext, hciState_Transact );
1357 if (NFCSTATUS_SUCCESS == status)
1359 switch (psHciContext->host_rf_type)
1361 case phHal_eISO14443_A_PICC:
1362 case phHal_eISO14443_B_PICC:
1363 case phHal_eISO14443_4A_PICC:
1364 case phHal_eISO14443_4B_PICC:
1369 case phHal_eNfcIP1_Initiator:
1371 if (p_remote_dev_info !=
1372 psHciContext->p_target_info )
1374 status = PHNFCSTVAL(CID_NFC_HCI,
1375 NFCSTATUS_INVALID_REMOTE_DEVICE);
1379 psHciContext->p_xchg_info = p_send_param;
1380 status = phHciNfc_NfcIP_Send_Data( psHciContext,
1381 pHwRef, p_send_param );
1385 case phHal_eNfcIP1_Target:
1387 psHciContext->p_xchg_info = p_send_param;
1388 status = phHciNfc_NfcIP_Send_Data( psHciContext,
1389 pHwRef, p_send_param );
1394 case phHal_eISO14443_BPrime_PCD:
1395 case phHal_eFelica_PCD:
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);
1403 case phHal_eUnknown_DevType:
1406 /* Roll Back the State Machine to its Original State */
1407 phHciNfc_FSM_Rollback ( psHciContext );
1408 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1412 }/* End of the Remote Target Type Switch */
1413 #if defined( ENABLE_P2P ) || defined (TYPE_B_PRIME)
1414 if( NFCSTATUS_PENDING != status )
1417 /* Roll Back the State Machine to its Original State */
1418 phHciNfc_FSM_Rollback ( psHciContext );
1423 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1425 } /* End of the HCI Handle Validation */
1434 * \brief Interface to Send the data from
1435 * the selected NfcIP.
1437 * This function sends and receives the data to/from
1438 * the selected remote target.
1442 phHciNfc_Receive_Data (
1449 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
1450 NFCSTATUS status = NFCSTATUS_SUCCESS;
1452 if( (NULL == psHciHandle)
1456 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1460 if (NFCSTATUS_SUCCESS == status)
1462 status = phHciNfc_Receive(psHciHandle, pHwRef, p_data, length);
1463 if( NFCSTATUS_PENDING != status )
1465 /* Roll Back the State Machine to its Original State */
1466 phHciNfc_FSM_Rollback ( psHciContext );
1477 * \brief Interface to Check for the presence of
1478 * the selected target in the field .
1480 * This function checks the presence of the
1481 * the selected remote target in the field .
1487 phHciNfc_Presence_Check (
1492 NFCSTATUS status = NFCSTATUS_SUCCESS;
1493 phHciNfc_sContext_t *psHciContext =
1494 ((phHciNfc_sContext_t *)psHciHandle);
1495 phHal_eRemDevType_t target_type = phHal_eUnknown_DevType;
1497 if( (NULL == psHciContext)
1501 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1505 psHciContext->p_hw_ref = pHwRef;
1506 status = phHciNfc_FSM_Update ( psHciContext, hciState_Presence );
1507 if (NFCSTATUS_SUCCESS == status)
1509 target_type = psHciContext->p_target_info->RemDevType;
1510 switch (target_type)
1512 case phHal_eISO14443_A_PICC:
1513 case phHal_eMifare_PICC:
1514 case phHal_eISO14443_4A_PICC:
1515 case phHal_eISO14443_3A_PICC:
1517 case phHal_eISO14443_B_PICC:
1518 case phHal_eISO14443_4B_PICC:
1521 case phHal_eFelica_PICC:
1524 case phHal_eJewel_PICC:
1526 #ifdef TYPE_ISO15693
1527 case phHal_eISO15693_PICC:
1528 #endif /* #ifdef TYPE_ISO15693 */
1530 case phHal_eNfcIP1_Target:
1533 status = phHciNfc_ReaderMgmt_Presence_Check(
1534 psHciContext, pHwRef );
1538 case phHal_eISO14443_BPrime_PICC:
1541 case phHal_eISO14443_B_PICC:
1542 case phHal_eISO14443_4B_PICC:
1545 case phHal_eFelica_PICC:
1548 case phHal_eJewel_PICC:
1550 case phHal_eUnknown_DevType:
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);
1559 /* Roll Back the State Machine to its Original State */
1560 phHciNfc_FSM_Rollback ( psHciContext );
1561 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1565 }/* End of the Remote Target Type Switch */
1566 if( NFCSTATUS_PENDING != status )
1568 /* Roll Back the State Machine to its Original State */
1569 phHciNfc_FSM_Rollback ( psHciContext );
1574 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
1576 } /* End of the HCI Handle Validation */
1582 phHciNfc_PRBS_Test (
1586 phNfc_sData_t *test_param
1589 NFCSTATUS status = NFCSTATUS_SUCCESS;
1590 phHciNfc_sContext_t *psHciContext =
1591 ((phHciNfc_sContext_t *)psHciHandle);
1593 if( (NULL == psHciContext)
1595 || (test_type != DEVMGMT_PRBS_TEST)
1598 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1602 psHciContext->p_hw_ref = pHwRef;
1603 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1604 if (NFCSTATUS_SUCCESS == status)
1606 status = phHciNfc_DevMgmt_Test(psHciContext, pHwRef,
1607 (uint8_t)(test_type & DEVMGMT_TEST_MASK), test_param);
1608 if( NFCSTATUS_PENDING != status )
1610 /* Roll Back the State Machine to its Original State */
1611 phHciNfc_FSM_Rollback ( psHciContext );
1620 phHciNfc_System_Test (
1624 phNfc_sData_t *test_param
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;
1633 if( (NULL == psHciContext)
1637 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1641 psHciContext->p_hw_ref = pHwRef;
1642 status = phHciNfc_FSM_Update ( psHciContext, hciState_Test );
1643 if (NFCSTATUS_SUCCESS == status)
1645 if (test_type != NFC_GPIO_READ)
1647 status = phHciNfc_DevMgmt_Test(psHciContext, pHwRef,
1648 (uint8_t)(test_type & DEVMGMT_TEST_MASK), test_param);
1652 test_result.buffer = &gpio_status;
1653 status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef,
1654 (uint16_t)NFC_GPIO_READ, test_result.buffer);
1657 if( NFCSTATUS_PENDING != status )
1659 /* Roll Back the State Machine to its Original State */
1660 phHciNfc_FSM_Rollback ( psHciContext );
1670 phHciNfc_System_Configure (
1673 uint32_t config_type,
1674 uint8_t config_value
1677 NFCSTATUS status = NFCSTATUS_SUCCESS;
1678 phHciNfc_sContext_t *psHciContext =
1679 ((phHciNfc_sContext_t *)psHciHandle);
1681 if( (NULL == psHciContext)
1685 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1689 psHciContext->p_hw_ref = pHwRef;
1690 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1691 if (NFCSTATUS_SUCCESS == status)
1693 status = phHciNfc_DevMgmt_Configure(psHciContext, pHwRef,
1694 (uint16_t)config_type, config_value);
1696 if( NFCSTATUS_PENDING != status )
1698 /* Roll Back the State Machine to its Original State */
1699 phHciNfc_FSM_Rollback ( psHciContext );
1707 phHciNfc_System_Get_Info(
1710 uint32_t config_type,
1711 uint8_t *p_config_value
1714 NFCSTATUS status = NFCSTATUS_SUCCESS;
1715 phHciNfc_sContext_t *psHciContext =
1716 ((phHciNfc_sContext_t *)psHciHandle);
1718 if( (NULL == psHciContext)
1720 || (NULL == p_config_value)
1723 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1727 psHciContext->p_hw_ref = pHwRef;
1728 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1729 if (NFCSTATUS_SUCCESS == status)
1731 status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef,
1732 (uint16_t)config_type, p_config_value);
1734 if( NFCSTATUS_PENDING != status )
1736 /* Roll Back the State Machine to its Original State */
1737 phHciNfc_FSM_Rollback ( psHciContext );
1747 phHciNfc_Get_Link_Status(
1752 NFCSTATUS status = NFCSTATUS_SUCCESS;
1753 phHciNfc_sContext_t *psHciContext =
1754 ((phHciNfc_sContext_t *)psHciHandle);
1756 if( (NULL == psHciContext)
1760 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1764 psHciContext->p_hw_ref = pHwRef;
1765 status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
1766 if (NFCSTATUS_SUCCESS == status)
1768 status = phHciNfc_LinkMgmt_Open(psHciContext, pHwRef);
1770 if( NFCSTATUS_PENDING != status )
1772 /* Roll Back the State Machine to its Original State */
1773 phHciNfc_FSM_Rollback ( psHciContext );