/*
 * Note: this file originally auto-generated by mib2c using
 * mib2c -c mib2c.scalar.conf BRIDGE-MIB::dot1dBase
 *        $
 */

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

/** Initializes the dot1dBase module */
void
init_dot1dBase(void)
{
    const oid dot1dBaseBridgeAddress_oid[] = { 1,3,6,1,2,1,17,1,1 };
    const oid dot1dBaseNumPorts_oid[] = { 1,3,6,1,2,1,17,1,2 };
    const oid dot1dBaseType_oid[] = { 1,3,6,1,2,1,17,1,3 };

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

    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1dBaseBridgeAddress", handle_dot1dBaseBridgeAddress,
                               dot1dBaseBridgeAddress_oid, OID_LENGTH(dot1dBaseBridgeAddress_oid),
                               HANDLER_CAN_RONLY
        ));
    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1dBaseNumPorts", handle_dot1dBaseNumPorts,
                               dot1dBaseNumPorts_oid, OID_LENGTH(dot1dBaseNumPorts_oid),
                               HANDLER_CAN_RONLY
        ));
    netsnmp_register_scalar(
        netsnmp_create_handler_registration("dot1dBaseType", handle_dot1dBaseType,
                               dot1dBaseType_oid, OID_LENGTH(dot1dBaseType_oid),
                               HANDLER_CAN_RONLY
        ));
}

int
handle_dot1dBaseBridgeAddress(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 i;

    switch(reqinfo->mode) {

        case MODE_GET:
            /* look for a first port */
            for (i = 0; i < hal_nports_local; i++) {
                if (!strcmp(hal_ports[i].name, FIRST_PORT_NAME)) {
                    /* First port found */
                    snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                     hal_ports[i].hw_addr,
                                     ETH_ALEN);
                    /* no need for more checks */
                    return SNMP_ERR_NOERROR;
                }
            }
            snmp_log(LOG_ERR, "Port name (%s) not found for handle_dot1dBaseBridgeAddress!\n", FIRST_PORT_NAME);
            return SNMP_ERR_GENERR;

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

    return SNMP_ERR_NOERROR;
}
int
handle_dot1dBaseNumPorts(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. */

    /* Get the port number from HAL */
    int port_num = hal_nports_local;
    switch(reqinfo->mode) {

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


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

    return SNMP_ERR_NOERROR;
}
int
handle_dot1dBaseType(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 baseType = BASETYPE_TRANSPARENT_ONLY;
    switch(reqinfo->mode) {

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


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

    return SNMP_ERR_NOERROR;
}
