[dummy,aoe] Move dummy creation IOCTL setup from AoE
[people/sha0/winvblock.git] / src / include / dummy.h
1 /**
2  * Copyright (C) 2010-2011, Shao Miller <shao.miller@yrdsb.edu.on.ca>.
3  *
4  * This file is part of WinVBlock, originally derived from WinAoE.
5  *
6  * WinVBlock is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * WinVBlock is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with WinVBlock.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef WV_M_DUMMY_H_
20 #  define WV_M_DUMMY_H_
21
22 /**
23  * @file
24  *
25  * Dummy device specifics.
26  */
27
28 #  define IOCTL_WV_DUMMY    \
29 CTL_CODE(                   \
30     FILE_DEVICE_CONTROLLER, \
31     0x806,                  \
32     METHOD_IN_DIRECT,       \
33     FILE_WRITE_DATA         \
34   )
35
36 /* PnP IDs for a dummy device. */
37 typedef struct WV_DUMMY_IDS {
38     UINT32 DevOffset;
39     UINT32 DevLen;
40     UINT32 InstanceOffset;
41     UINT32 InstanceLen;
42     UINT32 HardwareOffset;
43     UINT32 HardwareLen;
44     UINT32 CompatOffset;
45     UINT32 CompatLen;
46     UINT32 Len;
47     UINT32 Offset;
48     DEVICE_TYPE DevType;
49     ULONG DevCharacteristics;
50   } WV_S_DUMMY_IDS, * WV_SP_DUMMY_IDS;
51
52 /* Macro support for dummy ID generation. */
53 #define WV_M_DUMMY_IDS_ENUM(prefix_, name_, literal_)             \
54   prefix_ ## name_ ## Offset_,                                    \
55   prefix_ ## name_ ## Len_ = sizeof (literal_) / sizeof (WCHAR),  \
56   prefix_ ## name_ ## End_ =                                      \
57     prefix_ ## name_ ## Offset_ + prefix_ ## name_ ## Len_ - 1,
58
59 #define WV_M_DUMMY_IDS_LITERALS(dev_id_, inst_id_, hard_id_, compat_id_) \
60   dev_id_ L"\0" inst_id_ L"\0" hard_id_ L"\0" compat_id_
61
62 #define WV_M_DUMMY_IDS_FILL(prefix_, name_) \
63   prefix_ ## name_ ## Offset_,              \
64   prefix_ ## name_ ## Len_,
65
66 /**
67  * Generate a static const WV_S_DUMMY_IDS object.
68  *
69  * @v Qualifiers        Such as 'static const', perhaps.
70  * @v Name              The name of the desired object.  Also used as prefix.
71  * @v DevId             The device ID.
72  * @v InstanceId        The instance ID.
73  * @v HardwareId        The hardware ID(s).
74  * @v CompatId          Compatible ID(s).
75  * @v DevType           The device type for the dummy PDO.
76  * @v DevCharacts       The device characteristics for the dummy PDO.
77  *
78  * This macro will produce the following:
79  *   enum values:
80  *     [Name]DevOffset_
81  *     [Name]DevLen_
82  *     [Name]DevEnd_
83  *     [Name]InstanceOffset_
84  *     [Name]InstanceLen_
85  *     [Name]InstanceEnd_
86  *     [Name]HardwareOffset_
87  *     [Name]HardwareLen_
88  *     [Name]HardwareEnd_
89  *     [Name]CompatOffset_
90  *     [Name]CompatLen_
91  *     [Name]CompatEnd_
92  *     [Name]Len_
93  *   [Qualifiers] WV_S_DUMMY_IDS:
94  *     [Name]
95  */
96 #define WV_M_DUMMY_ID_GEN(                                            \
97     Qualifiers,                                                       \
98     Name,                                                             \
99     DevId,                                                            \
100     InstanceId,                                                       \
101     HardwareId,                                                       \
102     CompatId,                                                         \
103     DevType,                                                          \
104     DevCharacts                                                       \
105   )                                                                   \
106                                                                       \
107 enum {                                                                \
108     WV_M_DUMMY_IDS_ENUM(Name, Dev, DevId)                             \
109     WV_M_DUMMY_IDS_ENUM(Name, Instance, InstanceId)                   \
110     WV_M_DUMMY_IDS_ENUM(Name, Hardware, HardwareId)                   \
111     WV_M_DUMMY_IDS_ENUM(Name, Compat, CompatId)                       \
112     Name ## Len_                                                      \
113   };                                                                  \
114                                                                       \
115 struct Name ## Struct_ {                                              \
116     WV_S_DUMMY_IDS DummyIds;                                          \
117     WCHAR Ids[Name ## Len_];                                          \
118   };                                                                  \
119 Qualifiers struct Name ## Struct_ Name = {                            \
120     {                                                                 \
121         WV_M_DUMMY_IDS_FILL(Name, Dev)                                \
122         WV_M_DUMMY_IDS_FILL(Name, Instance)                           \
123         WV_M_DUMMY_IDS_FILL(Name, Hardware)                           \
124         WV_M_DUMMY_IDS_FILL(Name, Compat)                             \
125         sizeof (struct Name ## Struct_),                              \
126         FIELD_OFFSET(struct Name ## Struct_, Ids),                    \
127         DevType,                                                      \
128         DevCharacts,                                                  \
129       },                                                              \
130     WV_M_DUMMY_IDS_LITERALS(DevId, InstanceId, HardwareId, CompatId), \
131   }
132
133 extern WVL_M_LIB NTSTATUS STDCALL WvDummyAdd(IN const WV_S_DUMMY_IDS *);
134 extern WVL_M_LIB NTSTATUS STDCALL WvDummyRemove(IN PDEVICE_OBJECT);
135 extern NTSTATUS STDCALL WvDummyIoctl(IN PIRP);
136
137 #endif  /* WV_M_DUMMY_H_ */