static snmp_err_t ip_NetToMediaTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) { u8_t i; struct snmp_next_oid_state state; u32_t result_temp[LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges)]; /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges)); /* iterate over all possible OIDs to find the next one */ for (i=0; i<ARP_TABLE_SIZE; i++) { ip4_addr_t *ip; struct netif *netif; struct eth_addr *ethaddr; if (etharp_get_entry(i, &ip, &netif, ðaddr)) { u32_t test_oid[LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges)]; test_oid[0] = netif_to_num(netif); snmp_ip4_to_oid(ip, &test_oid[1]); /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges), LWIP_PTR_NUMERIC_CAST(void*, i)); } }
static snmp_err_t ip_AddrTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) { struct netif *netif; struct snmp_next_oid_state state; u32_t result_temp[LWIP_ARRAYSIZE(ip_AddrTable_oid_ranges)]; /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(ip_AddrTable_oid_ranges)); /* iterate over all possible OIDs to find the next one */ netif = netif_list; while (netif != NULL) { u32_t test_oid[LWIP_ARRAYSIZE(ip_AddrTable_oid_ranges)]; snmp_ip4_to_oid(netif_ip4_addr(netif), &test_oid[0]); /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(ip_AddrTable_oid_ranges), netif); netif = netif->next; } /* did we find a next one? */ if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* fill in object properties */ return ip_AddrTable_get_cell_value_core((struct netif*)state.reference, column, value, value_len); } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t sensor_table_get_next_cell_instance(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance) { size_t i; struct snmp_next_oid_state state; u32_t result_temp[LWIP_ARRAYSIZE(sensor_table_oid_ranges)]; LWIP_UNUSED_ARG(column); /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(sensor_table_oid_ranges)); /* iterate over all possible OIDs to find the next one */ for(i=0; i<LWIP_ARRAYSIZE(sensors); i++) { if(sensors[i].num != 0) { u32_t test_oid[LWIP_ARRAYSIZE(sensor_table_oid_ranges)]; test_oid[0] = sensors[i].num; /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(sensor_table_oid_ranges), (void*)i); } } /* did we find a next one? */ if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* store sensor index for subsequent operations (get/test/set) */ cell_instance->reference.u32 = LWIP_CONST_CAST(u32_t, state.reference); return SNMP_ERR_NOERROR; } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t interfaces_Table_get_next_cell_instance(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance) { struct netif *netif; struct snmp_next_oid_state state; u32_t result_temp[LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)]; LWIP_UNUSED_ARG(column); /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)); /* iterate over all possible OIDs to find the next one */ netif = netif_list; while (netif != NULL) { u32_t test_oid[LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)]; test_oid[0] = netif_to_num(netif); /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges), netif); netif = netif->next; } /* did we find a next one? */ if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* store netif pointer for subsequent operations (get/test/set) */ cell_instance->reference.ptr = /* (struct netif*) */state.reference; return SNMP_ERR_NOERROR; } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t sensor_table_get_cell_instance(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, struct snmp_node_instance* cell_instance) { u32_t sensor_num; size_t i; LWIP_UNUSED_ARG(column); /* check if incoming OID length and if values are in plausible range */ if(!snmp_oid_in_range(row_oid, row_oid_len, sensor_table_oid_ranges, LWIP_ARRAYSIZE(sensor_table_oid_ranges))) { return SNMP_ERR_NOSUCHINSTANCE; } /* get sensor index from incoming OID */ sensor_num = row_oid[0]; /* find sensor with index */ for(i=0; i<LWIP_ARRAYSIZE(sensors); i++) { if(sensors[i].num != 0) { if(sensors[i].num == sensor_num) { /* store sensor index for subsequent operations (get/test/set) */ cell_instance->reference.u32 = (u32_t)i; return SNMP_ERR_NOERROR; } } } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t tcp_ConnTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) { u8_t i; ip4_addr_t local_ip; ip4_addr_t remote_ip; u16_t local_port; u16_t remote_port; struct tcp_pcb *pcb; /* check if incoming OID length and if values are in plausible range */ if (!snmp_oid_in_range(row_oid, row_oid_len, tcp_ConnTable_oid_ranges, LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges))) { return SNMP_ERR_NOSUCHINSTANCE; } /* get IPs and ports from incoming OID */ snmp_oid_to_ip4(&row_oid[0], &local_ip); /* we know it succeeds because of oid_in_range check above */ local_port = (u16_t)row_oid[4]; snmp_oid_to_ip4(&row_oid[5], &remote_ip); /* we know it succeeds because of oid_in_range check above */ remote_port = (u16_t)row_oid[9]; /* find tcp_pcb with requested ips and ports */ for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) { pcb = *tcp_pcb_lists[i]; while (pcb != NULL) { /* do local IP and local port match? */ if (IP_IS_V4_VAL(pcb->local_ip) && ip4_addr_cmp(&local_ip, ip_2_ip4(&pcb->local_ip)) && (local_port == pcb->local_port)) { /* PCBs in state LISTEN are not connected and have no remote_ip or remote_port */ if (pcb->state == LISTEN) { if (ip4_addr_cmp(&remote_ip, IP4_ADDR_ANY) && (remote_port == 0)) { /* fill in object properties */ return tcp_ConnTable_get_cell_value_core(pcb, column, value, value_len); } } else { if (IP_IS_V4_VAL(pcb->remote_ip) && ip4_addr_cmp(&remote_ip, ip_2_ip4(&pcb->remote_ip)) && (remote_port == pcb->remote_port)) { /* fill in object properties */ return tcp_ConnTable_get_cell_value_core(pcb, column, value, value_len); } } } pcb = pcb->next; } } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) { u8_t i; struct tcp_pcb *pcb; struct snmp_next_oid_state state; u32_t result_temp[LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges)]; /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges)); /* iterate over all possible OIDs to find the next one */ for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) { pcb = *tcp_pcb_lists[i]; while (pcb != NULL) { u32_t test_oid[LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges)]; if (IP_IS_V4_VAL(pcb->local_ip)) { snmp_ip4_to_oid(ip_2_ip4(&pcb->local_ip), &test_oid[0]); test_oid[4] = pcb->local_port; /* PCBs in state LISTEN are not connected and have no remote_ip or remote_port */ if (pcb->state == LISTEN) { snmp_ip4_to_oid(IP4_ADDR_ANY, &test_oid[5]); test_oid[9] = 0; } else { if (IP_IS_V6_VAL(pcb->remote_ip)) { /* should never happen */ continue; } snmp_ip4_to_oid(ip_2_ip4(&pcb->remote_ip), &test_oid[5]); test_oid[9] = pcb->remote_port; } /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges), pcb); } pcb = pcb->next; } } /* did we find a next one? */ if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* fill in object properties */ return tcp_ConnTable_get_cell_value_core((struct tcp_pcb*)state.reference, column, value, value_len); } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t ip_AddrTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) { ip4_addr_t ip; struct netif *netif; /* check if incoming OID length and if values are in plausible range */ if (!snmp_oid_in_range(row_oid, row_oid_len, ip_AddrTable_oid_ranges, LWIP_ARRAYSIZE(ip_AddrTable_oid_ranges))) { return SNMP_ERR_NOSUCHINSTANCE; } /* get IP from incoming OID */ snmp_oid_to_ip4(&row_oid[0], &ip); /* we know it succeeds because of oid_in_range check above */ /* find netif with requested ip */ netif = netif_list; while (netif != NULL) { if (ip4_addr_cmp(&ip, netif_ip4_addr(netif))) { /* fill in object properties */ return ip_AddrTable_get_cell_value_core(netif, column, value, value_len); } netif = netif->next; } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t ip_NetToMediaTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) { ip4_addr_t ip_in; u8_t netif_index; u8_t i; /* check if incoming OID length and if values are in plausible range */ if (!snmp_oid_in_range(row_oid, row_oid_len, ip_NetToMediaTable_oid_ranges, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges))) { return SNMP_ERR_NOSUCHINSTANCE; } /* get IP from incoming OID */ netif_index = (u8_t)row_oid[0]; snmp_oid_to_ip4(&row_oid[1], &ip_in); /* we know it succeeds because of oid_in_range check above */ /* find requested entry */ for (i=0; i<ARP_TABLE_SIZE; i++) { ip4_addr_t *ip; struct netif *netif; struct eth_addr *ethaddr; if (etharp_get_entry(i, &ip, &netif, ðaddr)) { if ((netif_index == netif_to_num(netif)) && ip4_addr_cmp(&ip_in, ip)) { /* fill in object properties */ return ip_NetToMediaTable_get_cell_value_core(i, column, value, value_len); } } } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
/** Initialize this module */ void sys_timeouts_init(void) { size_t i; u32_t now = sys_now(); LWIP_ASSERT("Timer pool is too small!", LWIP_ARRAYSIZE(lwip_cyclic_timers) <= LWIP_NUM_SYS_TIMEOUT_INTERNAL); /* tcp_tmr() at index 0 is started on demand */ for (i = (LWIP_TCP ? 1 : 0); i < LWIP_ARRAYSIZE(lwip_cyclic_timers); i++) { const struct lwip_cyclic_timer *cyclic = &lwip_cyclic_timers[i]; void *arg = LWIP_CONST_CAST(void *, cyclic); #if LWIP_DEBUG_TIMERNAMES sys_timeout_abs((u32_t)(now + cyclic->interval_ms), lwip_cyclic_timer, arg, cyclic->handler_name); #else sys_timeout_abs((u32_t)(now + cyclic->interval_ms), lwip_cyclic_timer, arg); #endif } }
static snmp_err_t udp_Table_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) { ip4_addr_t ip; u16_t port; struct udp_pcb *pcb; /* check if incoming OID length and if values are in plausible range */ if(!snmp_oid_in_range(row_oid, row_oid_len, udp_Table_oid_ranges, LWIP_ARRAYSIZE(udp_Table_oid_ranges))) { return SNMP_ERR_NOSUCHINSTANCE; } /* get IP and port from incoming OID */ snmp_oid_to_ip4(&row_oid[0], &ip); /* we know it succeeds because of oid_in_range check above */ port = (u16_t)row_oid[4]; /* find udp_pcb with requested ip and port*/ pcb = udp_pcbs; while (pcb != NULL) { if(IP_IS_V4_VAL(pcb->local_ip)) { if(ip4_addr_cmp(&ip, ip_2_ip4(&pcb->local_ip)) && (port == pcb->local_port)) { /* fill in object properties */ return udp_Table_get_cell_value_core(pcb, column, value, value_len); } } pcb = pcb->next; } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t interfaces_Table_get_cell_instance(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, struct snmp_node_instance* cell_instance) { u32_t ifIndex; struct netif *netif; LWIP_UNUSED_ARG(column); /* check if incoming OID length and if values are in plausible range */ if(!snmp_oid_in_range(row_oid, row_oid_len, interfaces_Table_oid_ranges, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges))) { return SNMP_ERR_NOSUCHINSTANCE; } /* get netif index from incoming OID */ ifIndex = row_oid[0]; /* find netif with index */ netif = netif_list; while (netif != NULL) { if(netif_to_num(netif) == ifIndex) { /* store netif pointer for subsequent operations (get/test/set) */ cell_instance->reference.ptr = netif; return SNMP_ERR_NOERROR; } netif = netif->next; } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t udp_endpointTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) { struct udp_pcb *pcb; struct snmp_next_oid_state state; /* 1x udpEndpointLocalAddressType + 1x OID len + 16x udpEndpointLocalAddress + 1x udpEndpointLocalPort + * 1x udpEndpointRemoteAddressType + 1x OID len + 16x udpEndpointRemoteAddress + 1x udpEndpointRemotePort + * 1x udpEndpointInstance = 39 */ u32_t result_temp[39]; LWIP_UNUSED_ARG(value_len); /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(result_temp)); /* iterate over all possible OIDs to find the next one */ pcb = udp_pcbs; while (pcb != NULL) { u32_t test_oid[LWIP_ARRAYSIZE(result_temp)]; u8_t idx = 0; /* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */ idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]); /* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */ idx += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[idx]); test_oid[idx] = 0; /* udpEndpointInstance */ idx++; /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, idx, NULL); pcb = pcb->next; } /* did we find a next one? */ if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* fill in object properties */ return udp_endpointTable_get_cell_value_core(column, value); } else { /* not found */ return SNMP_ERR_NOSUCHINSTANCE; } }
static snmp_err_t tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) { struct tcp_pcb *pcb; struct snmp_next_oid_state state; /* 1x tcpConnectionLocalAddressType + 1x OID len + 16x tcpConnectionLocalAddress + 1x tcpConnectionLocalPort * 1x tcpConnectionRemAddressType + 1x OID len + 16x tcpConnectionRemAddress + 1x tcpConnectionRemPort */ u32_t result_temp[38]; u8_t i; struct tcp_pcb ** const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs}; LWIP_UNUSED_ARG(value_len); /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(result_temp)); /* iterate over all possible OIDs to find the next one */ for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) { pcb = *tcp_pcb_nonlisten_lists[i]; while (pcb != NULL) { u8_t idx = 0; u32_t test_oid[LWIP_ARRAYSIZE(result_temp)]; /* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */ idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]); /* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */ idx += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[idx]); /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, idx, pcb); pcb = pcb->next; } } /* did we find a next one? */ if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* fill in object properties */ return tcp_ConnectionTable_get_cell_value_core(column, (struct tcp_pcb*)state.reference, value); } else { /* not found */ return SNMP_ERR_NOSUCHINSTANCE; } }
/** Convert an smtp result to a string */ const char* smtp_result_str(u8_t smtp_result) { if (smtp_result >= LWIP_ARRAYSIZE(smtp_result_strs)) { return "UNKNOWN"; } return smtp_result_strs[smtp_result]; }
/** * Convert an lwip internal error to a string representation. * * @param err an lwip internal err_t * @return a string representation for err */ const char * lwip_strerr(err_t err) { if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) { return "Unknown error."; } return err_strerr[-err]; }
int err_to_errno(err_t err) { if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_to_errno_table))) { return EIO; } return err_to_errno_table[-err]; }
/** * Message type value to string * @param msg_type see enum mqtt_message_type * * @return Control message type text string */ static const char * mqtt_msg_type_to_str(u8_t msg_type) { if (msg_type >= LWIP_ARRAYSIZE(mqtt_message_type_str)) { msg_type = 0; } return mqtt_message_type_str[msg_type]; }
/** Initialize this module */ void sys_timeouts_init(void) { size_t i; /* tcp_tmr() at index 0 is started on demand */ for (i = 1; i < LWIP_ARRAYSIZE(lwip_cyclic_timers); i++) { sys_timeout(lwip_cyclic_timers[i].interval_ms, cyclic_timer, &lwip_cyclic_timers[i]); } #if NO_SYS /* Initialise timestamp for sys_check_timeouts */ timeouts_last_time = sys_now(); #endif }
/** Initialize this module */ void sys_timeouts_init(void) { size_t i; /* tcp_tmr() at index 0 is started on demand */ for (i = 1; i < LWIP_ARRAYSIZE(lwip_cyclic_timers); i++) { /* we have to cast via size_t to get rid of const warning (this is OK as cyclic_timer() casts back to const* */ sys_timeout(lwip_cyclic_timers[i].interval_ms, cyclic_timer, (void*)(size_t)&lwip_cyclic_timers[i]); } /* Initialise timestamp for sys_check_timeouts */ timeouts_last_time = sys_now(); }
static snmp_err_t ip_NetToMediaTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) { u8_t i; struct snmp_next_oid_state state; u32_t result_temp[LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges)]; /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges)); /* iterate over all possible OIDs to find the next one */ for (i=0; i<ARP_TABLE_SIZE; i++) { ip4_addr_t *ip; struct netif *netif; struct eth_addr *ethaddr; if (etharp_get_entry(i, &ip, &netif, ðaddr)) { u32_t test_oid[LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges)]; test_oid[0] = netif_to_num(netif); snmp_ip4_to_oid(ip, &test_oid[1]); /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges), (void*)(size_t)i); } } /* did we find a next one? */ if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* fill in object properties */ return ip_NetToMediaTable_get_cell_value_core((u8_t)(size_t)state.reference, column, value, value_len); } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
static snmp_err_t udp_Table_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) { struct udp_pcb *pcb; struct snmp_next_oid_state state; u32_t result_temp[LWIP_ARRAYSIZE(udp_Table_oid_ranges)]; /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(udp_Table_oid_ranges)); /* iterate over all possible OIDs to find the next one */ pcb = udp_pcbs; while (pcb != NULL) { u32_t test_oid[LWIP_ARRAYSIZE(udp_Table_oid_ranges)]; if(IP_IS_V4_VAL(pcb->local_ip)) { snmp_ip4_to_oid(ip_2_ip4(&pcb->local_ip), &test_oid[0]); test_oid[4] = pcb->local_port; /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(udp_Table_oid_ranges), pcb); } pcb = pcb->next; } /* did we find a next one? */ if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); /* fill in object properties */ return udp_Table_get_cell_value_core((struct udp_pcb*)state.reference, column, value, value_len); } else { /* not found */ return SNMP_ERR_NOSUCHINSTANCE; } }
/* sensorcount .1.3.6.1.4.1.26381.1.2 */ static s16_t sensor_count_get_value(struct snmp_node_instance* instance, void* value) { size_t count = 0; u32_t *uint_ptr = (u32_t*)value; LWIP_UNUSED_ARG(instance); for(count=0; count<LWIP_ARRAYSIZE(sensors); count++) { if(sensors[count].num == 0) { *uint_ptr = (u32_t)count; return sizeof(*uint_ptr); } } return 0; }
static snmp_err_t tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) { ip_addr_t local_ip, remote_ip; u16_t local_port, remote_port; struct tcp_pcb *pcb; u8_t idx = 0; u8_t i; struct tcp_pcb ** const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs}; LWIP_UNUSED_ARG(value_len); /* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */ idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &local_ip, &local_port); if (idx == 0) { return SNMP_ERR_NOSUCHINSTANCE; } /* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */ idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &remote_ip, &remote_port); if (idx == 0) { return SNMP_ERR_NOSUCHINSTANCE; } /* find tcp_pcb with requested ip and port*/ for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) { pcb = *tcp_pcb_nonlisten_lists[i]; while (pcb != NULL) { if (ip_addr_cmp(&local_ip, &pcb->local_ip) && (local_port == pcb->local_port) && ip_addr_cmp(&remote_ip, &pcb->remote_ip) && (remote_port == pcb->remote_port)) { /* fill in object properties */ return tcp_ConnectionTable_get_cell_value_core(column, pcb, value); } pcb = pcb->next; } } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
/** * Initializes lwIP built-in pools. * Related functions: memp_malloc, memp_free * * Carves out memp_memory into linked lists for each pool-type. */ void memp_init(void) { u16_t i; /* for every pool: */ for (i = 0; i < LWIP_ARRAYSIZE(memp_pools); i++) { memp_init_pool(memp_pools[i]); #if LWIP_STATS && MEMP_STATS lwip_stats.memp[i] = memp_pools[i]->stats; #endif } #if MEMP_OVERFLOW_CHECK >= 2 /* check everything a first time to see if it worked */ memp_overflow_check_all(); #endif /* MEMP_OVERFLOW_CHECK >= 2 */ }
static void tcpip_init_done(void *arg) { sys_sem_t *sem; sem = (sys_sem_t *)arg; init_netifs(); #if LWIP_IPV4 netbiosns_set_name("simhost"); netbiosns_init(); #endif /* LWIP_IPV4 */ sntp_setoperatingmode(SNTP_OPMODE_POLL); #if LWIP_DHCP sntp_servermode_dhcp(1); /* get SNTP server via DHCP */ #else /* LWIP_DHCP */ #if LWIP_IPV4 sntp_setserver(0, netif_ip_gw4(&netif)); #endif /* LWIP_IPV4 */ #endif /* LWIP_DHCP */ sntp_init(); #if LWIP_SNMP lwip_privmib_init(); #if SNMP_LWIP_MIB2 #if SNMP_USE_NETCONN snmp_threadsync_init(&snmp_mib2_lwip_locks, snmp_mib2_lwip_synchronizer); #endif /* SNMP_USE_NETCONN */ snmp_mib2_set_syscontact_readonly((const u8_t*)"root", NULL); snmp_mib2_set_syslocation_readonly((const u8_t*)"lwIP development PC", NULL); snmp_mib2_set_sysdescr((const u8_t*)"simhost", NULL); #endif /* SNMP_LWIP_MIB2 */ snmp_set_mibs(mibs, LWIP_ARRAYSIZE(mibs)); snmp_init(); #endif /* LWIP_SNMP */ sys_sem_signal(sem); }
static snmp_err_t ip_RouteTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) { ip4_addr_t test_ip; struct netif *netif; /* check if incoming OID length and if values are in plausible range */ if (!snmp_oid_in_range(row_oid, row_oid_len, ip_RouteTable_oid_ranges, LWIP_ARRAYSIZE(ip_RouteTable_oid_ranges))) { return SNMP_ERR_NOSUCHINSTANCE; } /* get IP and port from incoming OID */ snmp_oid_to_ip4(&row_oid[0], &test_ip); /* we know it succeeds because of oid_in_range check above */ /* default route is on default netif */ if (ip4_addr_isany_val(test_ip) && (netif_default != NULL)) { /* fill in object properties */ return ip_RouteTable_get_cell_value_core(netif_default, 1, column, value, value_len); } /* find netif with requested route */ netif = netif_list; while (netif != NULL) { ip4_addr_t dst; ip4_addr_get_network(&dst, netif_ip4_addr(netif), netif_ip4_netmask(netif)); if (ip4_addr_cmp(&dst, &test_ip)) { /* fill in object properties */ return ip_RouteTable_get_cell_value_core(netif, 0, column, value, value_len); } netif = netif->next; } /* not found */ return SNMP_ERR_NOSUCHINSTANCE; }
{DNS_TMR_INTERVAL, HANDLER(dns_tmr)}, #endif /* LWIP_DNS */ #if LWIP_IPV6 {ND6_TMR_INTERVAL, HANDLER(nd6_tmr)}, #if LWIP_IPV6_REASS {IP6_REASS_TMR_INTERVAL, HANDLER(ip6_reass_tmr)}, #endif /* LWIP_IPV6_REASS */ #if LWIP_IPV6_MLD {MLD6_TMR_INTERVAL, HANDLER(mld6_tmr)}, #endif /* LWIP_IPV6_MLD */ #if LWIP_IPV6_DHCP6 {DHCP6_TIMER_MSECS, HANDLER(dhcp6_tmr)}, #endif /* LWIP_IPV6_DHCP6 */ #endif /* LWIP_IPV6 */ }; const int lwip_num_cyclic_timers = LWIP_ARRAYSIZE(lwip_cyclic_timers); #if LWIP_TIMERS && !LWIP_TIMERS_CUSTOM /** The one and only timeout list */ static struct sys_timeo *next_timeout; static u32_t current_timeout_due_time; #if LWIP_TESTMODE struct sys_timeo** sys_timeouts_get_next_timeout(void) { return &next_timeout; } #endif
#include <string.h> #if (LWIP_SNMP && (SNMP_TRAP_DESTINATIONS<=0)) #error "If you want to use SNMP, you have to define SNMP_TRAP_DESTINATIONS>=1 in your lwipopts.h" #endif #if (!LWIP_UDP && LWIP_SNMP) #error "If you want to use SNMP, you have to define LWIP_UDP=1 in your lwipopts.h" #endif struct snmp_statistics snmp_stats; static const struct snmp_obj_id snmp_device_enterprise_oid_default = {SNMP_DEVICE_ENTERPRISE_OID_LEN, SNMP_DEVICE_ENTERPRISE_OID}; static const struct snmp_obj_id* snmp_device_enterprise_oid = &snmp_device_enterprise_oid_default; const u32_t snmp_zero_dot_zero_values[] = { 0, 0 }; const struct snmp_obj_id_const_ref snmp_zero_dot_zero = { LWIP_ARRAYSIZE(snmp_zero_dot_zero_values), snmp_zero_dot_zero_values }; #if SNMP_LWIP_MIB2 #include "lwip/apps/snmp_mib2.h" static const struct snmp_mib* const default_mibs[] = { &mib2 }; static u8_t snmp_num_mibs = 1; #else static const struct snmp_mib* const default_mibs[] = { NULL }; static u8_t snmp_num_mibs = 0; #endif /* List of known mibs */ static struct snmp_mib const * const *snmp_mibs = default_mibs; /**
static int upap_printpkt(const u_char *p, int plen, void (*printer) (void *, const char *, ...), void *arg) { int code, id, len; int mlen, ulen, wlen; const u_char *user, *pwd, *msg; const u_char *pstart; if (plen < UPAP_HEADERLEN) return 0; pstart = p; GETCHAR(code, p); GETCHAR(id, p); GETSHORT(len, p); if (len < UPAP_HEADERLEN || len > plen) return 0; if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(upap_codenames)) printer(arg, " %s", upap_codenames[code-1]); else printer(arg, " code=0x%x", code); printer(arg, " id=0x%x", id); len -= UPAP_HEADERLEN; switch (code) { case UPAP_AUTHREQ: if (len < 1) break; ulen = p[0]; if (len < ulen + 2) break; wlen = p[ulen + 1]; if (len < ulen + wlen + 2) break; user = (const u_char *) (p + 1); pwd = (const u_char *) (p + ulen + 2); p += ulen + wlen + 2; len -= ulen + wlen + 2; printer(arg, " user="******" password="******"<hidden>"); #endif break; case UPAP_AUTHACK: case UPAP_AUTHNAK: if (len < 1) break; mlen = p[0]; if (len < mlen + 1) break; msg = (const u_char *) (p + 1); p += mlen + 1; len -= mlen + 1; printer(arg, " "); ppp_print_string(msg, mlen, printer, arg); break; default: break; } /* print the rest of the bytes in the packet */ for (; len > 0; --len) { GETCHAR(code, p); printer(arg, " %.2x", code); } return p - pstart; }