/*
 * Note: this file originally auto-generated by mib2c using
 *       version $ of $ 
 *
 * $Id:$
 */
/* standard Net-SNMP includes */
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-features.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

#include "wrsSnmp.h"
#include "snmp_shmem.h"

/* include our parent header */
#include "dot1qPortVlanTable.h"


/** @defgroup data_get data_get: Routines to get data
 *
 * TODO:230:M: Implement dot1qPortVlanTable get routines.
 * TODO:240:M: Implement dot1qPortVlanTable mapping routines (if any).
 *
 * These routine are used to get the value for individual objects. The
 * row context is passed, along with a pointer to the memory where the
 * value should be copied.
 *
 * @{
 */
/**********************************************************************
 **********************************************************************
 ***
 *** Table dot1qPortVlanTable
 ***
 **********************************************************************
 **********************************************************************/
/*
 * Q-BRIDGE-MIB::dot1qPortVlanTable is subid 5 of dot1qVlan.
 * Its status is Current.
 * OID: .1.3.6.1.2.1.17.7.1.4.5, length: 11
*/

/* ---------------------------------------------------------------------
 * TODO:200:r: Implement dot1qPortVlanTable data context functions.
 */


/**
 * set mib index(es)
 *
 * @param tbl_idx mib index structure
 * @param dot1dBasePort_val
 *
 * @retval MFD_SUCCESS     : success.
 * @retval MFD_ERROR       : other error.
 *
 * @remark
 *  This convenience function is useful for setting all the MIB index
 *  components with a single function call. It is assume that the C values
 *  have already been mapped from their native/rawformat to the MIB format.
 */
int
dot1qPortVlanTable_indexes_set_tbl_idx(dot1qPortVlanTable_mib_index *tbl_idx, long dot1dBasePort_val)
{
    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortVlanTable_indexes_set_tbl_idx","called\n"));

    /* dot1dBasePort(1)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/R/d/h */
    tbl_idx->dot1dBasePort = dot1dBasePort_val;
    

    return MFD_SUCCESS;
} /* dot1qPortVlanTable_indexes_set_tbl_idx */

/**
 * @internal
 * set row context indexes
 *
 * @param reqreq_ctx the row context that needs updated indexes
 *
 * @retval MFD_SUCCESS     : success.
 * @retval MFD_ERROR       : other error.
 *
 * @remark
 *  This function sets the mib indexs, then updates the oid indexs
 *  from the mib index.
 */
int
dot1qPortVlanTable_indexes_set(dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, long dot1dBasePort_val)
{
    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortVlanTable_indexes_set","called\n"));

    if(MFD_SUCCESS != dot1qPortVlanTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx
                                   , dot1dBasePort_val
           ))
        return MFD_ERROR;

    /*
     * convert mib index to oid index
     */
    rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid);
    if(0 != dot1qPortVlanTable_index_to_oid(&rowreq_ctx->oid_idx,
                                    &rowreq_ctx->tbl_idx)) {
        return MFD_ERROR;
    }

    return MFD_SUCCESS;
} /* dot1qPortVlanTable_indexes_set */


/*---------------------------------------------------------------------
 * Q-BRIDGE-MIB::dot1qPortVlanEntry.dot1qPvid
 * dot1qPvid is subid 1 of dot1qPortVlanEntry.
 * Its status is Current, and its access level is ReadWrite.
 * OID: .1.3.6.1.2.1.17.7.1.4.5.1.1
 * Description:
The PVID, the VLAN-ID assigned to untagged frames or
        Priority-Tagged frames received on this port.

        The value of this object MUST be retained across
        reinitializations of the management system.
 *
 * Attributes:
 *   accessible 1     isscalar 0     enums  0      hasdefval 1
 *   readable   1     iscolumn 1     ranges 0      hashint   1
 *   settable   1
 *   defval: 1
 *   hint: d
 *
 *
 * Its syntax is VlanIndex (based on perltype UNSIGNED32)
 * The net-snmp type is ASN_UNSIGNED. The C type decl is u_long (u_long)
 */
