1 /***********************************************************************\
2 *                                 snmp.d                                *
3 *                                                                       *
4 *                       Windows API header module                       *
5 *                                                                       *
6 *                 Translated from MinGW Windows headers                 *
7 *                           by Stewart Gordon                           *
8 *                                                                       *
9 *                       Placed into public domain                       *
10 \***********************************************************************/
11 module win32.snmp;
12 version(Windows):
13 
14 private import win32.windows;
15 
16 // These are not documented on MSDN
17 enum {
18 	DEFAULT_SNMP_PORT_UDP     =   161,
19 	DEFAULT_SNMP_PORT_IPX     = 36879,
20 	DEFAULT_SNMPTRAP_PORT_UDP =   162,
21 	DEFAULT_SNMPTRAP_PORT_IPX = 36880
22 }
23 
24 enum : BYTE {
25 	ASN_UNIVERSAL                 = 0x00,
26 	ASN_PRIMITIVE                 = 0x00,
27 	ASN_CONSTRUCTOR               = 0x20,
28 	ASN_APPLICATION               = 0x40,
29 	ASN_CONTEXT                   = 0x80,
30 	ASN_PRIVATE                   = 0xC0,
31 
32 	SNMP_PDU_GET                  = ASN_CONTEXT | ASN_CONSTRUCTOR,
33 	SNMP_PDU_GETNEXT,
34 	SNMP_PDU_RESPONSE,
35 	SNMP_PDU_SET,
36 	SNMP_PDU_GETBULK,          // = ASN_CONTEXT | ASN_CONSTRUCTOR | 4
37 	SNMP_PDU_V1TRAP               = ASN_CONTEXT | ASN_CONSTRUCTOR | 4,
38 	SNMP_PDU_INFORM               = ASN_CONTEXT | ASN_CONSTRUCTOR | 6,
39 	SNMP_PDU_TRAP,
40 	SNMP_PDU_REPORT,
41 	ASN_INTEGER                   = ASN_UNIVERSAL | ASN_PRIMITIVE | 2,
42 	ASN_BITS,
43 	ASN_OCTETSTRING,
44 	ASN_NULL,
45 	ASN_OBJECTIDENTIFIER,      // = ASN_UNIVERSAL | ASN_PRIMITIVE | 6
46 	ASN_INTEGER32                 = ASN_INTEGER,
47 	ASN_SEQUENCE                  = ASN_UNIVERSAL | ASN_CONSTRUCTOR | 0x10,
48 	ASN_SEQUENCEOF                = ASN_SEQUENCE,
49 	ASN_IPADDRESS                 = ASN_APPLICATION | ASN_PRIMITIVE,
50 	ASN_COUNTER32,
51 	ASN_GAUGE32,
52 	ASN_TIMETICKS,
53 	ASN_OPAQUE,                // = ASN_APPLICATION | ASN_PRIMITIVE | 4
54 	ASN_COUNTER64                 = ASN_APPLICATION | ASN_PRIMITIVE | 6,
55 	ASN_UNSIGNED32,            // = ASN_APPLICATION | ASN_PRIMITIVE | 7
56 	SNMP_EXCEPTION_NOSUCHOBJECT   = ASN_CONTEXT | ASN_PRIMITIVE,
57 	SNMP_EXCEPTION_NOSUCHINSTANCE,
58 	SNMP_EXCEPTION_ENDOFMIBVIEW,
59 	SNMP_EXTENSION_GET            = SNMP_PDU_GET,
60 	SNMP_EXTENSION_GET_NEXT       = SNMP_PDU_GETNEXT,
61 	SNMP_EXTENSION_GET_BULK       = SNMP_PDU_GETBULK,
62 	SNMP_EXTENSION_SET_TEST       = ASN_PRIVATE | ASN_CONSTRUCTOR,
63 	SNMP_EXTENSION_SET_COMMIT     = SNMP_PDU_SET,
64 	SNMP_EXTENSION_SET_UNDO       = ASN_PRIVATE | ASN_CONSTRUCTOR | 1,
65 	SNMP_EXTENSION_SET_CLEANUP
66 }
67 
68 
69 enum : AsnInteger {
70 	SNMP_ERRORSTATUS_NOERROR,
71 	SNMP_ERRORSTATUS_TOOBIG,
72 	SNMP_ERRORSTATUS_NOSUCHNAME,
73 	SNMP_ERRORSTATUS_BADVALUE,
74 	SNMP_ERRORSTATUS_READONLY,
75 	SNMP_ERRORSTATUS_GENERR,
76 	SNMP_ERRORSTATUS_NOACCESS,
77 	SNMP_ERRORSTATUS_WRONGTYPE,
78 	SNMP_ERRORSTATUS_WRONGLENGTH,
79 	SNMP_ERRORSTATUS_WRONGENCODING,
80 	SNMP_ERRORSTATUS_WRONGVALUE,
81 	SNMP_ERRORSTATUS_NOCREATION,
82 	SNMP_ERRORSTATUS_INCONSISTENTVALUE,
83 	SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE,
84 	SNMP_ERRORSTATUS_COMMITFAILED,
85 	SNMP_ERRORSTATUS_UNDOFAILED,
86 	SNMP_ERRORSTATUS_AUTHORIZATIONERROR,
87 	SNMP_ERRORSTATUS_NOTWRITABLE,
88 	SNMP_ERRORSTATUS_INCONSISTENTNAME
89 }
90 
91 enum : AsnInteger {
92 	SNMP_GENERICTRAP_COLDSTART,
93 	SNMP_GENERICTRAP_WARMSTART,
94 	SNMP_GENERICTRAP_LINKDOWN,
95 	SNMP_GENERICTRAP_LINKUP,
96 	SNMP_GENERICTRAP_AUTHFAILURE,
97 	SNMP_GENERICTRAP_EGPNEIGHLOSS,
98 	SNMP_GENERICTRAP_ENTERSPECIFIC
99 }
100 
101 // These are not documented on MSDN
102 enum {
103 	SNMP_ACCESS_NONE,
104 	SNMP_ACCESS_NOTIFY,
105 	SNMP_ACCESS_READ_ONLY,
106 	SNMP_ACCESS_READ_WRITE,
107 	SNMP_ACCESS_READ_CREATE
108 }
109 
110 enum : BOOL {
111 	SNMPAPI_ERROR   = false,
112 	SNMPAPI_NOERROR = true
113 }
114 
115 enum : INT {
116 	SNMP_LOG_SILENT,
117 	SNMP_LOG_FATAL,
118 	SNMP_LOG_ERROR,
119 	SNMP_LOG_WARNING,
120 	SNMP_LOG_TRACE,
121 	SNMP_LOG_VERBOSE
122 }
123 
124 const INT
125 	SNMP_OUTPUT_TO_CONSOLE  = 1,
126 	SNMP_OUTPUT_TO_LOGFILE  = 2,
127 	SNMP_OUTPUT_TO_EVENTLOG = 4,
128 	SNMP_OUTPUT_TO_DEBUGGER = 8;
129 
130 const size_t SNMP_MAX_OID_LEN = 128;
131 
132 enum : DWORD {
133 	SNMP_MEM_ALLOC_ERROR          =  1,
134 	SNMP_BERAPI_INVALID_LENGTH    = 10,
135 	SNMP_BERAPI_INVALID_TAG,
136 	SNMP_BERAPI_OVERFLOW,
137 	SNMP_BERAPI_SHORT_BUFFER,
138 	SNMP_BERAPI_INVALID_OBJELEM,
139 	SNMP_PDUAPI_UNRECOGNIZED_PDU  = 20,
140 	SNMP_PDUAPI_INVALID_ES,
141 	SNMP_PDUAPI_INVALID_GT,
142 	SNMP_AUTHAPI_INVALID_VERSION  = 30,
143 	SNMP_AUTHAPI_INVALID_MSG_TYPE,
144 	SNMP_AUTHAPI_TRIV_AUTH_FAILED,
145 }
146 
147 alias INT SNMPAPI;
148 alias LONG AsnInteger32;
149 alias ULONG AsnUnsigned32, AsnCounter32, AsnGauge32, AsnTimeticks;
150 alias ULARGE_INTEGER AsnCounter64;
151 
152 align (4):
153 
154 struct AsnOctetString {
155 	BYTE* stream;
156 	UINT  length;
157 	BOOL  dynamic;
158 }
159 alias AsnOctetString AsnBits, AsnSequence, AsnImplicitSequence,
160   AsnIPAddress, AsnNetworkAddress, AsnDisplayString, AsnOpaque;
161 
162 struct AsnObjectIdentifier {
163 	UINT  idLength;
164 	UINT* ids;
165 }
166 alias AsnObjectIdentifier AsnObjectName;
167 
168 struct AsnAny {
169 	BYTE      asnType;
170 	union _asnValue {
171 		AsnInteger32        number;
172 		AsnUnsigned32       unsigned32;
173 		AsnCounter64        counter64;
174 		AsnOctetString      string;
175 		AsnBits             bits;
176 		AsnObjectIdentifier object;
177 		AsnSequence         sequence;
178 		AsnIPAddress        address;
179 		AsnCounter32        counter;
180 		AsnGauge32          gauge;
181 		AsnTimeticks        ticks;
182 		AsnOpaque           arbitrary;
183 	}
184 	_asnValue asnValue;
185 }
186 alias AsnAny AsnObjectSyntax;
187 
188 struct SnmpVarBind {
189 	AsnObjectName   name;
190 	AsnObjectSyntax value;
191 }
192 
193 struct SnmpVarBindList {
194 	SnmpVarBind* list;
195 	UINT         len;
196 }
197 
198 extern (Windows) {
199 	VOID SnmpExtensionClose();
200 	BOOL SnmpExtensionInit(DWORD, HANDLE*, AsnObjectIdentifier*);
201 	BOOL SnmpExtensionInitEx(AsnObjectIdentifier*);
202 	BOOL SnmpExtensionMonitor(LPVOID);
203 	BOOL SnmpExtensionQuery(BYTE, SnmpVarBindList*, AsnInteger32*,
204 	  AsnInteger32*);
205 	BOOL SnmpExtensionQueryEx(DWORD, DWORD, SnmpVarBindList*, AsnOctetString*,
206 	  AsnInteger32*, AsnInteger32*);
207 	BOOL SnmpExtensionTrap(AsnObjectIdentifier*, AsnInteger32*, AsnInteger32*,
208 	  AsnTimeticks*, SnmpVarBindList*);
209 	DWORD SnmpSvcGetUptime();
210 	VOID SnmpSvcSetLogLevel(INT);
211 	VOID SnmpSvcSetLogType(INT);
212 	SNMPAPI SnmpUtilAsnAnyCpy(AsnAny*, AsnAny*);
213 	VOID SnmpUtilAsnAnyFree(AsnAny*);
214 	VOID SnmpUtilDbgPrint(INT, LPSTR, ...);
215 	LPSTR SnmpUtilIdsToA(UINT*, UINT);
216 	LPVOID SnmpUtilMemAlloc(UINT);
217 	VOID SnmpUtilMemFree(LPVOID);
218 	LPVOID SnmpUtilMemReAlloc(LPVOID, UINT);
219 	SNMPAPI SnmpUtilOctetsCmp(AsnOctetString*, AsnOctetString*);
220 	SNMPAPI SnmpUtilOctetsCpy(AsnOctetString*, AsnOctetString*);
221 	VOID SnmpUtilOctetsFree(AsnOctetString*);
222 	SNMPAPI SnmpUtilOctetsNCmp(AsnOctetString*, AsnOctetString*, UINT);
223 	SNMPAPI SnmpUtilOidAppend(AsnObjectIdentifier*, AsnObjectIdentifier*);
224 	SNMPAPI SnmpUtilOidCmp(AsnObjectIdentifier*, AsnObjectIdentifier*);
225 	SNMPAPI SnmpUtilOidCpy(AsnObjectIdentifier*, AsnObjectIdentifier*);
226 	VOID SnmpUtilOidFree(AsnObjectIdentifier*);
227 	SNMPAPI SnmpUtilOidNCmp(AsnObjectIdentifier*, AsnObjectIdentifier*, UINT);
228 	LPSTR SnmpUtilOidToA(AsnObjectIdentifier*);
229 	VOID SnmpUtilPrintAsnAny(AsnAny*);
230 	VOID SnmpUtilPrintOid(AsnObjectIdentifier*);
231 	SNMPAPI SnmpUtilVarBindCpy(SnmpVarBind*, SnmpVarBind*);
232 	SNMPAPI SnmpUtilVarBindListCpy(SnmpVarBindList*, SnmpVarBindList*);
233 	VOID SnmpUtilVarBindFree(SnmpVarBind*);
234 	VOID SnmpUtilVarBindListFree(SnmpVarBindList*);
235 }
236 
237 alias SnmpUtilMemAlloc SNMP_malloc;
238 alias SnmpUtilMemFree SNMP_free;
239 alias SnmpUtilMemReAlloc SNMP_realloc;
240 alias SnmpUtilMemAlloc SNMP_DBG_malloc;
241 alias SnmpUtilMemFree SNMP_DBG_free;
242 alias SnmpUtilMemReAlloc SNMP_DBG_realloc;
243 alias SnmpUtilOidAppend SNMP_oidappend;
244 alias SnmpUtilOidCmp SNMP_oidcmp;
245 alias SnmpUtilOidCpy SNMP_oidcpy;
246 alias SnmpUtilOidFree SNMP_oidfree;
247 alias SnmpUtilOidNCmp SNMP_oidncmp;
248 alias SnmpUtilPrintAsnAny SNMP_printany;
249 alias SnmpUtilVarBindCpy SNMP_CopyVarBind;
250 alias SnmpUtilVarBindListCpy SNMP_CopyVarBindList;
251 alias SnmpUtilVarBindFree SNMP_FreeVarBind;
252 alias SnmpUtilVarBindListFree SNMP_FreeVarBindList;
253 alias ASN_IPADDRESS ASN_RFC1155_IPADDRESS;
254 alias ASN_COUNTER32 ASN_RFC1155_COUNTER;
255 alias ASN_GAUGE32 ASN_RFC1155_GAUGE;
256 alias ASN_TIMETICKS ASN_RFC1155_TIMETICKS;
257 alias ASN_OPAQUE ASN_RFC1155_OPAQUE;
258 alias ASN_OCTETSTRING ASN_RFC1213_DISPSTRING;
259 alias SNMP_PDU_GET ASN_RFC1157_GETREQUEST;
260 alias SNMP_PDU_GETNEXT ASN_RFC1157_GETNEXTREQUEST;
261 alias SNMP_PDU_RESPONSE ASN_RFC1157_GETRESPONSE;
262 alias SNMP_PDU_SET ASN_RFC1157_SETREQUEST;
263 alias SNMP_PDU_V1TRAP ASN_RFC1157_TRAP;
264 alias ASN_CONTEXT ASN_CONTEXTSPECIFIC;
265 alias ASN_PRIMITIVE ASN_PRIMATIVE;
266 alias SnmpVarBindList RFC1157VarBindList;
267 alias SnmpVarBind RFC1157VarBind;
268 alias AsnInteger32 AsnInteger;
269 alias AsnCounter32 AsnCounter;
270 alias AsnGauge32 AsnGauge;