43#include "lwip/ip_addr.h"
52const s32_t snmp_version = 0;
54const char snmp_publiccommunity[7] =
"public";
59struct udp_pcb *snmp1_pcb;
62static err_t snmp_pdu_header_check(
struct pbuf *
p,
u16_t ofs,
u16_t pdu_len,
u16_t *ofs_ret,
struct snmp_msg_pstat *m_stat);
63static err_t snmp_pdu_dec_varbindlist(
struct pbuf *
p,
u16_t ofs,
u16_t *ofs_ret,
struct snmp_msg_pstat *m_stat);
73 struct snmp_msg_pstat *msg_ps;
76 snmp1_pcb = udp_new();
77 if (snmp1_pcb !=
NULL)
79 udp_recv(snmp1_pcb, snmp_recv, (
void *)SNMP_IN_PORT);
82 msg_ps = &msg_input_list[0];
85 msg_ps->state = SNMP_MSG_EMPTY;
86 msg_ps->error_index = 0;
87 msg_ps->error_status = SNMP_ES_NOERROR;
90 trap_msg.pcb = snmp1_pcb;
92#ifdef SNMP_PRIVATE_MIB_INIT
97 SNMP_PRIVATE_MIB_INIT();
102 snmp_coldstart_trap();
106snmp_error_response(
struct snmp_msg_pstat *msg_ps,
u8_t error)
110 struct snmp_varbind *vbi = msg_ps->invb.head;
111 struct snmp_varbind *vbo = msg_ps->outvb.head;
112 for (
v=0;
v<msg_ps->vb_idx;
v++) {
113 vbi->ident_len = vbo->ident_len;
115 vbi->ident = vbo->ident;
121 snmp_varbind_list_free(&msg_ps->outvb);
123 msg_ps->outvb = msg_ps->invb;
124 msg_ps->invb.head =
NULL;
125 msg_ps->invb.tail =
NULL;
126 msg_ps->invb.count = 0;
127 msg_ps->error_status =
error;
129 msg_ps->error_index = (
error != SNMP_ES_TOOBIG) ? (1 + msg_ps->vb_idx) : 0;
130 snmp_send_response(msg_ps);
131 snmp_varbind_list_free(&msg_ps->outvb);
132 msg_ps->state = SNMP_MSG_EMPTY;
136snmp_ok_response(
struct snmp_msg_pstat *msg_ps)
140 err_ret = snmp_send_response(msg_ps);
150 snmp_varbind_list_free(&msg_ps->invb);
151 snmp_varbind_list_free(&msg_ps->outvb);
152 msg_ps->state = SNMP_MSG_EMPTY;
162snmp_msg_get_event(
u8_t request_id,
struct snmp_msg_pstat *msg_ps)
166 if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF)
168 struct mib_external_node *
en;
169 struct snmp_name_ptr np;
172 en = msg_ps->ext_mib_node;
173 np = msg_ps->ext_name_ptr;
176 en->get_object_def_a(request_id, np.ident_len, np.ident, &msg_ps->ext_object_def);
177 if ((msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) &&
178 (msg_ps->ext_object_def.access & MIB_ACCESS_READ))
180 msg_ps->state = SNMP_MSG_EXTERNAL_GET_VALUE;
181 en->get_value_q(request_id, &msg_ps->ext_object_def);
185 en->get_object_def_pc(request_id, np.ident_len, np.ident);
187 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
190 else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_VALUE)
192 struct mib_external_node *
en;
193 struct snmp_varbind *vb;
196 en = msg_ps->ext_mib_node;
199 vb = (
struct snmp_varbind *)
memp_malloc(MEMP_SNMP_VARBIND);
206 vb->ident = msg_ps->vb_ptr->ident;
207 vb->ident_len = msg_ps->vb_ptr->ident_len;
209 msg_ps->vb_ptr->ident =
NULL;
210 msg_ps->vb_ptr->ident_len = 0;
212 vb->value_type = msg_ps->ext_object_def.asn_type;
213 LWIP_ASSERT(
"invalid length", msg_ps->ext_object_def.v_len <= 0xff);
214 vb->value_len = (
u8_t)msg_ps->ext_object_def.v_len;
215 if (vb->value_len > 0)
219 if (vb->value !=
NULL)
221 en->get_value_a(request_id, &msg_ps->ext_object_def, vb->value_len, vb->value);
222 snmp_varbind_tail_add(&msg_ps->outvb, vb);
224 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
229 en->get_value_pc(request_id, &msg_ps->ext_object_def);
231 msg_ps->vb_ptr->ident = vb->ident;
232 msg_ps->vb_ptr->ident_len = vb->ident_len;
234 snmp_error_response(msg_ps,SNMP_ES_TOOBIG);
240 en->get_value_a(request_id, &msg_ps->ext_object_def, 0,
NULL);
242 snmp_varbind_tail_add(&msg_ps->outvb, vb);
244 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
250 en->get_value_pc(request_id, &msg_ps->ext_object_def);
252 snmp_error_response(msg_ps,SNMP_ES_TOOBIG);
256 while ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) &&
257 (msg_ps->vb_idx < msg_ps->invb.count))
260 struct snmp_name_ptr np;
262 if (msg_ps->vb_idx == 0)
264 msg_ps->vb_ptr = msg_ps->invb.head;
268 msg_ps->vb_ptr = msg_ps->vb_ptr->next;
271 if (snmp_iso_prefix_tst(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident))
273 mn = snmp_search_tree((
struct mib_node*)&internet, msg_ps->vb_ptr->ident_len - 4,
274 msg_ps->vb_ptr->ident + 4, &np);
277 if (mn->node_type == MIB_NODE_EX)
280 struct mib_external_node *
en = (
struct mib_external_node*)mn;
282 msg_ps->state = SNMP_MSG_EXTERNAL_GET_OBJDEF;
284 msg_ps->ext_mib_node =
en;
285 msg_ps->ext_name_ptr = np;
287 en->get_object_def_q(
en->addr_inf, request_id, np.ident_len, np.ident);
292 struct obj_def object_def;
294 msg_ps->state = SNMP_MSG_INTERNAL_GET_OBJDEF;
295 mn->get_object_def(np.ident_len, np.ident, &object_def);
296 if ((object_def.instance != MIB_OBJECT_NONE) &&
297 (object_def.access & MIB_ACCESS_READ))
308 struct snmp_varbind *vb;
310 msg_ps->state = SNMP_MSG_INTERNAL_GET_VALUE;
312 vb = (
struct snmp_varbind *)
memp_malloc(MEMP_SNMP_VARBIND);
319 vb->ident = msg_ps->vb_ptr->ident;
320 vb->ident_len = msg_ps->vb_ptr->ident_len;
322 msg_ps->vb_ptr->ident =
NULL;
323 msg_ps->vb_ptr->ident_len = 0;
325 vb->value_type = object_def.asn_type;
326 LWIP_ASSERT(
"invalid length", object_def.v_len <= 0xff);
327 vb->value_len = (
u8_t)object_def.v_len;
328 if (vb->value_len > 0)
330 LWIP_ASSERT(
"SNMP_MAX_OCTET_STRING_LEN is configured too low",
333 if (vb->value !=
NULL)
335 mn->get_value(&object_def, vb->value_len, vb->value);
336 snmp_varbind_tail_add(&msg_ps->outvb, vb);
337 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
343 msg_ps->vb_ptr->ident = vb->ident;
344 msg_ps->vb_ptr->ident_len = vb->ident_len;
348 snmp_error_response(msg_ps,SNMP_ES_TOOBIG);
355 snmp_varbind_tail_add(&msg_ps->outvb, vb);
356 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
363 snmp_error_response(msg_ps,SNMP_ES_TOOBIG);
376 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
379 if ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) &&
380 (msg_ps->vb_idx == msg_ps->invb.count))
382 snmp_ok_response(msg_ps);
393snmp_msg_getnext_event(
u8_t request_id,
struct snmp_msg_pstat *msg_ps)
397 if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF)
399 struct mib_external_node *
en;
402 en = msg_ps->ext_mib_node;
405 en->get_object_def_a(request_id, 1, &msg_ps->ext_oid.id[msg_ps->ext_oid.len - 1], &msg_ps->ext_object_def);
406 if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE)
408 msg_ps->state = SNMP_MSG_EXTERNAL_GET_VALUE;
409 en->get_value_q(request_id, &msg_ps->ext_object_def);
413 en->get_object_def_pc(request_id, 1, &msg_ps->ext_oid.id[msg_ps->ext_oid.len - 1]);
415 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
418 else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_VALUE)
420 struct mib_external_node *
en;
421 struct snmp_varbind *vb;
424 en = msg_ps->ext_mib_node;
426 LWIP_ASSERT(
"invalid length", msg_ps->ext_object_def.v_len <= 0xff);
427 vb = snmp_varbind_alloc(&msg_ps->ext_oid,
428 msg_ps->ext_object_def.asn_type,
429 (
u8_t)msg_ps->ext_object_def.v_len);
432 en->get_value_a(request_id, &msg_ps->ext_object_def, vb->value_len, vb->value);
433 snmp_varbind_tail_add(&msg_ps->outvb, vb);
434 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
439 en->get_value_pc(request_id, &msg_ps->ext_object_def);
441 snmp_error_response(msg_ps,SNMP_ES_TOOBIG);
445 while ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) &&
446 (msg_ps->vb_idx < msg_ps->invb.count))
449 struct snmp_obj_id oid;
451 if (msg_ps->vb_idx == 0)
453 msg_ps->vb_ptr = msg_ps->invb.head;
457 msg_ps->vb_ptr = msg_ps->vb_ptr->next;
459 if (snmp_iso_prefix_expand(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident, &oid))
461 if (msg_ps->vb_ptr->ident_len > 3)
464 mn = snmp_expand_tree((
struct mib_node*)&internet,
465 msg_ps->vb_ptr->ident_len - 4,
466 msg_ps->vb_ptr->ident + 4, &oid);
471 mn = snmp_expand_tree((
struct mib_node*)&internet, 0,
NULL, &oid);
480 if (mn->node_type == MIB_NODE_EX)
483 struct mib_external_node *
en = (
struct mib_external_node*)mn;
485 msg_ps->state = SNMP_MSG_EXTERNAL_GET_OBJDEF;
487 msg_ps->ext_mib_node =
en;
488 msg_ps->ext_oid = oid;
490 en->get_object_def_q(
en->addr_inf, request_id, 1, &oid.id[oid.len - 1]);
495 struct obj_def object_def;
496 struct snmp_varbind *vb;
498 msg_ps->state = SNMP_MSG_INTERNAL_GET_OBJDEF;
499 mn->get_object_def(1, &oid.id[oid.len - 1], &object_def);
501 LWIP_ASSERT(
"invalid length", object_def.v_len <= 0xff);
502 vb = snmp_varbind_alloc(&oid, object_def.asn_type, (
u8_t)object_def.v_len);
505 msg_ps->state = SNMP_MSG_INTERNAL_GET_VALUE;
506 mn->get_value(&object_def, object_def.v_len, vb->value);
507 snmp_varbind_tail_add(&msg_ps->outvb, vb);
508 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
514 snmp_error_response(msg_ps,SNMP_ES_TOOBIG);
521 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
524 if ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) &&
525 (msg_ps->vb_idx == msg_ps->invb.count))
527 snmp_ok_response(msg_ps);
538snmp_msg_set_event(
u8_t request_id,
struct snmp_msg_pstat *msg_ps)
542 if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF)
544 struct mib_external_node *
en;
545 struct snmp_name_ptr np;
548 en = msg_ps->ext_mib_node;
549 np = msg_ps->ext_name_ptr;
552 en->get_object_def_a(request_id, np.ident_len, np.ident, &msg_ps->ext_object_def);
553 if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE)
555 msg_ps->state = SNMP_MSG_EXTERNAL_SET_TEST;
556 en->set_test_q(request_id, &msg_ps->ext_object_def);
560 en->get_object_def_pc(request_id, np.ident_len, np.ident);
562 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
565 else if (msg_ps->state == SNMP_MSG_EXTERNAL_SET_TEST)
567 struct mib_external_node *
en;
570 en = msg_ps->ext_mib_node;
572 if (msg_ps->ext_object_def.access & MIB_ACCESS_WRITE)
574 if ((msg_ps->ext_object_def.asn_type == msg_ps->vb_ptr->value_type) &&
575 (
en->set_test_a(request_id,&msg_ps->ext_object_def,
576 msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value) != 0))
578 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
583 en->set_test_pc(request_id,&msg_ps->ext_object_def);
585 snmp_error_response(msg_ps,SNMP_ES_BADVALUE);
590 en->set_test_pc(request_id,&msg_ps->ext_object_def);
592 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
595 else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF_S)
597 struct mib_external_node *
en;
598 struct snmp_name_ptr np;
601 en = msg_ps->ext_mib_node;
602 np = msg_ps->ext_name_ptr;
605 en->get_object_def_a(request_id, np.ident_len, np.ident, &msg_ps->ext_object_def);
606 if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE)
608 msg_ps->state = SNMP_MSG_EXTERNAL_SET_VALUE;
609 en->set_value_q(request_id, &msg_ps->ext_object_def,
610 msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value);
614 en->get_object_def_pc(request_id, np.ident_len, np.ident);
616 snmp_error_response(msg_ps,SNMP_ES_GENERROR);
619 else if (msg_ps->state == SNMP_MSG_EXTERNAL_SET_VALUE)
621 struct mib_external_node *
en;
624 en = msg_ps->ext_mib_node;
625 en->set_value_a(request_id, &msg_ps->ext_object_def,
626 msg_ps->vb_ptr->value_len, msg_ps->vb_ptr->value);
629 msg_ps->state = SNMP_MSG_INTERNAL_SET_VALUE;
634 while ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) &&
635 (msg_ps->vb_idx < msg_ps->invb.count))
638 struct snmp_name_ptr np;
640 if (msg_ps->vb_idx == 0)
642 msg_ps->vb_ptr = msg_ps->invb.head;
646 msg_ps->vb_ptr = msg_ps->vb_ptr->next;
649 if (snmp_iso_prefix_tst(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident))
651 mn = snmp_search_tree((
struct mib_node*)&internet, msg_ps->vb_ptr->ident_len - 4,
652 msg_ps->vb_ptr->ident + 4, &np);
655 if (mn->node_type == MIB_NODE_EX)
658 struct mib_external_node *
en = (
struct mib_external_node*)mn;
660 msg_ps->state = SNMP_MSG_EXTERNAL_GET_OBJDEF;
662 msg_ps->ext_mib_node =
en;
663 msg_ps->ext_name_ptr = np;
665 en->get_object_def_q(
en->addr_inf, request_id, np.ident_len, np.ident);
670 struct obj_def object_def;
672 msg_ps->state = SNMP_MSG_INTERNAL_GET_OBJDEF;
673 mn->get_object_def(np.ident_len, np.ident, &object_def);
674 if (object_def.instance != MIB_OBJECT_NONE)
685 msg_ps->state = SNMP_MSG_INTERNAL_SET_TEST;
687 if (object_def.access & MIB_ACCESS_WRITE)
689 if ((object_def.asn_type == msg_ps->vb_ptr->value_type) &&
690 (mn->set_test(&object_def,msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value) != 0))
692 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
698 snmp_error_response(msg_ps,SNMP_ES_BADVALUE);
704 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
717 snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME);
721 if ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) &&
722 (msg_ps->vb_idx == msg_ps->invb.count))
725 msg_ps->state = SNMP_MSG_INTERNAL_SET_VALUE;
729 while ((msg_ps->state == SNMP_MSG_INTERNAL_SET_VALUE) &&
730 (msg_ps->vb_idx < msg_ps->invb.count))
733 struct snmp_name_ptr np;
735 if (msg_ps->vb_idx == 0)
737 msg_ps->vb_ptr = msg_ps->invb.head;
741 msg_ps->vb_ptr = msg_ps->vb_ptr->next;
744 mn = snmp_search_tree((
struct mib_node*)&internet, msg_ps->vb_ptr->ident_len - 4,
745 msg_ps->vb_ptr->ident + 4, &np);
750 if (mn->node_type == MIB_NODE_EX)
753 struct mib_external_node *
en = (
struct mib_external_node*)mn;
755 msg_ps->state = SNMP_MSG_EXTERNAL_GET_OBJDEF_S;
757 msg_ps->ext_mib_node =
en;
758 msg_ps->ext_name_ptr = np;
760 en->get_object_def_q(
en->addr_inf, request_id, np.ident_len, np.ident);
765 struct obj_def object_def;
767 msg_ps->state = SNMP_MSG_INTERNAL_GET_OBJDEF_S;
768 mn->get_object_def(np.ident_len, np.ident, &object_def);
769 msg_ps->state = SNMP_MSG_INTERNAL_SET_VALUE;
770 mn->set_value(&object_def,msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value);
775 if ((msg_ps->state == SNMP_MSG_INTERNAL_SET_VALUE) &&
776 (msg_ps->vb_idx == msg_ps->invb.count))
781 msg_ps->outvb = msg_ps->invb;
782 msg_ps->invb.head =
NULL;
783 msg_ps->invb.tail =
NULL;
784 msg_ps->invb.count = 0;
785 snmp_ok_response(msg_ps);
797snmp_msg_event(
u8_t request_id)
799 struct snmp_msg_pstat *msg_ps;
803 msg_ps = &msg_input_list[request_id];
804 if (msg_ps->rt == SNMP_ASN1_PDU_GET_NEXT_REQ)
806 snmp_msg_getnext_event(request_id, msg_ps);
808 else if (msg_ps->rt == SNMP_ASN1_PDU_GET_REQ)
810 snmp_msg_get_event(request_id, msg_ps);
812 else if(msg_ps->rt == SNMP_ASN1_PDU_SET_REQ)
814 snmp_msg_set_event(request_id, msg_ps);
824 struct snmp_msg_pstat *msg_ps;
827 u16_t payload_len =
p->tot_len;
828 u16_t payload_ofs = 0;
829 u16_t varbind_ofs = 0;
835 msg_ps = &msg_input_list[0];
859 err_ret = snmp_pdu_header_check(
p, payload_ofs, payload_len, &varbind_ofs, msg_ps);
862 if ((err_ret !=
ERR_OK) ||
863 ((msg_ps->rt != SNMP_ASN1_PDU_GET_REQ) &&
864 (msg_ps->rt != SNMP_ASN1_PDU_GET_NEXT_REQ) &&
865 (msg_ps->rt != SNMP_ASN1_PDU_SET_REQ)) ||
866 ((msg_ps->error_status != SNMP_ES_NOERROR) ||
867 (msg_ps->error_index != 0)) )
878 err_ret = snmp_pdu_dec_varbindlist(
p, varbind_ofs, &varbind_ofs, msg_ps);
881 if ((err_ret !=
ERR_OK) || (msg_ps->invb.count == 0))
890 msg_ps->error_status = SNMP_ES_NOERROR;
891 msg_ps->error_index = 0;
893 msg_ps->state = SNMP_MSG_SEARCH_OBJ;
900 snmp_msg_event(req_idx);
916snmp_pdu_header_check(
struct pbuf *
p,
u16_t ofs,
u16_t pdu_len,
u16_t *ofs_ret,
struct snmp_msg_pstat *m_stat)
925 snmp_asn1_dec_type(
p, ofs, &
type);
926 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
928 (pdu_len != (1 + len_octets +
len)) ||
929 (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ)))
934 ofs += (1 + len_octets);
935 snmp_asn1_dec_type(
p, ofs, &
type);
936 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
937 if ((derr !=
ERR_OK) || (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG)))
943 derr = snmp_asn1_dec_s32t(
p, ofs + 1 + len_octets,
len, &
version);
956 ofs += (1 + len_octets +
len);
957 snmp_asn1_dec_type(
p, ofs, &
type);
958 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
959 if ((derr !=
ERR_OK) || (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR)))
965 derr = snmp_asn1_dec_raw(
p, ofs + 1 + len_octets,
len, SNMP_COMMUNITY_STR_LEN, m_stat->community);
972 len = ((
len < (SNMP_COMMUNITY_STR_LEN))?(
len):(SNMP_COMMUNITY_STR_LEN));
973 m_stat->community[
len] = 0;
974 m_stat->com_strlen = (
u8_t)
len;
975 if (
strncmp(snmp_publiccommunity, (
const char*)m_stat->community, SNMP_COMMUNITY_STR_LEN) != 0)
979 snmp_authfail_trap();
982 ofs += (1 + len_octets +
len);
983 snmp_asn1_dec_type(
p, ofs, &
type);
984 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
992 case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_REQ):
997 case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_NEXT_REQ):
1002 case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_RESP):
1007 case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_SET_REQ):
1012 case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_TRAP):
1027 m_stat->rt =
type & 0x1F;
1028 ofs += (1 + len_octets);
1029 if (
len != (pdu_len - (ofs - ofs_base)))
1035 snmp_asn1_dec_type(
p, ofs, &
type);
1036 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
1037 if ((derr !=
ERR_OK) || (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG)))
1043 derr = snmp_asn1_dec_s32t(
p, ofs + 1 + len_octets,
len, &m_stat->rid);
1050 ofs += (1 + len_octets +
len);
1051 snmp_asn1_dec_type(
p, ofs, &
type);
1052 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
1053 if ((derr !=
ERR_OK) || (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG)))
1061 derr = snmp_asn1_dec_s32t(
p, ofs + 1 + len_octets,
len, &m_stat->error_status);
1068 switch (m_stat->error_status)
1070 case SNMP_ES_TOOBIG:
1073 case SNMP_ES_NOSUCHNAME:
1076 case SNMP_ES_BADVALUE:
1079 case SNMP_ES_READONLY:
1082 case SNMP_ES_GENERROR:
1086 ofs += (1 + len_octets +
len);
1087 snmp_asn1_dec_type(
p, ofs, &
type);
1088 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
1089 if ((derr !=
ERR_OK) || (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG)))
1097 derr = snmp_asn1_dec_s32t(
p, ofs + 1 + len_octets,
len, &m_stat->error_index);
1104 ofs += (1 + len_octets +
len);
1110snmp_pdu_dec_varbindlist(
struct pbuf *
p,
u16_t ofs,
u16_t *ofs_ret,
struct snmp_msg_pstat *m_stat)
1118 snmp_asn1_dec_type(
p, ofs, &
type);
1119 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &vb_len);
1121 (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ)))
1126 ofs += (1 + len_octets);
1129 m_stat->invb.count = 0;
1130 m_stat->invb.head =
NULL;
1131 m_stat->invb.tail =
NULL;
1135 struct snmp_obj_id oid, oid_value;
1136 struct snmp_varbind *vb;
1138 snmp_asn1_dec_type(
p, ofs, &
type);
1139 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
1141 (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ)) ||
1142 (
len == 0) || (
len > vb_len))
1146 snmp_varbind_list_free(&m_stat->invb);
1149 ofs += (1 + len_octets);
1150 vb_len -= (1 + len_octets);
1152 snmp_asn1_dec_type(
p, ofs, &
type);
1153 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
1154 if ((derr !=
ERR_OK) || (
type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID)))
1159 snmp_varbind_list_free(&m_stat->invb);
1162 derr = snmp_asn1_dec_oid(
p, ofs + 1 + len_octets,
len, &oid);
1168 snmp_varbind_list_free(&m_stat->invb);
1171 ofs += (1 + len_octets +
len);
1172 vb_len -= (1 + len_octets +
len);
1174 snmp_asn1_dec_type(
p, ofs, &
type);
1175 derr = snmp_asn1_dec_length(
p, ofs+1, &len_octets, &
len);
1181 snmp_varbind_list_free(&m_stat->invb);
1187 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG):
1188 vb = snmp_varbind_alloc(&oid,
type,
sizeof(
s32_t));
1193 derr = snmp_asn1_dec_s32t(
p, ofs + 1 + len_octets,
len, vptr);
1194 snmp_varbind_tail_add(&m_stat->invb, vb);
1201 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER):
1202 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE):
1203 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS):
1204 vb = snmp_varbind_alloc(&oid,
type,
sizeof(
u32_t));
1209 derr = snmp_asn1_dec_u32t(
p, ofs + 1 + len_octets,
len, vptr);
1210 snmp_varbind_tail_add(&m_stat->invb, vb);
1217 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR):
1218 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE):
1223 derr = snmp_asn1_dec_raw(
p, ofs + 1 + len_octets,
len, vb->value_len, (
u8_t*)vb->value);
1224 snmp_varbind_tail_add(&m_stat->invb, vb);
1231 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL):
1232 vb = snmp_varbind_alloc(&oid,
type, 0);
1235 snmp_varbind_tail_add(&m_stat->invb, vb);
1243 case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID):
1244 derr = snmp_asn1_dec_oid(
p, ofs + 1 + len_octets,
len, &oid_value);
1247 vb = snmp_varbind_alloc(&oid,
type, oid_value.len *
sizeof(
s32_t));
1250 u8_t i = oid_value.len;
1256 vptr[
i] = oid_value.id[
i];
1258 snmp_varbind_tail_add(&m_stat->invb, vb);
1267 case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR):
1271 vb = snmp_varbind_alloc(&oid,
type, 4);
1274 derr = snmp_asn1_dec_raw(
p, ofs + 1 + len_octets,
len, vb->value_len, (
u8_t*)vb->value);
1275 snmp_varbind_tail_add(&m_stat->invb, vb);
1295 snmp_varbind_list_free(&m_stat->invb);
1298 ofs += (1 + len_octets +
len);
1299 vb_len -= (1 + len_octets +
len);
1302 if (m_stat->rt == SNMP_ASN1_PDU_SET_REQ)
1318 struct snmp_varbind *vb;
1320 vb = (
struct snmp_varbind *)
memp_malloc(MEMP_SNMP_VARBIND);
1334 if (vb->ident ==
NULL)
1343 vb->ident[
i] = oid->id[
i];
1351 vb->value_type =
type;
1352 vb->value_len =
len;
1358 if (vb->value ==
NULL)
1361 if (vb->ident !=
NULL)
1383snmp_varbind_free(
struct snmp_varbind *vb)
1385 if (vb->value !=
NULL )
1389 if (vb->ident !=
NULL )
1397snmp_varbind_list_free(
struct snmp_varbind_root *
root)
1399 struct snmp_varbind *vb, *prev;
1402 while ( vb !=
NULL )
1405 snmp_varbind_free(vb);
1414snmp_varbind_tail_add(
struct snmp_varbind_root *
root,
struct snmp_varbind *vb)
1416 if (
root->count == 0)
1425 root->tail->next = vb;
1426 vb->prev =
root->tail;
1433snmp_varbind_tail_remove(
struct snmp_varbind_root *
root)
1435 struct snmp_varbind* vb;
1437 if (
root->count > 0)
1441 root->tail = vb->prev;
1442 vb->prev->next =
NULL;
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
#define LWIP_UNUSED_ARG(x)
static const WCHAR version[]
#define LWIP_DEBUGF(debug, message)
#define LWIP_ASSERT(message, assertion)
#define snmp_inc_snmpinbadcommunitynames()
#define snmp_inc_snmpinnosuchnames()
#define snmp_inc_snmpingetnexts()
#define snmp_inc_snmpinasnparseerrs()
#define snmp_inc_snmpingetrequests()
#define snmp_inc_snmpinbadvalues()
#define snmp_inc_snmpintraps()
#define snmp_inc_snmpintoobigs()
#define snmp_inc_snmpinbadversions()
#define snmp_inc_snmpinreadonlys()
#define snmp_inc_snmpinpkts()
#define snmp_add_snmpintotalreqvars(value)
#define snmp_inc_snmpingetresponses()
#define snmp_inc_snmpingenerrs()
#define snmp_inc_snmpinsetrequests()
#define snmp_add_snmpintotalsetvars(value)
GLuint GLuint GLsizei GLenum type
GLenum const GLvoid * addr
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
void * memp_malloc(memp_t type)
void memp_free(memp_t type, void *mem)
#define SNMP_MAX_TREE_DEPTH
#define SNMP_MAX_VALUE_SIZE
#define SNMP_CONCURRENT_REQUESTS
u8_t pbuf_free(struct pbuf *p)