Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

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