• 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 SERIAL_SYSFS_DEVICE_H
17 #define SERIAL_SYSFS_DEVICE_H
18 #include <stdint.h>
19 #include <string>
20 
21 #define SERIAL_MAX_INTERFACES     32
22 #define SYSFS_DEVICES_DIR "/sys/bus/usb-serial/devices/"
23 
24 namespace OHOS {
25 namespace HDI {
26 namespace Usb {
27 namespace Serial {
28 namespace V1_0 {
29 
30 struct UsbPnpNotifyInterfaceInfo {
31     uint8_t interfaceClass;
32     uint8_t interfaceSubClass;
33     uint8_t interfaceProtocol;
34     uint8_t interfaceNumber;
35 };
36 
37 struct UsbPnpNotifyDeviceInfo {
38     uint16_t vendorId;
39     uint16_t productId;
40     uint16_t bcdDeviceLow;
41     uint16_t bcdDeviceHigh;
42     uint8_t deviceClass;
43     uint8_t deviceSubClass;
44     uint8_t deviceProtocol;
45     std::string serialNo;
46 };
47 
48 struct UsbPnpNotifyMatchInfoTable {
49     uint64_t usbDevAddr;
50     int32_t devNum;
51     int32_t busNum;
52 
53     struct UsbPnpNotifyDeviceInfo deviceInfo;
54 
55     uint8_t removeType;
56     uint8_t numInfos;
57 
58     struct UsbPnpNotifyInterfaceInfo interfaceInfo[SERIAL_MAX_INTERFACES];
59 };
60 
61 typedef struct DevInterfaceInfo {
62     uint32_t busNum;
63     uint32_t devNum;
64     uint8_t  intfNum;
65 } DevInterfaceInfo;
66 
67 uint64_t SerialMakeDevAddr(uint32_t busNum, uint32_t devNum);
68 int32_t SerialGetDevice(const char *deviceDir, struct UsbPnpNotifyMatchInfoTable *device);
69 } // V1_0
70 } // Serial
71 } // Usb
72 } // HDI
73 } // OHOS
74 #endif // SERIAL_SYSFS_DEVICE_H