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

* info-daemon/NetworkManagerInfo.c:
		- (main): clean up Seth's code style

	* info-daemon/NetworkManagerInfoDbus.c:
		- Use the more aptly-named path/service/interface constants from NetworkManager
		- Don't return empty strings ("") as object paths ever, instead return errors

	* panel-applet/NMWirelessApplet.c:
		- Clean up Seth's code style

	* src/NetworkManager.[ch]
		- (nm_remove_device_from_list): remove anything having to do with pending_device
		- (main, nm_print_usage): change --daemon=[yes|no] -> --no-daemon

	* src/NetworkManagerAPList.[ch]
		- Move Iter struct right above the iter functions to preserve opacity
		- (nm_ap_list_remove_ap): implement
		- (nm_ap_list_update_network): deal with errors returned from nm_dbus_get_network_priority(),
			remove AP if NetworkManagerInfo doesn't know anything about it
		- (nm_ap_list_diff): user NMAPList iterators
		- (nm_ap_list_print_members): implement debugging function

	* src/NetworkManagerDbus.[ch]
		- (nm_dbus_nm_get_active_device): remove anything to do with pending_device
		- (nm_dbus_get_user_key_for_network): remove DBusPendingCall stuff (unused),
			and move the actual key setting stuff into NetworkManagerDevice.c
		- (nm_dbus_get_network_priority): return -1 now on errors
		- (nm_dbus_nmi_filter): fix strcmp() error that caused PreferredNetworkUpdate signals to
			get lost, and force the active device to update its "best" ap when AP lists change
		- (nm_dbus_nm_message_handler): Update conditions for returning "connecting" for a "status"
			method call due to pending_device member removal

	* src/NetworkManagerDevice.[ch]
		- Move NMDevice structure to the top
		- Add a wireless scan mutex and a best_ap mutex to the Wireless Options structure
		- Remove Pending Action stuff from everywhere
		- (nm_device_activation_*): We now "begin" activation and start a thread to do the
			activation for us.  This thread blocks until all conditions for activation have
			been met (ie for wireless devices, we need a valid WEP key and a "best" ap), and
			then setup up the interface and runs dhclient.  We have to do this because there
			is no guaruntee how long dhclient takes, and while we are blocking on it, we cannot
			run our main loop and respond to dbus method calls or HAL device removals/inserts
		- (nm_device_set_user_key_for_network): Move logic here from NetworkManagerDbus.c so we
			can tell nm_device_activation_worker() that we've got a key
		- (nm_device_*_best_ap): lock access to best_ap member of Wireless Options structure
		- (nm_device_get_path_for_ap): dumb it down so the list doesn't lock against itself when
			diffing (AP appear/disappear signal functions make sure the AP is actually in the device's
list)
		- (nm_device_update_best_ap): move logic from nm_wireless_is_ap_better() here

	* src/NetworkManagerPolicy.c
		- Remove anything to do with pending_device
		- Adjust device activation to deal with activation-in-worker-thread

	* src/NetworkManagerUtils.c
		- Clean up locking debugging a bit

	* src/NetworkManagerWireless.[ch]
		- (nm_wireless_is_ap_better): remove, stick logic in nm_device_update_best_ap().  This function
			was badly named and is better as a device function

	* panel-applet/.cvsignore: add


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@46 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2004-08-11 18:14:02 +00:00
parent 8e04fc11ff
commit d06aa3e6ff
18 changed files with 726 additions and 472 deletions

View File

