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 | { |
| 66 | auto ipObjectInfo = ipmi::getDbusObject( |
| 67 | bus, |
| 68 | ipmi::network::IP_INTERFACE, |
| 69 | ipmi::network::ROOT, |
| 70 | ipmi::network::IP_TYPE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 71 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 72 | auto properties = ipmi::getAllDbusProperties( |
| 73 | bus, |
| 74 | ipObjectInfo.second, |
| 75 | ipObjectInfo.first, |
| 76 | ipmi::network::IP_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 77 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 78 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 86 | } |
| 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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 97 | case LAN_PARM_IPSRC: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 98 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 99 | std::string networkInterfacePath; |
| 100 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 101 | if (lan_set_in_progress == SET_COMPLETE) |
| 102 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 103 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 113 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 114 | // 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 120 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 121 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 205 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 211 | } |
| 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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 222 | try |
| 223 | { |
| 224 | auto systemObject = ipmi::getDbusObject( |
| 225 | bus, |
| 226 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 227 | ipmi::network::ROOT); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 228 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 229 | auto systemProperties = ipmi::getAllDbusProperties( |
| 230 | bus, |
| 231 | systemObject.second, |
| 232 | systemObject.first, |
| 233 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 234 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 235 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 244 | |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 253 | } |
| 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 291 | case LAN_PARM_VLAN: |
| 292 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 293 | uint16_t vlanID {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 294 | if (lan_set_in_progress == SET_COMPLETE) |
| 295 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 296 | try |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 297 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 298 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 320 | } |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 332 | default: |
| 333 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 334 | } |
| 335 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 336 | catch (InternalFailure& e) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 337 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 338 | commit<InternalFailure>(); |
| 339 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 340 | return rc; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 341 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 342 | return rc; |
| 343 | } |
| 344 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 345 | ipmi_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 Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 351 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 352 | *data_len = 0; |
| 353 | return rc; |
| 354 | } |
| 355 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 356 | struct set_lan_t |
| 357 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 358 | uint8_t channel; |
| 359 | uint8_t parameter; |
| 360 | 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] | 361 | } __attribute__((packed)); |
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 | ipmi_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 369 | { |
| 370 | ipmi_ret_t rc = IPMI_CC_OK; |
| 371 | *data_len = 0; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 372 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 373 | char ipaddr[INET_ADDRSTRLEN]; |
| 374 | char netmask[INET_ADDRSTRLEN]; |
| 375 | char gateway[INET_ADDRSTRLEN]; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 376 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 377 | auto reqptr = reinterpret_cast<const set_lan_t*>(request); |
| 378 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
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 | switch (reqptr->parameter) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 381 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 382 | case LAN_PARM_IP: |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 383 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 384 | snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 385 | reqptr->data[0], reqptr->data[1], |
| 386 | reqptr->data[2], reqptr->data[3]); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 387 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 388 | channelConfig.ipaddr.assign(ipaddr); |
| 389 | |
| 390 | } |
| 391 | break; |
| 392 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 393 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 401 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 450 | 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 462 | 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 471 | entry("GATEWAY=%s", channelConfig.gateway.c_str()), |
| 472 | entry("VLAN=%d", channelConfig.vlanID)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 473 | |
| 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 487 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
| 488 | } |
| 489 | |
| 490 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 491 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 492 | return rc; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 495 | struct get_lan_t |
| 496 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 497 | uint8_t rev_channel; |
| 498 | uint8_t parameter; |
| 499 | uint8_t parameter_set; |
| 500 | uint8_t parameter_block; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 501 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 502 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 503 | ipmi_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 509 | { |
| 510 | ipmi_ret_t rc = IPMI_CC_OK; |
| 511 | *data_len = 0; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 512 | 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] | 513 | |
| 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, ¤t_revision, *data_len); |
| 521 | return IPMI_CC_OK; |
| 522 | } |
| 523 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 524 | if (reqptr->parameter == LAN_PARM_INPROGRESS) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 525 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 526 | uint8_t buf[] = {current_revision, lan_set_in_progress}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 527 | *data_len = sizeof(buf); |
| 528 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 529 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 530 | else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 531 | { |
| 532 | uint8_t buf[] = {current_revision,0x04}; |
| 533 | *data_len = sizeof(buf); |
| 534 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 535 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 536 | else if (reqptr->parameter == LAN_PARM_AUTHENABLES) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 537 | { |
| 538 | uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04}; |
| 539 | *data_len = sizeof(buf); |
| 540 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 541 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 542 | 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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 546 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 547 | uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 548 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 549 | *data_len = sizeof(current_revision); |
| 550 | memcpy(buf, ¤t_revision, *data_len); |
| 551 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 552 | if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 553 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 554 | 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 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 562 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 342df10 | 2016-02-10 13:48:16 -0600 | [diff] [blame] | 563 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 564 | else |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 565 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 566 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 567 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 568 | } |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 569 | else if (reqptr->parameter == LAN_PARM_VLAN) |
| 570 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 571 | uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 572 | |
| 573 | *data_len = sizeof(current_revision); |
| 574 | memcpy(buf, ¤t_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 Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 581 | 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, ¤t_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 Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 592 | else |
| 593 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 594 | log<level::ERR>("Unsupported parameter", |
| 595 | entry("PARAMETER=0x%x", reqptr->parameter)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 596 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | return rc; |
| 600 | } |
| 601 | |
| 602 | void register_netfn_transport_functions() |
| 603 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 604 | // <Wildcard Command> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 605 | 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] | 606 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard, |
| 607 | PRIVILEGE_USER); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 608 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 609 | // <Set LAN Configuration Parameters> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 610 | 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] | 611 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan, |
| 612 | PRIVILEGE_ADMIN); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 613 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 614 | // <Get LAN Configuration Parameters> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 615 | 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] | 616 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan, |
| 617 | PRIVILEGE_OPERATOR); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 618 | |
| 619 | return; |
| 620 | } |