00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _ASN1
00032 #define _ASN1
00033
00034 #ifdef WIN32
00035 #ifndef __unix
00036 #include <winsock.h>
00037 #endif
00038 #endif
00039
00040 #include "snmp_pp/target.h"
00041
00042 #ifdef SNMP_PP_NAMESPACE
00043 namespace Snmp_pp {
00044 #endif
00045
00046 #define MAXLENGTH_BUFFER SNMP_MSG_LENGTH
00047 #ifndef EIGHTBIT_SUBIDS
00048 typedef unsigned long oid;
00049 #define MAX_SUBID 0xFFFFFFFF
00050 #else
00051 typedef unsigned char oid;
00052 #define MAX_SUBID 0xFF
00053 #endif
00054
00055 #define MAX_OID_LEN 128
00056
00057
00058 #define ASN_BOOLEAN (0x01)
00059 #ifndef ASN_INTEGER
00060 #define ASN_INTEGER (0x02)
00061 #endif
00062 #define ASN_BIT_STR (0x03)
00063 #define ASN_OCTET_STR (0x04)
00064 #ifndef ASN_NULL
00065 #define ASN_NULL (0x05)
00066 #endif
00067 #define ASN_OBJECT_ID (0x06)
00068 #ifndef ASN_SEQUENCE
00069 #define ASN_SEQUENCE (0x10)
00070 #endif
00071 #define ASN_SET (0x11)
00072 #ifndef ASN_UNIVERSAL
00073 #define ASN_UNIVERSAL (0x00)
00074 #endif
00075 #ifndef ASN_APPLICATION
00076 #define ASN_APPLICATION (0x40)
00077 #endif
00078 #ifndef ASN_CONTEXT
00079 #define ASN_CONTEXT (0x80)
00080 #endif
00081 #ifndef ASN_PRIVATE
00082 #define ASN_PRIVATE (0xC0)
00083 #endif
00084 #ifndef ASN_PRIMITIVE
00085 #define ASN_PRIMITIVE (0x00)
00086 #endif
00087 #ifndef ASN_CONSTRUCTOR
00088 #define ASN_CONSTRUCTOR (0x20)
00089 #endif
00090 #define ASN_LONG_LEN (0x80)
00091 #define ASN_EXTENSION_ID (0x1F)
00092 #define ASN_BIT8 (0x80)
00093
00094 #define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR)
00095 #define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID)
00096
00097 #define ASN_MAX_NAME_LEN 128
00098 #define SNMP_VERSION_1 0
00099 #define SNMP_VERSION_2C 1
00100 #define SNMP_VERSION_2STERN 2
00101 #define SNMP_VERSION_3 3
00102
00103
00104 #define SMI_IPADDRESS (ASN_APPLICATION | 0)
00105 #define SMI_COUNTER (ASN_APPLICATION | 1)
00106 #define SMI_GAUGE (ASN_APPLICATION | 2)
00107 #define SMI_TIMETICKS (ASN_APPLICATION | 3)
00108 #define SMI_OPAQUE (ASN_APPLICATION | 4)
00109 #define SMI_NSAP (ASN_APPLICATION | 5)
00110 #define SMI_COUNTER64 (ASN_APPLICATION | 6)
00111 #define SMI_UINTEGER (ASN_APPLICATION | 7)
00112
00113 #define GET_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0)
00114 #define GETNEXT_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1)
00115 #define GET_RSP_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2)
00116 #define SET_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3)
00117 #define TRP_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)
00118
00119 #define GETBULK_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5)
00120 #define INFORM_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6)
00121 #define TRP2_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7)
00122 #define REPORT_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8)
00123
00124 #define SNMP_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x0)
00125 #define SNMP_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x1)
00126 #define SNMP_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x2)
00127
00128 #define SNMP_MSG_LENGTH MAX_SNMP_PACKET
00129
00130 #ifdef _DEBUG
00131 #define ASNERROR( string) debugprintf(3, "ASN parse error (%s)\n", string )
00132 #else
00133 #define ASNERROR( string)
00134 #endif
00135
00136
00137 typedef struct sockaddr_in ipaddr;
00138
00139
00140 struct snmp_pdu {
00141 int command;
00142 unsigned long reqid;
00143 #ifdef _SNMPv3
00144 unsigned long msgid;
00145 unsigned long maxsize_scopedpdu;
00146 #endif
00147 unsigned long errstat;
00148 unsigned long errindex;
00149
00150
00151 oid *enterprise;
00152 int enterprise_length;
00153 ipaddr agent_addr;
00154 int trap_type;
00155 int specific_type;
00156 unsigned long time;
00157
00158
00159 struct variable_list *variables;
00160 };
00161
00162
00163 struct variable_list {
00164 struct variable_list *next_variable;
00165 oid *name;
00166 int name_length;
00167 unsigned char type;
00168 union {
00169 long *integer;
00170 unsigned char *string;
00171 oid *objid;
00172 unsigned char *bitstring;
00173 struct counter64 *counter64;
00174 } val;
00175 int val_len;
00176 };
00177
00178 struct counter64 {
00179 unsigned long high;
00180 unsigned long low;
00181 };
00182
00183
00184
00185 DLLOPT unsigned char *asn_parse_int( unsigned char *data, int *datalength,
00186 unsigned char *type,
00187 long int *intp, int intsize);
00188
00189
00190 DLLOPT unsigned char *asn_parse_unsigned_int( unsigned char *data,
00191 int *datalength,
00192 unsigned char *type,
00193 unsigned long *intp,
00194 int intsize);
00195
00196 DLLOPT unsigned char *asn_build_int(unsigned char *data, int *datalength,
00197 const unsigned char type,
00198 const long *intp, int intsize);
00199
00200 DLLOPT unsigned char *asn_build_unsigned_int( unsigned char *data,
00201 int *datalength,
00202 unsigned char type,
00203 unsigned long *intp,
00204 int intsize);
00205
00206 DLLOPT unsigned char *asn_parse_string( unsigned char *data, int *datalength,
00207 unsigned char *type,
00208 unsigned char *string,
00209 int *strlength);
00210
00211 DLLOPT unsigned char *asn_build_string( unsigned char *data, int *datalength,
00212 const unsigned char type,
00213 const unsigned char *string,
00214 const int strlength);
00215
00216 DLLOPT unsigned char *asn_parse_header( unsigned char *data, int *datalength,
00217 unsigned char *type);
00218
00219 DLLOPT unsigned char *asn_build_header( unsigned char *data, int *datalength,
00220 unsigned char type,
00221 int length);
00222
00223 DLLOPT unsigned char *asn_build_sequence( unsigned char *data,
00224 int *datalength,
00225 unsigned char type,
00226 int length);
00227
00228 DLLOPT unsigned char *asn_parse_length( unsigned char *data,
00229 unsigned long *length);
00230
00231 DLLOPT unsigned char *asn_build_length( unsigned char *data, int *datalength,
00232 int length);
00233
00234 DLLOPT unsigned char *asn_parse_objid( unsigned char *data, int *datalength,
00235 unsigned char *type,
00236 oid *objid,
00237 int *objidlength);
00238
00239 DLLOPT unsigned char *asn_build_objid( unsigned char *data,
00240 int *datalength,
00241 unsigned char type,
00242 oid *objid,
00243 int objidlength);
00244
00245 DLLOPT unsigned char *asn_parse_null(unsigned char *data, int *datalength,
00246 unsigned char *type);
00247
00248 DLLOPT unsigned char *asn_build_null( unsigned char *data,int *datalength,
00249 unsigned char type);
00250
00251 DLLOPT unsigned char *asn_parse_bitstring( unsigned char *data,
00252 int *datalength,
00253 unsigned char *type,
00254 unsigned char *string,
00255 int *strlength);
00256
00257 DLLOPT unsigned char *asn_build_bitstring( unsigned char *data,
00258 int *datalength,
00259 unsigned char type,
00260 unsigned char *string,
00261 int strlength);
00262
00263 DLLOPT unsigned char *asn_parse_unsigned_int64( unsigned char *data,
00264 int *datalength,
00265 unsigned char *type,
00266 struct counter64 *cp,
00267 int countersize);
00268
00269 DLLOPT unsigned char *asn_build_unsigned_int64( unsigned char *data,
00270 int *datalength,
00271 unsigned char type,
00272 struct counter64 *cp,
00273 int countersize);
00274
00275 DLLOPT struct snmp_pdu *snmp_pdu_create( int command);
00276
00277 DLLOPT void snmp_free_pdu( struct snmp_pdu *pdu);
00278
00279 DLLOPT int snmp_build(struct snmp_pdu *pdu,
00280 unsigned char *packet,
00281 int *out_length,
00282 const long version,
00283 const unsigned char* community,
00284 const int community_len);
00285
00286 DLLOPT void snmp_add_var(struct snmp_pdu *pdu,
00287 oid *name, int name_length,
00288 SmiVALUE *smival);
00289
00290 DLLOPT int snmp_parse(struct snmp_pdu *pdu,
00291 unsigned char *data,
00292 int data_length,
00293 unsigned char *community_name,
00294 int &community_len,
00295 snmp_version &version);
00296
00297 DLLOPT unsigned char *build_vb(struct snmp_pdu *pdu,
00298 unsigned char *buf, int *buf_len);
00299
00300 DLLOPT unsigned char *build_data_pdu(struct snmp_pdu *pdu,
00301 unsigned char *buf, int *buf_len,
00302 unsigned char *vb_buf, int vb_buf_len);
00303
00304 DLLOPT unsigned char *snmp_build_var_op(unsigned char *data,
00305 oid * var_name,
00306 int *var_name_len,
00307 unsigned char var_val_type,
00308 int var_val_len,
00309 unsigned char *var_val,
00310 int *listlength);
00311
00312 DLLOPT unsigned char *snmp_parse_var_op( unsigned char *data,
00313 oid *var_name,
00314 int *var_name_len,
00315 unsigned char *var_val_type,
00316 int *var_val_len,
00317 unsigned char **var_val,
00318 int *listlength);
00319
00320 DLLOPT int snmp_parse_data_pdu(struct snmp_pdu *pdu,
00321 unsigned char *&data, int &length);
00322
00323 DLLOPT int snmp_parse_vb(struct snmp_pdu *pdu,
00324 unsigned char *&data, int &data_len);
00325
00326 DLLOPT void clear_pdu(struct snmp_pdu *pdu, bool clear_all = false);
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 DLLOPT unsigned char *asn1_build_header_data(unsigned char *outBuf,
00350 int *maxLength,
00351 long msgID,
00352 long maxMessageSize,
00353 unsigned char msgFlags,
00354 long securityModel);
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382 DLLOPT unsigned char *asn1_parse_header_data(unsigned char *buf, int *buf_len,
00383 long *msg_id, long *msg_max_size,
00384 unsigned char *msg_flags,
00385 long *msg_security_model);
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 DLLOPT unsigned char *asn1_parse_scoped_pdu(
00410 unsigned char *scoped_pdu, int *scoped_pdu_len,
00411 unsigned char *context_engine_id, int *context_engine_id_len,
00412 unsigned char *context_name, int *context_name_len );
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436 DLLOPT unsigned char *asn1_build_scoped_pdu(
00437 unsigned char *outBuf, int *max_len,
00438 unsigned char *contextEngineID, long contextEngineIDLength,
00439 unsigned char *contextName, long contextNameLength,
00440 unsigned char *data, long dataLength);
00441
00442
00443 #ifdef SNMP_PP_NAMESPACE
00444 };
00445 #endif
00446
00447 #endif // _ASN1
00448