2 * Copyright (C) 2010 NXP Semiconductors
3 * Copyright (C) 2012 Samsung Elevtronics Co., Ltd
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
21 * Project: NFC FRI / HALDL
\r
23 * $Date: Tue Jun 1 14:53:48 2010 $
\r
24 * $Author: ing07385 $
\r
26 * $Aliases: NFC_FRI1.1_WK1024_SDK $
\r
32 ************************* Header Files ****************************************
\r
35 #define LOG_TAG "NFC"
\r
37 #include <phLibNfc.h>
\r
38 #include <phDal4Nfc.h>
\r
39 #include <phHal4Nfc.h>
\r
40 #include <phOsalNfc.h>
\r
41 #include <phLibNfc_Internal.h>
\r
42 #include <phLibNfc_ndef_raw.h>
\r
43 #include <phLibNfc_initiator.h>
\r
44 #include <phLibNfc_discovery.h>
\r
45 #include <phNfcStatus.h>
\r
46 //#include <cutils/log.h>
\r
48 *************************** Macro's ******************************************
\r
51 extern int dlopen_firmware();
\r
53 #ifndef STATIC_DISABLE
\r
54 #define STATIC static
\r
61 *************************** Global Variables **********************************
\r
65 pphLibNfc_LibContext_t gpphLibContext=NULL;
\r
68 *************************** Static Function Declaration ***********************
\r
72 STATIC void phLibNfc_InitCb(void *pContext,NFCSTATUS status);
\r
74 /* Shutdown callback */
\r
75 STATIC void phLibNfc_ShutdownCb(void *pContext,NFCSTATUS status);
\r
77 /**Default notification handler registered with lower layer immediately after
\r
78 successful initialization*/
\r
79 STATIC void phLibNfc_DefaultHandler(
\r
81 phHal_eNotificationType_t type,
\r
82 phHal4Nfc_NotificationInfo_t info,
\r
86 *************************** Function Definitions ******************************
\r
89 NFCSTATUS phLibNfc_Mgt_ConfigureDriver (pphLibNfc_sConfig_t psConfig,
\r
90 void ** ppDriverHandle)
\r
92 if(NULL != gpphLibContext)
\r
94 return NFCSTATUS_ALREADY_INITIALISED;
\r
97 return phDal4Nfc_Config(psConfig, ppDriverHandle);
\r
100 NFCSTATUS phLibNfc_Mgt_UnConfigureDriver (void * pDriverHandle)
\r
102 if(NULL != gpphLibContext)
\r
104 return NFCSTATUS_ALREADY_INITIALISED;
\r
107 return phDal4Nfc_ConfigRelease(pDriverHandle);
\r
110 NFCSTATUS phLibNfc_HW_Reset ()
\r
112 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
114 Status = phDal4Nfc_Reset(1);
\r
115 Status = phDal4Nfc_Reset(0);
\r
116 Status = phDal4Nfc_Reset(1);
\r
121 NFCSTATUS phLibNfc_Download_Mode ()
\r
123 return phDal4Nfc_Download();
\r
126 int phLibNfc_Load_Firmware_Image ()
\r
129 status = dlopen_firmware();
\r
134 extern uint8_t nxp_nfc_isoxchg_timeout;
\r
135 NFCSTATUS phLibNfc_SetIsoXchgTimeout(uint8_t timeout) {
\r
136 nxp_nfc_isoxchg_timeout = timeout;
\r
137 return NFCSTATUS_SUCCESS;
\r
140 int phLibNfc_GetIsoXchgTimeout() {
\r
141 return nxp_nfc_isoxchg_timeout;
\r
144 extern uint32_t nxp_nfc_hci_response_timeout;
\r
145 NFCSTATUS phLibNfc_SetHciTimeout(uint32_t timeout_in_ms) {
\r
146 nxp_nfc_hci_response_timeout = timeout_in_ms;
\r
147 return NFCSTATUS_SUCCESS;
\r
150 int phLibNfc_GetHciTimeout() {
\r
151 return nxp_nfc_hci_response_timeout;
\r
154 extern uint32_t nxp_nfc_felica_timeout;
\r
155 NFCSTATUS phLibNfc_SetFelicaTimeout(uint8_t timeout_in_ms) {
\r
156 nxp_nfc_felica_timeout = timeout_in_ms;
\r
157 return NFCSTATUS_SUCCESS;
\r
160 int phLibNfc_GetFelicaTimeout() {
\r
161 return nxp_nfc_felica_timeout;
\r
164 extern uint8_t nxp_nfc_mifareraw_timeout;
\r
165 NFCSTATUS phLibNfc_SetMifareRawTimeout(uint8_t timeout) {
\r
166 nxp_nfc_mifareraw_timeout = timeout;
\r
167 return NFCSTATUS_SUCCESS;
\r
170 int phLibNfc_GetMifareRawTimeout() {
\r
171 return nxp_nfc_mifareraw_timeout;
\r
175 * Initialize the phLibNfc interface.
\r
178 NFCSTATUS phLibNfc_Mgt_Initialize(void *pDriverHandle,
\r
179 pphLibNfc_RspCb_t pInitCb,
\r
182 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
183 if((NULL == pDriverHandle)||(NULL == pInitCb))
\r
185 Status = NFCSTATUS_INVALID_PARAMETER;
\r
187 else if(NULL == gpphLibContext)
\r
189 /* Initialize the Lib context */
\r
190 gpphLibContext=(pphLibNfc_LibContext_t)phOsalNfc_GetMemory(
\r
191 (uint32_t)sizeof(phLibNfc_LibContext_t));
\r
192 if(NULL == gpphLibContext)
\r
194 Status=NFCSTATUS_INSUFFICIENT_RESOURCES;
\r
198 (void)memset((void *)gpphLibContext,0,(
\r
199 (uint32_t)sizeof(phLibNfc_LibContext_t)));
\r
201 /* Store the Callback and context in LibContext structure*/
\r
202 gpphLibContext->CBInfo.pClientInitCb=pInitCb;
\r
203 gpphLibContext->CBInfo.pClientInitCntx=pContext;
\r
204 /* Initialize the HwReferece structure */
\r
205 gpphLibContext->psHwReference=(phHal_sHwReference_t *)
\r
206 phOsalNfc_GetMemory((uint32_t)sizeof(phHal_sHwReference_t));
\r
207 (void)memset((void *)gpphLibContext->psHwReference,0,
\r
208 ((uint32_t)sizeof(phHal_sHwReference_t)));
\r
209 /* Allocate the Memory for the Transceive info */
\r
210 if( gpphLibContext->psHwReference!=NULL)
\r
212 gpphLibContext->psHwReference->p_board_driver = pDriverHandle;
\r
213 Status = phLibNfc_UpdateNextState(gpphLibContext,
\r
214 eLibNfcHalStateInitandIdle);
\r
215 if(Status==NFCSTATUS_SUCCESS)
\r
217 Status=phHal4Nfc_Open(
\r
218 gpphLibContext->psHwReference,
\r
221 (void *)gpphLibContext);
\r
226 Status = NFCSTATUS_INSUFFICIENT_RESOURCES;
\r
228 phLibNfc_Ndef_Init();
\r
231 else if(gpphLibContext->LibNfcState.next_state==eLibNfcHalStateShutdown)
\r
233 Status = NFCSTATUS_SHUTDOWN;
\r
237 Status=NFCSTATUS_ALREADY_INITIALISED;
\r
243 * This function called by the HAL4 when the initialization seq is completed.
\r
245 STATIC void phLibNfc_InitCb(void *pContext,NFCSTATUS status)
\r
247 pphLibNfc_LibContext_t pLibContext=NULL;
\r
248 pphLibNfc_RspCb_t pClientCb=NULL;
\r
249 void *pUpperLayerContext=NULL;
\r
252 /* Initialize the local variable */
\r
253 pLibContext = (pphLibNfc_LibContext_t)pContext;
\r
255 pClientCb =pLibContext->CBInfo.pClientInitCb;
\r
256 pUpperLayerContext=pLibContext->CBInfo.pClientInitCntx;
\r
257 if(status == NFCSTATUS_SUCCESS)
\r
259 /* Get the Lib context */
\r
260 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
\r
261 gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeOff;
\r
262 if(pLibContext->psHwReference->uicc_connected==TRUE)
\r
264 /* populate state of the secured element */
\r
265 gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault;
\r
266 sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState=phLibNfc_SE_Active;
\r
267 pLibContext->sSeContext.uUiccActivate=TRUE;
\r
269 if(pLibContext->psHwReference->smx_connected==TRUE)
\r
271 /* populate state of the secured element */
\r
272 gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault;
\r
273 sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState=phLibNfc_SE_Inactive;
\r
274 pLibContext->sSeContext.uSmxActivate =FALSE;
\r
277 phLibNfc_UpdateCurState(status,pLibContext);
\r
278 (void)phHal4Nfc_RegisterNotification(
\r
279 pLibContext->psHwReference,
\r
281 phLibNfc_DefaultHandler,
\r
284 /* call the upper layer register function */
\r
285 (*pClientCb)(pUpperLayerContext,status);
\r
290 /*Change the status code failed*/
\r
291 status = NFCSTATUS_FAILED;
\r
292 /* Get the Lib context */
\r
293 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
\r
295 phLibNfc_UpdateCurState(status,pLibContext);
\r
299 /* Allocate the Memory for the Transceive info */
\r
300 if(pLibContext->psHwReference!= NULL)
\r
302 phOsalNfc_FreeMemory(pLibContext->psHwReference);
\r
303 pLibContext->psHwReference = NULL;
\r
305 (*pClientCb)(pUpperLayerContext, status);
\r
307 phOsalNfc_FreeMemory(pLibContext);
\r
309 gpphLibContext = NULL;
\r
315 /**Default notification handler registered with lower layer immediately after
\r
316 successful initialization*/
\r
317 STATIC void phLibNfc_DefaultHandler(
\r
319 phHal_eNotificationType_t type,
\r
320 phHal4Nfc_NotificationInfo_t info,
\r
324 if(context != (void *)gpphLibContext)
\r
326 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
331 if((NFC_EVENT_NOTIFICATION == type) &&
\r
332 (NFCSTATUS_BOARD_COMMUNICATION_ERROR == status))
\r
334 phLibNfc_UpdateCurState(NFCSTATUS_FAILED,gpphLibContext);
\r
335 phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1);
\r
341 * De-Initialize the LIB NFC.
\r
343 NFCSTATUS phLibNfc_Mgt_DeInitialize(void * pDriverHandle,
\r
344 pphLibNfc_RspCb_t pDeInitCb,
\r
348 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
349 pphLibNfc_LibContext_t pLibContext = gpphLibContext;
\r
350 if(NULL==pDriverHandle)
\r
352 /*Check for valid parameters */
\r
353 Status = NFCSTATUS_INVALID_PARAMETER;
\r
355 else if((pLibContext==NULL)
\r
356 || (pLibContext->LibNfcState.cur_state
\r
357 == eLibNfcHalStateShutdown))
\r
358 { /*Lib Nfc not initlized*/
\r
359 Status = NFCSTATUS_NOT_INITIALISED;
\r
363 if(pDeInitCb==NULL)
\r
365 phHal4Nfc_Hal4Reset(pLibContext->psHwReference,(void *)pLibContext);
\r
366 if(pLibContext->psHwReference!=NULL)
\r
368 phOsalNfc_FreeMemory(pLibContext->psHwReference);
\r
369 pLibContext->psHwReference = NULL;
\r
371 /*Free the memory allocated during NDEF read,write
\r
372 and NDEF formatting*/
\r
373 phLibNfc_Ndef_DeInit();
\r
374 phOsalNfc_FreeMemory(pLibContext);
\r
375 gpphLibContext=NULL;
\r
380 if (NULL!= pLibContext->CBInfo.pClientShutdownCb)
\r
382 /* Previous callback pending */
\r
383 Status = NFCSTATUS_BUSY;
\r
385 Status = NFCSTATUS_PENDING;
\r
386 if(TRUE != pLibContext->status.GenCb_pending_status)
\r
388 Status = phHal4Nfc_Close(pLibContext->psHwReference,
\r
389 phLibNfc_ShutdownCb,
\r
390 (void *)pLibContext);
\r
392 if(Status== NFCSTATUS_PENDING)
\r
394 pLibContext->CBInfo.pClientShutdownCb = pDeInitCb;
\r
395 pLibContext->CBInfo.pClientShtdwnCntx = pContext;
\r
396 pLibContext->status.GenCb_pending_status=TRUE;
\r
397 pLibContext->LibNfcState.next_state= eLibNfcHalStateShutdown;
\r
401 Status =NFCSTATUS_FAILED;
\r
407 /* shutdown callback -
\r
408 Free the allocated memory here */
\r
409 STATIC void phLibNfc_ShutdownCb(void *pContext,NFCSTATUS status)
\r
411 pphLibNfc_RspCb_t pClientCb=NULL;
\r
412 void *pUpperLayerContext=NULL;
\r
413 pphLibNfc_LibContext_t pLibContext=NULL;
\r
415 PHNFC_UNUSED_VARIABLE(pContext);
\r
416 /* Get the Lib context */
\r
417 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
\r
419 if(pLibContext == NULL)
\r
421 status = NFCSTATUS_FAILED;
\r
425 /* Initialize the local variable */
\r
426 pClientCb =pLibContext->CBInfo.pClientShutdownCb;
\r
427 pUpperLayerContext=pLibContext->CBInfo.pClientShtdwnCntx;
\r
428 if(status == NFCSTATUS_SUCCESS)
\r
430 pLibContext->LibNfcState.cur_state = eLibNfcHalStateShutdown;
\r
431 phLibNfc_UpdateCurState(status,pLibContext);
\r
433 pLibContext->status.GenCb_pending_status=FALSE;
\r
435 /* Allocate the Memory for the Transceive info */
\r
436 if(pClientCb!=NULL)
\r
438 (*pClientCb)(pUpperLayerContext, status);
\r
440 if(pLibContext->psHwReference!=NULL)
\r
442 phOsalNfc_FreeMemory(pLibContext->psHwReference);
\r
443 pLibContext->psHwReference = NULL;
\r
445 if(NULL != gpphLibContext->psBufferedAuth)
\r
447 if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
\r
449 phOsalNfc_FreeMemory(
\r
450 gpphLibContext->psBufferedAuth->sRecvData.buffer);
\r
452 if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
\r
454 phOsalNfc_FreeMemory(
\r
455 gpphLibContext->psBufferedAuth->sSendData.buffer);
\r
457 phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
\r
458 gpphLibContext->psBufferedAuth = NULL;
\r
460 /*Free the memory allocated during NDEF read,write
\r
461 and NDEF formatting*/
\r
462 phLibNfc_Ndef_DeInit();
\r
463 phOsalNfc_FreeMemory(pLibContext);
\r
464 gpphLibContext=NULL;
\r
470 /* shutdown sequence failed by HAL 4 */
\r
471 status= NFCSTATUS_FAILED;
\r
472 pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
\r
473 phLibNfc_UpdateCurState(status,pLibContext);
\r
474 pLibContext->status.GenCb_pending_status=FALSE;
\r
475 if(pClientCb!=NULL)
\r
477 (*pClientCb)(pUpperLayerContext,status);
\r
483 * Pending shutdown call.
\r
487 void phLibNfc_Pending_Shutdown(void)
\r
489 NFCSTATUS RetStatus = NFCSTATUS_SUCCESS ;
\r
490 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
491 RetStatus = phHal4Nfc_Close(
\r
492 gpphLibContext->psHwReference,
\r
493 phLibNfc_ShutdownCb,
\r
494 (void *)gpphLibContext);
\r
495 PHNFC_UNUSED_VARIABLE(RetStatus);
\r
501 * Reset the LIB NFC.
\r
503 NFCSTATUS phLibNfc_Mgt_Reset(void *pContext)
\r
505 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
506 phLibNfc_LibContext_t *pLibNfc_Ctxt = (phLibNfc_LibContext_t *)pContext;
\r
508 if((pLibNfc_Ctxt == NULL)
\r
509 || (gpphLibContext->LibNfcState.cur_state
\r
510 == eLibNfcHalStateShutdown))
\r
511 { /*Lib Nfc not initlized*/
\r
512 Status = NFCSTATUS_NOT_INITIALISED;
\r
514 else if(NULL == pContext)
\r
516 Status = NFCSTATUS_INVALID_PARAMETER;
\r
518 /* Check for valid state,If De initialize is called then
\r
519 return NFCSTATUS_SHUTDOWN */
\r
520 else if(gpphLibContext->LibNfcState.next_state
\r
521 == eLibNfcHalStateShutdown)
\r
523 Status = NFCSTATUS_SHUTDOWN;
\r
527 /*Reset all callback status*/
\r
528 (void) memset(&(gpphLibContext->RegNtfType),0,
\r
529 sizeof(phLibNfc_Registry_Info_t));
\r
530 (void) memset(&(gpphLibContext->sADDconfig),0,
\r
531 sizeof(phLibNfc_sADD_Cfg_t));
\r
532 (void) memset(&(gpphLibContext->ndef_cntx),0,
\r
533 sizeof(phLibNfc_NdefInfo_t));
\r
534 (void) memset(&(gpphLibContext->sNfcIp_Context),0,
\r
535 sizeof(phLibNfc_NfcIpInfo_t));
\r
536 (void) memset(&(gpphLibContext->sCardEmulCfg),0,
\r
537 sizeof(phHal_sEmulationCfg_t));
\r
538 (void) memset(&(gpphLibContext->Discov_handle),0,
\r
539 MAX_REMOTE_DEVICES);
\r
541 /*Free memory allocated for NDEF records*/
\r
542 if(NULL != gpphLibContext->psBufferedAuth)
\r
544 if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
\r
546 phOsalNfc_FreeMemory(
\r
547 gpphLibContext->psBufferedAuth->sRecvData.buffer);
\r
548 gpphLibContext->psBufferedAuth->sRecvData.buffer = NULL;
\r
550 if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
\r
552 phOsalNfc_FreeMemory(
\r
553 gpphLibContext->psBufferedAuth->sSendData.buffer);
\r
554 gpphLibContext->psBufferedAuth->sSendData.buffer = NULL;
\r
556 phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
\r
557 gpphLibContext->psBufferedAuth = NULL;
\r
559 if(NULL != gpphLibContext->psTransInfo)
\r
561 phOsalNfc_FreeMemory(gpphLibContext->psTransInfo);
\r
562 gpphLibContext->psTransInfo = NULL;
\r
564 if(NULL != gpphLibContext->ndef_cntx.psNdefMap)
\r
566 if(NULL != gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf)
\r
568 phOsalNfc_FreeMemory(gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf);
\r
569 gpphLibContext->ndef_cntx.psNdefMap->SendRecvBuf = NULL;
\r
571 phOsalNfc_FreeMemory(gpphLibContext->ndef_cntx.psNdefMap);
\r
572 gpphLibContext->ndef_cntx.psNdefMap = NULL;
\r
574 if(NULL != gpphLibContext->psOverHalCtxt)
\r
576 phOsalNfc_FreeMemory(gpphLibContext->psOverHalCtxt);
\r
577 gpphLibContext->psTransInfo = NULL;
\r
579 if(NULL != gpphLibContext->psDevInputParam)
\r
581 phOsalNfc_FreeMemory(gpphLibContext->psDevInputParam);
\r
582 gpphLibContext->psDevInputParam = NULL;
\r
584 if(NULL != gpphLibContext->ndef_cntx.ndef_fmt)
\r
586 phOsalNfc_FreeMemory(gpphLibContext->ndef_cntx.ndef_fmt);
\r
587 gpphLibContext->ndef_cntx.ndef_fmt = NULL;
\r
589 if(NULL != pNdefRecord)
\r
591 if(NULL != pNdefRecord->Id)
\r
593 phOsalNfc_FreeMemory(pNdefRecord->Id);
\r
594 pNdefRecord->Id = NULL;
\r
596 if(NULL != pNdefRecord->Type)
\r
598 phOsalNfc_FreeMemory(pNdefRecord->Type);
\r
599 pNdefRecord->Type = NULL;
\r
601 if(NULL != pNdefRecord->PayloadData)
\r
603 phOsalNfc_FreeMemory(pNdefRecord->PayloadData);
\r
604 pNdefRecord->PayloadData = NULL;
\r
607 if(NULL != NdefInfo.pNdefRecord)
\r
609 phOsalNfc_FreeMemory(NdefInfo.pNdefRecord);
\r
610 NdefInfo.pNdefRecord = NULL;
\r
612 if(NULL != gpphLibContext->phLib_NdefRecCntx.NdefCb)
\r
614 phOsalNfc_FreeMemory(gpphLibContext->phLib_NdefRecCntx.NdefCb);
\r
615 gpphLibContext->phLib_NdefRecCntx.NdefCb = NULL;
\r
617 if(NULL != gpphLibContext->phLib_NdefRecCntx.ndef_message.buffer)
\r
619 phOsalNfc_FreeMemory(gpphLibContext->phLib_NdefRecCntx.ndef_message.buffer);
\r
620 gpphLibContext->phLib_NdefRecCntx.ndef_message.buffer = NULL;
\r
622 /* No device is connected */
\r
623 gpphLibContext->Connected_handle = 0x00;
\r
624 gpphLibContext->Prev_Connected_handle = 0x00;
\r
625 gpphLibContext->ReleaseType = NFC_INVALID_RELEASE_TYPE;
\r
626 gpphLibContext->eLibNfcCfgMode = NFC_DISCOVERY_STOP;
\r
627 /*Lib Nfc Stack is initilized and in idle state*/
\r
628 gpphLibContext->LibNfcState.cur_state = eLibNfcHalStateInitandIdle;
\r
630 /* Reset all callback status */
\r
631 gpphLibContext->CBInfo.pClientCkNdefCb = NULL;
\r
632 gpphLibContext->CBInfo.pClientCkNdefCntx = NULL;
\r
633 gpphLibContext->CBInfo.pClientConCntx = NULL;
\r
634 gpphLibContext->CBInfo.pClientConnectCb = NULL;
\r
635 gpphLibContext->CBInfo.pClientDConCntx = NULL;
\r
636 gpphLibContext->CBInfo.pClientDisCfgCntx = NULL;
\r
637 gpphLibContext->CBInfo.pClientDisConfigCb = NULL;
\r
638 gpphLibContext->CBInfo.pClientInitCb = NULL;
\r
639 gpphLibContext->CBInfo.pClientInitCntx = gpphLibContext;
\r
640 gpphLibContext->CBInfo.pClientNdefNtfRespCb = NULL;
\r
641 gpphLibContext->CBInfo.pClientNdefNtfRespCntx = NULL;
\r
642 gpphLibContext->CBInfo.pClientNtfRegRespCB = NULL;
\r
643 gpphLibContext->CBInfo.pClientNtfRegRespCntx = NULL;
\r
644 gpphLibContext->CBInfo.pClientPresChkCb = NULL;
\r
645 gpphLibContext->CBInfo.pClientPresChkCntx = NULL;
\r
646 gpphLibContext->CBInfo.pClientRdNdefCb = NULL;
\r
647 gpphLibContext->CBInfo.pClientRdNdefCntx = NULL;
\r
648 gpphLibContext->CBInfo.pClientShtdwnCntx = NULL;
\r
649 gpphLibContext->CBInfo.pClientShutdownCb = NULL;
\r
650 gpphLibContext->CBInfo.pClientTransceiveCb = NULL;
\r
651 gpphLibContext->CBInfo.pClientTranseCntx = NULL;
\r
652 gpphLibContext->CBInfo.pClientWrNdefCb = NULL;
\r
653 gpphLibContext->CBInfo.pClientWrNdefCntx = NULL;
\r
654 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb = NULL;
\r
655 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx = NULL;
\r
656 gpphLibContext->sNfcIp_Context.pClientNfcIpRxCb = NULL;
\r
657 gpphLibContext->sNfcIp_Context.pClientNfcIpRxCntx = NULL;
\r
658 gpphLibContext->sNfcIp_Context.pClientNfcIpTxCb = NULL;
\r
659 gpphLibContext->sNfcIp_Context.pClientNfcIpTxCntx = NULL;
\r
660 gpphLibContext->sSeContext.sSeCallabackInfo.pSeListenerNtfCb = NULL;
\r
661 gpphLibContext->sSeContext.sSeCallabackInfo.pSeListenerCtxt = NULL;
\r
662 gpphLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = NULL;
\r
663 gpphLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt = NULL;
\r
664 /*No callback is pending*/
\r
665 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
671 * LibNfc state machine next state update.
\r
675 phLibNfc_UpdateNextState(
\r
676 pphLibNfc_LibContext_t pLibContext,
\r
677 phLibNfc_State_t next_state
\r
680 NFCSTATUS status = NFCSTATUS_INVALID_STATE;
\r
681 switch(pLibContext->LibNfcState.cur_state)
\r
683 case eLibNfcHalStateShutdown:
\r
687 case eLibNfcHalStateShutdown:
\r
688 case eLibNfcHalStateInitandIdle:
\r
689 status = NFCSTATUS_SUCCESS;
\r
696 case eLibNfcHalStateConfigReady:
\r
700 case eLibNfcHalStateShutdown:
\r
701 case eLibNfcHalStateConfigReady:
\r
702 case eLibNfcHalStateInitandIdle:
\r
703 case eLibNfcHalStateConnect:
\r
704 status = NFCSTATUS_SUCCESS;
\r
711 case eLibNfcHalStateConnect:
\r
715 case eLibNfcHalStateShutdown:
\r
716 case eLibNfcHalStateRelease:
\r
717 case eLibNfcHalStateTransaction:
\r
718 case eLibNfcHalStatePresenceChk:
\r
719 status = NFCSTATUS_SUCCESS;
\r
726 case eLibNfcHalStatePresenceChk:
\r
730 case eLibNfcHalStateShutdown:
\r
731 case eLibNfcHalStateConfigReady:
\r
732 case eLibNfcHalStateRelease:
\r
733 case eLibNfcHalStateTransaction:
\r
734 case eLibNfcHalStatePresenceChk:
\r
735 status = NFCSTATUS_SUCCESS;
\r
742 case eLibNfcHalStateInitandIdle:
\r
746 case eLibNfcHalStateShutdown:
\r
747 case eLibNfcHalStateConfigReady:
\r
748 status = NFCSTATUS_SUCCESS;
\r
758 pLibContext->LibNfcState.next_state =
\r
759 (uint8_t)((NFCSTATUS_SUCCESS == status)?next_state:pLibContext->LibNfcState.next_state);
\r
765 * LibNfc state machine current state update.
\r
769 phLibNfc_UpdateCurState(
\r
771 pphLibNfc_LibContext_t psLibContext
\r
774 switch(psLibContext->LibNfcState.next_state)
\r
776 case eLibNfcHalStateTransaction:
\r
777 psLibContext->LibNfcState.cur_state = (uint8_t)eLibNfcHalStateConnect;
\r
779 case eLibNfcHalStateRelease:
\r
780 psLibContext->LibNfcState.cur_state
\r
781 = (uint8_t)(psLibContext->status.DiscEnbl_status == TRUE?
\r
782 eLibNfcHalStateInitandIdle:eLibNfcHalStateConfigReady);
\r
784 case eLibNfcHalStateInvalid:
\r
787 psLibContext->LibNfcState.cur_state
\r
788 = (uint8_t)((NFCSTATUS_SUCCESS == status)?
\r
789 psLibContext->LibNfcState.next_state:
\r
790 psLibContext->LibNfcState.cur_state);
\r
792 psLibContext->LibNfcState.next_state = (uint8_t)eLibNfcHalStateInvalid;
\r
795 /* Interface to stack capabilities */
\r
797 NFCSTATUS phLibNfc_Mgt_GetstackCapabilities(
\r
798 phLibNfc_StackCapabilities_t *phLibNfc_StackCapabilities,
\r
801 NFCSTATUS RetVal = NFCSTATUS_FAILED;
\r
802 /*Check Lib Nfc stack is initilized*/
\r
803 if((NULL == gpphLibContext)||
\r
804 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
\r
806 RetVal = NFCSTATUS_NOT_INITIALISED;
\r
808 /*Check application has sent the valid parameters*/
\r
809 else if((NULL == phLibNfc_StackCapabilities)
\r
810 || (NULL == pContext))
\r
812 RetVal= NFCSTATUS_INVALID_PARAMETER;
\r
814 else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
\r
816 RetVal = NFCSTATUS_SHUTDOWN;
\r
818 else if(TRUE == gpphLibContext->status.GenCb_pending_status)
\r
820 /*Previous operation is pending */
\r
821 RetVal = NFCSTATUS_BUSY;
\r
825 /* Tag Format Capabilities*/
\r
826 phLibNfc_StackCapabilities->psFormatCapabilities.Desfire = TRUE;
\r
827 phLibNfc_StackCapabilities->psFormatCapabilities.MifareStd = TRUE;
\r
828 phLibNfc_StackCapabilities->psFormatCapabilities.MifareUL = TRUE;
\r
829 phLibNfc_StackCapabilities->psFormatCapabilities.FeliCa = FALSE;
\r
830 phLibNfc_StackCapabilities->psFormatCapabilities.Jewel = FALSE;
\r
831 phLibNfc_StackCapabilities->psFormatCapabilities.ISO14443_4A = FALSE;
\r
832 phLibNfc_StackCapabilities->psFormatCapabilities.ISO14443_4B = FALSE;
\r
833 phLibNfc_StackCapabilities->psFormatCapabilities.MifareULC = TRUE;
\r
834 phLibNfc_StackCapabilities->psFormatCapabilities.ISO15693 = FALSE;
\r
836 /* Tag Mapping Capabilities */
\r
837 phLibNfc_StackCapabilities->psMappingCapabilities.FeliCa = TRUE;
\r
838 phLibNfc_StackCapabilities->psMappingCapabilities.Desfire = TRUE;
\r
839 phLibNfc_StackCapabilities->psMappingCapabilities.ISO14443_4A = TRUE;
\r
840 phLibNfc_StackCapabilities->psMappingCapabilities.ISO14443_4B = TRUE;
\r
841 phLibNfc_StackCapabilities->psMappingCapabilities.MifareStd = TRUE;
\r
842 phLibNfc_StackCapabilities->psMappingCapabilities.MifareUL = TRUE;
\r
843 phLibNfc_StackCapabilities->psMappingCapabilities.MifareULC = TRUE;
\r
844 phLibNfc_StackCapabilities->psMappingCapabilities.Jewel = TRUE;
\r
845 phLibNfc_StackCapabilities->psMappingCapabilities.ISO15693 = FALSE;
\r
847 /*Call Hal4 Get Dev Capabilities to get info about protocols supported
\r
849 PHDBG_INFO("LibNfc:Get Stack capabilities ");
\r
850 RetVal= phHal4Nfc_GetDeviceCapabilities(
\r
851 gpphLibContext->psHwReference,
\r
852 &(phLibNfc_StackCapabilities->psDevCapabilities),
\r
853 (void *)gpphLibContext);
\r
855 LIB_NFC_VERSION_SET(phLibNfc_StackCapabilities->psDevCapabilities.hal_version,
\r
856 PH_HAL4NFC_VERSION,
\r
857 PH_HAL4NFC_REVISION,
\r
861 phLibNfc_StackCapabilities->psDevCapabilities.fw_version=
\r
862 gpphLibContext->psHwReference->device_info.fw_version;
\r
863 phLibNfc_StackCapabilities->psDevCapabilities.hci_version=
\r
864 gpphLibContext->psHwReference->device_info.hci_version;
\r
865 phLibNfc_StackCapabilities->psDevCapabilities.hw_version=
\r
866 gpphLibContext->psHwReference->device_info.hw_version;
\r
867 phLibNfc_StackCapabilities->psDevCapabilities.model_id=
\r
868 gpphLibContext->psHwReference->device_info.model_id;
\r
869 (void)memcpy(phLibNfc_StackCapabilities->psDevCapabilities.full_version,
\r
870 gpphLibContext->psHwReference->device_info.full_version,NXP_FULL_VERSION_LEN);
\r
871 /* Check the firmware version */
\r
872 if (nxp_nfc_full_version == NULL) {
\r
873 // Couldn't load firmware, just pretend we're up to date.
\r
874 // LOGW("Firmware image not available: this device might be running old NFC firmware!");
\r
875 phLibNfc_StackCapabilities->psDevCapabilities.firmware_update_info = 0;
\r
877 phLibNfc_StackCapabilities->psDevCapabilities.firmware_update_info = memcmp(phLibNfc_StackCapabilities->psDevCapabilities.full_version, nxp_nfc_full_version,
\r
878 NXP_FULL_VERSION_LEN);
\r
881 if(NFCSTATUS_SUCCESS != RetVal)
\r
883 RetVal = NFCSTATUS_FAILED;
\r
894 NFCSTATUS phLibNfc_Mgt_ConfigureTestMode(void *pDriverHandle,
\r
895 pphLibNfc_RspCb_t pTestModeCb,
\r
896 phLibNfc_Cfg_Testmode_t eTstmode,
\r
899 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
900 phHal4Nfc_InitType_t eInitType=eInitDefault;
\r
902 if((NULL == pDriverHandle)||(NULL == pTestModeCb))
\r
904 Status = NFCSTATUS_INVALID_PARAMETER;
\r
906 else if((NULL != gpphLibContext) && \
\r
907 (gpphLibContext->LibNfcState.next_state==eLibNfcHalStateShutdown))
\r
909 Status = NFCSTATUS_SHUTDOWN;
\r
911 else if( (eTstmode == phLibNfc_TstMode_On) && (NULL != gpphLibContext))
\r
913 Status=NFCSTATUS_ALREADY_INITIALISED;
\r
915 else if( (eTstmode == phLibNfc_TstMode_Off) && (NULL == gpphLibContext))
\r
917 Status = NFCSTATUS_NOT_INITIALISED;
\r
919 else if( (eTstmode == phLibNfc_TstMode_Off) && (NULL != gpphLibContext))
\r
921 if (NULL!= gpphLibContext->CBInfo.pClientShutdownCb)
\r
922 { /* Previous callback pending */
\r
923 Status = NFCSTATUS_BUSY;
\r
927 Status = NFCSTATUS_PENDING;
\r
928 if(TRUE != gpphLibContext->status.GenCb_pending_status)
\r
930 Status = phHal4Nfc_Close(gpphLibContext->psHwReference,
\r
931 phLibNfc_ShutdownCb,
\r
932 (void *)gpphLibContext);
\r
934 if(Status== NFCSTATUS_PENDING)
\r
936 gpphLibContext->CBInfo.pClientShutdownCb = pTestModeCb;
\r
937 gpphLibContext->CBInfo.pClientShtdwnCntx = pContext;
\r
938 gpphLibContext->status.GenCb_pending_status=TRUE;
\r
939 gpphLibContext->LibNfcState.next_state= eLibNfcHalStateShutdown;
\r
943 Status =NFCSTATUS_FAILED;
\r
949 /* Initialize the Lib context */
\r
950 gpphLibContext=(pphLibNfc_LibContext_t)phOsalNfc_GetMemory(
\r
951 (uint32_t)sizeof(phLibNfc_LibContext_t));
\r
952 if(NULL == gpphLibContext)
\r
954 Status=NFCSTATUS_INSUFFICIENT_RESOURCES;
\r
958 (void)memset((void *)gpphLibContext,0,(
\r
959 (uint32_t)sizeof(phLibNfc_LibContext_t)));
\r
961 /* Store the Callback and context in LibContext structure*/
\r
962 gpphLibContext->CBInfo.pClientInitCb=pTestModeCb;
\r
963 gpphLibContext->CBInfo.pClientInitCntx=pContext;
\r
964 /* Initialize the HwReferece structure */
\r
965 gpphLibContext->psHwReference=(phHal_sHwReference_t *)
\r
966 phOsalNfc_GetMemory((uint32_t)sizeof(phHal_sHwReference_t));
\r
967 (void)memset((void *)gpphLibContext->psHwReference,0,
\r
968 ((uint32_t)sizeof(phHal_sHwReference_t)));
\r
969 /* Allocate the Memory for the Transceive info */
\r
970 if( gpphLibContext->psHwReference!=NULL)
\r
972 gpphLibContext->psHwReference->p_board_driver = pDriverHandle;
\r
973 Status = phLibNfc_UpdateNextState(gpphLibContext,
\r
974 eLibNfcHalStateInitandIdle);
\r
975 if(Status==NFCSTATUS_SUCCESS)
\r
977 if(eTstmode == phLibNfc_TstMode_On)
\r
978 eInitType = eInitTestModeOn;
\r
979 if(eTstmode == phLibNfc_TstMode_Off)
\r
980 eInitType = eInitDefault;
\r
981 Status=phHal4Nfc_Open(
\r
982 gpphLibContext->psHwReference,
\r
985 (void *)gpphLibContext);
\r
990 Status = NFCSTATUS_INSUFFICIENT_RESOURCES;
\r
992 phLibNfc_Ndef_Init();
\r