Commit 7c24f2af authored by Dan Williams's avatar Dan Williams
Browse files

2004-11-03 Dan Williams <dcbw@redhat.com>

	* panel-applet/NMWirelessAppletOtherNetworkDialog.c,
		- Disable OK button until valid data is entered
			for encryption stuff too

	* panel-applet/NMWirelessApplet.c
		- Report card strength for current AP if the card
			doesn't report strength data for scanned access
			points

	* src/NetworkManagerDevice.c
		- Smooth out cards reported quality, Atmel card was
			intermittently reporting no quality data but soon
			recovers

	* src/NetworkManagerWireless.c
		- Better quality data percentage calculation.  Atmel
			cards (mine at least) seem to report the quality
			in percentage format already, so honor that

	Patch from <j@bootlab.org>
	* NetworkManager.h
	  info-daemon/NetworkManagerInfoPassphraseDialog.c
	  info-daemon/passphrase.glade
	  panel-applet/NMWirelessAppletOtherNetworkDialog.c
	  panel-applet/essid.glade
	  src/NetworkManagerAP.c
	  src/NetworkManagerDevice.c
	  src/NetworkManagerWireless.[ch]
		- Support ASCII WEP keys, in both 40/64 bit and 104/128 bit


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@291 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent e4e84265
2004-11-03 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessAppletOtherNetworkDialog.c,
- Disable OK button until valid data is entered
for encryption stuff too
* panel-applet/NMWirelessApplet.c
- Report card strength for current AP if the card
doesn't report strength data for scanned access
points
* src/NetworkManagerDevice.c
- Smooth out cards reported quality, Atmel card was
intermittently reporting no quality data but soon
recovers
* src/NetworkManagerWireless.c
- Better quality data percentage calculation. Atmel
cards (mine at least) seem to report the quality
in percentage format already, so honor that
Patch from <j@bootlab.org>
* NetworkManager.h
info-daemon/NetworkManagerInfoPassphraseDialog.c
info-daemon/passphrase.glade
panel-applet/NMWirelessAppletOtherNetworkDialog.c
panel-applet/essid.glade
src/NetworkManagerAP.c
src/NetworkManagerDevice.c
src/NetworkManagerWireless.[ch]
- Support ASCII WEP keys, in both 40/64 bit and 104/128 bit
2004-11-03 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerDevice.[ch]
......
......@@ -75,9 +75,8 @@ typedef enum NMEncKeyType
{
NM_ENC_TYPE_UNKNOWN = 0,
NM_ENC_TYPE_NONE,
NM_ENC_TYPE_40_BIT_HEX_KEY,
NM_ENC_TYPE_40_BIT_PASSPHRASE,
NM_ENC_TYPE_128_BIT_HEX_KEY,
NM_ENC_TYPE_HEX_KEY,
NM_ENC_TYPE_ASCII_KEY,
NM_ENC_TYPE_128_BIT_PASSPHRASE
/* FIXME: WPA and 802.1x support */
} NMEncKeyType;
......
......@@ -41,7 +41,8 @@
enum NMIPassphraseDialogKeyTypes
{
KEY_TYPE_128_BIT_PASSPHRASE = 0,
KEY_TYPE_128_BIT_RAW_HEX_KEY = 1
KEY_TYPE_ASCII_KEY = 1,
KEY_TYPE_HEX_KEY = 2
};
......@@ -99,8 +100,11 @@ void nmi_passphrase_dialog_key_type_combo_changed (GtkWidget *key_type_combo, gp
case KEY_TYPE_128_BIT_PASSPHRASE:
gtk_label_set_label (entry_label, _("Passphrase:"));
break;
case KEY_TYPE_128_BIT_RAW_HEX_KEY:
gtk_label_set_label (entry_label, _("Key:"));
case KEY_TYPE_ASCII_KEY:
gtk_label_set_label (entry_label, _("Ascii Key:"));
break;
case KEY_TYPE_HEX_KEY:
gtk_label_set_label (entry_label, _("Hex Key:"));
break;
default:
break;
......@@ -140,8 +144,11 @@ void nmi_passphrase_dialog_ok_clicked (GtkWidget *ok_button, gpointer user_data)
case KEY_TYPE_128_BIT_PASSPHRASE:
key_type_return = NM_ENC_TYPE_128_BIT_PASSPHRASE;
break;
case KEY_TYPE_128_BIT_RAW_HEX_KEY:
key_type_return = NM_ENC_TYPE_128_BIT_HEX_KEY;
case KEY_TYPE_ASCII_KEY:
key_type_return = NM_ENC_TYPE_ASCII_KEY;
break;
case KEY_TYPE_HEX_KEY:
key_type_return = NM_ENC_TYPE_HEX_KEY;
break;
default:
key_type_return = NM_ENC_TYPE_UNKNOWN;
......
......@@ -147,8 +147,9 @@ A passphrase or encryption key is required to access the wireless network '%s'.<
<child>
<widget class="GtkComboBox" id="key_type_combo">
<property name="visible">True</property>
<property name="items" translatable="yes">128-bit Passphrase
128-bit Raw Hex Key</property>
<property name="items" translatable="yes">128-bit Passphrase (WEP)
Ascii Key (WEP)
Hex Key (WEP)</property>
</widget>
<packing>
<property name="padding">0</property>
......
......@@ -268,9 +268,8 @@ nmwa_update_state (NMWirelessApplet *applet)
strength = CLAMP ((int) network->strength, 0, 100);
}
if (strength == -1)
if (strength <= 0)
strength = applet->active_device->strength;
}
if (g_slist_length (applet->device_list) == 1 &&
......
......@@ -43,19 +43,57 @@
enum NMWAEncryptionKeyTypes
{
KEY_TYPE_128_BIT_PASSPHRASE = 0,
KEY_TYPE_128_BIT_HEX_KEY = 1
KEY_TYPE_ASCII_KEY = 1,
KEY_TYPE_HEX_KEY = 2
};
static void update_button_cb (GtkWidget *entry, GtkWidget *button)
static void update_button_cb (GtkWidget *widget, GladeXML *xml)
{
const char *text;
gboolean enable = TRUE;
const char *text;
GtkButton *button;
GtkEntry *essid_entry;
GtkCheckButton *enc_check_button;
text = gtk_entry_get_text (GTK_ENTRY (entry));
g_return_if_fail (xml != NULL);
essid_entry = GTK_ENTRY (glade_xml_get_widget (xml, "essid_entry"));
button = GTK_BUTTON (glade_xml_get_widget (xml, "ok_button"));
enc_check_button = GTK_CHECK_BUTTON (glade_xml_get_widget (xml, "use_encryption_checkbox"));
text = gtk_entry_get_text (essid_entry);
if (text[0] == '\000')
gtk_widget_set_sensitive (button, FALSE);
else
gtk_widget_set_sensitive (button, TRUE);
enable = FALSE;
/* If we're using encryptin, validate the settings */
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enc_check_button)))
{
GtkComboBox *combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo"));
GtkEntry *passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry"));
const char *passphrase_text = gtk_entry_get_text (passphrase_entry);
if (passphrase_text[0] == '\000')
enable = FALSE;
else
{
int combo_choice = gtk_combo_box_get_active (combo);
switch (combo_choice)
{
case KEY_TYPE_ASCII_KEY:
if ((strlen (passphrase_text) != 5) && (strlen (passphrase_text) != 13))
enable = FALSE;
break;
case KEY_TYPE_HEX_KEY:
if ((strlen (passphrase_text) != 10) && (strlen (passphrase_text) != 26))
enable = FALSE;
break;
default:
break;
}
}
}
gtk_widget_set_sensitive (GTK_WIDGET (button), enable);
}
static GtkTreeModel *create_wireless_adaptor_model (NMWirelessApplet *applet)
......@@ -108,12 +146,17 @@ void nmwa_other_network_dialog_key_type_combo_changed (GtkWidget *key_type_combo
case KEY_TYPE_128_BIT_PASSPHRASE:
gtk_label_set_label (entry_label, _("Passphrase:"));
break;
case KEY_TYPE_128_BIT_HEX_KEY:
gtk_label_set_label (entry_label, _("Key:"));
case KEY_TYPE_ASCII_KEY:
gtk_label_set_label (entry_label, _("Ascii Key:"));
break;
case KEY_TYPE_HEX_KEY:
gtk_label_set_label (entry_label, _("Hex Key:"));
break;
default:
break;
}
update_button_cb (key_type_combo, xml);
}
......@@ -145,15 +188,18 @@ void nmwa_other_network_dialog_enc_check_toggled (GtkWidget *enc_check_button, g
gtk_widget_set_sensitive (GTK_WIDGET (combo_label), active);
gtk_widget_set_sensitive (GTK_WIDGET (entry), active);
gtk_widget_set_sensitive (GTK_WIDGET (entry_label), active);
update_button_cb (enc_check_button, xml);
}
static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApplet *applet, NetworkDevice **def_dev)
{
GtkDialog *dialog = NULL;
GtkWidget *entry;
GtkWidget *essid_entry;
GtkWidget *button;
GtkComboBox *key_type_combo;
GtkEntry *passphrase_entry;
gint n_wireless_interfaces = 0;
GSList *element;
char *label;
......@@ -166,13 +212,13 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
/* Set up the dialog */
dialog = GTK_DIALOG (glade_xml_get_widget (xml, "custom_essid_dialog"));
entry = glade_xml_get_widget (xml, "essid_entry");
essid_entry = glade_xml_get_widget (xml, "essid_entry");
button = glade_xml_get_widget (xml, "ok_button");
gtk_widget_grab_focus (entry);
gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_widget_grab_focus (essid_entry);
gtk_entry_set_text (GTK_ENTRY (essid_entry), "");
gtk_widget_set_sensitive (button, FALSE);
g_signal_connect (entry, "changed", G_CALLBACK (update_button_cb), button);
g_signal_connect (essid_entry, "changed", G_CALLBACK (update_button_cb), xml);
label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
_("Custom wireless network"),
......@@ -234,6 +280,9 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
g_signal_connect (G_OBJECT (key_type_combo), "changed", GTK_SIGNAL_FUNC (nmwa_other_network_dialog_key_type_combo_changed), xml);
nmwa_other_network_dialog_key_type_combo_changed (GTK_WIDGET (key_type_combo), xml);
passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry"));
g_signal_connect (passphrase_entry, "changed", G_CALLBACK (update_button_cb), xml);
return (dialog);
}
......@@ -314,14 +363,16 @@ void nmwa_other_network_dialog_run (NMWirelessApplet *applet)
case KEY_TYPE_128_BIT_PASSPHRASE:
nm_key_type = NM_ENC_TYPE_128_BIT_PASSPHRASE;
break;
case KEY_TYPE_128_BIT_HEX_KEY:
nm_key_type = NM_ENC_TYPE_128_BIT_HEX_KEY;
case KEY_TYPE_ASCII_KEY:
nm_key_type = NM_ENC_TYPE_ASCII_KEY;
break;
case KEY_TYPE_HEX_KEY:
nm_key_type = NM_ENC_TYPE_HEX_KEY;
break;
default:
nm_key_type = NM_ENC_TYPE_UNKNOWN;
break;
}
applet->applet_state = APPLET_STATE_WIRELESS_CONNECTING;
applet->forcing_device = TRUE;
nmwa_dbus_set_device (applet->connection, def_dev, net, nm_key_type, passphrase);
......
......@@ -312,8 +312,9 @@
<child>
<widget class="GtkComboBox" id="key_type_combo">
<property name="visible">True</property>
<property name="items" translatable="yes">128-bit Passphrase
128-bit Raw Hex Key</property>
<property name="items" translatable="yes">128-bit Passphrase (WEP)
Ascii Key (WEP)
Hex Key (WEP)</property>
</widget>
<packing>
<property name="left_attach">1</property>
......
......@@ -435,7 +435,6 @@ gtk_cell_view_expose (GtkWidget *widget,
gdk_draw_rectangle (GTK_WIDGET (cellview)->window,
gc,
TRUE,
/*0, 0,*/
widget->allocation.x,
widget->allocation.y,
......
......@@ -223,10 +223,15 @@ char *nm_ap_get_enc_key_hashed (NMAccessPoint *ap)
if (source_key)
hashed = nm_wireless_128bit_key_from_passphrase (source_key);
break;
case (NM_ENC_TYPE_128_BIT_HEX_KEY):
case (NM_ENC_TYPE_40_BIT_PASSPHRASE):
case (NM_ENC_TYPE_40_BIT_HEX_KEY):
case (NM_ENC_TYPE_ASCII_KEY):
if (source_key){
if(strlen(source_key)<=5)
hashed = nm_wireless_64bit_ascii_to_hex (source_key);
else
hashed = nm_wireless_128bit_ascii_to_hex (source_key);
}
break;
case (NM_ENC_TYPE_HEX_KEY):
case (NM_ENC_TYPE_UNKNOWN):
if (source_key)
hashed = g_strdup (source_key);
......
......@@ -52,6 +52,7 @@ typedef struct NMDeviceWirelessOptions
guint8 max_quality;
guint8 noise;
gint8 strength;
gint8 invalid_strength_counter;
GMutex *scan_mutex;
/* We keep a couple lists around since wireless cards
......@@ -894,13 +895,11 @@ void nm_device_update_signal_strength (NMDevice *dev)
/* If we aren't the active device, we don't really have a signal strength
* that would mean anything.
*/
#if 0
if (dev != dev->app_data->active_device)
{
dev->options.wireless.strength = -1;
return;
}
#endif
/* Fake a value for test devices */
if (dev->test_device)
......@@ -926,6 +925,14 @@ void nm_device_update_signal_strength (NMDevice *dev)
}
close (iwlib_socket);
/* Try to smooth out the strength. Atmel cards, for example, will give no strength
* one second and normal strength the next.
*/
if ((percent == -1) && (++dev->options.wireless.invalid_strength_counter <= 3))
percent = dev->options.wireless.strength;
else
dev->options.wireless.invalid_strength_counter = 0;
dev->options.wireless.strength = percent;
}
......@@ -2163,9 +2170,13 @@ gboolean nm_device_wireless_network_exists (NMDevice *dev, const char *network,
case (NM_ENC_TYPE_128_BIT_PASSPHRASE):
hashed_key = nm_wireless_128bit_key_from_passphrase (key);
break;
case (NM_ENC_TYPE_128_BIT_HEX_KEY):
case (NM_ENC_TYPE_40_BIT_PASSPHRASE):
case (NM_ENC_TYPE_40_BIT_HEX_KEY):
case (NM_ENC_TYPE_ASCII_KEY):
if(strlen(key)<=5)
hashed_key = nm_wireless_64bit_ascii_to_hex (key);
else
hashed_key = nm_wireless_128bit_ascii_to_hex (key);
break;
case (NM_ENC_TYPE_HEX_KEY):
case (NM_ENC_TYPE_UNKNOWN):
hashed_key = g_strdup (key);
break;
......
......@@ -33,18 +33,42 @@
#include "NetworkManagerPolicy.h"
#include "NetworkManagerUtils.h"
/*
* nm_wireless_64bit_ascii_to_hex
*
* Convert an ASCII string into a suitable WEP key.
*
*/
char *nm_wireless_64bit_ascii_to_hex (const char *ascii)
{
static char hex_digits[] = "0123456789abcdef";
unsigned char *res;
int i;
res = g_malloc (33);
for (i = 0; i < 16; i++)
{
res[2*i] = hex_digits[ascii[i] >> 4];
res[2*i+1] = hex_digits[ascii[i] & 0xf];
}
/* We chomp it at byte 10, since WEP keys only use 40 bits */
res[10] = 0;
return (res);
}
/*
* nm_wireless_md5_digest_to_ascii
* nm_wireless_128bit_ascii_to_hex
*
* Convert an MD5 digest into an ascii string suitable for use
* Convert an ascii string into a suitable string for use
* as a WEP key.
*
* Code originally by Alex Larsson <alexl@redhat.com> and
* copyright Red Hat, Inc. under terms of the LGPL.
*
*/
static char *nm_wireless_md5_digest_to_ascii (unsigned char digest[16])
char *nm_wireless_128bit_ascii_to_hex (const char *ascii)
{
static char hex_digits[] = "0123456789abcdef";
unsigned char *res;
......@@ -53,8 +77,8 @@ static char *nm_wireless_md5_digest_to_ascii (unsigned char digest[16])
res = g_malloc (33);
for (i = 0; i < 16; i++)
{
res[2*i] = hex_digits[digest[i] >> 4];
res[2*i+1] = hex_digits[digest[i] & 0xf];
res[2*i] = hex_digits[ascii[i] >> 4];
res[2*i+1] = hex_digits[ascii[i] & 0xf];
}
/* We chomp it at byte 26, since WEP keys only use 104 bits */
......@@ -96,7 +120,7 @@ char *nm_wireless_128bit_key_from_passphrase (const char *passphrase)
gnome_keyring_md5_string (md5_data, digest);
#endif
return (nm_wireless_md5_digest_to_ascii (digest));
return (nm_wireless_128bit_ascii_to_hex (digest));
}
......@@ -115,8 +139,14 @@ int nm_wireless_qual_to_percent (NMDevice *dev, const struct iw_quality *qual)
g_return_val_if_fail (qual != NULL, -1);
/* Try using the card's idea of the signal quality first */
if (qual->qual >= 1)
if ((nm_device_get_max_quality (dev) == 100) && (qual->qual < 100))
{
/* Atmel driver seems to use qual->qual is the percentage value */
percent = CLAMP (qual->qual, 0, 100);
}
else if (qual->qual >= 1)
{
/* Try it the Gnome Wireless Applet way */
percent = (int)rint ((log (qual->qual) / log (94)) * 100.0);
percent = CLAMP (percent, 0, 100);
}
......@@ -129,7 +159,7 @@ int nm_wireless_qual_to_percent (NMDevice *dev, const struct iw_quality *qual)
/* If the statistics are in dBm or relative */
if(qual->level > nm_device_get_max_quality (dev))
{
#define BEST_SIGNAL 85 /* In dBm, stuck card next to AP, this is what I got :) */
#define BEST_SIGNAL 85 /* In dBm, stuck card next to AP, this is what I got */
/* Values in dBm (absolute power measurement) */
if (qual->level > 0)
......
......@@ -27,6 +27,8 @@
#include "NetworkManagerDevice.h"
#include "NetworkManagerAPList.h"
char * nm_wireless_64bit_ascii_to_hex (const char *ascii);
char * nm_wireless_128bit_ascii_to_hex (const char *ascii);
char * nm_wireless_128bit_key_from_passphrase (const char *passphrase);
gboolean nm_wireless_scan_monitor (gpointer user_data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment