• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "nfc_vendor_adaptions.h"
16 #include <dlfcn.h>
17 #include <fstream>
18 #include <hdf_base.h>
19 #include <hdf_log.h>
20 #include <mutex>
21 #include <iostream>
22 #include <pthread.h>
23 #include <string>
24 #include <sys/time.h>
25 #include <sys/resource.h>
26 #include <unistd.h>
27 #include "securec.h"
28 #include "hisysevent.h"
29 
30 #define HDF_LOG_TAG hdf_nfc_dal
31 
32 #ifdef LOG_DOMAIN
33 #undef LOG_DOMAIN
34 #endif
35 
36 #define LOG_DOMAIN 0xD000306
37 
38 const int32_t PRIORITY = -20;
39 
40 using namespace std;
41 namespace OHOS {
42 namespace HDI {
43 namespace Nfc {
44 std::mutex g_openMutex;
45 enum BootloaderRecoverStatus : uint16_t {
46     BOOTLOADER_STATUS_RECOVER_SUCCESS = 1,
47     BOOTLOADER_STATUS_RECOVER_FAILED,
48 };
49 template<typename... Types>
WriteEvent(const std::string & eventType,OHOS::HiviewDFX::HiSysEvent::EventType type,Types...args)50 static void WriteEvent(const std::string& eventType, OHOS::HiviewDFX::HiSysEvent::EventType type, Types... args)
51 {
52     int ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::SECURE_ELEMENT, eventType, type, args...);
53     if (ret != 0) {
54         HDF_LOGE("Write event fail: %{public}s", eventType.c_str());
55     } else {
56         HDF_LOGI("%{public}s success!", __func__);
57     }
58 }
59 
WriteBootloaderHiSysEvent(uint16_t errorCode)60 static void WriteBootloaderHiSysEvent(uint16_t errorCode)
61 {
62     const uint8_t bootloaderStatusType = 200; /* 100 ~ 199 for CA to TA hisysevent */
63     WriteEvent("ACCESS_SE_FAILED", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
64                "CHANNEL_TYPE", bootloaderStatusType,
65                "ERROR_CODE", errorCode);
66     HDF_LOGI("%{public}s value:%{public}d", __func__, errorCode);
67 }
68 
GetNfcHalSoName(const std::string & chipType)69 static string GetNfcHalSoName(const std::string &chipType)
70 {
71     string nfcHalSoName = NFC_HAL_SO_PREFIX + chipType + NFC_HAL_SO_SUFFIX;
72     return nfcHalSoName;
73 }
74 
GetChipType(void)75 string NfcVendorAdaptions::GetChipType(void)
76 {
77     string nfcChipType = "";
78     nfcExtHandle = dlopen(VENDOR_NFC_EXT_SERVICE_LIB.c_str(), RTLD_LAZY | RTLD_GLOBAL);
79     if (nfcExtHandle == nullptr) {
80         HDF_LOGE("%{public}s: fail to get nfc ext service handle.", __func__);
81         return nfcChipType;
82     }
83     nfcExtInf.getNfcChipType = reinterpret_cast<const char* (*)()>
84         (dlsym(nfcExtHandle, EXT_GET_CHIP_TYPE_FUNC_NAME.c_str()));
85     nfcExtInf.getNfcHalFuncNameSuffix = reinterpret_cast<const char* (*)(const char*)>
86         (dlsym(nfcExtHandle, EXT_GET_SUFFIX_FUNC_NAME.c_str()));
87 
88     if (nfcExtInf.getNfcChipType == nullptr || nfcExtInf.getNfcHalFuncNameSuffix == nullptr) {
89         HDF_LOGE("%{public}s: fail to init func ptr.", __func__);
90         return nfcChipType;
91     }
92     nfcChipType = string(nfcExtInf.getNfcChipType());
93     return nfcChipType;
94 }
95 
CheckFirmwareUpdate(void)96 void NfcVendorAdaptions::CheckFirmwareUpdate(void)
97 {
98     nfcExtHandle = dlopen(VENDOR_NFC_EXT_SERVICE_LIB.c_str(), RTLD_LAZY | RTLD_GLOBAL);
99     if (nfcExtHandle == nullptr) {
100         HDF_LOGE("%{public}s: fail to get nfc ext service handle.", __func__);
101         return;
102     }
103     nfcExtInf.checkFirmwareUpdate = reinterpret_cast<void (*)()>
104         (dlsym(nfcExtHandle, EXT_SET_FW_UPDATE_CONFIG_FUNC_NAME.c_str()));
105     if (nfcExtInf.checkFirmwareUpdate == nullptr) {
106         HDF_LOGE("%{public}s: fail to init func ptr.", __func__);
107         dlclose(nfcExtHandle);
108         nfcExtHandle = nullptr;
109         return;
110     }
111     nfcExtInf.checkFirmwareUpdate();
112     dlclose(nfcExtHandle);
113     nfcExtHandle = nullptr;
114 }
115 
UpdateNfcOpenStatus(const std::string & status)116 void NfcVendorAdaptions::UpdateNfcOpenStatus(const std::string &status)
117 {
118     nfcExtHandle = dlopen(VENDOR_NFC_EXT_SERVICE_LIB.c_str(), RTLD_LAZY | RTLD_GLOBAL);
119     if (nfcExtHandle == nullptr) {
120         HDF_LOGE("%{public}s: fail to get nfc ext service handle.", __func__);
121         return;
122     }
123     nfcExtInf.updateNfcOpenStatus = reinterpret_cast<void (*)(const char*, int)>
124         (dlsym(nfcExtHandle, EXT_UPDATE_NFC_OPEN_STATUS.c_str()));
125     if (nfcExtInf.updateNfcOpenStatus == nullptr) {
126         HDF_LOGE("%{public}s: fail to init func ptr.", __func__);
127         dlclose(nfcExtHandle);
128         nfcExtHandle = nullptr;
129         return;
130     }
131     nfcExtInf.updateNfcOpenStatus(status.c_str(), status.length());
132     HDF_LOGI("%{public}s: status [%{public}s].", __func__, status.c_str());
133     dlclose(nfcExtHandle);
134     nfcExtHandle = nullptr;
135 }
136 
137 /*
138 ** true : NFC in bootloader status
139 ** false : NFC in normal status
140 */
CheckNfcBootloaderStatus(void)141 bool NfcVendorAdaptions::CheckNfcBootloaderStatus(void)
142 {
143     nfcExtHandle = dlopen(VENDOR_NFC_EXT_SERVICE_LIB.c_str(), RTLD_LAZY | RTLD_GLOBAL);
144     if (nfcExtHandle == nullptr) {
145         HDF_LOGE("%{public}s: fail to get nfc ext service handle.", __func__);
146         return false;
147     }
148     nfcExtInf.checkNfcBootloaderStatus = reinterpret_cast<int (*)()>
149         (dlsym(nfcExtHandle, EXT_CHECK_NFC_BOOTLOADER_STATUS.c_str()));
150     if (nfcExtInf.checkNfcBootloaderStatus == nullptr) {
151         HDF_LOGE("%{public}s: fail to init func ptr.", __func__);
152         dlclose(nfcExtHandle);
153         nfcExtHandle = nullptr;
154         return false;
155     }
156     if (nfcExtInf.checkNfcBootloaderStatus() == 0) {
157         dlclose(nfcExtHandle);
158         nfcExtHandle = nullptr;
159         HDF_LOGE("%{public}s: NFC in bootloader status", __func__);
160         return true;
161     }
162     dlclose(nfcExtHandle);
163     nfcExtHandle = nullptr;
164     HDF_LOGI("%{public}s: NFC in normal status", __func__);
165     return false;
166 }
167 
GetNfcHalFuncNameSuffix(const std::string & chipType)168 string NfcVendorAdaptions::GetNfcHalFuncNameSuffix(const std::string &chipType)
169 {
170     string suffix = DEFAULT_FUNC_NAME_SUFFIX;
171     if (nfcExtInf.getNfcHalFuncNameSuffix != nullptr) {
172         suffix = string(nfcExtInf.getNfcHalFuncNameSuffix(chipType.c_str()));
173     }
174     return suffix;
175 }
176 
ResetNfcInterface(void)177 void NfcVendorAdaptions::ResetNfcInterface(void)
178 {
179     nfcHalHandle = nullptr;
180     nfcHalInf.nfcHalOpen = nullptr;
181     nfcHalInf.nfcHalWrite = nullptr;
182     nfcHalInf.nfcHalCoreInitialized = nullptr;
183     nfcHalInf.nfcHalPrediscover = nullptr;
184     nfcHalInf.nfcHalClose = nullptr;
185     nfcHalInf.nfcHalControlGranted = nullptr;
186     nfcHalInf.nfcHalPowerCycle = nullptr;
187     nfcHalInf.nfcHalIoctl = nullptr;
188     nfcHalInf.nfcHalGetConfig = nullptr;
189     nfcHalInf.nfcHalFactoryReset = nullptr;
190     nfcHalInf.nfcHalShutdownCase = nullptr;
191     nfcHalInf.nfcHalMinOpen = nullptr;
192     nfcHalInf.nfcHalMinClose = nullptr;
193     nfcExtHandle = nullptr;
194     nfcExtInf.getNfcChipType = nullptr;
195     nfcExtInf.getNfcHalFuncNameSuffix = nullptr;
196 }
197 
DoHalPreOpen(void * arg)198 void* NfcVendorAdaptions::DoHalPreOpen(void* arg)
199 {
200     NFCSTATUS status = HDF_SUCCESS;
201     if (arg == nullptr) {
202         return nullptr;
203     }
204     NfcVendorAdaptions *mVendorAdapter = static_cast<NfcVendorAdaptions*>(arg);
205     HDF_LOGI("%{public}s: enter.", __func__);
206     mVendorAdapter->isNfcPreDone = true;
207     if (mVendorAdapter->nfcHalInf.nfcHalMinOpen == nullptr ||
208         mVendorAdapter->nfcHalInf.nfcHalMinClose == nullptr) {
209         HDF_LOGE("%{public}s: function is null", __func__);
210         return nullptr;
211     }
212     std::lock_guard<std::mutex> lock(g_openMutex);
213     if (mVendorAdapter->CheckNfcBootloaderStatus()) {
214         mVendorAdapter->UpdateNfcOpenStatus(NFC_OPENING_STATUS);
215         status = mVendorAdapter->nfcHalInf.nfcHalMinOpen(true);
216         if (status != HDF_SUCCESS) {
217             HDF_LOGE("%{public}s: nfcHalMinOpen is fail", __func__);
218             mVendorAdapter->UpdateNfcOpenStatus(NFC_CLOSE_STATUS);
219             WriteBootloaderHiSysEvent(BOOTLOADER_STATUS_RECOVER_FAILED);
220             return nullptr;
221         }
222         status = mVendorAdapter->nfcHalInf.nfcHalMinClose();
223         if (status != HDF_SUCCESS) {
224             HDF_LOGE("%{public}s: nfcHalMinClose is fail", __func__);
225             mVendorAdapter->UpdateNfcOpenStatus(NFC_OPEN_STATUS);
226             WriteBootloaderHiSysEvent(BOOTLOADER_STATUS_RECOVER_FAILED);
227             return nullptr;
228         }
229         mVendorAdapter->UpdateNfcOpenStatus(NFC_CLOSE_STATUS);
230         WriteBootloaderHiSysEvent(BOOTLOADER_STATUS_RECOVER_SUCCESS);
231     }
232     HDF_LOGI("%{public}s: exit.", __func__);
233     return nullptr;
234 }
235 
HalPreOpen(void)236 void NfcVendorAdaptions::HalPreOpen(void)
237 {
238     int ret = HDF_SUCCESS;
239     pthread_t pthread;
240     HDF_LOGI("%{public}s: enter.", __func__);
241     if (!isNfcPreDone) {
242         ret = pthread_create(&pthread, nullptr, NfcVendorAdaptions::DoHalPreOpen, this);
243         if (ret != HDF_SUCCESS) {
244             HDF_LOGE("%{public}s: pthread_create is fail", __func__);
245         }
246     }
247     HDF_LOGI("%{public}s: exit.", __func__);
248 }
249 
PreInitNfcHalInterfaces(string nfcHalSoName,string suffix)250 int8_t NfcVendorAdaptions::PreInitNfcHalInterfaces(string nfcHalSoName, string suffix)
251 {
252     if (nfcHalHandle == nullptr) {
253         nfcHalHandle = dlopen(nfcHalSoName.c_str(), RTLD_LAZY | RTLD_GLOBAL);
254     }
255     if (nfcHalHandle == nullptr) {
256         HDF_LOGE("%{public}s: invalid input path, opening default hal lib", __func__);
257         nfcHalSoName = NFC_HAL_SO_DEFAULT_NAME;
258         suffix = DEFAULT_FUNC_NAME_SUFFIX;
259         nfcHalHandle = dlopen(nfcHalSoName.c_str(), RTLD_LAZY | RTLD_GLOBAL);
260     }
261     if (nfcHalHandle == nullptr) {
262         HDF_LOGE("%{public}s: fail to open hal path.", __func__);
263         return HDF_FAILURE;
264     }
265     return HDF_SUCCESS;
266 }
267 
InitNfcHalInterfaces(string nfcHalSoName,string suffix)268 int8_t NfcVendorAdaptions::InitNfcHalInterfaces(string nfcHalSoName, string suffix)
269 {
270     int8_t ret = PreInitNfcHalInterfaces(nfcHalSoName, suffix);
271     if (ret != HDF_SUCCESS) {
272         return ret;
273     }
274     nfcHalInf.nfcHalOpen = reinterpret_cast<int (*)(NfcStackCallbackT *, NfcStackDataCallbackT *)>
275         (dlsym(nfcHalHandle, (HAL_OPEN_FUNC_NAME + suffix).c_str()));
276 
277     nfcHalInf.nfcHalWrite = reinterpret_cast<int (*)(uint16_t, const uint8_t *)>
278         (dlsym(nfcHalHandle, (HAL_WRITE_FUNC_NAME + suffix).c_str()));
279 
280     nfcHalInf.nfcHalCoreInitialized = reinterpret_cast<int (*)(uint16_t, uint8_t *)>
281         (dlsym(nfcHalHandle, (HAL_CORE_INIT_FUNC_NAME + suffix).c_str()));
282 
283     nfcHalInf.nfcHalPrediscover = reinterpret_cast<int (*)()>
284         (dlsym(nfcHalHandle, (HAL_PRE_DISC_FUNC_NAME + suffix).c_str()));
285 
286     nfcHalInf.nfcHalClose = reinterpret_cast<int (*)(bool)>
287         (dlsym(nfcHalHandle, (HAL_CLOSE_FUNC_NAME + suffix).c_str()));
288 
289     nfcHalInf.nfcHalControlGranted = reinterpret_cast<int (*)()>
290         (dlsym(nfcHalHandle, (HAL_CTRL_GRANTED_FUNC_NAME + suffix).c_str()));
291 
292     nfcHalInf.nfcHalPowerCycle = reinterpret_cast<int (*)()>
293         (dlsym(nfcHalHandle, (HAL_POWER_CYCLE_FUNC_NAME + suffix).c_str()));
294 
295     nfcHalInf.nfcHalIoctl = reinterpret_cast<int (*)(long, void *)>
296         (dlsym(nfcHalHandle, (HAL_IOCTL_FUNC_NAME + suffix).c_str()));
297 
298     nfcHalInf.nfcHalGetConfig = reinterpret_cast<void (*)(V1_1::NfcVendorConfig &)>
299         (dlsym(nfcHalHandle, (HAL_GET_CONFIG_FUNC_NAME + suffix).c_str()));
300 
301     nfcHalInf.nfcHalFactoryReset = reinterpret_cast<void (*)()>
302         (dlsym(nfcHalHandle, (HAL_FACTORY_RESET_FUNC_NAME + suffix).c_str()));
303 
304     nfcHalInf.nfcHalShutdownCase = reinterpret_cast<int (*)()>
305         (dlsym(nfcHalHandle, (HAL_SHUTDOWN_CASE_FUNC_NAME + suffix).c_str()));
306 
307     nfcHalInf.nfcHalMinOpen = reinterpret_cast<NFCSTATUS (*)(bool)>
308         (dlsym(nfcHalHandle, (HAL_MIN_OPEN_FUNC_NAME + suffix).c_str()));
309 
310     nfcHalInf.nfcHalMinClose = reinterpret_cast<NFCSTATUS (*)()>
311         (dlsym(nfcHalHandle, (HAL_MIN_CLOSE_FUNC_NAME + suffix).c_str()));
312 
313     if (nfcHalInf.nfcHalOpen == nullptr || nfcHalInf.nfcHalWrite == nullptr ||
314         nfcHalInf.nfcHalCoreInitialized == nullptr || nfcHalInf.nfcHalPrediscover == nullptr ||
315         nfcHalInf.nfcHalClose == nullptr || nfcHalInf.nfcHalControlGranted == nullptr ||
316         nfcHalInf.nfcHalPowerCycle == nullptr || nfcHalInf.nfcHalIoctl == nullptr ||
317         nfcHalInf.nfcHalGetConfig == nullptr || nfcHalInf.nfcHalFactoryReset == nullptr ||
318         nfcHalInf.nfcHalShutdownCase == nullptr) {
319         HDF_LOGE("%{public}s: fail to init func ptr.", __func__);
320         return HDF_FAILURE;
321     }
322     HDF_LOGI("%{public}s: init nfc hal inf successfully.", __func__);
323     return HDF_SUCCESS;
324 }
325 
NfcVendorAdaptions()326 NfcVendorAdaptions::NfcVendorAdaptions()
327 {
328     ResetNfcInterface();
329     if (nfcHalHandle == nullptr) {
330         CheckFirmwareUpdate();
331         string chipType = GetChipType();
332         string nfcHalSoName = GetNfcHalSoName(chipType);
333         string nfcHalFuncNameSuffix = GetNfcHalFuncNameSuffix(chipType);
334         if (InitNfcHalInterfaces(nfcHalSoName, nfcHalFuncNameSuffix) != HDF_SUCCESS) {
335             HDF_LOGE("%{public}s: fail to init hal inf.", __func__);
336         }
337         HalPreOpen();
338     }
339 }
340 
~NfcVendorAdaptions()341 NfcVendorAdaptions::~NfcVendorAdaptions() {}
342 
SetPriority()343 void NfcVendorAdaptions::SetPriority()
344 {
345     if (setpriority(PRIO_PROCESS, 0, PRIORITY) != 0) {
346         HDF_LOGE("setpriority err %{public}s", strerror(errno));
347         return;
348     }
349     HDF_LOGE("setpriority succeed.");
350 }
351 
VendorOpen(NfcStackCallbackT * pCback,NfcStackDataCallbackT * pDataCback)352 int NfcVendorAdaptions::VendorOpen(NfcStackCallbackT *pCback, NfcStackDataCallbackT *pDataCback)
353 {
354     if (nfcHalInf.nfcHalOpen == nullptr) {
355         HDF_LOGE("%{public}s: Function null.", __func__);
356         return HDF_FAILURE;
357     }
358     if (pCback == nullptr || pDataCback == nullptr) {
359         HDF_LOGE("%{public}s: input param null.", __func__);
360         return HDF_FAILURE;
361     }
362     std::lock_guard<std::mutex> lock(g_openMutex);
363     SetPriority();
364     CheckFirmwareUpdate();
365     int ret = nfcHalInf.nfcHalOpen(pCback, pDataCback);
366     return ret;
367 }
368 
VendorCoreInitialized(uint16_t coreInitRspLen,uint8_t * pCoreInitRspParams)369 int NfcVendorAdaptions::VendorCoreInitialized(uint16_t coreInitRspLen, uint8_t *pCoreInitRspParams)
370 {
371     if (nfcHalInf.nfcHalCoreInitialized == nullptr) {
372         HDF_LOGE("%{public}s: Function null.", __func__);
373         return HDF_FAILURE;
374     }
375     if (pCoreInitRspParams == nullptr) {
376         HDF_LOGE("%{public}s: input param null.", __func__);
377         return HDF_FAILURE;
378     }
379     int ret = nfcHalInf.nfcHalCoreInitialized(coreInitRspLen, pCoreInitRspParams);
380     return ret;
381 }
382 
VendorWrite(uint16_t dataLen,const uint8_t * pData)383 int NfcVendorAdaptions::VendorWrite(uint16_t dataLen, const uint8_t *pData)
384 {
385     if (nfcHalInf.nfcHalWrite == nullptr) {
386         HDF_LOGE("%{public}s: Function null.", __func__);
387         return HDF_FAILURE;
388     }
389     if (pData == nullptr) {
390         HDF_LOGE("%{public}s: input param null.", __func__);
391         return HDF_FAILURE;
392     }
393     int ret = nfcHalInf.nfcHalWrite(dataLen, pData);
394     return ret;
395 }
396 
VendorPrediscover(void)397 int NfcVendorAdaptions::VendorPrediscover(void)
398 {
399     if (nfcHalInf.nfcHalPrediscover == nullptr) {
400         HDF_LOGE("%{public}s: Function null.", __func__);
401         return HDF_FAILURE;
402     }
403     int ret = nfcHalInf.nfcHalPrediscover();
404     return ret;
405 }
406 
VendorClose(bool bShutdown)407 int NfcVendorAdaptions::VendorClose(bool bShutdown)
408 {
409     if (nfcHalInf.nfcHalClose == nullptr) {
410         HDF_LOGE("%{public}s: Function null.", __func__);
411         return HDF_FAILURE;
412     }
413     int ret = nfcHalInf.nfcHalClose(bShutdown);
414     return ret;
415 }
416 
VendorControlGranted(void)417 int NfcVendorAdaptions::VendorControlGranted(void)
418 {
419     if (nfcHalInf.nfcHalControlGranted == nullptr) {
420         HDF_LOGE("%{public}s: Function null.", __func__);
421         return HDF_FAILURE;
422     }
423     int ret = nfcHalInf.nfcHalControlGranted();
424     return ret;
425 }
426 
VendorPowerCycle(void)427 int NfcVendorAdaptions::VendorPowerCycle(void)
428 {
429     if (nfcHalInf.nfcHalPowerCycle == nullptr) {
430         HDF_LOGE("%{public}s: Function null.", __func__);
431         return HDF_FAILURE;
432     }
433     int ret = nfcHalInf.nfcHalPowerCycle();
434     return ret;
435 }
436 
VendorIoctl(long arg,void * pData)437 int NfcVendorAdaptions::VendorIoctl(long arg, void *pData)
438 {
439     if (nfcHalInf.nfcHalIoctl == nullptr) {
440         HDF_LOGE("%{public}s: Function null.", __func__);
441         return HDF_FAILURE;
442     }
443     if (pData == nullptr) {
444         HDF_LOGE("%{public}s: input param null.", __func__);
445         return HDF_FAILURE;
446     }
447     int ret = nfcHalInf.nfcHalIoctl(arg, pData);
448     return ret;
449 }
450 
VendorIoctlWithResponse(long arg,void * pData,uint16_t dataLen,std::vector<uint8_t> & pRetVal)451 int NfcVendorAdaptions::VendorIoctlWithResponse(long arg, void *pData, uint16_t dataLen, std::vector<uint8_t> &pRetVal)
452 {
453     if (nfcHalInf.nfcHalIoctl == nullptr) {
454         HDF_LOGE("%{public}s: Function null.", __func__);
455         return HDF_FAILURE;
456     }
457     if (pData == nullptr) {
458         HDF_LOGE("%{public}s: input param null.", __func__);
459         return HDF_FAILURE;
460     }
461     if (arg == VENDOR_GET_HISTORY_NCI_CMD) {
462         HDF_LOGI("%{public}s: getting history nci from vendor!", __func__);
463         return VendorGetHistoryNci(pData, dataLen, pRetVal);
464     }
465     if (dataLen < VENDOR_IOCTL_INPUT_MIN_LEN || dataLen > VENDOR_IOCTL_TOTAL_LEN) {
466         HDF_LOGE("%{public}s: dataLen is invalid!", __func__);
467         return HDF_ERR_INVALID_PARAM;
468     }
469     uint8_t inOutData[VENDOR_IOCTL_TOTAL_LEN] = { 0 };
470     if (memcpy_s(inOutData, VENDOR_IOCTL_TOTAL_LEN, pData, VENDOR_IOCTL_INOUT_DATA_LEN) != EOK) {
471         HDF_LOGE("%{public}s: memcpy_s pData failed.", __func__);
472         return HDF_FAILURE;
473     }
474     int ret = nfcHalInf.nfcHalIoctl(arg, inOutData);
475     if (ret == HDF_SUCCESS) {
476         uint8_t* pTmp = inOutData;
477         int i;
478         for (i = 0; i <= pTmp[VENDOR_IOCTL_OUTPUT_LEN_INDEX]; i++) {
479             pRetVal.push_back(pTmp[VENDOR_IOCTL_OUTPUT_LEN_INDEX + i]);
480         }
481     }
482     return ret;
483 }
484 
VendorGetHistoryNci(void * pData,uint16_t dataLen,std::vector<uint8_t> & pRetVal)485 int NfcVendorAdaptions::VendorGetHistoryNci(void *pData, uint16_t dataLen, std::vector<uint8_t> &pRetVal)
486 {
487     if (dataLen != VENDOR_IOCTL_INPUT_DATA_LEN) {
488         HDF_LOGE("%{public}s: input param data len err.", __func__);
489         return HDF_FAILURE;
490     }
491     std::vector<uint8_t> inOutData(VENDOR_IOCTL_TOTAL_LENGTH, 0);
492     if (memcpy_s(&inOutData[0], inOutData.size(), pData, dataLen) != EOK) {
493         HDF_LOGE("%{public}s: memcpy_s pData failed.", __func__);
494         return HDF_FAILURE;
495     }
496     int ret = nfcHalInf.nfcHalIoctl(VENDOR_GET_HISTORY_NCI_CMD, &inOutData[0]);
497     if (ret == HDF_SUCCESS) {
498         for (uint16_t i = 0; i < VENDOR_IOCTL_OUTPUT_DATA_LEN; i++) {
499             pRetVal.push_back(inOutData[VENDOR_IOCTL_OUTPUT_DATA_START_INDEX + i]);
500         }
501     }
502     return ret;
503 }
504 
VendorGetConfig(V1_1::NfcVendorConfig & config)505 int NfcVendorAdaptions::VendorGetConfig(V1_1::NfcVendorConfig &config)
506 {
507     HDF_LOGD("%{public}s: start.", __func__);
508     if (nfcHalInf.nfcHalGetConfig == nullptr) {
509         HDF_LOGE("%{public}s: Function null.", __func__);
510         return HDF_FAILURE;
511     }
512     nfcHalInf.nfcHalGetConfig(config);
513     return HDF_SUCCESS;
514 }
515 
VendorFactoryReset(void)516 int NfcVendorAdaptions::VendorFactoryReset(void)
517 {
518     HDF_LOGD("%{public}s: start.", __func__);
519     if (nfcHalInf.nfcHalFactoryReset == nullptr) {
520         HDF_LOGE("%{public}s: Function null.", __func__);
521         return HDF_FAILURE;
522     }
523     nfcHalInf.nfcHalFactoryReset();
524     return HDF_SUCCESS;
525 }
526 
VendorShutdownCase(void)527 int NfcVendorAdaptions::VendorShutdownCase(void)
528 {
529     HDF_LOGD("%{public}s: start.", __func__);
530     if (nfcHalInf.nfcHalShutdownCase == nullptr) {
531         HDF_LOGE("%{public}s: Function null.", __func__);
532         return HDF_FAILURE;
533     }
534     int ret = nfcHalInf.nfcHalShutdownCase();
535     return ret;
536 }
537 } // Nfc
538 } // HDI
539 } // OHOS