Re: WIFI autoconnect implementation
- From: 代尔欣 <daierxin gmail com>
- To: Dan Williams <dcbw redhat com>
- Cc: networkmanager-list <networkmanager-list gnome org>
- Subject: Re: WIFI autoconnect implementation
- Date: Wed, 31 Mar 2010 10:02:30 +0800
Hi Dan,
Below is what I changed, because I change the codes much for other purposes, I can't provide a patch file so I just paste the codes segment for this change.
Note:
1. My device only have one wifi device. So the changes may not work for all cases(But works for my device).
2. The changes base on the NM0.7.0.
But From my test, the change does not work good enough. The key issue is the invalid AP(shutdown or walk out of the range) need a long time(5-6 minutes, I know it is the NM behavior, check the AP 3 times and max interval is 120 seconds) disappear. If the user power up the AP or walk back the AP range in 5-6 minutes. The AP can't autoconnect again. But if we wait more than 6 minutes, the autoconnect will happen.
My changes depends on the "access-point-removed" signal.
In NetworkManagerPolicy.c
...
#include "nm-setting-wireless.h"
...
static void
wireless_networks_changed_ap_removed (NMDeviceWifi *device, NMAccessPoint *ap, gpointer user_data)
{
GSList *connections, *iter;
NMPolicy *policy = (NMPolicy *) user_data;
/* To do.. Instead search all connections here, More efficiency way here is search a blocklist for the wifi connections marked as invalid. The invalid connection can be filled in the blocklist in device_state_changed() function "case NM_DEVICE_STATE_FAILED". But need more maintain work for this blocklist, e.g. when "connection-update" we need remove the corresponding connection from the list...*/
/* System connections first, then user connections */
connections = nm_manager_get_connections (policy->manager, NM_CONNECTION_SCOPE_SYSTEM);
connections = g_slist_concat (connections, nm_manager_get_connections (policy->manager, NM_CONNECTION_SCOPE_USER));
iter = connections;
while (iter) {
NMConnection *iter_connection = NM_CONNECTION (iter->data);
GSList *next = g_slist_next (iter);
NMSettingConnection *s_con;
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (iter_connection, NM_TYPE_SETTING_CONNECTION));
g_assert (s_con);
if (!strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_WIRELESS_SETTING_NAME)) {
if (g_object_get_data (G_OBJECT (iter_connection), INVALID_TAG)) {
if(nm_ap_check_compatible (ap, iter_connection)) {
/* Clear the invalid tag on the connection if it got updated. */
g_object_set_data (G_OBJECT (iter_connection), INVALID_TAG, NULL);
break;
}
}
}
iter = next;
}
}
...
static void
device_added (NMManager *manager, NMDevice *device, gpointer user_data)
{
...
- id = g_signal_connect (device, "access-point-removed", G_CALLBACK (wireless_networks_changed), policy);
+ id = g_signal_connect (device, "access-point-removed", G_CALLBACK (wireless_networks_changed_ap_removed), policy);
...
}
2010/3/31 Dan Williams
<dcbw redhat com>
On Wed, 2010-03-24 at 11:13 +0800, 代尔欣 wrote:
> Hi all,
> I am trying implement an autoconnect behavior like:
> User move outside of AP radio range. NM disconnect the AP. ---
> This should already work with original NM.
> User move into the AP radio range again. NM autoconnect the AP
> just disconnect. -- It seems NM0.7.0 or NM0.7.2 can't do this yet. Not
> sure the NM0.8.0.
It depends on the scan results too. As long as when you move back in
range of the AP again and another scan is done, and NM gets the AP back
in the scan list, we're OK.
> From my observe, when user move outside of AP range or just shutdown
> the AP. NM will disconnect the AP and then autoconnect the AP
> immediately. This connection definitely fail. And the connection will
> be marked as invalid and can't autoconnect again.
>
> I can managed to clear the invalid tag of the failed connection. But
> the key is how to know when need autoconnect. Any idea implement this?
The "invalid" stuff was done so that NM wouldn't continually attempt to
reconnect to the same AP over and over again after you'd failed to
connect the first time, or if you'd gotten the password wrong and had
hit "cancel" because you didn't know the password at the time. If the
invalid tag wasn't there, even after hitting "cancel" NM would
continuously reconnect to the AP and keep asking you for the password.
Here's what I'd do... Any time an AP disappears from the internal scan
list for an AP, the manager should look through each wifi device's scan
list and see if there is any other AP that matches that SSID. If all
APs of the SSID are really gone, then we clear the INVALID tag from that
NMConnection.
Need more pointers on where to put that code? If you get it written,
please post it to the list since this seems like a very good
enhancement.
Dan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]