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__,
43           (int)inOutData.size());
44     return Void();
45   }
46   /*data from proxy->stub is copied to local data which can be updated by
47    * underlying HAL implementation since its an inout argument*/
48   memcpy(&inpOutData, pInOutData, sizeof(nfc_nci_IoctlInOutData_t));
49   status = phNxpNciHal_ioctl(ioctlType, &inpOutData);
50   /*copy data and additional fields indicating status of ioctl operation
51    * and context of the caller. Then invoke the corresponding proxy callback*/
52   inpOutData.out.ioctlType = ioctlType;
53   inpOutData.out.context = pInOutData->inp.context;
54   inpOutData.out.result = status;
55   outputData.setToExternal((uint8_t*)&inpOutData.out,
56                            sizeof(nfc_nci_ExtnOutputData_t));
57   _hidl_cb(outputData);
58   return Void();
59 }
60 
61 }  // namespace implementation
62 }  // namespace V1_0
63 }  // namespace nxpnfc
64 }  // namespace nxp
65 }  // namespace vendor
66