2012-04-25 22:26:35 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-04-25 22:26:35 +04:00
|
|
|
* RemoteFX USB Redirection
|
|
|
|
*
|
|
|
|
* Copyright 2012 Atrust corp.
|
|
|
|
* Copyright 2012 Alfred Liu <alfred.liu@atruscorp.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2012-04-25 22:26:35 +04:00
|
|
|
#include <freerdp/utils/msusb.h>
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("utils")
|
|
|
|
|
2014-04-15 20:36:22 +04:00
|
|
|
#ifdef WITH_DEBUG_MSUSB
|
2016-10-07 15:04:40 +03:00
|
|
|
#define DEBUG_MSUSB(...) WLog_DBG(TAG, __VA_ARGS__)
|
2014-04-15 20:36:22 +04:00
|
|
|
#else
|
2016-10-07 15:04:40 +03:00
|
|
|
#define DEBUG_MSUSB(...) do { } while (0)
|
2014-04-15 20:36:22 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
static MSUSB_PIPE_DESCRIPTOR* msusb_mspipe_new()
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
return (MSUSB_PIPE_DESCRIPTOR*) calloc(1, sizeof(MSUSB_PIPE_DESCRIPTOR));
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes,
|
|
|
|
UINT32 NumberOfPipes)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int pnum = 0;
|
2012-10-23 19:55:41 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (MsPipes)
|
|
|
|
{
|
|
|
|
for (pnum = 0; pnum < NumberOfPipes && MsPipes[pnum]; pnum++)
|
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
zfree(MsPipes[pnum]);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
zfree(MsPipes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
void msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface,
|
|
|
|
MSUSB_PIPE_DESCRIPTOR** NewMsPipes, UINT32 NewNumberOfPipes)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
/* free orignal MsPipes */
|
|
|
|
msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes);
|
|
|
|
/* And replace it */
|
|
|
|
MsInterface->MsPipes = NewMsPipes;
|
|
|
|
MsInterface->NumberOfPipes = NewNumberOfPipes;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(BYTE* data, UINT32 data_size,
|
|
|
|
UINT32 NumberOfPipes, int* offset)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int pnum, move = 0;
|
2012-10-23 19:55:41 +04:00
|
|
|
MSUSB_PIPE_DESCRIPTOR** MsPipes;
|
2016-10-07 15:04:40 +03:00
|
|
|
MsPipes = (MSUSB_PIPE_DESCRIPTOR**) calloc(NumberOfPipes,
|
|
|
|
sizeof(MSUSB_PIPE_DESCRIPTOR*));
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!MsPipes)
|
|
|
|
return NULL;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
for (pnum = 0; pnum < NumberOfPipes; pnum++)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
MSUSB_PIPE_DESCRIPTOR* MsPipe = msusb_mspipe_new();
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!MsPipe)
|
|
|
|
goto out_error;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data + move, MsPipe->MaximumPacketSize);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + move + 4, MsPipe->MaximumTransferSize);
|
|
|
|
data_read_UINT32(data + move + 8, MsPipe->PipeFlags);
|
2012-04-25 22:26:35 +04:00
|
|
|
move += 12;
|
2016-10-07 15:04:40 +03:00
|
|
|
/* Already set to zero by memset
|
|
|
|
MsPipe->PipeHandle = 0;
|
|
|
|
MsPipe->bEndpointAddress = 0;
|
|
|
|
MsPipe->bInterval = 0;
|
|
|
|
MsPipe->PipeType = 0;
|
|
|
|
MsPipe->InitCompleted = 0;
|
|
|
|
*/
|
2012-04-25 22:26:35 +04:00
|
|
|
MsPipes[pnum] = MsPipe;
|
2016-10-07 15:04:40 +03:00
|
|
|
}
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
*offset += move;
|
|
|
|
return MsPipes;
|
2015-06-16 16:42:07 +03:00
|
|
|
out_error:
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
for (pnum = 0; pnum < NumberOfPipes; pnum++)
|
|
|
|
{
|
|
|
|
free(MsPipes[pnum]);
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
free(MsPipes);
|
|
|
|
return NULL;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
static MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_new()
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
return (MSUSB_INTERFACE_DESCRIPTOR*) calloc(1,
|
|
|
|
sizeof(MSUSB_INTERFACE_DESCRIPTOR));
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
static void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
if (MsInterface)
|
|
|
|
{
|
|
|
|
msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes);
|
|
|
|
MsInterface->MsPipes = NULL;
|
|
|
|
zfree(MsInterface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR**
|
|
|
|
MsInterfaces, UINT32 NumInterfaces)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int inum = 0;
|
|
|
|
|
|
|
|
if (MsInterfaces)
|
|
|
|
{
|
|
|
|
for (inum = 0; inum < NumInterfaces; inum++)
|
|
|
|
{
|
|
|
|
msusb_msinterface_free(MsInterfaces[inum]);
|
|
|
|
}
|
2012-10-23 19:55:41 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
zfree(MsInterfaces);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
void msusb_msinterface_replace(MSUSB_CONFIG_DESCRIPTOR* MsConfig,
|
|
|
|
BYTE InterfaceNumber, MSUSB_INTERFACE_DESCRIPTOR* NewMsInterface)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
msusb_msinterface_free(MsConfig->MsInterfaces[InterfaceNumber]);
|
2016-10-07 15:04:40 +03:00
|
|
|
MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(BYTE* data, UINT32 data_size,
|
|
|
|
int* offset)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-23 19:55:41 +04:00
|
|
|
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
|
2012-04-25 22:26:35 +04:00
|
|
|
MsInterface = msusb_msinterface_new();
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!MsInterface)
|
|
|
|
return NULL;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data, MsInterface->Length);
|
|
|
|
data_read_UINT16(data + 2, MsInterface->NumberOfPipesExpected);
|
|
|
|
data_read_BYTE(data + 4, MsInterface->InterfaceNumber);
|
|
|
|
data_read_BYTE(data + 5, MsInterface->AlternateSetting);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 8, MsInterface->NumberOfPipes);
|
2012-04-25 22:26:35 +04:00
|
|
|
*offset += 12;
|
2012-10-23 19:55:41 +04:00
|
|
|
MsInterface->InterfaceHandle = 0;
|
|
|
|
MsInterface->bInterfaceClass = 0;
|
2012-04-25 22:26:35 +04:00
|
|
|
MsInterface->bInterfaceSubClass = 0;
|
|
|
|
MsInterface->bInterfaceProtocol = 0;
|
2012-10-23 19:55:41 +04:00
|
|
|
MsInterface->InitCompleted = 0;
|
|
|
|
MsInterface->MsPipes = NULL;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (MsInterface->NumberOfPipes > 0)
|
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
MsInterface->MsPipes =
|
|
|
|
msusb_mspipes_read(data + (*offset), data_size - (*offset),
|
|
|
|
MsInterface->NumberOfPipes, offset);
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!MsInterface->MsPipes)
|
|
|
|
goto out_error;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2015-06-16 16:42:07 +03:00
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
return MsInterface;
|
2015-06-16 16:42:07 +03:00
|
|
|
out_error:
|
|
|
|
msusb_msinterface_free(MsInterface);
|
|
|
|
return NULL;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data,
|
|
|
|
int* offset)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
MSUSB_PIPE_DESCRIPTOR** MsPipes;
|
|
|
|
MSUSB_PIPE_DESCRIPTOR* MsPipe;
|
2012-04-25 22:26:35 +04:00
|
|
|
int pnum = 0, move = 0;
|
|
|
|
/* Length */
|
2016-10-07 15:04:40 +03:00
|
|
|
data_write_UINT16(data, MsInterface->Length);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* InterfaceNumber */
|
2016-10-07 15:04:40 +03:00
|
|
|
data_write_BYTE(data + 2, MsInterface->InterfaceNumber);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* AlternateSetting */
|
2016-10-07 15:04:40 +03:00
|
|
|
data_write_BYTE(data + 3, MsInterface->AlternateSetting);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* bInterfaceClass */
|
2016-10-07 15:04:40 +03:00
|
|
|
data_write_BYTE(data + 4, MsInterface->bInterfaceClass);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* bInterfaceSubClass */
|
2016-10-07 15:04:40 +03:00
|
|
|
data_write_BYTE(data + 5, MsInterface->bInterfaceSubClass);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* bInterfaceProtocol */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_BYTE(data + 6, MsInterface->bInterfaceProtocol);
|
2016-10-07 15:04:40 +03:00
|
|
|
/* Padding */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_BYTE(data + 7, 0);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* InterfaceHandle */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(data + 8, MsInterface->InterfaceHandle);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* NumberOfPipes */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(data + 12, MsInterface->NumberOfPipes);
|
2012-04-25 22:26:35 +04:00
|
|
|
move += 16;
|
|
|
|
/* Pipes */
|
|
|
|
MsPipes = MsInterface->MsPipes;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
|
|
|
for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
MsPipe = MsPipes[pnum];
|
|
|
|
/* MaximumPacketSize */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(data + move, MsPipe->MaximumPacketSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* EndpointAddress */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_BYTE(data + move + 2, MsPipe->bEndpointAddress);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* Interval */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_BYTE(data + move + 3, MsPipe->bInterval);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* PipeType */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(data + move + 4, MsPipe->PipeType);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* PipeHandle */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(data + move + 8, MsPipe->PipeHandle);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* MaximumTransferSize */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(data + move + 12, MsPipe->MaximumTransferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* PipeFlags */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(data + move + 16, MsPipe->PipeFlags);
|
2012-04-25 22:26:35 +04:00
|
|
|
move += 20;
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
*offset += move;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
static MSUSB_INTERFACE_DESCRIPTOR** msusb_msinterface_read_list(BYTE* data,
|
|
|
|
UINT32 data_size, UINT32 NumInterfaces)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int inum, offset = 0;
|
2012-10-23 19:55:41 +04:00
|
|
|
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
|
2016-10-07 15:04:40 +03:00
|
|
|
MsInterfaces = (MSUSB_INTERFACE_DESCRIPTOR**) calloc(NumInterfaces,
|
|
|
|
sizeof(MSUSB_INTERFACE_DESCRIPTOR*));
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!MsInterfaces)
|
|
|
|
return NULL;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
for (inum = 0; inum < NumInterfaces; inum++)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
MsInterfaces[inum] = msusb_msinterface_read(data + offset, data_size - offset,
|
|
|
|
&offset);
|
|
|
|
}
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return MsInterfaces;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
int msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, BYTE* data,
|
|
|
|
int* offset)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int inum = 0;
|
2012-10-23 19:55:41 +04:00
|
|
|
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
|
|
|
|
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
|
2012-04-25 22:26:35 +04:00
|
|
|
/* ConfigurationHandle*/
|
2012-10-23 19:55:41 +04:00
|
|
|
data_write_UINT32(data + *offset, MsConfg->ConfigurationHandle);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* NumInterfaces*/
|
2016-10-07 15:04:40 +03:00
|
|
|
data_write_UINT32(data + *offset + 4, MsConfg->NumInterfaces);
|
2012-04-25 22:26:35 +04:00
|
|
|
*offset += 8;
|
|
|
|
/* Interfaces */
|
|
|
|
MsInterfaces = MsConfg->MsInterfaces;
|
2012-10-23 19:55:41 +04:00
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
for (inum = 0; inum < MsConfg->NumInterfaces; inum++)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
MsInterface = MsInterfaces[inum];
|
|
|
|
msusb_msinterface_write(MsInterface, data + (*offset), offset);
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_new()
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
return (MSUSB_CONFIG_DESCRIPTOR*) calloc(1, sizeof(MSUSB_CONFIG_DESCRIPTOR));
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
void msusb_msconfig_free(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
if (MsConfig)
|
|
|
|
{
|
|
|
|
msusb_msinterface_free_list(MsConfig->MsInterfaces, MsConfig->NumInterfaces);
|
|
|
|
MsConfig->MsInterfaces = NULL;
|
|
|
|
zfree(MsConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:04:40 +03:00
|
|
|
MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(BYTE* data, UINT32 data_size,
|
|
|
|
UINT32 NumInterfaces)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int i, offset = 0;
|
2012-10-23 19:55:41 +04:00
|
|
|
UINT16 lenInterface;
|
|
|
|
MSUSB_CONFIG_DESCRIPTOR* MsConfig;
|
|
|
|
BYTE lenConfiguration, typeConfiguration;
|
2012-04-25 22:26:35 +04:00
|
|
|
MsConfig = msusb_msconfig_new();
|
2016-10-07 15:04:40 +03:00
|
|
|
|
|
|
|
for (i = 0; i < NumInterfaces; i++)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data + offset, lenInterface);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset += lenInterface;
|
|
|
|
}
|
2012-10-23 19:55:41 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_BYTE(data + offset, lenConfiguration);
|
|
|
|
data_read_BYTE(data + offset + 1, typeConfiguration);
|
2012-10-23 19:55:41 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (lenConfiguration != 0x9 || typeConfiguration != 0x2)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_MSUSB("%s: len and type must be 0x9 and 0x2 , but it is 0x%"PRIx8" and 0x%"PRIx8"",
|
|
|
|
__FUNCTION__, lenConfiguration, typeConfiguration);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2012-10-23 19:55:41 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data + offset + 2, MsConfig->wTotalLength);
|
|
|
|
data_read_BYTE(data + offset + 5, MsConfig->bConfigurationValue);
|
2012-10-23 19:55:41 +04:00
|
|
|
MsConfig->NumInterfaces = NumInterfaces;
|
2012-04-25 22:26:35 +04:00
|
|
|
MsConfig->ConfigurationHandle = 0;
|
2012-10-23 19:55:41 +04:00
|
|
|
MsConfig->InitCompleted = 0;
|
|
|
|
MsConfig->MsOutSize = 0;
|
|
|
|
MsConfig->MsInterfaces = NULL;
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 0;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (NumInterfaces > 0)
|
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
MsConfig->MsInterfaces = msusb_msinterface_read_list(data, data_size,
|
|
|
|
NumInterfaces);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return MsConfig;
|
|
|
|
}
|
|
|
|
|
2012-10-23 19:55:41 +04:00
|
|
|
void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2016-10-07 15:04:40 +03:00
|
|
|
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
|
|
|
|
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
|
|
|
|
MSUSB_PIPE_DESCRIPTOR** MsPipes;
|
|
|
|
MSUSB_PIPE_DESCRIPTOR* MsPipe;
|
2012-04-25 22:26:35 +04:00
|
|
|
int inum = 0, pnum = 0;
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, "=================MsConfig:========================");
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, "wTotalLength:%"PRIu16"", MsConfig->wTotalLength);
|
|
|
|
WLog_INFO(TAG, "bConfigurationValue:%"PRIu8"", MsConfig->bConfigurationValue);
|
|
|
|
WLog_INFO(TAG, "ConfigurationHandle:0x%08"PRIx32"", MsConfig->ConfigurationHandle);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, "InitCompleted:%d", MsConfig->InitCompleted);
|
|
|
|
WLog_INFO(TAG, "MsOutSize:%d", MsConfig->MsOutSize);
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, "NumInterfaces:%"PRIu32"", MsConfig->NumInterfaces);
|
2012-04-25 22:26:35 +04:00
|
|
|
MsInterfaces = MsConfig->MsInterfaces;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
|
|
|
for (inum = 0; inum < MsConfig->NumInterfaces; inum++)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
MsInterface = MsInterfaces[inum];
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, " Interface: %"PRIu8"", MsInterface->InterfaceNumber);
|
|
|
|
WLog_INFO(TAG, " Length: %"PRIu16"", MsInterface->Length);
|
|
|
|
WLog_INFO(TAG, " NumberOfPipesExpected: %"PRIu16"",
|
2016-10-07 15:04:40 +03:00
|
|
|
MsInterface->NumberOfPipesExpected);
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, " AlternateSetting: %"PRIu8"", MsInterface->AlternateSetting);
|
|
|
|
WLog_INFO(TAG, " NumberOfPipes: %"PRIu32"", MsInterface->NumberOfPipes);
|
|
|
|
WLog_INFO(TAG, " InterfaceHandle: 0x%08"PRIx32"", MsInterface->InterfaceHandle);
|
|
|
|
WLog_INFO(TAG, " bInterfaceClass: 0x%02"PRIx8"", MsInterface->bInterfaceClass);
|
|
|
|
WLog_INFO(TAG, " bInterfaceSubClass: 0x%02"PRIx8"", MsInterface->bInterfaceSubClass);
|
|
|
|
WLog_INFO(TAG, " bInterfaceProtocol: 0x%02"PRIx8"", MsInterface->bInterfaceProtocol);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, " InitCompleted: %d", MsInterface->InitCompleted);
|
2012-04-25 22:26:35 +04:00
|
|
|
MsPipes = MsInterface->MsPipes;
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
|
|
|
|
{
|
|
|
|
MsPipe = MsPipes[pnum];
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, " Pipe: %d", pnum);
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, " MaximumPacketSize: 0x%04"PRIx16"", MsPipe->MaximumPacketSize);
|
|
|
|
WLog_INFO(TAG, " MaximumTransferSize: 0x%08"PRIx32"", MsPipe->MaximumTransferSize);
|
|
|
|
WLog_INFO(TAG, " PipeFlags: 0x%08"PRIx32"", MsPipe->PipeFlags);
|
|
|
|
WLog_INFO(TAG, " PipeHandle: 0x%08"PRIx32"", MsPipe->PipeHandle);
|
|
|
|
WLog_INFO(TAG, " bEndpointAddress: 0x%02"PRIx8"", MsPipe->bEndpointAddress);
|
|
|
|
WLog_INFO(TAG, " bInterval: %"PRIu8"", MsPipe->bInterval);
|
|
|
|
WLog_INFO(TAG, " PipeType: 0x%02"PRIx8"", MsPipe->PipeType);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, " InitCompleted: %d", MsPipe->InitCompleted);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
}
|
2016-10-07 15:04:40 +03:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, "==================================================");
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|