/*							-- DO NOT EDIT --
 * This file has been generated by smidump
 * version 0.3.1 for the scli package.
 *
 * Derived from ATM-MIB:
 *   This is the MIB Module for ATM and AAL5-related
 *   objects for managing ATM interfaces, ATM virtual
 *   links, ATM cross-connects, AAL5 entities, and
 *   and AAL5 connections.
 *
 * Revision 1998-10-19 12:00:
 *   The initial revision of this module was published
 *   as RFC 1695. Key revisions include:
 *   o  Textual Conventions and OBJECT IDENTITIES have
 *      been moved to a separate MIB module.
 *   o  Applicability of objects to PVCs, SVCs and Soft
 *      PVCs has been clarified.
 *   o  DEFVAL clauses have been added.
 *   o  The relationship of ifIndex values with different
 *      layers and sublayers related to ATM has been
 *      clarified.
 *   o  atmTrafficQosClass has been deprecated
 *      and replaced with atmServiceCategory.
 *   o  atmInterfaceCurrentMaxVpiBits and
 *      atmInterfaceCurrentMaxVciBits have been added with
 *      a description on their relationship with other
 *      objects.
 *   o  atmInterfaceAddressType and atmInterfaceAdminAddress
 *      have been deprecated and replaced by
 *      atmInterfaceSubscrAddress.
 *   o  atmInterfaceTCAlarmState has been clarified.
 *   o  atmTrafficDescrParamIndexNext has been introduced
 *      in order to provide a manager a free
 *      atmTrafficDescrParamIndex value.
 *   o  The atmTrafficFrameDiscard capability has been added.
 *   o  A connection topology type (atmVpl/VclCastType) and
 *      a call control type (atmVpl/VclConnKind) have been
 *      added.
 *   o  aal2 has been added to atmVccAalType.
 *
 * Revision 1994-06-07 22:45:
 *   The RFC1695 version of this MIB module.
 *
 * $Id: atm-mib.c,v 1.14 2002/03/27 13:48:21 schoenw Exp $
 */

#include "atm-mib.h"

GSnmpEnum const atm_mib_enums_atmInterfaceAddressType[] = {
    { ATM_MIB_ATMINTERFACEADDRESSTYPE_PRIVATE,    "private" },
    { ATM_MIB_ATMINTERFACEADDRESSTYPE_NSAPE164,   "nsapE164" },
    { ATM_MIB_ATMINTERFACEADDRESSTYPE_NATIVEE164, "nativeE164" },
    { ATM_MIB_ATMINTERFACEADDRESSTYPE_OTHER,      "other" },
    { 0, NULL }
};


static guint32 atmInterfaceMaxVpcs_constraints[] = {0L, 4096L, 0, 0};
static guint32 atmInterfaceMaxVccs_constraints[] = {0L, 65536L, 0, 0};
static guint32 atmInterfaceConfVpcs_constraints[] = {0L, 4096L, 0, 0};
static guint32 atmInterfaceConfVccs_constraints[] = {0L, 65536L, 0, 0};
static guint32 atmInterfaceMaxActiveVpiBits_constraints[] = {0L, 12L, 0, 0};
static guint32 atmInterfaceMaxActiveVciBits_constraints[] = {0L, 16L, 0, 0};
static guint32 atmInterfaceIlmiVpi_constraints[] = {0L, 4095L, 0, 0};
static guint32 atmInterfaceIlmiVci_constraints[] = {0L, 65535L, 0, 0};
static guint16 atmInterfaceAdminAddress_constraints[] = {0, 40, 0, 0};
static guint16 atmInterfaceMyNeighborIpAddress_constraints[] = {4, 4, 0, 0};
static guint16 atmInterfaceMyNeighborIfName_constraints[] = {0, 255, 0, 0};
static guint32 atmInterfaceCurrentMaxVpiBits_constraints[] = {0L, 12L, 0, 0};
static guint32 atmInterfaceCurrentMaxVciBits_constraints[] = {0L, 16L, 0, 0};
static guint16 atmInterfaceSubscrAddress_constraints[] = {0, 40, 0, 0};


static guint32 const atmInterfaceConfEntry_oid[] = {1, 3, 6, 1, 2, 1, 37, 1, 2, 1};

