~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/vtpm_manager/util/log.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ===================================================================
 
2
// 
 
3
// Copyright (c) 2005, Intel Corp.
 
4
// All rights reserved.
 
5
//
 
6
// Redistribution and use in source and binary forms, with or without 
 
7
// modification, are permitted provided that the following conditions 
 
8
// are met:
 
9
//
 
10
//   * Redistributions of source code must retain the above copyright 
 
11
//     notice, this list of conditions and the following disclaimer.
 
12
//   * Redistributions in binary form must reproduce the above 
 
13
//     copyright notice, this list of conditions and the following 
 
14
//     disclaimer in the documentation and/or other materials provided 
 
15
//     with the distribution.
 
16
//   * Neither the name of Intel Corporation nor the names of its 
 
17
//     contributors may be used to endorse or promote products derived
 
18
//     from this software without specific prior written permission.
 
19
//
 
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 
21
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 
22
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 
23
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 
24
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 
25
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
26
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 
27
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
28
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
29
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
30
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
31
// OF THE POSSIBILITY OF SUCH DAMAGE.
 
32
// ===================================================================
 
33
 
 
34
#ifndef __VTPM_LOG_H__
 
35
#define __VTPM_LOG_H__
 
36
 
 
37
#include <stdint.h>             // for uint32_t
 
38
#include <stddef.h>             // for pointer NULL
 
39
 
 
40
// =========================== LOGGING ==============================
 
41
 
 
42
// the logging module numbers
 
43
#define VTPM_LOG_CRYPTO      1
 
44
#define VTPM_LOG_BSG         2
 
45
#define VTPM_LOG_TXDATA      3
 
46
#define VTPM_LOG_TCS         4
 
47
#define VTPM_LOG_TCS_DEEP    5
 
48
#define VTPM_LOG_VTSP        6
 
49
#define VTPM_LOG_VTPM        7
 
50
#define VTPM_LOG_VTPM_DEEP   8
 
51
#define VTPM_LOG_VTSP_DEEP   9
 
52
 
 
53
static char *module_names[] = { "",
 
54
                                "CRYPTO",
 
55
                                "BSG",
 
56
                                "TXDATA",
 
57
                                "TCS",
 
58
                                "TCS",
 
59
                                "VTSP",
 
60
                                "VTPM",
 
61
                                "VTPM",
 
62
                                "VTSP"
 
63
                              };
 
64
 
 
65
// Default to standard logging
 
66
#ifndef LOGGING_MODULES
 
67
#define LOGGING_MODULES (BITMASK(VTPM_LOG_VTPM))
 
68
#endif
 
69
 
 
70
// bit-access macros
 
71
#define BITMASK(idx)      ( 1U << (idx) )
 
72
#define GETBIT(num,idx)   ( ((num) & BITMASK(idx)) >> idx )
 
73
#define SETBIT(num,idx)   (num) |= BITMASK(idx)
 
74
#define CLEARBIT(num,idx) (num) &= ( ~ BITMASK(idx) )
 
75
 
 
76
#define vtpmloginfo(module, fmt, args...) \
 
77
  if (GETBIT (LOGGING_MODULES, module) == 1) {                          \
 
78
    fprintf (stdout, "INFO[%s]: " fmt, module_names[module], ##args); \
 
79
  }
 
80
 
 
81
#define vtpmloginfomore(module, fmt, args...) \
 
82
  if (GETBIT (LOGGING_MODULES, module) == 1) {                        \
 
83
    fprintf (stdout, fmt,##args);                                     \
 
84
  }
 
85
                               
 
86
#define vtpmlogerror(module, fmt, args...) \
 
87
  fprintf (stderr, "ERROR[%s]: " fmt, module_names[module], ##args);
 
88
                               
 
89
//typedef UINT32 tpm_size_t;
 
90
                        
 
91
// helper function for the error codes:
 
92
const char* tpm_get_error_name (TPM_RESULT code);
 
93
 
 
94
#endif // _VTPM_LOG_H_