ncsi: return interface info from Interface::getInfo()
Rather than expecting the ncsi_util callback to print the interface
info, return the interface info, and print that.
This allows for a specific output formatting function in
ncsi_netlink_main.c, rather than printing directly from the libnl
callback. We reformat for a more structured display of the
package/channel layouts.
We use std::optional for the return value here; it would be nice to use
std::expected instead, and get a full error code, but that's not quite
working with clang-18 at present. Even if we have an error code though,
we're just going to return EXIT_FAILURE anyway.
Tested: Invoked on a simlated dual-channel NCSI package:
# ncsi-netlink -x 2 --info
<7> Get Info , PACKAGE : 0xffffffffffffffff, INTERFACE: 0x7e8bf9bc
<7> Package id : 0
<7> package is forced
<7> Channel id : 0
<7> version 1.2 (p0c00)
<7> link state 0x40022f
<7> Channel id : 1
<7> version 1.2 (p0c01)
<7> link state 0x40022f
Change-Id: Idb62cc6695da67f4415ed9b0e7950c506018d630
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
diff --git a/src/ncsi_util.hpp b/src/ncsi_util.hpp
index aa2051c..452c916 100644
--- a/src/ncsi_util.hpp
+++ b/src/ncsi_util.hpp
@@ -1,7 +1,11 @@
#pragma once
+#include <stdint.h>
+
+#include <optional>
#include <span>
#include <string>
+#include <vector>
namespace phosphor
{
@@ -13,6 +17,29 @@
constexpr auto DEFAULT_VALUE = -1;
constexpr auto NONE = 0;
+struct ChannelInfo
+{
+ uint32_t id;
+ bool active;
+ bool forced;
+ uint32_t version_major, version_minor;
+ std::string version;
+ uint32_t link_state;
+ std::vector<uint16_t> vlan_ids;
+};
+
+struct PackageInfo
+{
+ uint32_t id;
+ bool forced;
+ std::vector<ChannelInfo> channels;
+};
+
+struct InterfaceInfo
+{
+ std::vector<PackageInfo> packages;
+};
+
struct Interface
{
/* @brief This function will ask underlying NCSI driver
@@ -50,11 +77,13 @@
/* @brief This function is used to dump all the info
* of the package and the channels underlying
- * the package.
- * @param[in] package - NCSI Package.
- * @returns 0 on success and negative value for failure.
+ * the package, or all packages if DEFAULT_VALUE
+ * is passed
+ * @param[in] package - NCSI Package
+ * @returns an InterfaceInfo with package data the specified pacakge,
+ * or all packages if none is specified.
*/
- int getInfo(int package);
+ std::optional<InterfaceInfo> getInfo(int package);
/* @brief This function assigns a mask controlling responses to AEN from a
* package.