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 "usbsetcurrentfunctions_fuzzer.h"
17 #include "hdf_log.h"
18 #include "usbcommonfunction_fuzzer.h"
19 #include "v1_0/iusb_interface.h"
20
21 using namespace OHOS::HDI::Usb::V1_0;
22
23 namespace OHOS {
24 namespace USB {
UsbSetCurrentFunctionsFuzzTest(const uint8_t * data,size_t size)25 bool UsbSetCurrentFunctionsFuzzTest(const uint8_t *data, size_t size)
26 {
27 (void)size;
28 sptr<IUsbInterface> usbInterface = IUsbInterface::Get();
29 int32_t ret = usbInterface->SetPortRole(DEFAULT_PORT_ID, DEFAULT_ROLE_DEVICE, DEFAULT_ROLE_DEVICE);
30 sleep(SLEEP_TIME);
31 if (ret != HDF_SUCCESS) {
32 HDF_LOGE("%{public}s: set port role as host failed", __func__);
33 return ret;
34 }
35
36 int32_t timeout = *(reinterpret_cast<int32_t *>(*data));
37 ret = usbInterface->SetCurrentFunctions(func);
38 if (ret == HDF_SUCCESS) {
39 HDF_LOGI("%{public}s: set interface succeed", __func__);
40 }
41 return true;
42 }
43 } // namespace USB
44 } // namespace OHOS
45
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
47 {
48 OHOS::USB::UsbSetCurrentFunctionsFuzzTest(data, size);
49 return 0;
50 }