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 "arch/cc.h"
\r
40 #include "lwip/snmp.h"
\r
41 #include "lwip/snmp_structs.h"
\r
43 #if SNMP_PRIVATE_MIB
\r
44 #include "private_mib.h"
\r
47 #define SNMP_IN_PORT 161
\r
48 #define SNMP_TRAP_PORT 162
\r
50 #define SNMP_ES_NOERROR 0
\r
51 #define SNMP_ES_TOOBIG 1
\r
52 #define SNMP_ES_NOSUCHNAME 2
\r
53 #define SNMP_ES_BADVALUE 3
\r
54 #define SNMP_ES_READONLY 4
\r
55 #define SNMP_ES_GENERROR 5
\r
57 #define SNMP_GENTRAP_COLDSTART 0
\r
58 #define SNMP_GENTRAP_WARMSTART 1
\r
59 #define SNMP_GENTRAP_AUTHFAIL 4
\r
60 #define SNMP_GENTRAP_ENTERPRISESPC 6
\r
64 /* next pointer, NULL for last in list */
\r
65 struct snmp_varbind *next;
\r
66 /* previous pointer, NULL for first in list */
\r
67 struct snmp_varbind *prev;
\r
69 /* object identifier length (in s32_t) */
\r
71 /* object identifier array */
\r
74 /* object value ASN1 type */
\r
76 /* object value length (in u8_t) */
\r
81 /* encoding varbind seq length length */
\r
83 /* encoding object identifier length length */
\r
85 /* encoding object value length length */
\r
87 /* encoding varbind seq length */
\r
89 /* encoding object identifier length */
\r
91 /* encoding object value length */
\r
95 struct snmp_varbind_root
\r
97 struct snmp_varbind *head;
\r
98 struct snmp_varbind *tail;
\r
99 /* number of variable bindings in list */
\r
101 /* encoding varbind-list seq length length */
\r
103 /* encoding varbind-list seq length */
\r
107 /** output response message header length fields */
\r
108 struct snmp_resp_header_lengths
\r
110 /* encoding error-index length length */
\r
112 /* encoding error-status length length */
\r
113 u8_t errstatlenlen;
\r
114 /* encoding request id length length */
\r
116 /* encoding pdu length length */
\r
118 /* encoding community length length */
\r
120 /* encoding version length length */
\r
122 /* encoding sequence length length */
\r
125 /* encoding error-index length */
\r
127 /* encoding error-status length */
\r
129 /* encoding request id length */
\r
131 /* encoding pdu length */
\r
133 /* encoding community length */
\r
135 /* encoding version length */
\r
137 /* encoding sequence length */
\r
141 /** output response message header length fields */
\r
142 struct snmp_trap_header_lengths
\r
144 /* encoding timestamp length length */
\r
146 /* encoding specific-trap length length */
\r
148 /* encoding generic-trap length length */
\r
150 /* encoding agent-addr length length */
\r
152 /* encoding enterprise-id length length */
\r
154 /* encoding pdu length length */
\r
156 /* encoding community length length */
\r
158 /* encoding version length length */
\r
160 /* encoding sequence length length */
\r
163 /* encoding timestamp length */
\r
165 /* encoding specific-trap length */
\r
167 /* encoding generic-trap length */
\r
169 /* encoding agent-addr length */
\r
171 /* encoding enterprise-id length */
\r
173 /* encoding pdu length */
\r
175 /* encoding community length */
\r
177 /* encoding version length */
\r
179 /* encoding sequence length */
\r
183 /* Accepting new SNMP messages. */
\r
184 #define SNMP_MSG_EMPTY 0
\r
185 /* Search for matching object for variable binding. */
\r
186 #define SNMP_MSG_SEARCH_OBJ 1
\r
187 /* Perform SNMP operation on in-memory object.
\r
188 Pass-through states, for symmetry only. */
\r
189 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2
\r
190 #define SNMP_MSG_INTERNAL_GET_VALUE 3
\r
191 #define SNMP_MSG_INTERNAL_SET_TEST 4
\r
192 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
\r
193 #define SNMP_MSG_INTERNAL_SET_VALUE 6
\r
194 /* Perform SNMP operation on object located externally.
\r
195 In theory this could be used for building a proxy agent.
\r
196 Practical use is for an enterprise spc. app. gateway. */
\r
197 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
\r
198 #define SNMP_MSG_EXTERNAL_GET_VALUE 8
\r
199 #define SNMP_MSG_EXTERNAL_SET_TEST 9
\r
200 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
\r
201 #define SNMP_MSG_EXTERNAL_SET_VALUE 11
\r
203 #define SNMP_COMMUNITY_STR_LEN 64
\r
204 struct snmp_msg_pstat
\r
206 /* lwIP local port (161) binding */
\r
207 struct udp_pcb *pcb;
\r
208 /* source IP address */
\r
209 struct ip_addr sip;
\r
210 /* source UDP port */
\r
217 s32_t error_status;
\r
220 /* community name (zero terminated) */
\r
221 u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
\r
222 /* community string length (exclusive zero term) */
\r
224 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */
\r
226 /* saved arguments for MSG_EXTERNAL_x */
\r
227 struct mib_external_node *ext_mib_node;
\r
228 struct snmp_name_ptr ext_name_ptr;
\r
229 struct obj_def ext_object_def;
\r
230 struct snmp_obj_id ext_oid;
\r
231 /* index into input variable binding list */
\r
233 /* ptr into input variable binding list */
\r
234 struct snmp_varbind *vb_ptr;
\r
235 /* list of variable bindings from input */
\r
236 struct snmp_varbind_root invb;
\r
237 /* list of variable bindings to output */
\r
238 struct snmp_varbind_root outvb;
\r
239 /* output response lengths used in ASN encoding */
\r
240 struct snmp_resp_header_lengths rhl;
\r
243 struct snmp_msg_trap
\r
245 /* lwIP local port (161) binding */
\r
246 struct udp_pcb *pcb;
\r
247 /* destination IP address in network order */
\r
248 struct ip_addr dip;
\r
250 /* source enterprise ID (sysObjectID) */
\r
251 struct snmp_obj_id *enterprise;
\r
252 /* source IP address, raw network order format */
\r
254 /* generic trap code */
\r
256 /* specific trap code */
\r
260 /* list of variable bindings to output */
\r
261 struct snmp_varbind_root outvb;
\r
262 /* output trap lengths used in ASN encoding */
\r
263 struct snmp_trap_header_lengths thl;
\r
266 /** Agent Version constant, 0 = v1 oddity */
\r
267 extern const s32_t snmp_version;
\r
268 /** Agent default "public" community string */
\r
269 extern const char snmp_publiccommunity[7];
\r
271 extern struct snmp_msg_trap trap_msg;
\r
273 /** Agent setup, start listening to port 161. */
\r
274 void snmp_init(void);
\r
275 void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable);
\r
276 void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst);
\r
278 /** Varbind-list functions. */
\r
279 struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len);
\r
280 void snmp_varbind_free(struct snmp_varbind *vb);
\r
281 void snmp_varbind_list_free(struct snmp_varbind_root *root);
\r
282 void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb);
\r
283 struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root);
\r
285 /** Handle an internal (recv) or external (private response) event. */
\r
286 void snmp_msg_event(u8_t request_id);
\r
287 err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
\r
288 err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap);
\r
289 void snmp_coldstart_trap(void);
\r
290 void snmp_authfail_trap(void);
\r