/*
 * 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 "dot1dStaticTable.h"


/** @defgroup data_get data_get: Routines to get data
 *
 * TODO:230:M: Implement dot1dStaticTable get routines.
 * TODO:240:M: Implement dot1dStaticTable 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 dot1dStaticTable
 ***
 **********************************************************************
 **********************************************************************/
/*
 * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic.
 * Its status is Current.
 * OID: .1.3.6.1.2.1.17.5.1, length: 9
*/

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


/**
 * set mib index(es)
 *
 * @param tbl_idx mib index structure
 * @param dot1dStaticAddress_ptr
 * @param dot1dStaticAddress_ptr_len
 * @param dot1dStaticReceivePort_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
dot1dStaticTable_indexes_set_tbl_idx(dot1dStaticTable_mib_index *tbl_idx, char *dot1dStaticAddress_val_ptr,  size_t dot1dStaticAddress_val_ptr_len, long dot1dStaticReceivePort_val)
{
    DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_indexes_set_tbl_idx","called\n"));

    /* dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */
    tbl_idx->dot1dStaticAddress_len = sizeof(tbl_idx->dot1dStaticAddress)/sizeof(tbl_idx->dot1dStaticAddress[0]); /* max length */
    /*
     * make sure there is enough space for dot1dStaticAddress data
     */
    if ((NULL == tbl_idx->dot1dStaticAddress) ||
        (tbl_idx->dot1dStaticAddress_len <
         (dot1dStaticAddress_val_ptr_len))) {
        snmp_log(LOG_ERR,"not enough space for value (dot1dStaticAddress_val_ptr)\n");
        return MFD_ERROR;
    }
    tbl_idx->dot1dStaticAddress_len = dot1dStaticAddress_val_ptr_len;
    memcpy( tbl_idx->dot1dStaticAddress, dot1dStaticAddress_val_ptr, dot1dStaticAddress_val_ptr_len* sizeof(dot1dStaticAddress_val_ptr[0]) );
    
    /* dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h */
    tbl_idx->dot1dStaticReceivePort = dot1dStaticReceivePort_val;
    

    return MFD_SUCCESS;
} /* dot1dStaticTable_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
dot1dStaticTable_indexes_set(dot1dStaticTable_rowreq_ctx *rowreq_ctx, char *dot1dStaticAddress_val_ptr,  size_t dot1dStaticAddress_val_ptr_len, long dot1dStaticReceivePort_val)
{
    DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_indexes_set","called\n"));

    if(MFD_SUCCESS != dot1dStaticTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx
                                   , dot1dStaticAddress_val_ptr, dot1dStaticAddress_val_ptr_len
                                   , dot1dStaticReceivePort_val
           ))
        return MFD_ERROR;

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

    return MFD_SUCCESS;
} /* dot1dStaticTable_indexes_set */


/*---------------------------------------------------------------------
 * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticAllowedToGoTo
 * dot1dStaticAllowedToGoTo is subid 3 of dot1dStaticEntry.
 * Its status is Current, and its access level is Create.
 * OID: .1.3.6.1.2.1.17.5.1.1.3
 * Description:
The set of ports to which frames received from a
        specific port and destined for a specific MAC address,
        are allowed to be forwarded.  Each octet within the
        value of this object specifies a set of eight ports,
        with the first octet specifying ports 1 through 8, the
        second octet specifying ports 9 through 16, etc.  Within
        each octet, the most significant bit represents the
        lowest numbered port, and the least significant bit
        represents the highest numbered port.  Thus, each port
        of the bridge is represented by a single bit within the
        value of this object.  If that bit has a value of '1',
        then that port is included in the set of ports; the port
        is not included if its bit has a value of '0'.  (Note
        that the setting of the bit corresponding to the port
        from which a frame is received is irrelevant.)  The
        default value of this object is a string of ones of
        appropriate length.

        The value of this object may exceed the required minimum
        maximum message size of some SNMP transport (484 bytes,
        in the case of SNMP over UDP, see RFC 3417, section 3.2).
        SNMP engines on bridges supporting a large number of
        ports must support appropriate maximum message sizes.
 *
 * Attributes:
 *   accessible 1     isscalar 0     enums  0      hasdefval 0
 *   readable   1     iscolumn 1     ranges 1      hashint   0
 *   settable   1
 *
 * Ranges:  0 - 512;
 *
 * Its syntax is OCTETSTR (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 512)
 */
