aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/networkmanager/files/avoid_frequent_scan.patch
blob: 43f84f7674203fbb553e6f5a8d3c7643cf5a9462 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
Index: NetworkManager-0.6.6/src/nm-device-802-11-wireless.c
===================================================================
--- NetworkManager-0.6.6.orig/src/nm-device-802-11-wireless.c	2008-09-05 15:01:32.000000000 -0300
+++ NetworkManager-0.6.6/src/nm-device-802-11-wireless.c	2008-09-08 11:37:23.000000000 -0300
@@ -624,9 +624,12 @@
 	NMDevice80211Wireless *	self = NM_DEVICE_802_11_WIRELESS (dev);
 	GSource *				source;
 	guint				source_id;
+    NMData *                app_data;
+
+    app_data = nm_device_get_app_data (NM_DEVICE (self));
 
 	/* Start the scanning timeout for devices that can do scanning */
-	if (nm_device_get_capabilities (dev) & NM_DEVICE_CAP_WIRELESS_SCAN) {
+	if (!app_data->no_scan && nm_device_get_capabilities (dev) & NM_DEVICE_CAP_WIRELESS_SCAN) {
 		/* Stupid orinoco has problems scanning immediately after being up,
 		 * so wait a bit before triggering a scan.
 		 */
@@ -1063,9 +1066,14 @@
                                              NMWirelessScanInterval interval)
 {
 	guint8 seconds = nm_wireless_scan_interval_to_seconds (interval);
+	NMData *app_data;
 
 	g_return_if_fail (self != NULL);
 
+	app_data = nm_device_get_app_data (NM_DEVICE (self));
+	if (app_data->no_scan)
+		return;
+
 	self->priv->scan_interval = seconds;	
 
 	if (interval == NM_WIRELESS_SCAN_INTERVAL_ACTIVE && !self->priv->scanning) {
@@ -1974,9 +1982,13 @@
 scan_results_timeout (NMDevice80211Wireless *self)
 {
 	GTimeVal cur_time;
+    NMData * app_data;
 
 	g_return_val_if_fail (self != NULL, FALSE);
 
+    app_data = nm_device_get_app_data (NM_DEVICE (self));
+    g_assert (app_data);
+
 	request_and_convert_scan_results (self);
 
 	self->priv->scanning = FALSE;
@@ -1984,11 +1996,39 @@
 	g_get_current_time (&cur_time);
 	self->priv->last_scan = cur_time.tv_sec;
 
-	/* After the first successful scan back down to the ACTIVE scan interval */
-	if (self->priv->scan_interval == nm_wireless_scan_interval_to_seconds (NM_WIRELESS_SCAN_INTERVAL_INIT))
-		nm_device_802_11_wireless_set_scan_interval (self, NM_WIRELESS_SCAN_INTERVAL_ACTIVE);
-	else
-		schedule_scan (self, 0);
+    if (!app_data->no_scan)
+    {
+	    /* After the first successful scan back down to the ACTIVE scan interval */
+	    if (self->priv->scan_interval == nm_wireless_scan_interval_to_seconds (NM_WIRELESS_SCAN_INTERVAL_INIT))
+		    nm_device_802_11_wireless_set_scan_interval (self, NM_WIRELESS_SCAN_INTERVAL_ACTIVE);
+	    else
+		    schedule_scan (self, 0);
+    }
+    else
+    {
+        /* If we're in "no scan" mode, lets always signalize that we've performed a scan */
+        DBusMessage *message;
+        char        *dev_path = NULL;
+
+        if (!(dev_path = nm_dbus_get_object_path_for_device (NM_DEVICE (self))))
+            goto out;
+
+        if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "ScanPerformed")))
+        {
+            nm_warning ("scan_results_timeout(): Not enough memory for new dbus message!");
+            goto out;
+        }
+
+        dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INVALID);
+
+        if (!dbus_connection_send (app_data->dbus_connection, message, NULL))
+            nm_warning ("scan_results_timeout(): Could not raise the ScanPerformed signal!");
+
+        dbus_message_unref (message);
+
+out:
+        g_free (dev_path);
+    }
 
 	return FALSE;
 }
@@ -2134,7 +2174,7 @@
 		}
 		schedule_scan_results_timeout (self, 10);
 	}
-	return FALSE;
+	return TRUE;
 
 reschedule:
 	schedule_scan (self, 0);
@@ -2156,6 +2196,13 @@
 }
 
 
