snmp_custom.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /********************************************************************************************
  2. * SNMP : User Customization Part
  3. * - OID Registration
  4. * - User defined functions for OID related
  5. * + Integer value, String
  6. * + I/O control / Chip registers
  7. * + Network Informations
  8. * + Etc.
  9. *
  10. *********************************************************************************************/
  11. #include "snmp_custom.h"
  12. #ifdef _USE_WIZNET_W5500_EVB_
  13. #include "board.h"
  14. #endif
  15. dataEntryType snmpData[] =
  16. {
  17. // System MIB
  18. // SysDescr Entry
  19. {8, {0x2b, 6, 1, 2, 1, 1, 1, 0},
  20. SNMPDTYPE_OCTET_STRING, 30, {"WIZnet Embedded SNMP Agent"},
  21. NULL, NULL},
  22. // SysObjectID Entry
  23. {8, {0x2b, 6, 1, 2, 1, 1, 2, 0},
  24. SNMPDTYPE_OBJ_ID, 8, {"\x2b\x06\x01\x02\x01\x01\x02\x00"},
  25. NULL, NULL},
  26. // SysUptime Entry
  27. {8, {0x2b, 6, 1, 2, 1, 1, 3, 0},
  28. SNMPDTYPE_TIME_TICKS, 0, {""},
  29. currentUptime, NULL},
  30. // sysContact Entry
  31. {8, {0x2b, 6, 1, 2, 1, 1, 4, 0},
  32. SNMPDTYPE_OCTET_STRING, 30, {"http://www.wizwiki.net/forum"},
  33. NULL, NULL},
  34. // sysName Entry
  35. {8, {0x2b, 6, 1, 2, 1, 1, 5, 0},
  36. SNMPDTYPE_OCTET_STRING, 30, {"http://www.wiznet.co.kr"},
  37. NULL, NULL},
  38. // Location Entry
  39. {8, {0x2b, 6, 1, 2, 1, 1, 6, 0},
  40. SNMPDTYPE_OCTET_STRING, 30, {"4F Humax Village"},
  41. NULL, NULL},
  42. // SysServices
  43. {8, {0x2b, 6, 1, 2, 1, 1, 7, 0},
  44. SNMPDTYPE_INTEGER, 4, {""},
  45. NULL, NULL},
  46. #ifdef _USE_WIZNET_W5500_EVB_
  47. // Get the WIZnet W5500-EVB LED Status
  48. {8, {0x2b, 6, 1, 4, 1, 6, 1, 0},
  49. SNMPDTYPE_OCTET_STRING, 40, {""},
  50. get_LEDStatus_all, NULL},
  51. // Set the LED_R (RGB LED)
  52. {8, {0x2b, 6, 1, 4, 1, 6, 1, 1},
  53. SNMPDTYPE_INTEGER, 4, {""},
  54. NULL, set_LEDStatus_R},
  55. // Set the LED_G (RGB LED)
  56. {8, {0x2b, 6, 1, 4, 1, 6, 1, 2},
  57. SNMPDTYPE_INTEGER, 4, {""},
  58. NULL, set_LEDStatus_G},
  59. // Set the LED_B (RGB LED)
  60. {8, {0x2b, 6, 1, 4, 1, 6, 1, 3},
  61. SNMPDTYPE_INTEGER, 4, {""},
  62. NULL, set_LEDStatus_B},
  63. #endif
  64. // OID Test #1 (long-length OID example, 19865)
  65. {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00},
  66. SNMPDTYPE_OCTET_STRING, 30, {"long-length OID Test #1"},
  67. NULL, NULL},
  68. // OID Test #2 (long-length OID example, 22210)
  69. {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0xad, 0x42, 0x01, 0x00},
  70. SNMPDTYPE_OCTET_STRING, 35, {"long-length OID Test #2"},
  71. NULL, NULL},
  72. // OID Test #2: SysObjectID Entry
  73. {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0xad, 0x42, 0x02, 0x00},
  74. SNMPDTYPE_OBJ_ID, 0x0a, {"\x2b\x06\x01\x04\x01\x81\xad\x42\x02\x00"},
  75. NULL, NULL},
  76. };
  77. const int32_t maxData = (sizeof(snmpData) / sizeof(dataEntryType));
  78. void initTable()
  79. {
  80. // Example integer value for [OID 1.3.6.1.2.1.1.7.0]
  81. snmpData[6].u.intval = -5;
  82. }
  83. // W5500-EVB: LED Control ///////////////////////////////////////////////////////////////////////////
  84. #ifdef _USE_WIZNET_W5500_EVB_
  85. void get_LEDStatus_all(void *ptr, uint8_t *len)
  86. {
  87. uint8_t led_status[3] = {0, };
  88. led_status[LED_R] = (uint8_t)Board_LED_Test(LED_R);
  89. led_status[LED_G] = (uint8_t)Board_LED_Test(LED_G);
  90. led_status[LED_B] = (uint8_t)Board_LED_Test(LED_B);
  91. *len = sprintf((char *)ptr, "LED R [%s] / G [%s] / B [%s]", led_status[LED_R]?"On":"Off", led_status[LED_G]?"On":"Off", led_status[LED_B]?"On":"Off");
  92. }
  93. void set_LEDStatus_R(int32_t val)
  94. {
  95. if(val == 0) Board_LED_Set(LED_R, false);
  96. else Board_LED_Set(LED_R, true);
  97. }
  98. void set_LEDStatus_G(int32_t val)
  99. {
  100. if(val == 0) Board_LED_Set(LED_G, false);
  101. else Board_LED_Set(LED_G, true);
  102. }
  103. void set_LEDStatus_B(int32_t val)
  104. {
  105. if(val == 0) Board_LED_Set(LED_B, false);
  106. else Board_LED_Set(LED_B, true);
  107. }
  108. #endif
  109. /////////////////////////////////////////////////////////////////////////////////////////////////////
  110. void initial_Trap(uint8_t * managerIP, uint8_t * agentIP)
  111. {
  112. // SNMP Trap: WarmStart(1) Trap
  113. {
  114. dataEntryType enterprise_oid = {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00},
  115. SNMPDTYPE_OBJ_ID, 0x0a, {"\x2b\x06\x01\x04\x01\x81\x9b\x19\x10\x00"}, NULL, NULL};
  116. // Generic Trap: warmStart COMMUNITY
  117. snmp_sendTrap(managerIP, agentIP, (void *)COMMUNITY, enterprise_oid, SNMPTRAP_WARMSTART, 0, 0);
  118. }
  119. }