blob: b62bf9c9b00e363ad7a901e8240f3913dbc78e72 [file] [log] [blame]
Adriana Kobylak5d6481f2015-10-29 21:44:55 -05001#include <stdio.h>
2#include <string.h>
3#include <stdint.h>
Hariharasubramanian R83951912016-01-20 07:06:36 -06004#include <arpa/inet.h>
tomjose26e17732016-03-03 08:52:51 -06005#include <string>
Ratan Guptacc6cdbf2017-09-01 23:06:25 +05306#include <experimental/filesystem>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -05007
Patrick Williams37af7332016-09-02 21:21:42 -05008#include "host-ipmid/ipmid-api.h"
Patrick Williams53a360e2016-08-12 22:01:02 -05009#include "ipmid.hpp"
Ratan Guptab8e99552017-07-27 07:07:48 +053010#include "transporthandler.hpp"
11#include "utils.hpp"
12
13#include <phosphor-logging/log.hpp>
14#include <phosphor-logging/elog-errors.hpp>
15#include "xyz/openbmc_project/Common/error.hpp"
Adriana Kobylak5d6481f2015-10-29 21:44:55 -050016
Hariharasubramanian R83951912016-01-20 07:06:36 -060017#define SYSTEMD_NETWORKD_DBUS 1
18
19#ifdef SYSTEMD_NETWORKD_DBUS
20#include <systemd/sd-bus.h>
Sergey Solomineb9b8142016-08-23 09:07:28 -050021#include <mapper.h>
Hariharasubramanian R83951912016-01-20 07:06:36 -060022#endif
23
Adriana Kobylake08fbc62016-02-09 16:17:23 -060024const int SIZE_MAC = 18; //xx:xx:xx:xx:xx:xx
Adriana Kobylake08fbc62016-02-09 16:17:23 -060025
Ratan Guptab8e99552017-07-27 07:07:48 +053026struct ChannelConfig_t channelConfig;
Hariharasubramanian R83951912016-01-20 07:06:36 -060027
tomjose26e17732016-03-03 08:52:51 -060028const uint8_t SET_COMPLETE = 0;
29const uint8_t SET_IN_PROGRESS = 1;
30const uint8_t SET_COMMIT_WRITE = 2; //Optional
31const uint8_t SET_IN_PROGRESS_RESERVED = 3; //Reserved
32
33// Status of Set-In-Progress Parameter (# 0)
34uint8_t lan_set_in_progress = SET_COMPLETE;
35
Ratan Guptab8e99552017-07-27 07:07:48 +053036using namespace phosphor::logging;
37using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053038namespace fs = std::experimental::filesystem;
Hariharasubramanian R83951912016-01-20 07:06:36 -060039
Adriana Kobylak5d6481f2015-10-29 21:44:55 -050040void register_netfn_transport_functions() __attribute__((constructor));
41
Ratan Guptab8e99552017-07-27 07:07:48 +053042// Helper Function to get IP Address/NetMask/Gateway/MAC Address from Network Manager or
Nan Li3d0df912016-10-18 19:51:41 +080043// Cache based on Set-In-Progress State
Ratan Guptab8e99552017-07-27 07:07:48 +053044ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t* data)
tomjose26e17732016-03-03 08:52:51 -060045{
tomjose26e17732016-03-03 08:52:51 -060046 ipmi_ret_t rc = IPMI_CC_OK;
Ratan Guptab8e99552017-07-27 07:07:48 +053047 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Ratan Gupta533d03b2017-07-30 10:39:22 +053048
Ratan Guptab8e99552017-07-27 07:07:48 +053049 try
tomjose26e17732016-03-03 08:52:51 -060050 {
Ratan Guptab8e99552017-07-27 07:07:48 +053051 switch (lan_param)
tomjose26e17732016-03-03 08:52:51 -060052 {
Ratan Guptab8e99552017-07-27 07:07:48 +053053 case LAN_PARM_IP:
54 {
55 std::string ipaddress;
56 if (lan_set_in_progress == SET_COMPLETE)
57 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053058 try
59 {
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -050060 ipaddress = ipmi::getIPAddress(bus,
61 ipmi::network::IP_INTERFACE,
62 ipmi::network::ROOT,
63 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +053064
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053065 }
66 // ignore the exception, as it is a valid condtion that
67 // system is not confiured with any ip.
68 catch (InternalFailure& e)
69 {
70 // nothing to do.
71 }
Ratan Guptab8e99552017-07-27 07:07:48 +053072 }
73 else if (lan_set_in_progress == SET_IN_PROGRESS)
74 {
75 ipaddress = channelConfig.ipaddr;
76 }
77
78 inet_pton(AF_INET, ipaddress.c_str(),
79 reinterpret_cast<void*>(data));
80 }
81 break;
82
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053083 case LAN_PARM_IPSRC:
Ratan Guptab8e99552017-07-27 07:07:48 +053084 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053085 std::string networkInterfacePath;
86
Ratan Guptab8e99552017-07-27 07:07:48 +053087 if (lan_set_in_progress == SET_COMPLETE)
88 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053089 try
90 {
91 ipmi::ObjectTree ancestorMap;
92 // if the system is having ip object,then
93 // get the IP object.
94 auto ipObject = ipmi::getDbusObject(
95 bus,
96 ipmi::network::IP_INTERFACE,
97 ipmi::network::ROOT,
98 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +053099
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530100 // Get the parent interface of the IP object.
101 try
102 {
103 ipmi::InterfaceList interfaces;
104 interfaces.emplace_back(
105 ipmi::network::ETHERNET_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530106
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530107 ancestorMap = ipmi::getAllAncestors(
108 bus,
109 ipObject.first,
110 std::move(interfaces));
111 }
112 catch (InternalFailure& e)
113 {
114 // if unable to get the parent interface
115 // then commit the error and return.
116 log<level::ERR>("Unable to get the parent interface",
117 entry("PATH=%s", ipObject.first.c_str()),
118 entry("INTERFACE=%s",
119 ipmi::network::ETHERNET_INTERFACE));
120 break;
121
122 }
123 // for an ip object there would be single parent
124 // interface.
125 networkInterfacePath = ancestorMap.begin()->first;
126 }
127 catch (InternalFailure& e)
128 {
129 // if there is no ip configured on the system,then
130 // get the network interface object.
131 auto networkInterfaceObject = ipmi::getDbusObject(
132 bus,
133 ipmi::network::ETHERNET_INTERFACE,
134 ipmi::network::ROOT,
135 ipmi::network::INTERFACE);
136
137 networkInterfacePath = networkInterfaceObject.first;
138 }
139
140 auto variant = ipmi::getDbusProperty(
141 bus,
142 ipmi::network::SERVICE,
143 networkInterfacePath,
144 ipmi::network::ETHERNET_INTERFACE,
145 "DHCPEnabled");
146
147 auto dhcpEnabled = variant.get<bool>();
148 // As per IPMI spec 2=>DHCP, 1=STATIC
149 auto ipsrc = dhcpEnabled ? ipmi::network::IPOrigin::DHCP :
150 ipmi::network::IPOrigin::STATIC;
151
152 memcpy(data, &ipsrc, ipmi::network::IPSRC_SIZE_BYTE);
153 }
154 else if (lan_set_in_progress == SET_IN_PROGRESS)
155 {
156 memcpy(data, &(channelConfig.ipsrc),
157 ipmi::network::IPSRC_SIZE_BYTE);
158 }
159 }
160 break;
161
162 case LAN_PARM_SUBNET:
163 {
164 unsigned long mask {};
165 if (lan_set_in_progress == SET_COMPLETE)
166 {
167 try
168 {
169 auto ipObjectInfo = ipmi::getDbusObject(
170 bus,
171 ipmi::network::IP_INTERFACE,
172 ipmi::network::ROOT,
173 ipmi::network::IP_TYPE);
174
175 auto properties = ipmi::getAllDbusProperties(
176 bus,
177 ipObjectInfo.second,
178 ipObjectInfo.first,
179 ipmi::network::IP_INTERFACE);
180
181 auto prefix = properties["PrefixLength"].get<uint8_t>();
182 mask = ipmi::network::MASK_32_BIT;
183 mask = htonl(mask << (ipmi::network::BITS_32 - prefix));
184 }
185 // ignore the exception, as it is a valid condtion that
186 // system is not confiured with any ip.
187 catch (InternalFailure& e)
188 {
189 // nothing to do
190 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530191 memcpy(data, &mask, ipmi::network::IPV4_ADDRESS_SIZE_BYTE);
192 }
193 else if (lan_set_in_progress == SET_IN_PROGRESS)
194 {
195 inet_pton(AF_INET, channelConfig.netmask.c_str(),
196 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530197 }
198
199 }
200 break;
201
202 case LAN_PARM_GATEWAY:
203 {
204 std::string gateway;
205
206 if (lan_set_in_progress == SET_COMPLETE)
207 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530208 try
209 {
210 auto systemObject = ipmi::getDbusObject(
211 bus,
212 ipmi::network::SYSTEMCONFIG_INTERFACE,
213 ipmi::network::ROOT);
Ratan Guptab8e99552017-07-27 07:07:48 +0530214
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530215 auto systemProperties = ipmi::getAllDbusProperties(
216 bus,
217 systemObject.second,
218 systemObject.first,
219 ipmi::network::SYSTEMCONFIG_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530220
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530221 gateway = systemProperties["DefaultGateway"].get<
222 std::string>();
223 }
224 // ignore the exception, as it is a valid condtion that
225 // system is not confiured with any ip.
226 catch (InternalFailure& e)
227 {
228 // nothing to do
229 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530230
231 }
232 else if (lan_set_in_progress == SET_IN_PROGRESS)
233 {
234 gateway = channelConfig.gateway;
235 }
236
237 inet_pton(AF_INET, gateway.c_str(),
238 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530239 }
240 break;
241
242 case LAN_PARM_MAC:
243 {
244 std::string macAddress;
245 if (lan_set_in_progress == SET_COMPLETE)
246 {
247 auto macObjectInfo = ipmi::getDbusObject(
248 bus,
249 ipmi::network::MAC_INTERFACE,
250 ipmi::network::ROOT);
251
252 auto variant = ipmi::getDbusProperty(
253 bus,
254 macObjectInfo.second,
255 macObjectInfo.first,
256 ipmi::network::MAC_INTERFACE,
257 "MACAddress");
258
259 macAddress = variant.get<std::string>();
260
261 }
262 else if (lan_set_in_progress == SET_IN_PROGRESS)
263 {
264 macAddress = channelConfig.macAddress;
265 }
266
267 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
268 (data),
269 (data + 1),
270 (data + 2),
271 (data + 3),
272 (data + 4),
273 (data + 5));
274 }
275 break;
276
Ratan Gupta533d03b2017-07-30 10:39:22 +0530277 case LAN_PARM_VLAN:
278 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530279 uint16_t vlanID {};
Ratan Gupta533d03b2017-07-30 10:39:22 +0530280 if (lan_set_in_progress == SET_COMPLETE)
281 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530282 try
Ratan Gupta533d03b2017-07-30 10:39:22 +0530283 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530284 auto ipObjectInfo = ipmi::getDbusObject(
285 bus,
286 ipmi::network::IP_INTERFACE,
287 ipmi::network::ROOT,
288 ipmi::network::IP_TYPE);
289
290 vlanID = static_cast<uint16_t>(
291 ipmi::network::getVLAN(ipObjectInfo.first));
292
293 vlanID = htole16(vlanID);
294
295 if (vlanID)
296 {
297 //Enable the 16th bit
298 vlanID |= htole16(ipmi::network::VLAN_ENABLE_MASK);
299 }
300 }
301 // ignore the exception, as it is a valid condtion that
302 // system is not confiured with any ip.
303 catch (InternalFailure& e)
304 {
305 // nothing to do
Ratan Gupta533d03b2017-07-30 10:39:22 +0530306 }
307
308 memcpy(data, &vlanID, ipmi::network::VLAN_SIZE_BYTE);
309 }
310 else if (lan_set_in_progress == SET_IN_PROGRESS)
311 {
312 memcpy(data, &(channelConfig.vlanID),
313 ipmi::network::VLAN_SIZE_BYTE);
314 }
315 }
316 break;
317
Ratan Guptab8e99552017-07-27 07:07:48 +0530318 default:
319 rc = IPMI_CC_PARM_OUT_OF_RANGE;
tomjose26e17732016-03-03 08:52:51 -0600320 }
321 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530322 catch (InternalFailure& e)
tomjose26e17732016-03-03 08:52:51 -0600323 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530324 commit<InternalFailure>();
325 rc = IPMI_CC_UNSPECIFIED_ERROR;
326 return rc;
tomjose26e17732016-03-03 08:52:51 -0600327 }
tomjose26e17732016-03-03 08:52:51 -0600328 return rc;
329}
330
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500331ipmi_ret_t ipmi_transport_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
332 ipmi_request_t request, ipmi_response_t response,
333 ipmi_data_len_t data_len, ipmi_context_t context)
334{
335 printf("Handling TRANSPORT WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
336 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800337 ipmi_ret_t rc = IPMI_CC_INVALID;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500338 *data_len = 0;
339 return rc;
340}
341
Ratan Guptab8e99552017-07-27 07:07:48 +0530342struct set_lan_t
343{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500344 uint8_t channel;
345 uint8_t parameter;
346 uint8_t data[8]; // Per IPMI spec, not expecting more than this size
Ratan Guptab8e99552017-07-27 07:07:48 +0530347} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500348
Ratan Guptab8e99552017-07-27 07:07:48 +0530349ipmi_ret_t ipmi_transport_set_lan(ipmi_netfn_t netfn,
350 ipmi_cmd_t cmd,
351 ipmi_request_t request,
352 ipmi_response_t response,
353 ipmi_data_len_t data_len,
354 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500355{
356 ipmi_ret_t rc = IPMI_CC_OK;
357 *data_len = 0;
Nan Li3d0df912016-10-18 19:51:41 +0800358
Ratan Guptab8e99552017-07-27 07:07:48 +0530359 char ipaddr[INET_ADDRSTRLEN];
360 char netmask[INET_ADDRSTRLEN];
361 char gateway[INET_ADDRSTRLEN];
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500362
Ratan Guptab8e99552017-07-27 07:07:48 +0530363 auto reqptr = reinterpret_cast<const set_lan_t*>(request);
364 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500365
Ratan Guptab8e99552017-07-27 07:07:48 +0530366 switch (reqptr->parameter)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500367 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530368 case LAN_PARM_IP:
Hariharasubramanian R83951912016-01-20 07:06:36 -0600369 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530370 snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
371 reqptr->data[0], reqptr->data[1],
372 reqptr->data[2], reqptr->data[3]);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500373
Ratan Guptab8e99552017-07-27 07:07:48 +0530374 channelConfig.ipaddr.assign(ipaddr);
375
376 }
377 break;
378
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530379 case LAN_PARM_IPSRC:
380 {
381 uint8_t ipsrc{};
382 memcpy(&ipsrc, reqptr->data, ipmi::network::IPSRC_SIZE_BYTE);
383 channelConfig.ipsrc = static_cast<ipmi::network::IPOrigin>(ipsrc);
384 }
385 break;
386
Ratan Guptab8e99552017-07-27 07:07:48 +0530387 case LAN_PARM_MAC:
388 {
389 char mac[SIZE_MAC];
390
391 snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
392 reqptr->data[0],
393 reqptr->data[1],
394 reqptr->data[2],
395 reqptr->data[3],
396 reqptr->data[4],
397 reqptr->data[5]);
398
399 auto macObjectInfo = ipmi::getDbusObject(
400 bus,
401 ipmi::network::MAC_INTERFACE,
402 ipmi::network::ROOT,
403 ipmi::network::INTERFACE);
404
405 ipmi::setDbusProperty(bus,
406 macObjectInfo.second,
407 macObjectInfo.first,
408 ipmi::network::MAC_INTERFACE,
409 "MACAddress",
410 std::string(mac));
411
412 channelConfig.macAddress = mac;
413
414 }
415 break;
416
417 case LAN_PARM_SUBNET:
418 {
419 snprintf(netmask, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
420 reqptr->data[0], reqptr->data[1],
421 reqptr->data[2], reqptr->data[3]);
422 channelConfig.netmask.assign(netmask);
423 }
424 break;
425
426 case LAN_PARM_GATEWAY:
427 {
428 snprintf(gateway, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
429 reqptr->data[0], reqptr->data[1],
430 reqptr->data[2], reqptr->data[3]);
431 channelConfig.gateway.assign(gateway);
432
433 }
434 break;
435
Ratan Gupta533d03b2017-07-30 10:39:22 +0530436 case LAN_PARM_VLAN:
437 {
438 uint16_t vlan {};
439 memcpy(&vlan, reqptr->data, ipmi::network::VLAN_SIZE_BYTE);
440 // We are not storing the enable bit
441 // We assume that ipmitool always send enable
442 // bit as 1.
443 vlan = le16toh(vlan);
444 channelConfig.vlanID = vlan;
445 }
446 break;
447
Ratan Guptab8e99552017-07-27 07:07:48 +0530448 case LAN_PARM_INPROGRESS:
449 {
450 if (reqptr->data[0] == SET_COMPLETE)
451 {
452 lan_set_in_progress = SET_COMPLETE;
453
454 log<level::INFO>("Network data from Cache",
455 entry("PREFIX=%s", channelConfig.netmask.c_str()),
456 entry("ADDRESS=%s", channelConfig.ipaddr.c_str()),
Ratan Gupta533d03b2017-07-30 10:39:22 +0530457 entry("GATEWAY=%s", channelConfig.gateway.c_str()),
458 entry("VLAN=%d", channelConfig.vlanID));
Ratan Guptab8e99552017-07-27 07:07:48 +0530459
460 log<level::INFO>("Use Set Channel Access command to apply");
461
462 }
463 else if (reqptr->data[0] == SET_IN_PROGRESS) // Set In Progress
464 {
465 lan_set_in_progress = SET_IN_PROGRESS;
466 }
467
468 }
469 break;
470
471 default:
472 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530473 rc = IPMI_CC_PARM_NOT_SUPPORTED;
474 }
475
476 }
vishwa1eaea4f2016-02-26 11:57:40 -0600477
tomjose26e17732016-03-03 08:52:51 -0600478 return rc;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500479}
480
Ratan Guptab8e99552017-07-27 07:07:48 +0530481struct get_lan_t
482{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500483 uint8_t rev_channel;
484 uint8_t parameter;
485 uint8_t parameter_set;
486 uint8_t parameter_block;
Ratan Guptab8e99552017-07-27 07:07:48 +0530487} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500488
Ratan Guptab8e99552017-07-27 07:07:48 +0530489ipmi_ret_t ipmi_transport_get_lan(ipmi_netfn_t netfn,
490 ipmi_cmd_t cmd,
491 ipmi_request_t request,
492 ipmi_response_t response,
493 ipmi_data_len_t data_len,
494 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500495{
496 ipmi_ret_t rc = IPMI_CC_OK;
497 *data_len = 0;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500498 const uint8_t current_revision = 0x11; // Current rev per IPMI Spec 2.0
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500499
500 get_lan_t *reqptr = (get_lan_t*) request;
501
502 if (reqptr->rev_channel & 0x80) // Revision is bit 7
503 {
504 // Only current revision was requested
505 *data_len = sizeof(current_revision);
506 memcpy(response, &current_revision, *data_len);
507 return IPMI_CC_OK;
508 }
509
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600510 if (reqptr->parameter == LAN_PARM_INPROGRESS)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500511 {
tomjose26e17732016-03-03 08:52:51 -0600512 uint8_t buf[] = {current_revision, lan_set_in_progress};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500513 *data_len = sizeof(buf);
514 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500515 }
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600516 else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500517 {
518 uint8_t buf[] = {current_revision,0x04};
519 *data_len = sizeof(buf);
520 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500521 }
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600522 else if (reqptr->parameter == LAN_PARM_AUTHENABLES)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500523 {
524 uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04};
525 *data_len = sizeof(buf);
526 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500527 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530528 else if ((reqptr->parameter == LAN_PARM_IP) ||
529 (reqptr->parameter == LAN_PARM_SUBNET) ||
530 (reqptr->parameter == LAN_PARM_GATEWAY) ||
531 (reqptr->parameter == LAN_PARM_MAC))
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500532 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530533 uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500534
tomjose26e17732016-03-03 08:52:51 -0600535 *data_len = sizeof(current_revision);
536 memcpy(buf, &current_revision, *data_len);
537
Ratan Guptab8e99552017-07-27 07:07:48 +0530538 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
vishwa1eaea4f2016-02-26 11:57:40 -0600539 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530540 if (reqptr->parameter == LAN_PARM_MAC)
541 {
542 *data_len = sizeof(buf);
543 }
544 else
545 {
546 *data_len = ipmi::network::IPV4_ADDRESS_SIZE_BYTE + 1;
547 }
tomjose26e17732016-03-03 08:52:51 -0600548 memcpy(response, &buf, *data_len);
Adriana Kobylak342df102016-02-10 13:48:16 -0600549 }
tomjose26e17732016-03-03 08:52:51 -0600550 else
Hariharasubramanian R83951912016-01-20 07:06:36 -0600551 {
tomjose26e17732016-03-03 08:52:51 -0600552 rc = IPMI_CC_UNSPECIFIED_ERROR;
Hariharasubramanian R83951912016-01-20 07:06:36 -0600553 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500554 }
Ratan Gupta533d03b2017-07-30 10:39:22 +0530555 else if (reqptr->parameter == LAN_PARM_VLAN)
556 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530557 uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {};
Ratan Gupta533d03b2017-07-30 10:39:22 +0530558
559 *data_len = sizeof(current_revision);
560 memcpy(buf, &current_revision, *data_len);
561 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
562 {
563 *data_len = sizeof(buf);
564 memcpy(response, &buf, *data_len);
565 }
566 }
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530567 else if (reqptr->parameter == LAN_PARM_IPSRC)
568 {
569 uint8_t buff[ipmi::network::IPSRC_SIZE_BYTE + 1] = {};
570 *data_len = sizeof(current_revision);
571 memcpy(buff, &current_revision, *data_len);
572 if (getNetworkData(reqptr->parameter, &buff[1]) == IPMI_CC_OK)
573 {
574 *data_len = sizeof(buff);
575 memcpy(response, &buff, *data_len);
576 }
577 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500578 else
579 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530580 log<level::ERR>("Unsupported parameter",
581 entry("PARAMETER=0x%x", reqptr->parameter));
vishwa1eaea4f2016-02-26 11:57:40 -0600582 rc = IPMI_CC_PARM_NOT_SUPPORTED;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500583 }
584
585 return rc;
586}
587
588void register_netfn_transport_functions()
589{
Tom05732372016-09-06 17:21:23 +0530590 // <Wildcard Command>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500591 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_WILDCARD);
Tom05732372016-09-06 17:21:23 +0530592 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard,
593 PRIVILEGE_USER);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500594
Tom05732372016-09-06 17:21:23 +0530595 // <Set LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500596 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_SET_LAN);
Tom05732372016-09-06 17:21:23 +0530597 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan,
598 PRIVILEGE_ADMIN);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500599
Tom05732372016-09-06 17:21:23 +0530600 // <Get LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500601 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_GET_LAN);
Tom05732372016-09-06 17:21:23 +0530602 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan,
603 PRIVILEGE_OPERATOR);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500604
605 return;
606}