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
16#include "usbsetconfig_fuzzer.h"
17#include "UsbSubscriberTest.h"
18#include "hdf_log.h"
19#include "usbcommonfunction_fuzzer.h"
20#include "v1_0/iusb_interface.h"
21
22using namespace OHOS::HDI::Usb::V1_0;
23
24namespace OHOS {
25namespace USB {
26bool UsbSetConfigFuzzTest(const uint8_t *data, size_t size)
27{
28    (void)size;
29    UsbDev dev;
30    sptr<IUsbInterface> usbInterface = IUsbInterface::Get();
31    int32_t ret = UsbFuzzTestHostModeInit(dev, usbInterface);
32    if (ret != HDF_SUCCESS) {
33        HDF_LOGE("%{public}s: UsbFuzzTestHostModeInit failed", __func__);
34        return false;
35    }
36
37    ret = usbInterface->SetConfig(dev, *data);
38    if (ret == HDF_SUCCESS) {
39        HDF_LOGI("%{public}s: set config succeed", __func__);
40    }
41
42    ret = usbInterface->CloseDevice(dev);
43    if (ret != HDF_SUCCESS) {
44        HDF_LOGE("%{public}s: close device failed", __func__);
45        return false;
46    }
47    return true;
48}
49} // namespace USB
50} // namespace OHOS
51
52extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
53{
54    OHOS::USB::UsbSetConfigFuzzTest(data, size);
55    return 0;
56}