⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpdef.h

📁 在freescale 的ne64上开发的源代码
💻 H
字号:
#ifndef INCLUDE_SNMPDEF_H
#define INCLUDE_SNMPDEF_H
#include "snmptype.h"
#include <string.h>
#include <stdio.h>

#define DECODE_ASN_PARSE_ERROR      -1
#define DECODE_ALLOCATION_FAILURE   -2
#define DECODE_UNKNOWN_PDU_HANDLERS -3
#define DECODE_UNKNOWN_CONTEXTS     -4

/* Values for pdu_type (class and form bits are not included) */
#define GET_REQUEST_PDU            0
#define GET_NEXT_REQUEST_PDU   	   1
#define GET_RESPONSE_PDU           2
#define SET_REQUEST_PDU            3
#define TRAP_PDU                   4
#define GET_BULK_REQUEST_PDU       5
#define INFORM_REQUEST_PDU         6
#define TRAP2_PDU                  7
#define REPORT_PDU                 8
#define MAX_V1_PDU                 4
#define MAX_PDU                    8
#define NO_PDU                     0xFF

/* Values for error_status      */
#define NO_ERROR                 0
#define TOO_BIG                  1
#define NO_SUCH_NAME             2
#define BAD_VALUE                3
#define READ_ONLY                4
#define GEN_ERR                  5
#define NO_ACCESS                6
#define WRONG_TYPE               7
#define WRONG_LENGTH             8
#define WRONG_ENCODING           9
#define WRONG_VALUE             10
#define NO_CREATION             11
#define INCONSISTENT_VALUE      12
#define RESOURCE_UNAVAILABLE    13
#define COMMIT_FAILED           14
#define UNDO_FAILED             15
#define AUTHORIZATION_ERROR     16
#define NOT_WRITABLE            17
#define INCONSISTENT_NAME       18
#define LAST_ERROR              19

/* ASN.1 basic types, all in UNIVERSAL scope */
#define A_NO_ID             0x00
#define A_BOOLEAN           0x01
#define A_INTEGER           0x02
#define A_BITSTRING         0x03
#define A_OCTETSTRING       0x04
#define A_NULL              0x05
#define A_OBJECTID          0x06
#define A_SEQUENCE          0x10	/*different from asn1.h*/
#define A_SET               0x11

/* ASN.1 FLAGS (form and class), adjusted for position within an octet */
#define A_IDCF_MASK         0xE0	/* Mask for ID CLASS and FORM bits */
#define A_IDC_MASK          0xC0	/* Mask for ID CLASS bits */
#define A_IDF_MASK          0x20	/* Mask for ID FORM bit */
#define A_FLAG_MASK         0xE0
#define A_UNIVERSAL         0x00
#define A_APPLICATION       0x40
#define A_CONTEXT           0x80
#define A_PRIVATE           0xC0
#define A_PRIMITIVE         0x00
#define A_CONSTRUCTOR       0x20
#define A_DEFAULT_SCOPE     A_CONTEXT

/* Values for vb_type      */
#define VT_NUMBER       A_INTEGER
#define VT_STRING       A_OCTETSTRING
#define VT_BITS         A_OCTETSTRING	/* same as a string */
#define VT_OBJECT       A_OBJECTID
#define VT_EMPTY        A_NULL
#define VT_IPADDRESS    (A_APPLICATION | 0)
#define VT_COUNTER      (A_APPLICATION | 1)
#define VT_GAUGE        (A_APPLICATION | 2)
#define VT_UNSIGNED32   (A_APPLICATION | 2)	/* same as a guage */
#define VT_TIMETICKS    (A_APPLICATION | 3)
#define VT_OPAQUE       (A_APPLICATION | 4)
#define VT_COUNTER64    (A_APPLICATION | 6)
#define VT_UINTEGER32   (A_APPLICATION | 7)

/* values for exception data types */
#define VT_NOSUCHOBJ    (A_CONTEXT | 0)
#define VT_NOSUCHINS    (A_CONTEXT | 1)
#define VT_ENDOFMIB     (A_CONTEXT | 2)

