示例#1
0
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;

    if( simulator )
    {
        sendbuf[3] = cmd;

        OpenOutFile( &outFp );

        // Send the command
        iResult = send( TCTI_CONTEXT_INTEL->otherSock, sendbuf, 4, 0 );

        if (iResult == SOCKET_ERROR) {
            (*printfFunction)(NO_PREFIX, "send failed with error: %d\n", WSAGetLastError() );
            closesocket(TCTI_CONTEXT_INTEL->otherSock);
            WSACleanup();
            rval = TSS2_TCTI_RC_IO_ERROR;
        }
        else
        {
#ifdef DEBUG_SOCKETS
            (*printfFunction)( rmDebugPrefix, "Send Bytes to socket #0x%x: \n", TCTI_CONTEXT_INTEL->otherSock );
            DebugPrintBuffer( (UINT8 *)sendbuf, 4 );
#endif

            // Read result
            iResult = recv( TCTI_CONTEXT_INTEL->otherSock, recvbuf, 4, 0);
            if (iResult == SOCKET_ERROR) {
                (*printfFunction)(NO_PREFIX, "In PlatformCommand, recv failed (socket: 0x%x) with error: %d\n",
                        TCTI_CONTEXT_INTEL->otherSock, WSAGetLastError() );
                closesocket(TCTI_CONTEXT_INTEL->otherSock);
                WSACleanup();
                rval = TSS2_TCTI_RC_IO_ERROR;
            }
            else if( recvbuf[0] != 0 || recvbuf[1] != 0 || recvbuf[2] != 0 || recvbuf[3] != 0 )
            {
                (*printfFunction)(NO_PREFIX, "PlatformCommand failed with error: %d\n", recvbuf[3] );
                closesocket(TCTI_CONTEXT_INTEL->otherSock);
                WSACleanup();
                rval = TSS2_TCTI_RC_IO_ERROR;
            }
            else
            {
#ifdef DEBUG_SOCKETS
                (*printfFunction)(NO_PREFIX, "Receive bytes from socket #0x%x: \n", TCTI_CONTEXT_INTEL->otherSock );
                DebugPrintBuffer( (UINT8 *)recvbuf, 4 );
#endif
            }
        }

        CloseOutFile( &outFp );
    }
    return rval;
}
示例#2
0
TSS2_RC sendBytes( SOCKET tpmSock, const char *data, int len )
{
    int iResult = 0;
    int sentLength = 0;
    
#ifdef DEBUG_SOCKETS
    PrintRMDebugPrefix();
    (*printfFunction)(NO_PREFIX, "Send Bytes to socket #0x%x: \n", tpmSock );
    DebugPrintBuffer( (UINT8 *)data, len );
#endif    

    for( sentLength = 0; sentLength < len; len -= iResult, sentLength += iResult )
    {
        iResult = send( tpmSock, data, len, 0  );
        if (iResult == SOCKET_ERROR) {
            (*printfFunction)(NO_PREFIX, "send failed with error: %d\n", WSAGetLastError() );
//            closesocket(tpmSock);
//            WSACleanup();
//            exit(1);
            return TSS2_TCTI_RC_IO_ERROR;
        }
    }
    
    return TSS2_RC_SUCCESS;
}
示例#3
0
TSS2_RC recvBytes( SOCKET tpmSock, unsigned char *data, int len )
{
    int iResult = 0;
    int length;
    int bytesRead;
    
    for( bytesRead = 0, length = len; bytesRead != len; length -= iResult, bytesRead += iResult )
    {
        iResult = recv( tpmSock, (char *)&( data[bytesRead] ), length, 0);
        if (iResult == SOCKET_ERROR) {
            PrintRMDebugPrefix();
            (*printfFunction)(NO_PREFIX, "In recvBytes, recv failed (socket: 0x%x) with error: %d\n",
                    tpmSock, WSAGetLastError() );
//            closesocket(tpmSock);
//            WSACleanup();
//            exit(1);
            return TSS2_TCTI_RC_IO_ERROR;
        }
    }

#ifdef DEBUG_SOCKETS
    (*printfFunction)( rmDebugPrefix, "Receive Bytes from socket #0x%x: \n", tpmSock );
    DebugPrintBuffer( data, len );
#endif
    
    return TSS2_RC_SUCCESS;
}