- Shut up warnings
- Fix whitespace issues

svn path=/trunk/; revision=56469
This commit is contained in:
Thomas Faber 2012-05-01 16:53:02 +00:00
parent ae1974497f
commit 4c2fd89c46
5 changed files with 484 additions and 484 deletions

View file

@ -22,13 +22,13 @@
// Dispatch routine for CreateHandle
NTSTATUS FreeBT_DispatchCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
ULONG i;
//ULONG i;
NTSTATUS ntStatus;
PFILE_OBJECT fileObject;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
PFREEBT_PIPE_CONTEXT pipeContext;
PUSBD_INTERFACE_INFORMATION interface;
//PFREEBT_PIPE_CONTEXT pipeContext;
PUSBD_INTERFACE_INFORMATION interface;
PAGED_CODE();
@ -71,12 +71,12 @@ NTSTATUS FreeBT_DispatchCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
if (deviceExtension->OpenHandleCount>0)
{
ntStatus = STATUS_ACCESS_VIOLATION;
goto FreeBT_DispatchCreate_Exit;
if (deviceExtension->OpenHandleCount>0)
{
ntStatus = STATUS_ACCESS_VIOLATION;
goto FreeBT_DispatchCreate_Exit;
}
}
// opening a device as opposed to pipe.
ntStatus = STATUS_SUCCESS;
@ -105,15 +105,15 @@ NTSTATUS FreeBT_DispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
PFILE_OBJECT fileObject;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
PFREEBT_PIPE_CONTEXT pipeContext;
PUSBD_PIPE_INFORMATION pipeInformation;
//PFREEBT_PIPE_CONTEXT pipeContext;
//PUSBD_PIPE_INFORMATION pipeInformation;
PAGED_CODE();
irpStack = IoGetCurrentIrpStackLocation(Irp);
fileObject = irpStack->FileObject;
pipeContext = NULL;
pipeInformation = NULL;
//pipeContext = NULL;
//pipeInformation = NULL;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
FreeBT_DbgPrint(3, ("FreeBT_DispatchClose: Entered\n"));
@ -134,16 +134,16 @@ NTSTATUS FreeBT_DispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// Called when a HCI Send on the control pipe completes
NTSTATUS FreeBT_HCISendCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
ULONG stageLength;
//ULONG stageLength;
NTSTATUS ntStatus;
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_HCISendCompletion, status=0x%08X\n", Irp->IoStatus.Status));
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);
ExFreePool(Context);
FreeBT_IoDecrement(DeviceObject->DeviceExtension);
FreeBT_IoDecrement(DeviceObject->DeviceExtension);
ntStatus = Irp->IoStatus.Status;
Irp->IoStatus.Information = 0;
@ -155,79 +155,79 @@ NTSTATUS FreeBT_HCISendCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, I
// HCI Commands are sent on the (default) control pipe
NTSTATUS FreeBT_SendHCICommand(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID IoBuffer, IN ULONG InputBufferLength)
{
PDEVICE_EXTENSION deviceExtension;
ULONG urbFlags;
ULONG stageLength;
PVOID pBuffer;
PURB urb;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
//PFBT_HCI_CMD_HEADER pHCICommand;
//LARGE_INTEGER delay;
PDEVICE_EXTENSION deviceExtension;
//ULONG urbFlags;
//ULONG stageLength;
//PVOID pBuffer;
PURB urb;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
//PFBT_HCI_CMD_HEADER pHCICommand;
//LARGE_INTEGER delay;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
if (!deviceExtension)
{
ntStatus=STATUS_INVALID_PARAMETER;
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_SendHCICommand: Failed to get DeviceExtension\n"));
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return ntStatus;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
if (!deviceExtension)
{
ntStatus=STATUS_INVALID_PARAMETER;
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_SendHCICommand: Failed to get DeviceExtension\n"));
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return ntStatus;
}
}
// The user is doing a reset, reset all the pipes as well, so that any
// old events or data are removed
/*pHCICommand=(PFBT_HCI_CMD_HEADER)IoBuffer;
if (pHCICommand->OpCode==FBT_HCI_CMD_RESET)
{
FreeBT_ResetPipe(DeviceObject, deviceExtension->EventPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->DataInPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->DataOutPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->AudioInPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->AudioOutPipe.PipeHandle);
// The user is doing a reset, reset all the pipes as well, so that any
// old events or data are removed
/*pHCICommand=(PFBT_HCI_CMD_HEADER)IoBuffer;
if (pHCICommand->OpCode==FBT_HCI_CMD_RESET)
{
FreeBT_ResetPipe(DeviceObject, deviceExtension->EventPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->DataInPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->DataOutPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->AudioInPipe.PipeHandle);
FreeBT_ResetPipe(DeviceObject, deviceExtension->AudioOutPipe.PipeHandle);
// Wait a second for the device to recover
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_SendHCICommand: Sleeping\n"));
delay.QuadPart = -10000 * 5000; // 5s
// Wait a second for the device to recover
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_SendHCICommand: Sleeping\n"));
delay.QuadPart = -10000 * 5000; // 5s
KeWaitForSingleObject(&deviceExtension->DelayEvent,
Executive,
UserMode,
FALSE,
&delay);
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_SendHCICommand: Finished sleeping\n"));
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_SendHCICommand: Finished sleeping\n"));
}*/
}*/
// Create the URB
// Create the URB
urb = (PURB)ExAllocatePool(NonPagedPool, sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST));
if(urb == NULL)
{
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_SendHCICommand: Failed to alloc mem for urb\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return ntStatus;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return ntStatus;
}
UsbBuildVendorRequest(
urb,
URB_FUNCTION_CLASS_DEVICE, // This works, for CSR and Silicon Wave
sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST),
0,
0,
0,
0,
0,
IoBuffer,
NULL,
InputBufferLength,
NULL);
UsbBuildVendorRequest(
urb,
URB_FUNCTION_CLASS_DEVICE, // This works, for CSR and Silicon Wave
sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST),
0,
0,
0,
0,
0,
IoBuffer,
NULL,
InputBufferLength,
NULL);
// use the original irp as an internal device control irp
nextStack = IoGetNextIrpStackLocation(Irp);
@ -236,41 +236,41 @@ NTSTATUS FreeBT_SendHCICommand(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN P
nextStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
IoSetCompletionRoutine(
Irp,
(PIO_COMPLETION_ROUTINE)FreeBT_HCISendCompletion,
urb,
TRUE,
TRUE,
TRUE);
Irp,
(PIO_COMPLETION_ROUTINE)FreeBT_HCISendCompletion,
urb,
TRUE,
TRUE,
TRUE);
// We return STATUS_PENDING; call IoMarkIrpPending.
IoMarkIrpPending(Irp);
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand::"));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand::"));
FreeBT_IoIncrement(deviceExtension);
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand: Sending IRP %X to underlying driver\n", Irp));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand: Sending IRP %X to underlying driver\n", Irp));
ntStatus=IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(!NT_SUCCESS(ntStatus))
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand: IoCallDriver fails with status %X\n", ntStatus));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand::"));
FreeBT_IoDecrement(deviceExtension);
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand::"));
FreeBT_IoDecrement(deviceExtension);
// If the device was surprise removed out, the pipeInformation field is invalid.
// similarly if the request was cancelled, then we need not reset the device.
if((ntStatus != STATUS_CANCELLED) && (ntStatus != STATUS_DEVICE_NOT_CONNECTED))
ntStatus = FreeBT_ResetDevice(DeviceObject);
ntStatus = FreeBT_ResetDevice(DeviceObject);
else
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SendHCICommand: ntStatus is STATUS_CANCELLED or STATUS_DEVICE_NOT_CONNECTED\n"));
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return ntStatus;
return ntStatus;
}
@ -283,24 +283,24 @@ NTSTATUS FreeBT_SendHCICommand(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN P
// Called when a HCI Get on the event pipe completes
NTSTATUS FreeBT_HCIEventCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
ULONG stageLength;
//ULONG stageLength;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
PURB urb;
PURB urb;
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_HCIEventCompletion, status=0x%08X\n", Irp->IoStatus.Status));
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);
// initialize variables
urb=(PURB)Context;
urb=(PURB)Context;
ntStatus = Irp->IoStatus.Status;
Irp->IoStatus.Information = urb->UrbBulkOrInterruptTransfer.TransferBufferLength;
nextStack = IoGetNextIrpStackLocation(Irp);
ExFreePool(Context);
FreeBT_IoDecrement(DeviceObject->DeviceExtension);
FreeBT_IoDecrement(DeviceObject->DeviceExtension);
return ntStatus;
@ -309,10 +309,10 @@ NTSTATUS FreeBT_HCIEventCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
// Called from the DeviceIOControl handler to wait for an event on the interrupt pipe
NTSTATUS FreeBT_GetHCIEvent(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID IoBuffer, IN ULONG InputBufferLength)
{
PDEVICE_EXTENSION deviceExtension;
PURB urb;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
PDEVICE_EXTENSION deviceExtension;
PURB urb;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetHCIEvent: Entered\n"));
@ -346,17 +346,17 @@ NTSTATUS FreeBT_GetHCIEvent(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOI
nextStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
IoSetCompletionRoutine(
Irp,
(PIO_COMPLETION_ROUTINE)FreeBT_HCIEventCompletion,
urb,
TRUE,
TRUE,
TRUE);
Irp,
(PIO_COMPLETION_ROUTINE)FreeBT_HCIEventCompletion,
urb,
TRUE,
TRUE,
TRUE);
// We return STATUS_PENDING; call IoMarkIrpPending.
IoMarkIrpPending(Irp);
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetHCIEvent::"));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetHCIEvent::"));
FreeBT_IoIncrement(deviceExtension);
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
@ -364,8 +364,8 @@ NTSTATUS FreeBT_GetHCIEvent(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOI
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetHCIEvent: IoCallDriver fails with status %X\n", ntStatus));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetHCIEvent::"));
FreeBT_IoDecrement(deviceExtension);
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetHCIEvent::"));
FreeBT_IoDecrement(deviceExtension);
// If the device was surprise removed out, the pipeInformation field is invalid.
// similarly if the request was cancelled, then we need not reset the pipe.
@ -432,17 +432,17 @@ NTSTATUS FreeBT_DispatchDevCtrl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
if (deviceExtension->DeviceState != Working)
{
FreeBT_DbgPrint(1, ("FBTUSB: Invalid device state\n"));
ntStatus = STATUS_INVALID_DEVICE_STATE;
goto FreeBT_DispatchDevCtrlExit;
ntStatus = STATUS_INVALID_DEVICE_STATE;
goto FreeBT_DispatchDevCtrlExit;
}
}
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchDevCtrl::"));
// Make sure that any selective suspend request has been completed.
if (deviceExtension->SSEnable)
{
FreeBT_DbgPrint(3, ("Waiting on the IdleReqPendEvent\n"));
FreeBT_DbgPrint(3, ("Waiting on the IdleReqPendEvent\n"));
KeWaitForSingleObject(&deviceExtension->NoIdleReqPendEvent,
Executive,
KernelMode,
@ -453,49 +453,49 @@ NTSTATUS FreeBT_DispatchDevCtrl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
switch(code)
{
case IOCTL_FREEBT_HCI_SEND_CMD:
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD received\n"));
if (inputBufferLength<FBT_HCI_CMD_MIN_SIZE)
{
ntStatus = STATUS_BUFFER_TOO_SMALL;
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD: Buffer too small\n"));
goto FreeBT_DispatchDevCtrlExit;
case IOCTL_FREEBT_HCI_SEND_CMD:
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD received\n"));
if (inputBufferLength<FBT_HCI_CMD_MIN_SIZE)
{
ntStatus = STATUS_BUFFER_TOO_SMALL;
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD: Buffer too small\n"));
goto FreeBT_DispatchDevCtrlExit;
}
}
if (inputBufferLength>FBT_HCI_CMD_MAX_SIZE)
{
ntStatus = STATUS_INVALID_BUFFER_SIZE;
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD: Buffer too long\n"));
goto FreeBT_DispatchDevCtrlExit;
if (inputBufferLength>FBT_HCI_CMD_MAX_SIZE)
{
ntStatus = STATUS_INVALID_BUFFER_SIZE;
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD: Buffer too long\n"));
goto FreeBT_DispatchDevCtrlExit;
}
}
return FreeBT_SendHCICommand(DeviceObject, Irp, ioBuffer, inputBufferLength);
break;
return FreeBT_SendHCICommand(DeviceObject, Irp, ioBuffer, inputBufferLength);
break;
case IOCTL_FREEBT_HCI_GET_EVENT:
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_GET_EVENT received\n"));
if (outputBufferLength<FBT_HCI_EVENT_MAX_SIZE)
{
ntStatus = STATUS_BUFFER_TOO_SMALL;
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_GET_EVENT: Buffer too small\n"));
goto FreeBT_DispatchDevCtrlExit;
case IOCTL_FREEBT_HCI_GET_EVENT:
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_GET_EVENT received\n"));
if (outputBufferLength<FBT_HCI_EVENT_MAX_SIZE)
{
ntStatus = STATUS_BUFFER_TOO_SMALL;
FreeBT_DbgPrint(3, ("FBTUSB: IOCTL_FREEBT_HCI_GET_EVENT: Buffer too small\n"));
goto FreeBT_DispatchDevCtrlExit;
}
}
return FreeBT_GetHCIEvent(DeviceObject, Irp, ioBuffer, outputBufferLength);
break;
return FreeBT_GetHCIEvent(DeviceObject, Irp, ioBuffer, outputBufferLength);
break;
default:
FreeBT_DbgPrint(3, ("FBTUSB: Invalid IOCTL 0x%08x received\n", code));
FreeBT_DbgPrint(3, ("FBTUSB: Invalid IOCTL 0x%08x received\n", code));
ntStatus = STATUS_INVALID_DEVICE_REQUEST;
break;
}
FreeBT_DispatchDevCtrlExit:
Irp->IoStatus.Information = 0;
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = ntStatus;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
@ -1125,13 +1125,13 @@ VOID CancelSelectSuspend(IN PDEVICE_EXTENSION DeviceExtension)
{
FreeBT_DbgPrint(3, ("IoCancelIrp returns TRUE\n"));
}
}
else
{
FreeBT_DbgPrint(3, ("IoCancelIrp returns FALSE\n"));
}
}
// ....we decrement the FreeIdleIrpCount from 2 to 1.
// if completion routine runs ahead of us, then this routine
@ -1167,7 +1167,7 @@ VOID PoIrpCompletionFunc(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction,
if(irpContext)
{
KeSetEvent(irpContext->Event, 0, FALSE);
FreeBT_IoDecrement(irpContext->DeviceExtension);
FreeBT_IoDecrement(irpContext->DeviceExtension);
ExFreePool(irpContext);
}

View file

@ -25,7 +25,7 @@ NTSTATUS FreeBT_DispatchPnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PIO_STACK_LOCATION irpStack;
PDEVICE_EXTENSION deviceExtension;
KEVENT startDeviceEvent;
//KEVENT startDeviceEvent;
NTSTATUS ntStatus;
irpStack = IoGetCurrentIrpStackLocation(Irp);
@ -33,7 +33,7 @@ NTSTATUS FreeBT_DispatchPnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// since the device is removed, fail the Irp.
if (Removed == deviceExtension->DeviceState)
{
{
ntStatus = STATUS_DELETE_PENDING;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
@ -45,15 +45,15 @@ NTSTATUS FreeBT_DispatchPnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchPnP::"));
FreeBT_IoIncrement(deviceExtension);
if (irpStack->MinorFunction == IRP_MN_START_DEVICE)
{
{
ASSERT(deviceExtension->IdleReqPend == 0);
}
else
{
{
if (deviceExtension->SSEnable)
{
{
CancelSelectSuspend(deviceExtension);
}
@ -64,7 +64,7 @@ NTSTATUS FreeBT_DispatchPnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchPnP::"));
FreeBT_DbgPrint(2, (PnPMinorFunctionString(irpStack->MinorFunction)));
switch (irpStack->MinorFunction)
{
{
case IRP_MN_START_DEVICE:
ntStatus = HandleStartDevice(DeviceObject, Irp);
break;
@ -73,7 +73,7 @@ NTSTATUS FreeBT_DispatchPnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// if we cannot stop the device, we fail the query stop irp
ntStatus = CanStopDevice(DeviceObject, Irp);
if(NT_SUCCESS(ntStatus))
{
{
ntStatus = HandleQueryStopDevice(DeviceObject, Irp);
return ntStatus;
@ -168,14 +168,14 @@ NTSTATUS HandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if (ntStatus == STATUS_PENDING)
{
{
KeWaitForSingleObject(&startDeviceEvent, Executive, KernelMode, FALSE, NULL);
ntStatus = Irp->IoStatus.Status;
}
if (!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleStartDevice: Lower drivers failed this Irp (0x%08x)\n", ntStatus));
return ntStatus;
@ -185,7 +185,7 @@ NTSTATUS HandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// and select the interface descriptors
ntStatus = ReadandSelectDescriptors(DeviceObject);
if (!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleStartDevice: ReadandSelectDescriptors failed (0x%08x)\n", ntStatus));
return ntStatus;
@ -195,7 +195,7 @@ NTSTATUS HandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// handles to the device
ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName, TRUE);
if (!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleStartDevice: IoSetDeviceInterfaceState failed (0x%08x)\n", ntStatus));
return ntStatus;
@ -213,19 +213,19 @@ NTSTATUS HandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
deviceExtension->WaitWakeIrp = NULL;
if (deviceExtension->WaitWakeEnable)
{
{
IssueWaitWake(deviceExtension);
}
ProcessQueuedRequests(deviceExtension);
if (WinXpOrBetter == deviceExtension->WdmVersion)
{
{
deviceExtension->SSEnable = deviceExtension->SSRegistryEnable;
// set timer.for selective suspend requests
if (deviceExtension->SSEnable)
{
{
dueTime.QuadPart = -10000 * IDLE_INTERVAL; // 5000 ms
KeSetTimerEx(&deviceExtension->Timer, dueTime, IDLE_INTERVAL, &deviceExtension->DeferredProcCall);
deviceExtension->FreeIdleIrpCount = 0;
@ -254,11 +254,11 @@ NTSTATUS ReadandSelectDescriptors(IN PDEVICE_OBJECT DeviceObject)
// 1. Read the device descriptor
urb = (PURB) ExAllocatePool(NonPagedPool, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
if(urb)
{
{
siz = sizeof(USB_DEVICE_DESCRIPTOR);
deviceDescriptor = (PUSB_DEVICE_DESCRIPTOR) ExAllocatePool(NonPagedPool, siz);
if (deviceDescriptor)
{
{
UsbBuildGetDescriptorRequest(
urb,
(USHORT) sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
@ -272,7 +272,7 @@ NTSTATUS ReadandSelectDescriptors(IN PDEVICE_OBJECT DeviceObject)
ntStatus = CallUSBD(DeviceObject, urb);
if (NT_SUCCESS(ntStatus))
{
{
ASSERT(deviceDescriptor->bNumConfigurations);
ntStatus = ConfigureDevice(DeviceObject);
@ -284,7 +284,7 @@ NTSTATUS ReadandSelectDescriptors(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: ReadandSelectDescriptors: Failed to allocate memory for deviceDescriptor"));
ExFreePool(urb);
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
@ -294,7 +294,7 @@ NTSTATUS ReadandSelectDescriptors(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: ReadandSelectDescriptors: Failed to allocate memory for urb"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
@ -323,12 +323,12 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
// 2. Read the CD with all embedded interface and endpoint descriptors
urb = (PURB) ExAllocatePool(NonPagedPool, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
if (urb)
{
{
siz = sizeof(USB_CONFIGURATION_DESCRIPTOR);
configurationDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR) ExAllocatePool(NonPagedPool, siz);
if(configurationDescriptor)
{
{
UsbBuildGetDescriptorRequest(
urb,
(USHORT) sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
@ -342,7 +342,7 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
ntStatus = CallUSBD(DeviceObject, urb);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: UsbBuildGetDescriptorRequest failed\n"));
goto ConfigureDevice_Exit;
@ -351,7 +351,7 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: Failed to allocate mem for config Descriptor\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto ConfigureDevice_Exit;
@ -363,7 +363,7 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
configurationDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR) ExAllocatePool(NonPagedPool, siz);
if (configurationDescriptor)
{
{
UsbBuildGetDescriptorRequest(
urb,
(USHORT)sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
@ -377,7 +377,7 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
ntStatus = CallUSBD(DeviceObject, urb);
if (!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1,("FBTUSB: ConfigureDevice: Failed to read configuration descriptor"));
goto ConfigureDevice_Exit;
@ -386,7 +386,7 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: Failed to alloc mem for config Descriptor\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto ConfigureDevice_Exit;
@ -396,7 +396,7 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: Failed to allocate memory for urb\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto ConfigureDevice_Exit;
@ -404,7 +404,7 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
}
if (configurationDescriptor)
{
{
// save a copy of configurationDescriptor in deviceExtension
// remember to free it later.
deviceExtension->UsbConfigurationDescriptor = configurationDescriptor;
@ -427,14 +427,14 @@ NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
deviceExtension->UsbConfigurationDescriptor = NULL;
}
ConfigureDevice_Exit:
if (urb)
{
{
ExFreePool(urb);
}
@ -448,7 +448,7 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
LONG numberOfInterfaces, interfaceNumber, interfaceindex;
ULONG i;
PURB urb;
PUCHAR pInf;
//PUCHAR pInf;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
PUSB_INTERFACE_DESCRIPTOR interfaceDescriptor;
@ -465,10 +465,10 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
// Parse the configuration descriptor for the interface;
tmp = interfaceList = (PUSBD_INTERFACE_LIST_ENTRY)
ExAllocatePool(NonPagedPool, sizeof(USBD_INTERFACE_LIST_ENTRY) * (numberOfInterfaces + 1));
ExAllocatePool(NonPagedPool, sizeof(USBD_INTERFACE_LIST_ENTRY) * (numberOfInterfaces + 1));
if (!tmp)
{
{
FreeBT_DbgPrint(1, ("FBTUSB: SelectInterfaces: Failed to allocate mem for interfaceList\n"));
return STATUS_INSUFFICIENT_RESOURCES;
@ -476,11 +476,11 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
}
FreeBT_DbgPrint(3, ("FBTUSB: -------------\n"));
FreeBT_DbgPrint(3, ("FBTUSB: Number of interfaces %d\n", numberOfInterfaces));
FreeBT_DbgPrint(3, ("FBTUSB: -------------\n"));
FreeBT_DbgPrint(3, ("FBTUSB: Number of interfaces %d\n", numberOfInterfaces));
while (interfaceNumber < numberOfInterfaces)
{
{
interfaceDescriptor = USBD_ParseConfigurationDescriptorEx(
ConfigurationDescriptor,
ConfigurationDescriptor,
@ -488,7 +488,7 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
0, -1, -1, -1);
if (interfaceDescriptor)
{
{
interfaceList->InterfaceDescriptor = interfaceDescriptor;
interfaceList->Interface = NULL;
interfaceList++;
@ -505,10 +505,10 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
urb = USBD_CreateConfigurationRequestEx(ConfigurationDescriptor, tmp);
if (urb)
{
{
Interface = &urb->UrbSelectConfiguration.Interface;
for (i=0; i<Interface->NumberOfPipes; i++)
{
{
// perform pipe initialization here
// set the transfer size and any pipe flags we use
// USBD sets the rest of the Interface struct members
@ -518,17 +518,17 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
ntStatus = CallUSBD(DeviceObject, urb);
if (NT_SUCCESS(ntStatus))
{
{
// save a copy of interface information in the device extension.
deviceExtension->UsbInterface = (PUSBD_INTERFACE_INFORMATION) ExAllocatePool(NonPagedPool, Interface->Length);
if (deviceExtension->UsbInterface)
{
{
RtlCopyMemory(deviceExtension->UsbInterface, Interface, Interface->Length);
}
else
{
{
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
FreeBT_DbgPrint(1, ("FBTUSB: SelectInterfaces: Memory alloc for UsbInterface failed\n"));
@ -547,18 +547,18 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
Interface->SubClass,
Interface->Protocol));
if (Interface->Class==FREEBT_USB_STDCLASS && Interface->SubClass==FREEBT_USB_STDSUBCLASS &&
Interface->Protocol==FREEBT_USB_STDPROTOCOL)
{
FreeBT_DbgPrint(3, ("FBTUSB: This is a standard USB Bluetooth device\n"));
if (Interface->Class==FREEBT_USB_STDCLASS && Interface->SubClass==FREEBT_USB_STDSUBCLASS &&
Interface->Protocol==FREEBT_USB_STDPROTOCOL)
{
FreeBT_DbgPrint(3, ("FBTUSB: This is a standard USB Bluetooth device\n"));
}
}
else
{
FreeBT_DbgPrint(3, ("FBTUSB: WARNING: This device does not report itself as a standard USB Bluetooth device\n"));
else
{
FreeBT_DbgPrint(3, ("FBTUSB: WARNING: This device does not report itself as a standard USB Bluetooth device\n"));
}
}
// Initialize the PipeContext
// Dump the pipe info
@ -568,74 +568,74 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
sizeof(FREEBT_PIPE_CONTEXT));
if (!deviceExtension->PipeContext)
{
{
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
FreeBT_DbgPrint(1, ("FBTUSB: Memory alloc for UsbInterface failed\n"));
}
else
{
FreeBT_DbgPrint(3, ("FBTUSB: SelectInterfaces: Allocated PipeContext %p\n", deviceExtension->PipeContext));
for (i=0; i<Interface->NumberOfPipes; i++)
{
deviceExtension->PipeContext[i].PipeOpen = FALSE;
{
FreeBT_DbgPrint(3, ("FBTUSB: SelectInterfaces: Allocated PipeContext %p\n", deviceExtension->PipeContext));
for (i=0; i<Interface->NumberOfPipes; i++)
{
deviceExtension->PipeContext[i].PipeOpen = FALSE;
FreeBT_DbgPrint(3, ("FBTUSB: ---------\n"));
FreeBT_DbgPrint(3, ("FBTUSB: PipeType 0x%x\n", Interface->Pipes[i].PipeType));
FreeBT_DbgPrint(3, ("FBTUSB: EndpointAddress 0x%x\n", Interface->Pipes[i].EndpointAddress));
FreeBT_DbgPrint(3, ("FBTUSB: MaxPacketSize 0x%x\n", Interface->Pipes[i].MaximumPacketSize));
FreeBT_DbgPrint(3, ("FBTUSB: Interval 0x%x\n", Interface->Pipes[i].Interval));
FreeBT_DbgPrint(3, ("FBTUSB: Handle 0x%x\n", Interface->Pipes[i].PipeHandle));
FreeBT_DbgPrint(3, ("FBTUSB: MaximumTransferSize 0x%x\n", Interface->Pipes[i].MaximumTransferSize));
FreeBT_DbgPrint(3, ("FBTUSB: ---------\n"));
FreeBT_DbgPrint(3, ("FBTUSB: PipeType 0x%x\n", Interface->Pipes[i].PipeType));
FreeBT_DbgPrint(3, ("FBTUSB: EndpointAddress 0x%x\n", Interface->Pipes[i].EndpointAddress));
FreeBT_DbgPrint(3, ("FBTUSB: MaxPacketSize 0x%x\n", Interface->Pipes[i].MaximumPacketSize));
FreeBT_DbgPrint(3, ("FBTUSB: Interval 0x%x\n", Interface->Pipes[i].Interval));
FreeBT_DbgPrint(3, ("FBTUSB: Handle 0x%x\n", Interface->Pipes[i].PipeHandle));
FreeBT_DbgPrint(3, ("FBTUSB: MaximumTransferSize 0x%x\n", Interface->Pipes[i].MaximumTransferSize));
// Log the pipes
// Note the HCI Command endpoint won't appear here, because the Default Control Pipe
// is used for this. The Default Control Pipe is always present at EndPointAddress 0x0
switch (Interface->Pipes[i].EndpointAddress)
{
case FREEBT_STDENDPOINT_HCIEVENT:
deviceExtension->PipeContext[i].PipeType=HciEventPipe;
deviceExtension->EventPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: HCI Event Endpoint\n"));
break;
// Log the pipes
// Note the HCI Command endpoint won't appear here, because the Default Control Pipe
// is used for this. The Default Control Pipe is always present at EndPointAddress 0x0
switch (Interface->Pipes[i].EndpointAddress)
{
case FREEBT_STDENDPOINT_HCIEVENT:
deviceExtension->PipeContext[i].PipeType=HciEventPipe;
deviceExtension->EventPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: HCI Event Endpoint\n"));
break;
case FREEBT_STDENDPOINT_ACLIN:
deviceExtension->PipeContext[i].PipeType=AclDataIn;
deviceExtension->DataInPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data In Endpoint\n"));
break;
case FREEBT_STDENDPOINT_ACLIN:
deviceExtension->PipeContext[i].PipeType=AclDataIn;
deviceExtension->DataInPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data In Endpoint\n"));
break;
case FREEBT_STDENDPOINT_ACLOUT:
deviceExtension->PipeContext[i].PipeType=AclDataOut;
deviceExtension->DataOutPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data Out Endpoint\n"));
break;
case FREEBT_STDENDPOINT_ACLOUT:
deviceExtension->PipeContext[i].PipeType=AclDataOut;
deviceExtension->DataOutPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data Out Endpoint\n"));
break;
case FREEBT_STDENDPOINT_AUDIOIN:
deviceExtension->PipeContext[i].PipeType=SCODataIn;
deviceExtension->AudioInPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data Out Endpoint\n"));
break;
case FREEBT_STDENDPOINT_AUDIOIN:
deviceExtension->PipeContext[i].PipeType=SCODataIn;
deviceExtension->AudioInPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data Out Endpoint\n"));
break;
case FREEBT_STDENDPOINT_AUDIOOUT:
deviceExtension->PipeContext[i].PipeType=SCODataOut;
deviceExtension->AudioOutPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data Out Endpoint\n"));
break;
case FREEBT_STDENDPOINT_AUDIOOUT:
deviceExtension->PipeContext[i].PipeType=SCODataOut;
deviceExtension->AudioOutPipe=Interface->Pipes[i];
FreeBT_DbgPrint(3, ("FBTUSB: ACL Data Out Endpoint\n"));
break;
}
}
}
}
}
}
FreeBT_DbgPrint(3, ("FBTUSB: ---------\n"));
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: SelectInterfaces: Failed to select an interface\n"));
}
@ -643,20 +643,20 @@ NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: SelectInterfaces: USBD_CreateConfigurationRequestEx failed\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
if (tmp)
{
{
ExFreePool(tmp);
}
if (urb)
{
{
ExFreePool(urb);
}
@ -674,11 +674,11 @@ NTSTATUS DeconfigureDevice(IN PDEVICE_OBJECT DeviceObject)
siz = sizeof(struct _URB_SELECT_CONFIGURATION);
urb = (PURB) ExAllocatePool(NonPagedPool, siz);
if (urb)
{
{
UsbBuildSelectConfigurationRequest(urb, (USHORT)siz, NULL);
ntStatus = CallUSBD(DeviceObject, urb);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(3, ("FBTUSB: DeconfigureDevice: Failed to deconfigure device\n"));
}
@ -688,7 +688,7 @@ NTSTATUS DeconfigureDevice(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: DeconfigureDevice: Failed to allocate urb\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
@ -722,7 +722,7 @@ NTSTATUS CallUSBD(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
&ioStatus);
if (!irp)
{
{
FreeBT_DbgPrint(1, ("FBTUSB: CallUSBD: IoBuildDeviceIoControlRequest failed\n"));
return STATUS_INSUFFICIENT_RESOURCES;
@ -737,7 +737,7 @@ NTSTATUS CallUSBD(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, irp);
if (ntStatus == STATUS_PENDING)
{
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
@ -808,7 +808,7 @@ NTSTATUS HandleCancelStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// above us fails a query-stop and passes down the subsequent
// cancel-stop.
if(PendingStop == deviceExtension->DeviceState)
{
{
KeInitializeEvent(&event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(Irp);
@ -821,14 +821,14 @@ NTSTATUS HandleCancelStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(ntStatus == STATUS_PENDING)
{
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
ntStatus = Irp->IoStatus.Status;
}
if(NT_SUCCESS(ntStatus))
{
{
KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
RESTORE_PREVIOUS_PNP_STATE(deviceExtension);
@ -844,7 +844,7 @@ NTSTATUS HandleCancelStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
else
{
{
// spurious Irp
ntStatus = STATUS_SUCCESS;
@ -866,9 +866,9 @@ NTSTATUS HandleStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
if(WinXpOrBetter == deviceExtension->WdmVersion)
{
{
if(deviceExtension->SSEnable)
{
{
// Cancel the timer so that the DPCs are no longer fired.
// Thus, we are making judicious usage of our resources.
// we do not need DPCs because the device is stopping.
@ -898,7 +898,7 @@ NTSTATUS HandleStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// the driver must not send any more Irps down that touch
// the device until another Start has occurred.
if (deviceExtension->WaitWakeEnable)
{
{
CancelWaitWake(deviceExtension);
}
@ -988,7 +988,7 @@ NTSTATUS HandleCancelRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// someone above us fails a query-remove and passes down the
// subsequent cancel-remove.
if(PendingRemove == deviceExtension->DeviceState)
{
{
KeInitializeEvent(&event, NotificationEvent, FALSE);
@ -1002,14 +1002,14 @@ NTSTATUS HandleCancelRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(ntStatus == STATUS_PENDING)
{
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
ntStatus = Irp->IoStatus.Status;
}
if (NT_SUCCESS(ntStatus))
{
{
KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
deviceExtension->QueueState = AllowRequests;
@ -1026,8 +1026,8 @@ NTSTATUS HandleCancelRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
else
{
// spurious cancel-remove
{
// spurious cancel-remove
ntStatus = STATUS_SUCCESS;
}
@ -1053,16 +1053,16 @@ NTSTATUS HandleSurpriseRemoval(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// 2. return device and memory resources
// 3. disable interfaces
if(deviceExtension->WaitWakeEnable)
{
{
CancelWaitWake(deviceExtension);
}
if (WinXpOrBetter == deviceExtension->WdmVersion)
{
{
if (deviceExtension->SSEnable)
{
{
// Cancel the timer so that the DPCs are no longer fired.
// we do not need DPCs because the device has been surprise
// removed
@ -1090,7 +1090,7 @@ NTSTATUS HandleSurpriseRemoval(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName, FALSE);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleSurpriseRemoval: IoSetDeviceInterfaceState::disable:failed\n"));
}
@ -1112,7 +1112,7 @@ NTSTATUS HandleSurpriseRemoval(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
NTSTATUS HandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
KEVENT event;
//KEVENT event;
ULONG requestCount;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
@ -1126,7 +1126,7 @@ NTSTATUS HandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// (If we wanted to express an interest in preventing this removal,
// we should have failed the query remove IRP).
if(SurpriseRemoved != deviceExtension->DeviceState)
{
{
// we are here after QUERY_REMOVE
KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
@ -1134,15 +1134,15 @@ NTSTATUS HandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
if(deviceExtension->WaitWakeEnable)
{
{
CancelWaitWake(deviceExtension);
}
if(WinXpOrBetter == deviceExtension->WdmVersion)
{
{
if (deviceExtension->SSEnable)
{
{
// Cancel the timer so that the DPCs are no longer fired.
// we do not need DPCs because the device has been removed
KeCancelTimer(&deviceExtension->Timer);
@ -1164,7 +1164,7 @@ NTSTATUS HandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName, FALSE);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleRemoveDevice: IoSetDeviceInterfaceState::disable:failed\n"));
}
@ -1231,7 +1231,7 @@ NTSTATUS HandleQueryCapabilities(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
pdc = irpStack->Parameters.DeviceCapabilities.Capabilities;
if(pdc->Version < 1 || pdc->Size < sizeof(DEVICE_CAPABILITIES))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleQueryCapabilities::request failed\n"));
ntStatus = STATUS_UNSUCCESSFUL;
@ -1254,7 +1254,7 @@ NTSTATUS HandleQueryCapabilities(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
TRUE);
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(ntStatus == STATUS_PENDING)
{
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
ntStatus = Irp->IoStatus.Status;
@ -1263,12 +1263,12 @@ NTSTATUS HandleQueryCapabilities(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// initialize PowerDownLevel to disabled
deviceExtension->PowerDownLevel = PowerDeviceUnspecified;
if(NT_SUCCESS(ntStatus))
{
{
deviceExtension->DeviceCapabilities = *pdc;
for(i = PowerSystemSleeping1; i <= PowerSystemSleeping3; i++)
{
{
if(deviceExtension->DeviceCapabilities.DeviceState[i] < PowerDeviceD3)
{
{
deviceExtension->PowerDownLevel = deviceExtension->DeviceCapabilities.DeviceState[i];
}
@ -1283,8 +1283,8 @@ NTSTATUS HandleQueryCapabilities(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
if(deviceExtension->PowerDownLevel == PowerDeviceUnspecified ||
deviceExtension->PowerDownLevel <= PowerDeviceD0)
{
deviceExtension->PowerDownLevel <= PowerDeviceD0)
{
deviceExtension->PowerDownLevel = PowerDeviceD2;
}
@ -1317,19 +1317,19 @@ VOID DpcRoutine(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1
KeClearEvent(&deviceExtension->NoDpcWorkItemPendingEvent);
if(CanDeviceSuspend(deviceExtension))
{
{
FreeBT_DbgPrint(3, ("FBTUSB: DpcRoutine: Device is Idle\n"));
item = IoAllocateWorkItem(deviceObject);
if (item)
{
{
IoQueueWorkItem(item, IdleRequestWorkerRoutine, DelayedWorkQueue, item);
ntStatus = STATUS_PENDING;
}
else
{
{
FreeBT_DbgPrint(3, ("FBTUSB: DpcRoutine: Cannot alloc memory for work item\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
KeSetEvent(&deviceExtension->NoDpcWorkItemPendingEvent, IO_NO_INCREMENT, FALSE);
@ -1339,7 +1339,7 @@ VOID DpcRoutine(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1
}
else
{
{
FreeBT_DbgPrint(3, ("FBTUSB: DpcRoutine: Idle event not signaled\n"));
KeSetEvent(&deviceExtension->NoDpcWorkItemPendingEvent, IO_NO_INCREMENT, FALSE);
@ -1351,7 +1351,7 @@ VOID DpcRoutine(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1
VOID IdleRequestWorkerRoutine(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
{
PIRP irp;
//PIRP irp;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
PIO_WORKITEM workItem;
@ -1362,11 +1362,11 @@ VOID IdleRequestWorkerRoutine(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
workItem = (PIO_WORKITEM) Context;
if(CanDeviceSuspend(deviceExtension))
{
{
FreeBT_DbgPrint(3, ("FBTUSB: IdleRequestWorkerRoutine: Device is idle\n"));
ntStatus = SubmitIdleRequestIrp(deviceExtension);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: IdleRequestWorkerRoutine: SubmitIdleRequestIrp failed\n"));
}
@ -1374,7 +1374,7 @@ VOID IdleRequestWorkerRoutine(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
}
else
{
{
FreeBT_DbgPrint(3, ("FBTUSB: IdleRequestWorkerRoutine: Device is not idle\n"));
}
@ -1427,10 +1427,10 @@ Return Value:
// 3a. if the device is active, send them down
// 3b. else complete with STATUS_DELETE_PENDING
while(1)
{
{
KeAcquireSpinLock(&DeviceExtension->QueueLock, &oldIrql);
if(IsListEmpty(&DeviceExtension->NewRequestsQueue))
{
{
KeReleaseSpinLock(&DeviceExtension->QueueLock, oldIrql);
break;
@ -1443,9 +1443,9 @@ Return Value:
// check if its already cancelled
if (nextIrp->Cancel)
{
{
if(cancelRoutine)
{
{
// the cancel routine for this IRP hasnt been called yet
// so queue the IRP in the cancelledIrp list and complete
// after releasing the lock
@ -1454,8 +1454,8 @@ Return Value:
}
else
{
// the cancel routine has run
{
// the cancel routine has run
// it must be waiting to hold the queue lock
// so initialize the IRPs listEntry
InitializeListHead(listEntry);
@ -1467,10 +1467,10 @@ Return Value:
}
else
{
{
KeReleaseSpinLock(&DeviceExtension->QueueLock, oldIrql);
if(FailRequests == DeviceExtension->QueueState)
{
{
nextIrp->IoStatus.Information = 0;
nextIrp->IoStatus.Status = STATUS_DELETE_PENDING;
IoCompleteRequest(nextIrp, IO_NO_INCREMENT);
@ -1478,8 +1478,8 @@ Return Value:
}
else
{
PIO_STACK_LOCATION irpStack;
{
//PIO_STACK_LOCATION irpStack;
FreeBT_DbgPrint(3, ("FBTUSB: ProcessQueuedRequests::"));
FreeBT_IoIncrement(DeviceExtension);
@ -1497,7 +1497,7 @@ Return Value:
}
while(!IsListEmpty(&cancelledIrpList))
{
{
PLIST_ENTRY cancelEntry = RemoveHeadList(&cancelledIrpList);
cancelledIrp = CONTAINING_RECORD(cancelEntry, IRP, Tail.Overlay.ListEntry);
@ -1547,14 +1547,14 @@ NTSTATUS FreeBT_GetRegistryDword(IN PWCHAR RegPath, IN PWCHAR ValueName, IN OUT
NULL);
if (NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetRegistryDword: Success, Value = %X\n", *Value));
return STATUS_SUCCESS;
}
else
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetRegistryDword: Failed\n"));
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_GetRegistryDword: Failed\n"));
*Value = 0;
return STATUS_UNSUCCESSFUL;
@ -1573,7 +1573,7 @@ NTSTATUS FreeBT_DispatchClean(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
PIRP pendingIrp;
PIO_STACK_LOCATION pendingIrpStack,
irpStack;
NTSTATUS ntStatus;
//NTSTATUS ntStatus;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
irpStack = IoGetCurrentIrpStackLocation(Irp);
@ -1588,21 +1588,21 @@ NTSTATUS FreeBT_DispatchClean(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
for(thisEntry = listHead->Flink, nextEntry = thisEntry->Flink;
thisEntry != listHead;
thisEntry = nextEntry, nextEntry = thisEntry->Flink)
{
{
pendingIrp = CONTAINING_RECORD(thisEntry, IRP, Tail.Overlay.ListEntry);
pendingIrpStack = IoGetCurrentIrpStackLocation(pendingIrp);
if (irpStack->FileObject == pendingIrpStack->FileObject)
{
{
RemoveEntryList(thisEntry);
if (NULL == IoSetCancelRoutine(pendingIrp, NULL))
{
{
InitializeListHead(thisEntry);
}
else
{
{
InsertTailList(&cleanupList, thisEntry);
}
@ -1614,7 +1614,7 @@ NTSTATUS FreeBT_DispatchClean(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
KeReleaseSpinLock(&deviceExtension->QueueLock, oldIrql);
while(!IsListEmpty(&cleanupList))
{
{
thisEntry = RemoveHeadList(&cleanupList);
pendingIrp = CONTAINING_RECORD(thisEntry, IRP, Tail.Overlay.ListEntry);
@ -1644,7 +1644,7 @@ BOOLEAN CanDeviceSuspend(IN PDEVICE_EXTENSION DeviceExtension)
if ((DeviceExtension->OpenHandleCount == 0) && (DeviceExtension->OutStandingIO == 1))
return TRUE;
return FALSE;
return FALSE;
}
@ -1654,8 +1654,8 @@ NTSTATUS FreeBT_AbortPipes(IN PDEVICE_OBJECT DeviceObject)
ULONG i;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
PFREEBT_PIPE_CONTEXT pipeContext;
PUSBD_PIPE_INFORMATION pipeInformation;
PFREEBT_PIPE_CONTEXT pipeContext;
//PUSBD_PIPE_INFORMATION pipeInformation;
PUSBD_INTERFACE_INFORMATION interfaceInfo;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
@ -1668,14 +1668,14 @@ NTSTATUS FreeBT_AbortPipes(IN PDEVICE_OBJECT DeviceObject)
return STATUS_SUCCESS;
for(i=0; i<interfaceInfo->NumberOfPipes; i++)
{
{
if(pipeContext[i].PipeOpen)
{
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_AbortPipes: Aborting open pipe %d\n", i));
urb = (PURB) ExAllocatePool(NonPagedPool, sizeof(struct _URB_PIPE_REQUEST));
if (urb)
{
{
urb->UrbHeader.Length = sizeof(struct _URB_PIPE_REQUEST);
urb->UrbHeader.Function = URB_FUNCTION_ABORT_PIPE;
urb->UrbPipeRequest.PipeHandle = interfaceInfo->Pipes[i].PipeHandle;
@ -1687,7 +1687,7 @@ NTSTATUS FreeBT_AbortPipes(IN PDEVICE_OBJECT DeviceObject)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_AbortPipes: Failed to alloc memory for urb\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
return ntStatus;
@ -1731,7 +1731,7 @@ LONG FreeBT_IoIncrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
if (result == 2)
KeClearEvent(&DeviceExtension->StopEvent);
KeReleaseSpinLock(&DeviceExtension->IOCountLock, oldIrql);
KeReleaseSpinLock(&DeviceExtension->IOCountLock, oldIrql);
FreeBT_DbgPrint(3, ("FreeBT_IoIncrement::%d\n", result));
@ -1752,7 +1752,7 @@ LONG FreeBT_IoDecrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
KeSetEvent(&DeviceExtension->StopEvent, IO_NO_INCREMENT, FALSE);
if(result == 0)
{
{
ASSERT(Removed == DeviceExtension->DeviceState);
KeSetEvent(&DeviceExtension->RemoveEvent, IO_NO_INCREMENT, FALSE);
@ -1790,35 +1790,35 @@ NTSTATUS CanRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
NTSTATUS ReleaseMemory(IN PDEVICE_OBJECT DeviceObject)
{
// Disconnect from the interrupt and unmap any I/O ports
PDEVICE_EXTENSION deviceExtension;
UNICODE_STRING uniDeviceName;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
UNICODE_STRING uniDeviceName;
NTSTATUS ntStatus;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
if (deviceExtension->UsbConfigurationDescriptor)
{
FreeBT_DbgPrint(3, ("FBTUSB: ReleaseMemory: Freeing UsbConfigurationDescriptor\n"));
{
FreeBT_DbgPrint(3, ("FBTUSB: ReleaseMemory: Freeing UsbConfigurationDescriptor\n"));
ExFreePool(deviceExtension->UsbConfigurationDescriptor);
deviceExtension->UsbConfigurationDescriptor = NULL;
}
if(deviceExtension->UsbInterface)
{
FreeBT_DbgPrint(3, ("FBTUSB: ReleaseMemory: Freeing UsbInterface\n"));
{
FreeBT_DbgPrint(3, ("FBTUSB: ReleaseMemory: Freeing UsbInterface\n"));
ExFreePool(deviceExtension->UsbInterface);
deviceExtension->UsbInterface = NULL;
}
if(deviceExtension->PipeContext)
{
RtlInitUnicodeString(&uniDeviceName, deviceExtension->wszDosDeviceName);
ntStatus = IoDeleteSymbolicLink(&uniDeviceName);
if (!NT_SUCCESS(ntStatus))
FreeBT_DbgPrint(3, ("FBTUSB: Failed to delete symbolic link %ws\n", deviceExtension->wszDosDeviceName));
{
RtlInitUnicodeString(&uniDeviceName, deviceExtension->wszDosDeviceName);
ntStatus = IoDeleteSymbolicLink(&uniDeviceName);
if (!NT_SUCCESS(ntStatus))
FreeBT_DbgPrint(3, ("FBTUSB: Failed to delete symbolic link %ws\n", deviceExtension->wszDosDeviceName));
FreeBT_DbgPrint(3, ("FBTUSB: ReleaseMemory: Freeing PipeContext %p\n", deviceExtension->PipeContext));
FreeBT_DbgPrint(3, ("FBTUSB: ReleaseMemory: Freeing PipeContext %p\n", deviceExtension->PipeContext));
ExFreePool(deviceExtension->PipeContext);
deviceExtension->PipeContext = NULL;
@ -1831,7 +1831,7 @@ NTSTATUS ReleaseMemory(IN PDEVICE_OBJECT DeviceObject)
PCHAR PnPMinorFunctionString (UCHAR MinorFunction)
{
switch (MinorFunction)
{
{
case IRP_MN_START_DEVICE:
return "IRP_MN_START_DEVICE\n";

View file

@ -22,9 +22,9 @@
// Handle power events
NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
NTSTATUS ntStatus;
NTSTATUS ntStatus = STATUS_SUCCESS;
PIO_STACK_LOCATION irpStack;
PUNICODE_STRING tagString;
//PUNICODE_STRING tagString;
PDEVICE_EXTENSION deviceExtension;
irpStack = IoGetCurrentIrpStackLocation(Irp);
@ -38,7 +38,7 @@ NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// it should return STATUS_PENDING and queue all incoming
// IRPs until the IRP completes.
if (Removed == deviceExtension->DeviceState)
{
{
// Even if a driver fails the IRP, it must nevertheless call
// PoStartNextPowerIrp to inform the Power Manager that it
@ -53,7 +53,7 @@ NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
if (NotStarted == deviceExtension->DeviceState)
{
{
// if the device is not started yet, pass it down
PoStartNextPowerIrp(Irp);
IoSkipCurrentIrpStackLocation(Irp);
@ -66,7 +66,7 @@ NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
FreeBT_IoIncrement(deviceExtension);
switch(irpStack->MinorFunction)
{
{
case IRP_MN_SET_POWER:
// The Power Manager sends this IRP for one of the
// following reasons:
@ -82,7 +82,7 @@ NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
IoMarkIrpPending(Irp);
switch(irpStack->Parameters.Power.Type)
{
{
case SystemPowerState:
HandleSystemSetPower(DeviceObject, Irp);
ntStatus = STATUS_PENDING;
@ -108,7 +108,7 @@ NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
IoMarkIrpPending(Irp);
switch(irpStack->Parameters.Power.Type)
{
{
case SystemPowerState:
HandleSystemQueryPower(DeviceObject, Irp);
ntStatus = STATUS_PENDING;
@ -144,7 +144,7 @@ NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
PoStartNextPowerIrp(Irp);
ntStatus = PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: Lower drivers failed the wait-wake Irp\n"));
}
@ -168,7 +168,7 @@ NTSTATUS FreeBT_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
IoSkipCurrentIrpStackLocation(Irp);
ntStatus = PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_DispatchPower: Lower drivers failed this Irp\n"));
}
@ -205,7 +205,7 @@ NTSTATUS HandleSystemQueryPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// Fail a query for a power state incompatible with waking up the system
if ((deviceExtension->WaitWakeEnable) && (systemState > deviceExtension->DeviceCapabilities.SystemWake))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleSystemQueryPower: Query for an incompatible system power state\n"));
PoStartNextPowerIrp(Irp);
@ -222,7 +222,7 @@ NTSTATUS HandleSystemQueryPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// if querying for a lower S-state, issue a wait-wake
if((systemState > deviceExtension->SysPower) && (deviceExtension->WaitWakeEnable))
{
{
IssueWaitWake(deviceExtension);
}
@ -296,7 +296,7 @@ NTSTATUS HandleDeviceQueryPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
deviceExtension->DevPower - 1));
if (deviceExtension->WaitWakeEnable && deviceState > deviceExtension->DeviceCapabilities.DeviceWake)
{
{
PoStartNextPowerIrp(Irp);
Irp->IoStatus.Status = ntStatus = STATUS_INVALID_DEVICE_STATE;
Irp->IoStatus.Information = 0;
@ -310,16 +310,16 @@ NTSTATUS HandleDeviceQueryPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
}
if (deviceState < deviceExtension->DevPower)
{
{
ntStatus = STATUS_SUCCESS;
}
else
{
{
ntStatus = HoldIoRequests(DeviceObject, Irp);
if(STATUS_PENDING == ntStatus)
{
{
return ntStatus;
}
@ -332,13 +332,13 @@ NTSTATUS HandleDeviceQueryPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
if(!NT_SUCCESS(ntStatus))
{
{
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}
else
{
{
IoSkipCurrentIrpStackLocation(Irp);
ntStatus=PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
@ -357,7 +357,7 @@ NTSTATUS HandleDeviceQueryPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
NTSTATUS SysPoCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PDEVICE_EXTENSION DeviceExtension)
{
NTSTATUS ntStatus;
PIO_STACK_LOCATION irpStack;
PIO_STACK_LOCATION irpStack;
ntStatus = Irp->IoStatus.Status;
irpStack = IoGetCurrentIrpStackLocation(Irp);
@ -366,7 +366,7 @@ NTSTATUS SysPoCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN
// lower drivers failed this Irp
if(!NT_SUCCESS(ntStatus))
{
{
PoStartNextPowerIrp(Irp);
FreeBT_DbgPrint(3, ("FBTUSB: SysPoCompletionRoutine::"));
FreeBT_IoDecrement(DeviceExtension);
@ -377,7 +377,7 @@ NTSTATUS SysPoCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN
// ..otherwise update the cached system power state (IRP_MN_SET_POWER)
if(irpStack->MinorFunction == IRP_MN_SET_POWER)
{
{
DeviceExtension->SysPower = irpStack->Parameters.Power.State.SystemState;
}
@ -415,14 +415,14 @@ VOID SendDeviceIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP SIrp )
powerContext = (PPOWER_COMPLETION_CONTEXT) ExAllocatePool(NonPagedPool, sizeof(POWER_COMPLETION_CONTEXT));
if (!powerContext)
{
{
FreeBT_DbgPrint(1, ("FBTUSB: SendDeviceIrp: Failed to alloc memory for powerContext\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
else
{
{
powerContext->DeviceObject = DeviceObject;
powerContext->SIrp = SIrp;
@ -438,9 +438,9 @@ VOID SendDeviceIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP SIrp )
}
if (!NT_SUCCESS(ntStatus))
{
{
if (powerContext)
{
{
ExFreePool(powerContext);
}
@ -516,7 +516,7 @@ NTSTATUS HandleDeviceSetPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
deviceExtension->DevPower - 1));
if (newDevState < oldDevState)
{
{
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower: Adding power to the device\n"));
@ -531,23 +531,23 @@ NTSTATUS HandleDeviceSetPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ntStatus = PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
}
}
else
{
{
// newDevState >= oldDevState
// hold I/O if transition from D0 -> DX (X = 1, 2, 3)
// if transition from D1 or D2 to deeper sleep states,
// I/O queue is already on hold.
if(PowerDeviceD0 == oldDevState && newDevState > oldDevState)
{
{
// D0 -> DX transition
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower: Removing power from the device\n"));
ntStatus = HoldIoRequests(DeviceObject, Irp);
if (!NT_SUCCESS(ntStatus))
{
{
PoStartNextPowerIrp(Irp);
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
@ -561,7 +561,7 @@ NTSTATUS HandleDeviceSetPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
else
{
{
goto HandleDeviceSetPower_Exit;
}
@ -569,7 +569,7 @@ NTSTATUS HandleDeviceSetPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
else if (PowerDeviceD0 == oldDevState && PowerDeviceD0 == newDevState)
{
{
// D0 -> D0
// unblock the queue which may have been blocked processing
// query irp
@ -594,7 +594,7 @@ NTSTATUS HandleDeviceSetPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
ntStatus = PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HandleDeviceSetPower: Lower drivers failed a power Irp\n"));
}
@ -617,13 +617,13 @@ NTSTATUS FinishDevPoUpIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PDEVIC
ntStatus = Irp->IoStatus.Status;
if(Irp->PendingReturned)
{
{
IoMarkIrpPending(Irp);
}
if(!NT_SUCCESS(ntStatus))
{
{
PoStartNextPowerIrp(Irp);
FreeBT_DbgPrint(3, ("FBTUSB: FinishDevPoUpIrp::"));
@ -665,7 +665,7 @@ NTSTATUS SetDeviceFunctional(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PDE
// save/restore.
PoSetPowerState(DeviceObject, DevicePowerState, newState);
if(PowerDeviceD0 == newDevState)
{
{
KeAcquireSpinLock(&DeviceExtension->DevStateLock, &oldIrql);
DeviceExtension->QueueState = AllowRequests;
KeReleaseSpinLock(&DeviceExtension->DevStateLock, oldIrql);
@ -701,7 +701,7 @@ NTSTATUS FinishDevPoDnIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PDEVIC
newState = irpStack->Parameters.Power.State;
if (NT_SUCCESS(ntStatus) && irpStack->MinorFunction == IRP_MN_SET_POWER)
{
{
FreeBT_DbgPrint(3, ("FBTUSB: updating cache..\n"));
DeviceExtension->DevPower = newState.DeviceState;
PoSetPowerState(DeviceObject, DevicePowerState, newState);
@ -734,7 +734,7 @@ NTSTATUS HoldIoRequests(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
context = (PWORKER_THREAD_CONTEXT) ExAllocatePool(NonPagedPool, sizeof(WORKER_THREAD_CONTEXT));
if(context)
{
{
item = IoAllocateWorkItem(DeviceObject);
context->Irp = Irp;
@ -742,7 +742,7 @@ NTSTATUS HoldIoRequests(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
context->WorkItem = item;
if (item)
{
{
IoMarkIrpPending(Irp);
IoQueueWorkItem(item, HoldIoRequestsWorkerRoutine, DelayedWorkQueue, context);
ntStatus = STATUS_PENDING;
@ -750,7 +750,7 @@ NTSTATUS HoldIoRequests(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
else
{
{
FreeBT_DbgPrint(3, ("FBTUSB: HoldIoRequests: Failed to allocate memory for workitem\n"));
ExFreePool(context);
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
@ -760,7 +760,7 @@ NTSTATUS HoldIoRequests(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
else
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HoldIoRequests: Failed to alloc memory for worker thread context\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
@ -806,16 +806,16 @@ VOID HoldIoRequestsWorkerRoutine(IN PDEVICE_OBJECT DeviceObject, IN PVOID Contex
// now send the Irp down
IoCopyCurrentIrpStackLocationToNext(irp);
IoSetCompletionRoutine(
irp,
(PIO_COMPLETION_ROUTINE) FinishDevPoDnIrp,
deviceExtension,
TRUE,
TRUE,
TRUE);
irp,
(PIO_COMPLETION_ROUTINE) FinishDevPoDnIrp,
deviceExtension,
TRUE,
TRUE,
TRUE);
ntStatus = PoCallDriver(deviceExtension->TopOfStackDeviceObject, irp);
if(!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: HoldIoRequestsWorkerRoutine: Lower driver fail a power Irp\n"));
}
@ -892,7 +892,7 @@ NTSTATUS IssueWaitWake(IN PDEVICE_EXTENSION DeviceExtension)
FreeBT_DbgPrint(3, ("FBTUSB: IssueWaitWake: Entered\n"));
if(InterlockedExchange(&DeviceExtension->FlagWWOutstanding, 1))
{
{
return STATUS_DEVICE_BUSY;
}
@ -909,7 +909,7 @@ NTSTATUS IssueWaitWake(IN PDEVICE_EXTENSION DeviceExtension)
&DeviceExtension->WaitWakeIrp);
if(!NT_SUCCESS(ntStatus))
{
{
InterlockedExchange(&DeviceExtension->FlagWWOutstanding, 0);
}
@ -928,10 +928,10 @@ VOID CancelWaitWake(IN PDEVICE_EXTENSION DeviceExtension)
Irp = (PIRP) InterlockedExchangePointer(&DeviceExtension->WaitWakeIrp, NULL);
if(Irp)
{
{
IoCancelIrp(Irp);
if(InterlockedExchange(&DeviceExtension->FlagWWCancel, 1))
{
{
PoStartNextPowerIrp(Irp);
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
@ -949,7 +949,7 @@ NTSTATUS WaitWakeCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
{
FreeBT_DbgPrint(3, ("FBTUSB: WaitWakeCompletionRoutine: Entered\n"));
if(Irp->PendingReturned)
{
{
IoMarkIrpPending(Irp);
}
@ -958,7 +958,7 @@ NTSTATUS WaitWakeCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
// as part of the completion process. If it's already NULL,
// avoid race with the CancelWaitWake routine.
if(InterlockedExchangePointer(&DeviceExtension->WaitWakeIrp, NULL))
{
{
PoStartNextPowerIrp(Irp);
return STATUS_SUCCESS;
@ -969,7 +969,7 @@ NTSTATUS WaitWakeCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
// If FlagWWCancel != 0, complete the Irp.
// If FlagWWCancel == 0, CancelWaitWake completes it.
if(InterlockedExchange(&DeviceExtension->FlagWWCancel, 1))
{
{
PoStartNextPowerIrp(Irp);
return STATUS_CANCELLED;
@ -1000,14 +1000,14 @@ VOID WaitWakeCallback(
InterlockedExchange(&deviceExtension->FlagWWOutstanding, 0);
if(!NT_SUCCESS(IoStatus->Status))
{
{
return;
}
// wake up the device
if(deviceExtension->DevPower == PowerDeviceD0)
{
{
FreeBT_DbgPrint(3, ("FBTUSB: WaitWakeCallback: Device already powered up...\n"));
return;
@ -1026,7 +1026,7 @@ VOID WaitWakeCallback(
NULL);
if(deviceExtension->WaitWakeEnable)
{
{
IssueWaitWake(deviceExtension);
}
@ -1041,7 +1041,7 @@ VOID WaitWakeCallback(
PCHAR PowerMinorFunctionString (IN UCHAR MinorFunction)
{
switch (MinorFunction)
{
{
case IRP_MN_SET_POWER:
return "IRP_MN_SET_POWER\n";

View file

@ -22,18 +22,18 @@
// Read/Write handler
NTSTATUS FreeBT_DispatchRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PMDL mdl;
PURB urb;
ULONG totalLength;
ULONG stageLength;
NTSTATUS ntStatus;
ULONG_PTR virtualAddress;
PFILE_OBJECT fileObject;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
ULONG maxLength=0;
PMDL mdl;
PURB urb;
ULONG totalLength;
ULONG stageLength;
NTSTATUS ntStatus;
ULONG_PTR virtualAddress;
PFILE_OBJECT fileObject;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
//ULONG maxLength=0;
urb = NULL;
mdl = NULL;
@ -56,7 +56,7 @@ NTSTATUS FreeBT_DispatchRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// Make sure that any selective suspend request has been completed.
if (deviceExtension->SSEnable)
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchRead: Waiting on the IdleReqPendEvent\n"));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchRead: Waiting on the IdleReqPendEvent\n"));
KeWaitForSingleObject(&deviceExtension->NoIdleReqPendEvent,
Executive,
KernelMode,
@ -80,7 +80,7 @@ NTSTATUS FreeBT_DispatchRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_DispatchRead: Transfer data length = %d\n", totalLength));
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_DispatchRead: Transfer data length = %d\n", totalLength));
if (totalLength == 0)
{
ntStatus = STATUS_SUCCESS;
@ -189,7 +189,7 @@ NTSTATUS FreeBT_DispatchRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchRead::"));
FreeBT_IoIncrement(deviceExtension);
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchRead: URB sent to lower driver, IRP is pending\n"));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchRead: URB sent to lower driver, IRP is pending\n"));
// we return STATUS_PENDING and not the status returned by the lower layer.
return STATUS_PENDING;
@ -206,13 +206,13 @@ FreeBT_DispatchRead_Exit:
NTSTATUS FreeBT_ReadCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
ULONG stageLength;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
PDEVICE_EXTENSION deviceExtension;
//ULONG stageLength;
NTSTATUS ntStatus;
//PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
PDEVICE_EXTENSION deviceExtension;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
rwContext = (PFREEBT_RW_CONTEXT) Context;
ntStatus = Irp->IoStatus.Status;
@ -221,13 +221,13 @@ NTSTATUS FreeBT_ReadCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN P
if (NT_SUCCESS(ntStatus))
{
Irp->IoStatus.Information = rwContext->Urb->UrbBulkOrInterruptTransfer.TransferBufferLength;
Irp->IoStatus.Information = rwContext->Urb->UrbBulkOrInterruptTransfer.TransferBufferLength;
}
else
{
Irp->IoStatus.Information = 0;
Irp->IoStatus.Information = 0;
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_ReadCompletion: - failed with status = %X\n", ntStatus));
}
@ -252,18 +252,18 @@ NTSTATUS FreeBT_ReadCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN P
// Read/Write handler
NTSTATUS FreeBT_DispatchWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PMDL mdl;
PURB urb;
ULONG totalLength;
ULONG stageLength;
NTSTATUS ntStatus;
ULONG_PTR virtualAddress;
PFILE_OBJECT fileObject;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
ULONG maxLength=0;
PMDL mdl;
PURB urb;
ULONG totalLength;
ULONG stageLength;
NTSTATUS ntStatus;
ULONG_PTR virtualAddress;
PFILE_OBJECT fileObject;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
//ULONG maxLength=0;
urb = NULL;
mdl = NULL;
@ -286,7 +286,7 @@ NTSTATUS FreeBT_DispatchWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
// Make sure that any selective suspend request has been completed.
if (deviceExtension->SSEnable)
{
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_WriteDispatch: Waiting on the IdleReqPendEvent\n"));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_WriteDispatch: Waiting on the IdleReqPendEvent\n"));
KeWaitForSingleObject(&deviceExtension->NoIdleReqPendEvent,
Executive,
KernelMode,
@ -310,10 +310,10 @@ NTSTATUS FreeBT_DispatchWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
}
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_WriteDispatch: Transfer data length = %d\n", totalLength));
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_WriteDispatch: Transfer data length = %d\n", totalLength));
if (totalLength>FBT_HCI_DATA_MAX_SIZE)
{
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_WriteDispatch: Buffer exceeds maximum packet length (%d), failing IRP\n", FBT_HCI_DATA_MAX_SIZE));
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_WriteDispatch: Buffer exceeds maximum packet length (%d), failing IRP\n", FBT_HCI_DATA_MAX_SIZE));
ntStatus = STATUS_INVALID_BUFFER_SIZE;
ExFreePool(rwContext);
goto FreeBT_DispatchWrite_Exit;
@ -322,7 +322,7 @@ NTSTATUS FreeBT_DispatchWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
if (totalLength<FBT_HCI_DATA_MIN_SIZE)
{
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_WriteDispatch: Zero length buffer, completing IRP\n"));
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_WriteDispatch: Zero length buffer, completing IRP\n"));
ntStatus = STATUS_BUFFER_TOO_SMALL;
ExFreePool(rwContext);
goto FreeBT_DispatchWrite_Exit;
@ -429,7 +429,7 @@ NTSTATUS FreeBT_DispatchWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchWrite::"));
FreeBT_IoIncrement(deviceExtension);
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchWrite: URB sent to lower driver, IRP is pending\n"));
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchWrite: URB sent to lower driver, IRP is pending\n"));
// we return STATUS_PENDING and not the status returned by the lower layer.
return STATUS_PENDING;
@ -446,13 +446,13 @@ FreeBT_DispatchWrite_Exit:
NTSTATUS FreeBT_WriteCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
ULONG stageLength;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
PDEVICE_EXTENSION deviceExtension;
ULONG stageLength;
NTSTATUS ntStatus;
PIO_STACK_LOCATION nextStack;
PFREEBT_RW_CONTEXT rwContext;
PDEVICE_EXTENSION deviceExtension;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
rwContext = (PFREEBT_RW_CONTEXT) Context;
ntStatus = Irp->IoStatus.Status;
@ -508,7 +508,7 @@ NTSTATUS FreeBT_WriteCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN
else
{
// No more data to transfer
FreeBT_DbgPrint(1, ("FBTUSB: FreeNT_WriteCompletion: Write completed, %d bytes written\n", Irp->IoStatus.Information));
FreeBT_DbgPrint(1, ("FBTUSB: FreeNT_WriteCompletion: Write completed, %d bytes written\n", Irp->IoStatus.Information));
Irp->IoStatus.Information = rwContext->Numxfer;
}

View file

@ -49,7 +49,7 @@ NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING Un
registryPath->Buffer = (PWSTR) ExAllocatePool(PagedPool, registryPath->MaximumLength);
if (!registryPath->Buffer)
{
{
FreeBT_DbgPrint(1, ("FBTUSB: Failed to allocate memory for registryPath\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto DriverEntry_Exit;
@ -90,7 +90,7 @@ VOID NTAPI FreeBT_DriverUnload(IN PDRIVER_OBJECT DriverObject)
registryPath = &Globals.FreeBT_RegistryPath;
if(registryPath->Buffer)
{
{
ExFreePool(registryPath->Buffer);
registryPath->Buffer = NULL;
@ -107,68 +107,68 @@ VOID NTAPI FreeBT_DriverUnload(IN PDRIVER_OBJECT DriverObject)
// to initialise
NTSTATUS NTAPI FreeBT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
{
NTSTATUS ntStatus;
PDEVICE_OBJECT deviceObject;
PDEVICE_EXTENSION deviceExtension;
POWER_STATE state;
KIRQL oldIrql;
UNICODE_STRING uniDeviceName;
WCHAR wszDeviceName[255]={0};
UNICODE_STRING uniDosDeviceName;
LONG instanceNumber=0;
NTSTATUS ntStatus;
PDEVICE_OBJECT deviceObject;
PDEVICE_EXTENSION deviceExtension;
POWER_STATE state;
//KIRQL oldIrql;
UNICODE_STRING uniDeviceName;
WCHAR wszDeviceName[255]={0};
UNICODE_STRING uniDosDeviceName;
LONG instanceNumber=0;
FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_AddDevice: Entered\n"));
deviceObject = NULL;
swprintf(wszDeviceName, L"\\Device\\FbtUsb%02d", instanceNumber);
RtlInitUnicodeString(&uniDeviceName, wszDeviceName);
ntStatus=STATUS_OBJECT_NAME_COLLISION;
while (instanceNumber<99 && !NT_SUCCESS(ntStatus))
{
swprintf(wszDeviceName, L"\\Device\\FbtUsb%02d", instanceNumber);
uniDeviceName.Length = wcslen(wszDeviceName) * sizeof(WCHAR);
FreeBT_DbgPrint(1, ("FBTUSB: Attempting to create device %ws\n", wszDeviceName));
ntStatus = IoCreateDevice(
DriverObject, // our driver object
sizeof(DEVICE_EXTENSION), // extension size for us
&uniDeviceName, // name for this device
FILE_DEVICE_UNKNOWN,
0, // device characteristics
FALSE, // Not exclusive
&deviceObject); // Our device object
swprintf(wszDeviceName, L"\\Device\\FbtUsb%02d", instanceNumber);
RtlInitUnicodeString(&uniDeviceName, wszDeviceName);
ntStatus=STATUS_OBJECT_NAME_COLLISION;
while (instanceNumber<99 && !NT_SUCCESS(ntStatus))
{
swprintf(wszDeviceName, L"\\Device\\FbtUsb%02d", instanceNumber);
uniDeviceName.Length = wcslen(wszDeviceName) * sizeof(WCHAR);
FreeBT_DbgPrint(1, ("FBTUSB: Attempting to create device %ws\n", wszDeviceName));
ntStatus = IoCreateDevice(
DriverObject, // our driver object
sizeof(DEVICE_EXTENSION), // extension size for us
&uniDeviceName, // name for this device
FILE_DEVICE_UNKNOWN,
0, // device characteristics
FALSE, // Not exclusive
&deviceObject); // Our device object
if (!NT_SUCCESS(ntStatus))
instanceNumber++;
if (!NT_SUCCESS(ntStatus))
instanceNumber++;
}
}
if (!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: Failed to create device object\n"));
return ntStatus;
}
FreeBT_DbgPrint(1, ("FBTUSB: Created device %ws\n", wszDeviceName));
FreeBT_DbgPrint(1, ("FBTUSB: Created device %ws\n", wszDeviceName));
deviceExtension = (PDEVICE_EXTENSION) deviceObject->DeviceExtension;
deviceExtension->FunctionalDeviceObject = deviceObject;
deviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
deviceObject->Flags |= DO_DIRECT_IO;
swprintf(deviceExtension->wszDosDeviceName, L"\\DosDevices\\FbtUsb%02d", instanceNumber);
RtlInitUnicodeString(&uniDosDeviceName, deviceExtension->wszDosDeviceName);
ntStatus=IoCreateSymbolicLink(&uniDosDeviceName, &uniDeviceName);
if (!NT_SUCCESS(ntStatus))
{
FreeBT_DbgPrint(1, ("FBTUSB: Failed to create symbolic link %ws to %ws, status=0x%08x\n", deviceExtension->wszDosDeviceName, wszDeviceName, ntStatus));
IoDeleteDevice(deviceObject);
return ntStatus;
swprintf(deviceExtension->wszDosDeviceName, L"\\DosDevices\\FbtUsb%02d", instanceNumber);
RtlInitUnicodeString(&uniDosDeviceName, deviceExtension->wszDosDeviceName);
ntStatus=IoCreateSymbolicLink(&uniDosDeviceName, &uniDeviceName);
if (!NT_SUCCESS(ntStatus))
{
FreeBT_DbgPrint(1, ("FBTUSB: Failed to create symbolic link %ws to %ws, status=0x%08x\n", deviceExtension->wszDosDeviceName, wszDeviceName, ntStatus));
IoDeleteDevice(deviceObject);
return ntStatus;
}
}
FreeBT_DbgPrint(1, ("FBTUSB: Created symbolic link %ws\n", deviceExtension->wszDosDeviceName));
FreeBT_DbgPrint(1, ("FBTUSB: Created symbolic link %ws\n", deviceExtension->wszDosDeviceName));
KeInitializeSpinLock(&deviceExtension->DevStateLock);
@ -205,10 +205,10 @@ NTSTATUS NTAPI FreeBT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJEC
// Delegating to WMILIB
ntStatus = FreeBT_WmiRegistration(deviceExtension);
if (!NT_SUCCESS(ntStatus))
{
{
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_WmiRegistration failed with %X\n", ntStatus));
IoDeleteDevice(deviceObject);
IoDeleteSymbolicLink(&uniDosDeviceName);
IoDeleteSymbolicLink(&uniDosDeviceName);
return ntStatus;
}
@ -216,7 +216,7 @@ NTSTATUS NTAPI FreeBT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJEC
// Set the flags as underlying PDO
if (PhysicalDeviceObject->Flags & DO_POWER_PAGABLE)
{
{
deviceObject->Flags |= DO_POWER_PAGABLE;
}
@ -237,12 +237,12 @@ NTSTATUS NTAPI FreeBT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJEC
// attachment chain. This is where all the IRPs should be routed.
deviceExtension->TopOfStackDeviceObject = IoAttachDeviceToDeviceStack(deviceObject, PhysicalDeviceObject);
if (NULL == deviceExtension->TopOfStackDeviceObject)
{
{
#ifdef ENABLE_WMI
FreeBT_WmiDeRegistration(deviceExtension);
#endif
IoDeleteDevice(deviceObject);
IoDeleteSymbolicLink(&uniDosDeviceName);
IoDeleteSymbolicLink(&uniDosDeviceName);
return STATUS_NO_SUCH_DEVICE;
}
@ -253,37 +253,37 @@ NTSTATUS NTAPI FreeBT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJEC
NULL,
&deviceExtension->InterfaceName);
if (!NT_SUCCESS(ntStatus))
{
{
#ifdef ENABLE_WMI
FreeBT_WmiDeRegistration(deviceExtension);
#endif
IoDetachDevice(deviceExtension->TopOfStackDeviceObject);
IoDeleteDevice(deviceObject);
IoDeleteSymbolicLink(&uniDosDeviceName);
IoDeleteSymbolicLink(&uniDosDeviceName);
return ntStatus;
}
if (IoIsWdmVersionAvailable(1, 0x20))
{
{
deviceExtension->WdmVersion = WinXpOrBetter;
}
else if (IoIsWdmVersionAvailable(1, 0x10))
{
{
deviceExtension->WdmVersion = Win2kOrBetter;
}
else if (IoIsWdmVersionAvailable(1, 0x5))
{
{
deviceExtension->WdmVersion = WinMeOrBetter;
}
else if (IoIsWdmVersionAvailable(1, 0x0))
{
{
deviceExtension->WdmVersion = Win98OrBetter;
}
@ -292,14 +292,14 @@ NTSTATUS NTAPI FreeBT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJEC
deviceExtension->SSEnable = 0;
// WinXP only: check the registry flag indicating whether
// the device should selectively suspend when idle
// the device should selectively suspend when idle
if (WinXpOrBetter == deviceExtension->WdmVersion)
{
{
FreeBT_GetRegistryDword(FREEBT_REGISTRY_PARAMETERS_PATH,
L"BulkUsbEnable",
(PULONG)(&deviceExtension->SSRegistryEnable));
if (deviceExtension->SSRegistryEnable)
{
{
// initialize DPC
KeInitializeDpc(&deviceExtension->DeferredProcCall, DpcRoutine, deviceObject);