This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Keil TCPnet stack-SNMP

Hi,

I am using the SNMP demo code for SNMP agent but i cant send trap message from agent, I configured everything that specified in help document of keil. see the code where i am sending trap message.

int main (void)
{ /* Main Thread of the TcpNet */

init (); init_display (); init_TcpNet ();

dhcp_tout = DHCP_TOUT; LED_out (0x55);

while (1) { timer_poll (); main_TcpNet (); dhcp_check (); if (LCDupdate == __TRUE) { upd_display (); snmp_trap (NULL, 6, 1, obj); } }
}

what is wrong in that code? any thing else i need to enable?

-pratheep.k

  • I'm not using the Keil stack so I don't know much about it (except the issues with source code).

    But how to you specify where that trap should be sent?

  • Hi;

    whenever my system boot up i have to send a TRAP.

    -Pratheep

  • Exactly how would that be an answer to my question "But how do you specify where that trap should be sent?"

  • whenever i get information from GPS i'll send a trap. the trap sending function will be called from conditional loop in the while(1).

    Even me also don't know clearly about that but i'll call snmp_trap() function as per keil's user guide, wherever i need to send a Trap.

  • Yes, yes, yes. But that is not what I'm asking about.

    How do you specify WHICH IP NUMBER TO SEND THE TRAP TO?

  • Trap Server specifies the IP address of the Trap Server which receives Trap messages. This IP address is used when the Trap Server IP is not specified in snmp_trap() function parameter.
    #define SNMP_TRAPIP1 192
    #define SNMP_TRAPIP2 168
    #define SNMP_TRAPIP3 0
    #define SNMP_TRAPIP4 1

    Summary #include <net_config.h>

    BOOL snmp_trap ( U8* man_ip, /* Pointer to the IP address of Trap Manager. */ U8 gen_trap, /* Generic Trap value. */ U8 spec_trap, /* Specific Trap value. */ U16* obj_list ); /* Pointer to the list of objects. */

    Description The snmp_trap function sends a trap message to the Trap Manager. Parameter man_ip specifies the IP address of the Trap server, where the trap message is destined to. If the IP address of the Trap Manager is not specified (parameter man_ip is NULL), the IP address of Trap Server configured in Net_Config.c is used instead.

    Parameter gen_trap specifies the generic trap type:

    Type Description
    0 coldStart trap
    1 warmStart trap
    2 linkDown trap
    3 linkUp trap
    4 authenticationFailure trap
    5 egpNeighborLoss trap
    6 enterpriseSpecific trap

    Parameter spec_trap specifies the specific trap type. It must be set to 0 for all generic traps from 0 to 5. It defines a specific trap type for generic enterpriseSpecific trap.

    Parameter obj_list specifies the objects from the MIB table, which will be included in the trap message variable-bindings. This parameter is a pointer to the object list array. This array is of variable size. The first element specifies the count of objects in the object list array, followed by the object MIB index values.

    Array Index Array Value
    obj[0] number of objects n
    obj[1] MIB index of first object
    obj[2] MIB index of second object
    .. ..
    obj[n] MIB index of last object

    If obj_list parameter is NULL, or obj[0] = 0, no object values will be binded to the trap message.

    The snmp_trap function is a system function that is in the RL-TCPnet library. The prototype is defined in net_config.h.

    Note:

    The maximum number of objects that can be binded to the trap message is limited to 20 objects.

    Return Value The snmp_trap function returns __TRUE when the SNMP trap message has been sent successfully. On error, this function returns __FALSE.

    Example: void send_alarm (void) { /* Send a trap message when alarm input is activated.*/ U16 obj[2];

    /* Add "KeyIn" value to trap message. */ obj[0] = 1; obj[1] = 8; /* Index of "KeyIn" entry in MIB table. */ snmp_trap (NULL, 6, 1, obj);
    }

    these are mentioned in keils user document.

  • Never underestimate the value of links - no need to duplicate the Keil text when the manual is available online.

    Interesting that Keil are using so strange terms for describing the obj_list. They call every index position an object. But the code seems to indicate that the array is storing the "path" numbers for forming a single OID while the manual text talks about the ability to send up to 20 objects.

    If the second is true, then obj_list should be index values to point at up to 20 OID stored somewhere else - each OID a sequence of one or more numbers.

    By the way - have you verified if a trap is sent or not? And are you using the correct community? And do your snmp trap listener accepting the used protocol version? You say you can't send traps, but you aren't even checking the return code from the call.