15d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
25d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Copyright (C) 2010 NXP Semiconductors
35d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
45d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Licensed under the Apache License, Version 2.0 (the "License");
55d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * you may not use this file except in compliance with the License.
65d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * You may obtain a copy of the License at
75d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
85d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *      http://www.apache.org/licenses/LICENSE-2.0
95d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Unless required by applicable law or agreed to in writing, software
115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * distributed under the License is distributed on an "AS IS" BASIS,
125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * See the License for the specific language governing permissions and
145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * limitations under the License.
155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \file phLibNfc_initiator.c
195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: NFC FRI 1.1
215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Date: Fri Apr 23 14:34:08 2010 $
235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Author: ing07385 $
245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Revision: 1.53 $
255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $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 $
265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly************************* Header Files ****************************************
315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfcStatus.h>
345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc.h>
355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHal4Nfc.h>
365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h>
375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc_Internal.h>
385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc_SE.h>
395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc_ndef_raw.h>
405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc_initiator.h>
415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc_discovery.h>
425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*************************** Macro's  ****************************************
465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef STATIC_DISABLE
495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define STATIC static
505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define STATIC
525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*************************** Global Variables **********************************
565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
58a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen#define PN544_IO_TIMEOUT_RESPONSE 0x89
595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*************************** Static Function Declaration ***********************
625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* Target discvovery notification callback */
655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_NotificationRegister_Resp_Cb (
665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                void                             *context,
675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHal_eNotificationType_t        type,
685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHal4Nfc_NotificationInfo_t     info,
695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS                        status
705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Remote device connect response callback*/
735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_RemoteDev_Connect_Cb(
745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           void        *pContext,
755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           phHal_sRemoteDevInformation_t *pRmtdev_info,
765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           NFCSTATUS    status
775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           );
785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
79d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#ifdef RECONNECT_SUPPORT
80d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn CoenenSTATIC
81d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenenvoid
82d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn CoenenphLibNfc_config_discovery_con_failure_cb (
83d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    void                *context,
84d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    NFCSTATUS           status);
85d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#endif /* #ifdef RECONNECT_SUPPORT */
86d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Remote device disconnect response callback*/
885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_RemoteDev_Disconnect_cb(
895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                void                          *context,
905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHal_sRemoteDevInformation_t *reg_handle,
915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS                      status
925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Remote device Transceive response callback*/
945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_RemoteDev_Transceive_Cb(void *context,
955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHal_sRemoteDevInformation_t *pRmtdev_info,
965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phNfc_sData_t *response,
975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS status
985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Set P2P config paramater response callback*/
1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_Mgt_SetP2P_ConfigParams_Cb(
1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                void                             *context,
1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS                        status
1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*************************** Function Definitions ******************************
1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Response to target discovery.
1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC
1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phLibNfc_NotificationRegister_Resp_Cb (
1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                void                            *context,
1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHal_eNotificationType_t       type,
1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHal4Nfc_NotificationInfo_t    info,
1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS                       status
1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                )
1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetVal = NFCSTATUS_SUCCESS,
1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly              Status = NFCSTATUS_SUCCESS;
1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint16_t DeviceIndx, DeviceIndx1;
1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t sak_byte=0;
1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t tag_disc_flg = 0;
1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLibNfc_NtfRegister_RspCb_t pClientCb=NULL;
1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pClientCb =gpphLibContext->CBInfo.pClientNtfRegRespCB;
1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly	PHNFC_UNUSED_VARIABLE(context);
1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(( type != NFC_DISCOVERY_NOTIFICATION )
1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        &&(PHNFCSTATUS(status)!=NFCSTATUS_DESELECTED))
1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Status = NFCSTATUS_FAILED;
1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
136e13ca0d66e4682aafb2c031b45a953b1aa153a4bSunil Jogi    else if (PHNFCSTATUS(status) == NFCSTATUS_DESELECTED)
137e13ca0d66e4682aafb2c031b45a953b1aa153a4bSunil Jogi    {
138e13ca0d66e4682aafb2c031b45a953b1aa153a4bSunil Jogi        return;
139e13ca0d66e4682aafb2c031b45a953b1aa153a4bSunil Jogi    }
1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly	else
1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly	{
1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		DeviceIndx=0;DeviceIndx1=0;
1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		while(DeviceIndx < info.psDiscoveryInfo->NumberOfDevices)
1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		{
1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly			switch(info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx]->RemDevType)
1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly			{
1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eMifare_PICC:
1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					/*Mifare Tag discovered*/
1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					sak_byte =  info.psDiscoveryInfo->
1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								ppRemoteDevInfo[DeviceIndx]->RemoteDevInfo.Iso14443A_Info.Sak;
1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if((TRUE == gpphLibContext->RegNtfType.MifareUL)&& (sak_byte==0x00))
1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the tag related info*/
1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
158a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross							(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if((TRUE == gpphLibContext->RegNtfType.MifareStd)&&
166eb6da80b266a263350769a0e5629f4089aad32bbSunil Jogi						(((sak_byte & 0x18)==0x08)||((sak_byte & 0x18)==0x18) ||
167eb6da80b266a263350769a0e5629f4089aad32bbSunil Jogi                                                (sak_byte == 0x01)))
1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the tag related info*/
1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
173a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross							(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1]=
1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}break;
1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eISO14443_A_PICC:
1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					/*ISO 14443-A type tag discovered*/
1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.ISO14443_4A)
1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the ISO type A tag info*/
1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
190a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}break;
1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eISO14443_3A_PICC:
1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					/*ISO 14443-A type tag discovered*/
2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.MifareUL)
2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the ISO type A tag info*/
2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
206a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}break;
2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eISO14443_B_PICC:
2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					/*ISO 14443-B type tag Discovered */
2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.ISO14443_4B)
2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the Type B tag info */
2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
222a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}break;
2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eFelica_PICC:
2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					/*Felica Type Tag Discovered */
2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.Felica)
2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the Felica tag info */
2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
238a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}break;
2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eJewel_PICC:
2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
2475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					/*Jewel Type Tag Discovered */
2485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.Jewel)
2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the Felica tag info */
2515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
2525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
2535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
254a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
2555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}
2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				break;
2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eISO15693_PICC:
2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					/*Jewel Type Tag Discovered */
2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.ISO15693)
2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						/*Copy the Felica tag info */
2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
271a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}
2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				break;
2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eNfcIP1_Target:
2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.NFC)
2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
286a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx].psRemoteDevInfo;
2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->Discov_handle[DeviceIndx1] =
2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly							gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}
2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				break;
2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				case  phHal_eNfcIP1_Initiator:
2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					if(TRUE == gpphLibContext->RegNtfType.NFC)
2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					{
2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->LibNfcState.cur_state=eLibNfcHalStateConnect;
2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo=
3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								info.psDiscoveryInfo->ppRemoteDevInfo[DeviceIndx];
3015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev =
302a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross								(phLibNfc_Handle)gpphLibContext->psRemoteDevList[DeviceIndx1].psRemoteDevInfo;
3035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						gpphLibContext->sNfcIp_Context.Rem_Initiator_Handle=
3045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly								gpphLibContext->psRemoteDevList[DeviceIndx1].hTargetDev;
3055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						DeviceIndx1++;
3065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly						tag_disc_flg++;
3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					}
3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}
3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				break;
3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				default :
3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				{
3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					break;
3135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				}
3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly			}
3155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly			DeviceIndx++;
3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		}
3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly	}
3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((tag_disc_flg >0 )&&(status != NFCSTATUS_FAILED))
3205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->dev_cnt = tag_disc_flg;
3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Check for if the discovered tags are multiple or
3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         Multiple protocol tag */
3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if((gpphLibContext->dev_cnt > 1)&&(
3255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (status ==NFCSTATUS_MULTIPLE_PROTOCOLS) ||
3265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (status ==NFCSTATUS_MULTIPLE_TAGS)) )
3275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = status;
3295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
3315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status =NFCSTATUS_SUCCESS;
3335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Notify to upper layer the no of tag discovered and
3355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          the protocol */
3365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != pClientCb)
3375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pClientCb(
3395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					(void*)gpphLibContext->CBInfo.pClientNtfRegRespCntx,
3405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->psRemoteDevList,
3415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->dev_cnt,
3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly					status
3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    );
3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(PHNFCSTATUS(status)==NFCSTATUS_DESELECTED)
3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        info.psDiscoveryInfo->NumberOfDevices = 0;
3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != pClientCb)
3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->LibNfcState.cur_state=eLibNfcHalStateRelease;
3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pClientCb((void*)gpphLibContext->CBInfo.pClientNtfRegRespCntx,
3545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    NULL,
3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    0,
3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status);
3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else /*Reconfigure the discovery wheel*/
3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = phHal4Nfc_ConfigureDiscovery ( gpphLibContext->psHwReference,
3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            NFC_DISCOVERY_RESUME,
3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            &(gpphLibContext->sADDconfig),
3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            phLibNfc_config_discovery_cb,
3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            gpphLibContext);
3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if((RetVal!=NFCSTATUS_SUCCESS) &&(RetVal!=NFCSTATUS_PENDING))
3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Status = NFCSTATUS_FAILED;
3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(Status == NFCSTATUS_FAILED)
3755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != pClientCb)
3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pClientCb(gpphLibContext->CBInfo.pClientNtfRegRespCntx,
3795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                NULL,
3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                0,
3815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Status);
3825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This interface registers notification handler for target discovery.
3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
3915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLibNfc_RemoteDev_NtfRegister(
3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phLibNfc_Registry_Info_t*       pRegistryInfo,
3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phLibNfc_NtfRegister_RspCb_t    pNotificationHandler,
3945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pContext
3955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        )
3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Check for valid parameters*/
4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((NULL == pNotificationHandler)
4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pContext)
4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ||(NULL== pRegistryInfo))
4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_INVALID_PARAMETER;
4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == gpphLibContext) ||
4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (gpphLibContext->LibNfcState.cur_state
4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown))
4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_NOT_INITIALISED;
4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->LibNfcState.next_state
4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown)
4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Next state is shutdown*/
4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_SHUTDOWN;
4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PHDBG_INFO("LibNfc:Registering Notification Handler");
4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void) memcpy(&(gpphLibContext->RegNtfType),pRegistryInfo,
4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phLibNfc_Registry_Info_t));
4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Register Discovery Notification Handler*/
4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		/*Register for NFCIP1 target type*/
4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		RetVal = phHal4Nfc_RegisterNotification(
4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                gpphLibContext->psHwReference,
4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                eRegisterP2PDiscovery,
4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phLibNfc_NotificationRegister_Resp_Cb,
4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (void*)gpphLibContext
4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Register for Tag discovery*/
4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		RetVal = phHal4Nfc_RegisterNotification(
4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            gpphLibContext->psHwReference,
4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            eRegisterTagDiscovery,
4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            phLibNfc_NotificationRegister_Resp_Cb,
4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (void*)gpphLibContext
4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            );
4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->CBInfo.pClientNtfRegRespCB = pNotificationHandler;
4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->CBInfo.pClientNtfRegRespCntx = pContext;
4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Register notification handler with below layer*/
4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetVal;
4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This interface unregisters notification handler for target discovery.
4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phLibNfc_RemoteDev_NtfUnregister(void)
4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((NULL == gpphLibContext) ||
4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       (gpphLibContext->LibNfcState.cur_state
4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown))
4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Lib Nfc not Initialized*/
4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_NOT_INITIALISED;
4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->LibNfcState.next_state
4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown)
4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Lib Nfc Shutdown*/
4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_SHUTDOWN;
4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Unregister notification handler with lower layer */
4725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = phHal4Nfc_UnregisterNotification(
4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    gpphLibContext->psHwReference,
4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    eRegisterP2PDiscovery,
4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    gpphLibContext);
4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		RetVal = phHal4Nfc_UnregisterNotification(
4785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    gpphLibContext->psHwReference,
4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    eRegisterTagDiscovery,
4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    gpphLibContext);
4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->CBInfo.pClientNtfRegRespCB = NULL;
4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->CBInfo.pClientNtfRegRespCntx =NULL;
4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PHDBG_INFO("LibNfc:Unregister Notification Handler");
4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetVal;
4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
489d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#ifdef RECONNECT_SUPPORT
490d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
491d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn CoenenNFCSTATUS
492d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn CoenenphLibNfc_RemoteDev_ReConnect (
493d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    phLibNfc_Handle                 hRemoteDevice,
494d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    pphLibNfc_ConnectCallback_t     pNotifyReConnect_RspCb,
495d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    void                            *pContext)
496d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen{
497d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
498d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    NFCSTATUS                           ret_val = NFCSTATUS_FAILED;
499d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    phLibNfc_sRemoteDevInformation_t    *psRemoteDevInfo = NULL;
500d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
501d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    if ((NULL == gpphLibContext)
502d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen      || (eLibNfcHalStateShutdown ==
503d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        gpphLibContext->LibNfcState.cur_state))
504d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {
505d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         ret_val = NFCSTATUS_NOT_INITIALISED;
506d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
507d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    else if ((NULL == pContext)
508d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        || (NULL == pNotifyReConnect_RspCb)
509d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        || (NULL == (void *)hRemoteDevice))
510d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {
511d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        /* Check valid parameters */
512d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        ret_val = NFCSTATUS_INVALID_PARAMETER;
513d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
514d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    /* Check valid lib nfc State */
515d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    else if (gpphLibContext->LibNfcState.next_state
516d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen             == eLibNfcHalStateShutdown)
517d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {
518d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        ret_val = NFCSTATUS_SHUTDOWN;
519d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
520d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    else if (0 == gpphLibContext->Connected_handle)
521d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {
522d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        ret_val = NFCSTATUS_TARGET_NOT_CONNECTED;
523d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
524d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    else if ((gpphLibContext->Discov_handle[0] != hRemoteDevice)
525d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[1] != hRemoteDevice)
526d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[2] != hRemoteDevice)
527d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[3] != hRemoteDevice)
528d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[4] != hRemoteDevice)
529d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[5] != hRemoteDevice)
530d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[6] != hRemoteDevice)
531d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[7] != hRemoteDevice)
532d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[8] != hRemoteDevice)
533d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen		&& (gpphLibContext->Discov_handle[9] != hRemoteDevice))
534d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {
535d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        ret_val = NFCSTATUS_INVALID_HANDLE;
536d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
537d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    else
538d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {
539d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t *)hRemoteDevice;
540d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
541d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        /* Call the HAL connect*/
542d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        ret_val = phHal4Nfc_Connect (gpphLibContext->psHwReference,
543d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                               psRemoteDevInfo,
544d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                               phLibNfc_RemoteDev_Connect_Cb,
545d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                               (void *)gpphLibContext);
546d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
547d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        if (NFCSTATUS_PENDING == ret_val)
548d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        {
549d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            /* If HAL Connect is pending update the LibNFC state machine
550d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                and store the CB pointer and Context,
551d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                mark the General CB pending status is TRUE */
552d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            gpphLibContext->CBInfo.pClientConnectCb = pNotifyReConnect_RspCb;
553d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            gpphLibContext->CBInfo.pClientConCntx = pContext;
554d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            gpphLibContext->status.GenCb_pending_status = TRUE;
555d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen			gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
55634caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas
55734caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas            gpphLibContext->Prev_Connected_handle = gpphLibContext->Connected_handle;
55834caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas
559d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen			gpphLibContext->Connected_handle = hRemoteDevice;
560d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         }
561d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         else if (NFCSTATUS_INVALID_REMOTE_DEVICE == PHNFCSTATUS(ret_val))
562d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         {
563d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen           /* The Handle given for connect is invalid*/
564d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            ret_val = NFCSTATUS_TARGET_NOT_CONNECTED;
565d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         }
566d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         else
567d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         {
568d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            /* Lower layer returns internal error code return NFCSTATUS_FAILED*/
569d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            ret_val = NFCSTATUS_FAILED;
570d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen         }
571d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
572d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
573d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    return ret_val;
574d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen}
575d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#endif /* #ifdef RECONNECT_SUPPORT */
576d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Connect to a single Remote Device
5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phLibNfc_RemoteDev_Connect(
5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phLibNfc_Handle             hRemoteDevice,
5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    pphLibNfc_ConnectCallback_t pNotifyConnect_RspCb,
5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                        *pContext
5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    )
5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetVal = NFCSTATUS_FAILED;
5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLibNfc_sRemoteDevInformation_t *psRemoteDevInfo;
5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((NULL == gpphLibContext) ||
5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         RetVal = NFCSTATUS_NOT_INITIALISED;
5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }/* Check valid parameters*/
5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == pContext)
5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pNotifyConnect_RspCb)
5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == (void*)hRemoteDevice))
5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       RetVal= NFCSTATUS_INVALID_PARAMETER;
6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Check valid lib nfc State*/
6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->LibNfcState.next_state
6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown)
6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_SHUTDOWN;
6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((gpphLibContext->Discov_handle[0] != hRemoteDevice)&&
6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[1] != hRemoteDevice)&&
6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[2] != hRemoteDevice)&&
6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[3] != hRemoteDevice)&&
6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[4] != hRemoteDevice)&&
6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[5] != hRemoteDevice)&&
6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[6] != hRemoteDevice)&&
6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[7] != hRemoteDevice)&&
6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[8] != hRemoteDevice)&&
6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		(gpphLibContext->Discov_handle[9] != hRemoteDevice))
6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_INVALID_HANDLE;
6205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
621d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    else if ((hRemoteDevice != gpphLibContext->Connected_handle)
622d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        && (0 != gpphLibContext->Connected_handle))
623d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {
624d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        RetVal = NFCSTATUS_FAILED;
625d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice;
6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Call the HAL connect*/
6315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = phHal4Nfc_Connect(gpphLibContext->psHwReference,
6325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                               psRemoteDevInfo,
6335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                               phLibNfc_RemoteDev_Connect_Cb,
6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                               (void* )gpphLibContext);
6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(RetVal== NFCSTATUS_PENDING)
6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* If HAL Connect is pending update the LibNFC state machine
6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                and store the CB pointer and Context,
6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                mark the General CB pending status is TRUE*/
6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->CBInfo.pClientConnectCb = pNotifyConnect_RspCb;
6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->CBInfo.pClientConCntx = pContext;
6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->status.GenCb_pending_status=TRUE;
6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly			gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
64434caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas            gpphLibContext->Prev_Connected_handle = gpphLibContext->Connected_handle;
6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly			gpphLibContext->Connected_handle = hRemoteDevice;
6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         else if(PHNFCSTATUS(RetVal) == NFCSTATUS_INVALID_REMOTE_DEVICE)
6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly           /* The Handle given for connect is invalid*/
6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal= NFCSTATUS_TARGET_NOT_CONNECTED;
6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         else
6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Lower layer returns internal error code return NFCSTATUS_FAILED*/
6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = NFCSTATUS_FAILED;
6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetVal;
6595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
660d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
661d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#ifdef RECONNECT_SUPPORT
662d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn CoenenSTATIC
663d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenenvoid
664d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn CoenenphLibNfc_config_discovery_con_failure_cb (
665d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    void                *context,
666d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    NFCSTATUS           status)
667d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen{
668d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    if((phLibNfc_LibContext_t *)context == gpphLibContext)
669d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {   /*check for same context*/
670d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        pphLibNfc_ConnectCallback_t    ps_client_con_cb =
671d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                                    gpphLibContext->CBInfo.pClientConnectCb;
672d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
673d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
674d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        {
675d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            /*If shutdown called in between allow shutdown to happen*/
676d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            phLibNfc_Pending_Shutdown();
677d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            status = NFCSTATUS_SHUTDOWN;
678d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        }
679d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        else
680d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        {
681d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            gpphLibContext->status.GenCb_pending_status = FALSE;
682d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            gpphLibContext->status.DiscEnbl_status = FALSE;
683d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            status = NFCSTATUS_TARGET_LOST;
684d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
685d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            phLibNfc_UpdateCurState (status,gpphLibContext);
686d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#ifdef RESTART_CFG
687d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            if(gpphLibContext->status.Discovery_pending_status == TRUE)
688d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            {
689d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                NFCSTATUS RetStatus = NFCSTATUS_FAILED;
690d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                /* Application has called discovery before receiving this callback,
691d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                so NO notification to the upper layer, instead lower layer
692d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                discovery is called */
693d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                gpphLibContext->status.Discovery_pending_status = FALSE;
694d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                RetStatus =  phHal4Nfc_ConfigureDiscovery(
695d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                        gpphLibContext->psHwReference,
696d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                        gpphLibContext->eLibNfcCfgMode,
697d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                        &gpphLibContext->sADDconfig,
698d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                        (pphLibNfc_RspCb_t)
699d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                        phLibNfc_config_discovery_cb,
700d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                        (void *)gpphLibContext);
701d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                if (NFCSTATUS_PENDING == RetStatus)
702d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                {
703d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                    (void)phLibNfc_UpdateNextState(gpphLibContext,
704d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                                            eLibNfcHalStateConfigReady);
705d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                    gpphLibContext->status.GenCb_pending_status = TRUE;
706d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                    gpphLibContext->status.DiscEnbl_status = TRUE;
707d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                }
708d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            }
709d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
710d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#endif /* #ifdef RESTART_CFG */
711d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        }
712d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
713d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        if (NULL != ps_client_con_cb)
714d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        {
715d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            gpphLibContext->CBInfo.pClientConnectCb = NULL;
716d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            /* Call the upper layer callback*/
717d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen            ps_client_con_cb (gpphLibContext->CBInfo.pClientConCntx,
718d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen                            0, NULL, status);
719d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        }
720d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    } /*End of if-context check*/
721d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    else
722d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    {   /*exception: wrong context pointer returned*/
723d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
724d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen        status = NFCSTATUS_FAILED;
725d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen    }
726d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
727d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen
728d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen}
729d75796b759f9baac8facf22f1b6c6bcfbc51161eMartijn Coenen#endif /* #ifdef RECONNECT_SUPPORT */
7305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
7315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Response callback for remote device connect
7325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_RemoteDev_Connect_Cb(
7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           void        *pContext,
7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           phHal_sRemoteDevInformation_t *pRmtdev_info,
7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           NFCSTATUS    status
7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           )
7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
7395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS             Connect_status = NFCSTATUS_SUCCESS;
7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Check valid lib nfc context is returned from lower layer*/
7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((phLibNfc_LibContext_t *)pContext == gpphLibContext)
7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
74327c8b351b2494780c538ed5f1e5f843712f07e92Martijn Coenen        gpphLibContext->LastTrancvSuccess = FALSE;
7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Mark General Callback pending status as false*/
7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->status.GenCb_pending_status = FALSE;
7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Check the shutdown is called during the lower layer Connect in process,
7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly           If yes call shutdown call and return NFCSTATUS_SHUTDOWN */
7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if((eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state))
7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLibNfc_Pending_Shutdown();
7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Connect_status = NFCSTATUS_SHUTDOWN;
7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if(PHNFCSTATUS(status)==NFCSTATUS_SUCCESS)
7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Copy the Remote device address as connected handle*/
759a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross            gpphLibContext->Connected_handle = (uintptr_t)pRmtdev_info;
7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Update the state to connected and return status as SUCCESS*/
7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Connect_status = NFCSTATUS_SUCCESS;
7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {  /* if(PHNFCSTATUS(status)==NFCSTATUS_INVALID_REMOTE_DEVICE) */
7665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* If remote device is invalid return as TARGET LOST to upper layer*/
7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* If error code is other than SUCCESS return NFCSTATUS_TARGET_LOST */
7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Connect_status = NFCSTATUS_TARGET_LOST;
76934caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas            gpphLibContext->Connected_handle = gpphLibContext->Prev_Connected_handle ;
7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->ndef_cntx.is_ndef = CHK_NDEF_NOT_DONE;
7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Update the Current Sate*/
7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLibNfc_UpdateCurState(Connect_status,(phLibNfc_LibContext_t *)pContext);
7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Call the upper layer callback*/
7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->CBInfo.pClientConnectCb(
7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->CBInfo.pClientConCntx,
777a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross                    (phLibNfc_Handle)pRmtdev_info,
7785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (phLibNfc_sRemoteDevInformation_t*)pRmtdev_info,
7795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Connect_status);
7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
7825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {   /*exception: wrong context pointer returned*/
7835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
7865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
7895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Allows to disconnect from already connected target.
7905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phLibNfc_RemoteDev_Disconnect( phLibNfc_Handle                 hRemoteDevice,
7925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phLibNfc_eReleaseType_t          ReleaseType,
7935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        pphLibNfc_DisconnectCallback_t   pDscntCallback,
7945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        void*                            pContext
7955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        )
7965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phLibNfc_sRemoteDevInformation_t *psRemoteDevInfo=NULL;
7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Check for valid parameter*/
8015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((NULL == gpphLibContext) ||
8025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (gpphLibContext->LibNfcState.cur_state
8035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown))
8045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_NOT_INITIALISED;
8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == pContext) ||
8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (NULL == pDscntCallback)||(hRemoteDevice == 0))
8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_INVALID_PARAMETER;
8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Check for valid state,If De initialize is called then
8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return NFCSTATUS_SHUTDOWN */
8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->LibNfcState.next_state
8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown)
8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_SHUTDOWN;
8185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->Connected_handle==0)
8205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal=NFCSTATUS_TARGET_NOT_CONNECTED;
8225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* The given handle is not the connected handle return NFCSTATUS_INVALID_HANDLE*/
8245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(hRemoteDevice != gpphLibContext->Connected_handle )
8255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal=NFCSTATUS_INVALID_HANDLE;
8275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
8295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if((eLibNfcHalStateRelease == gpphLibContext->LibNfcState.next_state)
8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ||((gpphLibContext->sSeContext.eActivatedMode == phLibNfc_SE_ActModeWired)&&
8326e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas                    (ReleaseType != NFC_SMARTMX_RELEASE))
8336e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas                    ||((gpphLibContext->sSeContext.eActivatedMode != phLibNfc_SE_ActModeWired)&&
8346e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas                            (ReleaseType == NFC_SMARTMX_RELEASE)))
8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {   /* Previous disconnect callback is pending */
8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = NFCSTATUS_REJECTED;
8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8386e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas#ifndef LLCP_CHANGES
8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if(eLibNfcHalStateTransaction == gpphLibContext->LibNfcState.next_state)
8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {   /* Previous  Transaction is Pending*/
8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = NFCSTATUS_BUSY;
8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("LibNfc:Transaction is Pending");
8435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8446e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas#endif /* #ifdef LLCP_CHANGES */
8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->ReleaseType = ReleaseType;
8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice;
8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = phHal4Nfc_Disconnect(gpphLibContext->psHwReference,
8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (phHal_sRemoteDevInformation_t*)psRemoteDevInfo,
8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                gpphLibContext->ReleaseType,
8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (pphHal4Nfc_DiscntCallback_t)
8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phLibNfc_RemoteDev_Disconnect_cb,
8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (void *)gpphLibContext);
8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING == PHNFCSTATUS(RetVal))
8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Copy the upper layer Callback pointer and context*/
8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->CBInfo.pClientDisConnectCb = pDscntCallback;
8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->CBInfo.pClientDConCntx = pContext;
8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Mark general callback pending status as TRUE and update the state*/
8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->status.GenCb_pending_status=TRUE;
8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly				gpphLibContext->LibNfcState.next_state = eLibNfcHalStateRelease;
8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*If lower layer returns other than pending
8685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (internal error codes) return NFCSTATUS_FAILED */
8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                RetVal = NFCSTATUS_FAILED;
8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetVal;
8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
8755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Response callback for Remote device Disconnect.
8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_RemoteDev_Disconnect_cb(
8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                void                          *context,
8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHal_sRemoteDevInformation_t *reg_handle,
8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS                      status
8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                )
8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS             DisCnct_status = NFCSTATUS_SUCCESS;
8855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pphLibNfc_DisconnectCallback_t pUpper_NtfCb = NULL;
8865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        void  *pUpper_Context = NULL;
8875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Copy the upper layer Callback and context*/
8895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pUpper_NtfCb = gpphLibContext->CBInfo.pClientDisConnectCb;
8905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pUpper_Context = gpphLibContext->CBInfo.pClientDConCntx;
8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Check valid context is returned or not */
8935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((phLibNfc_LibContext_t *)context != gpphLibContext)
8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*exception: wrong context pointer returned*/
8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
8995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Mark the General callback pending status FALSE   */
9015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->status.GenCb_pending_status = FALSE;
9025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->CBInfo.pClientDisConnectCb = NULL;
9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->CBInfo.pClientDConCntx = NULL;
9045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->ndef_cntx.is_ndef = CHK_NDEF_NOT_DONE;
9065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->LastTrancvSuccess = FALSE;
9075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Reset Connected handle */
9085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->Connected_handle=0x0000;
90934caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas        /*Reset previous Connected handle */
91034caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas        gpphLibContext->Prev_Connected_handle = 0x0000;
91134caeca8a5ec2aedade68a77393d0aff03f9bd72Daniel Tomas
91275b0473b9eedf7673ed4502978205f4fa5563357Daniel Tomas        if(gpphLibContext->sSeContext.eActivatedMode == phLibNfc_SE_ActModeWired)
91375b0473b9eedf7673ed4502978205f4fa5563357Daniel Tomas        {
91475b0473b9eedf7673ed4502978205f4fa5563357Daniel Tomas          gpphLibContext->sSeContext.eActivatedMode = phLibNfc_SE_ActModeDefault;
91575b0473b9eedf7673ed4502978205f4fa5563357Daniel Tomas        }
9165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NULL != gpphLibContext->psBufferedAuth)
9175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
9185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
9195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
9205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phOsalNfc_FreeMemory(
9215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->psBufferedAuth->sRecvData.buffer);
9225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
9235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
9245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
9255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phOsalNfc_FreeMemory(
9265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->psBufferedAuth->sSendData.buffer);
9275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
9285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
9295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->psBufferedAuth = NULL;
9305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
9315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Check DeInit is called or not */
9335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
9345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*call shutdown and return  status as NFCSTATUS_SHUTDOWN */
9365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLibNfc_Pending_Shutdown();
9375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        DisCnct_status = NFCSTATUS_SHUTDOWN;
9385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(NFCSTATUS_SUCCESS == status)
9405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        DisCnct_status = NFCSTATUS_SUCCESS;
9425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly		gpphLibContext->LibNfcState.next_state = eLibNfcHalStateRelease;
9435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
9455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        DisCnct_status = NFCSTATUS_FAILED;
9475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLibNfc_UpdateCurState(DisCnct_status,(phLibNfc_LibContext_t *)context);
9485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Call the upper layer Callback */
9505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    (*pUpper_NtfCb)(pUpper_Context,
951a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross                    (phLibNfc_Handle)reg_handle,
9525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    DisCnct_status);
9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This interface allows to perform Read/write operation on remote device.
9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLibNfc_RemoteDev_Transceive(phLibNfc_Handle                   hRemoteDevice,
9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              phLibNfc_sTransceiveInfo_t*       psTransceiveInfo,
9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              pphLibNfc_TransceiveCallback_t    pTransceive_RspCb,
9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void*                             pContext
9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              )
9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetVal = NFCSTATUS_SUCCESS;
9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Check for valid parameter */
9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((NULL == gpphLibContext) ||
9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (gpphLibContext->LibNfcState.cur_state
9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown))
9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_NOT_INITIALISED;
9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == psTransceiveInfo)
9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pTransceive_RspCb)
9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == (void *)hRemoteDevice)
9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == psTransceiveInfo->sRecvData.buffer)
9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == psTransceiveInfo->sSendData.buffer)
9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pContext))
9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_INVALID_PARAMETER;
9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* Check the state for DeInit is called or not,if yes return NFCSTATUS_SHUTDOWN*/
9865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->LibNfcState.next_state
9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown)
9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_SHUTDOWN;
9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }/* If there is no handle connected return NFCSTATUS_TARGET_NOT_CONNECTED*/
9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->Connected_handle==0)
9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal=NFCSTATUS_TARGET_NOT_CONNECTED;
9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }/* If the given handle is not the connected handle return NFCSTATUS_INVALID_HANDLE */
9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly	else if(gpphLibContext->Connected_handle!= hRemoteDevice )
9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal=NFCSTATUS_INVALID_HANDLE;
9985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } /*If the transceive is called before finishing the previous transceive function
9995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      return NFCSTATUS_REJECTED  */
10005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((eLibNfcHalStateTransaction ==
10015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->LibNfcState.next_state)
10025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ||(phHal_eNfcIP1_Initiator==
10035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ((phHal_sRemoteDevInformation_t*)hRemoteDevice)->RemDevType))
10045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
10055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_REJECTED;
10065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
10076e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas#ifdef LLCP_TRANSACT_CHANGES
10086e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas    else if ((LLCP_STATE_RESET_INIT != gpphLibContext->llcp_cntx.sLlcpContext.state)
10096e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas            && (LLCP_STATE_CHECKED != gpphLibContext->llcp_cntx.sLlcpContext.state))
10106e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas    {
10116e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas        RetVal= NFCSTATUS_BUSY;
10126e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas    }
10136e286043593b281d161dad4969e05ba9c53ef6d1daniel_Tomas#endif /* #ifdef LLCP_TRANSACT_CHANGES */
10145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
10155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
10165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->ndef_cntx.eLast_Call = RawTrans;
10175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (void)memcpy((void *)(gpphLibContext->psTransInfo),
10185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void *)psTransceiveInfo,
10195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sizeof(phLibNfc_sTransceiveInfo_t));
10205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Check the given Mifare command is supported or not ,
10215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            If not return NFCSTATUS_COMMAND_NOT_SUPPORTED */
10225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if( (((phHal_sRemoteDevInformation_t*)hRemoteDevice)->RemDevType ==
10235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               phHal_eMifare_PICC)&&
10245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRaw ) &&
10255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareAuthentA ) &&
10265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareAuthentB ) &&
10275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRead16 ) &&
10285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRead ) &&
10295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareWrite16 ) &&
10305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareWrite4 ) &&
10315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareDec ) &&
10325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareTransfer ) &&
10335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareRestore ) &&
10345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareReadSector ) &&
10355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ( gpphLibContext->psTransInfo->cmd.MfCmd != phHal_eMifareWriteSector ))
10365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
10375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = NFCSTATUS_COMMAND_NOT_SUPPORTED;
10385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
10395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(eLibNfcHalStatePresenceChk !=
10405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     gpphLibContext->LibNfcState.next_state)
10415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
10425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("LibNfc:Transceive In Progress");
10435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if((((phHal_sRemoteDevInformation_t*)hRemoteDevice)->RemDevType ==
10445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               phHal_eMifare_PICC) && (((phHal_sRemoteDevInformation_t*)
10455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               hRemoteDevice)->RemoteDevInfo.Iso14443A_Info.Sak != 0)&&
10465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               (phHal_eMifareAuthentA == gpphLibContext->psTransInfo->cmd.MfCmd))
10475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
10485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(NULL != gpphLibContext->psBufferedAuth)
10495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
10505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
10515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
10525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phOsalNfc_FreeMemory(
10535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            gpphLibContext->psBufferedAuth->sRecvData.buffer);
10545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
10555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
10565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
10575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phOsalNfc_FreeMemory(
10585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            gpphLibContext->psBufferedAuth->sSendData.buffer);
10595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
10605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
10615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
10625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->psBufferedAuth
10635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    =(phLibNfc_sTransceiveInfo_t *)
10645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phOsalNfc_GetMemory(sizeof(phLibNfc_sTransceiveInfo_t));
10655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->psBufferedAuth->addr = psTransceiveInfo->addr;
10665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->psBufferedAuth->cmd = psTransceiveInfo->cmd;
10675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->psBufferedAuth->sSendData.length
10685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    = psTransceiveInfo->sSendData.length;
10695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->psBufferedAuth->sRecvData.length
10705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    = psTransceiveInfo->sRecvData.length;
10715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->psBufferedAuth->sSendData.buffer
10725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  = (uint8_t *)
10735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      phOsalNfc_GetMemory(
10745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      gpphLibContext->psTransInfo->sSendData.length);
10755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (void)memcpy((void *)
10775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (gpphLibContext->psBufferedAuth->sSendData.buffer),
10785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)psTransceiveInfo->sSendData.buffer,
10795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psTransceiveInfo->sSendData.length);
10805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->psBufferedAuth->sRecvData.buffer
10825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  = (uint8_t *)
10835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      phOsalNfc_GetMemory(
10845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        gpphLibContext->psTransInfo->sRecvData.length);
10855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
10865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*Call the lower layer Transceive function */
10875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = phHal4Nfc_Transceive( gpphLibContext->psHwReference,
10885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (phHal_sTransceiveInfo_t*)gpphLibContext->psTransInfo,
10895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice,
10905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (pphHal4Nfc_TransceiveCallback_t)
10915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phLibNfc_RemoteDev_Transceive_Cb,
10925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (void* )gpphLibContext);
10935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(PHNFCSTATUS(RetVal) == NFCSTATUS_PENDING)
10945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
10955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Copy the upper layer callback pointer and context */
10965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->CBInfo.pClientTransceiveCb = pTransceive_RspCb;
10975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->CBInfo.pClientTranseCntx = pContext;
10985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Mark the General callback pending status is TRUE */
10995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->status.GenCb_pending_status = TRUE;
11005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Transceive is in Progress-Used in Release API*/
11015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Update the state machine*/
11035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->LibNfcState.next_state = eLibNfcHalStateTransaction;
11045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
11055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
11075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
11085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->status.GenCb_pending_status = FALSE;
11095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = NFCSTATUS_FAILED;
11105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
11125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetVal;
11135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
11145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
11155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Response for Remote device transceive.
11165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
11175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC
11185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phLibNfc_RemoteDev_Transceive_Cb(void *context,
11195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    phHal_sRemoteDevInformation_t *pRmtdev_info,
11205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    phNfc_sData_t *response,
11215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    NFCSTATUS status
11225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    )
11235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
11245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS             trans_status = NFCSTATUS_SUCCESS;
11255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phNfc_sData_t         *trans_resp= NULL;
11265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    void                  *pUpper_Context = NULL;
11275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pphLibNfc_TransceiveCallback_t pUpper_TagNtfCb =
11285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            gpphLibContext->CBInfo.pClientTransceiveCb;
11295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Check valid context is returned or not */
11315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((phLibNfc_LibContext_t *)context == gpphLibContext)
11325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
11335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        trans_resp = &gpphLibContext->psTransInfo->sRecvData;
11345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        pUpper_Context = gpphLibContext->CBInfo.pClientTranseCntx;
11365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->status.GenCb_pending_status = FALSE;
11375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*If DeInit is called during the transceive,
11395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly           call the shutdown and return NFCSTATUS_SHUTDOWN*/
11405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(gpphLibContext->LibNfcState.next_state
11415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            == eLibNfcHalStateShutdown)
11425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
11435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLibNfc_Pending_Shutdown();
11445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            trans_status = NFCSTATUS_SHUTDOWN;
11455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         /* If Disconnect is called return NFCSTATUS_ABORTED */
11475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if(eLibNfcHalStateRelease ==
11485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->LibNfcState.next_state)
11495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
11505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            trans_status = NFCSTATUS_ABORTED;
11515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* If the received lower layer status is not SUCCESS return NFCSTATUS_FAILED */
11535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if( NFCSTATUS_SUCCESS == status)
11545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
11555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            trans_status = NFCSTATUS_SUCCESS;
11565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if((PHNFCSTATUS(status) != NFCSTATUS_SUCCESS) &&
11585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (phHal_eMifare_PICC == pRmtdev_info->RemDevType) &&
11595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (0x00 != pRmtdev_info->RemoteDevInfo.Iso14443A_Info.Sak))
11605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1161d1e3b1245b00df78329b90f396d2a7fa92e6644edaniel_Tomas            gpphLibContext->LastTrancvSuccess = FALSE;
11625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            trans_status = NFCSTATUS_FAILED;
11635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* card type is mifare 1k/4k, then reconnect */
11645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            trans_status = phHal4Nfc_Connect(gpphLibContext->psHwReference,
11655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pRmtdev_info,
11665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (pphHal4Nfc_ConnectCallback_t)
11675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phLibNfc_Reconnect_Mifare_Cb,
11685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)gpphLibContext);
11695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1170a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen        else if ((PHNFCSTATUS(status) == PN544_IO_TIMEOUT_RESPONSE) ||
1171a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen                 (PHNFCSTATUS(status) == NFCSTATUS_RF_TIMEOUT))
11725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1173a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen            // 0x89, 0x09 HCI response values from PN544 indicate timeout
11745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            trans_status = NFCSTATUS_TARGET_LOST;
11755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1176a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen        else
1177a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen        {
1178a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen            // PN544 did get some reply from tag, just not valid
1179a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen            trans_status = NFCSTATUS_FAILED;
1180a61bf7e2cb6cf80f1deea680613423a477ac4fb8Martijn Coenen        }
11815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Update the state machine */
11825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLibNfc_UpdateCurState(status,gpphLibContext);
11835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->LibNfcState.next_state = eLibNfcHalStateConnect;
11845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NFCSTATUS_PENDING != trans_status)
11855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
11865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Tranceive over */
11875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("LibNfc:TXRX Callback-Update the Transceive responce");
11885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NULL != pUpper_TagNtfCb)
11895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
11905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(trans_status == NFCSTATUS_SUCCESS)
11915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
11925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->LastTrancvSuccess = TRUE;
11935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    pUpper_Context = gpphLibContext->CBInfo.pClientTranseCntx;
11945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    trans_resp->buffer = response->buffer;
11955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    trans_resp->length = response->length;
11965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            /* Notify the upper layer */
11975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("LibNfc:Transceive Complete");
11985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Notify the Transceive Completion to upper layer */
11995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->CBInfo.pClientTransceiveCb(pUpper_Context,
1200a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross                                (phLibNfc_Handle)pRmtdev_info,
12015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                trans_resp,
12025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                trans_status);
12035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
12045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
12055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
12065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->LastTrancvSuccess = FALSE;
12075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    pUpper_Context = gpphLibContext->CBInfo.pClientTranseCntx;
12085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    trans_resp->length = 0;
12095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            /* Notify the upper layer */
12105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("LibNfc:Transceive Complete");
12115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Notify the Transceive Completion to upper layer */
12125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    gpphLibContext->CBInfo.pClientTransceiveCb(pUpper_Context,
1213a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross                                (phLibNfc_Handle)pRmtdev_info,
12145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                trans_resp,
12155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                trans_status);
12165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
12175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
12185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       }
12195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
12225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {    /*exception: wrong context pointer returned*/
12235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
12245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
12275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
12285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
12295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Interface to configure P2P configurations.
12305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
12315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
12325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphLibNfc_Mgt_SetP2P_ConfigParams(phLibNfc_sNfcIPCfg_t*		pConfigInfo,
12335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                pphLibNfc_RspCb_t			pConfigRspCb,
12345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                void*						pContext
12355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                )
12365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
12375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetVal = NFCSTATUS_FAILED;
12385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* LibNfc Initialized or not */
12395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((NULL == gpphLibContext)||
12405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
12415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_NOT_INITIALISED;
12435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }/* Check for valid parameters */
12445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == pConfigInfo) || (NULL == pConfigRspCb)
12455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pContext))
12465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal= NFCSTATUS_INVALID_PARAMETER;
12485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
12505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_SHUTDOWN;
12525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(TRUE == gpphLibContext->status.GenCb_pending_status)
12545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    { /*Previous callback is pending */
12555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetVal = NFCSTATUS_BUSY;
12565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
12585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(eLibNfcHalStatePresenceChk !=
12605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                gpphLibContext->LibNfcState.next_state)
12615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phHal_uConfig_t uConfig;
12635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* copy General bytes of Max length = 48 bytes */
12645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (void)memcpy((void *)&(uConfig.nfcIPConfig.generalBytes),
12655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void *)pConfigInfo->generalBytes,
12665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    pConfigInfo->generalBytesLength);
12675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* also copy the General Bytes length*/
12685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            uConfig.nfcIPConfig.generalBytesLength = pConfigInfo->generalBytesLength;
12695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = phHal4Nfc_ConfigParameters(
12715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                gpphLibContext->psHwReference,
12725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFC_P2P_CONFIG,
12735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                &uConfig,
12745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phLibNfc_Mgt_SetP2P_ConfigParams_Cb,
12755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (void *)gpphLibContext
12765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
12775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
12795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly             gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb= NULL;
12815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly             RetVal = NFCSTATUS_PENDING;
12825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NFCSTATUS_PENDING == RetVal)
12845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* save the context and callback for later use */
12865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb = pConfigRspCb;
12875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx = pContext;
12885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->status.GenCb_pending_status=TRUE;
12895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Next state is configured */
12905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->LibNfcState.next_state =eLibNfcHalStateConfigReady;
12915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
12935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetVal = NFCSTATUS_FAILED;
12955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetVal;
12985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
12995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
13005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Response callback for P2P configurations.
13015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
13025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phLibNfc_Mgt_SetP2P_ConfigParams_Cb(void     *context,
13035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        NFCSTATUS status)
13045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
13055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        pphLibNfc_RspCb_t       pClientCb=NULL;
13065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    void                    *pUpperLayerContext=NULL;
13075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly     /* Check for the context returned by below layer */
13085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((phLibNfc_LibContext_t *)context != gpphLibContext)
13095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {   /*wrong context returned*/
13105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
13115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
13125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
13135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
13145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
13155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {   /*shutdown called before completion of this api allow
13165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            shutdown to happen */
13175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phLibNfc_Pending_Shutdown();
13185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = NFCSTATUS_SHUTDOWN;
13195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
13215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            gpphLibContext->status.GenCb_pending_status = FALSE;
13235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NFCSTATUS_SUCCESS != status)
13245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
13255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = NFCSTATUS_FAILED;
13265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
13275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
13285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
13295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = NFCSTATUS_SUCCESS;
13305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
13315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*update the current state */
13335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phLibNfc_UpdateCurState(status,gpphLibContext);
13345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        pClientCb = gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb;
13365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        pUpperLayerContext = gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx;
13375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCb = NULL;
13395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        gpphLibContext->sNfcIp_Context.pClientNfcIpCfgCntx = NULL;
13405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NULL != pClientCb)
13415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Notify to upper layer status of configure operation */
13435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pClientCb(pUpperLayerContext, status);
13445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
13465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
13475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
13485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1358