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