#include "fbtusr.h"
// Handle PNP events
-NTSTATUS FreeBT_DispatchPnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI 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);
// since the device is removed, fail the Irp.
if (Removed == deviceExtension->DeviceState)
- {
+ {
ntStatus = STATUS_DELETE_PENDING;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
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);
}
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;
// 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;
}
-NTSTATUS HandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
KEVENT startDeviceEvent;
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;
// 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;
// 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;
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;
}
-NTSTATUS ReadandSelectDescriptors(IN PDEVICE_OBJECT DeviceObject)
+NTSTATUS NTAPI ReadandSelectDescriptors(IN PDEVICE_OBJECT DeviceObject)
{
PURB urb;
ULONG siz;
// 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),
ntStatus = CallUSBD(DeviceObject, urb);
if (NT_SUCCESS(ntStatus))
- {
+ {
ASSERT(deviceDescriptor->bNumConfigurations);
ntStatus = ConfigureDevice(DeviceObject);
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: ReadandSelectDescriptors: Failed to allocate memory for deviceDescriptor"));
ExFreePool(urb);
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: ReadandSelectDescriptors: Failed to allocate memory for urb"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
-NTSTATUS ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
+NTSTATUS NTAPI ConfigureDevice(IN PDEVICE_OBJECT DeviceObject)
{
PURB urb;
ULONG siz;
// 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),
ntStatus = CallUSBD(DeviceObject, urb);
if(!NT_SUCCESS(ntStatus))
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: UsbBuildGetDescriptorRequest failed\n"));
goto ConfigureDevice_Exit;
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: Failed to allocate mem for config Descriptor\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto ConfigureDevice_Exit;
configurationDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR) ExAllocatePool(NonPagedPool, siz);
if (configurationDescriptor)
- {
+ {
UsbBuildGetDescriptorRequest(
urb,
(USHORT)sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
ntStatus = CallUSBD(DeviceObject, urb);
if (!NT_SUCCESS(ntStatus))
- {
+ {
FreeBT_DbgPrint(1,("FBTUSB: ConfigureDevice: Failed to read configuration descriptor"));
goto ConfigureDevice_Exit;
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: Failed to alloc mem for config Descriptor\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto ConfigureDevice_Exit;
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: ConfigureDevice: Failed to allocate memory for urb\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto ConfigureDevice_Exit;
}
if (configurationDescriptor)
- {
+ {
// save a copy of configurationDescriptor in deviceExtension
// remember to free it later.
deviceExtension->UsbConfigurationDescriptor = configurationDescriptor;
}
else
- {
+ {
deviceExtension->UsbConfigurationDescriptor = NULL;
}
ConfigureDevice_Exit:
if (urb)
- {
+ {
ExFreePool(urb);
}
}
-NTSTATUS SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
+NTSTATUS NTAPI SelectInterfaces(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
{
LONG numberOfInterfaces, interfaceNumber, interfaceindex;
ULONG i;
PURB urb;
- PUCHAR pInf;
+ //PUCHAR pInf;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
PUSB_INTERFACE_DESCRIPTOR interfaceDescriptor;
// 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;
}
- 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,
0, -1, -1, -1);
if (interfaceDescriptor)
- {
+ {
interfaceList->InterfaceDescriptor = interfaceDescriptor;
interfaceList->Interface = NULL;
interfaceList++;
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
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"));
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
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: ---------\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;
-
- 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_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;
-
- }
-
- }
-
- }
+ {
+ 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));
+
+ // 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_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_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"));
}
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: SelectInterfaces: USBD_CreateConfigurationRequestEx failed\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
if (tmp)
- {
+ {
ExFreePool(tmp);
}
if (urb)
- {
+ {
ExFreePool(urb);
}
}
-NTSTATUS DeconfigureDevice(IN PDEVICE_OBJECT DeviceObject)
+NTSTATUS NTAPI DeconfigureDevice(IN PDEVICE_OBJECT DeviceObject)
{
PURB urb;
ULONG siz;
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"));
}
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: DeconfigureDevice: Failed to allocate urb\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
-NTSTATUS CallUSBD(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
+NTSTATUS NTAPI CallUSBD(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
{
PIRP irp;
KEVENT event;
&ioStatus);
if (!irp)
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: CallUSBD: IoBuildDeviceIoControlRequest failed\n"));
return STATUS_INSUFFICIENT_RESOURCES;
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, irp);
if (ntStatus == STATUS_PENDING)
- {
+ {
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
-NTSTATUS HandleQueryStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleQueryStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
NTSTATUS ntStatus;
}
-NTSTATUS HandleCancelStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleCancelStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
KEVENT event;
// above us fails a query-stop and passes down the subsequent
// cancel-stop.
if(PendingStop == deviceExtension->DeviceState)
- {
+ {
KeInitializeEvent(&event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(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);
}
else
- {
+ {
// spurious Irp
ntStatus = STATUS_SUCCESS;
}
-NTSTATUS HandleStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
NTSTATUS ntStatus;
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.
// the driver must not send any more Irps down that touch
// the device until another Start has occurred.
if (deviceExtension->WaitWakeEnable)
- {
+ {
CancelWaitWake(deviceExtension);
}
}
-NTSTATUS HandleQueryRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleQueryRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
NTSTATUS ntStatus;
}
-NTSTATUS HandleCancelRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleCancelRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
KEVENT event;
// someone above us fails a query-remove and passes down the
// subsequent cancel-remove.
if(PendingRemove == deviceExtension->DeviceState)
- {
+ {
KeInitializeEvent(&event, NotificationEvent, FALSE);
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;
}
else
- {
- // spurious cancel-remove
+ {
+ // spurious cancel-remove
ntStatus = STATUS_SUCCESS;
}
}
-NTSTATUS HandleSurpriseRemoval(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleSurpriseRemoval(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
NTSTATUS ntStatus;
// 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
ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName, FALSE);
if(!NT_SUCCESS(ntStatus))
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: HandleSurpriseRemoval: IoSetDeviceInterfaceState::disable:failed\n"));
}
}
-NTSTATUS HandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
- KEVENT event;
+ //KEVENT event;
ULONG requestCount;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
// (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);
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);
ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName, FALSE);
if(!NT_SUCCESS(ntStatus))
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: HandleRemoveDevice: IoSetDeviceInterfaceState::disable:failed\n"));
}
}
-NTSTATUS HandleQueryCapabilities(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI HandleQueryCapabilities(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
ULONG i;
KEVENT event;
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;
TRUE);
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(ntStatus == STATUS_PENDING)
- {
+ {
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
ntStatus = Irp->IoStatus.Status;
// 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];
}
}
if(deviceExtension->PowerDownLevel == PowerDeviceUnspecified ||
- deviceExtension->PowerDownLevel <= PowerDeviceD0)
- {
+ deviceExtension->PowerDownLevel <= PowerDeviceD0)
+ {
deviceExtension->PowerDownLevel = PowerDeviceD2;
}
}
-VOID DpcRoutine(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
+VOID NTAPI DpcRoutine(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
/*++
DPC routine triggered by the timer to check the idle state
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);
}
else
- {
+ {
FreeBT_DbgPrint(3, ("FBTUSB: DpcRoutine: Idle event not signaled\n"));
KeSetEvent(&deviceExtension->NoDpcWorkItemPendingEvent, IO_NO_INCREMENT, FALSE);
}
-VOID IdleRequestWorkerRoutine(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
+VOID NTAPI IdleRequestWorkerRoutine(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
{
- PIRP irp;
+ //PIRP irp;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
PIO_WORKITEM workItem;
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"));
}
}
else
- {
+ {
FreeBT_DbgPrint(3, ("FBTUSB: IdleRequestWorkerRoutine: Device is not idle\n"));
}
}
-VOID ProcessQueuedRequests(IN OUT PDEVICE_EXTENSION DeviceExtension)
+VOID NTAPI ProcessQueuedRequests(IN OUT PDEVICE_EXTENSION DeviceExtension)
/*++
Routine Description:
// 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;
// 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
}
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);
}
else
- {
+ {
KeReleaseSpinLock(&DeviceExtension->QueueLock, oldIrql);
if(FailRequests == DeviceExtension->QueueState)
- {
+ {
nextIrp->IoStatus.Information = 0;
nextIrp->IoStatus.Status = STATUS_DELETE_PENDING;
IoCompleteRequest(nextIrp, IO_NO_INCREMENT);
}
else
- {
- PIO_STACK_LOCATION irpStack;
+ {
+ //PIO_STACK_LOCATION irpStack;
FreeBT_DbgPrint(3, ("FBTUSB: ProcessQueuedRequests::"));
FreeBT_IoIncrement(DeviceExtension);
}
while(!IsListEmpty(&cancelledIrpList))
- {
+ {
PLIST_ENTRY cancelEntry = RemoveHeadList(&cancelledIrpList);
cancelledIrp = CONTAINING_RECORD(cancelEntry, IRP, Tail.Overlay.ListEntry);
}
-NTSTATUS FreeBT_GetRegistryDword(IN PWCHAR RegPath, IN PWCHAR ValueName, IN OUT PULONG Value)
+NTSTATUS NTAPI FreeBT_GetRegistryDword(IN PWCHAR RegPath, IN PWCHAR ValueName, IN OUT PULONG Value)
{
ULONG defaultData;
WCHAR buffer[MAXIMUM_FILENAME_LENGTH];
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;
}
-NTSTATUS FreeBT_DispatchClean(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI FreeBT_DispatchClean(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PDEVICE_EXTENSION deviceExtension;
KIRQL oldIrql;
PIRP pendingIrp;
PIO_STACK_LOCATION pendingIrpStack,
irpStack;
- NTSTATUS ntStatus;
+ //NTSTATUS ntStatus;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
irpStack = IoGetCurrentIrpStackLocation(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);
}
KeReleaseSpinLock(&deviceExtension->QueueLock, oldIrql);
while(!IsListEmpty(&cleanupList))
- {
+ {
thisEntry = RemoveHeadList(&cleanupList);
pendingIrp = CONTAINING_RECORD(thisEntry, IRP, Tail.Overlay.ListEntry);
}
-BOOLEAN CanDeviceSuspend(IN PDEVICE_EXTENSION DeviceExtension)
+BOOLEAN NTAPI CanDeviceSuspend(IN PDEVICE_EXTENSION DeviceExtension)
{
FreeBT_DbgPrint(3, ("FBTUSB: CanDeviceSuspend: Entered\n"));
if ((DeviceExtension->OpenHandleCount == 0) && (DeviceExtension->OutStandingIO == 1))
return TRUE;
- return FALSE;
+ return FALSE;
}
-NTSTATUS FreeBT_AbortPipes(IN PDEVICE_OBJECT DeviceObject)
+NTSTATUS NTAPI FreeBT_AbortPipes(IN PDEVICE_OBJECT DeviceObject)
{
PURB urb;
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;
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;
}
else
- {
+ {
FreeBT_DbgPrint(1, ("FBTUSB: FreeBT_AbortPipes: Failed to alloc memory for urb\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
return ntStatus;
}
// Completion routine for PNP IRPs
-NTSTATUS IrpCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
+NTSTATUS NTAPI IrpCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
PKEVENT event = (PKEVENT) Context;
KeSetEvent(event, 0, FALSE);
}
-LONG FreeBT_IoIncrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
+LONG NTAPI FreeBT_IoIncrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
{
LONG result = 0;
KIRQL oldIrql;
if (result == 2)
KeClearEvent(&DeviceExtension->StopEvent);
- KeReleaseSpinLock(&DeviceExtension->IOCountLock, oldIrql);
+ KeReleaseSpinLock(&DeviceExtension->IOCountLock, oldIrql);
FreeBT_DbgPrint(3, ("FreeBT_IoIncrement::%d\n", result));
}
-LONG FreeBT_IoDecrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
+LONG NTAPI FreeBT_IoDecrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
{
LONG result = 0;
KIRQL oldIrql;
KeSetEvent(&DeviceExtension->StopEvent, IO_NO_INCREMENT, FALSE);
if(result == 0)
- {
+ {
ASSERT(Removed == DeviceExtension->DeviceState);
KeSetEvent(&DeviceExtension->RemoveEvent, IO_NO_INCREMENT, FALSE);
}
-NTSTATUS CanStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI CanStopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
// For the time being, just allow it to be stopped
UNREFERENCED_PARAMETER(DeviceObject);
}
-NTSTATUS CanRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+NTSTATUS NTAPI CanRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
// For the time being, just allow it to be removed
}
-NTSTATUS ReleaseMemory(IN PDEVICE_OBJECT DeviceObject)
+NTSTATUS NTAPI 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;
}
-PCHAR PnPMinorFunctionString (UCHAR MinorFunction)
+PCHAR NTAPI PnPMinorFunctionString (UCHAR MinorFunction)
{
switch (MinorFunction)
- {
+ {
case IRP_MN_START_DEVICE:
return "IRP_MN_START_DEVICE\n";