/*****************************************************************************
* Copyright (c) 2001-2007 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/

#include "trdefs.h"

#include "trasn1.h"
#include "trimpl.h"
#include "trmib.h"
#include "trconsts.h"

#include "trmib2.h"

#ifdef TM_SNMP_AGENT_V3
#include "trsnmpv3.h"
#include "trdeskey.h"
#endif /* TM_SNMP_AGENT_V3 */

#include "ups-mib_local.h"
#include "ups-mib_var.h"
#include "snmp-target-mib_local.h"
#include "snmp-target-mib_var.h"
#include "snmp-notification-mib_local.h"
#include "snmp-notification-mib_var.h"

#include "trapi.h"
#include "trintapi.h"
#include "nastatus.h"
#include "snmpapi.h"

/*  Pulled directly from the example.ins file generated by the MIB compiler */
const struct tsSnmpVariable tvSnmpUpsobjectsVars[] = {
    {tfvar_upsident, TM_SNMP_RONLY, 0, 2, UPSIDENTMANUFACTURER, TM_SNMP_STRING, 0, {1,1}},
    {tfvar_upsident, TM_SNMP_RONLY, 0, 2, UPSIDENTMODEL, TM_SNMP_STRING, 0, {1,2}},
    {tfvar_upsident, TM_SNMP_RONLY, 0, 2, UPSIDENTUPSSOFTWAREVERSION, TM_SNMP_STRING, 0, {1,3}},
    {tfvar_upsident, TM_SNMP_RONLY, 0, 2, UPSIDENTAGENTSOFTWAREVERSION, TM_SNMP_STRING, 0, {1,4}},
    {tfvar_upsident, TM_SNMP_RWRITE, 0, 2, UPSIDENTNAME, TM_SNMP_STRING, 0, {1,5}},
    {tfvar_upsident, TM_SNMP_RWRITE, 0, 2, UPSIDENTATTACHEDDEVICES, TM_SNMP_STRING, 0, {1,6}},
    {tfvar_upsbattery, TM_SNMP_RONLY, 0, 2, UPSBATTERYSTATUS, TM_SNMP_INTEGER, 0, {2,1}},
    {tfvar_upsbattery, TM_SNMP_RONLY, 0, 2, UPSSECONDSONBATTERY, TM_SNMP_INTEGER, 0, {2,2}},
    {tfvar_upsbattery, TM_SNMP_RONLY, 0, 2, UPSESTIMATEDMINUTESREMAINING, TM_SNMP_INTEGER, 0, {2,3}},
    {tfvar_upsbattery, TM_SNMP_RONLY, 0, 2, UPSESTIMATEDCHARGEREMAINING, TM_SNMP_INTEGER, 0, {2,4}},
    {tfvar_upsbattery, TM_SNMP_RONLY, 0, 2, UPSBATTERYVOLTAGE, TM_SNMP_INTEGER, 0, {2,5}},
    {tfvar_upsbattery, TM_SNMP_RONLY, 0, 2, UPSBATTERYCURRENT, TM_SNMP_INTEGER, 0, {2,6}},
    {tfvar_upsbattery, TM_SNMP_RONLY, 0, 2, UPSBATTERYTEMPERATURE, TM_SNMP_INTEGER, 0, {2,7}},
    {tfvar_upsinput, TM_SNMP_RONLY, 0, 2, UPSINPUTLINEBADS, TM_SNMP_COUNTER, 0, {3,1}},
    {tfvar_upsinput, TM_SNMP_RONLY, 0, 2, UPSINPUTNUMLINES, TM_SNMP_INTEGER, 0, {3,2}},
    {tfvar_upsinputtable, TM_SNMP_RONLY, 0, 4, UPSINPUTFREQUENCY, TM_SNMP_INTEGER, 0, {3,3,1,2}},
    {tfvar_upsinputtable, TM_SNMP_RONLY, 0, 4, UPSINPUTVOLTAGE, TM_SNMP_INTEGER, 0, {3,3,1,3}},
    {tfvar_upsinputtable, TM_SNMP_RONLY, 0, 4, UPSINPUTCURRENT, TM_SNMP_INTEGER, 0, {3,3,1,4}},
    {tfvar_upsinputtable, TM_SNMP_RONLY, 0, 4, UPSINPUTTRUEPOWER, TM_SNMP_INTEGER, 0, {3,3,1,5}},
    {tfvar_upsoutput, TM_SNMP_RONLY, 0, 2, UPSOUTPUTSOURCE, TM_SNMP_INTEGER, 0, {4,1}},
    {tfvar_upsoutput, TM_SNMP_RONLY, 0, 2, UPSOUTPUTFREQUENCY, TM_SNMP_INTEGER, 0, {4,2}},
    {tfvar_upsoutput, TM_SNMP_RONLY, 0, 2, UPSOUTPUTNUMLINES, TM_SNMP_INTEGER, 0, {4,3}},
    {tfvar_upsoutputtable, TM_SNMP_RONLY, 0, 4, UPSOUTPUTVOLTAGE, TM_SNMP_INTEGER, 0, {4,4,1,2}},
    {tfvar_upsoutputtable, TM_SNMP_RONLY, 0, 4, UPSOUTPUTCURRENT, TM_SNMP_INTEGER, 0, {4,4,1,3}},
    {tfvar_upsoutputtable, TM_SNMP_RONLY, 0, 4, UPSOUTPUTPOWER, TM_SNMP_INTEGER, 0, {4,4,1,4}},
    {tfvar_upsoutputtable, TM_SNMP_RONLY, 0, 4, UPSOUTPUTPERCENTLOAD, TM_SNMP_INTEGER, 0, {4,4,1,5}},
    {tfvar_upsbypass, TM_SNMP_RONLY, 0, 2, UPSBYPASSFREQUENCY, TM_SNMP_INTEGER, 0, {5,1}},
    {tfvar_upsbypass, TM_SNMP_RONLY, 0, 2, UPSBYPASSNUMLINES, TM_SNMP_INTEGER, 0, {5,2}},
    {tfvar_upsbypasstable, TM_SNMP_RONLY, 0, 4, UPSBYPASSVOLTAGE, TM_SNMP_INTEGER, 0, {5,3,1,2}},
    {tfvar_upsbypasstable, TM_SNMP_RONLY, 0, 4, UPSBYPASSCURRENT, TM_SNMP_INTEGER, 0, {5,3,1,3}},
    {tfvar_upsbypasstable, TM_SNMP_RONLY, 0, 4, UPSBYPASSPOWER, TM_SNMP_INTEGER, 0, {5,3,1,4}},
    {tfvar_upsalarm, TM_SNMP_RONLY, 0, 2, UPSALARMSPRESENT, TM_SNMP_GAUGE, 0, {6,1}},
    {tfvar_upsalarmtable, TM_SNMP_RONLY, 0, 4, UPSALARMDESCR, TM_SNMP_OBJID, 0, {6,2,1,2}},
    {tfvar_upsalarmtable, TM_SNMP_RONLY, 0, 4, UPSALARMTIME, TM_SNMP_UINTEGER, 0, {6,2,1,3}},
    {tfvar_upstest, TM_SNMP_RWRITE, 0, 2, UPSTESTID, TM_SNMP_OBJID, 0, {7,1}},
    {tfvar_upstest, TM_SNMP_RWRITE, 0, 2, UPSTESTSPINLOCK, TM_SNMP_INTEGER, 0, {7,2}},
    {tfvar_upstest, TM_SNMP_RONLY, 0, 2, UPSTESTRESULTSSUMMARY, TM_SNMP_INTEGER, 0, {7,3}},
    {tfvar_upstest, TM_SNMP_RONLY, 0, 2, UPSTESTRESULTSDETAIL, TM_SNMP_STRING, 0, {7,4}},
    {tfvar_upstest, TM_SNMP_RONLY, 0, 2, UPSTESTSTARTTIME, TM_SNMP_UINTEGER, 0, {7,5}},
    {tfvar_upstest, TM_SNMP_RONLY, 0, 2, UPSTESTELAPSEDTIME, TM_SNMP_INTEGER, 0, {7,6}},
    {tfvar_upscontrol, TM_SNMP_RWRITE, 0, 2, UPSSHUTDOWNTYPE, TM_SNMP_INTEGER, 0, {8,1}},
    {tfvar_upscontrol, TM_SNMP_RWRITE, 0, 2, UPSSHUTDOWNAFTERDELAY, TM_SNMP_INTEGER, 0, {8,2}},
    {tfvar_upscontrol, TM_SNMP_RWRITE, 0, 2, UPSSTARTUPAFTERDELAY, TM_SNMP_INTEGER, 0, {8,3}},
    {tfvar_upscontrol, TM_SNMP_RWRITE, 0, 2, UPSREBOOTWITHDURATION, TM_SNMP_INTEGER, 0, {8,4}},
    {tfvar_upscontrol, TM_SNMP_RWRITE, 0, 2, UPSAUTORESTART, TM_SNMP_INTEGER, 0, {8,5}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGINPUTVOLTAGE, TM_SNMP_INTEGER, 0, {9,1}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGINPUTFREQ, TM_SNMP_INTEGER, 0, {9,2}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGOUTPUTVOLTAGE, TM_SNMP_INTEGER, 0, {9,3}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGOUTPUTFREQ, TM_SNMP_INTEGER, 0, {9,4}},
    {tfvar_upsconfig, TM_SNMP_RONLY, 0, 2, UPSCONFIGOUTPUTVA, TM_SNMP_INTEGER, 0, {9,5}},
    {tfvar_upsconfig, TM_SNMP_RONLY, 0, 2, UPSCONFIGOUTPUTPOWER, TM_SNMP_INTEGER, 0, {9,6}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGLOWBATTTIME, TM_SNMP_INTEGER, 0, {9,7}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGAUDIBLESTATUS, TM_SNMP_INTEGER, 0, {9,8}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGLOWVOLTAGETRANSFERPOINT, TM_SNMP_INTEGER, 0, {9,9}},
    {tfvar_upsconfig, TM_SNMP_RWRITE, 0, 2, UPSCONFIGHIGHVOLTAGETRANSFERPOINT, TM_SNMP_INTEGER, 0, {9,10}}
};

