|
||||
Warning, cross-references for /kernel/include/lwip/snmp_msg.h need to be fixed.
0001 /** 0002 * @file 0003 * SNMP Agent message handling structures. 0004 */ 0005 0006 /* 0007 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. 0008 * All rights reserved. 0009 * 0010 * Redistribution and use in source and binary forms, with or without modification, 0011 * are permitted provided that the following conditions are met: 0012 * 0013 * 1. Redistributions of source code must retain the above copyright notice, 0014 * this list of conditions and the following disclaimer. 0015 * 2. Redistributions in binary form must reproduce the above copyright notice, 0016 * this list of conditions and the following disclaimer in the documentation 0017 * and/or other materials provided with the distribution. 0018 * 3. The name of the author may not be used to endorse or promote products 0019 * derived from this software without specific prior written permission. 0020 * 0021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 0022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 0023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 0024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 0025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 0026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 0029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 0030 * OF SUCH DAMAGE. 0031 * 0032 * Author: Christiaan Simons <christiaan.simons@axon.tv> 0033 */ 0034 0035 #ifndef __LWIP_SNMP_MSG_H__ 0036 #define __LWIP_SNMP_MSG_H__ 0037 0038 #include "lwip/opt.h" 0039 #include "lwip/snmp.h" 0040 #include "lwip/snmp_structs.h" 0041 0042 #if LWIP_SNMP 0043 0044 #if SNMP_PRIVATE_MIB 0045 #include "private_mib.h" 0046 #endif 0047 0048 #ifdef __cplusplus 0049 extern "C" { 0050 #endif 0051 0052 /* The listen port of the SNMP agent. Clients have to make their requests to 0053 this port. Most standard clients won't work if you change this! */ 0054 #ifndef SNMP_IN_PORT 0055 #define SNMP_IN_PORT 161 0056 #endif 0057 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't 0058 work if you change this! */ 0059 #ifndef SNMP_TRAP_PORT 0060 #define SNMP_TRAP_PORT 162 0061 #endif 0062 0063 #define SNMP_ES_NOERROR 0 0064 #define SNMP_ES_TOOBIG 1 0065 #define SNMP_ES_NOSUCHNAME 2 0066 #define SNMP_ES_BADVALUE 3 0067 #define SNMP_ES_READONLY 4 0068 #define SNMP_ES_GENERROR 5 0069 0070 #define SNMP_GENTRAP_COLDSTART 0 0071 #define SNMP_GENTRAP_WARMSTART 1 0072 #define SNMP_GENTRAP_AUTHFAIL 4 0073 #define SNMP_GENTRAP_ENTERPRISESPC 6 0074 0075 struct snmp_varbind 0076 { 0077 /* next pointer, NULL for last in list */ 0078 struct snmp_varbind *next; 0079 /* previous pointer, NULL for first in list */ 0080 struct snmp_varbind *prev; 0081 0082 /* object identifier length (in s32_t) */ 0083 u8_t ident_len; 0084 /* object identifier array */ 0085 s32_t *ident; 0086 0087 /* object value ASN1 type */ 0088 u8_t value_type; 0089 /* object value length (in u8_t) */ 0090 u8_t value_len; 0091 /* object value */ 0092 void *value; 0093 0094 /* encoding varbind seq length length */ 0095 u8_t seqlenlen; 0096 /* encoding object identifier length length */ 0097 u8_t olenlen; 0098 /* encoding object value length length */ 0099 u8_t vlenlen; 0100 /* encoding varbind seq length */ 0101 u16_t seqlen; 0102 /* encoding object identifier length */ 0103 u16_t olen; 0104 /* encoding object value length */ 0105 u16_t vlen; 0106 }; 0107 0108 struct snmp_varbind_root 0109 { 0110 struct snmp_varbind *head; 0111 struct snmp_varbind *tail; 0112 /* number of variable bindings in list */ 0113 u8_t count; 0114 /* encoding varbind-list seq length length */ 0115 u8_t seqlenlen; 0116 /* encoding varbind-list seq length */ 0117 u16_t seqlen; 0118 }; 0119 0120 /** output response message header length fields */ 0121 struct snmp_resp_header_lengths 0122 { 0123 /* encoding error-index length length */ 0124 u8_t erridxlenlen; 0125 /* encoding error-status length length */ 0126 u8_t errstatlenlen; 0127 /* encoding request id length length */ 0128 u8_t ridlenlen; 0129 /* encoding pdu length length */ 0130 u8_t pdulenlen; 0131 /* encoding community length length */ 0132 u8_t comlenlen; 0133 /* encoding version length length */ 0134 u8_t verlenlen; 0135 /* encoding sequence length length */ 0136 u8_t seqlenlen; 0137 0138 /* encoding error-index length */ 0139 u16_t erridxlen; 0140 /* encoding error-status length */ 0141 u16_t errstatlen; 0142 /* encoding request id length */ 0143 u16_t ridlen; 0144 /* encoding pdu length */ 0145 u16_t pdulen; 0146 /* encoding community length */ 0147 u16_t comlen; 0148 /* encoding version length */ 0149 u16_t verlen; 0150 /* encoding sequence length */ 0151 u16_t seqlen; 0152 }; 0153 0154 /** output response message header length fields */ 0155 struct snmp_trap_header_lengths 0156 { 0157 /* encoding timestamp length length */ 0158 u8_t tslenlen; 0159 /* encoding specific-trap length length */ 0160 u8_t strplenlen; 0161 /* encoding generic-trap length length */ 0162 u8_t gtrplenlen; 0163 /* encoding agent-addr length length */ 0164 u8_t aaddrlenlen; 0165 /* encoding enterprise-id length length */ 0166 u8_t eidlenlen; 0167 /* encoding pdu length length */ 0168 u8_t pdulenlen; 0169 /* encoding community length length */ 0170 u8_t comlenlen; 0171 /* encoding version length length */ 0172 u8_t verlenlen; 0173 /* encoding sequence length length */ 0174 u8_t seqlenlen; 0175 0176 /* encoding timestamp length */ 0177 u16_t tslen; 0178 /* encoding specific-trap length */ 0179 u16_t strplen; 0180 /* encoding generic-trap length */ 0181 u16_t gtrplen; 0182 /* encoding agent-addr length */ 0183 u16_t aaddrlen; 0184 /* encoding enterprise-id length */ 0185 u16_t eidlen; 0186 /* encoding pdu length */ 0187 u16_t pdulen; 0188 /* encoding community length */ 0189 u16_t comlen; 0190 /* encoding version length */ 0191 u16_t verlen; 0192 /* encoding sequence length */ 0193 u16_t seqlen; 0194 }; 0195 0196 /* Accepting new SNMP messages. */ 0197 #define SNMP_MSG_EMPTY 0 0198 /* Search for matching object for variable binding. */ 0199 #define SNMP_MSG_SEARCH_OBJ 1 0200 /* Perform SNMP operation on in-memory object. 0201 Pass-through states, for symmetry only. */ 0202 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2 0203 #define SNMP_MSG_INTERNAL_GET_VALUE 3 0204 #define SNMP_MSG_INTERNAL_SET_TEST 4 0205 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5 0206 #define SNMP_MSG_INTERNAL_SET_VALUE 6 0207 /* Perform SNMP operation on object located externally. 0208 In theory this could be used for building a proxy agent. 0209 Practical use is for an enterprise spc. app. gateway. */ 0210 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7 0211 #define SNMP_MSG_EXTERNAL_GET_VALUE 8 0212 #define SNMP_MSG_EXTERNAL_SET_TEST 9 0213 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10 0214 #define SNMP_MSG_EXTERNAL_SET_VALUE 11 0215 0216 #define SNMP_COMMUNITY_STR_LEN 64 0217 struct snmp_msg_pstat 0218 { 0219 /* lwIP local port (161) binding */ 0220 struct udp_pcb *pcb; 0221 /* source IP address */ 0222 struct ip_addr sip; 0223 /* source UDP port */ 0224 u16_t sp; 0225 /* request type */ 0226 u8_t rt; 0227 /* request ID */ 0228 s32_t rid; 0229 /* error status */ 0230 s32_t error_status; 0231 /* error index */ 0232 s32_t error_index; 0233 /* community name (zero terminated) */ 0234 u8_t community[SNMP_COMMUNITY_STR_LEN + 1]; 0235 /* community string length (exclusive zero term) */ 0236 u8_t com_strlen; 0237 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */ 0238 u8_t state; 0239 /* saved arguments for MSG_EXTERNAL_x */ 0240 struct mib_external_node *ext_mib_node; 0241 struct snmp_name_ptr ext_name_ptr; 0242 struct obj_def ext_object_def; 0243 struct snmp_obj_id ext_oid; 0244 /* index into input variable binding list */ 0245 u8_t vb_idx; 0246 /* ptr into input variable binding list */ 0247 struct snmp_varbind *vb_ptr; 0248 /* list of variable bindings from input */ 0249 struct snmp_varbind_root invb; 0250 /* list of variable bindings to output */ 0251 struct snmp_varbind_root outvb; 0252 /* output response lengths used in ASN encoding */ 0253 struct snmp_resp_header_lengths rhl; 0254 }; 0255 0256 struct snmp_msg_trap 0257 { 0258 /* lwIP local port (161) binding */ 0259 struct udp_pcb *pcb; 0260 /* destination IP address in network order */ 0261 struct ip_addr dip; 0262 0263 /* source enterprise ID (sysObjectID) */ 0264 struct snmp_obj_id *enterprise; 0265 /* source IP address, raw network order format */ 0266 u8_t sip_raw[4]; 0267 /* generic trap code */ 0268 u32_t gen_trap; 0269 /* specific trap code */ 0270 u32_t spc_trap; 0271 /* timestamp */ 0272 u32_t ts; 0273 /* list of variable bindings to output */ 0274 struct snmp_varbind_root outvb; 0275 /* output trap lengths used in ASN encoding */ 0276 struct snmp_trap_header_lengths thl; 0277 }; 0278 0279 /** Agent Version constant, 0 = v1 oddity */ 0280 extern const s32_t snmp_version; 0281 /** Agent default "public" community string */ 0282 extern const char snmp_publiccommunity[7]; 0283 0284 extern struct snmp_msg_trap trap_msg; 0285 0286 /** Agent setup, start listening to port 161. */ 0287 void snmp_init(void); 0288 void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable); 0289 void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst); 0290 0291 /** Varbind-list functions. */ 0292 struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len); 0293 void snmp_varbind_free(struct snmp_varbind *vb); 0294 void snmp_varbind_list_free(struct snmp_varbind_root *root); 0295 void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb); 0296 struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root); 0297 0298 /** Handle an internal (recv) or external (private response) event. */ 0299 void snmp_msg_event(u8_t request_id); 0300 err_t snmp_send_response(struct snmp_msg_pstat *m_stat); 0301 err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap); 0302 void snmp_coldstart_trap(void); 0303 void snmp_authfail_trap(void); 0304 0305 #ifdef __cplusplus 0306 } 0307 #endif 0308 0309 #endif /* LWIP_SNMP */ 0310 0311 #endif /* __LWIP_SNMP_MSG_H__ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 1.2.0 LXR engine. |