@@ -1,3 +1,67 @@
2004-08-11 Dan Williams <dcbw@redhat.com>
* info-daemon/NetworkManagerInfo.c:
- (main): clean up Seth's code style
* info-daemon/NetworkManagerInfoDbus.c:
- Use the more aptly-named path/service/interface constants from NetworkManager
- Don't return empty strings ("") as object paths ever, instead return errors
* panel-applet/NMWirelessApplet.c:
- Clean up Seth's code style
* src/NetworkManager.[ch]
- (nm_remove_device_from_list): remove anything having to do with pending_device
- (main, nm_print_usage): change --daemon=[yes|no] -> --no-daemon
* src/NetworkManagerAPList.[ch]
- Move Iter struct right above the iter functions to preserve opacity
- (nm_ap_list_remove_ap): implement
- (nm_ap_list_update_network): deal with errors returned from nm_dbus_get_network_priority(),
remove AP if NetworkManagerInfo doesn't know anything about it
- (nm_ap_list_diff): user NMAPList iterators
- (nm_ap_list_print_members): implement debugging function
* src/NetworkManagerDbus.[ch]
- (nm_dbus_nm_get_active_device): remove anything to do with pending_device
- (nm_dbus_get_user_key_for_network): remove DBusPendingCall stuff (unused),
and move the actual key setting stuff into NetworkManagerDevice.c
- (nm_dbus_get_network_priority): return -1 now on errors
- (nm_dbus_nmi_filter): fix strcmp() error that caused PreferredNetworkUpdate signals to
get lost, and force the active device to update its "best" ap when AP lists change
- (nm_dbus_nm_message_handler): Update conditions for returning "connecting" for a "status"
method call due to pending_device member removal
* src/NetworkManagerDevice.[ch]
- Move NMDevice structure to the top
- Add a wireless scan mutex and a best_ap mutex to the Wireless Options structure
- Remove Pending Action stuff from everywhere
- (nm_device_activation_*): We now "begin" activation and start a thread to do the
activation for us. This thread blocks until all conditions for activation have
been met (ie for wireless devices, we need a valid WEP key and a "best" ap), and
then setup up the interface and runs dhclient. We have to do this because there
is no guaruntee how long dhclient takes, and while we are blocking on it, we cannot
run our main loop and respond to dbus method calls or HAL device removals/inserts
- (nm_device_set_user_key_for_network): Move logic here from NetworkManagerDbus.c so we
can tell nm_device_activation_worker() that we've got a key
- (nm_device_*_best_ap): lock access to best_ap member of Wireless Options structure
- (nm_device_get_path_for_ap): dumb it down so the list doesn't lock against itself when
diffing (AP appear/disappear signal functions make sure the AP is actually in the device's list)
- (nm_device_update_best_ap): move logic from nm_wireless_is_ap_better() here
* src/NetworkManagerPolicy.c
- Remove anything to do with pending_device
- Adjust device activation to deal with activation-in-worker-thread
* src/NetworkManagerUtils.c
- Clean up locking debugging a bit
* src/NetworkManagerWireless.[ch]
- (nm_wireless_is_ap_better): remove, stick logic in nm_device_update_best_ap(). This function
was badly named and is better as a device function
* panel-applet/.cvsignore: add
2004-08-09 Seth Nickell <seth@gnome.org>
* panel-applet/NMWirelessApplet.c: (nmwa_timeout_handler),

View File

@@ -168,7 +168,8 @@ int main( int argc, char *argv[] )
GMainLoop *loop;
guint notify_id;
struct poptOption options[] = {
struct poptOption options[] =
{
{ "no-daemon", 'n', POPT_ARG_NONE, NULL, 0,
"Don't detatch from the console and run in the background.", NULL },
{ NULL, '\0', 0, NULL, 0, NULL, NULL }

View File

@@ -30,13 +30,24 @@
#include "NetworkManagerInfoDbus.h"
#include "NetworkManagerInfoPassphraseDialog.h"
#define NMI_DBUS_NMI_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManagerInfo"
#define NMI_DBUS_NMI_NAMESPACE "org.freedesktop.NetworkManagerInfo"
#define NM_DBUS_NM_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManager"
#define NM_DBUS_NM_NAMESPACE "org.freedesktop.NetworkManager"
#define NM_DBUS_NM_DEVICES_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManager/Devices"
#define NM_DBUS_NM_DEVICES_NAMESPACE "org.freedesktop.NetworkManager.Devices"
#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager"
#define NM_DBUS_PATH "/org/freedesktop/NetworkManager"
#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager"
#define NM_DBUS_PATH_DEVICES "/org/freedesktop/NetworkManager/Devices"
#define NM_DBUS_INTERFACE_DEVICES "org.freedesktop.NetworkManager.Devices"
#define NMI_DBUS_SERVICE "org.freedesktop.NetworkManagerInfo"
#define NMI_DBUS_PATH "/org/freedesktop/NetworkManagerInfo"
#define NMI_DBUS_INTERFACE "org.freedesktop.NetworkManagerInfo"
/*
* nmi_network_type_valid
*
* Helper to validate network types NMI can deal with
*
*/
inline gboolean nmi_network_type_valid (NMINetworkType type)
{
if ((type == NETWORK_TYPE_TRUSTED) || (type == NETWORK_TYPE_PREFERRED))
@@ -113,11 +124,7 @@ void nmi_dbus_return_user_key (DBusConnection *connection, const char *device,
g_return_if_fail (network != NULL);
g_return_if_fail (passphrase != NULL);
message = dbus_message_new_method_call (NM_DBUS_NM_NAMESPACE,
NM_DBUS_NM_OBJECT_PATH_PREFIX,
NM_DBUS_NM_NAMESPACE,
"setKeyForNetwork");
if (message == NULL)
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setKeyForNetwork")))
{
fprintf (stderr, "nmi_dbus_return_user_key(): Couldn't allocate the dbus message\n");
return;
@@ -161,7 +168,7 @@ void nmi_dbus_signal_update_network (DBusConnection *connection, const char *net
default: return;
}
message = dbus_message_new_signal (NMI_DBUS_NMI_OBJECT_PATH_PREFIX, NMI_DBUS_NMI_NAMESPACE, signal);
message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, signal);
if (!message)
{
fprintf (stderr, "nmi_dbus_signal_update_network(): Not enough memory for new dbus message!\n");
@@ -200,14 +207,14 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
dbus_error_init (&error);
if (!dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID))
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidArguments",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getNetworks called with invalid arguments.");
return (reply_message);
}
if (!nmi_network_type_valid (type))
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidArguments",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getNetworks called with an invalid network type %d.", type);
return (reply_message);
}
@@ -222,16 +229,20 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
/* List all allowed access points that gconf knows about */
element = dir_list = gconf_client_all_dirs (info->gconf_client, path, NULL);
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
if (!dir_list)
dbus_message_iter_append_string (&iter_array, "");
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks",
"There were are no %s networks stored.",
type == NETWORK_TYPE_TRUSTED ? "trusted" : (type == NETWORK_TYPE_PREFERRED ? "preferred" : "unknown"));
}
else
{
gboolean value_added = FALSE;
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
/* Append the essid of every allowed or ignored access point we know of
* to a string array in the dbus message.
*/
@@ -256,7 +267,12 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
/* Make sure that there's at least one array element if all the gconf calls failed */
if (!value_added)
dbus_message_iter_append_string (&iter_array, "");
{
dbus_message_unref (reply_message);
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks",
"There were are no %s networks stored.",
type == NETWORK_TYPE_TRUSTED ? "trusted" : (type == NETWORK_TYPE_PREFERRED ? "preferred" : "unknown"));
}
}
return (reply_message);
@@ -288,7 +304,7 @@ static DBusMessage *nmi_dbus_get_network_prio (NMIAppInfo *info, DBusMessage *me
|| !nmi_network_type_valid (type)
|| (strlen (network) <= 0))
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidArguments",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::get*NetworkPriority called with invalid arguments.");
return (reply_message);
}
@@ -313,7 +329,7 @@ static DBusMessage *nmi_dbus_get_network_prio (NMIAppInfo *info, DBusMessage *me
}
else
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "BadNetworkData",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
"NetworkManagerInfo::get*NetworkPriority could not access data for network '%s'", network);
}
@@ -347,7 +363,7 @@ static DBusMessage *nmi_dbus_get_network_essid (NMIAppInfo *info, DBusMessage *m
|| !nmi_network_type_valid (type)
|| (strlen (network) <= 0))
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidArguments",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::get*NetworkEssid called with invalid arguments.");
return (reply_message);
}
@@ -372,7 +388,7 @@ static DBusMessage *nmi_dbus_get_network_essid (NMIAppInfo *info, DBusMessage *m
}
else
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "BadNetworkData",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadNetworkData",
"NetworkManagerInfo::get*NetworkEssid could not access data for network '%s'", network);
}
@@ -406,7 +422,7 @@ static DBusMessage *nmi_dbus_get_network_key (NMIAppInfo *info, DBusMessage *mes
|| !nmi_network_type_valid (type)
|| (strlen (network) <= 0))
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidArguments",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::get*NetworkKey called with invalid arguments.");
return (reply_message);
}
@@ -479,7 +495,7 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio
reply_message = nmi_dbus_get_network_key (info, message);
else
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "UnknownMethod",
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "UnknownMethod",
"NetworkManagerInfo knows nothing about the method %s for object %s", method, path);
}
@@ -518,9 +534,9 @@ static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessag
g_return_val_if_fail (info != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
if (dbus_message_is_signal (message, NM_DBUS_NM_NAMESPACE, "WirelessNetworkAppeared"))
if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkAppeared"))
appeared = TRUE;
else if (dbus_message_is_signal (message, NM_DBUS_NM_NAMESPACE, "WirelessNetworkDisappeared"))
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkDisappeared"))
disappeared = TRUE;
if (appeared || disappeared)
@@ -560,14 +576,14 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
DBusObjectPathVTable nmi_vtable = { &nmi_dbus_nmi_unregister_handler, &nmi_dbus_nmi_message_handler, NULL, NULL, NULL, NULL };
dbus_error_init (&dbus_error);
dbus_bus_acquire_service (dbus_connection, NMI_DBUS_NMI_NAMESPACE, 0, &dbus_error);
dbus_bus_acquire_service (dbus_connection, NMI_DBUS_SERVICE, 0, &dbus_error);
if (dbus_error_is_set (&dbus_error))
{
fprintf (stderr, "nmi_dbus_service_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'\n", dbus_error.message);
return (-1);
}
if (!dbus_connection_register_object_path (dbus_connection, NMI_DBUS_NMI_OBJECT_PATH_PREFIX, &nmi_vtable, info))
if (!dbus_connection_register_object_path (dbus_connection, NMI_DBUS_PATH, &nmi_vtable, info))
{
fprintf (stderr, "nmi_dbus_service_init() could not register a handler for NetworkManagerInfo. Not enough memory?\n");
return (-1);
@@ -579,9 +595,9 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
dbus_error_init (&dbus_error);
dbus_bus_add_match (dbus_connection,
"type='signal',"
"interface='"NM_DBUS_NM_NAMESPACE"',"
"sender='"NM_DBUS_NM_NAMESPACE"',"
"path='"NM_DBUS_NM_OBJECT_PATH_PREFIX"'", &dbus_error);
"interface='" NM_DBUS_INTERFACE "',"
"sender='" NM_DBUS_SERVICE "',"
"path='" NM_DBUS_PATH "'", &dbus_error);
if (dbus_error_is_set (&dbus_error))
return (-1);

3
panel-applet/.cvsignore Normal file
View File

@@ -0,0 +1,3 @@
Makefile
Makefile.in
NMWirelessApplet.server

View File

@@ -41,7 +41,7 @@ $(server_in_files:.server.in=.server): $(server_in_files)
uidir = $(datadir)/gnome-2.0/ui
ui_DATA = NMWirelessApplet.xml
pixmapdir = $(datadir)/pixmaps/NMWirelessApplet/
pixmapdir = $(datadir)/pixmaps/NMWirelessApplet
pixmap_DATA = no-link-0.png \
broken-0.png \
signal-1-40.png \

View File

@@ -162,22 +162,28 @@ static int nmwa_timeout_handler (NMWirelessApplet *applet)
if (!applet->connection)
applet->connection = nmwa_dbus_init (applet);
if (applet->nm_active) {
fprintf( stderr, "NM is present {\n");
if ((active_device = nmwa_dbus_get_active_wireless_device (applet->connection))) {
applet->have_active_device = TRUE;
nmwa_update_state (applet);
fprintf( stderr, " A wireless device was active, showing applet\n");
gtk_widget_show (GTK_WIDGET (applet));
dbus_free (active_device);
} else {
fprintf( stderr, " A wireless device was not active, hiding applet\n");
gtk_widget_hide (GTK_WIDGET (applet));
}
fprintf( stderr, "}\n\n");
} else {
fprintf( stderr, "NM is *not* present\n");
gtk_widget_hide (GTK_WIDGET (applet));
if (applet->nm_active)
{
fprintf( stderr, "NM is present {\n");
if ((active_device = nmwa_dbus_get_active_wireless_device (applet->connection)))
{
applet->have_active_device = TRUE;
nmwa_update_state (applet);
fprintf( stderr, " A wireless device was active, showing applet\n");
gtk_widget_show (GTK_WIDGET (applet));
dbus_free (active_device);
}
else
{
fprintf( stderr, " A wireless device was not active, hiding applet\n");
gtk_widget_hide (GTK_WIDGET (applet));
}
fprintf( stderr, "}\n\n");
}
else
{
fprintf( stderr, "NM is *not* present\n");
gtk_widget_hide (GTK_WIDGET (applet));
}
return (TRUE);

View File

@@ -148,10 +148,8 @@ void nm_remove_device_from_list (NMData *data, const char *udi)
{
if (data->active_device && (dev == data->active_device))
data->active_device = NULL;
else if (data->pending_device && (dev == data->pending_device))
data->pending_device = NULL;
nm_device_pending_action_cancel (dev);
nm_device_activation_cancel (dev);
nm_device_unref (dev);
/* Remove the device entry from the device list and free its data */
@@ -445,7 +443,6 @@ static void nm_data_free (NMData *data)
g_return_if_fail (data != NULL);
nm_device_unref (data->active_device);
nm_device_unref (data->pending_device);
g_slist_foreach (data->dev_list, nm_data_dev_list_element_free, NULL);
g_slist_free (data->dev_list);
@@ -483,11 +480,11 @@ void nm_data_set_state_modified (NMData *data, gboolean modified)
*/
static void nm_print_usage (void)
{
fprintf (stderr, "\n" "usage : NetworkManager [--daemon=yes|no] [--help]\n");
fprintf (stderr, "\n" "usage : NetworkManager [--no-daemon] [--help]\n");
fprintf (stderr,
"\n"
" --daemon=yes|no Become a daemon\n"
" --help Show this information and exit\n"
" --no-daemon Become a daemon\n"
" --help Show this information and exit\n"
"\n"
"NetworkManager monitors all network connections and automatically\n"
"chooses the best connection to use. It also allows the user to\n"
@@ -517,7 +514,7 @@ int main( int argc, char *argv[] )
const char *opt;
static struct option options[] = {
{"daemon", 1, NULL, 0},
{"no-daemon", 0, NULL, 0},
{"help", 0, NULL, 0},
{NULL, 0, NULL, 0}
};
@@ -535,18 +532,8 @@ int main( int argc, char *argv[] )
nm_print_usage ();
exit (EXIT_SUCCESS);
}
else if (strcmp (opt, "daemon") == 0)
{
if (strcmp ("yes", optarg) == 0)
become_daemon = TRUE;
else if (strcmp ("no", optarg) == 0)
become_daemon = FALSE;
else
{
nm_print_usage ();
exit (EXIT_FAILURE);
}
}
else if (strcmp (opt, "no-daemon") == 0)
become_daemon = FALSE;
break;
default:

View File

@@ -38,7 +38,6 @@ struct NMData
GMutex *dev_list_mutex;
struct NMDevice *active_device;
struct NMDevice *pending_device;
gboolean state_modified;
GMutex *state_modified_mutex;

View File

@@ -37,13 +37,6 @@ struct NMAccessPointList
};
struct NMAPListIter
{
NMAccessPointList *list;
GSList *cur_pos;
gboolean valid;
};
/*
* nm_ap_list_new
*
@@ -148,6 +141,43 @@ void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap)
}
/*
* nm_ap_list_remove_ap
*
* Helper to remove an AP to an ap list of a certain type.
*
*/
void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap)
{
GSList *element = NULL;
g_return_if_fail (list != NULL);
g_return_if_fail (ap != NULL);
if (!nm_try_acquire_mutex (list->mutex, __FUNCTION__))
{
NM_DEBUG_PRINT( "nm_ap_list_append_ap() could not acquire AP list mutex.\n" );
return;
}
element = list->ap_list;
while (element)
{
NMAccessPoint *list_ap = (NMAccessPoint *)(element->data);
if (list_ap == ap)
{
list->ap_list = g_slist_remove_link (list->ap_list, element);
nm_ap_unref (list_ap);
g_slist_free (element);
break;
}
element = g_slist_next (element);
}
nm_unlock_mutex (list->mutex, __FUNCTION__);
}
/*
* nm_ap_list_get_ap_by_essid
@@ -199,23 +229,32 @@ void nm_ap_list_update_network (NMAccessPointList *list, const char *network, NM
g_return_if_fail (network != NULL);
g_return_if_fail (((list->type == NETWORK_TYPE_TRUSTED) || (list->type == NETWORK_TYPE_PREFERRED)));
/* Find access point in list, if not found create a new AP and add it to the list */
if (!(ap = nm_ap_list_get_ap_by_essid (list, network)))
nm_ap_list_append_ap (list, (ap = nm_ap_new ()));
/* Get the allowed access point's details from NetworkManagerInfo */
if ((essid = nm_dbus_get_network_essid (data->dbus_connection, list->type, network)))
{
char *key = nm_dbus_get_network_key (data->dbus_connection, list->type, network);
guint priority = nm_dbus_get_network_priority (data->dbus_connection, list->type, network);
gint priority = nm_dbus_get_network_priority (data->dbus_connection, list->type, network);
nm_ap_set_essid (ap, essid);
nm_ap_set_wep_key (ap, key);
nm_ap_set_priority (ap, priority);
if (priority >= 0)
{
/* Find access point in list, if not found create a new AP and add it to the list */
if (!(ap = nm_ap_list_get_ap_by_essid (list, network)))
nm_ap_list_append_ap (list, (ap = nm_ap_new ()));
nm_ap_set_essid (ap, essid);
nm_ap_set_wep_key (ap, key);
nm_ap_set_priority (ap, priority);
}
g_free (essid);
g_free (key);
}
else
{
/* AP got deleted, remove it from our list */
if ((ap = nm_ap_list_get_ap_by_essid (list, network)))
nm_ap_list_remove_ap (list, ap);
}
}
@@ -267,22 +306,20 @@ void nm_ap_list_populate (NMAccessPointList *list, NMData *data)
*/
void nm_ap_list_diff (NMData *data, NMDevice *dev, NMAccessPointList *old, NMAccessPointList *new)
{
GSList *element = NULL;
NMAPListIter *iter;
NMAccessPoint *old_ap;
NMAccessPoint *new_ap;
g_return_if_fail (data != NULL);
g_return_if_fail (dev != NULL);
if (old)
element = old->ap_list;
/* Iterate over each item in the old list and find it in the new list */
while (element)
if (old && (iter = nm_ap_list_iter_new (old)))
{
NMAccessPoint *old_ap = (NMAccessPoint *)(element->data);
NMAccessPoint *new_ap = NULL;
if (old_ap)
while ((old_ap = nm_ap_list_iter_next (iter)))
{
NMAccessPoint *new_ap = NULL;
if ((new_ap = nm_ap_list_get_ap_by_essid (new, nm_ap_get_essid (old_ap))))
{
nm_ap_set_matched (old_ap, TRUE);
@@ -293,27 +330,30 @@ void nm_ap_list_diff (NMData *data, NMDevice *dev, NMAccessPointList *old, NMAcc
else
nm_dbus_signal_wireless_network_disappeared (data->dbus_connection, dev, old_ap);
}
element = g_slist_next (element);
nm_ap_list_iter_free (iter);
}
/* Iterate over the new list and compare to the old list. Items that aren't already
* matched are by definition new networks.
*/
if (new)
element = new->ap_list;
else
element = NULL;
while (element)
if (new && (iter = nm_ap_list_iter_new (new)))
{
NMAccessPoint *new_ap = (NMAccessPoint *)(element->data);
if (new_ap && !nm_ap_get_matched (new_ap))
nm_dbus_signal_wireless_network_appeared (data->dbus_connection, dev, new_ap);
element = g_slist_next (element);
while ((new_ap = nm_ap_list_iter_next (iter)))
{
if (!nm_ap_get_matched (new_ap))
nm_dbus_signal_wireless_network_appeared (data->dbus_connection, dev, new_ap);
}
nm_ap_list_iter_free (iter);
}
}
/*
* nm_ap_list_lock
*
* Grab exclusive access to an access point list
*
*/
gboolean nm_ap_list_lock (NMAccessPointList *list)
{
g_return_val_if_fail (list != NULL, FALSE);
@@ -322,6 +362,12 @@ gboolean nm_ap_list_lock (NMAccessPointList *list)
}
/*
* nm_ap_list_unlock
*
* Give up access to an access point list
*
*/
void nm_ap_list_unlock (NMAccessPointList *list)
{
g_return_if_fail (list != NULL);
@@ -330,6 +376,15 @@ void nm_ap_list_unlock (NMAccessPointList *list)
}
struct NMAPListIter
{
NMAccessPointList *list;
GSList *cur_pos;
gboolean valid;
};
NMAPListIter * nm_ap_list_iter_new (NMAccessPointList *list)
{
NMAPListIter *iter;
@@ -387,3 +442,35 @@ void nm_ap_list_iter_free (NMAPListIter *iter)
nm_ap_list_unlock (iter->list);
g_free (iter);
}
/*
* nm_ap_list_print_members
*
* Print the information about each access point in an AP list
*
*/
void nm_ap_list_print_members (NMAccessPointList *list, const char *name)
{
NMAccessPoint *ap;
NMAPListIter *iter;
int i = 0;
g_return_if_fail (list != NULL);
g_return_if_fail (name != NULL);
if (!(iter = nm_ap_list_iter_new (list)))
return;
fprintf (stderr, "AP_LIST_PRINT: printing members of '%s'\n", name);
while ((ap = nm_ap_list_iter_next (iter)))
{
fprintf (stderr, "\t%d)\tessid='%s', prio=%d, key='%s', enc=%d, addr=0x%X, qual=%d, freq=%f, rate=%d, inval=%d\n",
i, nm_ap_get_essid (ap), nm_ap_get_priority (ap), nm_ap_get_wep_key (ap), nm_ap_get_encrypted (ap),
nm_ap_get_address (ap), nm_ap_get_quality (ap), nm_ap_get_freq (ap), nm_ap_get_rate (ap),
nm_ap_get_invalid (ap));
i++;
}
fprintf (stderr, "AP_LIST_PRINT: done\n");
nm_ap_list_iter_free (iter);
}

View File

@@ -43,6 +43,7 @@ void nm_ap_list_ref (NMAccessPointList *list);
void nm_ap_list_unref (NMAccessPointList *list);
void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap);
void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap);
NMAccessPoint * nm_ap_list_get_ap_by_essid (NMAccessPointList *list, const char *network);
@@ -60,4 +61,6 @@ NMAccessPoint * nm_ap_list_iter_get_ap (NMAPListIter *iter);
NMAccessPoint * nm_ap_list_iter_next (NMAPListIter *iter);
void nm_ap_list_iter_free (NMAPListIter *iter);
void nm_ap_list_print_members (NMAccessPointList *list, const char *name);
#endif

View File

@@ -167,19 +167,13 @@ static NMAccessPoint *nm_dbus_get_ap_from_object_path (const char *path, NMDevic
static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DBusMessage *message, NMData *data)
{
DBusMessage *reply_message = NULL;
NMDevice *dev = NULL;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
if (data->active_device)
dev = data->active_device;
else if (data->pending_device)
dev = data->pending_device;
/* Construct object path of "active" device and return it */
if (dev)
if (data->active_device)
{
char *object_path;
@@ -187,7 +181,7 @@ static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DB
if (!reply_message)
return (NULL);
object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (data->active_device));
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, object_path, DBUS_TYPE_INVALID);
g_free (object_path);
}
@@ -526,8 +520,7 @@ void nm_dbus_get_user_key_for_network_data_free (void *user_data)
* Asks NetworkManagerInfo for a user-entered WEP key.
*
*/
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap,
DBusPendingCall **pending)
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap)
{
DBusMessage *message;
@@ -596,27 +589,9 @@ static void nm_dbus_set_user_key_for_network (DBusConnection *connection, DBusMe
DBUS_TYPE_INVALID))
{
NMDevice *dev;
const char *cancel_message = "***canceled***";
if ((dev = nm_get_device_by_iface (data, device)))
{
/* If the user canceled, mark the ap as invalid */
if (strncmp (passphrase, cancel_message, strlen (cancel_message)) == 0)
{
NMAccessPoint *ap;
if ((ap = nm_device_ap_list_get_ap_by_essid (dev, network)))
{
NMAccessPoint *invalid_ap = nm_ap_new_from_ap (ap);
nm_ap_list_append_ap (data->invalid_ap_list, invalid_ap);
nm_device_pending_action_cancel (dev);
nm_device_update_best_ap (dev);
}
}
else
nm_device_pending_action_set_user_key (dev, passphrase);
}
nm_device_set_user_key_for_network (dev, data->invalid_ap_list, network, passphrase);
char *key = nm_wireless_128bit_key_from_passphrase (passphrase);
g_free (key);
@@ -775,24 +750,27 @@ char * nm_dbus_get_network_key (DBusConnection *connection, NMNetworkType type,
*
* Get a network's priority from NetworkManagerInfo
*
* Returns: -1 on error
* AP Priority if no error
*
*/
guint nm_dbus_get_network_priority (DBusConnection *connection, NMNetworkType type, const char *network)
gint nm_dbus_get_network_priority (DBusConnection *connection, NMNetworkType type, const char *network)
{
DBusMessage *message;
DBusError error;
DBusMessage *reply;
guint priority = NM_AP_PRIORITY_WORST;
guint priority = -1;
g_return_val_if_fail (connection != NULL, NM_AP_PRIORITY_WORST);
g_return_val_if_fail (network != NULL, NM_AP_PRIORITY_WORST);
g_return_val_if_fail (type != NETWORK_TYPE_UNKNOWN, NM_AP_PRIORITY_WORST);
g_return_val_if_fail (connection != NULL, -1);
g_return_val_if_fail (network != NULL, -1);
g_return_val_if_fail (type != NETWORK_TYPE_UNKNOWN, -1);
message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH,
NMI_DBUS_INTERFACE, "getNetworkPriority");
if (!message)
{
NM_DEBUG_PRINT ("nm_dbus_get_network_priority(): Couldn't allocate the dbus message\n");
return (NM_AP_PRIORITY_WORST);
return (-1);
}
dbus_message_append_args (message, DBUS_TYPE_STRING, network,
@@ -810,7 +788,7 @@ guint nm_dbus_get_network_priority (DBusConnection *connection, NMNetworkType ty
{
dbus_error_init (&error);
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID))
priority = NM_AP_PRIORITY_WORST;
priority = -1;
}
dbus_message_unref (message);
@@ -883,21 +861,24 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes
{
NMData *data = (NMData *)user_data;
const char *object_path;
const char *method;
NMAccessPointList *list = NULL;
gboolean handled = FALSE;
g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
printf ("NMI Filter called\n");
method = dbus_message_get_member (message);
if (!(object_path = dbus_message_get_path (message)))
return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
if ( (strcmp (object_path, NMI_DBUS_PATH) != 0)
NM_DEBUG_PRINT_2 ("nm_dbus_nmi_filter() got method %s for path %s\n", method, object_path);
if ( (strcmp (object_path, NMI_DBUS_PATH) == 0)
&& dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "TrustedNetworkUpdate"))
list = data->trusted_ap_list;
else if ( (strcmp (object_path, NMI_DBUS_PATH) != 0)
else if ( (strcmp (object_path, NMI_DBUS_PATH) == 0)
&& dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "PreferredNetworkUpdate"))
list = data->preferred_ap_list;
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceCreated"))
@@ -913,6 +894,9 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes
data->info_daemon_avail = TRUE;
nm_data_set_state_modified (data, TRUE);
}
/* Don't set handled = TRUE since other filter functions on this dbus connection
* may want to know about service signals.
*/
}
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceDeleted"))
{
@@ -927,6 +911,9 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes
data->info_daemon_avail = FALSE;
nm_data_set_state_modified (data, TRUE);
}
/* Don't set handled = TRUE since other filter functions on this dbus connection
* may want to know about service signals.
*/
}
if (list)
@@ -938,11 +925,26 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes
if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID))
return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
fprintf( stderr, "update of network '%s'\n", network);
nm_ap_list_update_network (list, network, data);
dbus_free (network);
/* Make sure the currently active device updates its "best" ap
* based on the new preferred/trusted network information.
*/
if ( data->active_device
&& nm_device_is_wireless (data->active_device)
&& !nm_device_activating (data->active_device))
{
fprintf( stderr, "updating active device's best ap\n");
nm_device_update_best_ap (data->active_device);
nm_data_set_state_modified (data, TRUE);
fprintf( stderr, "Device's best ap now '%s'\n", nm_ap_get_essid (nm_device_get_best_ap (data->active_device)));
}
handled = TRUE;
}
return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
}
@@ -1173,7 +1175,7 @@ static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection,
{
if (data->active_device)
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "connected", DBUS_TYPE_INVALID);
else if (!data->active_device && data->pending_device)
if (data->active_device && nm_device_activating (data->active_device))
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "connecting", DBUS_TYPE_INVALID);
else
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "disconnected", DBUS_TYPE_INVALID);

