view packages/net/snmp/agent/current/src/mibgroup/mibII/dot3.c @ 105:5a0cc6c243a9 ecos-sw-2000-06-30

Merge from eCos master repository on 2000-06-30-08:18:49-BST
author jlarmour
date Fri, 30 Jun 2000 16:27:35 +0000
parents 95f3e12a6327
children bd1a71e3e476
line wrap: on
line source

//==========================================================================
//
//      snmp/snmpagent/current/src/mibgroup/mibII/dot3.c
//
//
//==========================================================================
//####COPYRIGHTBEGIN####
//                                                                          
// -------------------------------------------                              
// The contents of this file are subject to the Red Hat eCos Public License 
// Version 1.1 (the "License"); you may not use this file except in         
// compliance with the License.  You may obtain a copy of the License at    
// http://www.redhat.com/                                                   
//                                                                          
// Software distributed under the License is distributed on an "AS IS"      
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the 
// License for the specific language governing rights and limitations under 
// the License.                                                             
//                                                                          
// The Original Code is eCos - Embedded Configurable Operating System,      
// released September 30, 1998.                                             
//                                                                          
// The Initial Developer of the Original Code is Red Hat.                   
// Portions created by Red Hat are                                          
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.                             
// All Rights Reserved.                                                     
// -------------------------------------------                              
//                                                                          
//####COPYRIGHTEND####
//####UCDSNMPCOPYRIGHTBEGIN####
//
// -------------------------------------------
//
// Portions of this software may have been derived from the UCD-SNMP
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
// California at Davis, which was originally based on the Carnegie Mellon
// University SNMP implementation.  Portions of this software are therefore
// covered by the appropriate copyright disclaimers included herein.
//
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
// -------------------------------------------
//
//####UCDSNMPCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    hmt
// Contributors: hmt
// Date:         2000-05-30
// Purpose:      Port of UCD-SNMP distribution to eCos.
// Description:  
//              
//
//####DESCRIPTIONEND####
//
//==========================================================================
/********************************************************************
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
 
                          Derivative Work -
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
 
                         All Rights Reserved
 
Permission to use, copy, modify and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appears in all copies and
that both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU and The Regents of
the University of California not be used in advertising or publicity
pertaining to distribution of the software without specific written
permission.
 
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*********************************************************************/
/* This file was generated by mib2c and is intended for use as a mib module
   for the ucd-snmp snmpd agent. */


/* This should always be included first before anything else */
#include <config.h>


/* minimal include directives */
#include "mibincl.h"
#include "mibgroup/util_funcs.h"
#include "mibgroup/mibII/dot3.h"

#include <net/if_types.h>

// Get info about the device
#include <pkgconf/system.h>

#include <eth_drv.h>

#ifdef CYGBLD_DEVS_ETH_DEVICE_H
#include CYGBLD_DEVS_ETH_DEVICE_H
#endif

#ifdef CYGBLD_DEVS_ETH_INFO_H
#include CYGBLD_DEVS_ETH_INFO_H
#endif

/* 
 * dot3_variables_oid:
 *   this is the top level oid that we want to register under.  This
 *   is essentially a prefix, with the suffix appearing in the
 *   variable below.
 */

oid dot3_variables_oid[] = { 1,3,6,1,2,1,10,7 };


extern struct ifnet_head ifnet;


/* 
 * variable4 dot3_variables:
 *   this variable defines function callbacks and type return information 
 *   for the dot3 mib section 
 */
