Wireless Connection Help

Hello all,
I am looking for some help with using NetworkManager in a c++ application.

I am able to use network manager to scan the list of ap's and also go through the list of connections.  I think if the network is already listed in the connection list I need to activate it instead of trying to add it.  

However what I am missing is how do I activate the wireless connection and how do I set the WPA2 key (or other key depending on the security used) I have not found any code examples on how to use ActivateConnection or AddAndActivateConnection2 methods.  

Below was an attempt I made at setting up the connection (borrowed heavily from
https://github.com/lcp/NetworkManager/blob/master/examples/C/glib/add-connection-libnm-glib.c )
gboolean NetworkSettings::add_connection(NMRemoteSettings *settingsGMainLoop *loopconst char *con_namestd::string SSIDstd::string sKey)
   NMConnection *connection;
   NMSettingConnection *s_con;
   NMSettingWireless *s_wireless;
   NMSettingIP4Config *s_ip4;
   char *uuid;
   gboolean success;

   // Create a new connection object 
   connection = nm_connection_new();

   // Build up the 'connection' Setting 
   s_con = (NMSettingConnection *)nm_setting_connection_new();
   uuid = nm_utils_uuid_generate();
                 NM_SETTING_CONNECTION_UUID, uuid,
                 NM_SETTING_CONNECTION_ID, con_name,
                 NM_SETTING_CONNECTION_TYPE, "802-11-wireless",
   nm_connection_add_setting(connection, NM_SETTING(s_con));

   // Build up the 'wireless' Setting 
   s_wireless = (NMSettingWireless *)nm_setting_wireless_new();
      NM_SETTING_WIRELESS_SEC, sKey.c_str(),
   nm_connection_add_setting(connection, NM_SETTING(s_wireless));

   // Build up the 'ipv4' Setting
   s_ip4 = (NMSettingIP4Config *)nm_setting_ip4_config_new();
   nm_connection_add_setting(connection, NM_SETTING(s_ip4));

   // Ask the settings service to add the new connection; we'll quit the
   // mainloop and exit when the callback is called.
   success = nm_remote_settings_add_connection(settings, connection, NetworkSettings::added_cb, loop);
      g_print("Error adding connection\n");

   return success;

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