1
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
3
* Dan Williams <dcbw@redhat.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
* (C) Copyright 2005 Red Hat, Inc.
23
#include <glib/gi18n.h>
25
#include <glade/glade.h>
26
#include <dbus/dbus.h>
29
#include "wireless-security-option.h"
30
#include "wso-wpa-psk.h"
31
#include "wso-private.h"
33
#include "cipher-wpa-psk-hex.h"
34
#include "cipher-wpa-psk-passphrase.h"
35
#include "dbus-helpers.h"
36
#include "NetworkManager.h"
42
const char * entry_name;
43
const char * key_type_combo_name;
44
const char * show_checkbutton_name;
45
IEEE_802_11_Cipher * hex_cipher;
46
IEEE_802_11_Cipher * passphrase_cipher;
50
data_free_func (WirelessSecurityOption *opt)
52
g_return_if_fail (opt != NULL);
53
g_return_if_fail (opt->data != NULL);
55
ieee_802_11_cipher_ref (opt->data->passphrase_cipher);
56
ieee_802_11_cipher_ref (opt->data->hex_cipher);
57
memset (opt->data, 0, sizeof (opt->data));
62
static void show_passphrase_cb (GtkToggleButton *button, GtkEntry *entry)
64
gtk_entry_set_visibility (entry, gtk_toggle_button_get_active (button));
69
widget_create_func (WirelessSecurityOption *opt,
70
GtkSignalFunc validate_cb,
74
GtkWidget * checkbutton;
77
g_return_val_if_fail (opt != NULL, NULL);
78
g_return_val_if_fail (opt->data != NULL, NULL);
79
g_return_val_if_fail (validate_cb != NULL, NULL);
81
widget = wso_widget_helper (opt);
82
entry = glade_xml_get_widget (opt->uixml, opt->data->entry_name);
83
g_signal_connect (G_OBJECT (entry), "changed", validate_cb, user_data);
85
checkbutton = glade_xml_get_widget (opt->uixml, opt->data->show_checkbutton_name);
86
g_signal_connect (G_OBJECT (checkbutton), "toggled", GTK_SIGNAL_FUNC (show_passphrase_cb), GTK_ENTRY (entry));
93
validate_input_func (WirelessSecurityOption *opt,
95
IEEE_802_11_Cipher **out_cipher)
100
g_return_val_if_fail (opt != NULL, FALSE);
102
entry = glade_xml_get_widget (opt->uixml, opt->data->entry_name);
103
input = gtk_entry_get_text (GTK_ENTRY (entry));
104
return wso_validate_helper (opt, ssid, input, out_cipher);
109
append_dbus_params_func (WirelessSecurityOption *opt,
111
DBusMessage *message)
113
IEEE_802_11_Cipher * cipher = NULL;
117
g_return_val_if_fail (opt != NULL, FALSE);
118
g_return_val_if_fail (opt->data != NULL, FALSE);
119
g_return_val_if_fail (opt->data->entry_name != NULL, FALSE);
121
entry = glade_xml_get_widget (opt->uixml, opt->data->entry_name);
122
input = gtk_entry_get_text (GTK_ENTRY (entry));
123
if (!wso_validate_helper (opt, ssid, input, &cipher) || !cipher)
126
nmu_security_serialize_wpa_psk_with_cipher (message, cipher, ssid, input,
127
opt->data->wpa2 ? IW_AUTH_WPA_VERSION_WPA2 : IW_AUTH_WPA_VERSION_WPA,
128
IW_AUTH_KEY_MGMT_PSK);
135
key_type_combo_changed_cb (GtkComboBox *combo,
138
WirelessSecurityOption * opt = (WirelessSecurityOption *) user_data;
140
GtkTreeModel * model;
144
g_return_if_fail (opt != NULL);
146
model = gtk_combo_box_get_model (combo);
147
gtk_combo_box_get_active_iter (combo, &iter);
148
gtk_tree_model_get (model, &iter, WPA_KEY_TYPE_CIPHER_COL, &we_cipher, -1);
150
for (elt = opt->ciphers; elt; elt = g_slist_next (elt))
152
IEEE_802_11_Cipher * cipher = (IEEE_802_11_Cipher *)(elt->data);
154
if (cipher == opt->data->passphrase_cipher)
155
cipher_wpa_psk_passphrase_set_we_cipher (cipher, we_cipher);
156
else if (cipher == opt->data->hex_cipher)
157
cipher_wpa_psk_hex_set_we_cipher (cipher, we_cipher);
162
WirelessSecurityOption *
163
wso_wpa_psk_new (const char *glade_file,
167
WirelessSecurityOption * opt = NULL;
168
OptData * data = NULL;
169
GtkWidget * key_type_combo;
171
GtkTreeModel * model;
174
g_return_val_if_fail (glade_file != NULL, NULL);
176
opt = g_malloc0 (sizeof (WirelessSecurityOption));
178
opt->name = g_strdup (_("WPA2 Personal"));
180
opt->name = g_strdup (_("WPA Personal"));
181
opt->widget_name = "wpa_psk_notebook";
182
opt->data_free_func = data_free_func;
183
opt->validate_input_func = validate_input_func;
184
opt->widget_create_func = widget_create_func;
185
opt->append_dbus_params_func = append_dbus_params_func;
187
if (!(opt->uixml = glade_xml_new (glade_file, opt->widget_name, NULL)))
193
/* Option-specific data */
194
opt->data = data = g_malloc0 (sizeof (OptData));
196
data->entry_name = "wpa_psk_entry";
197
data->key_type_combo_name = "wpa_psk_type_combo";
198
data->show_checkbutton_name = "show_checkbutton";
200
/* Set up our ciphers */
201
data->passphrase_cipher = cipher_wpa_psk_passphrase_new ();
202
ieee_802_11_cipher_ref (data->passphrase_cipher);
203
opt->ciphers = g_slist_append (opt->ciphers, data->passphrase_cipher);
204
data->hex_cipher = cipher_wpa_psk_hex_new ();
205
ieee_802_11_cipher_ref (data->hex_cipher);
206
opt->ciphers = g_slist_append (opt->ciphers, data->hex_cipher);
208
key_type_combo = glade_xml_get_widget (opt->uixml, data->key_type_combo_name);
209
g_signal_connect (G_OBJECT (key_type_combo), "changed", (GCallback) key_type_combo_changed_cb, opt);
210
model = wso_wpa_create_key_type_model (capabilities, FALSE, &num_added);
211
gtk_combo_box_set_model (GTK_COMBO_BOX (key_type_combo), model);
212
gtk_tree_model_get_iter_first (model, &iter);
213
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (key_type_combo), &iter);
215
gtk_widget_set_sensitive (key_type_combo, FALSE);