View File

@@ -53,7 +53,7 @@ void nm_dbus_signal_wireless_network_appeared (DBusConnection *connection, NMD
void nm_dbus_signal_wireless_network_disappeared (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap);
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, DBusPendingCall **pending);
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap);
void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection);
@@ -61,7 +61,7 @@ char * nm_dbus_get_network_essid (DBusConnection *connection, NMNetworkType t
char * nm_dbus_get_network_key (DBusConnection *connection, NMNetworkType type, const char *network);
guint nm_dbus_get_network_priority (DBusConnection *connection, NMNetworkType type, const char *network);
gint nm_dbus_get_network_priority (DBusConnection *connection, NMNetworkType type, const char *network);
char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, int *num_networks);

View File

@@ -37,7 +37,64 @@
extern gboolean debug;
/* Local static prototypes */
static gboolean mii_get_link (NMDevice *dev);
static gpointer nm_device_activation_worker (gpointer user_data);
/******************************************************/
/* Wireless device specific options */
typedef struct NMDeviceWirelessOptions
{
gchar *cur_essid;
gboolean supports_wireless_scan;
GMutex *scan_mutex;
NMAccessPointList *ap_list;
NMAccessPoint *best_ap;
GMutex *best_ap_mutex;
gboolean freeze_best_ap;
gboolean user_key_received;
} NMDeviceWirelessOptions;
/* Wired device specific options */
typedef struct NMDeviceWiredOptions
{
int foo;
} NMDeviceWiredOptions;
typedef union NMDeviceOptions
{
NMDeviceWirelessOptions wireless;
NMDeviceWiredOptions wired;
} NMDeviceOptions;
/*
* NetworkManager device structure
*/
struct NMDevice
{
guint refcount;
gchar *udi;
gchar *iface;
NMDeviceType type;
gboolean link_active;
guint32 ip4_address;
/* FIXME: ipv6 address too */
NMData *app_data;
NMDeviceOptions options;
gboolean activating;
gboolean just_activated;
gboolean quit_activation;
};
/******************************************************/
/*
* nm_device_test_wireless_extensions
@@ -158,69 +215,13 @@ NMDevice *nm_get_device_by_iface (NMData *data, const char *iface)
/*****************************************************************************/
/* NMDevice object routines */
/* NMDevice object routines */
/*****************************************************************************/
enum NMPendingAction
{
NM_PENDING_ACTION_NONE,
NM_PENDING_ACTION_GET_USER_KEY
};
typedef enum NMPendingAction NMPendingAction;
typedef struct NMDeviceWirelessOptions
{
gchar *cur_essid;
gboolean supports_wireless_scan;
NMAccessPointList *ap_list;
NMAccessPoint *best_ap;
gboolean freeze_best_ap;
} NMDeviceWirelessOptions;
typedef struct NMDeviceWiredOptions
{
int foo;
} NMDeviceWiredOptions;
typedef union NMDeviceOptions
{
NMDeviceWirelessOptions wireless;
NMDeviceWiredOptions wired;
} NMDeviceOptions;
typedef struct NMPendingActionUserKeyOptions
{
unsigned char *essid; // ESSID we are waiting for a key for
DBusPendingCall *pending_call;
} NMPendingActionUserKeyOptions;
typedef union NMPendingActionOptions
{
NMPendingActionUserKeyOptions user_key;
} NMPendingActionOptions;
/*
* NetworkManager device structure
*/
struct NMDevice
{
guint refcount;
gchar *udi;
gchar *iface;
NMDeviceType type;
gboolean link_active;
NMPendingAction pending_action;
NMPendingActionOptions pending_action_options;
guint32 ip4_address;
/* FIXME: ipv6 address too */
NMData *app_data;
NMDeviceOptions options;
};
/*
* nm_device_new
*
* Creates and initializes the structure representation of an NLM device.
* Creates and initializes the structure representation of an NM device.
*
*/
NMDevice *nm_device_new (const char *iface, NMData *app_data)
@@ -244,9 +245,25 @@ NMDevice *nm_device_new (const char *iface, NMData *app_data)
if (nm_device_is_wireless (dev))
{
if (!(dev->options.wireless.scan_mutex = g_mutex_new ()))
{
g_free (dev->iface);
g_free (dev);
return (NULL);
}
if (!(dev->options.wireless.best_ap_mutex = g_mutex_new ()))
{
g_mutex_free (dev->options.wireless.scan_mutex);
g_free (dev->iface);
g_free (dev);
return (NULL);
}
if (!(dev->options.wireless.ap_list = nm_ap_list_new (NETWORK_TYPE_DEVICE)))
{
g_free (dev->iface);
g_mutex_free (dev->options.wireless.best_ap_mutex);
g_free (dev);
return (NULL);
}
@@ -286,8 +303,10 @@ void nm_device_unref (NMDevice *dev)
g_free (dev->iface);
if (nm_device_is_wireless (dev))
{
g_mutex_free (dev->options.wireless.scan_mutex);
nm_ap_list_unref (dev->options.wireless.ap_list);
nm_ap_unref (dev->options.wireless.best_ap);
g_mutex_free (dev->options.wireless.best_ap_mutex);
}
dev->udi = NULL;
@@ -417,7 +436,7 @@ void nm_device_update_link_active (NMDevice *dev, gboolean check_mii)
* only scan for active/pending device and clear ap_list and best_ap for
* devices that aren't active/pending.
*/
if ((dev == data->active_device) || (dev == data->pending_device))
if (dev == data->active_device)
{
iwlib_socket = iw_sockets_open ();
if (iw_get_ext (iwlib_socket, nm_device_get_iface (dev), SIOCGIWAP, &wrq) >= 0)
@@ -779,68 +798,162 @@ gboolean nm_device_is_up (NMDevice *dev)
/*
* nm_device_activate
* nm_device_activation_begin
*
* Activate the device, bringing it up and getting it an
* IP address.
* Spawn a new thread to handle device activation.
*
* Returns: TRUE on success activation beginning
* FALSE on error beginning activation (bad params, couldn't create thread)
*
*/
gboolean nm_device_activate (NMDevice *dev)
gboolean nm_device_activation_begin (NMDevice *dev)
{
GError *error = NULL;
g_return_val_if_fail (dev != NULL, FALSE);
/* Ref the device so it doesn't go away while worker function is active */
nm_device_ref (dev);
/* Reset communication flags between worker and main thread */
dev->activating = FALSE;
dev->just_activated = FALSE;
dev->quit_activation = FALSE;
if (nm_device_is_wireless (dev))
dev->options.wireless.user_key_received = FALSE;
if (!g_thread_create (nm_device_activation_worker, dev, FALSE, &error))
{
NM_DEBUG_PRINT ("nm_device_activation_begin(): could not create activation worker thread.\n");
return (FALSE);
}
return (TRUE);
}
/*
* nm_device_wireless_activate
*
* Bring up a wireless card with the essid and wep key of its "best" ap
*
* Returns: TRUE on successful activation
* FALSE on unsuccessful activation (ie no best AP)
*
*/
static gboolean nm_device_activate_wireless (NMDevice *dev)
{
NMAccessPoint *best_ap;
gboolean success = FALSE;
g_return_val_if_fail (dev != NULL, FALSE);
g_return_val_if_fail (nm_device_is_wireless (dev), FALSE);
/* If the card is just inserted, we may not have had a chance to scan yet */
if (!(best_ap = nm_device_get_best_ap (dev)))
{
nm_device_do_wireless_scan (dev);
best_ap = nm_device_get_best_ap (dev);
}
/* If there is a desired AP to connect to, use that essid and possible WEP key */
if (best_ap && nm_ap_get_essid (best_ap))
{
nm_device_bring_down (dev);
nm_device_set_essid (dev, nm_ap_get_essid (best_ap));
/* Disable WEP */
nm_device_set_wep_key (dev, NULL);
if (nm_ap_get_encrypted (best_ap) && nm_ap_get_wep_key (best_ap))
nm_device_set_wep_key (dev, nm_ap_get_wep_key (best_ap));
NM_DEBUG_PRINT_2 ("nm_device_wireless_activate(%s) using essid '%s'\n", nm_device_get_iface (dev), nm_ap_get_essid (best_ap));
/* Bring the device up */
if (!nm_device_is_up (dev));
nm_device_bring_up (dev);
g_usleep (G_USEC_PER_SEC / 2); /* Pause to allow card to associate */
nm_device_update_link_active (dev, FALSE);
success = TRUE;
}
return (success);
}
/*
* nm_device_activation_worker
*
* Thread worker function to actually activate a device. We have to do it in another
* thread because things like dhclient block our main thread's event loop, and thus we
* wouldn't respond to dbus messages.
*/
static gpointer nm_device_activation_worker (gpointer user_data)
{
unsigned char buf[500];
gboolean success = FALSE;
unsigned char *iface;
unsigned char hostname[100] = "\0";
int host_err;
int dhclient_err;
FILE *pidfile;
NMDevice *dev = (NMDevice *)user_data;
g_return_val_if_fail (dev != NULL, FALSE);
g_return_val_if_fail (dev->app_data != NULL, FALSE);
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (dev->app_data != NULL, NULL);
fprintf( stderr, "nm_device_activation_worker (%s) started...\n", nm_device_get_iface (dev));
dev->activating = TRUE;
/* If its a wireless device, set the ESSID and WEP key */
if (nm_device_is_wireless (dev))
{
NMAccessPoint *best_ap = nm_device_get_best_ap (dev);
nm_device_activate_wireless (dev);
/* If the card is just inserted, we may not have had a chance to scan yet */
if (!best_ap)
/* If we don't have a link, it probably means the access point has
* encryption enabled and we don't have the right WEP key, or we don't
* have a "best" access point. Sit around and wait for either the WEP key
* or a good "best" AP.
*/
while (!nm_device_get_link_active (dev))
{
nm_device_do_wireless_scan (dev);
best_ap = nm_device_get_best_ap (dev);
}
NMAccessPoint *best_ap;
/* If there is a desired AP to connect to, use that essid and possible WEP key */
if (best_ap && nm_ap_get_essid (best_ap))
{
nm_device_bring_down (dev);
nm_device_set_essid (dev, nm_ap_get_essid (best_ap));
/* Disable WEP */
nm_device_set_wep_key (dev, NULL);
if (nm_ap_get_encrypted (best_ap) && nm_ap_get_wep_key (best_ap))
nm_device_set_wep_key (dev, nm_ap_get_wep_key (best_ap));
NM_DEBUG_PRINT_2 ("nm_device_activate(%s) using essid '%s'\n", nm_device_get_iface (dev), nm_ap_get_essid (best_ap));
/* Bring the device up */
if (!nm_device_is_up (dev));
nm_device_bring_up (dev);
g_usleep (G_USEC_PER_SEC / 2); /* Pause to allow card to associate */
/* If we don't have a link, it probably means the access point has
* encryption enabled and we don't have the right WEP key.
*/
nm_device_update_link_active (dev, FALSE);
best_ap = nm_device_get_best_ap (dev);
if (!best_ap)
return (FALSE);
if ( !nm_device_get_link_active (dev)
&& !nm_device_need_ap_switch (dev)
&& nm_ap_get_encrypted (best_ap))
if ((best_ap = nm_device_get_best_ap (dev)))
{
nm_device_pending_action_get_user_key (dev, best_ap);
return (FALSE);
/* WEP key we have is wrong, ask user for one */
if (!nm_device_need_ap_switch (dev) && 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);
/* Wait for the key to come back */
while (!dev->options.wireless.user_key_received && !dev->quit_activation)
g_usleep (G_USEC_PER_SEC / 4);
/* If we were told to quit activation, stop the thread and return */
if (dev->quit_activation)
{
fprintf( stderr, "nm_device_activation_worker(%s): activation canceled 1\n", nm_device_get_iface (dev));
dev->just_activated = FALSE;
nm_device_unref (dev);
return (NULL);
}
fprintf (stderr, "nm_device_activation_worker(%s): user key received!\n", nm_device_get_iface (dev));
}
nm_device_activate_wireless (dev);
}
else
g_usleep (G_USEC_PER_SEC * 2);
/* If we were told to quit activation, stop the thread and return */
if (dev->quit_activation)
{
fprintf( stderr, "nm_device_activation_worker(%s): activation canceled 1.5\n", nm_device_get_iface (dev));
dev->just_activated = FALSE;
nm_device_unref (dev);
return (NULL);
}
}
}
@@ -891,9 +1004,23 @@ gboolean nm_device_activate (NMDevice *dev)
snprintf (buf, 500, "/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-%s.leases -pf /var/run/dhclient-%s.pid -cf /etc/dhclient-%s.conf %s\n",
iface, iface, iface, iface);
dhclient_err = system (buf);
if (dhclient_err == 0)
success = TRUE;
else
/* Set the hostname back to what it was before so that X11 doesn't
* puke when the hostname changes, and so users can actually launch stuff.
*/
if (host_err >= 0)
sethostname (hostname, strlen (hostname));
/* If we were told to quit activation, stop the thread and return */
if (dev->quit_activation)
{
fprintf( stderr, "nm_device_activation_worker(%s): activation canceled 2\n", nm_device_get_iface (dev));
dev->just_activated = FALSE;
nm_device_unref (dev);
return (NULL);
}
if (dhclient_err != 0)
{
/* Interfaces cannot be down if they are the active interface,
* otherwise we cannot use them for scanning or link detection.
@@ -909,21 +1036,77 @@ gboolean nm_device_activate (NMDevice *dev)
nm_device_bring_up (dev);
}
/* Set the hostname back to what it was before so that X11 doesn't
* puke when the hostname changes, and so users can actually launch stuff.
*/
if (host_err >= 0)
sethostname (hostname, strlen (hostname));
/* Restart the nameservice caching daemon to make apps aware of new DNS servers */
snprintf (buf, 500, "/sbin/service nscd restart");
system (buf);
}
nm_dbus_signal_device_now_active (dev->app_data->dbus_connection, dev);
/* If we were told to quit activation, stop the thread and return */
if (dev->quit_activation)
{
fprintf( stderr, "nm_device_activation_worker(%s): activation canceled 3\n", nm_device_get_iface (dev));
dev->just_activated = FALSE;
nm_device_unref (dev);
return (NULL);
}
dev->just_activated = TRUE;
fprintf( stderr, "nm_device_activation_worker(%s): device activated\n", nm_device_get_iface (dev));
nm_device_update_ip4_address (dev);
return (success);
dev->activating = FALSE;
nm_device_unref (dev);
return (NULL);
}
/*
* nm_device_just_activated
*
* Check if the device was just activated successfully or not. If so, clear
* its just_activated flag and return TRUE. If its not activated yet, return FALSE.
*
*/
gboolean nm_device_just_activated (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, FALSE);
if (dev->just_activated)
{
dev->just_activated = FALSE;
return (TRUE);
}
else
return (FALSE);
}
/*
* nm_device_activating
*
* Return whether or not the device is currently activating itself.
*
*/
gboolean nm_device_activating (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, FALSE);
return (dev->activating);
}
/*
* nm_device_activation_cancel
*
* Signal activation worker that it should stop and die.
*
*/
void nm_device_activation_cancel (NMDevice *dev)
{
g_return_if_fail (dev != NULL);
fprintf( stderr, "nm_device_activation_cancel(%s): canceled\n", nm_device_get_iface (dev));
dev->quit_activation = TRUE;
}
@@ -942,11 +1125,12 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added)
g_return_val_if_fail (dev != NULL, FALSE);
g_return_val_if_fail (dev->app_data != NULL, FALSE);
iface = nm_device_get_iface (dev);
nm_device_activation_cancel (dev);
/* Take out any entries in the routing table and any IP address the old interface
* had.
*/
iface = nm_device_get_iface (dev);
if (iface && strlen (iface))
{
/* Remove routing table entries */
@@ -957,7 +1141,6 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added)
snprintf (buf, 500, "/sbin/ip address flush dev %s", iface);
system (buf);
nm_device_pending_action_cancel (dev);
dev->ip4_address = 0;
success = TRUE;
@@ -979,104 +1162,47 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added)
/*
* nm_device_pending_action
*
* Returns whether the device is blocking on a pending action or not.
*
*/
gboolean nm_device_pending_action (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, FALSE);
return (dev->pending_action != NM_PENDING_ACTION_NONE);
}
/*
* nm_device_pending_action_get_user_key
*
* Initiate a pending action to retrieve a key from the user, using
* NetworkManagerInfo daemon.
*
*/
void nm_device_pending_action_get_user_key (NMDevice *dev, NMAccessPoint *ap)
{
g_return_if_fail (dev != NULL);
g_return_if_fail (dev->app_data != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
g_return_if_fail (ap != NULL);
g_return_if_fail (nm_ap_get_essid (ap) != NULL);
if (dev->pending_action != NM_PENDING_ACTION_NONE)
return;
dev->pending_action = NM_PENDING_ACTION_GET_USER_KEY;
dev->pending_action_options.user_key.essid = g_strdup (nm_ap_get_essid (ap));
nm_dbus_get_user_key_for_network (dev->app_data->dbus_connection, dev, ap, &(dev->pending_action_options.user_key.pending_call));
}
/*
* nm_device_pending_action_set_user_key
* nm_device_set_user_key_for_network
*
* Called upon receipt of a NetworkManagerInfo reply with a
* user-supplied key.
*
*/
void nm_device_pending_action_set_user_key (NMDevice *dev, unsigned char *key)
void nm_device_set_user_key_for_network (NMDevice *dev, NMAccessPointList *invalid_list,
unsigned char *network, unsigned char *key)
{
NMAccessPoint *best_ap;
const char *cancel_message = "***canceled***";
g_return_if_fail (dev != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
g_return_if_fail (dev->pending_action == NM_PENDING_ACTION_GET_USER_KEY);
g_return_if_fail (network != NULL);
g_return_if_fail (key != NULL);
/* We only set the key on the access point if we can verify that the key is meant
* for that access point.
*/
if(dev->pending_action_options.user_key.essid)
/* If the user canceled, mark the ap as invalid */
if (strncmp (key, cancel_message, strlen (cancel_message)) == 0)
{
NMAccessPoint *best_ap = nm_device_get_best_ap (dev);
NMAccessPoint *ap;
if (best_ap)
if ((ap = nm_device_ap_list_get_ap_by_essid (dev, network)))
{
/* Make sure the "best" ap matches the essid we asked for the key of */
if (nm_null_safe_strcmp (dev->pending_action_options.user_key.essid, nm_ap_get_essid (best_ap)))
nm_ap_set_wep_key (best_ap, key);
NMAccessPoint *invalid_ap = nm_ap_new_from_ap (ap);
if (invalid_list)
nm_ap_list_append_ap (invalid_list, invalid_ap);
}
g_free (dev->pending_action_options.user_key.essid);
nm_device_update_best_ap (dev);
}
dev->pending_action = NM_PENDING_ACTION_NONE;
}
/*
* nm_device_cancel_pending_action
*
* Cancel any pending actions a device is blocking on and clean up
* those actions' data.
*
*/
void nm_device_pending_action_cancel (NMDevice *dev)
{
g_return_if_fail (dev != NULL);
g_return_if_fail (dev->app_data != NULL);
if (dev->pending_action == NM_PENDING_ACTION_GET_USER_KEY)
else if ((best_ap = nm_device_get_best_ap (dev)))
{
/* Tell NetworkManagerInfo to cancel the operation, and clean up data related to it */
#if 0
dbus_pending_call_cancel (dev->pending_action_options.user_key.pending_call);
dbus_pending_call_unref (dev->pending_action_options.user_key.pending_call);
#endif
g_free (dev->pending_action_options.user_key.essid);
dev->pending_action_options.user_key.essid = NULL;
nm_dbus_cancel_get_user_key_for_network (dev->app_data->dbus_connection);
/* Make sure the "best" ap matches the essid we asked for the key of,
* then set the new key on the access point.
*/
if (nm_null_safe_strcmp (network, nm_ap_get_essid (best_ap)))
nm_ap_set_wep_key (best_ap, key);
}
dev->pending_action = NM_PENDING_ACTION_NONE;
dev->options.wireless.user_key_received = TRUE;
}
@@ -1160,10 +1286,16 @@ NMAccessPointList *nm_device_ap_list_get (NMDevice *dev)
*/
NMAccessPoint *nm_device_get_best_ap (NMDevice *dev)
{
NMAccessPoint *best_ap;
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (nm_device_is_wireless (dev), NULL);
return (dev->options.wireless.best_ap);
g_mutex_lock (dev->options.wireless.best_ap_mutex);
best_ap = dev->options.wireless.best_ap;
g_mutex_unlock (dev->options.wireless.best_ap_mutex);
return (best_ap);
}
void nm_device_set_best_ap (NMDevice *dev, NMAccessPoint *ap)
@@ -1171,6 +1303,8 @@ void nm_device_set_best_ap (NMDevice *dev, NMAccessPoint *ap)
g_return_if_fail (dev != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
g_mutex_lock (dev->options.wireless.best_ap_mutex);
if (dev->options.wireless.best_ap)
nm_ap_unref (dev->options.wireless.best_ap);
@@ -1178,38 +1312,24 @@ void nm_device_set_best_ap (NMDevice *dev, NMAccessPoint *ap)
nm_ap_ref (ap);
dev->options.wireless.best_ap = ap;
g_mutex_unlock (dev->options.wireless.best_ap_mutex);
}
/*
* nm_device_get_path_for_ap
*
* Return the object path for an access point.
*
* NOTE: assumes the access point is actually in the device's access point list.
*
*/
char * nm_device_get_path_for_ap (NMDevice *dev, NMAccessPoint *ap)
{
NMAccessPointList *list;
NMAPListIter *iter;
NMAccessPoint *list_ap;
char *path = NULL;
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (ap != NULL, NULL);
if (!(list = nm_device_ap_list_get (dev)))
return (NULL);
if (!(iter = nm_ap_list_iter_new (list)))
return (NULL);
while ((list_ap = nm_ap_list_iter_next (iter)))
{
if (list_ap == ap)
{
path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES,
nm_device_get_iface (dev), nm_ap_get_essid (ap));
break;
}
}
nm_ap_list_iter_free (iter);
return (path);
return (g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev), nm_ap_get_essid (ap)));
}
@@ -1229,7 +1349,7 @@ gboolean nm_device_need_ap_switch (NMDevice *dev)
g_return_val_if_fail (nm_device_is_wireless (dev), FALSE);
ap = nm_device_get_best_ap (dev);
if (ap && (nm_null_safe_strcmp (nm_device_get_essid (dev), nm_ap_get_essid (ap)) != 0))
if (nm_null_safe_strcmp (nm_device_get_essid (dev), (ap ? nm_ap_get_essid (ap) : NULL)) != 0)
need_switch = TRUE;
return (need_switch);
@@ -1262,10 +1382,22 @@ void nm_device_update_best_ap (NMDevice *dev)
return;
while ((ap = nm_ap_list_iter_next (iter)))
{
char *ap_essid = nm_ap_get_essid (ap);
/* Access points in the "invalid" list cannot be used */
if (!nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, nm_ap_get_essid (ap)))
if (nm_wireless_is_ap_better (dev->app_data->trusted_ap_list, ap, &highest_priority))
if (!nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, ap_essid))
{
NMAccessPoint *tmp_ap = nm_ap_list_get_ap_by_essid (dev->app_data->trusted_ap_list, ap_essid);
/* If it exists in the trusted ap list, and it has a better priority than
* an access points already tested, make it the best for now.
*/
if (tmp_ap && (nm_ap_get_priority (tmp_ap) < highest_priority))
{
best_ap = ap;
highest_priority = nm_ap_get_priority (ap);
}
}
}
nm_ap_list_iter_free (iter);
@@ -1278,10 +1410,24 @@ void nm_device_update_best_ap (NMDevice *dev)
return;
while ((ap = nm_ap_list_iter_next (iter)))
{
char *ap_essid = nm_ap_get_essid (ap);
/* Access points in the "invalid" list cannot be used */
if (!nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, nm_ap_get_essid (ap)))
if (nm_wireless_is_ap_better (dev->app_data->preferred_ap_list, ap, &highest_priority))
fprintf( stderr, "PREF: Looking at ap '%s'\n", nm_ap_get_essid (ap));
if (!nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, ap_essid))
{
NMAccessPoint *tmp_ap = nm_ap_list_get_ap_by_essid (dev->app_data->preferred_ap_list, ap_essid);
/* If it exists in the preferred ap list, and it has a better priority than
* an access points already tested, make it the best for now.
*/
if ( tmp_ap && (nm_ap_get_priority (tmp_ap) < highest_priority))
{
fprintf( stderr, "PREF: setting ap '%s' as best\n", nm_ap_get_essid (ap));
best_ap = ap;
highest_priority = nm_ap_get_priority (ap);
}
}
}
nm_ap_list_iter_free (iter);
}
@@ -1383,7 +1529,7 @@ static void nm_device_do_normal_scan (NMDevice *dev)
* Users shouldn't get notification of new wireless networks if the device isn't the
* one that will provide their network connection.
*/
if ((dev == data->active_device) || (dev == data->pending_device))
if (dev == data->active_device)
nm_ap_list_diff (dev->app_data, dev, old_ap_list, nm_device_ap_list_get (dev));
if (old_ap_list)
nm_ap_list_unref (old_ap_list);
@@ -1484,6 +1630,9 @@ void nm_device_do_wireless_scan (NMDevice *dev)
g_return_if_fail (dev->app_data != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
if (!nm_try_acquire_mutex (dev->options.wireless.scan_mutex, __FUNCTION__))
return;
if (nm_device_get_supports_wireless_scan (dev))
nm_device_do_normal_scan (dev);
else
@@ -1503,6 +1652,8 @@ void nm_device_do_wireless_scan (NMDevice *dev)
nm_device_do_pseudo_scan (dev);
}
}
nm_unlock_mutex (dev->options.wireless.scan_mutex, __FUNCTION__);
}

