blob: 77c384920b082df5d63d5c38556a687ebacea2bf [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
24// OpenBMC System Manager dbus framework
Hariharasubramanian R83951912016-01-20 07:06:36 -060025const char *obj = "/org/openbmc/NetworkManager/Interface";
26const char *ifc = "org.openbmc.NetworkManager";
27
tomjose26e17732016-03-03 08:52:51 -060028const char *nwinterface = "eth0";
29
Adriana Kobylake08fbc62016-02-09 16:17:23 -060030const int SIZE_MAC = 18; //xx:xx:xx:xx:xx:xx
Adriana Kobylake08fbc62016-02-09 16:17:23 -060031
Ratan Guptab8e99552017-07-27 07:07:48 +053032struct ChannelConfig_t channelConfig;
Hariharasubramanian R83951912016-01-20 07:06:36 -060033
tomjose26e17732016-03-03 08:52:51 -060034const uint8_t SET_COMPLETE = 0;
35const uint8_t SET_IN_PROGRESS = 1;
36const uint8_t SET_COMMIT_WRITE = 2; //Optional
37const uint8_t SET_IN_PROGRESS_RESERVED = 3; //Reserved
38
39// Status of Set-In-Progress Parameter (# 0)
40uint8_t lan_set_in_progress = SET_COMPLETE;
41
Ratan Guptab8e99552017-07-27 07:07:48 +053042using namespace phosphor::logging;
43using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053044namespace fs = std::experimental::filesystem;
Hariharasubramanian R83951912016-01-20 07:06:36 -060045
Adriana Kobylak5d6481f2015-10-29 21:44:55 -050046void register_netfn_transport_functions() __attribute__((constructor));
47
Ratan Guptab8e99552017-07-27 07:07:48 +053048// Helper Function to get IP Address/NetMask/Gateway/MAC Address from Network Manager or
Nan Li3d0df912016-10-18 19:51:41 +080049// Cache based on Set-In-Progress State
Ratan Guptab8e99552017-07-27 07:07:48 +053050ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t* data)
tomjose26e17732016-03-03 08:52:51 -060051{
tomjose26e17732016-03-03 08:52:51 -060052 ipmi_ret_t rc = IPMI_CC_OK;
Ratan Guptab8e99552017-07-27 07:07:48 +053053 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Ratan Gupta533d03b2017-07-30 10:39:22 +053054
Ratan Guptab8e99552017-07-27 07:07:48 +053055 try
tomjose26e17732016-03-03 08:52:51 -060056 {
Ratan Guptab8e99552017-07-27 07:07:48 +053057 switch (lan_param)
tomjose26e17732016-03-03 08:52:51 -060058 {
Ratan Guptab8e99552017-07-27 07:07:48 +053059 case LAN_PARM_IP:
60 {
61 std::string ipaddress;
62 if (lan_set_in_progress == SET_COMPLETE)
63 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053064 try
65 {
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -050066 ipaddress = ipmi::getIPAddress(bus,
67 ipmi::network::IP_INTERFACE,
68 ipmi::network::ROOT,
69 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +053070
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053071 }
72 // ignore the exception, as it is a valid condtion that
73 // system is not confiured with any ip.
74 catch (InternalFailure& e)
75 {
76 // nothing to do.
77 }
Ratan Guptab8e99552017-07-27 07:07:48 +053078 }
79 else if (lan_set_in_progress == SET_IN_PROGRESS)
80 {
81 ipaddress = channelConfig.ipaddr;
82 }
83
84 inet_pton(AF_INET, ipaddress.c_str(),
85 reinterpret_cast<void*>(data));
86 }
87 break;
88
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053089 case LAN_PARM_IPSRC:
Ratan Guptab8e99552017-07-27 07:07:48 +053090 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053091 std::string networkInterfacePath;
92
Ratan Guptab8e99552017-07-27 07:07:48 +053093 if (lan_set_in_progress == SET_COMPLETE)
94 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053095 try
96 {
97 ipmi::ObjectTree ancestorMap;
98 // if the system is having ip object,then
99 // get the IP object.
100 auto ipObject = ipmi::getDbusObject(
101 bus,
102 ipmi::network::IP_INTERFACE,
103 ipmi::network::ROOT,
104 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530105
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530106 // Get the parent interface of the IP object.
107 try
108 {
109 ipmi::InterfaceList interfaces;
110 interfaces.emplace_back(
111 ipmi::network::ETHERNET_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530112
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530113 ancestorMap = ipmi::getAllAncestors(
114 bus,
115 ipObject.first,
116 std::move(interfaces));
117 }
118 catch (InternalFailure& e)
119 {
120 // if unable to get the parent interface
121 // then commit the error and return.
122 log<level::ERR>("Unable to get the parent interface",
123 entry("PATH=%s", ipObject.first.c_str()),
124 entry("INTERFACE=%s",
125 ipmi::network::ETHERNET_INTERFACE));
126 break;
127
128 }
129 // for an ip object there would be single parent
130 // interface.
131 networkInterfacePath = ancestorMap.begin()->first;
132 }
133 catch (InternalFailure& e)
134 {
135 // if there is no ip configured on the system,then
136 // get the network interface object.
137 auto networkInterfaceObject = ipmi::getDbusObject(
138 bus,
139 ipmi::network::ETHERNET_INTERFACE,
140 ipmi::network::ROOT,
141 ipmi::network::INTERFACE);
142
143 networkInterfacePath = networkInterfaceObject.first;
144 }
145
146 auto variant = ipmi::getDbusProperty(
147 bus,
148 ipmi::network::SERVICE,
149 networkInterfacePath,
150 ipmi::network::ETHERNET_INTERFACE,
151 "DHCPEnabled");
152
153 auto dhcpEnabled = variant.get<bool>();
154 // As per IPMI spec 2=>DHCP, 1=STATIC
155 auto ipsrc = dhcpEnabled ? ipmi::network::IPOrigin::DHCP :
156 ipmi::network::IPOrigin::STATIC;
157
158 memcpy(data, &ipsrc, ipmi::network::IPSRC_SIZE_BYTE);
159 }
160 else if (lan_set_in_progress == SET_IN_PROGRESS)
161 {
162 memcpy(data, &(channelConfig.ipsrc),
163 ipmi::network::IPSRC_SIZE_BYTE);
164 }
165 }
166 break;
167
168 case LAN_PARM_SUBNET:
169 {
170 unsigned long mask {};
171 if (lan_set_in_progress == SET_COMPLETE)
172 {
173 try
174 {
175 auto ipObjectInfo = ipmi::getDbusObject(
176 bus,
177 ipmi::network::IP_INTERFACE,
178 ipmi::network::ROOT,
179 ipmi::network::IP_TYPE);
180
181 auto properties = ipmi::getAllDbusProperties(
182 bus,
183 ipObjectInfo.second,
184 ipObjectInfo.first,
185 ipmi::network::IP_INTERFACE);
186
187 auto prefix = properties["PrefixLength"].get<uint8_t>();
188 mask = ipmi::network::MASK_32_BIT;
189 mask = htonl(mask << (ipmi::network::BITS_32 - prefix));
190 }
191 // ignore the exception, as it is a valid condtion that
192 // system is not confiured with any ip.
193 catch (InternalFailure& e)
194 {
195 // nothing to do
196 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530197 memcpy(data, &mask, ipmi::network::IPV4_ADDRESS_SIZE_BYTE);
198 }
199 else if (lan_set_in_progress == SET_IN_PROGRESS)
200 {
201 inet_pton(AF_INET, channelConfig.netmask.c_str(),
202 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530203 }
204
205 }
206 break;
207
208 case LAN_PARM_GATEWAY:
209 {
210 std::string gateway;
211
212 if (lan_set_in_progress == SET_COMPLETE)
213 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530214 try
215 {
216 auto systemObject = ipmi::getDbusObject(
217 bus,
218 ipmi::network::SYSTEMCONFIG_INTERFACE,
219 ipmi::network::ROOT);
Ratan Guptab8e99552017-07-27 07:07:48 +0530220
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530221 auto systemProperties = ipmi::getAllDbusProperties(
222 bus,
223 systemObject.second,
224 systemObject.first,
225 ipmi::network::SYSTEMCONFIG_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530226
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530227 gateway = systemProperties["DefaultGateway"].get<
228 std::string>();
229 }
230 // ignore the exception, as it is a valid condtion that
231 // system is not confiured with any ip.
232 catch (InternalFailure& e)
233 {
234 // nothing to do
235 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530236
237 }
238 else if (lan_set_in_progress == SET_IN_PROGRESS)
239 {
240 gateway = channelConfig.gateway;
241 }
242
243 inet_pton(AF_INET, gateway.c_str(),
244 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530245 }
246 break;
247
248 case LAN_PARM_MAC:
249 {
250 std::string macAddress;
251 if (lan_set_in_progress == SET_COMPLETE)
252 {
253 auto macObjectInfo = ipmi::getDbusObject(
254 bus,
255 ipmi::network::MAC_INTERFACE,
256 ipmi::network::ROOT);
257
258 auto variant = ipmi::getDbusProperty(
259 bus,
260 macObjectInfo.second,
261 macObjectInfo.first,
262 ipmi::network::MAC_INTERFACE,
263 "MACAddress");
264
265 macAddress = variant.get<std::string>();
266
267 }
268 else if (lan_set_in_progress == SET_IN_PROGRESS)
269 {
270 macAddress = channelConfig.macAddress;
271 }
272
273 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
274 (data),
275 (data + 1),
276 (data + 2),
277 (data + 3),
278 (data + 4),
279 (data + 5));
280 }
281 break;
282
Ratan Gupta533d03b2017-07-30 10:39:22 +0530283 case LAN_PARM_VLAN:
284 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530285 uint16_t vlanID {};
Ratan Gupta533d03b2017-07-30 10:39:22 +0530286 if (lan_set_in_progress == SET_COMPLETE)
287 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530288 try
Ratan Gupta533d03b2017-07-30 10:39:22 +0530289 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530290 auto ipObjectInfo = ipmi::getDbusObject(
291 bus,
292 ipmi::network::IP_INTERFACE,
293 ipmi::network::ROOT,
294 ipmi::network::IP_TYPE);
295
296 vlanID = static_cast<uint16_t>(
297 ipmi::network::getVLAN(ipObjectInfo.first));
298
299 vlanID = htole16(vlanID);
300
301 if (vlanID)
302 {
303 //Enable the 16th bit
304 vlanID |= htole16(ipmi::network::VLAN_ENABLE_MASK);
305 }
306 }
307 // ignore the exception, as it is a valid condtion that
308 // system is not confiured with any ip.
309 catch (InternalFailure& e)
310 {
311 // nothing to do
Ratan Gupta533d03b2017-07-30 10:39:22 +0530312 }
313
314 memcpy(data, &vlanID, ipmi::network::VLAN_SIZE_BYTE);
315 }
316 else if (lan_set_in_progress == SET_IN_PROGRESS)
317 {
318 memcpy(data, &(channelConfig.vlanID),
319 ipmi::network::VLAN_SIZE_BYTE);
320 }
321 }
322 break;
323
Ratan Guptab8e99552017-07-27 07:07:48 +0530324 default:
325 rc = IPMI_CC_PARM_OUT_OF_RANGE;
tomjose26e17732016-03-03 08:52:51 -0600326 }
327 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530328 catch (InternalFailure& e)
tomjose26e17732016-03-03 08:52:51 -0600329 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530330 commit<InternalFailure>();
331 rc = IPMI_CC_UNSPECIFIED_ERROR;
332 return rc;
tomjose26e17732016-03-03 08:52:51 -0600333 }
tomjose26e17732016-03-03 08:52:51 -0600334 return rc;
335}
336
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500337ipmi_ret_t ipmi_transport_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
338 ipmi_request_t request, ipmi_response_t response,
339 ipmi_data_len_t data_len, ipmi_context_t context)
340{
341 printf("Handling TRANSPORT WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
342 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800343 ipmi_ret_t rc = IPMI_CC_INVALID;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500344 *data_len = 0;
345 return rc;
346}
347
Ratan Guptab8e99552017-07-27 07:07:48 +0530348struct set_lan_t
349{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500350 uint8_t channel;
351 uint8_t parameter;
352 uint8_t data[8]; // Per IPMI spec, not expecting more than this size
Ratan Guptab8e99552017-07-27 07:07:48 +0530353} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500354
Ratan Guptab8e99552017-07-27 07:07:48 +0530355ipmi_ret_t ipmi_transport_set_lan(ipmi_netfn_t netfn,
356 ipmi_cmd_t cmd,
357 ipmi_request_t request,
358 ipmi_response_t response,
359 ipmi_data_len_t data_len,
360 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500361{
362 ipmi_ret_t rc = IPMI_CC_OK;
363 *data_len = 0;
Nan Li3d0df912016-10-18 19:51:41 +0800364
Ratan Guptab8e99552017-07-27 07:07:48 +0530365 char ipaddr[INET_ADDRSTRLEN];
366 char netmask[INET_ADDRSTRLEN];
367 char gateway[INET_ADDRSTRLEN];
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500368
Ratan Guptab8e99552017-07-27 07:07:48 +0530369 auto reqptr = reinterpret_cast<const set_lan_t*>(request);
370 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500371
Ratan Guptab8e99552017-07-27 07:07:48 +0530372 switch (reqptr->parameter)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500373 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530374 case LAN_PARM_IP:
Hariharasubramanian R83951912016-01-20 07:06:36 -0600375 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530376 snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
377 reqptr->data[0], reqptr->data[1],
378 reqptr->data[2], reqptr->data[3]);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500379
Ratan Guptab8e99552017-07-27 07:07:48 +0530380 channelConfig.ipaddr.assign(ipaddr);
381
382 }
383 break;
384
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530385 case LAN_PARM_IPSRC:
386 {
387 uint8_t ipsrc{};
388 memcpy(&ipsrc, reqptr->data, ipmi::network::IPSRC_SIZE_BYTE);
389 channelConfig.ipsrc = static_cast<ipmi::network::IPOrigin>(ipsrc);
390 }
391 break;
392
Ratan Guptab8e99552017-07-27 07:07:48 +0530393 case LAN_PARM_MAC:
394 {
395 char mac[SIZE_MAC];
396
397 snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
398 reqptr->data[0],
399 reqptr->data[1],
400 reqptr->data[2],
401 reqptr->data[3],
402 reqptr->data[4],
403 reqptr->data[5]);
404
405 auto macObjectInfo = ipmi::getDbusObject(
406 bus,
407 ipmi::network::MAC_INTERFACE,
408 ipmi::network::ROOT,
409 ipmi::network::INTERFACE);
410
411 ipmi::setDbusProperty(bus,
412 macObjectInfo.second,
413 macObjectInfo.first,
414 ipmi::network::MAC_INTERFACE,
415 "MACAddress",
416 std::string(mac));
417
418 channelConfig.macAddress = mac;
419
420 }
421 break;
422
423 case LAN_PARM_SUBNET:
424 {
425 snprintf(netmask, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
426 reqptr->data[0], reqptr->data[1],
427 reqptr->data[2], reqptr->data[3]);
428 channelConfig.netmask.assign(netmask);
429 }
430 break;
431
432 case LAN_PARM_GATEWAY:
433 {
434 snprintf(gateway, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
435 reqptr->data[0], reqptr->data[1],
436 reqptr->data[2], reqptr->data[3]);
437 channelConfig.gateway.assign(gateway);
438
439 }
440 break;
441
Ratan Gupta533d03b2017-07-30 10:39:22 +0530442 case LAN_PARM_VLAN:
443 {
444 uint16_t vlan {};
445 memcpy(&vlan, reqptr->data, ipmi::network::VLAN_SIZE_BYTE);
446 // We are not storing the enable bit
447 // We assume that ipmitool always send enable
448 // bit as 1.
449 vlan = le16toh(vlan);
450 channelConfig.vlanID = vlan;
451 }
452 break;
453
Ratan Guptab8e99552017-07-27 07:07:48 +0530454 case LAN_PARM_INPROGRESS:
455 {
456 if (reqptr->data[0] == SET_COMPLETE)
457 {
458 lan_set_in_progress = SET_COMPLETE;
459
460 log<level::INFO>("Network data from Cache",
461 entry("PREFIX=%s", channelConfig.netmask.c_str()),
462 entry("ADDRESS=%s", channelConfig.ipaddr.c_str()),
Ratan Gupta533d03b2017-07-30 10:39:22 +0530463 entry("GATEWAY=%s", channelConfig.gateway.c_str()),
464 entry("VLAN=%d", channelConfig.vlanID));
Ratan Guptab8e99552017-07-27 07:07:48 +0530465
466 log<level::INFO>("Use Set Channel Access command to apply");
467
468 }
469 else if (reqptr->data[0] == SET_IN_PROGRESS) // Set In Progress
470 {
471 lan_set_in_progress = SET_IN_PROGRESS;
472 }
473
474 }
475 break;
476
477 default:
478 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530479 rc = IPMI_CC_PARM_NOT_SUPPORTED;
480 }
481
482 }
vishwa1eaea4f2016-02-26 11:57:40 -0600483
tomjose26e17732016-03-03 08:52:51 -0600484 return rc;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500485}
486
Ratan Guptab8e99552017-07-27 07:07:48 +0530487struct get_lan_t
488{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500489 uint8_t rev_channel;
490 uint8_t parameter;
491 uint8_t parameter_set;
492 uint8_t parameter_block;
Ratan Guptab8e99552017-07-27 07:07:48 +0530493} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500494
Ratan Guptab8e99552017-07-27 07:07:48 +0530495ipmi_ret_t ipmi_transport_get_lan(ipmi_netfn_t netfn,
496 ipmi_cmd_t cmd,
497 ipmi_request_t request,
498 ipmi_response_t response,
499 ipmi_data_len_t data_len,
500 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500501{
502 ipmi_ret_t rc = IPMI_CC_OK;
503 *data_len = 0;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500504 const uint8_t current_revision = 0x11; // Current rev per IPMI Spec 2.0
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500505
506 get_lan_t *reqptr = (get_lan_t*) request;
507
508 if (reqptr->rev_channel & 0x80) // Revision is bit 7
509 {
510 // Only current revision was requested
511 *data_len = sizeof(current_revision);
512 memcpy(response, &current_revision, *data_len);
513 return IPMI_CC_OK;
514 }
515
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600516 if (reqptr->parameter == LAN_PARM_INPROGRESS)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500517 {
tomjose26e17732016-03-03 08:52:51 -0600518 uint8_t buf[] = {current_revision, lan_set_in_progress};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500519 *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_AUTHSUPPORT)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500523 {
524 uint8_t buf[] = {current_revision,0x04};
525 *data_len = sizeof(buf);
526 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500527 }
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600528 else if (reqptr->parameter == LAN_PARM_AUTHENABLES)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500529 {
530 uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04};
531 *data_len = sizeof(buf);
532 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500533 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530534 else if ((reqptr->parameter == LAN_PARM_IP) ||
535 (reqptr->parameter == LAN_PARM_SUBNET) ||
536 (reqptr->parameter == LAN_PARM_GATEWAY) ||
537 (reqptr->parameter == LAN_PARM_MAC))
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500538 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530539 uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500540
tomjose26e17732016-03-03 08:52:51 -0600541 *data_len = sizeof(current_revision);
542 memcpy(buf, &current_revision, *data_len);
543
Ratan Guptab8e99552017-07-27 07:07:48 +0530544 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
vishwa1eaea4f2016-02-26 11:57:40 -0600545 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530546 if (reqptr->parameter == LAN_PARM_MAC)
547 {
548 *data_len = sizeof(buf);
549 }
550 else
551 {
552 *data_len = ipmi::network::IPV4_ADDRESS_SIZE_BYTE + 1;
553 }
tomjose26e17732016-03-03 08:52:51 -0600554 memcpy(response, &buf, *data_len);
Adriana Kobylak342df102016-02-10 13:48:16 -0600555 }
tomjose26e17732016-03-03 08:52:51 -0600556 else
Hariharasubramanian R83951912016-01-20 07:06:36 -0600557 {
tomjose26e17732016-03-03 08:52:51 -0600558 rc = IPMI_CC_UNSPECIFIED_ERROR;
Hariharasubramanian R83951912016-01-20 07:06:36 -0600559 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500560 }
Ratan Gupta533d03b2017-07-30 10:39:22 +0530561 else if (reqptr->parameter == LAN_PARM_VLAN)
562 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530563 uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {};
Ratan Gupta533d03b2017-07-30 10:39:22 +0530564
565 *data_len = sizeof(current_revision);
566 memcpy(buf, &current_revision, *data_len);
567 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
568 {
569 *data_len = sizeof(buf);
570 memcpy(response, &buf, *data_len);
571 }
572 }
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530573 else if (reqptr->parameter == LAN_PARM_IPSRC)
574 {
575 uint8_t buff[ipmi::network::IPSRC_SIZE_BYTE + 1] = {};
576 *data_len = sizeof(current_revision);
577 memcpy(buff, &current_revision, *data_len);
578 if (getNetworkData(reqptr->parameter, &buff[1]) == IPMI_CC_OK)
579 {
580 *data_len = sizeof(buff);
581 memcpy(response, &buff, *data_len);
582 }
583 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500584 else
585 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530586 log<level::ERR>("Unsupported parameter",
587 entry("PARAMETER=0x%x", reqptr->parameter));
vishwa1eaea4f2016-02-26 11:57:40 -0600588 rc = IPMI_CC_PARM_NOT_SUPPORTED;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500589 }
590
591 return rc;
592}
593
594void register_netfn_transport_functions()
595{
Tom05732372016-09-06 17:21:23 +0530596 // <Wildcard Command>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500597 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_WILDCARD);
Tom05732372016-09-06 17:21:23 +0530598 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard,
599 PRIVILEGE_USER);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500600
Tom05732372016-09-06 17:21:23 +0530601 // <Set LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500602 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_SET_LAN);
Tom05732372016-09-06 17:21:23 +0530603 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan,
604 PRIVILEGE_ADMIN);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500605
Tom05732372016-09-06 17:21:23 +0530606 // <Get LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500607 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_GET_LAN);
Tom05732372016-09-06 17:21:23 +0530608 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan,
609 PRIVILEGE_OPERATOR);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500610
611 return;
612}