[go: up one dir, main page]

File: entity-sensor-mib.c

package info (click to toggle)
scli 0.3.1-3.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,872 kB
  • ctags: 8,627
  • sloc: ansic: 32,657; sh: 7,388; makefile: 321
file content (264 lines) | stat: -rw-r--r-- 9,630 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*							-- DO NOT EDIT --
 * Generated by smidump version 0.4.3:
 *   smidump -f scli ENTITY-SENSOR-MIB
 *
 * Derived from ENTITY-SENSOR-MIB:
 *   This module defines Entity MIB extensions for physical
 *   sensors.
 *   
 *   Copyright (C) The Internet Society (2002). This version
 *   of this MIB module is part of RFC 3433; see the RFC
 *   itself for full legal notices.
 *
 * Revision 2002-12-16 00:00:
 *   Initial version of the Entity Sensor MIB module, published
 *   as RFC 3433.
 *
 * $Id: entity-sensor-mib.c 1788 2006-02-21 20:47:18Z schoenw $
 */

#include "entity-sensor-mib.h"

GNetSnmpEnum const entity_sensor_mib_enums_EntitySensorDataType[] = {
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_OTHER,      "other" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_UNKNOWN,    "unknown" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_VOLTSAC,    "voltsAC" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_VOLTSDC,    "voltsDC" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_AMPERES,    "amperes" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_WATTS,      "watts" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_HERTZ,      "hertz" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_CELSIUS,    "celsius" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_PERCENTRH,  "percentRH" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_RPM,        "rpm" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_CMM,        "cmm" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATATYPE_TRUTHVALUE, "truthvalue" },
    { 0, NULL }
};

GNetSnmpEnum const entity_sensor_mib_enums_EntitySensorDataScale[] = {
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_YOCTO, "yocto" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_ZEPTO, "zepto" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_ATTO,  "atto" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_FEMTO, "femto" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_PICO,  "pico" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_NANO,  "nano" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_MICRO, "micro" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_MILLI, "milli" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_UNITS, "units" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_KILO,  "kilo" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_MEGA,  "mega" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_GIGA,  "giga" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_TERA,  "tera" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_EXA,   "exa" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_PETA,  "peta" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_ZETTA, "zetta" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORDATASCALE_YOTTA, "yotta" },
    { 0, NULL }
};

GNetSnmpEnum const entity_sensor_mib_enums_EntitySensorStatus[] = {
    { ENTITY_SENSOR_MIB_ENTITYSENSORSTATUS_OK,             "ok" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORSTATUS_UNAVAILABLE,    "unavailable" },
    { ENTITY_SENSOR_MIB_ENTITYSENSORSTATUS_NONOPERATIONAL, "nonoperational" },
    { 0, NULL }
};


static gint32 entPhySensorPrecision_constraints[] = {-8L, 9L, 0, 0};
static gint32 entPhySensorValue_constraints[] = {-1000000000L, 1000000000L, 0, 0};
static guint16 entPhySensorUnitsDisplay_constraints[] = {0U, 255U, 0, 0};


static guint32 const entPhySensorEntry_oid[] = {1, 3, 6, 1, 2, 1, 99, 1, 1, 1};

static GNetSnmpAttribute entPhySensorEntry_attr[] = {
    { 1, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      ENTITY_SENSOR_MIB_ENTPHYSENSORTYPE, "entPhySensorType",
       NULL,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorType),
      0,
      0 },
    { 2, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      ENTITY_SENSOR_MIB_ENTPHYSENSORSCALE, "entPhySensorScale",
       NULL,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorScale),
      0,
      0 },
    { 3, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      ENTITY_SENSOR_MIB_ENTPHYSENSORPRECISION, "entPhySensorPrecision",
       entPhySensorPrecision_constraints,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorPrecision),
      0,
      0 },
    { 4, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      ENTITY_SENSOR_MIB_ENTPHYSENSORVALUE, "entPhySensorValue",
       entPhySensorValue_constraints,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorValue),
      0,
      0 },
    { 5, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      ENTITY_SENSOR_MIB_ENTPHYSENSOROPERSTATUS, "entPhySensorOperStatus",
       NULL,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorOperStatus),
      0,
      0 },
    { 6, GNET_SNMP_VARBIND_TYPE_OCTETSTRING,
      ENTITY_SENSOR_MIB_ENTPHYSENSORUNITSDISPLAY, "entPhySensorUnitsDisplay",
       entPhySensorUnitsDisplay_constraints,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorUnitsDisplay),
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, _entPhySensorUnitsDisplayLength),
      0 },
    { 7, GNET_SNMP_VARBIND_TYPE_TIMETICKS,
      ENTITY_SENSOR_MIB_ENTPHYSENSORVALUETIMESTAMP, "entPhySensorValueTimeStamp",
       NULL,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorValueTimeStamp),
      0,
      0 },
    { 8, GNET_SNMP_VARBIND_TYPE_UNSIGNED32,
      ENTITY_SENSOR_MIB_ENTPHYSENSORVALUEUPDATERATE, "entPhySensorValueUpdateRate",
       NULL,
      G_STRUCT_OFFSET(entity_sensor_mib_entPhySensorEntry_t, entPhySensorValueUpdateRate),
      0,
      0 },
    { 0, 0, 0, NULL }
};


