/*
 * Note: this file originally auto-generated by mib2c using
 *        $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "dot1qBase.h"
#include "wrsSnmp.h"
#include "snmp_shmem.h"

/** Initializes the dot1qBase module */
void
init_dot1qBase(void)
{
    const oid dot1qVlanVersionNumber_oid[] = { 1,3,6,1,2,1,17,7,1,1,1 };
    const oid dot1qMaxVlanId_oid[] = { 1,3,6,1,2,1,17,7,1,1,2 };
    const oid dot1qMaxSupportedVlans_oid[] = { 1,3,6,1,2,1,17,7,1,1,3 };
    const oid dot1qNumVlans_oid[] = { 1,3,6,1,2,1,17,7,1,1,4 };
    const oid dot1qGvrpStatus_oid[] = { 1,3,6,1,2,1,17,7,1,1,5 };

  DEBUGMSGTL(("dot1qBase", "Initializing\n"));

    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1qVlanVersionNumber", handle_dot1qVlanVersionNumber,
                               dot1qVlanVersionNumber_oid, OID_LENGTH(dot1qVlanVersionNumber_oid),
                               HANDLER_CAN_RONLY
        ));
    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1qMaxVlanId", handle_dot1qMaxVlanId,
                               dot1qMaxVlanId_oid, OID_LENGTH(dot1qMaxVlanId_oid),
                               HANDLER_CAN_RONLY
        ));
    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1qMaxSupportedVlans", handle_dot1qMaxSupportedVlans,
                               dot1qMaxSupportedVlans_oid, OID_LENGTH(dot1qMaxSupportedVlans_oid),
                               HANDLER_CAN_RONLY
        ));
    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1qNumVlans", handle_dot1qNumVlans,
                               dot1qNumVlans_oid, OID_LENGTH(dot1qNumVlans_oid),
                               HANDLER_CAN_RONLY
        ));
    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1qGvrpStatus", handle_dot1qGvrpStatus,
                               dot1qGvrpStatus_oid, OID_LENGTH(dot1qGvrpStatus_oid),
                               HANDLER_CAN_RWRITE
        ));
}

int
handle_dot1qVlanVersionNumber(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */
    int dot1qVlanVersionNumber;
    dot1qVlanVersionNumber = DOT1QVLANVERSIONNUMBER;
    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     &dot1qVlanVersionNumber,
                                     sizeof(dot1qVlanVersionNumber));
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_dot1qVlanVersionNumber\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
int
handle_dot1qMaxVlanId(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */
    int dot1qMaxVlanId;
    dot1qMaxVlanId = RTU_VID_MAX;
    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     &dot1qMaxVlanId,
                                     sizeof(dot1qMaxVlanId));
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_dot1qMaxVlanId\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
int
handle_dot1qMaxSupportedVlans(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */
    int dot1qMaxSupportedVlans;
    dot1qMaxSupportedVlans = RTU_VID_MAX;
    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED,
                                     &dot1qMaxSupportedVlans,
                                     sizeof(dot1qMaxSupportedVlans));
            break;


        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_dot1qMaxSupportedVlans\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
int
handle_dot1qNumVlans(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */
    int nvlans = 0;
    int i;
    struct rtu_vlan_table_entry vlan_tab_local[NUM_VLANS];

    switch(reqinfo->mode) {

        case MODE_GET:
	    if (0 != shmem_rtu_read_vlans(vlan_tab_local)) {
		return SNMP_ERR_GENERR;
	    }

	    for (i = 0; i < NUM_VLANS; i++) {
		if ((vlan_tab_local[i].drop != 0)
		    && (vlan_tab_local[i].port_mask == 0x0))
			continue;
		nvlans++;
	    }

            snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED,
                                     &nvlans,
                                     sizeof(nvlans));
            break;


        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_dot1qNumVlans\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
int
handle_dot1qGvrpStatus(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */
    int dot1qGvrpStatus;
    dot1qGvrpStatus = DOT1QGVRPSTATUS_DISABLED;
    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     &dot1qGvrpStatus,
                                     sizeof(dot1qGvrpStatus));
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_dot1qGvrpStatus\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
