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 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 28 | using namespace phosphor::logging; |
| 29 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 30 | namespace fs = std::experimental::filesystem; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 31 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 32 | void register_netfn_transport_functions() __attribute__((constructor)); |
| 33 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 34 | // 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] | 35 | // Cache based on Set-In-Progress State |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 36 | ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t* data) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 37 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 38 | ipmi_ret_t rc = IPMI_CC_OK; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 39 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 40 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 41 | try |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 42 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 43 | switch (lan_param) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 44 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 45 | case LAN_PARM_IP: |
| 46 | { |
| 47 | std::string ipaddress; |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 48 | if (channelConfig.lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 49 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 50 | try |
| 51 | { |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 52 | auto ipObjectInfo = ipmi::getIPObject( |
| 53 | bus, |
| 54 | ipmi::network::IP_INTERFACE, |
| 55 | ipmi::network::ROOT, |
| 56 | ipmi::network::IP_TYPE); |
| 57 | |
| 58 | auto properties = ipmi::getAllDbusProperties( |
| 59 | bus, |
| 60 | ipObjectInfo.second, |
| 61 | ipObjectInfo.first, |
| 62 | ipmi::network::IP_INTERFACE); |
| 63 | |
| 64 | ipaddress = properties["Address"].get<std::string>(); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 65 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 66 | } |
| 67 | // ignore the exception, as it is a valid condtion that |
| 68 | // system is not confiured with any ip. |
| 69 | catch (InternalFailure& e) |
| 70 | { |
| 71 | // nothing to do. |
| 72 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 73 | } |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 74 | else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 75 | { |
| 76 | ipaddress = channelConfig.ipaddr; |
| 77 | } |
| 78 | |
| 79 | inet_pton(AF_INET, ipaddress.c_str(), |
| 80 | reinterpret_cast<void*>(data)); |
| 81 | } |
| 82 | break; |
| 83 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 84 | case LAN_PARM_IPSRC: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 85 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 86 | std::string networkInterfacePath; |
| 87 | |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 88 | if (channelConfig.lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 89 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 90 | try |
| 91 | { |
| 92 | ipmi::ObjectTree ancestorMap; |
| 93 | // if the system is having ip object,then |
| 94 | // get the IP object. |
| 95 | auto ipObject = ipmi::getDbusObject( |
| 96 | bus, |
| 97 | ipmi::network::IP_INTERFACE, |
| 98 | ipmi::network::ROOT, |
| 99 | ipmi::network::IP_TYPE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 100 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 101 | // Get the parent interface of the IP object. |
| 102 | try |
| 103 | { |
| 104 | ipmi::InterfaceList interfaces; |
| 105 | interfaces.emplace_back( |
| 106 | ipmi::network::ETHERNET_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 107 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 108 | ancestorMap = ipmi::getAllAncestors( |
| 109 | bus, |
| 110 | ipObject.first, |
| 111 | std::move(interfaces)); |
| 112 | } |
| 113 | catch (InternalFailure& e) |
| 114 | { |
| 115 | // if unable to get the parent interface |
| 116 | // then commit the error and return. |
| 117 | log<level::ERR>("Unable to get the parent interface", |
| 118 | entry("PATH=%s", ipObject.first.c_str()), |
| 119 | entry("INTERFACE=%s", |
| 120 | ipmi::network::ETHERNET_INTERFACE)); |
| 121 | break; |
| 122 | |
| 123 | } |
| 124 | // for an ip object there would be single parent |
| 125 | // interface. |
| 126 | networkInterfacePath = ancestorMap.begin()->first; |
| 127 | } |
| 128 | catch (InternalFailure& e) |
| 129 | { |
| 130 | // if there is no ip configured on the system,then |
| 131 | // get the network interface object. |
| 132 | auto networkInterfaceObject = ipmi::getDbusObject( |
| 133 | bus, |
| 134 | ipmi::network::ETHERNET_INTERFACE, |
| 135 | ipmi::network::ROOT, |
| 136 | ipmi::network::INTERFACE); |
| 137 | |
| 138 | networkInterfacePath = networkInterfaceObject.first; |
| 139 | } |
| 140 | |
| 141 | auto variant = ipmi::getDbusProperty( |
| 142 | bus, |
| 143 | ipmi::network::SERVICE, |
| 144 | networkInterfacePath, |
| 145 | ipmi::network::ETHERNET_INTERFACE, |
| 146 | "DHCPEnabled"); |
| 147 | |
| 148 | auto dhcpEnabled = variant.get<bool>(); |
| 149 | // As per IPMI spec 2=>DHCP, 1=STATIC |
| 150 | auto ipsrc = dhcpEnabled ? ipmi::network::IPOrigin::DHCP : |
| 151 | ipmi::network::IPOrigin::STATIC; |
| 152 | |
| 153 | memcpy(data, &ipsrc, ipmi::network::IPSRC_SIZE_BYTE); |
| 154 | } |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 155 | else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 156 | { |
| 157 | memcpy(data, &(channelConfig.ipsrc), |
| 158 | ipmi::network::IPSRC_SIZE_BYTE); |
| 159 | } |
| 160 | } |
| 161 | break; |
| 162 | |
| 163 | case LAN_PARM_SUBNET: |
| 164 | { |
| 165 | unsigned long mask {}; |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 166 | if (channelConfig.lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 167 | { |
| 168 | try |
| 169 | { |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 170 | auto ipObjectInfo = ipmi::getIPObject( |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 171 | bus, |
| 172 | ipmi::network::IP_INTERFACE, |
| 173 | ipmi::network::ROOT, |
| 174 | ipmi::network::IP_TYPE); |
| 175 | |
| 176 | auto properties = ipmi::getAllDbusProperties( |
| 177 | bus, |
| 178 | ipObjectInfo.second, |
| 179 | ipObjectInfo.first, |
| 180 | ipmi::network::IP_INTERFACE); |
| 181 | |
| 182 | auto prefix = properties["PrefixLength"].get<uint8_t>(); |
| 183 | mask = ipmi::network::MASK_32_BIT; |
| 184 | mask = htonl(mask << (ipmi::network::BITS_32 - prefix)); |
| 185 | } |
| 186 | // ignore the exception, as it is a valid condtion that |
| 187 | // system is not confiured with any ip. |
| 188 | catch (InternalFailure& e) |
| 189 | { |
| 190 | // nothing to do |
| 191 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 192 | memcpy(data, &mask, ipmi::network::IPV4_ADDRESS_SIZE_BYTE); |
| 193 | } |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 194 | else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 195 | { |
| 196 | inet_pton(AF_INET, channelConfig.netmask.c_str(), |
| 197 | reinterpret_cast<void*>(data)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | } |
| 201 | break; |
| 202 | |
| 203 | case LAN_PARM_GATEWAY: |
| 204 | { |
| 205 | std::string gateway; |
| 206 | |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 207 | if (channelConfig.lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 208 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 209 | try |
| 210 | { |
| 211 | auto systemObject = ipmi::getDbusObject( |
| 212 | bus, |
| 213 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 214 | ipmi::network::ROOT); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 215 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 216 | auto systemProperties = ipmi::getAllDbusProperties( |
| 217 | bus, |
| 218 | systemObject.second, |
| 219 | systemObject.first, |
| 220 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 221 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 222 | gateway = systemProperties["DefaultGateway"].get< |
| 223 | std::string>(); |
| 224 | } |
| 225 | // ignore the exception, as it is a valid condtion that |
| 226 | // system is not confiured with any ip. |
| 227 | catch (InternalFailure& e) |
| 228 | { |
| 229 | // nothing to do |
| 230 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 231 | |
| 232 | } |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 233 | else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 234 | { |
| 235 | gateway = channelConfig.gateway; |
| 236 | } |
| 237 | |
| 238 | inet_pton(AF_INET, gateway.c_str(), |
| 239 | reinterpret_cast<void*>(data)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 240 | } |
| 241 | break; |
| 242 | |
| 243 | case LAN_PARM_MAC: |
| 244 | { |
| 245 | std::string macAddress; |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 246 | if (channelConfig.lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 247 | { |
| 248 | auto macObjectInfo = ipmi::getDbusObject( |
| 249 | bus, |
| 250 | ipmi::network::MAC_INTERFACE, |
| 251 | ipmi::network::ROOT); |
| 252 | |
| 253 | auto variant = ipmi::getDbusProperty( |
| 254 | bus, |
| 255 | macObjectInfo.second, |
| 256 | macObjectInfo.first, |
| 257 | ipmi::network::MAC_INTERFACE, |
| 258 | "MACAddress"); |
| 259 | |
| 260 | macAddress = variant.get<std::string>(); |
| 261 | |
| 262 | } |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 263 | else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 264 | { |
| 265 | macAddress = channelConfig.macAddress; |
| 266 | } |
| 267 | |
| 268 | sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT, |
| 269 | (data), |
| 270 | (data + 1), |
| 271 | (data + 2), |
| 272 | (data + 3), |
| 273 | (data + 4), |
| 274 | (data + 5)); |
| 275 | } |
| 276 | break; |
| 277 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 278 | case LAN_PARM_VLAN: |
| 279 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 280 | uint16_t vlanID {}; |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 281 | if (channelConfig.lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 282 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 283 | try |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 284 | { |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 285 | auto ipObjectInfo = ipmi::getIPObject( |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 286 | bus, |
| 287 | ipmi::network::IP_INTERFACE, |
| 288 | ipmi::network::ROOT, |
| 289 | ipmi::network::IP_TYPE); |
| 290 | |
| 291 | vlanID = static_cast<uint16_t>( |
| 292 | ipmi::network::getVLAN(ipObjectInfo.first)); |
| 293 | |
| 294 | vlanID = htole16(vlanID); |
| 295 | |
| 296 | if (vlanID) |
| 297 | { |
| 298 | //Enable the 16th bit |
| 299 | vlanID |= htole16(ipmi::network::VLAN_ENABLE_MASK); |
| 300 | } |
| 301 | } |
| 302 | // ignore the exception, as it is a valid condtion that |
| 303 | // system is not confiured with any ip. |
| 304 | catch (InternalFailure& e) |
| 305 | { |
| 306 | // nothing to do |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | memcpy(data, &vlanID, ipmi::network::VLAN_SIZE_BYTE); |
| 310 | } |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 311 | else if (channelConfig.lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 312 | { |
| 313 | memcpy(data, &(channelConfig.vlanID), |
| 314 | ipmi::network::VLAN_SIZE_BYTE); |
| 315 | } |
| 316 | } |
| 317 | break; |
| 318 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 319 | default: |
| 320 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 321 | } |
| 322 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 323 | catch (InternalFailure& e) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 324 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 325 | commit<InternalFailure>(); |
| 326 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 327 | return rc; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 328 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 329 | return rc; |
| 330 | } |
| 331 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 332 | ipmi_ret_t ipmi_transport_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 333 | ipmi_request_t request, ipmi_response_t response, |
| 334 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 335 | { |
| 336 | printf("Handling TRANSPORT WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 337 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 338 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 339 | *data_len = 0; |
| 340 | return rc; |
| 341 | } |
| 342 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 343 | struct set_lan_t |
| 344 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 345 | uint8_t channel; |
| 346 | uint8_t parameter; |
| 347 | 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] | 348 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 349 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 350 | ipmi_ret_t ipmi_transport_set_lan(ipmi_netfn_t netfn, |
| 351 | ipmi_cmd_t cmd, |
| 352 | ipmi_request_t request, |
| 353 | ipmi_response_t response, |
| 354 | ipmi_data_len_t data_len, |
| 355 | ipmi_context_t context) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 356 | { |
| 357 | ipmi_ret_t rc = IPMI_CC_OK; |
| 358 | *data_len = 0; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 359 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 360 | char ipaddr[INET_ADDRSTRLEN]; |
| 361 | char netmask[INET_ADDRSTRLEN]; |
| 362 | char gateway[INET_ADDRSTRLEN]; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 363 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 364 | auto reqptr = reinterpret_cast<const set_lan_t*>(request); |
| 365 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 366 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 367 | switch (reqptr->parameter) |
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 | case LAN_PARM_IP: |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 370 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 371 | snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 372 | reqptr->data[0], reqptr->data[1], |
| 373 | reqptr->data[2], reqptr->data[3]); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 374 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 375 | channelConfig.ipaddr.assign(ipaddr); |
| 376 | |
| 377 | } |
| 378 | break; |
| 379 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 380 | case LAN_PARM_IPSRC: |
| 381 | { |
| 382 | uint8_t ipsrc{}; |
| 383 | memcpy(&ipsrc, reqptr->data, ipmi::network::IPSRC_SIZE_BYTE); |
| 384 | channelConfig.ipsrc = static_cast<ipmi::network::IPOrigin>(ipsrc); |
| 385 | } |
| 386 | break; |
| 387 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 388 | case LAN_PARM_MAC: |
| 389 | { |
| 390 | char mac[SIZE_MAC]; |
| 391 | |
| 392 | snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT, |
| 393 | reqptr->data[0], |
| 394 | reqptr->data[1], |
| 395 | reqptr->data[2], |
| 396 | reqptr->data[3], |
| 397 | reqptr->data[4], |
| 398 | reqptr->data[5]); |
| 399 | |
| 400 | auto macObjectInfo = ipmi::getDbusObject( |
| 401 | bus, |
| 402 | ipmi::network::MAC_INTERFACE, |
| 403 | ipmi::network::ROOT, |
| 404 | ipmi::network::INTERFACE); |
| 405 | |
| 406 | ipmi::setDbusProperty(bus, |
| 407 | macObjectInfo.second, |
| 408 | macObjectInfo.first, |
| 409 | ipmi::network::MAC_INTERFACE, |
| 410 | "MACAddress", |
| 411 | std::string(mac)); |
| 412 | |
| 413 | channelConfig.macAddress = mac; |
| 414 | |
| 415 | } |
| 416 | break; |
| 417 | |
| 418 | case LAN_PARM_SUBNET: |
| 419 | { |
| 420 | snprintf(netmask, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 421 | reqptr->data[0], reqptr->data[1], |
| 422 | reqptr->data[2], reqptr->data[3]); |
| 423 | channelConfig.netmask.assign(netmask); |
| 424 | } |
| 425 | break; |
| 426 | |
| 427 | case LAN_PARM_GATEWAY: |
| 428 | { |
| 429 | snprintf(gateway, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 430 | reqptr->data[0], reqptr->data[1], |
| 431 | reqptr->data[2], reqptr->data[3]); |
| 432 | channelConfig.gateway.assign(gateway); |
| 433 | |
| 434 | } |
| 435 | break; |
| 436 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 437 | case LAN_PARM_VLAN: |
| 438 | { |
| 439 | uint16_t vlan {}; |
| 440 | memcpy(&vlan, reqptr->data, ipmi::network::VLAN_SIZE_BYTE); |
| 441 | // We are not storing the enable bit |
| 442 | // We assume that ipmitool always send enable |
| 443 | // bit as 1. |
| 444 | vlan = le16toh(vlan); |
| 445 | channelConfig.vlanID = vlan; |
| 446 | } |
| 447 | break; |
| 448 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 449 | case LAN_PARM_INPROGRESS: |
| 450 | { |
| 451 | if (reqptr->data[0] == SET_COMPLETE) |
| 452 | { |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 453 | channelConfig.lan_set_in_progress = SET_COMPLETE; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 454 | |
| 455 | log<level::INFO>("Network data from Cache", |
| 456 | entry("PREFIX=%s", channelConfig.netmask.c_str()), |
| 457 | entry("ADDRESS=%s", channelConfig.ipaddr.c_str()), |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 458 | entry("GATEWAY=%s", channelConfig.gateway.c_str()), |
| 459 | entry("VLAN=%d", channelConfig.vlanID)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 460 | |
| 461 | log<level::INFO>("Use Set Channel Access command to apply"); |
| 462 | |
| 463 | } |
| 464 | else if (reqptr->data[0] == SET_IN_PROGRESS) // Set In Progress |
| 465 | { |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 466 | channelConfig.lan_set_in_progress = SET_IN_PROGRESS; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | } |
| 470 | break; |
| 471 | |
| 472 | default: |
| 473 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 474 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
| 475 | } |
| 476 | |
| 477 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 478 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 479 | return rc; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 480 | } |
| 481 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 482 | struct get_lan_t |
| 483 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 484 | uint8_t rev_channel; |
| 485 | uint8_t parameter; |
| 486 | uint8_t parameter_set; |
| 487 | uint8_t parameter_block; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 488 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 489 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 490 | ipmi_ret_t ipmi_transport_get_lan(ipmi_netfn_t netfn, |
| 491 | ipmi_cmd_t cmd, |
| 492 | ipmi_request_t request, |
| 493 | ipmi_response_t response, |
| 494 | ipmi_data_len_t data_len, |
| 495 | ipmi_context_t context) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 496 | { |
| 497 | ipmi_ret_t rc = IPMI_CC_OK; |
| 498 | *data_len = 0; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 499 | 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] | 500 | |
| 501 | get_lan_t *reqptr = (get_lan_t*) request; |
| 502 | |
| 503 | if (reqptr->rev_channel & 0x80) // Revision is bit 7 |
| 504 | { |
| 505 | // Only current revision was requested |
| 506 | *data_len = sizeof(current_revision); |
| 507 | memcpy(response, ¤t_revision, *data_len); |
| 508 | return IPMI_CC_OK; |
| 509 | } |
| 510 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 511 | if (reqptr->parameter == LAN_PARM_INPROGRESS) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 512 | { |
Patrick Venture | 585a1e9 | 2017-11-17 07:36:15 -0800 | [diff] [blame] | 513 | uint8_t buf[] = {current_revision, channelConfig.lan_set_in_progress}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 514 | *data_len = sizeof(buf); |
| 515 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 516 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 517 | else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 518 | { |
| 519 | uint8_t buf[] = {current_revision,0x04}; |
| 520 | *data_len = sizeof(buf); |
| 521 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 522 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 523 | else if (reqptr->parameter == LAN_PARM_AUTHENABLES) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 524 | { |
| 525 | uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04}; |
| 526 | *data_len = sizeof(buf); |
| 527 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 528 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 529 | else if ((reqptr->parameter == LAN_PARM_IP) || |
| 530 | (reqptr->parameter == LAN_PARM_SUBNET) || |
| 531 | (reqptr->parameter == LAN_PARM_GATEWAY) || |
| 532 | (reqptr->parameter == LAN_PARM_MAC)) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 533 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 534 | uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 535 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 536 | *data_len = sizeof(current_revision); |
| 537 | memcpy(buf, ¤t_revision, *data_len); |
| 538 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 539 | if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 540 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 541 | if (reqptr->parameter == LAN_PARM_MAC) |
| 542 | { |
| 543 | *data_len = sizeof(buf); |
| 544 | } |
| 545 | else |
| 546 | { |
| 547 | *data_len = ipmi::network::IPV4_ADDRESS_SIZE_BYTE + 1; |
| 548 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 549 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 342df10 | 2016-02-10 13:48:16 -0600 | [diff] [blame] | 550 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 551 | else |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 552 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 553 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 554 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 555 | } |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 556 | else if (reqptr->parameter == LAN_PARM_VLAN) |
| 557 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 558 | uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 559 | |
| 560 | *data_len = sizeof(current_revision); |
| 561 | memcpy(buf, ¤t_revision, *data_len); |
| 562 | if (getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK) |
| 563 | { |
| 564 | *data_len = sizeof(buf); |
| 565 | memcpy(response, &buf, *data_len); |
| 566 | } |
| 567 | } |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 568 | else if (reqptr->parameter == LAN_PARM_IPSRC) |
| 569 | { |
| 570 | uint8_t buff[ipmi::network::IPSRC_SIZE_BYTE + 1] = {}; |
| 571 | *data_len = sizeof(current_revision); |
| 572 | memcpy(buff, ¤t_revision, *data_len); |
| 573 | if (getNetworkData(reqptr->parameter, &buff[1]) == IPMI_CC_OK) |
| 574 | { |
| 575 | *data_len = sizeof(buff); |
| 576 | memcpy(response, &buff, *data_len); |
| 577 | } |
| 578 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 579 | else |
| 580 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 581 | log<level::ERR>("Unsupported parameter", |
| 582 | entry("PARAMETER=0x%x", reqptr->parameter)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 583 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | return rc; |
| 587 | } |
| 588 | |
| 589 | void register_netfn_transport_functions() |
| 590 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 591 | // <Wildcard Command> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 592 | 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] | 593 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard, |
| 594 | PRIVILEGE_USER); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 595 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 596 | // <Set LAN Configuration Parameters> |
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_SET_LAN); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 598 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan, |
| 599 | PRIVILEGE_ADMIN); |
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 | // <Get 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_GET_LAN); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 603 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan, |
| 604 | PRIVILEGE_OPERATOR); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 605 | |
| 606 | return; |
| 607 | } |