1 /*++
2 
3 Copyright (c) Microsoft Corporation.  All rights reserved.
4 
5 Module Name:
6 
7     FxRequestContext.hpp
8 
9 Abstract:
10 
11     Defines the base structure for contexts associated with FxRequest
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19     Both kernel and user mode
20 
21 Revision History:
22 
23 --*/
24 
25 #ifndef _FXREQUESTCONTEXT_H_
26 #define _FXREQUESTCONTEXT_H_
27 
28 typedef UCHAR FX_REQUEST_CONTEXT_TYPE;
29 
30 //
31 // IO_STACK_LOCATION::Parameters.Others.Argument3 is taken up by the IOCTL
32 // value, so there are only 3
33 //
34 #define FX_REQUEST_NUM_OTHER_PARAMS (3)
35 
36 //
37 // Here are all the derivations off of FxRequestContext
38 //
39 // FxIoContext
40 // FxInternalIoctlOthersContext
41 // FxUsbRequestContext
42 //   +FxUsbDeviceVendorContext
43 //   +FxUsbDeviceStatusContext
44 //   +FxUsbDeviceFeatureContext
45 //   +FxUsbPipeTransferContext
46 //   +FxUsbUrbContext
47 //   +FxUsbPipeRequestContext
48 //   +FxUsbPipeControlTransferContext
49 //
50 
51 typedef struct _FxInternalIoctlParams{
52     WDFMEMORY  Argument1;
53     WDFMEMORY  Argument2;
54     WDFMEMORY  Argument4;
55 }FxInternalIoctlParams,*pFxInternalIoctlParams;
56 
57 struct FxRequestContext : public FxStump {
58 
59     FxRequestContext(
60         __in FX_REQUEST_CONTEXT_TYPE Type
61         );
62 
63     virtual
64     ~FxRequestContext(
65         VOID
66         );
67 
68     virtual
69     VOID
DisposeFxRequestContext70     Dispose(
71         VOID
72         )
73     {}
74 
75     virtual
76     VOID
77     StoreAndReferenceMemory(
78         __in FxRequestBuffer* Buffer
79         );
80 
81     virtual
82     VOID
83     ReleaseAndRestore(
84         __in FxRequestBase* Request
85         );
86 
87     __inline
88     BOOLEAN
IsTypeFxRequestContext89     IsType(
90         __in FX_REQUEST_CONTEXT_TYPE Type
91         )
92     {
93         return m_RequestType == Type;
94     }
95 
96     virtual
97     VOID
CopyParametersFxRequestContext98     CopyParameters(
99         __in FxRequestBase* Request
100         )
101     {
102         UNREFERENCED_PARAMETER(Request);
103     }
104 
105     VOID
106     FormatWriteParams(
107         __in_opt IFxMemory* WriteMemory,
108         __in_opt PWDFMEMORY_OFFSET WriteOffsets
109         );
110 
111     VOID
112     FormatReadParams(
113         __in_opt IFxMemory* ReadMemory,
114         __in_opt PWDFMEMORY_OFFSET ReadOffsets
115         );
116 
117     VOID
118     FormatOtherParams(
119         __in FxInternalIoctlParams *InternalIoctlParams
120         );
121 
122 protected:
123     static
124     VOID
125     _StoreAndReferenceMemoryWorker(
126         __in PVOID Tag,
127         __deref_out_opt IFxMemory** PPMemory,
128         __in FxRequestBuffer* Buffer
129         );
130 
131     VOID
132     __inline
InitCompletionParamsFxRequestContext133     InitCompletionParams(
134         VOID
135         )
136     {
137         WDF_REQUEST_COMPLETION_PARAMS_INIT(&m_CompletionParams);
138         m_CompletionParams.Type = WdfRequestTypeNoFormat;
139     }
140 
141 public:
142     WDF_REQUEST_COMPLETION_PARAMS m_CompletionParams;
143 
144     //
145     // Memory associated with the context that will be released when the
146     // FxRequestBase has been completed by the target.
147     //
148     IFxMemory* m_RequestMemory;
149 
150     //
151     // RTTI replacement
152     //
153     FX_REQUEST_CONTEXT_TYPE m_RequestType;
154 };
155 
156 #endif // _FXREQUESTCONTEXT_H_
157