5

We are developing a small App for Android to smoothly switch between two different wireless access points in the same network (same SSID and same network configuration but different physical locations), with the goal of not dropping existing connections after the handover is performed. I've been reading several posts here explaining how to control the wifi programmatically, and now we have a half working solution.

The way we implemented it, the service is scanning for the AP matching our criteria with best signal, and if it's different than the one the system is currently connected to, it will switch to the new AP. The relevant part of the code:

...
// Some initializations and bestOne is the ScanResult with the best signal
conf.BSSID = bestOne.BSSID;
actualNid = mWifiManager.updateNetwork(conf);
mWifiManager.enableNetwork(actualNid, false);
mWifiManager.saveConfiguration();
conf = getWifiConfiguration(mWifiManager, conf);
if(conf == null) {
    return;
}
if(!mWifiManager.enableNetwork(conf.networkId, true)) {
    return;
}
if (mWifiManager.reconnect()) {
    // Great
} else {
    // Error
}

The problem is that all the execution goes through the expected code path. However the handover is not really performed, the logs show as the reconnect is executed, and true is returned. Moreover there are no events received from any SUPPLICANT_CONNECTION_CHANGE_ACTION, or SUPPLICANT_STATE_CHANGED_ACTION, so it seems that the handover is not even triggered.

Another fact is that if we insert a mWifiManager.disconnect() before enabling the network the handover is actually performed. Nevertheless, this is not an option as the running apps lose connectivity, thus dropping the session, which is precisely what we want to avoid.

Any suggestion is more than welcome.

4

1 回答 1

1

这可能不仅仅是软件相关的问题。通常网络适配器 (wifi) 负责跟踪信号电平并决定何时漫游和漫游到哪里。这些算法是特定于供应商的,您可能无法影响它们。漫游是通过从客户端发送 802.11 重新关联帧(请求)来完成的,漫游过程是在 L2 级别(在您的场景中)完成的。但这个过程可能并不那么简单。两个 AP 都应该知道客户端是否漫游,并且向这些 AP 发送帧的交换机应该在其 CAM 表中具有该更新。客户端从中漫游的 AP 可能会缓冲所有发往客户端的帧,并在客户端重新关联时将其发送到新的 AP,从而不会丢失数据。因为这不是 802 所要求的。

这可能无法帮助您解决问题,但我试图指出这确实应该在较低级别(物理、数据链路或传输)而不是应用程序级别上完成。漫游几乎无缝的天气取决于使用的许多硬件(在双方)和网络配置,您无能为力改变这一点。唯一想到的是发送 802.11 探测请求,以便客户端知道其他可能具有更强信号的 AP,您已经在代码中执行了这些操作,并将漫游的决定留给网络适配器。

于 2013-07-29T18:56:27.663 回答