2 * Copyright (C) 2010 Damjan Jovanovic
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
25 #define WIN32_NO_STATUS
31 #include "ddk/usbdlib.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(usbd);
36 PUSB_INTERFACE_DESCRIPTOR WINAPI USBD_ParseConfigurationDescriptorEx(
37 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
38 PVOID StartPosition, LONG InterfaceNumber,
39 LONG AlternateSetting, LONG InterfaceClass,
40 LONG InterfaceSubClass, LONG InterfaceProtocol )
42 /* http://blogs.msdn.com/usbcoreblog/archive/2009/12/12/
43 * what-is-the-right-way-to-validate-and-parse-configuration-descriptors.aspx
46 PUSB_INTERFACE_DESCRIPTOR interface;
48 TRACE( "(%p, %p, %d, %d, %d, %d, %d)\n", ConfigurationDescriptor,
49 StartPosition, InterfaceNumber, AlternateSetting,
50 InterfaceClass, InterfaceSubClass, InterfaceProtocol );
52 interface = (PUSB_INTERFACE_DESCRIPTOR) USBD_ParseDescriptors(
53 ConfigurationDescriptor, ConfigurationDescriptor->wTotalLength,
54 StartPosition, USB_INTERFACE_DESCRIPTOR_TYPE );
55 while (interface != NULL)
57 if ((InterfaceNumber == -1 || interface->bInterfaceNumber == InterfaceNumber) &&
58 (AlternateSetting == -1 || interface->bAlternateSetting == AlternateSetting) &&
59 (InterfaceClass == -1 || interface->bInterfaceClass == InterfaceClass) &&
60 (InterfaceSubClass == -1 || interface->bInterfaceSubClass == InterfaceSubClass) &&
61 (InterfaceProtocol == -1 || interface->bInterfaceProtocol == InterfaceProtocol))
65 interface = (PUSB_INTERFACE_DESCRIPTOR) USBD_ParseDescriptors(
66 ConfigurationDescriptor, ConfigurationDescriptor->wTotalLength,
67 interface + 1, USB_INTERFACE_DESCRIPTOR_TYPE );
72 PUSB_COMMON_DESCRIPTOR WINAPI USBD_ParseDescriptors(
73 PVOID DescriptorBuffer,
78 PUSB_COMMON_DESCRIPTOR common;
80 TRACE( "(%p, %u, %p, %d)\n", DescriptorBuffer, TotalLength, StartPosition, DescriptorType );
82 for (common = (PUSB_COMMON_DESCRIPTOR)DescriptorBuffer;
83 ((char*)common) + sizeof(USB_COMMON_DESCRIPTOR) <= ((char*)DescriptorBuffer) + TotalLength;
84 common = (PUSB_COMMON_DESCRIPTOR)(((char*)common) + common->bLength))
86 if (StartPosition <= (PVOID)common && common->bDescriptorType == DescriptorType)
92 ULONG WINAPI USBD_GetInterfaceLength(
93 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
96 PUSB_COMMON_DESCRIPTOR common;
97 ULONG total = InterfaceDescriptor->bLength;
99 TRACE( "(%p, %p)\n", InterfaceDescriptor, BufferEnd );
101 for (common = (PUSB_COMMON_DESCRIPTOR)(InterfaceDescriptor + 1);
102 (((PUCHAR)common) + sizeof(USB_COMMON_DESCRIPTOR)) <= BufferEnd &&
103 common->bDescriptorType != USB_INTERFACE_DESCRIPTOR_TYPE;
104 common = (PUSB_COMMON_DESCRIPTOR)(((char*)common) + common->bLength))
106 total += common->bLength;
111 NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
113 TRACE( "(%p, %s)\n", driver, debugstr_w(path->Buffer) );
114 return STATUS_SUCCESS;