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.
18 * \file phLibNfc_Ioctl.c
20 * Project: NFC FRI 1.1
22 * $Date: Mon Mar 1 19:07:05 2010 $
25 * $Aliases: NFC_FRI1.1_WK1008_SDK,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1007_SDK,NFC_FRI1.1_WK1014_SDK,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1019_SDK,NFC_FRI1.1_WK1024_SDK $
30 ************************* Header Files ****************************************
33 #include <phLibNfcStatus.h>
35 #include <phHal4Nfc.h>
36 #include <phOsalNfc.h>
37 #include <phLibNfc_Internal.h>
38 #include <phLibNfc_ndef_raw.h>
39 #include <phLibNfc_initiator.h>
40 #include <phLibNfc_discovery.h>
41 #include <phLibNfc_ioctl.h>
42 #include <phNfcStatus.h>
45 *************************** Macro's ****************************************
48 #ifndef STATIC_DISABLE
55 *************************** Global Variables **********************************
58 STATIC phLibNfc_Ioctl_Cntx_t phLibNfc_Ioctl_Cntx;
61 *************************** Static Function Declaration ***********************
65 /* Response callback for Ioctl management */
66 STATIC void phLibNfc_Ioctl_Mgmt_CB(void *context,
67 phNfc_sData_t *pOutData,
71 /** Response callback for UICC switch mode*/
72 STATIC void phLibNfc_Switch_Swp_Mode_CB(
78 *************************** Function Definitions ******************************
82 * The I/O Control function allows the caller to configure specific
83 * functionality provided by the lower layer.Each feature is accessible
84 * via a specific IOCTL Code.
86 NFCSTATUS phLibNfc_Mgt_IoCtl (void* pDalHandle,
88 phNfc_sData_t* pInParam,
89 phNfc_sData_t* pOutParam,
90 pphLibNfc_IoctlCallback_t pIoCtl_Rsp_cb,
94 NFCSTATUS StatusCode=NFCSTATUS_INVALID_PARAMETER;
97 if((IoctlCode==0)||(NULL==pIoCtl_Rsp_cb) ||
98 (NULL==pContext) ||(NULL==pInParam) ||
101 StatusCode=NFCSTATUS_INVALID_PARAMETER;
104 if(IoctlCode!= NFC_FW_DOWNLOAD)
106 if(pOutParam == NULL)
108 StatusCode = NFCSTATUS_INVALID_PARAMETER;
111 if(( gpphLibContext == NULL) ||
112 (gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown))
114 StatusCode = NFCSTATUS_NOT_INITIALISED;
119 if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown)
121 StatusCode = NFCSTATUS_SHUTDOWN;
126 phLibNfc_Ioctl_Cntx.CliRspCb =pIoCtl_Rsp_cb;
127 phLibNfc_Ioctl_Cntx.pCliCntx = pContext;
128 phLibNfc_Ioctl_Cntx.pOutParam = pOutParam;
129 phLibNfc_Ioctl_Cntx.IoctlCode = IoctlCode;
130 /* Process the IOCTL requests */
133 case NFC_FW_DOWNLOAD:
134 {/* Set power status */
135 phLibNfc_Ioctl_Cntx.psHwReference = phOsalNfc_GetMemory((uint32_t)sizeof(phHal_sHwReference_t));
136 if(phLibNfc_Ioctl_Cntx.psHwReference == NULL)
137 return NFCSTATUS_FAILED;
138 (void)memset(phLibNfc_Ioctl_Cntx.psHwReference,0,sizeof(phHal_sHwReference_t));
139 phLibNfc_Ioctl_Cntx.psHwReference->p_board_driver = pDalHandle;
141 StatusCode = phHal4Nfc_Ioctl( phLibNfc_Ioctl_Cntx.psHwReference,
145 phLibNfc_Ioctl_Mgmt_CB,
146 &phLibNfc_Ioctl_Cntx );
150 StatusCode = phHal4Nfc_Ioctl(gpphLibContext->psHwReference,
154 phLibNfc_Ioctl_Mgmt_CB,
155 &phLibNfc_Ioctl_Cntx );
161 StatusCode = phHal4Nfc_Ioctl( gpphLibContext->psHwReference,
165 phLibNfc_Ioctl_Mgmt_CB,
166 &phLibNfc_Ioctl_Cntx );
169 case PHLIBNFC_ANTENNA_TEST:
172 StatusCode = phHal4Nfc_Ioctl( gpphLibContext->psHwReference,
173 PHLIBNFC_ANTENNA_TEST,
176 phLibNfc_Ioctl_Mgmt_CB,
177 &phLibNfc_Ioctl_Cntx );
180 case PHLIBNFC_SWP_TEST:
183 StatusCode = phHal4Nfc_Ioctl( gpphLibContext->psHwReference,
187 phLibNfc_Ioctl_Mgmt_CB,
188 &phLibNfc_Ioctl_Cntx );
192 case PHLIBNFC_PRBS_TEST:
194 StatusCode = phHal4Nfc_Ioctl( gpphLibContext->psHwReference,
198 phLibNfc_Ioctl_Mgmt_CB,
199 &phLibNfc_Ioctl_Cntx );
203 case PHLIBNFC_SWITCH_SWP_MODE:
205 StatusCode = phHal4Nfc_Switch_Swp_Mode( gpphLibContext->psHwReference,
206 (phHal_eSWP_Mode_t)pInParam->buffer[0],
207 phLibNfc_Switch_Swp_Mode_CB,
215 /* don't do any thing*/
218 } /* End of IOCTL switch */
219 if(StatusCode!=NFCSTATUS_PENDING)
221 StatusCode = NFCSTATUS_FAILED;
225 if(IoctlCode!= NFC_FW_DOWNLOAD)
227 gpphLibContext->status.GenCb_pending_status=TRUE;
232 } /* End of IOCTL handler function */
236 STATIC void phLibNfc_Ioctl_Mgmt_CB(void *context,
237 phNfc_sData_t *pOutData,
240 phLibNfc_Ioctl_Cntx_t *pIoctlCntx=NULL;
241 if(PHNFCSTATUS(status) == NFCSTATUS_FEATURE_NOT_SUPPORTED)
243 status = NFCSTATUS_FEATURE_NOT_SUPPORTED;
245 else if(PHNFCSTATUS(status)!=NFCSTATUS_SUCCESS)
247 status = NFCSTATUS_FAILED;
249 if(gpphLibContext!= NULL)
251 if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
253 /*If shutdown called in between allow shutdown to happen*/
254 phLibNfc_Pending_Shutdown();
255 status = NFCSTATUS_SHUTDOWN;
258 pIoctlCntx= (phLibNfc_Ioctl_Cntx_t*)context;
259 if( pIoctlCntx !=NULL)
261 switch(pIoctlCntx->IoctlCode)
263 case NFC_FW_DOWNLOAD:
265 /*Release the hardware reference memory*/
266 phOsalNfc_FreeMemory(pIoctlCntx->psHwReference);
277 case PHLIBNFC_ANTENNA_TEST:
281 case PHLIBNFC_SWP_TEST:
285 case PHLIBNFC_PRBS_TEST:
293 pIoctlCntx->CliRspCb(pIoctlCntx->pCliCntx,pOutData,status);
294 if(gpphLibContext!= NULL)
296 gpphLibContext->status.GenCb_pending_status=FALSE;
301 STATIC void phLibNfc_Switch_Swp_Mode_CB(
306 if(PHNFCSTATUS(status)!=NFCSTATUS_SUCCESS)
308 status = NFCSTATUS_FAILED;
310 if(gpphLibContext!= NULL)
312 if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
314 /*If shutdown called in between allow shutdown to happen*/
315 phLibNfc_Pending_Shutdown();
316 status = NFCSTATUS_SHUTDOWN;
319 if((NULL != context)&&(context == (void *)&phLibNfc_Ioctl_Cntx))
321 if(NULL != phLibNfc_Ioctl_Cntx.CliRspCb)
323 (*phLibNfc_Ioctl_Cntx.CliRspCb)(
324 phLibNfc_Ioctl_Cntx.pCliCntx,
325 phLibNfc_Ioctl_Cntx.pOutParam,