Здравствуйте! Собственно, сабж. Ниже то, что навоял по немногим примерам. Казалось бы, куда проще ssid + password = connect, НО оказалось, библиотека куда более сложна. Думаю, проблема в настройках соедиенния или в specific_object в ф-и подключения.
gboolean wi_fi_dev_activate_connection(const gchar * ssid, const gchar * key)
{
//получаем устройство
NMDevice *device = get_device_by_type(NM_WIFI_DEVICE);
if (device == NULL) {
printf("Cannot get available device!\n");
return FALSE;
}
//получаем точку доступа по ssid
NMAccessPoint* ap = wifi_device_get_ap_by_ssid(device, ssid);
if (ap == NULL) {
printf("Cannot get acces point!\n");
return FALSE;
}
//создаем подключение
NMConnection *connection = nm_connection_new();
//натраиваем его...
//общие настройки
NMSettingConnection *s_connection =
(NMSettingConnection *) nm_setting_connection_new();
char *uuid = nm_utils_uuid_generate();
g_object_set(s_connection,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
NM_SETTING_CONNECTION_UUID, uuid, "autoconnect", TRUE, "id",
ssid, "name", "wireless", NULL);
nm_connection_add_setting(connection, (NMSetting *) s_connection);
g_free(uuid);
//настройки беспроводного
NMSettingWireless *s_wireless =
(NMSettingWireless *) nm_setting_wireless_new();
GByteArray *_ssid;
gint len = strlen(ssid);
_ssid = g_byte_array_sized_new(len);
g_byte_array_append(_ssid, (const guint8 *) ssid, len);
g_object_set(s_wireless, NM_SETTING_WIRELESS_SSID, _ssid,
NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, NULL);
g_byte_array_free(_ssid, TRUE);
nm_connection_add_setting(connection, (NMSetting *) s_wireless);
//настройки безопасности
NMSettingWirelessSecurity *s_wireless_security =
(NMSettingWirelessSecurity *) nm_setting_wireless_security_new();
g_object_set(s_wireless_security, "wep-key0", key, "key-mgmt","ieee8021x", NULL);
nm_connection_add_setting(connection,(NMSetting *) s_wireless_security);
//настройки IP4(6)
NMSettingIP4Config *s_ip4 =
(NMSettingIP4Config *) nm_setting_ip4_config_new();
g_object_set(s_ip4, NM_SETTING_IP4_CONFIG_METHOD,
NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting(connection, (NMSetting *) s_ip4);
NMSettingIP6Config *s_ip6 =
(NMSettingIP6Config *) nm_setting_ip6_config_new();
g_object_set(s_ip6, NM_SETTING_IP6_CONFIG_METHOD,
NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting(connection, (NMSetting *) s_ip6);
//Подключаемся...
nm_client_activate_connection(client,
connection,
device,
ap ? nm_object_get_path(NM_OBJECT(ap)) : NULL,
activate_new_cb, NULL);
return TRUE;
}