3 # For the license, see the LICENSE file in the root directory.
5 ROOT
=${abs_top_builddir:-$(dirname "$0")/..}
6 TESTDIR
=${abs_top_testdir:-$(dirname "$0")}
9 SWTPM_CTRL_UNIX_PATH
=$TPMDIR/sock
10 PID_FILE
=$TPMDIR/swtpm.pid
11 LOG_FILE
=$TPMDIR/swtpm.log
13 source ${TESTDIR}/test_common
15 trap "cleanup" SIGTERM EXIT
20 if [ -n "$PID" ]; then
21 kill -SIGTERM $PID 2>/dev
/null
25 SWTPM_INTERFACE
=socket
+unix
26 source ${TESTDIR}/common
28 # Test 1: test the control channel on the chardev tpm
33 --tpmstate dir
=$TPMDIR \
34 --pid file=$PID_FILE \
35 --ctrl type=unixio
,path
=$SWTPM_CTRL_UNIX_PATH \
36 --log file=$LOG_FILE,level
=20 &
40 if wait_for_file
$PID_FILE 3; then
41 echo "Error: Chardev TPM did not write pidfile."
45 PID
="$(cat $PID_FILE)"
47 # Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01
48 res
="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')"
49 exp
=" 00 00 00 00 00 00 7f ff"
50 if [ "$res" != "$exp" ]; then
51 echo "Error: Unexpected response from CMD_GET_CAPABILITY:"
53 echo " expected: $exp"
57 # Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
58 res
="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')"
60 if [ "$res" != "$exp" ]; then
61 echo "Error: Unexpected response from CMD_INIT:"
63 echo " expected: $exp"
67 # Send unknown command to the TPM
68 res
="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')"
70 if [ "$res" != "$exp" ]; then
71 echo "Error: Unexpected response from sending unsupported command:"
73 echo " expected: $exp"
77 # Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a
78 res
="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')"
80 if [ "$res" != "$exp" ]; then
81 echo "Error: Unexpected response from CMD_STORE_VOLATILE:"
83 echo " expected: $exp"
87 if [ ! -r $TPMDIR/tpm-00.volatilestate
]; then
88 echo "Error: Socket TPM: Did not write volatile state file"
92 # Send stop command to the TPM: CMD_STOP = 00 00 00 0e
93 res
="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')"
95 if [ "$res" != "$exp" ]; then
96 echo "Error: Socket TPM: Unexpected response from CMD_STOP:"
98 echo " expected: $exp"
102 # Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f
103 res
="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')"
104 exp
=" 00 00 00 00 00 00 00 00"
105 if [ "$res" != "$exp" ]; then
106 echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:"
107 echo " actual : $res"
108 echo " expected: $exp"
112 # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
113 res
="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')"
115 if [ "$res" != "$exp" ]; then
116 echo "Error: Unexpected response from CMD_SHUTDOWN:"
117 echo " actual : $res"
118 echo " expected: $exp"
122 if wait_process_gone
$PID 1; then
123 echo "Error: TPM should not be running anymore."
127 if wait_file_gone
$PID_FILE 2; then
128 echo "Error: TPM should have removed PID file by now."
132 check_logfile_patterns_level_20
$LOG_FILE