entity_sensor_mib_entPhySensorEntry_t *
entity_sensor_mib_new_entPhySensorEntry()
{
    entity_sensor_mib_entPhySensorEntry_t *entPhySensorEntry;

    entPhySensorEntry = (entity_sensor_mib_entPhySensorEntry_t *) g_malloc0(sizeof(entity_sensor_mib_entPhySensorEntry_t) + sizeof(gpointer));
    return entPhySensorEntry;
}

static inline int
unpack_entPhySensorEntry(GNetSnmpVarBind *vb, entity_sensor_mib_entPhySensorEntry_t *entPhySensorEntry)
{
    guint8 idx = 11;

    if (vb->oid_len < idx) return -1;
    entPhySensorEntry->entPhysicalIndex = vb->oid[idx++];
    if ((entPhySensorEntry->entPhysicalIndex < 1)) {
         return -1;
    }
    if (vb->oid_len > idx) return -1;
    return 0;
}

static inline gint8
pack_entPhySensorEntry(guint32 *base, gint32 entPhysicalIndex)
{
    guint8 idx = 11;

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

static inline entity_sensor_mib_entPhySensorEntry_t *
assign_entPhySensorEntry(GList *vbl)
{
    entity_sensor_mib_entPhySensorEntry_t *entPhySensorEntry;
    char *p;

    entPhySensorEntry = entity_sensor_mib_new_entPhySensorEntry();
    p = (char *) entPhySensorEntry + sizeof(entity_sensor_mib_entPhySensorEntry_t);
    * (GList **) p = vbl;

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

    gnet_snmp_attr_assign(vbl, entPhySensorEntry_oid, G_N_ELEMENTS(entPhySensorEntry_oid),
                      entPhySensorEntry_attr, entPhySensorEntry);

    return entPhySensorEntry;
}

void
entity_sensor_mib_get_entPhySensorTable(GNetSnmp *s, entity_sensor_mib_entPhySensorEntry_t ***entPhySensorEntry, gint64 mask)
{
    GList *in = NULL, *out = NULL;
    GList *row;
    int i;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 99, 1, 1, 1, 0};

    *entPhySensorEntry = NULL;

    gnet_snmp_attr_get(s, &in, base, 11, 10, entPhySensorEntry_attr, mask);

    out = gnet_snmp_sync_table(s, in);
    /* gnet_snmp_varbind_list_free(in); */

    if (out) {
        *entPhySensorEntry = (entity_sensor_mib_entPhySensorEntry_t **) g_malloc0((g_list_length(out) + 1) * sizeof(entity_sensor_mib_entPhySensorEntry_t *));
        for (row = out, i = 0; row; row = g_list_next(row), i++) {
            (*entPhySensorEntry)[i] = assign_entPhySensorEntry(row->data);
        }
    }
}

void
entity_sensor_mib_get_entPhySensorEntry(GNetSnmp *s, entity_sensor_mib_entPhySensorEntry_t **entPhySensorEntry, gint32 entPhysicalIndex, gint64 mask)
{
    GList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memcpy(base, entPhySensorEntry_oid, sizeof(entPhySensorEntry_oid));
    len = pack_entPhySensorEntry(base, entPhysicalIndex);
    if (len < 0) {
        g_warning("%s: invalid index values", "entPhySensorEntry");
        s->error_status = GNET_SNMP_PDU_ERR_INTERNAL;
        return;
    }

    *entPhySensorEntry = NULL;

    gnet_snmp_attr_get(s, &in, base, len, 10, entPhySensorEntry_attr, mask);

    out = gnet_snmp_sync_get(s, in);
    g_list_foreach(in, (GFunc) gnet_snmp_varbind_delete, NULL);
    g_list_free(in);
    if (out) {
        if (s->error_status != GNET_SNMP_PDU_ERR_NOERROR) {
            g_list_foreach(out, (GFunc) gnet_snmp_varbind_delete, NULL);
            g_list_free(out);
            return;
        }
        *entPhySensorEntry = assign_entPhySensorEntry(out);
    }
}

void
entity_sensor_mib_free_entPhySensorEntry(entity_sensor_mib_entPhySensorEntry_t *entPhySensorEntry)
{
    GList *vbl;
    char *p;

    if (entPhySensorEntry) {
        p = (char *) entPhySensorEntry + sizeof(entity_sensor_mib_entPhySensorEntry_t);
        vbl = * (GList **) p;
        g_list_foreach(vbl, (GFunc) gnet_snmp_varbind_delete, NULL);
        g_list_free(vbl);
        g_free(entPhySensorEntry);
    }
}

void
entity_sensor_mib_free_entPhySensorTable(entity_sensor_mib_entPhySensorEntry_t **entPhySensorEntry)
{
    int i;

    if (entPhySensorEntry) {
        for (i = 0; entPhySensorEntry[i]; i++) {
            entity_sensor_mib_free_entPhySensorEntry(entPhySensorEntry[i]);
        }
        g_free(entPhySensorEntry);
    }
}