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
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <inttypes.h>
16
17 #include "trousers/tss.h"
18 #include "trousers_types.h"
19 #include "tcs_tsp.h"
20 #include "tcsps.h"
21 #include "tcs_utils.h"
22 #include "tcs_int_literals.h"
23 #include "capabilities.h"
24 #include "tcslog.h"
25 #include "req_mgr.h"
26 #include "tcsd_wrap.h"
27 #include "tcsd.h"
28
29
30 TSS_RESULT
TCSP_GetCapability_Internal(TCS_CONTEXT_HANDLE hContext,TCPA_CAPABILITY_AREA capArea,UINT32 subCapSize,BYTE * subCap,UINT32 * respSize,BYTE ** resp)31 TCSP_GetCapability_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
32 TCPA_CAPABILITY_AREA capArea, /* in */
33 UINT32 subCapSize, /* in */
34 BYTE * subCap, /* in */
35 UINT32 * respSize, /* out */
36 BYTE ** resp) /* out */
37 {
38 UINT64 offset = 0;
39 UINT32 paramSize;
40 TSS_RESULT result;
41 BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
42
43 LogDebug("Entering Get Cap");
44
45 if ((result = tpm_rqu_build(TPM_ORD_GetCapability, &offset, txBlob, capArea, subCapSize,
46 subCap, NULL)))
47 return result;
48
49 if ((result = req_mgr_submit_req(txBlob)))
50 return result;
51
52 result = UnloadBlob_Header(txBlob, ¶mSize);
53 if (!result) {
54 result = tpm_rsp_parse(TPM_ORD_GetCapability, txBlob, paramSize, respSize, resp,
55 NULL, NULL);
56 }
57 LogResult("Get Cap", result);
58 return result;
59 }
60
61 TSS_RESULT
TCSP_GetCapabilityOwner_Internal(TCS_CONTEXT_HANDLE hContext,TPM_AUTH * pOwnerAuth,TCPA_VERSION * pVersion,UINT32 * pNonVolatileFlags,UINT32 * pVolatileFlags)62 TCSP_GetCapabilityOwner_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
63 TPM_AUTH * pOwnerAuth, /* in / out */
64 TCPA_VERSION * pVersion, /* out */
65 UINT32 * pNonVolatileFlags, /* out */
66 UINT32 * pVolatileFlags) /* out */
67 {
68 UINT64 offset = 0;
69 TSS_RESULT result;
70 UINT32 paramSize;
71 BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
72
73 LogDebug("Entering Getcap owner");
74
75 if ((result = ctx_verify_context(hContext)))
76 goto done;
77
78 if ((result = auth_mgr_check(hContext, &pOwnerAuth->AuthHandle)))
79 goto done;
80
81 if ((result = tpm_rqu_build(TPM_ORD_GetCapabilityOwner, &offset, txBlob, pOwnerAuth)))
82 goto done;
83
84 if ((result = req_mgr_submit_req(txBlob)))
85 goto done;
86
87 result = UnloadBlob_Header(txBlob, ¶mSize);
88 if (!result) {
89 result = tpm_rsp_parse(TPM_ORD_GetCapabilityOwner, txBlob, paramSize, pVersion,
90 pNonVolatileFlags, pVolatileFlags, pOwnerAuth);
91 }
92
93 LogResult("GetCapowner", result);
94 done:
95 auth_mgr_release_auth(pOwnerAuth, NULL, hContext);
96 return result;
97 }
98
99 TSS_RESULT
TCSP_SetCapability_Internal(TCS_CONTEXT_HANDLE hContext,TCPA_CAPABILITY_AREA capArea,UINT32 subCapSize,BYTE * subCap,UINT32 valueSize,BYTE * value,TPM_AUTH * pOwnerAuth)100 TCSP_SetCapability_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
101 TCPA_CAPABILITY_AREA capArea, /* in */
102 UINT32 subCapSize, /* in */
103 BYTE * subCap, /* in */
104 UINT32 valueSize, /* in */
105 BYTE * value, /* in */
106 TPM_AUTH * pOwnerAuth) /* in, out */
107 {
108 UINT64 offset = 0;
109 TSS_RESULT result;
110 UINT32 paramSize;
111 BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
112
113 if ((result = ctx_verify_context(hContext)))
114 goto done;
115
116 if ((pOwnerAuth != NULL) &&
117 (result = auth_mgr_check(hContext, &pOwnerAuth->AuthHandle)))
118 goto done;
119
120 if ((result = tpm_rqu_build(TPM_ORD_SetCapability, &offset, txBlob, capArea, subCapSize,
121 subCap, valueSize, value, pOwnerAuth)))
122 return result;
123
124 if ((result = req_mgr_submit_req(txBlob)))
125 goto done;
126
127 result = UnloadBlob_Header(txBlob, ¶mSize);
128 if (!result) {
129 result = tpm_rsp_parse(TPM_ORD_SetCapability, txBlob, paramSize, pOwnerAuth);
130 }
131
132 done:
133 auth_mgr_release_auth(pOwnerAuth, NULL, hContext);
134 return result;
135 }
136
137