3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004-2006
17
#include "trousers/tss.h"
18
#include "trousers_types.h"
20
#include "tcs_utils.h"
21
#include "tcs_int_literals.h"
22
#include "capabilities.h"
24
#include "tcsd_wrap.h"
26
#include "tcs_utils.h"
27
#include "rpc_tcstp_tcs.h"
31
tcs_wrap_GetCapability(struct tcsd_thread_data *data)
33
TCS_CONTEXT_HANDLE hContext;
34
TCPA_CAPABILITY_AREA capArea;
41
if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
42
return TCSERR(TSS_E_INTERNAL_ERROR);
44
LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
46
if (getData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &data->comm))
47
return TCSERR(TSS_E_INTERNAL_ERROR);
48
if (getData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &data->comm))
49
return TCSERR(TSS_E_INTERNAL_ERROR);
54
subCap = calloc(1, subCapSize);
56
LogError("malloc of %u bytes failed.", subCapSize);
57
return TCSERR(TSS_E_OUTOFMEMORY);
59
if (getData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &data->comm)) {
61
return TCSERR(TSS_E_INTERNAL_ERROR);
65
MUTEX_LOCK(tcsp_lock);
67
result = TCSP_GetCapability_Internal(hContext, capArea, subCapSize, subCap, &respSize,
70
MUTEX_UNLOCK(tcsp_lock);
73
if (result == TSS_SUCCESS) {
74
initData(&data->comm, 2);
75
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &respSize, 0, &data->comm)) {
77
return TCSERR(TSS_E_INTERNAL_ERROR);
79
if (setData(TCSD_PACKET_TYPE_PBYTE, 1, resp, respSize, &data->comm)) {
81
return TCSERR(TSS_E_INTERNAL_ERROR);
85
initData(&data->comm, 0);
87
data->comm.hdr.u.result = result;
92
tcs_wrap_GetCapabilityOwner(struct tcsd_thread_data *data)
94
TCS_CONTEXT_HANDLE hContext;
101
if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
102
return TCSERR(TSS_E_INTERNAL_ERROR);
104
LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
106
if (getData(TCSD_PACKET_TYPE_AUTH, 1, &ownerAuth, 0, &data->comm))
107
return TCSERR(TSS_E_INTERNAL_ERROR);
109
MUTEX_LOCK(tcsp_lock);
111
result = TCSP_GetCapabilityOwner_Internal(hContext, &ownerAuth, &version, &nonVol, &vol);
113
MUTEX_UNLOCK(tcsp_lock);
115
if (result == TSS_SUCCESS) {
116
initData(&data->comm, 4);
117
if (setData(TCSD_PACKET_TYPE_VERSION, 0, &version, 0, &data->comm)) {
118
return TCSERR(TSS_E_INTERNAL_ERROR);
120
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &nonVol, 0, &data->comm)) {
121
return TCSERR(TSS_E_INTERNAL_ERROR);
123
if (setData(TCSD_PACKET_TYPE_UINT32, 2, &vol, 0, &data->comm)) {
124
return TCSERR(TSS_E_INTERNAL_ERROR);
126
if (setData(TCSD_PACKET_TYPE_AUTH, 3, &ownerAuth, 0, &data->comm)) {
127
return TCSERR(TSS_E_INTERNAL_ERROR);
130
initData(&data->comm, 0);
132
data->comm.hdr.u.result = result;
137
tcs_wrap_SetCapability(struct tcsd_thread_data *data)
139
TCS_CONTEXT_HANDLE hContext;
140
TCPA_CAPABILITY_AREA capArea;
146
TPM_AUTH ownerAuth, *pOwnerAuth;
148
if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
149
return TCSERR(TSS_E_INTERNAL_ERROR);
151
LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
153
if (getData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &data->comm))
154
return TCSERR(TSS_E_INTERNAL_ERROR);
155
if (getData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &data->comm))
156
return TCSERR(TSS_E_INTERNAL_ERROR);
161
subCap = calloc(1, subCapSize);
162
if (subCap == NULL) {
163
LogError("malloc of %u bytes failed.", subCapSize);
164
return TCSERR(TSS_E_OUTOFMEMORY);
166
if (getData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &data->comm)) {
168
return TCSERR(TSS_E_INTERNAL_ERROR);
172
if (getData(TCSD_PACKET_TYPE_UINT32, 4, &valueSize, 0, &data->comm))
173
return TCSERR(TSS_E_INTERNAL_ERROR);
178
value = calloc(1, valueSize);
181
LogError("malloc of %u bytes failed.", valueSize);
182
return TCSERR(TSS_E_OUTOFMEMORY);
184
if (getData(TCSD_PACKET_TYPE_PBYTE, 5, value, valueSize, &data->comm)) {
187
return TCSERR(TSS_E_INTERNAL_ERROR);
191
if (getData(TCSD_PACKET_TYPE_AUTH, 6, &ownerAuth, 0, &data->comm))
194
pOwnerAuth = &ownerAuth;
197
MUTEX_LOCK(tcsp_lock);
199
result = TCSP_SetCapability_Internal(hContext, capArea, subCapSize, subCap, valueSize,
202
MUTEX_UNLOCK(tcsp_lock);
206
if (result == TSS_SUCCESS) {
207
initData(&data->comm, 1);
209
if (setData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &data->comm)) {
210
return TCSERR(TSS_E_INTERNAL_ERROR);
214
initData(&data->comm, 0);
216
data->comm.hdr.u.result = result;