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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/tddl/Makefile.am ('k') | src/trspi/Makefile.am » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/tddl/tddl.c
diff --git a/src/tddl/tddl.c b/src/tddl/tddl.c
index a8fafd1aba663533d57489f83274d65abe9098de..b4f95b23c62b23d7f162006c2bb60b7364c5c2e4 100644
--- a/src/tddl/tddl.c
+++ b/src/tddl/tddl.c
@@ -32,23 +32,89 @@ struct tpm_device_node tpm_device_nodes[] = {
struct tpm_device_node *opened_device = NULL;
BYTE txBuffer[TDDL_TXBUF_SIZE];
+TSS_BOOL use_in_socket = FALSE;
+struct tcsd_config *_tcsd_options = NULL;
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <netdb.h>
+#include <fcntl.h>
+
int
-open_device(void)
+open_device()
{
- int i;
-
- /* tpm_device_paths is filled out in tddl.h */
- for (i = 0; tpm_device_nodes[i].path != NULL; i++) {
- errno = 0;
- if ((tpm_device_nodes[i].fd = open(tpm_device_nodes[i].path, O_RDWR)) < 0)
- continue;
-
+ int i = 0, fd = -1, tcp_device_port;
+ char *tcp_device_hostname = NULL;
+ char *un_socket_device_path = NULL;
+ char *tcp_device_port_string = NULL;
+
+ if (getenv("TCSD_USE_TCP_DEVICE")) {
+ if ((tcp_device_hostname = getenv("TCSD_TCP_DEVICE_HOSTNAME")) == NULL)
+ tcp_device_hostname = "localhost";
+ if ((un_socket_device_path = getenv("TCSD_UN_SOCKET_DEVICE_PATH")) == NULL)
+ un_socket_device_path = "/var/run/tpm/tpmd_socket:0";
+ if ((tcp_device_port_string = getenv("TCSD_TCP_DEVICE_PORT")) != NULL)
+ tcp_device_port = atoi(tcp_device_port_string);
+ else
+ tcp_device_port = 6545;
+
+
+ fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd > 0) {
+ struct hostent *host = gethostbyname(tcp_device_hostname);
+ if (host != NULL) {
+ struct sockaddr_in addr;
+ memset(&addr, 0x0, sizeof(addr));
+ addr.sin_family = host->h_addrtype;
+ addr.sin_port = htons(tcp_device_port);
+ memcpy(&addr.sin_addr,
+ host->h_addr,
+ host->h_length);
+ if (connect(fd, (struct sockaddr *)&addr,
+ sizeof(addr)) < 0) {
+ close(fd);
+ fd = -1;
+ } else
+ use_in_socket = TRUE;
+ } else {
+ close (fd);
+ fd = -1;
+ }
+ }
+
+ if (fd < 0) {
+ struct sockaddr_un addr;
+
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd >= 0) {
+ addr.sun_family = AF_UNIX;
+ strncpy(addr.sun_path, un_socket_device_path,
+ sizeof(addr.sun_path));
+ if (connect(fd, (void *)&addr, sizeof(addr)) < 0) {
+ close(fd);
+ fd = -1;
+ }
+ }
+ }
+ }
+
+ if (fd < 0) {
+ /* tpm_device_paths is filled out in tddl.h */
+ for (i = 0; tpm_device_nodes[i].path != NULL; i++) {
+ errno = 0;
+ if ((fd = open(tpm_device_nodes[i].path, O_RDWR)) >= 0)
+ break;
+ }
+ }
+
+ if (fd > 0) {
opened_device = &(tpm_device_nodes[i]);
- return opened_device->fd;
+ tpm_device_nodes[i].fd = fd;
}
-
- return -1;
+ return fd;
}
TSS_RESULT
@@ -104,6 +170,12 @@ Tddli_TransmitData(BYTE * pTransmitBuf, UINT32 TransmitBufLen, BYTE * pReceiveBu
memcpy(txBuffer, pTransmitBuf, TransmitBufLen);
LogDebug("Calling write to driver");
+ if (use_in_socket) {
+ Tddli_Close();
+ if (Tddli_Open())
+ return TDDLERR(TDDL_E_IOERROR);
+ }
+
switch (opened_device->transmit) {
case TDDL_UNDEF:
/* fall through */
« 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