Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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