1
2/*
3 * Licensed Materials - Property of IBM
4 *
5 * trousers - An open source TCG Software Stack
6 *
7 * (C) Copyright International Business Machines Corp. 2004-2006
8 *
9 */
10
11#include <stdlib.h>
12#include <stdio.h>
13#include <string.h>
14#include <assert.h>
15
16#include "trousers/tss.h"
17#include "trousers/trousers.h"
18#include "trousers_types.h"
19#include "spi_utils.h"
20#include "capabilities.h"
21#include "tsplog.h"
22#include "hosttable.h"
23#include "tcsd_wrap.h"
24#include "obj.h"
25#include "rpc_tcstp_tsp.h"
26
27
28TSS_RESULT
29RPC_SelfTestFull_TP(struct host_table_entry *hte)
30{
31	TSS_RESULT result;
32
33	initData(&hte->comm, 1);
34	hte->comm.hdr.u.ordinal = TCSD_ORD_SELFTESTFULL;
35	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
36
37	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
38		return TSPERR(TSS_E_INTERNAL_ERROR);
39
40	result = sendTCSDPacket(hte);
41
42	if (result == TSS_SUCCESS)
43		result = hte->comm.hdr.u.result;
44
45	return result;
46}
47
48TSS_RESULT
49RPC_CertifySelfTest_TP(struct host_table_entry *hte,
50			TCS_KEY_HANDLE keyHandle,	/* in */
51			TCPA_NONCE antiReplay,	/* in */
52			TPM_AUTH * privAuth,	/* in, out */
53			UINT32 * sigSize,	/* out */
54			BYTE ** sig)	/* out */
55{
56	TSS_RESULT result;
57	int i;
58
59	initData(&hte->comm, 4);
60	hte->comm.hdr.u.ordinal = TCSD_ORD_CERTIFYSELFTEST;
61	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
62
63	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
64		return TSPERR(TSS_E_INTERNAL_ERROR);
65	if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
66		return TSPERR(TSS_E_INTERNAL_ERROR);
67	if (setData(TCSD_PACKET_TYPE_NONCE, 2, &antiReplay, 0, &hte->comm))
68		return TSPERR(TSS_E_INTERNAL_ERROR);
69
70	if (privAuth) {
71		if (setData(TCSD_PACKET_TYPE_AUTH, 3, privAuth, 0, &hte->comm))
72			return TSPERR(TSS_E_INTERNAL_ERROR);
73	}
74
75	result = sendTCSDPacket(hte);
76
77	if (result == TSS_SUCCESS)
78		result = hte->comm.hdr.u.result;
79
80	if (result == TSS_SUCCESS) {
81		i = 0;
82		if (privAuth) {
83			if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) {
84				LogDebug("privAuth");
85				result = TSPERR(TSS_E_INTERNAL_ERROR);
86				goto done;
87			}
88		}
89		if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) {
90			LogDebug("sigSize");
91			result = TSPERR(TSS_E_INTERNAL_ERROR);
92			goto done;
93		}
94		*sig = (BYTE *) malloc(*sigSize);
95		if (*sig == NULL) {
96			LogError("malloc of %u bytes failed.", *sigSize);
97			result = TSPERR(TSS_E_OUTOFMEMORY);
98			goto done;
99		}
100		if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) {
101			LogDebug("sig");
102			free(*sig);
103			result = TSPERR(TSS_E_INTERNAL_ERROR);
104		}
105	}
106
107done:
108	return result;
109}
110
111TSS_RESULT
112RPC_GetTestResult_TP(struct host_table_entry *hte,
113		      UINT32 * outDataSize,	/* out */
114		      BYTE ** outData)	/* out */
115{
116	TSS_RESULT result;
117
118	initData(&hte->comm, 1);
119	hte->comm.hdr.u.ordinal = TCSD_ORD_GETTESTRESULT;
120	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
121
122	LogDebug("RPC_GetTestResult_TP");
123	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
124		return TSPERR(TSS_E_INTERNAL_ERROR);
125
126	result = sendTCSDPacket(hte);
127
128	if (result == TSS_SUCCESS)
129		result = hte->comm.hdr.u.result;
130
131	if (result == TSS_SUCCESS) {
132		LogDebug("sendTCSDPacket succeeded");
133		if (getData(TCSD_PACKET_TYPE_UINT32, 0, outDataSize, 0, &hte->comm)) {
134			result = TSPERR(TSS_E_INTERNAL_ERROR);
135			goto done;
136		}
137
138		*outData = malloc(*outDataSize);
139		if (*outData == NULL) {
140			LogError("malloc of %u bytes failed.", *outDataSize);
141			result = TSPERR(TSS_E_OUTOFMEMORY);
142			goto done;
143		}
144
145		if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *outData, *outDataSize, &hte->comm)) {
146			free(*outData);
147			*outData = NULL;
148			result = TSPERR(TSS_E_INTERNAL_ERROR);
149		}
150	}
151	LogDebug("RPC_GetTestResult_TP exit");
152
153done:
154	return result;
155}
156