Author Topic: SNMP  (Read 13560 times)

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
SNMP
« on: September 26, 2007, 10:01:59 PM »
Hi , anyone add SNMP traps or agents to the uTasker ? Will this
be available some time  in the future ?

 John

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SNMP
« Reply #1 on: September 26, 2007, 11:18:17 PM »
Hi John

You will find the file snmp.c in the stack directory.
You can add #define USE_SNMP in the UDP section of config.h
Then search application.c for USE_SNMP and you will find some settings:
    static const unsigned char ucIP_SNMP_manager[IPV4_LENGTH] = {192, 168, 0, 1}; // SNMP manager address
    static const CHAR cSNMP_community[] = "public";
    static const CHAR cSNMP_enterprise[] = {0x2b, 6, 1,4,1,4,1,2,15};


On power up a COLD START trap will be sent to the snmp manager:
        fnStartSNMP(fnSNMP_callback, (unsigned char *)ucIP_SNMP_manager);
        fnSendSNMPTrap(SNMP_COLDSTART, 0);                               // send cold start trap to SNMP manager


Any queries from the SNMP manager will be handled by the SNMP listener. See the call back function:
static int fnSNMP_callback(unsigned char ucEvent, unsigned char *data, unsigned short usLength)
in application.c where some user data is added to responses.

This is however test code. It does work correctly (the framework is basically complete and good but tables need to be added) but only supports a couple of test queries and traps.
To complete SNMPV1 the individual cases have to be added (quite a lot of stuff if it needs to be complete). Enterprise things are more application specific special responses which will probably be handled in the listener call back.

The reason that this was added is so that anyone with interest can take a look at it and even add a couple of things if only quick and limited support is needed. If you have need for a few queries it should be quite easy to get these integrated so that it can already be used. Traps should already be possible with the function
extern void fnSendSNMPTrap(unsigned char ucTrap, unsigned char ucSpecificCode);

I do know of someone who has used the uTasker and integrated SNMPV1 and SNMPV2 (I don't know to what extent) for his project. If you have an urgent requirement I could put you in touch.

Regards

Mark


Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: SNMP
« Reply #2 on: September 27, 2007, 04:41:55 PM »
Thanks Mark, the files were in the stack sub, but had to be manually added to the CW project. I also had to add type casts in snmp.c on lines 291 and 293 to get it to compile with CW 6.3. I was able to send the cold trap out. I also added the pop3 to CW and it compiled ok. The code size is still under 85K !


 John
 

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SNMP
« Reply #3 on: September 27, 2007, 05:05:47 PM »
Hi John

Generally the project configuration is not updated with new files in the service pack so new files may have to be added to the project if used (this should be detailed in the SP release notes).

I checked the 2 lines you quoted
        usContentLength = 2;
and
        *ucData++ = 0x82;
but didn't have any problem with CW6.3.

Any ideas why you had to cast them?

Regards

Mark

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: SNMP
« Reply #4 on: September 27, 2007, 06:19:18 PM »
Mark, here's the code . It was lines 591 and 593 at the bottom, I have bad eyes

John


// The SNMP Agent listener function
//
static int fnSNMPListner(USOCKET SNMP_socket, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPort, unsigned char *ucData, unsigned short usDataLen)
{
    if (ucEvent == UDP_EVENT_RXDATA) {
        CHAR *cCommunity;
        unsigned char *frame_data = ucData;
        unsigned short usCommunityLength;
        unsigned short usStructureLength;

        if (*ucData++ != ASN1_SEQUENCE) {
            return 0;                                                    // not ANS.1 BER conform - silently ignore
        }
        ucData = fnGetASN1_length(ucData, &usStructureLength);
        if ((!usStructureLength) || (uMemcmp(ucData, ucSNMPV1, sizeof(ucSNMPV1)))) { // check the SNMP version number
            return 0;                                                    // silently discard since we only support V1
        }
        ucData += sizeof(ucSNMPV1);
        if (*ucData++ != ASN1_OCTET_STRING) {                            // community string is expected
            return 0;                                                    // silently ignore if string type not found
        }
        ucData = fnGetASN1_length(ucData, &usCommunityLength);
 ****       cCommunity = (CHAR*)ucData;
        ucData += usCommunityLength;
 ****       if (fnClientListener(SNMP_COMMUNITY_CHECK, (unsigned char*)cCommunity, usCommunityLength) != 0) { // check community

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SNMP
« Reply #5 on: September 27, 2007, 06:53:58 PM »
Hi John

Strange (again) I don't get a warning on this, but the castings are correct, so I have added them in my master version.

Thanks.

Regards

Mark

Offline eduardovra

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SNMP
« Reply #6 on: December 24, 2007, 04:41:46 PM »
Hi
I couldn't find the snmp.c file in my stack folder in the uTasker project.
I'm using uTasker v1.3. Is SNMP supported by this version ?

Regards

Eduardo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SNMP
« Reply #7 on: December 24, 2007, 04:56:21 PM »
Hi Eduardo

There is a development snap-shot in the SP5 for the M5223X.
http://www.utasker.com/software/softwareV1.3.html

Regards

Mark