Hot!Microchip SNMP TCP stack woes

Author
Dag
Starting Member
  • Total Posts : 50
  • Reward points : 0
  • Joined: 2014/10/31 11:53:36
  • Location: 0
  • Status: offline
2017/12/15 14:31:29 (permalink)
0

Microchip SNMP TCP stack woes

And so starting a project to implement SNMP embedded controller for a cage with a number of modules, had a PIC18F67j60 EV board laying around so I figured that it would be a good start. So I read AN870 and compiled the TCP demo project with the 5.42 stack and used iReasoning freeware to probe the SNMP structure. Looking good I thought as it worked nicely.
 
Another step into the job was to figure out how to build the files for the project, starting with the mib2bib.exe utility only where is the snmp.mib (Microchip syntax) that needs to be used? not in the project directory! So recalling that AN870 has a sample MIB - try that - No go: it is much shorter that the correct MIB file judging by the original mib.h that is present in the project directory.
 
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
 *
 *******************************************************************/
#define MICROCHIP 255 // This is an Agent ID for use in SNMPNotify() only.
#define SYS_UP_TIME 250 //43.6.1.2.1.1.3 : READONLY TIME_TICKS.
#define SNMP_DEMO_TRAP [<font]500 //43.6.1.4.1.17095.1.0.1 : READONLY BYTE.
#define TRAP_RECEIVER_ID 1 //43.6.1.4.1.17095.1.2.1.1.1 : READWRITE BYTE.
#define TRAP_RECEIVER_ENABLED 2 //43.6.1.4.1.17095.1.2.1.1.2 : READWRITE BYTE.
#define TRAP_RECEIVER_IP 3 //43.6.1.4.1.17095.1.2.1.1.3 : READWRITE IP_ADDRESS.
#define TRAP_COMMUNITY 4 //43.6.1.4.1.17095.1.2.1.1.4 : READWRITE ASCII_STRING.
#define LED_D5 5 //43.6.1.4.1.17095.1.3.1 : READWRITE BYTE.
#define LED_D6 6 //43.6.1.4.1.17095.1.3.2 : READWRITE BYTE. OID=".1.3.6.1.4.1.17095.1.3.2"
#define PUSH_BUTTON 7 //43.6.1.4.1.17095.1.3.3 : READONLY BYTE.
#define ANALOG_POT0 8 //43.6.1.4.1.17095.1.3.4 : READONLY WORD.
#define LCD_DISPLAY 10 //43.6.1.4.1.17095.1.3.6 : READWRITE ASCII_STRING.
#define USM_INDEX_ID 11 //43.6.1.4.1.17095.1.4.1.1.1 : READONLY BYTE.
#define USER_SECURITY_NAME 12 //43.6.1.4.1.17095.1.4.1.1.2 : READWRITE ASCII_STRING.
#define USM_AUTH_PROT 13 //43.6.1.4.1.17095.1.4.1.1.3 : READWRITE BYTE.
#define USM_AUTH_KEY 14 //43.6.1.4.1.17095.1.4.1.1.4 : READWRITE ASCII_STRING.
#define USM_PRIV_PROT 15 //43.6.1.4.1.17095.1.4.1.1.5 : READWRITE BYTE.
#define USM_PRIV_KEY 16 //43.6.1.4.1.17095.1.4.1.1.6 : READWRITE ASCII_STRING.
#define SNMP_TARGET_INDEX_ID 17 //43.6.1.4.1.17095.1.5.1.1.1 : READONLY BYTE.
#define SNMP_TARGET_MP_MODEL 18 //43.6.1.4.1.17095.1.5.1.1.2 : READWRITE BYTE.
#define SNMP_TARGET_SECURITY_MODEL 19 //43.6.1.4.1.17095.1.5.1.1.3 : READWRITE BYTE.
#define SNMP_TARGET_SECURITY_NAME 20 //43.6.1.4.1.17095.1.5.1.1.4 : READWRITE ASCII_STRING.
#define SNMP_TARGET_SECURITY_LEVEL 21 //43.6.1.4.1.17095.1.5.1.1.5 : READWRITE BYTE.
#define ENGINE_ID 249 //43.6.1.6.3.10.2.1.1 : READONLY ASCII_STRING.
#define ENGINE_BOOT 248 //43.6.1.6.3.10.2.1.2 : READONLY DWORD.
#define ENGINE_TIME 247 //43.6.1.6.3.10.2.1.3 : READONLY DWORD.
#define ENGINE_MAX_MSG 246 //43.6.1.6.3.10.2.1.4 : READONLY WORD.
 
