xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/tspi/rpc/tcstp/rpc_dir.c (revision 2d5f7628c5531eb583b9313ac2fd1cf8582b4479)
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 
28 TSS_RESULT
RPC_DirWriteAuth_TP(struct host_table_entry * hte,TCPA_DIRINDEX dirIndex,TCPA_DIRVALUE * newContents,TPM_AUTH * ownerAuth)29 RPC_DirWriteAuth_TP(struct host_table_entry *hte,
30 				 TCPA_DIRINDEX dirIndex,	/* in */
31 				 TCPA_DIRVALUE *newContents,	/* in */
32 				 TPM_AUTH * ownerAuth	/* in, out */
33     ) {
34 	TSS_RESULT result;
35 
36 	initData(&hte->comm, 4);
37 	hte->comm.hdr.u.ordinal = TCSD_ORD_DIRWRITEAUTH;
38 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
39 
40 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
41 		return TSPERR(TSS_E_INTERNAL_ERROR);
42 	if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &hte->comm))
43 		return TSPERR(TSS_E_INTERNAL_ERROR);
44 	if (setData(TCSD_PACKET_TYPE_DIGEST, 2, newContents, 0, &hte->comm))
45 		return TSPERR(TSS_E_INTERNAL_ERROR);
46 	if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm))
47 		return TSPERR(TSS_E_INTERNAL_ERROR);
48 
49 	result = sendTCSDPacket(hte);
50 
51 	if (result == TSS_SUCCESS)
52 		result = hte->comm.hdr.u.result;
53 
54 	if (result == TSS_SUCCESS) {
55 		if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
56 			result = TSPERR(TSS_E_INTERNAL_ERROR);
57 	}
58 
59 	return result;
60 }
61 
62 TSS_RESULT
RPC_DirRead_TP(struct host_table_entry * hte,TCPA_DIRINDEX dirIndex,TCPA_DIRVALUE * dirValue)63 RPC_DirRead_TP(struct host_table_entry *hte,
64 			    TCPA_DIRINDEX dirIndex,	/* in */
65 			    TCPA_DIRVALUE * dirValue	/* out */
66     ) {
67 	TSS_RESULT result;
68 
69 	initData(&hte->comm, 2);
70 	hte->comm.hdr.u.ordinal = TCSD_ORD_DIRREAD;
71 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
72 
73 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
74 		return TSPERR(TSS_E_INTERNAL_ERROR);
75 	if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &hte->comm))
76 		return TSPERR(TSS_E_INTERNAL_ERROR);
77 
78 	result = sendTCSDPacket(hte);
79 
80 	if (result == TSS_SUCCESS)
81 		result = hte->comm.hdr.u.result;
82 
83 	if (hte->comm.hdr.u.result == TSS_SUCCESS) {
84 		if (getData(TCSD_PACKET_TYPE_DIGEST, 0, dirValue, 0, &hte->comm))
85 			result = TSPERR(TSS_E_INTERNAL_ERROR);
86 	}
87 
88 	return result;
89 }
90