Debian Codegraph @

stubdom/vtpmmgr/log.h

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