[USBAUDIO]

- implement retrieving string descriptor of product and store it in registry.

svn path=/trunk/; revision=73016
This commit is contained in:
Johannes Anderwald 2016-10-21 21:15:01 +00:00
parent 6357011e41
commit a9a9930090
2 changed files with 154 additions and 3 deletions

View file

@ -1023,22 +1023,172 @@ USBAudioPinBuildDescriptors(
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
USBAudioGetDescriptor(
IN PDEVICE_OBJECT DeviceObject,
IN UCHAR DescriptorType,
IN ULONG DescriptorLength,
IN UCHAR DescriptorIndex,
IN LANGID LanguageId,
OUT PVOID *OutDescriptor)
{
PURB Urb;
NTSTATUS Status;
PVOID Descriptor;
/* sanity checks */
ASSERT(DeviceObject);
ASSERT(OutDescriptor);
ASSERT(DescriptorLength);
//
// first allocate descriptor buffer
//
Descriptor = AllocFunction(DescriptorLength);
if (!Descriptor)
{
/* no memory */
return STATUS_INSUFFICIENT_RESOURCES;
}
/* allocate urb */
Urb = (PURB)AllocFunction(sizeof(URB));
if (!Urb)
{
/* no memory */
FreeFunction(Descriptor);
return STATUS_INSUFFICIENT_RESOURCES;
}
/* initialize urb */
UsbBuildGetDescriptorRequest(Urb,
sizeof(Urb->UrbControlDescriptorRequest),
DescriptorType,
DescriptorIndex,
LanguageId,
Descriptor,
NULL,
DescriptorLength,
NULL);
/* submit urb */
Status = SubmitUrbSync(DeviceObject, Urb);
/* free urb */
FreeFunction(Urb);
if (NT_SUCCESS(Status))
{
/* store result */
*OutDescriptor = Descriptor;
}
/* done */
return Status;
}
NTSTATUS
NTAPI
USBAudioGetStringDescriptor(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG DescriptorLength,
IN UCHAR DescriptorIndex,
IN LANGID LanguageId,
OUT PVOID *OutDescriptor)
{
NTSTATUS Status;
PUSB_STRING_DESCRIPTOR StringDescriptor;
/* retrieve descriptor */
Status = USBAudioGetDescriptor(DeviceObject, USB_STRING_DESCRIPTOR_TYPE, DescriptorLength, DescriptorIndex, LanguageId, OutDescriptor);
if (!NT_SUCCESS(Status))
{
// failed
return Status;
}
return STATUS_SUCCESS;
}
NTSTATUS
USBAudioRegCreateMediaCategoriesKey(
IN PUNICODE_STRING Name,
OUT PHANDLE OutHandle)
{
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DestinationString;
HANDLE Handle;
/* initialize root name*/
RtlInitUnicodeString(&DestinationString, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\MediaCategories\\");
/* initialize object attributes */
InitializeObjectAttributes(&ObjectAttributes, &DestinationString, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, NULL, NULL);
/* create the key */
Status = ZwOpenKey(&Handle, KEY_ALL_ACCESS, &ObjectAttributes);
if (NT_SUCCESS(Status))
{
/* initialize object attributes */
InitializeObjectAttributes(&ObjectAttributes, Name, OBJ_CASE_INSENSITIVE, Handle, NULL);
Status = ZwCreateKey(OutHandle, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, 0, NULL);
ZwClose(Handle);
}
return Status;
}
NTSTATUS
USBAudioInitComponentId(
PKSDEVICE Device,
IN PKSCOMPONENTID ComponentId)
{
PDEVICE_EXTENSION DeviceExtension;
NTSTATUS Status;
LPWSTR DescriptionBuffer;
UNICODE_STRING GuidString;
UNICODE_STRING Name;
HANDLE hKey;
GUID TempGuid;
/* get device extension */
DeviceExtension = Device->Context;
/* init component id */
ComponentId->Component = KSCOMPONENTID_USBAUDIO;
ComponentId->Version = HIBYTE(DeviceExtension->DeviceDescriptor->bcdDevice);
ComponentId->Revision = LOBYTE(DeviceExtension->DeviceDescriptor->bcdDevice);
INIT_USBAUDIO_MID(&ComponentId->Manufacturer, DeviceExtension->DeviceDescriptor->idVendor);
INIT_USBAUDIO_PID(&ComponentId->Product, DeviceExtension->DeviceDescriptor->idProduct);
INIT_USBAUDIO_PRODUCT_NAME(&TempGuid, DeviceExtension->DeviceDescriptor->idVendor, DeviceExtension->DeviceDescriptor->idProduct, 0);
//ComponentId->Component = KSCOMPONENTID_USBAUDIO;
UNIMPLEMENTED
return STATUS_NOT_IMPLEMENTED;
if (DeviceExtension->DeviceDescriptor->iProduct)
{
Status = USBAudioGetStringDescriptor(DeviceExtension->LowerDevice, 100 * sizeof(WCHAR), DeviceExtension->DeviceDescriptor->iProduct, 0x0409 /* FIXME */, (PVOID*)&DescriptionBuffer);
if (NT_SUCCESS(Status))
{
Status = RtlStringFromGUID(&TempGuid, &GuidString);
if (NT_SUCCESS(Status))
{
Status = USBAudioRegCreateMediaCategoriesKey(&GuidString, &hKey);
if (NT_SUCCESS(Status))
{
RtlInitUnicodeString(&Name, L"Name");
ZwSetValueKey(hKey, &Name, 0, REG_SZ, DescriptionBuffer, (wcslen(DescriptionBuffer) + 1) * sizeof(WCHAR));
ZwClose(hKey);
INIT_USBAUDIO_PRODUCT_NAME(&ComponentId->Name, DeviceExtension->DeviceDescriptor->idVendor, DeviceExtension->DeviceDescriptor->idProduct, 0);
}
RtlFreeUnicodeString(&GuidString);
}
FreeFunction(DescriptionBuffer);
}
}
return STATUS_SUCCESS;
}

View file

@ -15,4 +15,5 @@ DEFINE_GUID(KSNODETYPE_TONE, 0x7607E580L, 0xC557, 0x11D0, 0x
DEFINE_GUID(KSNODETYPE_SUM, 0xDA441A60L, 0xC556, 0x11D0, 0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1);
DEFINE_GUID(KSNODETYPE_SUPERMIX, 0xE573ADC0L, 0xC555, 0x11D0, 0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1);
DEFINE_GUID(KSNODETYPE_VOLUME, 0x3A5ACC00L, 0xC557, 0x11D0, 0x8A, 0x2B, 0x00, 0xA0, 0xC9, 0x25, 0x5A, 0xC1);
DEFINE_GUID(KSCOMPONENTID_USBAUDIO, 0x8F1275F0L, 0x26E9, 0x4264, 0xBA, 0x4D, 0x39, 0xFF, 0xF0, 0x1D, 0x94, 0xAA);
/* NO CODE HERE, THIS IS JUST REQUIRED FOR THE GUID DEFINITIONS */