struct variable4 dot3_variables[] = {
/*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
#define   DOT3STATSINDEX        3
  { DOT3STATSINDEX      , ASN_INTEGER   , RONLY , var_dot3StatsTable, 3, { 2,1,1 } },
#define   DOT3STATSALIGNMENTERRORS  4
  { DOT3STATSALIGNMENTERRORS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,2 } },
#define   DOT3STATSFCSERRORS    5
  { DOT3STATSFCSERRORS  , ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,3 } },
#define   DOT3STATSSINGLECOLLISIONFRAMES  6
  { DOT3STATSSINGLECOLLISIONFRAMES, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,4 } },
#define   DOT3STATSMULTIPLECOLLISIONFRAMES  7
  { DOT3STATSMULTIPLECOLLISIONFRAMES, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,5 } },
#define   DOT3STATSSQETESTERRORS  8
  { DOT3STATSSQETESTERRORS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,6 } },
#define   DOT3STATSDEFERREDTRANSMISSIONS  9
  { DOT3STATSDEFERREDTRANSMISSIONS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,7 } },
#define   DOT3STATSLATECOLLISIONS  10
  { DOT3STATSLATECOLLISIONS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,8 } },
#define   DOT3STATSEXCESSIVECOLLISIONS  11
  { DOT3STATSEXCESSIVECOLLISIONS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,9 } },
#define   DOT3STATSINTERNALMACTRANSMITERRORS  12
  { DOT3STATSINTERNALMACTRANSMITERRORS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,10 } },
#define   DOT3STATSCARRIERSENSEERRORS  13
  { DOT3STATSCARRIERSENSEERRORS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,11 } },
#define   DOT3STATSFRAMETOOLONGS  14
  { DOT3STATSFRAMETOOLONGS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,13 } },
#define   DOT3STATSINTERNALMACRECEIVEERRORS  15
  { DOT3STATSINTERNALMACRECEIVEERRORS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,16 } },
#define   DOT3STATSETHERCHIPSET  16
  { DOT3STATSETHERCHIPSET, ASN_OBJECT_ID , RONLY , var_dot3StatsTable, 3, { 2,1,17 } },
#define   DOT3STATSSYMBOLERRORS  17
  { DOT3STATSSYMBOLERRORS, ASN_COUNTER   , RONLY , var_dot3StatsTable, 3, { 2,1,18 } },
#define   DOT3STATSDUPLEXSTATUS  18
  { DOT3STATSDUPLEXSTATUS, ASN_INTEGER   , RONLY , var_dot3StatsTable, 3, { 2,1,19 } },

// We do not have this histogram available:
//#define   DOT3COLLFREQUENCIES   22
//  { DOT3COLLFREQUENCIES , ASN_COUNTER   , RONLY , var_dot3CollTable, 3, { 5,1,3 } },

//UNSUPPORTED: currently we do not get these statistics out
//#define   DOT3CONTROLFUNCTIONSSUPPORTED  25
//  { DOT3CONTROLFUNCTIONSSUPPORTED, ASN_BIT_STR , RONLY , var_dot3ControlTable, 3, { 9,1,1 } },
//#define   DOT3CONTROLINUNKNOWNOPCODES  26
//  { DOT3CONTROLINUNKNOWNOPCODES, ASN_COUNTER   , RONLY , var_dot3ControlTable, 3, { 9,1,2 } },


//UNSUPPORTED: currently we do not get these statistics out
//#define   DOT3PAUSEADMINMODE    29
//  { DOT3PAUSEADMINMODE  , ASN_INTEGER   , RWRITE, var_dot3PauseTable, 3, { 10,1,1 } },
//#define   DOT3PAUSEOPERMODE     30
//  { DOT3PAUSEOPERMODE   , ASN_INTEGER   , RONLY , var_dot3PauseTable, 3, { 10,1,2 } },
//#define   DOT3INPAUSEFRAMES     31
//  { DOT3INPAUSEFRAMES   , ASN_COUNTER   , RONLY , var_dot3PauseTable, 3, { 10,1,3 } },
//#define   DOT3OUTPAUSEFRAMES    32
//  { DOT3OUTPAUSEFRAMES  , ASN_COUNTER   , RONLY , var_dot3PauseTable, 3, { 10,1,4 } },

};
/*    (L = length of the oidsuffix) */


/*
 * init_dot3():
 *   Initialization routine.  This is called when the agent starts up.
 *   At a minimum, registration of your variables should take place here.
 */
void init_dot3(void)
{
    /* register ourselves with the agent to handle our mib tree */
    REGISTER_MIB("dot3", dot3_variables, variable4,
                 dot3_variables_oid);

    /* place any other initialization junk you need here */
}


/*
 * var_dot3StatsTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_dot3StatsTable above.
 */
unsigned char *
var_dot3StatsTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
    	    WriteMethod **write_method)
{
    static long long_ret;
    struct eth_drv_sc *sc;
#ifdef ETH_DEV_DOT3STATSETHERCHIPSET
    static oid etherobjid[] = { ETH_DEV_DOT3STATSETHERCHIPSET };
#endif
    static oid nullobjid[] = { 0,0 };

    register struct ifnet *ifp;
    int interface_count = 0;

    for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next)
        interface_count++;
        
    if ( header_simple_table( vp,name,length,exact,var_len,write_method,
                              interface_count)
         == MATCH_FAILED )
        return NULL;

    for ( interface_count = name[ (*length)-1 ], ifp = ifnet.tqh_first;
          interface_count > 1 && ifp != 0;
          interface_count-- )
        ifp = ifp->if_list.tqe_next;
    
    if ( ! ifp )
        return NULL;

    if ( IFT_LOOP == ifp->if_type ) {
        switch(vp->magic) {
        case DOT3STATSINDEX:
            long_ret = name[(*length)-1];
            return (unsigned char *) &long_ret;

        case DOT3STATSETHERCHIPSET:
            *var_len = sizeof(nullobjid);
            return (unsigned char *) nullobjid;

        case DOT3STATSDUPLEXSTATUS:
            long_ret = 1;
            return (unsigned char *) &long_ret;
                
        default:
            long_ret = 0; // a dummy value for most of them
            return (unsigned char *) &long_ret;
        }
    }

    sc = ifp->if_softc;
    // Otherwise, assume it is ethernet...
    {
#ifdef ETH_STATS_INIT
        ETH_STATS_INIT( sc );
#endif

        switch(vp->magic) {
        case DOT3STATSINDEX:
            long_ret = name[(*length)-1];
            return (unsigned char *) &long_ret;

        case DOT3STATSALIGNMENTERRORS:
#ifdef  ETH_DEV_STATSALIGNMENTERRORS
            long_ret = ETH_DEV_STATSALIGNMENTERRORS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSFCSERRORS:
#ifdef  ETH_DEV_STATSFCSERRORS
            long_ret = ETH_DEV_STATSFCSERRORS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSSINGLECOLLISIONFRAMES:
#ifdef  ETH_DEV_STATSSINGLECOLLISIONFRAMES
            long_ret = ETH_DEV_STATSSINGLECOLLISIONFRAMES( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSMULTIPLECOLLISIONFRAMES:
#ifdef  ETH_DEV_STATSMULTIPLECOLLISIONFRAMES
            long_ret = ETH_DEV_STATSMULTIPLECOLLISIONFRAMES( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSSQETESTERRORS:
#ifdef  ETH_DEV_STATSSQETESTERRORS
            long_ret = ETH_DEV_STATSSQETESTERRORS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSDEFERREDTRANSMISSIONS:
#ifdef  ETH_DEV_STATSDEFERREDTRANSMISSIONS
            long_ret = ETH_DEV_STATSDEFERREDTRANSMISSIONS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSLATECOLLISIONS:
#ifdef  ETH_DEV_STATSLATECOLLISIONS
            long_ret = ETH_DEV_STATSLATECOLLISIONS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSEXCESSIVECOLLISIONS:
#ifdef  ETH_DEV_STATSEXCESSIVECOLLISIONS
            long_ret = ETH_DEV_STATSEXCESSIVECOLLISIONS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSINTERNALMACTRANSMITERRORS:
#ifdef  ETH_DEV_STATSINTERNALMACTRANSMITERRORS
            long_ret = ETH_DEV_STATSINTERNALMACTRANSMITERRORS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSCARRIERSENSEERRORS:
#ifdef  ETH_DEV_STATSCARRIERSENSEERRORS
            long_ret = ETH_DEV_STATSCARRIERSENSEERRORS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSFRAMETOOLONGS:
#ifdef  ETH_DEV_STATSFRAMETOOLONGS
            long_ret = ETH_DEV_STATSFRAMETOOLONGS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSINTERNALMACRECEIVEERRORS:
#ifdef  ETH_DEV_STATSINTERNALMACRECEIVEERRORS
            long_ret = ETH_DEV_STATSINTERNALMACRECEIVEERRORS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSETHERCHIPSET:
#ifdef ETH_DEV_DOT3STATSETHERCHIPSET
            *var_len = sizeof(etherobjid);
            return (unsigned char *) etherobjid;
#else
            *var_len = sizeof(nullobjid);
            return (unsigned char *) nullobjid;
#endif
    
        case DOT3STATSSYMBOLERRORS:
#ifdef  ETH_DEV_STATSSYMBOLERRORS
            long_ret = ETH_DEV_STATSSYMBOLERRORS( sc );
#else
            long_ret = 0;
#endif
            return (unsigned char *) &long_ret;
    
        case DOT3STATSDUPLEXSTATUS:
#ifdef  ETH_DEV_FULLDUPLEX
            if ( ETH_DEV_FULLDUPLEX( sc ) )
                long_ret = 3; // fullDuplex
            else
                long_ret = 2; // halfDuplex
#else
            long_ret = 1; // Unknown
#endif
            return (unsigned char *) &long_ret;
    
        default:
            ERROR_MSG("");
        }
    }
    return NULL;
}


#if 0 // UNSUPPORTED: we do not have the information for these tables.
/*
 * var_dot3ControlTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_dot3ControlTable above.
 */
unsigned char *
var_dot3ControlTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
    	    WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;
    if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
        == MATCH_FAILED )
        return NULL;

    switch(vp->magic) {
    case DOT3CONTROLFUNCTIONSSUPPORTED:
        long_ret = 1;
        return &long_ret;

    case DOT3CONTROLINUNKNOWNOPCODES:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    default:
      ERROR_MSG("");
    }
    return NULL;
}

