⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mib2.c

📁 《嵌入式网络系统设计-基于Atmel ARM7 系列》这个本书的光盘资料
💻 C
📖 第 1 页 / 共 5 页
字号:
/** * 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;    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 voidsystem_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,len / sizeof(s32_t));      break;    case 3: /* sysUpTime */      {        u32_t *uint_ptr = value;        *uint_ptr = sysuptime;      }      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_tsystem_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 voidsystem_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 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){  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 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;    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 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);  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 */    case 8: /* ifOperStatus */      {        s32_t *sint_ptr = value;        if (netif_is_up(netif))        {          *sint_ptr = 1;        }        else        {          *sint_ptr = 2;        }      }      break;    case 9: /* ifLastChange */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ts;      }      break;    case 10: /* ifInOctets */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifinoctets;      }      break;    case 11: /* ifInUcastPkts */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifinucastpkts;      }      break;    case 12: /* ifInNUcastPkts */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifinnucastpkts;      }      break;    case 13: /* ifInDiscarts */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifindiscards;      }      break;    case 14: /* ifInErrors */    case 15: /* ifInUnkownProtos */      /** @todo add these counters! */      {        u32_t *uint_ptr = value;        *uint_ptr = 0;      }      break;    case 16: /* ifOutOctets */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifoutoctets;      }      break;    case 17: /* ifOutUcastPkts */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifoutucastpkts;      }      break;    case 18: /* ifOutNUcastPkts */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifoutnucastpkts;      }      break;    case 19: /* ifOutDiscarts */      {        u32_t *uint_ptr = value;        *uint_ptr = netif->ifoutdiscards;      }      break;    case 20: /* ifOutErrors */       /** @todo add this counter! */      {        u32_t *uint_ptr = value;        *uint_ptr = 0;      }      break;    case 21: /* ifOutQLen */      /** @todo figure out if this must be 0 (no queue) or 1? */      {        u32_t *uint_ptr = value;        *uint_ptr = 0;      }      break;    case 22: /* ifSpecific */      objectidncpy((s32_t*)value,(s32_t*)ifspecific.id,len / sizeof(s32_t));      break;  };}/** * Returns atentry object definitions. * * @param ident_len the address length (6) * @param ident points to objectname.atifindex.atnetaddress * @param od points to object definition. */static voidatentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od){  /* return to object name, adding index depth (5) */  ident_len += 5;  ident -= 5;  if (ident_len == 6)  {    od->id_inst_len = ident_len;    od->id_inst_ptr = ident;    switch (ident[0])    {      case 1: /* atIfIndex */        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 2: /* atPhysAddress */        od->instance = MIB_OBJECT_TAB;        od->access = MIB_OBJECT_READ_WRITE;        od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);        od->v_len = sizeof(struct eth_addr);        break;      case 3: /* atNetAddress */        od->instance = MIB_OBJECT_TAB;        od->access = MIB_OBJECT_READ_WRITE;        od->as

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -