1 // Copyright (c) 2004, Antony C. Roberts
3 // Use of this file is subject to the terms
4 // described in the LICENSE.TXT file that
5 // accompanies this file.
7 // Your use of this file indicates your
8 // acceptance of the terms described in
11 // http://www.freebt.net
24 // Pull in all the command, event and structure definitions
25 #include "fbtHciDefs.h"
27 // Standard USB Wireless/Bluetooth class, etc
28 #define FREEBT_USB_STDCLASS 0xE0 // Wireless Controller
29 #define FREEBT_USB_STDSUBCLASS 0x01 // RF Controller
30 #define FREEBT_USB_STDPROTOCOL 0x01 // Bluetooth Programming
32 // Recommended Bluetooth Endpoints
33 #define FREEBT_STDENDPOINT_HCICMD 0x00 // HCI Command
34 #define FREEBT_STDENDPOINT_HCIEVENT 0x81 // HCI Event
35 #define FREEBT_STDENDPOINT_ACLIN 0x82 // HCI Data In
36 #define FREEBT_STDENDPOINT_ACLOUT 0x02 // HCI Data Out
37 #define FREEBT_STDENDPOINT_AUDIOIN 0x83 // SCO In
38 #define FREEBT_STDENDPOINT_AUDIOOUT 0x03 // SCO Out
41 #define OBTTAG (ULONG) 'OBTU'
44 #define ExAllocatePool(type, size) ExAllocatePoolWithTag(type, size, OBTTAG);
48 #define FreeBT_DbgPrint(level, _x_) \
49 if((level) <= DebugLevel) { \
55 #define FreeBT_DbgPrint(level, _x_)
59 typedef struct _GLOBALS
61 UNICODE_STRING FreeBT_RegistryPath
;
65 #define IDLE_INTERVAL 5000
67 typedef enum _PIPETYPE
78 typedef enum _DEVSTATE
80 NotStarted
, // not started
81 Stopped
, // device stopped
82 Working
, // started and working
83 PendingStop
, // stop pending
84 PendingRemove
, // remove pending
85 SurpriseRemoved
, // removed by surprise
90 typedef enum _QUEUE_STATE
92 HoldRequests
, // device is not started yet
93 AllowRequests
, // device is ready to process
94 FailRequests
// fail both existing and queued up requests
98 typedef enum _WDM_VERSION
107 #define INITIALIZE_PNP_STATE(_Data_) \
108 (_Data_)->DeviceState = NotStarted;\
109 (_Data_)->PrevDevState = NotStarted;
111 #define SET_NEW_PNP_STATE(_Data_, _state_) \
112 (_Data_)->PrevDevState = (_Data_)->DeviceState;\
113 (_Data_)->DeviceState = (_state_);
115 #define RESTORE_PREVIOUS_PNP_STATE(_Data_) \
116 (_Data_)->DeviceState = (_Data_)->PrevDevState;
119 // registry path used for parameters
120 // global to all instances of the driver
121 #define FREEBT_REGISTRY_PARAMETERS_PATH L"\\REGISTRY\\Machine\\System\\CurrentControlSet\\SERVICES\\BULKUSB\\Parameters"
123 typedef struct _FREEBT_PIPE_CONTEXT
126 FREEBT_PIPETYPE PipeType
;
128 } FREEBT_PIPE_CONTEXT
, *PFREEBT_PIPE_CONTEXT
;
130 // A structure representing the instance information associated with
131 // this particular device.
132 typedef struct _DEVICE_EXTENSION
134 // Functional Device Object
135 PDEVICE_OBJECT FunctionalDeviceObject
;
137 // Device object we call when submitting Urbs
138 PDEVICE_OBJECT TopOfStackDeviceObject
;
140 // The bus driver object
141 PDEVICE_OBJECT PhysicalDeviceObject
;
143 // Name buffer for our named Functional device object link
144 // The name is generated based on the driver's class GUID
145 UNICODE_STRING InterfaceName
;
147 // Bus drivers set the appropriate values in this structure in response
148 // to an IRP_MN_QUERY_CAPABILITIES IRP. Function and filter drivers might
149 // alter the capabilities set by the bus driver.
150 DEVICE_CAPABILITIES DeviceCapabilities
;
152 // Configuration Descriptor
153 PUSB_CONFIGURATION_DESCRIPTOR UsbConfigurationDescriptor
;
155 // Interface Information structure
156 PUSBD_INTERFACE_INFORMATION UsbInterface
;
158 // Pipe context for the driver
159 PFREEBT_PIPE_CONTEXT PipeContext
;
161 // current state of device
162 DEVSTATE DeviceState
;
164 // state prior to removal query
165 DEVSTATE PrevDevState
;
167 // obtain and hold this lock while changing the device state,
168 // the queue state and while processing the queue.
169 KSPIN_LOCK DevStateLock
;
171 // current system power state
172 SYSTEM_POWER_STATE SysPower
;
174 // current device power state
175 DEVICE_POWER_STATE DevPower
;
177 // Pending I/O queue state
178 QUEUE_STATE QueueState
;
181 LIST_ENTRY NewRequestsQueue
;
184 KSPIN_LOCK QueueLock
;
192 KSPIN_LOCK IOCountLock
;
194 // Selective Suspend variables
196 LONG SSRegistryEnable
;
197 PUSB_IDLE_CALLBACK_INFO IdleCallbackInfo
;
200 LONG FreeIdleIrpCount
;
201 KSPIN_LOCK IdleReqStateLock
;
202 KEVENT NoIdleReqPendEvent
;
204 // Default power state to power down to on self-susped
205 ULONG PowerDownLevel
;
207 // remote wakeup variables
210 LONG FlagWWOutstanding
;
214 LONG OpenHandleCount
;
216 // Selective suspend model uses timers, dpcs and work item.
219 KDPC DeferredProcCall
;
221 // This event is cleared when a DPC/Work Item is queued.
222 // and signaled when the work-item completes.
223 // This is essential to prevent the driver from unloading
224 // while we have DPC or work-item queued up.
225 KEVENT NoDpcWorkItemPendingEvent
;
228 WMILIB_CONTEXT WmiLibInfo
;
231 WDM_VERSION WdmVersion
;
234 FREEBT_PIPETYPE PipeType
;
236 // User accessible object name
237 WCHAR wszDosDeviceName
[50];
239 // A never triggered event used for delaying execution
243 USBD_PIPE_INFORMATION EventPipe
;
244 USBD_PIPE_INFORMATION DataInPipe
;
245 USBD_PIPE_INFORMATION DataOutPipe
;
246 USBD_PIPE_INFORMATION AudioInPipe
;
247 USBD_PIPE_INFORMATION AudioOutPipe
;
249 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
;
252 typedef struct _IRP_COMPLETION_CONTEXT
254 PDEVICE_EXTENSION DeviceExtension
;
257 } IRP_COMPLETION_CONTEXT
, *PIRP_COMPLETION_CONTEXT
;
259 extern GLOBALS Globals
;
260 extern ULONG DebugLevel
;