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> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 6 | |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 7 | #include "host-ipmid/ipmid-api.h" |
Patrick Williams | 53a360e | 2016-08-12 22:01:02 -0500 | [diff] [blame] | 8 | #include "ipmid.hpp" |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 9 | #include "transporthandler.h" |
| 10 | |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 11 | #define SYSTEMD_NETWORKD_DBUS 1 |
| 12 | |
| 13 | #ifdef SYSTEMD_NETWORKD_DBUS |
| 14 | #include <systemd/sd-bus.h> |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 15 | #include <mapper.h> |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 16 | #endif |
| 17 | |
| 18 | // OpenBMC System Manager dbus framework |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 19 | const char *obj = "/org/openbmc/NetworkManager/Interface"; |
| 20 | const char *ifc = "org.openbmc.NetworkManager"; |
| 21 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 22 | const char *nwinterface = "eth0"; |
| 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 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 26 | char new_ipaddr [INET_ADDRSTRLEN] = ""; |
| 27 | char new_netmask [INET_ADDRSTRLEN] = ""; |
| 28 | char new_gateway [INET_ADDRSTRLEN] = ""; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 29 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 30 | const uint8_t SET_COMPLETE = 0; |
| 31 | const uint8_t SET_IN_PROGRESS = 1; |
| 32 | const uint8_t SET_COMMIT_WRITE = 2; //Optional |
| 33 | const uint8_t SET_IN_PROGRESS_RESERVED = 3; //Reserved |
| 34 | |
| 35 | // Status of Set-In-Progress Parameter (# 0) |
| 36 | uint8_t lan_set_in_progress = SET_COMPLETE; |
| 37 | |
| 38 | |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 39 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 40 | void register_netfn_transport_functions() __attribute__((constructor)); |
| 41 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 42 | // Helper Function to get IP Address/NetMask/Gateway from Network Manager or Cache |
| 43 | // based on Set-In-Progress State |
| 44 | ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t * data) |
| 45 | { |
| 46 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 47 | sd_bus_message *reply = NULL; |
| 48 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 49 | int family; |
| 50 | unsigned char prefixlen; |
| 51 | char* ipaddr = NULL; |
| 52 | unsigned long mask = 0xFFFFFFFF; |
| 53 | char* gateway = NULL; |
| 54 | int r = 0; |
| 55 | ipmi_ret_t rc = IPMI_CC_OK; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 56 | char *app = NULL; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 57 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 58 | r = mapper_get_service(bus, obj, &app); |
| 59 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 60 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 61 | obj, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 62 | goto cleanup; |
| 63 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 64 | r = sd_bus_call_method(bus, app, obj, ifc, "GetAddress4", &error, |
| 65 | &reply, "s", nwinterface); |
| 66 | if(r < 0) |
| 67 | { |
| 68 | fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r)); |
| 69 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 70 | goto cleanup; |
| 71 | } |
| 72 | |
| 73 | r = sd_bus_message_read(reply, "iyss", &family, &prefixlen, &ipaddr, &gateway); |
| 74 | if(r < 0) |
| 75 | { |
| 76 | fprintf(stderr, "Failed to get a response: %s\n", strerror(-rc)); |
| 77 | rc = IPMI_CC_RESPONSE_ERROR; |
| 78 | goto cleanup; |
| 79 | } |
| 80 | |
| 81 | printf("N/W data from HW %s:%d:%s:%s\n", family==AF_INET?"IPv4":"IPv6", prefixlen, ipaddr,gateway); |
| 82 | printf("N/W data from Cache: %s:%s:%s\n", new_ipaddr, new_netmask, new_gateway); |
| 83 | |
| 84 | if(lan_param == LAN_PARM_IP) |
| 85 | { |
| 86 | if(lan_set_in_progress == SET_COMPLETE) |
| 87 | { |
| 88 | std::string ipaddrstr(ipaddr); |
| 89 | inet_pton(AF_INET, ipaddrstr.c_str(),(void *)data); |
| 90 | } |
| 91 | else if(lan_set_in_progress == SET_IN_PROGRESS) |
| 92 | { |
| 93 | inet_pton(AF_INET, new_ipaddr, (void *)data); |
| 94 | } |
| 95 | } |
| 96 | else if(lan_param == LAN_PARM_SUBNET) |
| 97 | { |
| 98 | if(lan_set_in_progress == SET_COMPLETE) |
| 99 | { |
| 100 | mask = htonl(mask<<(32-prefixlen)); |
| 101 | memcpy(data, &mask, 4); |
| 102 | } |
| 103 | else if(lan_set_in_progress == SET_IN_PROGRESS) |
| 104 | { |
| 105 | inet_pton(AF_INET, new_netmask, (void *)data); |
| 106 | } |
| 107 | } |
| 108 | else if(lan_param == LAN_PARM_GATEWAY) |
| 109 | { |
| 110 | if(lan_set_in_progress == SET_COMPLETE) |
| 111 | { |
| 112 | std::string gatewaystr(gateway); |
| 113 | inet_pton(AF_INET, gatewaystr.c_str(), (void *)data); |
| 114 | } |
| 115 | else if(lan_set_in_progress == SET_IN_PROGRESS) |
| 116 | { |
| 117 | inet_pton(AF_INET, new_gateway,(void *)data); |
| 118 | } |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
| 123 | } |
| 124 | |
| 125 | cleanup: |
| 126 | sd_bus_error_free(&error); |
| 127 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 128 | free(app); |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 129 | |
| 130 | return rc; |
| 131 | } |
| 132 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 133 | ipmi_ret_t ipmi_transport_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 134 | ipmi_request_t request, ipmi_response_t response, |
| 135 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 136 | { |
| 137 | printf("Handling TRANSPORT WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 138 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 139 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 140 | *data_len = 0; |
| 141 | return rc; |
| 142 | } |
| 143 | |
| 144 | struct set_lan_t { |
| 145 | uint8_t channel; |
| 146 | uint8_t parameter; |
| 147 | uint8_t data[8]; // Per IPMI spec, not expecting more than this size |
| 148 | } __attribute__ ((packed)); |
| 149 | |
| 150 | ipmi_ret_t ipmi_transport_set_lan(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 151 | ipmi_request_t request, ipmi_response_t response, |
| 152 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 153 | { |
| 154 | ipmi_ret_t rc = IPMI_CC_OK; |
| 155 | *data_len = 0; |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 156 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 157 | sd_bus_message *reply = NULL; |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 158 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 159 | int r = 0; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 160 | char *app = NULL; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 161 | |
| 162 | printf("IPMI SET_LAN\n"); |
| 163 | |
| 164 | set_lan_t *reqptr = (set_lan_t*) request; |
| 165 | |
| 166 | // TODO Use dbus interface once available. For now use cmd line. |
| 167 | // TODO Add the rest of the parameters like setting auth type |
| 168 | // TODO Add error handling |
| 169 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 170 | if (reqptr->parameter == LAN_PARM_IP) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 171 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 172 | snprintf(new_ipaddr, INET_ADDRSTRLEN, "%d.%d.%d.%d", |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 173 | reqptr->data[0], reqptr->data[1], reqptr->data[2], reqptr->data[3]); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 174 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 175 | else if (reqptr->parameter == LAN_PARM_MAC) |
Adriana Kobylak | d54a9dd | 2016-02-03 17:25:54 -0600 | [diff] [blame] | 176 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 177 | char mac[SIZE_MAC]; |
Adriana Kobylak | d54a9dd | 2016-02-03 17:25:54 -0600 | [diff] [blame] | 178 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 179 | snprintf(mac, SIZE_MAC, "%02x:%02x:%02x:%02x:%02x:%02x", |
Adriana Kobylak | d54a9dd | 2016-02-03 17:25:54 -0600 | [diff] [blame] | 180 | reqptr->data[0], |
| 181 | reqptr->data[1], |
| 182 | reqptr->data[2], |
| 183 | reqptr->data[3], |
| 184 | reqptr->data[4], |
| 185 | reqptr->data[5]); |
| 186 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 187 | r = mapper_get_service(bus, obj, &app); |
| 188 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 189 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 190 | obj, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 191 | goto finish; |
| 192 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 193 | r = sd_bus_call_method(bus, app, obj, ifc, "SetHwAddress", &error, |
| 194 | &reply, "ss", nwinterface, mac); |
| 195 | if(r < 0) |
| 196 | { |
| 197 | fprintf(stderr, "Failed to call the method: %s\n", strerror(-r)); |
| 198 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Adriana Kobylak | d54a9dd | 2016-02-03 17:25:54 -0600 | [diff] [blame] | 199 | } |
| 200 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 201 | else if (reqptr->parameter == LAN_PARM_SUBNET) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 202 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 203 | snprintf(new_netmask, INET_ADDRSTRLEN, "%d.%d.%d.%d", |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 204 | reqptr->data[0], reqptr->data[1], reqptr->data[2], reqptr->data[3]); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 205 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 206 | else if (reqptr->parameter == LAN_PARM_GATEWAY) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 207 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 208 | snprintf(new_gateway, INET_ADDRSTRLEN, "%d.%d.%d.%d", |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 209 | reqptr->data[0], reqptr->data[1], reqptr->data[2], reqptr->data[3]); |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 210 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 211 | else if (reqptr->parameter == LAN_PARM_INPROGRESS) |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 212 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 213 | if(reqptr->data[0] == SET_COMPLETE) // Set Complete |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 214 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 215 | lan_set_in_progress = SET_COMPLETE; |
| 216 | // Apply the IP settings once IP Address, Netmask and Gateway is set |
| 217 | if (!strcmp(new_ipaddr, "") || !strcmp (new_netmask, "") || !strcmp (new_gateway, "")) |
| 218 | { |
| 219 | printf("ERROR: Incomplete LAN Parameters\n"); |
| 220 | } |
| 221 | else |
| 222 | { |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 223 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 224 | r = sd_bus_call_method(bus, // On the System Bus |
| 225 | app, // Service to contact |
| 226 | obj, // Object path |
| 227 | ifc, // Interface name |
| 228 | "SetAddress4", // Method to be called |
| 229 | &error, // object to return error |
| 230 | &reply, // Response message on success |
| 231 | "ssss", // input message (Interface, IP Address, Netmask, Gateway) |
| 232 | nwinterface, // eth0 |
| 233 | new_ipaddr, |
| 234 | new_netmask, |
| 235 | new_gateway); |
| 236 | if(r < 0) |
| 237 | { |
| 238 | fprintf(stderr, "Failed to set network data %s:%s:%s %s\n", new_ipaddr, new_netmask, new_gateway, error.message); |
| 239 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 240 | } |
| 241 | memset(new_ipaddr, 0, INET_ADDRSTRLEN); |
| 242 | memset(new_netmask, 0, INET_ADDRSTRLEN); |
| 243 | memset(new_gateway, 0, INET_ADDRSTRLEN); |
| 244 | } |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 245 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 246 | else if(reqptr->data[0] == SET_IN_PROGRESS) // Set In Progress |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 247 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 248 | lan_set_in_progress = SET_IN_PROGRESS; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 249 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 250 | } |
| 251 | else |
| 252 | { |
| 253 | fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 254 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 255 | } |
| 256 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 257 | finish: |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 258 | sd_bus_error_free(&error); |
| 259 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 260 | free(app); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 261 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 262 | return rc; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | struct get_lan_t { |
| 266 | uint8_t rev_channel; |
| 267 | uint8_t parameter; |
| 268 | uint8_t parameter_set; |
| 269 | uint8_t parameter_block; |
| 270 | } __attribute__ ((packed)); |
| 271 | |
| 272 | ipmi_ret_t ipmi_transport_get_lan(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 273 | ipmi_request_t request, ipmi_response_t response, |
| 274 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 275 | { |
| 276 | ipmi_ret_t rc = IPMI_CC_OK; |
| 277 | *data_len = 0; |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 278 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 279 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 280 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 281 | int r = 0; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 282 | const uint8_t current_revision = 0x11; // Current rev per IPMI Spec 2.0 |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 283 | int i = 0; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 284 | char *app = NULL; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 285 | |
| 286 | printf("IPMI GET_LAN\n"); |
| 287 | |
| 288 | get_lan_t *reqptr = (get_lan_t*) request; |
| 289 | |
| 290 | if (reqptr->rev_channel & 0x80) // Revision is bit 7 |
| 291 | { |
| 292 | // Only current revision was requested |
| 293 | *data_len = sizeof(current_revision); |
| 294 | memcpy(response, ¤t_revision, *data_len); |
| 295 | return IPMI_CC_OK; |
| 296 | } |
| 297 | |
| 298 | // TODO Use dbus interface once available. For now use ip cmd. |
| 299 | // TODO Add the rest of the parameters, like gateway |
| 300 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 301 | if (reqptr->parameter == LAN_PARM_INPROGRESS) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 302 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 303 | uint8_t buf[] = {current_revision, lan_set_in_progress}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 304 | *data_len = sizeof(buf); |
| 305 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 306 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 307 | else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 308 | { |
| 309 | uint8_t buf[] = {current_revision,0x04}; |
| 310 | *data_len = sizeof(buf); |
| 311 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 312 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 313 | else if (reqptr->parameter == LAN_PARM_AUTHENABLES) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 314 | { |
| 315 | uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04}; |
| 316 | *data_len = sizeof(buf); |
| 317 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 318 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 319 | else if ((reqptr->parameter == LAN_PARM_IP) || (reqptr->parameter == LAN_PARM_SUBNET) || (reqptr->parameter == LAN_PARM_GATEWAY)) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 320 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 321 | uint8_t buf[5]; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 322 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 323 | *data_len = sizeof(current_revision); |
| 324 | memcpy(buf, ¤t_revision, *data_len); |
| 325 | |
| 326 | if(getNetworkData(reqptr->parameter, &buf[1]) == IPMI_CC_OK) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 327 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 328 | *data_len = sizeof(buf); |
| 329 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 342df10 | 2016-02-10 13:48:16 -0600 | [diff] [blame] | 330 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 331 | else |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 332 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 333 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 334 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 335 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 336 | else if (reqptr->parameter == LAN_PARM_MAC) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 337 | { |
| 338 | //string to parse: link/ether xx:xx:xx:xx:xx:xx |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 339 | uint8_t buf[7]; |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 340 | char *eaddr1 = NULL; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 341 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 342 | r = mapper_get_service(bus, obj, &app); |
| 343 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 344 | fprintf(stderr, "Failed to get %s bus name: %s\n", |
| 345 | obj, strerror(-r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 346 | goto cleanup; |
| 347 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 348 | r = sd_bus_call_method(bus, app, obj, ifc, "GetHwAddress", &error, |
| 349 | &reply, "s", nwinterface); |
| 350 | if(r < 0) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 351 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 352 | fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r)); |
| 353 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 354 | goto cleanup; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 355 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 356 | |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 357 | r = sd_bus_message_read(reply, "s", &eaddr1); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 358 | if (r < 0) |
| 359 | { |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 360 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 361 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 362 | goto cleanup; |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 363 | } |
| 364 | if (eaddr1 == NULL) |
| 365 | { |
| 366 | fprintf(stderr, "Failed to get a valid response: %s", strerror(-r)); |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 367 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 368 | goto cleanup; |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 369 | } |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 370 | |
| 371 | memcpy((void*)&buf[0], ¤t_revision, 1); |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 372 | |
| 373 | char *tokptr = NULL; |
| 374 | char* digit = strtok_r(eaddr1, ":", &tokptr); |
| 375 | if (digit == NULL) |
| 376 | { |
| 377 | fprintf(stderr, "Unexpected MAC format: %s", eaddr1); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 378 | rc = IPMI_CC_RESPONSE_ERROR; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 379 | goto cleanup; |
Adriana Kobylak | 9355f61 | 2016-02-08 17:30:37 -0600 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | i=0; |
| 383 | while (digit != NULL) |
| 384 | { |
| 385 | int resp_byte = strtoul(digit, NULL, 16); |
| 386 | memcpy((void*)&buf[i+1], &resp_byte, 1); |
| 387 | i++; |
| 388 | digit = strtok_r(NULL, ":", &tokptr); |
| 389 | } |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 390 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 391 | *data_len = sizeof(buf); |
| 392 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 393 | } |
| 394 | else |
| 395 | { |
| 396 | fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 397 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 398 | } |
| 399 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 400 | cleanup: |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 401 | sd_bus_error_free(&error); |
| 402 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 403 | free(app); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 404 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 405 | return rc; |
| 406 | } |
| 407 | |
| 408 | void register_netfn_transport_functions() |
| 409 | { |
| 410 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_WILDCARD); |
| 411 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard); |
| 412 | |
| 413 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_SET_LAN); |
| 414 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan); |
| 415 | |
| 416 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_TRANSPORT, IPMI_CMD_GET_LAN); |
| 417 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan); |
| 418 | |
| 419 | return; |
| 420 | } |