51
52
static void wireless_dialog_response_cb (GtkDialog *dialog, gint response, gpointer user_data);
54
static void nag_dialog_response_cb (GtkDialog *nag_dialog, gint response, gpointer user_data);
53
56
static NMAccessPoint *update_active_ap (NMDevice *device, NMDeviceState state, NMApplet *applet);
58
static void _do_new_auto_connection (NMApplet *applet,
61
AppletNewAutoConnectionCallback callback,
62
gpointer callback_data);
56
65
show_ignore_focus_stealing_prevention (GtkWidget *widget)
58
69
gtk_widget_realize (widget);
59
70
gtk_widget_show (widget);
60
gtk_window_present_with_time (GTK_WINDOW (widget),
61
gdk_x11_get_server_time (gtk_widget_get_window (widget)));
71
window = gtk_widget_get_window (widget);
72
gtk_window_present_with_time (GTK_WINDOW (widget), gdk_x11_get_server_time (window));
65
other_wireless_activate_cb (GtkWidget *menu_item,
76
applet_wifi_connect_to_hidden_network (NMApplet *applet)
70
80
dialog = nma_wireless_dialog_new_for_other (applet);
74
g_signal_connect (dialog, "response",
75
G_CALLBACK (wireless_dialog_response_cb),
78
show_ignore_focus_stealing_prevention (dialog);
82
g_signal_connect (dialog, "response",
83
G_CALLBACK (wireless_dialog_response_cb),
85
show_ignore_focus_stealing_prevention (dialog);
90
99
gtk_container_add (GTK_CONTAINER (menu_item), label);
91
100
gtk_widget_show_all (menu_item);
92
101
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
93
g_signal_connect (menu_item, "activate", G_CALLBACK (other_wireless_activate_cb), applet);
97
new_network_activate_cb (GtkWidget *menu_item, NMApplet *applet)
102
g_signal_connect_swapped (menu_item, "activate",
103
G_CALLBACK (applet_wifi_connect_to_hidden_network),
108
applet_wifi_can_create_wifi_network (NMApplet *applet)
110
gboolean disabled, allowed = FALSE;
111
NMClientPermissionResult perm;
112
GError *error = NULL;
114
/* FIXME: check WIFI_SHARE_PROTECTED too, and make the wireless dialog
115
* handle the permissions as well so that admins can restrict open network
116
* creation separately from protected network creation.
118
perm = nm_client_get_permission_result (applet->nm_client, NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN);
119
if (perm == NM_CLIENT_PERMISSION_RESULT_YES || perm == NM_CLIENT_PERMISSION_RESULT_AUTH) {
120
disabled = gconf_client_get_bool (applet->gconf_client, PREF_DISABLE_WIFI_CREATE, &error);
121
if (!disabled && !error)
123
g_clear_error (&error);
129
applet_wifi_create_wifi_network (NMApplet *applet)
99
131
GtkWidget *dialog;
101
133
dialog = nma_wireless_dialog_new_for_create (applet);
105
g_signal_connect (dialog, "response",
106
G_CALLBACK (wireless_dialog_response_cb),
109
show_ignore_focus_stealing_prevention (dialog);
135
g_signal_connect (dialog, "response",
136
G_CALLBACK (wireless_dialog_response_cb),
138
show_ignore_focus_stealing_prevention (dialog);
123
152
gtk_container_add (GTK_CONTAINER (menu_item), label);
124
153
gtk_widget_show_all (menu_item);
125
154
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
126
g_signal_connect (menu_item, "activate", G_CALLBACK (new_network_activate_cb), applet);
155
g_signal_connect_swapped (menu_item, "activate",
156
G_CALLBACK (applet_wifi_create_wifi_network),
128
/* FIXME: should really use PolicyKit and NM permissions here instead
129
* using using GConf mandatory settings. But this works for now.
131
disabled = gconf_client_get_bool (applet->gconf_client, PREF_DISABLE_WIFI_CREATE, &error);
132
if (error || disabled)
159
if (!applet_wifi_can_create_wifi_network (applet))
133
160
gtk_widget_set_sensitive (GTK_WIDGET (menu_item), FALSE);
134
g_clear_error (&error);
164
dbus_8021x_add_and_activate_cb (NMClient *client,
165
NMActiveConnection *active,
166
const char *connection_path,
171
g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
181
dbus_connect_8021x_cb (NMConnection *connection,
182
gboolean auto_created,
186
Dbus8021xInfo *info = user_data;
188
if (canceled == FALSE) {
189
g_return_if_fail (connection != NULL);
191
/* Ask NM to add the new connection and activate it; NM will fill in the
192
* missing details based on the specific object and the device.
194
nm_client_add_and_activate_connection (info->applet->nm_client,
197
nm_object_get_path (NM_OBJECT (info->ap)),
198
dbus_8021x_add_and_activate_cb,
202
g_object_unref (info->device);
203
g_object_unref (info->ap);
204
memset (info, 0, sizeof (*info));
209
applet_wifi_connect_to_8021x_network (NMApplet *applet,
215
info = g_malloc0 (sizeof (*info));
216
info->applet = applet;
217
info->device = g_object_ref (device);
218
info->ap = g_object_ref (ap);
220
_do_new_auto_connection (applet, device, ap, dbus_connect_8021x_cb, info);
206
309
return is_ssid_in_list (ssid, blacklisted_ssids);
210
add_ciphers_from_flags (NMSettingWirelessSecurity *sec,
215
if (flags & NM_802_11_AP_SEC_PAIR_TKIP)
216
nm_setting_wireless_security_add_pairwise (sec, "tkip");
217
if (flags & NM_802_11_AP_SEC_PAIR_CCMP)
218
nm_setting_wireless_security_add_pairwise (sec, "ccmp");
220
if (flags & NM_802_11_AP_SEC_GROUP_WEP40)
221
nm_setting_wireless_security_add_group (sec, "wep40");
222
if (flags & NM_802_11_AP_SEC_GROUP_WEP104)
223
nm_setting_wireless_security_add_group (sec, "wep104");
224
if (flags & NM_802_11_AP_SEC_GROUP_TKIP)
225
nm_setting_wireless_security_add_group (sec, "tkip");
226
if (flags & NM_802_11_AP_SEC_GROUP_CCMP)
227
nm_setting_wireless_security_add_group (sec, "ccmp");
231
static NMSettingWirelessSecurity *
232
get_security_for_ap (NMAccessPoint *ap,
235
NMSetting8021x **s_8021x)
237
NMSettingWirelessSecurity *sec;
243
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
244
g_return_val_if_fail (supported != NULL, NULL);
245
g_return_val_if_fail (*supported == TRUE, NULL);
246
g_return_val_if_fail (s_8021x != NULL, NULL);
247
g_return_val_if_fail (*s_8021x == NULL, NULL);
249
sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
251
mode = nm_access_point_get_mode (ap);
252
flags = nm_access_point_get_flags (ap);
253
wpa_flags = nm_access_point_get_wpa_flags (ap);
254
rsn_flags = nm_access_point_get_rsn_flags (ap);
257
if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
258
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
259
&& (rsn_flags == NM_802_11_AP_SEC_NONE))
262
/* Static WEP, Dynamic WEP, or LEAP */
263
if (flags & NM_802_11_AP_FLAGS_PRIVACY) {
264
if ((dev_caps & NM_WIFI_DEVICE_CAP_RSN) || (dev_caps & NM_WIFI_DEVICE_CAP_WPA)) {
265
/* If the device can do WPA/RSN but the AP has no WPA/RSN informatoin
266
* elements, it must be LEAP or static/dynamic WEP.
268
if ((wpa_flags == NM_802_11_AP_SEC_NONE) && (rsn_flags == NM_802_11_AP_SEC_NONE)) {
270
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
271
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, 0,
275
/* Otherwise, the AP supports WPA or RSN, which is preferred */
277
/* Device can't do WPA/RSN, but can at least pass through the
278
* WPA/RSN information elements from a scan. Since Privacy was
279
* advertised, LEAP or static/dynamic WEP must be in use.
282
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
283
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, 0,
289
/* Stuff after this point requires infrastructure */
290
if (mode != NM_802_11_MODE_INFRA) {
296
if ( (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)
297
&& (dev_caps & NM_WIFI_DEVICE_CAP_RSN)) {
298
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
299
nm_setting_wireless_security_add_proto (sec, "rsn");
300
add_ciphers_from_flags (sec, rsn_flags, TRUE);
301
add_ciphers_from_flags (sec, rsn_flags, FALSE);
306
if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)
307
&& (dev_caps & NM_WIFI_DEVICE_CAP_WPA)) {
308
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
309
nm_setting_wireless_security_add_proto (sec, "wpa");
310
add_ciphers_from_flags (sec, wpa_flags, TRUE);
311
add_ciphers_from_flags (sec, wpa_flags, FALSE);
315
/* WPA2 Enterprise */
316
if ( (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
317
&& (dev_caps & NM_WIFI_DEVICE_CAP_RSN)) {
318
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
319
nm_setting_wireless_security_add_proto (sec, "rsn");
320
add_ciphers_from_flags (sec, rsn_flags, TRUE);
321
add_ciphers_from_flags (sec, rsn_flags, FALSE);
323
*s_8021x = NM_SETTING_802_1X (nm_setting_802_1x_new ());
324
nm_setting_802_1x_add_eap_method (*s_8021x, "ttls");
325
g_object_set (*s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
330
if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
331
&& (dev_caps & NM_WIFI_DEVICE_CAP_WPA)) {
332
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
333
nm_setting_wireless_security_add_proto (sec, "wpa");
334
add_ciphers_from_flags (sec, wpa_flags, TRUE);
335
add_ciphers_from_flags (sec, wpa_flags, FALSE);
337
*s_8021x = NM_SETTING_802_1X (nm_setting_802_1x_new ());
338
nm_setting_802_1x_add_eap_method (*s_8021x, "ttls");
339
g_object_set (*s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
346
g_object_unref (sec);
350
312
#ifdef ENABLE_INDICATOR
352
314
get_best_icon_name_for_ap (NMAccessPoint *ap, gboolean need_sec, gboolean encrypted)
382
AppletNewAutoConnectionCallback callback;
383
gpointer callback_data;
387
more_info_wifi_dialog_response_cb (GtkDialog *foo,
391
NMAWirelessDialog *dialog = NMA_WIRELESS_DIALOG (foo);
392
MoreInfo *info = user_data;
393
NMConnection *connection = NULL;
394
NMDevice *device = NULL;
395
NMAccessPoint *ap = NULL;
397
if (response != GTK_RESPONSE_OK) {
398
info->callback (NULL, FALSE, TRUE, info->callback_data);
402
if (!nma_wireless_dialog_get_nag_ignored (dialog)) {
403
GtkWidget *nag_dialog;
405
/* Nag the user about certificates or whatever. Only destroy the dialog
406
* if no nagging was done.
408
nag_dialog = nma_wireless_dialog_nag_user (dialog);
410
gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
411
g_signal_connect (nag_dialog, "response",
412
G_CALLBACK (nag_dialog_response_cb),
418
/* nma_wireless_dialog_get_connection() returns a connection with the
419
* refcount incremented, so the caller must remember to unref it.
421
connection = nma_wireless_dialog_get_connection (dialog, &device, &ap);
422
g_assert (connection);
425
info->callback (connection, TRUE, FALSE, info->callback_data);
427
/* Balance nma_wireless_dialog_get_connection() */
428
g_object_unref (connection);
432
gtk_widget_hide (GTK_WIDGET (dialog));
433
gtk_widget_destroy (GTK_WIDGET (dialog));
437
_do_new_auto_connection (NMApplet *applet,
440
AppletNewAutoConnectionCallback callback,
441
gpointer callback_data)
443
NMConnection *connection = NULL;
444
NMSettingConnection *s_con = NULL;
445
NMSettingWireless *s_wifi = NULL;
446
NMSettingWirelessSecurity *s_wsec = NULL;
447
NMSetting8021x *s_8021x = NULL;
448
const GByteArray *ssid;
449
NM80211ApSecurityFlags wpa_flags, rsn_flags;
458
connection = nm_connection_new ();
460
ssid = nm_access_point_get_ssid (ap);
461
if ( (nm_access_point_get_mode (ap) == NM_802_11_MODE_INFRA)
462
&& (is_manufacturer_default_ssid (ssid) == TRUE)) {
464
/* Lock connection to this AP if it's a manufacturer-default SSID
465
* so that we don't randomly connect to some other 'linksys'
467
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
468
clamp_ap_to_bssid (ap, s_wifi);
469
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
472
/* If the AP is WPA[2]-Enterprise then we need to set up a minimal 802.1x
473
* setting and ask the user for more information.
475
rsn_flags = nm_access_point_get_rsn_flags (ap);
476
wpa_flags = nm_access_point_get_wpa_flags (ap);
477
if ( (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
478
|| (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
480
/* Need a UUID for the "always ask" stuff in the Dialog of Doom */
481
s_con = (NMSettingConnection *) nm_setting_connection_new ();
482
uuid = nm_utils_uuid_generate ();
483
g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
485
nm_connection_add_setting (connection, NM_SETTING (s_con));
488
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
489
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
491
g_object_set (s_wifi,
492
NM_SETTING_WIRELESS_SSID, ssid,
493
NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
496
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
497
g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
498
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
500
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
501
nm_setting_802_1x_add_eap_method (s_8021x, "ttls");
502
g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
503
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
506
/* If it's an 802.1x connection, we need more information, so pop up the
510
more_info = g_malloc0 (sizeof (*more_info));
511
more_info->applet = applet;
512
more_info->callback = callback;
513
more_info->callback_data = callback_data;
515
dialog = nma_wireless_dialog_new (applet, connection, device, ap);
517
g_signal_connect (dialog, "response",
518
G_CALLBACK (more_info_wifi_dialog_response_cb),
520
show_ignore_focus_stealing_prevention (dialog);
523
/* Everything else can just get activated right away */
524
callback (connection, TRUE, FALSE, callback_data);
419
529
wireless_new_auto_connection (NMDevice *device,
420
530
gpointer dclass_data,
422
532
gpointer callback_data)
424
534
WirelessMenuItemInfo *info = (WirelessMenuItemInfo *) dclass_data;
425
NMConnection *connection = NULL;
426
NMSettingConnection *s_con = NULL;
427
NMSettingWireless *s_wireless = NULL;
428
NMSettingWirelessSecurity *s_wireless_sec = NULL;
429
NMSetting8021x *s_8021x = NULL;
430
const GByteArray *ap_ssid;
436
gboolean supported = TRUE;
439
g_warning ("%s: AP not set", __func__);
443
s_wireless = (NMSettingWireless *) nm_setting_wireless_new ();
445
ap_ssid = nm_access_point_get_ssid (info->ap);
446
g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, ap_ssid, NULL);
448
mode = nm_access_point_get_mode (info->ap);
449
if (mode == NM_802_11_MODE_ADHOC)
450
g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, "adhoc", NULL);
451
else if (mode == NM_802_11_MODE_INFRA) {
452
g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL);
453
/* Lock connection to this AP if it's a manufacturer-default SSID */
454
if (is_manufacturer_default_ssid (ap_ssid))
455
clamp_ap_to_bssid (info->ap, s_wireless);
457
g_assert_not_reached ();
459
dev_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device));
460
s_wireless_sec = get_security_for_ap (info->ap, dev_caps, &supported, &s_8021x);
462
g_warning ("Unsupported AP configuration: dev_caps 0x%X, ap_flags 0x%X, "
463
"wpa_flags 0x%X, rsn_flags 0x%x, mode %d",
465
nm_access_point_get_flags (info->ap),
466
nm_access_point_get_wpa_flags (info->ap),
467
nm_access_point_get_rsn_flags (info->ap),
468
nm_access_point_get_mode (info->ap));
469
g_object_unref (s_wireless);
471
} else if (s_wireless_sec)
472
g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL);
474
connection = nm_connection_new ();
475
nm_connection_add_setting (connection, NM_SETTING (s_wireless));
477
nm_connection_add_setting (connection, NM_SETTING (s_wireless_sec));
479
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
481
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
483
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
484
NM_SETTING_CONNECTION_AUTOCONNECT, !is_manufacturer_default_ssid (ap_ssid),
487
memset (buf, 0, sizeof (buf));
488
buf_len = MIN(ap_ssid->len, sizeof (buf) - 1);
489
memcpy (buf, ap_ssid->data, buf_len);
490
id = g_strdup_printf ("Auto %s", nm_utils_ssid_to_utf8 (buf, buf_len));
491
g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
494
id = nm_utils_uuid_generate ();
495
g_object_set (s_con, NM_SETTING_CONNECTION_UUID, id, NULL);
498
nm_connection_add_setting (connection, NM_SETTING (s_con));
500
(*callback) (connection, TRUE, FALSE, callback_data);
536
g_return_val_if_fail (device != NULL, FALSE);
537
g_return_val_if_fail (info->ap != NULL, FALSE);
539
_do_new_auto_connection (info->applet, device, info->ap, callback, callback_data);
505
545
wireless_menu_item_activate (GtkMenuItem *item, gpointer user_data)
1401
1415
if (new_state != NM_DEVICE_STATE_ACTIVATED)
1405
const GByteArray *ssid = nm_access_point_get_ssid (new);
1408
esc_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
1409
g_object_set_data_full (G_OBJECT(device), "canonical-last-essid", g_strdup (esc_ssid), (GDestroyNotify) g_free);
1412
/* Save this BSSID to seen-bssids list */
1413
connection = applet_get_exported_connection_for_device (device, applet);
1415
add_seen_bssid (connection, new);
1418
esc_ssid = get_ssid_utf8 (new);
1419
g_object_set_data_full (G_OBJECT(device), "canonical-last-essid", g_strdup (esc_ssid), (GDestroyNotify) g_free);
1418
1420
applet_do_notify_with_pref (applet,
1419
esc_ssid ? esc_ssid : _("(none)"),
1420
_("Connection Established"),
1421
"notification-network-wireless-full",
1421
esc_ssid ? esc_ssid : _("(none)"),
1422
_("Connection Established"),
1423
"notification-network-wireless-full",
1422
1424
PREF_DISABLE_CONNECTED_NOTIFICATIONS);
1423
1425
g_free (esc_ssid);
1590
1587
g_assert (connection);
1591
1588
g_assert (device);
1593
/* If it's a system connection we just need to tell NM to activate it */
1594
if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
1595
service = NM_DBUS_SERVICE_SYSTEM_SETTINGS;
1590
/* Find a similar connection and use that instead */
1591
all = applet_get_all_connections (applet);
1592
for (iter = all; iter; iter = g_slist_next (iter)) {
1593
if (nm_connection_compare (connection,
1594
NM_CONNECTION (iter->data),
1595
(NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) {
1596
fuzzy_match = NM_CONNECTION (iter->data);
1599
if (NMA_IS_GCONF_CONNECTION (connection)) {
1600
/* Not a new or system connection, save the updated settings to GConf */
1601
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (connection),
1603
nm_client_activate_connection (applet->nm_client,
1606
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
1607
activate_existing_cb,
1607
/* Find a similar connection and use that instead */
1608
all = applet_get_all_connections (applet);
1609
for (iter = all; iter; iter = g_slist_next (iter)) {
1610
if (nm_connection_compare (connection,
1611
NM_CONNECTION (iter->data),
1612
(NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) {
1613
fuzzy_match = g_object_ref (NM_CONNECTION (iter->data));
1620
if (nm_connection_get_scope (fuzzy_match) == NM_CONNECTION_SCOPE_SYSTEM) {
1621
// FIXME: do something other than just use the system connection?
1623
NMSettingWirelessSecurity *s_wireless_sec;
1625
/* Copy secrets & wireless security */
1626
s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
1627
if (s_wireless_sec) {
1629
NMSetting *dup_setting;
1631
hash = nm_setting_to_hash (NM_SETTING (s_wireless_sec));
1632
dup_setting = nm_setting_new_from_hash (NM_TYPE_SETTING_WIRELESS_SECURITY, hash);
1633
g_hash_table_destroy (hash);
1634
nm_connection_add_setting (fuzzy_match, dup_setting);
1638
/* Balance nma_wireless_dialog_get_connection() */
1639
g_object_unref (connection);
1640
connection = g_object_ref (fuzzy_match);
1642
/* Entirely new connection */
1643
NMAGConfConnection *new_gconf_connection;
1644
NMSettingConnection *s_con;
1647
/* Update a new connection's name and autoconnect status */
1648
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
1649
id = (char *) nm_setting_connection_get_id (s_con);
1652
NMSettingWireless *s_wireless;
1653
const GByteArray *ssid;
1656
s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
1657
ssid = nm_setting_wireless_get_ssid (s_wireless);
1659
id = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
1660
g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
1663
// FIXME: don't autoconnect until the connection is successful at least once
1664
/* Don't autoconnect adhoc networks by default for now */
1665
mode = nm_setting_wireless_get_mode (s_wireless);
1666
if (!mode || !strcmp (mode, "infrastructure"))
1667
g_object_set (s_con, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);
1670
/* Export it over D-Bus */
1671
new_gconf_connection = nma_gconf_settings_add_connection (applet->gconf_settings, connection);
1672
if (!new_gconf_connection) {
1673
nm_warning ("Couldn't create new network connection.");
1677
/* Balance nma_wireless_dialog_get_connection() */
1678
g_object_unref (connection);
1679
connection = g_object_ref (new_gconf_connection);
1611
NMSettingWireless *s_wifi = NULL;
1612
const char *mode = NULL;
1614
/* Entirely new connection */
1616
/* Don't autoconnect adhoc networks by default for now */
1617
s_wifi = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
1619
mode = nm_setting_wireless_get_mode (s_wifi);
1620
if (g_strcmp0 (mode, "adhoc") == 0) {
1621
s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
1623
s_con = nm_setting_connection_new ();
1624
nm_connection_add_setting (connection, s_con);
1626
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL);
1629
nm_client_add_and_activate_connection (applet->nm_client,
1632
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
1684
nm_client_activate_connection (applet->nm_client,
1686
nm_connection_get_path (connection),
1688
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
1637
/* Balance nma_wireless_dialog_get_connection() */
1638
g_object_unref (connection);
1693
/* Balance nma_wireless_dialog_get_connection() */
1695
g_object_unref (connection);
1697
1641
gtk_widget_hide (GTK_WIDGET (dialog));
1698
1642
gtk_widget_destroy (GTK_WIDGET (dialog));
1702
wireless_get_more_info (NMDevice *device,
1703
NMConnection *connection,
1707
WirelessMenuItemInfo *info = (WirelessMenuItemInfo *) user_data;
1710
dialog = nma_wireless_dialog_new (applet, connection, device, info->ap);
1711
g_return_if_fail (dialog != NULL);
1713
g_signal_connect (dialog, "response",
1714
G_CALLBACK (wireless_dialog_response_cb),
1717
show_ignore_focus_stealing_prevention (dialog);
1720
1645
static gboolean
1721
1646
add_one_setting (GHashTable *settings,
1722
1647
NMConnection *connection,
1802
/* Got a user response, clear the NMActiveConnection destroy handler for
1803
* this dialog since this function will now take over dialog destruction.
1805
g_object_weak_unref (G_OBJECT (info->active_connection), destroy_wifi_dialog, info);
1807
1724
if (response != GTK_RESPONSE_OK) {
1808
1725
g_set_error (&error,
1809
NM_SETTINGS_INTERFACE_ERROR,
1810
NM_SETTINGS_INTERFACE_ERROR_SECRETS_REQUEST_CANCELED,
1726
NM_SECRET_AGENT_ERROR,
1727
NM_SECRET_AGENT_ERROR_USER_CANCELED,
1811
1728
"%s.%d (%s): canceled",
1812
1729
__FILE__, __LINE__, __func__);
1816
connection = nma_wireless_dialog_get_connection (dialog, &device, NULL);
1733
connection = nma_wireless_dialog_get_connection (dialog, NULL, NULL);
1817
1734
if (!connection) {
1818
1735
g_set_error (&error,
1819
NM_SETTINGS_INTERFACE_ERROR,
1820
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1736
NM_SECRET_AGENT_ERROR,
1737
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
1821
1738
"%s.%d (%s): couldn't get connection from wireless dialog.",
1822
1739
__FILE__, __LINE__, __func__);
1882
1799
/* Add the 802-11-wireless-security setting no matter what */
1883
if (!add_one_setting (settings, connection, NM_SETTING (s_wireless_sec), &error))
1886
info->callback (NM_SETTINGS_CONNECTION_INTERFACE (connection), settings, NULL, info->callback_data);
1888
/* Save the connection back to GConf _after_ hashing it, because
1889
* saving to GConf might trigger the GConf change notifiers, resulting
1890
* in the connection being read back in from GConf which clears secrets.
1892
if (NMA_IS_GCONF_CONNECTION (connection)) {
1893
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (connection),
1800
add_one_setting (settings, connection, NM_SETTING (s_wireless_sec), &error);
1803
applet_secrets_request_complete (req, settings, error);
1804
applet_secrets_request_free (req);
1900
1807
g_hash_table_destroy (settings);
1903
g_warning ("%s", error->message);
1904
info->callback (NM_SETTINGS_CONNECTION_INTERFACE (connection), NULL, error, info->callback_data);
1905
g_error_free (error);
1908
1808
if (connection)
1909
1809
nm_connection_clear_secrets (connection);
1911
destroy_wifi_dialog (info, NULL);
1914
1812
static gboolean
1915
wireless_get_secrets (NMDevice *device,
1916
NMSettingsConnectionInterface *connection,
1917
NMActiveConnection *active_connection,
1918
const char *setting_name,
1920
NMANewSecretsRequestedFunc callback,
1921
gpointer callback_data,
1813
wireless_get_secrets (SecretsRequest *req, GError **error)
1927
const char *specific_object;
1929
if (!setting_name || !active_connection) {
1931
NM_SETTINGS_INTERFACE_ERROR,
1932
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1933
"%s.%d (%s): setting name and active connection object required",
1934
__FILE__, __LINE__, __func__);
1938
specific_object = nm_active_connection_get_specific_object (active_connection);
1939
if (!specific_object) {
1941
NM_SETTINGS_INTERFACE_ERROR,
1942
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1943
"%s.%d (%s): could not determine AP for specific object",
1944
__FILE__, __LINE__, __func__);
1948
info = g_malloc0 (sizeof (NMWifiInfo));
1950
ap = nm_device_wifi_get_access_point_by_path (NM_DEVICE_WIFI (device), specific_object);
1951
info->dialog = nma_wireless_dialog_new (applet, NM_CONNECTION (connection), device, ap);
1952
if (!info->dialog) {
1954
NM_SETTINGS_INTERFACE_ERROR,
1955
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1815
NMWifiInfo *info = (NMWifiInfo *) req;
1817
applet_secrets_request_set_free_func (req, free_wifi_info);
1819
info->dialog = nma_wireless_dialog_new (req->applet, req->connection, NULL, NULL);
1821
g_signal_connect (info->dialog, "response",
1822
G_CALLBACK (get_secrets_dialog_response_cb),
1824
show_ignore_focus_stealing_prevention (info->dialog);
1827
NM_SECRET_AGENT_ERROR,
1828
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
1956
1829
"%s.%d (%s): couldn't display secrets UI",
1957
1830
__FILE__, __LINE__, __func__);
1962
info->applet = applet;
1963
info->active_connection = active_connection;
1964
info->callback = callback;
1965
info->callback_data = callback_data;
1966
info->setting_name = g_strdup (setting_name);
1968
g_signal_connect (info->dialog, "response",
1969
G_CALLBACK (get_secrets_dialog_response_cb),
1972
/* Attach a destroy notifier to the NMActiveConnection so we can destroy
1973
* the dialog when the active connection goes away.
1975
g_object_weak_ref (G_OBJECT (active_connection), destroy_wifi_dialog, info);
1977
show_ignore_focus_stealing_prevention (info->dialog);
1832
return !!info->dialog;
1981
1835
NMADeviceClass *