NetworkManager r3246 - in branches/nm-0-6-olpc: . src



Author: dcbw
Date: Fri Jan 18 15:25:05 2008
New Revision: 3246
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3246&view=rev

Log:
2008-01-18  Dan Williams  <dcbw redhat com>

	* src/nm-device.c
	  src/nm-device.h
		- (nm_device_deactivate_quickly, nm_device_deactivate): both get a new
			argument 'force', which is used to indicate to subclasses that any
			persistent device state should be completely cleared, becasue the
			device is not intended to be usable after deactivation.  Should be
			set to TRUE for cases like disabling wireless and NM shutdown.

	* src/nm-dbus-nm.c
		- (nm_dbus_nm_set_active_device): fix for nm_device_deactivate() changes
		- (nm_dbus_nm_set_wireless_enabled): set TX power on when enabling,
			set TX power off when disabling.  
		- (nm_dbus_nm_sleep, nm_dbus_nm_wake): return success/fail value to
			callers over D-Bus

	* src/NetworkManagerPolicy.c
		- (nm_policy_activation_failed, nm_policy_deactivate,
		   nm_policy_device_change_check, nm_policy_device_activate): fix for
			nm_device_deactivate() changes

	* src/NetworkManager.c
		- (nm_create_device_and_add_to_list): fix for nm_device_deactivate()
			changes

	* src/nm-device-802-11-wireless.c
	  src/nm-device-802-11-wireless.h
		- (real_init): ensure wireless TX power is on
		- (nm_device_802_11_wireless_set_tx_power_on): new function; control
			wireless TX power

	* src/nm-device-802-11-mesh-olpc.c
		- (real_init): ensure wireless TX power is on
		- (real_deactivate_quickly): for forced deactivations (wireless disabled,
			etc) reset the mesh state machine so that upon enabling wireless,
			the mesh device starts at the beginning looking for a school server
			instead of where it stopped prior to disabling wireless



Modified:
   branches/nm-0-6-olpc/ChangeLog
   branches/nm-0-6-olpc/src/NetworkManager.c
   branches/nm-0-6-olpc/src/NetworkManagerPolicy.c
   branches/nm-0-6-olpc/src/nm-dbus-nm.c
   branches/nm-0-6-olpc/src/nm-device-802-11-mesh-olpc.c
   branches/nm-0-6-olpc/src/nm-device-802-11-wireless.c
   branches/nm-0-6-olpc/src/nm-device-802-11-wireless.h
   branches/nm-0-6-olpc/src/nm-device.c
   branches/nm-0-6-olpc/src/nm-device.h

Modified: branches/nm-0-6-olpc/src/NetworkManager.c
==============================================================================
--- branches/nm-0-6-olpc/src/NetworkManager.c	(original)
+++ branches/nm-0-6-olpc/src/NetworkManager.c	Fri Jan 18 15:25:05 2008
@@ -322,7 +322,7 @@
 			}
 
 			data->dev_list = g_slist_append (data->dev_list, dev);
