41 if (deviceExtension->DeviceState !=
Working)
44 goto FreeBT_DispatchCreate_Exit;
48 if (deviceExtension->UsbInterface)
58 goto FreeBT_DispatchCreate_Exit;
64 fileObject->FsContext =
NULL;
70 goto FreeBT_DispatchCreate_Exit;
74 if (deviceExtension->OpenHandleCount>0)
77 goto FreeBT_DispatchCreate_Exit;
88 if (deviceExtension->SSEnable)
91FreeBT_DispatchCreate_Exit:
92 Irp->IoStatus.Status = ntStatus;
93 Irp->IoStatus.Information = 0;
122 Irp->IoStatus.Status = ntStatus;
123 Irp->IoStatus.Information = 0;
140 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_HCISendCompletion, status=0x%08X\n",
Irp->IoStatus.Status));
142 if (
Irp->PendingReturned)
147 ntStatus =
Irp->IoStatus.Status;
148 Irp->IoStatus.Information = 0;
169 if (!deviceExtension)
172 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_SendHCICommand: Failed to get DeviceExtension\n"));
173 Irp->IoStatus.Status = ntStatus;
174 Irp->IoStatus.Information = 0;
209 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_SendHCICommand: Failed to alloc mem for urb\n"));
211 Irp->IoStatus.Status = ntStatus;
212 Irp->IoStatus.Information = 0;
252 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_SendHCICommand: Sending IRP %X to underlying driver\n",
Irp));
256 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_SendHCICommand: IoCallDriver fails with status %X\n", ntStatus));
267 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_SendHCICommand: ntStatus is STATUS_CANCELLED or STATUS_DEVICE_NOT_CONNECTED\n"));
269 Irp->IoStatus.Status = ntStatus;
270 Irp->IoStatus.Information = 0;
277 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_SendHCICommand: Completed successfully\n"));
291 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_HCIEventCompletion, status=0x%08X\n",
Irp->IoStatus.Status));
293 if (
Irp->PendingReturned)
298 ntStatus =
Irp->IoStatus.Status;
325 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_GetHCIEvent: Failed to alloc mem for urb\n"));
327 goto FreeBT_GetHCIEvent_Exit;
334 deviceExtension->EventPipe.PipeHandle,
365 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_GetHCIEvent: IoCallDriver fails with status %X\n", ntStatus));
386 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_GetHCIEvent: ntStatus is STATUS_CANCELLED or STATUS_DEVICE_NOT_CONNECTED\n"));
390 goto FreeBT_GetHCIEvent_Exit;
400FreeBT_GetHCIEvent_Exit:
401 Irp->IoStatus.Status=ntStatus;
402 Irp->IoStatus.Information=0;
404 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_GetHCIEvent: Failure (0x%08x), completing IRP\n", ntStatus));
416 ULONG inputBufferLength;
417 ULONG outputBufferLength;
428 ioBuffer =
Irp->AssociatedIrp.SystemBuffer;
432 if (deviceExtension->DeviceState !=
Working)
436 goto FreeBT_DispatchDevCtrlExit;
443 if (deviceExtension->SSEnable)
461 FreeBT_DbgPrint(3, (
"FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD: Buffer too small\n"));
462 goto FreeBT_DispatchDevCtrlExit;
469 FreeBT_DbgPrint(3, (
"FBTUSB: IOCTL_FREEBT_HCI_SEND_CMD: Buffer too long\n"));
470 goto FreeBT_DispatchDevCtrlExit;
482 FreeBT_DbgPrint(3, (
"FBTUSB: IOCTL_FREEBT_HCI_GET_EVENT: Buffer too small\n"));
483 goto FreeBT_DispatchDevCtrlExit;
497FreeBT_DispatchDevCtrlExit:
498 Irp->IoStatus.Information = 0;
499 Irp->IoStatus.Status = ntStatus;
582 deviceExtension->TopOfStackDeviceObject,
607 ioStatus.
Status = ntStatus;
609 ntStatus = ioStatus.
Status;
633 deviceExtension->TopOfStackDeviceObject,
657 ioStatus.
Status = ntStatus;
660 ntStatus = ioStatus.
Status;
674 PUSB_IDLE_CALLBACK_INFO idleCallbackInfo;
680 idleCallbackInfo =
NULL;
688 goto SubmitIdleRequestIrp_Exit;
701 goto SubmitIdleRequestIrp_Exit;
714 if(idleCallbackInfo) {
718 idleCallbackInfo->IdleContext = (
PVOID)DeviceExtension;
720 ASSERT(DeviceExtension->IdleCallbackInfo ==
NULL);
722 DeviceExtension->IdleCallbackInfo = idleCallbackInfo;
737 KeSetEvent(&DeviceExtension->NoIdleReqPendEvent,
749 goto SubmitIdleRequestIrp_Exit;
758 IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION;
764 sizeof(
struct _USB_IDLE_CALLBACK_INFO);
774 DeviceExtension->PendingIdleIrp =
irp;
787 DeviceExtension->FreeIdleIrpCount = 2;
811 DeviceExtension->IdleCallbackInfo =
NULL;
813 DeviceExtension->PendingIdleIrp =
NULL;
815 KeSetEvent(&DeviceExtension->NoIdleReqPendEvent,
823 if(idleCallbackInfo) {
842 goto SubmitIdleRequestIrp_Exit;
860 goto SubmitIdleRequestIrp_Exit;
865 FreeBT_DbgPrint(1, (
"Memory allocation for idleCallbackInfo failed\n"));
867 KeSetEvent(&DeviceExtension->NoIdleReqPendEvent,
878SubmitIdleRequestIrp_Exit:
890 KEVENT irpCompletionEvent;
901 if(DeviceExtension->DeviceState !=
Working) {
909 if(DeviceExtension->WaitWakeEnable) {
925 FreeBT_DbgPrint(1, (
"FBTUSB: IdleNotificationCallback: Failed to alloc memory for irpContext\n"));
946 irpContext->
Event = &irpCompletionEvent;
949 DeviceExtension->PhysicalDeviceObject,
959 "waiting for the power irp to complete\n"));
988 PUSB_IDLE_CALLBACK_INFO idleCallbackInfo;
990 FreeBT_DbgPrint(3, (
"FBTUSB: IdleNotificationRequestCompete: Entered\n"));
994 ntStatus =
Irp->IoStatus.Status;
997 FreeBT_DbgPrint(3, (
"FBTUSB: IdleNotificationRequestCompete: Idle irp completes with error::"));
1014 goto IdleNotificationRequestComplete_Exit;
1028 DeviceExtension->PhysicalDeviceObject,
1040IdleNotificationRequestComplete_Exit:
1042 idleCallbackInfo = DeviceExtension->IdleCallbackInfo;
1043 DeviceExtension->IdleCallbackInfo =
NULL;
1050 if(idleCallbackInfo)
1059 FreeBT_DbgPrint(3, (
"completion routine has a valid irp and frees it\n"));
1080 if(DeviceExtension->SSEnable)
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define InterlockedIncrement
#define InterlockedExchange
#define InterlockedDecrement
#define NT_SUCCESS(StatCode)
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define InterlockedExchangePointer(Target, Value)
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
#define KeInitializeEvent(pEvt, foo, foo2)
#define KeReleaseSpinLock(sl, irql)
#define KeSetEvent(pEvt, foo, foo2)
#define KeAcquireSpinLock(sl, irql)
#define KeGetCurrentIrql()
VOID NTAPI KeClearEvent(IN PKEVENT Event)
#define FBT_HCI_EVENT_MAX_SIZE
#define FBT_HCI_CMD_MIN_SIZE
#define FBT_HCI_CMD_MAX_SIZE
NTSTATUS NTAPI FreeBT_DispatchCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
NTSTATUS NTAPI IdleNotificationRequestComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PDEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI FreeBT_HCISendCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
VOID NTAPI CancelSelectSuspend(IN PDEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI FreeBT_SendHCICommand(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID IoBuffer, IN ULONG InputBufferLength)
NTSTATUS NTAPI SubmitIdleRequestIrp(IN PDEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI FreeBT_ResetPipe(IN PDEVICE_OBJECT DeviceObject, IN USBD_PIPE_HANDLE PipeHandle)
VOID NTAPI WWIrpCompletionFunc(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
VOID NTAPI IdleNotificationCallback(IN PDEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI FreeBT_GetPortStatus(IN PDEVICE_OBJECT DeviceObject, IN OUT PULONG PortStatus)
VOID NTAPI PoIrpAsyncCompletionFunc(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
NTSTATUS NTAPI FreeBT_HCIEventCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
NTSTATUS NTAPI FreeBT_ResetParentPort(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS NTAPI FreeBT_ResetDevice(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS NTAPI FreeBT_DispatchClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
NTSTATUS NTAPI FreeBT_DispatchDevCtrl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
VOID NTAPI PoIrpCompletionFunc(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
NTSTATUS NTAPI FreeBT_GetHCIEvent(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID IoBuffer, IN ULONG InputBufferLength)
NTSTATUS NTAPI CallUSBD(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
BOOLEAN NTAPI CanDeviceSuspend(IN PDEVICE_EXTENSION DeviceExtension)
LONG NTAPI FreeBT_IoDecrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
LONG NTAPI FreeBT_IoIncrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI IssueWaitWake(IN PDEVICE_EXTENSION DeviceExtension)
#define FreeBT_DbgPrint(level, _x_)
struct _IRP_COMPLETION_CONTEXT * PIRP_COMPLETION_CONTEXT
#define ExAllocatePool(type, size)
#define IOCTL_FREEBT_HCI_GET_EVENT
#define IOCTL_FREEBT_HCI_SEND_CMD
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
#define IoCompleteRequest
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
VOID NTAPI IoFreeIrp(IN PIRP Irp)
NTSTATUS NTAPI PoRequestPowerIrp(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
#define STATUS_INVALID_BUFFER_SIZE
#define STATUS_POWER_STATE_INVALID
#define STATUS_NOT_SUPPORTED
#define STATUS_ACCESS_VIOLATION
#define STATUS_MORE_PROCESSING_REQUIRED
#define STATUS_BUFFER_TOO_SMALL
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
struct _IO_STACK_LOCATION::@3974::@4013 Others
PDEVICE_EXTENSION DeviceExtension
struct _URB_BULK_OR_INTERRUPT_TRANSFER UrbBulkOrInterruptTransfer
struct _URB_PIPE_REQUEST UrbPipeRequest
struct _URB_HEADER UrbHeader
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
#define STATUS_INVALID_DEVICE_REQUEST
#define STATUS_DEVICE_NOT_CONNECTED
#define STATUS_INVALID_PARAMETER
#define STATUS_UNSUCCESSFUL
#define STATUS_INVALID_DEVICE_STATE
#define STATUS_DEVICE_BUSY
#define STATUS_INSUFFICIENT_RESOURCES
DEVICE_POWER_STATE DeviceState
#define URB_FUNCTION_RESET_PIPE
#define USBD_TRANSFER_DIRECTION_IN
#define USBD_SHORT_TRANSFER_OK
#define URB_FUNCTION_CLASS_DEVICE
#define UsbBuildInterruptOrBulkTransferRequest(urb, length, pipeHandle, transferBuffer, transferBufferMDL, transferBufferLength, transferFlags, link)
#define UsbBuildVendorRequest(urb, cmd, length, transferFlags, reservedbits, request, value, index, transferBuffer, transferBufferMDL, transferBufferLength, link)
#define IOCTL_INTERNAL_USB_SUBMIT_URB
#define IOCTL_INTERNAL_USB_RESET_PORT
#define USBD_PORT_ENABLED
#define USBD_PORT_CONNECTED
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
_In_ PDEVICE_OBJECT DeviceObject
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
_In_ UCHAR _In_ UCHAR MinorFunction
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
_In_ WDFUSBINTERFACE UsbInterface
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
IO_COMPLETION_ROUTINE * PIO_COMPLETION_ROUTINE
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
REQUEST_POWER_COMPLETE * PREQUEST_POWER_COMPLETE