blob: d280a99842d3b7d0a40bfc9ec65bb77265c33c72 [file] [log] [blame]
/*
* Copyright (C) 2003-2014 FreeIPMI Core Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*****************************************************************************\
* Copyright (C) 2007-2014 Lawrence Livermore National Security, LLC.
* Copyright (C) 2007 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Albert Chu <chu11@llnl.gov>
* UCRL-CODE-232183
*
* This file is part of Ipmi-fru, a tool used for retrieving
* motherboard field replaceable unit (FRU) information. For details,
* see http://www.llnl.gov/linux/.
*
* Ipmi-fru is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* Ipmi-fru 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. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Ipmi-fru. If not, see <http://www.gnu.org/licenses/>.
\*****************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <systemd/sd-bus.h>
#define IPMI_FRU_PARSER_DEBUG 1
#define uint8_t unsigned char
#define uint32_t unsigned int
#define TEXTSTR(a) #a
# define ASSERT(x) \
do { \
if (0 == (x)) { \
fprintf(stderr, \
"Assertion failed: %s, " \
"%d at \'%s\'\n", \
__FILE__, \
__LINE__, \
TEXTSTR(a)); \
return -1; \
} \
} while (0)
#define IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX 512
#define IPMI_FRU_SENTINEL_VALUE 0xC1
#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK 0xC0
#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT 0x06
#define IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK 0x3F
#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE 0x03
/* OpenBMC defines for Parser */
#define IPMI_FRU_AREA_INTERNAL_USE 0x00
#define IPMI_FRU_AREA_CHASSIS_INFO 0x01
#define IPMI_FRU_AREA_BOARD_INFO 0x02
#define IPMI_FRU_AREA_PRODUCT_INFO 0x03
#define IPMI_FRU_AREA_MULTI_RECORD 0x04
#define IPMI_FRU_AREA_TYPE_MAX 0x05
#define OPENBMC_VPD_KEY_LEN 64
#define OPENBMC_VPD_VAL_LEN 512
struct ipmi_fru_field
{
uint8_t type_length_field[IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX];
/* store length of data stored in buffer */
unsigned int type_length_field_length;
};
typedef struct ipmi_fru_field ipmi_fru_field_t;
/*
* FRU Parser
*/
typedef struct ipmi_fru_area_info
{
uint8_t off;
uint8_t len;
} ipmi_fru_area_info_t;
typedef struct ipmi_fru_common_hdr
{
uint8_t fmtver;
uint8_t internal;
uint8_t chassis;
uint8_t board;
uint8_t product;
uint8_t multirec;
} __attribute__((packed)) ipmi_fru_common_hdr_t;
enum openbmc_vpd_key_id
{
OPENBMC_VPD_KEY_CHASSIS_TYPE = 1, /* not a type/len */
OPENBMC_VPD_KEY_CHASSIS_PART_NUM,
OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,
OPENBMC_VPD_KEY_CHASSIS_MAX = OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,
/* TODO: chassis_custom_fields */
OPENBMC_VPD_KEY_BOARD_MFG_DATE, /* not a type/len */
OPENBMC_VPD_KEY_BOARD_MFR,
OPENBMC_VPD_KEY_BOARD_NAME,
OPENBMC_VPD_KEY_BOARD_SERIAL_NUM,
OPENBMC_VPD_KEY_BOARD_PART_NUM,
OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID,
OPENBMC_VPD_KEY_BOARD_MAX = OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID,
/* TODO: board_custom_fields */
OPENBMC_VPD_KEY_PRODUCT_MFR,
OPENBMC_VPD_KEY_PRODUCT_NAME,
OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM,
OPENBMC_VPD_KEY_PRODUCT_VER,
OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM,
OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG,
OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID,
OPENBMC_VPD_KEY_PRODUCT_MAX = OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID,
/* TODO: product_custom_fields */
OPENBMC_VPD_KEY_MAX,
};
const char* vpd_key_names [] =
{
"Key Names Table Start",
"Chassis Type", /*OPENBMC_VPD_KEY_CHASSIS_TYPE*/
"Chassis Part Number", /*OPENBMC_VPD_KEY_CHASSIS_PART_NUM,*/
"Chassis Serial Number", /*OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,*/
/* TODO: chassis_custom_fields */
"Board Mfg Date", /* OPENBMC_VPD_KEY_BOARD_MFG_DATE, */ /* not a type/len */
"Board Manufacturer", /* OPENBMC_VPD_KEY_BOARD_MFR, */
"Board Name", /* OPENBMC_VPD_KEY_BOARD_NAME, */
"Board Serial Number", /* OPENBMC_VPD_KEY_BOARD_SERIAL_NUM, */
"Board Part Number", /* OPENBMC_VPD_KEY_BOARD_PART_NUM, */
"Board FRU File ID", /* OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID, */
/* TODO: board_custom_fields */
"Product Manufacturer", /* OPENBMC_VPD_KEY_PRODUCT_MFR, */
"Product Name", /* OPENBMC_VPD_KEY_PRODUCT_NAME, */
"Product Model Number", /* OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM, */
"Product Version", /* OPENBMC_VPD_KEY_PRODUCT_VER, */
"Product Serial Number", /* OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM, */
"Product Asset Tag", /* OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG, */
"Product FRU File ID", /* OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID, */
/* TODO: product_custom_fields */
"Key Names Table End" /*OPENBMC_VPD_KEY_MAX,*/
};
/*
* --------------------------------------------------------------------
*
* --------------------------------------------------------------------
*/
/* private method to parse type/length */
static int
_parse_type_length (const void *areabuf,
unsigned int areabuflen,
unsigned int current_area_offset,
uint8_t *number_of_data_bytes,
ipmi_fru_field_t *field)
{
const uint8_t *areabufptr = (const uint8_t*) areabuf;
uint8_t type_length;
uint8_t type_code;
ASSERT (areabuf);
ASSERT (areabuflen);
ASSERT (number_of_data_bytes);
type_length = areabufptr[current_area_offset];
/* ipmi workaround
*
* dell p weredge r610
*
* my reading of the fru spec is that all non-custom fields are
* required to be listed by the vendor. however, on this
* motherboard, some areas list this, indicating that there is
* no more data to be parsed. so now, for "required" fields, i
* check to see if the type-length field is a sentinel before
* calling this function.
*/
ASSERT (type_length != IPMI_FRU_SENTINEL_VALUE);
type_code = (type_length & IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK) >> IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT;
(*number_of_data_bytes) = type_length & IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK;
/* special case: this shouldn't be a length of 0x01 (see type/length
* byte format in fru information storage definition).
*/
if (type_code == IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE
&& (*number_of_data_bytes) == 0x01)
{
return (-1);
}
if ((current_area_offset + 1 + (*number_of_data_bytes)) > areabuflen)
{
return (-1);
}
if (field)
{
memset (field->type_length_field,
'\0',
IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
memcpy (field->type_length_field,
&areabufptr[current_area_offset],
1 + (*number_of_data_bytes));
field->type_length_field_length = 1 + (*number_of_data_bytes);
}
return (0);
}
int
ipmi_fru_chassis_info_area (const void *areabuf,
unsigned int areabuflen,
uint8_t *chassis_type,
ipmi_fru_field_t *chassis_part_number,
ipmi_fru_field_t *chassis_serial_number,
ipmi_fru_field_t *chassis_custom_fields,
unsigned int chassis_custom_fields_len)
{
const uint8_t *areabufptr = (const uint8_t*) areabuf;
unsigned int area_offset = 0;
unsigned int custom_fields_index = 0;
uint8_t number_of_data_bytes;
int rv = -1;
if (!areabuf || !areabuflen)
{
return (-1);
}
if (chassis_part_number)
memset (chassis_part_number,
'\0',
sizeof (ipmi_fru_field_t));
if (chassis_serial_number)
memset (chassis_serial_number,
'\0',
sizeof (ipmi_fru_field_t));
if (chassis_custom_fields && chassis_custom_fields_len)
memset (chassis_custom_fields,
'\0',
sizeof (ipmi_fru_field_t) * chassis_custom_fields_len);
if (chassis_type)
(*chassis_type) = areabufptr[area_offset];
area_offset++;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
chassis_part_number) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
chassis_serial_number) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
while (area_offset < areabuflen
&& areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
{
ipmi_fru_field_t *field_ptr = NULL;
if (chassis_custom_fields && chassis_custom_fields_len)
{
if (custom_fields_index < chassis_custom_fields_len)
field_ptr = &chassis_custom_fields[custom_fields_index];
else
{
goto cleanup;
}
}
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
field_ptr) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
custom_fields_index++;
}
out:
rv = 0;
cleanup:
return (rv);
}
int
ipmi_fru_board_info_area (const void *areabuf,
unsigned int areabuflen,
uint8_t *language_code,
uint32_t *mfg_date_time,
ipmi_fru_field_t *board_manufacturer,
ipmi_fru_field_t *board_product_name,
ipmi_fru_field_t *board_serial_number,
ipmi_fru_field_t *board_part_number,
ipmi_fru_field_t *board_fru_file_id,
ipmi_fru_field_t *board_custom_fields,
unsigned int board_custom_fields_len)
{
const uint8_t *areabufptr = (const uint8_t*) areabuf;
uint32_t mfg_date_time_tmp = 0;
unsigned int area_offset = 0;
unsigned int custom_fields_index = 0;
uint8_t number_of_data_bytes;
int rv = -1;
if (!areabuf || !areabuflen)
{
return (-1);
}
if (board_manufacturer)
memset (board_manufacturer,
'\0',
sizeof (ipmi_fru_field_t));
if (board_product_name)
memset (board_product_name,
'\0',
sizeof (ipmi_fru_field_t));
if (board_serial_number)
memset (board_serial_number,
'\0',
sizeof (ipmi_fru_field_t));
if (board_part_number)
memset (board_part_number,
'\0',
sizeof (ipmi_fru_field_t));
if (board_fru_file_id)
memset (board_fru_file_id,
'\0',
sizeof (ipmi_fru_field_t));
if (board_custom_fields && board_custom_fields_len)
memset (board_custom_fields,
'\0',
sizeof (ipmi_fru_field_t) * board_custom_fields_len);
if (language_code)
(*language_code) = areabufptr[area_offset];
area_offset++;
if (mfg_date_time)
{
struct tm tm;
time_t t;
/* mfg_date_time is little endian - see spec */
mfg_date_time_tmp |= areabufptr[area_offset];
area_offset++;
mfg_date_time_tmp |= (areabufptr[area_offset] << 8);
area_offset++;
mfg_date_time_tmp |= (areabufptr[area_offset] << 16);
area_offset++;
/* mfg_date_time is in minutes, so multiple by 60 to get seconds */
mfg_date_time_tmp *= 60;
/* posix says individual calls need not clear/set all portions of
* 'struct tm', thus passing 'struct tm' between functions could
* have issues. so we need to memset.
*/
memset (&tm, '\0', sizeof(struct tm));
/* in fru, epoch is 0:00 hrs 1/1/96
*
* so convert into ansi epoch
*/
tm.tm_year = 96; /* years since 1900 */
tm.tm_mon = 0; /* months since january */
tm.tm_mday = 1; /* 1-31 */
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
tm.tm_isdst = -1;
if ((t = mktime (&tm)) == (time_t)-1)
{
goto cleanup;
}
mfg_date_time_tmp += (uint32_t)t;
(*mfg_date_time) = mfg_date_time_tmp;
}
else
area_offset += 3;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
board_manufacturer) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
board_product_name) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
board_serial_number) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
board_part_number) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
board_fru_file_id) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
while (area_offset < areabuflen
&& areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
{
ipmi_fru_field_t *field_ptr = NULL;
if (board_custom_fields && board_custom_fields_len)
{
if (custom_fields_index < board_custom_fields_len)
field_ptr = &board_custom_fields[custom_fields_index];
else
{
goto cleanup;
}
}
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
field_ptr) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
custom_fields_index++;
}
out:
rv = 0;
cleanup:
return (rv);
}
int
ipmi_fru_product_info_area (const void *areabuf,
unsigned int areabuflen,
uint8_t *language_code,
ipmi_fru_field_t *product_manufacturer_name,
ipmi_fru_field_t *product_name,
ipmi_fru_field_t *product_part_model_number,
ipmi_fru_field_t *product_version,
ipmi_fru_field_t *product_serial_number,
ipmi_fru_field_t *product_asset_tag,
ipmi_fru_field_t *product_fru_file_id,
ipmi_fru_field_t *product_custom_fields,
unsigned int product_custom_fields_len)
{
const uint8_t *areabufptr = (const uint8_t*) areabuf;
unsigned int area_offset = 0;
unsigned int custom_fields_index = 0;
uint8_t number_of_data_bytes;
int rv = -1;
if (!areabuf || !areabuflen)
{
return (-1);
}
if (product_manufacturer_name)
memset (product_manufacturer_name,
'\0',
sizeof (ipmi_fru_field_t));
if (product_name)
memset (product_name,
'\0',
sizeof (ipmi_fru_field_t));
if (product_part_model_number)
memset (product_part_model_number,
'\0',
sizeof (ipmi_fru_field_t));
if (product_version)
memset (product_version,
'\0',
sizeof (ipmi_fru_field_t));
if (product_serial_number)
memset (product_serial_number,
'\0',
sizeof (ipmi_fru_field_t));
if (product_asset_tag)
memset (product_asset_tag,
'\0',
sizeof (ipmi_fru_field_t));
if (product_fru_file_id)
memset (product_fru_file_id,
'\0',
sizeof (ipmi_fru_field_t));
if (product_custom_fields && product_custom_fields_len)
memset (product_custom_fields,
'\0',
sizeof (ipmi_fru_field_t) * product_custom_fields_len);
if (language_code)
(*language_code) = areabufptr[area_offset];
area_offset++;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
product_manufacturer_name) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
product_name) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
product_part_model_number) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
product_version) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
product_serial_number) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
product_asset_tag) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
goto out;
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
product_fru_file_id) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
while (area_offset < areabuflen
&& areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
{
ipmi_fru_field_t *field_ptr = NULL;
if (product_custom_fields && product_custom_fields_len)
{
if (custom_fields_index < product_custom_fields_len)
field_ptr = &product_custom_fields[custom_fields_index];
else
{
goto cleanup;
}
}
if (_parse_type_length (areabufptr,
areabuflen,
area_offset,
&number_of_data_bytes,
field_ptr) < 0)
goto cleanup;
area_offset += 1; /* type/length byte */
area_offset += number_of_data_bytes;
custom_fields_index++;
}
out:
rv = 0;
cleanup:
return (rv);
}
int
parse_fru (const void* msgbuf, sd_bus_message* vpdtbl)
{
int ret = 0;
int rv = -1;
int i = 0;
ipmi_fru_area_info_t fru_area_info [ IPMI_FRU_AREA_TYPE_MAX ];
ipmi_fru_common_hdr_t* chdr = NULL;
uint8_t* hdr = NULL;
ipmi_fru_field_t vpd_info [ OPENBMC_VPD_KEY_MAX ];
/*char ipmi_fru_field_str [ IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX ];
uint32_t len=0;*/
const uint8_t* ipmi_fru_field_str;
/* Chassis */
uint8_t chassis_type;
/* Board */
uint32_t mfg_date_time;
/* Product */
unsigned int product_custom_fields_len;
ASSERT (msgbuf);
ASSERT (vpdtbl);
for (i=0; i<OPENBMC_VPD_KEY_MAX; i++)
{
memset (vpd_info[i].type_length_field, '\0', IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
vpd_info[i].type_length_field_length = 0;
}
for (i=0; i<IPMI_FRU_AREA_TYPE_MAX; i++)
{
fru_area_info [ i ].off = 0;
fru_area_info [ i ].len = 0;
}
chdr = (ipmi_fru_common_hdr_t*) msgbuf;
hdr = (uint8_t*) msgbuf;
fru_area_info [ IPMI_FRU_AREA_INTERNAL_USE ].off = chdr->internal;
fru_area_info [ IPMI_FRU_AREA_CHASSIS_INFO ].off = chdr->chassis;
fru_area_info [ IPMI_FRU_AREA_BOARD_INFO ].off = chdr->board;
fru_area_info [ IPMI_FRU_AREA_PRODUCT_INFO ].off = chdr->product;
fru_area_info [ IPMI_FRU_AREA_MULTI_RECORD ].off = chdr->multirec;
if (chdr->internal)
{
fru_area_info [ IPMI_FRU_AREA_INTERNAL_USE ].len = 8*(*(hdr+8*chdr->internal+1));
/* TODO: Parse internal use area */
}
if (chdr->chassis)
{
fru_area_info [ IPMI_FRU_AREA_CHASSIS_INFO ].len = 8*(*(hdr+8*chdr->chassis+1));
ipmi_fru_chassis_info_area (hdr+8*chdr->chassis+2,
fru_area_info [ IPMI_FRU_AREA_CHASSIS_INFO ].len,
&chassis_type,
&vpd_info [OPENBMC_VPD_KEY_CHASSIS_PART_NUM],
&vpd_info [OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM],
NULL, 0);
}
if (chdr->board)
{
fru_area_info [ IPMI_FRU_AREA_BOARD_INFO ].len = 8*(*(hdr+8*chdr->board+1));
ipmi_fru_board_info_area (hdr+8*chdr->board+2,
fru_area_info [ IPMI_FRU_AREA_BOARD_INFO ].len,
NULL,
&mfg_date_time,
&vpd_info [OPENBMC_VPD_KEY_BOARD_MFR],
&vpd_info [OPENBMC_VPD_KEY_BOARD_NAME],
&vpd_info [OPENBMC_VPD_KEY_BOARD_SERIAL_NUM],
&vpd_info [OPENBMC_VPD_KEY_BOARD_PART_NUM],
&vpd_info [OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID],
NULL, 0);
}
if (chdr->product)
{
fru_area_info [ IPMI_FRU_AREA_PRODUCT_INFO ].len = 8*(*(hdr+8*chdr->product+1));
ipmi_fru_product_info_area (hdr+8*chdr->product+2,
fru_area_info [ IPMI_FRU_AREA_PRODUCT_INFO ].len,
NULL,
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_MFR],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_NAME],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_VER],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID],
NULL, 0);
}
if (chdr->multirec)
{
fru_area_info [ IPMI_FRU_AREA_MULTI_RECORD ].len = 8*(*(hdr+8*chdr->multirec+1));
/* TODO: Parse multi record area */
}
for (i=0; i<IPMI_FRU_AREA_TYPE_MAX; i++)
{
#if IPMI_FRU_PARSER_DEBUG
printf ("IPMI_FRU_AREA_TYPE=[%d] : Offset=[%d] : Len=[%d]\n", i, fru_area_info [i].off, fru_area_info[i].len);
#else
;
#endif
}
/* Populate VPD Table */
for (i=1; i<OPENBMC_VPD_KEY_MAX; i++)
{
if (i==OPENBMC_VPD_KEY_CHASSIS_TYPE)
{
sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "y", chassis_type);
#if IPMI_FRU_PARSER_DEBUG
printf ("[%s] = [%d]\n", vpd_key_names[i], chassis_type);
#else
;
#endif
continue;
}
if (i==OPENBMC_VPD_KEY_BOARD_MFG_DATE)
{
sd_bus_message_append (vpdtbl, "sa{y}", vpd_key_names[i], mfg_date_time);
#if IPMI_FRU_PARSER_DEBUG
printf ("[%s] = [%d]\n", vpd_key_names[i], mfg_date_time);
#else
;
#endif
continue;
}
/* FIXME: Field type encoding *ASSUMED* to be *BINARY* */
ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
if (vpd_info[i].type_length_field_length)
{
#if IPMI_FRU_PARSER_DEBUG
printf ("[%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
#else
;
#endif
}
}
out:
rv = 0;
cleanup:
return (rv);
}
int parse_fru_area (const uint8_t area, const void* msgbuf, const uint8_t len, sd_bus_message* vpdtbl)
{
int ret = 0;
int rv = -1;
int i = 0;
ipmi_fru_area_info_t fru_area_info [ IPMI_FRU_AREA_TYPE_MAX ];
ipmi_fru_common_hdr_t* chdr = NULL;
uint8_t* hdr = NULL;
const uint8_t* ipmi_fru_field_str=NULL;
ipmi_fru_field_t vpd_info [ OPENBMC_VPD_KEY_MAX ];
for (i=0; i<OPENBMC_VPD_KEY_MAX; i++)
{
memset (vpd_info[i].type_length_field, '\0', IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
vpd_info[i].type_length_field_length = 0;
}
/* Chassis */
uint8_t chassis_type;
/* Board */
uint32_t mfg_date_time;
/* Product */
unsigned int product_custom_fields_len;
ASSERT (msgbuf);
ASSERT (vpdtbl);
switch (area)
{
case IPMI_FRU_AREA_CHASSIS_INFO:
ipmi_fru_chassis_info_area (msgbuf,
len,
&chassis_type,
&vpd_info [OPENBMC_VPD_KEY_CHASSIS_PART_NUM],
&vpd_info [OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM],
NULL, 0);
/* Populate VPD Table */
for (i=1; i<=OPENBMC_VPD_KEY_CHASSIS_MAX; i++)
{
if (i==OPENBMC_VPD_KEY_CHASSIS_TYPE)
{
sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "y", chassis_type);
#if IPMI_FRU_PARSER_DEBUG
printf ("Chassis : [%s] = [%d]\n", vpd_key_names[i], chassis_type);
#else
;
#endif
continue;
}
ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
#if IPMI_FRU_PARSER_DEBUG
printf ("Chassis : [%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
#else
;
#endif
}
break;
case IPMI_FRU_AREA_BOARD_INFO:
ipmi_fru_board_info_area (msgbuf,
len,
NULL,
&mfg_date_time,
&vpd_info [OPENBMC_VPD_KEY_BOARD_MFR],
&vpd_info [OPENBMC_VPD_KEY_BOARD_NAME],
&vpd_info [OPENBMC_VPD_KEY_BOARD_SERIAL_NUM],
&vpd_info [OPENBMC_VPD_KEY_BOARD_PART_NUM],
&vpd_info [OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID],
NULL, 0);
/* Populate VPD Table */
for (i=OPENBMC_VPD_KEY_BOARD_MFR; i<=OPENBMC_VPD_KEY_BOARD_MAX; i++)
{
if (i==OPENBMC_VPD_KEY_BOARD_MFG_DATE)
{
sd_bus_message_append (vpdtbl, "sa{y}", vpd_key_names[i], mfg_date_time);
#if IPMI_FRU_PARSER_DEBUG
printf ("Board : [%s] = [%d]\n", vpd_key_names[i], mfg_date_time);
#else
;
#endif
continue;
}
ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
#if IPMI_FRU_PARSER_DEBUG
printf ("Board : [%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
#else
;
#endif
}
break;
case IPMI_FRU_AREA_PRODUCT_INFO:
ipmi_fru_product_info_area (msgbuf,
len,
NULL,
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_MFR],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_NAME],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_VER],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG],
&vpd_info [OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID],
NULL, 0);
for (i=OPENBMC_VPD_KEY_PRODUCT_MFR; i<=OPENBMC_VPD_KEY_PRODUCT_MAX; i++)
{
ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
#if IPMI_FRU_PARSER_DEBUG
printf ("Product : [%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
#else
;
#endif
}
break;
defualt:
/* TODO: Parse Multi Rec / Internal use area */
break;
}
out:
rv = 0;
cleanup:
return (rv);
}