[RK3288][Android6.0] WiFi之Autojoin對無線網路的選擇機制
Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92
當有兩個或者兩個以上的已經儲存的無線網路可以連線時,系統通過attemptAutoJoin()來選擇一個最優網路。
假設只有兩個儲存的無線網路,配置檔案如下:
[email protected]:/ # cat /data/misc/wifi/wpa_supplicant.conf
network={
ssid="RD-TA100-2.4G"
psk="Gerrit2All"
key_mgmt=WPA-PSK
priority=2
}
network={
ssid= "Kris"
psk="20122008"
key_mgmt=WPA-PSK
priority=3
}
來看attemptAutoJoin():
boolean attemptAutoJoin()
{
//獲取上一次選擇的網路配置,我上次選的是ap: "Kris"
String lastSelectedConfiguration = mWifiConfigStore.getLastSelectedConfiguration();
if (lastSelectedConfiguration != null) {
age = 14000;
}
//獲取最近配置過的網路,這裡會獲取到兩個,也就是配置檔案中的那兩個
List<WifiConfiguration> list =
mWifiConfigStore.getRecentConfiguredNetworks(age, false);
for (WifiConfiguration config : list) {
//candidate儲存當前網路配置
if (candidate == null) {
candidate = config;
} else {
//迴圈第二次時就會比較兩個網路配置
int order = compareWifiConfigurations(candidate, config);
if (order > 0) {
// Ascending : candidate < config
//經過一番計算後,發現order>0,那麼老的candidate網路配置就會被新的代替,
//如果有多餘兩個儲存的無線網路,那麼依次計算並且符合條件後替換
candidate = config;
}
}
}
if (mWifiStateMachine.shouldSwitchNetwork(networkDelta)) { // !!! JNo: Here!
//傳送自動連線event給WifiStateMachine
mWifiStateMachine.sendMessage(WifiStateMachine.CMD_AUTO_CONNECT,
candidate.networkId, networkSwitchType, candidate);
found = true;
}
return found;
}
compareWifiConfigurations():
int compareWifiConfigurations(WifiConfiguration a, WifiConfiguration b)
{
int order = 0;
boolean linked = false;
// ephemeral的解釋是
// Indicate that a WifiConfiguration is temporary and should not be saved
//nor considered by AutoJoin.
//正常連線時WifiStateMachine在connect的時候設定為false
//當是未信任網路時會設定為true
if (a.ephemeral && b.ephemeral == false) {
return 1; // b is of higher priority - ascending
}
if (b.ephemeral && a.ephemeral == false) {
return -1; // a is of higher priority - descending
}
// Apply RSSI, in the range [-5, +5]
// after band adjustment, +n difference roughly corresponds to +10xn dBm
//通過RSSI也就是訊號強度計算得到一個order
order = order + compareWifiConfigurationsRSSI(a, b, mCurrentConfigurationKey);
// If the configurations are not linked, compare by user's choice, only a
// very high RSSI difference can then override the choice
//如果使用者上次有選擇過某個網路,那麼又要根據選擇的choice來重新計算最終的order
if (!linked) {
int choice;
choice = getConnectChoice(a, b, false);
if (choice > 0) {
// a is of higher priority - descending
order = order - choice;
if (a.visibility != null) {
a.visibility.lastChoiceBoost = choice;
a.visibility.lastChoiceConfig = b.configKey();
}
}
choice = getConnectChoice(b, a, false);
if (choice > 0) {
// a is of lower priority - ascending
order = order + choice;
if (b.visibility != null) {
b.visibility.lastChoiceBoost = choice;
b.visibility.lastChoiceConfig = a.configKey();
}
}
}
String sorder = " == ";
if (order > 0) {
sorder = " < ";
} else if (order < 0) {
sorder = " > ";
}
return order;
}
除錯時可以把debug log開啟,對應的log如下:
07-06 15:41:00.357 557 608 D WifiAutoJoinController : attemptAutoJoin() status=wpa_state=SCANNING
07-06 15:41:00.357 557 608 D WifiAutoJoinController : p2p_device_address=b2:f1:ec:49:50:cb
07-06 15:41:00.357 557 608 D WifiAutoJoinController : address=b0:f1:ec:49:50:cb
07-06 15:41:00.357 557 608 D WifiAutoJoinController : uuid=544ae0ce-fa0a-58d2-af21-81be288cb44c
07-06 15:41:00.358 557 608 D WifiAutoJoinController : attemptAutoJoin() num recent config 2 ---> suppNetId=-1
07-06 15:41:00.358 557 608 D WifiAutoJoinController : attemptAutoJoin good candidate seen, bumped hard -> status="Kris"WPA_PSK status=0
07-06 15:41:00.358 557 608 D WifiAutoJoinController : attemptAutoJoin trying id=1 "Kris"WPA_PSK status=0
07-06 15:41:00.359 557 608 D WifiAutoJoinController : attemptAutoJoin good candidate seen, bumped hard -> status="RD-TA100-2.4G"WPA_PSK status=0
07-06 15:41:00.359 557 608 D WifiAutoJoinController : attemptAutoJoin trying id=0 "RD-TA100-2.4G"WPA_PSK status=0 current candidate "Kris"WPA_PSK
07-06 15:41:00.359 557 608 D WifiAutoJoinController : attemptAutoJoin will compare candidate "Kris"WPA_PSK with "RD-TA100-2.4G"WPA_PSK
07-06 15:41:00.359 557 608 D WifiAutoJoinController : compareWifiConfigurationsRSSI: "Kris"WPA_PSK rssi=-55,-127 boost=0 "RD-TA100-2.4G"WPA_PSK rssi=-47,-127 boost=0
07-06 15:41:00.359 557 608 D WifiAutoJoinController : "Kris"WPA_PSK is5=false score=-55 "RD-TA100-2.4G"WPA_PSK is5=false score=-47
07-06 15:41:00.359 557 608 D WifiAutoJoinController : compareWifiConfigurationsRSSI "Kris"WPA_PSK rssi=(-55,-127) num=(1,0) < "RD-TA100-2.4G"WPA_PSK rssi=(-47,-127) num=(1,0) -> 8
07-06 15:41:00.360 557 608 D WifiAutoJoinController : compareWifiConfigurations prefers "Kris"WPA_PSK over "RD-TA100-2.4G"WPA_PSK due to user choice of 60 order -> -52
07-06 15:41:00.360 557 608 D WifiAutoJoinController : compareWifiConfigurations: "Kris"WPA_PSK > "RD-TA100-2.4G"WPA_PSK order -52
07-06 15:41:00.360 557 608 D WifiAutoJoinController : attemptAutoJoin compareWifiConfigurations returned -52
07-06 15:41:00.360 557 608 D WifiAutoJoinController : attemptAutoJoin networkSwitching candidate "Kris"WPA_PSK linked=false : delta=1000
07-06 15:41:00.361 557 608 D WifiStateMachine: shouldSwitchNetwork txSuccessRate=0.00 rxSuccessRate=0.00 delta 1000 -> 1000
07-06 15:41:00.361 557 608 D WifiAutoJoinController : AutoJoin auto connect with netId 1 to "Kris"WPA_PSK
07-06 15:41:00.361 557 608 D WifiAutoJoinController : attemptRoam: "Kris"WPA_PSK Found ee:29:f5:be:c5:6b rssi=-55 freq=2437
07-06 15:41:00.361 557 608 D WifiAutoJoinController : Done attemptAutoJoin status=3
總的來說,評分機制有三種:
1. ephemeral值,即是否是未信任網路
2. RSSI值
3. 使用者上次選擇,優先順序比RSSI高,除非RSSI非常大的情況
相關推薦
[RK3288][Android6.0] WiFi之Autojoin對無線網路的選擇機制
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 當有兩個或者兩個以上的已經儲存的無線網路可以連線時,系統通過attemptAutoJoin()來選擇一個最優網路。 假設只有兩個儲存的無線網路,配置檔案
[RK3288][Android6.0] WiFi之無線網路配置的關閉過程
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 是wifi enabled的逆過程,不過呼叫的也是setWifiEnable()介面. onSwitchChanged -> WifiEnabler.java mWifiManager.setWif
[RK3288][Android6.0] WiFi之Framework連線過程小結
Platform: Rockchip OS: Android 6.0Kernel: 3.10.92 onPreferenceTreeClick -> WifiSettings.java preference.getAccessPoint //獲取當前選擇的ap
[RK3288][Android6.0] PMIC之RK818驅動小結
uboot部分: pmic_init -> power_rockchip.c pmic_rk818_init -> pmic_rk818.c rk818_parse_dt -> fdt_get_i2c_info
[RK3288][Android6.0] PMIC之RK818硬體部分小結
電源分類: 主要分兩種: DC/DC 和 LDO, 兩種特性如下: DC/DC: 即直流變壓器.分buck(降壓),boost(升壓),buck-boost(升降壓).效率高,成本高,大電流使用,不過
[RK3288][Android6.0] WiFi的dts配置說明(AP6335)
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 原理圖 配置檔案 參考 使用的是AP6335, 硬體上用的是SDIO0. 原理圖: 配置檔案: 電源部分:
[RK3288][Android6.0] WiFi的HAL層載入問題
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 背景: 幾年前做高通平臺到現在,我一直認為hardware下面目錄都是隻跟用哪個vendor相關,比如現在用的是rk,那麼就是rockchip目錄有
[RK3288][Android6.0] PMIC之RK818配置說明
Platform: ROCKCHIP OS: Android 6.0 Kernel: 3.10.92 對應dts檔案是 rk3288/kernel/arch/arm/boot/dts/rk818.dt
[RK3288][Android6.0] 使用者空間對音訊暫存器的控制
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 Audio HAL控制驅動中的暫存器是通過kcontrol結構實現的,kcontrol有多種型別,如mixer, mux等,由struct snd_kco
[RK3288][Android6.0] 除錯筆記 --- 普通串列埠的新增
Platform: ROCKCHIP OS: Android 6.0 Kernel: 3.10.92 uart0,1,3,4 (普通串列埠) 用的是同一個串列埠驅動. uart2(除錯串列埠)的驅動程式碼嵌在fiq debugger的code中. 相關的配置在rk3288.dtsi中:
rk3288 android6.0 camera子系統
概述 camera kernel驅動是基於Linux的v4l2驅動,裝置名/dev/videox。camera系統採用Client/Service構架,通過Binder IPC來通訊,最終Client通過呼叫Service介面實現各個具體功能。Service程序負責
[RK3288][Android6.0] 除錯筆記 --- hwclock命令無法使用
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 現象: 使用hwclock,提示找不到檔案 [email protected]:/ # hwclock
[RK3288][Android6.0] 控制匯流排通用介面regmap小結
Platform: RockchipOS: Android 6.0Kernel: 3.10.92看音訊模組時發現了一個叫regmap的東西,看了下以後勢必會用到,也把小結分享給大家。之前使用I2C或者SPI匯流排進行讀寫時的框架:需要自己再對讀寫函式進行封裝,這樣每個裝置驅動
[RK3288][Android6.0] AT24C02驅動分析及功能增加小結
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 Spec: 網上很多,如 https://wenku.baidu.com/view/0020131fff00bed5b8f31d05.html驅動: 檔案: kernel/
[RK3288][Android6.0] I2C預設傳輸速率及修改
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 RK對應的i2c controller驅動在 kernel/drivers/i2c/busses/i2c-rockchip.c 對應的傳輸函式是rockchip_i2c_
[RK3288][Android6.0] RTC驅動的上層呼叫流程
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 說明: RTC驅動在註冊的時候提供了兩個字元裝置給使用者空間供操作。 1. /dev/alarm, android特有裝置,為了提高平臺無關性而加
[RK3288][Android6.0] 除錯筆記 --- I2C通訊失敗問題
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 使用rk3288的i2c5讀寫時,會出現以下error log: [email prot
[RK3288][Android6.0] 系統除錯串列埠驅動流程小結
Platform: ROCKCHIP OS: Android 6.0 Kernel: 3.10.92 rk3288提供了fiq debugger功能, 因此rk將debug uart和普通uart區分開來, debug uart的初始化整合到了fiq debugger程式碼中完成,不過uart的初始化 方法還
[RK3288][Android6.0] 除錯筆記 --- 測試I2C裝置正常傳輸方法
Platform: Rockchip OS: Android 6.0 Kernel: 3.10.92 rk在驅動層做了一個通用i2c測試程式碼提供給上層快速測試i2c外設是否傳輸正常. 測試使用方法
[RK3288][Android6.0] 移植筆記 --- 13.3寸eDP顯示屏新增
Platform: RK3288 OS: Android 6.0 Kernel: 3.10.92 不得不說從 RGB -> LVDS -> MIPI -> eDP 一路過來,現在的