25#include <freerdp/log.h>
28#define TAG FREERDP_TAG("utils")
39 for (UINT32 pnum = 0; pnum < NumberOfPipes && MsPipes[pnum]; pnum++)
49 if (!MsInterface || !NewMsPipes)
53 msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes);
55 MsInterface->MsPipes = NewMsPipes;
56 MsInterface->NumberOfPipes = NewNumberOfPipes;
64 if (!Stream_CheckAndLogRequiredCapacityOfSize(TAG, (s), NumberOfPipes, 12ull))
72 for (UINT32 pnum = 0; pnum < NumberOfPipes; pnum++)
79 Stream_Read_UINT16(s, MsPipe->MaximumPacketSize);
81 Stream_Read_UINT32(s, MsPipe->MaximumTransferSize);
82 Stream_Read_UINT32(s, MsPipe->PipeFlags);
90 MsPipes[pnum] = MsPipe;
96 for (UINT32 pnum = 0; pnum < NumberOfPipes; pnum++)
103WINPR_ATTR_MALLOC(msusb_msinterface_free, 1)
113 msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes);
114 MsInterface->MsPipes = NULL;
120 UINT32 NumInterfaces)
124 for (UINT32 inum = 0; inum < NumInterfaces; inum++)
126 msusb_msinterface_free(MsInterfaces[inum]);
129 free((
void*)MsInterfaces);
136 if (!MsConfig || !MsConfig->MsInterfaces)
138 if (MsConfig->NumInterfaces <= InterfaceNumber)
141 msusb_msinterface_free(MsConfig->MsInterfaces[InterfaceNumber]);
142 MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface;
148 if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 12))
156 Stream_Read_UINT16(s, MsInterface->Length);
157 Stream_Read_UINT16(s, MsInterface->NumberOfPipesExpected);
158 Stream_Read_UINT8(s, MsInterface->InterfaceNumber);
159 Stream_Read_UINT8(s, MsInterface->AlternateSetting);
161 Stream_Read_UINT32(s, MsInterface->NumberOfPipes);
162 MsInterface->InterfaceHandle = 0;
163 MsInterface->bInterfaceClass = 0;
164 MsInterface->bInterfaceSubClass = 0;
165 MsInterface->bInterfaceProtocol = 0;
166 MsInterface->InitCompleted = 0;
167 MsInterface->MsPipes = NULL;
169 if (MsInterface->NumberOfPipes > 0)
171 MsInterface->MsPipes = msusb_mspipes_read(s, MsInterface->NumberOfPipes);
173 if (!MsInterface->MsPipes)
179 msusb_msinterface_free(MsInterface);
191 if (!Stream_EnsureRemainingCapacity(out, 16 + MsInterface->NumberOfPipes * 20))
195 Stream_Write_UINT16(out, MsInterface->Length);
197 Stream_Write_UINT8(out, MsInterface->InterfaceNumber);
199 Stream_Write_UINT8(out, MsInterface->AlternateSetting);
201 Stream_Write_UINT8(out, MsInterface->bInterfaceClass);
203 Stream_Write_UINT8(out, MsInterface->bInterfaceSubClass);
205 Stream_Write_UINT8(out, MsInterface->bInterfaceProtocol);
207 Stream_Write_UINT8(out, 0);
209 Stream_Write_UINT32(out, MsInterface->InterfaceHandle);
211 Stream_Write_UINT32(out, MsInterface->NumberOfPipes);
213 MsPipes = MsInterface->MsPipes;
215 for (UINT32 pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
217 MsPipe = MsPipes[pnum];
219 Stream_Write_UINT16(out, MsPipe->MaximumPacketSize);
221 Stream_Write_UINT8(out, MsPipe->bEndpointAddress);
223 Stream_Write_UINT8(out, MsPipe->bInterval);
225 Stream_Write_UINT32(out, MsPipe->PipeType);
227 Stream_Write_UINT32(out, MsPipe->PipeHandle);
229 Stream_Write_UINT32(out, MsPipe->MaximumTransferSize);
231 Stream_Write_UINT32(out, MsPipe->PipeFlags);
246 for (UINT32 inum = 0; inum < NumInterfaces; inum++)
248 MsInterfaces[inum] = msusb_msinterface_read(s);
250 if (!MsInterfaces[inum])
257 for (UINT32 inum = 0; inum < NumInterfaces; inum++)
258 msusb_msinterface_free(MsInterfaces[inum]);
260 free((
void*)MsInterfaces);
269 if (!Stream_EnsureRemainingCapacity(out, 8))
273 Stream_Write_UINT32(out, MsConfg->ConfigurationHandle);
275 Stream_Write_UINT32(out, MsConfg->NumInterfaces);
279 for (UINT32 inum = 0; inum < MsConfg->NumInterfaces; inum++)
283 if (!msusb_msinterface_write(MsInterface, out))
299 msusb_msinterface_free_list(MsConfig->MsInterfaces, MsConfig->NumInterfaces);
300 MsConfig->MsInterfaces = NULL;
308 BYTE lenConfiguration = 0;
309 BYTE typeConfiguration = 0;
311 if (!Stream_CheckAndLogRequiredCapacityOfSize(TAG, (s), 3ULL + NumInterfaces, 2ULL))
314 MsConfig = msusb_msconfig_new();
319 MsConfig->MsInterfaces = msusb_msinterface_read_list(s, NumInterfaces);
321 if (!MsConfig->MsInterfaces)
324 Stream_Read_UINT8(s, lenConfiguration);
325 Stream_Read_UINT8(s, typeConfiguration);
327 if (lenConfiguration != 0x9 || typeConfiguration != 0x2)
329 WLog_ERR(TAG,
"len and type must be 0x9 and 0x2 , but it is 0x%" PRIx8
" and 0x%" PRIx8
"",
330 lenConfiguration, typeConfiguration);
334 Stream_Read_UINT16(s, MsConfig->wTotalLength);
336 Stream_Read_UINT8(s, MsConfig->bConfigurationValue);
337 MsConfig->NumInterfaces = NumInterfaces;
340 msusb_msconfig_free(MsConfig);
351 WLog_INFO(TAG,
"=================MsConfig:========================");
352 WLog_INFO(TAG,
"wTotalLength:%" PRIu16
"", MsConfig->wTotalLength);
353 WLog_INFO(TAG,
"bConfigurationValue:%" PRIu8
"", MsConfig->bConfigurationValue);
354 WLog_INFO(TAG,
"ConfigurationHandle:0x%08" PRIx32
"", MsConfig->ConfigurationHandle);
355 WLog_INFO(TAG,
"InitCompleted:%d", MsConfig->InitCompleted);
356 WLog_INFO(TAG,
"MsOutSize:%d", MsConfig->MsOutSize);
357 WLog_INFO(TAG,
"NumInterfaces:%" PRIu32
"", MsConfig->NumInterfaces);
358 MsInterfaces = MsConfig->MsInterfaces;
360 for (UINT32 inum = 0; inum < MsConfig->NumInterfaces; inum++)
362 MsInterface = MsInterfaces[inum];
363 WLog_INFO(TAG,
" Interface: %" PRIu8
"", MsInterface->InterfaceNumber);
364 WLog_INFO(TAG,
" Length: %" PRIu16
"", MsInterface->Length);
365 WLog_INFO(TAG,
" NumberOfPipesExpected: %" PRIu16
"",
366 MsInterface->NumberOfPipesExpected);
367 WLog_INFO(TAG,
" AlternateSetting: %" PRIu8
"", MsInterface->AlternateSetting);
368 WLog_INFO(TAG,
" NumberOfPipes: %" PRIu32
"", MsInterface->NumberOfPipes);
369 WLog_INFO(TAG,
" InterfaceHandle: 0x%08" PRIx32
"", MsInterface->InterfaceHandle);
370 WLog_INFO(TAG,
" bInterfaceClass: 0x%02" PRIx8
"", MsInterface->bInterfaceClass);
371 WLog_INFO(TAG,
" bInterfaceSubClass: 0x%02" PRIx8
"", MsInterface->bInterfaceSubClass);
372 WLog_INFO(TAG,
" bInterfaceProtocol: 0x%02" PRIx8
"", MsInterface->bInterfaceProtocol);
373 WLog_INFO(TAG,
" InitCompleted: %d", MsInterface->InitCompleted);
374 MsPipes = MsInterface->MsPipes;
376 for (UINT32 pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
378 MsPipe = MsPipes[pnum];
379 WLog_INFO(TAG,
" Pipe: %" PRIu32, pnum);
380 WLog_INFO(TAG,
" MaximumPacketSize: 0x%04" PRIx16
"", MsPipe->MaximumPacketSize);
381 WLog_INFO(TAG,
" MaximumTransferSize: 0x%08" PRIx32
"",
382 MsPipe->MaximumTransferSize);
383 WLog_INFO(TAG,
" PipeFlags: 0x%08" PRIx32
"", MsPipe->PipeFlags);
384 WLog_INFO(TAG,
" PipeHandle: 0x%08" PRIx32
"", MsPipe->PipeHandle);
385 WLog_INFO(TAG,
" bEndpointAddress: 0x%02" PRIx8
"", MsPipe->bEndpointAddress);
386 WLog_INFO(TAG,
" bInterval: %" PRIu8
"", MsPipe->bInterval);
387 WLog_INFO(TAG,
" PipeType: 0x%02" PRIx8
"", MsPipe->PipeType);
388 WLog_INFO(TAG,
" InitCompleted: %d", MsPipe->InitCompleted);
392 WLog_INFO(TAG,
"==================================================");