FreeRDP
urbdrc_main.h
1 
21 #ifndef FREERDP_CHANNEL_URBDRC_CLIENT_MAIN_H
22 #define FREERDP_CHANNEL_URBDRC_CLIENT_MAIN_H
23 
24 #include <winpr/pool.h>
25 #include <freerdp/channels/log.h>
26 #include <freerdp/client/channels.h>
27 
28 #include <msusb.h>
29 
30 #define DEVICE_HARDWARE_ID_SIZE 32
31 #define DEVICE_COMPATIBILITY_ID_SIZE 36
32 #define DEVICE_INSTANCE_STR_SIZE 37
33 #define DEVICE_CONTAINER_STR_SIZE 39
34 
35 #define TAG CHANNELS_TAG("urbdrc.client")
36 #ifdef WITH_DEBUG_DVC
37 #define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
38 #else
39 #define DEBUG_DVC(...) \
40  do \
41  { \
42  } while (0)
43 #endif
44 
45 typedef struct S_IUDEVICE IUDEVICE;
46 typedef struct S_IUDEVMAN IUDEVMAN;
47 
48 #define BASIC_DEV_STATE_DEFINED(_arg, _type) \
49  _type (*get_##_arg)(IUDEVICE * pdev); \
50  void (*set_##_arg)(IUDEVICE * pdev, _type _arg)
51 
52 #define BASIC_DEVMAN_STATE_DEFINED(_arg, _type) \
53  _type (*get_##_arg)(IUDEVMAN * udevman); \
54  void (*set_##_arg)(IUDEVMAN * udevman, _type _arg)
55 
56 typedef struct
57 {
58  IWTSPlugin iface;
59 
60  GENERIC_LISTENER_CALLBACK* listener_callback;
61 
62  IUDEVMAN* udevman;
63  UINT32 vchannel_status;
64  char* subsystem;
65 
66  wLog* log;
67  IWTSListener* listener;
68  BOOL initialized;
70 
71 typedef BOOL (*PREGISTERURBDRCSERVICE)(IWTSPlugin* plugin, IUDEVMAN* udevman);
72 typedef struct
73 {
74  IWTSPlugin* plugin;
75  PREGISTERURBDRCSERVICE pRegisterUDEVMAN;
76  const ADDIN_ARGV* args;
79 
80 typedef UINT(VCAPITYPE* PFREERDP_URBDRC_DEVICE_ENTRY)(
82 
83 typedef struct
84 {
85  GENERIC_CHANNEL_CALLBACK* callback;
86  URBDRC_PLUGIN* urbdrc;
87  IUDEVMAN* udevman;
88  IWTSVirtualChannel* channel;
89  wStream* s;
91 
92 typedef void (*t_isoch_transfer_cb)(IUDEVICE* idev, GENERIC_CHANNEL_CALLBACK* callback,
93  wStream* out, UINT32 InterfaceId, BOOL noAck, UINT32 MessageId,
94  UINT32 RequestId, UINT32 NumberOfPackets, UINT32 status,
95  UINT32 StartFrame, UINT32 ErrorCount, UINT32 OutputBufferSize);
96 
97 struct S_IUDEVICE
98 {
99  /* Transfer */
100  int (*isoch_transfer)(IUDEVICE* idev, GENERIC_CHANNEL_CALLBACK* callback, UINT32 MessageId,
101  UINT32 RequestId, UINT32 EndpointAddress, UINT32 TransferFlags,
102  UINT32 StartFrame, UINT32 ErrorCount, BOOL NoAck,
103  const BYTE* packetDescriptorData, UINT32 NumberOfPackets,
104  UINT32 BufferSize, const BYTE* Buffer, t_isoch_transfer_cb cb,
105  UINT32 Timeout);
106 
107  BOOL(*control_transfer)
108  (IUDEVICE* idev, UINT32 RequestId, UINT32 EndpointAddress, UINT32 TransferFlags,
109  BYTE bmRequestType, BYTE Request, UINT16 Value, UINT16 Index, UINT32* UrbdStatus,
110  UINT32* BufferSize, BYTE* Buffer, UINT32 Timeout);
111 
112  int (*bulk_or_interrupt_transfer)(IUDEVICE* idev, GENERIC_CHANNEL_CALLBACK* callback,
113  UINT32 MessageId, UINT32 RequestId, UINT32 EndpointAddress,
114  UINT32 TransferFlags, BOOL NoAck, UINT32 BufferSize,
115  const BYTE* data, t_isoch_transfer_cb cb, UINT32 Timeout);
116 
117  int (*select_configuration)(IUDEVICE* idev, UINT32 bConfigurationValue);
118 
119  int (*select_interface)(IUDEVICE* idev, BYTE InterfaceNumber, BYTE AlternateSetting);
120 
121  int (*control_pipe_request)(IUDEVICE* idev, UINT32 RequestId, UINT32 EndpointAddress,
122  UINT32* UsbdStatus, int command);
123 
124  UINT32(*control_query_device_text)
125  (IUDEVICE* idev, UINT32 TextType, UINT16 LocaleId, UINT8* BufferSize, BYTE* Buffer);
126 
127  int (*os_feature_descriptor_request)(IUDEVICE* idev, UINT32 RequestId, BYTE Recipient,
128  BYTE InterfaceNumber, BYTE Ms_PageIndex,
129  UINT16 Ms_featureDescIndex, UINT32* UsbdStatus,
130  UINT32* BufferSize, BYTE* Buffer, UINT32 Timeout);
131 
132  void (*cancel_all_transfer_request)(IUDEVICE* idev);
133 
134  int (*cancel_transfer_request)(IUDEVICE* idev, UINT32 RequestId);
135 
136  int (*query_device_descriptor)(IUDEVICE* idev, int offset);
137 
138  BOOL (*detach_kernel_driver)(IUDEVICE* idev);
139 
140  BOOL (*attach_kernel_driver)(IUDEVICE* idev);
141 
142  int (*query_device_port_status)(IUDEVICE* idev, UINT32* UsbdStatus, UINT32* BufferSize,
143  BYTE* Buffer);
144 
145  MSUSB_CONFIG_DESCRIPTOR* (*complete_msconfig_setup)(IUDEVICE* idev,
146  MSUSB_CONFIG_DESCRIPTOR* MsConfig);
147  /* Basic state */
148  int (*isCompositeDevice)(IUDEVICE* idev);
149 
150  int (*isExist)(IUDEVICE* idev);
151  int (*isAlreadySend)(IUDEVICE* idev);
152  int (*isChannelClosed)(IUDEVICE* idev);
153 
154  void (*setAlreadySend)(IUDEVICE* idev);
155  void (*setChannelClosed)(IUDEVICE* idev);
156  void (*markChannelClosed)(IUDEVICE* idev);
157  char* (*getPath)(IUDEVICE* idev);
158 
159  void (*free)(IUDEVICE* idev);
160 
161  BASIC_DEV_STATE_DEFINED(channelManager, IWTSVirtualChannelManager*);
162  BASIC_DEV_STATE_DEFINED(channelID, UINT32);
163  BASIC_DEV_STATE_DEFINED(UsbDevice, UINT32);
164  BASIC_DEV_STATE_DEFINED(ReqCompletion, UINT32);
165  BASIC_DEV_STATE_DEFINED(bus_number, BYTE);
166  BASIC_DEV_STATE_DEFINED(dev_number, BYTE);
167  BASIC_DEV_STATE_DEFINED(port_number, UINT8);
168  BASIC_DEV_STATE_DEFINED(MsConfig, MSUSB_CONFIG_DESCRIPTOR*);
169 
170  BASIC_DEV_STATE_DEFINED(p_udev, void*);
171  BASIC_DEV_STATE_DEFINED(p_prev, void*);
172  BASIC_DEV_STATE_DEFINED(p_next, void*);
173 };
174 
176 {
177  /* Standard */
178  void (*free)(IUDEVMAN* idevman);
179 
180  /* Manage devices */
181  void (*rewind)(IUDEVMAN* idevman);
182  BOOL (*has_next)(IUDEVMAN* idevman);
183  BOOL (*unregister_udevice)(IUDEVMAN* idevman, BYTE bus_number, BYTE dev_number);
184  size_t (*register_udevice)(IUDEVMAN* idevman, BYTE bus_number, BYTE dev_number, UINT16 idVendor,
185  UINT16 idProduct, UINT32 flag);
186  IUDEVICE* (*get_next)(IUDEVMAN* idevman);
187  IUDEVICE* (*get_udevice_by_UsbDevice)(IUDEVMAN* idevman, UINT32 UsbDevice);
188  IUDEVICE* (*get_udevice_by_ChannelID)(IUDEVMAN* idevman, UINT32 channelID);
189 
190  /* Extension */
191  int (*isAutoAdd)(IUDEVMAN* idevman);
192 
193  /* Basic state */
194  BASIC_DEVMAN_STATE_DEFINED(device_num, UINT32);
195  BASIC_DEVMAN_STATE_DEFINED(next_device_id, UINT32);
196 
197  /* control semaphore or mutex lock */
198  void (*loading_lock)(IUDEVMAN* idevman);
199  void (*loading_unlock)(IUDEVMAN* idevman);
200  BOOL (*initialize)(IUDEVMAN* idevman, UINT32 channelId);
201  UINT (*listener_created_callback)(IUDEVMAN* idevman);
202 
203  IWTSPlugin* plugin;
204  UINT32 controlChannelId;
205  UINT32 status;
206 };
207 
208 #define DEVICE_ADD_FLAG_BUS 0x01
209 #define DEVICE_ADD_FLAG_DEV 0x02
210 #define DEVICE_ADD_FLAG_VENDOR 0x04
211 #define DEVICE_ADD_FLAG_PRODUCT 0x08
212 #define DEVICE_ADD_FLAG_REGISTER 0x10
213 
214 #define DEVICE_ADD_FLAG_ALL \
215  (DEVICE_ADD_FLAG_BUS | DEVICE_ADD_FLAG_DEV | DEVICE_ADD_FLAG_VENDOR | \
216  DEVICE_ADD_FLAG_PRODUCT | DEVICE_ADD_FLAG_REGISTER)
217 
218 FREERDP_API BOOL add_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum,
219  UINT16 idVendor, UINT16 idProduct);
220 FREERDP_API BOOL del_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum,
221  UINT16 idVendor, UINT16 idProduct);
222 
223 UINT stream_write_and_free(IWTSPlugin* plugin, IWTSVirtualChannel* channel, wStream* out);
224 
225 #endif /* FREERDP_CHANNEL_URBDRC_CLIENT_MAIN_H */
Definition: urbdrc_main.h:73