Make Send Command feature more flexible
The sendOemCommand command, used to send NCSI_CMD_SEND_CMD payloads,
is hardcoded to only send one command.
Update the sendOemCommand function to allow the sub-operation to be
passed as a command line argument. This is done by prepending the
sub-operation byte to the front of the Send Cmd payload.
Doing this allows sub-operations without any payload bytes to be
called. For example "-o 0a", where the sub-operation for Send Cmd is
the 0x0a value.
Tested:
Sent 'ncsi-netlink -x 3 -p 0 -c 0 -o 50000001572100' and confirmed
the 0x50 byte worked the same way as the original hard-coded value.
Sent 'ncsi-netlink -x 3 -p 0 -c 0 -o 0a' and confirmed the 0x0a
sub-operation functioned on the submitters SUT.
Change-Id: I20f093fd8296f549fce03dc5729b8e5fedcab313
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/src/ncsi_netlink_main.cpp b/src/ncsi_netlink_main.cpp
index 5f65777..7808ef7 100644
--- a/src/ncsi_netlink_main.cpp
+++ b/src/ncsi_netlink_main.cpp
@@ -37,6 +37,7 @@
int packageInt{};
int channelInt{};
int indexInt{};
+ int operationInt{DEFAULT_VALUE};
// Parse out interface argument.
auto ifIndex = (options)["index"];
@@ -97,7 +98,11 @@
exitWithError("Payload invalid: specify two hex digits per byte.",
argv);
- // Parse the payload string (e.g. "000001572100") to byte data
+ // Parse the payload string (e.g. "50000001572100") to byte data
+ // The first two characters (i.e. "50") represent the Send Cmd Operation
+ // All remaining pairs, interpreted in hex radix, represent the command
+ // payload
+ int sendCmdSelect{};
for (unsigned int i = 1; i < payloadStr.size(); i += 2)
{
byte[0] = payloadStr[i - 1];
@@ -105,15 +110,23 @@
try
{
- payload.push_back(stoi(byte, nullptr, 16));
+ sendCmdSelect = stoi(byte, nullptr, 16);
}
catch (const std::exception& e)
{
exitWithError("Payload invalid.", argv);
}
+ if (i == 1)
+ {
+ operationInt = sendCmdSelect;
+ }
+ else
+ {
+ payload.push_back(sendCmdSelect);
+ }
}
- if (payload.empty())
+ if (operationInt == DEFAULT_VALUE)
{
exitWithError("No payload specified.", argv);
}
@@ -124,7 +137,7 @@
}
return ncsi::sendOemCommand(
- indexInt, packageInt, channelInt,
+ indexInt, packageInt, channelInt, operationInt,
std::span<const unsigned char>(payload.begin(), payload.end()));
}
else if ((options)["set"] == "true")