~ubuntu-branches/ubuntu/precise/trousers/precise-proposed

« back to all changes in this revision

Viewing changes to src/tcs/req_mgr.c

  • Committer: Bazaar Package Importer
  • Author(s): William Lima
  • Date: 2007-04-18 16:39:38 UTC
  • Revision ID: james.westby@ubuntu.com-20070418163938-opscl2mvvi76jiec
Tags: upstream-0.2.9.1
ImportĀ upstreamĀ versionĀ 0.2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <syslog.h>
 
15
#include <pthread.h>
 
16
#include <signal.h>
 
17
#include <string.h>
 
18
#include <errno.h>
 
19
#include <unistd.h>
 
20
 
 
21
#include "trousers/tss.h"
 
22
#include "trousers_types.h"
 
23
#include "tcs_tsp.h"
 
24
#include "tcs_utils.h"
 
25
#include "tcsd_wrap.h"
 
26
#include "tcsd.h"
 
27
#include "tddl.h"
 
28
#include "req_mgr.h"
 
29
#include "tcslog.h"
 
30
 
 
31
static struct tpm_req_mgr *trm;
 
32
 
 
33
#ifdef TSS_DEBUG
 
34
#define TSS_TPM_DEBUG
 
35
#endif
 
36
 
 
37
TSS_RESULT
 
38
req_mgr_submit_req(BYTE *blob)
 
39
{
 
40
        TSS_RESULT result;
 
41
        BYTE loc_buf[TSS_TPM_TXBLOB_SIZE];
 
42
        UINT32 size = TSS_TPM_TXBLOB_SIZE;
 
43
        UINT32 retry = TSS_REQ_MGR_MAX_RETRIES;
 
44
        UINT32 blob_size = Decode_UINT32(&blob[2]);
 
45
 
 
46
        if (blob_size > TSS_TPM_TXBLOB_SIZE) {
 
47
                LogDebugFn("TPM blob is too large! (%u bytes)", blob_size);
 
48
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
49
        }
 
50
 
 
51
        pthread_mutex_lock(&(trm->queue_lock));
 
52
 
 
53
#ifdef TSS_TPM_DEBUG
 
54
        LogBlobData("To TPM:", blob_size, blob);
 
55
#endif
 
56
 
 
57
        do {
 
58
                result = Tddli_TransmitData(blob, blob_size, loc_buf, &size);
 
59
        } while (!result && (Decode_UINT32(&loc_buf[6]) == TCPA_E_RETRY) && --retry);
 
60
 
 
61
        if (!result)
 
62
                memcpy(blob, loc_buf, Decode_UINT32(&loc_buf[2]));
 
63
 
 
64
#ifdef TSS_TPM_DEBUG
 
65
        LogBlobData("From TPM:", size, loc_buf);
 
66
#endif
 
67
 
 
68
        pthread_mutex_unlock(&(trm->queue_lock));
 
69
 
 
70
        return result;
 
71
}
 
72
 
 
73
TSS_RESULT
 
74
req_mgr_init()
 
75
{
 
76
        if ((trm = calloc(1, sizeof(struct tpm_req_mgr))) == NULL) {
 
77
                LogError("malloc of %zd bytes failed.", sizeof(struct tpm_req_mgr));
 
78
                return TSS_E_OUTOFMEMORY;
 
79
        }
 
80
 
 
81
        pthread_mutex_init(&(trm->queue_lock), NULL);
 
82
 
 
83
        return Tddli_Open();
 
84
}
 
85
 
 
86
TSS_RESULT
 
87
req_mgr_final()
 
88
{
 
89
        free(trm);
 
90
 
 
91
        return Tddli_Close();
 
92
}
 
93