ipmi: pull the netfn and command into parameters
Pull the netfn and cmd into parameters instead of hard-coding them for
blob commands.
Tested: Only ran unit-tests.
Change-Id: I1a73de32e14cc78ece94a26f6c447824af88c984
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/src/ipmiblob/blob_handler.cpp b/src/ipmiblob/blob_handler.cpp
index 039b7e0..6adbe89 100644
--- a/src/ipmiblob/blob_handler.cpp
+++ b/src/ipmiblob/blob_handler.cpp
@@ -67,7 +67,7 @@
try
{
- reply = ipmi->sendPacket(request);
+ reply = ipmi->sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, request);
}
catch (const IpmiException& e)
{
diff --git a/src/ipmiblob/blob_handler.hpp b/src/ipmiblob/blob_handler.hpp
index 68708d8..c57b11d 100644
--- a/src/ipmiblob/blob_handler.hpp
+++ b/src/ipmiblob/blob_handler.hpp
@@ -130,4 +130,7 @@
std::unique_ptr<IpmiInterface> ipmi;
};
+constexpr int ipmiOEMNetFn = 46;
+constexpr int ipmiOEMBlobCmd = 128;
+
} // namespace ipmiblob
diff --git a/src/ipmiblob/ipmi_handler.cpp b/src/ipmiblob/ipmi_handler.cpp
index 568b86c..682fe45 100644
--- a/src/ipmiblob/ipmi_handler.cpp
+++ b/src/ipmiblob/ipmi_handler.cpp
@@ -65,17 +65,15 @@
}
std::vector<std::uint8_t>
- IpmiHandler::sendPacket(std::vector<std::uint8_t>& data)
+ IpmiHandler::sendPacket(std::uint8_t netfn, std::uint8_t cmd,
+ std::vector<std::uint8_t>& data)
{
if (fd < 0)
{
open();
}
- constexpr int ipmiOEMNetFn = 46;
constexpr int ipmiOEMLun = 0;
- /* /openbmc/phosphor-host-ipmid/blob/master/host-ipmid/oemopenbmc.hpp */
- constexpr int ipmiOEMBlobCmd = 128;
constexpr int fifteenMs = 15 * 1000;
constexpr int ipmiReadTimeout = fifteenMs;
constexpr int ipmiResponseBufferLen = IPMI_MAX_MSG_LENGTH;
@@ -98,8 +96,8 @@
request.msgid = sequence++;
request.msg.data = reinterpret_cast<unsigned char*>(data.data());
request.msg.data_len = data.size();
- request.msg.netfn = ipmiOEMNetFn;
- request.msg.cmd = ipmiOEMBlobCmd;
+ request.msg.netfn = netfn;
+ request.msg.cmd = cmd;
struct ipmi_recv reply;
reply.addr = reinterpret_cast<unsigned char*>(&systemAddress);
diff --git a/src/ipmiblob/ipmi_handler.hpp b/src/ipmiblob/ipmi_handler.hpp
index 34177ae..21d0fc7 100644
--- a/src/ipmiblob/ipmi_handler.hpp
+++ b/src/ipmiblob/ipmi_handler.hpp
@@ -37,7 +37,8 @@
* @throws IpmiException on failure.
*/
std::vector<std::uint8_t>
- sendPacket(std::vector<std::uint8_t>& data) override;
+ sendPacket(std::uint8_t netfn, std::uint8_t cmd,
+ std::vector<std::uint8_t>& data) override;
private:
const internal::Sys* sys;
diff --git a/src/ipmiblob/ipmi_interface.hpp b/src/ipmiblob/ipmi_interface.hpp
index bf7b448..4a62c2c 100644
--- a/src/ipmiblob/ipmi_interface.hpp
+++ b/src/ipmiblob/ipmi_interface.hpp
@@ -14,12 +14,15 @@
/**
* Send an IPMI packet to the BMC.
*
+ * @param[in] netfn - the netfn for the IPMI packet.
+ * @param[in] cmd - the command.
* @param[in] data - a vector of the IPMI packet contents.
* @return the bytes returned.
* @throws IpmiException on failure.
*/
virtual std::vector<std::uint8_t>
- sendPacket(std::vector<std::uint8_t>& data) = 0;
+ sendPacket(std::uint8_t netfn, std::uint8_t cmd,
+ std::vector<std::uint8_t>& data) = 0;
};
} // namespace ipmiblob
diff --git a/src/ipmiblob/test/ipmi_interface_mock.hpp b/src/ipmiblob/test/ipmi_interface_mock.hpp
index c8324af..5f5514c 100644
--- a/src/ipmiblob/test/ipmi_interface_mock.hpp
+++ b/src/ipmiblob/test/ipmi_interface_mock.hpp
@@ -11,8 +11,9 @@
{
public:
virtual ~IpmiInterfaceMock() = default;
- MOCK_METHOD1(sendPacket,
- std::vector<std::uint8_t>(std::vector<std::uint8_t>&));
+ MOCK_METHOD3(sendPacket,
+ std::vector<std::uint8_t>(std::uint8_t, std::uint8_t,
+ std::vector<std::uint8_t>&));
};
} // namespace ipmiblob
diff --git a/test/tools_blob_unittest.cpp b/test/tools_blob_unittest.cpp
index 3afb61b..3fe7974 100644
--- a/test/tools_blob_unittest.cpp
+++ b/test/tools_blob_unittest.cpp
@@ -16,6 +16,7 @@
return (crcIntf) ? crcIntf->generateCrc(data) : 0x00;
}
+using ::testing::ContainerEq;
using ::testing::Eq;
using ::testing::Return;
@@ -52,9 +53,12 @@
0x01, 0x00, 0x00, 0x00};
std::vector<std::uint8_t> bytes = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
EXPECT_EQ(1, blob.getBlobCount());
}
@@ -79,10 +83,14 @@
std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd', 0x00};
std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str());
}
@@ -105,9 +113,12 @@
std::vector<std::uint8_t> resp = {};
std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
EXPECT_STREQ("", blob.enumerateBlob(1).c_str());
}
@@ -128,9 +139,12 @@
0x01, 0x00, 0x00, 0x00};
std::vector<std::uint8_t> bytes1 = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes1))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes1)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request1))).WillOnce(Return(resp1));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request1)))
+ .WillOnce(Return(resp1));
std::vector<std::uint8_t> request2 = {
0xcf, 0xc2,
@@ -145,10 +159,14 @@
std::vector<std::uint8_t> reqCrc = {0x00, 0x00, 0x00, 0x00};
std::vector<std::uint8_t> bytes2 = {'a', 'b', 'c', 'd', 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes2))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes2)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request2))).WillOnce(Return(resp2));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request2)))
+ .WillOnce(Return(resp2));
/* A std::string is not nul-terminated by default. */
std::vector<std::string> expectedList = {std::string{"abcd"}};
@@ -179,10 +197,14 @@
std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x02, 0x34, 0x45};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
auto meta = blob.getStat("abcd");
EXPECT_EQ(meta.blob_state, 0xffff);
@@ -215,10 +237,14 @@
std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
auto meta = blob.getStat("abcd");
EXPECT_EQ(meta.blob_state, 0xffff);
@@ -249,10 +275,14 @@
std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
auto meta = blob.getStat(0x0001);
EXPECT_EQ(meta.blob_state, 0xffff);
@@ -282,10 +312,14 @@
std::vector<std::uint8_t> reqCrc = {0x02, 0x04, 'a', 'b', 'c', 'd', 0x00};
std::vector<std::uint8_t> respCrc = {0xfe, 0xed};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
const int writeBit = (1 << 1);
const int lpcBit = (1 << 10);
@@ -309,9 +343,12 @@
0x01, 0x00};
std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
blob.closeBlob(0x0001);
}
@@ -333,9 +370,12 @@
std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
blob.commit(0x0001, {});
}
@@ -362,9 +402,12 @@
std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 'a', 'b', 'c', 'd'};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
blob.writeBytes(0x0001, 0, bytes);
}
@@ -394,10 +437,14 @@
0x00, 0x04, 0x00, 0x00, 0x00};
std::vector<std::uint8_t> respCrc = {'a', 'b', 'c', 'd'};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
+ .WillOnce(Return(0x00));
+ EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
+ .WillOnce(Return(0x00));
- EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+ EXPECT_CALL(*ipmiMock,
+ sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
+ .WillOnce(Return(resp));
EXPECT_EQ(blob.readBytes(0x0001, 0, 4), expectedBytes);
}