OLD | NEW |
1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux | 1 /* Software-based Trusted Platform Module (TPM) Emulator |
2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, | 2 * Copyright (C) 2004-2010 Mario Strasser <mast@gmx.net> |
3 * | 3 * |
4 * This module is free software; you can redistribute it and/or modify | 4 * This module is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published | 5 * it under the terms of the GNU General Public License as published |
6 * by the Free Software Foundation; either version 2 of the License, | 6 * by the Free Software Foundation; either version 2 of the License, |
7 * or (at your option) any later version. | 7 * or (at your option) any later version. |
8 * | 8 * |
9 * This module is distributed in the hope that it will be useful, | 9 * This module is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * $Id$ | 14 * $Id: tpmd_dev.c 426 2010-02-22 17:11:58Z mast $ |
15 */ | 15 */ |
16 | 16 |
17 #include <linux/module.h> | 17 #include <linux/module.h> |
18 #include <linux/kernel.h> | 18 #include <linux/kernel.h> |
19 #include <linux/init.h> | 19 #include <linux/init.h> |
20 #include <linux/miscdevice.h> | 20 #include <linux/miscdevice.h> |
21 #include <linux/poll.h> | 21 #include <linux/poll.h> |
22 | 22 |
23 #include <linux/socket.h> | 23 #include <linux/socket.h> |
24 #include <linux/net.h> | 24 #include <linux/net.h> |
25 #include <linux/un.h> | 25 #include <linux/un.h> |
26 | 26 |
| 27 #include "config.h" |
| 28 |
27 #define TPM_DEVICE_MINOR 224 | 29 #define TPM_DEVICE_MINOR 224 |
28 #define TPM_DEVICE_NAME "tpm" | 30 #define TPM_DEVICE_ID "tpm" |
29 #define TPM_MODULE_NAME "tpmd_dev" | 31 #define TPM_MODULE_NAME "tpmd_dev" |
30 | 32 |
31 #define TPM_RESPONSE_SIZE 4096 | |
32 #define TPM_STATE_IS_OPEN 0 | 33 #define TPM_STATE_IS_OPEN 0 |
33 | 34 |
34 #ifdef DEBUG | 35 #ifdef DEBUG |
35 #define debug(fmt, ...) printk(KERN_DEBUG "%s %s:%d: Debug: " fmt "\n", \ | 36 #define debug(fmt, ...) printk(KERN_DEBUG "%s %s:%d: Debug: " fmt "\n", \ |
36 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) | 37 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) |
37 #else | 38 #else |
38 #define debug(fmt, ...) | 39 #define debug(fmt, ...) |
39 #endif | 40 #endif |
40 #define info(fmt, ...) printk(KERN_INFO "%s %s:%d: Info: " fmt "\n", \ | 41 #define info(fmt, ...) printk(KERN_INFO "%s %s:%d: Info: " fmt "\n", \ |
41 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) | 42 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) |
42 #define error(fmt, ...) printk(KERN_ERR "%s %s:%d: Error: " fmt "\n", \ | 43 #define error(fmt, ...) printk(KERN_ERR "%s %s:%d: Error: " fmt "\n", \ |
43 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) | 44 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) |
44 #define alert(fmt, ...) printk(KERN_ALERT "%s %s:%d: Alert: " fmt "\n", \ | 45 #define alert(fmt, ...) printk(KERN_ALERT "%s %s:%d: Alert: " fmt "\n", \ |
45 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) | 46 TPM_MODULE_NAME, __FILE__, __LINE__, ## __VA_ARGS__) |
46 | 47 |
47 MODULE_LICENSE("GPL"); | 48 MODULE_LICENSE("GPL"); |
48 MODULE_AUTHOR("Mario Strasser <mast@gmx.net>"); | 49 MODULE_AUTHOR("Mario Strasser <mast@gmx.net>"); |
49 MODULE_DESCRIPTION("Trusted Platform Module (TPM) Emulator"); | 50 MODULE_DESCRIPTION("Trusted Platform Module (TPM) Emulator"); |
50 MODULE_SUPPORTED_DEVICE(TPM_DEVICE_NAME); | 51 MODULE_SUPPORTED_DEVICE(TPM_DEVICE_ID); |
51 | 52 |
52 /* module parameters */ | 53 /* module parameters */ |
53 char *tpmd_socket_name = "/var/run/tpm/tpmd_socket:0"; | 54 char *tpmd_socket_name = TPM_SOCKET_NAME; |
54 module_param(tpmd_socket_name, charp, 0444); | 55 module_param(tpmd_socket_name, charp, 0444); |
55 MODULE_PARM_DESC(tpmd_socket_name, " Sets the name of the TPM daemon socket."); | 56 MODULE_PARM_DESC(tpmd_socket_name, " Sets the name of the TPM daemon socket."); |
56 | 57 |
57 /* TPM lock */ | 58 /* TPM lock */ |
58 static struct semaphore tpm_mutex; | 59 static struct semaphore tpm_mutex; |
59 | 60 |
60 /* TPM command response */ | 61 /* TPM command response */ |
61 static struct { | 62 static struct { |
62 uint8_t *data; | 63 uint8_t *data; |
63 uint32_t size; | 64 uint32_t size; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 iov.iov_base = (void*)in; | 108 iov.iov_base = (void*)in; |
108 iov.iov_len = in_size; | 109 iov.iov_len = in_size; |
109 msg.msg_iov = &iov; | 110 msg.msg_iov = &iov; |
110 msg.msg_iovlen = 1; | 111 msg.msg_iovlen = 1; |
111 res = sock_sendmsg(tpmd_sock, &msg, in_size); | 112 res = sock_sendmsg(tpmd_sock, &msg, in_size); |
112 if (res < 0) { | 113 if (res < 0) { |
113 error("sock_sendmsg() failed: %d\n", res); | 114 error("sock_sendmsg() failed: %d\n", res); |
114 return res; | 115 return res; |
115 } | 116 } |
116 /* receive response from tpmd */ | 117 /* receive response from tpmd */ |
117 tpm_response.size = TPM_RESPONSE_SIZE; | 118 tpm_response.size = TPM_CMD_BUF_SIZE; |
118 tpm_response.data = kmalloc(tpm_response.size, GFP_KERNEL); | 119 tpm_response.data = kmalloc(tpm_response.size, GFP_KERNEL); |
119 if (tpm_response.data == NULL) return -1; | 120 if (tpm_response.data == NULL) return -1; |
120 memset(&msg, 0, sizeof(msg)); | 121 memset(&msg, 0, sizeof(msg)); |
121 iov.iov_base = (void*)tpm_response.data; | 122 iov.iov_base = (void*)tpm_response.data; |
122 iov.iov_len = tpm_response.size; | 123 iov.iov_len = tpm_response.size; |
123 msg.msg_iov = &iov; | 124 msg.msg_iov = &iov; |
124 msg.msg_iovlen = 1; | 125 msg.msg_iovlen = 1; |
125 oldmm = get_fs(); | 126 oldmm = get_fs(); |
126 set_fs(KERNEL_DS); | 127 set_fs(KERNEL_DS); |
127 res = sock_recvmsg(tpmd_sock, &msg, tpm_response.size, 0); | 128 res = sock_recvmsg(tpmd_sock, &msg, tpm_response.size, 0); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 .owner = THIS_MODULE, | 232 .owner = THIS_MODULE, |
232 .open = tpm_open, | 233 .open = tpm_open, |
233 .release = tpm_release, | 234 .release = tpm_release, |
234 .read = tpm_read, | 235 .read = tpm_read, |
235 .write = tpm_write, | 236 .write = tpm_write, |
236 .ioctl = tpm_ioctl, | 237 .ioctl = tpm_ioctl, |
237 }; | 238 }; |
238 | 239 |
239 static struct miscdevice tpm_dev = { | 240 static struct miscdevice tpm_dev = { |
240 .minor = TPM_DEVICE_MINOR, | 241 .minor = TPM_DEVICE_MINOR, |
241 .name = TPM_DEVICE_NAME, | 242 .name = TPM_DEVICE_ID, |
242 .fops = &fops, | 243 .fops = &fops, |
243 }; | 244 }; |
244 | 245 |
245 int __init init_tpm_module(void) | 246 int __init init_tpm_module(void) |
246 { | 247 { |
247 int res = misc_register(&tpm_dev); | 248 int res = misc_register(&tpm_dev); |
248 if (res != 0) { | 249 if (res != 0) { |
249 error("misc_register() failed for minor %d\n", TPM_DEVICE_MINOR); | 250 error("misc_register() failed for minor %d\n", TPM_DEVICE_MINOR); |
250 return res; | 251 return res; |
251 } | 252 } |
252 /* initialize variables */ | 253 /* initialize variables */ |
253 sema_init(&tpm_mutex, 1); | 254 sema_init(&tpm_mutex, 1); |
254 module_state = 0; | 255 module_state = 0; |
255 tpm_response.data = NULL; | 256 tpm_response.data = NULL; |
256 tpm_response.size = 0; | 257 tpm_response.size = 0; |
257 tpmd_sock = NULL; | 258 tpmd_sock = NULL; |
258 return 0; | 259 return 0; |
259 } | 260 } |
260 | 261 |
261 void __exit cleanup_tpm_module(void) | 262 void __exit cleanup_tpm_module(void) |
262 { | 263 { |
263 misc_deregister(&tpm_dev); | 264 misc_deregister(&tpm_dev); |
264 tpmd_disconnect(); | 265 tpmd_disconnect(); |
265 if (tpm_response.data != NULL) kfree(tpm_response.data); | 266 if (tpm_response.data != NULL) kfree(tpm_response.data); |
266 } | 267 } |
267 | 268 |
268 module_init(init_tpm_module); | 269 module_init(init_tpm_module); |
269 module_exit(cleanup_tpm_module); | 270 module_exit(cleanup_tpm_module); |
270 | 271 |
OLD | NEW |