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