2004-06-24 14:18:37 +00:00
|
|
|
/* 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-07-25 02:40:19 +00:00
|
|
|
gboolean nm_wireless_is_most_prefered_ap (NMData *data, NMAccessPoint *ap, int *highest_priority)
|
2004-06-24 14:18:37 +00:00
|
|
|
{
|
|
|
|
|
GSList *element;
|
|
|
|
|
gboolean is_most_preferred = FALSE;
|
|
|
|
|
|
2004-07-25 02:40:19 +00:00
|
|
|
g_return_val_if_fail (data != NULL, FALSE);
|
2004-06-24 14:18:37 +00:00
|
|
|
g_return_val_if_fail (ap != NULL, FALSE);
|
2004-07-25 02:40:19 +00:00
|
|
|
g_return_val_if_fail (highest_priority != NULL, FALSE);
|
2004-06-24 14:18:37 +00:00
|
|
|
|
|
|
|
|
/* 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 16:15:36 +00:00
|
|
|
|
2004-06-24 14:18:37 +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);
|
2004-06-24 14:18:37 +00:00
|
|
|
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);
|
2004-07-06 01:34:10 +00:00
|
|
|
|
2004-06-24 14:18:37 +00:00
|
|
|
if (!data->active_device)
|
|
|
|
|
return (TRUE);
|
|
|
|
|
|
2004-07-06 01:34:10 +00:00
|
|
|
/* Attempt to acquire mutex so that data->active_device sticks around.
|
2004-06-24 14:18:37 +00:00
|
|
|
* 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))
|
2004-07-06 01:34:10 +00:00
|
|
|
nm_device_do_wireless_scan (data->active_device);
|
2004-06-24 14:18:37 +00:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|