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]);
 
  128    free((
void*)MsInterfaces);
 
  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]);
 
  259  free((
void*)MsInterfaces);
 
  268  if (!Stream_EnsureRemainingCapacity(out, 8))
 
  272  Stream_Write_UINT32(out, MsConfg->ConfigurationHandle);
 
  274  Stream_Write_UINT32(out, MsConfg->NumInterfaces);
 
  278  for (UINT32 inum = 0; inum < MsConfg->NumInterfaces; inum++)
 
  282    if (!msusb_msinterface_write(MsInterface, out))
 
  298    msusb_msinterface_free_list(MsConfig->MsInterfaces, MsConfig->NumInterfaces);
 
  299    MsConfig->MsInterfaces = NULL;
 
  307  BYTE lenConfiguration = 0;
 
  308  BYTE typeConfiguration = 0;
 
  310  if (!Stream_CheckAndLogRequiredCapacityOfSize(TAG, (s), 3ULL + NumInterfaces, 2ULL))
 
  313  MsConfig = msusb_msconfig_new();
 
  318  MsConfig->MsInterfaces = msusb_msinterface_read_list(s, NumInterfaces);
 
  320  if (!MsConfig->MsInterfaces)
 
  323  Stream_Read_UINT8(s, lenConfiguration);
 
  324  Stream_Read_UINT8(s, typeConfiguration);
 
  326  if (lenConfiguration != 0x9 || typeConfiguration != 0x2)
 
  328    WLog_ERR(TAG, 
"len and type must be 0x9 and 0x2 , but it is 0x%" PRIx8 
" and 0x%" PRIx8 
"",
 
  329             lenConfiguration, typeConfiguration);
 
  333  Stream_Read_UINT16(s, MsConfig->wTotalLength);
 
  335  Stream_Read_UINT8(s, MsConfig->bConfigurationValue);
 
  336  MsConfig->NumInterfaces = NumInterfaces;
 
  339  msusb_msconfig_free(MsConfig);
 
  350  WLog_INFO(TAG, 
"=================MsConfig:========================");
 
  351  WLog_INFO(TAG, 
"wTotalLength:%" PRIu16 
"", MsConfig->wTotalLength);
 
  352  WLog_INFO(TAG, 
"bConfigurationValue:%" PRIu8 
"", MsConfig->bConfigurationValue);
 
  353  WLog_INFO(TAG, 
"ConfigurationHandle:0x%08" PRIx32 
"", MsConfig->ConfigurationHandle);
 
  354  WLog_INFO(TAG, 
"InitCompleted:%d", MsConfig->InitCompleted);
 
  355  WLog_INFO(TAG, 
"MsOutSize:%d", MsConfig->MsOutSize);
 
  356  WLog_INFO(TAG, 
"NumInterfaces:%" PRIu32 
"", MsConfig->NumInterfaces);
 
  357  MsInterfaces = MsConfig->MsInterfaces;
 
  359  for (UINT32 inum = 0; inum < MsConfig->NumInterfaces; inum++)
 
  361    MsInterface = MsInterfaces[inum];
 
  362    WLog_INFO(TAG, 
"  Interface: %" PRIu8 
"", MsInterface->InterfaceNumber);
 
  363    WLog_INFO(TAG, 
"  Length: %" PRIu16 
"", MsInterface->Length);
 
  364    WLog_INFO(TAG, 
"  NumberOfPipesExpected: %" PRIu16 
"",
 
  365              MsInterface->NumberOfPipesExpected);
 
  366    WLog_INFO(TAG, 
"  AlternateSetting: %" PRIu8 
"", MsInterface->AlternateSetting);
 
  367    WLog_INFO(TAG, 
"  NumberOfPipes: %" PRIu32 
"", MsInterface->NumberOfPipes);
 
  368    WLog_INFO(TAG, 
"  InterfaceHandle: 0x%08" PRIx32 
"", MsInterface->InterfaceHandle);
 
  369    WLog_INFO(TAG, 
"  bInterfaceClass: 0x%02" PRIx8 
"", MsInterface->bInterfaceClass);
 
  370    WLog_INFO(TAG, 
"  bInterfaceSubClass: 0x%02" PRIx8 
"", MsInterface->bInterfaceSubClass);
 
  371    WLog_INFO(TAG, 
"  bInterfaceProtocol: 0x%02" PRIx8 
"", MsInterface->bInterfaceProtocol);
 
  372    WLog_INFO(TAG, 
"  InitCompleted: %d", MsInterface->InitCompleted);
 
  373    MsPipes = MsInterface->MsPipes;
 
  375    for (UINT32 pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
 
  377      MsPipe = MsPipes[pnum];
 
  378      WLog_INFO(TAG, 
"    Pipe: %" PRIu32, pnum);
 
  379      WLog_INFO(TAG, 
"    MaximumPacketSize: 0x%04" PRIx16 
"", MsPipe->MaximumPacketSize);
 
  380      WLog_INFO(TAG, 
"    MaximumTransferSize: 0x%08" PRIx32 
"",
 
  381                MsPipe->MaximumTransferSize);
 
  382      WLog_INFO(TAG, 
"    PipeFlags: 0x%08" PRIx32 
"", MsPipe->PipeFlags);
 
  383      WLog_INFO(TAG, 
"    PipeHandle: 0x%08" PRIx32 
"", MsPipe->PipeHandle);
 
  384      WLog_INFO(TAG, 
"    bEndpointAddress: 0x%02" PRIx8 
"", MsPipe->bEndpointAddress);
 
  385      WLog_INFO(TAG, 
"    bInterval: %" PRIu8 
"", MsPipe->bInterval);
 
  386      WLog_INFO(TAG, 
"    PipeType: 0x%02" PRIx8 
"", MsPipe->PipeType);
 
  387      WLog_INFO(TAG, 
"    InitCompleted: %d", MsPipe->InitCompleted);
 
  391  WLog_INFO(TAG, 
"==================================================");