mbed Phone Platform

Dependencies:   ulaw mbed ConfigFile

Committer:
okini3939
Date:
Sun Dec 26 15:49:07 2010 +0000
Revision:
1:0f82c574096f

        

Who changed what in which revision?

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