-			nm_device_deactivate (dev);
+			nm_device_deactivate (dev, TRUE);
 
 			/* Notify other devices of the new device */
 			for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {

Modified: branches/nm-0-6-olpc/src/NetworkManagerPolicy.c
==============================================================================
--- branches/nm-0-6-olpc/src/NetworkManagerPolicy.c	(original)
+++ branches/nm-0-6-olpc/src/NetworkManagerPolicy.c	Fri Jan 18 15:25:05 2008
@@ -155,7 +155,7 @@
 	nm_info ("Activation (%s) failed.", nm_device_get_iface (dev));
 	nm_dbus_schedule_device_status_change_signal (data, dev, ap, DEVICE_ACTIVATION_FAILED);
 
-	nm_device_deactivate (dev);
+	nm_device_deactivate (dev, FALSE);
 	nm_schedule_state_change_signal_broadcast (data);
 	nm_policy_schedule_device_change_check (data);
 
@@ -205,7 +205,7 @@
 	data = nm_device_get_app_data (dev);
 	g_assert (data);
 
-	nm_device_deactivate (dev);
+	nm_device_deactivate (dev, FALSE);
 	g_object_unref (dev);
 
 	nm_schedule_state_change_signal_broadcast (data);
@@ -449,7 +449,7 @@
 	{
 		/* Terminate current connection */
 		nm_info ("SWITCH: terminating current connection '%s' because it's no longer valid.", nm_device_get_iface (old_dev));
-		nm_device_deactivate (old_dev);
+		nm_device_deactivate (old_dev, FALSE);
 		do_switch = TRUE;
 	}
 	else if (old_dev && new_dev)
@@ -596,7 +596,7 @@
 	g_assert (data);
 
 	if ((old_dev = nm_get_active_device (data)))
-		nm_device_deactivate (old_dev);
+		nm_device_deactivate (old_dev, FALSE);
 
 	new_dev = nm_act_request_get_dev (req);
 

Modified: branches/nm-0-6-olpc/src/nm-dbus-nm.c
==============================================================================
--- branches/nm-0-6-olpc/src/nm-dbus-nm.c	(original)
+++ branches/nm-0-6-olpc/src/nm-dbus-nm.c	Fri Jan 18 15:25:05 2008
@@ -351,7 +351,7 @@
 		         mesh_step == G_MAXUINT32 ? -1 : mesh_step);
 	}
 
-	nm_device_deactivate (dev);
+	nm_device_deactivate (dev, FALSE);
 	nm_schedule_state_change_signal_broadcast (data->data);
 	req = nm_act_request_new (data->data, dev, ap, TRUE);
 
