|
NAMETPMLIB_RegisterCallbacks - Register callbacks for implementing customized behavior of certain functions LIBRARYTPM library (libtpms, -ltpms) SYNOPSIS#include <libtpms/tpm_types.h> #include <libtpms/tpm_library.h> #include <libtpms/tpm_error.h> TPM_RESULT TPMLIB_RegisterCallbacks(struct tpmlibrary_callbacks *); DESCRIPTIONThe TPMLIB_RegisterCallbacks() functions allows to register several callback functions with libtpms that enable a user to implement customized behavior of several library-internal functions. This feature will typically be used if the behavior of the provided internal functions is not as needed. An example would be that libtpms writes all data into files with certain names. If, however, the data needs to be written into a special type of storage the user will register callbacks with the library that are invoked when the TPM needs to write, read or delete data from storage and the user may then implement custom behavior in these functions. The following shows the data structure used for registering the callbacks. struct libtpms_callbacks {
int sizeOfStruct;
TPM_RESULT (*tpm_nvram_init)(void);
TPM_RESULT (*tpm_nvram_loaddata)(unsigned char **data,
uint32_t *length,
uint32_t tpm_number,
const char *name);
TPM_RESULT (*tpm_nvram_storedata)(const unsigned char *data,
uint32_t length,
uint32_t tpm_number,
const char *name);
TPM_RESULT (*tpm_nvram_deletename)(uint32_t tpm_number,
const char *name,
TPM_BOOL mustExist);
TPM_RESULT (*tpm_io_init)(void);
TPM_RESULT (*tpm_io_getlocality)(TPM_MODIFIER_INDICATOR *localityModifer,
uint32_t tpm_number);
TPM_RESULT (*tpm_io_getphysicalpresence)(TPM_BOOL *physicalPresence,
uint32_t tpm_number);
};
Currently 7 callbacks are supported. If a callback pointer in the above structure is set to NULL the default library-internal implementation of that function will be used. If one of the callbacks in either the tpm_nvram or tpm_io group is set, then all of the callbacks in the respective group should be implemented.
RETURN VALUEUpon successful completion, TPMLIB_MainInit() returns TPM_SUCCESS, an error value otherwise. ERRORS
For a complete list of TPM error codes please consult the include file libtpms/tpm_error.h EXAMPLE #include <libtpms/tpm_types.h>
#include <libtpms/tpm_library.h>
#include <libtpms/tpm_error.h>
static TPM_MODIFIER_INDICATOR locality;
static TPM_RESULT mytpm_io_init(void)
{
return TPM_SUCCESS;
}
static TPM_RESULT mytpm_io_getlocality(TPM_MODIFIER_INDICATOR *locModif,
uint32_t tpm_number)
{
*locModif = locality;
return TPM_SUCCESS:
}
static TPM_RESULT mytpm_io_getphysicalpresence(TPM_BOOL *physicalPresence,
uint32_t tpm_number)
{
*physicalPresence = FALSE;
return TPM_SUCCESS;
}
int main(void) {
TPM_RESULT res;
unsigned char *respbuffer;
uint32_t resp_size;
uint32_t respbufsize;
unsigned char *command;
uint32_t command_size;
struct libtpms_callbacks cbs = {
.sizeOfStruct = sizeof(struct libtpms_callbacks),
.tpm_nvram_init = NULL,
.tpm_nvram_loaddata = NULL,
.tpm_nvram_storedata = NULL,
.tpm_nvram_deletename = NULL,
.tpm_io_init = mytpm_io_init,
.tpm_io_getlocality = mytpm_io_getlocality,
.tpm_io_getphysicalpresence = mytpm_io_getphysicalpresence,
};
[...]
if (TPMLIB_RegisterCallbacks(&cbs) != TPM_SUCCESS) {
fprintf(stderr, "Could not register the callbacks.\n");
return 1;
}
if (TPMLIB_MainInit()) != TPM_SUCCESS) {
fprintf(stderr, "Could not start the TPM.\n");
return 1;
}
[...]
/* build TPM command */
[...]
res = TPMLIB_Process(&respbuffer, &resp_size,
&respbufsize,
command, command_size);
[...]
TPMLIB_Terminate();
return 0;
}
SEE ALSOTPMLIB_Process(3), TPMLIB_MainInit(3), TPMLIB_Terminate(3), TPMLIB_DecodeBlobs(3)
|