2 * Copyright (C) 2010 NXP Semiconductors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * \file phLibNfc_initiator.c
\r
20 * Project: NFC FRI 1.1
\r
22 * $Date: Fri Apr 23 14:34:08 2010 $
\r
23 * $Author: ing07385 $
\r
25 * $Aliases: NFC_FRI1.1_WK1014_SDK,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1019_SDK,NFC_FRI1.1_WK1024_SDK $
\r
30 ************************* Header Files ****************************************
\r
33 #include <phLibNfcStatus.h>
\r
34 #include <phLibNfc.h>
\r
35 #include <phHal4Nfc.h>
\r
36 #include <phOsalNfc.h>
\r
37 #include <phLibNfc_Internal.h>
\r
38 #include <phLibNfc_SE.h>
\r
39 #include <phLibNfc_ndef_raw.h>
\r
40 #include <phLibNfc_initiator.h>
\r
41 #include <phLibNfc_discovery.h>
\r
45 *************************** Macro's ****************************************
\r
48 #ifndef STATIC_DISABLE
\r
49 #define STATIC static
\r
55 *************************** Global Variables **********************************
\r
58 #define PN544_IO_TIMEOUT_RESPONSE 0x89
\r
61 *************************** Static Function Declaration ***********************
\r
64 /* Target discvovery notification callback */
\r
65 STATIC void phLibNfc_NotificationRegister_Resp_Cb (
\r
67 phHal_eNotificationType_t type,
\r
68 phHal4Nfc_NotificationInfo_t info,
\r
72 /*Remote device connect response callback*/
\r
73 STATIC void phLibNfc_RemoteDev_Connect_Cb(
\r
75 phHal_sRemoteDevInformation_t *pRmtdev_info,
\r
79 #ifdef RECONNECT_SUPPORT
\r
82 phLibNfc_config_discovery_con_failure_cb (
\r
85 #endif /* #ifdef RECONNECT_SUPPORT */
\r
87 /*Remote device disconnect response callback*/
\r
88 STATIC void phLibNfc_RemoteDev_Disconnect_cb(
\r
90 phHal_sRemoteDevInformation_t *reg_handle,
\r
93 /*Remote device Transceive response callback*/
\r
94 STATIC void phLibNfc_RemoteDev_Transceive_Cb(void *context,
\r
95 phHal_sRemoteDevInformation_t *pRmtdev_info,
\r
96 phNfc_sData_t *response,
\r
99 /*Set P2P config paramater response callback*/
\r
100 STATIC void phLibNfc_Mgt_SetP2P_ConfigParams_Cb(
\r
107 *************************** Function Definitions ******************************
\r
111 * Response to target discovery.
\r
114 void phLibNfc_NotificationRegister_Resp_Cb (
\r
116 phHal_eNotificationType_t type,
\r
117 phHal4Nfc_NotificationInfo_t info,
\r
121 NFCSTATUS RetVal = NFCSTATUS_SUCCESS,
\r
122 Status = NFCSTATUS_SUCCESS;
\r
123 uint16_t DeviceIndx, DeviceIndx1;
\r
124 uint8_t sak_byte=0;
\r
125 uint8_t tag_disc_flg = 0;
\r
126 phLibNfc_NtfRegister_RspCb_t pClientCb=NULL;
\r
127 pClientCb =gpphLibContext->CBInfo.pClientNtfRegRespCB;
\r
128 PHNFC_UNUSED_VARIABLE(context);
\r
131 if(( type != NFC_DISCOVERY_NOTIFICATION )
\r
132 &&(PHNFCSTATUS(status)!=NFCSTATUS_DESELECTED))
\r
134 Status = NFCSTATUS_FAILED;
\r
136 else if (PHNFCSTATUS(status) == NFCSTATUS_DESELECTED)
\r
142 DeviceIndx=0;DeviceIndx1=0;
\r
143 while(DeviceIndx < info.psDiscoveryInfo->NumberOfDevices)
\r
145 switch(info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx]->RemDevType)
\r
147 case phHal_eMifare_PICC:
\r
149 /*Mifare Tag discovered*/
\r
150 sak_byte = info.psDiscoveryInfo->
\r
151 ppRemoteDevInfo[DeviceIndx]->RemoteDevInfo.Iso14443A_Info.Sak;
\r
152 if((TRUE == gpphLibContext->RegNtfType.MifareUL)&& (sak_byte==0x00))
\r
154 /*Copy the tag related info*/
\r
155 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
156 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
157 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
158 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
159 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
160 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
165 if((TRUE == gpphLibContext->RegNtfType.MifareStd)&&
\r
166 (((sak_byte & 0x18)==0x08)||((sak_byte & 0x18)==0x18)))
\r
168 /*Copy the tag related info*/
\r
169 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
170 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
171 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
172 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
173 gpphLibContext->Discov_handle[DeviceIndx1]=
\r
174 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
180 case phHal_eISO14443_A_PICC:
\r
182 /*ISO 14443-A type tag discovered*/
\r
183 if(TRUE == gpphLibContext->RegNtfType.ISO14443_4A)
\r
185 /*Copy the ISO type A tag info*/
\r
186 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
187 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
188 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
189 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
190 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
191 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
196 case phHal_eISO14443_3A_PICC:
\r
198 /*ISO 14443-A type tag discovered*/
\r
199 if(TRUE == gpphLibContext->RegNtfType.MifareUL)
\r
201 /*Copy the ISO type A tag info*/
\r
202 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
203 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
204 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
205 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
206 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
207 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
212 case phHal_eISO14443_B_PICC:
\r
214 /*ISO 14443-B type tag Discovered */
\r
215 if(TRUE == gpphLibContext->RegNtfType.ISO14443_4B)
\r
217 /*Copy the Type B tag info */
\r
218 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
219 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
220 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
221 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
222 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
223 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
228 case phHal_eFelica_PICC:
\r
230 /*Felica Type Tag Discovered */
\r
231 if(TRUE == gpphLibContext->RegNtfType.Felica)
\r
233 /*Copy the Felica tag info */
\r
234 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
235 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
236 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
237 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
238 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
239 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
244 case phHal_eJewel_PICC:
\r
246 /*Jewel Type Tag Discovered */
\r
247 if(TRUE == gpphLibContext->RegNtfType.Jewel)
\r
249 /*Copy the Felica tag info */
\r
250 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
251 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
252 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
253 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
254 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
255 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
261 case phHal_eISO15693_PICC:
\r
263 /*Jewel Type Tag Discovered */
\r
264 if(TRUE == gpphLibContext->RegNtfType.ISO15693)
\r
266 /*Copy the Felica tag info */
\r
267 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
268 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
269 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
270 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
271 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
272 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
278 case phHal_eNfcIP1_Target:
\r
280 if(TRUE == gpphLibContext->RegNtfType.NFC)
\r
282 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
283 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
284 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
285 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
\r
286 gpphLibContext->Discov_handle[DeviceIndx1] =
\r
287 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
293 case phHal_eNfcIP1_Initiator:
\r
295 if(TRUE == gpphLibContext->RegNtfType.NFC)
\r
297 gpphLibContext->LibNfcState.cur_state=eLibNfcHalStateConnect;
\r
298 gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
\r
299 info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
\r
300 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
\r
301 (uint32_t)gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo;
\r
302 gpphLibContext->sNfcIp_Context.Rem_Initiator_Handle=
\r
303 gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
\r
318 if((tag_disc_flg >0 )&&(status != NFCSTATUS_FAILED))
\r
320 gpphLibContext->dev_cnt = tag_disc_flg;
\r
321 /* Check for if the discovered tags are multiple or
\r
322 Multiple protocol tag */
\r
323 if((gpphLibContext->dev_cnt > 1)&&(
\r
324 (status ==NFCSTATUS_MULTIPLE_PROTOCOLS) ||
\r
325 (status ==NFCSTATUS_MULTIPLE_TAGS)) )
\r
331 status =NFCSTATUS_SUCCESS;
\r
333 /*Notify to upper layer the no of tag discovered and
\r
335 if (NULL != pClientCb)
\r
338 (void*)gpphLibContext->CBInfo.pClientNtfRegRespCntx,
\r
339 gpphLibContext->psRemoteDevList,
\r
340 gpphLibContext->dev_cnt,
\r
346 else if(PHNFCSTATUS(status)==NFCSTATUS_DESELECTED)
\r
348 info.psDiscoveryInfo->NumberOfDevices = 0;
\r
349 if (NULL != pClientCb)
\r
351 gpphLibContext->LibNfcState.cur_state=eLibNfcHalStateRelease;
\r
352 pClientCb((void*)gpphLibContext->CBInfo.pClientNtfRegRespCntx,
\r
359 else /*Reconfigure the discovery wheel*/
\r
361 RetVal = phHal4Nfc_ConfigureDiscovery ( gpphLibContext->psHwReference,
\r
362 NFC_DISCOVERY_RESUME,
\r
363 &(gpphLibContext->sADDconfig),
\r
364 phLibNfc_config_discovery_cb,
\r
367 if((RetVal!=NFCSTATUS_SUCCESS) &&(RetVal!=NFCSTATUS_PENDING))
\r
369 Status = NFCSTATUS_FAILED;
\r
373 if(Status == NFCSTATUS_FAILED)
\r
375 if (NULL != pClientCb)
\r
377 pClientCb(gpphLibContext->CBInfo.pClientNtfRegRespCntx,
\r
387 * This interface registers notification handler for target discovery.
\r
390 phLibNfc_RemoteDev_NtfRegister(
\r
391 phLibNfc_Registry_Info_t* pRegistryInfo,
\r
392 phLibNfc_NtfRegister_RspCb_t pNotificationHandler,
\r
396 NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
\r
399 /*Check for valid parameters*/
\r
400 if((NULL == pNotificationHandler)
\r
401 || (NULL == pContext)
\r
402 ||(NULL== pRegistryInfo))
\r
404 RetVal= NFCSTATUS_INVALID_PARAMETER;
\r
406 else if((NULL == gpphLibContext) ||
\r
407 (gpphLibContext->LibNfcState.cur_state
\r
408 == eLibNfcHalStateShutdown))
\r
410 RetVal = NFCSTATUS_NOT_INITIALISED;
\r
412 else if(gpphLibContext->LibNfcState.next_state
\r
413 == eLibNfcHalStateShutdown)
\r
415 /*Next state is shutdown*/
\r
416 RetVal= NFCSTATUS_SHUTDOWN;
\r
421 PHDBG_INFO("LibNfc:Registering Notification Handler");
\r
424 (void) memcpy(&(gpphLibContext->RegNtfType),pRegistryInfo,
\r
425 sizeof(phLibNfc_Registry_Info_t));
\r
426 /* Register Discovery Notification Handler*/
\r
428 /*Register for NFCIP1 target type*/
\r
429 RetVal = phHal4Nfc_RegisterNotification(
\r
430 gpphLibContext->psHwReference,
\r
431 eRegisterP2PDiscovery,
\r
432 phLibNfc_NotificationRegister_Resp_Cb,
\r
433 (void*)gpphLibContext
\r
435 /*Register for Tag discovery*/
\r
436 RetVal = phHal4Nfc_RegisterNotification(
\r
437 gpphLibContext->psHwReference,
\r
438 eRegisterTagDiscovery,
\r
439 phLibNfc_NotificationRegister_Resp_Cb,
\r
440 (void*)gpphLibContext
\r
442 gpphLibContext->CBInfo.pClientNtfRegRespCB = pNotificationHandler;
\r
443 gpphLibContext->CBInfo.pClientNtfRegRespCntx = pContext;
\r
444 /*Register notification handler with below layer*/
\r
450 * This interface unregisters notification handler for target discovery.
\r
452 NFCSTATUS phLibNfc_RemoteDev_NtfUnregister(void)
\r
454 NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
\r
455 if((NULL == gpphLibContext) ||
\r
456 (gpphLibContext->LibNfcState.cur_state
\r
457 == eLibNfcHalStateShutdown))
\r
459 /*Lib Nfc not Initialized*/
\r
460 RetVal = NFCSTATUS_NOT_INITIALISED;
\r
462 else if(gpphLibContext->LibNfcState.next_state
\r
463 == eLibNfcHalStateShutdown)
\r
465 /*Lib Nfc Shutdown*/
\r
466 RetVal= NFCSTATUS_SHUTDOWN;
\r
470 /*Unregister notification handler with lower layer */
\r
471 RetVal = phHal4Nfc_UnregisterNotification(
\r
472 gpphLibContext->psHwReference,
\r
473 eRegisterP2PDiscovery,
\r
476 RetVal = phHal4Nfc_UnregisterNotification(
\r
477 gpphLibContext->psHwReference,
\r
478 eRegisterTagDiscovery,
\r
481 gpphLibContext->CBInfo.pClientNtfRegRespCB = NULL;
\r
482 gpphLibContext->CBInfo.pClientNtfRegRespCntx =NULL;
\r
483 PHDBG_INFO("LibNfc:Unregister Notification Handler");
\r
488 #ifdef RECONNECT_SUPPORT
\r
491 phLibNfc_RemoteDev_ReConnect (
\r
492 phLibNfc_Handle hRemoteDevice,
\r
493 pphLibNfc_ConnectCallback_t pNotifyReConnect_RspCb,
\r
497 NFCSTATUS ret_val = NFCSTATUS_FAILED;
\r
498 phLibNfc_sRemoteDevInformation_t *psRemoteDevInfo = NULL;
\r
500 if ((NULL == gpphLibContext)
\r
501 || (eLibNfcHalStateShutdown ==
\r
502 gpphLibContext->LibNfcState.cur_state))
\r
504 ret_val = NFCSTATUS_NOT_INITIALISED;
\r
506 else if ((NULL == pContext)
\r
507 || (NULL == pNotifyReConnect_RspCb)
\r
508 || (NULL == (void *)hRemoteDevice))
\r
510 /* Check valid parameters */
\r
511 ret_val = NFCSTATUS_INVALID_PARAMETER;
\r
513 /* Check valid lib nfc State */
\r
514 else if (gpphLibContext->LibNfcState.next_state
\r
515 == eLibNfcHalStateShutdown)
\r
517 ret_val = NFCSTATUS_SHUTDOWN;
\r
519 else if (0 == gpphLibContext->Connected_handle)
\r
521 ret_val = NFCSTATUS_TARGET_NOT_CONNECTED;
\r
523 else if ((gpphLibContext->Discov_handle[0] != hRemoteDevice)
\r
524 && (gpphLibContext->Discov_handle[1] != hRemoteDevice)
\r
525 && (gpphLibContext->Discov_handle[2] != hRemoteDevice)
\r
526 && (gpphLibContext->Discov_handle[3] != hRemoteDevice)
\r
527 && (gpphLibContext->Discov_handle[4] != hRemoteDevice)
\r
528 && (gpphLibContext->Discov_handle[5] != hRemoteDevice)
\r
529 && (gpphLibContext->Discov_handle[6] != hRemoteDevice)
\r
530 && (gpphLibContext->Discov_handle[7] != hRemoteDevice)
\r
531 && (gpphLibContext->Discov_handle[8] != hRemoteDevice)
\r
532 && (gpphLibContext->Discov_handle[9] != hRemoteDevice))
\r
534 ret_val = NFCSTATUS_INVALID_HANDLE;
\r
538 psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t *)hRemoteDevice;
\r
540 /* Call the HAL connect*/
\r
541 ret_val = phHal4Nfc_Connect (gpphLibContext->psHwReference,
\r
543 phLibNfc_RemoteDev_Connect_Cb,
\r
544 (void *)gpphLibContext);
\r
546 if (NFCSTATUS_PENDING == ret_val)
\r
548 /* If HAL Connect is pending update the LibNFC state machine
\r
549 and store the CB pointer and Context,
\r
550 mark the General CB pending status is TRUE */
\r
551 gpphLibContext->CBInfo.pClientConnectCb = pNotifyReConnect_RspCb;
\r
552 gpphLibContext->CBInfo.pClientConCntx = pContext;
\r
553 gpphLibContext->status.GenCb_pending_status = TRUE;
\r
554 gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
\r
556 gpphLibContext->Prev_Connected_handle = gpphLibContext->Connected_handle;
\r
558 gpphLibContext->Connected_handle = hRemoteDevice;
\r
560 else if (NFCSTATUS_INVALID_REMOTE_DEVICE == PHNFCSTATUS(ret_val))
\r
562 /* The Handle given for connect is invalid*/
\r
563 ret_val = NFCSTATUS_TARGET_NOT_CONNECTED;
\r
567 /* Lower layer returns internal error code return NFCSTATUS_FAILED*/
\r
568 ret_val = NFCSTATUS_FAILED;
\r
574 #endif /* #ifdef RECONNECT_SUPPORT */
\r
578 * Connect to a single Remote Device
\r
580 NFCSTATUS phLibNfc_RemoteDev_Connect(
\r
581 phLibNfc_Handle hRemoteDevice,
\r
582 pphLibNfc_ConnectCallback_t pNotifyConnect_RspCb,
\r
587 NFCSTATUS RetVal = NFCSTATUS_FAILED;
\r
588 phLibNfc_sRemoteDevInformation_t *psRemoteDevInfo;
\r
590 if((NULL == gpphLibContext) ||
\r
591 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
\r
593 RetVal = NFCSTATUS_NOT_INITIALISED;
\r
594 }/* Check valid parameters*/
\r
595 else if((NULL == pContext)
\r
596 || (NULL == pNotifyConnect_RspCb)
\r
597 || (NULL == (void*)hRemoteDevice))
\r
599 RetVal= NFCSTATUS_INVALID_PARAMETER;
\r
601 /* Check valid lib nfc State*/
\r
602 else if(gpphLibContext->LibNfcState.next_state
\r
603 == eLibNfcHalStateShutdown)
\r
605 RetVal= NFCSTATUS_SHUTDOWN;
\r
607 else if((gpphLibContext->Discov_handle[0] != hRemoteDevice)&&
\r
608 (gpphLibContext->Discov_handle[1] != hRemoteDevice)&&
\r
609 (gpphLibContext->Discov_handle[2] != hRemoteDevice)&&
\r
610 (gpphLibContext->Discov_handle[3] != hRemoteDevice)&&
\r
611 (gpphLibContext->Discov_handle[4] != hRemoteDevice)&&
\r
612 (gpphLibContext->Discov_handle[5] != hRemoteDevice)&&
\r
613 (gpphLibContext->Discov_handle[6] != hRemoteDevice)&&
\r
614 (gpphLibContext->Discov_handle[7] != hRemoteDevice)&&
\r
615 (gpphLibContext->Discov_handle[8] != hRemoteDevice)&&
\r
616 (gpphLibContext->Discov_handle[9] != hRemoteDevice))
\r
618 RetVal= NFCSTATUS_INVALID_HANDLE;
\r
620 else if ((hRemoteDevice != gpphLibContext->Connected_handle)
\r
621 && (0 != gpphLibContext->Connected_handle))
\r
623 RetVal = NFCSTATUS_FAILED;
\r
627 psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice;
\r
629 /* Call the HAL connect*/
\r
630 RetVal = phHal4Nfc_Connect(gpphLibContext->psHwReference,
\r
632 phLibNfc_RemoteDev_Connect_Cb,
\r
633 (void* )gpphLibContext);
\r
634 if(RetVal== NFCSTATUS_PENDING)
\r
636 /* If HAL Connect is pending update the LibNFC state machine
\r
637 and store the CB pointer and Context,
\r
638 mark the General CB pending status is TRUE*/
\r
639 gpphLibContext->CBInfo.pClientConnectCb = pNotifyConnect_RspCb;
\r
640 gpphLibContext->CBInfo.pClientConCntx = pContext;
\r
641 gpphLibContext->status.GenCb_pending_status=TRUE;
\r
642 gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
\r
643 gpphLibContext->Prev_Connected_handle = gpphLibContext->Connected_handle;
\r
644 gpphLibContext->Connected_handle = hRemoteDevice;
\r
646 else if(PHNFCSTATUS(RetVal) == NFCSTATUS_INVALID_REMOTE_DEVICE)
\r
648 /* The Handle given for connect is invalid*/
\r
649 RetVal= NFCSTATUS_TARGET_NOT_CONNECTED;
\r
653 /* Lower layer returns internal error code return NFCSTATUS_FAILED*/
\r
654 RetVal = NFCSTATUS_FAILED;
\r
660 #ifdef RECONNECT_SUPPORT
\r
663 phLibNfc_config_discovery_con_failure_cb (
\r
667 if((phLibNfc_LibContext_t *)context == gpphLibContext)
\r
668 { /*check for same context*/
\r
669 pphLibNfc_ConnectCallback_t ps_client_con_cb =
\r
670 gpphLibContext->CBInfo.pClientConnectCb;
\r
672 if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
\r
674 /*If shutdown called in between allow shutdown to happen*/
\r
675 phLibNfc_Pending_Shutdown();
\r
676 status = NFCSTATUS_SHUTDOWN;
\r
680 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
681 gpphLibContext->status.DiscEnbl_status = FALSE;
\r
682 status = NFCSTATUS_TARGET_LOST;
\r
684 phLibNfc_UpdateCurState (status,gpphLibContext);
\r
686 if(gpphLibContext->status.Discovery_pending_status == TRUE)
\r
688 NFCSTATUS RetStatus = NFCSTATUS_FAILED;
\r
689 /* Application has called discovery before receiving this callback,
\r
690 so NO notification to the upper layer, instead lower layer
\r
691 discovery is called */
\r
692 gpphLibContext->status.Discovery_pending_status = FALSE;
\r
693 RetStatus = phHal4Nfc_ConfigureDiscovery(
\r
694 gpphLibContext->psHwReference,
\r
695 gpphLibContext->eLibNfcCfgMode,
\r
696 &gpphLibContext->sADDconfig,
\r
697 (pphLibNfc_RspCb_t)
\r
698 phLibNfc_config_discovery_cb,
\r
699 (void *)gpphLibContext);
\r
700 if (NFCSTATUS_PENDING == RetStatus)
\r
702 (void)phLibNfc_UpdateNextState(gpphLibContext,
\r
703 eLibNfcHalStateConfigReady);
\r
704 gpphLibContext->status.GenCb_pending_status = TRUE;
\r
705 gpphLibContext->status.DiscEnbl_status = TRUE;
\r
709 #endif /* #ifdef RESTART_CFG */
\r
712 if (NULL != ps_client_con_cb)
\r
714 gpphLibContext->CBInfo.pClientConnectCb = NULL;
\r
715 /* Call the upper layer callback*/
\r
716 ps_client_con_cb (gpphLibContext->CBInfo.pClientConCntx,
\r
719 } /*End of if-context check*/
\r
721 { /*exception: wrong context pointer returned*/
\r
722 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
723 status = NFCSTATUS_FAILED;
\r
728 #endif /* #ifdef RECONNECT_SUPPORT */
\r
730 * Response callback for remote device connect
\r
732 STATIC void phLibNfc_RemoteDev_Connect_Cb(
\r
734 phHal_sRemoteDevInformation_t *pRmtdev_info,
\r
738 NFCSTATUS Connect_status = NFCSTATUS_SUCCESS;
\r
739 /*Check valid lib nfc context is returned from lower layer*/
\r
740 if((phLibNfc_LibContext_t *)pContext == gpphLibContext)
\r
742 gpphLibContext->LastTrancvSuccess = FALSE;
\r
744 /* Mark General Callback pending status as false*/
\r
745 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
747 /* Check the shutdown is called during the lower layer Connect in process,
\r
748 If yes call shutdown call and return NFCSTATUS_SHUTDOWN */
\r
749 if((eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state))
\r
751 phLibNfc_Pending_Shutdown();
\r
752 Connect_status = NFCSTATUS_SHUTDOWN;
\r
755 else if(PHNFCSTATUS(status)==NFCSTATUS_SUCCESS)
\r
757 /* Copy the Remote device address as connected handle*/
\r
758 gpphLibContext->Connected_handle =(uint32_t) pRmtdev_info;
\r
759 /* Update the state to connected and return status as SUCCESS*/
\r
760 gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
\r
761 Connect_status = NFCSTATUS_SUCCESS;
\r
764 { /* if(PHNFCSTATUS(status)==NFCSTATUS_INVALID_REMOTE_DEVICE) */
\r
765 /* If remote device is invalid return as TARGET LOST to upper layer*/
\r
766 /* If error code is other than SUCCESS return NFCSTATUS_TARGET_LOST */
\r
767 Connect_status = NFCSTATUS_TARGET_LOST;
\r
768 gpphLibContext->Connected_handle = gpphLibContext->Prev_Connected_handle ;
\r
770 gpphLibContext->ndef_cntx.is_ndef = CHK_NDEF_NOT_DONE;
\r
771 /* Update the Current Sate*/
\r
772 phLibNfc_UpdateCurState(Connect_status,(phLibNfc_LibContext_t *)pContext);
\r
773 /* Call the upper layer callback*/
\r
774 gpphLibContext->CBInfo.pClientConnectCb(
\r
775 gpphLibContext->CBInfo.pClientConCntx,
\r
776 (uint32_t)pRmtdev_info,
\r
777 (phLibNfc_sRemoteDevInformation_t*)pRmtdev_info,
\r
781 { /*exception: wrong context pointer returned*/
\r
782 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
788 * Allows to disconnect from already connected target.
\r
790 NFCSTATUS phLibNfc_RemoteDev_Disconnect( phLibNfc_Handle hRemoteDevice,
\r
791 phLibNfc_eReleaseType_t ReleaseType,
\r
792 pphLibNfc_DisconnectCallback_t pDscntCallback,
\r
796 NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
\r
797 phLibNfc_sRemoteDevInformation_t *psRemoteDevInfo=NULL;
\r
799 /*Check for valid parameter*/
\r
800 if((NULL == gpphLibContext) ||
\r
801 (gpphLibContext->LibNfcState.cur_state
\r
802 == eLibNfcHalStateShutdown))
\r
804 RetVal = NFCSTATUS_NOT_INITIALISED;
\r
806 else if((NULL == pContext) ||
\r
807 (NULL == pDscntCallback)||(hRemoteDevice == 0))
\r
809 RetVal= NFCSTATUS_INVALID_PARAMETER;
\r
811 /* Check for valid state,If De initialize is called then
\r
812 return NFCSTATUS_SHUTDOWN */
\r
813 else if(gpphLibContext->LibNfcState.next_state
\r
814 == eLibNfcHalStateShutdown)
\r
816 RetVal= NFCSTATUS_SHUTDOWN;
\r
818 else if(gpphLibContext->Connected_handle==0)
\r
820 RetVal=NFCSTATUS_TARGET_NOT_CONNECTED;
\r
822 /* The given handle is not the connected handle return NFCSTATUS_INVALID_HANDLE*/
\r
823 else if(hRemoteDevice != gpphLibContext->Connected_handle )
\r
825 RetVal=NFCSTATUS_INVALID_HANDLE;
\r
829 if((eLibNfcHalStateRelease == gpphLibContext->LibNfcState.next_state)
\r
830 ||((gpphLibContext->sSeContext.eActivatedMode == phLibNfc_SE_ActModeWired)&&
\r
831 (ReleaseType != NFC_SMARTMX_RELEASE))
\r
832 ||((gpphLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)&&
\r
833 (ReleaseType == NFC_SMARTMX_RELEASE)))
\r
834 { /* Previous disconnect callback is pending */
\r
835 RetVal = NFCSTATUS_REJECTED;
\r
837 #ifndef LLCP_CHANGES
\r
838 else if(eLibNfcHalStateTransaction == gpphLibContext->LibNfcState.next_state)
\r
839 { /* Previous Transaction is Pending*/
\r
840 RetVal = NFCSTATUS_BUSY;
\r
841 PHDBG_INFO("LibNfc:Transaction is Pending");
\r
843 #endif /* #ifdef LLCP_CHANGES */
\r
846 gpphLibContext->ReleaseType = ReleaseType;
\r
847 psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice;
\r
848 RetVal = phHal4Nfc_Disconnect(gpphLibContext->psHwReference,
\r
849 (phHal_sRemoteDevInformation_t*)psRemoteDevInfo,
\r
850 gpphLibContext->ReleaseType,
\r
851 (pphHal4Nfc_DiscntCallback_t)
\r
852 phLibNfc_RemoteDev_Disconnect_cb,
\r
853 (void *)gpphLibContext);
\r
854 if( NFCSTATUS_PENDING == PHNFCSTATUS(RetVal))
\r
856 /*Copy the upper layer Callback pointer and context*/
\r
857 gpphLibContext->CBInfo.pClientDisConnectCb = pDscntCallback;
\r
858 gpphLibContext->CBInfo.pClientDConCntx = pContext;
\r
859 /* Mark general callback pending status as TRUE and update the state*/
\r
860 gpphLibContext->status.GenCb_pending_status=TRUE;
\r
861 gpphLibContext->LibNfcState.next_state = eLibNfcHalStateRelease;
\r
866 /*If lower layer returns other than pending
\r
867 (internal error codes) return NFCSTATUS_FAILED */
\r
868 RetVal = NFCSTATUS_FAILED;
\r
875 * Response callback for Remote device Disconnect.
\r
877 STATIC void phLibNfc_RemoteDev_Disconnect_cb(
\r
879 phHal_sRemoteDevInformation_t *reg_handle,
\r
883 NFCSTATUS DisCnct_status = NFCSTATUS_SUCCESS;
\r
884 pphLibNfc_DisconnectCallback_t pUpper_NtfCb = NULL;
\r
885 void *pUpper_Context = NULL;
\r
887 /* Copy the upper layer Callback and context*/
\r
888 pUpper_NtfCb = gpphLibContext->CBInfo.pClientDisConnectCb;
\r
889 pUpper_Context = gpphLibContext->CBInfo.pClientDConCntx;
\r
891 /* Check valid context is returned or not */
\r
892 if((phLibNfc_LibContext_t *)context != gpphLibContext)
\r
894 /*exception: wrong context pointer returned*/
\r
895 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
899 /* Mark the General callback pending status FALSE */
\r
900 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
901 gpphLibContext->CBInfo.pClientDisConnectCb = NULL;
\r
902 gpphLibContext->CBInfo.pClientDConCntx = NULL;
\r
904 gpphLibContext->ndef_cntx.is_ndef = CHK_NDEF_NOT_DONE;
\r
905 gpphLibContext->LastTrancvSuccess = FALSE;
\r
906 /*Reset Connected handle */
\r
907 gpphLibContext->Connected_handle=0x0000;
\r
908 /*Reset previous Connected handle */
\r
909 gpphLibContext->Prev_Connected_handle = 0x0000;
\r
911 if(gpphLibContext->sSeContext.eActivatedMode == phLibNfc_SE_ActModeWired)
\r
913 gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault;
\r
915 if(NULL != gpphLibContext->psBufferedAuth)
\r
917 if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
\r
919 phOsalNfc_FreeMemory(
\r
920 gpphLibContext->psBufferedAuth->sRecvData.buffer);
\r
922 if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
\r
924 phOsalNfc_FreeMemory(
\r
925 gpphLibContext->psBufferedAuth->sSendData.buffer);
\r
927 phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
\r
928 gpphLibContext->psBufferedAuth = NULL;
\r
931 /* Check DeInit is called or not */
\r
932 if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
\r
934 /*call shutdown and return status as NFCSTATUS_SHUTDOWN */
\r
935 phLibNfc_Pending_Shutdown();
\r
936 DisCnct_status = NFCSTATUS_SHUTDOWN;
\r
938 else if(NFCSTATUS_SUCCESS == status)
\r
940 DisCnct_status = NFCSTATUS_SUCCESS;
\r
941 gpphLibContext->LibNfcState.next_state = eLibNfcHalStateRelease;
\r
945 DisCnct_status = NFCSTATUS_FAILED;
\r
946 phLibNfc_UpdateCurState(DisCnct_status,(phLibNfc_LibContext_t *)context);
\r
948 /* Call the upper layer Callback */
\r
949 (*pUpper_NtfCb)(pUpper_Context,
\r
950 (uint32_t)reg_handle,
\r
956 * This interface allows to perform Read/write operation on remote device.
\r
959 phLibNfc_RemoteDev_Transceive(phLibNfc_Handle hRemoteDevice,
\r
960 phLibNfc_sTransceiveInfo_t* psTransceiveInfo,
\r
961 pphLibNfc_TransceiveCallback_t pTransceive_RspCb,
\r
965 NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
\r
967 /*Check for valid parameter */
\r
969 if((NULL == gpphLibContext) ||
\r
970 (gpphLibContext->LibNfcState.cur_state
\r
971 == eLibNfcHalStateShutdown))
\r
973 RetVal = NFCSTATUS_NOT_INITIALISED;
\r
975 else if((NULL == psTransceiveInfo)
\r
976 || (NULL == pTransceive_RspCb)
\r
977 || (NULL == (void *)hRemoteDevice)
\r
978 || (NULL == psTransceiveInfo->sRecvData.buffer)
\r
979 || (NULL == psTransceiveInfo->sSendData.buffer)
\r
980 || (NULL == pContext))
\r
982 RetVal= NFCSTATUS_INVALID_PARAMETER;
\r
984 /* Check the state for DeInit is called or not,if yes return NFCSTATUS_SHUTDOWN*/
\r
985 else if(gpphLibContext->LibNfcState.next_state
\r
986 == eLibNfcHalStateShutdown)
\r
988 RetVal= NFCSTATUS_SHUTDOWN;
\r
989 }/* If there is no handle connected return NFCSTATUS_TARGET_NOT_CONNECTED*/
\r
990 else if(gpphLibContext->Connected_handle==0)
\r
992 RetVal=NFCSTATUS_TARGET_NOT_CONNECTED;
\r
993 }/* If the given handle is not the connected handle return NFCSTATUS_INVALID_HANDLE */
\r
994 else if(gpphLibContext->Connected_handle!= hRemoteDevice )
\r
996 RetVal=NFCSTATUS_INVALID_HANDLE;
\r
997 } /*If the transceive is called before finishing the previous transceive function
\r
998 return NFCSTATUS_REJECTED */
\r
999 else if((eLibNfcHalStateTransaction ==
\r
1000 gpphLibContext->LibNfcState.next_state)
\r
1001 ||(phHal_eNfcIP1_Initiator==
\r
1002 ((phHal_sRemoteDevInformation_t*)hRemoteDevice)->RemDevType))
\r
1004 RetVal = NFCSTATUS_REJECTED;
\r
1006 #ifdef LLCP_TRANSACT_CHANGES
\r
1007 else if ((LLCP_STATE_RESET_INIT != gpphLibContext->llcp_cntx.sLlcpContext.state)
\r
1008 && (LLCP_STATE_CHECKED != gpphLibContext->llcp_cntx.sLlcpContext.state))
\r
1010 RetVal= NFCSTATUS_BUSY;
\r
1012 #endif /* #ifdef LLCP_TRANSACT_CHANGES */
\r
1015 gpphLibContext->ndef_cntx.eLast_Call = RawTrans;
\r
1016 (void)memcpy((void *)(gpphLibContext->psTransInfo),
\r
1017 (void *)psTransceiveInfo,
\r
1018 sizeof(phLibNfc_sTransceiveInfo_t));
\r
1019 /* Check the given Mifare command is supported or not ,
\r
1020 If not return NFCSTATUS_COMMAND_NOT_SUPPORTED */
\r
1021 if( (((phHal_sRemoteDevInformation_t*)hRemoteDevice)->RemDevType ==
\r
1022 phHal_eMifare_PICC)&&
\r
1023 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRaw ) &&
\r
1024 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareAuthentA ) &&
\r
1025 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareAuthentB ) &&
\r
1026 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRead16 ) &&
\r
1027 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRead ) &&
\r
1028 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareWrite16 ) &&
\r
1029 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareWrite4 ) &&
\r
1030 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareDec ) &&
\r
1031 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareTransfer ) &&
\r
1032 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRestore ) &&
\r
1033 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareReadSector ) &&
\r
1034 ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareWriteSector ))
\r
1036 RetVal = NFCSTATUS_COMMAND_NOT_SUPPORTED;
\r
1038 if(eLibNfcHalStatePresenceChk !=
\r
1039 gpphLibContext->LibNfcState.next_state)
\r
1041 PHDBG_INFO("LibNfc:Transceive In Progress");
\r
1042 if((((phHal_sRemoteDevInformation_t*)hRemoteDevice)->RemDevType ==
\r
1043 phHal_eMifare_PICC) && (((phHal_sRemoteDevInformation_t*)
\r
1044 hRemoteDevice)->RemoteDevInfo.Iso14443A_Info.Sak != 0)&&
\r
1045 (phHal_eMifareAuthentA == gpphLibContext->psTransInfo->cmd.MfCmd))
\r
1047 if(NULL != gpphLibContext->psBufferedAuth)
\r
1049 if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
\r
1051 phOsalNfc_FreeMemory(
\r
1052 gpphLibContext->psBufferedAuth->sRecvData.buffer);
\r
1054 if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
\r
1056 phOsalNfc_FreeMemory(
\r
1057 gpphLibContext->psBufferedAuth->sSendData.buffer);
\r
1059 phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
\r
1061 gpphLibContext->psBufferedAuth
\r
1062 =(phLibNfc_sTransceiveInfo_t *)
\r
1063 phOsalNfc_GetMemory(sizeof(phLibNfc_sTransceiveInfo_t));
\r
1064 gpphLibContext->psBufferedAuth->addr = psTransceiveInfo->addr;
\r
1065 gpphLibContext->psBufferedAuth->cmd = psTransceiveInfo->cmd;
\r
1066 gpphLibContext->psBufferedAuth->sSendData.length
\r
1067 = psTransceiveInfo->sSendData.length;
\r
1068 gpphLibContext->psBufferedAuth->sRecvData.length
\r
1069 = psTransceiveInfo->sRecvData.length;
\r
1070 gpphLibContext->psBufferedAuth->sSendData.buffer
\r
1072 phOsalNfc_GetMemory(
\r
1073 gpphLibContext->psTransInfo->sSendData.length);
\r
1075 (void)memcpy((void *)
\r
1076 (gpphLibContext->psBufferedAuth->sSendData.buffer),
\r
1077 (void *)psTransceiveInfo->sSendData.buffer,
\r
1078 psTransceiveInfo->sSendData.length);
\r
1080 gpphLibContext->psBufferedAuth->sRecvData.buffer
\r
1082 phOsalNfc_GetMemory(
\r
1083 gpphLibContext->psTransInfo->sRecvData.length);
\r
1085 /*Call the lower layer Transceive function */
\r
1086 RetVal = phHal4Nfc_Transceive( gpphLibContext->psHwReference,
\r
1087 (phHal_sTransceiveInfo_t*)gpphLibContext->psTransInfo,
\r
1088 (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice,
\r
1089 (pphHal4Nfc_TransceiveCallback_t)
\r
1090 phLibNfc_RemoteDev_Transceive_Cb,
\r
1091 (void* )gpphLibContext);
\r
1092 if(PHNFCSTATUS(RetVal) == NFCSTATUS_PENDING)
\r
1094 /* Copy the upper layer callback pointer and context */
\r
1095 gpphLibContext->CBInfo.pClientTransceiveCb = pTransceive_RspCb;
\r
1096 gpphLibContext->CBInfo.pClientTranseCntx = pContext;
\r
1097 /* Mark the General callback pending status is TRUE */
\r
1098 gpphLibContext->status.GenCb_pending_status = TRUE;
\r
1099 /*Transceive is in Progress-Used in Release API*/
\r
1101 /*Update the state machine*/
\r
1102 gpphLibContext->LibNfcState.next_state = eLibNfcHalStateTransaction;
\r
1107 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
1108 RetVal = NFCSTATUS_FAILED;
\r
1114 * Response for Remote device transceive.
\r
1117 void phLibNfc_RemoteDev_Transceive_Cb(void *context,
\r
1118 phHal_sRemoteDevInformation_t *pRmtdev_info,
\r
1119 phNfc_sData_t *response,
\r
1123 NFCSTATUS trans_status = NFCSTATUS_SUCCESS;
\r
1124 phNfc_sData_t *trans_resp= NULL;
\r
1125 void *pUpper_Context = NULL;
\r
1126 pphLibNfc_TransceiveCallback_t pUpper_TagNtfCb =
\r
1127 gpphLibContext->CBInfo.pClientTransceiveCb;
\r
1129 /*Check valid context is returned or not */
\r
1130 if((phLibNfc_LibContext_t *)context == gpphLibContext)
\r
1132 trans_resp = &gpphLibContext->psTransInfo->sRecvData;
\r
1134 pUpper_Context = gpphLibContext->CBInfo.pClientTranseCntx;
\r
1135 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
1137 /*If DeInit is called during the transceive,
\r
1138 call the shutdown and return NFCSTATUS_SHUTDOWN*/
\r
1139 if(gpphLibContext->LibNfcState.next_state
\r
1140 == eLibNfcHalStateShutdown)
\r
1142 phLibNfc_Pending_Shutdown();
\r
1143 trans_status = NFCSTATUS_SHUTDOWN;
\r
1145 /* If Disconnect is called return NFCSTATUS_ABORTED */
\r
1146 else if(eLibNfcHalStateRelease ==
\r
1147 gpphLibContext->LibNfcState.next_state)
\r
1149 trans_status = NFCSTATUS_ABORTED;
\r
1151 /* If the received lower layer status is not SUCCESS return NFCSTATUS_FAILED */
\r
1152 else if( NFCSTATUS_SUCCESS == status)
\r
1154 trans_status = NFCSTATUS_SUCCESS;
\r
1156 else if((PHNFCSTATUS(status) != NFCSTATUS_SUCCESS) &&
\r
1157 (phHal_eMifare_PICC == pRmtdev_info->RemDevType) &&
\r
1158 (0x00 != pRmtdev_info->RemoteDevInfo.Iso14443A_Info.Sak))
\r
1160 gpphLibContext->LastTrancvSuccess = FALSE;
\r
1161 trans_status = NFCSTATUS_FAILED;
\r
1162 /* card type is mifare 1k/4k, then reconnect */
\r
1163 trans_status = phHal4Nfc_Connect(gpphLibContext->psHwReference,
\r
1165 (pphHal4Nfc_ConnectCallback_t)
\r
1166 phLibNfc_Reconnect_Mifare_Cb,
\r
1167 (void *)gpphLibContext);
\r
1169 else if ((PHNFCSTATUS(status) == PN544_IO_TIMEOUT_RESPONSE) ||
\r
1170 (PHNFCSTATUS(status) == NFCSTATUS_RF_TIMEOUT))
\r
1172 // 0x89, 0x09 HCI response values from PN544 indicate timeout
\r
1173 trans_status = NFCSTATUS_TARGET_LOST;
\r
1177 // PN544 did get some reply from tag, just not valid
\r
1178 trans_status = NFCSTATUS_FAILED;
\r
1180 /*Update the state machine */
\r
1181 phLibNfc_UpdateCurState(status,gpphLibContext);
\r
1182 gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
\r
1183 if(NFCSTATUS_PENDING != trans_status)
\r
1185 /* Tranceive over */
\r
1186 PHDBG_INFO("LibNfc:TXRX Callback-Update the Transceive responce");
\r
1187 if (NULL != pUpper_TagNtfCb)
\r
1189 if(trans_status == NFCSTATUS_SUCCESS)
\r
1191 gpphLibContext->LastTrancvSuccess = TRUE;
\r
1192 pUpper_Context = gpphLibContext->CBInfo.pClientTranseCntx;
\r
1193 trans_resp->buffer = response->buffer;
\r
1194 trans_resp->length = response->length;
\r
1195 /* Notify the upper layer */
\r
1196 PHDBG_INFO("LibNfc:Transceive Complete");
\r
1197 /* Notify the Transceive Completion to upper layer */
\r
1198 gpphLibContext->CBInfo.pClientTransceiveCb(pUpper_Context,
\r
1199 (uint32_t)pRmtdev_info,
\r
1205 gpphLibContext->LastTrancvSuccess = FALSE;
\r
1206 pUpper_Context = gpphLibContext->CBInfo.pClientTranseCntx;
\r
1207 trans_resp->length = 0;
\r
1208 /* Notify the upper layer */
\r
1209 PHDBG_INFO("LibNfc:Transceive Complete");
\r
1210 /* Notify the Transceive Completion to upper layer */
\r
1211 gpphLibContext->CBInfo.pClientTransceiveCb(pUpper_Context,
\r
1212 (uint32_t)pRmtdev_info,
\r
1221 { /*exception: wrong context pointer returned*/
\r
1222 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
1228 * Interface to configure P2P configurations.
\r
1231 phLibNfc_Mgt_SetP2P_ConfigParams(phLibNfc_sNfcIPCfg_t* pConfigInfo,
\r
1232 pphLibNfc_RspCb_t pConfigRspCb,
\r
1236 NFCSTATUS RetVal = NFCSTATUS_FAILED;
\r
1237 /* LibNfc Initialized or not */
\r
1238 if((NULL == gpphLibContext)||
\r
1239 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
\r
1241 RetVal = NFCSTATUS_NOT_INITIALISED;
\r
1242 }/* Check for valid parameters */
\r
1243 else if((NULL == pConfigInfo) || (NULL == pConfigRspCb)
\r
1244 || (NULL == pContext))
\r
1246 RetVal= NFCSTATUS_INVALID_PARAMETER;
\r
1248 else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
\r
1250 RetVal = NFCSTATUS_SHUTDOWN;
\r
1252 else if(TRUE == gpphLibContext->status.GenCb_pending_status)
\r
1253 { /*Previous callback is pending */
\r
1254 RetVal = NFCSTATUS_BUSY;
\r
1258 if(eLibNfcHalStatePresenceChk !=
\r
1259 gpphLibContext->LibNfcState.next_state)
\r
1261 phHal_uConfig_t uConfig;
\r
1262 /* copy General bytes of Max length = 48 bytes */
\r
1263 (void)memcpy((void *)&(uConfig.nfcIPConfig.generalBytes),
\r
1264 (void *)pConfigInfo->generalBytes,
\r
1265 pConfigInfo->generalBytesLength);
\r
1266 /* also copy the General Bytes length*/
\r
1267 uConfig.nfcIPConfig.generalBytesLength = pConfigInfo->generalBytesLength;
\r
1269 RetVal = phHal4Nfc_ConfigParameters(
\r
1270 gpphLibContext->psHwReference,
\r
1273 phLibNfc_Mgt_SetP2P_ConfigParams_Cb,
\r
1274 (void *)gpphLibContext
\r
1279 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb= NULL;
\r
1280 RetVal = NFCSTATUS_PENDING;
\r
1282 if(NFCSTATUS_PENDING == RetVal)
\r
1284 /* save the context and callback for later use */
\r
1285 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb = pConfigRspCb;
\r
1286 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx = pContext;
\r
1287 gpphLibContext->status.GenCb_pending_status=TRUE;
\r
1288 /* Next state is configured */
\r
1289 gpphLibContext->LibNfcState.next_state =eLibNfcHalStateConfigReady;
\r
1293 RetVal = NFCSTATUS_FAILED;
\r
1299 * Response callback for P2P configurations.
\r
1301 STATIC void phLibNfc_Mgt_SetP2P_ConfigParams_Cb(void *context,
\r
1304 pphLibNfc_RspCb_t pClientCb=NULL;
\r
1305 void *pUpperLayerContext=NULL;
\r
1306 /* Check for the context returned by below layer */
\r
1307 if((phLibNfc_LibContext_t *)context != gpphLibContext)
\r
1308 { /*wrong context returned*/
\r
1309 phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
\r
1313 if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
\r
1314 { /*shutdown called before completion of this api allow
\r
1315 shutdown to happen */
\r
1316 phLibNfc_Pending_Shutdown();
\r
1317 status = NFCSTATUS_SHUTDOWN;
\r
1321 gpphLibContext->status.GenCb_pending_status = FALSE;
\r
1322 if(NFCSTATUS_SUCCESS != status)
\r
1324 status = NFCSTATUS_FAILED;
\r
1328 status = NFCSTATUS_SUCCESS;
\r
1331 /*update the current state */
\r
1332 phLibNfc_UpdateCurState(status,gpphLibContext);
\r
1334 pClientCb = gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb;
\r
1335 pUpperLayerContext = gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx;
\r
1337 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb = NULL;
\r
1338 gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx = NULL;
\r
1339 if (NULL != pClientCb)
\r
1341 /* Notify to upper layer status of configure operation */
\r
1342 pClientCb(pUpperLayerContext, status);
\r