From 956ad6fbb803b9ee4650b66fd98c09b2cdcb8871 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 16 Nov 2004 16:34:14 +0000 Subject: [PATCH] 2004-11-16 Dan Williams * src/NetworkManagerDevice.[ch] - (nm_device_clear_activation_fail): new function * src/NetworkManagerPolicy.c - (nm_state_modification_monitor): clear the activation_failed flag on devices when we've dealt with the failure so the user doesn't get failure-dialog-spammed git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@317 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 9 +++ src/NetworkManagerDevice.c | 125 +++---------------------------------- src/NetworkManagerDevice.h | 1 + src/NetworkManagerPolicy.c | 25 +++++--- 4 files changed, 33 insertions(+), 127 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0f9f1a030..77d2d850fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-11-16 Dan Williams + + * src/NetworkManagerDevice.[ch] + - (nm_device_clear_activation_fail): new function + + * src/NetworkManagerPolicy.c + - (nm_state_modification_monitor): clear the activation_failed flag on devices + when we've dealt with the failure so the user doesn't get failure-dialog-spammed + 2004-11-16 Dan Williams * src/NetworkManagerDevice.c diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index 66e74021ec..3cbf3bf0de 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -1458,123 +1458,6 @@ gboolean HAVE_LINK (NMDevice *dev) return (nm_device_get_link_active (dev)); } -#if 0 -/* - * nm_device_activate_wireless_wait_for_link - * - * Spin until we have a wireless link, which may mean - * requesting a key from the user and trying various hashed - * iterations of that key. - * - */ -void nm_device_activate_wireless_wait_for_link (NMDevice *dev) -{ - NMAccessPoint *best_ap; - guint32 bad_crypt_packets = 0; - int attempt = 1; - - g_return_if_fail (dev != NULL); - - /* If the card is just inserted, we may not have had a chance to scan yet */ - best_ap = nm_device_get_best_ap (dev); - if (!best_ap) - { - nm_device_do_wireless_scan (dev); - nm_device_update_best_ap (dev); - best_ap = nm_device_get_best_ap (dev); - } - - /* Wait until we have a link. Some things that might block us from - * getting one: - * 1) Access point we want to associate with has encryption enabled and - * we don't have the right encryption key. If we have a key of some - * sort, try various passhprase->key hashes of it. If we don't have - * a key, ask the user for one and wait until we are canceled (wireless - * card was ejected or the user plugged the computer into a wired network) - * or until we get a key back. - * 2) We don't have any access points we wish to associate with yet. In that case - * wait for the wireless scan to complete in the other thread and to pick - * a "best" access point for us. - * - */ - - /* There are two ways to check for a good link. If we are using WEP and Open System - * authentication, then we can associate with the base station regardless of whether the - * WEP key is right or not. Therefore, we have to monitor the # of packets the card discards - * when its unable to decrypt them, since that gives us some indicator of whether the WEP - * key is wrong. It seems that right after association, at least one packet is dropped by - * most cards if the WEP key is wrong. - * - * The second and better way (if all cards actually supported it) is to check the MAC address - * the card is associated with. However, this doesn't tell us if the WEP key is wrong when we - * are using Open System authentication. Also, not all drivers return an invalid MAC address - * when the card cannot communicate with the access point. - */ - - /* Try activating the device with the key and access point we have already */ - if (best_ap) - nm_device_activate_wireless (dev, best_ap, &bad_crypt_packets); - - /* For the link check, ensure that: - * 1) a classic link check is good, ie does the card report a valid associated AP MAC address and is it - * receiving WEP-enabled packets OK if WEP is on - * 2) we have a best access point, and if that AP is encrypted, that we have a valid encryption key for it - * - * If either of these things fail, we try other access points or we try to retrieve another encrpytion key - * from the user. - * - */ - while (!HAVE_LINK (dev, bad_crypt_packets) || (best_ap && AP_NEED_KEY (best_ap))) - { - /* Refresh what we think is the best AP to associate with */ - if (best_ap) - nm_ap_unref (best_ap); - if ((best_ap = nm_device_get_best_ap (dev))) - { - dev->options.wireless.now_scanning = FALSE; - - /* If we don't have a link yet, the encryption key is bad. Ask the user for a - * new one. - */ - if (nm_ap_get_encrypted (best_ap)) - { - dev->options.wireless.user_key_received = FALSE; - nm_dbus_get_user_key_for_network (dev->app_data->dbus_connection, dev, best_ap, attempt); - attempt++; - - /* Wait for the key to come back */ - syslog (LOG_DEBUG, "nm_device_activation_worker(%s): asking for user key.", nm_device_get_iface (dev)); - while (!dev->options.wireless.user_key_received && !dev->quit_activation) - g_usleep (G_USEC_PER_SEC / 2); - - syslog (LOG_DEBUG, "nm_device_activation_worker(%s): user key received.", nm_device_get_iface (dev)); - - /* If we were told to quit activation, stop the thread and return */ - if (nm_device_activation_should_cancel (dev)) - goto out; - } - - /* Try activating again with up-to-date access point and keys */ - nm_device_activate_wireless (dev, best_ap, &bad_crypt_packets); - } - else - { - dev->options.wireless.now_scanning = TRUE; - syslog (LOG_DEBUG, "nm_device_activation_worker(%s): waiting for an access point.", nm_device_get_iface (dev)); - g_usleep (G_USEC_PER_SEC * 2); - } - - /* If we were told to quit activation, stop the thread and return */ - if (nm_device_activation_should_cancel (dev)) - goto out; - } - -out: - if (best_ap) - nm_ap_unref (best_ap); - dev->options.wireless.now_scanning = FALSE; -} -#endif /* * nm_device_activate_wireless @@ -1886,6 +1769,14 @@ gboolean nm_device_did_activation_fail (NMDevice *dev) } +void nm_device_clear_activation_fail (NMDevice *dev) +{ + g_return_if_fail (dev != NULL); + + dev->activation_failed = FALSE; +} + + /* * nm_device_activation_cancel * diff --git a/src/NetworkManagerDevice.h b/src/NetworkManagerDevice.h index 3b93e6adcc..cb54fbd662 100644 --- a/src/NetworkManagerDevice.h +++ b/src/NetworkManagerDevice.h @@ -107,6 +107,7 @@ void nm_device_activation_cancel (NMDevice *dev); gboolean nm_device_is_just_activated (NMDevice *dev); gboolean nm_device_is_activating (NMDevice *dev); gboolean nm_device_did_activation_fail (NMDevice *dev); +void nm_device_clear_activation_fail (NMDevice *dev); gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added); gboolean nm_device_is_scanning (NMDevice *dev); diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index bf9954de09..ef4f45c84b 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -350,23 +350,28 @@ gboolean nm_state_modification_monitor (gpointer user_data) } else if (data->active_device && nm_device_did_activation_fail (data->active_device)) { - NMAccessPoint *ap = NULL; + nm_device_clear_activation_fail (data->active_device); nm_dbus_signal_device_status_change (data->dbus_connection, data->active_device, DEVICE_ACTIVATION_FAILED); if (nm_device_is_wireless (data->active_device)) { - ap = nm_device_get_best_ap (data->active_device); - /* Add the AP to the invalid list and force a best ap update */ - nm_ap_list_append_ap (data->invalid_ap_list, ap); - nm_ap_unref (ap); - nm_device_update_best_ap (data->active_device); + NMAccessPoint *ap = nm_device_get_best_ap (data->active_device); + if (ap) + { + /* Add the AP to the invalid list and force a best ap update */ + nm_ap_list_append_ap (data->invalid_ap_list, ap); + nm_device_update_best_ap (data->active_device); + + /* Unref once because the list takes ownership, and unref a second time because + * nm_device_get_best_ap() refs it before returning. + */ + nm_ap_unref (ap); + nm_ap_unref (ap); + } + syslog (LOG_INFO, "nm_state_modification_monitor() failed to activate device %s (%s)", nm_device_get_iface (data->active_device), ap ? nm_ap_get_essid (ap) : "(none)"); } - if (ap && nm_ap_get_essid (ap)) - syslog (LOG_INFO, "nm_state_modification_monitor() failed to activate device %s (%s)", nm_device_get_iface (data->active_device), nm_ap_get_essid (ap)); else syslog (LOG_INFO, "nm_state_modification_monitor() failed to activate device %s", nm_device_get_iface (data->active_device)); nm_data_mark_state_changed (data); - if (ap) - nm_ap_unref (ap); } /* Clear the starting up flag, so we will now take over and have our way with