static GSnmpAttribute atmInterfaceConfEntry_attr[] = {
    { 1, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACEMAXVPCS, "atmInterfaceMaxVpcs",
       atmInterfaceMaxVpcs_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceMaxVpcs),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 2, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACEMAXVCCS, "atmInterfaceMaxVccs",
       atmInterfaceMaxVccs_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceMaxVccs),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 3, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACECONFVPCS, "atmInterfaceConfVpcs",
       atmInterfaceConfVpcs_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceConfVpcs),
      0,
      0 },
    { 4, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACECONFVCCS, "atmInterfaceConfVccs",
       atmInterfaceConfVccs_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceConfVccs),
      0,
      0 },
    { 5, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACEMAXACTIVEVPIBITS, "atmInterfaceMaxActiveVpiBits",
       atmInterfaceMaxActiveVpiBits_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceMaxActiveVpiBits),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 6, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACEMAXACTIVEVCIBITS, "atmInterfaceMaxActiveVciBits",
       atmInterfaceMaxActiveVciBits_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceMaxActiveVciBits),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 7, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACEILMIVPI, "atmInterfaceIlmiVpi",
       atmInterfaceIlmiVpi_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceIlmiVpi),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 8, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACEILMIVCI, "atmInterfaceIlmiVci",
       atmInterfaceIlmiVci_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceIlmiVci),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 9, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACEADDRESSTYPE, "atmInterfaceAddressType",
       NULL,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceAddressType),
      0,
      0 },
    { 10, G_SNMP_OCTETSTRING,
      ATM_MIB_ATMINTERFACEADMINADDRESS, "atmInterfaceAdminAddress",
       atmInterfaceAdminAddress_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceAdminAddress),
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, _atmInterfaceAdminAddressLength),
      0 },
    { 11, G_SNMP_IPADDRESS,
      ATM_MIB_ATMINTERFACEMYNEIGHBORIPADDRESS, "atmInterfaceMyNeighborIpAddress",
       atmInterfaceMyNeighborIpAddress_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceMyNeighborIpAddress),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 12, G_SNMP_OCTETSTRING,
      ATM_MIB_ATMINTERFACEMYNEIGHBORIFNAME, "atmInterfaceMyNeighborIfName",
       atmInterfaceMyNeighborIfName_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceMyNeighborIfName),
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, _atmInterfaceMyNeighborIfNameLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 13, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACECURRENTMAXVPIBITS, "atmInterfaceCurrentMaxVpiBits",
       atmInterfaceCurrentMaxVpiBits_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceCurrentMaxVpiBits),
      0,
      0 },
    { 14, G_SNMP_INTEGER32,
      ATM_MIB_ATMINTERFACECURRENTMAXVCIBITS, "atmInterfaceCurrentMaxVciBits",
       atmInterfaceCurrentMaxVciBits_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceCurrentMaxVciBits),
      0,
      0 },
    { 15, G_SNMP_OCTETSTRING,
      ATM_MIB_ATMINTERFACESUBSCRADDRESS, "atmInterfaceSubscrAddress",
       atmInterfaceSubscrAddress_constraints,
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, atmInterfaceSubscrAddress),
      G_STRUCT_OFFSET(atm_mib_atmInterfaceConfEntry_t, _atmInterfaceSubscrAddressLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 0, 0, 0, NULL }
};


atm_mib_atmInterfaceConfEntry_t *
atm_mib_new_atmInterfaceConfEntry()
{
    atm_mib_atmInterfaceConfEntry_t *atmInterfaceConfEntry;

    atmInterfaceConfEntry = (atm_mib_atmInterfaceConfEntry_t *) g_malloc0(sizeof(atm_mib_atmInterfaceConfEntry_t) + sizeof(gpointer));
    return atmInterfaceConfEntry;
}

static int
unpack_atmInterfaceConfEntry(GSnmpVarBind *vb, atm_mib_atmInterfaceConfEntry_t *atmInterfaceConfEntry)
{
    guint8 idx = 11;

    if (vb->id_len < idx) return -1;
    atmInterfaceConfEntry->ifIndex = vb->id[idx++];
    if (vb->id_len > idx) return -1;
    return 0;
}

static int
pack_atmInterfaceConfEntry(guint32 *base, gint32 ifIndex)
{
    guint8 idx = 11;

    base[idx++] = ifIndex;
    return idx;
}