const struct tsSnmpVariable tvSnmpSnmptargetobjectsVars[] = {
    {tfvar_snmptargetobjects, TM_SNMP_RWRITE, 0, 1, SNMPTARGETSPINLOCK, TM_SNMP_INTEGER, 0, {1}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRTDOMAIN, TM_SNMP_OBJID, 0, {2,1,2}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRTADDRESS, TM_SNMP_STRING, 0, {2,1,3}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRTIMEOUT, TM_SNMP_INTEGER, 0, {2,1,4}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRRETRYCOUNT, TM_SNMP_INTEGER, 0, {2,1,5}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRTAGLIST, TM_SNMP_STRING, 0, {2,1,6}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRPARAMS, TM_SNMP_STRING, 0, {2,1,7}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRSTORAGETYPE, TM_SNMP_INTEGER, 0, {2,1,8}},
    {tfvar_snmptargetaddrtable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETADDRROWSTATUS, TM_SNMP_INTEGER, 0, {2,1,9}},
    {tfvar_snmptargetparamstable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETPARAMSMPMODEL, TM_SNMP_INTEGER, 0, {3,1,2}},
    {tfvar_snmptargetparamstable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETPARAMSSECURITYMODEL, TM_SNMP_INTEGER, 0, {3,1,3}},
    {tfvar_snmptargetparamstable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETPARAMSSECURITYNAME, TM_SNMP_STRING, 0, {3,1,4}},
    {tfvar_snmptargetparamstable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETPARAMSSECURITYLEVEL, TM_SNMP_INTEGER, 0, {3,1,5}},
    {tfvar_snmptargetparamstable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETPARAMSSTORAGETYPE, TM_SNMP_INTEGER, 0, {3,1,6}},
    {tfvar_snmptargetparamstable, TM_SNMP_RWRITE, 0, 3, SNMPTARGETPARAMSROWSTATUS, TM_SNMP_INTEGER, 0, {3,1,7}},
    {tfvar_snmptargetobjects, TM_SNMP_RONLY, 0, 1, SNMPUNAVAILABLECONTEXTS, TM_SNMP_COUNTER, 0, {4}},
    {tfvar_snmptargetobjects, TM_SNMP_RONLY, 0, 1, SNMPUNKNOWNCONTEXTS, TM_SNMP_COUNTER, 0, {5}}
};

