static void sensorentry_set_test_q(u8_t rid, struct obj_def *od) { LWIP_UNUSED_ARG(od); /* fake async quesion/answer */ snmp_msg_event(rid); }
static void sensorentry_set_value_q(u8_t rid, struct obj_def *od, u16_t len, void *value) { LWIP_UNUSED_ARG(rid); LWIP_UNUSED_ARG(od); LWIP_UNUSED_ARG(len); LWIP_UNUSED_ARG(value); /* fake async quesion/answer */ snmp_msg_event(rid); }
/** * Async question for object definition */ static void sensorentry_get_object_def_q(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident) { s32_t sensor_register, sensor_address; LWIP_UNUSED_ARG(addr_inf); LWIP_UNUSED_ARG(rid); ident_len += 1; ident -= 1; /* send request */ sensor_register = ident[0]; sensor_address = ident[1]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("sensor_request reg=%"S32_F" addr=%"S32_F"\n", sensor_register, sensor_address)); /* fake async quesion/answer */ snmp_msg_event(rid); }
/* lwIP UDP receive callback function */ static void snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port) { struct snmp_msg_pstat *msg_ps; u8_t req_idx; err_t err_ret; u16_t payload_len = p->tot_len; u16_t payload_ofs = 0; u16_t varbind_ofs = 0; /* suppress unused argument warning */ LWIP_UNUSED_ARG(arg); /* traverse input message process list, look for SNMP_MSG_EMPTY */ msg_ps = &msg_input_list[0]; req_idx = 0; while ((req_idx < SNMP_CONCURRENT_REQUESTS) && (msg_ps->state != SNMP_MSG_EMPTY)) { req_idx++; msg_ps++; } if (req_idx == SNMP_CONCURRENT_REQUESTS) { /* exceeding number of concurrent requests */ pbuf_free(p); return; } /* accepting request */ snmp_inc_snmpinpkts(); /* record used 'protocol control block' */ msg_ps->pcb = pcb; /* source address (network order) */ msg_ps->sip = *addr; /* source port (host order (lwIP oddity)) */ msg_ps->sp = port; /* check total length, version, community, pdu type */ err_ret = snmp_pdu_header_check(p, payload_ofs, payload_len, &varbind_ofs, msg_ps); /* Only accept requests and requests without error (be robust) */ /* Reject response and trap headers or error requests as input! */ if ((err_ret != ERR_OK) || ((msg_ps->rt != SNMP_ASN1_PDU_GET_REQ) && (msg_ps->rt != SNMP_ASN1_PDU_GET_NEXT_REQ) && (msg_ps->rt != SNMP_ASN1_PDU_SET_REQ)) || ((msg_ps->error_status != SNMP_ES_NOERROR) || (msg_ps->error_index != 0)) ) { /* header check failed drop request silently, do not return error! */ pbuf_free(p); LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_pdu_header_check() failed\n")); return; } LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_recv ok, community %s\n", msg_ps->community)); /* Builds a list of variable bindings. Copy the varbinds from the pbuf chain to glue them when these are divided over two or more pbuf's. */ err_ret = snmp_pdu_dec_varbindlist(p, varbind_ofs, &varbind_ofs, msg_ps); /* we've decoded the incoming message, release input msg now */ pbuf_free(p); if ((err_ret != ERR_OK) || (msg_ps->invb.count == 0)) { /* varbind-list decode failed, or varbind list empty. drop request silently, do not return error! (errors are only returned for a specific varbind failure) */ LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_pdu_dec_varbindlist() failed\n")); return; } msg_ps->error_status = SNMP_ES_NOERROR; msg_ps->error_index = 0; /* find object for each variable binding */ msg_ps->state = SNMP_MSG_SEARCH_OBJ; /* first variable binding from list to inspect */ msg_ps->vb_idx = 0; LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_recv varbind cnt=%"U16_F"\n",(u16_t)msg_ps->invb.count)); /* handle input event and as much objects as possible in one go */ snmp_msg_event(req_idx); }