static atm_mib_atmInterfaceConfEntry_t *
assign_atmInterfaceConfEntry(GSList *vbl)
{
    atm_mib_atmInterfaceConfEntry_t *atmInterfaceConfEntry;
    char *p;

    atmInterfaceConfEntry = atm_mib_new_atmInterfaceConfEntry();
    if (! atmInterfaceConfEntry) {
        return NULL;
    }

    p = (char *) atmInterfaceConfEntry + sizeof(atm_mib_atmInterfaceConfEntry_t);
    * (GSList **) p = vbl;

    if (unpack_atmInterfaceConfEntry((GSnmpVarBind *) vbl->data, atmInterfaceConfEntry) < 0) {
        g_warning("%s: invalid instance identifier", "atmInterfaceConfEntry");
        g_free(atmInterfaceConfEntry);
        return NULL;
    }

    gsnmp_attr_assign(vbl, atmInterfaceConfEntry_oid, sizeof(atmInterfaceConfEntry_oid)/sizeof(guint32),
                      atmInterfaceConfEntry_attr, atmInterfaceConfEntry);

    return atmInterfaceConfEntry;
}

void
atm_mib_get_atmInterfaceConfTable(GSnmpSession *s, atm_mib_atmInterfaceConfEntry_t ***atmInterfaceConfEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    GSList *row;
    int i;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 37, 1, 2, 1, 0};

    *atmInterfaceConfEntry = NULL;

    gsnmp_attr_get(s, &in, base, 11, 10, atmInterfaceConfEntry_attr, mask);

    out = gsnmp_gettable(s, in);
    /* g_snmp_vbl_free(in); */

    if (out) {
        *atmInterfaceConfEntry = (atm_mib_atmInterfaceConfEntry_t **) g_malloc0((g_slist_length(out) + 1) * sizeof(atm_mib_atmInterfaceConfEntry_t *));
        if (! *atmInterfaceConfEntry) {
            s->error_status = G_SNMP_ERR_INTERNAL;
            g_snmp_vbl_free(out);
            return;
        }
        for (row = out, i = 0; row; row = g_slist_next(row), i++) {
            (*atmInterfaceConfEntry)[i] = assign_atmInterfaceConfEntry(row->data);
        }
    }
}

void
atm_mib_get_atmInterfaceConfEntry(GSnmpSession *s, atm_mib_atmInterfaceConfEntry_t **atmInterfaceConfEntry, gint32 ifIndex, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, atmInterfaceConfEntry_oid, sizeof(atmInterfaceConfEntry_oid));
    len = pack_atmInterfaceConfEntry(base, ifIndex);
    if (len < 0) {
        g_warning("%s: invalid index values", "atmInterfaceConfEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    *atmInterfaceConfEntry = NULL;

    gsnmp_attr_get(s, &in, base, len, 10, atmInterfaceConfEntry_attr, mask);

    out = g_snmp_session_sync_get(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        if (s->error_status != G_SNMP_ERR_NOERROR) {
            g_snmp_vbl_free(out);
            return;
        }
        *atmInterfaceConfEntry = assign_atmInterfaceConfEntry(out);
    }
}

void
atm_mib_set_atmInterfaceConfEntry(GSnmpSession *s, atm_mib_atmInterfaceConfEntry_t *atmInterfaceConfEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, atmInterfaceConfEntry_oid, sizeof(atmInterfaceConfEntry_oid));
    len = pack_atmInterfaceConfEntry(base, atmInterfaceConfEntry->ifIndex);
    if (len < 0) {
        g_warning("%s: invalid index values", "atmInterfaceConfEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    gsnmp_attr_set(s, &in, base, len, 10, atmInterfaceConfEntry_attr, mask, atmInterfaceConfEntry);

    out = g_snmp_session_sync_set(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        g_snmp_vbl_free(out);
    }
}

void
atm_mib_free_atmInterfaceConfEntry(atm_mib_atmInterfaceConfEntry_t *atmInterfaceConfEntry)
{
    GSList *vbl;
    char *p;

    if (atmInterfaceConfEntry) {
        p = (char *) atmInterfaceConfEntry + sizeof(atm_mib_atmInterfaceConfEntry_t);
        vbl = * (GSList **) p;
        g_snmp_vbl_free(vbl);
        g_free(atmInterfaceConfEntry);
    }
}

void
atm_mib_free_atmInterfaceConfTable(atm_mib_atmInterfaceConfEntry_t **atmInterfaceConfEntry)
{
    int i;

    if (atmInterfaceConfEntry) {
        for (i = 0; atmInterfaceConfEntry[i]; i++) {
            atm_mib_free_atmInterfaceConfEntry(atmInterfaceConfEntry[i]);
        }
        g_free(atmInterfaceConfEntry);
    }
}