const struct tsSnmpVariable tvSnmpSnmpnotifyobjectsVars[] = {
    {tfvar_snmpnotifytable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYTAG, TM_SNMP_STRING, 0, {1,1,2}},
    {tfvar_snmpnotifytable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYTYPE, TM_SNMP_INTEGER, 0, {1,1,3}},
    {tfvar_snmpnotifytable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYSTORAGETYPE, TM_SNMP_INTEGER, 0, {1,1,4}},
    {tfvar_snmpnotifytable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYROWSTATUS, TM_SNMP_INTEGER, 0, {1,1,5}},
    {tfvar_snmpnotifyfilterprofiletable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYFILTERPROFILENAME, TM_SNMP_STRING, 0, {2,1,1}},
    {tfvar_snmpnotifyfilterprofiletable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYFILTERPROFILESTORTYPE, TM_SNMP_INTEGER, 0, {2,1,2}},
    {tfvar_snmpnotifyfilterprofiletable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYFILTERPROFILEROWSTATUS, TM_SNMP_INTEGER, 0, {2,1,3}},
    {tfvar_snmpnotifyfiltertable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYFILTERMASK, TM_SNMP_STRING, 0, {3,1,2}},
    {tfvar_snmpnotifyfiltertable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYFILTERTYPE, TM_SNMP_INTEGER, 0, {3,1,3}},
    {tfvar_snmpnotifyfiltertable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYFILTERSTORAGETYPE, TM_SNMP_INTEGER, 0, {3,1,4}},
    {tfvar_snmpnotifyfiltertable, TM_SNMP_RWRITE, 0, 3, SNMPNOTIFYFILTERROWSTATUS, TM_SNMP_INTEGER, 0, {3,1,5}}
};