/**
 * Extract the current value of the dot1qPvid data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1qPvid_val_ptr
 *        Pointer to storage for a u_long variable
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_SKIP            : skip this node (no value for now)
 * @retval MFD_ERROR           : Any other error
 */
int
dot1qPvid_get( dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, u_long * dot1qPvid_val_ptr )
{
   /** we should have a non-NULL pointer */
   netsnmp_assert( NULL != dot1qPvid_val_ptr );


    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPvid_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

/*
 * TODO:231:o: |-> Extract the current value of the dot1qPvid data.
 * copy (* dot1qPvid_val_ptr ) from rowreq_ctx->data
 */
    (* dot1qPvid_val_ptr ) = rowreq_ctx->data.dot1qPvid;

    return MFD_SUCCESS;
} /* dot1qPvid_get */

/*---------------------------------------------------------------------
 * Q-BRIDGE-MIB::dot1qPortVlanEntry.dot1qPortAcceptableFrameTypes
 * dot1qPortAcceptableFrameTypes is subid 2 of dot1qPortVlanEntry.
 * Its status is Current, and its access level is ReadWrite.
 * OID: .1.3.6.1.2.1.17.7.1.4.5.1.2
 * Description:
When this is admitOnlyVlanTagged(2), the device will
        discard untagged frames or Priority-Tagged frames
        received on this port.  When admitAll(1), untagged
        frames or Priority-Tagged frames received on this port
        will be accepted and assigned to a VID based on the
        PVID and VID Set for this port.

        This control does not affect VLAN-independent Bridge
        Protocol Data Unit (BPDU) frames, such as GVRP and
        Spanning Tree Protocol (STP).  It does affect VLAN-
        dependent BPDU frames, such as GMRP.

        The value of this object MUST be retained across
        reinitializations of the management system.
 *
 * Attributes:
 *   accessible 1     isscalar 0     enums  1      hasdefval 1
 *   readable   1     iscolumn 1     ranges 0      hashint   0
 *   settable   1
 *   defval: admitAll
 *
 * Enum range: 2/8. Values:  admitAll(1), admitOnlyVlanTagged(2)
 *
 * Its syntax is INTEGER (based on perltype INTEGER)
 * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long)
 */
/**
 * map a value from its original native format to the MIB format.
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_ERROR           : Any other error
 *
 * @note parameters follow the memset convention (dest, src).
 *
 * @note generation and use of this function can be turned off by re-running
 * mib2c after adding the following line to the file
 * defaults/node-dot1qPortAcceptableFrameTypes.m2d :
 *   @eval $m2c_node_skip_mapping = 1@
 *
 * @remark
 *  If the values for your data type don't exactly match the
 *  possible values defined by the mib, you should map them here.
 *  Otherwise, just do a direct copy.
 */
int
dot1qPortAcceptableFrameTypes_map(u_long *mib_dot1qPortAcceptableFrameTypes_val_ptr, u_long raw_dot1qPortAcceptableFrameTypes_val)
{
    netsnmp_assert(NULL != mib_dot1qPortAcceptableFrameTypes_val_ptr);
    
    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortAcceptableFrameTypes_map","called\n"));
    
    /*
     * |-> Implement dot1qPortAcceptableFrameTypes enum mapping.
     * uses INTERNAL_* macros defined in the header files
     */
    switch(raw_dot1qPortAcceptableFrameTypes_val) {
	case QMODE_ACCESS:
	case QMODE_DISABLED:
	case QMODE_UNQ:
             *mib_dot1qPortAcceptableFrameTypes_val_ptr = DOT1QPORTACCEPTABLEFRAMETYPES_ADMITALL;
             break;

	case QMODE_TRUNK:
             *mib_dot1qPortAcceptableFrameTypes_val_ptr = DOT1QPORTACCEPTABLEFRAMETYPES_ADMITONLYVLANTAGGED;
             break;

	default:
	    snmp_log(LOG_ERR, "couldn't map value %ld for dot1qPortAcceptableFrameTypes\n", raw_dot1qPortAcceptableFrameTypes_val );
	    return MFD_ERROR;
    }

    return MFD_SUCCESS;
} /* dot1qPortAcceptableFrameTypes_map */

