A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
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 00042 #if SNMP_PRIVATE_MIB 00043 #include "private_mib.h" 00044 #endif 00045 00046 #ifdef __cplusplus 00047 extern "C" { 00048 #endif 00049 00050 /* The listen port of the SNMP agent. Clients have to make their requests to 00051 this port. Most standard clients won't work if you change this! */ 00052 #ifndef SNMP_IN_PORT 00053 #define SNMP_IN_PORT 161 00054 #endif 00055 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't 00056 work if you change this! */ 00057 #ifndef SNMP_TRAP_PORT 00058 #define SNMP_TRAP_PORT 162 00059 #endif 00060 00061 #define SNMP_ES_NOERROR 0 00062 #define SNMP_ES_TOOBIG 1 00063 #define SNMP_ES_NOSUCHNAME 2 00064 #define SNMP_ES_BADVALUE 3 00065 #define SNMP_ES_READONLY 4 00066 #define SNMP_ES_GENERROR 5 00067 00068 #define SNMP_GENTRAP_COLDSTART 0 00069 #define SNMP_GENTRAP_WARMSTART 1 00070 #define SNMP_GENTRAP_AUTHFAIL 4 00071 #define SNMP_GENTRAP_ENTERPRISESPC 6 00072 00073 struct snmp_varbind 00074 { 00075 /* next pointer, NULL for last in list */ 00076 struct snmp_varbind *next; 00077 /* previous pointer, NULL for first in list */ 00078 struct snmp_varbind *prev; 00079 00080 /* object identifier length (in s32_t) */ 00081 u8_t ident_len; 00082 /* object identifier array */ 00083 s32_t *ident; 00084 00085 /* object value ASN1 type */ 00086 u8_t value_type; 00087 /* object value length (in u8_t) */ 00088 u8_t value_len; 00089 /* object value */ 00090 void *value; 00091 00092 /* encoding varbind seq length length */ 00093 u8_t seqlenlen; 00094 /* encoding object identifier length length */ 00095 u8_t olenlen; 00096 /* encoding object value length length */ 00097 u8_t vlenlen; 00098 /* encoding varbind seq length */ 00099 u16_t seqlen; 00100 /* encoding object identifier length */ 00101 u16_t olen; 00102 /* encoding object value length */ 00103 u16_t vlen; 00104 }; 00105 00106 struct snmp_varbind_root 00107 { 00108 struct snmp_varbind *head; 00109 struct snmp_varbind *tail; 00110 /* number of variable bindings in list */ 00111 u8_t count; 00112 /* encoding varbind-list seq length length */ 00113 u8_t seqlenlen; 00114 /* encoding varbind-list seq length */ 00115 u16_t seqlen; 00116 }; 00117 00118 /** output response message header length fields */ 00119 struct snmp_resp_header_lengths 00120 { 00121 /* encoding error-index length length */ 00122 u8_t erridxlenlen; 00123 /* encoding error-status length length */ 00124 u8_t errstatlenlen; 00125 /* encoding request id length length */ 00126 u8_t ridlenlen; 00127 /* encoding pdu length length */ 00128 u8_t pdulenlen; 00129 /* encoding community length length */ 00130 u8_t comlenlen; 00131 /* encoding version length length */ 00132 u8_t verlenlen; 00133 /* encoding sequence length length */ 00134 u8_t seqlenlen; 00135 00136 /* encoding error-index length */ 00137 u16_t erridxlen; 00138 /* encoding error-status length */ 00139 u16_t errstatlen; 00140 /* encoding request id length */ 00141 u16_t ridlen; 00142 /* encoding pdu length */ 00143 u16_t pdulen; 00144 /* encoding community length */ 00145 u16_t comlen; 00146 /* encoding version length */ 00147 u16_t verlen; 00148 /* encoding sequence length */ 00149 u16_t seqlen; 00150 }; 00151 00152 /** output response message header length fields */ 00153 struct snmp_trap_header_lengths 00154 { 00155 /* encoding timestamp length length */ 00156 u8_t tslenlen; 00157 /* encoding specific-trap length length */ 00158 u8_t strplenlen; 00159 /* encoding generic-trap length length */ 00160 u8_t gtrplenlen; 00161 /* encoding agent-addr length length */ 00162 u8_t aaddrlenlen; 00163 /* encoding enterprise-id length length */ 00164 u8_t eidlenlen; 00165 /* encoding pdu length length */ 00166 u8_t pdulenlen; 00167 /* encoding community length length */ 00168 u8_t comlenlen; 00169 /* encoding version length length */ 00170 u8_t verlenlen; 00171 /* encoding sequence length length */ 00172 u8_t seqlenlen; 00173 00174 /* encoding timestamp length */ 00175 u16_t tslen; 00176 /* encoding specific-trap length */ 00177 u16_t strplen; 00178 /* encoding generic-trap length */ 00179 u16_t gtrplen; 00180 /* encoding agent-addr length */ 00181 u16_t aaddrlen; 00182 /* encoding enterprise-id length */ 00183 u16_t eidlen; 00184 /* encoding pdu length */ 00185 u16_t pdulen; 00186 /* encoding community length */ 00187 u16_t comlen; 00188 /* encoding version length */ 00189 u16_t verlen; 00190 /* encoding sequence length */ 00191 u16_t seqlen; 00192 }; 00193 00194 /* Accepting new SNMP messages. */ 00195 #define SNMP_MSG_EMPTY 0 00196 /* Search for matching object for variable binding. */ 00197 #define SNMP_MSG_SEARCH_OBJ 1 00198 /* Perform SNMP operation on in-memory object. 00199 Pass-through states, for symmetry only. */ 00200 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2 00201 #define SNMP_MSG_INTERNAL_GET_VALUE 3 00202 #define SNMP_MSG_INTERNAL_SET_TEST 4 00203 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5 00204 #define SNMP_MSG_INTERNAL_SET_VALUE 6 00205 /* Perform SNMP operation on object located externally. 00206 In theory this could be used for building a proxy agent. 00207 Practical use is for an enterprise spc. app. gateway. */ 00208 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7 00209 #define SNMP_MSG_EXTERNAL_GET_VALUE 8 00210 #define SNMP_MSG_EXTERNAL_SET_TEST 9 00211 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10 00212 #define SNMP_MSG_EXTERNAL_SET_VALUE 11 00213 00214 #define SNMP_COMMUNITY_STR_LEN 64 00215 struct snmp_msg_pstat 00216 { 00217 /* lwIP local port (161) binding */ 00218 struct udp_pcb *pcb; 00219 /* source IP address */ 00220 struct ip_addr sip; 00221 /* source UDP port */ 00222 u16_t sp; 00223 /* request type */ 00224 u8_t rt; 00225 /* request ID */ 00226 s32_t rid; 00227 /* error status */ 00228 s32_t error_status; 00229 /* error index */ 00230 s32_t error_index; 00231 /* community name (zero terminated) */ 00232 u8_t community[SNMP_COMMUNITY_STR_LEN + 1]; 00233 /* community string length (exclusive zero term) */ 00234 u8_t com_strlen; 00235 /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */ 00236 u8_t state; 00237 /* saved arguments for MSG_EXTERNAL_x */ 00238 struct mib_external_node *ext_mib_node; 00239 struct snmp_name_ptr ext_name_ptr; 00240 struct obj_def ext_object_def; 00241 struct snmp_obj_id ext_oid; 00242 /* index into input variable binding list */ 00243 u8_t vb_idx; 00244 /* ptr into input variable binding list */ 00245 struct snmp_varbind *vb_ptr; 00246 /* list of variable bindings from input */ 00247 struct snmp_varbind_root invb; 00248 /* list of variable bindings to output */ 00249 struct snmp_varbind_root outvb; 00250 /* output response lengths used in ASN encoding */ 00251 struct snmp_resp_header_lengths rhl; 00252 }; 00253 00254 struct snmp_msg_trap 00255 { 00256 /* lwIP local port (161) binding */ 00257 struct udp_pcb *pcb; 00258 /* destination IP address in network order */ 00259 struct ip_addr dip; 00260 00261 /* source enterprise ID (sysObjectID) */ 00262 struct snmp_obj_id *enterprise; 00263 /* source IP address, raw network order format */ 00264 u8_t sip_raw[4]; 00265 /* generic trap code */ 00266 u32_t gen_trap; 00267 /* specific trap code */ 00268 u32_t spc_trap; 00269 /* timestamp */ 00270 u32_t ts; 00271 /* list of variable bindings to output */ 00272 struct snmp_varbind_root outvb; 00273 /* output trap lengths used in ASN encoding */ 00274 struct snmp_trap_header_lengths thl; 00275 }; 00276 00277 /** Agent Version constant, 0 = v1 oddity */ 00278 extern const s32_t snmp_version; 00279 /** Agent default "public" community string */ 00280 extern const char snmp_publiccommunity[7]; 00281 00282 extern struct snmp_msg_trap trap_msg; 00283 00284 /** Agent setup, start listening to port 161. */ 00285 void snmp_init(void); 00286 void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable); 00287 void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst); 00288 00289 /** Varbind-list functions. */ 00290 struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len); 00291 void snmp_varbind_free(struct snmp_varbind *vb); 00292 void snmp_varbind_list_free(struct snmp_varbind_root *root); 00293 void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb); 00294 struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root); 00295 00296 /** Handle an internal (recv) or external (private response) event. */ 00297 void snmp_msg_event(u8_t request_id); 00298 err_t snmp_send_response(struct snmp_msg_pstat *m_stat); 00299 err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap); 00300 void snmp_coldstart_trap(void); 00301 void snmp_authfail_trap(void); 00302 00303 #ifdef __cplusplus 00304 } 00305 #endif 00306 00307 #endif /* __LWIP_SNMP_MSG_H__ */
Generated on Tue Jul 12 2022 16:06:23 by 1.7.2