Ok, i need some help here. I’m doing something wrong in my driver. I try to obtain the name of the USB hostcontroller i’m connected to. I want this because i’m trying to get the USB-device tree. And the tree is needed for my application in my endproduct.
I have made an functions that should get the name for me.
The weird thing is that de returned size is 204 (so it looks like it has found a string of 204 chars) but the returned string in my debugprint is only ''
my debug print looks like this:
“HostCtrlr Name: \ (204 chars)!”
if i try to display char by char i get an BSOD.
Below is my function. I think i’m doing something wrong but i dont see it.
VOID GenerateUSBTree ( PDEVICE_OBJECT Device )
{
PIRP Irp = NULL;
IO_STATUS_BLOCK iostatus;
PIO_STACK_LOCATION stack = NULL;
KEVENT event;
NTSTATUS status = STATUS_SUCCESS;
ULONG ulNewLength = 0;
PUSB_HUB_NAME pHostControllerName, pHostControllerForLength;
pHostControllerForLength = ExAllocatePoolWithTag(NonPagedPool, sizeof(struct _USB_HUB_NAME), ‘TAGG’);
// Initialize the event to the non-signalled state
KeInitializeEvent ( &event, NotificationEvent, FALSE );
Irp = IoBuildDeviceIoControlRequest ( IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME,
Device,
NULL, 0,
NULL, 0,
TRUE,
&event,
&iostatus );
if ( !Irp )
{
DebugPrint(“Unable to allocate IRP for getting controller name”);
KeClearEvent ( &event );
return;
}
/*
IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME
Input
Parameters.Others.Argument1 should be a pointer to a USB_HUB_NAME structure that will be filled in with the name of the host controller.
Parameters.Others.Argument2 should be a ULONG specifying the length of the buffer (in bytes) in Parameters.Others.Argument1.
*/
// Set up the stack for the IRP
stack = IoGetNextIrpStackLocation ( Irp );
stack->Parameters.Others.Argument1 = pHostControllerForLength;
stack->Parameters.Others.Argument2 = (PVOID) sizeof(struct _USB_HUB_NAME);
// Send it down and wait for a response
status = IoCallDriver ( Device, Irp );
if ( status == STATUS_PENDING )
{
DebugPrint(“Waiting”);
KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
DebugPrint(“Done Wait!”);
status = iostatus.Status;
}
ulNewLength = pHostControllerForLength->ActualLength;
pHostControllerName = ExAllocatePoolWithTag(NonPagedPool, ulNewLength, ‘TAGG’);
// Re-Initialize the event to the non-signalled state
KeClearEvent ( &event );
KeInitializeEvent ( &event, NotificationEvent, FALSE );
Irp = IoBuildDeviceIoControlRequest ( IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME,
Device,
NULL, 0,
NULL, 0,
TRUE,
&event,
&iostatus );
if ( !Irp )
{
DebugPrint(“Unable to allocate IRP for getting controller name”);
KeClearEvent ( &event );
return;
}
/*
IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME
Input
Parameters.Others.Argument1 should be a pointer to a USB_HUB_NAME structure that will be filled in with the name of the host controller.
Parameters.Others.Argument2 should be a ULONG specifying the length of the buffer (in bytes) in Parameters.Others.Argument1.
*/
// Set up the stack for the IRP
stack = IoGetNextIrpStackLocation ( Irp );
stack->Parameters.Others.Argument1 = pHostControllerName;
stack->Parameters.Others.Argument2 = (PVOID) &ulNewLength;
// Send it down and wait for a response
status = IoCallDriver ( Device, Irp );
if ( status == STATUS_PENDING )
{
DebugPrint(“Waiting”);
KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
DebugPrint(“Done Wait!”);
status = iostatus.Status;
}
if ( !NT_SUCCESS(status) )
{
DebugPrint(“Unable to determine controller name (%s)”, NTStatusToString(status) );
// return;
}
KeClearEvent ( &event );
DebugPrint(“HostCtrlr Name: %s (%d chars)!”, pHostControllerName->HubName, pHostControllerName->ActualLength );
return;
}
Regards,
Rik van der Heijden