fru-parse.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2012 CERN (www.cern.ch)
  3. * Author: Alessandro Rubini <rubini@gnudd.com>
  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. /* Some internal helpers */
  12. static struct fru_type_length *
  13. __fru_get_board_tl(struct fru_common_header *header, int nr)
  14. {
  15. struct fru_board_info_area *bia;
  16. struct fru_type_length *tl;
  17. bia = fru_get_board_area(header);
  18. tl = bia->tl;
  19. while (nr > 0 && !fru_is_eof(tl)) {
  20. tl = fru_next_tl(tl);
  21. nr--;
  22. }
  23. if (fru_is_eof(tl))
  24. return NULL;
  25. return tl;
  26. }
  27. static char *__fru_alloc_get_tl(struct fru_common_header *header, int nr)
  28. {
  29. struct fru_type_length *tl;
  30. char *res;
  31. tl = __fru_get_board_tl(header, nr);
  32. if (!tl)
  33. return NULL;
  34. res = fru_alloc(fru_strlen(tl) + 1);
  35. if (!res)
  36. return NULL;
  37. return fru_strcpy(res, tl);
  38. }
  39. /* Public checksum verifiers */
  40. int fru_header_cksum_ok(struct fru_common_header *header)
  41. {
  42. uint8_t *ptr = (void *)header;
  43. int i, sum;
  44. for (i = sum = 0; i < sizeof(*header); i++)
  45. sum += ptr[i];
  46. return (sum & 0xff) == 0;
  47. }
  48. int fru_bia_cksum_ok(struct fru_board_info_area *bia)
  49. {
  50. uint8_t *ptr = (void *)bia;
  51. int i, sum;
  52. for (i = sum = 0; i < 8 * bia->area_len; i++)
  53. sum += ptr[i];
  54. return (sum & 0xff) == 0;
  55. }
  56. /* Get various stuff, trivial */
  57. char *fru_get_board_manufacturer(struct fru_common_header *header)
  58. {
  59. return __fru_alloc_get_tl(header, 0);
  60. }
  61. char *fru_get_product_name(struct fru_common_header *header)
  62. {
  63. return __fru_alloc_get_tl(header, 1);
  64. }
  65. char *fru_get_serial_number(struct fru_common_header *header)
  66. {
  67. return __fru_alloc_get_tl(header, 2);
  68. }
  69. char *fru_get_part_number(struct fru_common_header *header)
  70. {
  71. return __fru_alloc_get_tl(header, 3);
  72. }