• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 USBFN_INTERFACE_H
17 #define USBFN_INTERFACE_H
18 
19 #include "usb_object.h"
20 #include "usbfn_request.h"
21 
22 /* Interface class codes */
23 #define USB_INTERFACE_CLASS_UNSPEC              0x00
24 #define USB_INTERFACE_CLASS_AUDIO               0x01
25 #define USB_INTERFACE_CLASS_CDC                 0x02
26 #define USB_INTERFACE_CLASS_HID                 0x03
27 #define USB_INTERFACE_CLASS_PHYSICAL            0x05
28 #define USB_INTERFACE_CLASS_IMAGE               0x06
29 #define USB_INTERFACE_CLASS_PRINTER             0x07
30 #define USB_INTERFACE_CLASS_MASS_STORAGE        0x08
31 #define USB_INTERFACE_CLASS_HUB                 0x09
32 #define USB_INTERFACE_CLASS_CDC_DATA            0x0a
33 #define USB_INTERFACE_CLASS_SMARTCARD           0x0b
34 #define USB_INTERFACE_CLASS_FIRM_UPD            0x0c
35 #define USB_INTERFACE_CLASS_SECURITY            0x0d
36 #define USB_INTERFACE_CLASS_VIDEO               0x0e
37 #define USB_INTERFACE_CLASS_DIAGNOSTIC          0xdc
38 #define USB_INTERFACE_CLASS_WIRELESS            0xe0
39 #define USB_INTERFACE_CLASS_IAD                 0xef
40 #define USB_INTERFACE_CLASS_APP_SPEC            0xfe
41 #define USB_INTERFACE_CLASS_VENDOR              0xff
42 
43 typedef enum {
44     USBFN_STATE_BIND,
45     USBFN_STATE_UNBIND,
46     USBFN_STATE_ENABLE,
47     USBFN_STATE_DISABLE,
48     USBFN_STATE_SETUP,
49     USBFN_STATE_SUSPEND,
50     USBFN_STATE_RESUME,
51 } UsbFnDeviceState;
52 
53 struct UsbFnCtrlRequest {
54     uint8_t reqType;
55     uint8_t request;
56     uint16_t value;
57     uint16_t index;
58     uint16_t length;
59 } __attribute__((packed));
60 
61 struct UsbFnEvent {
62     struct UsbFnCtrlRequest *setup;
63     UsbFnDeviceState        type;
64     void                    *context;
65 };
66 
67 struct UsbFnInterfaceInfo {
68     uint8_t index;              /* the index number of this interface */
69     uint8_t numPipes;           /* the number of pipes on this interface */
70     uint8_t interfaceClass;     /* class code for this interface */
71     uint8_t subclass;           /* subclass code for this interface */
72     uint8_t protocol;           /* protocol code for this interface */
73     uint8_t configIndex;        /* config number for this interface */
74 };
75 
76 struct UsbFnInterface {
77     const struct UsbObject    *object;
78     struct UsbFnInterfaceInfo info;
79 };
80 
81 struct UsbFnPipeInfo {
82     uint8_t           id;
83     UsbPipeType       type;
84     UsbPipeDirection  dir;
85     uint16_t          maxPacketSize;
86     uint8_t           interval;
87 };
88 
89 typedef void (*UsbFnEventCallback)(struct UsbFnEvent *event);
90 typedef int32_t (*UsbFnPropCallback)(const struct UsbFnInterface *intf, const char *name, const char *value);
91 
92 struct UsbFnRegistInfo {
93     const char *name;
94     const char *value;
95     UsbFnPropCallback getProp;
96     UsbFnPropCallback setProp;
97 };
98 
99 int UsbFnStartRecvInterfaceEvent(struct UsbFnInterface *interface, uint32_t eventMask,
100     UsbFnEventCallback callback, void *context);
101 int UsbFnStopRecvInterfaceEvent(struct UsbFnInterface *interface);
102 UsbFnInterfaceHandle UsbFnOpenInterface(struct UsbFnInterface *interface);
103 int UsbFnCloseInterface(UsbFnInterfaceHandle handle);
104 int UsbFnGetInterfacePipeInfo(struct UsbFnInterface *interface, uint8_t pipeId, struct UsbFnPipeInfo *info);
105 int UsbFnRegistInterfaceProp(const struct UsbFnInterface *interface,
106     const struct UsbFnRegistInfo *registInfo);
107 int UsbFnGetInterfaceProp(const struct UsbFnInterface *interface,
108     const char *name, char *value);
109 int UsbFnSetInterfaceProp(const struct UsbFnInterface *interface,
110     const char *name, const char *value);
111 
112 #endif /* USBFN_INTERFACE_H */
113