Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 0:479ce5546098 1 /**
sherckuith 0:479ce5546098 2 * @file
sherckuith 0:479ce5546098 3 * SNMP Agent message handling structures.
sherckuith 0:479ce5546098 4 */
sherckuith 0:479ce5546098 5
sherckuith 0:479ce5546098 6 /*
sherckuith 0:479ce5546098 7 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
sherckuith 0:479ce5546098 8 * All rights reserved.
sherckuith 0:479ce5546098 9 *
sherckuith 0:479ce5546098 10 * Redistribution and use in source and binary forms, with or without modification,
sherckuith 0:479ce5546098 11 * are permitted provided that the following conditions are met:
sherckuith 0:479ce5546098 12 *
sherckuith 0:479ce5546098 13 * 1. Redistributions of source code must retain the above copyright notice,
sherckuith 0:479ce5546098 14 * this list of conditions and the following disclaimer.
sherckuith 0:479ce5546098 15 * 2. Redistributions in binary form must reproduce the above copyright notice,
sherckuith 0:479ce5546098 16 * this list of conditions and the following disclaimer in the documentation
sherckuith 0:479ce5546098 17 * and/or other materials provided with the distribution.
sherckuith 0:479ce5546098 18 * 3. The name of the author may not be used to endorse or promote products
sherckuith 0:479ce5546098 19 * derived from this software without specific prior written permission.
sherckuith 0:479ce5546098 20 *
sherckuith 0:479ce5546098 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
sherckuith 0:479ce5546098 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sherckuith 0:479ce5546098 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
sherckuith 0:479ce5546098 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sherckuith 0:479ce5546098 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
sherckuith 0:479ce5546098 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sherckuith 0:479ce5546098 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sherckuith 0:479ce5546098 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sherckuith 0:479ce5546098 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
sherckuith 0:479ce5546098 30 * OF SUCH DAMAGE.
sherckuith 0:479ce5546098 31 *
sherckuith 0:479ce5546098 32 * Author: Christiaan Simons <christiaan.simons@axon.tv>
sherckuith 0:479ce5546098 33 */
sherckuith 0:479ce5546098 34
sherckuith 0:479ce5546098 35 #ifndef __LWIP_SNMP_MSG_H__
sherckuith 0:479ce5546098 36 #define __LWIP_SNMP_MSG_H__
sherckuith 0:479ce5546098 37
sherckuith 0:479ce5546098 38 #include "lwip/opt.h"
sherckuith 0:479ce5546098 39 #include "lwip/snmp.h"
sherckuith 0:479ce5546098 40 #include "lwip/snmp_structs.h"
sherckuith 0:479ce5546098 41 #include "lwip/ip_addr.h"
sherckuith 0:479ce5546098 42 #include "lwip/err.h"
sherckuith 0:479ce5546098 43
sherckuith 0:479ce5546098 44 #if LWIP_SNMP
sherckuith 0:479ce5546098 45
sherckuith 0:479ce5546098 46 #if SNMP_PRIVATE_MIB
sherckuith 0:479ce5546098 47 /* When using a private MIB, you have to create a file 'private_mib.h' that contains
sherckuith 0:479ce5546098 48 * a 'struct mib_array_node mib_private' which contains your MIB. */
sherckuith 0:479ce5546098 49 #include "private_mib.h"
sherckuith 0:479ce5546098 50 #endif
sherckuith 0:479ce5546098 51
sherckuith 0:479ce5546098 52 #ifdef __cplusplus
sherckuith 0:479ce5546098 53 extern "C" {
sherckuith 0:479ce5546098 54 #endif
sherckuith 0:479ce5546098 55
sherckuith 0:479ce5546098 56 /* The listen port of the SNMP agent. Clients have to make their requests to
sherckuith 0:479ce5546098 57 this port. Most standard clients won't work if you change this! */
sherckuith 0:479ce5546098 58 #ifndef SNMP_IN_PORT
sherckuith 0:479ce5546098 59 #define SNMP_IN_PORT 161
sherckuith 0:479ce5546098 60 #endif
sherckuith 0:479ce5546098 61 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't
sherckuith 0:479ce5546098 62 work if you change this! */
sherckuith 0:479ce5546098 63 #ifndef SNMP_TRAP_PORT
sherckuith 0:479ce5546098 64 #define SNMP_TRAP_PORT 162
sherckuith 0:479ce5546098 65 #endif
sherckuith 0:479ce5546098 66
sherckuith 0:479ce5546098 67 #define SNMP_ES_NOERROR 0
sherckuith 0:479ce5546098 68 #define SNMP_ES_TOOBIG 1
sherckuith 0:479ce5546098 69 #define SNMP_ES_NOSUCHNAME 2
sherckuith 0:479ce5546098 70 #define SNMP_ES_BADVALUE 3
sherckuith 0:479ce5546098 71 #define SNMP_ES_READONLY 4
sherckuith 0:479ce5546098 72 #define SNMP_ES_GENERROR 5
sherckuith 0:479ce5546098 73
sherckuith 0:479ce5546098 74 #define SNMP_GENTRAP_COLDSTART 0
sherckuith 0:479ce5546098 75 #define SNMP_GENTRAP_WARMSTART 1
sherckuith 0:479ce5546098 76 #define SNMP_GENTRAP_AUTHFAIL 4
sherckuith 0:479ce5546098 77 #define SNMP_GENTRAP_ENTERPRISESPC 6
sherckuith 0:479ce5546098 78
sherckuith 0:479ce5546098 79 struct snmp_varbind
sherckuith 0:479ce5546098 80 {
sherckuith 0:479ce5546098 81 /* next pointer, NULL for last in list */
sherckuith 0:479ce5546098 82 struct snmp_varbind *next;
sherckuith 0:479ce5546098 83 /* previous pointer, NULL for first in list */
sherckuith 0:479ce5546098 84 struct snmp_varbind *prev;
sherckuith 0:479ce5546098 85
sherckuith 0:479ce5546098 86 /* object identifier length (in s32_t) */
sherckuith 0:479ce5546098 87 u8_t ident_len;
sherckuith 0:479ce5546098 88 /* object identifier array */
sherckuith 0:479ce5546098 89 s32_t *ident;
sherckuith 0:479ce5546098 90
sherckuith 0:479ce5546098 91 /* object value ASN1 type */
sherckuith 0:479ce5546098 92 u8_t value_type;
sherckuith 0:479ce5546098 93 /* object value length (in u8_t) */
sherckuith 0:479ce5546098 94 u8_t value_len;
sherckuith 0:479ce5546098 95 /* object value */
sherckuith 0:479ce5546098 96 void *value;
sherckuith 0:479ce5546098 97
sherckuith 0:479ce5546098 98 /* encoding varbind seq length length */
sherckuith 0:479ce5546098 99 u8_t seqlenlen;
sherckuith 0:479ce5546098 100 /* encoding object identifier length length */
sherckuith 0:479ce5546098 101 u8_t olenlen;
sherckuith 0:479ce5546098 102 /* encoding object value length length */
sherckuith 0:479ce5546098 103 u8_t vlenlen;
sherckuith 0:479ce5546098 104 /* encoding varbind seq length */
sherckuith 0:479ce5546098 105 u16_t seqlen;
sherckuith 0:479ce5546098 106 /* encoding object identifier length */
sherckuith 0:479ce5546098 107 u16_t olen;
sherckuith 0:479ce5546098 108 /* encoding object value length */
sherckuith 0:479ce5546098 109 u16_t vlen;
sherckuith 0:479ce5546098 110 };
sherckuith 0:479ce5546098 111
sherckuith 0:479ce5546098 112 struct snmp_varbind_root
sherckuith 0:479ce5546098 113 {
sherckuith 0:479ce5546098 114 struct snmp_varbind *head;
sherckuith 0:479ce5546098 115 struct snmp_varbind *tail;
sherckuith 0:479ce5546098 116 /* number of variable bindings in list */
sherckuith 0:479ce5546098 117 u8_t count;
sherckuith 0:479ce5546098 118 /* encoding varbind-list seq length length */
sherckuith 0:479ce5546098 119 u8_t seqlenlen;
sherckuith 0:479ce5546098 120 /* encoding varbind-list seq length */
sherckuith 0:479ce5546098 121 u16_t seqlen;
sherckuith 0:479ce5546098 122 };
sherckuith 0:479ce5546098 123
sherckuith 0:479ce5546098 124 /** output response message header length fields */
sherckuith 0:479ce5546098 125 struct snmp_resp_header_lengths
sherckuith 0:479ce5546098 126 {
sherckuith 0:479ce5546098 127 /* encoding error-index length length */
sherckuith 0:479ce5546098 128 u8_t erridxlenlen;
sherckuith 0:479ce5546098 129 /* encoding error-status length length */
sherckuith 0:479ce5546098 130 u8_t errstatlenlen;
sherckuith 0:479ce5546098 131 /* encoding request id length length */
sherckuith 0:479ce5546098 132 u8_t ridlenlen;
sherckuith 0:479ce5546098 133 /* encoding pdu length length */
sherckuith 0:479ce5546098 134 u8_t pdulenlen;
sherckuith 0:479ce5546098 135 /* encoding community length length */
sherckuith 0:479ce5546098 136 u8_t comlenlen;
sherckuith 0:479ce5546098 137 /* encoding version length length */
sherckuith 0:479ce5546098 138 u8_t verlenlen;
sherckuith 0:479ce5546098 139 /* encoding sequence length length */
sherckuith 0:479ce5546098 140 u8_t seqlenlen;
sherckuith 0:479ce5546098 141
sherckuith 0:479ce5546098 142 /* encoding error-index length */
sherckuith 0:479ce5546098 143 u16_t erridxlen;
sherckuith 0:479ce5546098 144 /* encoding error-status length */
sherckuith 0:479ce5546098 145 u16_t errstatlen;
sherckuith 0:479ce5546098 146 /* encoding request id length */
sherckuith 0:479ce5546098 147 u16_t ridlen;
sherckuith 0:479ce5546098 148 /* encoding pdu length */
sherckuith 0:479ce5546098 149 u16_t pdulen;
sherckuith 0:479ce5546098 150 /* encoding community length */
sherckuith 0:479ce5546098 151 u16_t comlen;
sherckuith 0:479ce5546098 152 /* encoding version length */
sherckuith 0:479ce5546098 153 u16_t verlen;
sherckuith 0:479ce5546098 154 /* encoding sequence length */
sherckuith 0:479ce5546098 155 u16_t seqlen;
sherckuith 0:479ce5546098 156 };
sherckuith 0:479ce5546098 157
sherckuith 0:479ce5546098 158 /** output response message header length fields */
sherckuith 0:479ce5546098 159 struct snmp_trap_header_lengths
sherckuith 0:479ce5546098 160 {
sherckuith 0:479ce5546098 161 /* encoding timestamp length length */
sherckuith 0:479ce5546098 162 u8_t tslenlen;
sherckuith 0:479ce5546098 163 /* encoding specific-trap length length */
sherckuith 0:479ce5546098 164 u8_t strplenlen;
sherckuith 0:479ce5546098 165 /* encoding generic-trap length length */
sherckuith 0:479ce5546098 166 u8_t gtrplenlen;
sherckuith 0:479ce5546098 167 /* encoding agent-addr length length */
sherckuith 0:479ce5546098 168 u8_t aaddrlenlen;
sherckuith 0:479ce5546098 169 /* encoding enterprise-id length length */
sherckuith 0:479ce5546098 170 u8_t eidlenlen;
sherckuith 0:479ce5546098 171 /* encoding pdu length length */
sherckuith 0:479ce5546098 172 u8_t pdulenlen;
sherckuith 0:479ce5546098 173 /* encoding community length length */
sherckuith 0:479ce5546098 174 u8_t comlenlen;
sherckuith 0:479ce5546098 175 /* encoding version length length */
sherckuith 0:479ce5546098 176 u8_t verlenlen;
sherckuith 0:479ce5546098 177 /* encoding sequence length length */
sherckuith 0:479ce5546098 178 u8_t seqlenlen;
sherckuith 0:479ce5546098 179
sherckuith 0:479ce5546098 180 /* encoding timestamp length */
sherckuith 0:479ce5546098 181 u16_t tslen;
sherckuith 0:479ce5546098 182 /* encoding specific-trap length */
sherckuith 0:479ce5546098 183 u16_t strplen;
sherckuith 0:479ce5546098 184 /* encoding generic-trap length */
sherckuith 0:479ce5546098 185 u16_t gtrplen;
sherckuith 0:479ce5546098 186 /* encoding agent-addr length */
sherckuith 0:479ce5546098 187 u16_t aaddrlen;
sherckuith 0:479ce5546098 188 /* encoding enterprise-id length */
sherckuith 0:479ce5546098 189 u16_t eidlen;
sherckuith 0:479ce5546098 190 /* encoding pdu length */
sherckuith 0:479ce5546098 191 u16_t pdulen;
sherckuith 0:479ce5546098 192 /* encoding community length */
sherckuith 0:479ce5546098 193 u16_t comlen;
sherckuith 0:479ce5546098 194 /* encoding version length */
sherckuith 0:479ce5546098 195 u16_t verlen;
sherckuith 0:479ce5546098 196 /* encoding sequence length */
sherckuith 0:479ce5546098 197 u16_t seqlen;
sherckuith 0:479ce5546098 198 };
sherckuith 0:479ce5546098 199
sherckuith 0:479ce5546098 200 /* Accepting new SNMP messages. */
sherckuith 0:479ce5546098 201 #define SNMP_MSG_EMPTY 0
sherckuith 0:479ce5546098 202 /* Search for matching object for variable binding. */
sherckuith 0:479ce5546098 203 #define SNMP_MSG_SEARCH_OBJ 1
sherckuith 0:479ce5546098 204 /* Perform SNMP operation on in-memory object.
sherckuith 0:479ce5546098 205 Pass-through states, for symmetry only. */
sherckuith 0:479ce5546098 206 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2
sherckuith 0:479ce5546098 207 #define SNMP_MSG_INTERNAL_GET_VALUE 3
sherckuith 0:479ce5546098 208 #define SNMP_MSG_INTERNAL_SET_TEST 4
sherckuith 0:479ce5546098 209 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
sherckuith 0:479ce5546098 210 #define SNMP_MSG_INTERNAL_SET_VALUE 6
sherckuith 0:479ce5546098 211 /* Perform SNMP operation on object located externally.
sherckuith 0:479ce5546098 212 In theory this could be used for building a proxy agent.
sherckuith 0:479ce5546098 213 Practical use is for an enterprise spc. app. gateway. */
sherckuith 0:479ce5546098 214 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
sherckuith 0:479ce5546098 215 #define SNMP_MSG_EXTERNAL_GET_VALUE 8
sherckuith 0:479ce5546098 216 #define SNMP_MSG_EXTERNAL_SET_TEST 9
sherckuith 0:479ce5546098 217 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
sherckuith 0:479ce5546098 218 #define SNMP_MSG_EXTERNAL_SET_VALUE 11
sherckuith 0:479ce5546098 219
sherckuith 0:479ce5546098 220 #define SNMP_COMMUNITY_STR_LEN 64
sherckuith 0:479ce5546098 221 struct snmp_msg_pstat
sherckuith 0:479ce5546098 222 {
sherckuith 0:479ce5546098 223 /* lwIP local port (161) binding */
sherckuith 0:479ce5546098 224 struct udp_pcb *pcb;
sherckuith 0:479ce5546098 225 /* source IP address */
sherckuith 0:479ce5546098 226 ip_addr_t sip;
sherckuith 0:479ce5546098 227 /* source UDP port */
sherckuith 0:479ce5546098 228 u16_t sp;
sherckuith 0:479ce5546098 229 /* request type */
sherckuith 0:479ce5546098 230 u8_t rt;
sherckuith 0:479ce5546098 231 /* request ID */
sherckuith 0:479ce5546098 232 s32_t rid;
sherckuith 0:479ce5546098 233 /* error status */
sherckuith 0:479ce5546098 234 s32_t error_status;
sherckuith 0:479ce5546098 235 /* error index */
sherckuith 0:479ce5546098 236 s32_t error_index;
sherckuith 0:479ce5546098 237 /* community name (zero terminated) */
sherckuith 0:479ce5546098 238 u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
sherckuith 0:479ce5546098 239 /* community string length (exclusive zero term) */
sherckuith 0:479ce5546098 240 u8_t com_strlen;
sherckuith 0:479ce5546098 241 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */
sherckuith 0:479ce5546098 242 u8_t state;
sherckuith 0:479ce5546098 243 /* saved arguments for MSG_EXTERNAL_x */
sherckuith 0:479ce5546098 244 struct mib_external_node *ext_mib_node;
sherckuith 0:479ce5546098 245 struct snmp_name_ptr ext_name_ptr;
sherckuith 0:479ce5546098 246 struct obj_def ext_object_def;
sherckuith 0:479ce5546098 247 struct snmp_obj_id ext_oid;
sherckuith 0:479ce5546098 248 /* index into input variable binding list */
sherckuith 0:479ce5546098 249 u8_t vb_idx;
sherckuith 0:479ce5546098 250 /* ptr into input variable binding list */
sherckuith 0:479ce5546098 251 struct snmp_varbind *vb_ptr;
sherckuith 0:479ce5546098 252 /* list of variable bindings from input */
sherckuith 0:479ce5546098 253 struct snmp_varbind_root invb;
sherckuith 0:479ce5546098 254 /* list of variable bindings to output */
sherckuith 0:479ce5546098 255 struct snmp_varbind_root outvb;
sherckuith 0:479ce5546098 256 /* output response lengths used in ASN encoding */
sherckuith 0:479ce5546098 257 struct snmp_resp_header_lengths rhl;
sherckuith 0:479ce5546098 258 };
sherckuith 0:479ce5546098 259
sherckuith 0:479ce5546098 260 struct snmp_msg_trap
sherckuith 0:479ce5546098 261 {
sherckuith 0:479ce5546098 262 /* lwIP local port (161) binding */
sherckuith 0:479ce5546098 263 struct udp_pcb *pcb;
sherckuith 0:479ce5546098 264 /* destination IP address in network order */
sherckuith 0:479ce5546098 265 ip_addr_t dip;
sherckuith 0:479ce5546098 266
sherckuith 0:479ce5546098 267 /* source enterprise ID (sysObjectID) */
sherckuith 0:479ce5546098 268 struct snmp_obj_id *enterprise;
sherckuith 0:479ce5546098 269 /* source IP address, raw network order format */
sherckuith 0:479ce5546098 270 u8_t sip_raw[4];
sherckuith 0:479ce5546098 271 /* generic trap code */
sherckuith 0:479ce5546098 272 u32_t gen_trap;
sherckuith 0:479ce5546098 273 /* specific trap code */
sherckuith 0:479ce5546098 274 u32_t spc_trap;
sherckuith 0:479ce5546098 275 /* timestamp */
sherckuith 0:479ce5546098 276 u32_t ts;
sherckuith 0:479ce5546098 277 /* list of variable bindings to output */
sherckuith 0:479ce5546098 278 struct snmp_varbind_root outvb;
sherckuith 0:479ce5546098 279 /* output trap lengths used in ASN encoding */
sherckuith 0:479ce5546098 280 struct snmp_trap_header_lengths thl;
sherckuith 0:479ce5546098 281 };
sherckuith 0:479ce5546098 282
sherckuith 0:479ce5546098 283 /** Agent Version constant, 0 = v1 oddity */
sherckuith 0:479ce5546098 284 extern const s32_t snmp_version;
sherckuith 0:479ce5546098 285 /** Agent default "public" community string */
sherckuith 0:479ce5546098 286 extern const char snmp_publiccommunity[7];
sherckuith 0:479ce5546098 287
sherckuith 0:479ce5546098 288 extern struct snmp_msg_trap trap_msg;
sherckuith 0:479ce5546098 289
sherckuith 0:479ce5546098 290 /** Agent setup, start listening to port 161. */
sherckuith 0:479ce5546098 291 void snmp_init(void);
sherckuith 0:479ce5546098 292 void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable);
sherckuith 0:479ce5546098 293 void snmp_trap_dst_ip_set(u8_t dst_idx, ip_addr_t *dst);
sherckuith 0:479ce5546098 294
sherckuith 0:479ce5546098 295 /** Varbind-list functions. */
sherckuith 0:479ce5546098 296 struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len);
sherckuith 0:479ce5546098 297 void snmp_varbind_free(struct snmp_varbind *vb);
sherckuith 0:479ce5546098 298 void snmp_varbind_list_free(struct snmp_varbind_root *root);
sherckuith 0:479ce5546098 299 void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb);
sherckuith 0:479ce5546098 300 struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root);
sherckuith 0:479ce5546098 301
sherckuith 0:479ce5546098 302 /** Handle an internal (recv) or external (private response) event. */
sherckuith 0:479ce5546098 303 void snmp_msg_event(u8_t request_id);
sherckuith 0:479ce5546098 304 err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
sherckuith 0:479ce5546098 305 err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap);
sherckuith 0:479ce5546098 306 void snmp_coldstart_trap(void);
sherckuith 0:479ce5546098 307 void snmp_authfail_trap(void);
sherckuith 0:479ce5546098 308
sherckuith 0:479ce5546098 309 #ifdef __cplusplus
sherckuith 0:479ce5546098 310 }
sherckuith 0:479ce5546098 311 #endif
sherckuith 0:479ce5546098 312
sherckuith 0:479ce5546098 313 #endif /* LWIP_SNMP */
sherckuith 0:479ce5546098 314
sherckuith 0:479ce5546098 315 #endif /* __LWIP_SNMP_MSG_H__ */