/**
 * Extract the current value of the dot1qPortAcceptableFrameTypes data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1qPortAcceptableFrameTypes_val_ptr
 *        Pointer to storage for a long variable
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_SKIP            : skip this node (no value for now)
 * @retval MFD_ERROR           : Any other error
 */
int
dot1qPortAcceptableFrameTypes_get( dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, u_long * dot1qPortAcceptableFrameTypes_val_ptr )
{
   /** we should have a non-NULL pointer */
   netsnmp_assert( NULL != dot1qPortAcceptableFrameTypes_val_ptr );


    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortAcceptableFrameTypes_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

/*
 * TODO:231:o: |-> Extract the current value of the dot1qPortAcceptableFrameTypes data.
 * copy (* dot1qPortAcceptableFrameTypes_val_ptr ) from rowreq_ctx->data
 */
    (* dot1qPortAcceptableFrameTypes_val_ptr ) = rowreq_ctx->data.dot1qPortAcceptableFrameTypes;

    return MFD_SUCCESS;
} /* dot1qPortAcceptableFrameTypes_get */


/**
 * Extract the current value of the dot1qPortIngressFiltering data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1qPortIngressFiltering_val_ptr
 *        Pointer to storage for a long variable
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_SKIP            : skip this node (no value for now)
 * @retval MFD_ERROR           : Any other error
 */
int
dot1qPortIngressFiltering_get( dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, u_long * dot1qPortIngressFiltering_val_ptr )
{
   /** we should have a non-NULL pointer */
   netsnmp_assert( NULL != dot1qPortIngressFiltering_val_ptr );


    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortIngressFiltering_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

/*
 * TODO:231:o: |-> Extract the current value of the dot1qPortIngressFiltering data.
 * copy (* dot1qPortIngressFiltering_val_ptr ) from rowreq_ctx->data
 */
    (* dot1qPortIngressFiltering_val_ptr ) = rowreq_ctx->data.dot1qPortIngressFiltering;

    return MFD_SUCCESS;
} /* dot1qPortIngressFiltering_get */

/**
 * Extract the current value of the dot1qPortGvrpStatus data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1qPortGvrpStatus_val_ptr
 *        Pointer to storage for a long variable
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_SKIP            : skip this node (no value for now)
 * @retval MFD_ERROR           : Any other error
 */
int
dot1qPortGvrpStatus_get( dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, u_long * dot1qPortGvrpStatus_val_ptr )
{
   /** we should have a non-NULL pointer */
   netsnmp_assert( NULL != dot1qPortGvrpStatus_val_ptr );


    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortGvrpStatus_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

/*
 * TODO:231:o: |-> Extract the current value of the dot1qPortGvrpStatus data.
 * copy (* dot1qPortGvrpStatus_val_ptr ) from rowreq_ctx->data
 */
    (* dot1qPortGvrpStatus_val_ptr ) = rowreq_ctx->data.dot1qPortGvrpStatus;

    return MFD_SUCCESS;
} /* dot1qPortGvrpStatus_get */

