Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdint.h> |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 4 | #include <arpa/inet.h> |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 5 | #include <string> |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 6 | #include <experimental/filesystem> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 7 | |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 8 | #include "host-ipmid/ipmid-api.h" |
Patrick Williams | 53a360e | 2016-08-12 22:01:02 -0500 | [diff] [blame] | 9 | #include "ipmid.hpp" |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 10 | #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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 16 | |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 17 | #define SYSTEMD_NETWORKD_DBUS 1 |
| 18 | |
| 19 | #ifdef SYSTEMD_NETWORKD_DBUS |
| 20 | #include <systemd/sd-bus.h> |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 21 | #include <mapper.h> |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 22 | #endif |
| 23 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 24 | const int SIZE_MAC = 18; //xx:xx:xx:xx:xx:xx |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 25 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 26 | struct ChannelConfig_t channelConfig; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 27 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 28 | const uint8_t SET_COMPLETE = 0; |
| 29 | const uint8_t SET_IN_PROGRESS = 1; |
| 30 | const uint8_t SET_COMMIT_WRITE = 2; //Optional |
| 31 | const uint8_t SET_IN_PROGRESS_RESERVED = 3; //Reserved |
| 32 | |
| 33 | // Status of Set-In-Progress Parameter (# 0) |
| 34 | uint8_t lan_set_in_progress = SET_COMPLETE; |
| 35 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 36 | using namespace phosphor::logging; |
| 37 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 38 | namespace fs = std::experimental::filesystem; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 39 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 40 | void register_netfn_transport_functions() __attribute__((constructor)); |
| 41 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 42 | // Helper Function to get IP Address/NetMask/Gateway/MAC Address from Network Manager or |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 43 | // Cache based on Set-In-Progress State |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 44 | ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t* data) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 45 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 46 | ipmi_ret_t rc = IPMI_CC_OK; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 47 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 48 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 49 | try |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 50 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 51 | switch (lan_param) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 52 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 53 | case LAN_PARM_IP: |
| 54 | { |
| 55 | std::string ipaddress; |
| 56 | if (lan_set_in_progress == SET_COMPLETE) |
| 57 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 58 | try |
| 59 | { |
Nagaraju Goruganti | 1fe5c83 | 2017-09-21 07:44:17 -0500 | [diff] [blame] | 60 | ipaddress = ipmi::getIPAddress(bus, |
| 61 | ipmi::network::IP_INTERFACE, |
| 62 | ipmi::network::ROOT, |
| 63 | ipmi::network::IP_TYPE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 64 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 65 | } |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 72 | } |
| 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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 83 | case LAN_PARM_IPSRC: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 84 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 85 | std::string networkInterfacePath; |
| 86 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 87 | if (lan_set_in_progress == SET_COMPLETE) |
| 88 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 89 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 99 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 100 | // 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 106 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 107 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 191 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 197 | } |
| 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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 208 | try |
| 209 | { |
| 210 | auto systemObject = ipmi::getDbusObject( |
| 211 | bus, |
| 212 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 213 | ipmi::network::ROOT); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 214 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 215 | auto systemProperties = ipmi::getAllDbusProperties( |
| 216 | bus, |
| 217 | systemObject.second, |
| 218 | systemObject.first, |
| 219 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 220 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 221 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 230 | |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 239 | } |
| 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 277 | case LAN_PARM_VLAN: |
| 278 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 279 | uint16_t vlanID {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 280 | if (lan_set_in_progress == SET_COMPLETE) |
| 281 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 282 | try |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 283 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 284 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 306 | } |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 318 | default: |
| 319 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 320 | } |
| 321 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 322 | catch (InternalFailure& e) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 323 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 324 | commit<InternalFailure>(); |
| 325 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 326 | return rc; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 327 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 328 | return rc; |
| 329 | } |
| 330 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 331 | ipmi_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 Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 337 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 338 | *data_len = 0; |
| 339 | return rc; |
| 340 | } |
| 341 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 342 | struct set_lan_t |
| 343 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 344 | uint8_t channel; |
| 345 | uint8_t parameter; |
| 346 | uint8_t data[8]; // Per IPMI spec, not expecting more than this size |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 347 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 348 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 349 | ipmi_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 355 | { |
| 356 | ipmi_ret_t rc = IPMI_CC_OK; |
| 357 | *data_len = 0; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 358 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 359 | char ipaddr[INET_ADDRSTRLEN]; |
| 360 | char netmask[INET_ADDRSTRLEN]; |
| 361 | char gateway[INET_ADDRSTRLEN]; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 362 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 363 | auto reqptr = reinterpret_cast<const set_lan_t*>(request); |
| 364 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 365 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 366 | switch (reqptr->parameter) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 367 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 368 | case LAN_PARM_IP: |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 369 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 370 | snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 371 | reqptr->data[0], reqptr->data[1], |
| 372 | reqptr->data[2], reqptr->data[3]); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 373 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 374 | channelConfig.ipaddr.assign(ipaddr); |
| 375 | |
| 376 | } |
| 377 | break; |
| 378 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 379 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 387 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 436 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 448 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 457 | entry("GATEWAY=%s", channelConfig.gateway.c_str()), |
| 458 | entry("VLAN=%d", channelConfig.vlanID)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 459 | |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 473 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
| 474 | } |
| 475 | |
| 476 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 477 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 478 | return rc; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 479 | } |
| 480 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 481 | struct get_lan_t |
| 482 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 483 | uint8_t rev_channel; |
| 484 | uint8_t parameter; |
| 485 | uint8_t parameter_set; |
| 486 | uint8_t parameter_block; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 487 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 488 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 489 | ipmi_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 495 | { |
| 496 | ipmi_ret_t rc = IPMI_CC_OK; |
| 497 | *data_len = 0; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 498 | const uint8_t current_revision = 0x11; // Current rev per IPMI Spec 2.0 |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 499 | |
| 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, ¤t_revision, *data_len); |
| 507 | return IPMI_CC_OK; |
| 508 | } |
| 509 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 510 | if (reqptr->parameter == LAN_PARM_INPROGRESS) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 511 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 512 | uint8_t buf[] = {current_revision, lan_set_in_progress}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 513 | *data_len = sizeof(buf); |
| 514 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 515 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 516 | else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 517 | { |
| 518 | uint8_t buf[] = {current_revision,0x04}; |
| 519 | *data_len = sizeof(buf); |
| 520 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 521 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 522 | else if (reqptr->parameter == LAN_PARM_AUTHENABLES) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 523 | { |
| 524 | uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04}; |
| 525 | *data_len = sizeof(buf); |
| 526 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 527 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 528 | 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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 532 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 533 | uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 534 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 535 | *data_len = sizeof(current_revision); |
| 536 | memcpy(buf, ¤t_revision, *data_len); |
| 537 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 538 | if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 539 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 540 | 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 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 548 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 342df10 | 2016-02-10 13:48:16 -0600 | [diff] [blame] | 549 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 550 | else |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 551 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 552 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 553 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 554 | } |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 555 | else if (reqptr->parameter == LAN_PARM_VLAN) |
| 556 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 557 | uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 558 | |
| 559 | *data_len = sizeof(current_revision); |
| 560 | memcpy(buf, ¤t_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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 567 | 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, ¤t_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 578 | else |
| 579 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 580 | log<level::ERR>("Unsupported parameter", |
| 581 | entry("PARAMETER=0x%x", reqptr->parameter)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 582 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | return rc; |
| 586 | } |
| 587 | |
| 588 | void register_netfn_transport_functions() |
| 589 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 590 | // <Wildcard Command> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 591 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_WILDCARD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 592 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard, |
| 593 | PRIVILEGE_USER); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 594 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 595 | // <Set LAN Configuration Parameters> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 596 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_SET_LAN); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 597 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan, |
| 598 | PRIVILEGE_ADMIN); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 599 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 600 | // <Get LAN Configuration Parameters> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 601 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_GET_LAN); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 602 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan, |
| 603 | PRIVILEGE_OPERATOR); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 604 | |
| 605 | return; |
| 606 | } |