Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1 | #include "chassishandler.h" |
| 2 | #include "ipmid-api.h" |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <stdint.h> |
Brad Bishop | 3551868 | 2016-07-22 08:35:41 -0400 | [diff] [blame] | 6 | #include <mapper.h> |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 7 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 8 | |
| 9 | //Defines |
| 10 | #define SET_PARM_VERSION 1 |
| 11 | #define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 //boot flags data1 7th bit on |
| 12 | #define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 //boot flags data1 8th bit on |
| 13 | #define SET_PARM_BOOT_FLAGS_VALID_PERMANENT 0xC0 //boot flags data1 7 & 8 bit on |
| 14 | |
| 15 | |
| 16 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 17 | // OpenBMC Chassis Manager dbus framework |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 18 | const char *chassis_object_name = "/org/openbmc/control/chassis0"; |
| 19 | const char *chassis_intf_name = "org.openbmc.control.Chassis"; |
| 20 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 21 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 22 | void register_netfn_chassis_functions() __attribute__((constructor)); |
| 23 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 24 | // Host settings in dbus |
| 25 | // Service name should be referenced by connection name got via object mapper |
| 26 | const char *settings_object_name = "/org/openbmc/settings/host0"; |
| 27 | const char *settings_intf_name = "org.freedesktop.DBus.Properties"; |
| 28 | const char *host_intf_name = "org.openbmc.settings.Host"; |
| 29 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 30 | int dbus_get_property(const char *name, char **buf) |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 31 | { |
| 32 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 33 | sd_bus_message *m = NULL; |
| 34 | sd_bus *bus = NULL; |
| 35 | char *temp_buf = NULL; |
| 36 | char *connection = NULL; |
| 37 | int r; |
| 38 | |
Brad Bishop | 3551868 | 2016-07-22 08:35:41 -0400 | [diff] [blame] | 39 | // Get the system bus where most system services are provided. |
| 40 | bus = ipmid_get_sd_bus_connection(); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 41 | |
Brad Bishop | 3551868 | 2016-07-22 08:35:41 -0400 | [diff] [blame] | 42 | r = mapper_get_service(bus, settings_object_name, &connection); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 43 | if (r < 0) { |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 44 | fprintf(stderr, "Failed to get connection, return value: %s.\n", strerror(-r)); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 45 | goto finish; |
| 46 | } |
| 47 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 48 | /* |
| 49 | * Bus, service, object path, interface and method are provided to call |
| 50 | * the method. |
| 51 | * Signatures and input arguments are provided by the arguments at the |
| 52 | * end. |
| 53 | */ |
| 54 | r = sd_bus_call_method(bus, |
| 55 | connection, /* service to contact */ |
| 56 | settings_object_name, /* object path */ |
| 57 | settings_intf_name, /* interface name */ |
| 58 | "Get", /* method name */ |
| 59 | &error, /* object to return error in */ |
| 60 | &m, /* return message on success */ |
| 61 | "ss", /* input signature */ |
| 62 | host_intf_name, /* first argument */ |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 63 | name); /* second argument */ |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 64 | |
| 65 | if (r < 0) { |
| 66 | fprintf(stderr, "Failed to issue method call: %s\n", error.message); |
| 67 | goto finish; |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * The output should be parsed exactly the same as the output formatting |
| 72 | * specified. |
| 73 | */ |
| 74 | r = sd_bus_message_read(m, "v", "s", &temp_buf); |
| 75 | if (r < 0) { |
| 76 | fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r)); |
| 77 | goto finish; |
| 78 | } |
| 79 | |
| 80 | asprintf(buf, "%s", temp_buf); |
| 81 | /* *buf = (char*) malloc(strlen(temp_buf)); |
| 82 | if (*buf) { |
| 83 | strcpy(*buf, temp_buf); |
| 84 | } |
| 85 | */ |
| 86 | printf("IPMID boot option property get: {%s}.\n", (char *) temp_buf); |
| 87 | |
| 88 | finish: |
| 89 | sd_bus_error_free(&error); |
| 90 | sd_bus_message_unref(m); |
| 91 | free(connection); |
| 92 | |
| 93 | return r; |
| 94 | } |
| 95 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 96 | int dbus_set_property(const char * name, const char *value) |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 97 | { |
| 98 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 99 | sd_bus_message *m = NULL; |
| 100 | sd_bus *bus = NULL; |
| 101 | char *connection = NULL; |
| 102 | int r; |
| 103 | |
Brad Bishop | 3551868 | 2016-07-22 08:35:41 -0400 | [diff] [blame] | 104 | // Get the system bus where most system services are provided. |
| 105 | bus = ipmid_get_sd_bus_connection(); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 106 | |
Brad Bishop | 3551868 | 2016-07-22 08:35:41 -0400 | [diff] [blame] | 107 | r = mapper_get_service(bus, settings_object_name, &connection); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 108 | if (r < 0) { |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 109 | fprintf(stderr, "Failed to get connection, return value: %s.\n", strerror(-r)); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 110 | goto finish; |
| 111 | } |
| 112 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 113 | /* |
| 114 | * Bus, service, object path, interface and method are provided to call |
| 115 | * the method. |
| 116 | * Signatures and input arguments are provided by the arguments at the |
| 117 | * end. |
| 118 | */ |
| 119 | r = sd_bus_call_method(bus, |
| 120 | connection, /* service to contact */ |
| 121 | settings_object_name, /* object path */ |
| 122 | settings_intf_name, /* interface name */ |
| 123 | "Set", /* method name */ |
| 124 | &error, /* object to return error in */ |
| 125 | &m, /* return message on success */ |
| 126 | "ssv", /* input signature */ |
| 127 | host_intf_name, /* first argument */ |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 128 | name, /* second argument */ |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 129 | "s", /* third argument */ |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 130 | value); /* fourth argument */ |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 131 | |
| 132 | if (r < 0) { |
| 133 | fprintf(stderr, "Failed to issue method call: %s\n", error.message); |
| 134 | goto finish; |
| 135 | } |
| 136 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 137 | printf("IPMID boot option property set: {%s}.\n", value); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 138 | |
| 139 | finish: |
| 140 | sd_bus_error_free(&error); |
| 141 | sd_bus_message_unref(m); |
| 142 | free(connection); |
| 143 | |
| 144 | return r; |
| 145 | } |
| 146 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 147 | struct get_sys_boot_options_t { |
| 148 | uint8_t parameter; |
| 149 | uint8_t set; |
| 150 | uint8_t block; |
| 151 | } __attribute__ ((packed)); |
| 152 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 153 | struct get_sys_boot_options_response_t { |
| 154 | uint8_t version; |
| 155 | uint8_t parm; |
| 156 | uint8_t data[5]; |
| 157 | } __attribute__ ((packed)); |
| 158 | |
| 159 | struct set_sys_boot_options_t { |
| 160 | uint8_t parameter; |
| 161 | uint8_t data[8]; |
| 162 | } __attribute__ ((packed)); |
| 163 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 164 | ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 165 | ipmi_request_t request, ipmi_response_t response, |
| 166 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 167 | { |
| 168 | printf("Handling CHASSIS WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 169 | // Status code. |
| 170 | ipmi_ret_t rc = IPMI_CC_OK; |
| 171 | *data_len = 0; |
| 172 | return rc; |
| 173 | } |
| 174 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 175 | //------------------------------------------------------------ |
| 176 | // Calls into Chassis Control Dbus object to do the power off |
| 177 | //------------------------------------------------------------ |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 178 | int ipmi_chassis_power_control(const char *method) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 179 | { |
| 180 | // sd_bus error |
| 181 | int rc = 0; |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 182 | char *busname = NULL; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 183 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 184 | // SD Bus error report mechanism. |
| 185 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 186 | |
| 187 | // Response from the call. Although there is no response for this call, |
| 188 | // obligated to mention this to make compiler happy. |
| 189 | sd_bus_message *response = NULL; |
| 190 | |
| 191 | // Gets a hook onto either a SYSTEM or SESSION bus |
| 192 | sd_bus *bus_type = ipmid_get_sd_bus_connection(); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 193 | rc = mapper_get_service(bus_type, chassis_object_name, &busname); |
| 194 | if (rc < 0) { |
| 195 | fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-rc)); |
| 196 | goto finish; |
| 197 | } |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 198 | rc = sd_bus_call_method(bus_type, // On the System Bus |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 199 | busname, // Service to contact |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 200 | chassis_object_name, // Object path |
| 201 | chassis_intf_name, // Interface name |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 202 | method, // Method to be called |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 203 | &bus_error, // object to return error |
| 204 | &response, // Response buffer if any |
| 205 | NULL); // No input arguments |
| 206 | if(rc < 0) |
| 207 | { |
| 208 | fprintf(stderr,"ERROR initiating Power Off:[%s]\n",bus_error.message); |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | printf("Chassis Power Off initiated successfully\n"); |
| 213 | } |
| 214 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 215 | finish: |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 216 | sd_bus_error_free(&bus_error); |
| 217 | sd_bus_message_unref(response); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 218 | free(busname); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 219 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame^] | 220 | return rc; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 221 | } |
| 222 | |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 223 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 224 | //---------------------------------------------------------------------- |
| 225 | // Chassis Control commands |
| 226 | //---------------------------------------------------------------------- |
| 227 | ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 228 | ipmi_request_t request, ipmi_response_t response, |
| 229 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 230 | { |
| 231 | // Error from power off. |
| 232 | int rc = 0; |
| 233 | |
| 234 | // No response for this command. |
| 235 | *data_len = 0; |
| 236 | |
| 237 | // Catch the actual operaton by peeking into request buffer |
| 238 | uint8_t chassis_ctrl_cmd = *(uint8_t *)request; |
| 239 | printf("Chassis Control Command: Operation:[0x%X]\n",chassis_ctrl_cmd); |
| 240 | |
| 241 | switch(chassis_ctrl_cmd) |
| 242 | { |
| 243 | case CMD_POWER_OFF: |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 244 | rc = ipmi_chassis_power_control("powerOff"); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 245 | break; |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 246 | case CMD_HARD_RESET: |
| 247 | rc = ipmi_chassis_power_control("reboot"); |
| 248 | break; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 249 | default: |
| 250 | { |
| 251 | fprintf(stderr, "Invalid Chassis Control command:[0x%X] received\n",chassis_ctrl_cmd); |
| 252 | rc = -1; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | return ( (rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK); |
| 257 | } |
| 258 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 259 | struct bootOptionTypeMap_t { |
| 260 | uint8_t ipmibootflag; |
| 261 | char dbusname[8]; |
| 262 | }; |
| 263 | |
| 264 | #define INVALID_STRING "Invalid" |
| 265 | // dbus supports this list of boot devices. |
| 266 | bootOptionTypeMap_t g_bootOptionTypeMap_t[] = { |
| 267 | |
| 268 | {0x01, "Network"}, |
| 269 | {0x02, "Disk"}, |
| 270 | {0x03, "Safe"}, |
| 271 | {0x05, "CDROM"}, |
| 272 | {0x06, "Setup"}, |
| 273 | {0x00, "Default"}, |
| 274 | {0xFF, INVALID_STRING} |
| 275 | }; |
| 276 | |
| 277 | uint8_t get_ipmi_boot_option(char *p) { |
| 278 | |
| 279 | bootOptionTypeMap_t *s = g_bootOptionTypeMap_t; |
| 280 | |
| 281 | while (s->ipmibootflag != 0xFF) { |
| 282 | if (!strcmp(s->dbusname,p)) |
| 283 | break; |
| 284 | s++; |
| 285 | } |
| 286 | |
| 287 | if (!s->ipmibootflag) |
| 288 | printf("Failed to find Sensor Type %s\n", p); |
| 289 | |
| 290 | return s->ipmibootflag; |
| 291 | } |
| 292 | |
| 293 | char* get_boot_option_by_ipmi(uint8_t p) { |
| 294 | |
| 295 | bootOptionTypeMap_t *s = g_bootOptionTypeMap_t; |
| 296 | |
| 297 | while (s->ipmibootflag != 0xFF) { |
| 298 | |
| 299 | if (s->ipmibootflag == p) |
| 300 | break; |
| 301 | |
| 302 | s++; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | if (!s->ipmibootflag) |
| 307 | printf("Failed to find Sensor Type 0x%x\n", p); |
| 308 | |
| 309 | return s->dbusname; |
| 310 | } |
| 311 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 312 | ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 313 | ipmi_request_t request, ipmi_response_t response, |
| 314 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 315 | { |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 316 | ipmi_ret_t rc = IPMI_CC_PARM_NOT_SUPPORTED; |
| 317 | char *p = NULL; |
| 318 | get_sys_boot_options_response_t *resp = (get_sys_boot_options_response_t *) response; |
| 319 | get_sys_boot_options_t *reqptr = (get_sys_boot_options_t*) request; |
| 320 | uint8_t s; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 321 | |
| 322 | printf("IPMI GET_SYS_BOOT_OPTIONS\n"); |
| 323 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 324 | memset(resp,0,sizeof(*resp)); |
| 325 | resp->version = SET_PARM_VERSION; |
| 326 | resp->parm = 5; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 327 | resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 328 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 329 | *data_len = sizeof(*resp); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 330 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 331 | /* |
| 332 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 333 | * This is the only parameter used by petitboot. |
| 334 | */ |
| 335 | if (reqptr->parameter == 5) { |
| 336 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 337 | /* Get the boot device */ |
| 338 | int r = dbus_get_property("boot_flags",&p); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 339 | |
| 340 | if (r < 0) { |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 341 | fprintf(stderr, "Dbus get property(boot_flags) failed for get_sys_boot_options.\n"); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 342 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 343 | |
| 344 | } else { |
| 345 | |
| 346 | s = get_ipmi_boot_option(p); |
| 347 | resp->data[1] = (s << 2); |
| 348 | rc = IPMI_CC_OK; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 349 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 350 | } |
| 351 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 352 | if (p) |
| 353 | { |
| 354 | free(p); |
| 355 | p = NULL; |
| 356 | } |
| 357 | |
| 358 | /* Get the boot policy */ |
| 359 | r = dbus_get_property("boot_policy",&p); |
| 360 | |
| 361 | if (r < 0) { |
| 362 | fprintf(stderr, "Dbus get property(boot_policy) failed for get_sys_boot_options.\n"); |
| 363 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 364 | |
| 365 | } else { |
| 366 | |
| 367 | printf("BootPolicy is[%s]", p); |
| 368 | resp->data[0] = (strncmp(p,"ONETIME",strlen("ONETIME"))==0) ? |
| 369 | SET_PARM_BOOT_FLAGS_VALID_ONE_TIME: |
| 370 | SET_PARM_BOOT_FLAGS_VALID_PERMANENT; |
| 371 | rc = IPMI_CC_OK; |
| 372 | |
| 373 | } |
| 374 | |
| 375 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 376 | } else { |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 377 | fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | if (p) |
| 381 | free(p); |
| 382 | |
| 383 | return rc; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | |
| 388 | ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 389 | ipmi_request_t request, ipmi_response_t response, |
| 390 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 391 | { |
| 392 | ipmi_ret_t rc = IPMI_CC_OK; |
| 393 | char *s; |
| 394 | |
| 395 | printf("IPMI SET_SYS_BOOT_OPTIONS\n"); |
| 396 | |
| 397 | set_sys_boot_options_t *reqptr = (set_sys_boot_options_t *) request; |
| 398 | |
| 399 | // This IPMI command does not have any resposne data |
| 400 | *data_len = 0; |
| 401 | |
| 402 | /* 000101 |
| 403 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 404 | * This is the only parameter used by petitboot. |
| 405 | */ |
| 406 | if (reqptr->parameter == 5) { |
| 407 | |
| 408 | s = get_boot_option_by_ipmi(((reqptr->data[1] & 0x3C) >> 2)); |
| 409 | |
| 410 | printf("%d: %s\n", __LINE__, s); |
| 411 | if (!strcmp(s,INVALID_STRING)) { |
| 412 | |
| 413 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
| 414 | |
| 415 | } else { |
| 416 | |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 417 | int r = dbus_set_property("boot_flags",s); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 418 | |
| 419 | if (r < 0) { |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 420 | fprintf(stderr, "Dbus set property(boot_flags) failed for set_sys_boot_options.\n"); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 421 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 422 | } |
| 423 | } |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 424 | |
| 425 | /* setting the boot policy */ |
| 426 | s = (char *)(((reqptr->data[0] & SET_PARM_BOOT_FLAGS_PERMANENT) == |
| 427 | SET_PARM_BOOT_FLAGS_PERMANENT) ?"PERMANENT":"ONETIME"); |
| 428 | |
| 429 | printf ( "\nBoot Policy is %s",s); |
| 430 | int r = dbus_set_property("boot_policy",s); |
| 431 | |
| 432 | if (r < 0) { |
| 433 | fprintf(stderr, "Dbus set property(boot_policy) failed for set_sys_boot_options.\n"); |
| 434 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 435 | } |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 436 | |
| 437 | } else { |
| 438 | fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter); |
| 439 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | return rc; |
| 443 | } |
| 444 | |
| 445 | void register_netfn_chassis_functions() |
| 446 | { |
| 447 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_WILDCARD); |
| 448 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL, ipmi_chassis_wildcard); |
| 449 | |
| 450 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS); |
| 451 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL, ipmi_chassis_get_sys_boot_options); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 452 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 453 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL); |
| 454 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL, NULL, ipmi_chassis_control); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 455 | |
| 456 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS); |
| 457 | ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS, NULL, ipmi_chassis_set_sys_boot_options); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 458 | } |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 459 | |