View File

@@ -81,18 +81,19 @@ char * nm_device_get_path_for_ap (NMDevice *dev, NMAccessPoint *ap);
/* There is no function to get the WEP key since that's a slight security risk */
void nm_device_set_wep_key (NMDevice *dev, const char *wep_key);
gboolean nm_device_activate (NMDevice *dev);
gboolean nm_device_activation_begin (NMDevice *dev);
void nm_device_activation_cancel (NMDevice *dev);
gboolean nm_device_just_activated (NMDevice *dev);
gboolean nm_device_activating (NMDevice *dev);
gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added);
void nm_device_set_user_key_for_network (NMDevice *dev, struct NMAccessPointList *invalid_list,
unsigned char *network, unsigned char *key);
void nm_device_bring_up (NMDevice *dev);
void nm_device_bring_down (NMDevice *dev);
gboolean nm_device_is_up (NMDevice *dev);
gboolean nm_device_pending_action (NMDevice *dev);
void nm_device_pending_action_cancel (NMDevice *dev);
void nm_device_pending_action_get_user_key (NMDevice *dev, NMAccessPoint *ap);
void nm_device_pending_action_set_user_key (NMDevice *dev, unsigned char *key);
void nm_device_ap_list_add (NMDevice *dev, NMAccessPoint *ap);
void nm_device_ap_list_clear (NMDevice *dev);
struct NMAccessPointList *nm_device_ap_list_get (NMDevice *dev);

