• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef OHOS_HDI_USB_V2_0_USB_HOST_IMPL_H
17 #define OHOS_HDI_USB_V2_0_USB_HOST_IMPL_H
18 
19 #include <iostream>
20 
21 #include "hdf_slist.h"
22 #include "usb_host_data.h"
23 #include "usbd_function.h"
24 #include "usbd_port.h"
25 #include "v2_0/iusb_host_interface.h"
26 
27 #define BASE_CLASS_HUB 0x09
28 constexpr uint8_t MAX_INTERFACEID = 0xFF;
29 namespace OHOS {
30 namespace HDI {
31 namespace Usb {
32 namespace V2_0 {
33 class UsbHostImpl : public IUsbHostInterface {
34 public:
35 
36     UsbHostImpl();
37     ~UsbHostImpl() override;
38     int32_t OpenDevice(const UsbDev &dev) override;
39     int32_t CloseDevice(const UsbDev &dev) override;
40     int32_t GetStringDescriptor(const UsbDev &dev, uint8_t descId, std::vector<uint8_t> &descriptor) override;
41     int32_t GetRawDescriptor(const UsbDev &dev, std::vector<uint8_t> &descriptor) override;
42     int32_t SetConfig(const UsbDev &dev, uint8_t configIndex) override;
43     int32_t GetConfig(const UsbDev &dev, uint8_t &configIndex) override;
44     int32_t ClaimInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t force) override;
45     int32_t ManageInterface(const UsbDev &dev, uint8_t interfaceId, bool disable) override;
46     int32_t ReleaseInterface(const UsbDev &dev, uint8_t interfaceId) override;
47     int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex) override;
48     int32_t BulkTransferRead(
49         const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector<uint8_t> &data) override;
50     int32_t BulkTransferWrite(
51         const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, const std::vector<uint8_t> &data) override;
52     int32_t ControlTransferRead(const UsbDev &dev, const UsbCtrlTransfer &ctrl, std::vector<uint8_t> &data) override;
53     int32_t ControlTransferWrite(
54         const UsbDev &dev, const UsbCtrlTransfer &ctrl, const std::vector<uint8_t> &data) override;
55     int32_t BindUsbdHostSubscriber(const sptr<IUsbdSubscriber> &subscriber) override;
56     int32_t UnbindUsbdHostSubscriber(const sptr<IUsbdSubscriber> &subscriber) override;
57     int32_t GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool &unactivated) override;
58     int32_t GetDeviceSpeed(const UsbDev &dev, uint8_t &speed) override;
59     int32_t BulkTransferReadwithLength(const UsbDev &dev,
60         const UsbPipe &pipe, int32_t timeout, int32_t length, std::vector<uint8_t> &data) override;
61     int32_t GetDeviceFileDescriptor(const UsbDev &dev, int32_t &fd) override;
62     int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe) override;
63     int32_t ControlTransferReadwithLength(
64         const UsbDev &dev, const UsbCtrlTransferParams &ctrlParams, std::vector<uint8_t> &data) override;
65     int32_t ResetDevice(const UsbDev &dev) override;
66     int32_t RequestQueue(const UsbDev &dev, const UsbPipe &pipe, const std::vector<uint8_t> &clientData,
67         const std::vector<uint8_t> &buffer) override;
68     int32_t GetDeviceDescriptor(const UsbDev &dev, std::vector<uint8_t> &descriptor) override;
69     int32_t GetConfigDescriptor(const UsbDev &dev, uint8_t descId, std::vector<uint8_t> &descriptor) override;
70     int32_t GetFileDescriptor(const UsbDev &dev, int32_t &fd) override;
71     int32_t InterruptTransferRead(
72         const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector<uint8_t> &data) override;
73     int32_t InterruptTransferWrite(
74         const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, const std::vector<uint8_t> &data) override;
75     int32_t IsoTransferRead(
76         const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector<uint8_t> &data) override;
77     int32_t IsoTransferWrite(
78         const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, const std::vector<uint8_t> &data) override;
79     int32_t RegBulkCallback(const UsbDev &dev, const UsbPipe &pipe, const sptr<IUsbdBulkCallback> &cb) override;
80     int32_t UnRegBulkCallback(const UsbDev &dev, const UsbPipe &pipe) override;
81     int32_t BulkRead(const UsbDev &dev, const UsbPipe &pipe, const sptr<Ashmem> &ashmem) override;
82     int32_t BulkWrite(const UsbDev &dev, const UsbPipe &pipe, const sptr<Ashmem> &ashmem) override;
83     int32_t BulkCancel(const UsbDev &dev, const UsbPipe &pipe) override;
84     int32_t RequestWait(
85         const UsbDev &dev, std::vector<uint8_t> &clientData, std::vector<uint8_t> &buffer, int32_t timeout) override;
86     int32_t RequestCancel(const UsbDev &dev, const UsbPipe &pipe) override;
87     int32_t UsbSubmitTransfer(const UsbDev &dev, const USBTransferInfo &info, const sptr<IUsbdTransferCallback> &cb,
88         const sptr<Ashmem> &ashmem) override;
89     int32_t UsbCancelTransfer(const UsbDev &dev, const int32_t endpoint) override;
90 private:
91     static bool isGadgetConnected_;
92 };
93 } // namespace V2_0
94 } // namespace Usb
95 } // namespace HDI
96 } // namespace OHOS
97 #endif // OHOS_HDI_USB_V2_0_USB_HOST_IMPL_H