]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/lwip/snmp_msg.h
MIB-2 object values near to completion, just committing for keeping the flame alive.
[pes-rpp/rpp-lwip.git] / src / include / lwip / snmp_msg.h
1 /**
2  * @file
3  * [EXPERIMENTAL] 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
42 #if SNMP_PRIVATE_MIB
43 #include "private_mib.h"
44 #endif
45
46 #define SNMP_IN_PORT 161
47 #define SNMP_TRAP_PORT 162
48
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
55
56 struct snmp_varbind
57 {
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;
62
63   /* object identifier length (in s32_t) */
64   u8_t ident_len;
65   /* object identifier array */
66   s32_t *ident;
67
68   /* object value ASN1 type */
69   u8_t value_type;
70   /* object value length (in u8_t) */
71   u8_t value_len;
72   /* object value */
73   void *value;
74
75   /* encoding varbind seq length length */
76   u8_t seqlenlen;
77   /* encoding object identifier length length */
78   u8_t olenlen;
79   /* encoding object value length length */
80   u8_t vlenlen;
81   /* encoding varbind seq length */
82   u16_t seqlen;
83   /* encoding object identifier length */
84   u16_t olen;
85   /* encoding object value length */
86   u16_t vlen;
87 };
88
89 struct snmp_varbind_root
90 {
91   struct snmp_varbind *head;
92   struct snmp_varbind *tail;
93   /* number of variable bindings in list */
94   u8_t count;
95   /* encoding varbind-list seq length length */
96   u8_t seqlenlen;
97   /* encoding varbind-list seq length */
98   u16_t seqlen;
99 };
100
101 /** output response message header length fields */
102 struct snmp_resp_header_lengths
103 {
104   /* encoding error-index length length */
105   u8_t erridxlenlen;
106   /* encoding error-status length length */
107   u8_t errstatlenlen;
108   /* encoding request id length length */
109   u8_t ridlenlen;
110   /* encoding pdu length length */
111   u8_t pdulenlen;
112   /* encoding community length length */
113   u8_t comlenlen;
114   /* encoding version length length */
115   u8_t verlenlen;
116   /* encoding sequence length length */
117   u8_t seqlenlen;
118
119   /* encoding error-index length */
120   u16_t erridxlen;
121   /* encoding error-status length */
122   u16_t errstatlen;
123   /* encoding request id length */
124   u16_t ridlen;
125   /* encoding pdu length */
126   u16_t pdulen;
127   /* encoding community length */
128   u16_t comlen;
129   /* encoding version length */
130   u16_t verlen;
131   /* encoding sequence length */
132   u16_t seqlen;
133 };
134
135 /** output response message header length fields */
136 struct snmp_trap_header_lengths
137 {
138   /* encoding timestamp length length */
139   u8_t tslenlen;
140   /* encoding specific-trap length length */
141   u8_t strplenlen;
142   /* encoding generic-trap length length */
143   u8_t gtrplenlen;
144   /* encoding agent-addr length length */
145   u8_t aaddrlenlen;
146   /* encoding enterprise-id length length */
147   u8_t eidlenlen;
148   /* encoding pdu length length */
149   u8_t pdulenlen;
150   /* encoding community length length */
151   u8_t comlenlen;
152   /* encoding version length length */
153   u8_t verlenlen;
154   /* encoding sequence length length */
155   u8_t seqlenlen;
156
157   /* encoding timestamp length */
158   u16_t tslen;
159   /* encoding specific-trap length */
160   u16_t strplen;
161   /* encoding generic-trap length */
162   u16_t gtrplen;
163   /* encoding agent-addr length */
164   u16_t aaddrlen;
165   /* encoding enterprise-id length */
166   u16_t eidlen;
167   /* encoding pdu length */
168   u16_t pdulen;
169   /* encoding community length */
170   u16_t comlen;
171   /* encoding version length */
172   u16_t verlen;
173   /* encoding sequence length */
174   u16_t seqlen;
175 };
176
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
185
186
187 #define SNMP_COMMUNITY_STR_LEN 64
188 struct snmp_msg_pstat
189 {
190 #if 0
191   struct snmp_msg_pstat *next;
192 #endif
193   /* lwIP local port (161) binding */
194   struct udp_pcb *pcb;
195   /* source IP address */
196   struct ip_addr sip;
197   /* source UDP port */
198   u16_t sp;
199   /* request type */
200   u8_t rt;
201   /* request ID */
202   s32_t rid;
203   /* error status */
204   s32_t error_status;
205   /* error index */
206   s32_t error_index;
207   /* community name (zero terminated) */
208   u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
209   /* community string length (exclusive zero term) */
210   u8_t com_strlen;
211   /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL */
212   u8_t state;
213   /* index into input variable binding list */
214   u8_t vb_idx;
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;
223 #if SNMP_PRIVATE_MIB
224   struct private_state ps;
225 #endif
226 };
227
228 struct snmp_msg_trap
229 {
230 #if 0
231   struct snmp_msg_trap *next;
232 #endif
233   /* lwIP local port (161) binding */
234   struct udp_pcb *pcb;
235   /* destination IP address in network order */
236   struct ip_addr dip;
237
238   /* source enterprise ID (sysObjectID) */
239   struct snmp_obj_id *enterprise;
240   /* source IP address, raw network order format */
241   u8_t sip_raw[4];
242   /* generic trap code */
243   u32_t gen_trap;
244   /* specific trap code */
245   u32_t spc_trap;
246   /* timestamp */
247   u32_t ts;
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;
252 #if SNMP_PRIVATE_MIB
253   /** @todo is this really needed? */
254   struct private_state ps;
255 #endif
256 };
257
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];
262
263 extern struct snmp_msg_trap trap_msg;
264
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);
271
272 #endif