bulkusb.h
5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*++
Copyright (c) 2000 Microsoft Corporation
Module Name:
bulkusb.h
Abstract:
Environment:
Kernel mode
Notes:
Copyright (c) 2000 Microsoft Corporation.
All Rights Reserved.
--*/
#include <initguid.h>
#include <wdm.h>
#include <wmilib.h>
#include <wmistr.h>
#include "usbdi.h"
#include "usbdlib.h"
#ifndef _BULKUSB_H
#define _BULKUSB_H
#define BULKTAG (ULONG) 'KluB'
#undef ExAllocatePool
#define ExAllocatePool(type, size) \
ExAllocatePoolWithTag(type, size, BULKTAG);
#if DBG
#define BulkUsb_DbgPrint(level, _x_) \
if((level) <= DebugLevel) { \
DbgPrint _x_; \
}
#else
#define BulkUsb_DbgPrint(level, _x_)
#endif
typedef struct _GLOBALS {
UNICODE_STRING BulkUsb_RegistryPath;
} GLOBALS;
#define IDLE_INTERVAL 5000
typedef enum _DEVSTATE {
NotStarted, // not started
Stopped, // device stopped
Working, // started and working
PendingStop, // stop pending
PendingRemove, // remove pending
SurpriseRemoved, // removed by surprise
Removed // removed
} DEVSTATE;
typedef enum _QUEUE_STATE {
HoldRequests, // device is not started yet
AllowRequests, // device is ready to process
FailRequests // fail both existing and queued up requests
} QUEUE_STATE;
typedef enum _WDM_VERSION {
WinXpOrBetter,
Win2kOrBetter,
WinMeOrBetter,
Win98OrBetter
} WDM_VERSION;
#define INITIALIZE_PNP_STATE(_Data_) \
(_Data_)->DeviceState = NotStarted;\
(_Data_)->PrevDevState = NotStarted;
#define SET_NEW_PNP_STATE(_Data_, _state_) \
(_Data_)->PrevDevState = (_Data_)->DeviceState;\
(_Data_)->DeviceState = (_state_);
#define RESTORE_PREVIOUS_PNP_STATE(_Data_) \
(_Data_)->DeviceState = (_Data_)->PrevDevState;
#define BULKUSB_MAX_TRANSFER_SIZE 256
#define BULKUSB_TEST_BOARD_TRANSFER_BUFFER_SIZE (64 *1024 )
//
// registry path used for parameters
// global to all instances of the driver
//
#define BULKUSB_REGISTRY_PARAMETERS_PATH \
L"\\REGISTRY\\Machine\\System\\CurrentControlSet\\SERVICES\\BULKUSB\\Parameters"
typedef struct _BULKUSB_PIPE_CONTEXT {
BOOLEAN PipeOpen;
} BULKUSB_PIPE_CONTEXT, *PBULKUSB_PIPE_CONTEXT;
//
// A structure representing the instance information associated with
// this particular device.
//
typedef struct _DEVICE_EXTENSION {
// Functional Device Object
PDEVICE_OBJECT FunctionalDeviceObject;
// Device object we call when submitting Urbs
PDEVICE_OBJECT TopOfStackDeviceObject;
// The bus driver object
PDEVICE_OBJECT PhysicalDeviceObject;
// Name buffer for our named Functional device object link
// The name is generated based on the driver's class GUID
UNICODE_STRING InterfaceName;
// Bus drivers set the appropriate values in this structure in response
// to an IRP_MN_QUERY_CAPABILITIES IRP. Function and filter drivers might
// alter the capabilities set by the bus driver.
DEVICE_CAPABILITIES DeviceCapabilities;
// Configuration Descriptor
PUSB_CONFIGURATION_DESCRIPTOR UsbConfigurationDescriptor;
// Interface Information structure
PUSBD_INTERFACE_INFORMATION UsbInterface;
// Pipe context for the bulkusb driver
PBULKUSB_PIPE_CONTEXT PipeContext;
// current state of device
DEVSTATE DeviceState;
// state prior to removal query
DEVSTATE PrevDevState;
// obtain and hold this lock while changing the device state,
// the queue state and while processing the queue.
KSPIN_LOCK DevStateLock;
// current system power state
SYSTEM_POWER_STATE SysPower;
// current device power state
DEVICE_POWER_STATE DevPower;
// Pending I/O queue state
QUEUE_STATE QueueState;
// Pending I/O queue
LIST_ENTRY NewRequestsQueue;
// I/O Queue Lock
KSPIN_LOCK QueueLock;
KEVENT RemoveEvent;
KEVENT StopEvent;
ULONG OutStandingIO;
KSPIN_LOCK IOCountLock;
// selective suspend variables
LONG SSEnable;
LONG SSRegistryEnable;
PUSB_IDLE_CALLBACK_INFO IdleCallbackInfo;
PIRP PendingIdleIrp;
LONG IdleReqPend;
LONG FreeIdleIrpCount;
KSPIN_LOCK IdleReqStateLock;
KEVENT NoIdleReqPendEvent;
// default power state to power down to on self-susped
ULONG PowerDownLevel;
// remote wakeup variables
PIRP WaitWakeIrp;
LONG FlagWWCancel;
LONG FlagWWOutstanding;
LONG WaitWakeEnable;
// open handle count
LONG OpenHandleCount;
// selective suspend model uses timers, dpcs and work item.
KTIMER Timer;
KDPC DeferredProcCall;
// This event is cleared when a DPC/Work Item is queued.
// and signaled when the work-item completes.
// This is essential to prevent the driver from unloading
// while we have DPC or work-item queued up.
KEVENT NoDpcWorkItemPendingEvent;
// WMI information
WMILIB_CONTEXT WmiLibInfo;
// WDM version
WDM_VERSION WdmVersion;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
typedef struct _IRP_COMPLETION_CONTEXT {
PDEVICE_EXTENSION DeviceExtension;
PKEVENT Event;
} IRP_COMPLETION_CONTEXT, *PIRP_COMPLETION_CONTEXT;
extern GLOBALS Globals;
extern ULONG DebugLevel;
#endif