Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

391 lines
13 KiB

  1. /*
  2. * gennt.h v0.15 March 21, 1996
  3. *
  4. ****************************************************************************
  5. * *
  6. * (C) Copyright 1995 DIGITAL EQUIPMENT CORPORATION *
  7. * *
  8. * This software is an unpublished work protected under the *
  9. * the copyright laws of the United States of America, all *
  10. * rights reserved. *
  11. * *
  12. * In the event this software is licensed for use by the United *
  13. * States Government, all use, duplication or disclosure by the *
  14. * United States Government is subject to restrictions as set *
  15. * forth in either subparagraph (c)(1)(ii) of the Rights in *
  16. * Technical Data And Computer Software Clause at DFARS *
  17. * 252.227-7013, or the Commercial Computer Software Restricted *
  18. * Rights Clause at FAR 52.221-19, whichever is applicable. *
  19. * *
  20. ****************************************************************************
  21. *
  22. * Facility:
  23. *
  24. * SNMP Extension Agent
  25. *
  26. * Abstract:
  27. *
  28. * Agent.
  29. *
  30. * This module contains the definitions for the table driven SNMP dlls.
  31. *
  32. * Author:
  33. * Miriam Amos Nihart, Kathy Faust
  34. *
  35. * Date:
  36. * 2/17/95
  37. *
  38. * Revision History:
  39. * v0.11 11/15/95 ags added mib-2 definitions.
  40. * v0.12 Feb 14, 1996 ags changed SMIGet/SetBoolean to SMIGet/SetNSMBoolean
  41. * v0.13 Mar 12, 1996 kkf revised trap_control_block so that VarBindList
  42. * is built prior to queuing to the trap_queue
  43. * v0.14 Mar 19, 1996 kkf fixed numerous trap related bugs
  44. * v0.15 Mar 22, 1996 kkf fixed mib-2 code definition (should be 1 not 2)
  45. *
  46. */
  47. #ifndef gennt_h
  48. #define gennt_h
  49. // Necessary includes.
  50. #include <snmp.h>
  51. #include <stdlib.h>
  52. #include <malloc.h>
  53. #include <memory.h>
  54. #include <string.h>
  55. // MIB function actions.
  56. #define MIB_ACTION_GET ASN_RFC1157_GETREQUEST
  57. #define MIB_ACTION_SET ASN_RFC1157_SETREQUEST
  58. #define MIB_ACTION_GETNEXT ASN_RFC1157_GETNEXTREQUEST
  59. typedef enum
  60. { NSM_READ_ONLY, NSM_WRITE_ONLY, NSM_READ_WRITE, NSM_NO_ACCESS } access_mode_t ;
  61. typedef enum
  62. {
  63. NON_TABLE = 0 ,
  64. TABLE = 1
  65. } table_type_t ;
  66. typedef int (* PF)() ;
  67. typedef void (* PFV)() ;
  68. //
  69. // The variable structure is used to construct the variable table.
  70. // Each variable is represented by an entry in the table. The table
  71. // driven design indexes into the table to access information specific
  72. // to the variable, such as its oid, access, get and set routines.
  73. // "Holes" in the sequence of variables are represented by NULL entries.
  74. //
  75. typedef struct variable
  76. {
  77. AsnObjectIdentifier *oid ;
  78. BYTE type ;
  79. access_mode_t access_mode ;
  80. PF VarGet ;
  81. PF VarSet ;
  82. PF SMIGet ;
  83. PF SMISet ;
  84. } variable_t ;
  85. //
  86. // The class structure is used to construct the class_info table. It
  87. // is this table that represents the groups composing the mib view of
  88. // this dll. The table driven design uses this table in conjuction
  89. // with the variable tables to process the SNMP requests.
  90. //
  91. typedef struct class
  92. {
  93. table_type_t table ;
  94. AsnObjectIdentifier *oid ;
  95. unsigned long int var_index ;
  96. unsigned long int min_index ;
  97. unsigned long int max_index ;
  98. PF FindInstance ;
  99. PF FindNextInstance ;
  100. PF ConvertInstance ;
  101. PFV FreeInstance ;
  102. variable_t *variable ;
  103. } class_t ;
  104. //
  105. // The trap structure is used to construct the trap_info table. It
  106. // is this table that represents the trap for this mib view. The
  107. // table driven design uses this table to process the trap. A event
  108. // is sent to tell the Extendible Agent to call this dll's SnmpExtensionTrap
  109. // routine to "collect" a trap. This routine dequeues a trap from the
  110. // trap queue and then indexes into the trap_info table to fill in the
  111. // trap information for the trap pdu.
  112. //
  113. typedef struct trap_variable
  114. {
  115. AsnObjectIdentifier *oid ;
  116. PF SMIBuild ;
  117. } tvt_t ;
  118. typedef struct trap
  119. {
  120. AsnObjectIdentifier *oid ; /* enterprise OID */
  121. AsnInteger type ; /* SNMP_GENERICTRAP_ENTERSPECIFIC */
  122. AsnInteger specific ; /* trap value */
  123. UINT number_of_variables ;
  124. tvt_t *variables ;
  125. } trap_t ;
  126. typedef struct q_hdr
  127. {
  128. char *lifo_a ;
  129. char *fifo_a ;
  130. } q_hdr_t ;
  131. typedef struct trap_control_block
  132. {
  133. q_hdr_t chain_q ;
  134. AsnObjectIdentifier enterprise ;
  135. AsnInteger genericTrap ;
  136. AsnInteger specificTrap ;
  137. AsnTimeticks timeStamp ;
  138. RFC1157VarBindList varBindList ;
  139. } tcb_t ;
  140. //
  141. // Definitions of the oid sequence : 1.3.6.1.4.1.36.2 also described as:
  142. // iso.memberbody.dod.internet.mib.private.dec.ema
  143. //
  144. #define ISO_CODE 1
  145. #define ISO 1
  146. #define ISO_SEQ ISO_CODE
  147. #define ISO_LENGTH 1
  148. #define ORG_CODE 3
  149. #define ORG 3
  150. #define ORG_SEQ ISO_SEQ, ORG_CODE
  151. #define ORG_LENGTH ( ISO_LENGTH + 1 )
  152. #define DOD_CODE 6
  153. #define DOD 6
  154. #define DOD_SEQ ORG_SEQ, DOD_CODE
  155. #define DOD_LENGTH ( ORG_LENGTH + 1 )
  156. #define INTERNET_CODE 1
  157. #define INTERNET 1
  158. #define INTERNET_SEQ DOD_SEQ, INTERNET_CODE
  159. #define INTERNET_LENGTH ( DOD_LENGTH + 1 )
  160. #define DIRECTORY_CODE 1
  161. #define DIRECTORY 1
  162. #define DIRECTORY_SEQ INTERNET_SEQ, DIRECTORY_CODE
  163. #define DIRECTORY_LENGTH ( INTERNET_LENGTH + 1 )
  164. #define MGMT_CODE 2
  165. #define MGMT 2
  166. #define MGMT_SEQ INTERNET_SEQ, MGMT_CODE
  167. #define MGMT_LENGTH ( INTERNET_LENGTH + 1 )
  168. #define EXPERIMENTAL_CODE 3
  169. #define EXPERIMENTAL 3
  170. #define EXPERIMENTAL_SEQ INTERNET_SEQ, EXPERIMENTAL_CODE
  171. #define EXPERIMENTAL_LENGTH ( INTERNET_LENGTH + 1 )
  172. #define PRIVATE_CODE 4
  173. #define PRIVATE 4
  174. #define PRIVATE_SEQ INTERNET_SEQ, PRIVATE_CODE
  175. #define PRIVATE_LENGTH ( INTERNET_LENGTH + 1 )
  176. #define ENTERPRISES_CODE 1
  177. #define ENTERPRISES 1
  178. #define ENTERPRISES_SEQ PRIVATE_SEQ, ENTERPRISES_CODE
  179. #define ENTERPRISES_LENGTH ( PRIVATE_LENGTH + 1 )
  180. #define DEC_CODE 36
  181. #define DEC 36
  182. #define DEC_SEQ ENTERPRISES_SEQ, DEC_CODE
  183. #define DEC_LENGTH ( ENTERPRISES_LENGTH + 1 )
  184. #define EMA_CODE 2
  185. #define EMA 2
  186. #define EMA_SEQ DEC_SEQ, EMA_CODE
  187. #define EMA_LENGTH ( DEC_LENGTH + 1 )
  188. #define MIB_2_CODE 1
  189. #define MIB_2 2
  190. #define MIB_2_SEQ MGMT_SEQ, MIB_2_CODE
  191. #define MIB_2_LENGTH ( MGMT_LENGTH + 1 )
  192. //
  193. // Macros
  194. //
  195. #define SUCCESS 1
  196. #define FAILURE 0
  197. #define CHECK_VARIABLE( VarBind, cindex, vindex, status ) \
  198. { \
  199. if ( VarBind->name.idLength > class_info[ cindex ].var_index ) \
  200. { \
  201. vindex = VarBind->name.ids[ class_info[ cindex ].var_index - 1 ] ; \
  202. if ( ( vindex >= class_info[ cindex ].min_index ) && \
  203. ( vindex <= class_info[ cindex ].max_index ) ) \
  204. status = SUCCESS ; \
  205. else \
  206. status = FAILURE ; \
  207. } \
  208. else \
  209. status = FAILURE ; \
  210. }
  211. #define CHECK_ACCESS( cindex, vindex, PduAction, status ) \
  212. { \
  213. access_mode_t tmp ; \
  214. \
  215. tmp = class_info[ cindex ].variable[ vindex ].access_mode ; \
  216. if ( PduAction == MIB_ACTION_SET ) \
  217. { \
  218. if ( ( tmp == NSM_WRITE_ONLY ) || ( tmp == NSM_READ_WRITE ) ) \
  219. status = SUCCESS ; \
  220. else \
  221. status = FAILURE ; \
  222. } \
  223. else \
  224. { \
  225. if ( ( tmp == NSM_READ_ONLY ) || ( tmp == NSM_READ_WRITE ) ) \
  226. status = SUCCESS ; \
  227. else \
  228. status = FAILURE ; \
  229. } \
  230. }
  231. //
  232. // These macros are used by the trap logic. There is only one queue
  233. // used by the generic code - a trap queue. These macros can be used
  234. // elsewhere. The macros assume that the queue structure is the first
  235. // element in the queue entry structure.
  236. //
  237. #define QUEUE_ENTER( queue_head, entry ) \
  238. { \
  239. q_hdr_t *old_chain ; \
  240. \
  241. old_chain = (q_hdr_t *)(queue_head.lifo_a) ; \
  242. entry->chain_q.lifo_a = queue_head.lifo_a ; \
  243. queue_head.lifo_a = (char *)entry ; \
  244. entry->chain_q.fifo_a = NULL ; \
  245. if ( old_chain == NULL ) \
  246. queue_head.fifo_a = (char *)entry ; \
  247. else \
  248. old_chain->fifo_a = (char *)entry ; \
  249. }
  250. #define QUEUE_REMOVE( queue_head, entry ) \
  251. { \
  252. q_hdr_t *dequeue_chain ; \
  253. q_hdr_t *prev_chain ; \
  254. \
  255. dequeue_chain = (q_hdr_t *)(queue_head.fifo_a) ; \
  256. entry = (tcb_t *)dequeue_chain ; \
  257. if ( dequeue_chain != NULL ) \
  258. { \
  259. prev_chain = (q_hdr_t *)(dequeue_chain->fifo_a) ; \
  260. queue_head.fifo_a = (char *)prev_chain ; \
  261. if ( prev_chain != NULL ) \
  262. prev_chain->lifo_a = NULL ; \
  263. else \
  264. queue_head.lifo_a = NULL ; \
  265. } \
  266. }
  267. //
  268. // Function Prototypes
  269. //
  270. UINT UserMibInit(
  271. IN OUT HANDLE *hPollForTrapEvent ) ;
  272. void TrapInit(
  273. IN OUT HANDLE *hPollForTrapEvent ) ;
  274. UINT ResolveVarBind(
  275. IN OUT RFC1157VarBind *VarBind , // Variable Binding to resolve
  276. IN UINT PduAction ) ; // Action specified in PDU
  277. UINT FindClass(
  278. IN RFC1157VarBind *VarBind, // Variable Binding
  279. IN OUT UINT *cindex ) ; // Index into class_info table
  280. UINT ResolveGetNext(
  281. IN OUT RFC1157VarBind *VarBind, // Variable Binding
  282. IN OUT UINT *cindex, // Class Info table index
  283. IN OUT UINT *vindex , // Variable table index
  284. OUT AsnObjectIdentifier *instance ) ;
  285. void SetupTrap(
  286. IN OUT tcb_t **entryBlock ,
  287. IN int trapIndex ) ;
  288. UINT AddTrapVar(
  289. IN tcb_t *entry ,
  290. IN int trapIndex ,
  291. IN int varIndex ,
  292. IN AsnObjectIdentifier *instance ,
  293. IN char *value ) ;
  294. void PostTrap(
  295. IN tcb_t *entry ,
  296. IN int trapIndex ) ;
  297. //
  298. // Externals
  299. //
  300. extern UINT SMIGetInteger() ;
  301. extern UINT SMIGetNSMBoolean() ;
  302. extern UINT SMIGetBIDTEnum() ;
  303. extern UINT SMIGetOctetString() ;
  304. extern UINT SMIGetObjectId() ;
  305. extern UINT SMIGetCounter() ;
  306. extern UINT SMIGetGauge() ;
  307. extern UINT SMIGetTimeTicks() ;
  308. extern UINT SMIGetIpAddress() ;
  309. extern UINT SMIGetDispString() ;
  310. extern UINT SMISetInteger() ;
  311. extern UINT SMISetBIDTEnum() ;
  312. extern UINT SMISetOctetString() ;
  313. extern UINT SMISetObjectId() ;
  314. extern UINT SMISetCounter() ;
  315. extern UINT SMISetGauge() ;
  316. extern UINT SMISetTimeTicks() ;
  317. extern UINT SMISetIpAddress() ;
  318. extern UINT SMISetDispString() ;
  319. extern UINT SMIBuildInteger() ;
  320. extern UINT SMISetNSMBoolean() ;
  321. extern UINT SMIBuildBIDTEnum() ;
  322. extern UINT SMIBuildOctetString() ;
  323. extern UINT SMIBuildObjectId() ;
  324. extern UINT SMIBuildCounter() ;
  325. extern UINT SMIBuildGauge() ;
  326. extern UINT SMIBuildTimeTicks() ;
  327. extern UINT SMIBuildIpAddress() ;
  328. extern UINT SMIBuildDispString() ;
  329. extern void SMIFree() ;
  330. extern q_hdr_t trap_q ;
  331. extern HANDLE hEnabledTraps ;
  332. extern HANDLE hTrapQMutex ;
  333. // Microsoft MIB Specifics.
  334. #define MAX_STRING_LEN 255
  335. #endif /* gennt_h */
  336.