<div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt" ><div dir="ltr" >Hey Cyril,</div>
<div dir="ltr" > </div>
<div dir="ltr" >Please see my comments starting with <span style="font-size: 10.5pt;" >>>>> [pengfei]: </span></div>
<div dir="ltr" > </div>
<div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt" ><div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt" ><div dir="ltr" >GOU, Peng Fei (苟鹏飞), Ph.D.</div>
<div dir="ltr" >OpenPower Team.</div>
<div dir="ltr" >+86-21-609-28631</div></div></div>
<div dir="ltr" > </div>
<div dir="ltr" > </div>
<blockquote data-history-content-modified="1" data-history-expanded="1" dir="ltr" style="border-left:solid #aaaaaa 2px; margin-left:5px; padding-left:5px; direction:ltr; margin-right:0px" >----- Original message -----<br>From: Cyril Bur <cyrilbur@gmail.com><br>To: OpenBMC Patches <openbmc-patches@stwcx.xyz>, Peng Fei BG Gou/China/IBM@IBMCN<br>Cc: openbmc@lists.ozlabs.org<br>Subject: Re: [PATCH phosphor-host-ipmid v5] Add get/set boot option ipmid command support with correct DBUS property handling.<br>Date: Thu, Jan 7, 2016 2:05 PM<br>
<div><div><font face="Default Monospace,Courier New,Courier,monospace" size="2" >On Wed, 6 Jan 2016 02:30:29 -0600<br>OpenBMC Patches <openbmc-patches@stwcx.xyz> wrote:<br><br>Hi Peng,<br><br>Thanks for following my recommendations, much appreciated.<br><br>Ultimately we have a common goal which is to have the best possible code go<br>into the project, lets work together on this.<br><br><br><br>> From: shgoupf <shgoupf@cn.ibm.com><br>><br>> 1) Add support for IPMI get/set boot option command.<br>> a) boot options stored in dbus property.<br>> b) IPMI get boot option command get boot option from the dbus<br>> property.<br>> c) IPMI set boot option coomand set boot option to the dbus<br>> property.<br>> 2) Two methods to handle the dbus property set and get:<br>> a) dbus_set_property()<br>> b) dbus_get_property()<br>> 3) The property is stored as a 10 character strings which representsd 5-byte information.<br>> 4) ipmid set method is registered and implemented since petitboot will use it to clear the boot options.<br>> 5) Get service name via object mapper<br>> a) The connection name is got via objectmapper.<br>> b) The method used to get the connection name is object_mapper_get_connection().<br>> c) dbus_get_property/dbus_set_property will get the connection name via the above method instead of hard coding.<br>> 6) Error code are properly handled.<br>> 7) Use sprinf/sscanf for int/string conversion.<br>> a) Instead of reinventing the wheel by defining methods converting int to string, use sprintf/sscanf should be a more clean and robust way.<br>> 8) Fix issues addressed by the community.<br>> a) change malloc heap to stack local variable.<br>> b) Fix multi line comment style from "//" to "/**/".<br>> c) Add defines for return codes.<br>> d) Add more comments.<br>> ---<br>> chassishandler.C | 472 ++++++++++++++++++++++++++++++++++++++++++++++---------<br>> chassishandler.h | 18 +++<br>> 2 files changed, 413 insertions(+), 77 deletions(-)<br>><br>> diff --git a/chassishandler.C b/chassishandler.C<br>> index 1389db9..8d516de 100644<br>> --- a/chassishandler.C<br>> +++ b/chassishandler.C<br>> @@ -5,9 +5,233 @@<br>> #include <stdint.h><br>> <br>> // OpenBMC Chassis Manager dbus framework<br>> -const char *chassis_bus_name = "org.openbmc.control.Chassis";<br>> -const char *chassis_object_name = "/org/openbmc/control/chassis0";<br>> -const char *chassis_intf_name = "org.openbmc.control.Chassis";<br>> +const char *chassis_bus_name = "org.openbmc.control.Chassis";<br>> +const char *chassis_object_name = "/org/openbmc/control/chassis0";<br>> +const char *chassis_intf_name = "org.openbmc.control.Chassis";<br>> +<br>> +// Host settings in dbus<br>> +// Service name should be referenced by connection name got via object mapper<br>> +const char *settings_object_name = "/org/openbmc/settings/host0";<br>> +const char *settings_intf_name = "org.freedesktop.DBus.Properties";<br>> +<br>> +const char *objmapper_service_name = "org.openbmc.objectmapper";<br>> +const char *objmapper_object_name = "/org/openbmc/objectmapper/objectmapper";<br>> +const char *objmapper_intf_name = "org.openbmc.objectmapper.ObjectMapper";<br>> +<br>> +int object_mapper_get_connection(char ** buf, const char * obj_path)<br>> +{<br>> + sd_bus_error error = SD_BUS_ERROR_NULL;<br>> + sd_bus_message * m = NULL;<br>> + sd_bus * bus = NULL;<br>> + char * temp_buf = NULL, *intf = NULL;<br><br>Still strange spacing with the * character</font></div>
<div> </div>
<div>>>>> [pengfei]: Good point. I will fix in my next update. Actually it's just a different style preference. Maybe you will be interested in the astyle which will automatically format your code with various formatting options, as below:</div>
<div><a href="http://astyle.sourceforge.net/astyle.html" >http://astyle.sourceforge.net/astyle.html</a></div>
<div><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> + size_t buf_size = 0;<br>> + int r;<br>> +<br>> + // Open the system bus where most system services are provided.<br>> + r = sd_bus_open_system(&bus);<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));<br>> + goto finish;<br>> + }<br>> +<br>> + /*<br>> + * Bus, service, object path, interface and method are provided to call<br>> + * the method.<br>> + * Signatures and input arguments are provided by the arguments at the<br>> + * end.<br>> + */<br>> + r = sd_bus_call_method(bus,<br>> + objmapper_service_name, /* service to contact */<br>> + objmapper_object_name, /* object path */<br>> + objmapper_intf_name, /* interface name */<br>> + "GetObject", /* method name */<br>> + &error, /* object to return error in */<br>> + &m, /* return message on success */<br>> + "s", /* input signature */<br>> + obj_path /* first argument */<br>> + );<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to issue method call: %s\n", error.message);<br>> + goto finish;<br>> + }<br>> +<br>> + // Get the key, aka, the connection name<br>> + sd_bus_message_read(m, "a{sas}", 1, &temp_buf, 1, &intf);<br>> +<br><br>Still unsure about these interfaces, are you commenting them in the docs repo?</font></div>
<div><br>>>>> [pengfei]: Actually "busctl introspect" will give all the information about what exactly the signature a dbus method/property has. So there is no need for a specific doc. please refer to "busctl introspect" for the signature of each dbus method. As a result, I believe the usage in of my dbus signature is fine for now.<br><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> + /*<br>> + * TODO: check the return code. Currently for no reason the message<br>> + * parsing of object mapper is always complaining about<br>> + * "Device or resource busy", but the result seems OK for now. Need<br>> + * further checks.<br>> + * TODO: The following code is preserved in the comments so that it can be<br>> + * resumed after the problem aforementioned is resolved.<br>> + *r = sd_bus_message_read(m, "a{sas}", 1, &temp_buf, 1, &intf);<br>> + *if (r < 0) {<br>> + * fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));<br>> + * goto finish;<br>> + *}<br>> + */<br><br>This still worries me a lot, I've been looking through sd_bus_message_read(),<br>feel free to take a look,<br><a href="https://fossies.org/dox/systemd-228/dir_2d204f9a98721f367282e89b81571312.html" target="_blank" >https://fossies.org/dox/systemd-228/dir_2d204f9a98721f367282e89b81571312.html</a>.<br><br>If it returns a negative value there is absolutely no guarantee that it has<br>correctly set the parameters you passed, it may not have at all depending on at<br>which point it detects the error. This means you might be reading from an<br>invalid pointer later on.<br><br>I know you say it works, I'm concerned that you might be getting quite lucky<br>and that it only appears to work.</font></div>
<div> </div>
<div>>>>> [pengfei]: Again. I believe this piece of code is tricky here. But I believe there should be some problem in the objecmapper, not for this code (I investigate it a lot). This is very simple dbus method call process. So I believe for this patch, a "TODO" is sufficient to address the issues. We can fix it later when object mapper is updated.<br><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> +<br>> + buf_size = strlen(temp_buf) + 1;<br>> + printf("IPMID connection name: %s\n", temp_buf);<br>> + *buf = (char *)malloc(buf_size);<br>> +<br>> + if (*buf == NULL) {<br>> + fprintf(stderr, "Malloc failed for get_sys_boot_options");<br>> + r = -1;<br>> + goto finish;<br>> + }<br>> +<br>> + memcpy(*buf, temp_buf, buf_size);<br>> +<br>> +finish:<br>> + sd_bus_error_free(&error);<br>> + sd_bus_message_unref(m);<br>> + sd_bus_unref(bus);<br>> +<br>> + return r;<br>> +}<br>> +<br>> +int dbus_get_property(char * buf)<br>> +{<br>> + sd_bus_error error = SD_BUS_ERROR_NULL;<br>> + sd_bus_message * m = NULL;<br>> + sd_bus * bus = NULL;<br>> + char * temp_buf = NULL;<br>> + uint8_t * get_value = NULL;<br>> + char * connection = NULL;<br><br>More strange spacing around the *</font></div>
<div> </div>
<div>>>>> [pengfei]: answered before.<br><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> + int r, i;<br>> +<br>> + r = object_mapper_get_connection(&connection, settings_object_name);<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to get connection, return value: %d.\n", r);<br>> + goto finish;<br>> + }<br>> +<br>> + printf("connection: %s\n", connection);<br>> +<br>> + // Open the system bus where most system services are provided.<br>> + r = sd_bus_open_system(&bus);<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));<br>> + goto finish;<br>> + }<br>> +<br>> + /*<br>> + * Bus, service, object path, interface and method are provided to call<br>> + * the method.<br>> + * Signatures and input arguments are provided by the arguments at the<br>> + * end.<br>> + */<br>> + r = sd_bus_call_method(bus,<br>> + connection, /* service to contact */<br>> + settings_object_name, /* object path */<br>> + settings_intf_name, /* interface name */<br>> + "Get", /* method name */<br>> + &error, /* object to return error in */<br>> + &m, /* return message on success */<br>> + "ss", /* input signature */<br>> + settings_intf_name, /* first argument */<br>> + "boot_flags"); /* second argument */<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to issue method call: %s\n", error.message);<br>> + goto finish;<br>> + }<br>> +<br>> + /*<br>> + * The output should be parsed exactly the same as the output formatting<br>> + * specified.<br>> + */<br>> + r = sd_bus_message_read(m, "v", "s", &temp_buf);<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));<br>> + goto finish;<br>> + }<br>> +<br>> + printf("IPMID boot option property get: {%s}.\n", (char *) temp_buf);<br>> +<br>> + /*<br>> + * To represent a hex in string, e.g., "A0A0", which represents two bytes<br>> + * in the hex, but requires 5 bytes to store it as string, i.e., 4<br>> + * characters to store the "A0A0" and 1 additional space for "\0".<br>> + * Thereby we have 2 * <number of bytes> + 1 for the string buffer.<br>> + */<br>> + memcpy(buf, temp_buf, 2 * NUM_RETURN_BYTES_OF_GET_USED + 1);<br>> +<br>> +finish:<br>> + sd_bus_error_free(&error);<br>> + sd_bus_message_unref(m);<br>> + sd_bus_unref(bus);<br>> + free(connection);<br>> +<br>> + return r;<br>> +}<br>> +<br>> +int dbus_set_property(const char * buf)<br>> +{<br>> + sd_bus_error error = SD_BUS_ERROR_NULL;<br>> + sd_bus_message * m = NULL;<br>> + sd_bus * bus = NULL;<br>> + char * connection = NULL;<br>> + int r;<br>> +<br>> + r = object_mapper_get_connection(&connection, settings_object_name);<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to get connection, return value: %d.\n", r);<br>> + goto finish;<br>> + }<br>> +<br>> + printf("connection: %s\n", connection);<br>> +<br>> + // Open the system bus where most system services are provided.<br>> + r = sd_bus_open_system(&bus);<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));<br>> + goto finish;<br>> + }<br>> +<br>> + /*<br>> + * Bus, service, object path, interface and method are provided to call<br>> + * the method.<br>> + * Signatures and input arguments are provided by the arguments at the<br>> + * end.<br>> + */<br>> + r = sd_bus_call_method(bus,<br>> + connection, /* service to contact */<br>> + settings_object_name, /* object path */<br>> + settings_intf_name, /* interface name */<br>> + "Set", /* method name */<br>> + &error, /* object to return error in */<br>> + &m, /* return message on success */<br>> + "ssv", /* input signature */<br>> + settings_intf_name, /* first argument */<br>> + "boot_flags", /* second argument */<br>> + "s", /* third argument */<br>> + buf); /* fourth argument */<br><br>Still unsure about these interfaces, are you commenting them in the docs repo?</font></div>
<div><br>>>>> [pengfei]: answered before.</div>
<div><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Failed to issue method call: %s\n", error.message);<br>> + goto finish;<br>> + }<br>> +<br>> + printf("IPMID boot option property set: {%s}.\n", buf);<br>> +<br>> +finish:<br>> + sd_bus_error_free(&error);<br>> + sd_bus_message_unref(m);<br>> + sd_bus_unref(bus);<br>> + free(connection);<br>> +<br>> + return r;<br>> +}<br>> <br>> void register_netfn_chassis_functions() __attribute__((constructor));<br>> <br>> @@ -15,13 +239,30 @@ struct get_sys_boot_options_t {<br>> uint8_t parameter;<br>> uint8_t set;<br>> uint8_t block;<br>> -} __attribute__ ((packed));<br>> +} __attribute__((packed));<br>> <br>> -ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> - ipmi_request_t request, ipmi_response_t response,<br>> - ipmi_data_len_t data_len, ipmi_context_t context)<br>> +struct set_sys_boot_options_t {<br>> + uint8_t parameter;<br>> + union {<br>> + struct {<br>> + uint8_t d1;<br>> + uint8_t d2;<br>> + uint8_t d3;<br>> + uint8_t d4;<br>> + uint8_t d5;<br>> + uint8_t d6;<br>> + uint8_t d7;<br>> + uint8_t d8;<br>> + } data8;<br>> + uint64_t data64;<br>> + } data;<br>> +} __attribute__((packed));<br>> +<br>> +ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> + ipmi_request_t request, ipmi_response_t response,<br>> + ipmi_data_len_t data_len, ipmi_context_t context)<br>> {<br>> - printf("Handling CHASSIS WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);<br>> + printf("Handling CHASSIS WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n", netfn, cmd);<br>> // Status code.<br>> ipmi_ret_t rc = IPMI_CC_OK;<br>> *data_len = 0;<br>> @@ -31,103 +272,176 @@ ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> //------------------------------------------------------------<br>> // Calls into Chassis Control Dbus object to do the power off<br>> //------------------------------------------------------------<br>> -int ipmi_chassis_power_control(const char *method)<br>> +int ipmi_chassis_power_control(const char * method)<br>> {<br>> - // sd_bus error<br>> - int rc = 0;<br>> + // sd_bus error<br>> + int rc = 0;<br>> <br>> // SD Bus error report mechanism.<br>> sd_bus_error bus_error = SD_BUS_ERROR_NULL;<br>> <br>> - // Response from the call. Although there is no response for this call,<br>> - // obligated to mention this to make compiler happy.<br>> - sd_bus_message *response = NULL;<br>> -<br>> - // Gets a hook onto either a SYSTEM or SESSION bus<br>> - sd_bus *bus_type = ipmid_get_sd_bus_connection();<br>> -<br>> - rc = sd_bus_call_method(bus_type, // On the System Bus<br>> - chassis_bus_name, // Service to contact<br>> - chassis_object_name, // Object path<br>> - chassis_intf_name, // Interface name<br>> - method, // Method to be called<br>> - &bus_error, // object to return error<br>> - &response, // Response buffer if any<br>> - NULL); // No input arguments<br>> - if(rc < 0)<br>> - {<br>> - fprintf(stderr,"ERROR initiating Power Off:[%s]\n",bus_error.message);<br>> - }<br>> - else<br>> - {<br>> - printf("Chassis Power Off initiated successfully\n");<br>> - }<br>> + /*<br>> + * Response from the call. Although there is no response for this call,<br>> + * obligated to mention this to make compiler happy.<br>> + */<br>> + sd_bus_message * response = NULL;<br>> +<br>> + // Gets a hook onto either a SYSTEM or SESSION bus<br>> + sd_bus * bus_type = ipmid_get_sd_bus_connection();<br>> +<br>> + rc = sd_bus_call_method(bus_type, /* On the System Bus*/<br>> + chassis_bus_name, /* Service to contact*/<br>> + chassis_object_name, /* Object path*/<br>> + chassis_intf_name, /* Interface name*/<br>> + method, /* Method to be called*/<br>> + &bus_error, /* object to return error*/<br>> + &response, /* Response buffer if any*/<br>> + NULL); /* No input arguments*/<br>> +<br>> + if (rc < 0) {<br>> + fprintf(stderr, "ERROR initiating Power Off:[%s]\n", bus_error.message);<br>> + } else {<br>> + printf("Chassis Power Off initiated successfully\n");<br>> + }<br>> <br>> sd_bus_error_free(&bus_error);<br>> sd_bus_message_unref(response);<br>> <br>> - return rc;<br>> + return rc;<br>> }<br>> <br>> <br>> //----------------------------------------------------------------------<br>> // Chassis Control commands<br>> //----------------------------------------------------------------------<br>> -ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> - ipmi_request_t request, ipmi_response_t response,<br>> - ipmi_data_len_t data_len, ipmi_context_t context)<br>> +ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> + ipmi_request_t request, ipmi_response_t response,<br>> + ipmi_data_len_t data_len, ipmi_context_t context)<br>> {<br>> - // Error from power off.<br>> - int rc = 0;<br>> + // Error from power off.<br>> + int rc = 0;<br>> <br>> - // No response for this command.<br>> + // No response for this command.<br>> *data_len = 0;<br>> <br>> - // Catch the actual operaton by peeking into request buffer<br>> - uint8_t chassis_ctrl_cmd = *(uint8_t *)request;<br>> - printf("Chassis Control Command: Operation:[0x%X]\n",chassis_ctrl_cmd);<br>> -<br>> - switch(chassis_ctrl_cmd)<br>> - {<br>> - case CMD_POWER_OFF:<br>> - rc = ipmi_chassis_power_control("powerOff");<br>> - break;<br>> - case CMD_HARD_RESET:<br>> - rc = ipmi_chassis_power_control("reboot");<br>> - break;<br>> - default:<br>> - {<br>> - fprintf(stderr, "Invalid Chassis Control command:[0x%X] received\n",chassis_ctrl_cmd);<br>> - rc = -1;<br>> - }<br>> - }<br>> -<br>> - return ( (rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK);<br>> + // Catch the actual operaton by peeking into request buffer<br>> + uint8_t chassis_ctrl_cmd = * (uint8_t *)request;<br>> + printf("Chassis Control Command: Operation:[0x%X]\n", chassis_ctrl_cmd);<br>> +<br>> + switch (chassis_ctrl_cmd) {<br>> + case CMD_POWER_OFF:<br>> + rc = ipmi_chassis_power_control("powerOff");<br>> + break;<br>> +<br>> + case CMD_HARD_RESET:<br>> + rc = ipmi_chassis_power_control("reboot");<br>> + break;<br>> +<br>> + default: {<br>> + fprintf(stderr, "Invalid Chassis Control command:[0x%X] received\n", chassis_ctrl_cmd);<br>> + rc = -1;<br>> + }<br>> + }<br>> +<br>> + return ((rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK);<br>> }<br>> <br>> -ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> - ipmi_request_t request, ipmi_response_t response,<br>> - ipmi_data_len_t data_len, ipmi_context_t context)<br>> +ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> + ipmi_request_t request, ipmi_response_t response,<br>> + ipmi_data_len_t data_len, ipmi_context_t context)<br>> {<br>> ipmi_ret_t rc = IPMI_CC_OK;<br>> *data_len = 0;<br>> <br>> printf("IPMI GET_SYS_BOOT_OPTIONS\n");<br>> <br>> - get_sys_boot_options_t *reqptr = (get_sys_boot_options_t*) request;<br>> + get_sys_boot_options_t * reqptr = (get_sys_boot_options_t *) request;<br>> +<br>> + /*<br>> + * To represent a hex in string, e.g., "A0A0", which represents two bytes<br>> + * in the hex, but requires 5 bytes to store it as string, i.e., 4<br>> + * characters to store the "A0A0" and 1 additional space for "\0".<br>> + * Thereby we have 2 * <number of bytes> + 1 for the string buffer.<br>> + */<br>> + char buf[NUM_RETURN_BYTES_OF_GET * 2 + 1] = {0};<br><br>I still don't follow why these odd #define numbers, why don't you put the * 2 +<br>1 inside the #define?<br><br>Or, really we should be discussing why numbers are being passed around as<br>strings.</font></div>
<div> </div>
<div>>>>> [pengfei]: I think the explicit calculation of the bytes in the code is much more clear and straightforward for users. As for why the option is stored as strings. That is because the current developer of the boot option property (not me) prefers that. I don't think this matters a lot. </div>
<div><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> <br>> - // TODO Return default values to OPAL until dbus interface is available<br>> + /*<br>> + * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.<br>> + * This is the only parameter used by petitboot.<br>> + */<br>> + if (reqptr->parameter == 5) {<br>> + int r = dbus_get_property(buf);<br>> <br>> - if (reqptr->parameter == 5) // Parameter #5<br>> - {<br>> - uint8_t buf[] = {0x1,0x5,80,0,0,0,0};<br>> - *data_len = sizeof(buf);<br>> - memcpy(response, &buf, *data_len);<br>> + if (r < 0) {<br>> + fprintf(stderr, "Dbus get property failed for get_sys_boot_options.\n");<br>> + return IPMI_OUT_OF_SPACE;<br>> + }<br>> +<br>> + uint64_t return_value;<br>> + sscanf(buf, "%llX", &return_value);<br><br>Why can't we a) be passing numbers around as numbers b) use the correct tool<br>for the job.</font></div>
<div> </div>
<div>>>>> [pengfei]: answered before. The boot option is stored as string, not integer, so the conversion is necessary.<br><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> +<br>> + *data_len = NUM_RETURN_BYTES_OF_GET;<br>> + /*<br>> + * TODO: last 3 bytes<br>> + *(NUM_RETURN_BYTES_OF_GET - NUM_RETURN_BYTES_OF_GET_USED) is meanlingless<br>> + */<br>> + memcpy(response, (uint8_t *)(&return_value), *data_len);<br>> + } else {<br>> + *data_len = NUM_RETURN_BYTES_OF_GET;<br>> + // Parameter not supported<br>> + buf[0] = IPMI_CC_PARM_NOT_SUPPORTED;<br>> + memcpy(response, buf, *data_len);<br><br>... previous comments, there really is no need for the memcpy</font></div>
<div> </div>
<div>>>>> [pengfei]: I believe the memcpy is needed to keep return value correct and consistent if different return size is used.<br><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> + fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);<br>> + return IPMI_CC_PARM_NOT_SUPPORTED;<br>> }<br>> - else<br>> - {<br>> +<br>> + return rc;<br>> +}<br>> +<br>> +ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> + ipmi_request_t request, ipmi_response_t response,<br>> + ipmi_data_len_t data_len, ipmi_context_t context)<br>> +{<br>> + ipmi_ret_t rc = IPMI_CC_OK;<br>> +<br>> + printf("IPMI SET_SYS_BOOT_OPTIONS\n");<br>> + printf("IPMID set command required return bytes: %i\n", *data_len);<br>> +<br>> + set_sys_boot_options_t * reqptr = (set_sys_boot_options_t *) request;<br>> +<br>> + char output_buf[NUM_RETURN_BYTES_OF_SET] = {0};<br>> +<br>> + /*<br>> + * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.<br>> + * This is the only parameter used by petitboot.<br>> + */<br>> + if (reqptr->parameter == 5) {<br>> + /*<br>> + * To represent a hex in string, e.g., "A0A0", which represents two bytes<br>> + * in the hex, but requires 5 bytes to store it as string, i.e., 4<br>> + * characters to store the "A0A0" and 1 additional space for "\0".<br>> + * Thereby we have 2 * <number of bytes> + 1 for the string buffer.<br>> + */<br>> + char input_buf[NUM_INPUT_BYTES_OF_SET * 2 + 1];<br>> + sprintf(input_buf, "%llX", reqptr->data.data64);<br>> +<br>> + int r = dbus_set_property(input_buf);<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Dbus set property failed for set_sys_boot_options.\n");<br>> + return IPMI_OUT_OF_SPACE;<br>> + }<br>> +<br>> + *data_len = NUM_RETURN_BYTES_OF_SET;<br>> + // Return code OK.<br>> + output_buf[0] = IPMI_OK;<br>> + memcpy(response, output_buf, *data_len);<br>> + } else {<br>> + // Parameter not supported<br>> + output_buf[0] = IPMI_CC_PARM_NOT_SUPPORTED;<br>> + memcpy(response, output_buf, *data_len);<br><br>... previous comments, there really is no need for the memcpy</font></div>
<div> </div>
<div>>>>> [pengfei]: answered before.<br><br><font face="Default Monospace,Courier New,Courier,monospace" size="2" >> fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);<br>> - return IPMI_CC_PARM_NOT_SUPPORTED; <br>> + return IPMI_CC_PARM_NOT_SUPPORTED;<br>> }<br>> <br>> return rc;<br>> @@ -135,12 +449,16 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> <br>> void register_netfn_chassis_functions()<br>> {<br>> - printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_WILDCARD);<br>> + printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_CHASSIS, IPMI_CMD_WILDCARD);<br>> ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL, ipmi_chassis_wildcard);<br>> <br>> - printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS);<br>> + printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS);<br>> ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL, ipmi_chassis_get_sys_boot_options);<br>> <br>> - printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL);<br>> + printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS);<br>> + ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS, NULL, ipmi_chassis_set_sys_boot_options);<br>> +<br>> + printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL);<br>> ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL, NULL, ipmi_chassis_control);<br>> }<br>> +<br>> diff --git a/chassishandler.h b/chassishandler.h<br>> index 1a26411..a310741 100644<br>> --- a/chassishandler.h<br>> +++ b/chassishandler.h<br>> @@ -3,21 +3,39 @@<br>> <br>> #include <stdint.h><br>> <br>> +// TODO: Petitboot requires 8 bytes of response<br>> +// however only 5 of them are used. The remaining<br>> +// 3 bytes are not used in petitboot and the value<br>> +// of them are all zero.<br>> +#define NUM_RETURN_BYTES_OF_GET 8<br>> +#define NUM_RETURN_BYTES_OF_GET_USED 5<br>> +#define NUM_RETURN_BYTES_OF_SET 1<br>> +#define NUM_INPUT_BYTES_OF_SET 5<br>> +<br>> // IPMI commands for Chassis net functions.<br>> enum ipmi_netfn_app_cmds<br>> {<br>> // Chassis Control<br>> IPMI_CMD_CHASSIS_CONTROL = 0x02,<br>> // Get capability bits<br>> + IPMI_CMD_SET_SYS_BOOT_OPTIONS = 0x08,<br>> IPMI_CMD_GET_SYS_BOOT_OPTIONS = 0x09,<br>> };<br>> <br>> // Command specific completion codes<br>> enum ipmi_chassis_return_codes<br>> {<br>> + IPMI_OK = 0x0,<br>> IPMI_CC_PARM_NOT_SUPPORTED = 0x80,<br>> };<br>> <br>> +// Generic completion codes,<br>> +// see IPMI doc section 5.2<br>> +enum ipmi_generic_return_codes<br>> +{<br>> + IPMI_OUT_OF_SPACE = 0xC4,<br>> +};<br>> +<br>> // Various Chassis operations under a single command.<br>> enum ipmi_chassis_control_cmds : uint8_t<br>> {</font></div></div></blockquote>
<div dir="ltr" > </div></div><BR>