View File

@@ -163,7 +163,6 @@ gboolean nm_state_modification_monitor (gpointer user_data)
/* If the info daemon is now running, get our trusted/preferred ap lists from it */
if (data->info_daemon_avail && data->update_ap_lists)
{
fprintf( stderr, "getting lists from NetworkManagerInfo\n");
/* Query info daemon for network lists if its now running */
if (data->trusted_ap_list)
nm_ap_list_unref (data->trusted_ap_list);
@@ -198,7 +197,7 @@ fprintf( stderr, "getting lists from NetworkManagerInfo\n");
{
NMDevice *best_dev = NULL;
if ((best_dev = nm_policy_get_best_device (data)) != NULL)
if ((best_dev = nm_policy_get_best_device (data)))
nm_device_ref (best_dev);
/* Only do a switch when:
@@ -207,22 +206,10 @@ fprintf( stderr, "getting lists from NetworkManagerInfo\n");
* 3) best_dev is wireless and its access point is the best, but it doesn't have an IP address
*/
if ( best_dev != data->active_device
|| ( best_dev && nm_device_is_wireless (best_dev)
|| ( best_dev && nm_device_is_wireless (best_dev) && !nm_device_activating (best_dev)
&& (nm_device_need_ap_switch (best_dev) || (nm_device_get_ip4_address (best_dev) == 0))))
{
/* Cancel pending device actions on an existing pending device */
if (data->pending_device && (best_dev != data->pending_device))
{
nm_device_pending_action_cancel (data->pending_device);
nm_device_unref (data->pending_device);
data->pending_device = NULL;
}
NM_DEBUG_PRINT_1 ("nm_state_modification_monitor() set pending_device = %s\n", best_dev ? nm_device_get_iface (best_dev) : "(null)");
data->pending_device = best_dev;
if (data->pending_device && !nm_device_is_up (data->pending_device))
nm_device_bring_up (data->pending_device);
NM_DEBUG_PRINT_1 ("nm_state_modification_monitor(): beginning activation for device '%s'\n", best_dev ? nm_device_get_iface (best_dev) : "(null)");
/* Deactivate the old device */
if (data->active_device)
@@ -231,6 +218,11 @@ fprintf( stderr, "getting lists from NetworkManagerInfo\n");
nm_device_unref (data->active_device);
data->active_device = NULL;
}
/* Begin activation on the new device */
nm_device_ref (best_dev);
data->active_device = best_dev;
nm_device_activation_begin (data->active_device);
}
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
@@ -238,24 +230,10 @@ fprintf( stderr, "getting lists from NetworkManagerInfo\n");
else
NM_DEBUG_PRINT("nm_state_modification_monitor() could not get device list mutex\n");
}
else if (data->pending_device)
else if (data->active_device && nm_device_just_activated (data->active_device))
{
/* If there are pending device actions, don't switch to the device, but
* wait for the actions to complete.
*/
if (!nm_device_pending_action (data->pending_device))
{
/* Only move it from pending -> active if the activation was successfull,
* otherwise keep trying to activate it successfully.
*/
if (nm_device_activate (data->pending_device))
{
NM_DEBUG_PRINT_1 ("nm_state_modification_monitor() activated device %s\n", nm_device_get_iface (data->pending_device));
data->active_device = data->pending_device;
data->pending_device = NULL;
}
}
nm_dbus_signal_device_now_active (data->dbus_connection, data->active_device);
NM_DEBUG_PRINT_1 ("nm_state_modification_monitor() activated device %s\n", nm_device_get_iface (data->active_device));
}
return (TRUE);

View File

@@ -31,6 +31,8 @@
extern gboolean debug;
/*#define LOCKING_DEBUG /**/
/*
* nm_try_acquire_mutex
*
@@ -49,13 +51,12 @@ gboolean nm_try_acquire_mutex (GMutex *mutex, const char *func)
{
if (g_mutex_trylock (mutex))
{
/*
if (func)
NM_DEBUG_PRINT_1 ("MUTEX: %s got mutex\n", func);
*/
#ifdef LOCKING_DEBUG
if (func) NM_DEBUG_PRINT_2 ("MUTEX: %s got mutex 0x%X\n", func, mutex);
#endif
return (TRUE);
}
usleep (500);
g_usleep (G_USEC_PER_SEC / 2);
i++;
}
@@ -73,10 +74,10 @@ void nm_unlock_mutex (GMutex *mutex, const char *func)
{
g_return_if_fail (mutex != NULL);
/*
if (func)
NM_DEBUG_PRINT_1 ("MUTEX: %s released mutex\n", func);
*/
#ifdef LOCKING_DEBUG
if (func) NM_DEBUG_PRINT_2 ("MUTEX: %s released mutex 0x%X\n", func, mutex);
#endif
g_mutex_unlock (mutex);
}

