summaryrefslogtreecommitdiff
path: root/src/tspi/tspi_counter.c
blob: d494cc1f9b5edcae07af2f692ea4eab573ebffbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

/*
 * Licensed Materials - Property of IBM
 *
 * trousers - An open source TCG Software Stack
 *
 * (C) Copyright International Business Machines Corp. 2004-2007
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "trousers/tss.h"
#include "trousers/trousers.h"
#include "trousers_types.h"
#include "spi_utils.h"
#include "capabilities.h"
#include "tsplog.h"
#include "obj.h"


TSS_RESULT
Tspi_TPM_ReadCounter(TSS_HTPM hTPM,		/* in */
		     UINT32*  counterValue)	/* out */
{
	TSS_HCONTEXT tspContext;
	TCPA_RESULT result;
	TSS_COUNTER_ID counterID;
	TPM_COUNTER_VALUE counter_value;

	if (counterValue == NULL)
		return TSPERR(TSS_E_BAD_PARAMETER);

	if ((result = obj_tpm_get_tsp_context(hTPM, &tspContext)))
		return result;

	if ((result = obj_tpm_get_current_counter(hTPM, &counterID)))
		return result;

	if ((result = TCS_API(tspContext)->ReadCounter(tspContext, counterID, &counter_value)))
		return result;

	*counterValue = counter_value.counter;

	return TSS_SUCCESS;
}