2 * Copyright (C) 2010 NXP Semiconductors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * \file phHal4Nfc_Emulation.c
18 * \brief Hal4 Emulation source.
20 * Project: NFC-FRI 1.1
22 * $Date: Wed May 26 18:03:59 2010 $
25 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $
29 /* ---------------------------Include files ------------------------------------*/
31 #include <phHal4Nfc.h>
32 #include <phHal4Nfc_Internal.h>
33 #include <phOsalNfc.h>
35 /* ------------------------------- Macros ------------------------------------*/
37 /* Note : Macros required and used only in this module to be declared here*/
40 /* --------------------Structures and enumerations --------------------------*/
43 /*Event Notification handler for emulation*/
44 void phHal4Nfc_HandleEmulationEvent(
45 phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt,
49 phNfc_sNotificationInfo_t *psNotificationInfo = (phNfc_sNotificationInfo_t *)
51 phHal4Nfc_NotificationInfo_t uNotificationInfo = {NULL};
52 /*Pass on Event notification info from Hci to Upper layer*/
53 uNotificationInfo.psEventInfo = psNotificationInfo->info;
54 if(NULL != Hal4Ctxt->sUpperLayerInfo.pEventNotification)
56 Hal4Ctxt->sUpperLayerInfo.pEventNotification(
57 Hal4Ctxt->sUpperLayerInfo.EventNotificationCtxt,
58 psNotificationInfo->type,
63 else/*No Event notification handler registered*/
65 /*Use default handler to notify to the upper layer*/
66 if(NULL != Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler)
68 Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler(
69 Hal4Ctxt->sUpperLayerInfo.DefaultListenerCtxt,
70 psNotificationInfo->type,
79 /* Switch mode from Virtual to Wired or Vice Versa for SMX.
81 NFCSTATUS phHal4Nfc_Switch_SMX_Mode(
82 phHal_sHwReference_t *psHwReference,
83 phHal_eSmartMX_Mode_t smx_mode,
84 pphHal4Nfc_GenCallback_t pSwitchModecb,
88 NFCSTATUS CfgStatus = NFCSTATUS_PENDING;
89 phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL;
90 static phHal_sADD_Cfg_t sSmxCfg;
93 if((NULL == psHwReference) || (NULL == pSwitchModecb))
95 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
96 CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER);
98 /*Check Initialised state*/
99 else if((NULL == psHwReference->hal_context)
100 || (((phHal4Nfc_Hal4Ctxt_t *)
101 psHwReference->hal_context)->Hal4CurrentState
102 < eHal4StateOpenAndReady)
103 || (((phHal4Nfc_Hal4Ctxt_t *)
104 psHwReference->hal_context)->Hal4NextState
105 == eHal4StateClosed))
107 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
108 CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
112 Hal4Ctxt = psHwReference->hal_context;
113 /*Previous POLL Config has not completed or device is connected,
115 if(Hal4Ctxt->Hal4NextState == eHal4StateConfiguring)
117 PHDBG_INFO("Hal4:Configuration in progress.Returning status Busy");
118 CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_BUSY);
120 else if(Hal4Ctxt->Hal4CurrentState >= eHal4StateOpenAndReady)
122 /**If config discovery has not been called prior to this ,allocate
124 if (NULL == Hal4Ctxt->psADDCtxtInfo)
126 Hal4Ctxt->psADDCtxtInfo= (pphHal4Nfc_ADDCtxtInfo_t)
127 phOsalNfc_GetMemory((uint32_t)
128 (sizeof(phHal4Nfc_ADDCtxtInfo_t)));
129 if(NULL != Hal4Ctxt->psADDCtxtInfo)
131 (void)memset(Hal4Ctxt->psADDCtxtInfo,
132 0,sizeof(phHal4Nfc_ADDCtxtInfo_t));
135 if(NULL == Hal4Ctxt->psADDCtxtInfo)
137 phOsalNfc_RaiseException(phOsalNfc_e_NoMemory,0);
138 CfgStatus= PHNFCSTVAL(CID_NFC_HAL ,
139 NFCSTATUS_INSUFFICIENT_RESOURCES);
143 /* Register Upper layer context */
144 Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext;
145 /* Switch request to Wired mode */
146 if(eSmartMx_Wired == smx_mode)
148 if(Hal4Ctxt->Hal4CurrentState
149 == eHal4StateTargetConnected)
151 PHDBG_INFO("Hal4:In Connected state.Returning Busy");
152 CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_BUSY);
154 /*It is Mandatory to register a listener before switching
157 Hal4Ctxt->sUpperLayerInfo.pTagDiscoveryNotification)
159 CfgStatus = PHNFCSTVAL(CID_NFC_HAL ,
164 Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
165 Hal4Ctxt->psADDCtxtInfo->smx_discovery = TRUE;
166 sSmxCfg.PollDevInfo.PollCfgInfo.EnableIso14443A = TRUE;
167 sSmxCfg.PollDevInfo.PollCfgInfo.DisableCardEmulation = TRUE;
168 /*Switch mode to wired*/
169 CfgStatus = phHciNfc_Switch_SmxMode (
170 Hal4Ctxt->psHciHandle,
179 Hal4Ctxt->psADDCtxtInfo->smx_discovery = FALSE;
180 /*Switch mode to virtual or off*/
181 CfgStatus = phHciNfc_Switch_SmxMode (
182 Hal4Ctxt->psHciHandle,
185 &(Hal4Ctxt->psADDCtxtInfo->sADDCfg)
189 /* Change the State of the HAL only if Switch mode Returns
191 if ( NFCSTATUS_PENDING == CfgStatus )
193 Hal4Ctxt->Hal4NextState = eHal4StateConfiguring;
194 Hal4Ctxt->sUpperLayerInfo.pConfigCallback
199 else/*Return Status not initialised*/
201 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
202 CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
210 /* Switch mode for Swp.*/
211 NFCSTATUS phHal4Nfc_Switch_Swp_Mode(
212 phHal_sHwReference_t *psHwReference,
213 phHal_eSWP_Mode_t swp_mode,
214 pphHal4Nfc_GenCallback_t pSwitchModecb,
218 NFCSTATUS CfgStatus = NFCSTATUS_PENDING;
219 phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL;
221 if(NULL == psHwReference
222 || NULL == pSwitchModecb
225 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
226 CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER);
228 /*Check Initialised state*/
229 else if((NULL == psHwReference->hal_context)
230 || (((phHal4Nfc_Hal4Ctxt_t *)
231 psHwReference->hal_context)->Hal4CurrentState
232 < eHal4StateOpenAndReady)
233 || (((phHal4Nfc_Hal4Ctxt_t *)
234 psHwReference->hal_context)->Hal4NextState
235 == eHal4StateClosed))
237 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
238 CfgStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
242 Hal4Ctxt = psHwReference->hal_context;
243 /*Previous POLL CFG has not completed or device is connected,
245 if(Hal4Ctxt->Hal4NextState == eHal4StateConfiguring)
247 PHDBG_INFO("Hal4:Configuration in progress.Returning status Busy");
248 CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_BUSY);
250 else if(Hal4Ctxt->Hal4CurrentState >= eHal4StateOpenAndReady)
252 /**If config discovery has not been called prior to this ,allocate
254 if (NULL == Hal4Ctxt->psADDCtxtInfo)
256 Hal4Ctxt->psADDCtxtInfo= (pphHal4Nfc_ADDCtxtInfo_t)
257 phOsalNfc_GetMemory((uint32_t)
258 (sizeof(phHal4Nfc_ADDCtxtInfo_t)));
259 if(NULL != Hal4Ctxt->psADDCtxtInfo)
261 (void)memset(Hal4Ctxt->psADDCtxtInfo,
262 0,sizeof(phHal4Nfc_ADDCtxtInfo_t));
265 if(NULL == Hal4Ctxt->psADDCtxtInfo)
267 phOsalNfc_RaiseException(phOsalNfc_e_NoMemory,0);
268 CfgStatus= PHNFCSTVAL(CID_NFC_HAL ,
269 NFCSTATUS_INSUFFICIENT_RESOURCES);
273 /* Register Upper layer context */
274 Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt = pContext;
275 /*Switch mode to On or off*/
276 CfgStatus = phHciNfc_Switch_SwpMode(
277 Hal4Ctxt->psHciHandle,
282 /* Change the State of the HAL only if Switch mode Returns
284 if ( NFCSTATUS_PENDING == CfgStatus )
286 Hal4Ctxt->Hal4NextState = eHal4StateConfiguring;
287 Hal4Ctxt->sUpperLayerInfo.pConfigCallback
292 else/*Return Status not initialised*/
294 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
295 CfgStatus= PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
301 #ifdef FULL_HAL4_EMULATION_ENABLE
302 /* Switch Emulation mode ON or OFF.*/
303 NFCSTATUS phHal4Nfc_Host_Emulation_Mode(
304 phHal_sHwReference_t *psHwReference,
305 phNfc_eModeType_t eModeType,
306 pphHal4Nfc_GenCallback_t pEmulationModecb,
310 NFCSTATUS RetStatus = NFCSTATUS_PENDING;
311 phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = NULL;
313 if(NULL == psHwReference
314 || NULL == pEmulationModecb
317 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
318 RetStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_INVALID_PARAMETER);
320 /*Check Initialised state*/
321 else if((NULL == psHwReference->hal_context)
322 || (((phHal4Nfc_Hal4Ctxt_t *)
323 psHwReference->hal_context)->Hal4CurrentState
324 < eHal4StateOpenAndReady)
325 || (((phHal4Nfc_Hal4Ctxt_t *)
326 psHwReference->hal_context)->Hal4NextState
327 == eHal4StateClosed))
329 phOsalNfc_RaiseException(phOsalNfc_e_PrecondFailed,1);
330 RetStatus = PHNFCSTVAL(CID_NFC_HAL , NFCSTATUS_NOT_INITIALISED);
336 return NFCSTATUS_PENDING;
338 #endif /*FULL_HAL4_EMULATION_ENABLE*/