3 * 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__
39 #include "lwip/snmp.h"
40 #include "lwip/snmp_structs.h"
41 #include "lwip/ip_addr.h"
47 /* When using a private MIB, you have to create a file 'private_mib.h' that contains
48 * a 'struct mib_array_node mib_private' which contains your MIB. */
49 #include "private_mib.h"
56 /* The listen port of the SNMP agent. Clients have to make their requests to
57 this port. Most standard clients won't work if you change this! */
59 #define SNMP_IN_PORT 161
61 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't
62 work if you change this! */
63 #ifndef SNMP_TRAP_PORT
64 #define SNMP_TRAP_PORT 162
67 #define SNMP_ES_NOERROR 0
68 #define SNMP_ES_TOOBIG 1
69 #define SNMP_ES_NOSUCHNAME 2
70 #define SNMP_ES_BADVALUE 3
71 #define SNMP_ES_READONLY 4
72 #define SNMP_ES_GENERROR 5
74 #define SNMP_GENTRAP_COLDSTART 0
75 #define SNMP_GENTRAP_WARMSTART 1
76 #define SNMP_GENTRAP_AUTHFAIL 4
77 #define SNMP_GENTRAP_ENTERPRISESPC 6
81 /* next pointer, NULL for last in list */
82 struct snmp_varbind
*next
;
83 /* previous pointer, NULL for first in list */
84 struct snmp_varbind
*prev
;
86 /* object identifier length (in s32_t) */
88 /* object identifier array */
91 /* object value ASN1 type */
93 /* object value length (in u8_t) */
98 /* encoding varbind seq length length */
100 /* encoding object identifier length length */
102 /* encoding object value length length */
104 /* encoding varbind seq length */
106 /* encoding object identifier length */
108 /* encoding object value length */
112 struct snmp_varbind_root
114 struct snmp_varbind
*head
;
115 struct snmp_varbind
*tail
;
116 /* number of variable bindings in list */
118 /* encoding varbind-list seq length length */
120 /* encoding varbind-list seq length */
124 /** output response message header length fields */
125 struct snmp_resp_header_lengths
127 /* encoding error-index length length */
129 /* encoding error-status length length */
131 /* encoding request id length length */
133 /* encoding pdu length length */
135 /* encoding community length length */
137 /* encoding version length length */
139 /* encoding sequence length length */
142 /* encoding error-index length */
144 /* encoding error-status length */
146 /* encoding request id length */
148 /* encoding pdu length */
150 /* encoding community length */
152 /* encoding version length */
154 /* encoding sequence length */
158 /** output response message header length fields */
159 struct snmp_trap_header_lengths
161 /* encoding timestamp length length */
163 /* encoding specific-trap length length */
165 /* encoding generic-trap length length */
167 /* encoding agent-addr length length */
169 /* encoding enterprise-id length length */
171 /* encoding pdu length length */
173 /* encoding community length length */
175 /* encoding version length length */
177 /* encoding sequence length length */
180 /* encoding timestamp length */
182 /* encoding specific-trap length */
184 /* encoding generic-trap length */
186 /* encoding agent-addr length */
188 /* encoding enterprise-id length */
190 /* encoding pdu length */
192 /* encoding community length */
194 /* encoding version length */
196 /* encoding sequence length */
200 /* Accepting new SNMP messages. */
201 #define SNMP_MSG_EMPTY 0
202 /* Search for matching object for variable binding. */
203 #define SNMP_MSG_SEARCH_OBJ 1
204 /* Perform SNMP operation on in-memory object.
205 Pass-through states, for symmetry only. */
206 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2
207 #define SNMP_MSG_INTERNAL_GET_VALUE 3
208 #define SNMP_MSG_INTERNAL_SET_TEST 4
209 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
210 #define SNMP_MSG_INTERNAL_SET_VALUE 6
211 /* Perform SNMP operation on object located externally.
212 In theory this could be used for building a proxy agent.
213 Practical use is for an enterprise spc. app. gateway. */
214 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
215 #define SNMP_MSG_EXTERNAL_GET_VALUE 8
216 #define SNMP_MSG_EXTERNAL_SET_TEST 9
217 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
218 #define SNMP_MSG_EXTERNAL_SET_VALUE 11
220 #define SNMP_COMMUNITY_STR_LEN 64
221 struct snmp_msg_pstat
223 /* lwIP local port (161) binding */
225 /* source IP address */
227 /* source UDP port */
237 /* community name (zero terminated) */
238 u8_t community
[SNMP_COMMUNITY_STR_LEN
+ 1];
239 /* community string length (exclusive zero term) */
241 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */
243 /* saved arguments for MSG_EXTERNAL_x */
244 struct mib_external_node
*ext_mib_node
;
245 struct snmp_name_ptr ext_name_ptr
;
246 struct obj_def ext_object_def
;
247 struct snmp_obj_id ext_oid
;
248 /* index into input variable binding list */
250 /* ptr into input variable binding list */
251 struct snmp_varbind
*vb_ptr
;
252 /* list of variable bindings from input */
253 struct snmp_varbind_root invb
;
254 /* list of variable bindings to output */
255 struct snmp_varbind_root outvb
;
256 /* output response lengths used in ASN encoding */
257 struct snmp_resp_header_lengths rhl
;
262 /* lwIP local port (161) binding */
264 /* destination IP address in network order */
267 /* source enterprise ID (sysObjectID) */
268 struct snmp_obj_id
*enterprise
;
269 /* source IP address, raw network order format */
271 /* generic trap code */
273 /* specific trap code */
277 /* list of variable bindings to output */
278 struct snmp_varbind_root outvb
;
279 /* output trap lengths used in ASN encoding */
280 struct snmp_trap_header_lengths thl
;
283 /** Agent Version constant, 0 = v1 oddity */
284 extern const s32_t snmp_version
;
285 /** Agent default "public" community string */
286 extern const char snmp_publiccommunity
[7];
288 extern struct snmp_msg_trap trap_msg
;
290 /** Agent setup, start listening to port 161. */
291 void snmp_init(void);
292 void snmp_trap_dst_enable(u8_t dst_idx
, u8_t enable
);
293 void snmp_trap_dst_ip_set(u8_t dst_idx
, ip_addr_t
*dst
);
295 /** Varbind-list functions. */
296 struct snmp_varbind
* snmp_varbind_alloc(struct snmp_obj_id
*oid
, u8_t type
, u8_t len
);
297 void snmp_varbind_free(struct snmp_varbind
*vb
);
298 void snmp_varbind_list_free(struct snmp_varbind_root
*root
);
299 void snmp_varbind_tail_add(struct snmp_varbind_root
*root
, struct snmp_varbind
*vb
);
300 struct snmp_varbind
* snmp_varbind_tail_remove(struct snmp_varbind_root
*root
);
302 /** Handle an internal (recv) or external (private response) event. */
303 void snmp_msg_event(u8_t request_id
);
304 err_t
snmp_send_response(struct snmp_msg_pstat
*m_stat
);
305 err_t
snmp_send_trap(s8_t generic_trap
, struct snmp_obj_id
*eoid
, s32_t specific_trap
);
306 void snmp_coldstart_trap(void);
307 void snmp_authfail_trap(void);
313 #endif /* LWIP_SNMP */
315 #endif /* __LWIP_SNMP_MSG_H__ */