tcti: Reformat code.

This commit attempts to align the souce code in the TCTI modules
with the coding standard we're currently moving toward. Additionally
this commit flattens out the code by doing does away with the pattern
where nearly the whole body of a function is wrapped in a conditional
checking the result of the common check function. This caused a pile
of unnecessary indentation and generally made the code difficult to
read.

Additionally we take this opportunity to
1) replace the old pattern that put a space after the opening parenthesis
in a function call or control flow statement
2) standardizes on placing the open and closing curly braces for a scope
change on the same line as the conditional
3) breaks long lines up on 80 characters
4) removes 'goto' usage where a simple 'return' suffices
5) rename internal functions in the tcti module to use snake_case instead
of camelCase
6) Remove C++ comments, use c comments.

Signed-off-by: Philip Tricca <philip.b.tricca@intel.com>
diff --git a/tcti/tcti.c b/tcti/tcti.c
index 1ef019c..c62e432 100644
--- a/tcti/tcti.c
+++ b/tcti/tcti.c
@@ -1,58 +1,53 @@
-//**********************************************************************;
-// Copyright (c) 2015, 2017 Intel Corporation
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-// THE POSSIBILITY OF SUCH DAMAGE.
-//**********************************************************************;
+/***********************************************************************
+ * Copyright (c) 2015 - 2017 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ ***********************************************************************/
 
 #include <stdio.h>
-#include <stdlib.h>   // Needed for _wtoi
+#include <stdlib.h>
 
 #include <tcti/common.h>
 #include "sapi/tpm20.h"
 #include "tcti.h"
 #include "common/debug.h"
 
