xref: /illumos-gate/usr/src/cmd/picl/plugins/sun4v/lib/snmp/pdu.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_PDU_H
28 #define	_PDU_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 typedef uint_t	oid;
35 
36 /*
37  * SNMP PDU variable list
38  */
39 typedef struct pdu_varlist {
40 	struct pdu_varlist *nextvar;
41 	oid	*name;
42 	size_t	name_len;		/* number of subids in the name */
43 	union {
44 		uint_t	*uiptr;		/* unused except while parsing */
45 		int	*iptr;
46 		uchar_t	*str;
47 		oid	*objid;
48 	} val;
49 	size_t	val_len;		/* in bytes even if val is objid */
50 	uchar_t	type;
51 } pdu_varlist_t;
52 
53 /*
54  * Essential snmp message/PDU fields
55  */
56 typedef struct snmp_pdu {
57 	int	version;
58 	uchar_t	*community;
59 	size_t	community_len;
60 	int	command;
61 	int	reqid;
62 	int	errstat;	/* shared with non-repeaters for GETBULK */
63 	int	errindex;	/* shared with max-repetitions for GETBULK */
64 	pdu_varlist_t	*vars;
65 
66 	uchar_t	*req_pkt;	/* not really part of PDU */
67 	size_t	req_pktsz;	/* not really part of PDU */
68 	uchar_t	*reply_pkt;	/* not really part of PDU */
69 	size_t	reply_pktsz;	/* not really part of PDU */
70 } snmp_pdu_t;
71 #define	non_repeaters	errstat
72 #define	max_repetitions	errindex
73 
74 /*
75  * Supported SNMP versions
76  */
77 #define	SNMP_VERSION_1		0
78 #define	SNMP_VERSION_2c		1
79 
80 /*
81  * Community strings for supported PDUs
82  */
83 #define	SNMP_DEF_COMMUNITY	"public"
84 #define	SNMP_DEF_COMMUNITY_LEN	6
85 
86 /*
87  * PDU types (not all are supported)
88  */
89 #define	SNMP_MSG_GET		(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x0)
90 #define	SNMP_MSG_GETNEXT	(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x1)
91 #define	SNMP_MSG_RESPONSE	(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x2)
92 #define	SNMP_MSG_SET		(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x3)
93 #define	SNMP_MSG_TRAP		(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x4)
94 #define	SNMP_MSG_GETBULK	(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x5)
95 #define	SNMP_MSG_INFORM		(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x6)
96 #define	SNMP_MSG_TRAP2		(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x7)
97 #define	SNMP_MSG_REPORT		(ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x8)
98 
99 /*
100  * Exception values (not all are supported)
101  */
102 #define	SNMP_NOSUCHOBJECT	(ASN_CONTEXT | ASN_PRIMITIVE | (uchar_t)0x0)
103 #define	SNMP_NOSUCHINSTANCE	(ASN_CONTEXT | ASN_PRIMITIVE | (uchar_t)0x1)
104 #define	SNMP_ENDOFMIBVIEW	(ASN_CONTEXT | ASN_PRIMITIVE | (uchar_t)0x2)
105 
106 /*
107  * Error codes (not all are supported)
108  */
109 #define	SNMP_ERR_NOERROR		(0)
110 #define	SNMP_ERR_TOOBIG			(1)
111 #define	SNMP_ERR_NOSUCHNAME		(2)
112 #define	SNMP_ERR_BADVALUE		(3)
113 #define	SNMP_ERR_READONLY		(4)
114 #define	SNMP_ERR_GENERR			(5)
115 #define	SNMP_ERR_NOACCESS		(6)
116 #define	SNMP_ERR_WRONGTYPE		(7)
117 #define	SNMP_ERR_WRONGLENGTH		(8)
118 #define	SNMP_ERR_WRONGENCODING		(9)
119 #define	SNMP_ERR_WRONGVALUE		(10)
120 #define	SNMP_ERR_NOCREATION		(11)
121 #define	SNMP_ERR_INCONSISTENTVALUE	(12)
122 #define	SNMP_ERR_RESOURCEUNAVAILABLE	(13)
123 #define	SNMP_ERR_COMMITFAILED		(14)
124 #define	SNMP_ERR_UNDOFAILED		(15)
125 #define	SNMP_ERR_AUTHORIZATIONERROR	(16)
126 #define	SNMP_ERR_NOTWRITABLE		(17)
127 #define	SNMP_ERR_INCONSISTENTNAME	(18)
128 
129 /*
130  * Default values
131  */
132 #define	SNMP_DEF_NON_REPEATERS		0
133 #define	SNMP_DEF_MAX_REPETITIONS	25
134 #define	SNMP_DEF_PKTBUF_SZ		2048
135 #define	SNMP_PKTBUF_BLKSZ		1024
136 #define	SNMP_MAX_ERR    		18
137 #define	MIN_SUBIDS_IN_OID		2
138 #define	MAX_SUBIDS_IN_OID		128
139 
140 /*
141  * Exported interfaces used by other parts of snmplib
142  */
143 snmp_pdu_t	*snmp_create_pdu(int, int, char *, int, int);
144 int		snmp_make_packet(snmp_pdu_t *);
145 snmp_pdu_t	*snmp_parse_reply(int, uchar_t *, size_t);
146 void		snmp_free_pdu(snmp_pdu_t *);
147 
148 /*
149  * Imported from elsewhere
150  */
151 int		snmp_get_reqid(void);
152 
153 #ifdef	__cplusplus
154 }
155 #endif
156 
157 #endif	/* _PDU_H */
158