blob: d280a99842d3b7d0a40bfc9ec65bb77265c33c72 [file] [log] [blame]
Hariharasubramanian R44473092015-10-15 08:25:28 -05001/*
2 * Copyright (C) 2003-2014 FreeIPMI Core Team
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18/*****************************************************************************\
19 * Copyright (C) 2007-2014 Lawrence Livermore National Security, LLC.
20 * Copyright (C) 2007 The Regents of the University of California.
21 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
22 * Written by Albert Chu <chu11@llnl.gov>
23 * UCRL-CODE-232183
24 *
25 * This file is part of Ipmi-fru, a tool used for retrieving
26 * motherboard field replaceable unit (FRU) information. For details,
27 * see http://www.llnl.gov/linux/.
28 *
29 * Ipmi-fru is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by the
31 * Free Software Foundation; either version 3 of the License, or (at your
32 * option) any later version.
33 *
34 * Ipmi-fru is distributed in the hope that it will be useful, but
35 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
36 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37 * for more details.
38 *
39 * You should have received a copy of the GNU General Public License along
40 * with Ipmi-fru. If not, see <http://www.gnu.org/licenses/>.
41\*****************************************************************************/
42#include <stdio.h>
43#include <unistd.h>
44#include <string.h>
45#include <time.h>
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -050046#include <systemd/sd-bus.h>
Hariharasubramanian R44473092015-10-15 08:25:28 -050047
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -050048#define IPMI_FRU_PARSER_DEBUG 1
Hariharasubramanian R44473092015-10-15 08:25:28 -050049#define uint8_t unsigned char
50#define uint32_t unsigned int
51
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -050052#define TEXTSTR(a) #a
53# define ASSERT(x) \
54do { \
55if (0 == (x)) { \
56fprintf(stderr, \
57"Assertion failed: %s, " \
58"%d at \'%s\'\n", \
59__FILE__, \
60__LINE__, \
61TEXTSTR(a)); \
62return -1; \
63} \
64} while (0)
Hariharasubramanian R44473092015-10-15 08:25:28 -050065
66#define IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX 512
67#define IPMI_FRU_SENTINEL_VALUE 0xC1
68#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK 0xC0
69#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT 0x06
70#define IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK 0x3F
71#define IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE 0x03
72
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -050073/* OpenBMC defines for Parser */
74#define IPMI_FRU_AREA_INTERNAL_USE 0x00
75#define IPMI_FRU_AREA_CHASSIS_INFO 0x01
76#define IPMI_FRU_AREA_BOARD_INFO 0x02
77#define IPMI_FRU_AREA_PRODUCT_INFO 0x03
78#define IPMI_FRU_AREA_MULTI_RECORD 0x04
79#define IPMI_FRU_AREA_TYPE_MAX 0x05
80
81#define OPENBMC_VPD_KEY_LEN 64
82#define OPENBMC_VPD_VAL_LEN 512
Hariharasubramanian R44473092015-10-15 08:25:28 -050083
84struct ipmi_fru_field
85{
86 uint8_t type_length_field[IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX];
87 /* store length of data stored in buffer */
88 unsigned int type_length_field_length;
89};
90
91typedef struct ipmi_fru_field ipmi_fru_field_t;
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -050092/*
93 * FRU Parser
94 */
Hariharasubramanian R44473092015-10-15 08:25:28 -050095
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -050096typedef struct ipmi_fru_area_info
97{
98 uint8_t off;
99 uint8_t len;
100} ipmi_fru_area_info_t;
101
102typedef struct ipmi_fru_common_hdr
103{
104 uint8_t fmtver;
105 uint8_t internal;
106 uint8_t chassis;
107 uint8_t board;
108 uint8_t product;
109 uint8_t multirec;
110} __attribute__((packed)) ipmi_fru_common_hdr_t;
111
112enum openbmc_vpd_key_id
113{
114 OPENBMC_VPD_KEY_CHASSIS_TYPE = 1, /* not a type/len */
115 OPENBMC_VPD_KEY_CHASSIS_PART_NUM,
116 OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,
117 OPENBMC_VPD_KEY_CHASSIS_MAX = OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,
118 /* TODO: chassis_custom_fields */
119
120 OPENBMC_VPD_KEY_BOARD_MFG_DATE, /* not a type/len */
121 OPENBMC_VPD_KEY_BOARD_MFR,
122 OPENBMC_VPD_KEY_BOARD_NAME,
123 OPENBMC_VPD_KEY_BOARD_SERIAL_NUM,
124 OPENBMC_VPD_KEY_BOARD_PART_NUM,
125 OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID,
126 OPENBMC_VPD_KEY_BOARD_MAX = OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID,
127 /* TODO: board_custom_fields */
128
129 OPENBMC_VPD_KEY_PRODUCT_MFR,
130 OPENBMC_VPD_KEY_PRODUCT_NAME,
131 OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM,
132 OPENBMC_VPD_KEY_PRODUCT_VER,
133 OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM,
134 OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG,
135 OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID,
136 OPENBMC_VPD_KEY_PRODUCT_MAX = OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID,
137 /* TODO: product_custom_fields */
138
139 OPENBMC_VPD_KEY_MAX,
140
141};
142
143const char* vpd_key_names [] =
144{
145 "Key Names Table Start",
146 "Chassis Type", /*OPENBMC_VPD_KEY_CHASSIS_TYPE*/
147 "Chassis Part Number", /*OPENBMC_VPD_KEY_CHASSIS_PART_NUM,*/
148 "Chassis Serial Number", /*OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM,*/
149
150 /* TODO: chassis_custom_fields */
151
152 "Board Mfg Date", /* OPENBMC_VPD_KEY_BOARD_MFG_DATE, */ /* not a type/len */
153 "Board Manufacturer", /* OPENBMC_VPD_KEY_BOARD_MFR, */
154 "Board Name", /* OPENBMC_VPD_KEY_BOARD_NAME, */
155 "Board Serial Number", /* OPENBMC_VPD_KEY_BOARD_SERIAL_NUM, */
156 "Board Part Number", /* OPENBMC_VPD_KEY_BOARD_PART_NUM, */
157 "Board FRU File ID", /* OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID, */
158 /* TODO: board_custom_fields */
159
160 "Product Manufacturer", /* OPENBMC_VPD_KEY_PRODUCT_MFR, */
161 "Product Name", /* OPENBMC_VPD_KEY_PRODUCT_NAME, */
162 "Product Model Number", /* OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM, */
163 "Product Version", /* OPENBMC_VPD_KEY_PRODUCT_VER, */
164 "Product Serial Number", /* OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM, */
165 "Product Asset Tag", /* OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG, */
166 "Product FRU File ID", /* OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID, */
167 /* TODO: product_custom_fields */
168
169 "Key Names Table End" /*OPENBMC_VPD_KEY_MAX,*/
170};
171
172
173/*
174 * --------------------------------------------------------------------
175 *
176 * --------------------------------------------------------------------
177 */
178/* private method to parse type/length */
Hariharasubramanian R44473092015-10-15 08:25:28 -0500179static int
180_parse_type_length (const void *areabuf,
181 unsigned int areabuflen,
182 unsigned int current_area_offset,
183 uint8_t *number_of_data_bytes,
184 ipmi_fru_field_t *field)
185{
186 const uint8_t *areabufptr = (const uint8_t*) areabuf;
187 uint8_t type_length;
188 uint8_t type_code;
189
190 ASSERT (areabuf);
191 ASSERT (areabuflen);
192 ASSERT (number_of_data_bytes);
193
194 type_length = areabufptr[current_area_offset];
195
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500196 /* ipmi workaround
Hariharasubramanian R44473092015-10-15 08:25:28 -0500197 *
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500198 * dell p weredge r610
Hariharasubramanian R44473092015-10-15 08:25:28 -0500199 *
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500200 * my reading of the fru spec is that all non-custom fields are
201 * required to be listed by the vendor. however, on this
Hariharasubramanian R44473092015-10-15 08:25:28 -0500202 * motherboard, some areas list this, indicating that there is
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500203 * no more data to be parsed. so now, for "required" fields, i
Hariharasubramanian R44473092015-10-15 08:25:28 -0500204 * check to see if the type-length field is a sentinel before
205 * calling this function.
206 */
207
208 ASSERT (type_length != IPMI_FRU_SENTINEL_VALUE);
209
210 type_code = (type_length & IPMI_FRU_TYPE_LENGTH_TYPE_CODE_MASK) >> IPMI_FRU_TYPE_LENGTH_TYPE_CODE_SHIFT;
211 (*number_of_data_bytes) = type_length & IPMI_FRU_TYPE_LENGTH_NUMBER_OF_DATA_BYTES_MASK;
212
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500213 /* special case: this shouldn't be a length of 0x01 (see type/length
214 * byte format in fru information storage definition).
Hariharasubramanian R44473092015-10-15 08:25:28 -0500215 */
216 if (type_code == IPMI_FRU_TYPE_LENGTH_TYPE_CODE_LANGUAGE_CODE
217 && (*number_of_data_bytes) == 0x01)
218 {
219 return (-1);
220 }
221
222 if ((current_area_offset + 1 + (*number_of_data_bytes)) > areabuflen)
223 {
224 return (-1);
225 }
226
227 if (field)
228 {
229 memset (field->type_length_field,
230 '\0',
231 IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
232 memcpy (field->type_length_field,
233 &areabufptr[current_area_offset],
234 1 + (*number_of_data_bytes));
235 field->type_length_field_length = 1 + (*number_of_data_bytes);
236 }
237
238 return (0);
239}
240
241int
242ipmi_fru_chassis_info_area (const void *areabuf,
243 unsigned int areabuflen,
244 uint8_t *chassis_type,
245 ipmi_fru_field_t *chassis_part_number,
246 ipmi_fru_field_t *chassis_serial_number,
247 ipmi_fru_field_t *chassis_custom_fields,
248 unsigned int chassis_custom_fields_len)
249{
250 const uint8_t *areabufptr = (const uint8_t*) areabuf;
251 unsigned int area_offset = 0;
252 unsigned int custom_fields_index = 0;
253 uint8_t number_of_data_bytes;
254 int rv = -1;
255
256 if (!areabuf || !areabuflen)
257 {
258 return (-1);
259 }
260
261 if (chassis_part_number)
262 memset (chassis_part_number,
263 '\0',
264 sizeof (ipmi_fru_field_t));
265 if (chassis_serial_number)
266 memset (chassis_serial_number,
267 '\0',
268 sizeof (ipmi_fru_field_t));
269 if (chassis_custom_fields && chassis_custom_fields_len)
270 memset (chassis_custom_fields,
271 '\0',
272 sizeof (ipmi_fru_field_t) * chassis_custom_fields_len);
273
274 if (chassis_type)
275 (*chassis_type) = areabufptr[area_offset];
276 area_offset++;
277
278 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
279 goto out;
280
281 if (_parse_type_length (areabufptr,
282 areabuflen,
283 area_offset,
284 &number_of_data_bytes,
285 chassis_part_number) < 0)
286 goto cleanup;
287 area_offset += 1; /* type/length byte */
288 area_offset += number_of_data_bytes;
289
290 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
291 goto out;
292
293 if (_parse_type_length (areabufptr,
294 areabuflen,
295 area_offset,
296 &number_of_data_bytes,
297 chassis_serial_number) < 0)
298 goto cleanup;
299 area_offset += 1; /* type/length byte */
300 area_offset += number_of_data_bytes;
301
302 while (area_offset < areabuflen
303 && areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
304 {
305 ipmi_fru_field_t *field_ptr = NULL;
306
307 if (chassis_custom_fields && chassis_custom_fields_len)
308 {
309 if (custom_fields_index < chassis_custom_fields_len)
310 field_ptr = &chassis_custom_fields[custom_fields_index];
311 else
312 {
313 goto cleanup;
314 }
315 }
316
317 if (_parse_type_length (areabufptr,
318 areabuflen,
319 area_offset,
320 &number_of_data_bytes,
321 field_ptr) < 0)
322 goto cleanup;
323
324 area_offset += 1; /* type/length byte */
325 area_offset += number_of_data_bytes;
326 custom_fields_index++;
327 }
328
329
330 out:
331 rv = 0;
332 cleanup:
333 return (rv);
334}
335
336int
337ipmi_fru_board_info_area (const void *areabuf,
338 unsigned int areabuflen,
339 uint8_t *language_code,
340 uint32_t *mfg_date_time,
341 ipmi_fru_field_t *board_manufacturer,
342 ipmi_fru_field_t *board_product_name,
343 ipmi_fru_field_t *board_serial_number,
344 ipmi_fru_field_t *board_part_number,
345 ipmi_fru_field_t *board_fru_file_id,
346 ipmi_fru_field_t *board_custom_fields,
347 unsigned int board_custom_fields_len)
348{
349 const uint8_t *areabufptr = (const uint8_t*) areabuf;
350 uint32_t mfg_date_time_tmp = 0;
351 unsigned int area_offset = 0;
352 unsigned int custom_fields_index = 0;
353 uint8_t number_of_data_bytes;
354 int rv = -1;
355
356 if (!areabuf || !areabuflen)
357 {
358 return (-1);
359 }
360
361 if (board_manufacturer)
362 memset (board_manufacturer,
363 '\0',
364 sizeof (ipmi_fru_field_t));
365 if (board_product_name)
366 memset (board_product_name,
367 '\0',
368 sizeof (ipmi_fru_field_t));
369 if (board_serial_number)
370 memset (board_serial_number,
371 '\0',
372 sizeof (ipmi_fru_field_t));
373 if (board_part_number)
374 memset (board_part_number,
375 '\0',
376 sizeof (ipmi_fru_field_t));
377 if (board_fru_file_id)
378 memset (board_fru_file_id,
379 '\0',
380 sizeof (ipmi_fru_field_t));
381 if (board_custom_fields && board_custom_fields_len)
382 memset (board_custom_fields,
383 '\0',
384 sizeof (ipmi_fru_field_t) * board_custom_fields_len);
385
386 if (language_code)
387 (*language_code) = areabufptr[area_offset];
388 area_offset++;
389
390 if (mfg_date_time)
391 {
392 struct tm tm;
393 time_t t;
394
395 /* mfg_date_time is little endian - see spec */
396 mfg_date_time_tmp |= areabufptr[area_offset];
397 area_offset++;
398 mfg_date_time_tmp |= (areabufptr[area_offset] << 8);
399 area_offset++;
400 mfg_date_time_tmp |= (areabufptr[area_offset] << 16);
401 area_offset++;
402
403 /* mfg_date_time is in minutes, so multiple by 60 to get seconds */
404 mfg_date_time_tmp *= 60;
405
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500406 /* posix says individual calls need not clear/set all portions of
Hariharasubramanian R44473092015-10-15 08:25:28 -0500407 * 'struct tm', thus passing 'struct tm' between functions could
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500408 * have issues. so we need to memset.
Hariharasubramanian R44473092015-10-15 08:25:28 -0500409 */
410 memset (&tm, '\0', sizeof(struct tm));
411
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500412 /* in fru, epoch is 0:00 hrs 1/1/96
Hariharasubramanian R44473092015-10-15 08:25:28 -0500413 *
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500414 * so convert into ansi epoch
Hariharasubramanian R44473092015-10-15 08:25:28 -0500415 */
416
417 tm.tm_year = 96; /* years since 1900 */
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500418 tm.tm_mon = 0; /* months since january */
Hariharasubramanian R44473092015-10-15 08:25:28 -0500419 tm.tm_mday = 1; /* 1-31 */
420 tm.tm_hour = 0;
421 tm.tm_min = 0;
422 tm.tm_sec = 0;
423 tm.tm_isdst = -1;
424
425 if ((t = mktime (&tm)) == (time_t)-1)
426 {
427 goto cleanup;
428 }
429
430 mfg_date_time_tmp += (uint32_t)t;
431 (*mfg_date_time) = mfg_date_time_tmp;
432 }
433 else
434 area_offset += 3;
435
436 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
437 goto out;
438
439 if (_parse_type_length (areabufptr,
440 areabuflen,
441 area_offset,
442 &number_of_data_bytes,
443 board_manufacturer) < 0)
444 goto cleanup;
445 area_offset += 1; /* type/length byte */
446 area_offset += number_of_data_bytes;
447
448 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
449 goto out;
450
451 if (_parse_type_length (areabufptr,
452 areabuflen,
453 area_offset,
454 &number_of_data_bytes,
455 board_product_name) < 0)
456 goto cleanup;
457 area_offset += 1; /* type/length byte */
458 area_offset += number_of_data_bytes;
459
460 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
461 goto out;
462
463 if (_parse_type_length (areabufptr,
464 areabuflen,
465 area_offset,
466 &number_of_data_bytes,
467 board_serial_number) < 0)
468 goto cleanup;
469 area_offset += 1; /* type/length byte */
470 area_offset += number_of_data_bytes;
471
472 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
473 goto out;
474
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500475 if (_parse_type_length (areabufptr,
Hariharasubramanian R44473092015-10-15 08:25:28 -0500476 areabuflen,
477 area_offset,
478 &number_of_data_bytes,
479 board_part_number) < 0)
480 goto cleanup;
481 area_offset += 1; /* type/length byte */
482 area_offset += number_of_data_bytes;
483
484 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
485 goto out;
486
487 if (_parse_type_length (areabufptr,
488 areabuflen,
489 area_offset,
490 &number_of_data_bytes,
491 board_fru_file_id) < 0)
492 goto cleanup;
493 area_offset += 1; /* type/length byte */
494 area_offset += number_of_data_bytes;
495
496 while (area_offset < areabuflen
497 && areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
498 {
499 ipmi_fru_field_t *field_ptr = NULL;
500
501 if (board_custom_fields && board_custom_fields_len)
502 {
503 if (custom_fields_index < board_custom_fields_len)
504 field_ptr = &board_custom_fields[custom_fields_index];
505 else
506 {
507 goto cleanup;
508 }
509 }
510
511 if (_parse_type_length (areabufptr,
512 areabuflen,
513 area_offset,
514 &number_of_data_bytes,
515 field_ptr) < 0)
516 goto cleanup;
517
518 area_offset += 1; /* type/length byte */
519 area_offset += number_of_data_bytes;
520 custom_fields_index++;
521 }
522
523 out:
524 rv = 0;
525 cleanup:
526 return (rv);
527}
528
529int
530ipmi_fru_product_info_area (const void *areabuf,
531 unsigned int areabuflen,
532 uint8_t *language_code,
533 ipmi_fru_field_t *product_manufacturer_name,
534 ipmi_fru_field_t *product_name,
535 ipmi_fru_field_t *product_part_model_number,
536 ipmi_fru_field_t *product_version,
537 ipmi_fru_field_t *product_serial_number,
538 ipmi_fru_field_t *product_asset_tag,
539 ipmi_fru_field_t *product_fru_file_id,
540 ipmi_fru_field_t *product_custom_fields,
541 unsigned int product_custom_fields_len)
542{
543 const uint8_t *areabufptr = (const uint8_t*) areabuf;
544 unsigned int area_offset = 0;
545 unsigned int custom_fields_index = 0;
546 uint8_t number_of_data_bytes;
547 int rv = -1;
548
549 if (!areabuf || !areabuflen)
550 {
551 return (-1);
552 }
553
554 if (product_manufacturer_name)
555 memset (product_manufacturer_name,
556 '\0',
557 sizeof (ipmi_fru_field_t));
558 if (product_name)
559 memset (product_name,
560 '\0',
561 sizeof (ipmi_fru_field_t));
562 if (product_part_model_number)
563 memset (product_part_model_number,
564 '\0',
565 sizeof (ipmi_fru_field_t));
566 if (product_version)
567 memset (product_version,
568 '\0',
569 sizeof (ipmi_fru_field_t));
570 if (product_serial_number)
571 memset (product_serial_number,
572 '\0',
573 sizeof (ipmi_fru_field_t));
574 if (product_asset_tag)
575 memset (product_asset_tag,
576 '\0',
577 sizeof (ipmi_fru_field_t));
578 if (product_fru_file_id)
579 memset (product_fru_file_id,
580 '\0',
581 sizeof (ipmi_fru_field_t));
582 if (product_custom_fields && product_custom_fields_len)
583 memset (product_custom_fields,
584 '\0',
585 sizeof (ipmi_fru_field_t) * product_custom_fields_len);
586
587 if (language_code)
588 (*language_code) = areabufptr[area_offset];
589 area_offset++;
590
591 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
592 goto out;
593
594 if (_parse_type_length (areabufptr,
595 areabuflen,
596 area_offset,
597 &number_of_data_bytes,
598 product_manufacturer_name) < 0)
599 goto cleanup;
600 area_offset += 1; /* type/length byte */
601 area_offset += number_of_data_bytes;
602
603 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
604 goto out;
605
606 if (_parse_type_length (areabufptr,
607 areabuflen,
608 area_offset,
609 &number_of_data_bytes,
610 product_name) < 0)
611 goto cleanup;
612 area_offset += 1; /* type/length byte */
613 area_offset += number_of_data_bytes;
614
615 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
616 goto out;
617
618 if (_parse_type_length (areabufptr,
619 areabuflen,
620 area_offset,
621 &number_of_data_bytes,
622 product_part_model_number) < 0)
623 goto cleanup;
624 area_offset += 1; /* type/length byte */
625 area_offset += number_of_data_bytes;
626
627 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
628 goto out;
629
630 if (_parse_type_length (areabufptr,
631 areabuflen,
632 area_offset,
633 &number_of_data_bytes,
634 product_version) < 0)
635 goto cleanup;
636 area_offset += 1; /* type/length byte */
637 area_offset += number_of_data_bytes;
638
639 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
640 goto out;
641
642 if (_parse_type_length (areabufptr,
643 areabuflen,
644 area_offset,
645 &number_of_data_bytes,
646 product_serial_number) < 0)
647 goto cleanup;
648 area_offset += 1; /* type/length byte */
649 area_offset += number_of_data_bytes;
650
651 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
652 goto out;
653
654 if (_parse_type_length (areabufptr,
655 areabuflen,
656 area_offset,
657 &number_of_data_bytes,
658 product_asset_tag) < 0)
659 goto cleanup;
660 area_offset += 1; /* type/length byte */
661 area_offset += number_of_data_bytes;
662
663 if (areabufptr[area_offset] == IPMI_FRU_SENTINEL_VALUE)
664 goto out;
665
666 if (_parse_type_length (areabufptr,
667 areabuflen,
668 area_offset,
669 &number_of_data_bytes,
670 product_fru_file_id) < 0)
671 goto cleanup;
672 area_offset += 1; /* type/length byte */
673 area_offset += number_of_data_bytes;
674
675 while (area_offset < areabuflen
676 && areabufptr[area_offset] != IPMI_FRU_SENTINEL_VALUE)
677 {
678 ipmi_fru_field_t *field_ptr = NULL;
679
680 if (product_custom_fields && product_custom_fields_len)
681 {
682 if (custom_fields_index < product_custom_fields_len)
683 field_ptr = &product_custom_fields[custom_fields_index];
684 else
685 {
686 goto cleanup;
687 }
688 }
689
690 if (_parse_type_length (areabufptr,
691 areabuflen,
692 area_offset,
693 &number_of_data_bytes,
694 field_ptr) < 0)
695 goto cleanup;
696
697 area_offset += 1; /* type/length byte */
698 area_offset += number_of_data_bytes;
699 custom_fields_index++;
700 }
701
702
703 out:
704 rv = 0;
705 cleanup:
706 return (rv);
707}
Hariharasubramanian Rc2d79462015-10-16 06:47:56 -0500708
709
710int
711parse_fru (const void* msgbuf, sd_bus_message* vpdtbl)
712{
713 int ret = 0;
714 int rv = -1;
715 int i = 0;
716 ipmi_fru_area_info_t fru_area_info [ IPMI_FRU_AREA_TYPE_MAX ];
717 ipmi_fru_common_hdr_t* chdr = NULL;
718 uint8_t* hdr = NULL;
719
720
721 ipmi_fru_field_t vpd_info [ OPENBMC_VPD_KEY_MAX ];
722 /*char ipmi_fru_field_str [ IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX ];
723 uint32_t len=0;*/
724 const uint8_t* ipmi_fru_field_str;
725
726 /* Chassis */
727 uint8_t chassis_type;
728
729 /* Board */
730 uint32_t mfg_date_time;
731
732 /* Product */
733 unsigned int product_custom_fields_len;
734
735 ASSERT (msgbuf);
736 ASSERT (vpdtbl);
737
738 for (i=0; i<OPENBMC_VPD_KEY_MAX; i++)
739 {
740 memset (vpd_info[i].type_length_field, '\0', IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
741 vpd_info[i].type_length_field_length = 0;
742 }
743
744 for (i=0; i<IPMI_FRU_AREA_TYPE_MAX; i++)
745 {
746 fru_area_info [ i ].off = 0;
747 fru_area_info [ i ].len = 0;
748 }
749
750 chdr = (ipmi_fru_common_hdr_t*) msgbuf;
751 hdr = (uint8_t*) msgbuf;
752
753 fru_area_info [ IPMI_FRU_AREA_INTERNAL_USE ].off = chdr->internal;
754 fru_area_info [ IPMI_FRU_AREA_CHASSIS_INFO ].off = chdr->chassis;
755 fru_area_info [ IPMI_FRU_AREA_BOARD_INFO ].off = chdr->board;
756 fru_area_info [ IPMI_FRU_AREA_PRODUCT_INFO ].off = chdr->product;
757 fru_area_info [ IPMI_FRU_AREA_MULTI_RECORD ].off = chdr->multirec;
758
759 if (chdr->internal)
760 {
761 fru_area_info [ IPMI_FRU_AREA_INTERNAL_USE ].len = 8*(*(hdr+8*chdr->internal+1));
762
763 /* TODO: Parse internal use area */
764 }
765
766 if (chdr->chassis)
767 {
768 fru_area_info [ IPMI_FRU_AREA_CHASSIS_INFO ].len = 8*(*(hdr+8*chdr->chassis+1));
769 ipmi_fru_chassis_info_area (hdr+8*chdr->chassis+2,
770 fru_area_info [ IPMI_FRU_AREA_CHASSIS_INFO ].len,
771 &chassis_type,
772 &vpd_info [OPENBMC_VPD_KEY_CHASSIS_PART_NUM],
773 &vpd_info [OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM],
774 NULL, 0);
775 }
776
777 if (chdr->board)
778 {
779 fru_area_info [ IPMI_FRU_AREA_BOARD_INFO ].len = 8*(*(hdr+8*chdr->board+1));
780 ipmi_fru_board_info_area (hdr+8*chdr->board+2,
781 fru_area_info [ IPMI_FRU_AREA_BOARD_INFO ].len,
782 NULL,
783 &mfg_date_time,
784 &vpd_info [OPENBMC_VPD_KEY_BOARD_MFR],
785 &vpd_info [OPENBMC_VPD_KEY_BOARD_NAME],
786 &vpd_info [OPENBMC_VPD_KEY_BOARD_SERIAL_NUM],
787 &vpd_info [OPENBMC_VPD_KEY_BOARD_PART_NUM],
788 &vpd_info [OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID],
789 NULL, 0);
790 }
791
792 if (chdr->product)
793 {
794 fru_area_info [ IPMI_FRU_AREA_PRODUCT_INFO ].len = 8*(*(hdr+8*chdr->product+1));
795 ipmi_fru_product_info_area (hdr+8*chdr->product+2,
796 fru_area_info [ IPMI_FRU_AREA_PRODUCT_INFO ].len,
797 NULL,
798 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_MFR],
799 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_NAME],
800 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM],
801 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_VER],
802 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM],
803 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG],
804 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID],
805 NULL, 0);
806 }
807
808 if (chdr->multirec)
809 {
810 fru_area_info [ IPMI_FRU_AREA_MULTI_RECORD ].len = 8*(*(hdr+8*chdr->multirec+1));
811 /* TODO: Parse multi record area */
812 }
813
814 for (i=0; i<IPMI_FRU_AREA_TYPE_MAX; i++)
815 {
816#if IPMI_FRU_PARSER_DEBUG
817 printf ("IPMI_FRU_AREA_TYPE=[%d] : Offset=[%d] : Len=[%d]\n", i, fru_area_info [i].off, fru_area_info[i].len);
818#else
819;
820#endif
821 }
822
823 /* Populate VPD Table */
824 for (i=1; i<OPENBMC_VPD_KEY_MAX; i++)
825 {
826 if (i==OPENBMC_VPD_KEY_CHASSIS_TYPE)
827 {
828 sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "y", chassis_type);
829#if IPMI_FRU_PARSER_DEBUG
830 printf ("[%s] = [%d]\n", vpd_key_names[i], chassis_type);
831#else
832;
833#endif
834 continue;
835 }
836
837 if (i==OPENBMC_VPD_KEY_BOARD_MFG_DATE)
838 {
839 sd_bus_message_append (vpdtbl, "sa{y}", vpd_key_names[i], mfg_date_time);
840#if IPMI_FRU_PARSER_DEBUG
841 printf ("[%s] = [%d]\n", vpd_key_names[i], mfg_date_time);
842#else
843;
844#endif
845 continue;
846 }
847
848 /* FIXME: Field type encoding *ASSUMED* to be *BINARY* */
849 ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
850 sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
851 if (vpd_info[i].type_length_field_length)
852 {
853#if IPMI_FRU_PARSER_DEBUG
854 printf ("[%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
855#else
856;
857#endif
858 }
859 }
860
861 out:
862 rv = 0;
863 cleanup:
864 return (rv);
865}
866
867int parse_fru_area (const uint8_t area, const void* msgbuf, const uint8_t len, sd_bus_message* vpdtbl)
868{
869 int ret = 0;
870 int rv = -1;
871 int i = 0;
872 ipmi_fru_area_info_t fru_area_info [ IPMI_FRU_AREA_TYPE_MAX ];
873 ipmi_fru_common_hdr_t* chdr = NULL;
874 uint8_t* hdr = NULL;
875 const uint8_t* ipmi_fru_field_str=NULL;
876
877
878 ipmi_fru_field_t vpd_info [ OPENBMC_VPD_KEY_MAX ];
879 for (i=0; i<OPENBMC_VPD_KEY_MAX; i++)
880 {
881 memset (vpd_info[i].type_length_field, '\0', IPMI_FRU_AREA_TYPE_LENGTH_FIELD_MAX);
882 vpd_info[i].type_length_field_length = 0;
883 }
884
885 /* Chassis */
886 uint8_t chassis_type;
887
888 /* Board */
889 uint32_t mfg_date_time;
890
891 /* Product */
892 unsigned int product_custom_fields_len;
893
894 ASSERT (msgbuf);
895 ASSERT (vpdtbl);
896
897 switch (area)
898 {
899 case IPMI_FRU_AREA_CHASSIS_INFO:
900 ipmi_fru_chassis_info_area (msgbuf,
901 len,
902 &chassis_type,
903 &vpd_info [OPENBMC_VPD_KEY_CHASSIS_PART_NUM],
904 &vpd_info [OPENBMC_VPD_KEY_CHASSIS_SERIAL_NUM],
905 NULL, 0);
906
907 /* Populate VPD Table */
908 for (i=1; i<=OPENBMC_VPD_KEY_CHASSIS_MAX; i++)
909 {
910 if (i==OPENBMC_VPD_KEY_CHASSIS_TYPE)
911 {
912 sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "y", chassis_type);
913#if IPMI_FRU_PARSER_DEBUG
914 printf ("Chassis : [%s] = [%d]\n", vpd_key_names[i], chassis_type);
915#else
916;
917#endif
918 continue;
919 }
920 ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
921 sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
922#if IPMI_FRU_PARSER_DEBUG
923 printf ("Chassis : [%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
924#else
925;
926#endif
927 }
928 break;
929 case IPMI_FRU_AREA_BOARD_INFO:
930 ipmi_fru_board_info_area (msgbuf,
931 len,
932 NULL,
933 &mfg_date_time,
934 &vpd_info [OPENBMC_VPD_KEY_BOARD_MFR],
935 &vpd_info [OPENBMC_VPD_KEY_BOARD_NAME],
936 &vpd_info [OPENBMC_VPD_KEY_BOARD_SERIAL_NUM],
937 &vpd_info [OPENBMC_VPD_KEY_BOARD_PART_NUM],
938 &vpd_info [OPENBMC_VPD_KEY_BOARD_FRU_FILE_ID],
939 NULL, 0);
940
941 /* Populate VPD Table */
942 for (i=OPENBMC_VPD_KEY_BOARD_MFR; i<=OPENBMC_VPD_KEY_BOARD_MAX; i++)
943 {
944 if (i==OPENBMC_VPD_KEY_BOARD_MFG_DATE)
945 {
946 sd_bus_message_append (vpdtbl, "sa{y}", vpd_key_names[i], mfg_date_time);
947#if IPMI_FRU_PARSER_DEBUG
948 printf ("Board : [%s] = [%d]\n", vpd_key_names[i], mfg_date_time);
949#else
950;
951#endif
952 continue;
953 }
954 ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
955 sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
956#if IPMI_FRU_PARSER_DEBUG
957 printf ("Board : [%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
958#else
959;
960#endif
961 }
962 break;
963 case IPMI_FRU_AREA_PRODUCT_INFO:
964 ipmi_fru_product_info_area (msgbuf,
965 len,
966 NULL,
967 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_MFR],
968 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_NAME],
969 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_PART_MODEL_NUM],
970 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_VER],
971 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_SERIAL_NUM],
972 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_ASSET_TAG],
973 &vpd_info [OPENBMC_VPD_KEY_PRODUCT_FRU_FILE_ID],
974 NULL, 0);
975 for (i=OPENBMC_VPD_KEY_PRODUCT_MFR; i<=OPENBMC_VPD_KEY_PRODUCT_MAX; i++)
976 {
977 ipmi_fru_field_str = (unsigned char*) &(vpd_info[i].type_length_field) + 1;
978 sd_bus_message_append (vpdtbl, "{sv}", vpd_key_names[i], "s", ipmi_fru_field_str);
979#if IPMI_FRU_PARSER_DEBUG
980 printf ("Product : [%s] = [%s]\n", vpd_key_names[i], ipmi_fru_field_str);
981#else
982;
983#endif
984 }
985 break;
986 defualt:
987 /* TODO: Parse Multi Rec / Internal use area */
988 break;
989 }
990
991 out:
992 rv = 0;
993 cleanup:
994 return (rv);
995}