xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/tspi/rpc/tcstp/rpc_bind.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_UnBind_TP(struct host_table_entry * hte,TCS_KEY_HANDLE keyHandle,UINT32 inDataSize,BYTE * inData,TPM_AUTH * privAuth,UINT32 * outDataSize,BYTE ** outData)29 RPC_UnBind_TP(struct host_table_entry *hte,
30 			   TCS_KEY_HANDLE keyHandle,	/* in */
31 			   UINT32 inDataSize,	/* in */
32 			   BYTE * inData,	/* in */
33 			   TPM_AUTH * privAuth,	/* in, out */
34 			   UINT32 * outDataSize,	/* out */
35 			   BYTE ** outData	/* out */
36     ) {
37 	TSS_RESULT result;
38 	int i;
39 
40 	initData(&hte->comm, 5);
41 	hte->comm.hdr.u.ordinal = TCSD_ORD_UNBIND;
42 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
43 
44 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
45 		return TSPERR(TSS_E_INTERNAL_ERROR);
46 	if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
47 		return TSPERR(TSS_E_INTERNAL_ERROR);
48 	if (setData(TCSD_PACKET_TYPE_UINT32, 2, &inDataSize, 0, &hte->comm))
49 		return TSPERR(TSS_E_INTERNAL_ERROR);
50 	if (setData(TCSD_PACKET_TYPE_PBYTE, 3, inData, inDataSize, &hte->comm))
51 		return TSPERR(TSS_E_INTERNAL_ERROR);
52 
53 	if (privAuth != NULL) {
54 		if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm))
55 			return TSPERR(TSS_E_INTERNAL_ERROR);
56 	}
57 
58 	result = sendTCSDPacket(hte);
59 
60 	if (result == TSS_SUCCESS)
61 		result = hte->comm.hdr.u.result;
62 
63 	if (result == TSS_SUCCESS) {
64 		i = 0;
65 		if (privAuth != NULL) {
66 			if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) {
67 				result = TSPERR(TSS_E_INTERNAL_ERROR);
68 				goto done;
69 			}
70 		}
71 		if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) {
72 			result = TSPERR(TSS_E_INTERNAL_ERROR);
73 			goto done;
74 		}
75 
76 		*outData = (BYTE *) malloc(*outDataSize);
77 		if (*outData == NULL) {
78 			LogError("malloc of %u bytes failed.", *outDataSize);
79 			result = TSPERR(TSS_E_OUTOFMEMORY);
80 			goto done;
81 		}
82 		if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) {
83 			free(*outData);
84 			result = TSPERR(TSS_E_INTERNAL_ERROR);
85 		}
86 	}
87 
88 done:
89 	return result;
90 }
91