-TSS2_RC CommonSendChecks(
-    TSS2_TCTI_CONTEXT *tctiContext,       /* in */
-    uint8_t           *command_buffer     /* in */
+TSS2_RC tcti_send_checks (
+    TSS2_TCTI_CONTEXT *tctiContext,
+    uint8_t *command_buffer
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
 
-    if( tctiContext == NULL || command_buffer == NULL )
-    {
+    if (tctiContext == NULL || command_buffer == NULL) {
         return TSS2_TCTI_RC_BAD_REFERENCE;
     }
-
-    if (tcti_intel->previousStage == TCTI_STAGE_SEND_COMMAND)
-    {
+    if (tcti_intel->previousStage == TCTI_STAGE_SEND_COMMAND) {
         return TSS2_TCTI_RC_BAD_SEQUENCE;
     }
-
     if (tcti_intel->magic != TCTI_MAGIC ||
-        tcti_intel->version != TCTI_VERSION)
-    {
+        tcti_intel->version != TCTI_VERSION) {
         return TSS2_TCTI_RC_BAD_CONTEXT;
     }
 
@@ -60,27 +55,22 @@
 }
 
 
-TSS2_RC CommonReceiveChecks(
-    TSS2_TCTI_CONTEXT *tctiContext,     /* in */
-    size_t          *response_size,     /* out */
-    unsigned char   *response_buffer    /* in */
+TSS2_RC tcti_receive_checks (
+    TSS2_TCTI_CONTEXT *tctiContext,
+    size_t *response_size,
+    unsigned char *response_buffer
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
 
-    if( tctiContext == NULL || response_size == NULL )
-    {
+    if (tctiContext == NULL || response_size == NULL) {
         return TSS2_TCTI_RC_BAD_REFERENCE;
     }
-
-    if (tcti_intel->previousStage == TCTI_STAGE_RECEIVE_RESPONSE)
-    {
+    if (tcti_intel->previousStage == TCTI_STAGE_RECEIVE_RESPONSE) {
         return TSS2_TCTI_RC_BAD_SEQUENCE;
     }
-
     if (tcti_intel->magic != TCTI_MAGIC ||
-        tcti_intel->version != TCTI_VERSION)
-    {
+        tcti_intel->version != TCTI_VERSION) {
         return TSS2_TCTI_RC_BAD_CONTEXT;
     }
 
diff --git a/tcti/tcti.h b/tcti/tcti.h
index 105a56b..2429df4 100644
--- a/tcti/tcti.h
+++ b/tcti/tcti.h
@@ -1,41 +1,42 @@
-//**********************************************************************;
-// Copyright (c) 2015, 2017 Intel Corporation
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-// THE POSSIBILITY OF SUCH DAMAGE.
-//**********************************************************************;
+/***********************************************************************
+ * Copyright (c) 2015 - 2017 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ ***********************************************************************/
 
-//
-// The context for TCTI implementations is on opaque
-// structure. There shall never be a definition of its content.
-// Implementation provide the size information to
-// applications via the initialize call.
-// This makes use of a compiler trick that allows type
-// checking of the pointer even though the type isn't
-// defined.
-//
-// The first field of a Context must be the common part
-// (see below).
+/*
+ * The context for TCTI implementations is on opaque
+ * structure. There shall never be a definition of its content.
+ * Implementation provide the size information to
+ * applications via the initialize call.
+ * This makes use of a compiler trick that allows type
+ * checking of the pointer even though the type isn't
+ * defined.
+ *
+ * The first field of a Context must be the common part
+ * (see below).
+ */
 #ifndef TSS2_TCTI_UTIL_H
 #define TSS2_TCTI_UTIL_H
 
@@ -74,30 +75,32 @@
         UINT32 debugMsgEnabled: 1;
         UINT32 locality: 8;
         UINT32 commandSent: 1;
-        UINT32 rmDebugPrefix: 1;  // Used to add a prefix to RM debug messages.  This is ONLY used
-                                  // for TPM commands and responses as a way to differentiate
-                                  // RM generated TPM commands from application generated ones.
-
-        // Following two fields used to save partial response status in case receive buffer's too small.
+        /*
+         * Used to add a prefix to RM debug messages.  This is ONLY used
+         * for TPM commands and responses as a way to differentiate
+         * RM generated TPM commands from application generated ones.
+         */
+        UINT32 rmDebugPrefix: 1;
+        /* Following two fields used to save partial response status in case receive buffer's too small. */
         UINT32 tagReceived: 1;
         UINT32 responseSizeReceived: 1;
         UINT32 protocolResponseSizeReceived: 1;
     } status;
 
-    // Following two fields used to save partial response in case receive buffer's too small.
+    /* Following two fields used to save partial response in case receive buffer's too small. */
     TPM_ST tag;
     TPM_RC responseSize;
 
     TSS2_TCTI_CONTEXT *currentTctiContext;
 
-    // Sockets if socket interface is being used.
+    /* Sockets if socket interface is being used. */
     SOCKET otherSock;
     SOCKET tpmSock;
     SOCKET currentConnectSock;
 
-    // File descriptor for device file if real TPM is being used.
+    /* File descriptor for device file if real TPM is being used. */
     int devFile;
-    UINT8 previousStage;            // Used to check for sequencing errors.
+    UINT8 previousStage;            /* Used to check for sequencing errors. */
     unsigned char responseBuffer[4096];
     TCTI_LOG_CALLBACK logCallback;
     TCTI_LOG_BUFFER_CALLBACK logBufferCallback;
@@ -118,7 +121,7 @@
  * This function performs common checks on the context structure and the
  * buffer passed into TCTI 'transmit' functions.
  */
-TSS2_RC CommonSendChecks(
+TSS2_RC tcti_send_checks (
     TSS2_TCTI_CONTEXT *tctiContext,
     uint8_t           *command_buffer
     );
@@ -126,7 +129,7 @@
  * This function performs common checks on the context structure, buffer and
  * size parameter passed to the TCTI 'receive' functions.
  */
-TSS2_RC CommonReceiveChecks(
+TSS2_RC tcti_receive_checks (
     TSS2_TCTI_CONTEXT *tctiContext,
     size_t            *response_size,
     unsigned char     *response_buffer
diff --git a/tcti/tcti_device.c b/tcti/tcti_device.c
index c2dc025..2eb78e3 100644
--- a/tcti/tcti_device.c
+++ b/tcti/tcti_device.c
@@ -1,32 +1,32 @@
-//**********************************************************************;
-// Copyright (c) 2015, Intel Corporation
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-// THE POSSIBILITY OF SUCH DAMAGE.
-//**********************************************************************;
+/***********************************************************************
+ * Copyright (c) 2015 - 2017 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ ***********************************************************************/
 
 #include <stdio.h>
-#include <stdlib.h>   // Needed for _wtoi
+#include <stdlib.h>
 #include <unistd.h>
 
 #include "sapi/tpm20.h"
@@ -40,14 +40,10 @@
 #include "tcti/tcti_device.h"
 #include "logging.h"
 
-#define HOSTNAME_LENGTH 200
-
-const char *deviceTctiName = "device TCTI";
-
 TSS2_RC LocalTpmSendTpmCommand(
-    TSS2_TCTI_CONTEXT *tctiContext,       /* in */
-    size_t             command_size,      /* in */
-    uint8_t           *command_buffer     /* in */
+    TSS2_TCTI_CONTEXT *tctiContext,
+    size_t command_size,
+    uint8_t *command_buffer
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
@@ -60,63 +56,59 @@
 #endif
     printf_type rmPrefix;
 
-    rval = CommonSendChecks( tctiContext, command_buffer );
-
-    if( rval == TSS2_RC_SUCCESS )
-    {
-        if (tcti_intel->status.rmDebugPrefix == 1)
-            rmPrefix = RM_PREFIX;
-        else
-            rmPrefix = NO_PREFIX;
-
+    rval = tcti_send_checks (tctiContext, command_buffer);
+    if (rval != TSS2_RC_SUCCESS) {
+        return rval;
+    }
+    if (tcti_intel->status.rmDebugPrefix == 1) {
+        rmPrefix = RM_PREFIX;
+    } else {
+        rmPrefix = NO_PREFIX;
+    }
 #ifdef DEBUG
-        TSS2_RC rc;
-        size_t offset = sizeof (TPM_ST);
-        rc = Tss2_MU_TPM_ST_Unmarshal (command_buffer,
-                               command_size,
-                               &offset,
-                               &commandCode);
-        rc = Tss2_MU_UINT32_Unmarshal (command_buffer,
-                               command_size,
-                               &offset,
-                               &cnt);
-        if (tcti_intel->status.debugMsgEnabled == 1)
-        {
-            TCTI_LOG( tctiContext, rmPrefix, "" );
-            TCTI_LOG( tctiContext, rmPrefix, "Cmd sent: %s\n", strTpmCommandCode( commandCode ) );
-            DEBUG_PRINT_BUFFER( rmPrefix, command_buffer, cnt );
-        }
+    TSS2_RC rc;
+    size_t offset = sizeof (TPM_ST);
+    rc = Tss2_MU_TPM_ST_Unmarshal (command_buffer,
+                                   command_size,
+                                   &offset,
+                                   &commandCode);
+    rc = Tss2_MU_UINT32_Unmarshal (command_buffer,
+                                   command_size,
+                                   &offset,
+                                   &cnt);
+    if (tcti_intel->status.debugMsgEnabled == 1) {
+        TCTI_LOG (tctiContext, rmPrefix, "");
+        TCTI_LOG (tctiContext,
+                  rmPrefix,
+                  "Cmd sent: %s\n",
+                  strTpmCommandCode (commandCode));
+        DEBUG_PRINT_BUFFER (rmPrefix, command_buffer, cnt);
+    }
 #endif
-
-        size = write(tcti_intel->devFile, command_buffer, command_size);
-
-        if( size < 0 )
-        {
-            TCTI_LOG( tctiContext, rmPrefix, "send failed with error: %d\n", errno );
-            rval = TSS2_TCTI_RC_IO_ERROR;
-        }
-        else if( (size_t)size != command_size )
-        {
-            rval = TSS2_TCTI_RC_IO_ERROR;
-        }
-
-        if( rval == TSS2_RC_SUCCESS )
-        {
-            tcti_intel->previousStage = TCTI_STAGE_SEND_COMMAND;
-            tcti_intel->status.tagReceived = 0;
-            tcti_intel->status.responseSizeReceived = 0;
-            tcti_intel->status.protocolResponseSizeReceived = 0;
-        }
+    size = write (tcti_intel->devFile, command_buffer, command_size);
+    if (size < 0) {
+        TCTI_LOG (tctiContext,
+                  rmPrefix,
+                  "send failed with error: %d\n",
+                  errno);
+        return TSS2_TCTI_RC_IO_ERROR;
+    } else if ((size_t)size != command_size) {
+        return TSS2_TCTI_RC_IO_ERROR;
     }
 
-    return rval;
+    tcti_intel->previousStage = TCTI_STAGE_SEND_COMMAND;
+    tcti_intel->status.tagReceived = 0;
+    tcti_intel->status.responseSizeReceived = 0;
+    tcti_intel->status.protocolResponseSizeReceived = 0;
+
+    return TSS2_RC_SUCCESS;
 }
 
 TSS2_RC LocalTpmReceiveTpmResponse(
-    TSS2_TCTI_CONTEXT *tctiContext,     /* in */
-    size_t          *response_size,     /* out */
-    unsigned char   *response_buffer,    /* in */
-    int32_t         timeout
+    TSS2_TCTI_CONTEXT *tctiContext,
+    size_t *response_size,
+    unsigned char *response_buffer,
+    int32_t timeout
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
@@ -125,29 +117,27 @@
     unsigned int i;
     printf_type rmPrefix;
 
-    rval = CommonReceiveChecks( tctiContext, response_size, response_buffer );
-    if( rval != TSS2_RC_SUCCESS )
-    {
+    rval = tcti_receive_checks (tctiContext, response_size, response_buffer);
+    if (rval != TSS2_RC_SUCCESS) {
         goto retLocalTpmReceive;
     }
 
-    if (tcti_intel->status.rmDebugPrefix == 1)
+    if (tcti_intel->status.rmDebugPrefix == 1) {
         rmPrefix = RM_PREFIX;
-    else
+    } else {
         rmPrefix = NO_PREFIX;
+    }
 
-    if (tcti_intel->status.tagReceived == 0)
-    {
-        size = read(tcti_intel->devFile, tcti_intel->responseBuffer, 4096);
-
-        if( size < 0 )
-        {
-            TCTI_LOG( tctiContext, rmPrefix, "read failed with error: %d\n", errno );
+    if (tcti_intel->status.tagReceived == 0) {
+        size = read (tcti_intel->devFile, tcti_intel->responseBuffer, 4096);
+        if (size < 0) {
+            TCTI_LOG (tctiContext,
+                      rmPrefix,
+                      "read failed with error: %d\n",
+                      errno);
             rval = TSS2_TCTI_RC_IO_ERROR;
             goto retLocalTpmReceive;
-        }
-        else
-        {
+        } else {
             tcti_intel->status.tagReceived = 1;
             tcti_intel->responseSize = size;
         }
@@ -155,15 +145,12 @@
         tcti_intel->responseSize = size;
     }
 
-    if( response_buffer == NULL )
-    {
-        // In this case, just return the size
+    if (response_buffer == NULL) {
         *response_size = tcti_intel->responseSize;
         goto retLocalTpmReceive;
     }
 
-    if (*response_size < tcti_intel->responseSize)
-    {
+    if (*response_size < tcti_intel->responseSize) {
         rval = TSS2_TCTI_RC_INSUFFICIENT_BUFFER;
         *response_size = tcti_intel->responseSize;
         goto retLocalTpmReceive;
@@ -171,28 +158,26 @@
 
     *response_size = tcti_intel->responseSize;
 
-    for( i = 0; i < *response_size; i++ )
-    {
+    for (i = 0; i < *response_size; i++) {
         response_buffer[i] = tcti_intel->responseBuffer[i];
     }
 
 #ifdef DEBUG
-    if(tcti_intel->status.debugMsgEnabled == 1 &&
-       tcti_intel->responseSize > 0)
+    if (tcti_intel->status.debugMsgEnabled == 1 &&
+        tcti_intel->responseSize > 0)
     {
-        TCTI_LOG( tctiContext, rmPrefix, "\n" );
-        TCTI_LOG( tctiContext, rmPrefix, "Response Received: " );
-        DEBUG_PRINT_BUFFER(rmPrefix, response_buffer, tcti_intel->responseSize);
+        TCTI_LOG (tctiContext, rmPrefix, "\n");
+        TCTI_LOG (tctiContext, rmPrefix, "Response Received: ");
+        DEBUG_PRINT_BUFFER (rmPrefix,
+                            response_buffer,
+                            tcti_intel->responseSize);
     }
 #endif
 
     tcti_intel->status.commandSent = 0;
 
 retLocalTpmReceive:
-
-    if( rval == TSS2_RC_SUCCESS &&
-		response_buffer != NULL )
-    {
+    if (rval == TSS2_RC_SUCCESS && response_buffer != NULL ) {
         tcti_intel->previousStage = TCTI_STAGE_RECEIVE_RESPONSE;
     }
 
@@ -200,13 +185,12 @@
 }
 
 void LocalTpmFinalize(
-    TSS2_TCTI_CONTEXT *tctiContext       /* in */
+    TSS2_TCTI_CONTEXT *tctiContext
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
 
-    if( tctiContext != NULL )
-    {
+    if (tctiContext != NULL) {
         close(tcti_intel->devFile);
     }
 }
@@ -220,17 +204,17 @@
 }
 
 TSS2_RC LocalTpmGetPollHandles(
-    TSS2_TCTI_CONTEXT     *tctiContext,
+    TSS2_TCTI_CONTEXT *tctiContext,
     TSS2_TCTI_POLL_HANDLE *handles,
-    size_t                *num_handles)
+    size_t *num_handles)
 {
     /* Linux driver doesn't support polling. */
     return TSS2_TCTI_RC_NOT_IMPLEMENTED;
 }
 
 TSS2_RC LocalTpmSetLocality(
-    TSS2_TCTI_CONTEXT *tctiContext,       /* in */
-    uint8_t           locality     /* in */
+    TSS2_TCTI_CONTEXT *tctiContext,
+    uint8_t locality
     )
 {
     /*
@@ -241,49 +225,44 @@
 }
 
 TSS2_RC InitDeviceTcti (
-    TSS2_TCTI_CONTEXT *tctiContext, // OUT
-    size_t *contextSize,            // IN/OUT
-    const TCTI_DEVICE_CONF *config  // IN
+    TSS2_TCTI_CONTEXT *tctiContext,
+    size_t *contextSize,
+    const TCTI_DEVICE_CONF *config
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
     TSS2_RC rval = TSS2_RC_SUCCESS;
 
-    if( tctiContext == NULL && contextSize == NULL )
+    if (tctiContext == NULL && contextSize == NULL) {
         return TSS2_TCTI_RC_BAD_VALUE;
-    if( tctiContext == NULL )
-    {
+    } else if (tctiContext == NULL) {
         *contextSize = sizeof (TSS2_TCTI_CONTEXT_INTEL);
         return TSS2_RC_SUCCESS;
     }
-    else if( config == NULL )
-    {
+    if (config == NULL) {
         return TSS2_TCTI_RC_BAD_VALUE;
     }
-    else
-    {
-        // Init TCTI context.
-        TSS2_TCTI_MAGIC( tctiContext ) = TCTI_MAGIC;
-        TSS2_TCTI_VERSION( tctiContext ) = TCTI_VERSION;
-        TSS2_TCTI_TRANSMIT( tctiContext ) = LocalTpmSendTpmCommand;
-        TSS2_TCTI_RECEIVE( tctiContext ) = LocalTpmReceiveTpmResponse;
-        TSS2_TCTI_FINALIZE( tctiContext ) = LocalTpmFinalize;
-        TSS2_TCTI_CANCEL( tctiContext ) = LocalTpmCancel;
-        TSS2_TCTI_GET_POLL_HANDLES( tctiContext ) = LocalTpmGetPollHandles;
-        TSS2_TCTI_SET_LOCALITY( tctiContext ) = LocalTpmSetLocality;
-        tcti_intel->status.locality = 3;
-        tcti_intel->status.commandSent = 0;
-        tcti_intel->status.rmDebugPrefix = 0;
-        tcti_intel->currentTctiContext = 0;
-        tcti_intel->previousStage = TCTI_STAGE_INITIALIZE;
-        TCTI_LOG_CALLBACK( tctiContext ) = config->logCallback;
-        TCTI_LOG_DATA( tctiContext ) = config->logData;
 
-        tcti_intel->devFile = open(config->device_path, O_RDWR);
-        if (tcti_intel->devFile < 0)
-        {
-            return TSS2_TCTI_RC_IO_ERROR;
-        }
+    /* Init TCTI context */
+    TSS2_TCTI_MAGIC (tctiContext) = TCTI_MAGIC;
+    TSS2_TCTI_VERSION (tctiContext) = TCTI_VERSION;
+    TSS2_TCTI_TRANSMIT (tctiContext) = LocalTpmSendTpmCommand;
+    TSS2_TCTI_RECEIVE (tctiContext) = LocalTpmReceiveTpmResponse;
+    TSS2_TCTI_FINALIZE (tctiContext) = LocalTpmFinalize;
+    TSS2_TCTI_CANCEL (tctiContext) = LocalTpmCancel;
+    TSS2_TCTI_GET_POLL_HANDLES (tctiContext) = LocalTpmGetPollHandles;
+    TSS2_TCTI_SET_LOCALITY (tctiContext) = LocalTpmSetLocality;
+    tcti_intel->status.locality = 3;
+    tcti_intel->status.commandSent = 0;
+    tcti_intel->status.rmDebugPrefix = 0;
+    tcti_intel->currentTctiContext = 0;
+    tcti_intel->previousStage = TCTI_STAGE_INITIALIZE;
+    TCTI_LOG_CALLBACK (tctiContext) = config->logCallback;
+    TCTI_LOG_DATA (tctiContext) = config->logData;
+
+    tcti_intel->devFile = open (config->device_path, O_RDWR);
+    if (tcti_intel->devFile < 0) {
+        return TSS2_TCTI_RC_IO_ERROR;
     }
 
     return rval;
diff --git a/tcti/tcti_socket.c b/tcti/tcti_socket.c
index 9c6b478..6b1fd10 100644
--- a/tcti/tcti_socket.c
+++ b/tcti/tcti_socket.c
@@ -1,32 +1,32 @@
-//**********************************************************************;
-// Copyright (c) 2015, 2016, 2017 Intel Corporation
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
-// THE POSSIBILITY OF SUCH DAMAGE.
-//**********************************************************************;
+/***********************************************************************
+ * Copyright (c) 2015 - 2017 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ **********************************************************************/
 
 #include <stdio.h>
-#include <stdlib.h>   // Needed for _wtoi
+#include <stdlib.h>
 #include <sys/time.h>
 
 #include "sapi/tpm20.h"
@@ -39,69 +39,92 @@
 #include "sockets.h"
 #include "tss2_endian.h"
 
-static TSS2_RC tctiRecvBytes( TSS2_TCTI_CONTEXT *tctiContext, SOCKET sock, unsigned char *data, int len )
+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() );
+    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 );
+    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;
 }
 
-static TSS2_RC tctiSendBytes( TSS2_TCTI_CONTEXT *tctiContext, SOCKET sock, const unsigned char *data, int len )
+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 );
+    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() );
+    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;
 }
 
-TSS2_RC SendSessionEndSocketTcti(
-    TSS2_TCTI_CONTEXT *tctiContext,       /* in */
-    UINT8 tpmCmdServer )
+TSS2_RC SendSessionEndSocketTcti (
+    TSS2_TCTI_CONTEXT *tctiContext,
+    UINT8 tpmCmdServer
+    )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
-    // Value for "send command" to MS simulator
+    /* Value for "send command" to MS simulator */
     uint8_t buffer [4] = { 0, };
     SOCKET sock;
     TSS2_RC rval = TSS2_RC_SUCCESS;
 
-    if( tpmCmdServer )
-    {
+    if (tpmCmdServer) {
         sock = tcti_intel->tpmSock;
-    }
-    else
-    {
+    } else {
         sock = tcti_intel->otherSock;
     }
 
-    rval = Tss2_MU_UINT32_Marshal (TPM_SESSION_END, buffer, sizeof (buffer), NULL);
+    rval = Tss2_MU_UINT32_Marshal (TPM_SESSION_END,
+                                   buffer,
+                                   sizeof (buffer),
+                                   NULL);
     if (rval == TSS2_RC_SUCCESS) {
         return rval;
     }
-    rval = tctiSendBytes( tctiContext, sock, (char unsigned *)buffer, 4 );
+    rval = tctiSendBytes (tctiContext, sock, (char unsigned *)buffer, 4);
 
     return( rval );
 }
 
 TSS2_RC SocketSendTpmCommand(
-    TSS2_TCTI_CONTEXT *tctiContext,       /* in */
-    size_t             command_size,      /* in */
-    uint8_t           *command_buffer     /* in */
+    TSS2_TCTI_CONTEXT *tctiContext,
+    size_t command_size,
+    uint8_t *command_buffer
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
@@ -115,89 +138,114 @@
     UINT32 commandCode;
     printf_type rmPrefix;
 #endif
-    rval = CommonSendChecks( tctiContext, command_buffer );
-    if( rval != TSS2_RC_SUCCESS )
-    {
-        goto returnFromSocketSendTpmCommand;
+    rval = tcti_send_checks (tctiContext, command_buffer);
+    if (rval != TSS2_RC_SUCCESS) {
+        return rval;
     }
 
 #ifdef DEBUG
-    if (tcti_intel->status.rmDebugPrefix == 1)
+    if (tcti_intel->status.rmDebugPrefix == 1) {
         rmPrefix = RM_PREFIX;
-    else
+    } else {
         rmPrefix = NO_PREFIX;
+    }
 
-    if (tcti_intel->status.debugMsgEnabled == 1)
-    {
-        TCTI_LOG( tctiContext, rmPrefix, "" );
+    if (tcti_intel->status.debugMsgEnabled == 1) {
+        TCTI_LOG (tctiContext, rmPrefix, "");
         offset = sizeof (TPM_ST) + sizeof (UINT32);
         rval = Tss2_MU_TPM_CC_Unmarshal (command_buffer,
-                                 command_size,
-                                 &offset,
-                                 &commandCode);
+                                         command_size,
+                                         &offset,
+                                         &commandCode);
+
 #ifdef DEBUG_SOCKETS
-        TCTI_LOG(tctiContext, NO_PREFIX, "Command sent on socket #0x%x: %s\n", tcti_intel->tpmSock, strTpmCommandCode(commandCode));
+        TCTI_LOG (tctiContext,
+                  NO_PREFIX,
+                  "Command sent on socket #0x%x: %s\n",
+                  TCTI_CONTEXT_INTEL->tpmSock,
+                  strTpmCommandCode (commandCode));
+
 #else
-        TCTI_LOG(tctiContext, NO_PREFIX, "Cmd sent: %s\n", strTpmCommandCode(commandCode));
+        TCTI_LOG (tctiContext,
+                  NO_PREFIX,
+                  "Cmd sent: %s\n",
+                  strTpmCommandCode (commandCode));
 #endif
     }
 #endif
-    // Size TPM 1.2 and TPM 2.0 headers overlap exactly, we can use
-    // either 1.2 or 2.0 header to get the size.
+    /*
+     * Size TPM 1.2 and TPM 2.0 headers overlap exactly, we can use
+     * either 1.2 or 2.0 header to get the size.
+     */
     offset = sizeof (TPM_ST);
-    rval = Tss2_MU_UINT32_Unmarshal (command_buffer, command_size, &offset, &cnt);
+    rval = Tss2_MU_UINT32_Unmarshal (command_buffer,
+                                     command_size,
+                                     &offset,
+                                     &cnt);
 
-    // Send TPM_SEND_COMMAND
+    /* Send TPM_SEND_COMMAND */
     rval = Tss2_MU_UINT32_Marshal (MS_SIM_TPM_SEND_COMMAND,
                            (uint8_t*)&tpmSendCommand,
                            sizeof (tpmSendCommand),
-                           NULL);  // Value for "send command" to MS simulator.
-    rval = tctiSendBytes( tctiContext, tcti_intel->tpmSock, (unsigned char *)&tpmSendCommand, 4 );
-    if( rval != TSS2_RC_SUCCESS )
-        goto returnFromSocketSendTpmCommand;
+                           NULL);  /* Value for "send command" to MS simulator. */
+    rval = tctiSendBytes (tctiContext,
+                          tcti_intel->tpmSock,
+                          (unsigned char *)&tpmSendCommand,
+                          4);
+    if (rval != TSS2_RC_SUCCESS) {
+        return rval;
+    }
 
-    // Send the locality
+    /* Send the locality */
     locality = (UINT8)tcti_intel->status.locality;
-    rval = tctiSendBytes( tctiContext, tcti_intel->tpmSock, (unsigned char *)&locality, 1 );
-    if( rval != TSS2_RC_SUCCESS )
-        goto returnFromSocketSendTpmCommand;
+    rval = tctiSendBytes (tctiContext,
+                          tcti_intel->tpmSock,
+                          (unsigned char *)&locality,
+                          1);
+    if (rval != TSS2_RC_SUCCESS) {
+        return rval;
+    }
 
 #ifdef DEBUG
-    if (tcti_intel->status.debugMsgEnabled == 1)
-    {
-        TCTI_LOG( tctiContext, rmPrefix, "Locality = %d", tcti_intel->status.locality);
+    if (tcti_intel->status.debugMsgEnabled == 1) {
+        TCTI_LOG (tctiContext,
+                  rmPrefix,
+                  "Locality = %d",
+                  tcti_intel->status.locality);
     }
 #endif
 
-    // Send number of bytes.
+    /* Send number of bytes. */
     cnt1 = cnt;
     cnt = HOST_TO_BE_32(cnt);
-    rval = tctiSendBytes( tctiContext, tcti_intel->tpmSock, (unsigned char *)&cnt, 4 );
-    if( rval != TSS2_RC_SUCCESS )
-        goto returnFromSocketSendTpmCommand;
+    rval = tctiSendBytes (tctiContext,
+                          tcti_intel->tpmSock,
+                          (unsigned char *)&cnt,
+                          4);
+    if (rval != TSS2_RC_SUCCESS) {
+        return rval;
+    }
 
-    // Send the TPM command buffer
-    rval = tctiSendBytes( tctiContext, tcti_intel->tpmSock, (unsigned char *)command_buffer, cnt1 );
-    if( rval != TSS2_RC_SUCCESS )
-        goto returnFromSocketSendTpmCommand;
+    /* Send the TPM command buffer */
+    rval = tctiSendBytes (tctiContext,
+                          tcti_intel->tpmSock,
+                          (unsigned char *)command_buffer,
+                          cnt1);
+    if (rval != TSS2_RC_SUCCESS) {
+        return rval;
+    }
 
 #ifdef DEBUG
-    if (tcti_intel->status.debugMsgEnabled == 1)
-    {
-        DEBUG_PRINT_BUFFER( rmPrefix, command_buffer, cnt1 );
+    if (tcti_intel->status.debugMsgEnabled == 1) {
+        DEBUG_PRINT_BUFFER (rmPrefix, command_buffer, cnt1);
     }
 #endif
     tcti_intel->status.commandSent = 1;
 
-returnFromSocketSendTpmCommand:
-
-    if( rval == TSS2_RC_SUCCESS )
-    {
-        tcti_intel->previousStage = TCTI_STAGE_SEND_COMMAND;
-        tcti_intel->status.tagReceived = 0;
-        tcti_intel->status.responseSizeReceived = 0;
-        tcti_intel->status.protocolResponseSizeReceived = 0;
-    }
+    tcti_intel->previousStage = TCTI_STAGE_SEND_COMMAND;
+    tcti_intel->status.tagReceived = 0;
+    tcti_intel->status.responseSizeReceived = 0;
+    tcti_intel->status.protocolResponseSizeReceived = 0;
 
     return rval;
 }
@@ -207,80 +255,65 @@
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
-    TSS2_RC rval = TSS2_RC_SUCCESS;
 
-    if( tctiContext == 0 )
-    {
-        rval = TSS2_TCTI_RC_BAD_REFERENCE;
+    if (tctiContext == NULL) {
+        return TSS2_TCTI_RC_BAD_REFERENCE;
+    } else if (tcti_intel->status.commandSent != 1) {
+        return TSS2_TCTI_RC_BAD_SEQUENCE;
+    } else {
+        return PlatformCommand (tctiContext, MS_SIM_CANCEL_ON);
     }
-    else if (tcti_intel->status.commandSent != 1)
-    {
-        rval = TSS2_TCTI_RC_BAD_SEQUENCE;
-    }
-    else
-    {
-        rval = (TSS2_RC)PlatformCommand( tctiContext, MS_SIM_CANCEL_ON );
-    }
-
-    return rval;
 }
 
 TSS2_RC SocketSetLocality(
-    TSS2_TCTI_CONTEXT *tctiContext,       /* in */
-    uint8_t           locality     /* in */
+    TSS2_TCTI_CONTEXT *tctiContext,
+    uint8_t locality
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
-    TSS2_RC rval = TSS2_RC_SUCCESS;
 
-    if( tctiContext == 0 )
-    {
-        rval = TSS2_TCTI_RC_BAD_REFERENCE;
-    }
-    else if (tcti_intel->status.locality != locality)
-    {
-        if (tcti_intel->status.commandSent == 1)
-        {
-            rval = TSS2_TCTI_RC_BAD_SEQUENCE;
-        }
-        else
-        {
+    if (tctiContext == 0) {
+        return TSS2_TCTI_RC_BAD_REFERENCE;
+    } else if (tcti_intel->status.locality != locality) {
+        if (tcti_intel->status.commandSent == 1) {
+            return TSS2_TCTI_RC_BAD_SEQUENCE;
+        } else {
             tcti_intel->status.locality = locality;
         }
     }
 
-    return rval;
+    return TSS2_RC_SUCCESS;
 }
 
 TSS2_RC SocketGetPollHandles(
-    TSS2_TCTI_CONTEXT     *tctiContext,
+    TSS2_TCTI_CONTEXT *tctiContext,
     TSS2_TCTI_POLL_HANDLE *handles,
-    size_t                *num_handles)
+    size_t *num_handles)
 {
     return TSS2_TCTI_RC_NOT_IMPLEMENTED;
 }
 
 void SocketFinalize(
-    TSS2_TCTI_CONTEXT *tctiContext       /* in */
+    TSS2_TCTI_CONTEXT *tctiContext
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
 
-    if( tctiContext != NULL )
-    {
-        // Send session end messages to servers.
-        SendSessionEndSocketTcti( tctiContext, 1 );
-        SendSessionEndSocketTcti( tctiContext, 0 );
-
-        CloseSockets(tcti_intel->otherSock, tcti_intel->tpmSock);
+    if (tctiContext == NULL) {
+        return;
     }
+
+    SendSessionEndSocketTcti (tctiContext, 1);
+    SendSessionEndSocketTcti (tctiContext, 0);
+
+    CloseSockets (tcti_intel->otherSock, tcti_intel->tpmSock);
 }
 
 TSS2_RC SocketReceiveTpmResponse(
-    TSS2_TCTI_CONTEXT *tctiContext,     /* in */
-    size_t          *response_size,     /* out */
-    unsigned char   *response_buffer,    /* in */
-    int32_t         timeout
+    TSS2_TCTI_CONTEXT *tctiContext,
+    size_t *response_size,
+    unsigned char *response_buffer,
+    int32_t timeout
     )
 {
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
@@ -293,169 +326,176 @@
     unsigned char responseSizeDelta = 0;
     printf_type rmPrefix;
 
-    rval = CommonReceiveChecks( tctiContext, response_size, response_buffer );
-    if( rval != TSS2_RC_SUCCESS )
-    {
+    rval = tcti_receive_checks (tctiContext, response_size, response_buffer);
+    if (rval != TSS2_RC_SUCCESS) {
         goto retSocketReceiveTpmResponse;
     }
 
-    if (tcti_intel->status.rmDebugPrefix == 1)
+    if (tcti_intel->status.rmDebugPrefix == 1) {
         rmPrefix = RM_PREFIX;
-    else
+    } else {
         rmPrefix = NO_PREFIX;
-
-    if( timeout == TSS2_TCTI_TIMEOUT_BLOCK )
-    {
-        tvPtr = 0;
     }
-    else
-    {
+
+    if (timeout == TSS2_TCTI_TIMEOUT_BLOCK) {
+        tvPtr = 0;
+    } else {
         tv.tv_sec = timeout / 1000;
         tv.tv_usec = timeoutMsecs * 1000;
         tvPtr = &tv;
     }
 
-    FD_ZERO( &readFds );
-    FD_SET(tcti_intel->tpmSock, &readFds);
+    FD_ZERO (&readFds);
+    FD_SET (tcti_intel->tpmSock, &readFds);
 
-    iResult = select(tcti_intel->tpmSock + 1, &readFds, 0, 0, tvPtr);
-    if( iResult == 0 )
-    {
-        TCTI_LOG(tctiContext, rmPrefix, "select failed due to timeout, socket #: 0x%x\n", tcti_intel->tpmSock);
+    iResult = select (tcti_intel->tpmSock + 1, &readFds, 0, 0, tvPtr);
+    if (iResult == 0) {
+        TCTI_LOG (tctiContext,
+                  rmPrefix,
+                  "select failed due to timeout, socket #: 0x%x\n",
+                  tcti_intel->tpmSock);
         rval = TSS2_TCTI_RC_TRY_AGAIN;
         goto retSocketReceiveTpmResponse;
-    }
-    else if( iResult == SOCKET_ERROR )
-    {
-        TCTI_LOG( tctiContext, rmPrefix, "select failed with socket error: %d\n", WSAGetLastError() );
+    } else if (iResult == SOCKET_ERROR) {
+        TCTI_LOG (tctiContext,
+                  rmPrefix,
+                  "select failed with socket error: %d\n",
+                  WSAGetLastError ());
         rval = TSS2_TCTI_RC_IO_ERROR;
         goto retSocketReceiveTpmResponse;
-    }
-    else if ( iResult != 1 )
-    {
-        TCTI_LOG( tctiContext, rmPrefix, "select failed, read the wrong # of bytes: %d\n", iResult );
+    } else if (iResult != 1) {
+        TCTI_LOG (tctiContext,
+                  rmPrefix,
+                  "select failed, read the wrong # of bytes: %d\n",
+                  iResult);
         rval = TSS2_TCTI_RC_IO_ERROR;
         goto retSocketReceiveTpmResponse;
     }
 
-    if (tcti_intel->status.protocolResponseSizeReceived != 1)
-    {
-        // Receive the size of the response.
-        rval = tctiRecvBytes(tctiContext, tcti_intel->tpmSock, (unsigned char *)&tcti_intel->responseSize, 4);
-        if( rval != TSS2_RC_SUCCESS )
+    if (tcti_intel->status.protocolResponseSizeReceived != 1) {
+        /* Receive the size of the response. */
+        rval = tctiRecvBytes (tctiContext,
+                              tcti_intel->tpmSock,
+                              (unsigned char *)&tcti_intel->responseSize,
+                              4);
+        if (rval != TSS2_RC_SUCCESS) {
             goto retSocketReceiveTpmResponse;
+        }
 
-        tcti_intel->responseSize = BE_TO_HOST_32(tcti_intel->responseSize);
+        tcti_intel->responseSize = BE_TO_HOST_32 (tcti_intel->responseSize);
         tcti_intel->status.protocolResponseSizeReceived = 1;
     }
 
-    if( response_buffer == NULL )
-    {
-        // In this case, just return the size
+    if (response_buffer == NULL) {
         *response_size = tcti_intel->responseSize;
         tcti_intel->status.protocolResponseSizeReceived = 1;
         goto retSocketReceiveTpmResponse;
     }
 
-    if (*response_size < tcti_intel->responseSize)
-    {
+    if (*response_size < tcti_intel->responseSize) {
         *response_size = tcti_intel->responseSize;
         rval = TSS2_TCTI_RC_INSUFFICIENT_BUFFER;
 
-
-        // If possible, receive tag from TPM.
-        if (*response_size >= sizeof( TPM_ST ) && tcti_intel->status.tagReceived == 0)
+        /* If possible, receive tag from TPM. */
+        if (*response_size >= sizeof (TPM_ST) &&
+            tcti_intel->status.tagReceived == 0)
         {
-            if(TSS2_RC_SUCCESS != tctiRecvBytes(tctiContext, tcti_intel->tpmSock, (unsigned char *)&tcti_intel->tag, 2))
-            {
+            rval = tctiRecvBytes (tctiContext,
+                                  tcti_intel->tpmSock,
+                                  (unsigned char *)&tcti_intel->tag,
+                                  2);
+            if (rval != TSS2_RC_SUCCESS) {
                 goto retSocketReceiveTpmResponse;
-            }
-            else
-            {
+            } else {
                 tcti_intel->status.tagReceived = 1;
             }
         }
 
-        // If possible, receive response size from TPM
-        if (*response_size >= (sizeof(TPM_ST) + sizeof(TPM_RC)) && tcti_intel->status.responseSizeReceived == 0)
+        /* If possible, receive response size from TPM */
+        if (*response_size >= (sizeof (TPM_ST) + sizeof (TPM_RC)) &&
+            tcti_intel->status.responseSizeReceived == 0)
         {
-            if(TSS2_RC_SUCCESS != tctiRecvBytes(tctiContext, tcti_intel->tpmSock, (unsigned char *)&tcti_intel->responseSize, 4))
-            {
+            rval = tctiRecvBytes (tctiContext,
+                                  tcti_intel->tpmSock,
+                                  (unsigned char *)&tcti_intel->responseSize,
+                                  4);
+            if (rval != TSS2_RC_SUCCESS) {
                 goto retSocketReceiveTpmResponse;
-            }
-            else
-            {
+            } else {
                 tcti_intel->responseSize = BE_TO_HOST_32 (tcti_intel->responseSize);
                 tcti_intel->status.responseSizeReceived = 1;
             }
         }
-    }
-    else
-    {
+    } else {
         if (tcti_intel->status.debugMsgEnabled == 1 &&
             tcti_intel->responseSize > 0)
         {
 #ifdef DEBUG
-            TCTI_LOG( tctiContext, rmPrefix, "Response Received: " );
+            TCTI_LOG (tctiContext, rmPrefix, "Response Received: ");
 #endif
 #ifdef DEBUG_SOCKETS
-            TCTI_LOG(tctiContext, rmPrefix, "from socket #0x%x:\n", tcti_intel->tpmSock);
+            TCTI_LOG (tctiContext,
+                      rmPrefix,
+                      "from socket #0x%x:\n",
+                      tcti_intel->tpmSock);
 #endif
         }
 
-        if (tcti_intel->status.tagReceived == 1)
-        {
+        if (tcti_intel->status.tagReceived == 1) {
             *(TPM_ST *)response_buffer = tcti_intel->tag;
-            responseSizeDelta += sizeof(TPM_ST);
-            response_buffer += sizeof(TPM_ST);
+            responseSizeDelta += sizeof (TPM_ST);
+            response_buffer += sizeof (TPM_ST);
         }
 
-        if (tcti_intel->status.responseSizeReceived == 1)
-        {
-            *(TPM_RC *)response_buffer = HOST_TO_BE_32(tcti_intel->responseSize);
-            responseSizeDelta += sizeof(TPM_RC);
-            response_buffer += sizeof(TPM_RC);
+        if (tcti_intel->status.responseSizeReceived == 1) {
+            *(TPM_RC *)response_buffer = HOST_TO_BE_32 (tcti_intel->responseSize);
+            responseSizeDelta += sizeof (TPM_RC);
+            response_buffer += sizeof (TPM_RC);
         }
 
-        // Receive the TPM response.
-        rval = tctiRecvBytes(tctiContext, tcti_intel->tpmSock, (unsigned char *)response_buffer, tcti_intel->responseSize - responseSizeDelta );
-        if( rval != TSS2_RC_SUCCESS )
+        /* Receive the TPM response. */
+        rval = tctiRecvBytes (tctiContext,
+                              tcti_intel->tpmSock,
+                              (unsigned char *)response_buffer,
+                              tcti_intel->responseSize - responseSizeDelta);
+        if (rval != TSS2_RC_SUCCESS) {
             goto retSocketReceiveTpmResponse;
+        }
 
 #ifdef DEBUG
-        if (tcti_intel->status.debugMsgEnabled == 1)
-        {
-            DEBUG_PRINT_BUFFER(rmPrefix, response_buffer, tcti_intel->responseSize);
+        if (tcti_intel->status.debugMsgEnabled == 1) {
+            DEBUG_PRINT_BUFFER (rmPrefix,
+                                response_buffer,
+                                tcti_intel->responseSize);
         }
 #endif
 
-        // Receive the appended four bytes of 0's
-        rval = tctiRecvBytes(tctiContext, tcti_intel->tpmSock, (unsigned char *)&trash, 4);
-        if( rval != TSS2_RC_SUCCESS )
+        /* Receive the appended four bytes of 0's */
+        rval = tctiRecvBytes (tctiContext,
+                              tcti_intel->tpmSock,
+                              (unsigned char *)&trash,
+                              4);
+        if (rval != TSS2_RC_SUCCESS) {
             goto retSocketReceiveTpmResponse;
+        }
     }
 
-    if (tcti_intel->responseSize < *response_size)
-    {
+    if (tcti_intel->responseSize < *response_size) {
         *response_size = tcti_intel->responseSize;
     }
 
     tcti_intel->status.commandSent = 0;
 
-    // Turn cancel off.
-    if( rval == TSS2_RC_SUCCESS )
-    {
-        rval = (TSS2_RC)PlatformCommand( tctiContext, MS_SIM_CANCEL_OFF );
-    }
-    else
-    {
-        // Ignore return value so earlier error code is preserved.
-        PlatformCommand( tctiContext, MS_SIM_CANCEL_OFF );
+    /* Turn cancel off. */
+    if (rval == TSS2_RC_SUCCESS) {
+        rval = PlatformCommand (tctiContext, MS_SIM_CANCEL_OFF);
+    } else {
+        /* Ignore return value so earlier error code is preserved. */
+        PlatformCommand (tctiContext, MS_SIM_CANCEL_OFF);
     }
 
 retSocketReceiveTpmResponse:
-    if (rval == TSS2_RC_SUCCESS && response_buffer != NULL)
-    {
+    if (rval == TSS2_RC_SUCCESS && response_buffer != NULL) {
         tcti_intel->previousStage = TCTI_STAGE_RECEIVE_RESPONSE;
     }
 
@@ -484,22 +524,24 @@
     TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
     TSS2_RC rval;
 
-    rval = PlatformCommand( tctiContext ,MS_SIM_POWER_ON );
-    if( rval != TSS2_RC_SUCCESS ) {
-        CloseSockets( tcti_intel->otherSock, tcti_intel->tpmSock );
+    rval = PlatformCommand (tctiContext ,MS_SIM_POWER_ON);
+    if (rval != TSS2_RC_SUCCESS) {
+        CloseSockets (tcti_intel->otherSock, tcti_intel->tpmSock);
         return rval;
     }
-    rval = PlatformCommand( tctiContext, MS_SIM_NV_ON );
-    if( rval != TSS2_RC_SUCCESS )
-        CloseSockets( tcti_intel->otherSock, tcti_intel->tpmSock );
+
+    rval = PlatformCommand (tctiContext, MS_SIM_NV_ON);
+    if (rval != TSS2_RC_SUCCESS) {
+        CloseSockets (tcti_intel->otherSock, tcti_intel->tpmSock);
+    }
 
     return rval;
 }
 
 TSS2_RC InitSocketTcti (
-    TSS2_TCTI_CONTEXT *tctiContext, // OUT
-    size_t *contextSize,            // IN/OUT
-    const TCTI_SOCKET_CONF *conf,              // IN
+    TSS2_TCTI_CONTEXT *tctiContext,
+    size_t *contextSize,
+    const TCTI_SOCKET_CONF *conf,
     const uint8_t serverSockets
     )
 {
@@ -508,54 +550,48 @@
     SOCKET otherSock;
     SOCKET tpmSock;
 
-    if( tctiContext == NULL && contextSize == NULL )
-    {
+    if (tctiContext == NULL && contextSize == NULL) {
         return TSS2_TCTI_RC_BAD_VALUE;
-    }
-    else if( tctiContext == NULL )
-    {
-        *contextSize = sizeof( TSS2_TCTI_CONTEXT_INTEL );
+    } else if( tctiContext == NULL ) {
+        *contextSize = sizeof (TSS2_TCTI_CONTEXT_INTEL);
         return TSS2_RC_SUCCESS;
-    }
-    else if( conf == NULL )
-    {
+    } else if( conf == NULL ) {
         return TSS2_TCTI_RC_BAD_VALUE;
     }
-    else
-    {
-        // Init TCTI context.
-        TSS2_TCTI_MAGIC( tctiContext ) = TCTI_MAGIC;
-        TSS2_TCTI_VERSION( tctiContext ) = TCTI_VERSION;
-        TSS2_TCTI_TRANSMIT( tctiContext ) = SocketSendTpmCommand;
-        TSS2_TCTI_RECEIVE( tctiContext ) = SocketReceiveTpmResponse;
-        TSS2_TCTI_FINALIZE( tctiContext ) = SocketFinalize;
-        TSS2_TCTI_CANCEL( tctiContext ) = SocketCancel;
-        TSS2_TCTI_GET_POLL_HANDLES( tctiContext ) = SocketGetPollHandles;
-        TSS2_TCTI_SET_LOCALITY( tctiContext ) = SocketSetLocality;
-        tcti_intel->status.debugMsgEnabled = 0;
-        tcti_intel->status.locality = 3;
-        tcti_intel->status.commandSent = 0;
-        tcti_intel->status.rmDebugPrefix = 0;
-        tcti_intel->status.tagReceived = 0;
-        tcti_intel->status.responseSizeReceived = 0;
-        tcti_intel->status.protocolResponseSizeReceived = 0;
-        tcti_intel->currentTctiContext = 0;
-        tcti_intel->previousStage = TCTI_STAGE_INITIALIZE;
-        TCTI_LOG_CALLBACK( tctiContext ) = conf->logCallback;
-        TCTI_LOG_BUFFER_CALLBACK( tctiContext ) = conf->logBufferCallback;
-        TCTI_LOG_DATA( tctiContext ) = conf->logData;
 
-        rval = (TSS2_RC) InitSockets( conf->hostname, conf->port, &otherSock, &tpmSock, TCTI_LOG_CALLBACK( tctiContext ), TCTI_LOG_DATA( tctiContext) );
-        if( rval == TSS2_RC_SUCCESS )
-        {
-            tcti_intel->otherSock = otherSock;
-            tcti_intel->tpmSock = tpmSock;
-            rval = InitializeMsTpm2Simulator(tctiContext);
-        }
-        else
-        {
-            CloseSockets( otherSock, tpmSock);
-        }
+    TSS2_TCTI_MAGIC (tctiContext) = TCTI_MAGIC;
+    TSS2_TCTI_VERSION (tctiContext) = TCTI_VERSION;
+    TSS2_TCTI_TRANSMIT (tctiContext) = SocketSendTpmCommand;
+    TSS2_TCTI_RECEIVE (tctiContext) = SocketReceiveTpmResponse;
+    TSS2_TCTI_FINALIZE (tctiContext) = SocketFinalize;
+    TSS2_TCTI_CANCEL (tctiContext) = SocketCancel;
+    TSS2_TCTI_GET_POLL_HANDLES (tctiContext) = SocketGetPollHandles;
+    TSS2_TCTI_SET_LOCALITY (tctiContext) = SocketSetLocality;
+    tcti_intel->status.debugMsgEnabled = 0;
+    tcti_intel->status.locality = 3;
+    tcti_intel->status.commandSent = 0;
+    tcti_intel->status.rmDebugPrefix = 0;
+    tcti_intel->status.tagReceived = 0;
+    tcti_intel->status.responseSizeReceived = 0;
+    tcti_intel->status.protocolResponseSizeReceived = 0;
+    tcti_intel->currentTctiContext = 0;
+    tcti_intel->previousStage = TCTI_STAGE_INITIALIZE;
+    TCTI_LOG_CALLBACK (tctiContext) = conf->logCallback;
+    TCTI_LOG_BUFFER_CALLBACK (tctiContext) = conf->logBufferCallback;
+    TCTI_LOG_DATA (tctiContext) = conf->logData;
+
+    rval = (TSS2_RC) InitSockets (conf->hostname,
+                                  conf->port,
+                                  &otherSock,
+                                  &tpmSock,
+                                  TCTI_LOG_CALLBACK (tctiContext),
+                                  TCTI_LOG_DATA (tctiContext));
+    if (rval == TSS2_RC_SUCCESS) {
+        tcti_intel->otherSock = otherSock;
+        tcti_intel->tpmSock = tpmSock;
+        rval = InitializeMsTpm2Simulator (tctiContext);
+    } else {
+        CloseSockets (otherSock, tpmSock);
     }
 
     return rval;