<html><head><META http-equiv="Content-Type" content="text/html;charset=utf-8"></head><body><div id="content" contenteditable="true" spellcheck="true" autocorrect="true" autocapitalize="true" style="font-family: Helvetica;">This commit has patches from a different commit<div><br></div><div>Id there really a need for uint_to_char like functions?</div><div><br></div><div>Sdbus seems to have a bug (or maybe I don't know how to use it) but unref of of a bus doesn't seem to work.  So you should not call sdbus_open   You should call the get_sbus (my correct spelling but I'm on a plane) function found in the ipmid.c. File</div><div><br></div><div>I've never seen a need to create free desktop functions not sure why they are here.   Attaching an object manager is a single function call.  See the phosphor-event repository </div><div><br></div><div><br><br>Sent from my iPhone using IBM Verse<br><br><hr>On Dec 16, 2015, 8:20:47 PM, "OpenBMC Patches" <openbmc-patches@stwcx.xyz> wrote:<br><div style="margin-left: 15px;" id="MaaS360PIMSDKOriginalMessageId">From: shgoupf <shgoupf@cn.ibm.com><br>1) Two methods to handle the dbus property set and get:<br>   a) dbus_set_property()<br>   b) dbus_get_property()<br>2) The property is stored as a 10 character strings which represents<br>5-byte information.<br>3) ipmid set method is registered and implemented since petitboot will<br>use it to clear the boot options.<br>4) 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<br>the above method instead of hard coding.<br>---<br>chassishandler.C | 279 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-<br>chassishandler.h |   8 ++<br>2 files changed, 283 insertions(+), 4 deletions(-)<br>diff --git a/chassishandler.C b/chassishandler.C<br>index 1389db9..35b5086 100644<br>--- a/chassishandler.C<br>+++ b/chassishandler.C<br>@@ -9,6 +9,217 @@ 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_service_name =  "org.openbmc.settings.Host";<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>+char* uint8_to_char(uint8_t *a, size_t size)<br>+{<br>+    char* buffer;<br>+    int i;<br>+<br>+    buffer = (char*)malloc(size * 2 + 1);<br>+    if (!buffer)<br>+        return NULL;<br>+<br>+    buffer[size * 2] = 0;<br>+    for (i = 0; i < size; i++) {<br>+        uint8_t msb = (a[i] >> 4) & 0xF;<br>+        uint8_t lsb = a[i] & 0xF;<br>+        buffer[2*i] = msb > 9 ? msb + 'A' - 10 : msb + '0';<br>+        buffer[2*i + 1] = lsb > 9 ? lsb + 'A' - 10 : lsb + '0';<br>+    }<br>+<br>+    return buffer;<br>+}<br>+<br>+uint8_t* char_to_uint8(char *a, size_t size)<br>+{<br>+    uint8_t* buffer;<br>+    int i;<br>+<br>+    buffer = (uint8_t*)malloc(size);<br>+    if (!buffer)<br>+        return NULL;<br>+<br>+    for (i = 0; i < size; i++) {<br>+        uint8_t msb = (uint8_t)(a[2*i] > '9' ? a[2*i] - 'A' + 10 : a[2*i] - '0');<br>+        uint8_t lsb = (uint8_t)(a[2*i+1] > '9' ? a[2*i+1] - 'A' + 10 : a[2*i+1] - '0');<br>+        buffer[i] = ((msb << 4) | (lsb & 0xF)) & 0xFF;<br>+    }<br>+<br>+    return buffer;<br>+}<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;<br>+    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>+    if (r < 0) {<br>+        fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));<br>+        goto finish;<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>+    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>+    r = sd_bus_message_read(m, "a{sas}", 1, &temp_buf);<br>+    buf_size = strlen(temp_buf) + 1;<br>+    printf("IPMID connection name: %s\n", temp_buf);<br>+    *buf = (char*)malloc(buf_size);<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>+// TODO: object mapper should be used instead of hard-coding.<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>+    int r, i;<br>+<br>+    // Open the system bus where most system services are provided. <br>+    r = sd_bus_open_system(&bus);<br>+    if (r < 0) {<br>+        fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));<br>+        goto finish;<br>+    }<br>+<br>+    object_mapper_get_connection(&connection, settings_object_name);<br>+    printf("connection: %s\n", connection);<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>+    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>+    // The output should be parsed exactly the same as the output formatting<br>+    // specified.<br>+    r = sd_bus_message_read(m, "v", "s", &temp_buf);<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>+    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>+// TODO: object mapper should be used instead of hard-coding.<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>+    // Open the system bus where most system services are provided. <br>+    r = sd_bus_open_system(&bus);<br>+    if (r < 0) {<br>+        fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));<br>+        goto finish;<br>+    }<br>+<br>+    object_mapper_get_connection(&connection, settings_object_name);<br>+    printf("connection: %s\n", connection);<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>+    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>+    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>struct get_sys_boot_options_t {<br>@@ -17,6 +228,15 @@ struct get_sys_boot_options_t {<br>    uint8_t block;<br>}  __attribute__ ((packed));<br><br>+struct set_sys_boot_options_t {<br>+    uint8_t parameter;<br>+    uint8_t data1;<br>+    uint8_t data2;<br>+    uint8_t data3;<br>+    uint8_t data4;<br>+    uint8_t data5;<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>@@ -116,16 +336,63 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br><br>    get_sys_boot_options_t *reqptr = (get_sys_boot_options_t*) request;<br><br>-    // TODO Return default values to OPAL until dbus interface is available<br>+    char* buf = (char*)malloc(NUM_RETURN_BYTES_OF_GET);<br>+<br>+    if (reqptr->parameter == 5) // Parameter #5<br>+    {<br>+        dbus_get_property(buf);<br>+        uint8_t* return_value = char_to_uint8(buf, NUM_RETURN_BYTES_OF_GET_USED);<br>+        *data_len = NUM_RETURN_BYTES_OF_GET;<br>+        // TODO: last 3 bytes<br>+        // (NUM_RETURN_BYTES_OF_GET - NUM_RETURN_BYTES_OF_GET_USED) is meanlingless<br>+        memcpy(response, return_value, *data_len);<br>+        free(buf);<br>+        free(return_value);<br>+    }<br>+    else<br>+    {<br>+        *data_len = NUM_RETURN_BYTES_OF_GET;<br>+        // 0x80: parameter not supported<br>+        buf[0] = 0x80;<br>+        memcpy(response, buf, *data_len);<br>+        free(buf);<br>+        fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);<br>+        return IPMI_CC_PARM_NOT_SUPPORTED;        <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 = (char*)malloc(NUM_RETURN_BYTES_OF_SET);<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>+        char* input_buf = uint8_to_char((uint8_t*)(&(reqptr->data1)), NUM_INPUT_BYTES_OF_SET);<br>+        dbus_set_property(input_buf);<br>+        *data_len = NUM_RETURN_BYTES_OF_SET;<br>+        // 0x0: return code OK.<br>+        output_buf[0] = 0x0;<br>+        memcpy(response, output_buf, *data_len);<br>+        free(output_buf);<br>+        free(input_buf);<br>    }<br>    else<br>    {<br>+        // 0x80: parameter not supported<br>+        output_buf[0] = 0x80;<br>+        memcpy(response, output_buf, *data_len);<br>+        free(output_buf);<br>        fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);<br>        return IPMI_CC_PARM_NOT_SUPPORTED;        <br>    }<br>@@ -133,6 +400,7 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>    return rc;<br>}<br><br>+<br>void register_netfn_chassis_functions()<br>{<br>    printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_WILDCARD);<br>@@ -141,6 +409,9 @@ void register_netfn_chassis_functions()<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_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>diff --git a/chassishandler.h b/chassishandler.h<br>index 1a26411..0164ce1 100644<br>--- a/chassishandler.h<br>+++ b/chassishandler.h<br>@@ -3,12 +3,20 @@<br><br>#include <stdint.h><br><br>+// TODO: Petitboot requires 8 bytes of response<br>+// however only 5 of them are used.<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>-- <br>2.6.3<br>_______________________________________________<br>openbmc mailing list<br>openbmc@lists.ozlabs.org<br>https://lists.ozlabs.org/listinfo/openbmc<br></stdint.h></shgoupf@cn.ibm.com></div></div></div><BR>
</body></html>