blob: 70e934b802a38a8c8e809a21a8f8c76998278619 [file] [log] [blame]
Patrick Venture189d44e2018-07-09 12:30:59 -07001#include "ncsi_util.hpp"
2
Eddie Jamesfa1f5c02020-09-17 15:12:46 -05003#include <fmt/format.h>
Ratan Guptabbe45792018-03-23 00:22:55 +05304#include <linux/ncsi.h>
Ratan Guptabbe45792018-03-23 00:22:55 +05305#include <netlink/genl/ctrl.h>
Gunnar Mills57d9c502018-09-14 14:42:34 -05006#include <netlink/genl/genl.h>
7#include <netlink/netlink.h>
Ratan Guptabbe45792018-03-23 00:22:55 +05308
Patrick Williams89d734b2023-05-10 07:50:25 -05009#include <phosphor-logging/lg2.hpp>
10
Eddie Jamesfa1f5c02020-09-17 15:12:46 -050011#include <iomanip>
Manojkiran Edae5a867a2020-06-01 18:08:30 +053012#include <iostream>
Jiaqing Zhao7c44a782022-04-10 15:30:04 +080013#include <vector>
Ratan Guptabbe45792018-03-23 00:22:55 +053014
15namespace phosphor
16{
17namespace network
18{
19namespace ncsi
20{
21
Gunnar Mills57d9c502018-09-14 14:42:34 -050022using CallBack = int (*)(struct nl_msg* msg, void* arg);
Ratan Guptaaac603e2018-03-23 00:25:54 +053023
24namespace internal
25{
Ratan Guptabbe45792018-03-23 00:22:55 +053026
Eddie Jamesfa1f5c02020-09-17 15:12:46 -050027struct NCSIPacketHeader
28{
29 uint8_t MCID;
30 uint8_t revision;
31 uint8_t reserved;
32 uint8_t id;
33 uint8_t type;
34 uint8_t channel;
35 uint16_t length;
36 uint32_t rsvd[2];
37};
38
39class Command
40{
41 public:
42 Command() = delete;
43 ~Command() = default;
44 Command(const Command&) = delete;
45 Command& operator=(const Command&) = delete;
46 Command(Command&&) = default;
47 Command& operator=(Command&&) = default;
48 Command(
49 int c, int nc = DEFAULT_VALUE,
50 std::span<const unsigned char> p = std::span<const unsigned char>()) :
51 cmd(c),
52 ncsi_cmd(nc), payload(p)
Patrick Williams89d734b2023-05-10 07:50:25 -050053 {}
Eddie Jamesfa1f5c02020-09-17 15:12:46 -050054
55 int cmd;
56 int ncsi_cmd;
57 std::span<const unsigned char> payload;
58};
59
Ratan Guptabbe45792018-03-23 00:22:55 +053060using nlMsgPtr = std::unique_ptr<nl_msg, decltype(&::nlmsg_free)>;
61using nlSocketPtr = std::unique_ptr<nl_sock, decltype(&::nl_socket_free)>;
62
Eddie Jamesfa1f5c02020-09-17 15:12:46 -050063CallBack infoCallBack = [](struct nl_msg* msg, void* arg) {
Ratan Guptaaac603e2018-03-23 00:25:54 +053064 using namespace phosphor::network::ncsi;
65 auto nlh = nlmsg_hdr(msg);
66
Gunnar Mills57d9c502018-09-14 14:42:34 -050067 struct nlattr* tb[NCSI_ATTR_MAX + 1] = {nullptr};
68 struct nla_policy ncsiPolicy[NCSI_ATTR_MAX + 1] = {
William A. Kennington III05368f12021-05-13 18:40:47 -070069 {NLA_UNSPEC, 0, 0}, {NLA_U32, 0, 0}, {NLA_NESTED, 0, 0},
70 {NLA_U32, 0, 0}, {NLA_U32, 0, 0},
Ratan Guptaaac603e2018-03-23 00:25:54 +053071 };
72
Gunnar Mills57d9c502018-09-14 14:42:34 -050073 struct nlattr* packagetb[NCSI_PKG_ATTR_MAX + 1] = {nullptr};
74 struct nla_policy packagePolicy[NCSI_PKG_ATTR_MAX + 1] = {
William A. Kennington III05368f12021-05-13 18:40:47 -070075 {NLA_UNSPEC, 0, 0}, {NLA_NESTED, 0, 0}, {NLA_U32, 0, 0},
76 {NLA_FLAG, 0, 0}, {NLA_NESTED, 0, 0},
Ratan Guptaaac603e2018-03-23 00:25:54 +053077 };
78
Gunnar Mills57d9c502018-09-14 14:42:34 -050079 struct nlattr* channeltb[NCSI_CHANNEL_ATTR_MAX + 1] = {nullptr};
80 struct nla_policy channelPolicy[NCSI_CHANNEL_ATTR_MAX + 1] = {
William A. Kennington III05368f12021-05-13 18:40:47 -070081 {NLA_UNSPEC, 0, 0}, {NLA_NESTED, 0, 0}, {NLA_U32, 0, 0},
82 {NLA_FLAG, 0, 0}, {NLA_NESTED, 0, 0}, {NLA_UNSPEC, 0, 0},
Ratan Guptaaac603e2018-03-23 00:25:54 +053083 };
84
Eddie Jamesfa1f5c02020-09-17 15:12:46 -050085 *(int*)arg = 0;
86
Ratan Guptaaac603e2018-03-23 00:25:54 +053087 auto ret = genlmsg_parse(nlh, 0, tb, NCSI_ATTR_MAX, ncsiPolicy);
88 if (!tb[NCSI_ATTR_PACKAGE_LIST])
89 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -070090 lg2::error("No Packages");
Ratan Guptaaac603e2018-03-23 00:25:54 +053091 return -1;
92 }
93
94 auto attrTgt = static_cast<nlattr*>(nla_data(tb[NCSI_ATTR_PACKAGE_LIST]));
95 if (!attrTgt)
96 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -070097 lg2::error("Package list attribute is null");
Ratan Guptaaac603e2018-03-23 00:25:54 +053098 return -1;
99 }
100
101 auto rem = nla_len(tb[NCSI_ATTR_PACKAGE_LIST]);
102 nla_for_each_nested(attrTgt, tb[NCSI_ATTR_PACKAGE_LIST], rem)
103 {
104 ret = nla_parse_nested(packagetb, NCSI_PKG_ATTR_MAX, attrTgt,
105 packagePolicy);
106 if (ret < 0)
107 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700108 lg2::error("Failed to parse package nested");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530109 return -1;
110 }
111
112 if (packagetb[NCSI_PKG_ATTR_ID])
113 {
114 auto attrID = nla_get_u32(packagetb[NCSI_PKG_ATTR_ID]);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700115 lg2::debug("Package has id : {ATTR_ID}", "ATTR_ID", lg2::hex,
116 attrID);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530117 }
118 else
119 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700120 lg2::debug("Package with no id");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530121 }
122
123 if (packagetb[NCSI_PKG_ATTR_FORCED])
124 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700125 lg2::debug("This package is forced");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530126 }
127
128 auto channelListTarget = static_cast<nlattr*>(
Gunnar Mills57d9c502018-09-14 14:42:34 -0500129 nla_data(packagetb[NCSI_PKG_ATTR_CHANNEL_LIST]));
Ratan Guptaaac603e2018-03-23 00:25:54 +0530130
131 auto channelrem = nla_len(packagetb[NCSI_PKG_ATTR_CHANNEL_LIST]);
132 nla_for_each_nested(channelListTarget,
133 packagetb[NCSI_PKG_ATTR_CHANNEL_LIST], channelrem)
134 {
135 ret = nla_parse_nested(channeltb, NCSI_CHANNEL_ATTR_MAX,
136 channelListTarget, channelPolicy);
137 if (ret < 0)
138 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700139 lg2::error("Failed to parse channel nested");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530140 return -1;
141 }
142
143 if (channeltb[NCSI_CHANNEL_ATTR_ID])
144 {
145 auto channel = nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_ID]);
146 if (channeltb[NCSI_CHANNEL_ATTR_ACTIVE])
147 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700148 lg2::debug("Channel Active : {CHANNEL}", "CHANNEL",
149 lg2::hex, channel);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530150 }
151 else
152 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700153 lg2::debug("Channel Not Active : {CHANNEL}", "CHANNEL",
154 lg2::hex, channel);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530155 }
156
157 if (channeltb[NCSI_CHANNEL_ATTR_FORCED])
158 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700159 lg2::debug("Channel is forced");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530160 }
Ratan Guptaaac603e2018-03-23 00:25:54 +0530161 }
162 else
163 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700164 lg2::debug("Channel with no ID");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530165 }
Ratan Guptaed5d7ff2018-03-23 00:27:52 +0530166
Ratan Guptaaac603e2018-03-23 00:25:54 +0530167 if (channeltb[NCSI_CHANNEL_ATTR_VERSION_MAJOR])
168 {
Gunnar Mills57d9c502018-09-14 14:42:34 -0500169 auto major =
170 nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_VERSION_MAJOR]);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700171 lg2::debug("Channel Major Version : {CHANNEL_MAJOR_VERSION}",
172 "CHANNEL_MAJOR_VERSION", lg2::hex, major);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530173 }
174 if (channeltb[NCSI_CHANNEL_ATTR_VERSION_MINOR])
175 {
Gunnar Mills57d9c502018-09-14 14:42:34 -0500176 auto minor =
177 nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_VERSION_MINOR]);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700178 lg2::debug("Channel Minor Version : {CHANNEL_MINOR_VERSION}",
179 "CHANNEL_MINOR_VERSION", lg2::hex, minor);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530180 }
181 if (channeltb[NCSI_CHANNEL_ATTR_VERSION_STR])
182 {
Gunnar Mills57d9c502018-09-14 14:42:34 -0500183 auto str =
184 nla_get_string(channeltb[NCSI_CHANNEL_ATTR_VERSION_STR]);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700185 lg2::debug("Channel Version Str : {CHANNEL_VERSION_STR}",
186 "CHANNEL_VERSION_STR", str);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530187 }
188 if (channeltb[NCSI_CHANNEL_ATTR_LINK_STATE])
189 {
Gunnar Mills57d9c502018-09-14 14:42:34 -0500190 auto link =
191 nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_LINK_STATE]);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700192 lg2::debug("Channel Link State : {LINK_STATE}", "LINK_STATE",
193 lg2::hex, link);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530194 }
195 if (channeltb[NCSI_CHANNEL_ATTR_VLAN_LIST])
196 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700197 lg2::debug("Active Vlan ids");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530198 auto vids = channeltb[NCSI_CHANNEL_ATTR_VLAN_LIST];
199 auto vid = static_cast<nlattr*>(nla_data(vids));
200 auto len = nla_len(vids);
201 while (nla_ok(vid, len))
202 {
203 auto id = nla_get_u16(vid);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700204 lg2::debug("VID : {VLAN_ID}", "VLAN_ID", id);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530205 vid = nla_next(vid, &len);
206 }
207 }
Ratan Guptaaac603e2018-03-23 00:25:54 +0530208 }
Ratan Guptaaac603e2018-03-23 00:25:54 +0530209 }
210 return (int)NL_SKIP;
211};
212
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500213CallBack sendCallBack = [](struct nl_msg* msg, void* arg) {
214 using namespace phosphor::network::ncsi;
215 auto nlh = nlmsg_hdr(msg);
216 struct nlattr* tb[NCSI_ATTR_MAX + 1] = {nullptr};
217 static struct nla_policy ncsiPolicy[NCSI_ATTR_MAX + 1] = {
218 {NLA_UNSPEC, 0, 0}, {NLA_U32, 0, 0}, {NLA_NESTED, 0, 0},
219 {NLA_U32, 0, 0}, {NLA_U32, 0, 0}, {NLA_BINARY, 0, 0},
220 {NLA_FLAG, 0, 0}, {NLA_U32, 0, 0}, {NLA_U32, 0, 0},
221 };
222
223 *(int*)arg = 0;
224
225 auto ret = genlmsg_parse(nlh, 0, tb, NCSI_ATTR_MAX, ncsiPolicy);
226 if (ret)
227 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700228 lg2::error("Failed to parse package");
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500229 return ret;
230 }
231
Jian Zhang442d9e52022-10-20 22:11:14 +0800232 if (tb[NCSI_ATTR_DATA] == nullptr)
233 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700234 lg2::error("Response: No data");
Jian Zhang442d9e52022-10-20 22:11:14 +0800235 return -1;
236 }
237
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500238 auto data_len = nla_len(tb[NCSI_ATTR_DATA]) - sizeof(NCSIPacketHeader);
Patrick Williams89d734b2023-05-10 07:50:25 -0500239 unsigned char* data = (unsigned char*)nla_data(tb[NCSI_ATTR_DATA]) +
240 sizeof(NCSIPacketHeader);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500241 auto s = std::span<const unsigned char>(data, data_len);
242
243 // Dump the response to stdout. Enhancement: option to save response data
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700244 lg2::debug("Response : {DATA_LEN} bytes, {DATA}", "DATA_LEN", data_len,
245 "DATA",
246 fmt::format("{:02x}", fmt::join(s.begin(), s.end(), " ")));
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500247
248 return 0;
249};
250
251int applyCmd(int ifindex, const Command& cmd, int package = DEFAULT_VALUE,
Ratan Guptaaac603e2018-03-23 00:25:54 +0530252 int channel = DEFAULT_VALUE, int flags = NONE,
253 CallBack function = nullptr)
Ratan Guptabbe45792018-03-23 00:22:55 +0530254{
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500255 int cb_ret = 0;
Gunnar Mills57d9c502018-09-14 14:42:34 -0500256 nlSocketPtr socket(nl_socket_alloc(), &::nl_socket_free);
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700257 if (socket == nullptr)
258 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700259 lg2::error("Unable to allocate memory for the socket");
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700260 return -ENOMEM;
261 }
262
Ratan Guptabbe45792018-03-23 00:22:55 +0530263 auto ret = genl_connect(socket.get());
264 if (ret < 0)
265 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700266 lg2::error("Failed to open the socket , RC : {RC}", "RC", ret);
Ratan Guptabbe45792018-03-23 00:22:55 +0530267 return ret;
268 }
269
270 auto driverID = genl_ctrl_resolve(socket.get(), "NCSI");
271 if (driverID < 0)
272 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700273 lg2::error("Failed to resolve, RC : {RC}", "RC", ret);
Ratan Guptabbe45792018-03-23 00:22:55 +0530274 return driverID;
275 }
276
277 nlMsgPtr msg(nlmsg_alloc(), &::nlmsg_free);
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700278 if (msg == nullptr)
279 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700280 lg2::error("Unable to allocate memory for the message");
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700281 return -ENOMEM;
282 }
Ratan Guptabbe45792018-03-23 00:22:55 +0530283
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500284 auto msgHdr = genlmsg_put(msg.get(), 0, 0, driverID, 0, flags, cmd.cmd, 0);
Ratan Guptabbe45792018-03-23 00:22:55 +0530285 if (!msgHdr)
286 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700287 lg2::error("Unable to add the netlink headers , COMMAND : {COMMAND}",
288 "COMMAND", cmd.cmd);
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700289 return -ENOMEM;
Ratan Guptabbe45792018-03-23 00:22:55 +0530290 }
291
292 if (package != DEFAULT_VALUE)
293 {
294 ret = nla_put_u32(msg.get(), ncsi_nl_attrs::NCSI_ATTR_PACKAGE_ID,
295 package);
296 if (ret < 0)
297 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700298 lg2::error("Failed to set the attribute , RC : {RC} PACKAGE "
299 "{PACKAGE}",
300 "RC", ret, "PACKAGE", lg2::hex, package);
Ratan Guptabbe45792018-03-23 00:22:55 +0530301 return ret;
302 }
303 }
304
305 if (channel != DEFAULT_VALUE)
306 {
307 ret = nla_put_u32(msg.get(), ncsi_nl_attrs::NCSI_ATTR_CHANNEL_ID,
308 channel);
309 if (ret < 0)
310 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700311 lg2::error("Failed to set the attribute , RC : {RC} CHANNEL : "
312 "{CHANNEL}",
313 "RC", ret, "CHANNEL", lg2::hex, channel);
Ratan Guptabbe45792018-03-23 00:22:55 +0530314 return ret;
315 }
316 }
317
318 ret = nla_put_u32(msg.get(), ncsi_nl_attrs::NCSI_ATTR_IFINDEX, ifindex);
319 if (ret < 0)
320 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700321 lg2::error("Failed to set the attribute , RC : {RC} INTERFACE : "
322 "{INTERFACE}",
323 "RC", ret, "INTERFACE", lg2::hex, ifindex);
Ratan Guptabbe45792018-03-23 00:22:55 +0530324 return ret;
325 }
326
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500327 if (cmd.ncsi_cmd != DEFAULT_VALUE)
328 {
329 std::vector<unsigned char> pl(sizeof(NCSIPacketHeader) +
330 cmd.payload.size());
331 NCSIPacketHeader* hdr = (NCSIPacketHeader*)pl.data();
332
333 std::copy(cmd.payload.begin(), cmd.payload.end(),
334 pl.begin() + sizeof(NCSIPacketHeader));
335
336 hdr->type = cmd.ncsi_cmd;
337 hdr->length = htons(cmd.payload.size());
338
339 ret = nla_put(msg.get(), ncsi_nl_attrs::NCSI_ATTR_DATA, pl.size(),
340 pl.data());
341 if (ret < 0)
342 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700343 lg2::error("Failed to set the data attribute, RC : {RC}", "RC",
344 ret);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500345 return ret;
346 }
347
348 nl_socket_disable_seq_check(socket.get());
349 }
350
Ratan Guptaaac603e2018-03-23 00:25:54 +0530351 if (function)
352 {
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500353 cb_ret = 1;
354
Ratan Guptaaac603e2018-03-23 00:25:54 +0530355 // Add a callback function to the socket
Gunnar Mills57d9c502018-09-14 14:42:34 -0500356 nl_socket_modify_cb(socket.get(), NL_CB_VALID, NL_CB_CUSTOM, function,
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500357 &cb_ret);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530358 }
Ratan Guptabbe45792018-03-23 00:22:55 +0530359
360 ret = nl_send_auto(socket.get(), msg.get());
361 if (ret < 0)
362 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700363 lg2::error("Failed to send the message , RC : {RC}", "RC", ret);
Ratan Guptabbe45792018-03-23 00:22:55 +0530364 return ret;
365 }
366
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500367 do
Ratan Guptabbe45792018-03-23 00:22:55 +0530368 {
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500369 ret = nl_recvmsgs_default(socket.get());
370 if (ret < 0)
371 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700372 lg2::error("Failed to receive the message , RC : {RC}", "RC", ret);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500373 break;
374 }
375 } while (cb_ret);
376
Ratan Guptabbe45792018-03-23 00:22:55 +0530377 return ret;
378}
379
Gunnar Mills57d9c502018-09-14 14:42:34 -0500380} // namespace internal
Ratan Guptabbe45792018-03-23 00:22:55 +0530381
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500382int sendOemCommand(int ifindex, int package, int channel,
383 std::span<const unsigned char> payload)
384{
385 constexpr auto cmd = 0x50;
386
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700387 lg2::debug("Send OEM Command, CHANNEL : {CHANNEL} , PACKAGE : {PACKAGE}, "
388 "INTERFACE_INDEX: {INTERFACE_INDEX}",
389 "CHANNEL", lg2::hex, channel, "PACKAGE", lg2::hex, package,
390 "INTERFACE_INDEX", lg2::hex, ifindex);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500391 if (!payload.empty())
392 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700393 std::string payloadStr;
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500394 for (auto& i : payload)
395 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700396 payloadStr += fmt::format(" {:02x}", (int)i);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500397 }
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700398 lg2::debug("Payload :{PAYLOAD}", "PAYLOAD", payloadStr);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500399 }
400
401 return internal::applyCmd(
402 ifindex,
403 internal::Command(ncsi_nl_commands::NCSI_CMD_SEND_CMD, cmd, payload),
404 package, channel, NONE, internal::sendCallBack);
405}
406
Ratan Guptabbe45792018-03-23 00:22:55 +0530407int setChannel(int ifindex, int package, int channel)
408{
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700409 lg2::debug(
410 "Set CHANNEL : {CHANNEL} , PACKAGE : {PACKAGE}, INTERFACE_INDEX: "
411 "{INTERFACE_INDEX}",
412 "CHANNEL", lg2::hex, channel, "PACKAGE", lg2::hex, package,
413 "INTERFACE_INDEX", lg2::hex, ifindex);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500414 return internal::applyCmd(
415 ifindex, internal::Command(ncsi_nl_commands::NCSI_CMD_SET_INTERFACE),
416 package, channel);
Ratan Guptabbe45792018-03-23 00:22:55 +0530417}
418
419int clearInterface(int ifindex)
420{
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700421 lg2::debug("ClearInterface , INTERFACE_INDEX : {INTERFACE_INDEX}",
422 "INTERFACE_INDEX", lg2::hex, ifindex);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500423 return internal::applyCmd(
424 ifindex, internal::Command(ncsi_nl_commands::NCSI_CMD_CLEAR_INTERFACE));
Ratan Guptabbe45792018-03-23 00:22:55 +0530425}
426
Ratan Guptaaac603e2018-03-23 00:25:54 +0530427int getInfo(int ifindex, int package)
428{
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700429 lg2::debug(
430 "Get Info , PACKAGE : {PACKAGE}, INTERFACE_INDEX: {INTERFACE_INDEX}",
431 "PACKAGE", lg2::hex, package, "INTERFACE_INDEX", lg2::hex, ifindex);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530432 if (package == DEFAULT_VALUE)
433 {
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500434 return internal::applyCmd(
435 ifindex, internal::Command(ncsi_nl_commands::NCSI_CMD_PKG_INFO),
436 package, DEFAULT_VALUE, NLM_F_DUMP, internal::infoCallBack);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530437 }
438 else
439 {
440 return internal::applyCmd(ifindex, ncsi_nl_commands::NCSI_CMD_PKG_INFO,
441 package, DEFAULT_VALUE, NONE,
442 internal::infoCallBack);
443 }
444}
445
Gunnar Mills57d9c502018-09-14 14:42:34 -0500446} // namespace ncsi
447} // namespace network
448} // namespace phosphor