/* Values for OID*/
/****************************************************************************
NAME:  A_SizeOfLength
PURPOSE:  Compute the number of octets needed to hold an ASN.1 length field.
PARAMETERS: _UINT16   The proposed length
RETURNS:    _UINT16   The number of octets needed
****************************************************************************/
#define A_SizeOfLength(S) ((_UINT16)((S) <= 127 ? 1 : ((S) <= 255 ? 2 : 3)))

/****************************************************************************

NAME:  A_SizeOfType

PURPOSE:  Compute the number of octets needed to hold an ASN.1 type field

PARAMETERS: _UINT16           The proposed type (without CLASS & FORM bits)
RETURNS:    unsigned int        The number of octets needed
****************************************************************************/
#define A_SizeOfType(V) ((_UINT32) ((V) <= 30 ? 1 : ((V) <= 127 ? 2 : ((V) <= 16383 ? 3 : 4))))
/****************************************************************************
A_SizeOfOctetString --  Return total size that an octet string would
                        occupy when ASN.1 encoded (tag and length fields
                        are NOT included)

Parameters:       _UINT16       The size of the string
Returns: _UINT16  Number of octets the octet string would occupy if
                    in ASN.1 encoding, NOT including the type/length fields
                    of the outermost wrapper.  Since these routines only
                    generate non-constructor encodings, the length is
                    exactly that given.
****************************************************************************/
#define A_SizeOfOctetString(L)  ((_UINT16)(L))

/****************************************************************************
Decoding errors
****************************************************************************/
#define AE_PREMATURE_END                1
#define AE_INDEFINITE_LENGTH            2
#define AE_WRONG_VALUE                  3
#define AE_WRONG_TYPE                   4
#define AE_WRONG_LENGTH                 5
#define AE_ALLOC_FAILURE                6


#define SNMP_SUCCESS 	1
#define SNMP_FAILURE 	0


/* The following structure is used to internally hold an object identifier */
/* Each component is limited in range from 0 to 64K-1.                     */

typedef struct
{
	_UINT8 num_components;		/* # of object id components    */
	/* Note: this is the number of  */
	/* components in the object id, */
	/* which is one more than the # */
	/* of subidentifiers in an      */
	/* encoded object id.*/
	_UINT32 component_list[MAX_OID_LENGTH];
}OBJ_ID_T;

typedef struct
{
	_UINT32 high;			/* the high (msb) 4 bytes of the uint */
	_UINT32 low;			/* the low (lsb) 4 bytes of the uint  */
}UINT64_T;

typedef struct
{
	_UINT16 vb_seq_size;/* Overall length of the VarBind*/
	OBJ_ID_T vb_obj_id;	/* Object id for this VarBind */
	_UINT16 defined_prefix_len;
	_UINT16 defined_index_cnt;
	_UINT32 *pLeafId;
	_UINT32 *pIndex;
	_INT16 (*process)(_UINT8 request,void *vbp);
	_UINT8 vb_data_flags_n_type;/*Class form & type of data */
	_UINT8 vb_flags;			/*See below*/
	_UINT16 vb_data_length;	/*Length of the sending data when encode */
	union {
		_INT32 v_number;		/*Integer kinds of things  */
		_UINT32 v_counter;	/*Unsigned int things*/
		_UINT8 v_string[MAX_OCTET_LENGTH];	/* Octetstring things       */
		OBJ_ID_T v_object;	/* Object id things         */
		_UINT8 v_network_address[4];
		UINT64_T v_counter64;	/* 64 bit unsigned things   */
	}value_u;
}VB_T;


typedef struct{
	_UINT16 snmp_family;
	_UINT8  snmp_data[16];
	_UINT16  snmp_port;
}SNMPADDR_T;

typedef struct
{
	_UINT8  community[MAX_COMMUNITY_LEN];
	_UINT8  pdu_type;
	_UINT8 snmp_version;
	_UINT16 overall_length; /* Message Sequence length */
	_UINT16 pdu_length;
	_UINT32 localip;
#if (PLATFORM==LINUX) ||(PLATFORM==UCLINUX)  ||(PLATFORM==VXWORKS) 
	SNMPADDR_T peerAddr;
	SNMPADDR_T myAddr;
	_INT32 sock_cooike;
#endif
	struct
	{
		_UINT32 request_id;
		_UINT16 error_status;
		_UINT16 error_index;
		_UINT16 vbl_length;
		_UINT16 vb_count;
		VB_T  vb_obj[MAX_SUPPORT_OID_NUM];
	}pdu;
}SNMP_PKT_T;

