Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 1 | //**********************************************************************; |
| 2 | // Copyright (c) 2015, Intel Corporation |
| 3 | // All rights reserved. |
Philip Tricca | 1ea84a5 | 2015-11-19 18:07:06 -0800 | [diff] [blame] | 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 6 | // modification, are permitted provided that the following conditions are met: |
Philip Tricca | 1ea84a5 | 2015-11-19 18:07:06 -0800 | [diff] [blame] | 7 | // |
| 8 | // 1. Redistributions of source code must retain the above copyright notice, |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 9 | // this list of conditions and the following disclaimer. |
Philip Tricca | 1ea84a5 | 2015-11-19 18:07:06 -0800 | [diff] [blame] | 10 | // |
| 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | // this list of conditions and the following disclaimer in the documentation |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 13 | // and/or other materials provided with the distribution. |
Philip Tricca | 1ea84a5 | 2015-11-19 18:07:06 -0800 | [diff] [blame] | 14 | // |
| 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 25 | // THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | //**********************************************************************; |
| 27 | |
| 28 | // |
| 29 | // NOTE: this file is used in two places: application SAPI (to |
| 30 | // communicate with RM) and RM calls to SAPI (to communicate with |
| 31 | // TPM simulator. |
| 32 | // |
| 33 | // There will be a few small differences between the two uses and |
| 34 | // these will be handled via #ifdef's and different header files. |
| 35 | // |
| 36 | |
| 37 | // |
| 38 | // NOTE: uncomment following if you think you need to see all |
| 39 | // socket communications. |
| 40 | // |
| 41 | //#define DEBUG_SOCKETS |
| 42 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 43 | #include <stdio.h> |
| 44 | #include <stdlib.h> // Needed for _wtoi |
| 45 | |
Philip Tricca | e03b846 | 2016-07-08 19:51:23 -0700 | [diff] [blame] | 46 | #include <sapi/tpm20.h> |
Philip Tricca | 785e88d | 2016-02-13 12:02:44 -0800 | [diff] [blame] | 47 | #include <tcti/tcti_socket.h> |
Philip Tricca | c3dedc2 | 2016-01-15 13:47:22 -0800 | [diff] [blame] | 48 | #include "sysapi_util.h" |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 49 | #include "debug.h" |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 50 | #include "commonchecks.h" |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 51 | #include "logging.h" |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 52 | |
| 53 | #ifdef __cplusplus |
| 54 | extern "C" { |
| 55 | #endif |
| 56 | |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 57 | static TSS2_RC tctiRecvBytes( TSS2_TCTI_CONTEXT *tctiContext, SOCKET sock, unsigned char *data, int len ) |
Philip Tricca | a06f237 | 2016-03-30 17:13:11 -0700 | [diff] [blame] | 58 | { |
| 59 | TSS2_RC result = 0; |
| 60 | result = recvBytes( sock, data, len); |
wcarthur1 | e2e0418 | 2016-04-11 07:37:55 -0700 | [diff] [blame] | 61 | if ( (INT32)result == SOCKET_ERROR) { |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 62 | TCTI_LOG( tctiContext, NO_PREFIX, "In recvBytes, recv failed (socket: 0x%x) with error: %d\n", sock, WSAGetLastError() ); |
Philip Tricca | a06f237 | 2016-03-30 17:13:11 -0700 | [diff] [blame] | 63 | return TSS2_TCTI_RC_IO_ERROR; |
| 64 | } |
| 65 | #ifdef DEBUG_SOCKETS |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 66 | TCTI_LOG( tctiContext, NO_PREFIX, "Receive Bytes from socket #0x%x: \n", sock ); |
Philip Tricca | 4eb2f35 | 2016-03-31 05:55:35 -0700 | [diff] [blame] | 67 | TCTI_LOG_BUFFER( tctiContext, NO_PREFIX, data, len ); |
Philip Tricca | a06f237 | 2016-03-30 17:13:11 -0700 | [diff] [blame] | 68 | #endif |
| 69 | |
| 70 | return TSS2_RC_SUCCESS; |
| 71 | } |
| 72 | |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 73 | static TSS2_RC tctiSendBytes( TSS2_TCTI_CONTEXT *tctiContext, SOCKET sock, const unsigned char *data, int len ) |
Philip Tricca | 4ee284b | 2016-03-30 17:40:39 -0700 | [diff] [blame] | 74 | { |
| 75 | TSS2_RC ret = TSS2_RC_SUCCESS; |
| 76 | |
| 77 | #ifdef DEBUG_SOCKETS |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 78 | TCTI_LOG( tctiContext, NO_PREFIX, "Send Bytes to socket #0x%x: \n", sock ); |
Philip Tricca | 4eb2f35 | 2016-03-31 05:55:35 -0700 | [diff] [blame] | 79 | TCTI_LOG_BUFFER( tctiContext, NO_PREFIX, (UINT8 *)data, len ); |
Philip Tricca | 4ee284b | 2016-03-30 17:40:39 -0700 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | ret = sendBytes( sock, data, len); |
| 83 | if (ret != TSS2_RC_SUCCESS) |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 84 | TCTI_LOG( tctiContext, NO_PREFIX, "In recvBytes, recv failed (socket: 0x%x) with error: %d\n", sock, WSAGetLastError() ); |
Philip Tricca | 4ee284b | 2016-03-30 17:40:39 -0700 | [diff] [blame] | 85 | return ret; |
| 86 | } |
| 87 | |
Philip Tricca | d1bbedb | 2016-02-14 20:39:59 -0800 | [diff] [blame] | 88 | TSS2_RC SendSessionEndSocketTcti( |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 89 | TSS2_TCTI_CONTEXT *tctiContext, /* in */ |
| 90 | UINT8 tpmCmdServer ) |
| 91 | { |
| 92 | UINT32 tpmSendCommand = TPM_SESSION_END; // Value for "send command" to MS simulator. |
| 93 | SOCKET sock; |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 94 | TSS2_RC rval = TSS2_RC_SUCCESS; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 95 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 96 | if( tpmCmdServer ) |
| 97 | { |
| 98 | sock = TCTI_CONTEXT_INTEL->tpmSock; |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | sock = TCTI_CONTEXT_INTEL->otherSock; |
| 103 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 104 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 105 | tpmSendCommand = CHANGE_ENDIAN_DWORD(tpmSendCommand); |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 106 | rval = tctiSendBytes( tctiContext, sock, (char unsigned *)&tpmSendCommand, 4 ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 107 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 108 | return( rval ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 111 | TSS2_RC SocketSendTpmCommand( |
| 112 | TSS2_TCTI_CONTEXT *tctiContext, /* in */ |
| 113 | size_t command_size, /* in */ |
| 114 | uint8_t *command_buffer /* in */ |
| 115 | ) |
| 116 | { |
| 117 | UINT32 tpmSendCommand = MS_SIM_TPM_SEND_COMMAND; // Value for "send command" to MS simulator. |
| 118 | UINT32 cnt, cnt1; |
| 119 | UINT8 locality; |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 120 | TSS2_RC rval = TSS2_RC_SUCCESS; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 121 | |
| 122 | #ifdef DEBUG |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 123 | UINT32 commandCode; |
| 124 | printf_type rmPrefix; |
wcarthur1 | aee953e | 2016-04-01 15:13:24 -0700 | [diff] [blame] | 125 | #endif |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 126 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 127 | rval = CommonSendChecks( tctiContext, command_buffer ); |
| 128 | if( rval != TSS2_RC_SUCCESS ) |
| 129 | { |
| 130 | goto returnFromSocketSendTpmCommand; |
| 131 | } |
Will-nuc | 3ebfeb9 | 2015-10-29 15:53:27 -0400 | [diff] [blame] | 132 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 133 | #ifdef DEBUG |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 134 | if( ( ( TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.rmDebugPrefix == 1 ) |
| 135 | rmPrefix = RM_PREFIX; |
| 136 | else |
| 137 | rmPrefix = NO_PREFIX; |
| 138 | |
| 139 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled == 1 ) |
| 140 | { |
| 141 | TCTI_LOG( tctiContext, rmPrefix, "" ); |
wcarthur | 06befc0 | 2016-04-11 12:36:47 -0400 | [diff] [blame] | 142 | commandCode = CHANGE_ENDIAN_DWORD( ( (TPM20_Header_In *)command_buffer )->commandCode ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 143 | #ifdef DEBUG_SOCKETS |
wcarthur | 06befc0 | 2016-04-11 12:36:47 -0400 | [diff] [blame] | 144 | TCTI_LOG( tctiContext, NO_PREFIX, "Command sent on socket #0x%x: %s\n", TCTI_CONTEXT_INTEL->tpmSock, strTpmCommandCode( commandCode ) ); |
wcarthur1 | a10b0c9 | 2016-04-14 04:25:03 -0700 | [diff] [blame] | 145 | #else |
| 146 | TCTI_LOG( tctiContext, NO_PREFIX, "Cmd sent: %s\n", strTpmCommandCode( commandCode ) ); |
| 147 | #endif |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 148 | } |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 149 | #endif |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 150 | // Size TPM 1.2 and TPM 2.0 headers overlap exactly, we can use |
| 151 | // either 1.2 or 2.0 header to get the size. |
| 152 | cnt = CHANGE_ENDIAN_DWORD(((TPM20_Header_In *) command_buffer)->commandSize); |
| 153 | |
| 154 | // Send TPM_SEND_COMMAND |
| 155 | tpmSendCommand = CHANGE_ENDIAN_DWORD(tpmSendCommand); |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 156 | rval = tctiSendBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)&tpmSendCommand, 4 ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 157 | if( rval != TSS2_RC_SUCCESS ) |
| 158 | goto returnFromSocketSendTpmCommand; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 159 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 160 | // Send the locality |
| 161 | locality = (UINT8)( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.locality; |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 162 | rval = tctiSendBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)&locality, 1 ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 163 | if( rval != TSS2_RC_SUCCESS ) |
| 164 | goto returnFromSocketSendTpmCommand; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 165 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 166 | #ifdef DEBUG |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 167 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled == 1 ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 168 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 169 | TCTI_LOG( tctiContext, rmPrefix, "Locality = %d", ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.locality ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 170 | } |
| 171 | #endif |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 172 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 173 | // Send number of bytes. |
| 174 | cnt1 = cnt; |
| 175 | cnt = CHANGE_ENDIAN_DWORD(cnt); |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 176 | rval = tctiSendBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)&cnt, 4 ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 177 | if( rval != TSS2_RC_SUCCESS ) |
| 178 | goto returnFromSocketSendTpmCommand; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 179 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 180 | // Send the TPM command buffer |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 181 | rval = tctiSendBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)command_buffer, cnt1 ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 182 | if( rval != TSS2_RC_SUCCESS ) |
| 183 | goto returnFromSocketSendTpmCommand; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 184 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 185 | #ifdef DEBUG |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 186 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled == 1 ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 187 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 188 | DEBUG_PRINT_BUFFER( rmPrefix, command_buffer, cnt1 ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 189 | } |
| 190 | #endif |
| 191 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.commandSent = 1; |
| 192 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 193 | returnFromSocketSendTpmCommand: |
| 194 | |
| 195 | if( rval == TSS2_RC_SUCCESS ) |
| 196 | { |
| 197 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->previousStage = TCTI_STAGE_SEND_COMMAND; |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 198 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived = 0; |
| 199 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.responseSizeReceived = 0; |
| 200 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.protocolResponseSizeReceived = 0; |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | return rval; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | TSS2_RC SocketCancel( |
| 207 | TSS2_TCTI_CONTEXT *tctiContext |
| 208 | ) |
| 209 | { |
| 210 | TSS2_RC rval = TSS2_RC_SUCCESS; |
| 211 | |
| 212 | if( tctiContext == 0 ) |
| 213 | { |
| 214 | rval = TSS2_TCTI_RC_BAD_REFERENCE; |
| 215 | } |
| 216 | else if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.commandSent != 1 ) |
| 217 | { |
| 218 | rval = TSS2_TCTI_RC_BAD_SEQUENCE; |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | rval = (TSS2_RC)PlatformCommand( tctiContext, MS_SIM_CANCEL_ON ); |
| 223 | #if 0 |
| 224 | if( rval == TSS2_RC_SUCCESS ) |
| 225 | { |
| 226 | rval = (TSS2_RC)PlatformCommand( tctiContext, MS_SIM_CANCEL_OFF ); |
| 227 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgLevel == TSS2_TCTI_DEBUG_MSG_ENABLED ) |
| 228 | { |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 229 | TCTI_LOG( tctiContext, NO_PREFIX, "%s sent cancel ON command:\n", interfaceName ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 230 | } |
| 231 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 232 | #endif |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | return rval; |
| 236 | } |
| 237 | |
| 238 | TSS2_RC SocketSetLocality( |
| 239 | TSS2_TCTI_CONTEXT *tctiContext, /* in */ |
| 240 | uint8_t locality /* in */ |
| 241 | ) |
| 242 | { |
| 243 | TSS2_RC rval = TSS2_RC_SUCCESS; |
| 244 | |
| 245 | if( tctiContext == 0 ) |
| 246 | { |
| 247 | rval = TSS2_TCTI_RC_BAD_REFERENCE; |
| 248 | } |
| 249 | else if( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.locality != locality ) |
| 250 | { |
| 251 | if ( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.commandSent == 1 ) |
| 252 | { |
| 253 | rval = TSS2_TCTI_RC_BAD_SEQUENCE; |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.locality = locality; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | return rval; |
| 262 | } |
| 263 | |
wcarthur | 35aa539 | 2016-03-22 16:52:44 -0400 | [diff] [blame] | 264 | void SocketFinalize( |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 265 | TSS2_TCTI_CONTEXT *tctiContext /* in */ |
| 266 | ) |
| 267 | { |
wcarthur | 35aa539 | 2016-03-22 16:52:44 -0400 | [diff] [blame] | 268 | if( tctiContext != NULL ) |
wcarthur | f979e35 | 2015-11-24 17:34:44 -0500 | [diff] [blame] | 269 | { |
| 270 | // Send session end messages to servers. |
Philip Tricca | d1bbedb | 2016-02-14 20:39:59 -0800 | [diff] [blame] | 271 | SendSessionEndSocketTcti( tctiContext, 1 ); |
| 272 | SendSessionEndSocketTcti( tctiContext, 0 ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 273 | |
wcarthur | f979e35 | 2015-11-24 17:34:44 -0500 | [diff] [blame] | 274 | CloseSockets( TCTI_CONTEXT_INTEL->otherSock, TCTI_CONTEXT_INTEL->tpmSock ); |
wcarthur | f979e35 | 2015-11-24 17:34:44 -0500 | [diff] [blame] | 275 | } |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 276 | } |
| 277 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 278 | TSS2_RC SocketReceiveTpmResponse( |
| 279 | TSS2_TCTI_CONTEXT *tctiContext, /* in */ |
| 280 | size_t *response_size, /* out */ |
| 281 | unsigned char *response_buffer, /* in */ |
| 282 | int32_t timeout |
| 283 | ) |
| 284 | { |
| 285 | UINT32 trash; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 286 | TSS2_RC rval = TSS2_RC_SUCCESS; |
| 287 | fd_set readFds; |
| 288 | struct timeval tv, *tvPtr; |
| 289 | int32_t timeoutMsecs = timeout % 1000; |
| 290 | int iResult; |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 291 | unsigned char responseSizeDelta = 0; |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 292 | printf_type rmPrefix; |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 293 | |
| 294 | rval = CommonReceiveChecks( tctiContext, response_size, response_buffer ); |
| 295 | if( rval != TSS2_RC_SUCCESS ) |
| 296 | { |
| 297 | goto retSocketReceiveTpmResponse; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 298 | } |
| 299 | |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 300 | if( ( ( TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.rmDebugPrefix == 1 ) |
| 301 | rmPrefix = RM_PREFIX; |
| 302 | else |
| 303 | rmPrefix = NO_PREFIX; |
| 304 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 305 | if( timeout == TSS2_TCTI_TIMEOUT_BLOCK ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 306 | { |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 307 | tvPtr = 0; |
| 308 | } |
| 309 | else |
| 310 | { |
| 311 | tv.tv_sec = timeout / 1000; |
| 312 | tv.tv_usec = timeoutMsecs * 1000; |
| 313 | tvPtr = &tv; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 314 | } |
| 315 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 316 | FD_ZERO( &readFds ); |
| 317 | FD_SET( TCTI_CONTEXT_INTEL->tpmSock, &readFds ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 318 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 319 | iResult = select( TCTI_CONTEXT_INTEL->tpmSock+1, &readFds, 0, 0, tvPtr ); |
| 320 | if( iResult == 0 ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 321 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 322 | TCTI_LOG( tctiContext, rmPrefix, "select failed due to timeout, socket #: 0x%x\n", TCTI_CONTEXT_INTEL->tpmSock ); |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 323 | rval = TSS2_TCTI_RC_TRY_AGAIN; |
| 324 | goto retSocketReceiveTpmResponse; |
| 325 | } |
| 326 | else if( iResult == SOCKET_ERROR ) |
| 327 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 328 | TCTI_LOG( tctiContext, rmPrefix, "select failed with socket error: %d\n", WSAGetLastError() ); |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 329 | rval = TSS2_TCTI_RC_IO_ERROR; |
| 330 | goto retSocketReceiveTpmResponse; |
| 331 | } |
| 332 | else if ( iResult != 1 ) |
| 333 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 334 | TCTI_LOG( tctiContext, rmPrefix, "select failed, read the wrong # of bytes: %d\n", iResult ); |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 335 | rval = TSS2_TCTI_RC_IO_ERROR; |
| 336 | goto retSocketReceiveTpmResponse; |
| 337 | } |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 338 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 339 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.protocolResponseSizeReceived != 1 ) |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 340 | { |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 341 | // Receive the size of the response. |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 342 | rval = tctiRecvBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)& (((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize ), 4 ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 343 | if( rval != TSS2_RC_SUCCESS ) |
| 344 | goto retSocketReceiveTpmResponse; |
| 345 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 346 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize = CHANGE_ENDIAN_DWORD( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize ); |
| 347 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.protocolResponseSizeReceived = 1; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 348 | } |
| 349 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 350 | if( response_buffer == NULL ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 351 | { |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 352 | // In this case, just return the size |
| 353 | *response_size = ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize; |
| 354 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.protocolResponseSizeReceived = 1; |
| 355 | goto retSocketReceiveTpmResponse; |
| 356 | } |
| 357 | |
| 358 | if( *response_size < ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize ) |
| 359 | { |
| 360 | *response_size = ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 361 | rval = TSS2_TCTI_RC_INSUFFICIENT_BUFFER; |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 362 | |
| 363 | |
| 364 | // If possible, receive tag from TPM. |
| 365 | if( *response_size >= sizeof( TPM_ST ) && ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived == 0 ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 366 | { |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 367 | if( TSS2_RC_SUCCESS != tctiRecvBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)&( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->tag ), 2 ) ) |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 368 | { |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 369 | goto retSocketReceiveTpmResponse; |
wcarthur | 2efe291 | 2015-11-16 11:19:42 -0500 | [diff] [blame] | 370 | } |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 371 | else |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 372 | { |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 373 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived = 1; |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 374 | } |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 375 | } |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 376 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 377 | // If possible, receive response size from TPM |
| 378 | if( *response_size >= ( sizeof( TPM_ST ) + sizeof( TPM_RC ) ) && ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.responseSizeReceived == 0 ) |
| 379 | { |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 380 | if( TSS2_RC_SUCCESS != tctiRecvBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)&( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->responseSize ), 4 ) ) |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 381 | { |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 382 | goto retSocketReceiveTpmResponse; |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 383 | } |
| 384 | else |
| 385 | { |
| 386 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize = CHANGE_ENDIAN_DWORD( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize ); |
| 387 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.responseSizeReceived = 1; |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | else |
| 392 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 393 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled == 1 && |
Will-nuc | e0d3ec2 | 2015-12-09 15:09:49 -0500 | [diff] [blame] | 394 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize > 0 ) |
| 395 | { |
| 396 | #ifdef DEBUG |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 397 | TCTI_LOG( tctiContext, rmPrefix, "Response Received: " ); |
Will-nuc | e0d3ec2 | 2015-12-09 15:09:49 -0500 | [diff] [blame] | 398 | #endif |
| 399 | #ifdef DEBUG_SOCKETS |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 400 | TCTI_LOG( tctiContext, rmPrefix, "from socket #0x%x:\n", TCTI_CONTEXT_INTEL->tpmSock ); |
Will-nuc | e0d3ec2 | 2015-12-09 15:09:49 -0500 | [diff] [blame] | 401 | #endif |
| 402 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 403 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 404 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived == 1 ) |
| 405 | { |
| 406 | *(TPM_ST *)response_buffer = ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->tag; |
| 407 | responseSizeDelta += sizeof( TPM_ST ); |
| 408 | response_buffer += sizeof( TPM_ST ); |
| 409 | } |
| 410 | |
| 411 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.responseSizeReceived == 1 ) |
| 412 | { |
| 413 | *(TPM_RC *)response_buffer = CHANGE_ENDIAN_DWORD( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->responseSize ); |
| 414 | responseSizeDelta += sizeof( TPM_RC ); |
| 415 | response_buffer += sizeof( TPM_RC ); |
| 416 | } |
| 417 | |
| 418 | // Receive the TPM response. |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 419 | rval = tctiRecvBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)response_buffer, ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize - responseSizeDelta ); |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 420 | if( rval != TSS2_RC_SUCCESS ) |
| 421 | goto retSocketReceiveTpmResponse; |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 422 | |
wcarthur | 2efe291 | 2015-11-16 11:19:42 -0500 | [diff] [blame] | 423 | #ifdef DEBUG |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 424 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled == 1 ) |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 425 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 426 | DEBUG_PRINT_BUFFER( rmPrefix, response_buffer, ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize ); |
wcarthur | 0651af2 | 2015-11-25 15:01:22 -0500 | [diff] [blame] | 427 | } |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 428 | #endif |
wcarthur | 0651af2 | 2015-11-25 15:01:22 -0500 | [diff] [blame] | 429 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 430 | // Receive the appended four bytes of 0's |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 431 | rval = tctiRecvBytes( tctiContext, TCTI_CONTEXT_INTEL->tpmSock, (unsigned char *)&trash, 4 ); |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 432 | if( rval != TSS2_RC_SUCCESS ) |
| 433 | goto retSocketReceiveTpmResponse; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 434 | } |
| 435 | |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 436 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize < *response_size ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 437 | { |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 438 | *response_size = ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 439 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 440 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 441 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.commandSent = 0; |
| 442 | |
| 443 | // Turn cancel off. |
wcarthur | 2efe291 | 2015-11-16 11:19:42 -0500 | [diff] [blame] | 444 | if( rval == TSS2_RC_SUCCESS ) |
| 445 | { |
| 446 | rval = (TSS2_RC)PlatformCommand( tctiContext, MS_SIM_CANCEL_OFF ); |
| 447 | } |
| 448 | else |
| 449 | { |
| 450 | // Ignore return value so earlier error code is preserved. |
| 451 | PlatformCommand( tctiContext, MS_SIM_CANCEL_OFF ); |
| 452 | } |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 453 | |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 454 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled== 1 ) |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 455 | { |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 456 | // TCTI_LOG( tctiContext, NO_PREFIX, "%s sent cancel OFF command:\n", interfaceName ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | retSocketReceiveTpmResponse: |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 460 | if( rval == TSS2_RC_SUCCESS && |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 461 | response_buffer != NULL ) |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 462 | { |
| 463 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->previousStage = TCTI_STAGE_RECEIVE_RESPONSE; |
| 464 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 465 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 466 | return rval; |
| 467 | } |
| 468 | |
| 469 | #ifdef __cplusplus |
| 470 | } |
| 471 | #endif |
| 472 | |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 473 | #define HOSTNAME_LENGTH 200 |
| 474 | #define PORT_LENGTH 4 |
| 475 | |
Philip Tricca | d1bbedb | 2016-02-14 20:39:59 -0800 | [diff] [blame] | 476 | TSS2_RC InitSocketTcti ( |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 477 | TSS2_TCTI_CONTEXT *tctiContext, // OUT |
| 478 | size_t *contextSize, // IN/OUT |
Philip Tricca | 6feb976 | 2016-02-23 10:44:09 -0800 | [diff] [blame] | 479 | const TCTI_SOCKET_CONF *conf, // IN |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 480 | const uint8_t serverSockets |
| 481 | ) |
| 482 | { |
| 483 | TSS2_RC rval = TSS2_RC_SUCCESS; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 484 | SOCKET otherSock; |
| 485 | SOCKET tpmSock; |
| 486 | |
| 487 | if( tctiContext == NULL ) |
| 488 | { |
| 489 | *contextSize = sizeof( TSS2_TCTI_CONTEXT_INTEL ); |
| 490 | return TSS2_RC_SUCCESS; |
| 491 | } |
| 492 | else |
| 493 | { |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 494 | // Init TCTI context. |
Philip Tricca | 7b4948e | 2016-04-18 20:43:59 -0700 | [diff] [blame] | 495 | TSS2_TCTI_MAGIC( tctiContext ) = TCTI_MAGIC; |
| 496 | TSS2_TCTI_VERSION( tctiContext ) = TCTI_VERSION; |
| 497 | TSS2_TCTI_TRANSMIT( tctiContext ) = SocketSendTpmCommand; |
| 498 | TSS2_TCTI_RECEIVE( tctiContext ) = SocketReceiveTpmResponse; |
| 499 | TSS2_TCTI_FINALIZE( tctiContext ) = SocketFinalize; |
| 500 | TSS2_TCTI_CANCEL( tctiContext ) = SocketCancel; |
| 501 | TSS2_TCTI_GET_POLL_HANDLES( tctiContext ) = 0; |
| 502 | TSS2_TCTI_SET_LOCALITY( tctiContext ) = SocketSetLocality; |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 503 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.debugMsgEnabled = 0; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 504 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.locality = 3; |
| 505 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.commandSent = 0; |
| 506 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.rmDebugPrefix = 0; |
wcarthur | a05cdcc | 2015-12-04 18:07:16 -0500 | [diff] [blame] | 507 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived = 0; |
| 508 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.responseSizeReceived = 0; |
| 509 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.protocolResponseSizeReceived = 0; |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 510 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->currentTctiContext = 0; |
| 511 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->previousStage = TCTI_STAGE_INITIALIZE; |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 512 | TCTI_LOG_CALLBACK( tctiContext ) = conf->logCallback; |
Philip Tricca | 4eb2f35 | 2016-03-31 05:55:35 -0700 | [diff] [blame] | 513 | TCTI_LOG_BUFFER_CALLBACK( tctiContext ) = conf->logBufferCallback; |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 514 | TCTI_LOG_DATA( tctiContext ) = conf->logData; |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 515 | |
Philip Tricca | bcc7303 | 2016-03-30 19:50:54 -0700 | [diff] [blame] | 516 | rval = (TSS2_RC) InitSockets( conf->hostname, conf->port, serverSockets, &otherSock, &tpmSock, TCTI_LOG_CALLBACK( tctiContext ), TCTI_LOG_DATA( tctiContext) ); |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 517 | if( rval == TSS2_RC_SUCCESS ) |
| 518 | { |
| 519 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->otherSock = otherSock; |
| 520 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->tpmSock = tpmSock; |
| 521 | } |
| 522 | else |
| 523 | { |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 524 | CloseSockets( otherSock, tpmSock); |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame] | 525 | } |
Will Arthur | 54e04e4 | 2015-07-15 11:29:25 -0400 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | return rval; |
| 529 | } |