1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
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
* (C) Copyright 2007 - 2011 Red Hat, Inc.
25
#include <netinet/ether.h>
27
#include <glib/gi18n.h>
30
#include <nm-setting-connection.h>
35
static char *ignored_words[] = {
58
static char *ignored_phrases[] = {
59
"Multiprotocol MAC/baseband processor",
60
"Wireless LAN Controller",
61
"Wireless LAN Adapter",
64
"Wireless Cardbus Adapter",
65
"Wireless CardBus Adapter",
66
"54 Mbps Wireless PC Card",
69
"PC Card with XJACK(r) Antenna",
71
"Wireless LAN PC Card",
72
"Technology Group Ltd.",
73
"Communication S.p.A.",
74
"Business Mobile Networks BV",
75
"Mobile Broadband Minicard Composite Device",
76
"Mobile Communications AB",
82
fixup_desc_string (const char *desc)
88
p = temp = g_strdup (desc);
90
if (*p == '_' || *p == ',')
95
/* Attempt to shorten ID by ignoring certain phrases */
96
for (item = ignored_phrases; *item; item++) {
97
guint32 ignored_len = strlen (*item);
99
p = strstr (temp, *item);
101
memmove (p, p + ignored_len, strlen (p + ignored_len) + 1); /* +1 for the \0 */
104
/* Attmept to shorten ID by ignoring certain individual words */
105
words = g_strsplit (temp, " ", 0);
106
str = g_string_new_len (NULL, strlen (temp));
109
for (item = words; *item; item++) {
111
gboolean ignore = FALSE;
113
if (g_ascii_isspace (**item) || (**item == '\0'))
116
while (ignored_words[i] && !ignore) {
117
if (!strcmp (*item, ignored_words[i]))
124
g_string_append_c (str, ' ');
125
g_string_append (str, *item);
131
g_string_free (str, FALSE);
136
#define DESC_TAG "description"
139
utils_get_device_description (NMDevice *device)
141
char *description = NULL;
142
const char *dev_product;
143
const char *dev_vendor;
144
char *product = NULL;
148
g_return_val_if_fail (device != NULL, NULL);
150
description = g_object_get_data (G_OBJECT (device), DESC_TAG);
154
dev_product = nm_device_get_product (device);
155
dev_vendor = nm_device_get_vendor (device);
156
if (!dev_product || !dev_vendor)
159
product = fixup_desc_string (dev_product);
160
vendor = fixup_desc_string (dev_vendor);
162
str = g_string_new_len (NULL, strlen (vendor) + strlen (product) + 1);
164
/* Another quick hack; if all of the fixed up vendor string
165
* is found in product, ignore the vendor.
167
if (!strcasestr (product, vendor)) {
168
g_string_append (str, vendor);
169
g_string_append_c (str, ' ');
172
g_string_append (str, product);
176
description = str->str;
177
g_string_free (str, FALSE);
179
g_object_set_data_full (G_OBJECT (device),
180
"description", description,
181
(GDestroyNotify) g_free);
187
* utils_ether_addr_valid
189
* Compares an Ethernet address against known invalid addresses.
193
utils_ether_addr_valid (const struct ether_addr *test_addr)
195
guint8 invalid_addr1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
196
guint8 invalid_addr2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
197
guint8 invalid_addr3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
198
guint8 invalid_addr4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
200
g_return_val_if_fail (test_addr != NULL, FALSE);
202
/* Compare the AP address the card has with invalid ethernet MAC addresses. */
203
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr1, ETH_ALEN))
206
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr2, ETH_ALEN))
209
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr3, ETH_ALEN))
212
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr4, ETH_ALEN))
215
if (test_addr->ether_addr_octet[0] & 1) /* Multicast addresses */
222
utils_hash_ap (const GByteArray *ssid,
228
unsigned char input[66];
230
memset (&input[0], 0, sizeof (input));
233
memcpy (input, ssid->data, ssid->len);
235
if (mode == NM_802_11_MODE_INFRA)
236
input[32] |= (1 << 0);
237
else if (mode == NM_802_11_MODE_ADHOC)
238
input[32] |= (1 << 1);
240
input[32] |= (1 << 2);
242
/* Separate out no encryption, WEP-only, and WPA-capable */
243
if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
244
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
245
&& (rsn_flags == NM_802_11_AP_SEC_NONE))
246
input[32] |= (1 << 3);
247
else if ( (flags & NM_802_11_AP_FLAGS_PRIVACY)
248
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
249
&& (rsn_flags == NM_802_11_AP_SEC_NONE))
250
input[32] |= (1 << 4);
251
else if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
252
&& (wpa_flags != NM_802_11_AP_SEC_NONE)
253
&& (rsn_flags != NM_802_11_AP_SEC_NONE))
254
input[32] |= (1 << 5);
256
input[32] |= (1 << 6);
259
memcpy (&input[33], &input[0], 32);
260
return g_compute_checksum_for_data (G_CHECKSUM_MD5, input, sizeof (input));
265
const char *replacement;
268
static Tag escaped_tags[] = {
269
{ "<center>", NULL },
270
{ "</center>", NULL },
284
utils_escape_notify_message (const char *src)
289
/* Filter the source text and get rid of some HTML tags since the
290
* notification spec only allows a subset of HTML. Substitute
291
* HTML code for characters like & that are invalid in HTML.
294
escaped = g_string_sized_new (strlen (src) + 5);
296
Tag *t = &escaped_tags[0];
297
gboolean found = FALSE;
300
if (strncasecmp (p, t->tag, strlen (t->tag)) == 0) {
301
p += strlen (t->tag);
303
g_string_append (escaped, t->replacement);
310
g_string_append_c (escaped, *p++);
313
return g_string_free (escaped, FALSE);
317
utils_create_mobile_connection_id (const char *provider, const char *plan_name)
319
g_return_val_if_fail (provider != NULL, NULL);
322
return g_strdup_printf ("%s %s", provider, plan_name);
324
/* The %s is a mobile provider name, eg "T-Mobile" */
325
return g_strdup_printf (_("%s connection"), provider);
329
utils_show_error_dialog (const char *title,
335
GtkWidget *err_dialog;
337
g_return_if_fail (text1 != NULL);
339
err_dialog = gtk_message_dialog_new (parent,
340
GTK_DIALOG_DESTROY_WITH_PARENT,
347
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (err_dialog), "%s", text2);
349
gtk_window_set_title (GTK_WINDOW (err_dialog), title);
352
gtk_dialog_run (GTK_DIALOG (err_dialog));
353
gtk_widget_destroy (err_dialog);
355
g_signal_connect (err_dialog, "delete-event", G_CALLBACK (gtk_widget_destroy), NULL);
356
g_signal_connect (err_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
358
gtk_widget_show_all (err_dialog);
359
gtk_window_present (GTK_WINDOW (err_dialog));