FreeRDP
urbdrc_helpers.c
1 
20 #include <freerdp/config.h>
21 
22 #include "urbdrc_helpers.h"
23 #include "urbdrc_types.h"
24 #include <winpr/print.h>
25 
26 const char* mask_to_string(UINT32 mask)
27 {
28  switch (mask)
29  {
30  case STREAM_ID_NONE:
31  return "STREAM_ID_NONE";
32 
33  case STREAM_ID_PROXY:
34  return "STREAM_ID_PROXY";
35 
36  case STREAM_ID_STUB:
37  return "STREAM_ID_STUB";
38 
39  default:
40  return "UNKNOWN";
41  }
42 }
43 const char* interface_to_string(UINT32 id)
44 {
45  switch (id)
46  {
47  case CAPABILITIES_NEGOTIATOR:
48  return "CAPABILITIES_NEGOTIATOR";
49 
50  case SERVER_CHANNEL_NOTIFICATION:
51  return "SERVER_CHANNEL_NOTIFICATION";
52 
53  case CLIENT_CHANNEL_NOTIFICATION:
54  return "CLIENT_CHANNEL_NOTIFICATION";
55 
56  default:
57  return "DEVICE_MESSAGE";
58  }
59 }
60 
61 static const char* call_to_string_none(BOOL client, UINT32 interfaceId, UINT32 functionId)
62 {
63  WINPR_UNUSED(interfaceId);
64 
65  if (client)
66  return "RIM_EXCHANGE_CAPABILITY_RESPONSE [none |client]";
67  else
68  {
69  switch (functionId)
70  {
71  case RIM_EXCHANGE_CAPABILITY_REQUEST:
72  return "RIM_EXCHANGE_CAPABILITY_REQUEST [none |server]";
73 
74  case RIMCALL_RELEASE:
75  return "RIMCALL_RELEASE [none |server]";
76 
77  case RIMCALL_QUERYINTERFACE:
78  return "RIMCALL_QUERYINTERFACE [none |server]";
79 
80  default:
81  return "UNKNOWN [none |server]";
82  }
83  }
84 }
85 
86 static const char* call_to_string_proxy_server(UINT32 functionId)
87 {
88  switch (functionId)
89  {
90  case QUERY_DEVICE_TEXT:
91  return "QUERY_DEVICE_TEXT [proxy|server]";
92 
93  case INTERNAL_IO_CONTROL:
94  return "INTERNAL_IO_CONTROL [proxy|server]";
95 
96  case IO_CONTROL:
97  return "IO_CONTROL [proxy|server]";
98 
99  case REGISTER_REQUEST_CALLBACK:
100  return "REGISTER_REQUEST_CALLBACK [proxy|server]";
101 
102  case CANCEL_REQUEST:
103  return "CANCEL_REQUEST [proxy|server]";
104 
105  case RETRACT_DEVICE:
106  return "RETRACT_DEVICE [proxy|server]";
107 
108  case TRANSFER_IN_REQUEST:
109  return "TRANSFER_IN_REQUEST [proxy|server]";
110 
111  case TRANSFER_OUT_REQUEST:
112  return "TRANSFER_OUT_REQUEST [proxy|server]";
113 
114  default:
115  return "UNKNOWN [proxy|server]";
116  }
117 }
118 
119 static const char* call_to_string_proxy_client(UINT32 functionId)
120 {
121  switch (functionId)
122  {
123  case URB_COMPLETION_NO_DATA:
124  return "URB_COMPLETION_NO_DATA [proxy|client]";
125 
126  case URB_COMPLETION:
127  return "URB_COMPLETION [proxy|client]";
128 
129  case IOCONTROL_COMPLETION:
130  return "IOCONTROL_COMPLETION [proxy|client]";
131 
132  case TRANSFER_OUT_REQUEST:
133  return "TRANSFER_OUT_REQUEST [proxy|client]";
134 
135  default:
136  return "UNKNOWN [proxy|client]";
137  }
138 }
139 
140 static const char* call_to_string_proxy(BOOL client, UINT32 interfaceId, UINT32 functionId)
141 {
142  switch (interfaceId & INTERFACE_ID_MASK)
143  {
144  case CLIENT_DEVICE_SINK:
145  switch (functionId)
146  {
147  case ADD_VIRTUAL_CHANNEL:
148  return "ADD_VIRTUAL_CHANNEL [proxy|sink ]";
149 
150  case ADD_DEVICE:
151  return "ADD_DEVICE [proxy|sink ]";
152  case RIMCALL_RELEASE:
153  return "RIMCALL_RELEASE [proxy|sink ]";
154 
155  case RIMCALL_QUERYINTERFACE:
156  return "RIMCALL_QUERYINTERFACE [proxy|sink ]";
157  default:
158  return "UNKNOWN [proxy|sink ]";
159  }
160 
161  case SERVER_CHANNEL_NOTIFICATION:
162  switch (functionId)
163  {
164  case CHANNEL_CREATED:
165  return "CHANNEL_CREATED [proxy|server]";
166 
167  case RIMCALL_RELEASE:
168  return "RIMCALL_RELEASE [proxy|server]";
169 
170  case RIMCALL_QUERYINTERFACE:
171  return "RIMCALL_QUERYINTERFACE [proxy|server]";
172 
173  default:
174  return "UNKNOWN [proxy|server]";
175  }
176 
177  case CLIENT_CHANNEL_NOTIFICATION:
178  switch (functionId)
179  {
180  case CHANNEL_CREATED:
181  return "CHANNEL_CREATED [proxy|client]";
182  case RIMCALL_RELEASE:
183  return "RIMCALL_RELEASE [proxy|client]";
184  case RIMCALL_QUERYINTERFACE:
185  return "RIMCALL_QUERYINTERFACE [proxy|client]";
186  default:
187  return "UNKNOWN [proxy|client]";
188  }
189 
190  default:
191  if (client)
192  return call_to_string_proxy_client(functionId);
193  else
194  return call_to_string_proxy_server(functionId);
195  }
196 }
197 
198 static const char* call_to_string_stub(BOOL client, UINT32 interfaceNr, UINT32 functionId)
199 {
200  return "QUERY_DEVICE_TEXT_RSP [stub |client]";
201 }
202 
203 const char* call_to_string(BOOL client, UINT32 interfaceNr, UINT32 functionId)
204 {
205  const UINT32 mask = (interfaceNr & STREAM_ID_MASK) >> 30;
206  const UINT32 interfaceId = interfaceNr & INTERFACE_ID_MASK;
207 
208  switch (mask)
209  {
210  case STREAM_ID_NONE:
211  return call_to_string_none(client, interfaceId, functionId);
212 
213  case STREAM_ID_PROXY:
214  return call_to_string_proxy(client, interfaceId, functionId);
215 
216  case STREAM_ID_STUB:
217  return call_to_string_stub(client, interfaceId, functionId);
218 
219  default:
220  return "UNKNOWN[mask]";
221  }
222 }
223 
224 const char* urb_function_string(UINT16 urb)
225 {
226  switch (urb)
227  {
228  case TS_URB_SELECT_CONFIGURATION:
229  return "TS_URB_SELECT_CONFIGURATION";
230 
231  case TS_URB_SELECT_INTERFACE:
232  return "TS_URB_SELECT_INTERFACE";
233 
234  case TS_URB_PIPE_REQUEST:
235  return "TS_URB_PIPE_REQUEST";
236 
237  case TS_URB_TAKE_FRAME_LENGTH_CONTROL:
238  return "TS_URB_TAKE_FRAME_LENGTH_CONTROL";
239 
240  case TS_URB_RELEASE_FRAME_LENGTH_CONTROL:
241  return "TS_URB_RELEASE_FRAME_LENGTH_CONTROL";
242 
243  case TS_URB_GET_FRAME_LENGTH:
244  return "TS_URB_GET_FRAME_LENGTH";
245 
246  case TS_URB_SET_FRAME_LENGTH:
247  return "TS_URB_SET_FRAME_LENGTH";
248 
249  case TS_URB_GET_CURRENT_FRAME_NUMBER:
250  return "TS_URB_GET_CURRENT_FRAME_NUMBER";
251 
252  case TS_URB_CONTROL_TRANSFER:
253  return "TS_URB_CONTROL_TRANSFER";
254 
255  case TS_URB_BULK_OR_INTERRUPT_TRANSFER:
256  return "TS_URB_BULK_OR_INTERRUPT_TRANSFER";
257 
258  case TS_URB_ISOCH_TRANSFER:
259  return "TS_URB_ISOCH_TRANSFER";
260 
261  case TS_URB_GET_DESCRIPTOR_FROM_DEVICE:
262  return "TS_URB_GET_DESCRIPTOR_FROM_DEVICE";
263 
264  case TS_URB_SET_DESCRIPTOR_TO_DEVICE:
265  return "TS_URB_SET_DESCRIPTOR_TO_DEVICE";
266 
267  case TS_URB_SET_FEATURE_TO_DEVICE:
268  return "TS_URB_SET_FEATURE_TO_DEVICE";
269 
270  case TS_URB_SET_FEATURE_TO_INTERFACE:
271  return "TS_URB_SET_FEATURE_TO_INTERFACE";
272 
273  case TS_URB_SET_FEATURE_TO_ENDPOINT:
274  return "TS_URB_SET_FEATURE_TO_ENDPOINT";
275 
276  case TS_URB_CLEAR_FEATURE_TO_DEVICE:
277  return "TS_URB_CLEAR_FEATURE_TO_DEVICE";
278 
279  case TS_URB_CLEAR_FEATURE_TO_INTERFACE:
280  return "TS_URB_CLEAR_FEATURE_TO_INTERFACE";
281 
282  case TS_URB_CLEAR_FEATURE_TO_ENDPOINT:
283  return "TS_URB_CLEAR_FEATURE_TO_ENDPOINT";
284 
285  case TS_URB_GET_STATUS_FROM_DEVICE:
286  return "TS_URB_GET_STATUS_FROM_DEVICE";
287 
288  case TS_URB_GET_STATUS_FROM_INTERFACE:
289  return "TS_URB_GET_STATUS_FROM_INTERFACE";
290 
291  case TS_URB_GET_STATUS_FROM_ENDPOINT:
292  return "TS_URB_GET_STATUS_FROM_ENDPOINT";
293 
294  case TS_URB_RESERVED_0X0016:
295  return "TS_URB_RESERVED_0X0016";
296 
297  case TS_URB_VENDOR_DEVICE:
298  return "TS_URB_VENDOR_DEVICE";
299 
300  case TS_URB_VENDOR_INTERFACE:
301  return "TS_URB_VENDOR_INTERFACE";
302 
303  case TS_URB_VENDOR_ENDPOINT:
304  return "TS_URB_VENDOR_ENDPOINT";
305 
306  case TS_URB_CLASS_DEVICE:
307  return "TS_URB_CLASS_DEVICE";
308 
309  case TS_URB_CLASS_INTERFACE:
310  return "TS_URB_CLASS_INTERFACE";
311 
312  case TS_URB_CLASS_ENDPOINT:
313  return "TS_URB_CLASS_ENDPOINT";
314 
315  case TS_URB_RESERVE_0X001D:
316  return "TS_URB_RESERVE_0X001D";
317 
318  case TS_URB_SYNC_RESET_PIPE_AND_CLEAR_STALL:
319  return "TS_URB_SYNC_RESET_PIPE_AND_CLEAR_STALL";
320 
321  case TS_URB_CLASS_OTHER:
322  return "TS_URB_CLASS_OTHER";
323 
324  case TS_URB_VENDOR_OTHER:
325  return "TS_URB_VENDOR_OTHER";
326 
327  case TS_URB_GET_STATUS_FROM_OTHER:
328  return "TS_URB_GET_STATUS_FROM_OTHER";
329 
330  case TS_URB_CLEAR_FEATURE_TO_OTHER:
331  return "TS_URB_CLEAR_FEATURE_TO_OTHER";
332 
333  case TS_URB_SET_FEATURE_TO_OTHER:
334  return "TS_URB_SET_FEATURE_TO_OTHER";
335 
336  case TS_URB_GET_DESCRIPTOR_FROM_ENDPOINT:
337  return "TS_URB_GET_DESCRIPTOR_FROM_ENDPOINT";
338 
339  case TS_URB_SET_DESCRIPTOR_TO_ENDPOINT:
340  return "TS_URB_SET_DESCRIPTOR_TO_ENDPOINT";
341 
342  case TS_URB_CONTROL_GET_CONFIGURATION_REQUEST:
343  return "TS_URB_CONTROL_GET_CONFIGURATION_REQUEST";
344 
345  case TS_URB_CONTROL_GET_INTERFACE_REQUEST:
346  return "TS_URB_CONTROL_GET_INTERFACE_REQUEST";
347 
348  case TS_URB_GET_DESCRIPTOR_FROM_INTERFACE:
349  return "TS_URB_GET_DESCRIPTOR_FROM_INTERFACE";
350 
351  case TS_URB_SET_DESCRIPTOR_TO_INTERFACE:
352  return "TS_URB_SET_DESCRIPTOR_TO_INTERFACE";
353 
354  case TS_URB_GET_OS_FEATURE_DESCRIPTOR_REQUEST:
355  return "TS_URB_GET_OS_FEATURE_DESCRIPTOR_REQUEST";
356 
357  case TS_URB_RESERVE_0X002B:
358  return "TS_URB_RESERVE_0X002B";
359 
360  case TS_URB_RESERVE_0X002C:
361  return "TS_URB_RESERVE_0X002C";
362 
363  case TS_URB_RESERVE_0X002D:
364  return "TS_URB_RESERVE_0X002D";
365 
366  case TS_URB_RESERVE_0X002E:
367  return "TS_URB_RESERVE_0X002E";
368 
369  case TS_URB_RESERVE_0X002F:
370  return "TS_URB_RESERVE_0X002F";
371 
372  case TS_URB_SYNC_RESET_PIPE:
373  return "TS_URB_SYNC_RESET_PIPE";
374 
375  case TS_URB_SYNC_CLEAR_STALL:
376  return "TS_URB_SYNC_CLEAR_STALL";
377 
378  case TS_URB_CONTROL_TRANSFER_EX:
379  return "TS_URB_CONTROL_TRANSFER_EX";
380 
381  default:
382  return "UNKNOWN";
383  }
384 }
385 
386 void urbdrc_dump_message(wLog* log, BOOL client, BOOL write, wStream* s)
387 {
388  const char* type = write ? "WRITE" : "READ";
389  UINT32 InterfaceId = 0;
390  UINT32 MessageId = 0;
391  UINT32 FunctionId = 0;
392  size_t length = 0;
393  size_t pos = 0;
394 
395  pos = Stream_GetPosition(s);
396  if (write)
397  {
398  length = pos;
399  Stream_SetPosition(s, 0);
400  }
401  else
402  length = Stream_GetRemainingLength(s);
403 
404  if (length < 12)
405  return;
406 
407  Stream_Read_UINT32(s, InterfaceId);
408  Stream_Read_UINT32(s, MessageId);
409  Stream_Read_UINT32(s, FunctionId);
410  Stream_SetPosition(s, pos);
411 
412  WLog_Print(log, WLOG_DEBUG,
413  "[%-5s] %s [%08" PRIx32 "] InterfaceId=%08" PRIx32 ", MessageId=%08" PRIx32
414  ", FunctionId=%08" PRIx32 ", length=%" PRIuz,
415  type, call_to_string(client, InterfaceId, FunctionId), FunctionId, InterfaceId,
416  MessageId, FunctionId, length);
417 #if defined(WITH_DEBUG_URBDRC)
418  if (write)
419  WLog_Print(log, WLOG_TRACE, "-------------------------- URBDRC sent: ---");
420  else
421  WLog_Print(log, WLOG_TRACE, "-------------------------- URBDRC received:");
422  winpr_HexLogDump(log, WLOG_TRACE, Stream_Buffer(s), length);
423  WLog_Print(log, WLOG_TRACE, "-------------------------- URBDRC end -----");
424 #endif
425 }