/**
 * Extract the current value of the dot1dStaticAllowedToGoTo data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1dStaticAllowedToGoTo_val_ptr_ptr
 *        Pointer to storage for a char variable
 * @param dot1dStaticAllowedToGoTo_val_ptr_len_ptr
 *        Pointer to a size_t. On entry, it will contain the size (in bytes)
 *        pointed to by dot1dStaticAllowedToGoTo.
 *        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 (*dot1dStaticAllowedToGoTo_val_ptr_len_ptr) bytes of memory,
 *       allocate it using malloc() and update dot1dStaticAllowedToGoTo_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
dot1dStaticAllowedToGoTo_get( dot1dStaticTable_rowreq_ctx *rowreq_ctx, char **dot1dStaticAllowedToGoTo_val_ptr_ptr, size_t *dot1dStaticAllowedToGoTo_val_ptr_len_ptr )
{
   /** we should have a non-NULL pointer and enough storage */
   netsnmp_assert( (NULL != dot1dStaticAllowedToGoTo_val_ptr_ptr) && (NULL != *dot1dStaticAllowedToGoTo_val_ptr_ptr));
   netsnmp_assert( NULL != dot1dStaticAllowedToGoTo_val_ptr_len_ptr );


    DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticAllowedToGoTo_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

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

    return MFD_SUCCESS;
} /* dot1dStaticAllowedToGoTo_get */

/*---------------------------------------------------------------------
 * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticStatus
 * dot1dStaticStatus is subid 4 of dot1dStaticEntry.
 * Its status is Current, and its access level is Create.
 * OID: .1.3.6.1.2.1.17.5.1.1.4
 * Description:
This object indicates the status of this entry.
        The default value is permanent(3).
            other(1) - this entry is currently in use but the
                conditions under which it will remain so are
                different from each of the following values.
            invalid(2) - writing this value to the object
                removes the corresponding entry.
            permanent(3) - this entry is currently in use and
                will remain so after the next reset of the
                bridge.
            deleteOnReset(4) - this entry is currently in use
                and will remain so until the next reset of the
                bridge.
            deleteOnTimeout(5) - this entry is currently in use
                and will remain so until it is aged out.
 *
 * Attributes:
 *   accessible 1     isscalar 0     enums  1      hasdefval 0
 *   readable   1     iscolumn 1     ranges 0      hashint   0
 *   settable   1
 *
 * Enum range: 3/8. Values:  other(1), invalid(2), permanent(3), deleteOnReset(4), deleteOnTimeout(5)
 *
 * 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-dot1dStaticStatus.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
dot1dStaticStatus_map(u_long *mib_dot1dStaticStatus_val_ptr, u_long raw_dot1dStaticStatus_val)
{
    netsnmp_assert(NULL != mib_dot1dStaticStatus_val_ptr);
    
    DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticStatus_map","called\n"));
    
    /*
     * TODO:241:o: |-> Implement dot1dStaticStatus enum mapping.
     * uses INTERNAL_* macros defined in the header files
     */
    switch(raw_dot1dStaticStatus_val) {
        case RTU_ENTRY_TYPE_STATIC:
             *mib_dot1dStaticStatus_val_ptr = DOT1DSTATICSTATUS_PERMANENT;
             break;

         default:
             *mib_dot1dStaticStatus_val_ptr = DOT1DSTATICSTATUS_OTHER;
    }

    return MFD_SUCCESS;
} /* dot1dStaticStatus_map */

/**
 * Extract the current value of the dot1dStaticStatus data.
 *
 * Set a value using the data context for the row.
 *
 * @param rowreq_ctx
 *        Pointer to the row request context.
 * @param dot1dStaticStatus_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
dot1dStaticStatus_get( dot1dStaticTable_rowreq_ctx *rowreq_ctx, u_long * dot1dStaticStatus_val_ptr )
{
   /** we should have a non-NULL pointer */
   netsnmp_assert( NULL != dot1dStaticStatus_val_ptr );


    DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticStatus_get","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

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

    return MFD_SUCCESS;
} /* dot1dStaticStatus_get */



/** @} */
