/***************************************************************************/ /* Module: $Id: osusnmp.h,v 1.2 1999/05/07 04:15:27 maf Exp $ /* Description: Defines data types for OSU SNMP parser. /* Author: Shamim Ahmed /* Notes: /***************************************************************************/ /* $Log: osusnmp.h,v $ Revision 1.2 1999/05/07 04:15:27 maf pr -e2 Revision 1.1 1997/02/23 18:05:10 maf Initial revision * Revision 2.4 1994/05/09 13:29:21 maf * u_long prints at max 10 chars. * * Revision 2.3 1994/02/04 21:25:05 maf * changes for rconsole * * Revision 2.2 1994/01/02 20:06:22 maf * *** empty log message *** * * Revision 2.1 1993/10/19 19:37:18 maf * kbconfig 1.7+ * * Revision 1.1 1993/08/29 01:43:29 maf * Initial revision * */ #ifndef OSU_SNMP_H #define OSU_SNMP_H #include "snmpdbg.h" #include /* --- parameters for setting size limits --------*/ #define MAX_OID_LEN 40 /* max OID length (in elements) */ #define MAX_OID_ASN_LEN 80 /* max asn encoded OID len.*/ #define MAX_OBJ_LEN 768 /* max object length */ #define MAX_OBJ_ASN_LEN MAX_OBJ_LEN + 4 /* max. asn object len. */ /* max asn oid & obj combined*/ #define MAX_VARBIND_LEN MAX_OBJ_ASN_LEN + MAX_OID_ASN_LEN + 4 #define MAX_SEQ_LEN 256*4 /* max sequence length */ #define MAX_SNMP_HEADER_LEN 64 /* max header len. */ #define MAX_BIND_SIZE 20 /* max requests in 1 snmp packet */ #define MAX_COMMUNITY_LEN 32 /* max community name len */ #define SNMP_PKT_MAX 256*4 /* max size of SNMP packet */ #define SNMP_VERSION 0 /* snmp version number */ #define MAX_OID_VAL 0xFFFF /* max oid value */ typedef u_short OidEleType; /* size of each oid element */ /* ---------- SNMP enumerated types see RFC 1067 ---------- */ /* ----- error messages in snmp packet -------------------- */ typedef enum { snmpErrorNone, /* no error */ snmpErrorTooBig, /* snmp request exceeds space limit */ snmpErrorNoSuchName, /* object name does not exist */ snmpErrorBadValue, /* bad snmp packet */ snmpErrorReadOnly, /* read only object ?? */ snmpErrorGeneric, /* conditions not mentioned above */ } SnmpErrorType; typedef enum { readOnlyAccess, /* object is read only */ readWriteAccess /* object is read write */ } SnmpAccessType; typedef enum { snmpAuthReadOnly = 0x01, snmpAuthReadWrite = 0x02, snmpAuthWriteOnly = 0x04, snmpAuthNotAcc = 0x08 } SnmpAuthType; typedef enum { snmpGetRequest = 0x00, snmpNextRequest = 0x01, snmpGetResponse = 0x02, snmpSetRequest = 0x03, snmpTrap = 0x04 } SnmpRequestType; typedef enum { Asn_Universal = 0x00, Asn_Application = 0x40, Asn_Context = 0x80, Asn_Private = 0xC0 } AsnClassType; typedef enum { Asn_Primitive = 0x00, Asn_Constructor = 0x20 } AsnConstType; /* ----- SNMP tags at network level ( in SNMP packet ) ------ */ typedef enum { /* ------ UNIVERSAL TYPES ---- */ Asn_Integer = Asn_Universal | 0x02, Asn_Octect = Asn_Universal | 0x04, Asn_Null = Asn_Universal | 0x05, Asn_Oid = Asn_Universal | 0x06, Asn_Sequence = Asn_Universal | 0x10, /*--- APPLICATION (SNMP) TYPES -----*/ Smp_IpAddr = Asn_Application | 0x00, Smp_Counter = Asn_Application | 0x01, Smp_Guage = Asn_Application | 0x02, Smp_Ticks = Asn_Application | 0x03, Smp_Opaque = Asn_Application | 0x04 } AsnVarType; /* ASN SNMP type can be translated to the following machine types */ typedef enum { PC_Null = 0x00, /* null object 0 bytes */ PC_Integer2 = 0x01, /* positive integers 2 bytes */ PC_Integer4 = 0x02, /* positive integers 4 bytes */ PC_OctectString = 0x03, /* char. string n bytes */ PC_Oid = 0x04, /* OID n elements of OidEleType */ PC_IpAddr = 0x05, /* IP address 4 bytes */ PC_Guage = 0x06, /* Guage ( for speed) 4 bytes */ PC_Ticks = 0x07, /* time ticks 4 bytes */ PC_Opaque = 0x08, /* opeaque n bytes */ PC_Counter1 = 0x09, /* positive counter 1 byte */ PC_Counter2 = 0x0A, /* positive counter 2 bytes */ PC_Counter4 = 0x0B, /* positive counter 4 bytes */ PC_Counter6 = 0x0C, /* positive counter 6 bytes */ PC_Default = 0xff, /* type not known. use defaults */ } PCTypes; /* -------- password -------------------------------------- */ typedef struct { char rw[MAX_COMMUNITY_LEN]; /* read write password */ short lrw; /* length of rw */ char wo[MAX_COMMUNITY_LEN]; /* write only password */ short lwo; /* length of rw */ char ro[MAX_COMMUNITY_LEN]; /* read only passwd */ short lro; /* length of ro */ } PasswordType; /*------------------------------------------------------------------- ** structue varBindType for keeping one object ** ** { Seq } { OID } { Value } ** | * . . * | * * . . . .. . . * | * . . . . . * | ** |<------------------ tlen --------------------->| ** |<---oidAsnLen ----->|<-objAsnLen--->| ** ^ ^ ^ ** | | | ** asn oidAsn objAsn **------------------------------------------------------------------*/ typedef struct { SnmpRequestType req; /* SNMP request for this var-bind. */ SnmpAuthType auth; /* authentication for this var-bind */ u_char *asn; /* pointer to ASN encoded var-bind */ short tlen; /* length of ASN encoded var-bind. */ u_char *oidAsn; /* pointer to ASN encoded OID */ short oidAsnLen; /* length of ASN encoded OID */ u_char *objAsn; /* pointer to ASN encoded obj. val. */ short objAsnLen; /* length of ASN encoded object val.*/ OidEleType oid[MAX_OID_LEN]; /* decoded OID */ short oidLen; /* decoded OID length */ u_char obj[MAX_OBJ_LEN]; /* decoded object value */ short objLen; /* length of decodec object value */ PCTypes objType; /* object type */ #ifdef FOO /* some temporary buffers used during encodig var-bind */ u_char oidAsnTmp[MAX_OID_ASN_LEN]; /* temp. array for ASN encoded OID. */ u_char objAsnTmp[MAX_OBJ_ASN_LEN]; /* temp. array for ASN encoded object value. */ #endif FOO } VarBindType; /*-------------------------------------------------------------------- ** SnmpType keeps pointers and values for a SNMP packet. ** Snmp server uses one snmpType for each snmp packet while ** parsing the packet. ** ** |----------------- full snmp packect ------------| ** { Seq }{------- remaining snmp packet ---------} ** |<----------------- pktLen --------------------->| ** ^ ** | ** pkt **------------------------------------------------------------------*/ typedef struct { u_char *pkt; /* pointer to snmp packet */ short pktLen; /* length of snmp packet */ int version; /* version number */ u_char *communityAsn; /* ptr to asn community name */ short communityAsnLen; /* len asn community name */ /* decoded community name */ u_char communityName[MAX_COMMUNITY_LEN]; short communityLen; /* len of decoded community name */ SnmpAuthType auth; /* authentication code */ SnmpRequestType req; /* snmp command */ long id; /* request ID */ int errorStatus; /* error status */ int errorIndex; /* error Index */ u_char *currPtr; /* current ptr into packet */ short bytesLeft; /* bytes left to be parsed */ short bytesUsed; /* bytes used so far */ short bindCount; /* No of objects in the packet */ } SnmpType; /* ------ in misc.c --------- */ void snmpbzero(); void snmpbcopy(); SnmpErrorType errorHandler(); /* ----- in asn.c ----------- */ SnmpErrorType asnDecodeInt(); SnmpErrorType asnEncodeInt(); SnmpErrorType asnDecodeOctString(); SnmpErrorType asnEncodeOctString(); SnmpErrorType asnDecodeNull(); SnmpErrorType asnEncodeNull(); SnmpErrorType asnDecodeOid(); SnmpErrorType asnEncodeOid(); SnmpErrorType asnDecodeSeq(); SnmpErrorType asnEncodeSeq(); SnmpErrorType asnDecodeSmpIpAddr(); SnmpErrorType asnEncodeSmpIpAddr(); SnmpErrorType asnDecodeSmpCount(); SnmpErrorType asnEncodeSmpCount(); SnmpErrorType asnDecodeSmpGuage(); SnmpErrorType asnEncodeSmpGuage(); SnmpErrorType asnDecodeSmpTicks(); SnmpErrorType asnEncodeSmpTicks(); SnmpErrorType asnDecodeCommand(); SnmpErrorType asnEncodeCommand(); SnmpErrorType asnDecodeAny(); SnmpErrorType asnEncodeAny(); /* ----- In snmpsrv.c ----- */ int doSnmp(); /* ----- in snmpcmd.c ----- */ SnmpErrorType snmpGet(); SnmpErrorType snmpNext(); int initSnmp(); SnmpErrorType nextInList(); SnmpErrorType getInList(); /* ----- in debug.c ------ */ int printReq(); int printSmp(); /* Asn Types <-> C types */ typedef long ASN_Integer; typedef long ASN_Integer32; typedef long ASN_Gauge; typedef long ASN_Gauge32; typedef u_long ASN_Counter; typedef u_long ASN_Counter32; typedef u_long ASN_TimeTicks; typedef u_long ASN_UInteger32; typedef u_char ASN_PhysAddress[6]; typedef u_char ASN_MacAddress[6]; typedef u_char ASN_DisplayString[256]; typedef u_char ASN_IpAddress[4]; typedef OidEleType ASN_ObjectID[MAX_OID_LEN]; /* Asn to Ascii */ #define ASN_Integer_To_Ascii(BUF, VAR, LEN) \ sprintf(BUF, "%-11ld", VAR); \ if (LEN) \ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ else \ stripspaces(BUF); #define ASN_Integer32_To_Ascii(BUF, VAR, LEN) \ sprintf(BUF, "%-11ld", VAR, LEN);\ if (LEN)\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ #define ASN_Gauge_To_Ascii(BUF, VAR, LEN) \ sprintf(BUF, "%-10ld", VAR, LEN);\ if (LEN)\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ #define ASN_Gauge32_To_Ascii(BUF, VAR, LEN) \ sprintf(BUF, "%-10ld", VAR, LEN);\ if (LEN)\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ #define ASN_Counter_To_Ascii(BUF, VAR, LEN) \ sprintf(BUF, "%-10lu", VAR, LEN);\ if (LEN)\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ #define ASN_Counter32_To_Ascii(BUF, VAR, LEN) \ sprintf(BUF, "%-10lu", VAR, LEN);\ if (LEN)\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ #define ASN_TimeTicks_To_Ascii(BUF, VAR, LEN) \ sprintf(BUF, "%-10lu", VAR, LEN);\ if (LEN)\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ #define ASN_UInteger32(BUF, VAR, LEN) \ sprintf(BUF, "%-10lu", VAR, LEN);\ if (LEN)\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ #define ASN_DisplayString_To_Ascii(BUF, VAR, LEN) \ strcpy(BUF, VAR);\ if (LEN) {\ strcat(BUF, pr_spaces(LEN - strlen(BUF)));\ BUF[LEN] = 0;\ }\ #endif /* ----- OSU_SNMP_H ----- */