~ubuntu-branches/ubuntu/jaunty/trousers/jaunty

« back to all changes in this revision

Viewing changes to src/tcs/req_mgr.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-01-23 22:03:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123220300-fhtqja3c0oq0gp6z
Tags: 0.3.1-4
* Added patch from Aaron M. Ucko <ucko@debian.org> to allow trousers to
  build successfully on amd64, and presumably also other 64-bit
  architectures (Closes: #457400).
* Including udev rule for /dev/tpm from William Lima
  <wlima.amadeus@gmail.com> as suggested by David Smith <dds@google.com>
  (Closes: #459682).
* Added lintian overrides.

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