2 * Copyright (C) 2010 NXP Semiconductors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Project: NFC FRI / HALDL
22 * $Date: Tue Jun 1 14:53:48 2010 $
25 * $Aliases: NFC_FRI1.1_WK1024_SDK $
31 ************************* Header Files ****************************************
34 #define LOG_TAG "NFC_PLUGIN_NXP"
37 #include <phDal4Nfc.h>
38 #include <phHal4Nfc.h>
39 #include <phOsalNfc.h>
40 #include <phLibNfc_Internal.h>
41 #include <phLibNfc_ndef_raw.h>
42 #include <phLibNfc_initiator.h>
43 #include <phLibNfc_discovery.h>
44 #include <phNfcStatus.h>
45 #include <cutils/log.h>
47 *************************** Macro's ******************************************
50 extern int dlopen_firmware();
52 #ifndef STATIC_DISABLE
60 *************************** Global Variables **********************************
64 pphLibNfc_LibContext_t gpphLibContext=NULL;
67 *************************** Static Function Declaration ***********************
71 STATIC void phLibNfc_InitCb(void *pContext,NFCSTATUS status);
73 /* Shutdown callback */
74 STATIC void phLibNfc_ShutdownCb(void *pContext,NFCSTATUS status);
76 /**Default notification handler registered with lower layer immediately after
77 successful initialization*/
78 STATIC void phLibNfc_DefaultHandler(
80 phHal_eNotificationType_t type,
81 phHal4Nfc_NotificationInfo_t info,
85 *************************** Function Definitions ******************************
88 NFCSTATUS phLibNfc_Mgt_ConfigureDriver (pphLibNfc_sConfig_t psConfig,
89 void ** ppDriverHandle)
91 if(NULL != gpphLibContext)
93 return NFCSTATUS_ALREADY_INITIALISED;
96 return phDal4Nfc_Config(psConfig, ppDriverHandle);
99 NFCSTATUS phLibNfc_Mgt_UnConfigureDriver (void * pDriverHandle)
101 if(NULL != gpphLibContext)
103 return NFCSTATUS_ALREADY_INITIALISED;
106 return phDal4Nfc_ConfigRelease(pDriverHandle);
109 NFCSTATUS phLibNfc_HW_Reset ()
111 NFCSTATUS Status = NFCSTATUS_SUCCESS;
113 Status = phDal4Nfc_Reset(1);
114 Status = phDal4Nfc_Reset(0);
115 Status = phDal4Nfc_Reset(1);
120 NFCSTATUS phLibNfc_Download_Mode ()
122 return phDal4Nfc_Download();
125 int phLibNfc_Load_Firmware_Image ()
128 status = dlopen_firmware();
133 extern uint8_t nxp_nfc_isoxchg_timeout;
134 NFCSTATUS phLibNfc_SetIsoXchgTimeout(uint8_t timeout) {
135 nxp_nfc_isoxchg_timeout = timeout;
136 return NFCSTATUS_SUCCESS;
139 int phLibNfc_GetIsoXchgTimeout() {
140 return nxp_nfc_isoxchg_timeout;
143 extern uint32_t nxp_nfc_hci_response_timeout;
144 NFCSTATUS phLibNfc_SetHciTimeout(uint32_t timeout_in_ms) {
145 nxp_nfc_hci_response_timeout = timeout_in_ms;
146 return NFCSTATUS_SUCCESS;
149 int phLibNfc_GetHciTimeout() {
150 return nxp_nfc_hci_response_timeout;
153 extern uint32_t nxp_nfc_felica_timeout;
154 NFCSTATUS phLibNfc_SetFelicaTimeout(uint8_t timeout_in_ms) {
155 nxp_nfc_felica_timeout = timeout_in_ms;
156 return NFCSTATUS_SUCCESS;
159 int phLibNfc_GetFelicaTimeout() {
160 return nxp_nfc_felica_timeout;
163 extern uint8_t nxp_nfc_mifareraw_timeout;
164 NFCSTATUS phLibNfc_SetMifareRawTimeout(uint8_t timeout) {
165 nxp_nfc_mifareraw_timeout = timeout;
166 return NFCSTATUS_SUCCESS;
169 int phLibNfc_GetMifareRawTimeout() {
170 return nxp_nfc_mifareraw_timeout;
174 * Initialize the phLibNfc interface.
177 NFCSTATUS phLibNfc_Mgt_Initialize(void *pDriverHandle,
178 pphLibNfc_RspCb_t pInitCb,
181 NFCSTATUS Status = NFCSTATUS_SUCCESS;
182 if((NULL == pDriverHandle)||(NULL == pInitCb))
184 Status = NFCSTATUS_INVALID_PARAMETER;
186 else if(NULL == gpphLibContext)
188 /* Initialize the Lib context */
189 gpphLibContext=(pphLibNfc_LibContext_t)phOsalNfc_GetMemory(
190 (uint32_t)sizeof(phLibNfc_LibContext_t));
191 if(NULL == gpphLibContext)
193 Status=NFCSTATUS_INSUFFICIENT_RESOURCES;
197 (void)memset((void *)gpphLibContext,0,(
198 (uint32_t)sizeof(phLibNfc_LibContext_t)));
200 /* Store the Callback and context in LibContext structure*/
201 gpphLibContext->CBInfo.pClientInitCb=pInitCb;
202 gpphLibContext->CBInfo.pClientInitCntx=pContext;
203 /* Initialize the HwReferece structure */
204 gpphLibContext->psHwReference=(phHal_sHwReference_t *)
205 phOsalNfc_GetMemory((uint32_t)sizeof(phHal_sHwReference_t));
206 (void)memset((void *)gpphLibContext->psHwReference,0,
207 ((uint32_t)sizeof(phHal_sHwReference_t)));
208 /* Allocate the Memory for the Transceive info */
209 if( gpphLibContext->psHwReference!=NULL)
211 gpphLibContext->psHwReference->p_board_driver = pDriverHandle;
212 Status = phLibNfc_UpdateNextState(gpphLibContext,
213 eLibNfcHalStateInitandIdle);
214 if(Status==NFCSTATUS_SUCCESS)
216 Status=phHal4Nfc_Open(
217 gpphLibContext->psHwReference,
220 (void *)gpphLibContext);
225 Status = NFCSTATUS_INSUFFICIENT_RESOURCES;
227 phLibNfc_Ndef_Init();
230 else if(gpphLibContext->LibNfcState.next_state==eLibNfcHalStateShutdown)
232 Status = NFCSTATUS_SHUTDOWN;
236 Status=NFCSTATUS_ALREADY_INITIALISED;
242 * This function called by the HAL4 when the initialization seq is completed.
244 STATIC void phLibNfc_InitCb(void *pContext,NFCSTATUS status)
246 pphLibNfc_LibContext_t pLibContext=NULL;
247 pphLibNfc_RspCb_t pClientCb=NULL;
248 void *pUpperLayerContext=NULL;
251 /* Initialize the local variable */
252 pLibContext = (pphLibNfc_LibContext_t)pContext;
254 pClientCb =pLibContext->CBInfo.pClientInitCb;
255 pUpperLayerContext=pLibContext->CBInfo.pClientInitCntx;
256 if(status == NFCSTATUS_SUCCESS)
258 /* Get the Lib context */
259 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
260 gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeOff;
261 if(pLibContext->psHwReference->uicc_connected==TRUE)
263 /* populate state of the secured element */
264 gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault;
265 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState=phLibNfc_SE_Active;
266 pLibContext->sSeContext.uUiccActivate=TRUE;
268 if(pLibContext->psHwReference->smx_connected==TRUE)
270 /* populate state of the secured element */
271 gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault;
272 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState=phLibNfc_SE_Inactive;
273 pLibContext->sSeContext.uSmxActivate =FALSE;
276 phLibNfc_UpdateCurState(status,pLibContext);
277 (void)phHal4Nfc_RegisterNotification(
278 pLibContext->psHwReference,
280 phLibNfc_DefaultHandler,
283 /* call the upper layer register function */
284 (*pClientCb)(pUpperLayerContext,status);
289 /*Change the status code failed*/
290 status = NFCSTATUS_FAILED;
291 /* Get the Lib context */
292 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
294 phLibNfc_UpdateCurState(status,pLibContext);
298 /* Allocate the Memory for the Transceive info */
299 if(pLibContext->psHwReference!= NULL)
301 phOsalNfc_FreeMemory(pLibContext->psHwReference);
302 pLibContext->psHwReference = NULL;
304 (*pClientCb)(pUpperLayerContext, status);
306 phOsalNfc_FreeMemory(pLibContext);
308 gpphLibContext = NULL;
314 /**Default notification handler registered with lower layer immediately after
315 successful initialization*/
316 STATIC void phLibNfc_DefaultHandler(
318 phHal_eNotificationType_t type,
319 phHal4Nfc_NotificationInfo_t info,
323 if(context != (void *)gpphLibContext)
325 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
330 if((NFC_EVENT_NOTIFICATION == type) &&
331 (NFCSTATUS_BOARD_COMMUNICATION_ERROR == status))
333 phLibNfc_UpdateCurState(NFCSTATUS_FAILED,gpphLibContext);
334 phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1);
340 * De-Initialize the LIB NFC.
342 NFCSTATUS phLibNfc_Mgt_DeInitialize(void * pDriverHandle,
343 pphLibNfc_RspCb_t pDeInitCb,
347 NFCSTATUS Status = NFCSTATUS_SUCCESS;
348 pphLibNfc_LibContext_t pLibContext = gpphLibContext;
349 if(NULL==pDriverHandle)
351 /*Check for valid parameters */
352 Status = NFCSTATUS_INVALID_PARAMETER;
354 else if((pLibContext==NULL)
355 || (pLibContext->LibNfcState.cur_state
356 == eLibNfcHalStateShutdown))
357 { /*Lib Nfc not initlized*/
358 Status = NFCSTATUS_NOT_INITIALISED;
364 phHal4Nfc_Hal4Reset(pLibContext->psHwReference,(void *)pLibContext);
365 if(pLibContext->psHwReference!=NULL)
367 phOsalNfc_FreeMemory(pLibContext->psHwReference);
368 pLibContext->psHwReference = NULL;
370 /*Free the memory allocated during NDEF read,write
371 and NDEF formatting*/
372 phLibNfc_Ndef_DeInit();
373 phOsalNfc_FreeMemory(pLibContext);
379 if (NULL!= pLibContext->CBInfo.pClientShutdownCb)
381 /* Previous callback pending */
382 Status = NFCSTATUS_BUSY;
384 Status = NFCSTATUS_PENDING;
385 if(TRUE != pLibContext->status.GenCb_pending_status)
387 Status = phHal4Nfc_Close(pLibContext->psHwReference,
389 (void *)pLibContext);
391 if(Status== NFCSTATUS_PENDING)
393 pLibContext->CBInfo.pClientShutdownCb = pDeInitCb;
394 pLibContext->CBInfo.pClientShtdwnCntx = pContext;
395 pLibContext->status.GenCb_pending_status=TRUE;
396 pLibContext->LibNfcState.next_state= eLibNfcHalStateShutdown;
400 Status =NFCSTATUS_FAILED;
406 /* shutdown callback -
407 Free the allocated memory here */
408 STATIC void phLibNfc_ShutdownCb(void *pContext,NFCSTATUS status)
410 pphLibNfc_RspCb_t pClientCb=NULL;
411 void *pUpperLayerContext=NULL;
412 pphLibNfc_LibContext_t pLibContext=NULL;
414 PHNFC_UNUSED_VARIABLE(pContext);
415 /* Get the Lib context */
416 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
418 if(pLibContext == NULL)
420 status = NFCSTATUS_FAILED;
424 /* Initialize the local variable */
425 pClientCb =pLibContext->CBInfo.pClientShutdownCb;
426 pUpperLayerContext=pLibContext->CBInfo.pClientShtdwnCntx;
427 if(status == NFCSTATUS_SUCCESS)
429 pLibContext->LibNfcState.cur_state = eLibNfcHalStateShutdown;
430 phLibNfc_UpdateCurState(status,pLibContext);
432 pLibContext->status.GenCb_pending_status=FALSE;
434 /* Allocate the Memory for the Transceive info */
437 (*pClientCb)(pUpperLayerContext, status);
439 if(pLibContext->psHwReference!=NULL)
441 phOsalNfc_FreeMemory(pLibContext->psHwReference);
442 pLibContext->psHwReference = NULL;
444 if(NULL != gpphLibContext->psBufferedAuth)
446 if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
448 phOsalNfc_FreeMemory(
449 gpphLibContext->psBufferedAuth->sRecvData.buffer);
451 if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
453 phOsalNfc_FreeMemory(
454 gpphLibContext->psBufferedAuth->sSendData.buffer);
456 phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
457 gpphLibContext->psBufferedAuth = NULL;
459 /*Free the memory allocated during NDEF read,write
460 and NDEF formatting*/
461 phLibNfc_Ndef_DeInit();
462 phOsalNfc_FreeMemory(pLibContext);
469 /* shutdown sequence failed by HAL 4 */
470 status= NFCSTATUS_FAILED;
471 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
472 phLibNfc_UpdateCurState(status,pLibContext);
473 pLibContext->status.GenCb_pending_status=FALSE;
476 (*pClientCb)(pUpperLayerContext,status);
482 * Pending shutdown call.
486 void phLibNfc_Pending_Shutdown(void)
488 NFCSTATUS RetStatus = NFCSTATUS_SUCCESS ;
489 gpphLibContext->status.GenCb_pending_status = FALSE;
490 RetStatus = phHal4Nfc_Close(
491 gpphLibContext->psHwReference,
493 (void *)gpphLibContext);
494 PHNFC_UNUSED_VARIABLE(RetStatus);
502 NFCSTATUS phLibNfc_Mgt_Reset(void *pContext)
504 NFCSTATUS Status = NFCSTATUS_SUCCESS;
505 phLibNfc_LibContext_t *pLibNfc_Ctxt = (phLibNfc_LibContext_t *)pContext;
507 if((pLibNfc_Ctxt == NULL)
508 || (gpphLibContext->LibNfcState.cur_state
509 == eLibNfcHalStateShutdown))
510 { /*Lib Nfc not initlized*/
511 Status = NFCSTATUS_NOT_INITIALISED;
513 else if(NULL == pContext)
515 Status = NFCSTATUS_INVALID_PARAMETER;
517 /* Check for valid state,If De initialize is called then
518 return NFCSTATUS_SHUTDOWN */
519 else if(gpphLibContext->LibNfcState.next_state
520 == eLibNfcHalStateShutdown)
522 Status = NFCSTATUS_SHUTDOWN;
526 /*Reset all callback status*/
527 (void) memset(&(gpphLibContext->RegNtfType),0,
528 sizeof(phLibNfc_Registry_Info_t));
529 (void) memset(&(gpphLibContext->sADDconfig),0,
530 sizeof(phLibNfc_sADD_Cfg_t));
531 (void) memset(&(gpphLibContext->ndef_cntx),0,
532 sizeof(phLibNfc_NdefInfo_t));
533 (void) memset(&(gpphLibContext->sNfcIp_Context),0,
534 sizeof(phLibNfc_NfcIpInfo_t));
535 (void) memset(&(gpphLibContext->sCardEmulCfg),0,
536 sizeof(phHal_sEmulationCfg_t));
537 (void) memset(&(gpphLibContext->Discov_handle),0,
540 /*Free memory allocated for NDEF records*/
541 if(NULL != gpphLibContext->psBufferedAuth)
543 if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
545 phOsalNfc_FreeMemory(
546 gpphLibContext->psBufferedAuth->sRecvData.buffer);
547 gpphLibContext->psBufferedAuth->sRecvData.buffer = NULL;
549 if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
551 phOsalNfc_FreeMemory(
552 gpphLibContext->psBufferedAuth->sSendData.buffer);
553 gpphLibContext->psBufferedAuth->sSendData.buffer = NULL;
555 phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
556 gpphLibContext->psBufferedAuth = NULL;
558 if(NULL != gpphLibContext->psTransInfo)
560 phOsalNfc_FreeMemory(gpphLibContext->psTransInfo);
561 gpphLibContext->psTransInfo = NULL;
563 if(NULL != gpphLibContext->ndef_cntx.psNdefMap)
565 if(NULL != gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf)
567 phOsalNfc_FreeMemory(gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf);
568 gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf = NULL;
570 phOsalNfc_FreeMemory(gpphLibContext->ndef_cntx.psNdefMap);
571 gpphLibContext->ndef_cntx.psNdefMap = NULL;
573 if(NULL != gpphLibContext->psOverHalCtxt)
575 phOsalNfc_FreeMemory(gpphLibContext->psOverHalCtxt);
576 gpphLibContext->psTransInfo = NULL;
578 if(NULL != gpphLibContext->psDevInputParam)
580 phOsalNfc_FreeMemory(gpphLibContext->psDevInputParam);
581 gpphLibContext->psDevInputParam = NULL;
583 if(NULL != gpphLibContext->ndef_cntx.ndef_fmt)
585 phOsalNfc_FreeMemory(gpphLibContext->ndef_cntx.ndef_fmt);
586 gpphLibContext->ndef_cntx.ndef_fmt = NULL;
588 if(NULL != pNdefRecord)
590 if(NULL != pNdefRecord->Id)
592 phOsalNfc_FreeMemory(pNdefRecord->Id);
593 pNdefRecord->Id = NULL;
595 if(NULL != pNdefRecord->Type)
597 phOsalNfc_FreeMemory(pNdefRecord->Type);
598 pNdefRecord->Type = NULL;
600 if(NULL != pNdefRecord->PayloadData)
602 phOsalNfc_FreeMemory(pNdefRecord->PayloadData);
603 pNdefRecord->PayloadData = NULL;
606 if(NULL != NdefInfo.pNdefRecord)
608 phOsalNfc_FreeMemory(NdefInfo.pNdefRecord);
609 NdefInfo.pNdefRecord = NULL;
611 if(NULL != gpphLibContext->phLib_NdefRecCntx.NdefCb)
613 phOsalNfc_FreeMemory(gpphLibContext->phLib_NdefRecCntx.NdefCb);
614 gpphLibContext->phLib_NdefRecCntx.NdefCb = NULL;
616 if(NULL != gpphLibContext->phLib_NdefRecCntx.ndef_message.buffer)
618 phOsalNfc_FreeMemory(gpphLibContext->phLib_NdefRecCntx.ndef_message.buffer);
619 gpphLibContext->phLib_NdefRecCntx.ndef_message.buffer = NULL;
621 /* No device is connected */
622 gpphLibContext->Connected_handle = 0x00;
623 gpphLibContext->Prev_Connected_handle = 0x00;
624 gpphLibContext->ReleaseType = NFC_INVALID_RELEASE_TYPE;
625 gpphLibContext->eLibNfcCfgMode = NFC_DISCOVERY_STOP;
626 /*Lib Nfc Stack is initilized and in idle state*/
627 gpphLibContext->LibNfcState.cur_state = eLibNfcHalStateInitandIdle;
629 /* Reset all callback status */
630 gpphLibContext->CBInfo.pClientCkNdefCb = NULL;
631 gpphLibContext->CBInfo.pClientCkNdefCntx = NULL;
632 gpphLibContext->CBInfo.pClientConCntx = NULL;
633 gpphLibContext->CBInfo.pClientConnectCb = NULL;
634 gpphLibContext->CBInfo.pClientDConCntx = NULL;
635 gpphLibContext->CBInfo.pClientDisCfgCntx = NULL;
636 gpphLibContext->CBInfo.pClientDisConfigCb = NULL;
637 gpphLibContext->CBInfo.pClientInitCb = NULL;
638 gpphLibContext->CBInfo.pClientInitCntx = gpphLibContext;
639 gpphLibContext->CBInfo.pClientNdefNtfRespCb = NULL;
640 gpphLibContext->CBInfo.pClientNdefNtfRespCntx = NULL;
641 gpphLibContext->CBInfo.pClientNtfRegRespCB = NULL;
642 gpphLibContext->CBInfo.pClientNtfRegRespCntx = NULL;
643 gpphLibContext->CBInfo.pClientPresChkCb = NULL;
644 gpphLibContext->CBInfo.pClientPresChkCntx = NULL;
645 gpphLibContext->CBInfo.pClientRdNdefCb = NULL;
646 gpphLibContext->CBInfo.pClientRdNdefCntx = NULL;
647 gpphLibContext->CBInfo.pClientShtdwnCntx = NULL;
648 gpphLibContext->CBInfo.pClientShutdownCb = NULL;
649 gpphLibContext->CBInfo.pClientTransceiveCb = NULL;
650 gpphLibContext->CBInfo.pClientTranseCntx = NULL;
651 gpphLibContext->CBInfo.pClientWrNdefCb = NULL;
652 gpphLibContext->CBInfo.pClientWrNdefCntx = NULL;
653 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb = NULL;
654 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx = NULL;
655 gpphLibContext->sNfcIp_Context.pClientNfcIpRxCb = NULL;
656 gpphLibContext->sNfcIp_Context.pClientNfcIpRxCntx = NULL;
657 gpphLibContext->sNfcIp_Context.pClientNfcIpTxCb = NULL;
658 gpphLibContext->sNfcIp_Context.pClientNfcIpTxCntx = NULL;
659 gpphLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb = NULL;
660 gpphLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt = NULL;
661 gpphLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = NULL;
662 gpphLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt = NULL;
663 /*No callback is pending*/
664 gpphLibContext->status.GenCb_pending_status = FALSE;
670 * LibNfc state machine next state update.
674 phLibNfc_UpdateNextState(
675 pphLibNfc_LibContext_t pLibContext,
676 phLibNfc_State_t next_state
679 NFCSTATUS status = NFCSTATUS_INVALID_STATE;
680 switch(pLibContext->LibNfcState.cur_state)
682 case eLibNfcHalStateShutdown:
686 case eLibNfcHalStateShutdown:
687 case eLibNfcHalStateInitandIdle:
688 status = NFCSTATUS_SUCCESS;
695 case eLibNfcHalStateConfigReady:
699 case eLibNfcHalStateShutdown:
700 case eLibNfcHalStateConfigReady:
701 case eLibNfcHalStateInitandIdle:
702 case eLibNfcHalStateConnect:
703 status = NFCSTATUS_SUCCESS;
710 case eLibNfcHalStateConnect:
714 case eLibNfcHalStateShutdown:
715 case eLibNfcHalStateRelease:
716 case eLibNfcHalStateTransaction:
717 case eLibNfcHalStatePresenceChk:
718 status = NFCSTATUS_SUCCESS;
725 case eLibNfcHalStatePresenceChk:
729 case eLibNfcHalStateShutdown:
730 case eLibNfcHalStateConfigReady:
731 case eLibNfcHalStateRelease:
732 case eLibNfcHalStateTransaction:
733 case eLibNfcHalStatePresenceChk:
734 status = NFCSTATUS_SUCCESS;
741 case eLibNfcHalStateInitandIdle:
745 case eLibNfcHalStateShutdown:
746 case eLibNfcHalStateConfigReady:
747 status = NFCSTATUS_SUCCESS;
757 pLibContext->LibNfcState.next_state =
758 (uint8_t)((NFCSTATUS_SUCCESS == status)?next_state:pLibContext->LibNfcState.next_state);
764 * LibNfc state machine current state update.
768 phLibNfc_UpdateCurState(
770 pphLibNfc_LibContext_t psLibContext
773 switch(psLibContext->LibNfcState.next_state)
775 case eLibNfcHalStateTransaction:
776 psLibContext->LibNfcState.cur_state = (uint8_t)eLibNfcHalStateConnect;
778 case eLibNfcHalStateRelease:
779 psLibContext->LibNfcState.cur_state
780 = (uint8_t)(psLibContext->status.DiscEnbl_status == TRUE?
781 eLibNfcHalStateInitandIdle:eLibNfcHalStateConfigReady);
783 case eLibNfcHalStateInvalid:
786 psLibContext->LibNfcState.cur_state
787 = (uint8_t)((NFCSTATUS_SUCCESS == status)?
788 psLibContext->LibNfcState.next_state:
789 psLibContext->LibNfcState.cur_state);
791 psLibContext->LibNfcState.next_state = (uint8_t)eLibNfcHalStateInvalid;
794 /* Interface to stack capabilities */
796 NFCSTATUS phLibNfc_Mgt_GetstackCapabilities(
797 phLibNfc_StackCapabilities_t *phLibNfc_StackCapabilities,
800 NFCSTATUS RetVal = NFCSTATUS_FAILED;
801 /*Check Lib Nfc stack is initilized*/
802 if((NULL == gpphLibContext)||
803 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
805 RetVal = NFCSTATUS_NOT_INITIALISED;
807 /*Check application has sent the valid parameters*/
808 else if((NULL == phLibNfc_StackCapabilities)
809 || (NULL == pContext))
811 RetVal= NFCSTATUS_INVALID_PARAMETER;
813 else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
815 RetVal = NFCSTATUS_SHUTDOWN;
817 else if(TRUE == gpphLibContext->status.GenCb_pending_status)
819 /*Previous operation is pending */
820 RetVal = NFCSTATUS_BUSY;
824 /* Tag Format Capabilities*/
825 phLibNfc_StackCapabilities->psFormatCapabilities.Desfire = TRUE;
826 phLibNfc_StackCapabilities->psFormatCapabilities.MifareStd = TRUE;
827 phLibNfc_StackCapabilities->psFormatCapabilities.MifareUL = TRUE;
828 phLibNfc_StackCapabilities->psFormatCapabilities.FeliCa = FALSE;
829 phLibNfc_StackCapabilities->psFormatCapabilities.Jewel = FALSE;
830 phLibNfc_StackCapabilities->psFormatCapabilities.ISO14443_4A = FALSE;
831 phLibNfc_StackCapabilities->psFormatCapabilities.ISO14443_4B = FALSE;
832 phLibNfc_StackCapabilities->psFormatCapabilities.MifareULC = TRUE;
833 phLibNfc_StackCapabilities->psFormatCapabilities.ISO15693 = FALSE;
835 /* Tag Mapping Capabilities */
836 phLibNfc_StackCapabilities->psMappingCapabilities.FeliCa = TRUE;
837 phLibNfc_StackCapabilities->psMappingCapabilities.Desfire = TRUE;
838 phLibNfc_StackCapabilities->psMappingCapabilities.ISO14443_4A = TRUE;
839 phLibNfc_StackCapabilities->psMappingCapabilities.ISO14443_4B = TRUE;
840 phLibNfc_StackCapabilities->psMappingCapabilities.MifareStd = TRUE;
841 phLibNfc_StackCapabilities->psMappingCapabilities.MifareUL = TRUE;
842 phLibNfc_StackCapabilities->psMappingCapabilities.MifareULC = TRUE;
843 phLibNfc_StackCapabilities->psMappingCapabilities.Jewel = TRUE;
844 phLibNfc_StackCapabilities->psMappingCapabilities.ISO15693 = FALSE;
846 /*Call Hal4 Get Dev Capabilities to get info about protocols supported
848 PHDBG_INFO("LibNfc:Get Stack capabilities ");
849 RetVal= phHal4Nfc_GetDeviceCapabilities(
850 gpphLibContext->psHwReference,
851 &(phLibNfc_StackCapabilities->psDevCapabilities),
852 (void *)gpphLibContext);
854 LIB_NFC_VERSION_SET(phLibNfc_StackCapabilities->psDevCapabilities.hal_version,
860 phLibNfc_StackCapabilities->psDevCapabilities.fw_version=
861 gpphLibContext->psHwReference->device_info.fw_version;
862 phLibNfc_StackCapabilities->psDevCapabilities.hci_version=
863 gpphLibContext->psHwReference->device_info.hci_version;
864 phLibNfc_StackCapabilities->psDevCapabilities.hw_version=
865 gpphLibContext->psHwReference->device_info.hw_version;
866 phLibNfc_StackCapabilities->psDevCapabilities.model_id=
867 gpphLibContext->psHwReference->device_info.model_id;
868 (void)memcpy(phLibNfc_StackCapabilities->psDevCapabilities.full_version,
869 gpphLibContext->psHwReference->device_info.full_version,NXP_FULL_VERSION_LEN);
870 /* Check the firmware version */
871 if (nxp_nfc_full_version == NULL) {
872 // Couldn't load firmware, just pretend we're up to date.
873 LOGW("Firmware image not available: this device might be running old NFC firmware!");
874 phLibNfc_StackCapabilities->psDevCapabilities.firmware_update_info = 0;
876 phLibNfc_StackCapabilities->psDevCapabilities.firmware_update_info = memcmp(phLibNfc_StackCapabilities->psDevCapabilities.full_version, nxp_nfc_full_version,
877 NXP_FULL_VERSION_LEN);
880 if(NFCSTATUS_SUCCESS != RetVal)
882 RetVal = NFCSTATUS_FAILED;
893 NFCSTATUS phLibNfc_Mgt_ConfigureTestMode(void *pDriverHandle,
894 pphLibNfc_RspCb_t pTestModeCb,
895 phLibNfc_Cfg_Testmode_t eTstmode,
898 NFCSTATUS Status = NFCSTATUS_SUCCESS;
899 phHal4Nfc_InitType_t eInitType=eInitDefault;
901 if((NULL == pDriverHandle)||(NULL == pTestModeCb))
903 Status = NFCSTATUS_INVALID_PARAMETER;
905 else if((NULL != gpphLibContext) && \
906 (gpphLibContext->LibNfcState.next_state==eLibNfcHalStateShutdown))
908 Status = NFCSTATUS_SHUTDOWN;
910 else if( (eTstmode == phLibNfc_TstMode_On) && (NULL != gpphLibContext))
912 Status=NFCSTATUS_ALREADY_INITIALISED;
914 else if( (eTstmode == phLibNfc_TstMode_Off) && (NULL == gpphLibContext))
916 Status = NFCSTATUS_NOT_INITIALISED;
918 else if( (eTstmode == phLibNfc_TstMode_Off) && (NULL != gpphLibContext))
920 if (NULL!= gpphLibContext->CBInfo.pClientShutdownCb)
921 { /* Previous callback pending */
922 Status = NFCSTATUS_BUSY;
926 Status = NFCSTATUS_PENDING;
927 if(TRUE != gpphLibContext->status.GenCb_pending_status)
929 Status = phHal4Nfc_Close(gpphLibContext->psHwReference,
931 (void *)gpphLibContext);
933 if(Status== NFCSTATUS_PENDING)
935 gpphLibContext->CBInfo.pClientShutdownCb = pTestModeCb;
936 gpphLibContext->CBInfo.pClientShtdwnCntx = pContext;
937 gpphLibContext->status.GenCb_pending_status=TRUE;
938 gpphLibContext->LibNfcState.next_state= eLibNfcHalStateShutdown;
942 Status =NFCSTATUS_FAILED;
948 /* Initialize the Lib context */
949 gpphLibContext=(pphLibNfc_LibContext_t)phOsalNfc_GetMemory(
950 (uint32_t)sizeof(phLibNfc_LibContext_t));
951 if(NULL == gpphLibContext)
953 Status=NFCSTATUS_INSUFFICIENT_RESOURCES;
957 (void)memset((void *)gpphLibContext,0,(
958 (uint32_t)sizeof(phLibNfc_LibContext_t)));
960 /* Store the Callback and context in LibContext structure*/
961 gpphLibContext->CBInfo.pClientInitCb=pTestModeCb;
962 gpphLibContext->CBInfo.pClientInitCntx=pContext;
963 /* Initialize the HwReferece structure */
964 gpphLibContext->psHwReference=(phHal_sHwReference_t *)
965 phOsalNfc_GetMemory((uint32_t)sizeof(phHal_sHwReference_t));
966 (void)memset((void *)gpphLibContext->psHwReference,0,
967 ((uint32_t)sizeof(phHal_sHwReference_t)));
968 /* Allocate the Memory for the Transceive info */
969 if( gpphLibContext->psHwReference!=NULL)
971 gpphLibContext->psHwReference->p_board_driver = pDriverHandle;
972 Status = phLibNfc_UpdateNextState(gpphLibContext,
973 eLibNfcHalStateInitandIdle);
974 if(Status==NFCSTATUS_SUCCESS)
976 if(eTstmode == phLibNfc_TstMode_On)
977 eInitType = eInitTestModeOn;
978 if(eTstmode == phLibNfc_TstMode_Off)
979 eInitType = eInitDefault;
980 Status=phHal4Nfc_Open(
981 gpphLibContext->psHwReference,
984 (void *)gpphLibContext);
989 Status = NFCSTATUS_INSUFFICIENT_RESOURCES;
991 phLibNfc_Ndef_Init();