Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -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 | ca8e7f3 | 2015-08-03 15:35:19 -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 | ca8e7f3 | 2015-08-03 15:35:19 -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 | ca8e7f3 | 2015-08-03 15:35:19 -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 | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 25 | // THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | //**********************************************************************; |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> // Needed for _wtoi |
| 30 | |
Philip Tricca | e03b846 | 2016-07-08 19:51:23 -0700 | [diff] [blame] | 31 | #include <sapi/tpm20.h> |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 32 | //#include "resourcemgr.h" |
| 33 | //#include <sample.h> |
Philip Tricca | c3dedc2 | 2016-01-15 13:47:22 -0800 | [diff] [blame] | 34 | #include "sysapi_util.h" |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 35 | #include <errno.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <fcntl.h> |
Will-nuc | 3ebfeb9 | 2015-10-29 15:53:27 -0400 | [diff] [blame] | 39 | #include "debug.h" |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 40 | #include "commonchecks.h" |
Philip Tricca | 785e88d | 2016-02-13 12:02:44 -0800 | [diff] [blame] | 41 | #include <tcti/tcti_device.h> |
Philip Tricca | 068d563 | 2016-03-11 12:23:40 -0800 | [diff] [blame] | 42 | #include "logging.h" |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 43 | |
| 44 | #ifdef _WIN32 |
| 45 | #define ssize_t int |
| 46 | #elif __linux |
| 47 | #include <unistd.h> |
| 48 | #endif |
| 49 | |
| 50 | #define HOSTNAME_LENGTH 200 |
| 51 | |
Philip Tricca | 068d563 | 2016-03-11 12:23:40 -0800 | [diff] [blame] | 52 | const char *deviceTctiName = "device TCTI"; |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 53 | |
| 54 | TSS2_RC LocalTpmSendTpmCommand( |
| 55 | TSS2_TCTI_CONTEXT *tctiContext, /* in */ |
| 56 | size_t command_size, /* in */ |
| 57 | uint8_t *command_buffer /* in */ |
| 58 | ) |
| 59 | { |
| 60 | TSS2_RC rval = TSS2_RC_SUCCESS; |
| 61 | ssize_t size; |
| 62 | |
Will-nuc | 3ebfeb9 | 2015-10-29 15:53:27 -0400 | [diff] [blame] | 63 | #ifdef DEBUG |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 64 | UINT32 commandCode; |
| 65 | UINT32 cnt; |
| 66 | #endif |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 67 | printf_type rmPrefix; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 68 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 69 | rval = CommonSendChecks( tctiContext, command_buffer ); |
Will-nuc | 3ebfeb9 | 2015-10-29 15:53:27 -0400 | [diff] [blame] | 70 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 71 | if( rval == TSS2_RC_SUCCESS ) |
Will-nuc | 3ebfeb9 | 2015-10-29 15:53:27 -0400 | [diff] [blame] | 72 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 73 | if( ( ( TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.rmDebugPrefix == 1 ) |
| 74 | rmPrefix = RM_PREFIX; |
| 75 | else |
| 76 | rmPrefix = NO_PREFIX; |
| 77 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 78 | #ifdef DEBUG |
| 79 | commandCode = CHANGE_ENDIAN_DWORD( ( (TPM20_Header_In *)command_buffer )->commandCode ); |
| 80 | cnt = CHANGE_ENDIAN_DWORD(((TPM20_Header_In *) command_buffer)->commandSize); |
| 81 | |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 82 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled == 1 ) |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 83 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 84 | TCTI_LOG( tctiContext, rmPrefix, "" ); |
| 85 | TCTI_LOG( tctiContext, rmPrefix, "Cmd sent: %s\n", strTpmCommandCode( commandCode ) ); |
| 86 | DEBUG_PRINT_BUFFER( rmPrefix, command_buffer, cnt ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 87 | } |
Will-nuc | 3ebfeb9 | 2015-10-29 15:53:27 -0400 | [diff] [blame] | 88 | #endif |
| 89 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 90 | size = write( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->devFile, command_buffer, command_size ); |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 91 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 92 | if( size < 0 ) |
| 93 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 94 | TCTI_LOG( tctiContext, rmPrefix, "send failed with error: %d\n", errno ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 95 | rval = TSS2_TCTI_RC_IO_ERROR; |
| 96 | } |
| 97 | else if( (size_t)size != command_size ) |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 98 | { |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 99 | rval = TSS2_TCTI_RC_IO_ERROR; |
| 100 | } |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 101 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 102 | if( rval == TSS2_RC_SUCCESS ) |
| 103 | { |
| 104 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->previousStage = TCTI_STAGE_SEND_COMMAND; |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 105 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived = 0; |
| 106 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.responseSizeReceived = 0; |
| 107 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.protocolResponseSizeReceived = 0; |
| 108 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 109 | } |
| 110 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 111 | |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 112 | return rval; |
| 113 | } |
| 114 | |
| 115 | TSS2_RC LocalTpmReceiveTpmResponse( |
| 116 | TSS2_TCTI_CONTEXT *tctiContext, /* in */ |
| 117 | size_t *response_size, /* out */ |
| 118 | unsigned char *response_buffer, /* in */ |
| 119 | int32_t timeout |
| 120 | ) |
| 121 | { |
| 122 | TSS2_RC rval = TSS2_RC_SUCCESS; |
| 123 | ssize_t size; |
Will-nuc | 7f5680b | 2015-12-08 18:05:03 -0500 | [diff] [blame] | 124 | unsigned int i; |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 125 | printf_type rmPrefix; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 126 | |
wcarthur | f979e35 | 2015-11-24 17:34:44 -0500 | [diff] [blame] | 127 | rval = CommonReceiveChecks( tctiContext, response_size, response_buffer ); |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 128 | if( rval != TSS2_RC_SUCCESS ) |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 129 | { |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 130 | goto retLocalTpmReceive; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 131 | } |
Will-nuc | 9ab3461 | 2015-10-29 17:02:47 -0400 | [diff] [blame] | 132 | |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 133 | if( ( ( TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.rmDebugPrefix == 1 ) |
| 134 | rmPrefix = RM_PREFIX; |
| 135 | else |
| 136 | rmPrefix = NO_PREFIX; |
| 137 | |
Will-nuc | 8619aca | 2015-12-10 17:20:26 -0500 | [diff] [blame] | 138 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived == 0 ) |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 139 | { |
Will-nuc | 8619aca | 2015-12-10 17:20:26 -0500 | [diff] [blame] | 140 | size = read( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->devFile, &((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseBuffer[0], 4096 ); |
Will-nuc | 9ab3461 | 2015-10-29 17:02:47 -0400 | [diff] [blame] | 141 | |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 142 | if( size < 0 ) |
Will-nuc | 9ab3461 | 2015-10-29 17:02:47 -0400 | [diff] [blame] | 143 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 144 | TCTI_LOG( tctiContext, rmPrefix, "read failed with error: %d\n", errno ); |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 145 | rval = TSS2_TCTI_RC_IO_ERROR; |
Will-nuc | 8619aca | 2015-12-10 17:20:26 -0500 | [diff] [blame] | 146 | goto retLocalTpmReceive; |
Will-nuc | 9ab3461 | 2015-10-29 17:02:47 -0400 | [diff] [blame] | 147 | } |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 148 | else |
| 149 | { |
Will-nuc | 8619aca | 2015-12-10 17:20:26 -0500 | [diff] [blame] | 150 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.tagReceived = 1; |
| 151 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize = size; |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 152 | } |
Will-nuc | 8619aca | 2015-12-10 17:20:26 -0500 | [diff] [blame] | 153 | |
Will-nuc | 7f5680b | 2015-12-08 18:05:03 -0500 | [diff] [blame] | 154 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize = size; |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 155 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 156 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 157 | if( response_buffer == NULL ) |
| 158 | { |
| 159 | // In this case, just return the size |
Will-nuc | 8619aca | 2015-12-10 17:20:26 -0500 | [diff] [blame] | 160 | *response_size = ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize; |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 161 | goto retLocalTpmReceive; |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 162 | } |
| 163 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 164 | if( *response_size < ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize ) |
| 165 | { |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 166 | rval = TSS2_TCTI_RC_INSUFFICIENT_BUFFER; |
Will-nuc | 8619aca | 2015-12-10 17:20:26 -0500 | [diff] [blame] | 167 | *response_size = ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize; |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 168 | goto retLocalTpmReceive; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 169 | } |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 170 | |
Will-nuc | 7f5680b | 2015-12-08 18:05:03 -0500 | [diff] [blame] | 171 | *response_size = ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize; |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 172 | |
Will-nuc | 7f5680b | 2015-12-08 18:05:03 -0500 | [diff] [blame] | 173 | for( i = 0; i < *response_size; i++ ) |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 174 | { |
Will-nuc | e0d3ec2 | 2015-12-09 15:09:49 -0500 | [diff] [blame] | 175 | response_buffer[i] = ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseBuffer[i]; |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 176 | } |
Will-nuc | 7f5680b | 2015-12-08 18:05:03 -0500 | [diff] [blame] | 177 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 178 | #ifdef DEBUG |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 179 | if( ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->status.debugMsgEnabled == 1 && |
Will-nuc | e0d3ec2 | 2015-12-09 15:09:49 -0500 | [diff] [blame] | 180 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize > 0 ) |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 181 | { |
wcarthur | 1c82759 | 2016-04-27 11:07:51 -0400 | [diff] [blame] | 182 | TCTI_LOG( tctiContext, rmPrefix, "\n" ); |
| 183 | TCTI_LOG( tctiContext, rmPrefix, "Response Received: " ); |
| 184 | DEBUG_PRINT_BUFFER( rmPrefix, response_buffer, ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->responseSize ); |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 185 | } |
Will-nuc | 7f5680b | 2015-12-08 18:05:03 -0500 | [diff] [blame] | 186 | #endif |
| 187 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 188 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.commandSent = 0; |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 189 | |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 190 | retLocalTpmReceive: |
| 191 | |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 192 | if( rval == TSS2_RC_SUCCESS && |
wcarthur | 74a92a4 | 2015-12-07 16:02:12 -0500 | [diff] [blame] | 193 | response_buffer != NULL ) |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 194 | { |
| 195 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->previousStage = TCTI_STAGE_RECEIVE_RESPONSE; |
| 196 | } |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 197 | |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 198 | return rval; |
| 199 | } |
| 200 | |
wcarthur | 35aa539 | 2016-03-22 16:52:44 -0400 | [diff] [blame] | 201 | void LocalTpmFinalize( |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 202 | TSS2_TCTI_CONTEXT *tctiContext /* in */ |
| 203 | ) |
| 204 | { |
wcarthur | 35aa539 | 2016-03-22 16:52:44 -0400 | [diff] [blame] | 205 | if( tctiContext != NULL ) |
wcarthur | f979e35 | 2015-11-24 17:34:44 -0500 | [diff] [blame] | 206 | { |
| 207 | close( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->devFile ); |
| 208 | } |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | TSS2_RC LocalTpmCancel( |
| 212 | TSS2_TCTI_CONTEXT *tctiContext |
| 213 | ) |
| 214 | { |
| 215 | TSS2_RC rval = TSS2_RC_SUCCESS; |
| 216 | |
| 217 | // TBD. Needs support from device driver. |
| 218 | |
| 219 | return rval; |
| 220 | } |
| 221 | |
| 222 | TSS2_RC LocalTpmSetLocality( |
| 223 | TSS2_TCTI_CONTEXT *tctiContext, /* in */ |
| 224 | uint8_t locality /* in */ |
| 225 | ) |
| 226 | { |
| 227 | TSS2_RC rval = TSS2_RC_SUCCESS; |
| 228 | |
| 229 | // TBD: how do I do this? |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 230 | |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 231 | return rval; |
| 232 | } |
| 233 | |
Philip Tricca | 0dca4f1 | 2016-02-14 19:32:29 -0800 | [diff] [blame] | 234 | TSS2_RC InitDeviceTcti ( |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 235 | TSS2_TCTI_CONTEXT *tctiContext, // OUT |
| 236 | size_t *contextSize, // IN/OUT |
Philip Tricca | decc21c | 2016-03-30 13:45:18 -0700 | [diff] [blame] | 237 | const TCTI_DEVICE_CONF *config // IN |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 238 | ) |
| 239 | { |
| 240 | TSS2_RC rval = TSS2_RC_SUCCESS; |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 241 | |
| 242 | if( tctiContext == NULL ) |
| 243 | { |
| 244 | *contextSize = sizeof( TSS2_TCTI_CONTEXT_INTEL ); |
| 245 | return TSS2_RC_SUCCESS; |
| 246 | } |
Philip Tricca | 3f7201d | 2016-02-29 17:15:29 -0800 | [diff] [blame] | 247 | else if( config == NULL ) |
| 248 | { |
| 249 | return TSS2_TCTI_RC_BAD_VALUE; |
| 250 | } |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 251 | else |
| 252 | { |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 253 | // Init TCTI context. |
Philip Tricca | 7b4948e | 2016-04-18 20:43:59 -0700 | [diff] [blame] | 254 | TSS2_TCTI_MAGIC( tctiContext ) = TCTI_MAGIC; |
| 255 | TSS2_TCTI_VERSION( tctiContext ) = TCTI_VERSION; |
| 256 | TSS2_TCTI_TRANSMIT( tctiContext ) = LocalTpmSendTpmCommand; |
| 257 | TSS2_TCTI_RECEIVE( tctiContext ) = LocalTpmReceiveTpmResponse; |
| 258 | TSS2_TCTI_FINALIZE( tctiContext ) = LocalTpmFinalize; |
| 259 | TSS2_TCTI_CANCEL( tctiContext ) = LocalTpmCancel; |
| 260 | TSS2_TCTI_GET_POLL_HANDLES( tctiContext ) = 0; |
| 261 | TSS2_TCTI_SET_LOCALITY( tctiContext ) = LocalTpmSetLocality; |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 262 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.locality = 3; |
| 263 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.commandSent = 0; |
| 264 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->status.rmDebugPrefix = 0; |
| 265 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->currentTctiContext = 0; |
wcarthur | eedecd6 | 2015-11-20 16:59:45 -0500 | [diff] [blame] | 266 | ((TSS2_TCTI_CONTEXT_INTEL *)tctiContext)->previousStage = TCTI_STAGE_INITIALIZE; |
Philip Tricca | 068d563 | 2016-03-11 12:23:40 -0800 | [diff] [blame] | 267 | TCTI_LOG_CALLBACK( tctiContext ) = config->logCallback; |
| 268 | TCTI_LOG_DATA( tctiContext ) = config->logData; |
| 269 | |
Philip Tricca | 3f7201d | 2016-02-29 17:15:29 -0800 | [diff] [blame] | 270 | ( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->devFile ) = open( config->device_path, O_RDWR ); |
Philip Tricca | dfa41a5 | 2016-07-20 17:43:57 -0700 | [diff] [blame^] | 271 | if( ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )->devFile < 0 ) |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 272 | { |
| 273 | return( TSS2_TCTI_RC_IO_ERROR ); |
| 274 | } |
Will Arthur | ca8e7f3 | 2015-08-03 15:35:19 -0400 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | return rval; |
| 278 | } |