<span lang="EN">
<div>Hi All,</div>
<div> </div>
<div> I am trying to call ConnectService API defined in connman (open source connection manager daemon). Connman has defined ConnectService with "a{sv}" signature.</div>
<div> </div>
<div> When I tried to form and send message using below code, code is crashing with signal 11. Please let me know whats the issue in below code.</div>
<div> </div>
<div> </div>
<div>#include <stdio.h> </div>
<div>#include <errno.h> </div>
<div>#include <stdlib.h> </div>
<div>#include <string.h> </div>
<div>#include <stdbool.h></div>
<div>#include <glib.h></div>
<div>#include <dbus/dbus-glib.h></div>
<div>#include <dbus/dbus.h></div>
<div>#include <sys/types.h></div>
<div>#include <sys/stat.h></div>
<div> </div>
<div>typedef struct{</div>
<div>char type[20];</div>
<div>char mode[20];</div>
<div>char ssid[20];</div>
<div>char security[20];</div>
<div>char passphrase[20];</div>
<div>} network_connect_service_info_t;</div>
<div> </div>
<div>static int</div>
<div>network_dbus_connect_service(network_connect_service_info_t* conn_info)</div>
<div>{</div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div>DBusError error; </div>
<div> </div>
<div>const char *prop_type = "Type";</div>
<div>const char *prop_mode = "Mode";</div>
<div>const char *prop_ssid = "SSID";</div>
<div>const char *prop_security = "Security";</div>
<div>const char *prop_passphrase = "Passphrase";</div>
<p style="MARGIN-RIGHT: 0px" dir="ltr"></p>
<div style="MARGIN-RIGHT: 0px" dir="ltr">char* type = conn_info->type;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">char* mode = conn_info->mode;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">char* ssid = conn_info->ssid;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">char* security = conn_info->security;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">char* passphrase = conn_info->passphrase;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBusMessage *msg;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBusMessage *reply;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBusMessageIter dict, entry, array,value;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBusConnection* conn = NULL;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">if (conn == NULL) { </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">printf("Error!!! Can't get on system bus\n");</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">return -1;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">}</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">msg = dbus_message_new_method_call("org.moblin.connman", "/", "org.moblin.connman.Manager", "ConnectService");</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">if(msg == NULL)</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">{</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">printf("Error!!! dbus_message_new_method_call() failed\n");</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">return -1;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">}</div>
<p style="MARGIN-RIGHT: 0px" dir="ltr"> </p>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_init_append(msg, &array);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBUS_TYPE_STRING_AS_STRING </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBUS_TYPE_VARIANT_AS_STRING</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">DBUS_DICT_ENTRY_END_CHAR_AS_STRING,</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">&dict);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_type);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value); </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, type);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&entry, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&dict, &entry);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_mode);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, mode);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&entry, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&dict, &entry); </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_ssid);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, ssid);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&entry, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&dict, &entry); </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_security);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, security);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&entry, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&dict, &entry); </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_passphrase);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, passphrase);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&entry, &value);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&dict, &entry);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_iter_close_container(&array, &dict);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_error_init (&error);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">if (dbus_error_is_set (&error))</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">{</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">printf("Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n", <a href="http://error.name">error.name</a>, error.message);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">return -1;</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">}</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr"> </div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_unref(reply);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_message_unref(msg);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">printf("Successfully configured\n");</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">dbus_connection_unref(conn);</div>
<div style="MARGIN-RIGHT: 0px" dir="ltr">return 0;</div></blockquote>
<div>}</div>
<div> </div>
<div>int main()</div>
<div>{</div>
<p>network_connect_service_info_t connection_info = {"wifi","managed","datanet","psk","datanettest"};</p>
<p>network_dbus_connect_service(&connection_info);</p>
<p>return 0;</p>
<p>}</p></span><br clear="all"><br>-- <br>Regards & Thanks<br>Raghavendra. S<br>9880329621<br>