/*
 * var_dot3PauseTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_dot3PauseTable above.
 */
unsigned char *
var_dot3PauseTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
    	    WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;

    if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
        == MATCH_FAILED )
        return NULL;
    
    switch(vp->magic) {
    case DOT3PAUSEADMINMODE:
        *write_method = write_dot3PauseAdminMode;
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case DOT3PAUSEOPERMODE:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case DOT3INPAUSEFRAMES:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case DOT3OUTPAUSEFRAMES:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    default:
        ERROR_MSG("");
    }
    return NULL;
}


int
write_dot3PauseAdminMode(int      action,
            u_char   *var_val,
            u_char   var_val_type,
            size_t   var_val_len,
            u_char   *statP,
            oid      *name,
            size_t   name_len)
{
    static long *long_ret;
    int size;

    switch ( action ) {
    case RESERVE1:
        if (var_val_type != ASN_INTEGER){
            fprintf(stderr, "write to dot3PauseAdminMode not ASN_INTEGER\n");
            return SNMP_ERR_WRONGTYPE;
        }
        if (var_val_len > sizeof(long_ret)){
            fprintf(stderr,"write to dot3PauseAdminMode: bad length\n");
            return SNMP_ERR_WRONGLENGTH;
        }
        break;
        
    case RESERVE2:
        size = var_val_len;
        long_ret = (long *) var_val;
        break;
        
    case FREE:
        /* Release any resources that have been allocated */
        break;
        
    case ACTION:
        /* The variable has been stored in long_ret for
           you to use, and you have just been asked to do something with
           it.  Note that anything done here must be reversable in the UNDO case */
        break;
        
    case UNDO:
        /* Back out any changes made in the ACTION case */
        break;
        
    case COMMIT:
        /* Things are working well, so it's now safe to make the change
           permanently.  Make sure that anything done here can't fail! */
        break;
    }
    return SNMP_ERR_NOERROR;
}
#endif // UNSUPPORTED

// EOF dot3.c