I used the SNMP trap code in MQX34 and MQX37 to send some V1/V2 traps and found the following problems :in rtcs/source/snmp/traps.c :
- code is too big because it is made of several functions that where copied and modified from other functions; a more generic and unique function can be used instead (except maybe for linkup/linkdown that contain some additonal code)
- user specific trap V2 messages seem to have some wrong data : message type not recognized by SNMPB tool (SNMP Browser, a nice software for everyone working with SNMP)
- some inconsistencies between signed / unsignes types and ASN1 macros used
- ASN1_BKWRITE..... macros are made of several lines of code, and I'm not sure that the compiler can optimize the code size if these macros are used many times in the code. The code is duplicated leading to excessive code size (text section). It would probably be better to define these macros as functions.
To fix these problems, except the ASN1_BKWRITE... size (that is easy to fix if needed), I wrote.a new code as replacement for traps.c. You can put this code in your application or move it to the BSP tree (as you want).
Instead of calling functions in traps.c, you call SNMP_trap_send() instead.
This function :
- is a low level one so your can specify the target IP directly (needed to implement V2 inform traps)
- you can specify the request-id (usefull for resending message)
- you can override timestamp
- you can add as many additional bindings (data) you need
- you can send INFORMV2 traps in addition to TRAPV1 and TRAPV2
Within this code I added a demo function SNMP_send_trap_demo() to send several kind of traps for testing.
Please find the code attached below
NOTE : for debug, the traps can be displayed by running the SNMPB software on a system without the need to configure it to receive traps : just run SNMPB