const ttSnmpSubtree TM_CONST_QLF custSnmpSubtrees[] = 
{
    /*  Pulled directly from the example.ins file generated by the MIB compiler */
    {(struct tsSnmpVariable *)tvSnmpUpsobjectsVars,
     {1,3,6,1,2,1,33,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
     sizeof(tvSnmpUpsobjectsVars)/sizeof(*tvSnmpUpsobjectsVars),
     sizeof(*tvSnmpUpsobjectsVars), 8, 0, {'\0'}},
	 {(struct tsSnmpVariable *)tvSnmpSnmptargetobjectsVars,
     {1,3,6,1,6,3,12,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
     sizeof(tvSnmpSnmptargetobjectsVars)/sizeof(*tvSnmpSnmptargetobjectsVars),
     sizeof(*tvSnmpSnmptargetobjectsVars), 8, 0, {'\0'}},
	 {(struct tsSnmpVariable *)tvSnmpSnmpnotifyobjectsVars,
     {1,3,6,1,6,3,13,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
     sizeof(tvSnmpSnmpnotifyobjectsVars)/sizeof(*tvSnmpSnmpnotifyobjectsVars),
     sizeof(*tvSnmpSnmpnotifyobjectsVars), 8, 0, {'\0'}},
    
    {NULL,
     {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      0,
      0, 0, 0, {'\0'}}
};




const ttConceptualTable  TM_CONST_QLF  custConceptualTables[] =
{
    {
        { 1, 3, 6, 1, 6, 3, 12, 1, 2, 1}, 
        9, 10,
        { 0}
        ,
        { 0}
    }
    ,
    {
        { 1, 3, 6, 1, 6, 3, 12, 1, 3, 1}, 
        7, 10,
        { 0}
        ,
        { 0}
    }
    ,

   {
        { 1, 3, 6, 1, 6, 3, 13, 1, 1, 1}, 
        5, 10,
        { 0}
        ,
        { 0}
    }
    ,
    {
        { 1, 3, 6, 1, 6, 3, 13, 1, 2, 1}, 
        3, 10,
        { 0}
        ,
        { 0}
    }
    ,
    {
        { 1, 3, 6, 1, 6, 3, 13, 1, 3, 1}, 
        5, 10,
        { 0}
        ,
        { 0}
    }
    ,

    
   {
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
        0, 0,
        {0},
        {0}
    }
};    

NaStatus initializeCustomMibs(void)
{
   return naInitializeCustomMibs(custSnmpSubtrees, custConceptualTables);
}
