Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00048
00049 #include "private_mib.h"
00050 #endif
00051
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055
00056
00057
00058 #ifndef SNMP_IN_PORT
00059 #define SNMP_IN_PORT 161
00060 #endif
00061
00062
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
00082 struct snmp_varbind *next;
00083
00084 struct snmp_varbind *prev;
00085
00086
00087 u8_t ident_len;
00088
00089 s32_t *ident;
00090
00091
00092 u8_t value_type;
00093
00094 u8_t value_len;
00095
00096 void *value;
00097
00098
00099 u8_t seqlenlen;
00100
00101 u8_t olenlen;
00102
00103 u8_t vlenlen;
00104
00105 u16_t seqlen;
00106
00107 u16_t olen;
00108
00109 u16_t vlen;
00110 };
00111
00112 struct snmp_varbind_root
00113 {
00114 struct snmp_varbind *head;
00115 struct snmp_varbind *tail;
00116
00117 u8_t count;
00118
00119 u8_t seqlenlen;
00120
00121 u16_t seqlen;
00122 };
00123
00124
00125 struct snmp_resp_header_lengths
00126 {
00127
00128 u8_t erridxlenlen;
00129
00130 u8_t errstatlenlen;
00131
00132 u8_t ridlenlen;
00133
00134 u8_t pdulenlen;
00135
00136 u8_t comlenlen;
00137
00138 u8_t verlenlen;
00139
00140 u8_t seqlenlen;
00141
00142
00143 u16_t erridxlen;
00144
00145 u16_t errstatlen;
00146
00147 u16_t ridlen;
00148
00149 u16_t pdulen;
00150
00151 u16_t comlen;
00152
00153 u16_t verlen;
00154
00155 u16_t seqlen;
00156 };
00157
00158
00159 struct snmp_trap_header_lengths
00160 {
00161
00162 u8_t tslenlen;
00163
00164 u8_t strplenlen;
00165
00166 u8_t gtrplenlen;
00167
00168 u8_t aaddrlenlen;
00169
00170 u8_t eidlenlen;
00171
00172 u8_t pdulenlen;
00173
00174 u8_t comlenlen;
00175
00176 u8_t verlenlen;
00177
00178 u8_t seqlenlen;
00179
00180
00181 u16_t tslen;
00182
00183 u16_t strplen;
00184
00185 u16_t gtrplen;
00186
00187 u16_t aaddrlen;
00188
00189 u16_t eidlen;
00190
00191 u16_t pdulen;
00192
00193 u16_t comlen;
00194
00195 u16_t verlen;
00196
00197 u16_t seqlen;
00198 };
00199
00200
00201 #define SNMP_MSG_EMPTY 0
00202
00203 #define SNMP_MSG_SEARCH_OBJ 1
00204
00205
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
00212
00213
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
00224 struct udp_pcb *pcb;
00225
00226 ip_addr_t sip;
00227
00228 u16_t sp;
00229
00230 u8_t rt;
00231
00232 s32_t rid;
00233
00234 s32_t error_status;
00235
00236 s32_t error_index;
00237
00238 u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
00239
00240 u8_t com_strlen;
00241
00242 u8_t state;
00243
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
00249 u8_t vb_idx;
00250
00251 struct snmp_varbind *vb_ptr;
00252
00253 struct snmp_varbind_root invb;
00254
00255 struct snmp_varbind_root outvb;
00256
00257 struct snmp_resp_header_lengths rhl;
00258 };
00259
00260 struct snmp_msg_trap
00261 {
00262
00263 struct udp_pcb *pcb;
00264
00265 ip_addr_t dip;
00266
00267
00268 struct snmp_obj_id *enterprise;
00269
00270 u8_t sip_raw[4];
00271
00272 u32_t gen_trap;
00273
00274 u32_t spc_trap;
00275
00276 u32_t ts;
00277
00278 struct snmp_varbind_root outvb;
00279
00280 struct snmp_trap_header_lengths thl;
00281 };
00282
00283
00284 extern const s32_t snmp_version;
00285
00286 extern const char snmp_publiccommunity[7];
00287
00288 extern struct snmp_msg_trap trap_msg;
00289
00290
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
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
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
00314
00315 #endif