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 "usbcommonfunction_fuzzer.h"
17 #include "UsbSubscriberTest.h"
18 #include "hdf_log.h"
19
20 using namespace OHOS::HDI::Usb::V1_0;
21
22 namespace OHOS {
23 namespace USB {
UsbFuzzTestHostModeInit(UsbDev & dev,const sptr<IUsbInterface> & usbInterface)24 int32_t UsbFuzzTestHostModeInit(UsbDev &dev, const sptr<IUsbInterface> &usbInterface)
25 {
26 int32_t ret = usbInterface->SetPortRole(DEFAULT_PORT_ID, DEFAULT_ROLE_HOST, DEFAULT_ROLE_HOST);
27 sleep(SLEEP_TIME);
28 if (ret != HDF_SUCCESS) {
29 HDF_LOGE("%{public}s: set port role as host failed", __func__);
30 return ret;
31 }
32
33 sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
34 ret = usbInterface->BindUsbdSubscriber(subscriber);
35 if (ret != HDF_SUCCESS) {
36 HDF_LOGE("%{public}s: bind usbd subscriber failed", __func__);
37 return ret;
38 }
39
40 dev.busNum = subscriber->busNum_;
41 dev.devAddr = subscriber->devAddr_;
42 HDF_LOGI("%{public}s: busNum:%{public}d, devAddr:%{public}d", __func__, subscriber->busNum_, subscriber->devAddr_);
43 ret = usbInterface->OpenDevice(dev);
44 if (ret != HDF_SUCCESS) {
45 HDF_LOGE("%{public}s: open device failed", __func__);
46 return ret;
47 }
48 return ret;
49 }
50 } // namespace USB
51 } // namespace OHOS