#define A_DecodeTypeClass(L) ((_UINT8) (Lcl_Peekc((LCL_FILE *)(L)) &  A_IDCF_MASK))

#define SNMP_VERSION_MIN                0	/* Lower bound for SNMP version */
#define VERSION_RFC1067                 0	/* Classic SNMP */
#define VERSION_RFC1098                 0
#define VERSION_RFC1157                 0
#define SNMP_VERSION_1                  0	/* now being tagged as version 1 */
#define SNMP_VERSION_2                  1	/* SNMPV2 */
#define SNMP_VERSION_USEC            2	/* User Security option */
#define SNMP_VERSION_3                  3	/* SNMPv3 */
#define SNMP_VERSION_MAX       0x7fffffff	/* Upper bound for SNMP version */

#define SNMP_TERMINATOR  0
#define SNMP_SCALAR 	 1
#define SNMP_TABLE	 	 2
typedef struct
{
	_UINT16   type;
	_UINT32   prefixSubOid[MAX_OID_PREFIX_SIZE];
	_UINT16   prefixLen;
	_UINT16   idxCnt;
	_UINT16   leafNum;
	_INT16     (*pObjHandler)(_UINT8 request,void *vbp);
}SNMP_OID_TABLE_T;

typedef struct {
	_UINT32 snmpInPkts;
	_UINT32 snmpInBadVersions;
	_UINT32 snmpInBadCommunityNames;
	_UINT32 snmpInBadCommunityUses;
	_UINT32 snmpInASNParseErrs;
	_UINT16 snmpEnableAuthTraps;
	_UINT32 snmpOutPkts;
	_UINT32 snmpInBadTypes;
	_UINT32 snmpInTooBigs;
	_UINT32 snmpInNoSuchNames;
	_UINT32 snmpInBadValues;
	_UINT32 snmpInReadOnlys;
	_UINT32 snmpInGenErrs;
	_UINT32 snmpInTotalReqVars;
	_UINT32 snmpInTotalSetVars;
	_UINT32 snmpInGetRequests;
	_UINT32 snmpInGetNexts;
	_UINT32 snmpInSetRequests;
	_UINT32 snmpInGetResponses;
	_UINT32 snmpInTraps;
	_UINT32 snmpOutTooBigs;
	_UINT32 snmpOutNoSuchNames;
	_UINT32 snmpOutBadValues;
	_UINT32 snmpOutReadOnlys;
	_UINT32 snmpOutGenErrs;
	_UINT32 snmpOutGetRequests;
	_UINT32 snmpOutGetNexts;
	_UINT32 snmpOutSetRequests;
	_UINT32 snmpOutGetResponses;
	_UINT32 snmpOutTraps;
	_UINT32 snmpSilentDrops;
	_UINT32 snmpProxyDrops;
#ifdef INSTALL_SNMP_VERSION_3
	_UINT32 snmpUnknownSecurityModels;
	_UINT32 snmpInvalidMsgs;
	_UINT32 snmpUnknownPDUHandlers;
	_UINT32 snmpUnavailableContexts;
	_UINT32 snmpUnknownContexts;
	_UINT32 usmStatsUnsupportedSecLevels;
	_UINT32 usmStatsNotInTimeWindows;
	_UINT32 usmStatsUnknownUserNames;
	_UINT32 usmStatsUnknownEngineIDs;
	_UINT32 usmStatsWrongDigests;
	_UINT32 usmStatsDecryptionErrors;
#endif							/* INSTALL_ENVOY_SNMP_VERSION_3 */
} SNMP_STATS_T;

#define MAX_TRAP_SERVER_NUM 5
typedef struct {
	_UINT32 addr;
	_UINT16 port;
}t_Trap_server;

#define RW 1
#define RO  0
typedef struct {
	_UINT8 name[MAX_COMMUNITY_LEN];
	_UINT8 ability;
}t_Community;


#if 0
extern int snmp_debug;
#define SNMP_DEBUG if(snmp_debug) printf
#endif
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -