3 * [EXPERIMENTAL] SNMP Agent message handling structures.
7 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * Author: Christiaan Simons <christiaan.simons@axon.tv>
35 #ifndef __LWIP_SNMP_MSG_H__
36 #define __LWIP_SNMP_MSG_H__
40 #include "lwip/snmp.h"
43 #include "private_mib.h"
46 #define SNMP_IN_PORT 161
47 #define SNMP_TRAP_PORT 162
49 #define SNMP_ES_NOERROR 0
50 #define SNMP_ES_TOOBIG 1
51 #define SNMP_ES_NOSUCHNAME 2
52 #define SNMP_ES_BADVALUE 3
53 #define SNMP_ES_READONLY 4
54 #define SNMP_ES_GENERROR 5
58 /* next pointer, NULL for last in list */
59 struct snmp_varbind *next;
60 /* previous pointer, NULL for first in list */
61 struct snmp_varbind *prev;
63 /* object identifier length (in s32_t) */
65 /* object identifier array */
68 /* object value ASN1 type */
70 /* object value length (in u8_t) */
75 /* encoding varbind seq length length */
77 /* encoding object identifier length length */
79 /* encoding object value length length */
81 /* encoding varbind seq length */
83 /* encoding object identifier length */
85 /* encoding object value length */
89 struct snmp_varbind_root
91 struct snmp_varbind *head;
92 struct snmp_varbind *tail;
93 /* number of variable bindings in list */
95 /* encoding varbind-list seq length length */
97 /* encoding varbind-list seq length */
101 /** output response message header length fields */
102 struct snmp_resp_header_lengths
104 /* encoding error-index length length */
106 /* encoding error-status length length */
108 /* encoding request id length length */
110 /* encoding pdu length length */
112 /* encoding community length length */
114 /* encoding version length length */
116 /* encoding sequence length length */
119 /* encoding error-index length */
121 /* encoding error-status length */
123 /* encoding request id length */
125 /* encoding pdu length */
127 /* encoding community length */
129 /* encoding version length */
131 /* encoding sequence length */
135 /** output response message header length fields */
136 struct snmp_trap_header_lengths
138 /* encoding timestamp length length */
140 /* encoding specific-trap length length */
142 /* encoding generic-trap length length */
144 /* encoding agent-addr length length */
146 /* encoding enterprise-id length length */
148 /* encoding pdu length length */
150 /* encoding community length length */
152 /* encoding version length length */
154 /* encoding sequence length length */
157 /* encoding timestamp length */
159 /* encoding specific-trap length */
161 /* encoding generic-trap length */
163 /* encoding agent-addr length */
165 /* encoding enterprise-id length */
167 /* encoding pdu length */
169 /* encoding community length */
171 /* encoding version length */
173 /* encoding sequence length */
177 /* can accept new SNMP message */
178 #define SNMP_MSG_EMPTY 0
179 /* decode SNMP variable binding */
180 #define SNMP_MSG_DEMUX 1
181 /* perform SNMP operation on varbind for in-memory case */
182 #define SNMP_MSG_INTERNAL 2
183 /* perform SNMP operation on private varbind external case */
184 #define SNMP_MSG_EXTERNAL 3
187 #define SNMP_COMMUNITY_STR_LEN 64
188 struct snmp_msg_pstat
191 struct snmp_msg_pstat *next;
193 /* lwIP local port (161) binding */
195 /* source IP address */
197 /* source UDP port */
207 /* community name (zero terminated) */
208 u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
209 /* community string length (exclusive zero term) */
211 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL */
213 /* index into input variable binding list */
215 /* ptr into input variable binding list */
216 struct snmp_varbind *vb_ptr;
217 /* list of variable bindings from input */
218 struct snmp_varbind_root invb;
219 /* list of variable bindings to output */
220 struct snmp_varbind_root outvb;
221 /* output response lengths used in ASN encoding */
222 struct snmp_resp_header_lengths rhl;
224 struct private_state ps;
231 struct snmp_msg_trap *next;
233 /* lwIP local port (161) binding */
235 /* destination IP address in network order */
238 /* source enterprise ID (sysObjectID) */
239 struct snmp_obj_id *enterprise;
240 /* source IP address, raw network order format */
242 /* generic trap code */
244 /* specific trap code */
248 /* list of variable bindings to output */
249 struct snmp_varbind_root outvb;
250 /* output trap lengths used in ASN encoding */
251 struct snmp_trap_header_lengths thl;
253 /** @todo is this really needed? */
254 struct private_state ps;
258 /** Agent Version constant, 0 = v1 oddity */
259 extern const s32_t snmp_version;
260 /** Agent default "public" community string */
261 extern const char snmp_publiccommunity[7];
263 extern struct snmp_msg_trap trap_msg;
265 /** Agent setup, start listening to port 161. */
266 void snmp_init(void);
267 /** Handles internal/external events. */
268 void snmp_msg_event(struct snmp_msg_pstat *msg_ps);
269 err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
270 err_t snmp_send_trap(struct ip_addr *dst, s8_t generic_trap, s32_t specific_trap);