xref: /linux/include/linux/tpm_buf.h (revision 49bda4826843be0ef97a162009a29ea3a63f3935)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Following copyright information was take from the original file
4  * <include/linux/tpm.h> where the definitions were moved from:
5  *
6  * Copyright (C) 2004,2007,2008 IBM Corporation
7  *
8  * Authors:
9  * Leendert van Doorn <leendert@watson.ibm.com>
10  * Dave Safford <safford@watson.ibm.com>
11  * Reiner Sailer <sailer@watson.ibm.com>
12  * Kylene Hall <kjhall@us.ibm.com>
13  * Debora Velarde <dvelarde@us.ibm.com>
14  *
15  * Maintained by: <tpmdd_devel@lists.sourceforge.net>
16  *
17  * Device driver for TCG/TCPA TPM (trusted platform module).
18  * Specifications at www.trustedcomputinggroup.org
19  */
20 
21 #ifndef __LINUX_TPM_BUF_H__
22 #define __LINUX_TPM_BUF_H__
23 
24 #include <linux/types.h>
25 #include <linux/bits.h>
26 
27 enum tpm_buf_flags {
28 	/* TPM2B format: */
29 	TPM_BUF_TPM2B		= BIT(0),
30 	/* The buffer is in invalid and unusable state: */
31 	TPM_BUF_INVALID		= BIT(1),
32 };
33 
34 /*
35  * A buffer for constructing and parsing TPM commands, responses and sized
36  * (TPM2B) buffers.
37  */
38 struct tpm_buf {
39 	u8 flags;
40 	u8 handles;
41 	u16 length;
42 	u16 capacity;
43 	u8 data[];
44 };
45 
46 void tpm_buf_init(struct tpm_buf *buf, u16 buf_size);
47 void tpm_buf_init_sized(struct tpm_buf *buf, u16 buf_size);
48 void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal);
49 void tpm_buf_reset_sized(struct tpm_buf *buf);
50 u16 tpm_buf_length(struct tpm_buf *buf);
51 void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_length);
52 void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value);
53 void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value);
54 void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value);
55 u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset);
56 u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset);
57 u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset);
58 void tpm_buf_append_handle(struct tpm_buf *buf, u32 handle);
59 
60 #endif
61