3 * SNMP Agent message handling structures.
\r
7 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
\r
8 * All rights reserved.
\r
10 * Redistribution and use in source and binary forms, with or without modification,
\r
11 * are permitted provided that the following conditions are met:
\r
13 * 1. Redistributions of source code must retain the above copyright notice,
\r
14 * this list of conditions and the following disclaimer.
\r
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
16 * this list of conditions and the following disclaimer in the documentation
\r
17 * and/or other materials provided with the distribution.
\r
18 * 3. The name of the author may not be used to endorse or promote products
\r
19 * derived from this software without specific prior written permission.
\r
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
\r
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
\r
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
\r
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
\r
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
\r
32 * Author: Christiaan Simons <christiaan.simons@axon.tv>
\r
35 #ifndef __LWIP_SNMP_MSG_H__
\r
36 #define __LWIP_SNMP_MSG_H__
\r
38 #include "lwip/opt.h"
\r
39 #include "lwip/snmp.h"
\r
40 #include "lwip/snmp_structs.h"
\r
42 #if SNMP_PRIVATE_MIB
\r
43 #include "private_mib.h"
\r
50 /* The listen port of the SNMP agent. Clients have to make their requests to
\r
51 this port. Most standard clients won't work if you change this! */
\r
52 #ifndef SNMP_IN_PORT
\r
53 #define SNMP_IN_PORT 161
\r
55 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't
\r
56 work if you change this! */
\r
57 #ifndef SNMP_TRAP_PORT
\r
58 #define SNMP_TRAP_PORT 162
\r
61 #define SNMP_ES_NOERROR 0
\r
62 #define SNMP_ES_TOOBIG 1
\r
63 #define SNMP_ES_NOSUCHNAME 2
\r
64 #define SNMP_ES_BADVALUE 3
\r
65 #define SNMP_ES_READONLY 4
\r
66 #define SNMP_ES_GENERROR 5
\r
68 #define SNMP_GENTRAP_COLDSTART 0
\r
69 #define SNMP_GENTRAP_WARMSTART 1
\r
70 #define SNMP_GENTRAP_AUTHFAIL 4
\r
71 #define SNMP_GENTRAP_ENTERPRISESPC 6
\r
75 /* next pointer, NULL for last in list */
\r
76 struct snmp_varbind *next;
\r
77 /* previous pointer, NULL for first in list */
\r
78 struct snmp_varbind *prev;
\r
80 /* object identifier length (in s32_t) */
\r
82 /* object identifier array */
\r
85 /* object value ASN1 type */
\r
87 /* object value length (in u8_t) */
\r
92 /* encoding varbind seq length length */
\r
94 /* encoding object identifier length length */
\r
96 /* encoding object value length length */
\r
98 /* encoding varbind seq length */
\r
100 /* encoding object identifier length */
\r
102 /* encoding object value length */
\r
106 struct snmp_varbind_root
\r
108 struct snmp_varbind *head;
\r
109 struct snmp_varbind *tail;
\r
110 /* number of variable bindings in list */
\r
112 /* encoding varbind-list seq length length */
\r
114 /* encoding varbind-list seq length */
\r
118 /** output response message header length fields */
\r
119 struct snmp_resp_header_lengths
\r
121 /* encoding error-index length length */
\r
123 /* encoding error-status length length */
\r
124 u8_t errstatlenlen;
\r
125 /* encoding request id length length */
\r
127 /* encoding pdu length length */
\r
129 /* encoding community length length */
\r
131 /* encoding version length length */
\r
133 /* encoding sequence length length */
\r
136 /* encoding error-index length */
\r
138 /* encoding error-status length */
\r
140 /* encoding request id length */
\r
142 /* encoding pdu length */
\r
144 /* encoding community length */
\r
146 /* encoding version length */
\r
148 /* encoding sequence length */
\r
152 /** output response message header length fields */
\r
153 struct snmp_trap_header_lengths
\r
155 /* encoding timestamp length length */
\r
157 /* encoding specific-trap length length */
\r
159 /* encoding generic-trap length length */
\r
161 /* encoding agent-addr length length */
\r
163 /* encoding enterprise-id length length */
\r
165 /* encoding pdu length length */
\r
167 /* encoding community length length */
\r
169 /* encoding version length length */
\r
171 /* encoding sequence length length */
\r
174 /* encoding timestamp length */
\r
176 /* encoding specific-trap length */
\r
178 /* encoding generic-trap length */
\r
180 /* encoding agent-addr length */
\r
182 /* encoding enterprise-id length */
\r
184 /* encoding pdu length */
\r
186 /* encoding community length */
\r
188 /* encoding version length */
\r
190 /* encoding sequence length */
\r
194 /* Accepting new SNMP messages. */
\r
195 #define SNMP_MSG_EMPTY 0
\r
196 /* Search for matching object for variable binding. */
\r
197 #define SNMP_MSG_SEARCH_OBJ 1
\r
198 /* Perform SNMP operation on in-memory object.
\r
199 Pass-through states, for symmetry only. */
\r
200 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2
\r
201 #define SNMP_MSG_INTERNAL_GET_VALUE 3
\r
202 #define SNMP_MSG_INTERNAL_SET_TEST 4
\r
203 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
\r
204 #define SNMP_MSG_INTERNAL_SET_VALUE 6
\r
205 /* Perform SNMP operation on object located externally.
\r
206 In theory this could be used for building a proxy agent.
\r
207 Practical use is for an enterprise spc. app. gateway. */
\r
208 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
\r
209 #define SNMP_MSG_EXTERNAL_GET_VALUE 8
\r
210 #define SNMP_MSG_EXTERNAL_SET_TEST 9
\r
211 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
\r
212 #define SNMP_MSG_EXTERNAL_SET_VALUE 11
\r
214 #define SNMP_COMMUNITY_STR_LEN 64
\r
215 struct snmp_msg_pstat
\r
217 /* lwIP local port (161) binding */
\r
218 struct udp_pcb *pcb;
\r
219 /* source IP address */
\r
220 struct ip_addr sip;
\r
221 /* source UDP port */
\r
228 s32_t error_status;
\r
231 /* community name (zero terminated) */
\r
232 u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
\r
233 /* community string length (exclusive zero term) */
\r
235 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */
\r
237 /* saved arguments for MSG_EXTERNAL_x */
\r
238 struct mib_external_node *ext_mib_node;
\r
239 struct snmp_name_ptr ext_name_ptr;
\r
240 struct obj_def ext_object_def;
\r
241 struct snmp_obj_id ext_oid;
\r
242 /* index into input variable binding list */
\r
244 /* ptr into input variable binding list */
\r
245 struct snmp_varbind *vb_ptr;
\r
246 /* list of variable bindings from input */
\r
247 struct snmp_varbind_root invb;
\r
248 /* list of variable bindings to output */
\r
249 struct snmp_varbind_root outvb;
\r
250 /* output response lengths used in ASN encoding */
\r
251 struct snmp_resp_header_lengths rhl;
\r
254 struct snmp_msg_trap
\r
256 /* lwIP local port (161) binding */
\r
257 struct udp_pcb *pcb;
\r
258 /* destination IP address in network order */
\r
259 struct ip_addr dip;
\r
261 /* source enterprise ID (sysObjectID) */
\r
262 struct snmp_obj_id *enterprise;
\r
263 /* source IP address, raw network order format */
\r
265 /* generic trap code */
\r
267 /* specific trap code */
\r
271 /* list of variable bindings to output */
\r
272 struct snmp_varbind_root outvb;
\r
273 /* output trap lengths used in ASN encoding */
\r
274 struct snmp_trap_header_lengths thl;
\r
277 /** Agent Version constant, 0 = v1 oddity */
\r
278 extern const s32_t snmp_version;
\r
279 /** Agent default "public" community string */
\r
280 extern const char snmp_publiccommunity[7];
\r
282 extern struct snmp_msg_trap trap_msg;
\r
284 /** Agent setup, start listening to port 161. */
\r
285 void snmp_init(void);
\r
286 void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable);
\r
287 void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst);
\r
289 /** Varbind-list functions. */
\r
290 struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len);
\r
291 void snmp_varbind_free(struct snmp_varbind *vb);
\r
292 void snmp_varbind_list_free(struct snmp_varbind_root *root);
\r
293 void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb);
\r
294 struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root);
\r
296 /** Handle an internal (recv) or external (private response) event. */
\r
297 void snmp_msg_event(u8_t request_id);
\r
298 err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
\r
299 err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap);
\r
300 void snmp_coldstart_trap(void);
\r
301 void snmp_authfail_trap(void);
\r
307 #endif /* __LWIP_SNMP_MSG_H__ */
\r