OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 #ifndef TPM_LITE_TLCL_INTERNAL_H_ | 6 #ifndef TPM_LITE_TLCL_INTERNAL_H_ |
7 #define TPM_LITE_TLCL_INTERNAL_H_ | 7 #define TPM_LITE_TLCL_INTERNAL_H_ |
8 | 8 |
9 #include <stdarg.h> | |
10 #include <stdint.h> | 9 #include <stdint.h> |
11 #include <stdio.h> | 10 #include <stdio.h> |
12 #include <stdlib.h> | 11 #include <stdlib.h> |
13 | 12 |
14 typedef int bool; | 13 typedef int bool; |
15 const bool true = 1; | 14 const bool true = 1; |
16 const bool false = 0; | 15 const bool false = 0; |
17 | 16 |
18 #define POSSIBLY_UNUSED __attribute__((unused)) | |
19 | |
20 #ifdef __STRICT_ANSI__ | |
21 #define INLINE | |
22 #else | |
23 #define INLINE inline | |
24 #endif | |
25 | |
26 /* | |
27 * Output an error message and quit the program. | |
28 */ | |
29 static void error(const char *format, ...) { | |
30 va_list ap; | |
31 va_start(ap, format); | |
32 fprintf(stderr, "ERROR: "); | |
33 vfprintf(stderr, format, ap); | |
34 va_end(ap); | |
35 exit(1); | |
36 } | |
37 | |
38 /* | |
39 * Output a warning and continue. | |
40 */ | |
41 POSSIBLY_UNUSED | |
42 static void warning(const char *format, ...) { | |
43 va_list ap; | |
44 va_start(ap, format); | |
45 fprintf(stderr, "WARNING: "); | |
46 vfprintf(stderr, format, ap); | |
47 va_end(ap); | |
48 exit(1); | |
49 } | |
50 | |
51 #define assert(expr) do { if (!(expr)) { \ | |
52 error("assert fail: %s at %s:%d\n", \ | |
53 #expr, __FILE__, __LINE__); }} while(0) | |
54 | |
55 /* | 17 /* |
56 * Conversion functions. ToTpmTYPE puts a value of type TYPE into a TPM | 18 * Conversion functions. ToTpmTYPE puts a value of type TYPE into a TPM |
57 * command buffer. FromTpmTYPE gets a value of type TYPE from a TPM command | 19 * command buffer. FromTpmTYPE gets a value of type TYPE from a TPM command |
58 * buffer into a variable. | 20 * buffer into a variable. |
59 */ | 21 */ |
60 POSSIBLY_UNUSED | 22 POSSIBLY_UNUSED |
61 static INLINE void ToTpmUint32(uint8_t *buffer, uint32_t x) { | 23 static INLINE void ToTpmUint32(uint8_t *buffer, uint32_t x) { |
62 buffer[0] = (x >> 24); | 24 buffer[0] = (x >> 24); |
63 buffer[1] = ((x >> 16) & 0xff); | 25 buffer[1] = ((x >> 16) & 0xff); |
64 buffer[2] = ((x >> 8) & 0xff); | 26 buffer[2] = ((x >> 8) & 0xff); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 /* | 58 /* |
97 * These numbers derive from adding the sizes of command fields as shown in the | 59 * These numbers derive from adding the sizes of command fields as shown in the |
98 * TPM commands manual. | 60 * TPM commands manual. |
99 */ | 61 */ |
100 const int kTpmRequestHeaderLength = 10; | 62 const int kTpmRequestHeaderLength = 10; |
101 const int kTpmResponseHeaderLength = 14; | 63 const int kTpmResponseHeaderLength = 14; |
102 const int kTpmReadInfoLength = 12; | 64 const int kTpmReadInfoLength = 12; |
103 const int kEncAuthLength = 20; | 65 const int kEncAuthLength = 20; |
104 | 66 |
105 #endif | 67 #endif |
OLD | NEW |