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 * \file phLibNfc_SE.c
\r
20 * Project: NFC FRI / HALDL
\r
22 * $Date: Thu Apr 22 13:59:50 2010 $
\r
23 * $Author: ing07385 $
\r
25 * $Aliases: NFC_FRI1.1_WK1014_SDK,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1019_SDK,NFC_FRI1.1_WK1024_SDK $
\r
30 ************************* Header Files ***************************************
\r
33 #include <phNfcStatus.h>
\r
34 #include <phLibNfc.h>
\r
35 #include <phHal4Nfc.h>
\r
36 #include <phOsalNfc.h>
\r
37 #include <phLibNfc_Internal.h>
\r
38 #include <phLibNfc_SE.h>
\r
39 #include <phLibNfc_ndef_raw.h>
\r
40 #include <phLibNfc_initiator.h>
\r
41 #include <phLibNfc_discovery.h>
\r
44 *************************** Macro's ****************************************
\r
47 #ifndef STATIC_DISABLE
\r
48 #define STATIC static
\r
54 *************************** Global Variables **********************************
\r
57 /*This Structure contains the Secure Element information*/
\r
58 phLibNfc_SE_List_t sSecuredElementInfo[PHLIBNFC_MAXNO_OF_SE];
\r
61 *************************** Static Function Declaration ***********************
\r
64 /* Response callback for SE Set Mode*/
\r
66 void phLibNfc_SE_SetMode_cb(void *context, NFCSTATUS status);
\r
69 /* SE register listner response notification */
\r
71 void phLibNfc_SeNotification(void *context,
\r
72 phHal_eNotificationType_t type,
\r
73 phHal4Nfc_NotificationInfo_t info,
\r
77 *************************** Function Definitions ******************************
\r
81 * Registers notification handler to handle secure element specific events
\r
83 NFCSTATUS phLibNfc_SE_NtfRegister (
\r
84 pphLibNfc_SE_NotificationCb_t pSE_NotificationCb,
\r
88 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
89 pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
\r
91 if((NULL == gpphLibContext) ||
\r
92 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
\r
94 Status = NFCSTATUS_NOT_INITIALISED;
\r
96 else if((pSE_NotificationCb == NULL)
\r
97 ||(NULL == pContext))
\r
99 /*parameters sent by upper layer are not valid*/
\r
100 Status = NFCSTATUS_INVALID_PARAMETER;
\r
102 else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
\r
104 Status = NFCSTATUS_SHUTDOWN;
\r
108 /*Register SE notification with lower layer.
\r
109 Any activity on Smx or UICC will be notified */
\r
110 Status = phHal4Nfc_RegisterNotification(
\r
111 pLibContext->psHwReference,
\r
112 eRegisterSecureElement,
\r
113 phLibNfc_SeNotification,
\r
114 (void*)pLibContext);
\r
115 if(Status == NFCSTATUS_SUCCESS)
\r
117 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb = pSE_NotificationCb;
\r
118 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt=pContext;
\r
122 /* Registration failed */
\r
123 Status = NFCSTATUS_FAILED;
\r
129 * SE Notification events are notified with this callback
\r
131 STATIC void phLibNfc_SeNotification(void *context,
\r
132 phHal_eNotificationType_t type,
\r
133 phHal4Nfc_NotificationInfo_t info,
\r
136 pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)context;
\r
137 phHal_sEventInfo_t *pEvtInfo = NULL;
\r
138 phLibNfc_uSeEvtInfo_t Se_Trans_Info={{{0,0},{0,0}}};
\r
139 phLibNfc_SE_List_t *pSeInfo=NULL;
\r
141 if(pLibContext != gpphLibContext)
\r
143 /*wrong context returned*/
\r
144 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
148 if((status == NFCSTATUS_SUCCESS) && (type == NFC_EVENT_NOTIFICATION))
\r
150 pEvtInfo = info.psEventInfo;
\r
151 status = NFCSTATUS_SUCCESS;
\r
152 if((pEvtInfo->eventSource == phHal_ePICC_DevType )
\r
153 && (pEvtInfo->eventHost == phHal_eHostController) )
\r
155 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type = phLibNfc_SE_Type_SmartMX;
\r
156 /* Smartx Mx is Activated */
\r
157 pSeInfo = &sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX];
\r
159 if(pEvtInfo->eventHost == phHal_eUICCHost)
\r
161 /* UICC is Activate */
\r
162 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type = phLibNfc_SE_Type_UICC;
\r
163 pSeInfo = &sSecuredElementInfo[LIBNFC_SE_UICC_INDEX];
\r
167 /*presently Smx event source is not supported */
\r
171 switch(pEvtInfo->eventType)
\r
173 case NFC_EVT_TRANSACTION:
\r
175 if((pEvtInfo->eventInfo.aid.length != 0) && ((pEvtInfo->eventInfo.aid.length <= 16))) // PLG
\r
177 /*copy the Application id on which transaction happened*/
\r
178 Se_Trans_Info.UiccEvtInfo.aid.buffer =pEvtInfo->eventInfo.aid.buffer;
\r
179 Se_Trans_Info.UiccEvtInfo.aid.length =pEvtInfo->eventInfo.aid.length;
\r
184 Se_Trans_Info.UiccEvtInfo.aid.buffer = NULL;
\r
185 Se_Trans_Info.UiccEvtInfo.aid.length = 0;
\r
187 if((pEvtInfo->eventHost == phHal_eUICCHost)
\r
188 && (info.psEventInfo->eventInfo.uicc_info.param.length
\r
191 /*copy the parameters info on which transaction happened*/
\r
192 Se_Trans_Info.UiccEvtInfo.param.buffer =
\r
193 info.psEventInfo->eventInfo.uicc_info.param.buffer;
\r
194 Se_Trans_Info.UiccEvtInfo.param.length =
\r
195 info.psEventInfo->eventInfo.uicc_info.param.length;
\r
197 /*Notify to upper layer that transaction had happened on the
\r
198 one of the application stored in UICC or Smx*/
\r
199 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
200 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
201 phLibNfc_eSE_EvtStartTransaction,
\r
202 pSeInfo->hSecureElement,
\r
208 case NFC_EVT_APDU_RECEIVED:
\r
210 if ((pEvtInfo->eventInfo.aid.length != 0) && ((pEvtInfo->eventInfo.aid.length <= 16)))
\r
212 /* Copy received APDU to aid buffer. */
\r
213 Se_Trans_Info.UiccEvtInfo.aid.buffer = pEvtInfo->eventInfo.aid.buffer;
\r
214 Se_Trans_Info.UiccEvtInfo.aid.length = pEvtInfo->eventInfo.aid.length;
\r
217 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
218 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
219 phLibNfc_eSE_EvtApduReceived,
\r
220 pSeInfo->hSecureElement,
\r
226 case NFC_EVT_MIFARE_ACCESS:
\r
228 /* copy the Block MIFARE accessed */
\r
229 Se_Trans_Info.UiccEvtInfo.aid.buffer = pEvtInfo->eventInfo.aid.buffer;
\r
230 Se_Trans_Info.UiccEvtInfo.aid.length = pEvtInfo->eventInfo.aid.length;
\r
232 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
233 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
234 phLibNfc_eSE_EvtMifareAccess,
\r
235 pSeInfo->hSecureElement,
\r
241 case NFC_EVT_EMV_CARD_REMOVAL:
\r
243 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
244 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
245 phLibNfc_eSE_EvtCardRemoval,
\r
246 pSeInfo->hSecureElement,
\r
252 case NFC_EVT_END_OF_TRANSACTION:
\r
254 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
255 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
256 phLibNfc_eSE_EvtEndTransaction,
\r
257 pSeInfo->hSecureElement,
\r
262 case NFC_EVT_CONNECTIVITY:
\r
264 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
265 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
266 phLibNfc_eSE_EvtConnectivity,
\r
267 pSeInfo->hSecureElement,
\r
272 case NFC_EVT_START_OF_TRANSACTION:
\r
274 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
275 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
276 phLibNfc_eSE_EvtTypeTransaction,
\r
277 pSeInfo->hSecureElement,
\r
282 case NFC_EVT_FIELD_ON:
\r
284 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
285 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
286 phLibNfc_eSE_EvtFieldOn,
\r
287 pSeInfo->hSecureElement,
\r
292 case NFC_EVT_FIELD_OFF:
\r
294 (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
\r
295 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
\r
296 phLibNfc_eSE_EvtFieldOff,
\r
297 pSeInfo->hSecureElement,
\r
318 * Unregister the Secured Element Notification.
\r
320 NFCSTATUS phLibNfc_SE_NtfUnregister(void)
\r
322 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
323 pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
\r
325 if((NULL == gpphLibContext) ||
\r
326 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
\r
328 /*Lib Nfc is not initialized*/
\r
329 Status = NFCSTATUS_NOT_INITIALISED;
\r
331 else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
\r
333 Status = NFCSTATUS_SHUTDOWN;
\r
337 /*Unregister SE event notification with lower layer.
\r
338 even some transaction happens on UICC or Smx will not
\r
339 be notified afterworlds */
\r
340 Status = phHal4Nfc_UnregisterNotification(
\r
341 pLibContext->psHwReference,
\r
342 eRegisterSecureElement,
\r
344 if(Status != NFCSTATUS_SUCCESS)
\r
346 /*Unregister failed*/
\r
347 Status=NFCSTATUS_FAILED;
\r
349 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb=NULL;
\r
350 pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt=NULL;
\r
356 * Get list of available Secure Elements
\r
358 NFCSTATUS phLibNfc_SE_GetSecureElementList(
\r
359 phLibNfc_SE_List_t* pSE_List,
\r
363 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
364 uint8_t uNo_Of_SE = 0;
\r
366 if((NULL == gpphLibContext) ||
\r
367 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
\r
369 Status = NFCSTATUS_NOT_INITIALISED;
\r
371 else if((NULL ==pSE_List) || (NULL ==uSE_count))
\r
373 Status = NFCSTATUS_INVALID_PARAMETER;
\r
375 else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
\r
377 Status = NFCSTATUS_SHUTDOWN;
\r
381 /*Check for which type of Secure Element is available*/
\r
382 if(gpphLibContext->psHwReference->uicc_connected==TRUE)
\r
384 /* Populate the UICC type */
\r
385 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type = phLibNfc_SE_Type_UICC;
\r
387 /* Populate the UICC handle */
\r
388 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement =(phLibNfc_Handle)
\r
389 (LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
\r
391 #ifdef NXP_HAL_ENABLE_SMX
\r
393 pSE_List[LIBNFC_SE_UICC_INDEX].eSE_Type =
\r
394 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type;
\r
395 pSE_List[LIBNFC_SE_UICC_INDEX].hSecureElement = (phLibNfc_Handle)
\r
396 (LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
\r
397 pSE_List[LIBNFC_SE_UICC_INDEX].eSE_CurrentState =
\r
398 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState;
\r
400 pSE_List->eSE_Type =
\r
401 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type;
\r
402 pSE_List->hSecureElement = (phLibNfc_Handle)
\r
403 (LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
\r
404 pSE_List->eSE_CurrentState =
\r
405 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState;
\r
407 /* update the No of SE retrieved */
\r
411 if (gpphLibContext->psHwReference->smx_connected ==TRUE)
\r
413 /* if the Smx is also connected to the PN544 */
\r
414 /* Populate the SMX type */
\r
415 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type = phLibNfc_SE_Type_SmartMX;
\r
417 /* Populate the SMX handle */
\r
418 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement =(phLibNfc_Handle)
\r
419 (LIBNFC_SE_SMARTMX_INDEX + LIBNFC_SE_BASE_HANDLE);
\r
420 pSE_List[LIBNFC_SE_SMARTMX_INDEX].eSE_Type =
\r
421 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type;
\r
422 pSE_List[LIBNFC_SE_SMARTMX_INDEX].hSecureElement = (phLibNfc_Handle)
\r
423 (LIBNFC_SE_SMARTMX_INDEX + LIBNFC_SE_BASE_HANDLE);
\r
424 pSE_List[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState =
\r
425 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState;
\r
427 /* update the No of SE retrieved */
\r
431 *uSE_count = uNo_Of_SE;
\r
437 * Sets secure element mode.
\r
438 * This function configures SE to specific mode based on activation mode type
\r
441 NFCSTATUS phLibNfc_SE_SetMode ( phLibNfc_Handle hSE_Handle,
\r
442 phLibNfc_eSE_ActivationMode eActivation_mode,
\r
443 pphLibNfc_SE_SetModeRspCb_t pSE_SetMode_Rsp_cb,
\r
447 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
448 phHal_eEmulationType_t eEmulationType = NFC_SMARTMX_EMULATION;
\r
449 pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
\r
451 if((NULL == gpphLibContext) ||
\r
452 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
\r
454 Status = NFCSTATUS_NOT_INITIALISED;
\r
456 else if((pSE_SetMode_Rsp_cb ==NULL)
\r
457 ||(NULL == pContext)||(NULL==(void *)hSE_Handle))
\r
459 Status=NFCSTATUS_INVALID_PARAMETER;
\r
461 else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
\r
463 Status = NFCSTATUS_SHUTDOWN;
\r
465 else if((pLibContext->status.GenCb_pending_status == TRUE)
\r
466 ||(NULL!=pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb))
\r
468 /*previous callback is pending still*/
\r
469 Status =NFCSTATUS_REJECTED;
\r
473 switch(eActivation_mode)
\r
475 case phLibNfc_SE_ActModeVirtual:
\r
477 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
\r
479 eEmulationType = NFC_UICC_EMULATION;
\r
480 /*Enable the UICC -External reader can see it*/
\r
481 pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = TRUE;
\r
483 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
\r
485 eEmulationType = NFC_SMARTMX_EMULATION;
\r
486 /*Enable the SMX -External reader can see it*/
\r
487 pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = TRUE;
\r
491 Status=NFCSTATUS_INVALID_HANDLE;
\r
493 if(Status==NFCSTATUS_SUCCESS)
\r
495 if(pLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)
\r
497 pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeVirtual;
\r
499 pLibContext->sCardEmulCfg.emuType = eEmulationType;
\r
500 Status = phHal4Nfc_ConfigParameters(
\r
501 pLibContext->psHwReference,
\r
502 NFC_EMULATION_CONFIG,
\r
503 (phHal_uConfig_t*)&pLibContext->sCardEmulCfg,
\r
504 phLibNfc_SE_SetMode_cb,
\r
509 case phLibNfc_SE_ActModeVirtualVolatile:
\r
511 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
\r
513 eEmulationType = NFC_SMARTMX_EMULATION;
\r
514 /*Enable the SMX -External reader can see it*/
\r
515 pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = TRUE;
\r
516 pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeVirtualVolatile;
\r
518 Status = phHal4Nfc_Switch_SMX_Mode(
\r
519 pLibContext->psHwReference,
\r
521 phLibNfc_SE_SetMode_cb,
\r
525 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
\r
527 eEmulationType = NFC_UICC_EMULATION;
\r
528 /*Enable the UICC -External reader can see it*/
\r
529 pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = TRUE;
\r
530 pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeVirtualVolatile;
\r
532 Status = phHal4Nfc_Switch_Swp_Mode(
\r
533 pLibContext->psHwReference,
\r
535 phLibNfc_SE_SetMode_cb,
\r
541 Status = NFCSTATUS_INVALID_HANDLE;
\r
545 case phLibNfc_SE_ActModeDefault:
\r
547 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
\r
549 Status = phHal4Nfc_Switch_SMX_Mode(
\r
550 pLibContext->psHwReference,
\r
552 phLibNfc_SE_SetMode_cb,
\r
556 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
\r
558 Status = phHal4Nfc_Switch_Swp_Mode(
\r
559 pLibContext->psHwReference,
\r
560 eSWP_Switch_Default,
\r
561 phLibNfc_SE_SetMode_cb,
\r
567 Status = NFCSTATUS_INVALID_HANDLE;
\r
572 case phLibNfc_SE_ActModeWired:
\r
574 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
\r
576 if(pLibContext->CBInfo.pClientNtfRegRespCB!=NULL)
\r
578 /*Disable the SMX -External reader can't see it anymore*/
\r
579 pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = FALSE;
\r
580 pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeWired;
\r
582 Status = phHal4Nfc_Switch_SMX_Mode(
\r
583 pLibContext->psHwReference,
\r
585 phLibNfc_SE_SetMode_cb,
\r
590 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
\r
592 /*This mode is not applicable to UICC*/
\r
593 Status = NFCSTATUS_REJECTED;
\r
597 Status = NFCSTATUS_INVALID_HANDLE;
\r
602 case phLibNfc_SE_ActModeOff:
\r
604 /*UICC emulation deactivate*/
\r
605 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
\r
607 eEmulationType = NFC_UICC_EMULATION;
\r
608 /*Disable the UICC -External reader can't see it anymore*/
\r
609 pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = FALSE;
\r
612 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
\r
614 eEmulationType = NFC_SMARTMX_EMULATION;
\r
615 /*Disable the SMX -External reader can't see it anymore*/
\r
616 pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation=FALSE;
\r
621 Status = NFCSTATUS_INVALID_HANDLE;
\r
623 if(Status==NFCSTATUS_SUCCESS)
\r
625 pLibContext->sCardEmulCfg.emuType = eEmulationType;
\r
627 if(pLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)
\r
629 pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeOff;
\r
632 Status = phHal4Nfc_ConfigParameters(pLibContext->psHwReference,
\r
633 NFC_EMULATION_CONFIG,
\r
634 (phHal_uConfig_t*)&pLibContext->sCardEmulCfg,
\r
635 phLibNfc_SE_SetMode_cb,
\r
641 Status=NFCSTATUS_INVALID_PARAMETER;
\r
644 }/*End of eActivation_mode switch */
\r
645 if(Status==NFCSTATUS_PENDING)
\r
647 pLibContext->sSeContext.hSetemp=hSE_Handle;
\r
648 pLibContext->status.GenCb_pending_status = TRUE;
\r
649 pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = pSE_SetMode_Rsp_cb;
\r
650 pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt=pContext;
\r
652 else if(Status == NFCSTATUS_INVALID_HANDLE)
\r
658 Status = NFCSTATUS_FAILED;
\r
664 * Callback for Se Set mode
\r
666 STATIC void phLibNfc_SE_SetMode_cb(void *context, NFCSTATUS status)
\r
668 pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)context;
\r
669 pphLibNfc_SE_SetModeRspCb_t pUpperLayerCb=NULL;
\r
670 void *pUpperContext=NULL;
\r
671 phLibNfc_Handle hSeHandle=0;
\r
672 uint8_t TempState=FALSE;
\r
674 if(pLibContext != gpphLibContext)
\r
676 /*wrong context returned*/
\r
677 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
681 if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
\r
683 /*If shutdown is called in between allow shutdown to happen*/
\r
684 phLibNfc_Pending_Shutdown();
\r
685 status = NFCSTATUS_SHUTDOWN;
\r
689 if(status == NFCSTATUS_SUCCESS)
\r
691 hSeHandle = pLibContext->sSeContext.hSetemp;
\r
693 if(hSeHandle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
\r
695 if(TRUE==pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc)
\r
697 /*If Activation mode was virtual allow external reader to see it*/
\r
698 pLibContext->sSeContext.uUiccActivate = TRUE;
\r
699 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState = phLibNfc_SE_Active;
\r
703 /*If Activation mode was wired don't allow external reader to see it*/
\r
704 pLibContext->sSeContext.uUiccActivate = FALSE;
\r
705 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState =
\r
706 phLibNfc_SE_Inactive;
\r
708 status = NFCSTATUS_SUCCESS;
\r
709 TempState = pLibContext->sSeContext.uUiccActivate;
\r
711 else if (hSeHandle==sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
\r
713 if(TRUE==pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation)
\r
715 /*If Activation mode was virtual allow external reader to see it*/
\r
716 pLibContext->sSeContext.uSmxActivate = TRUE;
\r
717 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState =
\r
718 phLibNfc_SE_Active;
\r
722 /*If Activation mode was wired don't allow external reader to see it*/
\r
723 pLibContext->sSeContext.uSmxActivate = FALSE;
\r
724 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState=
\r
725 phLibNfc_SE_Inactive;
\r
727 status = NFCSTATUS_SUCCESS;
\r
728 TempState = pLibContext->sSeContext.uSmxActivate;
\r
732 status = NFCSTATUS_FAILED;
\r
737 status = NFCSTATUS_FAILED;
\r
739 pLibContext->status.GenCb_pending_status = FALSE;
\r
743 pUpperLayerCb = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb;
\r
744 pUpperContext = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt;
\r
745 pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = NULL;
\r
746 pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt = NULL;
\r
747 PHNFC_UNUSED_VARIABLE(TempState);
\r
748 /* Call the upper layer cb */
\r
749 if(pUpperLayerCb!= NULL )
\r
751 (*pUpperLayerCb)(pUpperContext,
\r