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