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