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++)
112 msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes);
113 MsInterface->MsPipes = NULL;
119 UINT32 NumInterfaces)
123 for (UINT32 inum = 0; inum < NumInterfaces; inum++)
125 msusb_msinterface_free(MsInterfaces[inum]);
135 if (!MsConfig || !MsConfig->MsInterfaces)
138 msusb_msinterface_free(MsConfig->MsInterfaces[InterfaceNumber]);
139 MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface;
147 if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 12))
150 MsInterface = msusb_msinterface_new();
155 Stream_Read_UINT16(s, MsInterface->Length);
156 Stream_Read_UINT16(s, MsInterface->NumberOfPipesExpected);
157 Stream_Read_UINT8(s, MsInterface->InterfaceNumber);
158 Stream_Read_UINT8(s, MsInterface->AlternateSetting);
160 Stream_Read_UINT32(s, MsInterface->NumberOfPipes);
161 MsInterface->InterfaceHandle = 0;
162 MsInterface->bInterfaceClass = 0;
163 MsInterface->bInterfaceSubClass = 0;
164 MsInterface->bInterfaceProtocol = 0;
165 MsInterface->InitCompleted = 0;
166 MsInterface->MsPipes = NULL;
168 if (MsInterface->NumberOfPipes > 0)
170 MsInterface->MsPipes = msusb_mspipes_read(s, MsInterface->NumberOfPipes);
172 if (!MsInterface->MsPipes)
178 msusb_msinterface_free(MsInterface);
190 if (!Stream_EnsureRemainingCapacity(out, 16 + MsInterface->NumberOfPipes * 20))
194 Stream_Write_UINT16(out, MsInterface->Length);
196 Stream_Write_UINT8(out, MsInterface->InterfaceNumber);
198 Stream_Write_UINT8(out, MsInterface->AlternateSetting);
200 Stream_Write_UINT8(out, MsInterface->bInterfaceClass);
202 Stream_Write_UINT8(out, MsInterface->bInterfaceSubClass);
204 Stream_Write_UINT8(out, MsInterface->bInterfaceProtocol);
206 Stream_Write_UINT8(out, 0);
208 Stream_Write_UINT32(out, MsInterface->InterfaceHandle);
210 Stream_Write_UINT32(out, MsInterface->NumberOfPipes);
212 MsPipes = MsInterface->MsPipes;
214 for (UINT32 pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
216 MsPipe = MsPipes[pnum];
218 Stream_Write_UINT16(out, MsPipe->MaximumPacketSize);
220 Stream_Write_UINT8(out, MsPipe->bEndpointAddress);
222 Stream_Write_UINT8(out, MsPipe->bInterval);
224 Stream_Write_UINT32(out, MsPipe->PipeType);
226 Stream_Write_UINT32(out, MsPipe->PipeHandle);
228 Stream_Write_UINT32(out, MsPipe->MaximumTransferSize);
230 Stream_Write_UINT32(out, MsPipe->PipeFlags);
245 for (UINT32 inum = 0; inum < NumInterfaces; inum++)
247 MsInterfaces[inum] = msusb_msinterface_read(s);
249 if (!MsInterfaces[inum])
256 for (UINT32 inum = 0; inum < NumInterfaces; inum++)
257 msusb_msinterface_free(MsInterfaces[inum]);
271 if (!Stream_EnsureRemainingCapacity(out, 8))
275 Stream_Write_UINT32(out, MsConfg->ConfigurationHandle);
277 Stream_Write_UINT32(out, MsConfg->NumInterfaces);
279 MsInterfaces = MsConfg->MsInterfaces;
281 for (UINT32 inum = 0; inum < MsConfg->NumInterfaces; inum++)
283 MsInterface = MsInterfaces[inum];
285 if (!msusb_msinterface_write(MsInterface, out))
301 msusb_msinterface_free_list(MsConfig->MsInterfaces, MsConfig->NumInterfaces);
302 MsConfig->MsInterfaces = NULL;
310 BYTE lenConfiguration = 0;
311 BYTE typeConfiguration = 0;
313 if (!Stream_CheckAndLogRequiredCapacityOfSize(TAG, (s), 3ULL + NumInterfaces, 2ULL))
316 MsConfig = msusb_msconfig_new();
321 MsConfig->MsInterfaces = msusb_msinterface_read_list(s, NumInterfaces);
323 if (!MsConfig->MsInterfaces)
326 Stream_Read_UINT8(s, lenConfiguration);
327 Stream_Read_UINT8(s, typeConfiguration);
329 if (lenConfiguration != 0x9 || typeConfiguration != 0x2)
331 WLog_ERR(TAG,
"len and type must be 0x9 and 0x2 , but it is 0x%" PRIx8
" and 0x%" PRIx8
"",
332 lenConfiguration, typeConfiguration);
336 Stream_Read_UINT16(s, MsConfig->wTotalLength);
338 Stream_Read_UINT8(s, MsConfig->bConfigurationValue);
339 MsConfig->NumInterfaces = NumInterfaces;
342 msusb_msconfig_free(MsConfig);
353 WLog_INFO(TAG,
"=================MsConfig:========================");
354 WLog_INFO(TAG,
"wTotalLength:%" PRIu16
"", MsConfig->wTotalLength);
355 WLog_INFO(TAG,
"bConfigurationValue:%" PRIu8
"", MsConfig->bConfigurationValue);
356 WLog_INFO(TAG,
"ConfigurationHandle:0x%08" PRIx32
"", MsConfig->ConfigurationHandle);
357 WLog_INFO(TAG,
"InitCompleted:%d", MsConfig->InitCompleted);
358 WLog_INFO(TAG,
"MsOutSize:%d", MsConfig->MsOutSize);
359 WLog_INFO(TAG,
"NumInterfaces:%" PRIu32
"", MsConfig->NumInterfaces);
360 MsInterfaces = MsConfig->MsInterfaces;
362 for (UINT32 inum = 0; inum < MsConfig->NumInterfaces; inum++)
364 MsInterface = MsInterfaces[inum];
365 WLog_INFO(TAG,
" Interface: %" PRIu8
"", MsInterface->InterfaceNumber);
366 WLog_INFO(TAG,
" Length: %" PRIu16
"", MsInterface->Length);
367 WLog_INFO(TAG,
" NumberOfPipesExpected: %" PRIu16
"",
368 MsInterface->NumberOfPipesExpected);
369 WLog_INFO(TAG,
" AlternateSetting: %" PRIu8
"", MsInterface->AlternateSetting);
370 WLog_INFO(TAG,
" NumberOfPipes: %" PRIu32
"", MsInterface->NumberOfPipes);
371 WLog_INFO(TAG,
" InterfaceHandle: 0x%08" PRIx32
"", MsInterface->InterfaceHandle);
372 WLog_INFO(TAG,
" bInterfaceClass: 0x%02" PRIx8
"", MsInterface->bInterfaceClass);
373 WLog_INFO(TAG,
" bInterfaceSubClass: 0x%02" PRIx8
"", MsInterface->bInterfaceSubClass);
374 WLog_INFO(TAG,
" bInterfaceProtocol: 0x%02" PRIx8
"", MsInterface->bInterfaceProtocol);
375 WLog_INFO(TAG,
" InitCompleted: %d", MsInterface->InitCompleted);
376 MsPipes = MsInterface->MsPipes;
378 for (UINT32 pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
380 MsPipe = MsPipes[pnum];
381 WLog_INFO(TAG,
" Pipe: %" PRIu32, pnum);
382 WLog_INFO(TAG,
" MaximumPacketSize: 0x%04" PRIx16
"", MsPipe->MaximumPacketSize);
383 WLog_INFO(TAG,
" MaximumTransferSize: 0x%08" PRIx32
"",
384 MsPipe->MaximumTransferSize);
385 WLog_INFO(TAG,
" PipeFlags: 0x%08" PRIx32
"", MsPipe->PipeFlags);
386 WLog_INFO(TAG,
" PipeHandle: 0x%08" PRIx32
"", MsPipe->PipeHandle);
387 WLog_INFO(TAG,
" bEndpointAddress: 0x%02" PRIx8
"", MsPipe->bEndpointAddress);
388 WLog_INFO(TAG,
" bInterval: %" PRIu8
"", MsPipe->bInterval);
389 WLog_INFO(TAG,
" PipeType: 0x%02" PRIx8
"", MsPipe->PipeType);
390 WLog_INFO(TAG,
" InitCompleted: %d", MsPipe->InitCompleted);
394 WLog_INFO(TAG,
"==================================================");