blob: e571d30c310b84100f64aaf14599c81c36683887 [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 {
66 auto ipObjectInfo = ipmi::getDbusObject(
67 bus,
68 ipmi::network::IP_INTERFACE,
69 ipmi::network::ROOT,
70 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +053071
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053072 auto properties = ipmi::getAllDbusProperties(
73 bus,
74 ipObjectInfo.second,
75 ipObjectInfo.first,
76 ipmi::network::IP_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +053077
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053078 ipaddress = properties["Address"].get<std::string>();
79 }
80 // ignore the exception, as it is a valid condtion that
81 // system is not confiured with any ip.
82 catch (InternalFailure& e)
83 {
84 // nothing to do.
85 }
Ratan Guptab8e99552017-07-27 07:07:48 +053086 }
87 else if (lan_set_in_progress == SET_IN_PROGRESS)
88 {
89 ipaddress = channelConfig.ipaddr;
90 }
91
92 inet_pton(AF_INET, ipaddress.c_str(),
93 reinterpret_cast<void*>(data));
94 }
95 break;
96
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053097 case LAN_PARM_IPSRC:
Ratan Guptab8e99552017-07-27 07:07:48 +053098 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053099 std::string networkInterfacePath;
100
Ratan Guptab8e99552017-07-27 07:07:48 +0530101 if (lan_set_in_progress == SET_COMPLETE)
102 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530103 try
104 {
105 ipmi::ObjectTree ancestorMap;
106 // if the system is having ip object,then
107 // get the IP object.
108 auto ipObject = ipmi::getDbusObject(
109 bus,
110 ipmi::network::IP_INTERFACE,
111 ipmi::network::ROOT,
112 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530113
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530114 // Get the parent interface of the IP object.
115 try
116 {
117 ipmi::InterfaceList interfaces;
118 interfaces.emplace_back(
119 ipmi::network::ETHERNET_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530120
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530121 ancestorMap = ipmi::getAllAncestors(
122 bus,
123 ipObject.first,
124 std::move(interfaces));
125 }
126 catch (InternalFailure& e)
127 {
128 // if unable to get the parent interface
129 // then commit the error and return.
130 log<level::ERR>("Unable to get the parent interface",
131 entry("PATH=%s", ipObject.first.c_str()),
132 entry("INTERFACE=%s",
133 ipmi::network::ETHERNET_INTERFACE));
134 break;
135
136 }
137 // for an ip object there would be single parent
138 // interface.
139 networkInterfacePath = ancestorMap.begin()->first;
140 }
141 catch (InternalFailure& e)
142 {
143 // if there is no ip configured on the system,then
144 // get the network interface object.
145 auto networkInterfaceObject = ipmi::getDbusObject(
146 bus,
147 ipmi::network::ETHERNET_INTERFACE,
148 ipmi::network::ROOT,
149 ipmi::network::INTERFACE);
150
151 networkInterfacePath = networkInterfaceObject.first;
152 }
153
154 auto variant = ipmi::getDbusProperty(
155 bus,
156 ipmi::network::SERVICE,
157 networkInterfacePath,
158 ipmi::network::ETHERNET_INTERFACE,
159 "DHCPEnabled");
160
161 auto dhcpEnabled = variant.get<bool>();
162 // As per IPMI spec 2=>DHCP, 1=STATIC
163 auto ipsrc = dhcpEnabled ? ipmi::network::IPOrigin::DHCP :
164 ipmi::network::IPOrigin::STATIC;
165
166 memcpy(data, &ipsrc, ipmi::network::IPSRC_SIZE_BYTE);
167 }
168 else if (lan_set_in_progress == SET_IN_PROGRESS)
169 {
170 memcpy(data, &(channelConfig.ipsrc),
171 ipmi::network::IPSRC_SIZE_BYTE);
172 }
173 }
174 break;
175
176 case LAN_PARM_SUBNET:
177 {
178 unsigned long mask {};
179 if (lan_set_in_progress == SET_COMPLETE)
180 {
181 try
182 {
183 auto ipObjectInfo = ipmi::getDbusObject(
184 bus,
185 ipmi::network::IP_INTERFACE,
186 ipmi::network::ROOT,
187 ipmi::network::IP_TYPE);
188
189 auto properties = ipmi::getAllDbusProperties(
190 bus,
191 ipObjectInfo.second,
192 ipObjectInfo.first,
193 ipmi::network::IP_INTERFACE);
194
195 auto prefix = properties["PrefixLength"].get<uint8_t>();
196 mask = ipmi::network::MASK_32_BIT;
197 mask = htonl(mask << (ipmi::network::BITS_32 - prefix));
198 }
199 // ignore the exception, as it is a valid condtion that
200 // system is not confiured with any ip.
201 catch (InternalFailure& e)
202 {
203 // nothing to do
204 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530205 memcpy(data, &mask, ipmi::network::IPV4_ADDRESS_SIZE_BYTE);
206 }
207 else if (lan_set_in_progress == SET_IN_PROGRESS)
208 {
209 inet_pton(AF_INET, channelConfig.netmask.c_str(),
210 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530211 }
212
213 }
214 break;
215
216 case LAN_PARM_GATEWAY:
217 {
218 std::string gateway;
219
220 if (lan_set_in_progress == SET_COMPLETE)
221 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530222 try
223 {
224 auto systemObject = ipmi::getDbusObject(
225 bus,
226 ipmi::network::SYSTEMCONFIG_INTERFACE,
227 ipmi::network::ROOT);
Ratan Guptab8e99552017-07-27 07:07:48 +0530228
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530229 auto systemProperties = ipmi::getAllDbusProperties(
230 bus,
231 systemObject.second,
232 systemObject.first,
233 ipmi::network::SYSTEMCONFIG_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530234
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530235 gateway = systemProperties["DefaultGateway"].get<
236 std::string>();
237 }
238 // ignore the exception, as it is a valid condtion that
239 // system is not confiured with any ip.
240 catch (InternalFailure& e)
241 {
242 // nothing to do
243 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530244
245 }
246 else if (lan_set_in_progress == SET_IN_PROGRESS)
247 {
248 gateway = channelConfig.gateway;
249 }
250
251 inet_pton(AF_INET, gateway.c_str(),
252 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530253 }
254 break;
255
256 case LAN_PARM_MAC:
257 {
258 std::string macAddress;
259 if (lan_set_in_progress == SET_COMPLETE)
260 {
261 auto macObjectInfo = ipmi::getDbusObject(
262 bus,
263 ipmi::network::MAC_INTERFACE,
264 ipmi::network::ROOT);
265
266 auto variant = ipmi::getDbusProperty(
267 bus,
268 macObjectInfo.second,
269 macObjectInfo.first,
270 ipmi::network::MAC_INTERFACE,
271 "MACAddress");
272
273 macAddress = variant.get<std::string>();
274
275 }
276 else if (lan_set_in_progress == SET_IN_PROGRESS)
277 {
278 macAddress = channelConfig.macAddress;
279 }
280
281 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
282 (data),
283 (data + 1),
284 (data + 2),
285 (data + 3),
286 (data + 4),
287 (data + 5));
288 }
289 break;
290
Ratan Gupta533d03b2017-07-30 10:39:22 +0530291 case LAN_PARM_VLAN:
292 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530293 uint16_t vlanID {};
Ratan Gupta533d03b2017-07-30 10:39:22 +0530294 if (lan_set_in_progress == SET_COMPLETE)
295 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530296 try
Ratan Gupta533d03b2017-07-30 10:39:22 +0530297 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530298 auto ipObjectInfo = ipmi::getDbusObject(
299 bus,
300 ipmi::network::IP_INTERFACE,
301 ipmi::network::ROOT,
302 ipmi::network::IP_TYPE);
303
304 vlanID = static_cast<uint16_t>(
305 ipmi::network::getVLAN(ipObjectInfo.first));
306
307 vlanID = htole16(vlanID);
308
309 if (vlanID)
310 {
311 //Enable the 16th bit
312 vlanID |= htole16(ipmi::network::VLAN_ENABLE_MASK);
313 }
314 }
315 // ignore the exception, as it is a valid condtion that
316 // system is not confiured with any ip.
317 catch (InternalFailure& e)
318 {
319 // nothing to do
Ratan Gupta533d03b2017-07-30 10:39:22 +0530320 }
321
322 memcpy(data, &vlanID, ipmi::network::VLAN_SIZE_BYTE);
323 }
324 else if (lan_set_in_progress == SET_IN_PROGRESS)
325 {
326 memcpy(data, &(channelConfig.vlanID),
327 ipmi::network::VLAN_SIZE_BYTE);
328 }
329 }
330 break;
331
Ratan Guptab8e99552017-07-27 07:07:48 +0530332 default:
333 rc = IPMI_CC_PARM_OUT_OF_RANGE;
tomjose26e17732016-03-03 08:52:51 -0600334 }
335 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530336 catch (InternalFailure& e)
tomjose26e17732016-03-03 08:52:51 -0600337 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530338 commit<InternalFailure>();
339 rc = IPMI_CC_UNSPECIFIED_ERROR;
340 return rc;
tomjose26e17732016-03-03 08:52:51 -0600341 }
tomjose26e17732016-03-03 08:52:51 -0600342 return rc;
343}
344
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500345ipmi_ret_t ipmi_transport_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
346 ipmi_request_t request, ipmi_response_t response,
347 ipmi_data_len_t data_len, ipmi_context_t context)
348{
349 printf("Handling TRANSPORT WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
350 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800351 ipmi_ret_t rc = IPMI_CC_INVALID;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500352 *data_len = 0;
353 return rc;
354}
355
Ratan Guptab8e99552017-07-27 07:07:48 +0530356struct set_lan_t
357{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500358 uint8_t channel;
359 uint8_t parameter;
360 uint8_t data[8]; // Per IPMI spec, not expecting more than this size
Ratan Guptab8e99552017-07-27 07:07:48 +0530361} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500362
Ratan Guptab8e99552017-07-27 07:07:48 +0530363ipmi_ret_t ipmi_transport_set_lan(ipmi_netfn_t netfn,
364 ipmi_cmd_t cmd,
365 ipmi_request_t request,
366 ipmi_response_t response,
367 ipmi_data_len_t data_len,
368 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500369{
370 ipmi_ret_t rc = IPMI_CC_OK;
371 *data_len = 0;
Nan Li3d0df912016-10-18 19:51:41 +0800372
Ratan Guptab8e99552017-07-27 07:07:48 +0530373 char ipaddr[INET_ADDRSTRLEN];
374 char netmask[INET_ADDRSTRLEN];
375 char gateway[INET_ADDRSTRLEN];
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500376
Ratan Guptab8e99552017-07-27 07:07:48 +0530377 auto reqptr = reinterpret_cast<const set_lan_t*>(request);
378 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500379
Ratan Guptab8e99552017-07-27 07:07:48 +0530380 switch (reqptr->parameter)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500381 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530382 case LAN_PARM_IP:
Hariharasubramanian R83951912016-01-20 07:06:36 -0600383 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530384 snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
385 reqptr->data[0], reqptr->data[1],
386 reqptr->data[2], reqptr->data[3]);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500387
Ratan Guptab8e99552017-07-27 07:07:48 +0530388 channelConfig.ipaddr.assign(ipaddr);
389
390 }
391 break;
392
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530393 case LAN_PARM_IPSRC:
394 {
395 uint8_t ipsrc{};
396 memcpy(&ipsrc, reqptr->data, ipmi::network::IPSRC_SIZE_BYTE);
397 channelConfig.ipsrc = static_cast<ipmi::network::IPOrigin>(ipsrc);
398 }
399 break;
400
Ratan Guptab8e99552017-07-27 07:07:48 +0530401 case LAN_PARM_MAC:
402 {
403 char mac[SIZE_MAC];
404
405 snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
406 reqptr->data[0],
407 reqptr->data[1],
408 reqptr->data[2],
409 reqptr->data[3],
410 reqptr->data[4],
411 reqptr->data[5]);
412
413 auto macObjectInfo = ipmi::getDbusObject(
414 bus,
415 ipmi::network::MAC_INTERFACE,
416 ipmi::network::ROOT,
417 ipmi::network::INTERFACE);
418
419 ipmi::setDbusProperty(bus,
420 macObjectInfo.second,
421 macObjectInfo.first,
422 ipmi::network::MAC_INTERFACE,
423 "MACAddress",
424 std::string(mac));
425
426 channelConfig.macAddress = mac;
427
428 }
429 break;
430
431 case LAN_PARM_SUBNET:
432 {
433 snprintf(netmask, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
434 reqptr->data[0], reqptr->data[1],
435 reqptr->data[2], reqptr->data[3]);
436 channelConfig.netmask.assign(netmask);
437 }
438 break;
439
440 case LAN_PARM_GATEWAY:
441 {
442 snprintf(gateway, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
443 reqptr->data[0], reqptr->data[1],
444 reqptr->data[2], reqptr->data[3]);
445 channelConfig.gateway.assign(gateway);
446
447 }
448 break;
449
Ratan Gupta533d03b2017-07-30 10:39:22 +0530450 case LAN_PARM_VLAN:
451 {
452 uint16_t vlan {};
453 memcpy(&vlan, reqptr->data, ipmi::network::VLAN_SIZE_BYTE);
454 // We are not storing the enable bit
455 // We assume that ipmitool always send enable
456 // bit as 1.
457 vlan = le16toh(vlan);
458 channelConfig.vlanID = vlan;
459 }
460 break;
461
Ratan Guptab8e99552017-07-27 07:07:48 +0530462 case LAN_PARM_INPROGRESS:
463 {
464 if (reqptr->data[0] == SET_COMPLETE)
465 {
466 lan_set_in_progress = SET_COMPLETE;
467
468 log<level::INFO>("Network data from Cache",
469 entry("PREFIX=%s", channelConfig.netmask.c_str()),
470 entry("ADDRESS=%s", channelConfig.ipaddr.c_str()),
Ratan Gupta533d03b2017-07-30 10:39:22 +0530471 entry("GATEWAY=%s", channelConfig.gateway.c_str()),
472 entry("VLAN=%d", channelConfig.vlanID));
Ratan Guptab8e99552017-07-27 07:07:48 +0530473
474 log<level::INFO>("Use Set Channel Access command to apply");
475
476 }
477 else if (reqptr->data[0] == SET_IN_PROGRESS) // Set In Progress
478 {
479 lan_set_in_progress = SET_IN_PROGRESS;
480 }
481
482 }
483 break;
484
485 default:
486 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530487 rc = IPMI_CC_PARM_NOT_SUPPORTED;
488 }
489
490 }
vishwa1eaea4f2016-02-26 11:57:40 -0600491
tomjose26e17732016-03-03 08:52:51 -0600492 return rc;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500493}
494
Ratan Guptab8e99552017-07-27 07:07:48 +0530495struct get_lan_t
496{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500497 uint8_t rev_channel;
498 uint8_t parameter;
499 uint8_t parameter_set;
500 uint8_t parameter_block;
Ratan Guptab8e99552017-07-27 07:07:48 +0530501} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500502
Ratan Guptab8e99552017-07-27 07:07:48 +0530503ipmi_ret_t ipmi_transport_get_lan(ipmi_netfn_t netfn,
504 ipmi_cmd_t cmd,
505 ipmi_request_t request,
506 ipmi_response_t response,
507 ipmi_data_len_t data_len,
508 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500509{
510 ipmi_ret_t rc = IPMI_CC_OK;
511 *data_len = 0;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500512 const uint8_t current_revision = 0x11; // Current rev per IPMI Spec 2.0
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500513
514 get_lan_t *reqptr = (get_lan_t*) request;
515
516 if (reqptr->rev_channel & 0x80) // Revision is bit 7
517 {
518 // Only current revision was requested
519 *data_len = sizeof(current_revision);
520 memcpy(response, &current_revision, *data_len);
521 return IPMI_CC_OK;
522 }
523
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600524 if (reqptr->parameter == LAN_PARM_INPROGRESS)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500525 {
tomjose26e17732016-03-03 08:52:51 -0600526 uint8_t buf[] = {current_revision, lan_set_in_progress};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500527 *data_len = sizeof(buf);
528 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500529 }
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600530 else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500531 {
532 uint8_t buf[] = {current_revision,0x04};
533 *data_len = sizeof(buf);
534 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500535 }
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600536 else if (reqptr->parameter == LAN_PARM_AUTHENABLES)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500537 {
538 uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04};
539 *data_len = sizeof(buf);
540 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500541 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530542 else if ((reqptr->parameter == LAN_PARM_IP) ||
543 (reqptr->parameter == LAN_PARM_SUBNET) ||
544 (reqptr->parameter == LAN_PARM_GATEWAY) ||
545 (reqptr->parameter == LAN_PARM_MAC))
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500546 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530547 uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500548
tomjose26e17732016-03-03 08:52:51 -0600549 *data_len = sizeof(current_revision);
550 memcpy(buf, &current_revision, *data_len);
551
Ratan Guptab8e99552017-07-27 07:07:48 +0530552 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
vishwa1eaea4f2016-02-26 11:57:40 -0600553 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530554 if (reqptr->parameter == LAN_PARM_MAC)
555 {
556 *data_len = sizeof(buf);
557 }
558 else
559 {
560 *data_len = ipmi::network::IPV4_ADDRESS_SIZE_BYTE + 1;
561 }
tomjose26e17732016-03-03 08:52:51 -0600562 memcpy(response, &buf, *data_len);
Adriana Kobylak342df102016-02-10 13:48:16 -0600563 }
tomjose26e17732016-03-03 08:52:51 -0600564 else
Hariharasubramanian R83951912016-01-20 07:06:36 -0600565 {
tomjose26e17732016-03-03 08:52:51 -0600566 rc = IPMI_CC_UNSPECIFIED_ERROR;
Hariharasubramanian R83951912016-01-20 07:06:36 -0600567 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500568 }
Ratan Gupta533d03b2017-07-30 10:39:22 +0530569 else if (reqptr->parameter == LAN_PARM_VLAN)
570 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530571 uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {};
Ratan Gupta533d03b2017-07-30 10:39:22 +0530572
573 *data_len = sizeof(current_revision);
574 memcpy(buf, &current_revision, *data_len);
575 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
576 {
577 *data_len = sizeof(buf);
578 memcpy(response, &buf, *data_len);
579 }
580 }
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530581 else if (reqptr->parameter == LAN_PARM_IPSRC)
582 {
583 uint8_t buff[ipmi::network::IPSRC_SIZE_BYTE + 1] = {};
584 *data_len = sizeof(current_revision);
585 memcpy(buff, &current_revision, *data_len);
586 if (getNetworkData(reqptr->parameter, &buff[1]) == IPMI_CC_OK)
587 {
588 *data_len = sizeof(buff);
589 memcpy(response, &buff, *data_len);
590 }
591 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500592 else
593 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530594 log<level::ERR>("Unsupported parameter",
595 entry("PARAMETER=0x%x", reqptr->parameter));
vishwa1eaea4f2016-02-26 11:57:40 -0600596 rc = IPMI_CC_PARM_NOT_SUPPORTED;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500597 }
598
599 return rc;
600}
601
602void register_netfn_transport_functions()
603{
Tom05732372016-09-06 17:21:23 +0530604 // <Wildcard Command>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500605 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_WILDCARD);
Tom05732372016-09-06 17:21:23 +0530606 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard,
607 PRIVILEGE_USER);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500608
Tom05732372016-09-06 17:21:23 +0530609 // <Set LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500610 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_SET_LAN);
Tom05732372016-09-06 17:21:23 +0530611 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan,
612 PRIVILEGE_ADMIN);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500613
Tom05732372016-09-06 17:21:23 +0530614 // <Get LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500615 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_GET_LAN);
Tom05732372016-09-06 17:21:23 +0530616 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan,
617 PRIVILEGE_OPERATOR);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500618
619 return;
620}