NetworkManager/src/NetworkManagerWireless.c

113 lines
3.3 KiB
C
Raw Normal View History

/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <stdio.h>
#include <iwlib.h>
#include "NetworkManager.h"
#include "NetworkManagerDevice.h"
#include "NetworkManagerWireless.h"
#include "NetworkManagerPolicy.h"
#include "NetworkManagerUtils.h"
extern gboolean debug;
/*
* nm_wireless_is_most_prefered_ap
*
* For a given AP, filter it through the allowed list and return TRUE if its
* both allowed _and_ has a better priority than highest_priority.
*
*/
gboolean nm_wireless_is_most_prefered_ap (NMData *data, NMAccessPoint *ap, int *highest_priority)
{
GSList *element;
gboolean is_most_preferred = FALSE;
g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (ap != NULL, FALSE);
g_return_val_if_fail (highest_priority != NULL, FALSE);
/* Attempt to acquire mutex for device list iteration.
* If the acquire fails, just ignore the scan completely.
*/
if (nm_try_acquire_mutex (data->allowed_ap_list_mutex, __FUNCTION__))
{
element = data->allowed_ap_list;
2004-07-27 Dan Williams <dcbw@redhat.com> * src/NetworkManagerAPList.[ch] src/Makefile.am - Add. Deal with allowed network list additions, deletions, and updates * dispatcher-daemon/NetworkManagerDispatcher.c - Add missing <dbus/dbus.h> header * info-daemon/NetworkManagerInfo.[ch] - Add missing <dbus/dbus.h> header - Implement the GConf notify callback to signal NetworkManager of an allowed network change - Better error checking * info-daemon/NetworkManagerInfoDbus.[ch] - Add missing <dbus/dbus.h> header - Convert to using dbus_message_append_args/dbus_message_get_args - Implement nmi_dbus_signal_update_allowed_network() to signal NetworkManager that an allowed network changed. We don't want to signal on individual keys _inside_ an allowed network really, just want NM to query the info daemon for updated info on all keys. - Better error checking * src/NetworkManager.[ch] - Add missing <dbus/dbus.h> header - Move allowed_ap_list free functions to NetworkManagerAPList.[ch] - Zero out NMData structure on free - No longer use a thread for allowed_ap_list updating, instead its now done through dbus queries against NetworkManagerInfo - Populate allowed_ap_list initially before adding existing network devices to the device list, so wireless devices can get their "best" AP * src/NetworkManagerDbus.[ch] - Convert to using dbus_message_append_args/dbus_message_get_args - Better error checking - Implement Allowed Network info functions to request allowed network info from NetworkManagerInfo - Implement the filter function to process signals from NetworkManagerInfo about changing allowed networks * src/NetworkManagerDevice.c - Fix file descriptor leak in nm_device_update_ip4_address() `CVS: Modified Files: git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@22 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-07-27 16:15:36 +00:00
while (element)
{
NMAccessPoint *allowed_ap = (NMAccessPoint *)(element->data);
/* If the essid of the scanned ap matches one in our allowed list, and this AP is
* a higher priority than one we may possibly have already found.
*/
if ( allowed_ap
&& (nm_null_safe_strcmp (nm_ap_get_essid (allowed_ap), nm_ap_get_essid (ap)) == 0)
&& (nm_ap_get_priority (allowed_ap) < *highest_priority))
{
2004-07-15 Dan Williams <dcbw@redhat.com> * src/Makefile.am - Turn on warnings * src/NetworkManager.c - nm_create_device_and_add_to_list(): call nm_device_deactivate() rather that doing the deactivation ourselves - Cancel an pending actions on a device if its being removed - Break up link state checking a bit, make non-active wireless cards deactivated to save power - Remove unused variables * src/NetworkManager.h - Add support for "pending" device * src/NetworkManagerAP.h src/NetworkManagerAP.c - Add support for determining whether and AP has encryption enabled or not - AP address is now "struct ether_addr" rather than a string * src/NetworkManagerDbus.h src/NetworkManagerDbus.c - Add signal NeedKeyForNetwork, method SetKeyForNetwork (testing only) - Changes for AP address from struct ether_addr->string * src/NetworkManagerDevice.h src/NetworkManagerDevice.c - Remove unused variables, fix warnings - Add support for Pending Actions (things that block a device from being "active" until they are completed). - First pending action: Get a WEP key from the user - Add nm_device_is_wire[d|less](), rename nm_device_is_wireless() - Clean up explicit testing of dev->iface_type to use nm_device_is_wireless() - Update wireless link checking to try to determine if the AP we are associated with is correct, but the WEP key we are using is just wrong. If its wrong, trigger the GetUserKey pending action on the device - If dhclient can't get an IP address, it brings the device down. Bring it back up in that case, otherwise we can't scan or link-check on it - Add IP address change notifications at appropriate points (still needs some work) - Add nm_device_need_ap_switch(), checks whether we need to switch access points or not * src/NetworkManagerPolicy.h src/NetworkManagerPolicy.c - Split out "best" access point determiniation into separate function - Make device activation 2-stage: first the device is pending, then in the next iteration through it becomes "active" unless it has pending actions * src/NetworkManagerUtils.h src/NetworkManagerUtils.c - Clean up unused variables and warnings - Wrap our debug macros in {} to prevent possible confusion * src/NetworkManagerWireless.c - Forgot to return current best priority, which lead to last available AP always being chosen no matter what its priority was. Corrected. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@15 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-07-15 16:51:48 +00:00
*highest_priority = nm_ap_get_priority (allowed_ap);
is_most_preferred = TRUE;
break;
}
element = g_slist_next (element);
}
nm_unlock_mutex (data->allowed_ap_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT( "nm_wireless_is_most_prefered_ap() could not acquire allowed access point mutex.\n" );
return (is_most_preferred);
}
/*
* nm_wireless_scan_monitor
*
* Called every 10s to get a list of access points.
*
*/
gboolean nm_wireless_scan_monitor (gpointer user_data)
{
NMData *data = (NMData *)user_data;
g_return_val_if_fail (data != NULL, TRUE);
if (!data->active_device)
return (TRUE);
/* Attempt to acquire mutex so that data->active_device sticks around.
* If the acquire fails, just ignore the scan completely.
*/
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
if (data->active_device && (nm_device_get_iface_type (data->active_device) == NM_IFACE_TYPE_WIRELESS_ETHERNET))
nm_device_do_wireless_scan (data->active_device);
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT( "nm_wireless_scan_monitor() could not acquire device list mutex.\n" );
return (TRUE);
}