| 1 | |
| 2 | * Copyright (C) 2012 CERN (www.cern.ch)
|
| 3 | * Author: Alessandro Rubini <[email protected]>
|
| 4 | *
|
| 5 | * Released according to the GNU GPL, version 2 or any later version.
|
| 6 | *
|
| 7 | * This work is part of the White Rabbit project, a research effort led
|
| 8 | * by CERN, the European Institute for Nuclear Research.
|
| 9 |
|
| 10 | #include <linux/ipmi-fru.h>
|
| 11 |
|
| 12 |
|
| 13 | static struct fru_type_length *
|
| 14 | __fru_get_board_tl(struct fru_common_header *header, int nr)
|
| 15 | {
|
| 16 | struct fru_board_info_area *bia;
|
| 17 | struct fru_type_length *tl;
|
| 18 |
|
| 19 | bia = fru_get_board_area(header);
|
| 20 | tl = bia->tl;
|
| 21 | while (nr > 0 && !fru_is_eof(tl)) {
|
| 22 | tl = fru_next_tl(tl);
|
| 23 | nr--;
|
| 24 | }
|
| 25 | if (fru_is_eof(tl))
|
| 26 | return NULL;
|
| 27 | return tl;
|
| 28 | }
|
| 29 |
|
| 30 | static char *__fru_alloc_get_tl(struct fru_common_header *header, int nr)
|
| 31 | {
|
| 32 | struct fru_type_length *tl;
|
| 33 | char *res;
|
| 34 | int len;
|
| 35 |
|
| 36 | tl = __fru_get_board_tl(header, nr);
|
| 37 | if (!tl)
|
| 38 | return NULL;
|
| 39 | len = fru_strlen(tl);
|
| 40 | res = fru_alloc(fru_strlen(tl) + 1);
|
| 41 | if (!res)
|
| 42 | return NULL;
|
| 43 | return fru_strcpy(res, tl);
|
| 44 | }
|
| 45 |
|
| 46 |
|
| 47 | int fru_header_cksum_ok(struct fru_common_header *header)
|
| 48 | {
|
| 49 | uint8_t *ptr = (void *)header;
|
| 50 | int i, sum;
|
| 51 |
|
| 52 | for (i = sum = 0; i < sizeof(*header); i++)
|
| 53 | sum += ptr[i];
|
| 54 | return (sum & 0xff) == 0;
|
| 55 | }
|
| 56 | int fru_bia_cksum_ok(struct fru_board_info_area *bia)
|
| 57 | {
|
| 58 | uint8_t *ptr = (void *)bia;
|
| 59 | int i, sum;
|
| 60 |
|
| 61 | for (i = sum = 0; i < 8 * bia->area_len; i++)
|
| 62 | sum += ptr[i];
|
| 63 | return (sum & 0xff) == 0;
|
| 64 | }
|
| 65 |
|
| 66 |
|
| 67 | char *fru_get_board_manufacturer(struct fru_common_header *header)
|
| 68 | {
|
| 69 | return __fru_alloc_get_tl(header, 0);
|
| 70 | }
|
| 71 | char *fru_get_product_name(struct fru_common_header *header)
|
| 72 | {
|
| 73 | return __fru_alloc_get_tl(header, 1);
|
| 74 | }
|
| 75 | char *fru_get_serial_number(struct fru_common_header *header)
|
| 76 | {
|
| 77 | return __fru_alloc_get_tl(header, 2);
|
| 78 | }
|
| 79 | char *fru_get_part_number(struct fru_common_header *header)
|
| 80 | {
|
| 81 | return __fru_alloc_get_tl(header, 3);
|
| 82 | }
|