1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* NetworkManager Applet -- allow user control over networking
4
* Dan Williams <dcbw@redhat.com>
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.
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.
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.
20
* Copyright 2007 - 2015 Red Hat, Inc.
25
#include <netinet/ether.h>
27
#include <glib/gi18n.h>
30
#include <nm-setting-connection.h>
36
* utils_ether_addr_valid
38
* Compares an Ethernet address against known invalid addresses.
42
utils_ether_addr_valid (const struct ether_addr *test_addr)
44
guint8 invalid_addr1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
45
guint8 invalid_addr2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
46
guint8 invalid_addr3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
47
guint8 invalid_addr4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
49
g_return_val_if_fail (test_addr != NULL, FALSE);
51
/* Compare the AP address the card has with invalid ethernet MAC addresses. */
52
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr1, ETH_ALEN))
55
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr2, ETH_ALEN))
58
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr3, ETH_ALEN))
61
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr4, ETH_ALEN))
64
if (test_addr->ether_addr_octet[0] & 1) /* Multicast addresses */
71
utils_hash_ap (const GByteArray *ssid,
77
unsigned char input[66];
79
memset (&input[0], 0, sizeof (input));
82
memcpy (input, ssid->data, ssid->len);
84
if (mode == NM_802_11_MODE_INFRA)
85
input[32] |= (1 << 0);
86
else if (mode == NM_802_11_MODE_ADHOC)
87
input[32] |= (1 << 1);
89
input[32] |= (1 << 2);
91
/* Separate out no encryption, WEP-only, and WPA-capable */
92
if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
93
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
94
&& (rsn_flags == NM_802_11_AP_SEC_NONE))
95
input[32] |= (1 << 3);
96
else if ( (flags & NM_802_11_AP_FLAGS_PRIVACY)
97
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
98
&& (rsn_flags == NM_802_11_AP_SEC_NONE))
99
input[32] |= (1 << 4);
100
else if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
101
&& (wpa_flags != NM_802_11_AP_SEC_NONE)
102
&& (rsn_flags != NM_802_11_AP_SEC_NONE))
103
input[32] |= (1 << 5);
105
input[32] |= (1 << 6);
108
memcpy (&input[33], &input[0], 32);
109
return g_compute_checksum_for_data (G_CHECKSUM_MD5, input, sizeof (input));
114
const char *replacement;
117
static Tag escaped_tags[] = {
118
{ "<center>", NULL },
119
{ "</center>", NULL },
133
utils_escape_notify_message (const char *src)
138
/* Filter the source text and get rid of some HTML tags since the
139
* notification spec only allows a subset of HTML. Substitute
140
* HTML code for characters like & that are invalid in HTML.
143
escaped = g_string_sized_new (strlen (src) + 5);
145
Tag *t = &escaped_tags[0];
146
gboolean found = FALSE;
149
if (strncasecmp (p, t->tag, strlen (t->tag)) == 0) {
150
p += strlen (t->tag);
152
g_string_append (escaped, t->replacement);
159
g_string_append_c (escaped, *p++);
162
return g_string_free (escaped, FALSE);
166
utils_create_mobile_connection_id (const char *provider, const char *plan_name)
168
g_return_val_if_fail (provider != NULL, NULL);
171
return g_strdup_printf ("%s %s", provider, plan_name);
173
/* The %s is a mobile provider name, eg "T-Mobile" */
174
return g_strdup_printf (_("%s connection"), provider);
178
utils_show_error_dialog (const char *title,
184
GtkWidget *err_dialog;
186
g_return_if_fail (text1 != NULL);
188
err_dialog = gtk_message_dialog_new (parent,
189
GTK_DIALOG_DESTROY_WITH_PARENT,
196
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (err_dialog), "%s", text2);
198
gtk_window_set_title (GTK_WINDOW (err_dialog), title);
201
gtk_dialog_run (GTK_DIALOG (err_dialog));
202
gtk_widget_destroy (err_dialog);
204
g_signal_connect (err_dialog, "delete-event", G_CALLBACK (gtk_widget_destroy), NULL);
205
g_signal_connect (err_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
207
gtk_widget_show_all (err_dialog);
208
gtk_window_present (GTK_WINDOW (err_dialog));
214
utils_char_is_ascii_print (char character)
216
return g_ascii_isprint (character);
220
utils_char_is_ascii_digit (char character)
222
return g_ascii_isdigit (character);
226
utils_char_is_ascii_ip4_address (char character)
228
return g_ascii_isdigit (character) || character == '.';
232
utils_char_is_ascii_ip6_address (char character)
234
return g_ascii_isxdigit (character) || character == ':';
238
utils_char_is_ascii_apn (char character)
240
return g_ascii_isalnum (character)
247
* Filters the characters from a text that was just input into GtkEditable.
248
* Returns FALSE, if after filtering no characters were left. TRUE means,
249
* that valid characters were added and the content of the GtkEditable changed.
252
utils_filter_editable_on_insert_text (GtkEditable *editable,
257
UtilsFilterGtkEditableFunc validate_character,
261
gchar *result = g_new (gchar, length+1);
263
for (i = 0; i < length; i++) {
264
if (validate_character (text[i]))
265
result[count++] = text[i];
271
g_signal_handlers_block_by_func (G_OBJECT (editable),
272
G_CALLBACK (block_func),
275
gtk_editable_insert_text (editable, result, count, position);
277
g_signal_handlers_unblock_by_func (G_OBJECT (editable),
278
G_CALLBACK (block_func),
282
g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");