blob: 07ac7aa048b99b312b9f8371a9ad1723d4724992 [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
Eddie Jamesfa1f5c02020-09-17 15:12:46 -05009#include <iomanip>
Manojkiran Edae5a867a2020-06-01 18:08:30 +053010#include <iostream>
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -070011#include <phosphor-logging/lg2.hpp>
Jiaqing Zhao7c44a782022-04-10 15:30:04 +080012#include <vector>
Ratan Guptabbe45792018-03-23 00:22:55 +053013
14namespace phosphor
15{
16namespace network
17{
18namespace ncsi
19{
20
Gunnar Mills57d9c502018-09-14 14:42:34 -050021using CallBack = int (*)(struct nl_msg* msg, void* arg);
Ratan Guptaaac603e2018-03-23 00:25:54 +053022
23namespace internal
24{
Ratan Guptabbe45792018-03-23 00:22:55 +053025
Eddie Jamesfa1f5c02020-09-17 15:12:46 -050026struct NCSIPacketHeader
27{
28 uint8_t MCID;
29 uint8_t revision;
30 uint8_t reserved;
31 uint8_t id;
32 uint8_t type;
33 uint8_t channel;
34 uint16_t length;
35 uint32_t rsvd[2];
36};
37
38class Command
39{
40 public:
41 Command() = delete;
42 ~Command() = default;
43 Command(const Command&) = delete;
44 Command& operator=(const Command&) = delete;
45 Command(Command&&) = default;
46 Command& operator=(Command&&) = default;
47 Command(
48 int c, int nc = DEFAULT_VALUE,
49 std::span<const unsigned char> p = std::span<const unsigned char>()) :
50 cmd(c),
51 ncsi_cmd(nc), payload(p)
52 {
53 }
54
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 {
Ratan Guptaed5d7ff2018-03-23 00:27:52 +0530190
Gunnar Mills57d9c502018-09-14 14:42:34 -0500191 auto link =
192 nla_get_u32(channeltb[NCSI_CHANNEL_ATTR_LINK_STATE]);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700193 lg2::debug("Channel Link State : {LINK_STATE}", "LINK_STATE",
194 lg2::hex, link);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530195 }
196 if (channeltb[NCSI_CHANNEL_ATTR_VLAN_LIST])
197 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700198 lg2::debug("Active Vlan ids");
Ratan Guptaaac603e2018-03-23 00:25:54 +0530199 auto vids = channeltb[NCSI_CHANNEL_ATTR_VLAN_LIST];
200 auto vid = static_cast<nlattr*>(nla_data(vids));
201 auto len = nla_len(vids);
202 while (nla_ok(vid, len))
203 {
204 auto id = nla_get_u16(vid);
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700205 lg2::debug("VID : {VLAN_ID}", "VLAN_ID", id);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530206 vid = nla_next(vid, &len);
207 }
208 }
Ratan Guptaaac603e2018-03-23 00:25:54 +0530209 }
Ratan Guptaaac603e2018-03-23 00:25:54 +0530210 }
211 return (int)NL_SKIP;
212};
213
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500214CallBack sendCallBack = [](struct nl_msg* msg, void* arg) {
215 using namespace phosphor::network::ncsi;
216 auto nlh = nlmsg_hdr(msg);
217 struct nlattr* tb[NCSI_ATTR_MAX + 1] = {nullptr};
218 static struct nla_policy ncsiPolicy[NCSI_ATTR_MAX + 1] = {
219 {NLA_UNSPEC, 0, 0}, {NLA_U32, 0, 0}, {NLA_NESTED, 0, 0},
220 {NLA_U32, 0, 0}, {NLA_U32, 0, 0}, {NLA_BINARY, 0, 0},
221 {NLA_FLAG, 0, 0}, {NLA_U32, 0, 0}, {NLA_U32, 0, 0},
222 };
223
224 *(int*)arg = 0;
225
226 auto ret = genlmsg_parse(nlh, 0, tb, NCSI_ATTR_MAX, ncsiPolicy);
227 if (ret)
228 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700229 lg2::error("Failed to parse package");
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500230 return ret;
231 }
232
Jian Zhang442d9e52022-10-20 22:11:14 +0800233 if (tb[NCSI_ATTR_DATA] == nullptr)
234 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700235 lg2::error("Response: No data");
Jian Zhang442d9e52022-10-20 22:11:14 +0800236 return -1;
237 }
238
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500239 auto data_len = nla_len(tb[NCSI_ATTR_DATA]) - sizeof(NCSIPacketHeader);
240 unsigned char* data =
241 (unsigned char*)nla_data(tb[NCSI_ATTR_DATA]) + sizeof(NCSIPacketHeader);
242 auto s = std::span<const unsigned char>(data, data_len);
243
244 // Dump the response to stdout. Enhancement: option to save response data
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700245 lg2::debug("Response : {DATA_LEN} bytes, {DATA}", "DATA_LEN", data_len,
246 "DATA",
247 fmt::format("{:02x}", fmt::join(s.begin(), s.end(), " ")));
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500248
249 return 0;
250};
251
252int applyCmd(int ifindex, const Command& cmd, int package = DEFAULT_VALUE,
Ratan Guptaaac603e2018-03-23 00:25:54 +0530253 int channel = DEFAULT_VALUE, int flags = NONE,
254 CallBack function = nullptr)
Ratan Guptabbe45792018-03-23 00:22:55 +0530255{
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500256 int cb_ret = 0;
Gunnar Mills57d9c502018-09-14 14:42:34 -0500257 nlSocketPtr socket(nl_socket_alloc(), &::nl_socket_free);
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700258 if (socket == nullptr)
259 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700260 lg2::error("Unable to allocate memory for the socket");
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700261 return -ENOMEM;
262 }
263
Ratan Guptabbe45792018-03-23 00:22:55 +0530264 auto ret = genl_connect(socket.get());
265 if (ret < 0)
266 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700267 lg2::error("Failed to open the socket , RC : {RC}", "RC", ret);
Ratan Guptabbe45792018-03-23 00:22:55 +0530268 return ret;
269 }
270
271 auto driverID = genl_ctrl_resolve(socket.get(), "NCSI");
272 if (driverID < 0)
273 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700274 lg2::error("Failed to resolve, RC : {RC}", "RC", ret);
Ratan Guptabbe45792018-03-23 00:22:55 +0530275 return driverID;
276 }
277
278 nlMsgPtr msg(nlmsg_alloc(), &::nlmsg_free);
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700279 if (msg == nullptr)
280 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700281 lg2::error("Unable to allocate memory for the message");
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700282 return -ENOMEM;
283 }
Ratan Guptabbe45792018-03-23 00:22:55 +0530284
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500285 auto msgHdr = genlmsg_put(msg.get(), 0, 0, driverID, 0, flags, cmd.cmd, 0);
Ratan Guptabbe45792018-03-23 00:22:55 +0530286 if (!msgHdr)
287 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700288 lg2::error("Unable to add the netlink headers , COMMAND : {COMMAND}",
289 "COMMAND", cmd.cmd);
Johnathan Manteyd49c5c62021-06-23 09:14:42 -0700290 return -ENOMEM;
Ratan Guptabbe45792018-03-23 00:22:55 +0530291 }
292
293 if (package != DEFAULT_VALUE)
294 {
295 ret = nla_put_u32(msg.get(), ncsi_nl_attrs::NCSI_ATTR_PACKAGE_ID,
296 package);
297 if (ret < 0)
298 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700299 lg2::error("Failed to set the attribute , RC : {RC} PACKAGE "
300 "{PACKAGE}",
301 "RC", ret, "PACKAGE", lg2::hex, package);
Ratan Guptabbe45792018-03-23 00:22:55 +0530302 return ret;
303 }
304 }
305
306 if (channel != DEFAULT_VALUE)
307 {
308 ret = nla_put_u32(msg.get(), ncsi_nl_attrs::NCSI_ATTR_CHANNEL_ID,
309 channel);
310 if (ret < 0)
311 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700312 lg2::error("Failed to set the attribute , RC : {RC} CHANNEL : "
313 "{CHANNEL}",
314 "RC", ret, "CHANNEL", lg2::hex, channel);
Ratan Guptabbe45792018-03-23 00:22:55 +0530315 return ret;
316 }
317 }
318
319 ret = nla_put_u32(msg.get(), ncsi_nl_attrs::NCSI_ATTR_IFINDEX, ifindex);
320 if (ret < 0)
321 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700322 lg2::error("Failed to set the attribute , RC : {RC} INTERFACE : "
323 "{INTERFACE}",
324 "RC", ret, "INTERFACE", lg2::hex, ifindex);
Ratan Guptabbe45792018-03-23 00:22:55 +0530325 return ret;
326 }
327
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500328 if (cmd.ncsi_cmd != DEFAULT_VALUE)
329 {
330 std::vector<unsigned char> pl(sizeof(NCSIPacketHeader) +
331 cmd.payload.size());
332 NCSIPacketHeader* hdr = (NCSIPacketHeader*)pl.data();
333
334 std::copy(cmd.payload.begin(), cmd.payload.end(),
335 pl.begin() + sizeof(NCSIPacketHeader));
336
337 hdr->type = cmd.ncsi_cmd;
338 hdr->length = htons(cmd.payload.size());
339
340 ret = nla_put(msg.get(), ncsi_nl_attrs::NCSI_ATTR_DATA, pl.size(),
341 pl.data());
342 if (ret < 0)
343 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700344 lg2::error("Failed to set the data attribute, RC : {RC}", "RC",
345 ret);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500346 return ret;
347 }
348
349 nl_socket_disable_seq_check(socket.get());
350 }
351
Ratan Guptaaac603e2018-03-23 00:25:54 +0530352 if (function)
353 {
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500354 cb_ret = 1;
355
Ratan Guptaaac603e2018-03-23 00:25:54 +0530356 // Add a callback function to the socket
Gunnar Mills57d9c502018-09-14 14:42:34 -0500357 nl_socket_modify_cb(socket.get(), NL_CB_VALID, NL_CB_CUSTOM, function,
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500358 &cb_ret);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530359 }
Ratan Guptabbe45792018-03-23 00:22:55 +0530360
361 ret = nl_send_auto(socket.get(), msg.get());
362 if (ret < 0)
363 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700364 lg2::error("Failed to send the message , RC : {RC}", "RC", ret);
Ratan Guptabbe45792018-03-23 00:22:55 +0530365 return ret;
366 }
367
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500368 do
Ratan Guptabbe45792018-03-23 00:22:55 +0530369 {
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500370 ret = nl_recvmsgs_default(socket.get());
371 if (ret < 0)
372 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700373 lg2::error("Failed to receive the message , RC : {RC}", "RC", ret);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500374 break;
375 }
376 } while (cb_ret);
377
Ratan Guptabbe45792018-03-23 00:22:55 +0530378 return ret;
379}
380
Gunnar Mills57d9c502018-09-14 14:42:34 -0500381} // namespace internal
Ratan Guptabbe45792018-03-23 00:22:55 +0530382
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500383int sendOemCommand(int ifindex, int package, int channel,
384 std::span<const unsigned char> payload)
385{
386 constexpr auto cmd = 0x50;
387
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700388 lg2::debug("Send OEM Command, CHANNEL : {CHANNEL} , PACKAGE : {PACKAGE}, "
389 "INTERFACE_INDEX: {INTERFACE_INDEX}",
390 "CHANNEL", lg2::hex, channel, "PACKAGE", lg2::hex, package,
391 "INTERFACE_INDEX", lg2::hex, ifindex);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500392 if (!payload.empty())
393 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700394 std::string payloadStr;
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500395 for (auto& i : payload)
396 {
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700397 payloadStr += fmt::format(" {:02x}", (int)i);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500398 }
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700399 lg2::debug("Payload :{PAYLOAD}", "PAYLOAD", payloadStr);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500400 }
401
402 return internal::applyCmd(
403 ifindex,
404 internal::Command(ncsi_nl_commands::NCSI_CMD_SEND_CMD, cmd, payload),
405 package, channel, NONE, internal::sendCallBack);
406}
407
Ratan Guptabbe45792018-03-23 00:22:55 +0530408int setChannel(int ifindex, int package, int channel)
409{
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700410 lg2::debug(
411 "Set CHANNEL : {CHANNEL} , PACKAGE : {PACKAGE}, INTERFACE_INDEX: "
412 "{INTERFACE_INDEX}",
413 "CHANNEL", lg2::hex, channel, "PACKAGE", lg2::hex, package,
414 "INTERFACE_INDEX", lg2::hex, ifindex);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500415 return internal::applyCmd(
416 ifindex, internal::Command(ncsi_nl_commands::NCSI_CMD_SET_INTERFACE),
417 package, channel);
Ratan Guptabbe45792018-03-23 00:22:55 +0530418}
419
420int clearInterface(int ifindex)
421{
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700422 lg2::debug("ClearInterface , INTERFACE_INDEX : {INTERFACE_INDEX}",
423 "INTERFACE_INDEX", lg2::hex, ifindex);
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500424 return internal::applyCmd(
425 ifindex, internal::Command(ncsi_nl_commands::NCSI_CMD_CLEAR_INTERFACE));
Ratan Guptabbe45792018-03-23 00:22:55 +0530426}
427
Ratan Guptaaac603e2018-03-23 00:25:54 +0530428int getInfo(int ifindex, int package)
429{
Jagpal Singh Gilld423beb2023-04-18 11:28:03 -0700430 lg2::debug(
431 "Get Info , PACKAGE : {PACKAGE}, INTERFACE_INDEX: {INTERFACE_INDEX}",
432 "PACKAGE", lg2::hex, package, "INTERFACE_INDEX", lg2::hex, ifindex);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530433 if (package == DEFAULT_VALUE)
434 {
Eddie Jamesfa1f5c02020-09-17 15:12:46 -0500435 return internal::applyCmd(
436 ifindex, internal::Command(ncsi_nl_commands::NCSI_CMD_PKG_INFO),
437 package, DEFAULT_VALUE, NLM_F_DUMP, internal::infoCallBack);
Ratan Guptaaac603e2018-03-23 00:25:54 +0530438 }
439 else
440 {
441 return internal::applyCmd(ifindex, ncsi_nl_commands::NCSI_CMD_PKG_INFO,
442 package, DEFAULT_VALUE, NONE,
443 internal::infoCallBack);
444 }
445}
446
Gunnar Mills57d9c502018-09-14 14:42:34 -0500447} // namespace ncsi
448} // namespace network
449} // namespace phosphor