+gboolean
+nm_device_802_11_wireless_perform_scan (NMDevice80211Wireless *self)
+{
+    return nm_device_802_11_wireless_scan ((gpointer) self);
+}
+
+
 /*
  * schedule_scan
  *
Index: NetworkManager-0.6.6/src/NetworkManager.c
===================================================================
--- NetworkManager-0.6.6.orig/src/NetworkManager.c	2008-03-06 17:14:39.000000000 -0300
+++ NetworkManager-0.6.6/src/NetworkManager.c	2008-09-05 15:01:32.000000000 -0300
@@ -929,6 +929,7 @@
 	gboolean		become_daemon = FALSE;
 	gboolean		enable_test_devices = FALSE;
 	gboolean		show_usage = FALSE;
+	gboolean		no_scan = FALSE;
 	char *		owner;
 	char *		pidfile = NULL;
 	char *		user_pidfile = NULL;
@@ -951,6 +952,7 @@
 			{"pid-file", 0, 0, G_OPTION_ARG_STRING, &user_pidfile, "Specify the location of a PID file", NULL},
 			{"enable-test-devices", 0, 0, G_OPTION_ARG_NONE, &enable_test_devices, "Allow dummy devices to be created via DBUS methods [DEBUG]", NULL},
 			{"info", 0, 0, G_OPTION_ARG_NONE, &show_usage, "Show application information", NULL},
+			{"no-scan", 0, 0, G_OPTION_ARG_NONE, &no_scan, "Prevent background scan", NULL},
 			{NULL}
 		};
 		opt_ctx = g_option_context_new("");
@@ -1009,6 +1011,8 @@
 		exit (EXIT_FAILURE);
 	}
 
+    nm_data->no_scan = no_scan;
+
 	/* Create our dbus service */
 	nm_data->dbus_connection = nm_dbus_init (nm_data);
 	if (!nm_data->dbus_connection)
Index: NetworkManager-0.6.6/src/NetworkManagerMain.h
===================================================================
--- NetworkManager-0.6.6.orig/src/NetworkManagerMain.h	2008-03-06 17:14:39.000000000 -0300
+++ NetworkManager-0.6.6/src/NetworkManagerMain.h	2008-09-05 15:01:32.000000000 -0300
@@ -87,6 +87,7 @@
 	gboolean				modem_active;
 	gboolean				asleep;
 	gboolean				disconnected;
+	gboolean				no_scan;
 
 	GSList *				dialup_list;
 	GMutex *				dialup_list_mutex;
Index: NetworkManager-0.6.6/src/nm-dbus-device.c
===================================================================
--- NetworkManager-0.6.6.orig/src/nm-dbus-device.c	2008-03-06 17:14:39.000000000 -0300
+++ NetworkManager-0.6.6/src/nm-dbus-device.c	2008-09-08 15:12:43.000000000 -0300
@@ -500,6 +500,44 @@
 }
 
 
+static DBusMessage *nm_dbus_device_perform_scan (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
+{
+    NMDevice    *dev;
+    DBusMessage *reply = NULL;
+    NMData * app_data;
+
+    g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
+
+    dev = data->dev;
+
+    app_data = nm_device_get_app_data (NM_DEVICE (dev));
+    if (!app_data->no_scan)
+    {
+        nm_warning ("You cannot ask for a scan if you're not in 'No scan' mode");
+        reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "Cannot perform scan", "You cannot ask for a scan if you're not in 'No scan' mode");
+        goto out;
+    }
+
+    if (!nm_device_is_802_11_wireless (dev))
+    {
+        reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotWireless",
+                "Wired devices cannot scan for wireless networks.");
+        goto out;
+    }
+
+    if (nm_device_802_11_wireless_perform_scan ((NMDevice80211Wireless *) dev))
+        reply = dbus_message_new_method_return (message); /* Success */
+    else
+        reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "Cannot perform scan", "The device cannot perform network scanning.");
+
+out:
+    if (!reply)
+        nm_warning ("Could not allocate dbus message.");
+
+    return reply;
+}
+
+
 /*
  * nm_dbus_device_methods_setup
  *
@@ -523,6 +561,7 @@
 	nm_dbus_method_list_add_method (list, "setLinkActive",		nm_dbus_device_set_link_active);
 	nm_dbus_method_list_add_method (list, "getCapabilities",	nm_dbus_device_get_capabilities);
 	nm_dbus_method_list_add_method (list, "getDriver",		nm_dbus_device_get_driver);
+	nm_dbus_method_list_add_method (list, "performScan",		nm_dbus_device_perform_scan);
 
 	return (list);
 }
Index: NetworkManager-0.6.6/src/nm-device-802-11-wireless.h
===================================================================
--- NetworkManager-0.6.6.orig/src/nm-device-802-11-wireless.h	2008-03-06 17:14:39.000000000 -0300
+++ NetworkManager-0.6.6/src/nm-device-802-11-wireless.h	2008-09-05 15:01:32.000000000 -0300
@@ -110,6 +110,8 @@
 
 gint8	nm_device_802_11_wireless_get_signal_strength (NMDevice80211Wireless *self);
 
+gboolean    nm_device_802_11_wireless_perform_scan (NMDevice80211Wireless *self);
+
 
 G_END_DECLS