swtpm_ioctls(3) | swtpm_ioctls(3) |
swtpm_ioctls - Description of the ioctl's of the CUSE TPM (swtpm_cuse) and control commands used by the control channel over socket interface.
#include <tpm_ioctl.h>
The CUSE TPM implements an ioctl interface on the CUSE TPM's character device. The ioctl's are used for out-of-band control of various TPM operations, such as its initialization, resetting, and state migration. The control channel over TCP or UnixIO sockets uses control commands for these operations.
The following is an enumeration of the supported ioctl's and control commands, along with the names of the data structure types. All ioctl's and control commands return a TPM error code in their response. Ioctl's are prefixed with PTM and control commands are prefixed with CMD.
In case of the ioctl interface, the pointer to a command's data structure is passed as the 2nd parameter to the ioctl() function. The fields in the command's data structure are to be fill out in host endianness format.
In case of control commands, the command code must be encoded as a 4 byte integer preceding the command's data structure. Command code and data must be written in big endian format.
The ptm_init data structure looks as follows:
struct ptm_init { union { struct { uint32_t init_flags; /* see definitions below */ } req; /* request */ struct { ptm_res tpm_result; } resp; /* response */ } u; };
The init_flags field in the request can be used to have the TPM delete the volatile state upon startup (PTM_INIT_FLAG_DELETE_VOLATILE).
A TPM result code is returned in the tpm_result field.
A TPM result code is returned in ptm_res.
The tpm_est data structure looks as follows:
struct ptm_est { union { struct { ptm_res tpm_result; unsigned char bit; /* TPM established bit */ } resp; /* response */ } u; };
A TPM result code is returned in the tpm_result field.
The status of the TPM establishment flag is returned in the bit field.
The ptm_loc data structure looks as follows:
struct ptm_loc { union { struct { uint8_t loc; /* locality to set */ } req; /* request */ struct { ptm_res tpm_result; } resp; /* response */ } u; };
The locality number must be set in the request's loc field. Valid localities are in the range of 0 to 4.
A TPM result code is returned in the tpm_result field.
A TPM result code is returned in ptm_res.
The ptm_hdata structure looks as follows:
struct ptm_hdata { union { struct { uint32_t length; uint8_t data[4096]; } req; /* request */ struct { ptm_res tpm_result; } resp; /* response */ } u; };
The length of the data is indicated in the length field with the data in the data field. Up to 4096 bytes can be transferred in one call.
A TPM result code is returned in the tpm_result field.
A TPM result code is returned in ptm_res.
A TPM result code is returned in ptm_res.
A TPM result code is returned in ptm_res.
The ptm_reset_est data structure looks as follows:
struct ptm_reset_est { union { struct { uint8_t loc; /* locality to use */ } req; /* request */ struct { ptm_res tpm_result; } resp; /* response */ } u; };
The locality in which the establishment flag is to be reset must be set in the loc field. Valid localities are in the range of 0 to 4.
A TPM result code is returned in the tpm_result field.
The ptm_getstate data structure looks as follows:
struct ptm_getstate { union { struct { uint32_t state_flags; /* may be: PTM_STATE_FLAG_DECRYPTED */ uint32_t type; /* which blob to pull */ uint32_t offset; /* offset from where to read */ } req; /* request */ struct { ptm_res tpm_result; uint32_t state_flags; /* may be: PTM_STATE_FLAG_ENCRYPTED */ uint32_t totlength; /* total length that will be transferred */ uint32_t length; /* number of bytes in following buffer */ uint8_t data[PTM_STATE_BLOB_SIZE]; } resp; /* response */ } u; };
In the request the state_flags field allows a user to set the PTM_STATE_FLAG_DECRYPT flag to retrieve decrypted TPM state in case the TPM's state was written in encrypted form.
The type field allows a user to choose one of the TPM's state blobs, and must be one of PTM_BLOB_TYPE_PERMANENT, PTM_BLOB_TYPE_VOLATILE, and PTM_BLOB_TYPE_SAVESTATE.
The offset field indicates at what offset to read the data from. Subsequent state transfers must advance the offset field to the next byte to be read. If the read() interface is used the offset will be advanced automatically.
The response returns a TPM error code in the tpm_result field.
The state_flags field in the response indicates whether the returned blob is encrypted.
The totlength field indicates the total length of the state blob.
The length field indicates the number of valid bytes in the data field.
If necessary, subsequent state blob transfers must be done using this ioctl or using the read() call on the file descriptor. All state must be transferred before the TPM will accept commands again.
The ptm_setstate data structure looks as follows:
struct ptm_setstate { union { struct { uint32_t state_flags; /* may be PTM_STATE_FLAG_ENCRYPTED */ uint32_t type; /* which blob to set */ uint32_t length; /* length of the data; use 0 on the first packet to transfer using write() */ uint8_t data[PTM_STATE_BLOB_SIZE]; } req; /* request */ struct { ptm_res tpm_result; } resp; /* response */ } u; };
The state_flags field indicates whether the provided state is encrypted. In case it is encrypted, a migration key must have been provided to the TPM for it to be able to decrypt the state.
The type field indicates which one of the TPM's state blobs is being set. It must be either one of PTM_BLOB_TYPE_PERMANENT, PTM_BLOB_TYPE_VOLATILE, and PTM_BLOB_TYPE_SAVESTATE.
The length field indicates the number of bytes of state blob data in the data field. To transfer the state blob using the write() call, set the length to 0.
The response returns a TPM error code in the tpm_result field.
A TPM result code is returned in ptm_res.
The ptm_getconfig data structure looks as follows:
struct ptm_getconfig { union { struct { ptm_res tpm_result; uint32_t flags; } resp; /* response */ } u; };
A TPM result code is returned in the tpm_result field.
The flags field holds individual flags that indicate whether a file encryption key is used (PTM_CONFIG_FLAG_FILE_KEY) and whether a migration key is used (PTM_CONFIG_FLAG_MIGRATION_KEY).
A TPM result code is returned in ptm_res.
The ptm_setbuffersize data structure looks as follows:
struct ptm_setbuffersize { union { struct { uint32_t buffersize; /* 0 to query for current buffer size */ } req; /* request */ struct { ptm_res tpm_result; uint32_t buffersize; /* buffer size in use */ uint32_t minsize; /* min. supported buffer size */ uint32_t maxsize; /* max. supported buffer size */ } resp; /* response */ } u; };
If a 0 is set in the buffer size of the request, the response will return the buffer size that is currently in use. Any other number will try to change the buffer size, but the TPM may adjust it to an allowed minimum or maximum. The minimum and maximum supported buffer sizes are returned in the response.
The buffersize can only be changed when the TPM is stopped. The currently used buffersize can be read at any time.
swtpm_ioctl(8), swtpm_cuse(8)
2024-11-02 | swtpm |