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
00042 #if LWIP_SNMP
00043
00044 #if SNMP_PRIVATE_MIB
00045 #include "private_mib.h"
00046 #endif
00047
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051
00052
00053
00054 #ifndef SNMP_IN_PORT
00055 #define SNMP_IN_PORT 161
00056 #endif
00057
00058
00059 #ifndef SNMP_TRAP_PORT
00060 #define SNMP_TRAP_PORT 162
00061 #endif
00062
00063 #define SNMP_ES_NOERROR 0
00064 #define SNMP_ES_TOOBIG 1
00065 #define SNMP_ES_NOSUCHNAME 2
00066 #define SNMP_ES_BADVALUE 3
00067 #define SNMP_ES_READONLY 4
00068 #define SNMP_ES_GENERROR 5
00069
00070 #define SNMP_GENTRAP_COLDSTART 0
00071 #define SNMP_GENTRAP_WARMSTART 1
00072 #define SNMP_GENTRAP_AUTHFAIL 4
00073 #define SNMP_GENTRAP_ENTERPRISESPC 6
00074
00075 struct snmp_varbind
00076 {
00077
00078 struct snmp_varbind *next;
00079
00080 struct snmp_varbind *prev;
00081
00082
00083 u8_t ident_len;
00084
00085 s32_t *ident;
00086
00087
00088 u8_t value_type;
00089
00090 u8_t value_len;
00091
00092 void *value;
00093
00094
00095 u8_t seqlenlen;
00096
00097 u8_t olenlen;
00098
00099 u8_t vlenlen;
00100
00101 u16_t seqlen;
00102
00103 u16_t olen;
00104
00105 u16_t vlen;
00106 };
00107
00108 struct snmp_varbind_root
00109 {
00110 struct snmp_varbind *head;
00111 struct snmp_varbind *tail;
00112
00113 u8_t count;
00114
00115 u8_t seqlenlen;
00116
00117 u16_t seqlen;
00118 };
00119
00120
00121 struct snmp_resp_header_lengths
00122 {
00123
00124 u8_t erridxlenlen;
00125
00126 u8_t errstatlenlen;
00127
00128 u8_t ridlenlen;
00129
00130 u8_t pdulenlen;
00131
00132 u8_t comlenlen;
00133
00134 u8_t verlenlen;
00135
00136 u8_t seqlenlen;
00137
00138
00139 u16_t erridxlen;
00140
00141 u16_t errstatlen;
00142
00143 u16_t ridlen;
00144
00145 u16_t pdulen;
00146
00147 u16_t comlen;
00148
00149 u16_t verlen;
00150
00151 u16_t seqlen;
00152 };
00153
00154
00155 struct snmp_trap_header_lengths
00156 {
00157
00158 u8_t tslenlen;
00159
00160 u8_t strplenlen;
00161
00162 u8_t gtrplenlen;
00163
00164 u8_t aaddrlenlen;
00165
00166 u8_t eidlenlen;
00167
00168 u8_t pdulenlen;
00169
00170 u8_t comlenlen;
00171
00172 u8_t verlenlen;
00173
00174 u8_t seqlenlen;
00175
00176
00177 u16_t tslen;
00178
00179 u16_t strplen;
00180
00181 u16_t gtrplen;
00182
00183 u16_t aaddrlen;
00184
00185 u16_t eidlen;
00186
00187 u16_t pdulen;
00188
00189 u16_t comlen;
00190
00191 u16_t verlen;
00192
00193 u16_t seqlen;
00194 };
00195
00196
00197 #define SNMP_MSG_EMPTY 0
00198
00199 #define SNMP_MSG_SEARCH_OBJ 1
00200
00201
00202 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2
00203 #define SNMP_MSG_INTERNAL_GET_VALUE 3
00204 #define SNMP_MSG_INTERNAL_SET_TEST 4
00205 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
00206 #define SNMP_MSG_INTERNAL_SET_VALUE 6
00207
00208
00209
00210 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
00211 #define SNMP_MSG_EXTERNAL_GET_VALUE 8
00212 #define SNMP_MSG_EXTERNAL_SET_TEST 9
00213 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
00214 #define SNMP_MSG_EXTERNAL_SET_VALUE 11
00215
00216 #define SNMP_COMMUNITY_STR_LEN 64
00217 struct snmp_msg_pstat
00218 {
00219
00220 struct udp_pcb *pcb;
00221
00222 struct ip_addr sip;
00223
00224 u16_t sp;
00225
00226 u8_t rt;
00227
00228 s32_t rid;
00229
00230 s32_t error_status;
00231
00232 s32_t error_index;
00233
00234 u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
00235
00236 u8_t com_strlen;
00237
00238 u8_t state;
00239
00240 struct mib_external_node *ext_mib_node;
00241 struct snmp_name_ptr ext_name_ptr;
00242 struct obj_def ext_object_def;
00243 struct snmp_obj_id ext_oid;
00244
00245 u8_t vb_idx;
00246
00247 struct snmp_varbind *vb_ptr;
00248
00249 struct snmp_varbind_root invb;
00250
00251 struct snmp_varbind_root outvb;
00252
00253 struct snmp_resp_header_lengths rhl;
00254 };
00255
00256 struct snmp_msg_trap
00257 {
00258
00259 struct udp_pcb *pcb;
00260
00261 struct ip_addr dip;
00262
00263
00264 struct snmp_obj_id *enterprise;
00265
00266 u8_t sip_raw[4];
00267
00268 u32_t gen_trap;
00269
00270 u32_t spc_trap;
00271
00272 u32_t ts;
00273
00274 struct snmp_varbind_root outvb;
00275
00276 struct snmp_trap_header_lengths thl;
00277 };
00278
00279
00280 extern const s32_t snmp_version;
00281
00282 extern const char snmp_publiccommunity[7];
00283
00284 extern struct snmp_msg_trap trap_msg;
00285
00286
00287 void snmp_init(void);
00288 void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable);
00289 void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst);
00290
00291
00292 struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len);
00293 void snmp_varbind_free(struct snmp_varbind *vb);
00294 void snmp_varbind_list_free(struct snmp_varbind_root *root);
00295 void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb);
00296 struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root);
00297
00298
00299 void snmp_msg_event(u8_t request_id);
00300 err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
00301 err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap);
00302 void snmp_coldstart_trap(void);
00303 void snmp_authfail_trap(void);
00304
00305 #ifdef __cplusplus
00306 }
00307 #endif
00308
00309 #endif
00310
00311 #endif