mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-06-03 20:51:36 +00:00
mc: Code refactor to reduce copy-paste ratio
* Replace with a macro all calls to val2str() for completion codes * Replace with a macro all calls to val2str() for manufacturer name * Replace with a macro all calls to val2str() for product name * Add ipmi24toh() and ipmi32toh() helpers, unify ipmi*toh() interface Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
@@ -113,13 +113,13 @@ uint16_t ipmi_get_oem_id(struct ipmi_intf *intf);
|
||||
|
||||
/* le16toh(), hto16le(), et. al. don't exist for Windows or Apple */
|
||||
/* For portability, let's simply define our own versions here */
|
||||
static inline uint16_t ipmi16toh(uint16_t le)
|
||||
static inline uint16_t ipmi16toh(void *ipmi16)
|
||||
{
|
||||
uint8_t *data = (uint8_t *)≤
|
||||
uint8_t *ipmi = (uint8_t *)ipmi16;
|
||||
uint16_t h;
|
||||
|
||||
h = data[1] << 8; /* MSB */
|
||||
h |= data[0]; /* LSB */
|
||||
h = ipmi[1] << 8; /* MSB */
|
||||
h |= ipmi[0]; /* LSB */
|
||||
|
||||
return h;
|
||||
}
|
||||
@@ -130,6 +130,31 @@ static inline void htoipmi16(uint16_t h, uint8_t *ipmi)
|
||||
ipmi[1] = h >> 8; /* MSB */
|
||||
}
|
||||
|
||||
static inline uint32_t ipmi24toh(void *ipmi24)
|
||||
{
|
||||
uint8_t *ipmi = (uint8_t *)ipmi24;
|
||||
uint32_t h = 0;
|
||||
|
||||
h = ipmi[2] << 16;
|
||||
h |= ipmi[1] << 8;
|
||||
h |= ipmi[0];
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
static inline uint32_t ipmi32toh(void *ipmi32)
|
||||
{
|
||||
uint8_t *ipmi = (uint8_t *)ipmi32;
|
||||
uint32_t h;
|
||||
|
||||
h = ipmi[3] << 24;
|
||||
h |= ipmi[2] << 16;
|
||||
h |= ipmi[1] << 8;
|
||||
h |= ipmi[0];
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
#define ipmi_open_file_read(file) ipmi_open_file(file, 0)
|
||||
#define ipmi_open_file_write(file) ipmi_open_file(file, 1)
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@
|
||||
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/ipmi_strings.h>
|
||||
|
||||
#define OEM_MFG_STRING(oem) val2str(IPM_DEV_MANUFACTURER_ID(oem),\
|
||||
ipmi_oem_info)
|
||||
#define OEM_PROD_STRING(oem, p) oemval2str(IPM_DEV_MANUFACTURER_ID(oem),\
|
||||
ipmi16toh(p),\
|
||||
ipmi_oem_product_info)
|
||||
|
||||
#define BMC_GET_DEVICE_ID 0x01
|
||||
#define BMC_COLD_RESET 0x02
|
||||
@@ -85,8 +92,8 @@ struct ipm_devid_rsp {
|
||||
#define IPM_DEV_IPMI_VERSION_MINOR(x) \
|
||||
((x & IPM_DEV_IPMI_VER_MINOR_MASK) >> IPM_DEV_IPMI_VER_MINOR_SHIFT)
|
||||
|
||||
#define IPM_DEV_MANUFACTURER_ID(x) \
|
||||
((uint32_t) ((x[2] & 0x0F) << 16 | x[1] << 8 | x[0]))
|
||||
#define IPM_DEV_MANUFACTURER_ID_MASK 0x0FFFFF
|
||||
#define IPM_DEV_MANUFACTURER_ID(x) (ipmi24toh(x) & IPM_DEV_MANUFACTURER_ID_MASK)
|
||||
|
||||
#define IPM_DEV_ADTL_SUPPORT_BITS (8)
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <ipmitool/helper.h>
|
||||
|
||||
#define CC_STRING(cc) val2str(cc, completion_code_vals)
|
||||
|
||||
extern const struct valstr completion_code_vals[];
|
||||
extern const struct valstr entity_id_vals[];
|
||||
extern const struct valstr entity_device_type_vals[];
|
||||
|
||||
Reference in New Issue
Block a user