15#define HUB_ID_MAX_CHARS 128
18#define HUB_INSTANCE_ID_CHARS 28
21#define HUB_LOCATION_TEXT_BYTES 42
23#define HUB_DEFAULT_LANGUAGE 0x0409
27 { 0x4B06FD46, 0xC84E, 0x4664, { 0x9C, 0x65, 0x0C, 0x86, 0xD9, 0x04, 0x7A, 0x0C } };
38#define HUB_FAILURE_ID(Reason, Pid, Text) { (Reason), (Pid), Text, sizeof(Text) }
141 DPRINT1(
"Id list of %lu bytes could not be allocated\n",
Total);
167 Ids->LengthInBytes = 0;
186 DPRINT1(
"Id list copy of %lu bytes could not be allocated\n",
Source->LengthInBytes);
249 DPRINT1(
"Formatting an id failed 0x%lx\n",
Text->Status);
270 String.MaximumLength = IdBytes;
314 static const WCHAR HexDigits[] =
L"0123456789ABCDEF";
320 Nibble = (BcdDevice >> (12 -
Index * 4)) & 0xF;
321 Text[
Index] = (BcdUsb > 0x0200) ? HexDigits[Nibble] : (
WCHAR)(
L'0' + Nibble);
354 USHORT VendorId =
Child->m_DeviceDescriptor.idVendor;
355 USHORT ProductId =
Child->m_DeviceDescriptor.idProduct;
366 Text.Format(
L"USB\\VID_%04X&PID_%04X", VendorId, ProductId);
368 Text.Append(
L"_NON_FUNCTIONAL");
426 static PCWSTR const Plain[] =
428 L"USB\\DevClass_00&SubClass_00&Prot_00",
429 L"USB\\DevClass_00&SubClass_00",
433 USHORT VendorId =
Child->m_DeviceDescriptor.idVendor;
439 Text.Format(
L"USB\\COMPAT_VID_%04X&DevClass_00&SubClass_00&Prot00", VendorId);
444 Text.Format(
L"USB\\COMPAT_VID_%04X&DevClass_00&SubClass_00", VendorId);
449 Text.Format(
L"USB\\COMPAT_VID_%04X&DevClass_00", VendorId);
477 Text.Set(
L"USB\\MS_COMP_");
480 if (SubCompatibleId !=
NULL)
483 Text.Append(
L"&MS_SUBCOMP_");
498 const UCHAR* CompatibleId;
499 const UCHAR* SubCompatibleId;
504 CompatibleId =
Child->m_MsOs20.CompatibleId->CompatibleId;
505 SubCompatibleId =
Child->m_MsOs20.CompatibleId->SubCompatibleId;
507 if (SubCompatibleId[0] != 0 && CompatibleId[0] != 0)
516 CompatibleId =
Child->m_MsOsExtConfig->Function[0].CompatibleId;
517 SubCompatibleId =
Child->m_MsOsExtConfig->Function[0].SubCompatibleId;
520 if (SubCompatibleId[0] != 0)
532 if (CompatibleId[0] != 0)
546 USHORT VendorId =
Child->m_DeviceDescriptor.idVendor;
556 SubClass =
Interface->bInterfaceSubClass;
565 Text.Format(
L"USB\\COMPAT_VID_%04X&Class_%02X&SubClass_%02X&Prot_%02X", VendorId,
Class, SubClass,
Protocol);
570 Text.Format(
L"USB\\COMPAT_VID_%04X&Class_%02X&SubClass_%02X", VendorId,
Class, SubClass);
575 Text.Format(
L"USB\\COMPAT_VID_%04X&Class_%02X", VendorId,
Class);
585 Text.Format(
L"USB\\Class_%02X&SubClass_%02X",
Class, SubClass);
619 switch (
Child->Speed())
623 Text.Set(
L"USB\\USB20_HUB");
627 Text.Set(
L"USB\\USB30_HUB");
651 ULONG NameBytes =
Child->m_SerialNumberLength + 28;
662 DPRINT1(
"Container id name for device %p could not be allocated\n",
Child);
700 Child->m_ContainerId.Data3 = (
Child->m_ContainerId.Data3 & 0x0FFF) | 0x5000;
701 Child->m_ContainerId.Data4[0] = (
Child->m_ContainerId.Data4[0] & 0x3F) | 0x80;
737 Text.Format(
L"{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
738 Id->Data1,
Id->Data2,
Id->Data3,
739 Id->Data4[0],
Id->Data4[1],
Id->Data4[2],
Id->Data4[3],
740 Id->Data4[4],
Id->Data4[5],
Id->Data4[6],
Id->Data4[7]);
769HubIdLoadVmReservedId(
779 if (
Child->m_VmReservedId.Buffer !=
NULL)
796 DPRINT1(
"VM reserved id for device %p could not be allocated\n",
Child);
805 Child->m_VmReservedId.MaximumLength =
Child->m_VmReservedId.Length;
816 if (
Child->m_VmReservedId.Buffer !=
NULL)
851 Port->m_InstancePortNumber != 0 &&
937HubIdReadProductString(
942 HubWaitForPnpEvent(&
Child->m_QueryTextEvent,
"device text query",
Child->m_Object);
959 DPRINT1(
"Location text for device %p could not be allocated\n",
Child);
964 Child->m_Port->Number(),
Child->m_Hub->m_HubNumber);
997 Irp->IoStatus.Information = 0;
1004 Child->m_LanguageId = Language;
1011 HubIdReadProductString(
Child);
1018 DPRINT(
"Device %p has no product string\n",
Child);
1023 HubIdReadProductString(
Child);
1027 DPRINT(
"Device %p has no product string\n",
Child);
1038 DPRINT1(
"Description text for device %p could not be allocated\n",
Child);
1052HubIdQueryDeviceText(
1061 switch (
Stack->Parameters.QueryDeviceText.DeviceTextType)
1090 return min(
Child->m_Control.Urb.TransferBufferLength, (
ULONG)
sizeof(
Child->m_ScratchBuffer));
1101 return (
Child->m_DeviceDescriptor.bcdUSB >= 0x0300) ?
L"MSFT30" :
L"MSFT20";
1120 Child->m_SerialNumberLength <
Child->m_SerialPrefixLength +
sizeof(
WCHAR))
1156 Child->m_DeviceDescriptor.bcdUSB,
1158 Child->HasHack(ChildHack::UseWin8DescriptorValidation),
1159 Child->m_Port->m_Info.SspIsochBurstCount,
1160 Child->m_ValidationBits);
1181 DPRINT1(
"Device %p serial number could not be allocated\n",
Child);
1193 Child->m_SerialPrefixLength = PrefixBytes;
1229 if (StoredLength ==
Returned - 2 &&
1235 DPRINT1(
"Device %p came back with a different serial number\n",
Child);
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
RtlInitEmptyUnicodeString(SymbolicLinkName, NULL, 0)
BOOLEAN SerialNumberValid()
BOOLEAN SerialNumberIndexZero()
BOOLEAN SerialNumberCompared()
BOOLEAN SameSerialNumber()
BOOLEAN IgnoreSerialNumber()
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
BOOLEAN HasHack(_In_ ChildHack Flag) const
#define STATUS_NOT_SUPPORTED
VOID NTAPI HubDescInitDeviceContext(_Out_ HubDescContext *Context, _In_ USHORT BcdUsb, _In_ USB_DEVICE_SPEED Speed, _In_ BOOLEAN Win8Behavior, _In_ ULONG SspIsochBurstCount, _In_opt_ PULONG Bitmap)
BOOLEAN NTAPI HubDescCheckSerialNumber(_In_ const HubDescContext *Context, _In_reads_bytes_(*Length) PUSB_STRING_DESCRIPTOR Descriptor, _Inout_ PULONG Length)
#define HUB_MSOS20_COMPATIBLE_ID
_Check_return_ _In_ ULONG _Inout_ PDXGK_CHILD_CONTAINER_ID ContainerId
#define NT_SUCCESS(StatCode)
#define _IRQL_requires_(irql)
#define ExAllocatePoolWithTag(hernya, size, tag)
VOID NTAPI KeClearEvent(IN PKEVENT Event)
static const HubFailureId HubUnknownDeviceId
static BOOLEAN NTAPI HubIdUsesFailureId(_In_ HubChild *Child)
#define HUB_DEFAULT_LANGUAGE
static PCWSTR NTAPI HubIdSerialPrefix(_In_ HubChild *Child)
static NTSTATUS NTAPI HubIdEmit(_In_ const HubIdSink *Sink, _In_ PCUNICODE_STRING Id)
static BOOLEAN NTAPI HubIdHasContainerId(_In_ HubChild *Child)
static const WCHAR HubBillboardId[]
BOOLEAN NTAPI HubIdLanguageSupported(_In_ HubChild *Child, _In_ USHORT Language)
static NTSTATUS NTAPI HubIdBuildCompositeIds(_In_ HubChild *Child, _In_ const HubIdSink *Sink)
static const GUID HubContainerIdNamespace
NTSTATUS NTAPI HubIdBuildCompatibleIds(_In_ HubChild *Child, _In_opt_ PWDFDEVICE_INIT DeviceInit, _Out_opt_ PUSB_ID_STRING Ids)
NTSTATUS NTAPI HubIdBuildHardwareIds(_In_ HubChild *Child, _In_opt_ PWDFDEVICE_INIT DeviceInit, _Out_opt_ PUSB_ID_STRING Ids)
_Inout_ PIRP _In_ LCID Locale
static const HubFailureId *NTAPI HubFailureIdFor(_In_ HubChild *Child)
static NTSTATUS NTAPI HubIdListAppend(_Inout_ PUSB_ID_STRING List, _In_ PCUNICODE_STRING Id)
static NTSTATUS NTAPI HubIdBuildClassIds(_In_ HubChild *Child, _In_ const HubIdSink *Sink)
PUSB_STRING_DESCRIPTOR Product
static VOID NTAPI HubIdBuildContainerId(_In_ HubChild *Child, _In_ PWDFDEVICE_INIT DeviceInit)
static NTSTATUS NTAPI HubIdEmitCounted(_In_ const HubIdSink *Sink, _In_reads_bytes_(IdBytes) PCWSTR Id, _In_ USHORT IdBytes)
static NTSTATUS NTAPI HubIdBuildMsOsIds(_In_ HubChild *Child, _In_ const HubIdSink *Sink)
VOID NTAPI HubIdListFree(_Inout_ PUSB_ID_STRING Ids)
HubSaveUxdState(Child->m_Hub, Child, NULL)
#define HUB_LOCATION_TEXT_BYTES
#define HUB_FAILURE_ID(Reason, Pid, Text)
VOID NTAPI HubIdFreeDeviceIds(_In_ HubChild *Child)
WCHAR Digits[HUB_INSTANCE_ID_CHARS]
static NTSTATUS NTAPI HubIdBuildDeviceId(_In_ HubChild *Child, _In_ PWDFDEVICE_INIT DeviceInit)
return HubIdAssignInstanceId(Child, DeviceInit)
static VOID NTAPI HubIdGenerateContainerId(_In_ HubChild *Child)
static BOOLEAN NTAPI HubIdIsKnown(_In_ HubChild *Child)
#define HUB_INSTANCE_ID_CHARS
static NTSTATUS NTAPI HubIdEmitMsComp(_In_ const HubIdSink *Sink, _In_reads_(8) const UCHAR *CompatibleId, _In_reads_opt_(8) const UCHAR *SubCompatibleId)
static VOID NTAPI HubIdWidenMsOsField(_In_reads_(8) const UCHAR *Field, _Out_writes_(9) PWCHAR Text)
BOOLEAN NTAPI HubIdGetContainerId(_In_ HubChild *Child, _Out_ GUID *ContainerId)
static BOOLEAN NTAPI HubIdIsVmReserved(_In_ HubChild *Child)
static ULONG NTAPI HubIdBytesReturned(_In_ HubChild *Child)
_In_ PWDFDEVICE_INIT DeviceInit
static NTSTATUS NTAPI HubIdEmitText(_In_ const HubIdSink *Sink, _In_ const HubIdText *Text)
static const HubFailureId HubFailureIds[]
NTSTATUS NTAPI HubIdListCopy(_Out_ PUSB_ID_STRING Destination, _In_ const USB_ID_STRING *Source)
BOOLEAN NTAPI HubIdGetSerialNumberText(_In_ HubChild *Child, _Outptr_result_bytebuffer_(*Length) PCWSTR *Text, _Out_ PULONG Length)
static VOID NTAPI HubIdRevisionText(_In_ USHORT BcdUsb, _In_ USHORT BcdDevice, _Out_writes_(5) PWCHAR Text)
#define HUB_ENUM_DEVICE_DESCRIPTOR_FAILED
#define HUB_ENUM_BAD_DEVICE_DESCRIPTOR
#define HUB_ENUM_BAD_SERIAL_NUMBER
#define HUB_ENUM_SET_ADDRESS_FAILED
#define HUB_SERIAL_PREFIX_BYTES
#define HUB_ENUM_BAD_CONFIG_DESCRIPTOR
VOID NTAPI HubSha1Init(_Out_ HubSha1 *Context)
VOID NTAPI HubSha1Update(_Inout_ HubSha1 *Context, _In_reads_bytes_(Length) const VOID *Data, _In_ SIZE_T Length)
VOID NTAPI HubSha1Final(_Inout_ HubSha1 *Context, _Out_writes_bytes_all_(HUB_SHA1_DIGEST_BYTES) PUCHAR Digest)
#define HUB_ENUM_PORT_RESET_FAILED
#define HUB_ENUM_LINK_COMPLIANCE
#define HUB_ENUM_CONFIG_DESCRIPTOR_FAILED
#define HUB_SHA1_DIGEST_BYTES
#define HUB_ENUM_LINK_SS_INACTIVE
_In_ const HubIdStrings * Ids
#define RtlEqualMemory(dst, src, len)
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
#define ExFreePoolWithTag(_P, _T)
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
#define _In_reads_bytes_(s)
#define _Outptr_result_bytebuffer_(s)
#define _In_reads_opt_(s)
#define _Printf_format_string_
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
_In_ ULONG _In_ ULONG _In_ ULONG Length
#define IoCompleteRequest
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
NTSTRSAFEAPI RtlStringCbCatW(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
_Must_inspect_result_ NTSTRSAFEAPI RtlStringCbLengthW(_In_reads_or_z_(cbMax/sizeof(wchar_t)) STRSAFE_LPCWSTR psz, _In_ _In_range_(1, NTSTRSAFE_MAX_CCH *sizeof(wchar_t)) size_t cbMax, _Out_opt_ _Deref_out_range_(<, cbMax - 1) size_t *pcbLength)
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
NTSTRSAFEAPI RtlStringCbVPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat, _In_ va_list argList)
#define LANGIDFROMLCID(l)
_In_ const GUID _In_ ULONG Revision
VOID Append(_In_z_ PCWSTR Text)
VOID Format(_In_z_ _Printf_format_string_ PCWSTR Format,...)
VOID Set(_In_z_ PCWSTR Text)
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
_In_ UCXUSBDEVICE _In_ ULONG Interface
#define STATUS_INSUFFICIENT_RESOURCES
struct _USB_STRING_DESCRIPTOR * PUSB_STRING_DESCRIPTOR
WdfStringGetUnicodeString(Original, &Name)
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ PWDFDEVICE_INIT DeviceInit
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFDEVICE Child
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
_Must_inspect_result_ _In_ WDFCMRESLIST List
#define WDF_NO_OBJECT_ATTRIBUTES
@ DeviceTextLocationInformation
_In_ __drv_aliasesMem PSTRING Prefix