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 * =========================================================================== *
21 * \file phHciNfc_Emulation.c *
22 * \brief HCI Emulation management routines. *
25 * Project: NFC-FRI-1.1 *
27 * $Date: Tue Jun 8 09:30:37 2010 $ *
28 * $Author: ing04880 $ *
30 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $
32 * =========================================================================== *
36 ***************************** Header File Inclusion ****************************
38 #include <phNfcConfig.h>
39 #include <phNfcCompId.h>
40 #include <phNfcHalTypes.h>
41 #include <phHciNfc_Pipe.h>
42 #include <phHciNfc_Emulation.h>
43 #include <phHciNfc_WI.h>
44 #include <phHciNfc_SWP.h>
46 #include <phHciNfc_NfcIPMgmt.h>
49 #include <phHciNfc_CE_A.h>
50 #include <phHciNfc_CE_B.h>
52 #include <phOsalNfc.h>
54 ****************************** Macro Definitions *******************************
60 *************************** Structure and Enumeration ***************************
63 /** \defgroup grp_hci_nfc HCI Emulation Management Component
68 typedef enum phHciNfc_EmulationMgmt_Seq{
69 NFCIP_TARGET_PIPE_OPEN = 0x00U,
70 NFCIP_TARGET_MODE_CONFIG,
71 NFCIP_TARGET_MERGE_SAK,
72 NFCIP_TARGET_PIPE_CLOSE,
85 WI_ENABLE_NOTIFICATION,
86 WI_DISABLE_NOTIFICATION,
89 WI_SWITCH_DEFAULT_MODE,
95 SWP_DEFAULT_EMULATION,
97 SWP_DISABLE_EMULATION,
101 CONFIG_DEFAULT_EMULATION,
104 } phHciNfc_EmulationMgmt_Seq_t;
106 typedef struct phHciNfc_EmulationMgmt_Info{
107 phHal_eEmulationType_t se_default;
108 uint8_t smx_powerless;
110 uint8_t uicc_powerless;
112 /* Application ID of the UICC Transaction performed */
113 uint8_t uicc_aid[MAX_AID_LEN];
114 uint8_t uicc_param[MAX_UICC_PARAM_LEN];
115 uint8_t uicc_param_len;
116 phHciNfc_Pipe_Info_t *p_uicc_pipe_info;
117 phHciNfc_EmulationMgmt_Seq_t emulation_cur_seq;
118 phHciNfc_EmulationMgmt_Seq_t emulation_next_seq;
121 } phHciNfc_EmulationMgmt_Info_t;
125 *************************** Static Function Declaration **************************
130 phHciNfc_Recv_Uicc_Cmd (
143 phHciNfc_Recv_Uicc_Event (
156 *************************** Function Definitions ***************************
160 phHciNfc_Uicc_Connectivity(
161 phHciNfc_sContext_t *psHciContext,
165 NFCSTATUS status = NFCSTATUS_SUCCESS;
166 phHciNfc_Pipe_Info_t *pPipeInfo = NULL;
167 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info = NULL;
169 if( NULL != psHciContext->p_emulation_mgmt_info )
171 p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)
172 psHciContext->p_emulation_mgmt_info ;
173 pPipeInfo = psHciContext->p_pipe_list[NXP_PIPE_CONNECTIVITY];
174 if( (TRUE == ((phHal_sHwReference_t *)pHwRef)->uicc_connected)
175 && (NULL == pPipeInfo))
177 status = phHciNfc_Allocate_Resource((void **)&pPipeInfo,
178 sizeof(phHciNfc_Pipe_Info_t));
179 if((NULL != pPipeInfo)
180 && (NFCSTATUS_SUCCESS == status))
182 /* The Source Host is the UICC Host */
183 pPipeInfo->pipe.source.host_id =
184 (uint8_t) phHciNfc_UICCHostID;
185 /* The Source Gate is same as the Destination Gate */
186 pPipeInfo->pipe.source.gate_id =
187 (uint8_t) phHciNfc_ConnectivityGate;
188 /* The Destination Host is the Terminal Host */
189 pPipeInfo->pipe.dest.host_id =
190 (uint8_t) phHciNfc_TerminalHostID;
191 /* The Source Gate is same as the Destination Gate */
192 pPipeInfo->pipe.dest.gate_id =
193 (uint8_t) phHciNfc_ConnectivityGate;
194 /* The Pipe ID is Hardcoded to Connectivity */
195 pPipeInfo->pipe.pipe_id = (uint8_t) NXP_PIPE_CONNECTIVITY;
198 status = phHciNfc_Uicc_Update_PipeInfo(psHciContext,
199 NXP_PIPE_CONNECTIVITY, pPipeInfo);
200 if (NFCSTATUS_SUCCESS == status)
202 psHciContext->p_pipe_list[NXP_PIPE_CONNECTIVITY] = pPipeInfo;
203 p_emulation_mgmt_info->uicc_enable = TRUE;
207 (void)phOsalNfc_FreeMemory(pPipeInfo);
216 * \brief Get the pipe_id of Connectivity Managment Gate.
218 * This function Get the pipe_id of Connectivity Managment Gate.
224 phHciNfc_Uicc_Get_PipeID(
225 phHciNfc_sContext_t *psHciContext,
229 NFCSTATUS status = NFCSTATUS_SUCCESS;
230 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info = NULL;
231 if( (NULL != psHciContext)
232 && ( NULL != ppipe_id )
233 && ( NULL != psHciContext->p_emulation_mgmt_info )
236 p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)
237 psHciContext->p_emulation_mgmt_info ;
238 *ppipe_id = p_emulation_mgmt_info->uicc_id ;
242 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
248 /* Function to Update the Pipe Information */
250 phHciNfc_Uicc_Update_PipeInfo(
251 phHciNfc_sContext_t *psHciContext,
253 phHciNfc_Pipe_Info_t *pPipeInfo
256 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info=NULL;
257 NFCSTATUS status = NFCSTATUS_SUCCESS;
259 if( NULL == psHciContext )
261 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
263 else if ( NULL == psHciContext->p_emulation_mgmt_info )
265 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
269 p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)
270 psHciContext->p_emulation_mgmt_info ;
271 /* Update the pipe_id of the Connectivity Gate
272 * obtained from the HCI Response */
273 p_emulation_mgmt_info->uicc_id = pipe_id;
274 p_emulation_mgmt_info->p_uicc_pipe_info = pPipeInfo;
275 if ( NULL != pPipeInfo)
277 /* Update the Response Receive routine of the Connectivity Gate */
278 /* pPipeInfo->recv_resp = phHciNfc_Recv_Uicc_Response; */
279 pPipeInfo->recv_cmd = &phHciNfc_Recv_Uicc_Cmd;
280 pPipeInfo->recv_event = &phHciNfc_Recv_Uicc_Event;
289 * \brief Updates the Sequence of Emulation Managment Gate.
291 * This function Resets/Updates the sequence of the Emulation Management
298 phHciNfc_EmuMgmt_Update_Seq(
299 phHciNfc_sContext_t *psHciContext,
300 phHciNfc_eSeqType_t seq_type
303 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info=NULL;
304 NFCSTATUS status = NFCSTATUS_SUCCESS;
305 if( NULL == psHciContext )
307 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
311 if( NULL == psHciContext->p_emulation_mgmt_info )
313 status = PHNFCSTVAL(CID_NFC_HCI,
314 NFCSTATUS_INVALID_HCI_INFORMATION);
318 p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)
319 psHciContext->p_emulation_mgmt_info ;
326 p_emulation_mgmt_info->emulation_cur_seq = NFCIP_TARGET_PIPE_OPEN;
328 p_emulation_mgmt_info->emulation_cur_seq = WI_PIPE_OPEN;
330 p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ ;
335 p_emulation_mgmt_info->emulation_cur_seq =
336 p_emulation_mgmt_info->emulation_next_seq;
341 p_emulation_mgmt_info->emulation_cur_seq = SWP_ENABLE_EMULATION;
342 p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ ;
347 p_emulation_mgmt_info->emulation_cur_seq = WI_DISABLE_EMULATION;
348 p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ ;
364 * \brief Initialisation of RF Emulation Gates.
366 * This function initialses the RF Emulation Management and
367 * populates the Reader Management Information Structure
373 phHciNfc_EmuMgmt_Initialise(
374 phHciNfc_sContext_t *psHciContext,
378 NFCSTATUS status = NFCSTATUS_SUCCESS;
379 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
380 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info=NULL;
382 if( NULL == psHciContext )
384 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
389 if( ( NULL == psHciContext->p_emulation_mgmt_info )
390 && (phHciNfc_Allocate_Resource((void **)(&p_emulation_mgmt_info),
391 sizeof(phHciNfc_EmulationMgmt_Info_t))== NFCSTATUS_SUCCESS)
394 psHciContext->p_emulation_mgmt_info = p_emulation_mgmt_info;
396 p_emulation_mgmt_info->emulation_cur_seq = NFCIP_TARGET_PIPE_OPEN;
398 p_emulation_mgmt_info->emulation_cur_seq = WI_PIPE_OPEN;
400 p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ;
401 p_emulation_mgmt_info->uicc_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
405 p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)
406 psHciContext->p_emulation_mgmt_info ;
409 if( NULL == psHciContext->p_emulation_mgmt_info )
411 status = PHNFCSTVAL(CID_NFC_HCI,
412 NFCSTATUS_INSUFFICIENT_RESOURCES);
414 #ifdef ESTABLISH_SESSION
415 else if(( hciMode_Session == psHciContext->hci_mode )
416 && (NFCIP_TARGET_PIPE_OPEN == p_emulation_mgmt_info->emulation_cur_seq )
419 status = NFCSTATUS_SUCCESS;
424 switch(p_emulation_mgmt_info->emulation_cur_seq )
427 /* NFCIP Target Open sequence */
428 case NFCIP_TARGET_PIPE_OPEN:
430 p_pipe_info = ((phHciNfc_NfcIP_Info_t *)
431 psHciContext->p_nfcip_info)->p_tgt_pipe_info;
432 if(NULL == p_pipe_info )
434 status = PHNFCSTVAL(CID_NFC_HCI,
435 NFCSTATUS_INVALID_HCI_INFORMATION);
439 status = phHciNfc_Open_Pipe( psHciContext,
440 pHwRef, p_pipe_info );
441 if(status == NFCSTATUS_SUCCESS)
443 p_emulation_mgmt_info->emulation_next_seq =
444 NFCIP_TARGET_MODE_CONFIG;
445 status = NFCSTATUS_PENDING;
450 /* NFCIP Target Mode Config sequence */
451 case NFCIP_TARGET_MODE_CONFIG:
453 #define NFCIP_ACTIVE_SHIFT 0x03U
454 #define NFCIP_PASSIVE_MASK 0x07U
455 uint8_t mode = ( NXP_NFCIP_ACTIVE_DEFAULT << NFCIP_ACTIVE_SHIFT ) |
456 ( DEFAULT_NFCIP_TARGET_MODE_SUPPORT & NFCIP_PASSIVE_MASK );
457 status = phHciNfc_NfcIP_SetMode( psHciContext, pHwRef,
459 if(status == NFCSTATUS_PENDING )
462 p_emulation_mgmt_info->emulation_next_seq =
463 NFCIP_TARGET_MERGE_SAK;
465 p_emulation_mgmt_info->emulation_next_seq =
467 #endif /* #ifdef TGT_MERGE_SAK */
468 /* status = NFCSTATUS_SUCCESS; */
473 /* NFCIP Target SAK Merge sequence */
474 case NFCIP_TARGET_MERGE_SAK:
476 status = phHciNfc_NfcIP_SetMergeSak( psHciContext, pHwRef,
478 if(status == NFCSTATUS_PENDING )
480 p_emulation_mgmt_info->emulation_next_seq =
482 /* status = NFCSTATUS_SUCCESS; */
486 #endif /* #ifdef TGT_MERGE_SAK */
487 #endif /* #ifdef ENABLE_P2P */
488 /* Secure Element WI pipe open sequence */
491 p_pipe_info = ((phHciNfc_WI_Info_t *)
492 psHciContext->p_wi_info)->p_pipe_info;
493 if(NULL == p_pipe_info )
495 status = PHNFCSTVAL(CID_NFC_HCI,
496 NFCSTATUS_INVALID_HCI_INFORMATION);
500 status = phHciNfc_Open_Pipe( psHciContext,
501 pHwRef, p_pipe_info );
502 if(status == NFCSTATUS_SUCCESS)
504 #ifdef DISABLE_WI_NOTIFICATION
505 p_emulation_mgmt_info->emulation_next_seq =
508 p_emulation_mgmt_info->emulation_next_seq =
509 WI_ENABLE_NOTIFICATION;
511 status = NFCSTATUS_PENDING;
516 /* Enable the SmartMx Notifications through WI */
517 case WI_ENABLE_NOTIFICATION:
519 p_pipe_info = ((phHciNfc_WI_Info_t *)
520 psHciContext->p_wi_info)->p_pipe_info;
521 if(NULL == p_pipe_info )
523 status = PHNFCSTVAL(CID_NFC_HCI,
524 NFCSTATUS_INVALID_HCI_INFORMATION);
528 status = phHciNfc_WI_Configure_Notifications(
529 psHciContext, pHwRef, eEnableEvents );
530 if(status == NFCSTATUS_PENDING)
532 p_emulation_mgmt_info->emulation_next_seq =
538 /* Enable the SmartMx Emulation by Default through WI */
539 case WI_ENABLE_EMULATION:
541 p_pipe_info = ((phHciNfc_WI_Info_t *)
542 psHciContext->p_wi_info)->p_pipe_info;
543 if(NULL == p_pipe_info )
545 status = PHNFCSTVAL(CID_NFC_HCI,
546 NFCSTATUS_INVALID_HCI_INFORMATION);
550 status = phHciNfc_WI_Configure_Default( psHciContext,
552 if(status == NFCSTATUS_PENDING)
554 p_emulation_mgmt_info->emulation_next_seq =
560 /* SWP pipe open sequence */
563 p_pipe_info = ((phHciNfc_SWP_Info_t *)
564 psHciContext->p_swp_info)->p_pipe_info;
565 if(NULL == p_pipe_info )
567 status = PHNFCSTVAL(CID_NFC_HCI,
568 NFCSTATUS_INVALID_HCI_INFORMATION);
572 status = phHciNfc_Open_Pipe( psHciContext,
573 pHwRef, p_pipe_info );
574 if(status == NFCSTATUS_SUCCESS)
576 p_emulation_mgmt_info->emulation_next_seq =
577 SWP_ENABLE_EMULATION;
578 #ifndef ESTABLISH_SESSION
579 status = NFCSTATUS_PENDING;
585 /* Enable the UICC Emulation through SWP */
586 case SWP_ENABLE_EMULATION:
588 p_pipe_info = ((phHciNfc_SWP_Info_t *)
589 psHciContext->p_swp_info)->p_pipe_info;
590 if(NULL == p_pipe_info )
592 status = PHNFCSTVAL(CID_NFC_HCI,
593 NFCSTATUS_INVALID_HCI_INFORMATION);
597 #ifdef SWP_EVENT_USAGE
598 status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef,
599 UICC_SWITCH_MODE_ON );
600 /* UICC_SWITCH_MODE_DEFAULT */
602 status = phHciNfc_SWP_Configure_Default( psHciContext,
605 if(status == NFCSTATUS_PENDING)
607 p_emulation_mgmt_info->emulation_next_seq =
609 /* status = NFCSTATUS_SUCCESS; */
614 /* Disable the UICC Emulation through SWP */
617 p_pipe_info = ((phHciNfc_SWP_Info_t *)
618 psHciContext->p_swp_info)->p_pipe_info;
619 if(NULL == p_pipe_info )
621 status = PHNFCSTVAL(CID_NFC_HCI,
622 NFCSTATUS_INVALID_HCI_INFORMATION);
627 status = phHciNfc_Uicc_Connect_Status(
628 psHciContext, pHwRef );
629 if(status == NFCSTATUS_SUCCESS)
631 uint8_t uicc_connect = ((phHciNfc_SWP_Info_t *)
632 psHciContext->p_swp_info)->uicc_status;
633 if(UICC_CONNECTED == uicc_connect)
635 #ifdef SWP_EVENT_USAGE
636 p_emulation_mgmt_info->emulation_next_seq =
637 SWP_DISABLE_EMULATION;
639 p_emulation_mgmt_info->emulation_next_seq =
640 WI_DISABLE_EMULATION;
642 ((phHal_sHwReference_t *)
643 pHwRef)->uicc_connected = TRUE;
644 status = NFCSTATUS_PENDING;
648 status = phHciNfc_SWP_Configure_Mode( psHciContext,
649 pHwRef, UICC_SWITCH_MODE_DEFAULT );
650 (NFCSTATUS_PENDING == status)?
651 (p_emulation_mgmt_info->emulation_next_seq =
652 WI_DISABLE_EMULATION):
653 (p_emulation_mgmt_info->emulation_next_seq =
665 /* Disable the SmartMx Emulation through WI */
666 case WI_DISABLE_EMULATION:
668 p_pipe_info = ((phHciNfc_WI_Info_t *)
669 psHciContext->p_wi_info)->p_pipe_info;
670 if(NULL == p_pipe_info )
672 status = PHNFCSTVAL(CID_NFC_HCI,
673 NFCSTATUS_INVALID_HCI_INFORMATION);
677 status = phHciNfc_WI_Configure_Mode( psHciContext,
678 pHwRef, eSmartMx_Default );
679 if(status == NFCSTATUS_PENDING)
681 p_emulation_mgmt_info->emulation_next_seq =
682 SWP_DISABLE_EMULATION;
683 status = NFCSTATUS_SUCCESS;
688 #ifndef SWP_EVENT_USAGE
690 /* Get the UICC Baud Rate Status */
691 case SWP_GET_BIT_RATE:
693 p_pipe_info = ((phHciNfc_SWP_Info_t *)
694 psHciContext->p_swp_info)->p_pipe_info;
695 if(NULL == p_pipe_info )
697 status = PHNFCSTVAL(CID_NFC_HCI,
698 NFCSTATUS_INVALID_HCI_INFORMATION);
702 status = phHciNfc_SWP_Get_Bitrate(
703 psHciContext, pHwRef );
704 if(status == NFCSTATUS_PENDING)
706 p_emulation_mgmt_info->emulation_next_seq =
707 SWP_DISABLE_EMULATION;
708 status = NFCSTATUS_SUCCESS;
715 /* Disable the UICC Emulation through SWP */
716 case SWP_DISABLE_EMULATION:
718 p_pipe_info = ((phHciNfc_SWP_Info_t *)
719 psHciContext->p_swp_info)->p_pipe_info;
720 if(NULL == p_pipe_info )
722 status = PHNFCSTVAL(CID_NFC_HCI,
723 NFCSTATUS_INVALID_HCI_INFORMATION);
727 status = phHciNfc_SWP_Configure_Mode( psHciContext,
728 pHwRef, UICC_SWITCH_MODE_DEFAULT );
729 if(status == NFCSTATUS_PENDING)
731 p_emulation_mgmt_info->emulation_next_seq =
732 WI_DISABLE_EMULATION;
733 /* Disable WI Emulation for Previous Wired
735 /* status = NFCSTATUS_SUCCESS; */
742 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
746 }/* End of the Sequence Switch */
748 }/* End of the Reader Info Memory Check */
750 } /* End of Null Context Check */
756 * \brief Connection Routine for the Uicc.
758 * This function tries to enable and initialise the UICC connected
765 phHciNfc_Uicc_Connect_Status(
766 phHciNfc_sContext_t *psHciContext,
770 NFCSTATUS status = NFCSTATUS_SUCCESS;
771 /* phHciNfc_Pipe_Info_t *p_pipe_info = NULL; */
772 /* phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info=NULL; */
773 static uint32_t uicc_connection_retry = 0;
775 if( NULL == psHciContext )
777 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
781 phHciNfc_SWP_Status_t uicc_status =
782 ((phHciNfc_SWP_Info_t *)
783 psHciContext->p_swp_info)->uicc_status;
784 if(uicc_connection_retry == 0)
786 #ifdef UICC_STATUS_DELAY
787 for( ;uicc_connection_retry < UICC_STATUS_DELAY_COUNT;
788 uicc_connection_retry ++ );
789 uicc_connection_retry = 0;
791 status = phHciNfc_SWP_Get_Status(
792 psHciContext, pHwRef );
793 if (NFCSTATUS_PENDING == status)
795 uicc_connection_retry++;
802 case UICC_CONNECTION_ONGOING:
803 case UICC_DISCONNECTION_ONGOING:
804 case UICC_NOT_CONNECTED:
806 if(uicc_connection_retry <
807 UICC_MAX_CONNECT_RETRY)
809 status = phHciNfc_SWP_Get_Status(
810 psHciContext, pHwRef );
811 if (NFCSTATUS_PENDING == status)
813 uicc_connection_retry++;
822 case UICC_CONNECTION_LOST:
823 case UICC_CONNECTION_FAILED:
826 uicc_connection_retry = 0;
829 } /* End of the Status Switch */
832 if( NFCSTATUS_PENDING != status )
834 uicc_connection_retry = 0;
835 /* Error Scenario due to SWP Disable Config */
838 } /* End of Null Context Check */
844 * \brief Release of RF Emulation Gate Configuration.
846 * This function initialses the RF Emulation Management and
847 * populates the Reader Management Information Structure
853 phHciNfc_EmuMgmt_Release(
854 phHciNfc_sContext_t *psHciContext,
858 NFCSTATUS status = NFCSTATUS_SUCCESS;
859 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
860 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info=NULL;
862 if( NULL == psHciContext )
864 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
869 p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)
870 psHciContext->p_emulation_mgmt_info ;
872 if( NULL == psHciContext->p_emulation_mgmt_info )
874 status = PHNFCSTVAL(CID_NFC_HCI,
875 NFCSTATUS_INSUFFICIENT_RESOURCES);
879 switch(p_emulation_mgmt_info->emulation_cur_seq )
881 /* Enable/Disable the SmartMx Emulation through WI
882 * After the power down
884 /* Enable the SmartMx Emulation by Default through WI */
885 case WI_DEFAULT_EMULATION:
887 p_pipe_info = ((phHciNfc_WI_Info_t *)
888 psHciContext->p_wi_info)->p_pipe_info;
889 if(NULL == p_pipe_info )
891 status = PHNFCSTVAL(CID_NFC_HCI,
892 NFCSTATUS_INVALID_HCI_INFORMATION);
896 status = phHciNfc_WI_Configure_Default( psHciContext,
897 pHwRef, p_emulation_mgmt_info->smx_powerless );
898 if(status == NFCSTATUS_PENDING)
900 p_emulation_mgmt_info->emulation_next_seq =
901 WI_DISABLE_EMULATION;
906 /* SmartMx In Default Mode */
907 case WI_DISABLE_EMULATION:
909 p_pipe_info = ((phHciNfc_WI_Info_t *)
910 psHciContext->p_wi_info)->p_pipe_info;
911 if(NULL == p_pipe_info )
913 status = PHNFCSTVAL(CID_NFC_HCI,
914 NFCSTATUS_INVALID_HCI_INFORMATION);
918 status = phHciNfc_WI_Configure_Mode( psHciContext,
919 pHwRef, eSmartMx_Default );
920 if(status == NFCSTATUS_SUCCESS )
922 p_emulation_mgmt_info->emulation_next_seq =
923 SWP_DISABLE_EMULATION;
924 status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
926 /* status = NFCSTATUS_PENDING; */
931 /* Enable/Disable the UICC Emulation through SWP
932 * After the power down
934 /* Enable the UICC Emulation by Default through SWP */
935 case SWP_DEFAULT_EMULATION:
937 p_pipe_info = ((phHciNfc_SWP_Info_t *)
938 psHciContext->p_swp_info)->p_pipe_info;
939 if(NULL == p_pipe_info )
941 status = PHNFCSTVAL(CID_NFC_HCI,
942 NFCSTATUS_INVALID_HCI_INFORMATION);
946 status = phHciNfc_SWP_Configure_Default( psHciContext,
947 pHwRef, p_emulation_mgmt_info->uicc_powerless );
948 if(status == NFCSTATUS_PENDING)
950 p_emulation_mgmt_info->emulation_next_seq =
951 SWP_DISABLE_EMULATION;
952 /* status = NFCSTATUS_SUCCESS; */
957 /* Disable the UICC Emulation through SWP */
958 case SWP_DISABLE_EMULATION:
960 p_pipe_info = ((phHciNfc_SWP_Info_t *)
961 psHciContext->p_swp_info)->p_pipe_info;
962 if(NULL == p_pipe_info )
964 status = PHNFCSTVAL(CID_NFC_HCI,
965 NFCSTATUS_INVALID_HCI_INFORMATION);
969 status = phHciNfc_SWP_Configure_Mode( psHciContext,
970 pHwRef, UICC_SWITCH_MODE_DEFAULT );
971 if(status == NFCSTATUS_PENDING)
973 p_emulation_mgmt_info->emulation_next_seq =
974 CONFIG_DEFAULT_EMULATION;
975 status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
977 status = NFCSTATUS_SUCCESS;
982 /* Configure the Default Secure Element Emulation */
983 case CONFIG_DEFAULT_EMULATION:
986 if(NULL == p_pipe_info )
988 status = PHNFCSTVAL(CID_NFC_HCI,
989 NFCSTATUS_INVALID_HCI_INFORMATION);
993 /* status = phHciNfc_DevMgmt_Configure( psHciContext,
995 if(status == NFCSTATUS_PENDING)
997 p_emulation_mgmt_info->emulation_next_seq =
999 status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
1001 status = NFCSTATUS_SUCCESS;
1009 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
1013 }/* End of the Sequence Switch */
1015 }/* End of the Reader Info Memory Check */
1017 } /* End of Null Context Check */
1024 phHciNfc_Emulation_Start (
1025 phHciNfc_sContext_t *psHciContext,
1029 NFCSTATUS status = NFCSTATUS_SUCCESS;
1036 phHciNfc_Emulation_Cfg (
1037 phHciNfc_sContext_t *psHciContext,
1039 phHciNfc_eConfigType_t cfg_type
1042 NFCSTATUS status = NFCSTATUS_SUCCESS;
1043 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info=NULL;
1044 phHal_sEmulationCfg_t *p_emulation_cfg = NULL;
1046 if( (NULL == psHciContext) || (NULL == pHwRef) )
1048 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1050 else if ( ( NULL == psHciContext->p_emulation_mgmt_info )
1051 || ( NULL == psHciContext->p_config_params ) )
1053 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1057 p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)
1058 psHciContext->p_emulation_mgmt_info ;
1059 p_emulation_cfg = psHciContext->p_config_params;
1064 phHal_sSmartMX_Cfg_t *smx_config =
1065 &p_emulation_cfg->config.smartMxCfg;
1066 p_emulation_mgmt_info->smx_powerless =
1067 (uint8_t)(FALSE != smx_config->lowPowerMode );
1068 status = phHciNfc_WI_Configure_Default( psHciContext, pHwRef,
1069 smx_config->enableEmulation );
1075 phHal_sUiccEmuCfg_t *uicc_config =
1076 &p_emulation_cfg->config.uiccEmuCfg;
1077 p_emulation_mgmt_info->uicc_powerless =
1078 (uint8_t)(FALSE != uicc_config->lowPowerMode );
1080 #ifdef SWP_EVENT_USAGE
1081 status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef,
1082 ((TRUE == uicc_config->enableUicc)? /* UICC_SWITCH_MODE_DEFAULT */
1083 UICC_SWITCH_MODE_ON :UICC_SWITCH_MODE_OFF));
1085 status = phHciNfc_SWP_Configure_Default( psHciContext, pHwRef,
1086 uicc_config->enableUicc );
1090 status = phHciNfc_SWP_Config_Sequence( psHciContext,
1091 pHwRef, p_emulation_cfg);
1097 phHal_sUiccEmuCfg_t *uicc_config =
1098 &p_emulation_cfg->config.uiccEmuCfg;
1099 p_emulation_mgmt_info->uicc_powerless =
1100 (uint8_t)(FALSE != uicc_config->lowPowerMode );
1102 status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef,
1103 ((TRUE == uicc_config->enableUicc)? /* UICC_SWITCH_MODE_DEFAULT */
1104 UICC_SWITCH_MODE_ON :UICC_SWITCH_MODE_DEFAULT));
1108 #ifdef HOST_EMULATION
1111 phHal_sHostEmuCfg_A_t *host_ce_a_cfg =
1112 &p_emulation_cfg->config.hostEmuCfg_A;
1113 if(host_ce_a_cfg->enableEmulation == TRUE )
1115 status = phHciNfc_CE_A_Initialise( psHciContext, pHwRef);
1119 status = phHciNfc_CE_A_Release( psHciContext, pHwRef);
1125 phHal_sHostEmuCfg_B_t *host_ce_b_cfg =
1126 &p_emulation_cfg->config.hostEmuCfg_B;
1127 if(host_ce_b_cfg->enableEmulation == TRUE )
1129 status = phHciNfc_CE_B_Initialise( psHciContext, pHwRef);
1133 status = phHciNfc_CE_B_Release( psHciContext, pHwRef);
1138 /* case INVALID_CFG:
1139 case POLL_LOOP_CFG: */
1142 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1146 } /* End of the Configuration Switch */
1155 phHciNfc_Recv_Uicc_Cmd (
1166 uint8_t pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
1167 uint8_t cmd = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;
1168 uint8_t response = (uint8_t) ANY_OK;
1169 NFCSTATUS status = NFCSTATUS_SUCCESS;
1170 phHciNfc_sContext_t *psHciContext =
1171 (phHciNfc_sContext_t *)psContext ;
1172 phHciNfc_HCP_Packet_t *hcp_packet = NULL;
1173 phHciNfc_HCP_Message_t *hcp_message = NULL;
1174 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
1175 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info=NULL;
1177 if( (NULL == psHciContext)
1179 || (HCP_HEADER_LEN > length )
1182 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1186 hcp_packet = (phHciNfc_HCP_Packet_t *)pCmd;
1187 hcp_message = &hcp_packet->msg.message;
1188 p_emulation_mgmt_info = psHciContext->p_emulation_mgmt_info;
1190 /* Get the Command instruction bits from the Message Header */
1191 cmd = (uint8_t) GET_BITS8( hcp_message->msg_header,
1192 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
1193 pipe_id = p_emulation_mgmt_info->uicc_id;
1194 p_pipe_info = psHciContext->p_pipe_list[pipe_id];
1198 /* These are Commands are sent from the UICC Controller */
1201 p_emulation_mgmt_info->uicc_enable = TRUE ;
1204 case ANY_CLOSE_PIPE:
1206 if(TRUE != p_emulation_mgmt_info->uicc_enable)
1208 response = ANY_E_PIPE_NOT_OPENED;
1209 /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FAILED); */
1213 p_emulation_mgmt_info->uicc_enable = FALSE;
1217 case ANY_SET_PARAMETER:
1218 case ANY_GET_PARAMETER:
1219 case PRO_HOST_REQUEST:
1221 response = ANY_E_CMD_NOT_SUPPORTED;
1222 /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_COMMAND_NOT_SUPPORTED);*/
1227 response = ANY_E_NOK;
1228 /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_COMMAND); */
1232 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
1233 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
1234 pipe_id, HCP_MSG_TYPE_RESPONSE, response );
1235 psHciContext->tx_total = HCP_HEADER_LEN;
1236 status = phHciNfc_Send_HCP( (void *)psHciContext, (void *)pHwRef );
1238 p_pipe_info->recv_msg_type = HCP_MSG_TYPE_COMMAND;
1239 p_pipe_info->sent_msg_type = HCP_MSG_TYPE_RESPONSE;
1240 p_pipe_info->prev_msg = response ;
1241 p_pipe_info->prev_status = status;
1242 status = NFCSTATUS_SUCCESS;
1250 phHciNfc_Recv_Uicc_Event (
1261 uint8_t event = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;
1263 NFCSTATUS status = NFCSTATUS_SUCCESS;
1264 phHciNfc_sContext_t *psHciContext =
1265 (phHciNfc_sContext_t *)psContext ;
1266 phHciNfc_HCP_Packet_t *hcp_packet = NULL;
1267 phHciNfc_HCP_Message_t *hcp_message = NULL;
1268 phHal_sEventInfo_t event_info;
1269 phHciNfc_EmulationMgmt_Info_t *p_emulation_mgmt_info =
1270 psHciContext->p_emulation_mgmt_info ;
1273 if( (NULL == p_emulation_mgmt_info)
1274 || ( TRUE != p_emulation_mgmt_info->uicc_enable)
1277 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1281 hcp_packet = (phHciNfc_HCP_Packet_t *)pEvent;
1282 hcp_message = &hcp_packet->msg.message;
1284 /* Get the Event instruction bits from the Message Header */
1285 event = (uint8_t) GET_BITS8( hcp_message->msg_header,
1286 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
1287 event_info.eventHost = phHal_eUICCHost ;
1288 event_info.eventSource = phHal_ePICC_DevType ;
1292 case EVT_END_OF_TRANSACTION:
1294 event_info.eventType = NFC_EVT_END_OF_TRANSACTION;
1297 case EVT_TRANSACTION:
1299 if(length > HCP_HEADER_LEN + TRANSACTION_MIN_LEN)
1301 event_info.eventType = NFC_EVT_TRANSACTION;
1303 for(;i<(length-HCP_HEADER_LEN);)
1305 switch (hcp_message->payload[i])
1307 case TRANSACTION_AID:
1309 /* AID LENGTH INDEX */
1311 /* Fill the event_info.eventInfo.aid
1312 * Structure with the Received Transaction AID.
1314 event_info.eventInfo.aid.length =
1315 hcp_message->payload[i++];
1316 (void) memcpy((void *)p_emulation_mgmt_info->uicc_aid,
1317 &(hcp_message->payload[i]),
1318 event_info.eventInfo.aid.length );
1319 event_info.eventInfo.aid.buffer = (uint8_t *)
1320 p_emulation_mgmt_info->uicc_aid;
1321 i = i + event_info.eventInfo.aid.length;
1324 case TRANSACTION_PARAM:
1326 /* Parameter Length Index */
1328 /* Fill the event_info.eventInfo.param
1329 * Structure with the Received Parameter.
1331 p_emulation_mgmt_info->uicc_param_len =
1332 hcp_message->payload[i++];
1333 (void) memcpy((void *)p_emulation_mgmt_info->uicc_param,
1334 &(hcp_message->payload[i]),
1335 p_emulation_mgmt_info->uicc_param_len );
1336 event_info.eventInfo.uicc_info.param.length =
1337 p_emulation_mgmt_info->uicc_param_len;
1338 event_info.eventInfo.uicc_info.param.buffer = (uint8_t *)
1339 p_emulation_mgmt_info->uicc_param;
1340 i = i + event_info.eventInfo.uicc_info.param.length;
1346 status = PHNFCSTVAL( CID_NFC_HCI,
1347 NFCSTATUS_FEATURE_NOT_SUPPORTED );
1349 HCI_DEBUG("%s: Statement Should Not Occur \n",
1350 "phHciNfc_Recv_Uicc_Event");
1353 } /* End of Transaction Switch */
1358 case EVT_CONNECTIVITY:
1360 event_info.eventType = NFC_EVT_CONNECTIVITY;
1363 case EVT_OPERATION_ENDED:
1365 event_info.eventType = NFC_EVT_OPERATION_ENDED;
1370 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
1371 HCI_DEBUG("%s: Statement Should Not Occur \n","phHciNfc_Recv_Uicc_Event");
1375 if ( NFCSTATUS_SUCCESS == status )
1377 phHciNfc_Notify_Event( psHciContext, pHwRef,
1378 NFC_NOTIFY_EVENT, (void *)&event_info );