📄 mib2.c
字号:
LWIP_UNUSED_ARG(value);}/** * Returns systems object definitions. * * @param ident_len the address length (2) * @param ident points to objectname.0 (object id trailer) * @param od points to object definition. */static voidsystem_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od){ u8_t id; /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id)); switch (id) { case 1: /* sysDescr */ od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); od->v_len = *sysdescr_len_ptr; break; case 2: /* sysObjectID */ od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); od->v_len = sysobjid.len * sizeof(s32_t); break; case 3: /* sysUpTime */ od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); od->v_len = sizeof(u32_t); break; case 4: /* sysContact */ od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_WRITE; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); od->v_len = *syscontact_len_ptr; break; case 5: /* sysName */ od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_WRITE; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); od->v_len = *sysname_len_ptr; break; case 6: /* sysLocation */ od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_WRITE; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); od->v_len = *syslocation_len_ptr; break; case 7: /* sysServices */ od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); od->v_len = sizeof(s32_t); break; default: LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n")); od->instance = MIB_OBJECT_NONE; break; }; } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; }}/** * Returns system object value. * * @param ident_len the address length (2) * @param ident points to objectname.0 (object id trailer) * @param len return value space (in bytes) * @param value points to (varbind) space to copy value into. */static voidsystem_get_value(struct obj_def *od, u16_t len, void *value){ u8_t id; LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; switch (id) { case 1: /* sysDescr */ ocstrncpy((u8_t*)value, sysdescr_ptr, len); break; case 2: /* sysObjectID */ objectidncpy((s32_t*)value, (s32_t*)sysobjid.id, (u8_t)(len / sizeof(s32_t))); break; case 3: /* sysUpTime */ { snmp_get_sysuptime((u32_t*)value); } break; case 4: /* sysContact */ ocstrncpy((u8_t*)value, syscontact_ptr, len); break; case 5: /* sysName */ ocstrncpy((u8_t*)value, sysname_ptr, len); break; case 6: /* sysLocation */ ocstrncpy((u8_t*)value, syslocation_ptr, len); break; case 7: /* sysServices */ { s32_t *sint_ptr = (s32_t*)value; *sint_ptr = sysservices; } break; };}static u8_tsystem_set_test(struct obj_def *od, u16_t len, void *value){ u8_t id, set_ok; LWIP_UNUSED_ARG(value); set_ok = 0; LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; switch (id) { case 4: /* sysContact */ if ((syscontact_ptr != syscontact_default) && (len <= 255)) { set_ok = 1; } break; case 5: /* sysName */ if ((sysname_ptr != sysname_default) && (len <= 255)) { set_ok = 1; } break; case 6: /* sysLocation */ if ((syslocation_ptr != syslocation_default) && (len <= 255)) { set_ok = 1; } break; }; return set_ok;}static voidsystem_set_value(struct obj_def *od, u16_t len, void *value){ u8_t id; LWIP_ASSERT("invalid len", len <= 0xff); LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; switch (id) { case 4: /* sysContact */ ocstrncpy(syscontact_ptr, (u8_t*)value, len); *syscontact_len_ptr = (u8_t)len; break; case 5: /* sysName */ ocstrncpy(sysname_ptr, (u8_t*)value, len); *sysname_len_ptr = (u8_t)len; break; case 6: /* sysLocation */ ocstrncpy(syslocation_ptr, (u8_t*)value, len); *syslocation_len_ptr = (u8_t)len; break; };}/** * Returns interfaces.ifnumber object definition. * * @param ident_len the address length (2) * @param ident points to objectname.index * @param od points to object definition. */static voidinterfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od){ /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); od->v_len = sizeof(s32_t); } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; }}/** * Returns interfaces.ifnumber object value. * * @param ident_len the address length (2) * @param ident points to objectname.0 (object id trailer) * @param len return value space (in bytes) * @param value points to (varbind) space to copy value into. */static voidinterfaces_get_value(struct obj_def *od, u16_t len, void *value){ LWIP_UNUSED_ARG(len); if (od->id_inst_ptr[0] == 1) { s32_t *sint_ptr = (s32_t*)value; *sint_ptr = iflist_root.count; }}/** * Returns ifentry object definitions. * * @param ident_len the address length (2) * @param ident points to objectname.index * @param od points to object definition. */static voidifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od){ u8_t id; /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id)); switch (id) { case 1: /* ifIndex */ case 3: /* ifType */ case 4: /* ifMtu */ case 8: /* ifOperStatus */ od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); od->v_len = sizeof(s32_t); break; case 2: /* ifDescr */ od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); /** @todo this should be some sort of sizeof(struct netif.name) */ od->v_len = 2; break; case 5: /* ifSpeed */ case 21: /* ifOutQLen */ od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE); od->v_len = sizeof(u32_t); break; case 6: /* ifPhysAddress */ { struct netif *netif; snmp_ifindextonetif(ident[1], &netif); od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); od->v_len = netif->hwaddr_len; } break; case 7: /* ifAdminStatus */ od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_WRITE; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); od->v_len = sizeof(s32_t); break; case 9: /* ifLastChange */ od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); od->v_len = sizeof(u32_t); break; case 10: /* ifInOctets */ case 11: /* ifInUcastPkts */ case 12: /* ifInNUcastPkts */ case 13: /* ifInDiscarts */ case 14: /* ifInErrors */ case 15: /* ifInUnkownProtos */ case 16: /* ifOutOctets */ case 17: /* ifOutUcastPkts */ case 18: /* ifOutNUcastPkts */ case 19: /* ifOutDiscarts */ case 20: /* ifOutErrors */ od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); od->v_len = sizeof(u32_t); break; case 22: /* ifSpecific */ /** @note returning zeroDotZero (0.0) no media specific MIB support */ od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); od->v_len = ifspecific.len * sizeof(s32_t); break; default: LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n")); od->instance = MIB_OBJECT_NONE; break; }; } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; }}/** * Returns ifentry object value. * * @param ident_len the address length (2) * @param ident points to objectname.0 (object id trailer) * @param len return value space (in bytes) * @param value points to (varbind) space to copy value into. */static voidifentry_get_value(struct obj_def *od, u16_t len, void *value){ struct netif *netif; u8_t id; snmp_ifindextonetif(od->id_inst_ptr[1], &netif); LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; switch (id) { case 1: /* ifIndex */ { s32_t *sint_ptr = (s32_t*)value; *sint_ptr = od->id_inst_ptr[1]; } break; case 2: /* ifDescr */ ocstrncpy((u8_t*)value, (u8_t*)netif->name, len); break; case 3: /* ifType */ { s32_t *sint_ptr = (s32_t*)value; *sint_ptr = netif->link_type; } break; case 4: /* ifMtu */ { s32_t *sint_ptr = (s32_t*)value; *sint_ptr = netif->mtu; } break; case 5: /* ifSpeed */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->link_speed; } break; case 6: /* ifPhysAddress */ ocstrncpy((u8_t*)value, netif->hwaddr, len); break; case 7: /* ifAdminStatus */ { s32_t *sint_ptr = (s32_t*)value; if (netif_is_up(netif)) { if (netif_is_link_up(netif)) { *sint_ptr = 1; /* up */ } else { *sint_ptr = 7; /* lowerLayerDown */ } } else { *sint_ptr = 2; /* down */ } } break; case 8: /* ifOperStatus */ { s32_t *sint_ptr = (s32_t*)value; if (netif_is_up(netif)) { *sint_ptr = 1; } else { *sint_ptr = 2; } } break; case 9: /* ifLastChange */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ts; } break; case 10: /* ifInOctets */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifinoctets; } break; case 11: /* ifInUcastPkts */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifinucastpkts; } break; case 12: /* ifInNUcastPkts */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifinnucastpkts; } break; case 13: /* ifInDiscarts */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifindiscards; } break; case 14: /* ifInErrors */ case 15: /* ifInUnkownProtos */ /** @todo add these counters! */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = 0; } break; case 16: /* ifOutOctets */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifoutoctets; } break; case 17: /* ifOutUcastPkts */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifoutucastpkts; } break; case 18: /* ifOutNUcastPkts */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifoutnucastpkts; } break; case 19: /* ifOutDiscarts */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = netif->ifoutdiscards; } break; case 20: /* ifOutErrors */ /** @todo add this counter! */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = 0; } break; case 21: /* ifOutQLen */ /** @todo figure out if this must be 0 (no queue) or 1? */ { u32_t *uint_ptr = (u32_t*)value; *uint_ptr = 0; } break; case 22: /* ifSpecific */ objectidncpy((s32_t*)value, (s32_t*)ifspecific.id, (u8_t)(len / sizeof(s32_t))); break; };}#if !SNMP_SAFE_REQUESTSstatic u8_tifentry_set_test(struct obj_def *od, u16_t len, void *value){ struct netif *netif; u8_t id, set_ok; LWIP_UNUSED_ARG(len); set_ok = 0; snmp_ifindextonetif(od->id_inst_ptr[1], &netif); id = (u8_t)od->id_inst_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -