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 | |
| 24 | // OpenBMC System Manager dbus framework |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 25 | const char *obj = "/org/openbmc/NetworkManager/Interface"; |
| 26 | const char *ifc = "org.openbmc.NetworkManager"; |
| 27 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 28 | const char *nwinterface = "eth0"; |
| 29 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 30 | const int SIZE_MAC = 18; //xx:xx:xx:xx:xx:xx |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 31 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 32 | struct ChannelConfig_t channelConfig; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 33 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 34 | const uint8_t SET_COMPLETE = 0; |
| 35 | const uint8_t SET_IN_PROGRESS = 1; |
| 36 | const uint8_t SET_COMMIT_WRITE = 2; //Optional |
| 37 | const uint8_t SET_IN_PROGRESS_RESERVED = 3; //Reserved |
| 38 | |
| 39 | // Status of Set-In-Progress Parameter (# 0) |
| 40 | uint8_t lan_set_in_progress = SET_COMPLETE; |
| 41 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 42 | using namespace phosphor::logging; |
| 43 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 44 | namespace fs = std::experimental::filesystem; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 45 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 46 | void register_netfn_transport_functions() __attribute__((constructor)); |
| 47 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 48 | // 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] | 49 | // Cache based on Set-In-Progress State |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 50 | ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t* data) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 51 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 52 | ipmi_ret_t rc = IPMI_CC_OK; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 53 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 54 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 55 | try |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 56 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 57 | switch (lan_param) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 58 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 59 | case LAN_PARM_IP: |
| 60 | { |
| 61 | std::string ipaddress; |
| 62 | if (lan_set_in_progress == SET_COMPLETE) |
| 63 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 64 | try |
| 65 | { |
Nagaraju Goruganti | 1fe5c83 | 2017-09-21 07:44:17 -0500 | [diff] [blame] | 66 | ipaddress = ipmi::getIPAddress(bus, |
| 67 | ipmi::network::IP_INTERFACE, |
| 68 | ipmi::network::ROOT, |
| 69 | ipmi::network::IP_TYPE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 70 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 71 | } |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 78 | } |
| 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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 89 | case LAN_PARM_IPSRC: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 90 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 91 | std::string networkInterfacePath; |
| 92 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 93 | if (lan_set_in_progress == SET_COMPLETE) |
| 94 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 95 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 105 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 106 | // 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 112 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 113 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 197 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 203 | } |
| 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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 214 | try |
| 215 | { |
| 216 | auto systemObject = ipmi::getDbusObject( |
| 217 | bus, |
| 218 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 219 | ipmi::network::ROOT); |
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 | auto systemProperties = ipmi::getAllDbusProperties( |
| 222 | bus, |
| 223 | systemObject.second, |
| 224 | systemObject.first, |
| 225 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 226 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 227 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 236 | |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 245 | } |
| 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 283 | case LAN_PARM_VLAN: |
| 284 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 285 | uint16_t vlanID {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 286 | if (lan_set_in_progress == SET_COMPLETE) |
| 287 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 288 | try |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 289 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 290 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 312 | } |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 324 | default: |
| 325 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 326 | } |
| 327 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 328 | catch (InternalFailure& e) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 329 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 330 | commit<InternalFailure>(); |
| 331 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 332 | return rc; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 333 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 334 | return rc; |
| 335 | } |
| 336 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 337 | ipmi_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 Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 343 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 344 | *data_len = 0; |
| 345 | return rc; |
| 346 | } |
| 347 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 348 | struct set_lan_t |
| 349 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 350 | uint8_t channel; |
| 351 | uint8_t parameter; |
| 352 | 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] | 353 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 354 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 355 | ipmi_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 361 | { |
| 362 | ipmi_ret_t rc = IPMI_CC_OK; |
| 363 | *data_len = 0; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 364 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 365 | char ipaddr[INET_ADDRSTRLEN]; |
| 366 | char netmask[INET_ADDRSTRLEN]; |
| 367 | char gateway[INET_ADDRSTRLEN]; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 368 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 369 | auto reqptr = reinterpret_cast<const set_lan_t*>(request); |
| 370 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 371 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 372 | switch (reqptr->parameter) |
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 | case LAN_PARM_IP: |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 375 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 376 | snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 377 | reqptr->data[0], reqptr->data[1], |
| 378 | reqptr->data[2], reqptr->data[3]); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 379 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 380 | channelConfig.ipaddr.assign(ipaddr); |
| 381 | |
| 382 | } |
| 383 | break; |
| 384 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 385 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 393 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 442 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 454 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 463 | entry("GATEWAY=%s", channelConfig.gateway.c_str()), |
| 464 | entry("VLAN=%d", channelConfig.vlanID)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 465 | |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 479 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
| 480 | } |
| 481 | |
| 482 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 483 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 484 | return rc; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 485 | } |
| 486 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 487 | struct get_lan_t |
| 488 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 489 | uint8_t rev_channel; |
| 490 | uint8_t parameter; |
| 491 | uint8_t parameter_set; |
| 492 | uint8_t parameter_block; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 493 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 494 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 495 | ipmi_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 501 | { |
| 502 | ipmi_ret_t rc = IPMI_CC_OK; |
| 503 | *data_len = 0; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 504 | 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] | 505 | |
| 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, ¤t_revision, *data_len); |
| 513 | return IPMI_CC_OK; |
| 514 | } |
| 515 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 516 | if (reqptr->parameter == LAN_PARM_INPROGRESS) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 517 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 518 | uint8_t buf[] = {current_revision, lan_set_in_progress}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 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_AUTHSUPPORT) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 523 | { |
| 524 | uint8_t buf[] = {current_revision,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 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 528 | else if (reqptr->parameter == LAN_PARM_AUTHENABLES) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 529 | { |
| 530 | uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04}; |
| 531 | *data_len = sizeof(buf); |
| 532 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 533 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 534 | 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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 538 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 539 | uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 540 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 541 | *data_len = sizeof(current_revision); |
| 542 | memcpy(buf, ¤t_revision, *data_len); |
| 543 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 544 | if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 545 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 546 | 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 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 554 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 342df10 | 2016-02-10 13:48:16 -0600 | [diff] [blame] | 555 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 556 | else |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 557 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 558 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 559 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 560 | } |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 561 | else if (reqptr->parameter == LAN_PARM_VLAN) |
| 562 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 563 | uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 564 | |
| 565 | *data_len = sizeof(current_revision); |
| 566 | memcpy(buf, ¤t_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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 573 | 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, ¤t_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 584 | else |
| 585 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 586 | log<level::ERR>("Unsupported parameter", |
| 587 | entry("PARAMETER=0x%x", reqptr->parameter)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 588 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | return rc; |
| 592 | } |
| 593 | |
| 594 | void register_netfn_transport_functions() |
| 595 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 596 | // <Wildcard Command> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 597 | 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] | 598 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard, |
| 599 | PRIVILEGE_USER); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 600 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 601 | // <Set LAN Configuration Parameters> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 602 | 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] | 603 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan, |
| 604 | PRIVILEGE_ADMIN); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 605 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 606 | // <Get LAN Configuration Parameters> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 607 | 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] | 608 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan, |
| 609 | PRIVILEGE_OPERATOR); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 610 | |
| 611 | return; |
| 612 | } |