Re: Need help with the NetworkManager DBUS API
On Monday 14 of February 2011 05:52:16 Anurup Raveendran wrote: i'm trying to establish a wireless network connection using the DBUS API but i have failed miserably. i have attached the code that I'm using. Regards, Instead 'failed miserably' you should say what is the real problem ;) And it is that the segmentation fault happens due to bad types of s_wireless properties. SSID is not string but a byte array (it can generaly contain 0) and the mode should be adhoc or infrastructure. See corrected example in the attachment. Jirka /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * (C) Copyright 2011 Red Hat, Inc. */ /* * The example shows how to call AddConnection() D-Bus method to add * a connection to system settings service. It uses dbus-glib and libnm-util * libraries. * * Compile with: * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util` add-wireless-connection-glib.c -o add-wireless-connection-glib */ #include glib.h #include dbus/dbus-glib.h #include nm-connection.h #include nm-setting-connection.h #include nm-setting-wireless.h #include nm-setting-ip4-config.h #include NetworkManager.h #include nm-utils.h #define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map (GHashTable, G_TYPE_STRING, G_TYPE_VALUE)) #define DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT (dbus_g_type_get_map (GHashTable, G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT)) static void add_connection (DBusGProxy *proxy, const char *con_name) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingIP4Config *s_ip4; char *uuid; GHashTable *hash; GByteArray *ssid; const unsigned char ssid_data[] = { 'T', 'e', 's', 't' }; GError *error = NULL; /* Create a new connection object */ connection = (NMConnection *) nm_connection_new (); /* Build up the 'connection' Setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_ID, con_name, NM_SETTING_CONNECTION_TYPE, 802-11-wireless, NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); /* Build up the 'wireless' Setting */ s_wireless = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wireless)); ssid = g_byte_array_sized_new (sizeof (ssid_data)); g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); g_object_set(s_wireless, NM_SETTING_WIRELESS_SSID, ssid, NULL); g_object_set(s_wireless, NM_SETTING_WIRELESS_MODE, adhoc, NULL); g_byte_array_free (ssid, TRUE); /* Build up the 'ipv4' Setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); hash = nm_connection_to_hash (connection); /* Call AddConnection with the hash as argument */ dbus_g_proxy_call (proxy, AddConnection, error, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, G_TYPE_INVALID); g_hash_table_destroy (hash); g_object_unref (connection); } int main (int argc, char *argv[]) { DBusGConnection *bus; DBusGProxy *proxy; /* Initialize GType system */ g_type_init (); /* Get system bus */ bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); /* Create a D-Bus proxy; NM_DBUS_* defined in NetworkManager.h */ proxy = dbus_g_proxy_new_for_name (bus, NM_DBUS_SERVICE_SYSTEM_SETTINGS, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS); /* Add a connection */ add_connection (proxy, __Test connection__); g_object_unref (proxy); dbus_g_connection_unref (bus); return 0; } ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Need help with the NetworkManager DBUS API
If you're trying to establish a connection while nm-applet is running then you have to add the connection information through gconf which nm-applet will pickup and create a new connection through NetworkManager. Hope this helps, Greg On Sun, Feb 13, 2011 at 8:52 PM, Anurup Raveendran anurupraveend...@gmail.com wrote: i'm trying to establish a wireless network connection using the DBUS API but i have failed miserably. i have attached the code that I'm using. Regards, -- Anurup Raveendran Computer Science Engineering(2007-2011) Model Engineering College, Cochin Mobile: +919895301078 Landline : 0496-2503009 E-mail id : anurupraveend...@gmail.com ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
RE: Need help with the NetworkManager DBUS API
I don't know whether this will help Anurup or not. I see that instead of using gconf, you can add the connections to the nm-applet via dbus. Regards, Jos Collin From: networkmanager-list-boun...@gnome.org [networkmanager-list-boun...@gnome.org] On Behalf Of Greg Suarez [gpsuarez2...@gmail.com] Sent: Tuesday, February 15, 2011 10:02 AM To: networkmanager-list@gnome.org Subject: Re: Need help with the NetworkManager DBUS API If you're trying to establish a connection while nm-applet is running then you have to add the connection information through gconf which nm-applet will pickup and create a new connection through NetworkManager. Hope this helps, Greg On Sun, Feb 13, 2011 at 8:52 PM, Anurup Raveendran anurupraveend...@gmail.commailto:anurupraveend...@gmail.com wrote: i'm trying to establish a wireless network connection using the DBUS API but i have failed miserably. i have attached the code that I'm using. Regards, -- Anurup Raveendran Computer Science Engineering(2007-2011) Model Engineering College, Cochin Mobile: +919895301078 Landline : 0496-2503009 E-mail id : anurupraveend...@gmail.commailto:anurupraveend...@gmail.com ___ networkmanager-list mailing list networkmanager-list@gnome.orgmailto:networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list ::DISCLAIMER:: --- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any mail and attachments please check them for viruses and defect. --- ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
Need help with the NetworkManager DBUS API
i'm trying to establish a wireless network connection using the DBUS API but i have failed miserably. i have attached the code that I'm using. Regards, -- Anurup Raveendran Computer Science Engineering(2007-2011) Model Engineering College, Cochin Mobile: +919895301078 Landline : 0496-2503009 E-mail id : anurupraveend...@gmail.com /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * (C) Copyright 2010 Red Hat, Inc. */ /* * The example shows how to call AddConnection() D-Bus method to add * a connection to system settings service. It uses dbus-glib and libnm-util * libraries. * * Compile with: * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm-util` add-connection-glib.c -o add-connection-glib */ #include glib.h #include dbus/dbus-glib.h #include nm-connection.h #include nm-setting-connection.h #include nm-setting-wireless.h #include nm-setting-ip4-config.h #include NetworkManager.h #include nm-utils.h #define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map (GHashTable, G_TYPE_STRING, G_TYPE_VALUE)) #define DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT (dbus_g_type_get_map (GHashTable, G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT)) static void add_connection (DBusGProxy *proxy, const char *con_name) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingIP4Config *s_ip4; char *uuid; GHashTable *hash; GError *error = NULL; /* Create a new connection object */ connection = (NMConnection *) nm_connection_new (); /* Build up the 'connection' Setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_ID, con_name, NM_SETTING_CONNECTION_TYPE, 802-11-wireless, NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); /* Build up the 'wireless' Setting */ s_wireless = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wireless)); g_object_set(s_wireless, NM_SETTING_WIRELESS_SSID,Test, NULL); g_object_set(s_wireless, NM_SETTING_WIRELESS_MODE, Ad-Hoc, NULL); /* Build up the 'ipv4' Setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); hash = nm_connection_to_hash (connection); /* Call AddConnection with the hash as argument */ dbus_g_proxy_call (proxy, AddConnection, error, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, G_TYPE_INVALID); g_hash_table_destroy (hash); g_object_unref (connection); } int main (int argc, char *argv[]) { DBusGConnection *bus; DBusGProxy *proxy; /* Initialize GType system */ g_type_init (); /* Get system bus */ bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); /* Create a D-Bus proxy; NM_DBUS_* defined in NetworkManager.h */ proxy = dbus_g_proxy_new_for_name (bus, NM_DBUS_SERVICE_SYSTEM_SETTINGS, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS); /* Add a connection */ add_connection (proxy, __Test connection__); g_object_unref (proxy); dbus_g_connection_unref (bus); return 0; } ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list