tcti: refactor PlatformCommand function
Refactor PlatformCommand to make it complient with coding convention.
Moved the function implementation to tcti_socket.c file.
Added tcti_ prefix to the function name.
Removed platformcommand.c file.
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
diff --git a/Makefile-test.am b/Makefile-test.am
index a8fb6c1..960ba4b 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -141,8 +141,8 @@
test_unit_tcti_socket_CFLAGS = $(CMOCKA_CFLAGS) $(AM_CFLAGS) $(URIPARSER_CFLAGS)
test_unit_tcti_socket_LDADD = $(CMOCKA_LIBS) $(libmarshal) $(URIPARSER_LIBS) $(libutil)
test_unit_tcti_socket_LDFLAGS = -Wl,--wrap=connect,--wrap=read,--wrap=select,--wrap=write
-test_unit_tcti_socket_SOURCES = tcti/platformcommand.c tcti/tcti_socket.c \
- tcti/sockets.c tcti/sockets.h test/unit/tcti-socket.c
+test_unit_tcti_socket_SOURCES = tcti/tcti_socket.c tcti/sockets.c \
+ tcti/sockets.h test/unit/tcti-socket.c
test_unit_socket_CFLAGS = $(CMOCKA_CFLAGS) $(AM_CFLAGS)
test_unit_socket_LDADD = $(CMOCKA_LIBS) $(libutil) $(libmarshal)
diff --git a/Makefile.am b/Makefile.am
index a70486b..6d0f3b7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -132,8 +132,7 @@
tcti_libtcti_socket_la_LDFLAGS = -Wl,--version-script=$(srcdir)/tcti/tcti_socket.map
endif # HAVE_LD_VERSION_SCRIPT
tcti_libtcti_socket_la_LIBADD = $(libmarshal) $(URIPARSER_LIBS) $(libutil)
-tcti_libtcti_socket_la_SOURCES = tcti/platformcommand.c tcti/tcti_socket.c \
- tcti/sockets.c tcti/sockets.h
+tcti_libtcti_socket_la_SOURCES = tcti/tcti_socket.c tcti/sockets.c tcti/sockets.h
nodist_pkgconfig_DATA += lib/tcti-socket.pc
EXTRA_DIST += \
diff --git a/include/tcti/tcti_socket.h b/include/tcti/tcti_socket.h
index cdc5e21..b9d323f 100644
--- a/include/tcti/tcti_socket.h
+++ b/include/tcti/tcti_socket.h
@@ -45,15 +45,14 @@
extern "C" {
#endif
-TSS2_RC PlatformCommand(
+TSS2_RC tcti_platform_command(
TSS2_TCTI_CONTEXT *tctiContext,
UINT32 cmd);
TSS2_RC Tss2_Tcti_Socket_Init (
TSS2_TCTI_CONTEXT *tctiContext,
size_t *size,
- const char *conf
- );
+ const char *conf);
#ifdef __cplusplus
}
diff --git a/tcti/platformcommand.c b/tcti/platformcommand.c
deleted file mode 100644
index bc4ba0e..0000000
--- a/tcti/platformcommand.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2015 - 2018 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 <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "sapi/tpm20.h"
-#include "tcti/tcti_socket.h"
-#include "sysapi_util.h"
-#include "sapi/tss2_tcti.h"
-#include "sockets.h"
-#include "tcti.h"
-#define LOGMODULE tcti
-#include "log/log.h"
-
-TSS2_RC PlatformCommand(
- TSS2_TCTI_CONTEXT *tctiContext,
- UINT32 cmd)
-{
- TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
- uint8_t buf [sizeof (cmd)] = { 0 };
- UINT32 rsp = 0;
- TSS2_RC rc = TSS2_RC_SUCCESS;
- int ret;
- ssize_t read_ret;
-
- rc = Tss2_MU_UINT32_Marshal (cmd, buf, sizeof (cmd), NULL);
- if (rc != TSS2_RC_SUCCESS) {
- LOG_ERROR ("Failed to marshal platform command %" PRIu32 ", rc: 0x%"
- PRIx32, cmd, rc);
- return rc;
- }
-
- LOGBLOB_DEBUG(buf, sizeof (cmd), "Sending %zu bytes to socket %" PRIu32
- ":", sizeof (cmd), tcti_intel->otherSock);
- ret = write_all (tcti_intel->otherSock, buf, sizeof (cmd));
- if (ret < sizeof (cmd)) {
- LOG_ERROR("Failed to send platform command %d with error: %d",
- cmd, ret);
- return TSS2_TCTI_RC_IO_ERROR;
- }
-
- read_ret = read (tcti_intel->otherSock, buf, sizeof (buf));
- if (read_ret < sizeof (buf)) {
- LOG_ERROR("Failed to get response to platform command, errno %d: %s",
- errno, strerror (errno));
- return TSS2_TCTI_RC_IO_ERROR;
- }
-
- LOGBLOB_DEBUG (buf, sizeof (buf), "Received %zu bytes from socket 0x%"
- PRIx32 ":", read_ret, tcti_intel->otherSock);
- rc = Tss2_MU_UINT32_Unmarshal (buf, sizeof (rsp), NULL, &rsp);
- if (rc != TSS2_RC_SUCCESS) {
- LOG_ERROR ("Failed to unmarshal response to platform command. rc: 0x%"
- PRIx32, rc);
- return rc;
- }
- if (rsp != 0) {
- LOG_INFO ("Platform command failed with error: %" PRIu32, rsp);
- return TSS2_TCTI_RC_IO_ERROR;
- }
- return rc;
-}
diff --git a/tcti/tcti_socket.c b/tcti/tcti_socket.c
index a8fce57..18241ac 100644
--- a/tcti/tcti_socket.c
+++ b/tcti/tcti_socket.c
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <sys/time.h>
#include <inttypes.h>
+#include <unistd.h>
#include <uriparser/Uri.h>
@@ -44,6 +45,55 @@
#define TCTI_SOCKET_DEFAULT_CONF "tcp://127.0.0.1:2321"
#define TCTI_SOCKET_DEFAULT_PORT 2321
+TSS2_RC tcti_platform_command (
+ TSS2_TCTI_CONTEXT *tctiContext,
+ UINT32 cmd)
+{
+ TSS2_TCTI_CONTEXT_INTEL *tcti_intel = tcti_context_intel_cast (tctiContext);
+ uint8_t buf [sizeof (cmd)] = { 0 };
+ UINT32 rsp = 0;
+ TSS2_RC rc = TSS2_RC_SUCCESS;
+ int ret;
+ ssize_t read_ret;
+
+ rc = Tss2_MU_UINT32_Marshal (cmd, buf, sizeof (cmd), NULL);
+ if (rc != TSS2_RC_SUCCESS) {
+ LOG_ERROR ("Failed to marshal platform command %" PRIu32 ", rc: 0x%"
+ PRIx32, cmd, rc);
+ return rc;
+ }
+
+ LOGBLOB_DEBUG(buf, sizeof (cmd), "Sending %zu bytes to socket %" PRIu32
+ ":", sizeof (cmd), tcti_intel->otherSock);
+ ret = write_all (tcti_intel->otherSock, buf, sizeof (cmd));
+ if (ret < sizeof (cmd)) {
+ LOG_ERROR("Failed to send platform command %d with error: %d",
+ cmd, ret);
+ return TSS2_TCTI_RC_IO_ERROR;
+ }
+
+ read_ret = read (tcti_intel->otherSock, buf, sizeof (buf));
+ if (read_ret < sizeof (buf)) {
+ LOG_ERROR("Failed to get response to platform command, errno %d: %s",
+ errno, strerror (errno));
+ return TSS2_TCTI_RC_IO_ERROR;
+ }
+
+ LOGBLOB_DEBUG (buf, sizeof (buf), "Received %zu bytes from socket 0x%"
+ PRIx32 ":", read_ret, tcti_intel->otherSock);
+ rc = Tss2_MU_UINT32_Unmarshal (buf, sizeof (rsp), NULL, &rsp);
+ if (rc != TSS2_RC_SUCCESS) {
+ LOG_ERROR ("Failed to unmarshal response to platform command. rc: 0x%"
+ PRIx32, rc);
+ return rc;
+ }
+ if (rsp != 0) {
+ LOG_INFO ("Platform command failed with error: %" PRIu32, rsp);
+ return TSS2_TCTI_RC_IO_ERROR;
+ }
+ return rc;
+}
+
TSS2_RC
send_sim_session_end (
SOCKET sock)
@@ -156,7 +206,7 @@
return TSS2_TCTI_RC_BAD_SEQUENCE;
}
- rc = PlatformCommand (tctiContext, MS_SIM_CANCEL_ON);
+ rc = tcti_platform_command (tctiContext, MS_SIM_CANCEL_ON);
if (rc != TSS2_RC_SUCCESS) {
return rc;
}
@@ -292,7 +342,7 @@
}
if (tcti_intel->cancel) {
- rc = PlatformCommand (tctiContext, MS_SIM_CANCEL_OFF);
+ rc = tcti_platform_command (tctiContext, MS_SIM_CANCEL_OFF);
tcti_intel->cancel = 0;
}
/*
@@ -309,7 +359,7 @@
/**
* This function sends the Microsoft simulator the MS_SIM_POWER_ON and
- * MS_SIM_NV_ON commands using the PlatformCommand mechanism. Without
+ * MS_SIM_NV_ON commands using the platform command mechanism. Without
* these the simulator will respond with zero sized buffer which causes
* the TSS to freak out. Sending this command more than once is harmelss
* so it's advisable to call this function as part of the TCTI context
@@ -327,13 +377,13 @@
LOG_TRACE ("Initializing TCTI context 0x%" PRIxPTR,
(uintptr_t)tctiContext);
- rc = PlatformCommand (tctiContext ,MS_SIM_POWER_ON);
+ rc = tcti_platform_command (tctiContext, MS_SIM_POWER_ON);
if (rc != TSS2_RC_SUCCESS) {
LOG_WARNING ("Failed to send MS_SIM_POWER_ON platform command.");
return rc;
}
- rc = PlatformCommand (tctiContext, MS_SIM_NV_ON);
+ rc = tcti_platform_command (tctiContext, MS_SIM_NV_ON);
if (rc != TSS2_RC_SUCCESS) {
LOG_WARNING ("Failed to send MS_SIM_NV_ON platform command.");
}
diff --git a/tcti/tcti_socket.map b/tcti/tcti_socket.map
index 1473127..6874b09 100644
--- a/tcti/tcti_socket.map
+++ b/tcti/tcti_socket.map
@@ -1,6 +1,6 @@
{
global:
- PlatformCommand;
+ tcti_platform_command;
Tss2_Tcti_Info;
Tss2_Tcti_Socket_Init;
local:
diff --git a/test/integration/command-cancel.int.c b/test/integration/command-cancel.int.c
index 563c906..a794d78 100644
--- a/test/integration/command-cancel.int.c
+++ b/test/integration/command-cancel.int.c
@@ -92,12 +92,12 @@
}
LOG_DEBUG("FlushContext SUCCESS!");
- rc = PlatformCommand(tcti_context, MS_SIM_CANCEL_ON);
+ rc = tcti_platform_command(tcti_context, MS_SIM_CANCEL_ON);
if (rc != TPM2_RC_SUCCESS) {
- LOG_ERROR("PlatformCommand FAILED! Response Code : 0x%x", rc);
+ LOG_ERROR("tcti_platform_command FAILED! Response Code : 0x%x", rc);
exit(1);
}
- LOG_DEBUG("PlatformCommand CANCEL_ON SUCCESS!");
+ LOG_DEBUG("tcti_platform_command CANCEL_ON SUCCESS!");
rc = Tss2_Sys_CreatePrimary (sapi_context,
TPM2_RH_OWNER,
@@ -120,12 +120,12 @@
}
LOG_DEBUG("create_primary returned rc cancelled!");
- rc = PlatformCommand(tcti_context, MS_SIM_CANCEL_OFF);
+ rc = tcti_platform_command(tcti_context, MS_SIM_CANCEL_OFF);
if (rc != TPM2_RC_SUCCESS) {
LOG_ERROR("FlushContext FAILED! Response Code : 0x%x", rc);
exit(1);
}
- LOG_DEBUG("PlatformCommand CANCEL_OFF SUCCESS!");
+ LOG_DEBUG("tcti_platform_command CANCEL_OFF SUCCESS!");
rc = create_primary_rsa_2048_aes_128_cfb(sapi_context, &handle);
if (rc != TPM2_RC_SUCCESS) {
diff --git a/test/tpmclient/tpmclient.int.c b/test/tpmclient/tpmclient.int.c
index 9c1a85b..a8bade3 100644
--- a/test/tpmclient/tpmclient.int.c
+++ b/test/tpmclient/tpmclient.int.c
@@ -162,7 +162,7 @@
if( resMgrTctiContext != 0 )
{
- PlatformCommand( resMgrTctiContext, MS_SIM_POWER_OFF );
+ tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_OFF );
tcti_teardown (resMgrTctiContext);
resMgrTctiContext = NULL;
}
@@ -225,10 +225,10 @@
{
TSS2_RC rval = TSS2_RC_SUCCESS;
- rval = (TSS2_RC)PlatformCommand( resMgrTctiContext, MS_SIM_POWER_OFF );
+ rval = (TSS2_RC)tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_OFF );
if( rval == TSS2_RC_SUCCESS )
{
- rval = (TSS2_RC)PlatformCommand( resMgrTctiContext, MS_SIM_POWER_ON );
+ rval = (TSS2_RC)tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_ON );
}
return rval;
}
@@ -298,9 +298,9 @@
// Cycle power using simulator interface.
- rval = PlatformCommand( resMgrTctiContext, MS_SIM_POWER_OFF );
+ rval = tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_OFF );
CheckPassed( rval );
- rval = PlatformCommand( resMgrTctiContext, MS_SIM_POWER_ON );
+ rval = tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_ON );
CheckPassed( rval );
@@ -315,9 +315,9 @@
CheckPassed( rval );
// Cycle power using simulator interface.
- rval = PlatformCommand( resMgrTctiContext, MS_SIM_POWER_OFF );
+ rval = tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_OFF );
CheckPassed( rval );
- rval = PlatformCommand( resMgrTctiContext, MS_SIM_POWER_ON );
+ rval = tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_ON );
CheckPassed( rval );
@@ -2847,7 +2847,7 @@
CheckPassed( rval );
- PlatformCommand( resMgrTctiContext, MS_SIM_POWER_OFF );
+ tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_OFF );
}
@@ -3898,7 +3898,7 @@
loadedSha1KeyAuth.buffer[0] = 0x00;
loadedSha1KeyAuth.buffer[1] = 0xff;
- rval = PlatformCommand( resMgrTctiContext, MS_SIM_POWER_OFF );
+ rval = tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_OFF );
CheckPassed( rval );
InitEntities();
@@ -3952,6 +3952,6 @@
rval = Tss2_Sys_FlushContext( sysContext, loadedSha1KeyHandle );
CheckPassed( rval );
- PlatformCommand( resMgrTctiContext, MS_SIM_POWER_OFF );
+ tcti_platform_command( resMgrTctiContext, MS_SIM_POWER_OFF );
return 0;
}
diff --git a/test/unit/tcti-socket.c b/test/unit/tcti-socket.c
index ea23af4..ce15769 100644
--- a/test/unit/tcti-socket.c
+++ b/test/unit/tcti-socket.c
@@ -193,7 +193,7 @@
will_return (__wrap_connect, 0);
will_return (__wrap_connect, 0);
/*
- * two 'PlatformCommands are sent on initialization, 4 bytes sent for
+ * two 'platform commands are sent on initialization, 4 bytes sent for
* each, 4 byte response received (all 0's) for each.
*/
will_return (__wrap_write, 4);