• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 USB_DEV_SUBSCRIBER_H
17 #define USB_DEV_SUBSCRIBER_H
18 #include "ibus_extension.h"
19 #include "usb_device_info.h"
20 #ifdef EXTDEVMGR_USB_PASS_THROUGH
21 #include "v2_0/iusb_host_interface.h"
22 #else
23 #include "v1_0/iusbd_subscriber.h"
24 #include "v1_0/iusb_interface.h"
25 #endif // EXTDEVMGR_USB_PASS_THROUGH
26 #include "v1_1/iusb_ddk.h"
27 #include "usb_config_desc_parser.h"
28 namespace OHOS {
29 namespace ExternalDeviceManager {
30 #ifdef EXTDEVMGR_USB_PASS_THROUGH
31 using namespace OHOS::HDI::Usb::V2_0;
32 #else
33 using namespace OHOS::HDI::Usb::V1_0;
34 #endif // EXTDEVMGR_USB_PASS_THROUGH
35 using namespace OHOS::HDI::Usb::Ddk;
36 
37 struct UsbDevDescLite {
38     uint8_t bLength;
39     uint8_t bDescriptorType;
40     uint16_t bcdUSB;
41     uint8_t bDeviceClass;
42     uint8_t bDeviceSubClass;
43     uint8_t bDeviceProtocol;
44     uint8_t bMaxPacketSize0;
45     uint16_t idVendor;
46     uint16_t idProduct;
47     uint16_t bcdDevice;
48     uint8_t iManufacturer;
49     uint8_t iProduct;
50     uint8_t iSerialNumber;
51     uint8_t bNumConfigurations;
52 } __attribute__((packed));
53 
54 class UsbDevSubscriber : public IUsbdSubscriber {
55 public:
56 #ifdef EXTDEVMGR_USB_PASS_THROUGH
57     void Init(shared_ptr<IDevChangeCallback> callback, sptr<IUsbHostInterface> iusb, sptr<V1_1::IUsbDdk> iUsbDdk);
58 #else
59     void Init(shared_ptr<IDevChangeCallback> callback, sptr<IUsbInterface> iusb, sptr<V1_1::IUsbDdk> iUsbDdk);
60 #endif // EXTDEVMGR_USB_PASS_THROUGH
61     int32_t DeviceEvent(const USBDeviceInfo &info) override;
62     int32_t PortChangedEvent(const PortInfo &info) override;
63 private:
64     shared_ptr<IDevChangeCallback> callback_;
65 #ifdef EXTDEVMGR_USB_PASS_THROUGH
66     sptr<IUsbHostInterface> iusb_;
67 #else
68     sptr<IUsbInterface> iusb_;
69 #endif // EXTDEVMGR_USB_PASS_THROUGH
70     sptr<V1_1::IUsbDdk> iUsbDdk_;
71     int32_t OnDeviceConnect(const UsbDev &usbDev);
72     int32_t OnDeviceDisconnect(const UsbDev &usbDev);
73     int32_t GetInterfaceDescriptor(const UsbDev &usbDev, std::vector<UsbInterfaceDescriptor> &interfaceList);
74     std::string GetDevStringVal(const UsbDev &usbDev, uint8_t idx);
75     void SetUsbDevInfoValue(const UsbDevDescLite &deviceDescriptor, shared_ptr<UsbDeviceInfo> &usbDevInfo,
76         std::string snNum);
77     int32_t GetUsbDeviceDescriptor(const UsbDev &usbDev, UsbDevDescLite &deviceDescriptor);
78 };
79 }
80 }
81 #endif