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-2007
8 *
9 */
10
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14
15 #include "trousers/tss.h"
16 #include "trousers/trousers.h"
17 #include "trousers_types.h"
18 #include "spi_utils.h"
19 #include "capabilities.h"
20 #include "tsplog.h"
21 #include "obj.h"
22
23
24 #ifdef TSS_BUILD_TRANSPORT
25 TSS_RESULT
Transport_ReadCounter(TSS_HCONTEXT tspContext,TSS_COUNTER_ID idCounter,TPM_COUNTER_VALUE * counterValue)26 Transport_ReadCounter(TSS_HCONTEXT tspContext, /* in */
27 TSS_COUNTER_ID idCounter, /* in */
28 TPM_COUNTER_VALUE* counterValue) /* out */
29 {
30 TSS_RESULT result;
31 UINT32 decLen = 0;
32 BYTE *dec = NULL;
33 UINT64 offset;
34 TCS_HANDLE handlesLen = 0;
35 BYTE data[sizeof(UINT32)];
36
37 if ((result = obj_context_transport_init(tspContext)))
38 return result;
39
40 LogDebugFn("Executing in a transport session");
41
42 offset = 0;
43 Trspi_LoadBlob_UINT32(&offset, idCounter, data);
44
45 if ((result = obj_context_transport_execute(tspContext, TPM_ORD_ReadCounter, sizeof(data),
46 data, NULL, &handlesLen, NULL, NULL, NULL,
47 &decLen, &dec)))
48 return result;
49
50 offset = 0;
51 Trspi_UnloadBlob_COUNTER_VALUE(&offset, dec, counterValue);
52
53 free(dec);
54
55 return TSS_SUCCESS;
56 }
57 #endif
58