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