2004-09-11 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessApplet.c panel-applet/NMWirelessAppletDbus.c - Start using NetworkDevice/WirelessNetwork structures in more places - Update for unified device/network forcing in NetworkManager * src/NetworkManager.c - some code consolidation * src/NetworkManagerDbus.c - (nm_dbus_nm_set_active_device): "setActiveDevice" now takes either one or two arguments: the first is the NM ID of the device to switch to, and the second (optional) argument is the ESSID of a wireless network to use as well. - Get rid of "setNetwork" method due to above change * src/NetworkManagerDevice.c - (nm_device_new): perform scan and update best AP on device creation - nm_device_activation_cancel_if_needed()->nm_device_activation_should_cancel() - nm_device_activation_signal_cancel()->nm_device_activation_cancel(), and spin waiting for cancellation to finish before returning * src/NetworkManagerPolicy.c - Changes here clarify the situations in which a device switch occurs, and make sure to keep using a forced device and network if the user gives us one - Remove old unused code git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@149 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
29
ChangeLog
29
ChangeLog
@@ -1,3 +1,32 @@
|
||||
2004-09-11 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* panel-applet/NMWirelessApplet.c
|
||||
panel-applet/NMWirelessAppletDbus.c
|
||||
- Start using NetworkDevice/WirelessNetwork structures in more places
|
||||
- Update for unified device/network forcing in NetworkManager
|
||||
|
||||
* src/NetworkManager.c
|
||||
- some code consolidation
|
||||
|
||||
* src/NetworkManagerDbus.c
|
||||
- (nm_dbus_nm_set_active_device): "setActiveDevice" now takes either one
|
||||
or two arguments: the first is the NM ID of the device to switch to,
|
||||
and the second (optional) argument is the ESSID of a wireless network
|
||||
to use as well.
|
||||
- Get rid of "setNetwork" method due to above change
|
||||
|
||||
* src/NetworkManagerDevice.c
|
||||
- (nm_device_new): perform scan and update best AP on device creation
|
||||
- nm_device_activation_cancel_if_needed()->nm_device_activation_should_cancel()
|
||||
- nm_device_activation_signal_cancel()->nm_device_activation_cancel(), and
|
||||
spin waiting for cancellation to finish before returning
|
||||
|
||||
* src/NetworkManagerPolicy.c
|
||||
- Changes here clarify the situations in which a device switch occurs, and
|
||||
make sure to keep using a forced device and network if the user gives
|
||||
us one
|
||||
- Remove old unused code
|
||||
|
||||
2004-09-11 Martin Willemoes Hansen <mwh@sysrq.dk>
|
||||
|
||||
* configure.in: Added Danish (da) to ALL_LINGUAS.
|
||||
|
@@ -366,15 +366,12 @@ static void nmwa_get_menu_pos (GtkMenu *menu, gint *x, gint *y, gboolean *push_i
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_handle_network_choice
|
||||
* nmwa_update_network_timestamp
|
||||
*
|
||||
* Update the timestamp of a network in GConf.
|
||||
*
|
||||
* Ask the user whether to add the network they have chosen to the trusted
|
||||
* networks list, and then stuff the network into gconf in either the trusted
|
||||
* or preferred networks list depending on their choice. This notifies
|
||||
* NetworkInfoManager that the networks list has changed, and it notifies
|
||||
* NetworkManager about those changes, triggering an AP switch.
|
||||
*/
|
||||
static void nmwa_handle_network_choice (NMWirelessApplet *applet, char *network)
|
||||
static void nmwa_update_network_timestamp (NMWirelessApplet *applet, const WirelessNetwork *network)
|
||||
{
|
||||
GConfEntry *gconf_entry;
|
||||
char *key;
|
||||
@@ -387,17 +384,83 @@ static void nmwa_handle_network_choice (NMWirelessApplet *applet, char *network)
|
||||
*/
|
||||
|
||||
/* Update timestamp on network */
|
||||
key = g_strdup_printf ("%s/%s/timestamp", NM_GCONF_WIRELESS_NETWORKS_PATH, network);
|
||||
key = g_strdup_printf ("%s/%s/timestamp", NM_GCONF_WIRELESS_NETWORKS_PATH, network->essid);
|
||||
gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL);
|
||||
g_free (key);
|
||||
|
||||
/* Force-set the essid too so that we have a semi-complete network entry */
|
||||
key = g_strdup_printf ("%s/%s/essid", NM_GCONF_WIRELESS_NETWORKS_PATH, network);
|
||||
gconf_client_set_string (applet->gconf_client, key, network, NULL);
|
||||
key = g_strdup_printf ("%s/%s/essid", NM_GCONF_WIRELESS_NETWORKS_PATH, network->essid);
|
||||
gconf_client_set_string (applet->gconf_client, key, network->essid, NULL);
|
||||
g_free (key);
|
||||
}
|
||||
|
||||
fprintf (stderr, "Forcing network '%s'\n", network);
|
||||
nmwa_dbus_set_network (applet->connection, network);
|
||||
|
||||
/*
|
||||
* nmwa_get_device_network_for_essid
|
||||
*
|
||||
* Searches the network list for a given network device and returns the
|
||||
* Wireless Network structure corresponding to it.
|
||||
*
|
||||
*/
|
||||
WirelessNetwork *nmwa_get_device_network_for_essid (NMWirelessApplet *applet, NetworkDevice *dev, const char *essid)
|
||||
{
|
||||
WirelessNetwork *found_network = NULL;
|
||||
GSList *element;
|
||||
|
||||
g_return_val_if_fail (applet != NULL, NULL);
|
||||
g_return_val_if_fail (dev != NULL, NULL);
|
||||
g_return_val_if_fail (essid != NULL, NULL);
|
||||
g_return_val_if_fail (strlen (essid), NULL);
|
||||
|
||||
g_mutex_lock (applet->data_mutex);
|
||||
element = dev->networks;
|
||||
while (element)
|
||||
{
|
||||
WirelessNetwork *network = (WirelessNetwork *)(element->data);
|
||||
if (network && (strcmp (network->essid, essid) == 0))
|
||||
{
|
||||
found_network = network;
|
||||
break;
|
||||
}
|
||||
element = g_slist_next (element);
|
||||
}
|
||||
g_mutex_unlock (applet->data_mutex);
|
||||
|
||||
return (found_network);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_get_device_for_nm_device
|
||||
*
|
||||
* Searches the device list for a device that matches the
|
||||
* NetworkManager ID given.
|
||||
*
|
||||
*/
|
||||
NetworkDevice *nmwa_get_device_for_nm_device (NMWirelessApplet *applet, const char *nm_dev)
|
||||
{
|
||||
NetworkDevice *found_dev = NULL;
|
||||
GSList *element;
|
||||
|
||||
g_return_val_if_fail (applet != NULL, NULL);
|
||||
g_return_val_if_fail (nm_dev != NULL, NULL);
|
||||
g_return_val_if_fail (strlen (nm_dev), NULL);
|
||||
|
||||
g_mutex_lock (applet->data_mutex);
|
||||
element = applet->devices;
|
||||
while (element)
|
||||
{
|
||||
NetworkDevice *dev = (NetworkDevice *)(element->data);
|
||||
if (dev && (strcmp (dev->nm_device, nm_dev) == 0))
|
||||
{
|
||||
found_dev = dev;
|
||||
break;
|
||||
}
|
||||
element = g_slist_next (element);
|
||||
}
|
||||
g_mutex_unlock (applet->data_mutex);
|
||||
|
||||
return (found_dev);
|
||||
}
|
||||
|
||||
|
||||
@@ -410,15 +473,26 @@ static void nmwa_handle_network_choice (NMWirelessApplet *applet, char *network)
|
||||
static void nmwa_menu_item_activate (GtkMenuItem *item, gpointer user_data)
|
||||
{
|
||||
NMWirelessApplet *applet = (NMWirelessApplet *)user_data;
|
||||
NetworkDevice *dev = NULL;
|
||||
WirelessNetwork *net = NULL;
|
||||
char *tag;
|
||||
|
||||
g_return_if_fail (item != NULL);
|
||||
g_return_if_fail (applet != NULL);
|
||||
|
||||
if ((tag = g_object_get_data (G_OBJECT (item), "network")))
|
||||
nmwa_handle_network_choice (applet, tag);
|
||||
{
|
||||
char *item_dev = g_object_get_data (G_OBJECT (item), "nm_device");
|
||||
|
||||
if (item_dev && (dev = nmwa_get_device_for_nm_device (applet, item_dev)))
|
||||
if ((net = nmwa_get_device_network_for_essid (applet, dev, tag)))
|
||||
nmwa_update_network_timestamp (applet, net);
|
||||
}
|
||||
else if ((tag = g_object_get_data (G_OBJECT (item), "device")))
|
||||
nmwa_dbus_set_device (applet->connection, tag);
|
||||
dev = nmwa_get_device_for_nm_device (applet, tag);
|
||||
|
||||
if (dev)
|
||||
nmwa_dbus_set_device (applet->connection, dev, net);
|
||||
}
|
||||
|
||||
|
||||
@@ -525,8 +599,8 @@ static void nmwa_menu_add_device_item (GtkWidget *menu, GdkPixbuf *icon, char *n
|
||||
* Add a wireless network menu item
|
||||
*
|
||||
*/
|
||||
static void nmwa_menu_add_network (GtkWidget *menu, GdkPixbuf *key, char *text, char *network, gboolean current,
|
||||
gboolean encrypted, guint8 quality, gpointer user_data)
|
||||
static void nmwa_menu_add_network (GtkWidget *menu, GdkPixbuf *key, NetworkDevice *dev,
|
||||
WirelessNetwork *net, gpointer user_data)
|
||||
{
|
||||
GtkWidget *menu_item;
|
||||
GtkWidget *label;
|
||||
@@ -535,8 +609,9 @@ static void nmwa_menu_add_network (GtkWidget *menu, GdkPixbuf *key, char *text,
|
||||
GtkWidget *progress;
|
||||
float percent;
|
||||
|
||||
g_return_if_fail (text != NULL);
|
||||
g_return_if_fail (menu != NULL);
|
||||
g_return_if_fail (net != NULL);
|
||||
g_return_if_fail (dev != NULL);
|
||||
|
||||
menu_item = gtk_menu_item_new ();
|
||||
hbox = gtk_hbox_new (FALSE, 5);
|
||||
@@ -549,10 +624,10 @@ static void nmwa_menu_add_network (GtkWidget *menu, GdkPixbuf *key, char *text,
|
||||
gtk_box_pack_start (GTK_BOX (hbox), foo, FALSE, FALSE, 2);
|
||||
gtk_widget_show (foo);
|
||||
|
||||
label = gtk_label_new (text);
|
||||
if (current)
|
||||
label = gtk_label_new (net->essid);
|
||||
if (net->active)
|
||||
{
|
||||
char *markup = g_strdup_printf ("<span weight=\"bold\">%s</span>", text);
|
||||
char *markup = g_strdup_printf ("<span weight=\"bold\">%s</span>", net->essid);
|
||||
gtk_label_set_markup (GTK_LABEL (label), markup);
|
||||
g_free (markup);
|
||||
}
|
||||
@@ -561,13 +636,13 @@ static void nmwa_menu_add_network (GtkWidget *menu, GdkPixbuf *key, char *text,
|
||||
gtk_widget_show (label);
|
||||
|
||||
progress = gtk_progress_bar_new ();
|
||||
percent = ((float)quality / (float)0x100);
|
||||
percent = ((float)net->quality / (float)0x100);
|
||||
percent = (percent < 0 ? 0 : (percent > 1.0 ? 1.0 : percent));
|
||||
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), percent);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), progress, TRUE, TRUE, 0);
|
||||
gtk_widget_show (progress);
|
||||
|
||||
if (encrypted)
|
||||
if (net->encrypted)
|
||||
{
|
||||
GtkWidget *image;
|
||||
|
||||
@@ -578,7 +653,8 @@ static void nmwa_menu_add_network (GtkWidget *menu, GdkPixbuf *key, char *text,
|
||||
}
|
||||
}
|
||||
|
||||
g_object_set_data (G_OBJECT (menu_item), "network", g_strdup (network));
|
||||
g_object_set_data (G_OBJECT (menu_item), "network", g_strdup (net->essid));
|
||||
g_object_set_data (G_OBJECT (menu_item), "nm_device", g_strdup (dev->nm_device));
|
||||
g_signal_connect(G_OBJECT (menu_item), "activate", G_CALLBACK(nmwa_menu_item_activate), user_data);
|
||||
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
|
||||
@@ -612,10 +688,7 @@ static void nmwa_menu_device_add_networks (GtkWidget *menu, NetworkDevice *dev,
|
||||
WirelessNetwork *net = (WirelessNetwork *)(element->data);
|
||||
|
||||
if (net)
|
||||
{
|
||||
nmwa_menu_add_network (menu, applet->key_pixbuf, net->essid,
|
||||
net->essid, net->active, net->encrypted, net->quality, applet);
|
||||
}
|
||||
nmwa_menu_add_network (menu, applet->key_pixbuf, dev, net, applet);
|
||||
|
||||
element = g_slist_next (element);
|
||||
}
|
||||
@@ -685,6 +758,12 @@ static void nmwa_menu_item_data_free (GtkWidget *menu_item, gpointer data)
|
||||
g_free (tag);
|
||||
}
|
||||
|
||||
if ((tag = g_object_get_data (G_OBJECT (menu_item), "nm_device")))
|
||||
{
|
||||
g_object_set_data (G_OBJECT (menu_item), "nm_device", NULL);
|
||||
g_free (tag);
|
||||
}
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(menu), menu_item);
|
||||
}
|
||||
|
||||
|
@@ -123,4 +123,7 @@ typedef struct
|
||||
GSList *networks;
|
||||
} NetworkDevice;
|
||||
|
||||
|
||||
NetworkDevice *nmwa_get_device_for_nm_device (NMWirelessApplet *applet, const char *nm_dev);
|
||||
|
||||
#endif
|
||||
|
@@ -711,47 +711,33 @@ static char *nmwa_dbus_get_hal_device_info (DBusConnection *connection, const ch
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_set_network
|
||||
*
|
||||
* Tell NetworkManager to use a specific network that the user picked.
|
||||
*
|
||||
*/
|
||||
void nmwa_dbus_set_network (DBusConnection *connection, char *network)
|
||||
{
|
||||
DBusMessage *message;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (network != NULL);
|
||||
|
||||
message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setNetwork");
|
||||
if (message)
|
||||
{
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INVALID);
|
||||
dbus_connection_send (connection, message, NULL);
|
||||
}
|
||||
else
|
||||
fprintf (stderr, "nm_dbus_set_network(): Couldn't allocate the dbus message\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_set_device
|
||||
*
|
||||
* Tell NetworkManager to use a specific network device that the user picked.
|
||||
* Tell NetworkManager to use a specific network device that the user picked, and
|
||||
* possibly a specific wireless network too.
|
||||
*
|
||||
*/
|
||||
void nmwa_dbus_set_device (DBusConnection *connection, char *device)
|
||||
void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev, const WirelessNetwork *network)
|
||||
{
|
||||
DBusMessage *message;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (device != NULL);
|
||||
g_return_if_fail (dev != NULL);
|
||||
|
||||
message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setActiveDevice");
|
||||
if (message)
|
||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setActiveDevice")))
|
||||
{
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, device, DBUS_TYPE_INVALID);
|
||||
if ((dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) && network && network->essid)
|
||||
{
|
||||
fprintf( stderr, "Forcing device '%s' and network '%s'\n", dev->nm_device, network->essid);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev->nm_device,
|
||||
DBUS_TYPE_STRING, network->essid, DBUS_TYPE_INVALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf( stderr, "Forcing device '%s'\n", dev->nm_device);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev->nm_device, DBUS_TYPE_INVALID);
|
||||
}
|
||||
dbus_connection_send (connection, message, NULL);
|
||||
}
|
||||
else
|
||||
@@ -1034,40 +1020,6 @@ static void nmwa_dbus_update_devices (NMWirelessApplet *applet)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_get_device_for_nm_device
|
||||
*
|
||||
* Searches the device list for a device that matches the
|
||||
* NetworkManager ID given.
|
||||
*
|
||||
*/
|
||||
static NetworkDevice *nmwa_dbus_get_device_for_nm_device (NMWirelessApplet *applet, const char *nm_dev)
|
||||
{
|
||||
NetworkDevice *found_dev = NULL;
|
||||
GSList *element;
|
||||
|
||||
g_return_val_if_fail (applet != NULL, NULL);
|
||||
g_return_val_if_fail (nm_dev != NULL, NULL);
|
||||
g_return_val_if_fail (strlen (nm_dev), NULL);
|
||||
|
||||
g_mutex_lock (applet->data_mutex);
|
||||
element = applet->devices;
|
||||
while (element)
|
||||
{
|
||||
NetworkDevice *dev = (NetworkDevice *)(element->data);
|
||||
if (dev && (strcmp (dev->nm_device, nm_dev) == 0))
|
||||
{
|
||||
found_dev = dev;
|
||||
break;
|
||||
}
|
||||
element = g_slist_next (element);
|
||||
}
|
||||
g_mutex_unlock (applet->data_mutex);
|
||||
|
||||
return (found_dev);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_filter
|
||||
*
|
||||
@@ -1114,7 +1066,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
|
||||
{
|
||||
NetworkDevice *dev;
|
||||
|
||||
if ((dev = nmwa_dbus_get_device_for_nm_device (applet, nm_device)))
|
||||
if ((dev = nmwa_get_device_for_nm_device (applet, nm_device)))
|
||||
{
|
||||
g_mutex_lock (applet->data_mutex);
|
||||
nmwa_dbus_update_device_wireless_networks (dev, applet);
|
||||
|
@@ -44,8 +44,7 @@ enum
|
||||
|
||||
gpointer nmwa_dbus_worker (gpointer user_data);
|
||||
|
||||
void nmwa_dbus_set_network (DBusConnection *connection, char *network);
|
||||
|
||||
void nmwa_dbus_set_device (DBusConnection *connection, char *device);
|
||||
void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev,
|
||||
const WirelessNetwork *network);
|
||||
|
||||
#endif
|
||||
|
@@ -176,7 +176,7 @@ void nm_remove_device_from_list (NMData *data, const char *udi)
|
||||
data->user_device = NULL;
|
||||
}
|
||||
|
||||
nm_device_activation_signal_cancel (dev);
|
||||
nm_device_activation_cancel (dev);
|
||||
nm_device_unref (dev);
|
||||
|
||||
/* Remove the device entry from the device list and free its data */
|
||||
@@ -353,36 +353,20 @@ gboolean nm_link_state_monitor (gpointer user_data)
|
||||
|
||||
if (dev)
|
||||
{
|
||||
/* Wired cards are always up and active, because otherwise we cannot do
|
||||
* link detection on them. A wireless card is only up if it's the active
|
||||
* device, since we only do scanning and link detection on the active device
|
||||
* anyway.
|
||||
*/
|
||||
switch (nm_device_get_type (dev))
|
||||
{
|
||||
case DEVICE_TYPE_WIRELESS_ETHERNET:
|
||||
if (!nm_device_is_up (dev))
|
||||
nm_device_bring_up (dev);
|
||||
nm_device_update_link_active (dev, FALSE);
|
||||
if ((dev == data->active_device) && !nm_device_get_link_active (dev))
|
||||
|
||||
if (dev == data->active_device)
|
||||
{
|
||||
if (nm_device_is_wireless (dev) && !nm_device_get_link_active (dev))
|
||||
{
|
||||
/* If we loose a link to the access point, then
|
||||
* look for another access point to connect to.
|
||||
*/
|
||||
nm_device_update_best_ap (dev);
|
||||
}
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_WIRED_ETHERNET:
|
||||
if (!nm_device_is_up (dev))
|
||||
nm_device_bring_up (dev);
|
||||
nm_device_update_link_active (dev, FALSE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (dev == data->active_device)
|
||||
{
|
||||
/* Check if the device's IP address has changed
|
||||
* (ie dhcp lease renew/address change)
|
||||
*/
|
||||
|
@@ -207,19 +207,38 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
|
||||
NMDevice *dev = NULL;
|
||||
DBusMessage *reply_message = NULL;
|
||||
char *dev_path = NULL;
|
||||
char *network = NULL;
|
||||
DBusError error;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
g_return_val_if_fail (message != NULL, NULL);
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
|
||||
/* Try to grab both device _and_ network first, and if that fails then just the device. */
|
||||
dbus_error_init (&error);
|
||||
if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev_path,
|
||||
DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID))
|
||||
{
|
||||
network = NULL;
|
||||
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
|
||||
/* So if that failed, try getting just the device */
|
||||
dbus_error_init (&error);
|
||||
if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev_path, DBUS_TYPE_INVALID))
|
||||
{
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
|
||||
reply_message = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments",
|
||||
"NetworkManager::setActiveDevice called with invalid arguments.");
|
||||
return (reply_message);
|
||||
} else fprintf (stderr, "FORCE: device '%s'\n", dev_path);
|
||||
}
|
||||
else fprintf (stderr, "FORCE: device '%s', network '%s'\n", dev_path, network);
|
||||
|
||||
/* So by now we have a valid device and possibly a network as well */
|
||||
|
||||
dev = nm_dbus_get_device_from_object_path (data, dev_path);
|
||||
dbus_free (dev_path);
|
||||
@@ -242,6 +261,21 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
|
||||
nm_device_ref (dev);
|
||||
data->user_device = dev;
|
||||
|
||||
/* If the user specificed a wireless network too, force that as well */
|
||||
if (network && nm_device_is_wireless (dev))
|
||||
{
|
||||
NMAccessPoint *ap;
|
||||
|
||||
if ((ap = nm_ap_list_get_ap_by_essid (nm_device_ap_list_get (dev), network)))
|
||||
{
|
||||
syslog (LOG_DEBUG, "Forcing AP '%s'", nm_ap_get_essid (ap));
|
||||
nm_device_set_best_ap (dev, ap);
|
||||
nm_device_freeze_best_ap (dev);
|
||||
nm_device_activation_cancel (dev);
|
||||
}
|
||||
}
|
||||
dbus_free (network);
|
||||
|
||||
nm_unlock_mutex (data->user_device_mutex, __FUNCTION__);
|
||||
nm_data_mark_state_changed (data);
|
||||
}
|
||||
@@ -1182,36 +1216,6 @@ static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection,
|
||||
nm_dbus_nm_set_active_device (connection, message, data);
|
||||
else if (strcmp ("setKeyForNetwork", method) == 0)
|
||||
nm_dbus_set_user_key_for_network (connection, message, data);
|
||||
else if (strcmp ("setNetwork", method) == 0)
|
||||
{
|
||||
if (data->active_device && nm_device_is_wireless (data->active_device))
|
||||
{
|
||||
char *network;
|
||||
DBusError error;
|
||||
|
||||
dbus_error_init (&error);
|
||||
if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID))
|
||||
{
|
||||
NMAccessPoint *ap;
|
||||
|
||||
if ((ap = nm_ap_list_get_ap_by_essid (nm_device_ap_list_get (data->active_device), network)))
|
||||
{
|
||||
syslog (LOG_DEBUG, "Forcing AP '%s'", nm_ap_get_essid (ap));
|
||||
nm_device_set_best_ap (data->active_device, ap);
|
||||
nm_device_freeze_best_ap (data->active_device);
|
||||
if (nm_device_activating (data->active_device))
|
||||
nm_device_activation_signal_cancel (data->active_device);
|
||||
nm_data_mark_state_changed (data);
|
||||
}
|
||||
dbus_free (network);
|
||||
}
|
||||
}
|
||||
else
|
||||
reply_message = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "BadDevice",
|
||||
"A network can only be set when a wireless device is active.");
|
||||
|
||||
handled = TRUE;
|
||||
}
|
||||
else if (strcmp ("status", method) == 0)
|
||||
{
|
||||
if ((reply_message = dbus_message_new_method_return (message)))
|
||||
|
@@ -320,6 +320,10 @@ NMDevice *nm_device_new (const char *iface, gboolean test_dev, NMDeviceType test
|
||||
return (NULL);
|
||||
}
|
||||
dev->options.wireless.supports_wireless_scan = nm_device_supports_wireless_scan (dev);
|
||||
|
||||
/* Perform an initial wireless scan */
|
||||
nm_device_do_wireless_scan (dev);
|
||||
nm_device_update_best_ap (dev);
|
||||
}
|
||||
|
||||
/* Grab IP config data for this device from the system configuration files */
|
||||
@@ -999,13 +1003,13 @@ gboolean nm_device_activation_begin (NMDevice *dev)
|
||||
|
||||
|
||||
/*
|
||||
* nm_device_activation_cancel_if_needed
|
||||
* nm_device_activation_should_cancel
|
||||
*
|
||||
* Check whether we should stop activation, and if so clean up flags
|
||||
* and other random things.
|
||||
*
|
||||
*/
|
||||
gboolean nm_device_activation_cancel_if_needed (NMDevice *dev)
|
||||
gboolean nm_device_activation_should_cancel (NMDevice *dev)
|
||||
{
|
||||
g_return_val_if_fail (dev != NULL, TRUE);
|
||||
|
||||
@@ -1168,7 +1172,7 @@ void nm_device_activate_wireless_wait_for_link (NMDevice *dev)
|
||||
}
|
||||
|
||||
/* If we were told to quit activation, stop the thread and return */
|
||||
if (nm_device_activation_cancel_if_needed (dev))
|
||||
if (nm_device_activation_should_cancel (dev))
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1182,7 +1186,7 @@ void nm_device_activate_wireless_wait_for_link (NMDevice *dev)
|
||||
}
|
||||
|
||||
/* If we were told to quit activation, stop the thread and return */
|
||||
if (nm_device_activation_cancel_if_needed (dev))
|
||||
if (nm_device_activation_should_cancel (dev))
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1249,7 +1253,7 @@ static gpointer nm_device_activation_worker (gpointer user_data)
|
||||
nm_device_activate_wireless_wait_for_link (dev);
|
||||
|
||||
/* If we were told to quit activation, stop the thread and return */
|
||||
if (nm_device_activation_cancel_if_needed (dev))
|
||||
if (nm_device_activation_should_cancel (dev))
|
||||
return (NULL);
|
||||
|
||||
/* Since we've got a link, the encryption method must be good */
|
||||
@@ -1283,7 +1287,7 @@ static gpointer nm_device_activation_worker (gpointer user_data)
|
||||
sethostname (hostname, strlen (hostname));
|
||||
|
||||
/* If we were told to quit activation, stop the thread and return */
|
||||
if (nm_device_activation_cancel_if_needed (dev))
|
||||
if (nm_device_activation_should_cancel (dev))
|
||||
return (NULL);
|
||||
|
||||
/* Make system aware of any new DNS settings from resolv.conf */
|
||||
@@ -1291,7 +1295,7 @@ static gpointer nm_device_activation_worker (gpointer user_data)
|
||||
}
|
||||
|
||||
/* If we were told to quit activation, stop the thread and return */
|
||||
if (nm_device_activation_cancel_if_needed (dev))
|
||||
if (nm_device_activation_should_cancel (dev))
|
||||
return (NULL);
|
||||
|
||||
dev->just_activated = TRUE;
|
||||
@@ -1340,20 +1344,27 @@ gboolean nm_device_activating (NMDevice *dev)
|
||||
|
||||
|
||||
/*
|
||||
* nm_device_activation_signal_cancel
|
||||
* nm_device_activation_cancel
|
||||
*
|
||||
* Signal activation worker that it should stop and die.
|
||||
*
|
||||
*/
|
||||
void nm_device_activation_signal_cancel (NMDevice *dev)
|
||||
void nm_device_activation_cancel (NMDevice *dev)
|
||||
{
|
||||
g_return_if_fail (dev != NULL);
|
||||
|
||||
if (dev->activating)
|
||||
if (nm_device_activating (dev))
|
||||
{
|
||||
syslog (LOG_DEBUG, "nm_device_activation_signal_cancel(%s): cancelling", nm_device_get_iface (dev));
|
||||
syslog (LOG_DEBUG, "nm_device_activation_cancel(%s): cancelling...", nm_device_get_iface (dev));
|
||||
dev->quit_activation = TRUE;
|
||||
nm_system_kill_all_dhcp_daemons (); /* dhcp daemons will block, so have to kill them to return control */
|
||||
|
||||
/* Spin until cancelled. Possible race conditions or deadlocks here.
|
||||
* The other problem with waiting here is that we hold up dbus traffic
|
||||
* that we should respond to.
|
||||
*/
|
||||
while (nm_device_activating (dev))
|
||||
g_usleep (G_USEC_PER_SEC / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1369,7 +1380,7 @@ 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);
|
||||
|
||||
nm_device_activation_signal_cancel (dev);
|
||||
nm_device_activation_cancel (dev);
|
||||
|
||||
/* Take out any entries in the routing table and any IP address the old device had. */
|
||||
nm_system_device_flush_routes (dev);
|
||||
|
@@ -75,7 +75,7 @@ char * nm_device_get_path_for_ap (NMDevice *dev, NMAccessPoint *ap);
|
||||
void nm_device_set_enc_key (NMDevice *dev, const char *key);
|
||||
|
||||
gboolean nm_device_activation_begin (NMDevice *dev);
|
||||
void nm_device_activation_signal_cancel (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);
|
||||
|
@@ -149,7 +149,7 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data)
|
||||
* under certain conditions.
|
||||
*
|
||||
*/
|
||||
static NMDevice * nm_policy_get_best_device (NMData *data)
|
||||
static NMDevice * nm_policy_get_best_device (NMData *data, gboolean *should_lock_on_activate)
|
||||
{
|
||||
NMDevice *best_dev = NULL;
|
||||
|
||||
@@ -159,6 +159,9 @@ static NMDevice * nm_policy_get_best_device (NMData *data)
|
||||
if (!data->active_device)
|
||||
data->active_device_locked = FALSE;
|
||||
|
||||
if (should_lock_on_activate)
|
||||
*should_lock_on_activate = FALSE;
|
||||
|
||||
/* If the user told us to switch to a particular device, do it now */
|
||||
if (nm_try_acquire_mutex (data->user_device_mutex, __FUNCTION__))
|
||||
{
|
||||
@@ -168,6 +171,7 @@ static NMDevice * nm_policy_get_best_device (NMData *data)
|
||||
|
||||
nm_device_unref (data->user_device);
|
||||
data->user_device = NULL;
|
||||
*should_lock_on_activate = TRUE;
|
||||
}
|
||||
nm_unlock_mutex (data->user_device_mutex, __FUNCTION__);
|
||||
}
|
||||
@@ -188,7 +192,8 @@ static NMDevice * nm_policy_get_best_device (NMData *data)
|
||||
break;
|
||||
|
||||
/* For wireless devices, we only "unlock" them if they are
|
||||
* removed from the system.
|
||||
* removed from the system or a different device is "locked"
|
||||
* by the user.
|
||||
*/
|
||||
case (DEVICE_TYPE_WIRELESS_ETHERNET):
|
||||
best_dev = data->active_device;
|
||||
@@ -199,18 +204,6 @@ static NMDevice * nm_policy_get_best_device (NMData *data)
|
||||
}
|
||||
}
|
||||
|
||||
/* Or, if the current active device is wireless and its "best" access
|
||||
* point is locked, use that device still. This happens when the user
|
||||
* forces a specific wireless network choice. The "best" ap will have
|
||||
* already been set and locked by the dbus message handler, so we just
|
||||
* need to test for a locked "best" ap.
|
||||
*/
|
||||
if (data->active_device && nm_device_is_wireless (data->active_device))
|
||||
{
|
||||
if (nm_device_get_best_ap_frozen (data->active_device))
|
||||
best_dev = data->active_device;
|
||||
}
|
||||
|
||||
/* Fall back to automatic device picking */
|
||||
if (!best_dev)
|
||||
{
|
||||
@@ -269,19 +262,34 @@ gboolean nm_state_modification_monitor (gpointer user_data)
|
||||
{
|
||||
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||
{
|
||||
gboolean should_lock_on_activate = FALSE;
|
||||
gboolean do_switch = FALSE;
|
||||
NMDevice *best_dev = NULL;
|
||||
|
||||
if ((best_dev = nm_policy_get_best_device (data)))
|
||||
if ((best_dev = nm_policy_get_best_device (data, &should_lock_on_activate)))
|
||||
nm_device_ref (best_dev);
|
||||
|
||||
/* Only do a switch when:
|
||||
* 1) the best_dev is different from data->active_device, OR
|
||||
* 2) best_dev is wireless and its access point is not the "best" ap, OR
|
||||
* 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) && !nm_device_activating (best_dev)
|
||||
&& (nm_device_need_ap_switch (best_dev) || (nm_device_get_ip4_address (best_dev) == 0))))
|
||||
/* Figure out if we need to change devices or wireless networks */
|
||||
if (best_dev != data->active_device)
|
||||
{
|
||||
syslog (LOG_INFO, " SWITCH: best device changed");
|
||||
do_switch = TRUE; /* Device changed */
|
||||
}
|
||||
else if (best_dev && nm_device_is_wireless (best_dev))
|
||||
{
|
||||
if (!nm_device_activating (best_dev) && nm_device_need_ap_switch (best_dev))
|
||||
{
|
||||
syslog (LOG_INFO, " SWITCH: need to associate with new access point");
|
||||
do_switch = TRUE;
|
||||
}
|
||||
else if (!nm_device_activating (best_dev) && (nm_device_get_ip4_address (best_dev) == 0))
|
||||
{
|
||||
syslog (LOG_INFO, " SWITCH: need to get an IP address");
|
||||
do_switch = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (do_switch)
|
||||
{
|
||||
/* Deactivate the old device */
|
||||
if (data->active_device)
|
||||
@@ -298,16 +306,17 @@ gboolean nm_state_modification_monitor (gpointer user_data)
|
||||
nm_device_ref (best_dev);
|
||||
data->active_device = best_dev;
|
||||
nm_device_activation_begin (data->active_device);
|
||||
|
||||
/* nm_policy_get_best_device() signals us that the user forced
|
||||
* a device upon us and that we should lock the active device.
|
||||
*/
|
||||
if (should_lock_on_activate)
|
||||
data->active_device_locked = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (best_dev)
|
||||
{
|
||||
if (nm_device_activating (best_dev))
|
||||
nm_data_mark_state_changed (data);
|
||||
|
||||
nm_device_unref (best_dev);
|
||||
}
|
||||
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
}
|
||||
@@ -322,149 +331,3 @@ gboolean nm_state_modification_monitor (gpointer user_data)
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* nm_policy_allowed_ap_refresh_worker
|
||||
*
|
||||
* Worker thread function to periodically refresh the allowed
|
||||
* access point list with updated data.
|
||||
*
|
||||
*/
|
||||
gpointer nm_policy_allowed_ap_refresh_worker (gpointer user_data)
|
||||
{
|
||||
NMData *data = (NMData *)(user_data);
|
||||
struct timeval timeout;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
|
||||
/* Simply loop and every 20s update the available allowed ap data */
|
||||
while (!allowed_ap_worker_exit)
|
||||
{
|
||||
int err;
|
||||
|
||||
timeout.tv_sec = 20;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
/* Wait, but don't execute the update if select () returned an error,
|
||||
* since it may have immediately returned, so that we don't hammer
|
||||
* GConf (or the hard drive).
|
||||
*/
|
||||
err = select (0, NULL, NULL, NULL, &timeout);
|
||||
if (err >= 0)
|
||||
nm_policy_update_allowed_access_points (data);
|
||||
}
|
||||
|
||||
g_thread_exit (0);
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_policy_update_allowed_access_points
|
||||
*
|
||||
* Grabs a list of allowed access points from the user's preferences
|
||||
*
|
||||
*/
|
||||
void nm_policy_update_allowed_access_points (NMData *data)
|
||||
{
|
||||
#define NM_ALLOWED_AP_FILE "/etc/sysconfig/networking/allowed_access_points"
|
||||
|
||||
FILE *ap_file;
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
if (nm_try_acquire_mutex (data->allowed_ap_list_mutex, __FUNCTION__))
|
||||
{
|
||||
ap_file = fopen (NM_ALLOWED_AP_FILE, "r");
|
||||
if (ap_file)
|
||||
{
|
||||
gchar line[ 500 ];
|
||||
gchar prio[ 20 ];
|
||||
gchar essid[ 50 ];
|
||||
gchar wep_key[ 50 ];
|
||||
|
||||
/* Free the old list of allowed access points */
|
||||
// nm_data_allowed_ap_list_free (data);
|
||||
|
||||
while (fgets (line, 499, ap_file))
|
||||
{
|
||||
guint len = strnlen (line, 499);
|
||||
gchar *p = &line[0];
|
||||
gchar *end = strchr (line, '\n');
|
||||
guint op = 0;
|
||||
|
||||
strcpy (prio, "\0");
|
||||
strcpy (essid, "\0");
|
||||
strcpy (wep_key, "\0");
|
||||
|
||||
if (end)
|
||||
*end = '\0';
|
||||
else
|
||||
end = p + len - 1;
|
||||
|
||||
while ((end-p > 0) && (*p=='\t'))
|
||||
p++;
|
||||
|
||||
while (end-p > 0)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case 0:
|
||||
strncat (prio, p, 1);
|
||||
break;
|
||||
case 1:
|
||||
strncat (essid, p, 1);
|
||||
break;
|
||||
case 2:
|
||||
strncat (wep_key, p, 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
|
||||
if ((end-p > 0) && (*p=='\t'))
|
||||
{
|
||||
op++;
|
||||
while ((end-p > 0) && (*p=='\t'))
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new entry for this essid */
|
||||
if (strlen (essid) > 0)
|
||||
{
|
||||
NMAccessPoint *ap;
|
||||
guint prio_num = atoi (prio);
|
||||
|
||||
if (prio_num < 1)
|
||||
prio_num = NM_AP_PRIORITY_WORST;
|
||||
else if (prio_num > NM_AP_PRIORITY_WORST)
|
||||
prio_num = NM_AP_PRIORITY_WORST;
|
||||
|
||||
ap = nm_ap_new ();
|
||||
nm_ap_set_priority (ap, prio_num);
|
||||
nm_ap_set_essid (ap, essid);
|
||||
if (strlen (wep_key) > 0)
|
||||
nm_ap_set_wep_key (ap, wep_key);
|
||||
|
||||
data->allowed_ap_list = g_slist_append (data->allowed_ap_list, ap);
|
||||
/*
|
||||
syslog( LOG_DEBUG, "FOUND: allowed ap, prio=%d essid=%s wep_key=%s", prio_num, essid, wep_key );
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
fclose (ap_file);
|
||||
}
|
||||
else
|
||||
syslog( LOG_WARNING, "nm_policy_update_allowed_access_points() could not open allowed ap list file %s. errno %d", NM_ALLOWED_AP_FILE, errno );
|
||||
|
||||
nm_unlock_mutex (data->allowed_ap_list_mutex, __FUNCTION__);
|
||||
}
|
||||
else
|
||||
syslog( LOG_ERR, "nm_policy_update_allowed_access_points() could not lock allowed ap list mutex" );
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user