问题描述
开发一款WIFI管理应用,基础功能有WIFI列表查询功能,在之前有链接过WIFI得清空下,频繁点击WIF列表查询功能会收到SUPPLICANT_ERROR广播。
问题分析
scan执行时间较长,而切换ap比较快,会导致底层和上层的状态不sync, 而出现此问题, 分析如下:
- scan期间处理connect 请求,由于scan时间较长,connect pending.
06-05 10:00:51.155156 10210 10210 D wpa_supplicant: wlan0: Add radio work 'connect'@0x7fb3add140
06-05 10:00:54.901443 10210 10210 D wpa_supplicant: wlan0: Radio work 'scan'@0x7fb3add190 done in 5.016538 seconds
06-05 10:00:54.901515 10210 10210 D wpa_supplicant: wlan0: Starting radio work 'connect'@0x7fb3add140 after 3.746329 second wait
- scan返回后,一方面底层会继续pending的connect,连接上
06-05 10:00:54.901540 10210 10210 I wpa_supplicant: wlan0: Trying to associate with SSID 'TP-test100-5g'
06-05 10:00:54.903265 10210 10210 D wpa_supplicant: * bssid_hint=20:6b:e7:e6:6a:78
06-05 10:00:54.998693 10210 10210 I wpa_supplicant: wlan0: CTRL-EVENT-CONNECTED - Connection to 20:6b:e7:e6:6a:78 completed [id=7 id_str=]
- 另一方面上层framework会根据result做auto join,由于framework是按序处理底层上送的消息的,在处理scan result消息做auto connect时,其实底层已经连接上, 并不会回复,就会authentication timeout
06-05 10:00:55.142016 10210 10210 D wpa_supplicant: CTRL_IFACE: SELECT_NETWORK id=7
06-05 10:00:55.153742 10210 10210 D wpa_supplicant: wlan0: Control interface command 'RECONNECT'
06-05 10:00:55.154083 10210 10210 D wpa_supplicant: wlan0: Request association with 20:6b:e7:e6:6a:78
06-05 10:00:55.183590 10210 10210 D wpa_supplicant: wlan0: Setting authentication timeout: 10 sec 0 usec
总的来说: 此现象在发生在scan和user connect刚好一前一后发生,并且scan未处理完user就trigger connect.,要求时间刚刚好打到。
所以应用层的解决方法是:1.避免在调用scanWifi()的短期内调用connect,就是避免在扫描期间调用connect。
问题解决
扫描期间禁止做connect操作;
自动链接WIFI得时候,要判断是否处于WIFI扫描期间;