Mobile broadband connection through gconf settings



Hello,

I am pasting a code which adds a connection for mobile broadband using system settings(i.e NetworkManagerSystemSettings)
I want the same connection to be added using gconf settings. I want the scope of connection to be user and not system. I know it is possible because the network manager applet 0.8 does that using gconf settings. Please help me either by guiding or pasting a relevent code for that. I will be very thankful to you.

Here is the code which I have writen

/*
gcc -Wall `pkg-config --cflags --libs libnm-glib glib-2.0 dbus-glib-1` add_mobile_bb_con.c -o add_mobile_bb_con
*/

#include <stdio.h>
#include <string.h>

#include <dbus/dbus-glib.h>

#include <nm-utils.h>
#include <nm-setting-connection.h>
#include <nm-setting-ip4-config.h>
#include <nm-setting-ppp.h>
#include <nm-setting-gsm.h>
#include <nm-setting-serial.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))

#define NM_DBUS_SERVICE                     "org.freedesktop.NetworkManager"

#define NM_DBUS_PATH                        "/org/freedesktop/NetworkManager"
#define NM_DBUS_INTERFACE                   "org.freedesktop.NetworkManager"
#define NM_DBUS_INTERFACE_DEVICE            NM_DBUS_INTERFACE ".Device"


#define NM_DBUS_INTERFACE_SERIAL_DEVICE     NM_DBUS_INTERFACE_DEVICE ".Serial"
#define NM_DBUS_INTERFACE_GSM_DEVICE        NM_DBUS_INTERFACE_DEVICE ".Gsm"
#define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active"
#define NM_DBUS_INTERFACE_IP4_CONFIG        NM_DBUS_INTERFACE ".IP4Config"

#define NM_DBUS_SERVICE_USER_SETTINGS     "org.freedesktop.NetworkManagerUserSettings"
#define NM_DBUS_SERVICE_SYSTEM_SETTINGS   "org.freedesktop.NetworkManagerSystemSettings"
#define NM_DBUS_IFACE_SETTINGS            "org.freedesktop.NetworkManagerSettings"
#define NM_DBUS_IFACE_SETTINGS_SYSTEM     "org.freedesktop.NetworkManagerSettings.System"
#define NM_DBUS_PATH_SETTINGS             "/org/freedesktop/NetworkManagerSettings"

#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection"
#define NM_DBUS_PATH_SETTINGS_CONNECTION  "/org/freedesktop/NetworkManagerSettings/Connection"

void add_mobile_bb_con(char*);

int main (int argc, char **argv)
{
        char* apn = "internet";

        add_mobile_bb_con (apn);

        return 0;
}

void
add_mobile_bb_con (char* apn)
{
        NMConnection *connection;
        NMSettingConnection *settingCon;
        NMSettingIP4Config *settingIP4;
        NMSettingGsm *settingGSM;
        NMSettingPPP *settingPPP;
        NMSettingSerial *settingSerial;
        char *uuid;
       
        DBusGConnection *bus;
        DBusGProxy *proxy;
        GError *error = NULL;
        GHashTable *settings=NULL;

        g_type_init ();

        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
        if (!bus)
                printf ("Couldn't connect to system bus");

        proxy = dbus_g_proxy_new_for_name (bus,
                         NM_DBUS_SERVICE_SYSTEM_SETTINGS,
                         NM_DBUS_PATH_SETTINGS,
                         NM_DBUS_IFACE_SETTINGS);

        if (!proxy)
                printf ("Failed to get name owner");

        connection = nm_connection_new ();

        /* Connection setting */
        settingCon = (NMSettingConnection *) nm_setting_connection_new ();
        uuid = nm_utils_uuid_generate ();
        g_object_set (settingCon,
                      NM_SETTING_CONNECTION_ID, "GPRS",
                      NM_SETTING_CONNECTION_UUID, uuid,
                      NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
                      NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME,
                      NULL);
    nm_connection_add_setting (connection, NM_SETTING (settingCon));
        g_free (uuid);

        /* GSM setting */
        settingGSM = (NMSettingGsm *) nm_setting_gsm_new ();
        g_object_set (settingGSM,
                      NM_SETTING_GSM_NUMBER, "*99#",
                      NM_SETTING_GSM_APN, apn,
                      NULL);
    nm_connection_add_setting (connection, NM_SETTING (settingGSM));

        /* Serial setting */
        settingSerial = (NMSettingSerial *) nm_setting_serial_new ();
        g_object_set (settingSerial,
                      NM_SETTING_SERIAL_BAUD, 115200,
                      NM_SETTING_SERIAL_BITS, 8,
                      NM_SETTING_SERIAL_PARITY, 'n',
                      NM_SETTING_SERIAL_STOPBITS, 1,
                      NULL);
    nm_connection_add_setting (connection, NM_SETTING (settingSerial));

        /* IP4 setting */
        settingIP4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();       
        g_object_set (settingIP4,
                      NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
                      NULL);
    nm_connection_add_setting (connection, NM_SETTING (settingIP4));

        /* PPP setting */
        settingPPP = (NMSettingPPP *) nm_setting_ppp_new ();
    g_object_set (settingPPP,
                    NM_SETTING_PPP_NOAUTH, TRUE,
                    NM_SETTING_PPP_REFUSE_EAP, TRUE,
            NM_SETTING_PPP_REFUSE_PAP, FALSE,   
                    NM_SETTING_PPP_REFUSE_CHAP, TRUE,
                NM_SETTING_PPP_REFUSE_MSCHAP, TRUE,
            NM_SETTING_PPP_REFUSE_MSCHAPV2, TRUE,
            NM_SETTING_PPP_NOBSDCOMP, TRUE,
            NM_SETTING_PPP_NO_VJ_COMP, TRUE,
            NM_SETTING_PPP_MRU, 1500,
            NM_SETTING_PPP_MTU, 1500,
            NM_SETTING_PPP_LCP_ECHO_FAILURE, 0,
            NM_SETTING_PPP_LCP_ECHO_INTERVAL, 0,
                    NULL);
    nm_connection_add_setting (connection, NM_SETTING (settingPPP));

        settings = nm_connection_to_hash (connection);

        if(!dbus_g_proxy_call (proxy, "AddConnection",
               &error, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT,
               settings, G_TYPE_INVALID))
    {
        g_print ("Error adding connection: %s \n %s \n",
                 dbus_g_error_get_name (error),
                 error->message);
    }

    g_clear_error (&error);

        g_hash_table_destroy(settings);
        g_object_unref (connection);
}
.

--
Regards

NAVEEN M N


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]