rpc_context.c revision 1.1
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 <syslog.h>
14#include <string.h>
15#include <netdb.h>
16
17#include "trousers/tss.h"
18#include "trousers_types.h"
19#include "tcs_tsp.h"
20#include "tcs_utils.h"
21#include "tcs_int_literals.h"
22#include "capabilities.h"
23#include "tcslog.h"
24#include "tcsd_wrap.h"
25#include "tcsd.h"
26#include "tcs_utils.h"
27#include "rpc_tcstp_tcs.h"
28
29
30TSS_RESULT
31tcs_wrap_OpenContext(struct tcsd_thread_data *data)
32{
33	TCS_CONTEXT_HANDLE hContext;
34	TSS_RESULT result;
35	UINT32 tpm_version = tpm_metrics.version.minor;
36
37	LogDebugFn("thread %ld", THREAD_ID);
38
39	result = TCS_OpenContext_Internal(&hContext);
40	if (result == TSS_SUCCESS) {
41		initData(&data->comm, 2);
42		if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
43			return TCSERR(TSS_E_INTERNAL_ERROR);
44
45		if (setData(TCSD_PACKET_TYPE_UINT32, 1, &tpm_version, 0, &data->comm))
46			return TCSERR(TSS_E_INTERNAL_ERROR);
47
48		/* Set the context in the thread's object. Later, if something goes wrong
49		 * and the connection can't be closed cleanly, we'll still have a reference
50		 * to what resources need to be freed. */
51		data->context = hContext;
52	} else
53		initData(&data->comm, 0);
54
55	data->comm.hdr.u.result = result;
56
57	return TSS_SUCCESS;
58}
59
60TSS_RESULT
61tcs_wrap_CloseContext(struct tcsd_thread_data *data)
62{
63	TCS_CONTEXT_HANDLE hContext;
64	TSS_RESULT result;
65
66	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
67		return TCSERR(TSS_E_INTERNAL_ERROR);
68
69	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
70
71	result = TCS_CloseContext_Internal(hContext);
72
73	/* This will signal the thread that the connection has been closed cleanly */
74	if (result == TSS_SUCCESS)
75		data->context = NULL_TCS_HANDLE;
76
77	initData(&data->comm, 0);
78	data->comm.hdr.u.result = result;
79
80	return TSS_SUCCESS;
81}
82