@@ -539,40 +539,50 @@
 
 static DBusMessage *nm_dbus_nm_set_wireless_enabled (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
 {
-	gboolean	enabled = FALSE;
-	DBusError	err;
-	NMData	*app_data;
+	gboolean enabled = FALSE;
+	DBusError err;
+	NMData *app_data;
+	GSList *elt;
+	DBusMessage *reply;
+	gboolean success = FALSE;
 
 	g_return_val_if_fail (data && data->data && connection && message, NULL);
 
 	dbus_error_init (&err);
 	if (!dbus_message_get_args (message, &err, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID))
-		return NULL;
+		goto out;
 
 	app_data = data->data;
 	app_data->wireless_enabled = enabled;
 
-	if (!enabled)
-	{
-		GSList	*elt;
-
-		/* Physically down all wireless devices */
-		nm_lock_mutex (app_data->dev_list_mutex, __FUNCTION__);
-		for (elt = app_data->dev_list; elt; elt = g_slist_next (elt))
-		{
-			NMDevice	*dev = (NMDevice *)(elt->data);
-			if (nm_device_is_802_11_wireless (dev) || nm_device_is_802_11_mesh_olpc (dev))
-			{
-				nm_device_deactivate (dev);
+	nm_lock_mutex (app_data->dev_list_mutex, __FUNCTION__);
+	for (elt = app_data->dev_list; elt; elt = g_slist_next (elt)) {
+		NMDevice *dev = (NMDevice *)(elt->data);
+		if (   nm_device_is_802_11_wireless (dev)
+		    || nm_device_is_802_11_mesh_olpc (dev)) {
+
+			if (enabled) {
+				nm_info ("%s: (%s) setting TX power ON", __func__, nm_device_get_iface (dev));
+				nm_device_802_11_wireless_set_tx_power_on (dev, TRUE);
+			} else {
+				nm_device_deactivate (dev, TRUE);
 				nm_device_bring_down (dev);
+				nm_info ("%s: (%s) setting TX power OFF", __func__, nm_device_get_iface (dev));
+				nm_device_802_11_wireless_set_tx_power_on (dev, FALSE);
 			}
 		}
-		nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
 	}
+	nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
 
 	nm_policy_schedule_device_change_check (data->data);
+	success = TRUE;
+
+out:
+	reply = dbus_message_new_method_return (message);
+	if (reply)
+		dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &success, DBUS_TYPE_INVALID);
 
-	return NULL;
+	return reply;
 }
 
 static DBusMessage *nm_dbus_nm_get_wireless_enabled (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
@@ -590,6 +600,8 @@
 static DBusMessage *nm_dbus_nm_sleep (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
 {
 	NMData	*app_data;
+	DBusMessage *reply = NULL;
+	gboolean success = TRUE;
 
 	g_return_val_if_fail (data && data->data && connection && message, NULL);
 
@@ -633,7 +645,7 @@
 		{
 			NMDevice *dev = (NMDevice *)(elt->data);
 			nm_device_set_removed (dev, TRUE);
-			nm_device_deactivate_quickly (dev);
+			nm_device_deactivate_quickly (dev, TRUE);
 			nm_system_device_set_up_down (dev, FALSE);
 		}
 		nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
@@ -644,7 +656,11 @@
 		nm_unlock_mutex (app_data->dialup_list_mutex, __FUNCTION__);
 	}
 
-	return NULL;
+	reply = dbus_message_new_method_return (message);
+	if (reply)
+		dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &success, DBUS_TYPE_INVALID);
+
+	return reply;
 }
 
 static DBusMessage *nm_dbus_nm_wake (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
@@ -652,6 +668,8 @@
 	NMData	*app_data;
 	DBusMessageIter iter;
 	gboolean enable_networking = FALSE;
+	DBusMessage *reply = NULL;
+	gboolean success = TRUE;
 
 	g_return_val_if_fail (data && data->data && connection && message, NULL);
 
@@ -694,7 +712,11 @@
 		nm_policy_schedule_device_change_check (data->data);
 	}
 
-	return NULL;
+	reply = dbus_message_new_method_return (message);
+	if (reply)
+		dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &success, DBUS_TYPE_INVALID);
+
+	return reply;
 }
 
 static DBusMessage *nm_dbus_nm_get_state (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)

Modified: branches/nm-0-6-olpc/src/nm-device-802-11-mesh-olpc.c
==============================================================================
--- branches/nm-0-6-olpc/src/nm-device-802-11-mesh-olpc.c	(original)
+++ branches/nm-0-6-olpc/src/nm-device-802-11-mesh-olpc.c	Fri Jan 18 15:25:05 2008
@@ -64,7 +64,6 @@
 static void mpp_cleanup (NMDevice80211MeshOLPC *self);
 static gboolean aipd_exec (NMDevice80211MeshOLPC *self);
 static gboolean aipd_monitor_start (NMDevice80211MeshOLPC *self);
-static void real_deactivate_quickly (NMDevice *dev);
 static void assoc_timeout_cleanup (NMDevice80211MeshOLPC * self);
 static gboolean is_mpp_active (NMDevice80211MeshOLPC *self);
 static gboolean mpp_autoip_start (NMDevice80211MeshOLPC *self);
@@ -426,6 +425,8 @@
 
 	iface = nm_device_get_iface (dev);
 
+	nm_device_802_11_wireless_set_tx_power_on (dev, TRUE);
+
 	success = g_file_get_contents (MESH_STEP_FILE,
 	                               &contents,
 	                               NULL,
@@ -871,7 +872,7 @@
 }
 
 static void
-real_deactivate_quickly (NMDevice *dev)
+real_deactivate_quickly (NMDevice *dev, gboolean force)
 {
 	NMDevice80211MeshOLPC *	self = NM_DEVICE_802_11_MESH_OLPC (dev);
 	NMDHCPManager * dhcp_mgr = nm_dhcp_manager_get (NULL);
@@ -888,6 +889,19 @@
 
 	/* Remove any dhclient.conf file we may have created for mshX */
 	remove (ETC_DHCLIENT_CONF_PATH);
+
+	/* If this is a forced device deactivation, reset everything and start
+	 * the mesh discovery process all over.
+	 */
+	if (force) {
+		self->priv->step = self->priv->default_first_step;
+		if (self->priv->default_first_step == MESH_S4_P2P_MESH)
+			self->priv->channel = 1;
+		else
+			self->priv->channel = get_random_channel ();
+		self->priv->chans_tried = 0;
+		self->priv->channel_locked = FALSE;
+	}
 }
 
 
@@ -1734,7 +1748,7 @@
 		         nm_device_get_iface (NM_DEVICE (self)),
 		         self->priv->channel);
 		self->priv->channel = next_chan;
