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.c 185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief Hal4Nfc source. 195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: NFC-FRI 1.1 215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Date: Fri Jun 11 09:32:23 2010 $ 235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Author: ing07385 $ 245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Revision: 1.192 $ 255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Aliases: NFC_FRI1.1_WK1023_R35_1 $ 265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* ---------------------------Include files ---------------------------------*/ 305e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHal4Nfc.h> 325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHal4Nfc_Internal.h> 335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h> 345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc.h> 355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLlcNfc.h> 365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc.h> 375e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#include <phDnldNfc.h> 385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc_Timer.h> 395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* ------------------------------- Macros -----------------------------------*/ 415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef HAL_UNIT_TEST 425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define STATIC static 435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else 445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define STATIC 455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifndef UNIT_TEST*/ 465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define HAL4_LAYERS 3 475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define LAYER_HCI 2 485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define LAYER_LLC 1 495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define LAYER_DAL 0 505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* --------------------Structures and enumerations --------------------------*/ 525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHal_sHwReference_t *gpphHal4Nfc_Hwref; 545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_IoctlComplete( 565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_LowerNotificationHandler( 615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext, 625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pHwRef, 635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t type, 645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_HandleEvent( 675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_OpenComplete( 725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_CloseComplete( 775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 815e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomasstatic void phHal4Nfc_DownloadComplete( 825e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas void *pContext, 835e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas void *pHwRef, 845e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas uint8_t type, 855e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas void *pInfo 865e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas ); 875e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic NFCSTATUS phHal4Nfc_Configure_Layers( 895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfcLayer_sCfg_t **pphLayer 905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Callback for Self tests*/ 945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_SelfTestComplete( 955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * The open callback function to be called by the HCI when open (initializaion) 1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * sequence is completed or if there is an error in initialization. 1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * It is passed as a parameter to HCI when calling HCI Init. 1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_OpenComplete( 1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = ((phNfc_sCompletionInfo_t *)pInfo)->status; 1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_GenCallback_t pUpper_OpenCb 1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = Hal4Ctxt->sUpperLayerInfo.pUpperOpenCb; 1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pUpper_Context 1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt; 1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status == NFCSTATUS_SUCCESS) 1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Open Successful"); 1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef MERGE_SAK_SW1 /*Software Workaround*/ 1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(eHal4StateOpenAndReady == Hal4Ctxt->Hal4NextState) 1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phHciNfc_System_Configure ( 1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle, 1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)gpphHal4Nfc_Hwref, 1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PH_HAL4NFC_TGT_MERGE_ADDRESS, 1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PH_HAL4NFC_TGT_MERGE_SAK /*config value*/ 1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NFCSTATUS_PENDING != status) 1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef MERGE_SAK_SW1*/ 1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Update State*/ 1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4CurrentState = Hal4Ctxt->Hal4NextState; 1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pUpperOpenCb = NULL; 1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != pUpper_OpenCb) 1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Upper layer's Open Cb*/ 1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pUpper_OpenCb)(Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt, 1395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_SUCCESS 1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else/*Open did not succeed.Go back to reset state*/ 1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4CurrentState = eHal4StateClosed; 1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle = NULL; 1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory((void *)Hal4Ctxt->pHal4Nfc_LayerCfg); 1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->pHal4Nfc_LayerCfg = NULL; 1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory((void *)Hal4Ctxt); 1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref->hal_context = NULL; 1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref = NULL; 1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Open Failed"); 1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call upper layer's Open Cb with error status*/ 1566dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren if(NULL != pUpper_OpenCb) 1576dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren { 1586dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren /*Upper layer's Open Cb*/ 1596dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren (*pUpper_OpenCb)(pUpper_Context,status); 1606dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren } 1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * The close callback function called by the HCI when close sequence is 1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * completed or if there is an error in closing. 1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * It is passed as a parameter to HCI when calling HCI Release. 1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_CloseComplete( 1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status= ((phNfc_sCompletionInfo_t *)pInfo)->status; 1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_GenCallback_t pUpper_CloseCb; 1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pUpper_Context; 1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t RemoteDevNumber = 0; 1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pUpper_CloseCb = Hal4Ctxt->sUpperLayerInfo.pUpperCloseCb; 1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pUpper_Context = Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt; 1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Update state*/ 1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4CurrentState = Hal4Ctxt->Hal4NextState; 1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*If Closed successfully*/ 1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NFCSTATUS_SUCCESS == status) 1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle = NULL; 1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Free all heap allocations*/ 1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory((void *)Hal4Ctxt->pHal4Nfc_LayerCfg); 1905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->pHal4Nfc_LayerCfg = NULL; 1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Free ADD context info*/ 1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psADDCtxtInfo) 1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly while(RemoteDevNumber < MAX_REMOTE_DEVICES) 1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->rem_dev_list[RemoteDevNumber]) 1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory((void *) 1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (Hal4Ctxt->rem_dev_list[RemoteDevNumber])); 2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->rem_dev_list[RemoteDevNumber] = NULL; 2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RemoteDevNumber++; 2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0; 2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->psADDCtxtInfo); 2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*if(NULL != Hal4Ctxt->psADDCtxtInfo)*/ 2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Free Trcv context info*/ 2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psTrcvCtxtInfo) 2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psTrcvCtxtInfo->sLowerRecvData.buffer) 2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory( 2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psTrcvCtxtInfo->sLowerRecvData.buffer 2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((NULL == Hal4Ctxt->sTgtConnectInfo.psConnectedDevice) 2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && (NULL != Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData)) 2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData); 2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo); 2225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*if(NULL != Hal4Ctxt->psTrcvCtxtInfo)*/ 2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Free Hal context and Hardware reference*/ 2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref->hal_context = NULL; 2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref = NULL; 2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory((void *)Hal4Ctxt); 2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/* if(NFCSTATUS_SUCCESS == status)*/ 2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call Upper layer's Close Cb with status*/ 2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pUpper_CloseCb)(pUpper_Context,status); 2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* 2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* For configuring the various layers during the Initialization call 2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 2385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic 2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS 2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHal4Nfc_Configure_Layers( 2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfcLayer_sCfg_t **pphLayer 2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index = HAL4_LAYERS - 1; 2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t i = 0; 2475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS ; 2485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Configuring layers"); 2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *pphLayer = (phNfcLayer_sCfg_t *) phOsalNfc_GetMemory( 2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sizeof(phNfcLayer_sCfg_t) * HAL4_LAYERS); 2515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( NULL == *pphLayer) 2535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = PHNFCSTVAL(CID_NFC_HAL, 2555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_INSUFFICIENT_RESOURCES);/*Memory allocation error*/ 2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void)memset((void *)*pphLayer,0,( 2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sizeof(phNfcLayer_sCfg_t) * HAL4_LAYERS)); 2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(i=0 ; i < HAL4_LAYERS ;i++, index-- ) 2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer + i)->layer_index = index; 2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(index) 2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case LAYER_HCI: /*Configure Hci*/ 2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_name =(uint8_t *) "Hci"; 2715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_registry = NULL; 2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_next = 2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (((phNfcLayer_sCfg_t *)*pphLayer) + i + 1); 2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case LAYER_LLC:/*Configure LLC*/ 2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_registry = phLlcNfc_Register; 2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_name = (uint8_t *)"Llc"; 2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_next = 2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (((phNfcLayer_sCfg_t *)*pphLayer) + i + 1); 2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case LAYER_DAL: /*Configure the DAL*/ 2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_registry = phDal4Nfc_Register; 2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_name = (uint8_t *)"Dal"; 2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pphLayer+i)->layer_next = NULL ; 2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } /* End of Switch */ 2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } /* End of For Loop */ 2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } /* End of NULL Check */ 2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status ; 2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3015e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3025e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#ifdef ANDROID 3035e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3045e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#define LOG_TAG "NFC-HCI" 3055e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3065e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#include <utils/Log.h> 3075e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#include <dlfcn.h> 3085e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3098d4d6a13c4c3bf4e966d12297cc9a9f6cf9d42a8Nick Pelly#define FW_PATH "/system/vendor/firmware/libpn544_fw.so" 3108d4d6a13c4c3bf4e966d12297cc9a9f6cf9d42a8Nick Pelly 311ac9c8c89d16e2c458c9c43e1def75d4e1f8f5b9bMartijn Coenenconst unsigned char *nxp_nfc_full_version = NULL; 312ac9c8c89d16e2c458c9c43e1def75d4e1f8f5b9bMartijn Coenenconst unsigned char *nxp_nfc_fw = NULL; 3135e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3145e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomasint dlopen_firmware() { 3155e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas void *p; 3165e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3178d4d6a13c4c3bf4e966d12297cc9a9f6cf9d42a8Nick Pelly void *handle = dlopen(FW_PATH, RTLD_NOW); 3185e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas if (handle == NULL) { 3198d4d6a13c4c3bf4e966d12297cc9a9f6cf9d42a8Nick Pelly LOGE("Could not open %s", FW_PATH); 3205e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas return -1; 3215e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas } 3225e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3235e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas p = dlsym(handle, "nxp_nfc_full_version"); 3245e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas if (p == NULL) { 3255e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas LOGE("Could not link nxp_nfc_full_version"); 3265e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas return -1; 3275e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas } 3285e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas nxp_nfc_full_version = (unsigned char *)p; 3295e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3305e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas p = dlsym(handle, "nxp_nfc_fw"); 3315e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas if (p == NULL) { 3325e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas LOGE("Could not link nxp_nfc_fw"); 3335e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas return -1; 3345e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas } 3355e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas nxp_nfc_fw = (unsigned char *)p; 3365e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3375e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas return 0; 3385e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas} 3395e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#endif 3405e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * The open function called by the upper HAL when HAL4 is to be opened 3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * (initialized). 3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_Open( 3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sHwReference_t *psHwReference, 3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_InitType_t InitType, 3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_GenCallback_t pOpenCallback, 3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext 3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS openRetVal = NFCSTATUS_SUCCESS; 3545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL; 3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Init_t eHciInitType = (phHciNfc_Init_t)InitType; 3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Set Default Clock settings once*/ 3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static phHal_sHwConfig_t sHwConfig = { 3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {0}, 3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NXP_DEFAULT_CLK_REQUEST, 3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NXP_DEFAULT_INPUT_CLK 3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }; 3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*NULL checks*/ 3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL == psHwReference || NULL == pOpenCallback) 3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1); 3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly openRetVal = PHNFCSTVAL(CID_NFC_HAL ,NFCSTATUS_INVALID_PARAMETER); 3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if(NULL != gpphHal4Nfc_Hwref) 3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Hal4 context is open or open in progress ,return Ctxt already open*/ 3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly openRetVal = PHNFCSTVAL(CID_NFC_HAL ,NFCSTATUS_ALREADY_INITIALISED); 3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else/*Do an initialization*/ 3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3755e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#ifdef ANDROID 376d4cb91ee6f74f187cc0e7ba9dc073b0a77c27dfaNick Pelly dlopen_firmware(); 3775e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas#endif 3785e97605ca8d83414b122bae72e65ea388b66718adaniel_Tomas 3795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*If hal4 ctxt in Hwreference is NULL create a new context*/ 3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL == ((phHal_sHwReference_t *)psHwReference)->hal_context) 3815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *) 3835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_GetMemory((uint32_t)sizeof( 3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t) 3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ((phHal_sHwReference_t *)psHwReference)->hal_context = Hal4Ctxt; 3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else/*Take context from Hw reference*/ 3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = ((phHal_sHwReference_t *)psHwReference)->hal_context; 3915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL == Hal4Ctxt) 3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly openRetVal = PHNFCSTVAL(CID_NFC_HAL, 3955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_INSUFFICIENT_RESOURCES); 3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void)memset((void *)Hal4Ctxt, 4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 0, 4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ((uint32_t)sizeof(phHal4Nfc_Hal4Ctxt_t))); 4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Configure layers if not configured */ 4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( NULL == Hal4Ctxt->pHal4Nfc_LayerCfg ) 4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly openRetVal = phHal4Nfc_Configure_Layers( 4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &(Hal4Ctxt->pHal4Nfc_LayerCfg) 4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( openRetVal == NFCSTATUS_SUCCESS ) 4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*update Next state*/ 4136dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren Hal4Ctxt->Hal4NextState = (HCI_NFC_DEVICE_TEST == eHciInitType? 4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly eHal4StateSelfTestMode:eHal4StateOpenAndReady); 4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Store callback and context ,and set Default settings in Context*/ 4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pUpperOpenCb = pOpenCallback; 4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext; 4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sTgtConnectInfo.EmulationState = NFC_EVT_DEACTIVATED; 4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref = psHwReference; 4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Calling Hci-Init"); 4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly openRetVal = phHciNfc_Initialise ( 4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)&Hal4Ctxt->psHciHandle, 4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference, 4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly eHciInitType, 4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &sHwConfig, 4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (pphNfcIF_Notification_CB_t) 4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_LowerNotificationHandler, 4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)Hal4Ctxt, 4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->pHal4Nfc_LayerCfg 4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Hci Init did not succeed.free Resources and return*/ 4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( (openRetVal != NFCSTATUS_SUCCESS) 4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && (PHNFCSTATUS (openRetVal) != NFCSTATUS_PENDING) ) 4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->pHal4Nfc_LayerCfg); 4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt); 4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = NULL; 4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*if( openRetVal == NFCSTATUS_SUCCESS )*/ 4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else/*Free the context*/ 4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt); 4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*else*/ 4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return openRetVal; 4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** The I/O Control function allows the caller to use (vendor-) specific 4505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* functionality provided by the lower layer or by the hardware. */ 4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_Ioctl( 4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sHwReference_t *psHwReference, 4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t IoctlCode, 4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *pInParam, 4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *pOutParam, 4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_IoctlCallback_t pIoctlCallback, 4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext 4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS RetStatus = NFCSTATUS_FAILED; 4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL; 4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t config_type = 0; 4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ind = 0; 4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*NULL checks*/ 4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((NULL == psHwReference) 4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (NULL == pIoctlCallback) 4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1); 4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = PHNFCSTVAL(CID_NFC_HAL ,NFCSTATUS_INVALID_PARAMETER); 4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Only the Ioctls NFC_FW_DOWNLOAD_CHECK and NFC_FW_DOWNLOAD are allowed in 4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly the uninitialized state of HAL*/ 4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if(NULL == psHwReference->hal_context) 4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef FW_DOWNLOAD 4776dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren 4786dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren#if !defined (NXP_FW_INTEGRITY_VERIFY) 4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NFC_FW_DOWNLOAD_CHECK == IoctlCode) 4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phDnldNfc_Run_Check( 4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference 4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4856dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren else 4866dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren#endif /* !defined (NXP_FW_INTEGRITY_VERIFY) */ 4876dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren if((NFC_FW_DOWNLOAD == IoctlCode) 4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &&(NULL == gpphHal4Nfc_Hwref))/*Indicates current state is shutdown*/ 4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *) 4915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_GetMemory((uint32_t)sizeof( 4925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t) 4935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 4945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL == Hal4Ctxt) 4955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = PHNFCSTVAL(CID_NFC_HAL, 4975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_INSUFFICIENT_RESOURCES); 4985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 5005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ((phHal_sHwReference_t *)psHwReference)->hal_context 5025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = Hal4Ctxt; 5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void)memset((void *)Hal4Ctxt, 5045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 0, 5055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ((uint32_t)sizeof(phHal4Nfc_Hal4Ctxt_t))); 5065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext; 5075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb 5085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = pIoctlCallback;/*Register upper layer callback*/ 5095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam = pOutParam; 5105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Upgrade the firmware*/ 5115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phDnldNfc_Upgrade ( 5125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference, 5135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_DownloadComplete, 5145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt 5155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 5166dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren if((NFCSTATUS_SUCCESS == RetStatus) 5176dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren || (NFCSTATUS_PENDING != PHNFCSTATUS(RetStatus)) 5186dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren ) 5195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt); 5215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ((phHal_sHwReference_t *)psHwReference)->hal_context = NULL; 5225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*NFC_FW_DOWNLOAD*/ 5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = PHNFCSTVAL(CID_NFC_HAL ,NFCSTATUS_NOT_INITIALISED); 5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else/*Status is Initialised*/ 5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Register upper layer context*/ 5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = psHwReference->hal_context; 5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam = pOutParam; 5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(IoctlCode) 5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Self test Ioctls*/ 5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case DEVMGMT_ANTENNA_TEST: 5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case DEVMGMT_SWP_TEST: 5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case DEVMGMT_NFCWI_TEST: 5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(eHal4StateSelfTestMode ==Hal4Ctxt->Hal4CurrentState) 5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phHciNfc_System_Test( 5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle, 5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)psHwReference, 5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly IoctlCode , 5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInParam 5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*PRBS Test*/ 5535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case DEVMGMT_PRBS_TEST: 5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phHciNfc_PRBS_Test( 5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle, 5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)psHwReference, 5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly IoctlCode , 5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInParam 5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*To Set Antenna Power Level*/ 5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_ANTENNA_CWG: 5635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(eHal4StateSelfTestMode ==Hal4Ctxt->Hal4CurrentState) 5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phHciNfc_System_Configure ( 5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle, 5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)psHwReference, 5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFC_ANTENNA_CWG, 5695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInParam->buffer[0] /**Set Power Level*/ 5705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Not allowed when Init is complete*/ 5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_FW_DOWNLOAD_CHECK: 5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_FW_DOWNLOAD: 5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = PHNFCSTVAL(CID_NFC_HAL, 5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_BUSY); 5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Gpio read*/ 5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_GPIO_READ: 5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* if(eHal4StateSelfTestMode == Hal4Ctxt->Hal4CurrentState) */ 5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phHciNfc_System_Get_Info( 5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle, 5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)psHwReference, 5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly IoctlCode , 5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pOutParam->buffer 5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Used to Read Memory/Registers .3 bytes of Array passed form the 5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly address to read from in MSB first format.*/ 5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_MEM_READ: 5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((NULL != pInParam) 5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && (pInParam->length == 3)) 5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for( ind = 0; ind < 3; ind++ ) 6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly config_type = ((config_type << BYTE_SIZE ) 6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly | (pInParam->buffer[ind] )); 6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phHciNfc_System_Get_Info( 6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle, 6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)psHwReference, 6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly config_type , 6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pOutParam->buffer 6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = PHNFCSTVAL(CID_NFC_HAL, 6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_INVALID_PARAMETER); 6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Used to Write Memory/Registers .First 3 bytes of Array passed in MSB 6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly first format form the address to write to.The 4th Byte is the 8 bit 6205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly value to be written to the address*/ 6215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_MEM_WRITE: 6225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((NULL != pInParam) 6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && (pInParam->length == 4)) 6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for( ind = 0; ind < 3; ind++ ) 6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly config_type = ((config_type << BYTE_SIZE ) 6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly | (pInParam->buffer[ind] )); 6305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phHciNfc_System_Configure ( 6325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psHciHandle, 6335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)psHwReference, 6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly config_type, 6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInParam->buffer[3] /*config value*/ 6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = PHNFCSTVAL(CID_NFC_HAL , 6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_INVALID_PARAMETER); 6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NFCSTATUS_PENDING == RetStatus)/*Callback Pending*/ 6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Register upper layer callback and context*/ 6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext; 6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb= pIoctlCallback; 6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Store the Ioctl code*/ 6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Ioctl_Type = IoctlCode; 6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return RetStatus; 6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 6595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 6625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * The close function called by the upper layer when HAL4 is to be closed 6635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * (shutdown). 6645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 6655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_Close( 6665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sHwReference_t *psHwReference, 6675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_GenCallback_t pCloseCallback, 6685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext 6695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 6705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 6715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS closeRetVal = NFCSTATUS_SUCCESS; 6725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL; 6735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*NULL checks*/ 6745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL == psHwReference || NULL == pCloseCallback) 6755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1); 6775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly closeRetVal = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER); 6785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if((NULL == psHwReference->hal_context) 6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (((phHal4Nfc_Hal4Ctxt_t *) 6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference->hal_context)->Hal4CurrentState 6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly < eHal4StateSelfTestMode) 6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (((phHal4Nfc_Hal4Ctxt_t *) 6845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference->hal_context)->Hal4NextState 6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly == eHal4StateClosed)) 6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*return already closed*/ 6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly closeRetVal= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED); 6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else /*Close the HAL*/ 6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Get Hal4 context from Hw reference*/ 6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)((phHal_sHwReference_t *) 6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference)->hal_context; 6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Unregister Tag Listener*/ 6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psADDCtxtInfo) 6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification = NULL; 6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*store Callback and Context*/ 7015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pUpperCloseCb = pCloseCallback; 7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext; 7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call Hci Release*/ 7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Calling Hci Release"); 7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly closeRetVal =(NFCSTATUS)phHciNfc_Release( 7065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)Hal4Ctxt->psHciHandle, 7075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference, 7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (pphNfcIF_Notification_CB_t) 7095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_LowerNotificationHandler, 7105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)Hal4Ctxt 7115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 7125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Update Next state and exit*/ 7135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( PHNFCSTATUS (closeRetVal) == NFCSTATUS_PENDING ) 7145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = eHal4StateClosed; 7165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification = NULL; 7175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 7195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return closeRetVal; 7245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 7255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Forcibly shutdown the HAl4.Frees all Resources in use by Hal4 before shutting 7275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly down*/ 7285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid phHal4Nfc_Hal4Reset( 7295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sHwReference_t *pHwRef, 7305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext 7315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 7325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL; 7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS closeRetVal = NFCSTATUS_SUCCESS; 7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t RemoteDevNumber = 0; 7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pHwRef ==NULL) 7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly closeRetVal = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER); 7395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if(pHwRef->hal_context != NULL) 7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Get the Hal context*/ 7435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)pHwRef->hal_context; 7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*store the upper layer context*/ 7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext; 7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = eHal4StateClosed; 7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification = NULL; 7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call Hci Release*/ 7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Calling Hci Release"); 7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly closeRetVal =(NFCSTATUS)phHciNfc_Release( 7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)Hal4Ctxt->psHciHandle, 7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pHwRef, 7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (pphNfcIF_Notification_CB_t)NULL, 7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)Hal4Ctxt 7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly );/*Clean up Hci*/ 7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4CurrentState = eHal4StateClosed; 7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory((void *)Hal4Ctxt->pHal4Nfc_LayerCfg); 7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->pHal4Nfc_LayerCfg = NULL; 7595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Free ADD context*/ 7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psADDCtxtInfo) 7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification = NULL; 7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly while(RemoteDevNumber < MAX_REMOTE_DEVICES) 7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->rem_dev_list[RemoteDevNumber]) 7665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory((void *) 7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (Hal4Ctxt->rem_dev_list[RemoteDevNumber])); 7695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->rem_dev_list[RemoteDevNumber] = NULL; 7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RemoteDevNumber++; 7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0; 7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->psADDCtxtInfo); 7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Free Trcv context*/ 7775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psTrcvCtxtInfo) 7785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psTrcvCtxtInfo->sLowerRecvData.buffer) 7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo 7825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ->sLowerRecvData.buffer); 7835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((NULL == Hal4Ctxt->sTgtConnectInfo.psConnectedDevice) 7855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && (NULL != Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData)) 7865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData); 7885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo); 7905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(Hal4Ctxt);/*Free the context*/ 7925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pHwRef->hal_context = NULL; 7935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref = NULL; 7945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 7965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Hal4 Context is already closed.Return Success*/ 7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Reset Should always return Success*/ 8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(closeRetVal != NFCSTATUS_SUCCESS) 8015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1); 8035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 8055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \if hal 8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_hal_common 8105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \else 8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_mw_external_hal_funcs 8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \endif 8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Retrieves the capabilities of the device represented by the Hardware 8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Reference parameter. 8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * The HW, SW versions, the MTU and other mandatory information are located 8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * inside the pDevCapabilities parameter. 8185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 8195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phHal4Nfc_GetDeviceCapabilities( 8205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sHwReference_t *psHwReference, 8215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sDeviceCapabilities_t *psDevCapabilities, 8225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext 8235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 8245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 8255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS retstatus = NFCSTATUS_SUCCESS; 8265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*NULL checks*/ 8275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psDevCapabilities == NULL || psHwReference == NULL || pContext == NULL) 8285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly retstatus = PHNFCSTVAL(CID_NFC_HAL ,NFCSTATUS_INVALID_PARAMETER); 8305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Check for Initialized state*/ 8325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if((NULL == psHwReference->hal_context) 8335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (((phHal4Nfc_Hal4Ctxt_t *) 8345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference->hal_context)->Hal4CurrentState 8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly < eHal4StateOpenAndReady) 8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (((phHal4Nfc_Hal4Ctxt_t *) 8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwReference->hal_context)->Hal4NextState 8385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly == eHal4StateClosed)) 8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly retstatus = PHNFCSTVAL(CID_NFC_HAL ,NFCSTATUS_NOT_INITIALISED); 8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else/*Provide Device capabilities and Version Info to the caller*/ 8435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void)memcpy((void *)psDevCapabilities, 8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)&(psHwReference->device_info), 8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sizeof(phHal_sDeviceCapabilities_t)); 8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.Felica = TRUE; 8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.ISO14443_4A = TRUE; 8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.ISO14443_4B = TRUE; 8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.ISO15693 = TRUE; 8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.Jewel = TRUE; 8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.MifareStd = TRUE; 8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.MifareUL = TRUE; 8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->ReaderSupProtocol.NFC = TRUE; 8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.Felica = FALSE; 8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.ISO14443_4A = FALSE; 8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.ISO14443_4B = FALSE; 8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.ISO15693 = FALSE; 8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.Jewel = FALSE; 8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.MifareStd = FALSE; 8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.MifareUL = FALSE; 8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->EmulationSupProtocol.NFC = TRUE; 8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psDevCapabilities->hal_version = ( 8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (((PH_HAL4NFC_INTERFACE_VERSION << BYTE_SIZE) 8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly |(PH_HAL4NFC_INTERFACE_REVISION)<<BYTE_SIZE) 8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly |(PH_HAL4NFC_INTERFACE_PATCH)<<BYTE_SIZE) 8675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly |PH_HAL4NFC_INTERAFECE_BUILD 8685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return retstatus; 8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* 8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Handles all notifications received from HCI layer. 8755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_LowerNotificationHandler( 8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext, 8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pHwRef, 8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t type, 8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL; 8855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((NULL == pInfo) || (NULL == pHwRef) 8865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (NULL == pContext)) 8875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1); 8895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*A copy of hardware reference is maintained in HAL for comparing passed 8935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly and returned context.Set to NULL after a Shutdown*/ 8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != gpphHal4Nfc_Hwref)/*Get context from Hw ref*/ 8955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)gpphHal4Nfc_Hwref->hal_context; 8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NFC_INVALID_RELEASE_TYPE == Hal4Ctxt->sTgtConnectInfo.ReleaseType) 8985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)pContext; 9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref = (phHal_sHwReference_t *)pHwRef; 9015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else/*No Copy of Hw ref in HAL.Copy both Hwref and Hal context passed 9045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly by Hci*/ 9055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)pContext; 9075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref = (phHal_sHwReference_t *)pHwRef; 9085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Check the type of notification received from Hci and handle it 9105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly accordingly*/ 9115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(type) 9125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_INIT_COMPLETED: 9145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_INIT_FAILED: 9155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_OpenComplete(Hal4Ctxt,pInfo); 9165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_IO_SUCCESS: 9185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_IO_ERROR: 9195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_IoctlComplete(Hal4Ctxt,pInfo); 9205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_RESULT: 9225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_SelfTestComplete(Hal4Ctxt,pInfo); 9235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_DEINIT_COMPLETED: 9255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_DEINIT_FAILED: 9265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_CloseComplete(Hal4Ctxt,pInfo); 9275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_POLL_ENABLED: 9295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_POLL_DISABLED: 9305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_POLL_RESTARTED: 9315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_CONFIG_ERROR: 9325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_CONFIG_SUCCESS: 9335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_ConfigureComplete(Hal4Ctxt,pInfo,type); 9345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TARGET_DISCOVERED: 9365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_DISCOVERY_ERROR: 9375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_TargetDiscoveryComplete(Hal4Ctxt,pInfo); 9385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TARGET_REACTIVATED: 9405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_ReactivationComplete(Hal4Ctxt,pInfo); 9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_EVENT: 9435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Calling Event callback"); 9445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEvent(Hal4Ctxt,pInfo); 9455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TARGET_CONNECTED: 9475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Calling Hal4 Connect complete"); 9485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_ConnectComplete(Hal4Ctxt,pInfo); 9495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TARGET_DISCONNECTED: 9525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Target Disconnected"); 9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(Hal4Ctxt->Hal4NextState == eHal4StatePresenceCheck) 9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_PresenceChkComplete(Hal4Ctxt,pInfo); 9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_DisconnectComplete(Hal4Ctxt,pInfo); 9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TRANSCEIVE_COMPLETED: 9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TRANSCEIVE_ERROR : 9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Transceive Callback"); 9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psTrcvCtxtInfo) 9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TRANSACTION_TIMER 9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly != PH_OSALNFC_INVALID_TIMER_ID) 9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_Timer_Stop( 9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_Timer_Delete( 9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = PH_OSALNFC_INVALID_TIMER_ID; 9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /*TRANSACTION_TIMER*/ 9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_TransceiveComplete(Hal4Ctxt,pInfo); 9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_SEND_COMPLETED : 9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:NfcIp1 Send Callback"); 9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psTrcvCtxtInfo) 9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_SendCompleteHandler(Hal4Ctxt,pInfo); 9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TRANSACTION : 9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEmulationEvent(Hal4Ctxt,pInfo); 9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_RECV_ERROR : 9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_RECV_EVENT : 9985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Receive Event"); 9995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psTrcvCtxtInfo) 10005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 10025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly != PH_OSALNFC_INVALID_TIMER_ID) 10035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_Timer_Stop( 10055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 10065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 10075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_Timer_Delete( 10085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 10095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 10105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId 10115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = PH_OSALNFC_INVALID_TIMER_ID; 10125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_RecvCompleteHandler(Hal4Ctxt,pInfo); 10155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 10165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_TARGET_PRESENT: 10175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_PresenceChkComplete(Hal4Ctxt,pInfo); 10185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 10195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_DEVICE_ERROR: 10205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10216dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren NFCSTATUS status = NFCSTATUS_BOARD_COMMUNICATION_ERROR; 10226dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren pphHal4Nfc_GenCallback_t pUpper_OpenCb 10236dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren = Hal4Ctxt->sUpperLayerInfo.pUpperOpenCb; 10246dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren void *pUpper_Context 10256dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren = Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt; 10265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static phHal4Nfc_NotificationInfo_t uNotificationInfo; 10275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler) 10285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10296dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 10305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler( 10315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.DefaultListenerCtxt, 10325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFC_EVENT_NOTIFICATION, 10335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uNotificationInfo, 10345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_BOARD_COMMUNICATION_ERROR 10355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 10365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10376dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren else if (( eHal4StateSelfTestMode == Hal4Ctxt->Hal4NextState ) 10386dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren || ( eHal4StateOpenAndReady == Hal4Ctxt->Hal4NextState ) ) 10396dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren { 10406dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren Hal4Ctxt->Hal4CurrentState = eHal4StateClosed; 10416dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 10426dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren (void)phHciNfc_Release((void *)Hal4Ctxt->psHciHandle, 10436dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren pHwRef, (pphNfcIF_Notification_CB_t)NULL, 10446dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren (void *)Hal4Ctxt);/*Clean up Hci*/ 10456dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren Hal4Ctxt->psHciHandle = NULL; 10466dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren phOsalNfc_FreeMemory((void *)Hal4Ctxt->pHal4Nfc_LayerCfg); 10476dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren Hal4Ctxt->pHal4Nfc_LayerCfg = NULL; 10486dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren phOsalNfc_FreeMemory((void *)Hal4Ctxt); 10496dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren gpphHal4Nfc_Hwref->hal_context = NULL; 10506dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren gpphHal4Nfc_Hwref = NULL; 10516dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren PHDBG_INFO("Hal4:Open Failed"); 10526dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren /*Call upper layer's Open Cb with error status*/ 10536dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren if(NULL != pUpper_OpenCb) 10546dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren { 10556dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren /*Upper layer's Open Cb*/ 10566dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren (*pUpper_OpenCb)(pUpper_Context,status); 10576dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren } 10586dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren } 10595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 10605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10616dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 10625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); 10635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 10655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_CONNECT_FAILED: 10675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_DISCONNECT_FAILED: 10685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Generic Error type received from Hci.Handle the error based on 10695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4 next state and which past callback was Pending*/ 10705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_NOTIFY_ERROR: 10715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_WARNING("Hal4:Error Notification from HCI"); 10735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(Hal4Ctxt->Hal4NextState) 10745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StateClosed: 10765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_CloseComplete(Hal4Ctxt,pInfo); 10775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 10785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StateSelfTestMode: 10795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_SelfTestComplete(Hal4Ctxt,pInfo); 10805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 10815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StateConfiguring: 10825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_ConfigureComplete(Hal4Ctxt,pInfo,type); 10835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 10845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StateTargetDiscovered: 10855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StateTargetActivate: 10865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->sTgtConnectInfo.pUpperConnectCb) 10885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL == Hal4Ctxt->sTgtConnectInfo.psConnectedDevice) 10905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_ConfigureComplete(Hal4Ctxt,pInfo,type); 10925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 10945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_ConnectComplete(Hal4Ctxt,pInfo); 10965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 10995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_TargetDiscoveryComplete(Hal4Ctxt,pInfo); 11015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StateTargetConnected: 11055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_ConnectComplete(Hal4Ctxt,pInfo); 11065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StateOpenAndReady: 11085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_DisconnectComplete(Hal4Ctxt,pInfo); 11095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case eHal4StatePresenceCheck: 11115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_PresenceChkComplete(Hal4Ctxt,pInfo); 11125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 11145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_WARNING("Unknown Error notification"); 11155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*End of switch(Hal4Ctxt->Hal4State)*/ 11195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 11205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1); 11215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*End of switch(type)*/ 11235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 11255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 11265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Event handler for HAL-HCI interface*/ 11295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_HandleEvent( 11305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 11315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 11325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 11335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 11345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sEventInfo_t *psEventInfo = (phHal_sEventInfo_t *)pInfo; 11355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static phNfc_sNotificationInfo_t sNotificationInfo; 11365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_NotificationInfo_t uNotificationInfo = {NULL}; 11375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS RetStatus = NFCSTATUS_FAILED; 11385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Check if Hal4 Close has already been called*/ 11395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(eHal4StateClosed != Hal4Ctxt->Hal4NextState) 11405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(psEventInfo->eventType) 11425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_ACTIVATED:/*Target Activated*/ 11445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psEventInfo->eventHost == phHal_eHostController) 11465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(psEventInfo->eventSource) 11485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phHal_eNfcIP1_Target: 11505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_P2PActivateComplete(Hal4Ctxt,pInfo); 11515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phHal_eISO14443_A_PICC: 11535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phHal_eISO14443_B_PICC: 11545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.info = psEventInfo; 11555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.status = NFCSTATUS_SUCCESS; 11565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type = NFC_EVENT_NOTIFICATION; 11575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInfo = &sNotificationInfo; 11585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEmulationEvent(Hal4Ctxt,pInfo); 11595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 11615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_DEACTIVATED:/*Target Deactivated*/ 11675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psEventInfo->eventHost == phHal_eHostController) 11695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(psEventInfo->eventSource) 11715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phHal_eNfcIP1_Target: 11735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleP2PDeActivate(Hal4Ctxt,pInfo); 11745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phHal_eISO14443_A_PICC: 11765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phHal_eISO14443_B_PICC: 11775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.info = psEventInfo; 11785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.status = NFCSTATUS_SUCCESS; 11795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type = NFC_EVENT_NOTIFICATION; 11805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInfo = &sNotificationInfo; 11815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEmulationEvent(Hal4Ctxt,pInfo); 11825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 11845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Set Protection Event*/ 11905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_PROTECTED: 11915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef IGNORE_EVT_PROTECTED 11935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Ignore_Event_Protected is set to false during Field Off event and 11945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Set protection Configuration.After a NFC_EVT_PROTECTED is received 11955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly once all subsequent NFC_EVT_PROTECTED events are ignored*/ 11965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(FALSE == Hal4Ctxt->Ignore_Event_Protected) 11975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Ignore_Event_Protected = TRUE; 11995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef IGNORE_EVT_PROTECTED*/ 12005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.info = psEventInfo; 12015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.status = NFCSTATUS_SUCCESS; 12025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type = NFC_EVENT_NOTIFICATION; 12035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInfo = &sNotificationInfo; 12045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEmulationEvent(Hal4Ctxt,pInfo); 12055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef IGNORE_EVT_PROTECTED 12065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef IGNORE_EVT_PROTECTED*/ 12085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 12095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*NFC_UICC_RDPHASES_DEACTIVATE_REQ*/ 12115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_UICC_RDPHASES_DEACTIVATE_REQ: 12125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != gpphHal4Nfc_Hwref) 12145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref->uicc_rdr_active = FALSE; 12165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 12185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_UICC_RDPHASES_ACTIVATE_REQ: 12205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != gpphHal4Nfc_Hwref) 12225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref->uicc_rdr_active = TRUE; 12245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*If a NFC_UICC_RDPHASES_ACTIVATE_REQ is received before a configure 12265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly discovery,then create a ADD context info*/ 12275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (NULL == Hal4Ctxt->psADDCtxtInfo) 12285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psADDCtxtInfo= (pphHal4Nfc_ADDCtxtInfo_t) 12305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_GetMemory((uint32_t) 12315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (sizeof(phHal4Nfc_ADDCtxtInfo_t))); 12325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psADDCtxtInfo) 12335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void)memset(Hal4Ctxt->psADDCtxtInfo,0, 12355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sizeof(phHal4Nfc_ADDCtxtInfo_t) 12365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 12375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->psADDCtxtInfo) 12405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psADDCtxtInfo->sADDCfg.PollDevInfo.PollEnabled 12425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly |= psEventInfo->eventInfo.rd_phases; 12435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Configure HCI Discovery*/ 12445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RetStatus = phHciNfc_Config_Discovery( 12455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void *)Hal4Ctxt->psHciHandle, 12465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly gpphHal4Nfc_Hwref, 12475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &(Hal4Ctxt->psADDCtxtInfo->sADDCfg) 12485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 12495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = (NFCSTATUS_PENDING == RetStatus? 12505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly eHal4StateConfiguring: 12515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState); 12525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 12545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call Default Event handler for these Events*/ 12565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_INFO_TXLDO_OVERCUR: 12575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_INFO_MEM_VIOLATION: 12585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_INFO_TEMP_OVERHEAT: 12596dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren case NFC_INFO_LLC_ERROR: 12605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.info = psEventInfo; 12625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.status = NFCSTATUS_SUCCESS; 12635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type = NFC_EVENT_NOTIFICATION; 12645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInfo = &sNotificationInfo; 12655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Exception events"); 12665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler) 12675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Pass on Event notification info from Hci to Upper layer*/ 12695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uNotificationInfo.psEventInfo = psEventInfo; 12705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler( 12715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.DefaultListenerCtxt, 12725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type, 12735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uNotificationInfo, 12745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_SUCCESS 12755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 12765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 12785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call emulation Event handler fto handle these Events*/ 12805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_TRANSACTION: 12815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_START_OF_TRANSACTION: 12825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_END_OF_TRANSACTION: 12835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_CONNECTIVITY: 1284967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas case NFC_EVT_OPERATION_ENDED: 1285967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas case NFC_EVT_MIFARE_ACCESS: 1286967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas case NFC_EVT_APDU_RECEIVED: 1287967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas case NFC_EVT_EMV_CARD_REMOVAL: 12885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.info = psEventInfo; 12895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.status = NFCSTATUS_SUCCESS; 12905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type = NFC_EVENT_NOTIFICATION; 12915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInfo = &sNotificationInfo; 12925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Event transaction\n"); 12935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEmulationEvent(Hal4Ctxt,pInfo); 12945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 12955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_FIELD_ON: 12965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psEventInfo = sNotificationInfo.info = psEventInfo; 12975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.status = NFCSTATUS_SUCCESS; 12985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type = NFC_EVENT_NOTIFICATION; 12995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInfo = &sNotificationInfo; 13005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Event Field ON\n"); 13015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEmulationEvent(Hal4Ctxt,pInfo); 13025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 13035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case NFC_EVT_FIELD_OFF: 13045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly #ifdef IGNORE_EVT_PROTECTED 13055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Ignore_Event_Protected = FALSE; 13065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly #endif/*#ifdef IGNORE_EVT_PROTECTED*/ 13075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->psEventInfo = sNotificationInfo.info = psEventInfo; 13085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.status = NFCSTATUS_SUCCESS; 13095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sNotificationInfo.type = NFC_EVENT_NOTIFICATION; 13105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pInfo = &sNotificationInfo; 13115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_INFO("Hal4:Event Field OFF\n"); 13125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_HandleEmulationEvent(Hal4Ctxt,pInfo); 13135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 13145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly default: 13155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHDBG_WARNING("Hal4:Unhandled Event type received"); 13165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 13175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*End of switch*/ 13185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }/*if(eHal4StateClosed != Hal4Ctxt->Hal4NextState)*/ 13195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 13205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 13215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*Callback handler for Self Test Ioctl completion*/ 13245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_SelfTestComplete( 13255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 13265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 13275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 13285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 13295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_FAILED; 13305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *SelfTestResults 13315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = (phNfc_sData_t *)(((phNfc_sCompletionInfo_t *)pInfo)->info); 13325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_IoctlCallback_t pUpper_IoctlCb 13335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb; 13345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pUpper_Context = Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt; 13355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*check for Success*/ 13366dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren if(( DEVMGMT_SWP_TEST == Hal4Ctxt->Ioctl_Type ) 13376dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren || ( DEVMGMT_ANTENNA_TEST == Hal4Ctxt->Ioctl_Type )) 13385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_SUCCESS; 13405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13416dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren else if((SelfTestResults->length > 0) && (0 == SelfTestResults->buffer[0])) 13426dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren { 13436dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren status = NFCSTATUS_SUCCESS; 13446dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren } 13456dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren else 13466dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren { 13476dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren if (NULL != pInfo) 13486dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren { 13496dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren status = ((phNfc_sCompletionInfo_t *)pInfo)->status; 13506dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren } 13516dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren } 13526dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren 13535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Copy response buffer and length*/ 13545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (void)memcpy(Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam->buffer, 13555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly SelfTestResults->buffer, 13565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly SelfTestResults->length); 13575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam->length 13585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = SelfTestResults->length; 13595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call registered Ioctl callback*/ 13605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pUpper_IoctlCb)( 13615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pUpper_Context, 13625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam, 13635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status 13645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 13655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 13665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 13675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phHal4Nfc_IoctlComplete( 13705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt, 13715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 13725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 13735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 13745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Copy status*/ 13755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = (((phNfc_sCompletionInfo_t *)pInfo)->status); 13765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_IoctlCallback_t pUpper_IoctlCb 13775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb; 13785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef MERGE_SAK_SW2 13795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_GenCallback_t pConfigCallback = 13805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pConfigCallback; 13815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef MERGE_SAK_SW2*/ 13825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pUpper_Context = Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt; 13835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb = NULL; 13845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef MERGE_SAK_SW1 /*Software workaround 1*/ 13855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(eHal4StateOpenAndReady == Hal4Ctxt->Hal4NextState) 13865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4CurrentState = Hal4Ctxt->Hal4NextState; 13885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 13895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Upper layer's Open Cb*/ 13905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*Hal4Ctxt->sUpperLayerInfo.pUpperOpenCb)( 13915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt, 13925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS_SUCCESS 13935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 13945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef MERGE_SAK_SW1*/ 13965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef MERGE_SAK_SW2 /*Software workaround 2*/ 13975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if((eHal4StateConfiguring == Hal4Ctxt->Hal4NextState) 13985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &&(NULL != pConfigCallback)) 13995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pConfigCallback = NULL; 14015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->Hal4NextState = eHal4StateInvalid; 14025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pConfigCallback)( 14035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,status 14045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 14055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 14075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif/*#ifdef MERGE_SAK_SW2*/ 14085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*for NFC_MEM_READ and NFC_GPIO_READ ,provide one Byte Response*/ 14105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((NFC_MEM_READ == Hal4Ctxt->Ioctl_Type) 14116dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren || (NFC_GPIO_READ == Hal4Ctxt->Ioctl_Type) 14126dd948323de0f31b413c9f19a905f1c145c9c456Rob von Behren ) 14135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam->length 14155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly = sizeof (uint8_t); 14165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call registered Ioctl callback*/ 14185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != pUpper_IoctlCb) 14195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pUpper_IoctlCb)( 14215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pUpper_Context, 14225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam, 14235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status 14245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 14255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 14285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 14295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef FW_DOWNLOAD 14315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**Callback handler for Download completion*/ 14325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellySTATIC void phHal4Nfc_DownloadComplete( 14335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext, 14345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pHwRef, 14355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t type, 14365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pInfo 14375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ) 14385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 14395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL; 14405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_FAILED; 14415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphHal4Nfc_IoctlCallback_t pUpper_DnldCb = NULL; 14425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *pIoctlOutParam = NULL; 14435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHal_sHwReference_t *psHwRef = NULL; 14445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pUpper_Context = NULL; 14455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*NULL checks*/ 14465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((NULL == pInfo) || (NULL == pHwRef) || (NULL == pContext)) 14475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1); 14495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 14515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly type = type; 14535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)pContext; 14545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Copy back stored context/callback for the upper layer*/ 14555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pUpper_Context = Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt; 14565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pIoctlOutParam = Hal4Ctxt->sUpperLayerInfo.pIoctlOutParam; 14575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pUpper_DnldCb = Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb; 14585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb = NULL; 14595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Copy download status*/ 14605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = (((phNfc_sCompletionInfo_t *)pInfo)->status); 14615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*copy hw reference*/ 14625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwRef = (phHal_sHwReference_t *)pHwRef; 14635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Free the temporary hal context used only for the sake of download*/ 14645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(psHwRef->hal_context); 14655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psHwRef->hal_context = NULL; 14665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*Call upper layer callback*/ 14675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(NULL != pUpper_DnldCb) 14685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (*pUpper_DnldCb)( 14705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pUpper_Context, 14715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pIoctlOutParam, 14725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status 14735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ); 14745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return; 14775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 14785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /*FW_DOWNLOAD*/ 14795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1480