summaryrefslogtreecommitdiff
path: root/src/tspi/tsp_admin.c
blob: 8b856c61d28403392bd67c386364ad00e95a7a3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

/*
 * Licensed Materials - Property of IBM
 *
 * trousers - An open source TCG Software Stack
 *
 * (C) Copyright International Business Machines Corp. 2007
 *
 */


#include <stdlib.h>
#include <string.h>

#include "trousers/tss.h"
#include "trousers/trousers.h"
#include "trousers_types.h"
#include "spi_utils.h"
#include "capabilities.h"
#include "tsplog.h"
#include "obj.h"


#ifdef TSS_BUILD_TRANSPORT
TSS_RESULT
Transport_GetCapabilityOwner(TSS_HCONTEXT tspContext,      /* in */
			     TPM_AUTH * pOwnerAuth,        /* in/out */
			     TCPA_VERSION * pVersion,      /* out */
			     UINT32 * pNonVolatileFlags,   /* out */
			     UINT32 * pVolatileFlags)      /* out */
{
	UINT64 offset;
	TSS_RESULT result;
	UINT32 handlesLen = 0, decLen;
	BYTE *dec;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	if ((result = obj_context_transport_execute(tspContext, TPM_ORD_GetCapabilityOwner, 0, NULL,
						    NULL, &handlesLen, NULL, pOwnerAuth, NULL,
						    &decLen, &dec)))
		return result;

	offset = 0;
	Trspi_UnloadBlob_TCPA_VERSION(&offset, dec, pVersion);
	Trspi_UnloadBlob_UINT32(&offset, pNonVolatileFlags, dec);
	Trspi_UnloadBlob_UINT32(&offset, pVolatileFlags, dec);

	free(dec);

	return result;
}

TSS_RESULT
Transport_SetOwnerInstall(TSS_HCONTEXT tspContext, /* in */
			  TSS_BOOL state)  /* in */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_SetOwnerInstall,
					       sizeof(TSS_BOOL), (BYTE *)&state, NULL, &handlesLen,
					       NULL, NULL, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_DisableOwnerClear(TSS_HCONTEXT tspContext,       /* in */
			    TPM_AUTH * ownerAuth)  /* in, out */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_DisableOwnerClear, 0, NULL, NULL,
					       &handlesLen, NULL, ownerAuth, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_DisableForceClear(TSS_HCONTEXT tspContext)       /* in */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_DisableForceClear, 0, NULL, NULL,
					       &handlesLen, NULL, NULL, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_OwnerSetDisable(TSS_HCONTEXT tspContext, /* in */
			  TSS_BOOL disableState,   /* in */
			  TPM_AUTH * ownerAuth)    /* in, out */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_OwnerSetDisable,
					       sizeof(TSS_BOOL), (BYTE *)&disableState, NULL,
					       &handlesLen, NULL, ownerAuth, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_PhysicalDisable(TSS_HCONTEXT tspContext) /* in */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_PhysicalDisable, 0, NULL, NULL,
					       &handlesLen, NULL, NULL, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_PhysicalEnable(TSS_HCONTEXT tspContext)  /* in */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_PhysicalEnable, 0, NULL, NULL,
					       &handlesLen, NULL, NULL, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_PhysicalSetDeactivated(TSS_HCONTEXT tspContext,  /* in */
				 TSS_BOOL state)   /* in */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_PhysicalSetDeactivated,
					       sizeof(TSS_BOOL), (BYTE *)&state, NULL, &handlesLen,
					       NULL, NULL, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_SetTempDeactivated(TSS_HCONTEXT tspContext)      /* in */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_SetTempDeactivated, 0, NULL,
					       NULL, &handlesLen, NULL, NULL, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_SetTempDeactivated2(TSS_HCONTEXT tspContext,     /* in */
			      TPM_AUTH *operatorAuth)      /* in, out */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_SetTempDeactivated, 0, NULL,
					       NULL, &handlesLen, NULL, operatorAuth, NULL, NULL,
					       NULL);

	return result;
}

TSS_RESULT
Transport_DisablePubekRead(TSS_HCONTEXT tspContext,        /* in */
			   TPM_AUTH * ownerAuth)   /* in, out */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_DisablePubekRead, 0, NULL, NULL,
					       &handlesLen, NULL, ownerAuth, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_ResetLockValue(TSS_HCONTEXT tspContext,  /* in */
			 TPM_AUTH * ownerAuth)     /* in, out */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TPM_ORD_ResetLockValue, 0, NULL, NULL,
					       &handlesLen, NULL, ownerAuth, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_PhysicalPresence(TSS_HCONTEXT tspContext,        /* in */
			   TCPA_PHYSICAL_PRESENCE fPhysicalPresence)       /* in */
{
	TSS_RESULT result;
	UINT32 handlesLen = 0;

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	result = obj_context_transport_execute(tspContext, TSC_ORD_PhysicalPresence,
					       sizeof(TCPA_PHYSICAL_PRESENCE),
					       (BYTE *)&fPhysicalPresence, NULL, &handlesLen, NULL,
					       NULL, NULL, NULL, NULL);

	return result;
}

TSS_RESULT
Transport_FlushSpecific(TSS_HCONTEXT tspContext, /* in */
			TCS_HANDLE hResHandle, /* in */
			TPM_RESOURCE_TYPE resourceType) /* in */
{
	UINT64 offset;
	TSS_RESULT result;
	UINT32 handlesLen = 1;
	TCS_HANDLE *handles, handle;
	BYTE data[sizeof(UINT32)];

	if ((result = obj_context_transport_init(tspContext)))
		return result;

	LogDebugFn("Executing in a transport session");

	handle = hResHandle;
	handles = &handle;

	offset = 0;
	Trspi_LoadBlob_UINT32(&offset, resourceType, data);

	result = obj_context_transport_execute(tspContext, TPM_ORD_FlushSpecific, sizeof(data),
					       data, NULL, &handlesLen, &handles, NULL, NULL, NULL,
					       NULL);

	return result;
}
#endif