-		real_deactivate_quickly (NM_DEVICE (self));
+		real_deactivate_quickly (NM_DEVICE (self), FALSE);
 		nm_device_activate_schedule_stage2_device_config (req);
 	}
 }

Modified: branches/nm-0-6-olpc/src/nm-device-802-11-wireless.c
==============================================================================
--- branches/nm-0-6-olpc/src/nm-device-802-11-wireless.c	(original)
+++ branches/nm-0-6-olpc/src/nm-device-802-11-wireless.c	Fri Jan 18 15:25:05 2008
@@ -32,6 +32,7 @@
 
 #include "nm-device.h"
 #include "nm-device-802-11-wireless.h"
+#include "nm-device-802-11-mesh-olpc.h"
 #include "nm-device-private.h"
 #include "NetworkManagerAPList.h"
 #include "NetworkManagerDbus.h"
@@ -416,6 +417,8 @@
 	nm_device_802_11_wireless_set_scan_interval (app_data, self, NM_WIRELESS_SCAN_INTERVAL_ACTIVE);
 
 	nm_device_802_11_wireless_set_mode (self, IW_MODE_INFRA);
+nm_info ("%s: setting TX power on", nm_device_get_iface (dev));
+	nm_device_802_11_wireless_set_tx_power_on (dev, TRUE);
 
 	/* Non-scanning devices show the entire allowed AP list as their
 	 * available networks.
@@ -650,7 +653,7 @@
 }
 
 static void
-real_deactivate_quickly (NMDevice *dev)
+real_deactivate_quickly (NMDevice *dev, gboolean force)
 {
 	NMDevice80211Wireless *	self = NM_DEVICE_802_11_WIRELESS (dev);
 
@@ -1139,6 +1142,56 @@
 	return self->priv->scanning;
 }
 
+/*
+ * nm_device_set_tx_power_on
+ *
+ * Control TX power of the device
+ *
+ */
+gboolean
+nm_device_802_11_wireless_set_tx_power_on (NMDevice *self, gboolean on)
+{
+	NMSock * sk;
+	gboolean success = FALSE;
+	const char * iface;
+	struct iwreq wrq;
+
+	g_return_val_if_fail (self != NULL, FALSE);
+
+	if (!nm_device_is_802_11_wireless (self) && !nm_device_is_802_11_mesh_olpc (self))
+		return FALSE;
+
+	iface = nm_device_get_iface (NM_DEVICE (self));
+	sk = nm_dev_sock_open (NM_DEVICE (self), DEV_WIRELESS, __func__, NULL);
+	if (!sk) {
+		nm_warning ("%s: couldn't open socket to device", iface);
+		return FALSE;
+	}
+
+#ifdef IOCTL_DEBUG
+	nm_info ("%s: About to SET IWTXPOW.", iface);
+#endif
+
+	memset (&wrq, 0, sizeof (wrq));
+	wrq.u.txpower.fixed = on ? 0 : 1;
+	wrq.u.txpower.disabled = on ? 0 : 1;
+	wrq.u.txpower.flags = IW_TXPOW_DBM;
+
+	if (iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWTXPOW, &wrq) == 0) {
+		success = TRUE;
+		nm_info ("%s: set TX power %s", iface, on ? "on" : "off");
+	} else {
+		nm_warning ("%s: error setting TX power %s: (%d) %s",
+		            iface,
+		            on ? "on" : "off",
+		            errno,
+		            strerror (errno));
+	}
+	nm_dev_sock_close (sk);
+
+	return success;
+}
+
 
 /*
  * nm_device_get_mode

Modified: branches/nm-0-6-olpc/src/nm-device-802-11-wireless.h
==============================================================================
--- branches/nm-0-6-olpc/src/nm-device-802-11-wireless.h	(original)
+++ branches/nm-0-6-olpc/src/nm-device-802-11-wireless.h	Fri Jan 18 15:25:05 2008
@@ -128,6 +128,8 @@
 
 double nm_device_802_11_wireless_get_frequency (NMDevice80211Wireless *self);
 
+gboolean nm_device_802_11_wireless_set_tx_power_on (NMDevice *self, gboolean on);
+
 G_END_DECLS
 
 #endif	/* NM_DEVICE_802_11_WIRELESS_H */

