* [tpm2] sending commands to simulator
@ 2019-10-25 19:19 Roberts, William C
0 siblings, 0 replies; only message in thread
From: Roberts, William C @ 2019-10-25 19:19 UTC (permalink / raw)
To: tpm2
[-- Attachment #1: Type: text/plain, Size: 2207 bytes --]
Just thought this might be valuable to others. To be more thorough in a test, we needed a way to send platform commands to the simulator, ideally through bash so we don't need to carry any other C programs.
I threw this little bash function together and thought I would share it for others.
mssim_command() {
local raw="no"
local port="2322"
local ip="127.0.0.1"
while getopts "a:p:rh" opt; do
case ${opt} in
h)
echo "Send a command to the simulator"
echo "mssim_command [option] <command>"
echo "Valid commands are: "
echo " on, off, reset, phys_on, phys_off, nv_on, nv_off and failure_mode"
echo "Additionally any other string can be passed and is interpreted as is"
echo ""
echo "Valid Options are:"
echo " -p: Setting port number, defaults to 2321"
echo " -a: Setting the IP Address, defaults to 127.0.0.1"
echo " -r: For raw mode, do not interpret the string as a 4 byte u32 via xxd -p -r first"
echo " -h: Show this help message"
;;
p )
port=$OPTARG
;;
a )
ip=$OPTARG
;;
r )
raw="yes"
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
;;
esac
shift
done
local arg1="$1"
if [ -z "$arg1" ]; then
echo "Expected command as argument"
return 1
fi
local cmd;
case "$arg1" in
on)
cmd="0000001"
;;
off)
cmd="0000002"
;;
reset)
cmd="00000011"
;;
phys_on)
cmd="00000003"
;;
phys_off)
cmd="00000004"
;;
cancel_on)
cmd="00000009"
;;
cancel_off)
cmd="0000000a"
;;
nv_on)
cmd="0000000b"
;;
nv_off)
cmd="0000000c"
;;
failure_mode)
cmd="0000001e"
;;
*)
cmd="$1"
;;
esac
if [ "$raw" == "yes" ]; then
echo -n "$cmd" | nc -N "$ip" "$port"
else
echo -n "$cmd" | xxd -p -r | nc -N "$ip" "$port"
fi
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-25 19:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25 19:19 [tpm2] sending commands to simulator Roberts, William C
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.