Searched the web for the file and find very little of use. Finally a pdf version of what seems to be the full version of the demo MIB was located.
 
 
 
 
If anyone has the correct snmp.mib file that makes the Demo work please feel free to share. There must be some differences that make the MIB tree function properly in the original demo files. Any other clues and tips about the Microchip MIB tree definition would also be welcome.
post edited by Dag - 2017/12/15 14:37:16
#1

2 Replies Related Threads

    Dag
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2014/10/31 11:53:36
    • Location: 0
    • Status: offline
    Re: Microchip SNMP tsp stack woes 2017/12/15 14:36:05 (permalink)
    0
    For any who are interested here is the long version of the SNMP.MIB that was found.
     
    * This is a MIB description for Microchip TCP/IP Stack.
    * Anyline starting without '$' is a comment.
    * Line starting with $ is a command and first word after $ must be
    * a valid command string.
    *
    * Use mib2bib to compile this file and generate binary BIB file.
    *
    * v1.0 supports following commands
    * $DeclareVar(<oidName>, <dataType>, <oidType>, <access>, <oidString>)
    *
    * Software License Agreement
    *
    * Copyright (C) 2012 Microchip Technology Inc. All rights reserved.
    *
    * Microchip licenses to you the right to use, modify, copy, and
    * distribute the Software when used with a Microchip microcontroller or
    * digital signal controller product which is integrated into Licensee's product.
    *
    * You should refer to the license agreement accompanying this
    * Software for additional information regarding your rights and
    * obligations.
    *
    * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
    * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
    * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
    * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
    * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
    * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
    * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
    * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
    * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
    * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
    * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE
    *
    *
    * Author Date Comment
    * ==========================================================================
    * Nilesh Rajbharti 5/21/03 Initial (v1.0)
    * Howard Schlunder 9/12/06 Testing with 3.75
    * Amit Shirbhate 3/10/09 Snmp Version v2c Updates
    *


    DeclareVar(<NodeName>, <NodeDataType>, <NodeType>, <NodeAccess>, <NodeOID>)


    ****************************************************************************
    * MIB-2 SYSTEM MIB
    ****************************************************************************
    $DeclareVar(SYS_NAME, ASCII_STRING, SINGLE, READONLY, 43.6.1.2.1.1.5)
    $StaticVar(SYS_NAME, Microchip)

    $DeclareVar(SYS_DESCR, ASCII_STRING, SINGLE, READONLY, 43.6.1.2.1.1.1)
    $StaticVar(SYS_DESCR, PIC)

    $DeclareVar(SYS_CONTACT, ASCII_STRING, SINGLE, READONLY, 43.6.1.2.1.1.4)
    $StaticVar(SYS_CONTACT, admin)

    $DeclareVar(SYS_LOCATION, ASCII_STRING, SINGLE, READONLY, 43.6.1.2.1.1.6)
    $StaticVar(SYS_LOCATION, office)

    $DeclareVar(SYS_SERVICES, BYTE, SINGLE, READONLY, 43.6.1.2.1.1.7)
    $StaticVar(SYS_SERVICES, 7)

    $DeclareVar(SYS_UP_TIME, TIME_TICKS, SINGLE, READONLY, 43.6.1.2.1.1.3)
    $DynamicVar(SYS_UP_TIME, 250)

    $DeclareVar(MICROCHIP, OID, SINGLE, READONLY, 43.6.1.2.1.1.2)
    $StaticVar(MICROCHIP, 43.6.1.4.1.17095.1)

    $AgentID(MICROCHIP, 255)
    *Agent ID declaration is must if the agent is required to send trap notifications.
    *Application should use this Agent ID while generating traps.

    ****************************************************************************
    * END OF MIB-2 SYSTEM MIB
    ****************************************************************************

        
    ****************************************************************************
    * MICROCHIP - MICROCHIP MIB
    ****************************************************************************

    ----------------------------------------------------------------------------
    - microchip.product
    ----------------------------------------------------------------------------
    $DeclareVar(PRODUCT_NAME, ASCII_STRING, SINGLE, READONLY, 43.6.1.4.1.17095.1.1.1)
    $StaticVar(PRODUCT_NAME, SNMPv3Agent)

    $DeclareVar(PRODUCT_VERSION, ASCII_STRING, SINGLE, READONLY, 43.6.1.4.1.17095.1.1.2)
    $StaticVar(PRODUCT_VERSION, v5.41)

    $DeclareVar(VERSION_DATE, ASCII_STRING, SINGLE, READONLY, 43.6.1.4.1.17095.1.1.3)
    $StaticVar(VERSION_DATE, Feb 15)


    ----------------------------------------------------------------------------
    - microchip.setup
    ----------------------------------------------------------------------------
    TRAP RECEIVER is table with following format:
        TRAP_RECEIVER_ID is index.

     -----------------------------------------------------------------------------
     TRAP_RECEIVER_ID | TRAP_ENABLED | TRAP_RECEIVER_IP | TRAP_COMMUNITY
     -----------------------------------------------------------------------------
        0..3 | OFF(0)/ON(0) | X.X.X.X | ASCII_STRING(0..7)
     ------------------------------------------------------------------------------

    $DeclareVar(TRAP_RECEIVER_ID, BYTE, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.2.1.1.1)
    $DynamicVar(TRAP_RECEIVER_ID, 1)
    $SequenceVar(TRAP_RECEIVER_ID, TRAP_RECEIVER_ID)

    $DeclareVar(TRAP_RECEIVER_ENABLED, BYTE, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.2.1.1.2)
    $DynamicVar(TRAP_RECEIVER_ENABLED, 2)
    $SequenceVar(TRAP_RECEIVER_ENABLED, TRAP_RECEIVER_ID)

    $DeclareVar(TRAP_RECEIVER_IP, IP_ADDRESS, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.2.1.1.3)
    $DynamicVar(TRAP_RECEIVER_IP, 3)
    $SequenceVar(TRAP_RECEIVER_IP, TRAP_RECEIVER_ID)

    $DeclareVar(TRAP_COMMUNITY, ASCII_STRING, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.2.1.1.4)
    $DynamicVar(TRAP_COMMUNITY, 4)
    $SequenceVar(TRAP_COMMUNITY, TRAP_RECEIVER_ID)


    ----------------------------------------------------------------------------
    - microchip.control
    ----------------------------------------------------------------------------
    microchip.control.ledD5
    $DeclareVar(LED_D5, BYTE, SINGLE, READWRITE, 43.6.1.4.1.17095.1.3.1)
    $DynamicVar(LED_D5, 5)

    microchip.control.ledD6
    $DeclareVar(LED_D6, BYTE, SINGLE, READWRITE, 43.6.1.4.1.17095.1.3.2)
    $DynamicVar(LED_D6, 6)

    microchip.control.pushButton
    $DeclareVar(PUSH_BUTTON, BYTE, SINGLE, READONLY, 43.6.1.4.1.17095.1.3.3)
    $DynamicVar(PUSH_BUTTON, 7)

    microchip.control.analogPot0
    $DeclareVar(ANALOG_POT0, WORD, SINGLE, READONLY, 43.6.1.4.1.17095.1.3.4)
    $DynamicVar(ANALOG_POT0, 8)

    microchip.control.lcdDisplay
    $DeclareVar(LCD_DISPLAY, ASCII_STRING, SINGLE, READWRITE, 43.6.1.4.1.17095.1.3.6)
    $DynamicVar(LCD_DISPLAY, 10)


    ****************************************************************************
    * snmpFrameworkMIBObjects
    ****************************************************************************
    $DeclareVar(ENGINE_ID, ASCII_STRING, SINGLE, READONLY, 43.6.1.6.3.10.2.1.1)
    $DynamicVar(ENGINE_ID, 249)

    $DeclareVar(ENGINE_BOOT, DWORD, SINGLE, READONLY, 43.6.1.6.3.10.2.1.2)
    $DynamicVar(ENGINE_BOOT, 248)

    $DeclareVar(ENGINE_TIME, DWORD, SINGLE, READONLY, 43.6.1.6.3.10.2.1.3)
    $DynamicVar(ENGINE_TIME, 247)

    $DeclareVar(ENGINE_MAX_MSG, WORD, SINGLE, READONLY, 43.6.1.6.3.10.2.1.4)
    $DynamicVar(ENGINE_MAX_MSG, 246)


    ****************************************************************************
    * END OF SNMP FRAMEWORK MIB
    ****************************************************************************

        
    ****************************************************************************
    * SNMP-USER-BASED-SM-MIB
    ****************************************************************************
    User configured USM table where USM_INDEX_ID is used as index


    $DeclareVar(USM_INDEX_ID, BYTE, SEQUENCE, READONLY, 43.6.1.4.1.17095.1.4.1.1.1)
    $DynamicVar(USM_INDEX_ID, 11)
    $SequenceVar(USM_INDEX_ID, USM_INDEX_ID)

    $DeclareVar(USER_SECURITY_NAME, ASCII_STRING, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.4.1.1.2)
    $DynamicVar(USER_SECURITY_NAME, 12)
    $SequenceVar(USER_SECURITY_NAME, USM_INDEX_ID)

    $DeclareVar(USM_AUTH_PROT, BYTE, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.4.1.1.3)
    $DynamicVar(USM_AUTH_PROT, 13)
    $SequenceVar(USM_AUTH_PROT, USM_INDEX_ID)

    $DeclareVar(USM_AUTH_KEY, ASCII_STRING, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.4.1.1.4)
    $DynamicVar(USM_AUTH_KEY, 14)
    $SequenceVar(USM_AUTH_KEY, USM_INDEX_ID)

    $DeclareVar(USM_PRIV_PROT, BYTE, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.4.1.1.5)
    $DynamicVar(USM_PRIV_PROT, 15)
    $SequenceVar(USM_PRIV_PROT, USM_INDEX_ID)

    $DeclareVar(USM_PRIV_KEY, ASCII_STRING, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.4.1.1.6)
    $DynamicVar(USM_PRIV_KEY, 16)
    $SequenceVar(USM_PRIV_KEY, USM_INDEX_ID)

    ****************************************************************************
    * SNMP-TARGET-MIB
    ****************************************************************************
    User configured USM table where SNMP_TARGET_INDEX_ID is used as index


    $DeclareVar(SNMP_TARGET_INDEX_ID, BYTE, SEQUENCE, READONLY, 43.6.1.4.1.17095.1.5.1.1.1)
    $DynamicVar(SNMP_TARGET_INDEX_ID, 17)
    $SequenceVar(SNMP_TARGET_INDEX_ID,SNMP_TARGET_INDEX_ID)

    $DeclareVar(SNMP_TARGET_MP_MODEL, BYTE, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.5.1.1.2)
    $DynamicVar(SNMP_TARGET_MP_MODEL, 18)
    $SequenceVar(SNMP_TARGET_MP_MODEL, SNMP_TARGET_INDEX_ID)

    $DeclareVar(SNMP_TARGET_SECURITY_MODEL, BYTE, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.5.1.1.3)
    $DynamicVar(SNMP_TARGET_SECURITY_MODEL, 19)
    $SequenceVar(SNMP_TARGET_SECURITY_MODEL, SNMP_TARGET_INDEX_ID)

    $DeclareVar(SNMP_TARGET_SECURITY_NAME, ASCII_STRING, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.5.1.1.4)
    $DynamicVar(SNMP_TARGET_SECURITY_NAME, 20)
    $SequenceVar(SNMP_TARGET_SECURITY_NAME, SNMP_TARGET_INDEX_ID)

    $DeclareVar(SNMP_TARGET_SECURITY_LEVEL, BYTE, SEQUENCE, READWRITE, 43.6.1.4.1.17095.1.5.1.1.5)
    $DynamicVar(SNMP_TARGET_SECURITY_LEVEL, 21)
    $SequenceVar(SNMP_TARGET_SECURITY_LEVEL, SNMP_TARGET_INDEX_ID)


    ****************************************************************************
    * END OF USM MIB
    ****************************************************************************
    ****************************************************************************
    * SNMP-DEMO-TRAP
    ****************************************************************************

    $DeclareVar(SNMP_DEMO_TRAP, BYTE, SINGLE, READONLY, 43.6.1.4.1.17095.1.0.1)
    ---- Original line $DynamicVar(SNMP_DEMO_TRAP,500)
    $DynamicVar(SNMP_DEMO_TRAP,251)

    ****************************************************************************
    * END OF DEMO TRAP MIB
    ****************************************************************************

    ****************************************************************************
    * END OF MICROCHIP - Demo MIB
    ****************************************************************************
    Happily I extracted it and tried to mib2bib it. No go! the last variable in the file has an OID of 500 and mib2bib says that OID must be in the range 0-255. Wait - I check the existing mib.h and walla that OID is 500 in the original demo file. Not really clear what did Microchip use to generate the mib.h (maybe the java version of mib2bib can handle 500?). Change that OID to 251, ifigure and that will be it? 
     
    No that would be too simple. Compiled the project with the new mib.h and used MPFS tool to combine the bib with the webpages and upload the image only to find that iReasoning MIB browser is not getting all the OIDs that were there in the original demo, and does not drill down into the private part of the MIB as it did with the original demo file. It seems stuck in loop in the Enterprise section under GetNext skipping some of the OIDs that are defined in the snmp.mib.
    #2
    Dag
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2014/10/31 11:53:36
    • Location: 0
    • Status: offline
    Re: Microchip SNMP tsp stack woes 2017/12/18 06:57:16 (permalink)
    0
    Hi All,
    All Solved finally ! till further notice...
    Problem was that once I mib2bib and upload the file posted above, which seems to be the complete DemoApp MIB (using MPFS2) above, the iReasoning MIB browser sees only the system MIB (MIB-2) and does not flow into the MIB-4 enterprise tree. The original DempApp bin file works correctly! therefore something I was doing was not correct(See 4 below)  As mentioned for some reason the original Microchip MIB file for the DemoApp is nowhere to be found.
     
    This is turning into sort of a blog ...
    Here is a short summary what was discovered to date;
    1. Do not use the mib2bib.exe version that is found on the web in a number of places. It compiles the Microchip MIB syntax into a BIB that has some incompatibilities with the latest 5.42 TCP stack.
    Instead use the mib2bib.jar Java applet which is a newer version that works with the V5.42 stack.
    2. Unlike the examples in AN870 you must code the Enterprise OID with a trailing 1
    Like:
    $DeclareVar(MyCompanyLtd, OID, SINGLE, READONLY, 43.6.1.2.1.1.2)
    $StaticVar(MyCompanyLtd,43.6.1.4.1.19999.1)

    3. The Microchip MIB needs to define only the leafs. All the branches are implied and should not be coded in the Microchip syntax.
    4. One last thing that was hidden and not clearly mentioned is the Enterprise hex BER code at the beginning of of the CustomSNMPApplication.c; It is a bit hidden because it made sense to look for instances of the Microchip PEN (17095) and replace them with the one obtained for the client BUT there is a pesky Community string that must be modified to match the new PEN. I used Peter's suggested set of macros:
    #define PEN1 19999 // enterprise PEN
    #define PENBYTE3 (PEN1 & 0x7F)
    #define PEN2 (PEN1 >> 7)
    #define PENBYTE2 ((PEN2 & 0x7F) | 0x80)
    #define PEN3 (PEN2 >> 7)
    #define PENBYTE1 (PEN3 | 0x80)
       :
       :
     {{43,6,1,4,1,PENBYTE1,PENBYTE2,PENBYTE3,0x1,1},SNMP_V2C},

    To make sure that once the PEN is defined the hex codes (hard coded in the original file) will be set correctly.
    5. The rest seems straight forward - Implement the dynamic variables, traps etc and complete the Agent code by interfacing to the hardware.
    6. Oh one more unrelated small matter of HTML include files that do not allow embedded Dynamic variables in the Original Microchip TCP stack. I made several changes to HTTP2.c to provide support for them which should make life simpler for the Web page designer. PM me if you need this code.
     
    post edited by Dag - 2017/12/18 22:52:42
    #3
    Jump to:
    © 2018 APG vNext Trial Version 4.5