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 * \file  phHal4Nfc_ADD.c
185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief Hal4Nfc_ADD source.
195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: NFC-FRI 1.1
215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Date: Mon May 31 11:43:42 2010 $
235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Author: ing07385 $
245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Revision: 1.151 $
255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Aliases: NFC_FRI1.1_WK1023_R35_1 $
265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* ---------------------------Include files ----------------------------------*/
305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc.h>
315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHal4Nfc.h>
325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHal4Nfc_Internal.h>
335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h>
345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* ------------------------------- Macros ------------------------------------*/
365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define     NFCIP_ACTIVE_SHIFT      0x03U
375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define     NXP_UID                 0x04U
385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define     NXP_MIN_UID_LEN         0x07U
395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* --------------------Structures and enumerations --------------------------*/
405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_ConfigParameters(
425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sHwReference_t     *psHwReference,
435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_eConfigType_t       CfgType,
445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_uConfig_t          *puConfig,
455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pphHal4Nfc_GenCallback_t  pConfigCallback,
465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                     *pContext
475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        )
485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS CfgStatus = NFCSTATUS_SUCCESS;
505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL;
515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*NULL checks*/
525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(NULL == psHwReference
535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || NULL == pConfigCallback
545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || NULL == puConfig
555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER);
595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Check if initialised*/
615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == psHwReference->hal_context)
625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4CurrentState
645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               < eHal4StateOpenAndReady)
655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4NextState
675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               == eHal4StateClosed))
685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt = psHwReference->hal_context;
755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*If previous Configuration request has not completed,do not allow new
765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          configuration*/
775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(Hal4Ctxt->Hal4NextState == eHal4StateConfiguring)
785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:PollCfg in progress.Returning status Busy");
805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_BUSY);
815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if(Hal4Ctxt->Hal4CurrentState >= eHal4StateOpenAndReady)
835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*Allocate ADD context*/
855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NULL == Hal4Ctxt->psADDCtxtInfo)
865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->psADDCtxtInfo= (pphHal4Nfc_ADDCtxtInfo_t)
885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phOsalNfc_GetMemory((uint32_t)
895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (sizeof(phHal4Nfc_ADDCtxtInfo_t)));
905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(NULL != Hal4Ctxt->psADDCtxtInfo)
915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)memset(Hal4Ctxt->psADDCtxtInfo,0,
935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal4Nfc_ADDCtxtInfo_t)
945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NULL == Hal4Ctxt->psADDCtxtInfo)
985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phOsalNfc_RaiseException(phOsalNfc_e_NoMemory,0);
1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                CfgStatus= PHNFCSTVAL(CID_NFC_HAL ,
1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    NFCSTATUS_INSUFFICIENT_RESOURCES);
1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Register Upper layer context*/
106143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#ifdef LLCP_DISCON_CHANGES
107143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCfgDiscCtxt = pContext;
108143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#else /* #ifdef LLCP_DISCON_CHANGES */
1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext;
110143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#endif /* #ifdef LLCP_DISCON_CHANGES */
1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                switch(CfgType)
1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*NFC_EMULATION_CONFIG*/
1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_EMULATION_CONFIG:
1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)memcpy((void *)&Hal4Ctxt->uConfig,
1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)puConfig,
1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal_uConfig_t)
1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*P2P Configuration*/
1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_P2P_CONFIG:
1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*If general bytes are not provided by above layer copy zeros
1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      in general bytes*/
1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if(puConfig->nfcIPConfig.generalBytesLength == 0)
1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
129830ba9657bc2cceac78ea5b285a95560e3329eb4Jan Brands                        Hal4Ctxt->uConfig.nfcIPConfig.generalBytesLength = 0x00;
1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void)memset(Hal4Ctxt->uConfig.nfcIPConfig.generalBytes,
1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    0,Hal4Ctxt->uConfig.nfcIPConfig.generalBytesLength
1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    );
1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    else
1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void)memcpy((void *)&Hal4Ctxt->uConfig,
1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (void *)puConfig,
1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            sizeof(phHal_uConfig_t)
1395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            );
1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Protection config*/
1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_SE_PROTECTION_CONFIG:
1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef IGNORE_EVT_PROTECTED
1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->Ignore_Event_Protected = FALSE;
1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef IGNORE_EVT_PROTECTED*/
1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)memcpy((void *)&Hal4Ctxt->uConfig,
1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)puConfig,
1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal_uConfig_t)
1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    CfgStatus = NFCSTATUS_FAILED;
1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
1585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if ( NFCSTATUS_SUCCESS == CfgStatus )
1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*Issue configure with given configuration*/
1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    CfgStatus = phHciNfc_Configure(
1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (void *)Hal4Ctxt->psHciHandle,
1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (void *)psHwReference,
1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    CfgType,
1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    &Hal4Ctxt->uConfig
1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    );
1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Change the State of the HAL only if status is Pending */
1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if ( NFCSTATUS_PENDING == CfgStatus )
1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Hal4Ctxt->Hal4NextState = eHal4StateConfiguring;
1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Hal4Ctxt->sUpperLayerInfo.pConfigCallback
1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            = pConfigCallback;
1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return CfgStatus;
1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**Configure the discovery*/
1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_ConfigureDiscovery(
1905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sHwReference_t          *psHwReference,
1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_eDiscoveryConfigMode_t   discoveryMode,
1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sADD_Cfg_t              *discoveryCfg,
1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pphHal4Nfc_GenCallback_t       pConfigCallback,
1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                          *pContext
1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        )
1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS CfgStatus = NFCSTATUS_SUCCESS;
1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL;
1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(NULL == psHwReference
2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || NULL == pConfigCallback
2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || NULL == discoveryCfg
2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER);
2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == psHwReference->hal_context)
2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4CurrentState
2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               < eHal4StateOpenAndReady)
2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4NextState
2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               == eHal4StateClosed))
2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt = psHwReference->hal_context;
2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*If previous Configuration request has not completed ,do not allow
2225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          new configuration*/
2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(Hal4Ctxt->Hal4NextState == eHal4StateConfiguring)
2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:PollCfg in progress.Returning status Busy");
2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_BUSY);
2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if(Hal4Ctxt->Hal4CurrentState >= eHal4StateOpenAndReady)
2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NULL == Hal4Ctxt->psADDCtxtInfo)
2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->psADDCtxtInfo= (pphHal4Nfc_ADDCtxtInfo_t)
2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phOsalNfc_GetMemory((uint32_t)
2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (sizeof(phHal4Nfc_ADDCtxtInfo_t)));
2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(NULL != Hal4Ctxt->psADDCtxtInfo)
2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)memset(Hal4Ctxt->psADDCtxtInfo,0,
2385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal4Nfc_ADDCtxtInfo_t)
2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NULL == Hal4Ctxt->psADDCtxtInfo)
2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phOsalNfc_RaiseException(phOsalNfc_e_NoMemory,0);
2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                CfgStatus= PHNFCSTVAL(CID_NFC_HAL ,
2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    NFCSTATUS_INSUFFICIENT_RESOURCES);
2475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Register Upper layer context*/
251143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#ifdef LLCP_DISCON_CHANGES
252143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCfgDiscCtxt = pContext;
253143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#else /* #ifdef LLCP_DISCON_CHANGES */
2545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext;
255143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#endif /* #ifdef LLCP_DISCON_CHANGES */
2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                switch(discoveryMode)
2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_DISCOVERY_START:
2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Call to NFC_DISCOVERY_START");
2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_DISCOVERY_CONFIG:
2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Call to NFC_DISCOVERY_CONFIG");
2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*Since sADDCfg is allocated in stack ,copy the ADD
2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                      configuration structure to HAL4 context*/
2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)memcpy((void *)
2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &(Hal4Ctxt->psADDCtxtInfo->sADDCfg),
2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)discoveryCfg,
2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal_sADD_Cfg_t)
2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Finished copying sADDCfg");
2715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psADDCtxtInfo->smx_discovery = FALSE;
2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef UPDATE_NFC_ACTIVE
2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psADDCtxtInfo->sADDCfg.PollDevInfo.PollCfgInfo.EnableNfcActive
2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        = ( 0 == Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode?
2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode:
2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           NXP_NFCIP_ACTIVE_DEFAULT);
2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode = ((
2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode <<
2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (NXP_NFCIP_ACTIVE_DEFAULT * NFCIP_ACTIVE_SHIFT))
2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    | Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode);
2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef UPDATE_NFC_ACTIVE*/
2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* information system_code(Felica) and
2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    AFI(ReaderB) to be populated later */
2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    CfgStatus = phHciNfc_Config_Discovery(
2865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)Hal4Ctxt->psHciHandle,
2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)psHwReference,
2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &(Hal4Ctxt->psADDCtxtInfo->sADDCfg)
2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );/*Configure HCI Discovery*/
2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_DISCOVERY_STOP:
2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Restart Discovery wheel*/
2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_DISCOVERY_RESUME:
2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Call to NFC_DISCOVERY_RESUME");
2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    CfgStatus = phHciNfc_Restart_Discovery (
2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (void *)Hal4Ctxt->psHciHandle,
2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (void *)psHwReference,
3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    FALSE
3015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    );
3025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
3035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
3045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
3055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
3065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Change the State of the HAL only if HCI Configure
3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                   Returns status as Pending */
3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if ( NFCSTATUS_PENDING == CfgStatus )
3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)memcpy((void *)
3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &(Hal4Ctxt->psADDCtxtInfo->sCurrentPollConfig),
3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)&(discoveryCfg->PollDevInfo.PollCfgInfo),
3135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal_sPollDevInfo_t)
3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
3155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Finished copying PollCfgInfo");
3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Configure returned NFCSTATUS_PENDING");
3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->Hal4NextState = eHal4StateConfiguring;
3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->sUpperLayerInfo.pConfigCallback
3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        = pConfigCallback;
3205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
3215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else/*Configure failed.Restore old poll dev info*/
3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)memcpy((void *)
3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &(Hal4Ctxt->psADDCtxtInfo->sADDCfg.PollDevInfo.PollCfgInfo),
3255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)&(Hal4Ctxt->psADDCtxtInfo->sCurrentPollConfig),
3265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal_sPollDevInfo_t)
3275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
3285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
3295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
3305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
3325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
3345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
3355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return CfgStatus;
3385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Configuration completion handler*/
3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phHal4Nfc_ConfigureComplete(phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                 void                  *pInfo,
3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                 uint8_t                type
3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                 )
3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pphHal4Nfc_GenCallback_t    pConfigCallback
3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                = Hal4Ctxt->sUpperLayerInfo.pConfigCallback;
3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    pphHal4Nfc_ConnectCallback_t pUpperConnectCb
3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    = Hal4Ctxt->sTgtConnectInfo.pUpperConnectCb;
3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS Status = ((phNfc_sCompletionInfo_t *)pInfo)->status;
3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if((type == NFC_NOTIFY_POLL_ENABLED) ||(type == NFC_NOTIFY_POLL_RESTARTED))
3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt->psADDCtxtInfo->IsPollConfigured = TRUE;
3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PHDBG_INFO("Hal4:Poll Config Complete");
3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt->psADDCtxtInfo->IsPollConfigured = FALSE;
3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PHDBG_WARNING("Hal4:Poll disabled,config success or config error");
3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(NULL != Hal4Ctxt->sUpperLayerInfo.pConfigCallback)
3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef MERGE_SAK_SW2
3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if((NFC_UICC_EMULATION == Hal4Ctxt->uConfig.emuConfig.emuType)&&
3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly           (FALSE ==
3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->uConfig.emuConfig.config.uiccEmuCfg.enableUicc))
3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Status = phHciNfc_System_Configure (
3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                Hal4Ctxt->psHciHandle,
3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (void *)gpphHal4Nfc_Hwref,
3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_HAL4NFC_TGT_MERGE_ADDRESS,
3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                PH_HAL4NFC_TGT_MERGE_SAK /*config value*/
3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
3755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NFCSTATUS_PENDING != Status)
3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef MERGE_SAK_SW2*/
3795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->Hal4NextState = eHal4StateInvalid;
3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.pConfigCallback = NULL;
3815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (*pConfigCallback)(
382143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#ifdef LLCP_DISCON_CHANGES
383143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCfgDiscCtxt,
384143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#else /* #ifdef LLCP_DISCON_CHANGES */
385143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
386143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas#endif /* #ifdef LLCP_DISCON_CHANGES */
387143acf0b768ce3c2f61de2add5ca339479defd57daniel_Tomas                Status
3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                );
3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef MERGE_SAK_SW2
3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef MERGE_SAK_SW2*/
3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /**if connect failed and discovery wheel was restarted*/
3945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(Hal4Ctxt->sTgtConnectInfo.pUpperConnectCb)
3955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt->Hal4NextState = eHal4StateInvalid;
3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt->sTgtConnectInfo.pUpperConnectCb = NULL;
3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Notify to the upper layer*/
3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (*pUpperConnectCb)(
4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sTgtConnectInfo.psConnectedDevice,
4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            NFCSTATUS_FAILED
4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            );
4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt->Hal4NextState = eHal4StateInvalid;
4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /**if disconnect failed and discovery wheel was restarted*/
4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if ( NULL != Hal4Ctxt->sTgtConnectInfo.pUpperDisconnectCb)
4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            ((phNfc_sCompletionInfo_t *)pInfo)->status = NFCSTATUS_SUCCESS;
4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phHal4Nfc_DisconnectComplete(Hal4Ctxt,pInfo);
4135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**Handler for Target discovery completion for all remote device types*/
4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phHal4Nfc_TargetDiscoveryComplete(
4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       void                  *pInfo
4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       )
4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    static phHal4Nfc_DiscoveryInfo_t sDiscoveryInfo;
4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS status = NFCSTATUS_SUCCESS;
4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /**SAK byte*/
4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t Sak = 0;
4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Union type to encapsulate and return the discovery info*/
4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal4Nfc_NotificationInfo_t uNotificationInfo;
4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*All the following types will be discovered as type A ,and differentiation
4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      will have to be done within this module based on SAK byte and UID info*/
4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal_eRemDevType_t  aRemoteDevTypes[3] = {
4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               phHal_eISO14443_A_PICC,
4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               phHal_eNfcIP1_Target,
4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               phHal_eMifare_PICC
4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                              };
4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Count is used to add multiple info into remote dvice list for devices that
4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      support multiple protocols*/
4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t Count = 0,
4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        NfcIpDeviceCount = 0;/**<Number of NfcIp devices discovered*/
4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint16_t nfc_id = 0;
4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*remote device info*/
4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal_sRemoteDevInformation_t *psRemoteDevInfo = NULL;
4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    status = ((phNfc_sCompletionInfo_t *)pInfo)->status;
4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /*Update Hal4 state*/
4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    Hal4Ctxt->Hal4CurrentState = eHal4StateTargetDiscovered;
4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    Hal4Ctxt->Hal4NextState  = eHal4StateInvalid;
4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly     PHDBG_INFO("Hal4:Remotedevice Discovered");
4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(NULL != ((phNfc_sCompletionInfo_t *)pInfo)->info)
4505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Extract Remote device Info*/
4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psRemoteDevInfo = (phHal_sRemoteDevInformation_t *)
4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    ((phNfc_sCompletionInfo_t *)pInfo)->info;
4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        switch(psRemoteDevInfo->RemDevType)
4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phHal_eISO14443_A_PICC:/*for TYPE A*/
4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Sak = psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak;
4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if((Hal4Ctxt->psADDCtxtInfo->sCurrentPollConfig.EnableIso14443A)
4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    || (TRUE == Hal4Ctxt->psADDCtxtInfo->smx_discovery))
4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*Check if Iso is Supported*/
4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if(Sak & ISO_14443_BITMASK)
4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Count++;
4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*Check for Mifare Supported*/
4690cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                    switch( Sak )
4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
471eb6da80b266a263350769a0e5629f4089aad32bbSunil Jogi                      case 0x01: // 1K Classic
4720cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0x09: // Mini
4730cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0x08: // 1K
4740cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0x18: // 4K
4750cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0x88: // Infineon 1K
4760cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0x98: // Pro 4K
4770cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0xB8: // Pro 4K
4780cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0x28: // 1K emulation
4790cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                      case 0x38: // 4K emulation
4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        aRemoteDevTypes[Count] = phHal_eMifare_PICC;
4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Count++;
4820cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                        break;
4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
4840cdd303a6e2ad061d6b59649988ed489859333f6Jan Brands                    if((0 == Sak)&& (0 == Count))
4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        /*Mifare check*/
4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        if((NXP_UID ==
4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Uid[0])
4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &&(NXP_MIN_UID_LEN <=
4905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.UidLength))
4915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        {
4925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            aRemoteDevTypes[Count] = phHal_eMifare_PICC;
49397ffda519d438861f34d6de511f9025656470af6Martijn Coenen                            Count++;
4945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        }
4955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
4969e987ccb716624d658f98abc7db2097e11e3d8edMartijn Coenen                    // Always add a separate 3A target on a separate
4979e987ccb716624d658f98abc7db2097e11e3d8edMartijn Coenen                    // handle, so the upper layers can connect to it.
4989e987ccb716624d658f98abc7db2097e11e3d8edMartijn Coenen                    aRemoteDevTypes[Count] = phHal_eISO14443_3A_PICC;
4999e987ccb716624d658f98abc7db2097e11e3d8edMartijn Coenen                    Count++;
5005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Check for P2P target passive*/
5025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if((Sak & NFCIP_BITMASK) &&
5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (NULL != Hal4Ctxt->sUpperLayerInfo.pP2PNotification)&&
5045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode
5055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    & phHal_ePassive106))
5065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
50756075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                  if( Sak == 0x53 // Fudan card incompatible to ISO18092
50856075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                      && psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.AtqA[0] == 0x04
50956075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                      && psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.AtqA[1] == 0x00
51056075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                    )
51156075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                  {
51256075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                    aRemoteDevTypes[Count] = phHal_eISO14443_3A_PICC;
51356075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                    Count++;
51456075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                  }
51556075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                  else
51656075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands                  {
5175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    aRemoteDevTypes[Count] = phHal_eNfcIP1_Target;
5185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Count++;
51956075a1341b42c55a472ff6213c98b0e3c1bfdbbJan Brands									}
5205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/*case phHal_eISO14443_A_PICC:*/
5225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phHal_eNfcIP1_Target:/*P2P target detected*/
5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                aRemoteDevTypes[Count] = phHal_eNfcIP1_Target;
5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Count++;
5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly             case phHal_eISO14443_B_PICC: /*TYPE_B*/
5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B
5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                aRemoteDevTypes[Count] = phHal_eISO14443_B_PICC;
5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Count++;
5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phHal_eFelica_PICC: /*Felica*/
5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_FELICA
5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*nfc_id is used to differentiate between Felica and NfcIp target
5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  discovered in Type F*/
5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                nfc_id = (((uint16_t)psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm[0])
5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    << BYTE_SIZE) |
5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm[1];
5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*check  for NfcIp target*/
5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(NXP_NFCIP_NFCID2_ID  == nfc_id)
5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if((NULL != Hal4Ctxt->sUpperLayerInfo.pP2PNotification)
5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        &&((Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode
5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                             & phHal_ePassive212) ||
5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (Hal4Ctxt->psADDCtxtInfo->sADDCfg.NfcIP_Mode
5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                             & phHal_ePassive424)))
5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        aRemoteDevTypes[Count] = phHal_eNfcIP1_Target;
5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Count++;
5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
5535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else/*Felica*/
5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if(Hal4Ctxt->psADDCtxtInfo->sCurrentPollConfig.EnableFelica212
5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    || Hal4Ctxt->psADDCtxtInfo->sCurrentPollConfig.EnableFelica424)
5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        aRemoteDevTypes[Count] = phHal_eFelica_PICC;
5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Count++;
5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phHal_eJewel_PICC: /*Jewel*/
5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_JEWEL
5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Report Jewel tags only if TYPE A is enabled*/
5705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(Hal4Ctxt->psADDCtxtInfo->sCurrentPollConfig.EnableIso14443A)
5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    aRemoteDevTypes[Count] = phHal_eJewel_PICC;
5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Count++;
5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef  TYPE_ISO15693
5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phHal_eISO15693_PICC: /*ISO15693*/
5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(Hal4Ctxt->psADDCtxtInfo->sCurrentPollConfig.EnableIso15693)
5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    aRemoteDevTypes[Count] = phHal_eISO15693_PICC;
5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Count++;
5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef    TYPE_ISO15693 */
5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*Types currently not supported*/
5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case phHal_eISO14443_BPrime_PICC:
5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            default:
5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PHDBG_WARNING("Hal4:Notification for Not supported types");
5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/*End of switch*/
5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Update status code to success if atleast one device info is available*/
5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = (((NFCSTATUS_SUCCESS != status)
5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  && (NFCSTATUS_MULTIPLE_TAGS != status))
5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                   &&(Hal4Ctxt->psADDCtxtInfo->nbr_of_devices != 0))?
5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    NFCSTATUS_SUCCESS:status;
6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Update status to NFCSTATUS_MULTIPLE_PROTOCOLS if count > 1 ,and this
6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          is first discovery notification from Hci*/
6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = ((NFCSTATUS_SUCCESS == status)
6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    &&(Hal4Ctxt->psADDCtxtInfo->nbr_of_devices == 0)
6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    &&(Count > 1)?NFCSTATUS_MULTIPLE_PROTOCOLS:status);
6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         /*If multiple protocols are supported ,allocate separate remote device
6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          information for each protocol supported*/
6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Allocate and copy Remote device info into Hal4 Context*/
6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        while(Count)
6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Count is not zero");
6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            --Count;
6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*Allocate memory for each of Count number of
6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly              devices*/
6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NULL == Hal4Ctxt->rem_dev_list[
6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->psADDCtxtInfo->nbr_of_devices])
6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->rem_dev_list[
6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psADDCtxtInfo->nbr_of_devices]
6205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                = (phHal_sRemoteDevInformation_t *)
6215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phOsalNfc_GetMemory(
6225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (uint32_t)(
6235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sizeof(phHal_sRemoteDevInformation_t))
6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    );
6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NULL == Hal4Ctxt->rem_dev_list[
6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->psADDCtxtInfo->nbr_of_devices])
6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status =  PHNFCSTVAL(CID_NFC_HAL,
6305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    NFCSTATUS_INSUFFICIENT_RESOURCES);
6315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phOsalNfc_RaiseException(phOsalNfc_e_NoMemory,0);
6325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
6335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (void)memcpy(
6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void *)Hal4Ctxt->rem_dev_list[
6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Hal4Ctxt->psADDCtxtInfo->nbr_of_devices],
6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)psRemoteDevInfo,
6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        sizeof(phHal_sRemoteDevInformation_t)
6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Now copy appropriate device type from aRemoteDevTypes array*/
6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->rem_dev_list[
6445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Hal4Ctxt->psADDCtxtInfo->nbr_of_devices]->RemDevType
6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            =   aRemoteDevTypes[Count];
6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Increment number of devices*/
6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->psADDCtxtInfo->nbr_of_devices++;
6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/*End of else*/
6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/*End of while*/
6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*If Upper layer is interested only in P2P notifications*/
6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if((NULL != Hal4Ctxt->sUpperLayerInfo.pP2PNotification)
6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly           &&(((Hal4Ctxt->psADDCtxtInfo->nbr_of_devices == 1)
6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly              &&(phHal_eNfcIP1_Target == Hal4Ctxt->rem_dev_list[0]->RemDevType))
6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly              ||(NULL == Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification))
6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            )
6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Trying to notify P2P Listener");
6595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*NFCSTATUS_SUCCESS or NFCSTATUS_MULTIPLE_PROTOCOLS*/
6605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if((NFCSTATUS_SUCCESS == status)
6615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                ||(NFCSTATUS_MULTIPLE_PROTOCOLS == status))
6625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Pick only the P2P target device info from the list*/
6645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                for(Count = Hal4Ctxt->psADDCtxtInfo->nbr_of_devices;
6655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Count > 0;--Count)
6665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*Only one P2P target can be detected in one discovery*/
6685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if(phHal_eNfcIP1_Target ==
6695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Hal4Ctxt->rem_dev_list[Count-1]->RemDevType)
6705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
6719acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                        if (Count != 1)
6729acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                        {
6739acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                            (void)memcpy(
6749acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                                (void *)Hal4Ctxt->rem_dev_list[0],
6759acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                                (void *)Hal4Ctxt->rem_dev_list[Count-1],
6769acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                                        sizeof(phHal_sRemoteDevInformation_t)
6779acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                                        );
6789acc2486787ee83b436b2999cd27f7b1ffb9fd69Nick Kralevich                        }
6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NfcIpDeviceCount = 1;
6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        break;
6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*If any P2p devices are discovered free other device info*/
6845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                while(Hal4Ctxt->psADDCtxtInfo->nbr_of_devices > NfcIpDeviceCount)
6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phOsalNfc_FreeMemory(Hal4Ctxt->rem_dev_list[
6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        --Hal4Ctxt->psADDCtxtInfo->nbr_of_devices]);
6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->rem_dev_list[
6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Hal4Ctxt->psADDCtxtInfo->nbr_of_devices] = NULL;
6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /*Issue P2P notification*/
6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(NfcIpDeviceCount == 1)
6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sDiscoveryInfo.NumberOfDevices
6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        = Hal4Ctxt->psADDCtxtInfo->nbr_of_devices;
6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sDiscoveryInfo.ppRemoteDevInfo = Hal4Ctxt->rem_dev_list;
6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uNotificationInfo.psDiscoveryInfo = &sDiscoveryInfo;
6985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Calling P2P listener");
6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (*Hal4Ctxt->sUpperLayerInfo.pP2PNotification)(
7005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (void *)(Hal4Ctxt->sUpperLayerInfo.P2PDiscoveryCtxt),
7015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFC_DISCOVERY_NOTIFICATION,
7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            uNotificationInfo,
7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFCSTATUS_SUCCESS
7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            );
7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
7065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else/*Restart Discovery wheel*/
7075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:No P2P device in list");
7095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
7105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Restart discovery1");
7115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_Restart_Discovery (
7125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (void *)Hal4Ctxt->psHciHandle,
7135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (void *)gpphHal4Nfc_Hwref,
7145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        FALSE
7155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        );
7165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->Hal4NextState = (NFCSTATUS_PENDING == status?
7175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                        eHal4StateConfiguring:
7185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    Hal4Ctxt->Hal4NextState);
7195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
7205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*More discovery info available ,get next info from HCI*/
7225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else if((NFCSTATUS_MULTIPLE_TAGS == status)
7235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                &&(Hal4Ctxt->psADDCtxtInfo->nbr_of_devices
7245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     < MAX_REMOTE_DEVICES))
7255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_Select_Next_Target (
7275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->psHciHandle,
7285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void *)gpphHal4Nfc_Hwref
7295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    );
7305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else/*Failed discovery ,restart discovery*/
7325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PHDBG_INFO("Hal4:Restart discovery2");
7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_Restart_Discovery (
7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (void *)Hal4Ctxt->psHciHandle,
7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (void *)gpphHal4Nfc_Hwref,
7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        FALSE
7395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        );/*Restart Discovery wheel*/
7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->Hal4NextState = (NFCSTATUS_PENDING == status?
7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                eHal4StateConfiguring:
7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                Hal4Ctxt->Hal4NextState);
7435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/*if((NULL != Hal4Ctxt->sUpperLayerInfo.pP2PNotification)...*/
7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Notify if Upper layer is interested in tag notifications,also notify
7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          P2p if its in the list with other tags*/
7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else if(NULL != Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification)
7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Trying to notify Tag notification");
7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*Multiple tags in field, get discovery info a second time for the
7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly              other devices*/
7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if((NFCSTATUS_MULTIPLE_TAGS == status)
7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                &&(Hal4Ctxt->psADDCtxtInfo->nbr_of_devices < MAX_REMOTE_DEVICES))
7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PHDBG_INFO("Hal4:select next target1");
7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_Select_Next_Target (
7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    Hal4Ctxt->psHciHandle,
7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    (void *)gpphHal4Nfc_Hwref
7595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    );
7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*Single tag multiple protocols scenario,Notify Multiple Protocols
7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly              status to upper layer*/
7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else if(status == NFCSTATUS_MULTIPLE_PROTOCOLS)
7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                PHDBG_INFO("Hal4:Multiple Tags or protocols");
7665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                sDiscoveryInfo.NumberOfDevices
7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    = Hal4Ctxt->psADDCtxtInfo->nbr_of_devices;
7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                sDiscoveryInfo.ppRemoteDevInfo = Hal4Ctxt->rem_dev_list;
7695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                uNotificationInfo.psDiscoveryInfo = &sDiscoveryInfo;
7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (*Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification)(
7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            (void *)(Hal4Ctxt->sUpperLayerInfo.DiscoveryCtxt),
7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFC_DISCOVERY_NOTIFICATION,
7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            uNotificationInfo,
7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            status
7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            );
7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else /*NFCSTATUS_SUCCESS*/
7785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(((Hal4Ctxt->psADDCtxtInfo->nbr_of_devices == 1)
7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     &&(phHal_eNfcIP1_Target
7815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     == Hal4Ctxt->rem_dev_list[0]->RemDevType))
7825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     ||(NFCSTATUS_SUCCESS != status)
7835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     || (Hal4Ctxt->psADDCtxtInfo->nbr_of_devices == 0)
7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )/*device detected but upper layer is not interested
7855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       in the type(P2P) or activate next failed*/
7865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
7875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    while(Hal4Ctxt->psADDCtxtInfo->nbr_of_devices > 0)
7885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
7895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phOsalNfc_FreeMemory(Hal4Ctxt->rem_dev_list[
7905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            --Hal4Ctxt->psADDCtxtInfo->nbr_of_devices]);
7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Hal4Ctxt->rem_dev_list[
7925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            Hal4Ctxt->psADDCtxtInfo->nbr_of_devices] = NULL;
7935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
7945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Restart discovery3");
7955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_Restart_Discovery (
7965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)Hal4Ctxt->psHciHandle,
7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)gpphHal4Nfc_Hwref,
7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        FALSE
7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );/*Restart Discovery wheel*/
8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    Hal4Ctxt->Hal4NextState = (
8015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NFCSTATUS_PENDING == status?eHal4StateConfiguring
8025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    :Hal4Ctxt->Hal4NextState
8035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    );
8045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
8055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else/*All remote device info available.Notify to upper layer*/
8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*Update status for MULTIPLE_TAGS here*/
8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = (Hal4Ctxt->psADDCtxtInfo->nbr_of_devices > 1?
8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_MULTIPLE_TAGS:status);
8105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /*If listener is registered ,call it*/
8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sDiscoveryInfo.NumberOfDevices
8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        = Hal4Ctxt->psADDCtxtInfo->nbr_of_devices;
8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sDiscoveryInfo.ppRemoteDevInfo
8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        = Hal4Ctxt->rem_dev_list;
8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uNotificationInfo.psDiscoveryInfo = &sDiscoveryInfo;
8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    PHDBG_INFO("Hal4:Calling Discovery Handler1");
8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (*Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification)(
8185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        (void *)(Hal4Ctxt->sUpperLayerInfo.DiscoveryCtxt),
8195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NFC_DISCOVERY_NOTIFICATION,
8205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        uNotificationInfo,
8215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        status
8225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
8235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
8245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        } /*else if(NULL != Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification)*/
8265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else/*listener not registered ,Restart Discovery wheel*/
8275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:No listener registered.Ignoring Discovery  \
8295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        Notification");
8305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Restart discovery4");
8325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Restart_Discovery (
8335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (void *)Hal4Ctxt->psHciHandle,
8345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (void *)gpphHal4Nfc_Hwref,
8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                FALSE
8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                );
8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->Hal4NextState = (NFCSTATUS_PENDING == status?
8385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                eHal4StateConfiguring:
8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            Hal4Ctxt->Hal4NextState);
8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }/*if(NULL != ((phNfc_sCompletionInfo_t *)pInfo)->info)*/
8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else/*NULL info received*/
8435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        sDiscoveryInfo.NumberOfDevices
8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            = Hal4Ctxt->psADDCtxtInfo->nbr_of_devices;
8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        sDiscoveryInfo.ppRemoteDevInfo = Hal4Ctxt->rem_dev_list;
8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uNotificationInfo.psDiscoveryInfo = &sDiscoveryInfo;
8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*If Discovery info is available from previous notifications try to
8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          notify that to the upper layer*/
8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if((NULL != Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification)
8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef NFC_RF_NOISE_SW
8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly          &&((NFCSTATUS_SUCCESS == status)
8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            || (NFCSTATUS_MULTIPLE_TAGS == status))
8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef NFC_RF_NOISE_SW */
8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            )
8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef NFC_RF_NOISE_SW
8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = (((NFCSTATUS_SUCCESS != status)
8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  && (NFCSTATUS_MULTIPLE_TAGS != status))
8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                   &&(Hal4Ctxt->psADDCtxtInfo->nbr_of_devices != 0))?
8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    NFCSTATUS_SUCCESS:status;
8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifndef NFC_RF_NOISE_SW*/
8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Calling Discovery Handler2");
8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (*Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification)(
8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (void *)(Hal4Ctxt->sUpperLayerInfo.DiscoveryCtxt),
8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                NFC_DISCOVERY_NOTIFICATION,
8675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                uNotificationInfo,
8685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status
8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                );
8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else/*Restart Discovery wheel*/
8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Restart discovery5");
8755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Restart_Discovery (
8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (void *)Hal4Ctxt->psHciHandle,
8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (void *)gpphHal4Nfc_Hwref,
8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                FALSE
8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                );
8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->Hal4NextState = (NFCSTATUS_PENDING == status?
8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   eHal4StateConfiguring:Hal4Ctxt->Hal4NextState);
8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }/*else*/
8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return;
8855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
8865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**Register Notification handlers*/
8895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_RegisterNotification(
8905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sHwReference_t         *psHwReference,
8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal4Nfc_RegisterType_t      eRegisterType,
8925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pphHal4Nfc_Notification_t     pNotificationHandler,
8935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                         *Context
8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        )
8955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetStatus = NFCSTATUS_SUCCESS;
8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL;
8985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(NULL == pNotificationHandler || NULL == psHwReference)
8995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
9015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER);
9025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == psHwReference->hal_context)
9045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
9055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4CurrentState
9065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               < eHal4StateOpenAndReady)
9075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
9085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4NextState
9095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               == eHal4StateClosed))
9105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
9125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
9135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
9155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Extract context from hardware reference*/
9175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)psHwReference->hal_context;
9185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        switch(eRegisterType)
9195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
9205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case eRegisterTagDiscovery:
9215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.DiscoveryCtxt = Context;
9225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification
9235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    = pNotificationHandler;  /*Register the tag Notification*/
9245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
9255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case eRegisterP2PDiscovery:
9265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.P2PDiscoveryCtxt = Context;
9275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.pP2PNotification
9285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    = pNotificationHandler;  /*Register the P2P Notification*/
9295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
9305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case eRegisterHostCardEmulation:
9315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                RetStatus = NFCSTATUS_FEATURE_NOT_SUPPORTED;
9325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
9335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case eRegisterSecureElement:
9345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.EventNotificationCtxt = Context;
9355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.pEventNotification
9365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       = pNotificationHandler; /*Register the Se Notification*/
9375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
9385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            default:
9395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.DefaultListenerCtxt = Context;
9405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler
9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    = pNotificationHandler;  /*Register the default Notification*/
9425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
9435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
9445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        PHDBG_INFO("Hal4:listener registered");
9455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetStatus;
9475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
9485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**Unregister Notification handlers*/
9515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_UnregisterNotification(
9525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  phHal_sHwReference_t     *psHwReference,
9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  phHal4Nfc_RegisterType_t  eRegisterType,
9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  void                     *Context
9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  )
9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS RetStatus = NFCSTATUS_SUCCESS;
9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL;
9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if(psHwReference == NULL)
9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER);
9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if((NULL == psHwReference->hal_context)
9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4CurrentState
9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               < eHal4StateOpenAndReady)
9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        || (((phHal4Nfc_Hal4Ctxt_t *)
9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHwReference->hal_context)->Hal4NextState
9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               == eHal4StateClosed))
9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        RetStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /*Extract context from hardware reference*/
9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)psHwReference->hal_context;
9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        switch(eRegisterType)
9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case eRegisterTagDiscovery:
9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = Context;
9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.DiscoveryCtxt = NULL;
9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*UnRegister the tag Notification*/
9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification = NULL;
9865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Tag Discovery Listener Unregistered");
9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case eRegisterP2PDiscovery:
9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.P2PDiscoveryCtxt = NULL;
9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*UnRegister the p2p Notification*/
9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.pP2PNotification = NULL;
9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:P2P Discovery Listener Unregistered");
9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case eRegisterHostCardEmulation:/*RFU*/
9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            RetStatus = NFCSTATUS_FEATURE_NOT_SUPPORTED;
9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*UnRegister the Se Notification*/
9985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        case eRegisterSecureElement:
9995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.EventNotificationCtxt = NULL;
10005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.pEventNotification = NULL;
10015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:SE Listener Unregistered");
10025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
10035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        default:
10045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.DefaultListenerCtxt = NULL;
10055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*UnRegister the default Notification*/
10065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler = NULL;
10075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            PHDBG_INFO("Hal4:Default Listener Unregistered");
10085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            break;
10095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
10105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
10115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return RetStatus;
10125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
10135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1015