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. int len;
  32. tl = __fru_get_board_tl(header, nr);
  33. if (!tl)
  34. return NULL;
  35. len = fru_strlen(tl);
  36. res = fru_alloc(fru_strlen(tl) + 1);
  37. if (!res)
  38. return NULL;
  39. return fru_strcpy(res, tl);
  40. }
  41. /* Public checksum verifiers */
  42. int fru_header_cksum_ok(struct fru_common_header *header)
  43. {
  44. uint8_t *ptr = (void *)header;
  45. int i, sum;
  46. for (i = sum = 0; i < sizeof(*header); i++)
  47. sum += ptr[i];
  48. return (sum & 0xff) == 0;
  49. }
  50. int fru_bia_cksum_ok(struct fru_board_info_area *bia)
  51. {
  52. uint8_t *ptr = (void *)bia;
  53. int i, sum;
  54. for (i = sum = 0; i < 8 * bia->area_len; i++)
  55. sum += ptr[i];
  56. return (sum & 0xff) == 0;
  57. }
  58. /* Get various stuff, trivial */
  59. char *fru_get_board_manufacturer(struct fru_common_header *header)
  60. {
  61. return __fru_alloc_get_tl(header, 0);
  62. }
  63. char *fru_get_product_name(struct fru_common_header *header)
  64. {
  65. return __fru_alloc_get_tl(header, 1);
  66. }
  67. char *fru_get_serial_number(struct fru_common_header *header)
  68. {
  69. return __fru_alloc_get_tl(header, 2);
  70. }
  71. char *fru_get_part_number(struct fru_common_header *header)
  72. {
  73. return __fru_alloc_get_tl(header, 3);
  74. }