/* *************************** Function Definitions ****************************** */ void phLibNfc_config_discovery_cb(void *context, NFCSTATUS status) { if((phLibNfc_LibContext_t *)context == gpphLibContext) { /*check for same context*/ if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state) { /*If shutdown called in between allow shutdown to happen*/ phLibNfc_Pending_Shutdown(); status = NFCSTATUS_SHUTDOWN; } else { gpphLibContext->status.GenCb_pending_status = FALSE; gpphLibContext->status.DiscEnbl_status = FALSE; phLibNfc_UpdateCurState(status,gpphLibContext); #ifdef RESTART_CFG if(gpphLibContext->status.Discovery_pending_status == TRUE) { NFCSTATUS RetStatus = NFCSTATUS_FAILED; /* Application has called discovery before receiving this callback, so NO notification to the upper layer, instead lower layer discovery is called */ gpphLibContext->status.Discovery_pending_status = FALSE; RetStatus = phHal4Nfc_ConfigureDiscovery( gpphLibContext->psHwReference, gpphLibContext->eLibNfcCfgMode, &gpphLibContext->sADDconfig, (pphLibNfc_RspCb_t) phLibNfc_config_discovery_cb, (void *)gpphLibContext); if (NFCSTATUS_PENDING == RetStatus) { (void)phLibNfc_UpdateNextState(gpphLibContext, eLibNfcHalStateConfigReady); gpphLibContext->status.GenCb_pending_status = TRUE; gpphLibContext->status.DiscEnbl_status = TRUE; } else { status = NFCSTATUS_FAILED; } } #endif /* #ifdef RESTART_CFG */ } } /*End of if-context check*/ else { /*exception: wrong context pointer returned*/ phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1); status = NFCSTATUS_FAILED; } if(gpphLibContext->CBInfo.pClientDisConfigCb!=NULL) { gpphLibContext->CBInfo.pClientDisConfigCb(gpphLibContext->CBInfo.pClientDisCfgCntx,status); gpphLibContext->CBInfo.pClientDisConfigCb=NULL; } return; }
/** * Response Callback for Remote device Presence Check. */ STATIC void phLibNfc_RemoteDev_CheckPresence_Cb(void *context, NFCSTATUS status) { void *pUpperLayerContext=NULL; pphLibNfc_RspCb_t pClientCb=NULL; /*check valid context is returned or not*/ if((phLibNfc_LibContext_t *)context != gpphLibContext) { /*exception: wrong context pointer returned*/ phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1); } /* Mark general callback pending status as FALSE*/ gpphLibContext->status.GenCb_pending_status = FALSE; pClientCb =gpphLibContext->CBInfo.pClientPresChkCb ; pUpperLayerContext = gpphLibContext->CBInfo.pClientPresChkCntx; gpphLibContext->CBInfo.pClientPresChkCntx = NULL; gpphLibContext->CBInfo.pClientPresChkCb =NULL; /* Check DeInit call is called, if yes call pending shutdown and return NFCSTATUS_SHUTDOWN */ if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state) { phLibNfc_Pending_Shutdown(); status = NFCSTATUS_SHUTDOWN; } else { if (status != NFCSTATUS_SUCCESS) { /*If status is other than SUCCESS (Internal error) return NFCSTATUS_TARGET_LOST */ status= NFCSTATUS_TARGET_LOST; } else { status = NFCSTATUS_SUCCESS; } } /* Update the current state */ phLibNfc_UpdateCurState(status,gpphLibContext); if(NULL != pClientCb) { /* call the upper layer callback */ pClientCb(pUpperLayerContext,status); } return; }
/**Default notification handler registered with lower layer immediately after successful initialization*/ STATIC void phLibNfc_DefaultHandler( void *context, phHal_eNotificationType_t type, phHal4Nfc_NotificationInfo_t info, NFCSTATUS status ) { if(context != (void *)gpphLibContext) { phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1); } else { info = info; if((NFC_EVENT_NOTIFICATION == type) && (NFCSTATUS_BOARD_COMMUNICATION_ERROR == status)) { phLibNfc_UpdateCurState(NFCSTATUS_FAILED,gpphLibContext); phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); } } return; }
/* shutdown callback - Free the allocated memory here */ STATIC void phLibNfc_ShutdownCb(void *pContext,NFCSTATUS status) { pphLibNfc_RspCb_t pClientCb=NULL; void *pUpperLayerContext=NULL; pphLibNfc_LibContext_t pLibContext=NULL; PHNFC_UNUSED_VARIABLE(pContext); /* Get the Lib context */ pLibContext=(pphLibNfc_LibContext_t)gpphLibContext; if(pLibContext == NULL) { status = NFCSTATUS_FAILED; } else { /* Initialize the local variable */ pClientCb =pLibContext->CBInfo.pClientShutdownCb; pUpperLayerContext=pLibContext->CBInfo.pClientShtdwnCntx; if(status == NFCSTATUS_SUCCESS) { pLibContext->LibNfcState.cur_state = eLibNfcHalStateShutdown; phLibNfc_UpdateCurState(status,pLibContext); pLibContext->status.GenCb_pending_status=FALSE; /* Allocate the Memory for the Transceive info */ if(pClientCb!=NULL) { (*pClientCb)(pUpperLayerContext, status); } if(pLibContext->psHwReference!=NULL) { phOsalNfc_FreeMemory(pLibContext->psHwReference); pLibContext->psHwReference = NULL; } if(NULL != gpphLibContext->psBufferedAuth) { if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer) { phOsalNfc_FreeMemory( gpphLibContext->psBufferedAuth->sRecvData.buffer); } if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer) { phOsalNfc_FreeMemory( gpphLibContext->psBufferedAuth->sSendData.buffer); } phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth); gpphLibContext->psBufferedAuth = NULL; } /*Free the memory allocated during NDEF read,write and NDEF formatting*/ phLibNfc_Ndef_DeInit(); phOsalNfc_FreeMemory(pLibContext); gpphLibContext=NULL; pLibContext= NULL; } else { /* shutdown sequence failed by HAL 4 */ status= NFCSTATUS_FAILED; pLibContext=(pphLibNfc_LibContext_t)gpphLibContext; phLibNfc_UpdateCurState(status,pLibContext); pLibContext->status.GenCb_pending_status=FALSE; if(pClientCb!=NULL) { (*pClientCb)(pUpperLayerContext,status); } } } }
/* * This function called by the HAL4 when the initialization seq is completed. */ STATIC void phLibNfc_InitCb(void *pContext,NFCSTATUS status) { pphLibNfc_LibContext_t pLibContext=NULL; pphLibNfc_RspCb_t pClientCb=NULL; void *pUpperLayerContext=NULL; /* Initialize the local variable */ pLibContext = (pphLibNfc_LibContext_t)pContext; pClientCb =pLibContext->CBInfo.pClientInitCb; pUpperLayerContext=pLibContext->CBInfo.pClientInitCntx; if(status == NFCSTATUS_SUCCESS) { /* Get the Lib context */ pLibContext=(pphLibNfc_LibContext_t)gpphLibContext; gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeOff; if(pLibContext->psHwReference->uicc_connected==TRUE) { /* populate state of the secured element */ gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault; sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState=phLibNfc_SE_Active; pLibContext->sSeContext.uUiccActivate=TRUE; } if(pLibContext->psHwReference->smx_connected==TRUE) { /* populate state of the secured element */ gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault; sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState=phLibNfc_SE_Inactive; pLibContext->sSeContext.uSmxActivate =FALSE; } phLibNfc_UpdateCurState(status,pLibContext); (void)phHal4Nfc_RegisterNotification( pLibContext->psHwReference, eRegisterDefault, phLibNfc_DefaultHandler, (void*)pLibContext ); /* call the upper layer register function */ (*pClientCb)(pUpperLayerContext,status); } else { /*Change the status code failed*/ status = NFCSTATUS_FAILED; /* Get the Lib context */ pLibContext=(pphLibNfc_LibContext_t)gpphLibContext; phLibNfc_UpdateCurState(status,pLibContext); /* Allocate the Memory for the Transceive info */ if(pLibContext->psHwReference!= NULL) { phOsalNfc_FreeMemory(pLibContext->psHwReference); pLibContext->psHwReference = NULL; } (*pClientCb)(pUpperLayerContext, status); phOsalNfc_FreeMemory(pLibContext); pLibContext= NULL; gpphLibContext = NULL; } return; }