/*---------------------------------------------------------------------
 * Q-BRIDGE-MIB::dot1qPortVlanEntry.dot1qPortGvrpFailedRegistrations
 * dot1qPortGvrpFailedRegistrations is subid 5 of dot1qPortVlanEntry.
 * Its status is Current, and its access level is ReadOnly.
 * OID: .1.3.6.1.2.1.17.7.1.4.5.1.5
 * Description:
The total number of failed GVRP registrations, for any
        reason, on this port.
 *
 * Attributes:
 *   accessible 1     isscalar 0     enums  0      hasdefval 0
 *   readable   1     iscolumn 1     ranges 0      hashint   0
 *   settable   0
 *
 *
 * Its syntax is COUNTER (based on perltype COUNTER)
 * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long)
 */
/**
 * Extract the current value of the dot1qPortGvrpFailedRegistrations data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1qPortGvrpFailedRegistrations_val_ptr
 *        Pointer to storage for a u_long variable
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_SKIP            : skip this node (no value for now)
 * @retval MFD_ERROR           : Any other error
 */
int
dot1qPortGvrpFailedRegistrations_get( dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, u_long * dot1qPortGvrpFailedRegistrations_val_ptr )
{
   /** we should have a non-NULL pointer */
   netsnmp_assert( NULL != dot1qPortGvrpFailedRegistrations_val_ptr );


    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortGvrpFailedRegistrations_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

/*
 * TODO:231:o: |-> Extract the current value of the dot1qPortGvrpFailedRegistrations data.
 * copy (* dot1qPortGvrpFailedRegistrations_val_ptr ) from rowreq_ctx->data
 */
    (* dot1qPortGvrpFailedRegistrations_val_ptr ) = rowreq_ctx->data.dot1qPortGvrpFailedRegistrations;

    return MFD_SUCCESS;
} /* dot1qPortGvrpFailedRegistrations_get */

/*---------------------------------------------------------------------
 * Q-BRIDGE-MIB::dot1qPortVlanEntry.dot1qPortGvrpLastPduOrigin
 * dot1qPortGvrpLastPduOrigin is subid 6 of dot1qPortVlanEntry.
 * Its status is Current, and its access level is ReadOnly.
 * OID: .1.3.6.1.2.1.17.7.1.4.5.1.6
 * Description:
The Source MAC Address of the last GVRP message
        received on this port.
 *
 * Attributes:
 *   accessible 1     isscalar 0     enums  0      hasdefval 0
 *   readable   1     iscolumn 1     ranges 1      hashint   1
 *   settable   0
 *   hint: 1x:
 *
 * Ranges:  6;
 *
 * Its syntax is MacAddress (based on perltype OCTETSTR)
 * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char)
 * This data type requires a length.  (Max 6)
 */
/**
 * Extract the current value of the dot1qPortGvrpLastPduOrigin data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1qPortGvrpLastPduOrigin_val_ptr_ptr
 *        Pointer to storage for a char variable
 * @param dot1qPortGvrpLastPduOrigin_val_ptr_len_ptr
 *        Pointer to a size_t. On entry, it will contain the size (in bytes)
 *        pointed to by dot1qPortGvrpLastPduOrigin.
 *        On exit, this value should contain the data size (in bytes).
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_SKIP            : skip this node (no value for now)
 * @retval MFD_ERROR           : Any other error
*
 * @note If you need more than (*dot1qPortGvrpLastPduOrigin_val_ptr_len_ptr) bytes of memory,
 *       allocate it using malloc() and update dot1qPortGvrpLastPduOrigin_val_ptr_ptr.
 *       <b>DO NOT</b> free the previous pointer.
 *       The MFD helper will release the memory you allocate.
 *
 * @remark If you call this function yourself, you are responsible
 *         for checking if the pointer changed, and freeing any
 *         previously allocated memory. (Not necessary if you pass
 *         in a pointer to static memory, obviously.)
 */
