1/* 2 * Copyright (c) 2022-2023 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 21using namespace OHOS::HDI::Usb::V1_0; 22 23namespace OHOS { 24namespace USB { 25bool UsbSetCurrentFunctionsFuzzTest(const uint8_t *data, size_t size) 26{ 27 (void)size; 28 (void)data; 29 sptr<IUsbInterface> usbInterface = IUsbInterface::Get(); 30 int32_t ret = usbInterface->SetPortRole(DEFAULT_PORT_ID, DEFAULT_ROLE_DEVICE, DEFAULT_ROLE_DEVICE); 31 sleep(SLEEP_TIME); 32 if (ret != HDF_SUCCESS) { 33 HDF_LOGE("%{public}s: set port role as host failed", __func__); 34 return ret; 35 } 36 37 ret = usbInterface->SetCurrentFunctions(func); 38 if (ret != HDF_SUCCESS) { 39 HDF_LOGE("%{public}s: set current function failed", __func__); 40 return false; 41 } 42 return true; 43} 44} // namespace USB 45} // namespace OHOS 46 47extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 48{ 49 OHOS::USB::UsbSetCurrentFunctionsFuzzTest(data, size); 50 return 0; 51}