1 /*
2 * Copyright (c) 2024 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
16 #include "usbgetinterfacestatus_fuzzer.h"
17 #include "hdf_log.h"
18 #include "securec.h"
19 #include "usbcommonfunction_fuzzer.h"
20 #include "v1_1/iusb_interface.h"
21
22 using namespace OHOS::HDI::Usb::V1_1;
23
24 struct Parameters {
25 uint8_t interfaceId;
26 };
27
28 namespace OHOS {
29 namespace USB {
UsbGetInterfaceStatusFuzzTest(const uint8_t * data,size_t size)30 bool UsbGetInterfaceStatusFuzzTest(const uint8_t *data, size_t size)
31 {
32 (void)size;
33 UsbDev dev;
34 sptr<OHOS::HDI::Usb::V1_1::IUsbInterface> usbInterface = OHOS::HDI::Usb::V1_1::IUsbInterface::Get();
35 int32_t ret = UsbFuzzTestHostModeInit(dev, usbInterface);
36 if (ret != HDF_SUCCESS) {
37 HDF_LOGE("%{public}s: UsbFuzzTestHostModeInit failed", __func__);
38 return false;
39 }
40
41 Parameters param;
42 if (memcpy_s((void *)¶m, sizeof(param), data, sizeof(param)) != EOK) {
43 HDF_LOGE("%{public}s: memcpy_s failed", __func__);
44 return false;
45 }
46 bool unactived;
47 ret = usbInterface->GetInterfaceActiveStatus(dev, param.interfaceId, unactived);
48 if (ret == HDF_SUCCESS) {
49 HDF_LOGI("%{public}s: bulk Write succeed", __func__);
50 }
51
52 ret = usbInterface->CloseDevice(dev);
53 if (ret != HDF_SUCCESS) {
54 HDF_LOGE("%{public}s: close device failed", __func__);
55 return false;
56 }
57 return true;
58 }
59 } // namespace USB
60 } // namespace OHOS
61
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
63 {
64 OHOS::USB::UsbGetInterfaceStatusFuzzTest(data, size);
65 return 0;
66 }