📄 mib2.c
字号:
{
snmpingetresponses++;
}
void snmp_inc_snmpintraps(void)
{
snmpintraps++;
}
void snmp_inc_snmpouttoobigs(void)
{
snmpouttoobigs++;
}
void snmp_inc_snmpoutnosuchnames(void)
{
snmpoutnosuchnames++;
}
void snmp_inc_snmpoutbadvalues(void)
{
snmpoutbadvalues++;
}
void snmp_inc_snmpoutgenerrs(void)
{
snmpoutgenerrs++;
}
void snmp_inc_snmpoutgetrequests(void)
{
snmpoutgetrequests++;
}
void snmp_inc_snmpoutgetnexts(void)
{
snmpoutgetnexts++;
}
void snmp_inc_snmpoutsetrequests(void)
{
snmpoutsetrequests++;
}
void snmp_inc_snmpoutgetresponses(void)
{
snmpoutgetresponses++;
}
void snmp_inc_snmpouttraps(void)
{
snmpouttraps++;
}
void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid)
{
*oid = &snmpgrp_id;
}
void snmp_set_snmpenableauthentraps(u8_t *value)
{
if (value != NULL)
{
snmpenableauthentraps_ptr = value;
}
}
void snmp_get_snmpenableauthentraps(u8_t *value)
{
*value = *snmpenableauthentraps_ptr;
}
void
noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
{
if (ident_len){}
if (ident){}
od->instance = MIB_OBJECT_NONE;
}
void
noleafs_get_value(struct obj_def *od, u16_t len, void *value)
{
if (od){}
if (len){}
if (value){}
}
u8_t
noleafs_set_test(struct obj_def *od, u16_t len, void *value)
{
if (od){}
if (len){}
if (value){}
/* can't set */
return 0;
}
void
noleafs_set_value(struct obj_def *od, u16_t len, void *value)
{
if (od){}
if (len){}
if (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 void
system_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;
id = 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 void
system_get_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
id = od->id_inst_ptr[0];
switch (id)
{
case 1: /* sysDescr */
ocstrncpy(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(value);
}
break;
case 4: /* sysContact */
ocstrncpy(value,syscontact_ptr,len);
break;
case 5: /* sysName */
ocstrncpy(value,sysname_ptr,len);
break;
case 6: /* sysLocation */
ocstrncpy(value,syslocation_ptr,len);
break;
case 7: /* sysServices */
{
s32_t *sint_ptr = value;
*sint_ptr = sysservices;
}
break;
};
}
static u8_t
system_set_test(struct obj_def *od, u16_t len, void *value)
{
u8_t id, set_ok;
if (value) {}
set_ok = 0;
id = 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 void
system_set_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
id = od->id_inst_ptr[0];
switch (id)
{
case 4: /* sysContact */
ocstrncpy(syscontact_ptr,value,len);
*syscontact_len_ptr = len;
break;
case 5: /* sysName */
ocstrncpy(sysname_ptr,value,len);
*sysname_len_ptr = len;
break;
case 6: /* sysLocation */
ocstrncpy(syslocation_ptr,value,len);
*syslocation_len_ptr = 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 void
interfaces_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 void
interfaces_get_value(struct obj_def *od, u16_t len, void *value)
{
if (len){}
if (od->id_inst_ptr[0] == 1)
{
s32_t *sint_ptr = 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 void
ifentry_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;
id = 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 void
ifentry_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);
id = od->id_inst_ptr[0];
switch (id)
{
case 1: /* ifIndex */
{
s32_t *sint_ptr = value;
*sint_ptr = od->id_inst_ptr[1];
}
break;
case 2: /* ifDescr */
ocstrncpy(value,(u8_t*)netif->name,len);
break;
case 3: /* ifType */
{
s32_t *sint_ptr = value;
*sint_ptr = netif->link_type;
}
break;
case 4: /* ifMtu */
{
s32_t *sint_ptr = value;
*sint_ptr = netif->mtu;
}
break;
case 5: /* ifSpeed */
{
u32_t *uint_ptr = value;
*uint_ptr = netif->link_speed;
}
break;
case 6: /* ifPhysAddress */
ocstrncpy(value,netif->hwaddr,len);
break;
case 7: /* ifAdminStatus */
#if LWIP_NETIF_LINK_CALLBACK
{
s32_t *sint_ptr = value;
if (netif_is_up(netif))
{
if (netif_i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -