snmp_example.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Redistribution and use in source and binary forms, with or without modification,
  3. * are permitted provided that the following conditions are met:
  4. *
  5. * 1. Redistributions of source code must retain the above copyright notice,
  6. * this list of conditions and the following disclaimer.
  7. * 2. Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation
  9. * and/or other materials provided with the distribution.
  10. * 3. The name of the author may not be used to endorse or promote products
  11. * derived from this software without specific prior written permission.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  16. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  18. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  19. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  20. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  21. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  22. * OF SUCH DAMAGE.
  23. *
  24. * This file is part of the lwIP TCP/IP stack.
  25. *
  26. * Author: Dirk Ziegelmeier <dziegel@gmx.de>
  27. *
  28. */
  29. #include "lwip/netif.h"
  30. #include "lwip/apps/snmp.h"
  31. #include "lwip/apps/snmp_mib2.h"
  32. #include "lwip/apps/snmpv3.h"
  33. #include "lwip/apps/snmp_snmpv2_framework.h"
  34. #include "lwip/apps/snmp_snmpv2_usm.h"
  35. #include "examples/snmp/snmp_v3/snmpv3_dummy.h"
  36. #include "examples/snmp/snmp_private_mib/private_mib.h"
  37. #include "snmp_example.h"
  38. #if LWIP_SNMP
  39. static const struct snmp_mib *mibs[] = {
  40. &mib2,
  41. &mib_private
  42. #if LWIP_SNMP_V3
  43. , &snmpframeworkmib
  44. , &snmpusmmib
  45. #endif
  46. };
  47. #endif /* LWIP_SNMP */
  48. void
  49. snmp_example_init(void)
  50. {
  51. #if LWIP_SNMP
  52. s32_t req_nr;
  53. lwip_privmib_init();
  54. #if SNMP_LWIP_MIB2
  55. #if SNMP_USE_NETCONN
  56. snmp_threadsync_init(&snmp_mib2_lwip_locks, snmp_mib2_lwip_synchronizer);
  57. #endif /* SNMP_USE_NETCONN */
  58. snmp_mib2_set_syscontact_readonly((const u8_t*)"root", NULL);
  59. snmp_mib2_set_syslocation_readonly((const u8_t*)"lwIP development PC", NULL);
  60. snmp_mib2_set_sysdescr((const u8_t*)"lwIP example", NULL);
  61. #endif /* SNMP_LWIP_MIB2 */
  62. #if LWIP_SNMP_V3
  63. snmpv3_dummy_init();
  64. #endif
  65. snmp_set_mibs(mibs, LWIP_ARRAYSIZE(mibs));
  66. snmp_init();
  67. snmp_trap_dst_ip_set(0, &netif_default->gw);
  68. snmp_trap_dst_enable(0, 1);
  69. snmp_send_inform_generic(SNMP_GENTRAP_COLDSTART, NULL, &req_nr);
  70. snmp_send_trap_generic(SNMP_GENTRAP_COLDSTART);
  71. #endif /* LWIP_SNMP */
  72. }