TwitterExample with newer library (2012Aug)

Dependencies:   EthernetNetIf HTTPClient mbed

Committer:
nxpfan
Date:
Wed Aug 29 03:50:19 2012 +0000
Revision:
0:075157567b0c
simple twitter example with newer library

Who changed what in which revision?

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