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
|
/*
* ipmi_utils.cpp
*
* Copyright (c) 2003 by FORCE Computers
*
* Note that this file is based on parts of OpenIPMI
* written by Corey Minyard <minyard@mvista.com>
* of MontaVista Software. Corey's code was helpful
* and many thanks go to him. He gave the permission
* to use this code in OpenHPI under BSD license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This
* file and program are licensed under a BSD style license. See
* the Copying file included with the OpenHPI distribution for
* full licensing terms.
*
* Authors:
* Thomas Kanngieser <thomas.kanngieser@fci.com>
*/
#include <time.h>
#include "ipmi_utils.h"
static const char *fru_state[] =
{
"not installed",
"inactive",
"activation request",
"activation in progress",
"active",
"deactivation request",
"deactivation in progress",
"communication lost"
};
const char *
IpmiFruStateToString( tIpmiFruState val )
{
if ( val > eIpmiFruStateCommunicationLost )
return "invalid";
return fru_state[val];
}
unsigned int
IpmiGetUint32( const unsigned char *data )
{
return (data[0]
| (data[1] << 8)
| (data[2] << 16)
| (data[3] << 24));
}
// Extract a 16-bit integer from the data, IPMI (little-endian) style.
unsigned int
IpmiGetUint16( const unsigned char *data )
{
return data[0] | (data[1] << 8);
}
// Add a 32-bit integer to the data, IPMI (little-endian) style.
void
IpmiSetUint32( unsigned char *data, int val )
{
data[0] = val & 0xff;
data[1] = (val >> 8) & 0xff;
data[2] = (val >> 16) & 0xff;
data[3] = (val >> 24) & 0xff;
}
// Add a 16-bit integer to the data, IPMI (little-endian) style.
void
IpmiSetUint16( unsigned char *data, int val )
{
data[0] = val & 0xff;
data[1] = (val >> 8) & 0xff;
}
void
IpmiDateToString( unsigned int t, char *str )
{
struct tm tmt;
time_t dummy = t;
localtime_r( &dummy, &tmt );
// 2003.10.30
strftime( str, dDateStringSize, "%Y.%m.%d", &tmt );
}
void
IpmiTimeToString( unsigned int t, char *str )
{
struct tm tmt;
time_t dummy = t;
localtime_r( &dummy, &tmt );
// 11:11:11
strftime( str, dTimeStringSize, "%H:%M:%S", &tmt );
}
void
IpmiDateTimeToString( unsigned int t, char *str )
{
struct tm tmt;
time_t dummy = t;
localtime_r( &dummy, &tmt );
// 2003.10.30 11:11:11
strftime( str, dDateTimeStringSize, "%Y.%m.%d %H:%M:%S", &tmt );
}
|