blob: a90891a86fa534d328682f64baa0ff26fea71af0 [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
Ratan Guptab8e99552017-07-27 07:07:48 +053028using namespace phosphor::logging;
29using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053030namespace fs = std::experimental::filesystem;
Hariharasubramanian R83951912016-01-20 07:06:36 -060031
Adriana Kobylak5d6481f2015-10-29 21:44:55 -050032void register_netfn_transport_functions() __attribute__((constructor));
33
Ratan Guptab8e99552017-07-27 07:07:48 +053034// Helper Function to get IP Address/NetMask/Gateway/MAC Address from Network Manager or
Nan Li3d0df912016-10-18 19:51:41 +080035// Cache based on Set-In-Progress State
Ratan Guptab8e99552017-07-27 07:07:48 +053036ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t* data)
tomjose26e17732016-03-03 08:52:51 -060037{
tomjose26e17732016-03-03 08:52:51 -060038 ipmi_ret_t rc = IPMI_CC_OK;
Ratan Guptab8e99552017-07-27 07:07:48 +053039 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Ratan Gupta533d03b2017-07-30 10:39:22 +053040
Ratan Guptab8e99552017-07-27 07:07:48 +053041 try
tomjose26e17732016-03-03 08:52:51 -060042 {
Ratan Guptab8e99552017-07-27 07:07:48 +053043 switch (lan_param)
tomjose26e17732016-03-03 08:52:51 -060044 {
Ratan Guptab8e99552017-07-27 07:07:48 +053045 case LAN_PARM_IP:
46 {
47 std::string ipaddress;
Patrick Venture585a1e92017-11-17 07:36:15 -080048 if (channelConfig.lan_set_in_progress == SET_COMPLETE)
Ratan Guptab8e99552017-07-27 07:07:48 +053049 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053050 try
51 {
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -050052 ipaddress = ipmi::getIPAddress(bus,
53 ipmi::network::IP_INTERFACE,
54 ipmi::network::ROOT,
55 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +053056
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053057 }
58 // ignore the exception, as it is a valid condtion that
59 // system is not confiured with any ip.
60 catch (InternalFailure& e)
61 {
62 // nothing to do.
63 }
Ratan Guptab8e99552017-07-27 07:07:48 +053064 }
Patrick Venture585a1e92017-11-17 07:36:15 -080065 else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS)
Ratan Guptab8e99552017-07-27 07:07:48 +053066 {
67 ipaddress = channelConfig.ipaddr;
68 }
69
70 inet_pton(AF_INET, ipaddress.c_str(),
71 reinterpret_cast<void*>(data));
72 }
73 break;
74
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053075 case LAN_PARM_IPSRC:
Ratan Guptab8e99552017-07-27 07:07:48 +053076 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053077 std::string networkInterfacePath;
78
Patrick Venture585a1e92017-11-17 07:36:15 -080079 if (channelConfig.lan_set_in_progress == SET_COMPLETE)
Ratan Guptab8e99552017-07-27 07:07:48 +053080 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053081 try
82 {
83 ipmi::ObjectTree ancestorMap;
84 // if the system is having ip object,then
85 // get the IP object.
86 auto ipObject = ipmi::getDbusObject(
87 bus,
88 ipmi::network::IP_INTERFACE,
89 ipmi::network::ROOT,
90 ipmi::network::IP_TYPE);
Ratan Guptab8e99552017-07-27 07:07:48 +053091
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053092 // Get the parent interface of the IP object.
93 try
94 {
95 ipmi::InterfaceList interfaces;
96 interfaces.emplace_back(
97 ipmi::network::ETHERNET_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +053098
Ratan Guptacc6cdbf2017-09-01 23:06:25 +053099 ancestorMap = ipmi::getAllAncestors(
100 bus,
101 ipObject.first,
102 std::move(interfaces));
103 }
104 catch (InternalFailure& e)
105 {
106 // if unable to get the parent interface
107 // then commit the error and return.
108 log<level::ERR>("Unable to get the parent interface",
109 entry("PATH=%s", ipObject.first.c_str()),
110 entry("INTERFACE=%s",
111 ipmi::network::ETHERNET_INTERFACE));
112 break;
113
114 }
115 // for an ip object there would be single parent
116 // interface.
117 networkInterfacePath = ancestorMap.begin()->first;
118 }
119 catch (InternalFailure& e)
120 {
121 // if there is no ip configured on the system,then
122 // get the network interface object.
123 auto networkInterfaceObject = ipmi::getDbusObject(
124 bus,
125 ipmi::network::ETHERNET_INTERFACE,
126 ipmi::network::ROOT,
127 ipmi::network::INTERFACE);
128
129 networkInterfacePath = networkInterfaceObject.first;
130 }
131
132 auto variant = ipmi::getDbusProperty(
133 bus,
134 ipmi::network::SERVICE,
135 networkInterfacePath,
136 ipmi::network::ETHERNET_INTERFACE,
137 "DHCPEnabled");
138
139 auto dhcpEnabled = variant.get<bool>();
140 // As per IPMI spec 2=>DHCP, 1=STATIC
141 auto ipsrc = dhcpEnabled ? ipmi::network::IPOrigin::DHCP :
142 ipmi::network::IPOrigin::STATIC;
143
144 memcpy(data, &ipsrc, ipmi::network::IPSRC_SIZE_BYTE);
145 }
Patrick Venture585a1e92017-11-17 07:36:15 -0800146 else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS)
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530147 {
148 memcpy(data, &(channelConfig.ipsrc),
149 ipmi::network::IPSRC_SIZE_BYTE);
150 }
151 }
152 break;
153
154 case LAN_PARM_SUBNET:
155 {
156 unsigned long mask {};
Patrick Venture585a1e92017-11-17 07:36:15 -0800157 if (channelConfig.lan_set_in_progress == SET_COMPLETE)
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530158 {
159 try
160 {
161 auto ipObjectInfo = ipmi::getDbusObject(
162 bus,
163 ipmi::network::IP_INTERFACE,
164 ipmi::network::ROOT,
165 ipmi::network::IP_TYPE);
166
167 auto properties = ipmi::getAllDbusProperties(
168 bus,
169 ipObjectInfo.second,
170 ipObjectInfo.first,
171 ipmi::network::IP_INTERFACE);
172
173 auto prefix = properties["PrefixLength"].get<uint8_t>();
174 mask = ipmi::network::MASK_32_BIT;
175 mask = htonl(mask << (ipmi::network::BITS_32 - prefix));
176 }
177 // ignore the exception, as it is a valid condtion that
178 // system is not confiured with any ip.
179 catch (InternalFailure& e)
180 {
181 // nothing to do
182 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530183 memcpy(data, &mask, ipmi::network::IPV4_ADDRESS_SIZE_BYTE);
184 }
Patrick Venture585a1e92017-11-17 07:36:15 -0800185 else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS)
Ratan Guptab8e99552017-07-27 07:07:48 +0530186 {
187 inet_pton(AF_INET, channelConfig.netmask.c_str(),
188 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530189 }
190
191 }
192 break;
193
194 case LAN_PARM_GATEWAY:
195 {
196 std::string gateway;
197
Patrick Venture585a1e92017-11-17 07:36:15 -0800198 if (channelConfig.lan_set_in_progress == SET_COMPLETE)
Ratan Guptab8e99552017-07-27 07:07:48 +0530199 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530200 try
201 {
202 auto systemObject = ipmi::getDbusObject(
203 bus,
204 ipmi::network::SYSTEMCONFIG_INTERFACE,
205 ipmi::network::ROOT);
Ratan Guptab8e99552017-07-27 07:07:48 +0530206
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530207 auto systemProperties = ipmi::getAllDbusProperties(
208 bus,
209 systemObject.second,
210 systemObject.first,
211 ipmi::network::SYSTEMCONFIG_INTERFACE);
Ratan Guptab8e99552017-07-27 07:07:48 +0530212
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530213 gateway = systemProperties["DefaultGateway"].get<
214 std::string>();
215 }
216 // ignore the exception, as it is a valid condtion that
217 // system is not confiured with any ip.
218 catch (InternalFailure& e)
219 {
220 // nothing to do
221 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530222
223 }
Patrick Venture585a1e92017-11-17 07:36:15 -0800224 else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS)
Ratan Guptab8e99552017-07-27 07:07:48 +0530225 {
226 gateway = channelConfig.gateway;
227 }
228
229 inet_pton(AF_INET, gateway.c_str(),
230 reinterpret_cast<void*>(data));
Ratan Guptab8e99552017-07-27 07:07:48 +0530231 }
232 break;
233
234 case LAN_PARM_MAC:
235 {
236 std::string macAddress;
Patrick Venture585a1e92017-11-17 07:36:15 -0800237 if (channelConfig.lan_set_in_progress == SET_COMPLETE)
Ratan Guptab8e99552017-07-27 07:07:48 +0530238 {
239 auto macObjectInfo = ipmi::getDbusObject(
240 bus,
241 ipmi::network::MAC_INTERFACE,
242 ipmi::network::ROOT);
243
244 auto variant = ipmi::getDbusProperty(
245 bus,
246 macObjectInfo.second,
247 macObjectInfo.first,
248 ipmi::network::MAC_INTERFACE,
249 "MACAddress");
250
251 macAddress = variant.get<std::string>();
252
253 }
Patrick Venture585a1e92017-11-17 07:36:15 -0800254 else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS)
Ratan Guptab8e99552017-07-27 07:07:48 +0530255 {
256 macAddress = channelConfig.macAddress;
257 }
258
259 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
260 (data),
261 (data + 1),
262 (data + 2),
263 (data + 3),
264 (data + 4),
265 (data + 5));
266 }
267 break;
268
Ratan Gupta533d03b2017-07-30 10:39:22 +0530269 case LAN_PARM_VLAN:
270 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530271 uint16_t vlanID {};
Patrick Venture585a1e92017-11-17 07:36:15 -0800272 if (channelConfig.lan_set_in_progress == SET_COMPLETE)
Ratan Gupta533d03b2017-07-30 10:39:22 +0530273 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530274 try
Ratan Gupta533d03b2017-07-30 10:39:22 +0530275 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530276 auto ipObjectInfo = ipmi::getDbusObject(
277 bus,
278 ipmi::network::IP_INTERFACE,
279 ipmi::network::ROOT,
280 ipmi::network::IP_TYPE);
281
282 vlanID = static_cast<uint16_t>(
283 ipmi::network::getVLAN(ipObjectInfo.first));
284
285 vlanID = htole16(vlanID);
286
287 if (vlanID)
288 {
289 //Enable the 16th bit
290 vlanID |= htole16(ipmi::network::VLAN_ENABLE_MASK);
291 }
292 }
293 // ignore the exception, as it is a valid condtion that
294 // system is not confiured with any ip.
295 catch (InternalFailure& e)
296 {
297 // nothing to do
Ratan Gupta533d03b2017-07-30 10:39:22 +0530298 }
299
300 memcpy(data, &vlanID, ipmi::network::VLAN_SIZE_BYTE);
301 }
Patrick Venture585a1e92017-11-17 07:36:15 -0800302 else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS)
Ratan Gupta533d03b2017-07-30 10:39:22 +0530303 {
304 memcpy(data, &(channelConfig.vlanID),
305 ipmi::network::VLAN_SIZE_BYTE);
306 }
307 }
308 break;
309
Ratan Guptab8e99552017-07-27 07:07:48 +0530310 default:
311 rc = IPMI_CC_PARM_OUT_OF_RANGE;
tomjose26e17732016-03-03 08:52:51 -0600312 }
313 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530314 catch (InternalFailure& e)
tomjose26e17732016-03-03 08:52:51 -0600315 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530316 commit<InternalFailure>();
317 rc = IPMI_CC_UNSPECIFIED_ERROR;
318 return rc;
tomjose26e17732016-03-03 08:52:51 -0600319 }
tomjose26e17732016-03-03 08:52:51 -0600320 return rc;
321}
322
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500323ipmi_ret_t ipmi_transport_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
324 ipmi_request_t request, ipmi_response_t response,
325 ipmi_data_len_t data_len, ipmi_context_t context)
326{
327 printf("Handling TRANSPORT WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
328 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800329 ipmi_ret_t rc = IPMI_CC_INVALID;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500330 *data_len = 0;
331 return rc;
332}
333
Ratan Guptab8e99552017-07-27 07:07:48 +0530334struct set_lan_t
335{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500336 uint8_t channel;
337 uint8_t parameter;
338 uint8_t data[8]; // Per IPMI spec, not expecting more than this size
Ratan Guptab8e99552017-07-27 07:07:48 +0530339} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500340
Ratan Guptab8e99552017-07-27 07:07:48 +0530341ipmi_ret_t ipmi_transport_set_lan(ipmi_netfn_t netfn,
342 ipmi_cmd_t cmd,
343 ipmi_request_t request,
344 ipmi_response_t response,
345 ipmi_data_len_t data_len,
346 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500347{
348 ipmi_ret_t rc = IPMI_CC_OK;
349 *data_len = 0;
Nan Li3d0df912016-10-18 19:51:41 +0800350
Ratan Guptab8e99552017-07-27 07:07:48 +0530351 char ipaddr[INET_ADDRSTRLEN];
352 char netmask[INET_ADDRSTRLEN];
353 char gateway[INET_ADDRSTRLEN];
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500354
Ratan Guptab8e99552017-07-27 07:07:48 +0530355 auto reqptr = reinterpret_cast<const set_lan_t*>(request);
356 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500357
Ratan Guptab8e99552017-07-27 07:07:48 +0530358 switch (reqptr->parameter)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500359 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530360 case LAN_PARM_IP:
Hariharasubramanian R83951912016-01-20 07:06:36 -0600361 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530362 snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
363 reqptr->data[0], reqptr->data[1],
364 reqptr->data[2], reqptr->data[3]);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500365
Ratan Guptab8e99552017-07-27 07:07:48 +0530366 channelConfig.ipaddr.assign(ipaddr);
367
368 }
369 break;
370
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530371 case LAN_PARM_IPSRC:
372 {
373 uint8_t ipsrc{};
374 memcpy(&ipsrc, reqptr->data, ipmi::network::IPSRC_SIZE_BYTE);
375 channelConfig.ipsrc = static_cast<ipmi::network::IPOrigin>(ipsrc);
376 }
377 break;
378
Ratan Guptab8e99552017-07-27 07:07:48 +0530379 case LAN_PARM_MAC:
380 {
381 char mac[SIZE_MAC];
382
383 snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
384 reqptr->data[0],
385 reqptr->data[1],
386 reqptr->data[2],
387 reqptr->data[3],
388 reqptr->data[4],
389 reqptr->data[5]);
390
391 auto macObjectInfo = ipmi::getDbusObject(
392 bus,
393 ipmi::network::MAC_INTERFACE,
394 ipmi::network::ROOT,
395 ipmi::network::INTERFACE);
396
397 ipmi::setDbusProperty(bus,
398 macObjectInfo.second,
399 macObjectInfo.first,
400 ipmi::network::MAC_INTERFACE,
401 "MACAddress",
402 std::string(mac));
403
404 channelConfig.macAddress = mac;
405
406 }
407 break;
408
409 case LAN_PARM_SUBNET:
410 {
411 snprintf(netmask, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
412 reqptr->data[0], reqptr->data[1],
413 reqptr->data[2], reqptr->data[3]);
414 channelConfig.netmask.assign(netmask);
415 }
416 break;
417
418 case LAN_PARM_GATEWAY:
419 {
420 snprintf(gateway, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT,
421 reqptr->data[0], reqptr->data[1],
422 reqptr->data[2], reqptr->data[3]);
423 channelConfig.gateway.assign(gateway);
424
425 }
426 break;
427
Ratan Gupta533d03b2017-07-30 10:39:22 +0530428 case LAN_PARM_VLAN:
429 {
430 uint16_t vlan {};
431 memcpy(&vlan, reqptr->data, ipmi::network::VLAN_SIZE_BYTE);
432 // We are not storing the enable bit
433 // We assume that ipmitool always send enable
434 // bit as 1.
435 vlan = le16toh(vlan);
436 channelConfig.vlanID = vlan;
437 }
438 break;
439
Ratan Guptab8e99552017-07-27 07:07:48 +0530440 case LAN_PARM_INPROGRESS:
441 {
442 if (reqptr->data[0] == SET_COMPLETE)
443 {
Patrick Venture585a1e92017-11-17 07:36:15 -0800444 channelConfig.lan_set_in_progress = SET_COMPLETE;
Ratan Guptab8e99552017-07-27 07:07:48 +0530445
446 log<level::INFO>("Network data from Cache",
447 entry("PREFIX=%s", channelConfig.netmask.c_str()),
448 entry("ADDRESS=%s", channelConfig.ipaddr.c_str()),
Ratan Gupta533d03b2017-07-30 10:39:22 +0530449 entry("GATEWAY=%s", channelConfig.gateway.c_str()),
450 entry("VLAN=%d", channelConfig.vlanID));
Ratan Guptab8e99552017-07-27 07:07:48 +0530451
452 log<level::INFO>("Use Set Channel Access command to apply");
453
454 }
455 else if (reqptr->data[0] == SET_IN_PROGRESS) // Set In Progress
456 {
Patrick Venture585a1e92017-11-17 07:36:15 -0800457 channelConfig.lan_set_in_progress = SET_IN_PROGRESS;
Ratan Guptab8e99552017-07-27 07:07:48 +0530458 }
459
460 }
461 break;
462
463 default:
464 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530465 rc = IPMI_CC_PARM_NOT_SUPPORTED;
466 }
467
468 }
vishwa1eaea4f2016-02-26 11:57:40 -0600469
tomjose26e17732016-03-03 08:52:51 -0600470 return rc;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500471}
472
Ratan Guptab8e99552017-07-27 07:07:48 +0530473struct get_lan_t
474{
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500475 uint8_t rev_channel;
476 uint8_t parameter;
477 uint8_t parameter_set;
478 uint8_t parameter_block;
Ratan Guptab8e99552017-07-27 07:07:48 +0530479} __attribute__((packed));
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500480
Ratan Guptab8e99552017-07-27 07:07:48 +0530481ipmi_ret_t ipmi_transport_get_lan(ipmi_netfn_t netfn,
482 ipmi_cmd_t cmd,
483 ipmi_request_t request,
484 ipmi_response_t response,
485 ipmi_data_len_t data_len,
486 ipmi_context_t context)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500487{
488 ipmi_ret_t rc = IPMI_CC_OK;
489 *data_len = 0;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500490 const uint8_t current_revision = 0x11; // Current rev per IPMI Spec 2.0
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500491
492 get_lan_t *reqptr = (get_lan_t*) request;
493
494 if (reqptr->rev_channel & 0x80) // Revision is bit 7
495 {
496 // Only current revision was requested
497 *data_len = sizeof(current_revision);
498 memcpy(response, &current_revision, *data_len);
499 return IPMI_CC_OK;
500 }
501
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600502 if (reqptr->parameter == LAN_PARM_INPROGRESS)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500503 {
Patrick Venture585a1e92017-11-17 07:36:15 -0800504 uint8_t buf[] = {current_revision, channelConfig.lan_set_in_progress};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500505 *data_len = sizeof(buf);
506 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500507 }
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600508 else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500509 {
510 uint8_t buf[] = {current_revision,0x04};
511 *data_len = sizeof(buf);
512 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500513 }
Adriana Kobylake08fbc62016-02-09 16:17:23 -0600514 else if (reqptr->parameter == LAN_PARM_AUTHENABLES)
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500515 {
516 uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04};
517 *data_len = sizeof(buf);
518 memcpy(response, &buf, *data_len);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500519 }
Ratan Guptab8e99552017-07-27 07:07:48 +0530520 else if ((reqptr->parameter == LAN_PARM_IP) ||
521 (reqptr->parameter == LAN_PARM_SUBNET) ||
522 (reqptr->parameter == LAN_PARM_GATEWAY) ||
523 (reqptr->parameter == LAN_PARM_MAC))
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500524 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530525 uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {};
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500526
tomjose26e17732016-03-03 08:52:51 -0600527 *data_len = sizeof(current_revision);
528 memcpy(buf, &current_revision, *data_len);
529
Ratan Guptab8e99552017-07-27 07:07:48 +0530530 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
vishwa1eaea4f2016-02-26 11:57:40 -0600531 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530532 if (reqptr->parameter == LAN_PARM_MAC)
533 {
534 *data_len = sizeof(buf);
535 }
536 else
537 {
538 *data_len = ipmi::network::IPV4_ADDRESS_SIZE_BYTE + 1;
539 }
tomjose26e17732016-03-03 08:52:51 -0600540 memcpy(response, &buf, *data_len);
Adriana Kobylak342df102016-02-10 13:48:16 -0600541 }
tomjose26e17732016-03-03 08:52:51 -0600542 else
Hariharasubramanian R83951912016-01-20 07:06:36 -0600543 {
tomjose26e17732016-03-03 08:52:51 -0600544 rc = IPMI_CC_UNSPECIFIED_ERROR;
Hariharasubramanian R83951912016-01-20 07:06:36 -0600545 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500546 }
Ratan Gupta533d03b2017-07-30 10:39:22 +0530547 else if (reqptr->parameter == LAN_PARM_VLAN)
548 {
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530549 uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {};
Ratan Gupta533d03b2017-07-30 10:39:22 +0530550
551 *data_len = sizeof(current_revision);
552 memcpy(buf, &current_revision, *data_len);
553 if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK)
554 {
555 *data_len = sizeof(buf);
556 memcpy(response, &buf, *data_len);
557 }
558 }
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530559 else if (reqptr->parameter == LAN_PARM_IPSRC)
560 {
561 uint8_t buff[ipmi::network::IPSRC_SIZE_BYTE + 1] = {};
562 *data_len = sizeof(current_revision);
563 memcpy(buff, &current_revision, *data_len);
564 if (getNetworkData(reqptr->parameter, &buff[1]) == IPMI_CC_OK)
565 {
566 *data_len = sizeof(buff);
567 memcpy(response, &buff, *data_len);
568 }
569 }
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500570 else
571 {
Ratan Guptab8e99552017-07-27 07:07:48 +0530572 log<level::ERR>("Unsupported parameter",
573 entry("PARAMETER=0x%x", reqptr->parameter));
vishwa1eaea4f2016-02-26 11:57:40 -0600574 rc = IPMI_CC_PARM_NOT_SUPPORTED;
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500575 }
576
577 return rc;
578}
579
580void register_netfn_transport_functions()
581{
Tom05732372016-09-06 17:21:23 +0530582 // <Wildcard Command>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500583 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_WILDCARD);
Tom05732372016-09-06 17:21:23 +0530584 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard,
585 PRIVILEGE_USER);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500586
Tom05732372016-09-06 17:21:23 +0530587 // <Set LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500588 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_SET_LAN);
Tom05732372016-09-06 17:21:23 +0530589 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan,
590 PRIVILEGE_ADMIN);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500591
Tom05732372016-09-06 17:21:23 +0530592 // <Get LAN Configuration Parameters>
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500593 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_GET_LAN);
Tom05732372016-09-06 17:21:23 +0530594 ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan,
595 PRIVILEGE_OPERATOR);
Adriana Kobylak5d6481f2015-10-29 21:44:55 -0500596
597 return;
598}