1 /******************************************************************************
2  *
3  *  Copyright 2018 NXP
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #include <log/log.h>
20 
21 #include "NxpNfc.h"
22 #include "phNxpNciHal_Adaptation.h"
23 
24 extern bool nfc_debug_enabled;
25 
26 namespace vendor {
27 namespace nxp {
28 namespace nxpnfc {
29 namespace V1_0 {
30 namespace implementation {
31 // Methods from ::vendor::nxp::nxpnfc::V1_0::INxpNfc follow.
ioctl(uint64_t ioctlType,const hidl_vec<uint8_t> & inOutData,ioctl_cb _hidl_cb)32 Return<void> NxpNfc::ioctl(uint64_t ioctlType,
33                            const hidl_vec<uint8_t>& inOutData,
34                            ioctl_cb _hidl_cb) {
35   int status;
36   nfc_nci_IoctlInOutData_t inpOutData;
37   NfcData outputData;
38   nfc_nci_IoctlInOutData_t* pInOutData =
39       (nfc_nci_IoctlInOutData_t*)&inOutData[0];
40 
41   if (inOutData.size() < sizeof (nfc_nci_IoctlInOutData_t)) {
42     ALOGE("%s invalid inOutData size, size = %d", __func__, (int)inOutData.size());
43     return Void();
44   }
45   /*data from proxy->stub is copied to local data which can be updated by
46    * underlying HAL implementation since its an inout argument*/
47   memcpy(&inpOutData, pInOutData, sizeof(nfc_nci_IoctlInOutData_t));
48   status = phNxpNciHal_ioctl(ioctlType, &inpOutData);
49   /*copy data and additional fields indicating status of ioctl operation
50    * and context of the caller. Then invoke the corresponding proxy callback*/
51   inpOutData.out.ioctlType = ioctlType;
52   inpOutData.out.context = pInOutData->inp.context;
53   inpOutData.out.result = status;
54   outputData.setToExternal((uint8_t*)&inpOutData.out,
55                            sizeof(nfc_nci_ExtnOutputData_t));
56   _hidl_cb(outputData);
57   return Void();
58 }
59 
60 }  // namespace implementation
61 }  // namespace V1_0
62 }  // namespace nxpnfc
63 }  // namespace nxp
64 }  // namespace vendor
65