^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vpd_decode.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Google VPD decoding routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2017 Google Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef __VPD_DECODE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define __VPD_DECODE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) VPD_OK = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) VPD_FAIL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) VPD_TYPE_TERMINATOR = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) VPD_TYPE_STRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) VPD_TYPE_INFO = 0xfe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) VPD_TYPE_IMPLICIT_TERMINATOR = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* Callback for vpd_decode_string to invoke. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) typedef int vpd_decode_callback(const u8 *key, u32 key_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) const u8 *value, u32 value_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * vpd_decode_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Given the encoded string, this function invokes callback with extracted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * (key, value). The *consumed will be plused the number of bytes consumed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * The input_buf points to the first byte of the input buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * The *consumed starts from 0, which is actually the next byte to be decoded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * It can be non-zero to be used in multiple calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * If one entry is successfully decoded, sends it to callback and returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int vpd_decode_string(const u32 max_len, const u8 *input_buf, u32 *consumed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) vpd_decode_callback callback, void *callback_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #endif /* __VPD_DECODE_H */