int
dot1qPortGvrpLastPduOrigin_get( dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, char **dot1qPortGvrpLastPduOrigin_val_ptr_ptr, size_t *dot1qPortGvrpLastPduOrigin_val_ptr_len_ptr )
{
   /** we should have a non-NULL pointer and enough storage */
   netsnmp_assert( (NULL != dot1qPortGvrpLastPduOrigin_val_ptr_ptr) && (NULL != *dot1qPortGvrpLastPduOrigin_val_ptr_ptr));
   netsnmp_assert( NULL != dot1qPortGvrpLastPduOrigin_val_ptr_len_ptr );


    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortGvrpLastPduOrigin_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

/*
 * TODO:231:o: |-> Extract the current value of the dot1qPortGvrpLastPduOrigin data.
 * copy (* dot1qPortGvrpLastPduOrigin_val_ptr_ptr ) data and (* dot1qPortGvrpLastPduOrigin_val_ptr_len_ptr ) from rowreq_ctx->data
 */
    /*
     * make sure there is enough space for dot1qPortGvrpLastPduOrigin data
     */
    if ((NULL == (* dot1qPortGvrpLastPduOrigin_val_ptr_ptr )) ||
        ((* dot1qPortGvrpLastPduOrigin_val_ptr_len_ptr ) <
         (rowreq_ctx->data.dot1qPortGvrpLastPduOrigin_len* sizeof(rowreq_ctx->data.dot1qPortGvrpLastPduOrigin[0])))) {
        /*
         * allocate space for dot1qPortGvrpLastPduOrigin data
         */
        (* dot1qPortGvrpLastPduOrigin_val_ptr_ptr ) = malloc(rowreq_ctx->data.dot1qPortGvrpLastPduOrigin_len* sizeof(rowreq_ctx->data.dot1qPortGvrpLastPduOrigin[0]));
        if(NULL == (* dot1qPortGvrpLastPduOrigin_val_ptr_ptr )) {
            snmp_log(LOG_ERR,"could not allocate memory (rowreq_ctx->data.dot1qPortGvrpLastPduOrigin)\n");
            return MFD_ERROR;
        }
    }
    (* dot1qPortGvrpLastPduOrigin_val_ptr_len_ptr ) = rowreq_ctx->data.dot1qPortGvrpLastPduOrigin_len* sizeof(rowreq_ctx->data.dot1qPortGvrpLastPduOrigin[0]);
    memcpy( (* dot1qPortGvrpLastPduOrigin_val_ptr_ptr ), rowreq_ctx->data.dot1qPortGvrpLastPduOrigin, rowreq_ctx->data.dot1qPortGvrpLastPduOrigin_len* sizeof(rowreq_ctx->data.dot1qPortGvrpLastPduOrigin[0]) );

    return MFD_SUCCESS;
} /* dot1qPortGvrpLastPduOrigin_get */


/**
 * Extract the current value of the dot1qPortRestrictedVlanRegistration data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1qPortRestrictedVlanRegistration_val_ptr
 *        Pointer to storage for a long variable
 *
 * @retval MFD_SUCCESS         : success
 * @retval MFD_SKIP            : skip this node (no value for now)
 * @retval MFD_ERROR           : Any other error
 */
int
dot1qPortRestrictedVlanRegistration_get( dot1qPortVlanTable_rowreq_ctx *rowreq_ctx, u_long * dot1qPortRestrictedVlanRegistration_val_ptr )
{
   /** we should have a non-NULL pointer */
   netsnmp_assert( NULL != dot1qPortRestrictedVlanRegistration_val_ptr );


    DEBUGMSGTL(("verbose:dot1qPortVlanTable:dot1qPortRestrictedVlanRegistration_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

/*
 * TODO:231:o: |-> Extract the current value of the dot1qPortRestrictedVlanRegistration data.
 * copy (* dot1qPortRestrictedVlanRegistration_val_ptr ) from rowreq_ctx->data
 */
    (* dot1qPortRestrictedVlanRegistration_val_ptr ) = rowreq_ctx->data.dot1qPortRestrictedVlanRegistration;

    return MFD_SUCCESS;
} /* dot1qPortRestrictedVlanRegistration_get */



/** @} */
