Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: src/tddl/tddl.c

Issue 3581012: Upgrade from trousers 0.3.3 to 0.3.6 and from testsuite 0.2 to 0.3. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/trousers.git
Patch Set: git cl push Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/tddl/Makefile.am ('k') | src/trspi/Makefile.am » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Licensed Materials - Property of IBM 3 * Licensed Materials - Property of IBM
4 * 4 *
5 * trousers - An open source TCG Software Stack 5 * trousers - An open source TCG Software Stack
6 * 6 *
7 * (C) Copyright International Business Machines Corp. 2004, 2005 7 * (C) Copyright International Business Machines Corp. 2004, 2005
8 * 8 *
9 */ 9 */
10 10
(...skipping 14 matching lines...) Expand all
25 struct tpm_device_node tpm_device_nodes[] = { 25 struct tpm_device_node tpm_device_nodes[] = {
26 {"/dev/tpm0", TDDL_UNDEF, TDDL_UNDEF}, 26 {"/dev/tpm0", TDDL_UNDEF, TDDL_UNDEF},
27 {"/udev/tpm0", TDDL_UNDEF, TDDL_UNDEF}, 27 {"/udev/tpm0", TDDL_UNDEF, TDDL_UNDEF},
28 {"/dev/tpm", TDDL_UNDEF, TDDL_UNDEF}, 28 {"/dev/tpm", TDDL_UNDEF, TDDL_UNDEF},
29 {NULL, 0, 0} 29 {NULL, 0, 0}
30 }; 30 };
31 31
32 struct tpm_device_node *opened_device = NULL; 32 struct tpm_device_node *opened_device = NULL;
33 33
34 BYTE txBuffer[TDDL_TXBUF_SIZE]; 34 BYTE txBuffer[TDDL_TXBUF_SIZE];
35 TSS_BOOL use_in_socket = FALSE;
36 struct tcsd_config *_tcsd_options = NULL;
37
38 #include <sys/socket.h>
39 #include <sys/un.h>
40 #include <netinet/in.h>
41 #include <sys/types.h>
42 #include <netdb.h>
43 #include <fcntl.h>
44
35 45
36 int 46 int
37 open_device(void) 47 open_device()
38 { 48 {
39 » int i; 49 » int i = 0, fd = -1, tcp_device_port;
50 » char *tcp_device_hostname = NULL;
51 » char *un_socket_device_path = NULL;
52 » char *tcp_device_port_string = NULL;
53 »
54 » if (getenv("TCSD_USE_TCP_DEVICE")) {
55 » » if ((tcp_device_hostname = getenv("TCSD_TCP_DEVICE_HOSTNAME")) = = NULL)
56 » » » tcp_device_hostname = "localhost";
57 » » if ((un_socket_device_path = getenv("TCSD_UN_SOCKET_DEVICE_PATH" )) == NULL)
58 » » » un_socket_device_path = "/var/run/tpm/tpmd_socket:0";
59 » » if ((tcp_device_port_string = getenv("TCSD_TCP_DEVICE_PORT")) != NULL)
60 » » » tcp_device_port = atoi(tcp_device_port_string);
61 » » else
62 » » » tcp_device_port = 6545;
63 »
64 » »
65 » » fd = socket(AF_INET, SOCK_STREAM, 0);
66 » » if (fd > 0) {
67 » » » struct hostent *host = gethostbyname(tcp_device_hostname );
68 » » » if (host != NULL) {
69 » » » » struct sockaddr_in addr;
70 » » » » memset(&addr, 0x0, sizeof(addr));
71 » » » » addr.sin_family = host->h_addrtype;
72 » » » » addr.sin_port = htons(tcp_device_port);
73 » » » » memcpy(&addr.sin_addr,
74 » » » » » » host->h_addr,
75 » » » » » » host->h_length);
76 » » » » if (connect(fd,»(struct sockaddr *)&addr,
77 » » » » » sizeof(addr)) < 0) {
78 » » » » » close(fd);
79 » » » » » fd = -1;
80 » » » » } else
81 » » » » » use_in_socket = TRUE;
82 » » » } else {
83 » » » » close (fd);
84 » » » » fd = -1;
85 » » » }
86 » » }
87 »
88 » » if (fd < 0) {
89 » » » struct sockaddr_un addr;
40 90
41 » /* tpm_device_paths is filled out in tddl.h */ 91 » » » fd = socket(AF_UNIX, SOCK_STREAM, 0);
42 » for (i = 0; tpm_device_nodes[i].path != NULL; i++) { 92 » » » if (fd >= 0) {
43 » » errno = 0; 93 » » » » addr.sun_family = AF_UNIX;
44 » » if ((tpm_device_nodes[i].fd = open(tpm_device_nodes[i].path, O_R DWR)) < 0) 94 » » » » strncpy(addr.sun_path, un_socket_device_path,
45 » » » continue; 95 » » » » » » sizeof(addr.sun_path));
46 96 » » » » if (connect(fd, (void *)&addr, sizeof(addr)) < 0 ) {
97 » » » » » close(fd);
98 » » » » » fd = -1;
99 » » » » }
100 » » » }
101 » » }
102 » }
103 »
104 » if (fd < 0) {
105 » » /* tpm_device_paths is filled out in tddl.h */
106 » » for (i = 0; tpm_device_nodes[i].path != NULL; i++) {
107 » » » errno = 0;
108 » » » if ((fd = open(tpm_device_nodes[i].path, O_RDWR)) >= 0)
109 » » » » break;
110 » » }
111 » }
112 »
113 » if (fd > 0) {
47 opened_device = &(tpm_device_nodes[i]); 114 opened_device = &(tpm_device_nodes[i]);
48 » » return opened_device->fd; 115 » » tpm_device_nodes[i].fd = fd;
49 } 116 }
50 117 » return fd;
51 » return -1;
52 } 118 }
53 119
54 TSS_RESULT 120 TSS_RESULT
55 Tddli_Open() 121 Tddli_Open()
56 { 122 {
57 int rc; 123 int rc;
58 124
59 if (opened_device != NULL) { 125 if (opened_device != NULL) {
60 LogDebug("attempted to re-open the TPM driver!"); 126 LogDebug("attempted to re-open the TPM driver!");
61 return TDDLERR(TDDL_E_ALREADY_OPENED); 127 return TDDLERR(TDDL_E_ALREADY_OPENED);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 int sizeResult; 163 int sizeResult;
98 164
99 if (TransmitBufLen > TDDL_TXBUF_SIZE) { 165 if (TransmitBufLen > TDDL_TXBUF_SIZE) {
100 LogError("buffer size handed to TDDL is too large! (%u bytes)", TransmitBufLen); 166 LogError("buffer size handed to TDDL is too large! (%u bytes)", TransmitBufLen);
101 return TDDLERR(TDDL_E_FAIL); 167 return TDDLERR(TDDL_E_FAIL);
102 } 168 }
103 169
104 memcpy(txBuffer, pTransmitBuf, TransmitBufLen); 170 memcpy(txBuffer, pTransmitBuf, TransmitBufLen);
105 LogDebug("Calling write to driver"); 171 LogDebug("Calling write to driver");
106 172
173 if (use_in_socket) {
174 Tddli_Close();
175 if (Tddli_Open())
176 return TDDLERR(TDDL_E_IOERROR);
177 }
178
107 switch (opened_device->transmit) { 179 switch (opened_device->transmit) {
108 case TDDL_UNDEF: 180 case TDDL_UNDEF:
109 /* fall through */ 181 /* fall through */
110 case TDDL_TRANSMIT_IOCTL: 182 case TDDL_TRANSMIT_IOCTL:
111 errno = 0; 183 errno = 0;
112 if ((sizeResult = ioctl(opened_device->fd, TPMIOC_TRANSM IT, txBuffer)) != -1) { 184 if ((sizeResult = ioctl(opened_device->fd, TPMIOC_TRANSM IT, txBuffer)) != -1) {
113 opened_device->transmit = TDDL_TRANSMIT_IOCTL; 185 opened_device->transmit = TDDL_TRANSMIT_IOCTL;
114 break; 186 break;
115 } 187 }
116 LogWarn("ioctl: (%d) %s", errno, strerror(errno)); 188 LogWarn("ioctl: (%d) %s", errno, strerror(errno));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } else if (rc == -EIO) { 264 } else if (rc == -EIO) {
193 /* The driver timed out while trying to tell the chip to cancel */ 265 /* The driver timed out while trying to tell the chip to cancel */
194 return TDDLERR(TDDL_E_COMMAND_COMPLETED); 266 return TDDLERR(TDDL_E_COMMAND_COMPLETED);
195 } 267 }
196 268
197 return TSS_SUCCESS; 269 return TSS_SUCCESS;
198 } else { 270 } else {
199 return TDDLERR(TSS_E_NOTIMPL); 271 return TDDLERR(TSS_E_NOTIMPL);
200 } 272 }
201 } 273 }
OLDNEW
« no previous file with comments | « src/tddl/Makefile.am ('k') | src/trspi/Makefile.am » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698