Deprecated fork of old network stack source from github. Please use official library instead: https://mbed.org/users/mbed_official/code/EthernetInterface/
snmp_msg.h
00001 /** 00002 * @file 00003 * SNMP Agent message handling structures. 00004 */ 00005 00006 /* 00007 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * Author: Christiaan Simons <christiaan.simons@axon.tv> 00033 */ 00034 00035 #ifndef __LWIP_SNMP_MSG_H__ 00036 #define __LWIP_SNMP_MSG_H__ 00037 00038 #include "lwip/opt.h" 00039 #include "lwip/snmp.h" 00040 #include "lwip/snmp_structs.h" 00041 #include "lwip/ip_addr.h" 00042 #include "lwip/err.h" 00043 00044 #if LWIP_SNMP 00045 00046 #if SNMP_PRIVATE_MIB 00047 /* When using a private MIB, you have to create a file 'private_mib.h' that contains 00048 * a 'struct mib_array_node mib_private' which contains your MIB. */ 00049 #include "private_mib.h" 00050 #endif 00051 00052 #ifdef __cplusplus 00053 extern "C" { 00054 #endif 00055 00056 /* The listen port of the SNMP agent. Clients have to make their requests to 00057 this port. Most standard clients won't work if you change this! */ 00058 #ifndef SNMP_IN_PORT 00059 #define SNMP_IN_PORT 161 00060 #endif 00061 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't 00062 work if you change this! */ 00063 #ifndef SNMP_TRAP_PORT 00064 #define SNMP_TRAP_PORT 162 00065 #endif 00066 00067 #define SNMP_ES_NOERROR 0 00068 #define SNMP_ES_TOOBIG 1 00069 #define SNMP_ES_NOSUCHNAME 2 00070 #define SNMP_ES_BADVALUE 3 00071 #define SNMP_ES_READONLY 4 00072 #define SNMP_ES_GENERROR 5 00073 00074 #define SNMP_GENTRAP_COLDSTART 0 00075 #define SNMP_GENTRAP_WARMSTART 1 00076 #define SNMP_GENTRAP_AUTHFAIL 4 00077 #define SNMP_GENTRAP_ENTERPRISESPC 6 00078 00079 struct snmp_varbind 00080 { 00081 /* next pointer, NULL for last in list */ 00082 struct snmp_varbind *next; 00083 /* previous pointer, NULL for first in list */ 00084 struct snmp_varbind *prev; 00085 00086 /* object identifier length (in s32_t) */ 00087 u8_t ident_len; 00088 /* object identifier array */ 00089 s32_t *ident; 00090 00091 /* object value ASN1 type */ 00092 u8_t value_type; 00093 /* object value length (in u8_t) */ 00094 u8_t value_len; 00095 /* object value */ 00096 void *value; 00097 00098 /* encoding varbind seq length length */ 00099 u8_t seqlenlen; 00100 /* encoding object identifier length length */ 00101 u8_t olenlen; 00102 /* encoding object value length length */ 00103 u8_t vlenlen; 00104 /* encoding varbind seq length */ 00105 u16_t seqlen; 00106 /* encoding object identifier length */ 00107 u16_t olen; 00108 /* encoding object value length */ 00109 u16_t vlen; 00110 }; 00111 00112 struct snmp_varbind_root 00113 { 00114 struct snmp_varbind *head; 00115 struct snmp_varbind *tail; 00116 /* number of variable bindings in list */ 00117 u8_t count; 00118 /* encoding varbind-list seq length length */ 00119 u8_t seqlenlen; 00120 /* encoding varbind-list seq length */ 00121 u16_t seqlen; 00122 }; 00123 00124 /** output response message header length fields */ 00125 struct snmp_resp_header_lengths 00126 { 00127 /* encoding error-index length length */ 00128 u8_t erridxlenlen; 00129 /* encoding error-status length length */ 00130 u8_t errstatlenlen; 00131 /* encoding request id length length */ 00132 u8_t ridlenlen; 00133 /* encoding pdu length length */ 00134 u8_t pdulenlen; 00135 /* encoding community length length */ 00136 u8_t comlenlen; 00137 /* encoding version length length */ 00138 u8_t verlenlen; 00139 /* encoding sequence length length */ 00140 u8_t seqlenlen; 00141 00142 /* encoding error-index length */ 00143 u16_t erridxlen; 00144 /* encoding error-status length */ 00145 u16_t errstatlen; 00146 /* encoding request id length */ 00147 u16_t ridlen; 00148 /* encoding pdu length */ 00149 u16_t pdulen; 00150 /* encoding community length */ 00151 u16_t comlen; 00152 /* encoding version length */ 00153 u16_t verlen; 00154 /* encoding sequence length */ 00155 u16_t seqlen; 00156 }; 00157 00158 /** output response message header length fields */ 00159 struct snmp_trap_header_lengths 00160 { 00161 /* encoding timestamp length length */ 00162 u8_t tslenlen; 00163 /* encoding specific-trap length length */ 00164 u8_t strplenlen; 00165 /* encoding generic-trap length length */ 00166 u8_t gtrplenlen; 00167 /* encoding agent-addr length length */ 00168 u8_t aaddrlenlen; 00169 /* encoding enterprise-id length length */ 00170 u8_t eidlenlen; 00171 /* encoding pdu length length */ 00172 u8_t pdulenlen; 00173 /* encoding community length length */ 00174 u8_t comlenlen; 00175 /* encoding version length length */ 00176 u8_t verlenlen; 00177 /* encoding sequence length length */ 00178 u8_t seqlenlen; 00179 00180 /* encoding timestamp length */ 00181 u16_t tslen; 00182 /* encoding specific-trap length */ 00183 u16_t strplen; 00184 /* encoding generic-trap length */ 00185 u16_t gtrplen; 00186 /* encoding agent-addr length */ 00187 u16_t aaddrlen; 00188 /* encoding enterprise-id length */ 00189 u16_t eidlen; 00190 /* encoding pdu length */ 00191 u16_t pdulen; 00192 /* encoding community length */ 00193 u16_t comlen; 00194 /* encoding version length */ 00195 u16_t verlen; 00196 /* encoding sequence length */ 00197 u16_t seqlen; 00198 }; 00199 00200 /* Accepting new SNMP messages. */ 00201 #define SNMP_MSG_EMPTY 0 00202 /* Search for matching object for variable binding. */ 00203 #define SNMP_MSG_SEARCH_OBJ 1 00204 /* Perform SNMP operation on in-memory object. 00205 Pass-through states, for symmetry only. */ 00206 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2 00207 #define SNMP_MSG_INTERNAL_GET_VALUE 3 00208 #define SNMP_MSG_INTERNAL_SET_TEST 4 00209 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5 00210 #define SNMP_MSG_INTERNAL_SET_VALUE 6 00211 /* Perform SNMP operation on object located externally. 00212 In theory this could be used for building a proxy agent. 00213 Practical use is for an enterprise spc. app. gateway. */ 00214 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7 00215 #define SNMP_MSG_EXTERNAL_GET_VALUE 8 00216 #define SNMP_MSG_EXTERNAL_SET_TEST 9 00217 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10 00218 #define SNMP_MSG_EXTERNAL_SET_VALUE 11 00219 00220 #define SNMP_COMMUNITY_STR_LEN 64 00221 struct snmp_msg_pstat 00222 { 00223 /* lwIP local port (161) binding */ 00224 struct udp_pcb *pcb; 00225 /* source IP address */ 00226 ip_addr_t sip; 00227 /* source UDP port */ 00228 u16_t sp; 00229 /* request type */ 00230 u8_t rt; 00231 /* request ID */ 00232 s32_t rid; 00233 /* error status */ 00234 s32_t error_status; 00235 /* error index */ 00236 s32_t error_index; 00237 /* community name (zero terminated) */ 00238 u8_t community[SNMP_COMMUNITY_STR_LEN + 1]; 00239 /* community string length (exclusive zero term) */ 00240 u8_t com_strlen; 00241 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */ 00242 u8_t state; 00243 /* saved arguments for MSG_EXTERNAL_x */ 00244 struct mib_external_node *ext_mib_node; 00245 struct snmp_name_ptr ext_name_ptr; 00246 struct obj_def ext_object_def; 00247 struct snmp_obj_id ext_oid; 00248 /* index into input variable binding list */ 00249 u8_t vb_idx; 00250 /* ptr into input variable binding list */ 00251 struct snmp_varbind *vb_ptr; 00252 /* list of variable bindings from input */ 00253 struct snmp_varbind_root invb; 00254 /* list of variable bindings to output */ 00255 struct snmp_varbind_root outvb; 00256 /* output response lengths used in ASN encoding */ 00257 struct snmp_resp_header_lengths rhl; 00258 }; 00259 00260 struct snmp_msg_trap 00261 { 00262 /* lwIP local port (161) binding */ 00263 struct udp_pcb *pcb; 00264 /* destination IP address in network order */ 00265 ip_addr_t dip; 00266 00267 /* source enterprise ID (sysObjectID) */ 00268 struct snmp_obj_id *enterprise; 00269 /* source IP address, raw network order format */ 00270 u8_t sip_raw[4]; 00271 /* generic trap code */ 00272 u32_t gen_trap; 00273 /* specific trap code */ 00274 u32_t spc_trap; 00275 /* timestamp */ 00276 u32_t ts; 00277 /* list of variable bindings to output */ 00278 struct snmp_varbind_root outvb; 00279 /* output trap lengths used in ASN encoding */ 00280 struct snmp_trap_header_lengths thl; 00281 }; 00282 00283 /** Agent Version constant, 0 = v1 oddity */ 00284 extern const s32_t snmp_version; 00285 /** Agent default "public" community string */ 00286 extern const char snmp_publiccommunity[7]; 00287 00288 extern struct snmp_msg_trap trap_msg; 00289 00290 /** Agent setup, start listening to port 161. */ 00291 void snmp_init(void); 00292 void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable); 00293 void snmp_trap_dst_ip_set(u8_t dst_idx, ip_addr_t *dst); 00294 00295 /** Varbind-list functions. */ 00296 struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len); 00297 void snmp_varbind_free(struct snmp_varbind *vb); 00298 void snmp_varbind_list_free(struct snmp_varbind_root *root); 00299 void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb); 00300 struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root); 00301 00302 /** Handle an internal (recv) or external (private response) event. */ 00303 void snmp_msg_event(u8_t request_id); 00304 err_t snmp_send_response(struct snmp_msg_pstat *m_stat); 00305 err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap); 00306 void snmp_coldstart_trap(void); 00307 void snmp_authfail_trap(void); 00308 00309 #ifdef __cplusplus 00310 } 00311 #endif 00312 00313 #endif /* LWIP_SNMP */ 00314 00315 #endif /* __LWIP_SNMP_MSG_H__ */
Generated on Tue Jul 12 2022 23:10:20 by 1.7.2