1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* NetworkManager Applet -- allow user control over networking
3  *
4  * Dan Williams <dcbw@redhat.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Copyright 2007 - 2014 Red Hat, Inc.
21  */
22 
23 #include "nm-default.h"
24 
25 #include <ctype.h>
26 #include <string.h>
27 
28 #include "wireless-security.h"
29 #include "eap-method.h"
30 
31 struct _WirelessSecurityDynamicWEP {
32 	WirelessSecurity parent;
33 
34 	GtkSizeGroup *size_group;
35 };
36 
37 static void
destroy(WirelessSecurity * parent)38 destroy (WirelessSecurity *parent)
39 {
40 	WirelessSecurityDynamicWEP *sec = (WirelessSecurityDynamicWEP *) parent;
41 
42 	if (sec->size_group)
43 		g_object_unref (sec->size_group);
44 }
45 
46 static gboolean
validate(WirelessSecurity * parent,GError ** error)47 validate (WirelessSecurity *parent, GError **error)
48 {
49 	return ws_802_1x_validate (parent, "dynamic_wep_auth_combo", error);
50 }
51 
52 static void
add_to_size_group(WirelessSecurity * parent,GtkSizeGroup * group)53 add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group)
54 {
55 	WirelessSecurityDynamicWEP *sec = (WirelessSecurityDynamicWEP *) parent;
56 
57 	if (sec->size_group)
58 		g_object_unref (sec->size_group);
59 	sec->size_group = g_object_ref (group);
60 
61 	ws_802_1x_add_to_size_group (parent,
62 	                             sec->size_group,
63 	                             "dynamic_wep_auth_label",
64 	                             "dynamic_wep_auth_combo");
65 }
66 
67 static void
fill_connection(WirelessSecurity * parent,NMConnection * connection)68 fill_connection (WirelessSecurity *parent, NMConnection *connection)
69 {
70 	NMSettingWirelessSecurity *s_wireless_sec;
71 
72 	ws_802_1x_fill_connection (parent, "dynamic_wep_auth_combo", connection);
73 
74 	s_wireless_sec = nm_connection_get_setting_wireless_security (connection);
75 	g_assert (s_wireless_sec);
76 
77 	g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL);
78 }
79 
80 static void
auth_combo_changed_cb(GtkWidget * combo,gpointer user_data)81 auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
82 {
83 	WirelessSecurity *parent = WIRELESS_SECURITY (user_data);
84 	WirelessSecurityDynamicWEP *sec = (WirelessSecurityDynamicWEP *) parent;
85 
86 	ws_802_1x_auth_combo_changed (combo,
87 	                              parent,
88 	                              "dynamic_wep_method_vbox",
89 	                              sec->size_group);
90 }
91 
92 static void
update_secrets(WirelessSecurity * parent,NMConnection * connection)93 update_secrets (WirelessSecurity *parent, NMConnection *connection)
94 {
95 	ws_802_1x_update_secrets (parent, "dynamic_wep_auth_combo", connection);
96 }
97 
98 WirelessSecurityDynamicWEP *
ws_dynamic_wep_new(NMConnection * connection,gboolean is_editor,gboolean secrets_only)99 ws_dynamic_wep_new (NMConnection *connection,
100                     gboolean is_editor,
101                     gboolean secrets_only)
102 {
103 	WirelessSecurity *parent;
104 	GtkWidget *widget;
105 
106 	parent = wireless_security_init (sizeof (WirelessSecurityDynamicWEP),
107 	                                 validate,
108 	                                 add_to_size_group,
109 	                                 fill_connection,
110 	                                 update_secrets,
111 	                                 destroy,
112 	                                 "/org/cinnamon/control-center/network/ws-dynamic-wep.ui",
113 	                                 "dynamic_wep_notebook",
114 	                                 NULL);
115 	if (!parent)
116 		return NULL;
117 
118 	parent->adhoc_compatible = FALSE;
119 	parent->hotspot_compatible = FALSE;
120 
121 	widget = ws_802_1x_auth_combo_init (parent,
122 	                                    "dynamic_wep_auth_combo",
123 	                                    "dynamic_wep_auth_label",
124 	                                    (GCallback) auth_combo_changed_cb,
125 	                                    connection,
126 	                                    is_editor,
127 	                                    secrets_only);
128 	auth_combo_changed_cb (widget, (gpointer) parent);
129 
130 	return (WirelessSecurityDynamicWEP *) parent;
131 }
132 
133