vpd_decode.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * vpd_decode.h
  3. *
  4. * Google VPD decoding routines.
  5. *
  6. * Copyright 2017 Google Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License v2.0 as published by
  10. * the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #ifndef __VPD_DECODE_H
  18. #define __VPD_DECODE_H
  19. #include <linux/types.h>
  20. enum {
  21. VPD_OK = 0,
  22. VPD_FAIL,
  23. };
  24. enum {
  25. VPD_TYPE_TERMINATOR = 0,
  26. VPD_TYPE_STRING,
  27. VPD_TYPE_INFO = 0xfe,
  28. VPD_TYPE_IMPLICIT_TERMINATOR = 0xff,
  29. };
  30. /* Callback for vpd_decode_string to invoke. */
  31. typedef int vpd_decode_callback(const u8 *key, s32 key_len,
  32. const u8 *value, s32 value_len,
  33. void *arg);
  34. /*
  35. * vpd_decode_string
  36. *
  37. * Given the encoded string, this function invokes callback with extracted
  38. * (key, value). The *consumed will be plused the number of bytes consumed in
  39. * this function.
  40. *
  41. * The input_buf points to the first byte of the input buffer.
  42. *
  43. * The *consumed starts from 0, which is actually the next byte to be decoded.
  44. * It can be non-zero to be used in multiple calls.
  45. *
  46. * If one entry is successfully decoded, sends it to callback and returns the
  47. * result.
  48. */
  49. int vpd_decode_string(const s32 max_len, const u8 *input_buf, s32 *consumed,
  50. vpd_decode_callback callback, void *callback_arg);
  51. #endif /* __VPD_DECODE_H */