Modified: branches/nm-0-6-olpc/src/nm-device.c
==============================================================================
--- branches/nm-0-6-olpc/src/nm-device.c	(original)
+++ branches/nm-0-6-olpc/src/nm-device.c	Fri Jan 18 15:25:05 2008
@@ -331,7 +331,7 @@
 {
 	g_return_if_fail (self != NULL);
 
-	nm_device_deactivate (self);
+	nm_device_deactivate (self, TRUE);
 	nm_device_bring_down (self);
 
 	if (self->priv->loop)
@@ -1493,7 +1493,7 @@
  *
  */
 gboolean
-nm_device_deactivate_quickly (NMDevice *self)
+nm_device_deactivate_quickly (NMDevice *self, gboolean force)
 {
 	NMData *		app_data;
 	NMActRequest *	act_request;
@@ -1528,7 +1528,7 @@
 
 	/* Call device type-specific deactivation */
 	if (NM_DEVICE_GET_CLASS (self)->deactivate_quickly)
-		NM_DEVICE_GET_CLASS (self)->deactivate_quickly (self);
+		NM_DEVICE_GET_CLASS (self)->deactivate_quickly (self, force);
 
 	g_signal_emit (G_OBJECT (self), nm_device_signals[DEACTIVATED], 0);
 
@@ -1542,7 +1542,7 @@
  *
  */
 void
-nm_device_deactivate (NMDevice *self)
+nm_device_deactivate (NMDevice *self, gboolean force)
 {
 	NMData *		app_data;
 	NMIP4Config *	config;
@@ -1552,7 +1552,7 @@
 
 	nm_info ("Deactivating device %s.", nm_device_get_iface (self));
 
-	nm_device_deactivate_quickly (self);
+	nm_device_deactivate_quickly (self, force);
 
 	app_data = self->priv->app_data;
 

Modified: branches/nm-0-6-olpc/src/nm-device.h
==============================================================================
--- branches/nm-0-6-olpc/src/nm-device.h	(original)
+++ branches/nm-0-6-olpc/src/nm-device.h	Fri Jan 18 15:25:05 2008
@@ -103,7 +103,7 @@
 												 NMIP4Config **config);
 
 	void			(* deactivate)			(NMDevice *self);
-	void			(* deactivate_quickly)	(NMDevice *self);
+	void			(* deactivate_quickly)	(NMDevice *self, gboolean force);
 
 	void			(* activation_failure_handler)	(NMDevice *self,
 											 struct NMActRequest *req);
@@ -204,8 +204,8 @@
 void			nm_device_activate_schedule_stage4_ip_config_get		(struct NMActRequest *req);
 void			nm_device_activate_schedule_stage4_ip_config_timeout	(struct NMActRequest *req);
 void			nm_device_activate_schedule_stage5_ip_config_commit		(struct NMActRequest *req);
-void			nm_device_deactivate		(NMDevice *dev);
-gboolean		nm_device_deactivate_quickly	(NMDevice *dev);
+void			nm_device_deactivate		(NMDevice *dev, gboolean force);
+gboolean		nm_device_deactivate_quickly	(NMDevice *dev, gboolean force);
 gboolean		nm_device_is_activating		(NMDevice *dev);
 void			nm_device_activation_cancel	(NMDevice *dev);
 gboolean		nm_device_activation_should_cancel (NMDevice *self);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]