Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 NXP Semiconductors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*!
     18  * \file phLibNfc_SE.c
     19 
     20  * Project: NFC FRI / HALDL
     21  *
     22  * $Date: Thu Apr 22 13:59:50 2010 $
     23  * $Author: ing07385 $
     24  * $Revision: 1.65 $
     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 $
     26  *
     27  */
     28 
     29 /*
     30 ************************* Header Files ***************************************
     31 */
     32 
     33 #include <phNfcStatus.h>
     34 #include <phLibNfc.h>
     35 #include <phHal4Nfc.h>
     36 #include <phOsalNfc.h>
     37 #include <phLibNfc_Internal.h>
     38 #include <phLibNfc_SE.h>
     39 #include <phLibNfc_ndef_raw.h>
     40 #include <phLibNfc_initiator.h>
     41 #include <phLibNfc_discovery.h>
     42 
     43 /*
     44 *************************** Macro's  ****************************************
     45 */
     46 
     47 #ifndef STATIC_DISABLE
     48 #define STATIC static
     49 #else
     50 #define STATIC
     51 #endif
     52 
     53 /*
     54 *************************** Global Variables **********************************
     55 */
     56 
     57 /*This Structure  contains the Secure Element information*/
     58 phLibNfc_SE_List_t sSecuredElementInfo[PHLIBNFC_MAXNO_OF_SE];
     59 
     60 /*
     61 *************************** Static Function Declaration ***********************
     62 */
     63 
     64 /* Response callback for SE Set Mode*/
     65 STATIC
     66 void phLibNfc_SE_SetMode_cb(void  *context, NFCSTATUS status);
     67 
     68 
     69 /* SE register listner response notification */
     70 STATIC
     71 void phLibNfc_SeNotification(void                     *context,
     72                         phHal_eNotificationType_t     type,
     73                         phHal4Nfc_NotificationInfo_t  info,
     74                         NFCSTATUS                     status
     75                         );
     76 /*
     77 *************************** Function Definitions ******************************
     78 */
     79 
     80 /**
     81 * Registers notification handler to handle secure element specific events
     82 */
     83 NFCSTATUS phLibNfc_SE_NtfRegister   (
     84                             pphLibNfc_SE_NotificationCb_t  pSE_NotificationCb,
     85                             void                            *pContext
     86                             )
     87 {
     88      NFCSTATUS         Status = NFCSTATUS_SUCCESS;
     89      pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
     90 
     91      if((NULL == gpphLibContext) ||
     92          (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
     93      {
     94          Status = NFCSTATUS_NOT_INITIALISED;
     95      }
     96      else if((pSE_NotificationCb == NULL)
     97          ||(NULL == pContext))
     98      {
     99          /*parameters sent by upper layer are not valid*/
    100          Status = NFCSTATUS_INVALID_PARAMETER;
    101      }
    102      else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
    103      {
    104          Status = NFCSTATUS_SHUTDOWN;
    105      }
    106      else
    107      {
    108          /*Register SE notification with lower layer.
    109          Any activity on Smx or UICC will be notified */
    110          Status = phHal4Nfc_RegisterNotification(
    111                                             pLibContext->psHwReference,
    112                                             eRegisterSecureElement,
    113                                             phLibNfc_SeNotification,
    114                                             (void*)pLibContext);
    115         if(Status == NFCSTATUS_SUCCESS)
    116         {
    117             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb = pSE_NotificationCb;
    118             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt=pContext;
    119         }
    120         else
    121         {
    122             /* Registration failed */
    123             Status = NFCSTATUS_FAILED;
    124         }
    125      }
    126      return Status;
    127 }
    128 /**
    129 * SE Notification events are notified with this callback
    130 */
    131 STATIC void phLibNfc_SeNotification(void  *context,
    132                                     phHal_eNotificationType_t    type,
    133                                     phHal4Nfc_NotificationInfo_t  info,
    134                                     NFCSTATUS                   status)
    135 {
    136     pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)context;
    137     phHal_sEventInfo_t  *pEvtInfo = NULL;
    138     phLibNfc_uSeEvtInfo_t Se_Trans_Info={0};
    139     phLibNfc_SE_List_t  *pSeInfo=NULL;
    140 
    141     if(pLibContext != gpphLibContext)
    142     {
    143         /*wrong context returned*/
    144         phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
    145     }
    146     else
    147     {
    148         if((status == NFCSTATUS_SUCCESS) && (type == NFC_EVENT_NOTIFICATION))
    149         {
    150             pEvtInfo = info.psEventInfo;
    151             status = NFCSTATUS_SUCCESS;
    152             if((pEvtInfo->eventSource == phHal_ePICC_DevType )
    153                 && (pEvtInfo->eventHost == phHal_eHostController) )
    154             {
    155                 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type = phLibNfc_SE_Type_SmartMX;
    156                 /* Smartx Mx is Activated */
    157                 pSeInfo = &sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX];
    158             }
    159             if(pEvtInfo->eventHost == phHal_eUICCHost)
    160             {
    161                 /* UICC is Activate */
    162                 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type = phLibNfc_SE_Type_UICC;
    163                 pSeInfo = &sSecuredElementInfo[LIBNFC_SE_UICC_INDEX];
    164             }
    165             else
    166             {
    167                 /*presently Smx event source is not supported */
    168             }
    169             if(pSeInfo!=NULL)
    170             {
    171                 switch(pEvtInfo->eventType)
    172                 {
    173                     case NFC_EVT_TRANSACTION:
    174                     {
    175                         if((pEvtInfo->eventInfo.aid.length != 0) && ((pEvtInfo->eventInfo.aid.length <= 16)))  // PLG
    176                         {
    177                             /*copy the Application id on which transaction happened*/
    178 							Se_Trans_Info.UiccEvtInfo.aid.buffer =pEvtInfo->eventInfo.aid.buffer;
    179 							Se_Trans_Info.UiccEvtInfo.aid.length =pEvtInfo->eventInfo.aid.length;
    180                         }
    181 						else
    182 						{
    183 							// PLG patch
    184                             Se_Trans_Info.UiccEvtInfo.aid.buffer = NULL;
    185 							Se_Trans_Info.UiccEvtInfo.aid.length = 0;
    186 						}
    187 						if((pEvtInfo->eventHost == phHal_eUICCHost)
    188                            && (info.psEventInfo->eventInfo.uicc_info.param.length
    189                                 != 0))
    190                         {
    191                             /*copy the parameters info on which transaction happened*/
    192 							Se_Trans_Info.UiccEvtInfo.param.buffer =
    193 										info.psEventInfo->eventInfo.uicc_info.param.buffer;
    194 							Se_Trans_Info.UiccEvtInfo.param.length =
    195 										info.psEventInfo->eventInfo.uicc_info.param.length;
    196                         }
    197                             /*Notify to upper layer that transaction had happened on the
    198                             one of the application stored in UICC or Smx*/
    199                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    200                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    201                             phLibNfc_eSE_EvtStartTransaction,
    202                             pSeInfo->hSecureElement,
    203                             &Se_Trans_Info,
    204                             status);
    205                         break;
    206                     }
    207 
    208                     case NFC_EVT_APDU_RECEIVED:
    209                     {
    210                         if ((pEvtInfo->eventInfo.aid.length != 0) && ((pEvtInfo->eventInfo.aid.length <= 16)))
    211                         {
    212                             /* Copy received APDU to aid buffer. */
    213                             Se_Trans_Info.UiccEvtInfo.aid.buffer = pEvtInfo->eventInfo.aid.buffer;
    214                             Se_Trans_Info.UiccEvtInfo.aid.length = pEvtInfo->eventInfo.aid.length;
    215                         }
    216 
    217                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    218                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    219                             phLibNfc_eSE_EvtApduReceived,
    220                             pSeInfo->hSecureElement,
    221                             &Se_Trans_Info,
    222                             status);
    223                         break;
    224                     }
    225 
    226                     case NFC_EVT_MIFARE_ACCESS:
    227                     {
    228                         /* copy the Block MIFARE accessed */
    229                         Se_Trans_Info.UiccEvtInfo.aid.buffer = pEvtInfo->eventInfo.aid.buffer;
    230                         Se_Trans_Info.UiccEvtInfo.aid.length = pEvtInfo->eventInfo.aid.length;
    231 
    232                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    233                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    234                             phLibNfc_eSE_EvtMifareAccess,
    235                             pSeInfo->hSecureElement,
    236                             &Se_Trans_Info,
    237                             status);
    238                         break;
    239                     }
    240 
    241                     case NFC_EVT_EMV_CARD_REMOVAL:
    242                     {
    243                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    244                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    245                             phLibNfc_eSE_EvtCardRemoval,
    246                             pSeInfo->hSecureElement,
    247                             &Se_Trans_Info,
    248                             status);
    249                         break;
    250                     }
    251 
    252                     case NFC_EVT_END_OF_TRANSACTION:
    253                     {
    254                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    255                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    256                             phLibNfc_eSE_EvtEndTransaction,
    257                             pSeInfo->hSecureElement,
    258                             &Se_Trans_Info,
    259                             status);
    260                         break;
    261                     }
    262                     case NFC_EVT_CONNECTIVITY:
    263                     {
    264                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    265                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    266                             phLibNfc_eSE_EvtConnectivity,
    267                             pSeInfo->hSecureElement,
    268                             &Se_Trans_Info,
    269                             status);
    270                         break;
    271                     }
    272                     case NFC_EVT_START_OF_TRANSACTION:
    273                     {
    274                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    275                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    276                             phLibNfc_eSE_EvtTypeTransaction,
    277                             pSeInfo->hSecureElement,
    278                             &Se_Trans_Info,
    279                             status);
    280                         break;
    281                     }
    282                     case NFC_EVT_FIELD_ON:
    283                     {
    284                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    285                             pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    286                             phLibNfc_eSE_EvtFieldOn,
    287                             pSeInfo->hSecureElement,
    288                             &Se_Trans_Info,
    289                             status);
    290                         break;
    291                     }
    292                     case NFC_EVT_FIELD_OFF:
    293                     {
    294                         (*pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb)(
    295                              pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt,
    296                              phLibNfc_eSE_EvtFieldOff,
    297                              pSeInfo->hSecureElement,
    298                              &Se_Trans_Info,
    299                              status);
    300                         break;
    301                     }
    302                     default:
    303                     {
    304                         break;
    305                     }
    306                 }
    307             }
    308             else
    309             {
    310 
    311             }
    312          }
    313     }
    314   return;
    315 }
    316 
    317 /**
    318  * Unregister the Secured Element Notification.
    319  */
    320 NFCSTATUS phLibNfc_SE_NtfUnregister(void)
    321 {
    322     NFCSTATUS Status = NFCSTATUS_SUCCESS;
    323     pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
    324 
    325     if((NULL == gpphLibContext) ||
    326         (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
    327     {
    328         /*Lib Nfc is not initialized*/
    329         Status = NFCSTATUS_NOT_INITIALISED;
    330     }
    331     else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
    332     {
    333         Status = NFCSTATUS_SHUTDOWN;
    334     }
    335     else
    336     {
    337         /*Unregister SE event notification with lower layer.
    338         even some transaction happens on UICC or Smx will not
    339         be notified afterworlds */
    340         Status = phHal4Nfc_UnregisterNotification(
    341                                                 pLibContext->psHwReference,
    342                                                 eRegisterSecureElement,
    343                                                 pLibContext);
    344         if(Status != NFCSTATUS_SUCCESS)
    345         {
    346             /*Unregister failed*/
    347             Status=NFCSTATUS_FAILED;
    348         }
    349         pLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb=NULL;
    350         pLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt=NULL;
    351     }
    352     return Status;
    353 }
    354 
    355 /**
    356 * Get list of available Secure Elements
    357 */
    358 NFCSTATUS phLibNfc_SE_GetSecureElementList(
    359                         phLibNfc_SE_List_t*     pSE_List,
    360                         uint8_t*                uSE_count
    361                         )
    362 {
    363     NFCSTATUS Status = NFCSTATUS_SUCCESS;
    364 	uint8_t    uNo_Of_SE = 0;
    365 
    366     if((NULL == gpphLibContext) ||
    367         (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
    368     {
    369         Status = NFCSTATUS_NOT_INITIALISED;
    370     }
    371     else if((NULL ==pSE_List) || (NULL ==uSE_count))
    372     {
    373         Status = NFCSTATUS_INVALID_PARAMETER;
    374     }
    375     else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
    376     {
    377         Status = NFCSTATUS_SHUTDOWN;
    378     }
    379     else
    380     {
    381         /*Check for which type of Secure Element is available*/
    382         if(gpphLibContext->psHwReference->uicc_connected==TRUE)
    383         {
    384             /* Populate the UICC type */
    385             sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type = phLibNfc_SE_Type_UICC;
    386 
    387             /* Populate the UICC handle */
    388             sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement =(phLibNfc_Handle)
    389                             (LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
    390 
    391 #ifdef NXP_HAL_ENABLE_SMX
    392 
    393             pSE_List[LIBNFC_SE_UICC_INDEX].eSE_Type =
    394 				sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type;
    395             pSE_List[LIBNFC_SE_UICC_INDEX].hSecureElement = (phLibNfc_Handle)
    396                             (LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
    397             pSE_List[LIBNFC_SE_UICC_INDEX].eSE_CurrentState =
    398 				sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState;
    399 #else
    400 			pSE_List->eSE_Type =
    401 				sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_Type;
    402             pSE_List->hSecureElement = (phLibNfc_Handle)
    403                             (LIBNFC_SE_UICC_INDEX + LIBNFC_SE_BASE_HANDLE);
    404             pSE_List->eSE_CurrentState =
    405 				sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState;
    406 #endif
    407             /* update the No of SE retrieved */
    408 			uNo_Of_SE ++;
    409 
    410         }
    411         if (gpphLibContext->psHwReference->smx_connected ==TRUE)
    412         {
    413             /* if the Smx is also connected to the PN544 */
    414             /* Populate the SMX type */
    415             sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type = phLibNfc_SE_Type_SmartMX;
    416 
    417             /* Populate the SMX handle */
    418             sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement =(phLibNfc_Handle)
    419                             (LIBNFC_SE_SMARTMX_INDEX + LIBNFC_SE_BASE_HANDLE);
    420             pSE_List[LIBNFC_SE_SMARTMX_INDEX].eSE_Type =
    421 				sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_Type;
    422             pSE_List[LIBNFC_SE_SMARTMX_INDEX].hSecureElement = (phLibNfc_Handle)
    423                             (LIBNFC_SE_SMARTMX_INDEX + LIBNFC_SE_BASE_HANDLE);
    424             pSE_List[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState =
    425 				sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState;
    426 
    427             /* update the No of SE retrieved */
    428 			uNo_Of_SE ++;
    429 
    430         }
    431 		*uSE_count = uNo_Of_SE;
    432     }
    433     return Status;
    434 }
    435 
    436 /**
    437 * Sets secure element mode.
    438 * This  function configures SE to specific mode based on activation mode type
    439 */
    440 
    441 NFCSTATUS phLibNfc_SE_SetMode ( phLibNfc_Handle             hSE_Handle,
    442                                phLibNfc_eSE_ActivationMode  eActivation_mode,
    443                                pphLibNfc_SE_SetModeRspCb_t  pSE_SetMode_Rsp_cb,
    444                                void *                       pContext
    445                                )
    446 {
    447     NFCSTATUS Status = NFCSTATUS_SUCCESS;
    448     phHal_eEmulationType_t  eEmulationType = NFC_SMARTMX_EMULATION;
    449     pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
    450 
    451     if((NULL == gpphLibContext) ||
    452         (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
    453     {
    454         Status = NFCSTATUS_NOT_INITIALISED;
    455     }
    456 	else if((pSE_SetMode_Rsp_cb ==NULL)
    457         ||(NULL == pContext)||(NULL==(void *)hSE_Handle))
    458     {
    459         Status=NFCSTATUS_INVALID_PARAMETER;
    460     }
    461 	else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
    462     {
    463         Status = NFCSTATUS_SHUTDOWN;
    464     }
    465     else if((pLibContext->status.GenCb_pending_status == TRUE)
    466           ||(NULL!=pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb))
    467     {
    468         /*previous callback is pending still*/
    469         Status =NFCSTATUS_REJECTED;
    470     }
    471     else
    472     {
    473         switch(eActivation_mode)
    474         {
    475             case phLibNfc_SE_ActModeVirtual:
    476             case phLibNfc_SE_ActModeDefault:
    477             {
    478                 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
    479                 {
    480                     eEmulationType = NFC_UICC_EMULATION;
    481                     /*Enable the UICC -External reader can see it*/
    482                     pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = TRUE;
    483                 }
    484                 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
    485                 {
    486                     eEmulationType = NFC_SMARTMX_EMULATION;
    487                     /*Enable the SMX -External reader can see it*/
    488                     pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = TRUE;
    489                 }
    490                 else
    491                 {
    492                     Status=NFCSTATUS_INVALID_HANDLE;
    493                 }
    494                 if(Status==NFCSTATUS_SUCCESS)
    495                 {
    496                     if(pLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)
    497                     {
    498                         pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeVirtual;
    499                     }
    500                     pLibContext->sCardEmulCfg.emuType = eEmulationType;
    501                     Status = phHal4Nfc_ConfigParameters(
    502                                             pLibContext->psHwReference,
    503                                             NFC_EMULATION_CONFIG,
    504                                             (phHal_uConfig_t*)&pLibContext->sCardEmulCfg,
    505                                             phLibNfc_SE_SetMode_cb,
    506                                             pLibContext);
    507                 }
    508             }
    509             break;
    510             case phLibNfc_SE_ActModeWired:
    511             {
    512                 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
    513                 {
    514                     if(pLibContext->CBInfo.pClientNtfRegRespCB!=NULL)
    515                     {
    516                         /*Disable the SMX -External reader can't see it anymore*/
    517                         pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation = FALSE;
    518                         pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeWired;
    519 
    520                         Status = phHal4Nfc_Switch_SMX_Mode(
    521                                             pLibContext->psHwReference,
    522                                             eSmartMx_Wired,
    523                                             phLibNfc_SE_SetMode_cb,
    524                                             pLibContext
    525                                             );
    526                     }
    527                 }
    528                 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
    529                 {
    530                     /*This mode is not applicable to UICC*/
    531                     Status = NFCSTATUS_REJECTED;
    532                 }
    533                 else
    534                 {
    535                     Status = NFCSTATUS_INVALID_HANDLE;
    536                 }
    537             }
    538             break;
    539 
    540             case phLibNfc_SE_ActModeOff:
    541             {
    542                 /*UICC emulation deactivate*/
    543                 if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
    544                 {
    545                     eEmulationType = NFC_UICC_EMULATION;
    546                     /*Disable the UICC -External reader can't see it anymore*/
    547                     pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc = FALSE;
    548 
    549                 }
    550                 else if(hSE_Handle == sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
    551                 {
    552                     eEmulationType = NFC_SMARTMX_EMULATION;
    553                     /*Disable the SMX -External reader can't see it anymore*/
    554                     pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation=FALSE;
    555 
    556                 }
    557                 else
    558                 {
    559                     Status = NFCSTATUS_INVALID_HANDLE;
    560                 }
    561                 if(Status==NFCSTATUS_SUCCESS)
    562                 {
    563                     pLibContext->sCardEmulCfg.emuType = eEmulationType;
    564 
    565                     if(pLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)
    566                     {
    567                          pLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeOff;
    568                     }
    569 
    570                     Status = phHal4Nfc_ConfigParameters(pLibContext->psHwReference,
    571                                                             NFC_EMULATION_CONFIG,
    572                                                             (phHal_uConfig_t*)&pLibContext->sCardEmulCfg,
    573                                                             phLibNfc_SE_SetMode_cb,
    574                                                             pLibContext);
    575                 }
    576             }
    577             break;
    578             default:
    579                 Status=NFCSTATUS_INVALID_PARAMETER;
    580                 break;
    581 
    582         }/*End of eActivation_mode switch */
    583         if(Status==NFCSTATUS_PENDING)
    584         {
    585             pLibContext->sSeContext.hSetemp=hSE_Handle;
    586             pLibContext->status.GenCb_pending_status = TRUE;
    587             pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = pSE_SetMode_Rsp_cb;
    588             pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt=pContext;
    589         }
    590         else if(Status == NFCSTATUS_INVALID_HANDLE)
    591         {
    592             Status= Status;
    593         }
    594         else
    595         {
    596             Status = NFCSTATUS_FAILED;
    597         }
    598     }
    599     return Status;
    600 }
    601 /**
    602 * Callback for Se Set mode
    603 */
    604 STATIC void phLibNfc_SE_SetMode_cb(void  *context, NFCSTATUS status)
    605 {
    606     pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)context;
    607     pphLibNfc_SE_SetModeRspCb_t  pUpperLayerCb=NULL;
    608     void                         *pUpperContext=NULL;
    609     phLibNfc_Handle              hSeHandle=0;
    610     uint8_t                      TempState=FALSE;
    611 
    612     if(pLibContext != gpphLibContext)
    613     {
    614         /*wrong context returned*/
    615         phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
    616     }
    617     else
    618     {
    619         if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
    620         {
    621             /*If shutdown is called in between allow shutdown to happen*/
    622             phLibNfc_Pending_Shutdown();
    623             status = NFCSTATUS_SHUTDOWN;
    624         }
    625         else
    626         {
    627             if(status == NFCSTATUS_SUCCESS)
    628             {
    629                 hSeHandle = pLibContext->sSeContext.hSetemp;
    630 
    631                 if(hSeHandle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
    632                 {
    633                     if(TRUE==pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc)
    634                     {
    635                         /*If  Activation mode was virtual allow external reader to see it*/
    636                         pLibContext->sSeContext.uUiccActivate = TRUE;
    637                         sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState = phLibNfc_SE_Active;
    638                     }
    639                     else
    640                     {
    641                         /*If  Activation mode was wired don't allow external reader to see it*/
    642                         pLibContext->sSeContext.uUiccActivate = FALSE;
    643                         sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState =
    644                                                                     phLibNfc_SE_Inactive;
    645                     }
    646                     status = NFCSTATUS_SUCCESS;
    647                     TempState = pLibContext->sSeContext.uUiccActivate;
    648                 }
    649                 else if (hSeHandle==sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
    650                 {
    651                     if(TRUE==pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation)
    652                     {
    653                         /*If  Activation mode was virtual allow external reader to see it*/
    654                         pLibContext->sSeContext.uSmxActivate = TRUE;
    655                         sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState =
    656                                                                         phLibNfc_SE_Active;
    657                     }
    658                     else
    659                     {
    660                         /*If  Activation mode was wired don't allow external reader to see it*/
    661                         pLibContext->sSeContext.uSmxActivate = FALSE;
    662                         sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState=
    663                                                                         phLibNfc_SE_Inactive;
    664                     }
    665                     status = NFCSTATUS_SUCCESS;
    666                     TempState = pLibContext->sSeContext.uSmxActivate;
    667                 }
    668                 else
    669                 {
    670                     status = NFCSTATUS_FAILED;
    671                 }
    672             }
    673             else
    674             {
    675                 status = NFCSTATUS_FAILED;
    676             }
    677             pLibContext->status.GenCb_pending_status = FALSE;
    678         }
    679 
    680     }
    681     pUpperLayerCb = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb;
    682     pUpperContext = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt;
    683     pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = NULL;
    684     pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt = NULL;
    685 	PHNFC_UNUSED_VARIABLE(TempState);
    686     /* Call the upper layer cb */
    687     if(pUpperLayerCb!= NULL )
    688     {
    689         (*pUpperLayerCb)(pUpperContext,
    690                         hSeHandle,
    691 						status);
    692     }
    693     return;
    694 }
    695 
    696 
    697 
    698