blob: f3d97fe11911527f93aeeee2f39ef7398f295055 [file] [log] [blame]
Will Arthur54e04e42015-07-15 11:29:25 -04001//**********************************************************************;
2// Copyright (c) 2015, Intel Corporation
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice,
12// this list of conditions and the following disclaimer in the documentation
13// and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25// THE POSSIBILITY OF SUCH DAMAGE.
26//**********************************************************************;
27
28#ifndef RESOURCEMGR_H
29#define RESOURCEMGR_H
30
unknown53db2ff2015-09-01 18:08:18 -040031//#include "tpmclient.h"
Will Arthur54e04e42015-07-15 11:29:25 -040032#include "tss2_tcti.h"
33#include "tss2_sysapi_util.h"
34#include <stdlib.h>
35
36#define TSS2_RESMGR_MEMALLOC_FAILED ((TSS2_RC)(1 + TSS2_RESMGR_ERROR_LEVEL))
37#define TSS2_RESMGR_FIND_FAILED ((TSS2_RC)(2 + TSS2_RESMGR_ERROR_LEVEL))
38#define TSS2_RESMGR_BAD_FINDFIELD ((TSS2_RC)(3 + TSS2_RESMGR_ERROR_LEVEL))
39#define TSS2_RESMGR_VIRTUAL_HANDLE_OVERFLOW ((TSS2_RC)(4 + TSS2_RESMGR_ERROR_LEVEL)) // If more virtual handles are attempted to be allocated than RM can allocate.
40#define TSS2_RESMGR_UNOWNED_HANDLE ((TSS2_RC)(5 + TSS2_RESMGR_ERROR_LEVEL))
41#define TSS2_RESMGR_CONTINUE_BIT_MISMATCH ((TSS2_RC)(6 + TSS2_RESMGR_ERROR_LEVEL))
42#define TSS2_RESMGR_INSUFFICIENT_RESPONSE ((TSS2_RC)(7 + TSS2_RESMGR_ERROR_LEVEL)) // TPM response not enough bytes to look at return code.
43#define TSS2_RESMGR_INIT_SYS_CONTEXT_FAILED ((TSS2_RC)(8 + TSS2_RESMGR_ERROR_LEVEL))
44#define TSS2_RESMGR_INIT_FAILED ((TSS2_RC)(9 + TSS2_RESMGR_ERROR_LEVEL))
45#define TSS2_RESMGR_TCTI_INIT_FAILED ((TSS2_RC)(10 + TSS2_RESMGR_ERROR_LEVEL))
46#define TSS2_RESMGR_GAP_HANDLING_FAILED ((TSS2_RC)(11 + TSS2_RESMGR_ERROR_LEVEL))
47#define TSS2_RESMGR_UNLOADED_OBJECTS ((TSS2_RC)(12 + TSS2_RESMGR_ERROR_LEVEL))
48#define TSS2_RESMGR_UNLOADED_SESSIONS ((TSS2_RC)(13 + TSS2_RESMGR_ERROR_LEVEL))
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54extern UINT32 tpmMaxResponseLen;
55
56extern UINT8 rmDebugPrefix;
57
58TSS2_RC ResourceMgrSendTpmCommand(
59 TSS2_TCTI_CONTEXT *tctiContext,
60 size_t command_size, /* in */
61 uint8_t *command_buffer /* in */
62);
63
64TSS2_RC ResourceMgrReceiveTpmResponse(
65 TSS2_TCTI_CONTEXT *tctiContext,
66 UINT32 *response_size, /* out */
67 uint8_t *response_buffer, /* in */
68 int32_t timeout
69 );
70
71enum debugLevel { DBG_NO_COMMAND = 0, DBG_COMMAND = 1, DBG_COMMAND_RM = 2, DBG_COMMAND_RM_TABLES = 3 };
72
73void ResourceMgrInit( int debugLevel );
74
75// Uncommentting DEBUG_GAP_HANDLING instruments the max active sessions and gap
76// max values to something small that allows us to debug this feature.
77//
78// NOTE: only uncomment DEBUG_GAP_HANDLING this if you know what
79// you're doing. For this to work a specially doctored simulator
80// must be built with the following changes to implementation.h:
81//
82// #if 0
83// #define MAX_ACTIVE_SESSIONS 64
84// #define CONTEXT_SLOT UINT16
85// #else
86// #define MAX_ACTIVE_SESSIONS 32
87// #define CONTEXT_SLOT UINT8
88// #endif
89//
90#define DEBUG_GAP_HANDLING
91//
92#ifdef DEBUG_GAP_HANDLING
93// NOTE: these values must match the ones
94// for the simulator. For the following
95// I was running against a simulator built with
96// modified values for these. This was
97// done to facillitate faster testing of gap
98// handling in the resource manager.
99#define DEBUG_MAX_ACTIVE_SESSIONS 32
100#define DEBUG_GAP_MAX 255
101#endif
102
103extern TSS2_TCTI_DRIVER_INFO resMgrTctiDriverInfo;
104
105TSS2_RC InitResMgr( int debugLevel );
106
107#ifdef __cplusplus
108}
109#endif
110
111
112extern void *(*rmMalloc)(size_t size);
113extern void (*rmFree)(void *entry);
114extern int (*rmPrintf)( const char *format, ...);
115
116extern int printRMTables;
117
118#endif
119