1 |
606 |
jeremybenn |
/**
|
2 |
|
|
* @file
|
3 |
|
|
* SNMP Agent message handling structures.
|
4 |
|
|
*/
|
5 |
|
|
|
6 |
|
|
/*
|
7 |
|
|
* Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
|
8 |
|
|
* All rights reserved.
|
9 |
|
|
*
|
10 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
11 |
|
|
* are permitted provided that the following conditions are met:
|
12 |
|
|
*
|
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.
|
20 |
|
|
*
|
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
|
30 |
|
|
* OF SUCH DAMAGE.
|
31 |
|
|
*
|
32 |
|
|
* Author: Christiaan Simons <christiaan.simons@axon.tv>
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
|
|
#ifndef __LWIP_SNMP_MSG_H__
|
36 |
|
|
#define __LWIP_SNMP_MSG_H__
|
37 |
|
|
|
38 |
|
|
#include "lwip/opt.h"
|
39 |
|
|
#include "arch/cc.h"
|
40 |
|
|
#include "lwip/snmp.h"
|
41 |
|
|
#include "lwip/snmp_structs.h"
|
42 |
|
|
|
43 |
|
|
#if SNMP_PRIVATE_MIB
|
44 |
|
|
#include "private_mib.h"
|
45 |
|
|
#endif
|
46 |
|
|
|
47 |
|
|
#define SNMP_IN_PORT 161
|
48 |
|
|
#define SNMP_TRAP_PORT 162
|
49 |
|
|
|
50 |
|
|
#define SNMP_ES_NOERROR 0
|
51 |
|
|
#define SNMP_ES_TOOBIG 1
|
52 |
|
|
#define SNMP_ES_NOSUCHNAME 2
|
53 |
|
|
#define SNMP_ES_BADVALUE 3
|
54 |
|
|
#define SNMP_ES_READONLY 4
|
55 |
|
|
#define SNMP_ES_GENERROR 5
|
56 |
|
|
|
57 |
|
|
#define SNMP_GENTRAP_COLDSTART 0
|
58 |
|
|
#define SNMP_GENTRAP_WARMSTART 1
|
59 |
|
|
#define SNMP_GENTRAP_AUTHFAIL 4
|
60 |
|
|
#define SNMP_GENTRAP_ENTERPRISESPC 6
|
61 |
|
|
|
62 |
|
|
struct snmp_varbind
|
63 |
|
|
{
|
64 |
|
|
/* next pointer, NULL for last in list */
|
65 |
|
|
struct snmp_varbind *next;
|
66 |
|
|
/* previous pointer, NULL for first in list */
|
67 |
|
|
struct snmp_varbind *prev;
|
68 |
|
|
|
69 |
|
|
/* object identifier length (in s32_t) */
|
70 |
|
|
u8_t ident_len;
|
71 |
|
|
/* object identifier array */
|
72 |
|
|
s32_t *ident;
|
73 |
|
|
|
74 |
|
|
/* object value ASN1 type */
|
75 |
|
|
u8_t value_type;
|
76 |
|
|
/* object value length (in u8_t) */
|
77 |
|
|
u8_t value_len;
|
78 |
|
|
/* object value */
|
79 |
|
|
void *value;
|
80 |
|
|
|
81 |
|
|
/* encoding varbind seq length length */
|
82 |
|
|
u8_t seqlenlen;
|
83 |
|
|
/* encoding object identifier length length */
|
84 |
|
|
u8_t olenlen;
|
85 |
|
|
/* encoding object value length length */
|
86 |
|
|
u8_t vlenlen;
|
87 |
|
|
/* encoding varbind seq length */
|
88 |
|
|
u16_t seqlen;
|
89 |
|
|
/* encoding object identifier length */
|
90 |
|
|
u16_t olen;
|
91 |
|
|
/* encoding object value length */
|
92 |
|
|
u16_t vlen;
|
93 |
|
|
};
|
94 |
|
|
|
95 |
|
|
struct snmp_varbind_root
|
96 |
|
|
{
|
97 |
|
|
struct snmp_varbind *head;
|
98 |
|
|
struct snmp_varbind *tail;
|
99 |
|
|
/* number of variable bindings in list */
|
100 |
|
|
u8_t count;
|
101 |
|
|
/* encoding varbind-list seq length length */
|
102 |
|
|
u8_t seqlenlen;
|
103 |
|
|
/* encoding varbind-list seq length */
|
104 |
|
|
u16_t seqlen;
|
105 |
|
|
};
|
106 |
|
|
|
107 |
|
|
/** output response message header length fields */
|
108 |
|
|
struct snmp_resp_header_lengths
|
109 |
|
|
{
|
110 |
|
|
/* encoding error-index length length */
|
111 |
|
|
u8_t erridxlenlen;
|
112 |
|
|
/* encoding error-status length length */
|
113 |
|
|
u8_t errstatlenlen;
|
114 |
|
|
/* encoding request id length length */
|
115 |
|
|
u8_t ridlenlen;
|
116 |
|
|
/* encoding pdu length length */
|
117 |
|
|
u8_t pdulenlen;
|
118 |
|
|
/* encoding community length length */
|
119 |
|
|
u8_t comlenlen;
|
120 |
|
|
/* encoding version length length */
|
121 |
|
|
u8_t verlenlen;
|
122 |
|
|
/* encoding sequence length length */
|
123 |
|
|
u8_t seqlenlen;
|
124 |
|
|
|
125 |
|
|
/* encoding error-index length */
|
126 |
|
|
u16_t erridxlen;
|
127 |
|
|
/* encoding error-status length */
|
128 |
|
|
u16_t errstatlen;
|
129 |
|
|
/* encoding request id length */
|
130 |
|
|
u16_t ridlen;
|
131 |
|
|
/* encoding pdu length */
|
132 |
|
|
u16_t pdulen;
|
133 |
|
|
/* encoding community length */
|
134 |
|
|
u16_t comlen;
|
135 |
|
|
/* encoding version length */
|
136 |
|
|
u16_t verlen;
|
137 |
|
|
/* encoding sequence length */
|
138 |
|
|
u16_t seqlen;
|
139 |
|
|
};
|
140 |
|
|
|
141 |
|
|
/** output response message header length fields */
|
142 |
|
|
struct snmp_trap_header_lengths
|
143 |
|
|
{
|
144 |
|
|
/* encoding timestamp length length */
|
145 |
|
|
u8_t tslenlen;
|
146 |
|
|
/* encoding specific-trap length length */
|
147 |
|
|
u8_t strplenlen;
|
148 |
|
|
/* encoding generic-trap length length */
|
149 |
|
|
u8_t gtrplenlen;
|
150 |
|
|
/* encoding agent-addr length length */
|
151 |
|
|
u8_t aaddrlenlen;
|
152 |
|
|
/* encoding enterprise-id length length */
|
153 |
|
|
u8_t eidlenlen;
|
154 |
|
|
/* encoding pdu length length */
|
155 |
|
|
u8_t pdulenlen;
|
156 |
|
|
/* encoding community length length */
|
157 |
|
|
u8_t comlenlen;
|
158 |
|
|
/* encoding version length length */
|
159 |
|
|
u8_t verlenlen;
|
160 |
|
|
/* encoding sequence length length */
|
161 |
|
|
u8_t seqlenlen;
|
162 |
|
|
|
163 |
|
|
/* encoding timestamp length */
|
164 |
|
|
u16_t tslen;
|
165 |
|
|
/* encoding specific-trap length */
|
166 |
|
|
u16_t strplen;
|
167 |
|
|
/* encoding generic-trap length */
|
168 |
|
|
u16_t gtrplen;
|
169 |
|
|
/* encoding agent-addr length */
|
170 |
|
|
u16_t aaddrlen;
|
171 |
|
|
/* encoding enterprise-id length */
|
172 |
|
|
u16_t eidlen;
|
173 |
|
|
/* encoding pdu length */
|
174 |
|
|
u16_t pdulen;
|
175 |
|
|
/* encoding community length */
|
176 |
|
|
u16_t comlen;
|
177 |
|
|
/* encoding version length */
|
178 |
|
|
u16_t verlen;
|
179 |
|
|
/* encoding sequence length */
|
180 |
|
|
u16_t seqlen;
|
181 |
|
|
};
|
182 |
|
|
|
183 |
|
|
/* Accepting new SNMP messages. */
|
184 |
|
|
#define SNMP_MSG_EMPTY 0
|
185 |
|
|
/* Search for matching object for variable binding. */
|
186 |
|
|
#define SNMP_MSG_SEARCH_OBJ 1
|
187 |
|
|
/* Perform SNMP operation on in-memory object.
|
188 |
|
|
Pass-through states, for symmetry only. */
|
189 |
|
|
#define SNMP_MSG_INTERNAL_GET_OBJDEF 2
|
190 |
|
|
#define SNMP_MSG_INTERNAL_GET_VALUE 3
|
191 |
|
|
#define SNMP_MSG_INTERNAL_SET_TEST 4
|
192 |
|
|
#define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
|
193 |
|
|
#define SNMP_MSG_INTERNAL_SET_VALUE 6
|
194 |
|
|
/* Perform SNMP operation on object located externally.
|
195 |
|
|
In theory this could be used for building a proxy agent.
|
196 |
|
|
Practical use is for an enterprise spc. app. gateway. */
|
197 |
|
|
#define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
|
198 |
|
|
#define SNMP_MSG_EXTERNAL_GET_VALUE 8
|
199 |
|
|
#define SNMP_MSG_EXTERNAL_SET_TEST 9
|
200 |
|
|
#define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
|
201 |
|
|
#define SNMP_MSG_EXTERNAL_SET_VALUE 11
|
202 |
|
|
|
203 |
|
|
#define SNMP_COMMUNITY_STR_LEN 64
|
204 |
|
|
struct snmp_msg_pstat
|
205 |
|
|
{
|
206 |
|
|
/* lwIP local port (161) binding */
|
207 |
|
|
struct udp_pcb *pcb;
|
208 |
|
|
/* source IP address */
|
209 |
|
|
struct ip_addr sip;
|
210 |
|
|
/* source UDP port */
|
211 |
|
|
u16_t sp;
|
212 |
|
|
/* request type */
|
213 |
|
|
u8_t rt;
|
214 |
|
|
/* request ID */
|
215 |
|
|
s32_t rid;
|
216 |
|
|
/* error status */
|
217 |
|
|
s32_t error_status;
|
218 |
|
|
/* error index */
|
219 |
|
|
s32_t error_index;
|
220 |
|
|
/* community name (zero terminated) */
|
221 |
|
|
u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
|
222 |
|
|
/* community string length (exclusive zero term) */
|
223 |
|
|
u8_t com_strlen;
|
224 |
|
|
/* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */
|
225 |
|
|
u8_t state;
|
226 |
|
|
/* saved arguments for MSG_EXTERNAL_x */
|
227 |
|
|
struct mib_external_node *ext_mib_node;
|
228 |
|
|
struct snmp_name_ptr ext_name_ptr;
|
229 |
|
|
struct obj_def ext_object_def;
|
230 |
|
|
struct snmp_obj_id ext_oid;
|
231 |
|
|
/* index into input variable binding list */
|
232 |
|
|
u8_t vb_idx;
|
233 |
|
|
/* ptr into input variable binding list */
|
234 |
|
|
struct snmp_varbind *vb_ptr;
|
235 |
|
|
/* list of variable bindings from input */
|
236 |
|
|
struct snmp_varbind_root invb;
|
237 |
|
|
/* list of variable bindings to output */
|
238 |
|
|
struct snmp_varbind_root outvb;
|
239 |
|
|
/* output response lengths used in ASN encoding */
|
240 |
|
|
struct snmp_resp_header_lengths rhl;
|
241 |
|
|
};
|
242 |
|
|
|
243 |
|
|
struct snmp_msg_trap
|
244 |
|
|
{
|
245 |
|
|
/* lwIP local port (161) binding */
|
246 |
|
|
struct udp_pcb *pcb;
|
247 |
|
|
/* destination IP address in network order */
|
248 |
|
|
struct ip_addr dip;
|
249 |
|
|
|
250 |
|
|
/* source enterprise ID (sysObjectID) */
|
251 |
|
|
struct snmp_obj_id *enterprise;
|
252 |
|
|
/* source IP address, raw network order format */
|
253 |
|
|
u8_t sip_raw[4];
|
254 |
|
|
/* generic trap code */
|
255 |
|
|
u32_t gen_trap;
|
256 |
|
|
/* specific trap code */
|
257 |
|
|
u32_t spc_trap;
|
258 |
|
|
/* timestamp */
|
259 |
|
|
u32_t ts;
|
260 |
|
|
/* list of variable bindings to output */
|
261 |
|
|
struct snmp_varbind_root outvb;
|
262 |
|
|
/* output trap lengths used in ASN encoding */
|
263 |
|
|
struct snmp_trap_header_lengths thl;
|
264 |
|
|
};
|
265 |
|
|
|
266 |
|
|
/** Agent Version constant, 0 = v1 oddity */
|
267 |
|
|
extern const s32_t snmp_version;
|
268 |
|
|
/** Agent default "public" community string */
|
269 |
|
|
extern const char snmp_publiccommunity[7];
|
270 |
|
|
|
271 |
|
|
extern struct snmp_msg_trap trap_msg;
|
272 |
|
|
|
273 |
|
|
/** Agent setup, start listening to port 161. */
|
274 |
|
|
void snmp_init(void);
|
275 |
|
|
void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable);
|
276 |
|
|
void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst);
|
277 |
|
|
|
278 |
|
|
/** Varbind-list functions. */
|
279 |
|
|
struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len);
|
280 |
|
|
void snmp_varbind_free(struct snmp_varbind *vb);
|
281 |
|
|
void snmp_varbind_list_free(struct snmp_varbind_root *root);
|
282 |
|
|
void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb);
|
283 |
|
|
struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root);
|
284 |
|
|
|
285 |
|
|
/** Handle an internal (recv) or external (private response) event. */
|
286 |
|
|
void snmp_msg_event(u8_t request_id);
|
287 |
|
|
err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
|
288 |
|
|
err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap);
|
289 |
|
|
void snmp_coldstart_trap(void);
|
290 |
|
|
void snmp_authfail_trap(void);
|
291 |
|
|
|
292 |
|
|
#endif
|