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