1 #ifdef BRCM_SNMP_NOT_USED
3 * Host Resources MIB - utility functions - hr_utils.c
8 #include <net-snmp/net-snmp-config.h>
11 #include <netinet/in.h>
24 #if TIME_WITH_SYS_TIME
26 # include <sys/timeb.h>
28 # include <sys/time.h>
33 # include <sys/time.h>
39 #include <net-snmp/types.h>
40 #include <net-snmp/library/snmp-tc.h> /* for "internal" definitions */
41 #include <net-snmp/library/snmp_api.h>
44 date_n_time(time_t * when, size_t * length)
47 static u_char string[11];
52 if (when == NULL || *when == 0 || *when == (time_t) - 1) {
67 * Basic 'local' time handling
69 tm_p = localtime(when);
70 *(short *) string = htons(tm_p->tm_year + 1900);
71 string[2] = tm_p->tm_mon + 1;
72 string[3] = tm_p->tm_mday;
73 string[4] = tm_p->tm_hour;
74 string[5] = tm_p->tm_min;
75 string[6] = tm_p->tm_sec;
83 #if !defined(SYSV) && !defined(aix4) && !defined(aix5) && !defined(WIN32) && !defined(irix6)
84 #define timezone tm_p->tm_gmtoff
90 string[9] = abs(timezone) / 3600;
91 string[10] = (abs(timezone) - string[9] * 3600) / 60;
97 * Daylight saving time
99 if (tm_p->tm_isdst > 0) {
101 * Assume add one hour
103 if (string[8] == '-')
118 ctime_to_timet(char *string)
122 if (strlen(string) < 24)
128 if (!strncmp(string + 4, "Jan", 3))
130 else if (!strncmp(string + 4, "Feb", 3))
132 else if (!strncmp(string + 4, "Mar", 3))
134 else if (!strncmp(string + 4, "Apr", 3))
136 else if (!strncmp(string + 4, "May", 3))
138 else if (!strncmp(string + 4, "Jun", 3))
140 else if (!strncmp(string + 4, "Jul", 3))
142 else if (!strncmp(string + 4, "Aug", 3))
144 else if (!strncmp(string + 4, "Sep", 3))
146 else if (!strncmp(string + 4, "Oct", 3))
148 else if (!strncmp(string + 4, "Nov", 3))
150 else if (!strncmp(string + 4, "Dec", 3))
155 tm.tm_mday = atoi(string + 8);
156 tm.tm_hour = atoi(string + 11);
157 tm.tm_min = atoi(string + 14);
158 tm.tm_sec = atoi(string + 17);
159 tm.tm_year = atoi(string + 20) - 1900;
162 * Cope with timezone and DST
169 tm.tm_sec -= timezone;
172 return (mktime(&tm));
176 * blatantly lifted from opensmp
179 check_rowstatus_transition(int oldValue, int newValue)
182 * From the SNMPv2-TC MIB:
184 * +--------------+-----------+-------------+-------------
186 * | |status col.|status column|
187 * |status column | is | is |status column
188 * ACTION |does not exist| notReady | notInService| is active
189 * --------------+--------------+-----------+-------------+-------------
190 * set status |noError ->D|inconsist- |inconsistent-|inconsistent-
191 * column to | or | entValue| Value| Value
192 * createAndGo |inconsistent- | | |
194 * --------------+--------------+-----------+-------------+-------------
195 * set status |noError see 1|inconsist- |inconsistent-|inconsistent-
196 * column to | or | entValue| Value| Value
197 * createAndWait |wrongValue | | |
198 * --------------+--------------+-----------+-------------+-------------
199 * set status |inconsistent- |inconsist- |noError |noError
200 * column to | Value| entValue| |
204 * | |see 2 ->D|see 8 ->D| ->D
205 * --------------+--------------+-----------+-------------+-------------
206 * set status |inconsistent- |inconsist- |noError |noError ->C
207 * column to | Value| entValue| |
208 * notInService | | | |
211 * | |see 3 ->C| ->C|see 6
212 * --------------+--------------+-----------+-------------+-------------
213 * set status |noError |noError |noError |noError ->A
214 * column to | | | | or
215 * destroy | ->A| ->A| ->A|see 7
216 * --------------+--------------+-----------+-------------+-------------
217 * set any other |see 4 |noError |noError |see 5
218 * column to some| | | |
219 * value | | see 1| ->C| ->D
220 * --------------+--------------+-----------+-------------+-------------
222 * (1) goto B or C, depending on information available to the
225 * (2) if other variable bindings included in the same PDU,
226 * provide values for all columns which are missing but
227 * required, and all columns have acceptable values, then
228 * return noError and goto D.
230 * (3) if other variable bindings included in the same PDU,
231 * provide legal values for all columns which are missing but
232 * required, then return noError and goto C.
234 * (4) at the discretion of the agent, the return value may be
237 * inconsistentName: because the agent does not choose to
238 * create such an instance when the corresponding
239 * RowStatus instance does not exist, or
241 * inconsistentValue: if the supplied value is
242 * inconsistent with the state of some other MIB object's
245 * noError: because the agent chooses to create the
248 * If noError is returned, then the instance of the status
249 * column must also be created, and the new state is B or C,
250 * depending on the information available to the agent. If
251 * inconsistentName or inconsistentValue is returned, the row
252 * remains in state A.
254 * (5) depending on the MIB definition for the column/table,
255 * either noError or inconsistentValue may be returned.
257 * (6) the return value can indicate one of the following
260 * wrongValue: because the agent does not support
261 * notInService (e.g., an agent which does not support
264 * inconsistentValue: because the agent is unable to take
265 * the row out of service at this time, perhaps because it
266 * is in use and cannot be de-activated.
268 * (7) the return value can indicate the following error:
270 * inconsistentValue: because the agent is unable to
271 * remove the row at this time, perhaps because it is in
272 * use and cannot be de-activated.
274 * (8) the transition to D can fail, e.g., if the values of the
275 * conceptual row are inconsistent, then the error code would
276 * be inconsistentValue.
278 * NOTE: Other processing of (this and other varbinds of) the
279 * set request may result in a response other than noError
280 * being returned, e.g., wrongValue, noCreation, etc.
285 * these two end up being equivelent as far as checking the
288 * status goes, although the final states are based on the
294 case RS_NOTINSERVICE:
295 if (oldValue == RS_NOTINSERVICE || oldValue == RS_ACTIVE);
297 return SNMP_ERR_INCONSISTENTVALUE;
304 return SNMP_ERR_INCONSISTENTVALUE;
308 if (oldValue != RS_NONEXISTENT)
310 * impossible, we already exist.
312 return SNMP_ERR_INCONSISTENTVALUE;
315 case RS_CREATEANDWAIT:
316 if (oldValue != RS_NONEXISTENT)
318 * impossible, we already exist.
320 return SNMP_ERR_INCONSISTENTVALUE;
327 return SNMP_ERR_INCONSISTENTVALUE;
331 return SNMP_ERR_NOERROR;
335 check_storage_transition(int oldValue, int newValue)
338 * From the SNMPv2-TC MIB:
340 * "Describes the memory realization of a conceptual row. A
341 * row which is volatile(2) is lost upon reboot. A row which
342 * is either nonVolatile(3), permanent(4) or readOnly(5), is
343 * backed up by stable storage. A row which is permanent(4)
344 * can be changed but not deleted. A row which is readOnly(5)
345 * cannot be changed nor deleted.
347 * If the value of an object with this syntax is either
348 * permanent(4) or readOnly(5), it cannot be written.
349 * Conversely, if the value is either other(1), volatile(2) or
350 * nonVolatile(3), it cannot be modified to be permanent(4) or
351 * readOnly(5). (All illegal modifications result in a
352 * 'wrongValue' error.)
354 * Every usage of this textual convention is required to
355 * specify the columnar objects which a permanent(4) row must
356 * at a minimum allow to be writable."
359 case SNMP_STORAGE_PERMANENT:
360 case SNMP_STORAGE_READONLY:
361 return SNMP_ERR_INCONSISTENTVALUE;
363 case SNMP_STORAGE_NONE:
364 case SNMP_STORAGE_OTHER:
365 case SNMP_STORAGE_VOLATILE:
366 case SNMP_STORAGE_NONVOLATILE:
367 if (newValue == SNMP_STORAGE_PERMANENT ||
368 newValue == SNMP_STORAGE_READONLY)
369 return SNMP_ERR_INCONSISTENTVALUE;
372 return SNMP_ERR_NOERROR;
374 #endif /* #if BRCM_SNMP_NOT_USED */