TSS2_RC PlatformCommand( TSS2_TCTI_CONTEXT *tctiContext, /* in */ char cmd ) { int iResult = 0; // used to return function results char sendbuf[] = { 0x0,0x0,0x0,0x0 }; char recvbuf[] = { 0x0, 0x0, 0x0, 0x0 }; TSS2_RC rval = TSS2_RC_SUCCESS; sendbuf[3] = cmd; // Send the command iResult = send( TCTI_CONTEXT_INTEL->otherSock, sendbuf, 4, MSG_NOSIGNAL ); if (iResult == SOCKET_ERROR) { TCTI_LOG( tctiContext, NO_PREFIX, "send failed with error: %d\n", WSAGetLastError() ); rval = TSS2_TCTI_RC_IO_ERROR; } else { #ifdef DEBUG_SOCKETS TCTI_LOG( tctiContext, NO_PREFIX, "Send Bytes to socket #0x%x: \n", TCTI_CONTEXT_INTEL->otherSock ); TCTI_LOG_BUFFER( tctiContext, NO_PREFIX, (UINT8 *)sendbuf, 4 ); #endif // Read result iResult = recv( TCTI_CONTEXT_INTEL->otherSock, recvbuf, 4, 0); if (iResult == SOCKET_ERROR) { TCTI_LOG( tctiContext, NO_PREFIX, "In PlatformCommand, recv failed (socket: 0x%x) with error: %d\n", TCTI_CONTEXT_INTEL->otherSock, WSAGetLastError() ); rval = TSS2_TCTI_RC_IO_ERROR; } else if( recvbuf[0] != 0 || recvbuf[1] != 0 || recvbuf[2] != 0 || recvbuf[3] != 0 ) { TCTI_LOG( tctiContext, NO_PREFIX, "PlatformCommand failed with error: %d\n", recvbuf[3] ); rval = TSS2_TCTI_RC_IO_ERROR; } else { #ifdef DEBUG_SOCKETS TCTI_LOG( tctiContext, NO_PREFIX, "Receive bytes from socket #0x%x: \n", TCTI_CONTEXT_INTEL->otherSock ); TCTI_LOG_BUFFER( tctiContext, NO_PREFIX, (UINT8 *)recvbuf, 4 ); #endif } } return rval; }
static TSS2_RC tctiSendBytes( TSS2_TCTI_CONTEXT *tctiContext, SOCKET sock, const unsigned char *data, int len ) { TSS2_RC ret = TSS2_RC_SUCCESS; #ifdef DEBUG_SOCKETS TCTI_LOG( tctiContext, NO_PREFIX, "Send Bytes to socket #0x%x: \n", sock ); TCTI_LOG_BUFFER( tctiContext, NO_PREFIX, (UINT8 *)data, len ); #endif ret = sendBytes( sock, data, len); if (ret != TSS2_RC_SUCCESS) TCTI_LOG( tctiContext, NO_PREFIX, "In recvBytes, recv failed (socket: 0x%x) with error: %d\n", sock, WSAGetLastError() ); return ret; }
static TSS2_RC tctiRecvBytes( TSS2_TCTI_CONTEXT *tctiContext, SOCKET sock, unsigned char *data, int len ) { TSS2_RC result = 0; result = recvBytes( sock, data, len); if ( (INT32)result == SOCKET_ERROR) { TCTI_LOG( tctiContext, NO_PREFIX, "In recvBytes, recv failed (socket: 0x%x) with error: %d\n", sock, WSAGetLastError() ); return TSS2_TCTI_RC_IO_ERROR; } #ifdef DEBUG_SOCKETS TCTI_LOG( tctiContext, NO_PREFIX, "Receive Bytes from socket #0x%x: \n", sock ); TCTI_LOG_BUFFER( tctiContext, NO_PREFIX, data, len ); #endif return TSS2_RC_SUCCESS; }