View File

@@ -74,49 +74,6 @@ char *nm_wireless_128bit_key_from_passphrase (char *passphrase)
}
/*
* nm_wireless_is_ap_better
*
* 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_ap_better (NMAccessPointList *list, NMAccessPoint *ap, int *highest_priority)
{
NMAPListIter *iter;
NMAccessPoint *list_ap;
gboolean better = FALSE;
g_return_val_if_fail (list != NULL, FALSE);
g_return_val_if_fail (ap != NULL, FALSE);
g_return_val_if_fail (highest_priority != NULL, FALSE);
/* If the AP is marked as invalid, of course its not preferred */
if (nm_ap_get_invalid (ap))
return (FALSE);
if (!(iter = nm_ap_list_iter_new (list)))
return (FALSE);
while ((list_ap = nm_ap_list_iter_next (iter)))
{
/* 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 ( (nm_null_safe_strcmp (nm_ap_get_essid (list_ap), nm_ap_get_essid (ap)) == 0)
&& (nm_ap_get_priority (list_ap) < *highest_priority))
{
*highest_priority = nm_ap_get_priority (list_ap);
better = TRUE;
break;
}
}
nm_ap_list_iter_free (iter);
return (better);
}
/*
* nm_wireless_scan_monitor
*

View File

@@ -28,8 +28,6 @@
char * nm_wireless_128bit_key_from_passphrase (char *passphrase);
gboolean nm_wireless_is_ap_better (NMAccessPointList *list, NMAccessPoint *ap, int *highest_priority);
gboolean nm_wireless_scan_monitor (gpointer user_data);
#endif