wpa_supplicant 状态机的切换以及事件驱动

本文深入探讨了wpa_supplicant在Wi-Fi连接中的作用,详细解析了其状态机的各个阶段,包括扫描、认证、关联等过程,并介绍了如何处理各种网络事件,如信号丢失、身份验证失败等,帮助读者理解无线网络连接背后的机制。
摘要由CSDN通过智能技术生成


WIFI事件类型
pre-shared key may be incorrect  认证密码错误
EVENT_ASSOC_TIMED_OUT 连接超时
EVENT_AUTH_TIMED_OUT  认证超时
EVENT_SCAN_RESULTS 扫描完成,返回扫描结果
EVENT_AUTH 认证完成事件
EVENT_DEAUTH 认证解除
EVENT-STATE-CHANGE 状态机变化事件


enum wpa_event_type 
{
	EVENT_ASSOC,
	EVENT_DISASSOC,
	EVENT_MICHAEL_MIC_FAILURE,
	EVENT_SCAN_RESULTS,//【扫描结果】
	EVENT_ASSOCINFO,//【连接信息】
	EVENT_INTERFACE_STATUS, //【网卡状态】
	EVENT_PMKID_CANDIDATE,
	EVENT_STKSTART,
	EVENT_TDLS,
	EVENT_FT_RESPONSE,
	EVENT_IBSS_RSN_START,
	EVENT_AUTH, //【认证成功】
	EVENT_DEAUTH, //【认证解除】
	EVENT_ASSOC_REJECT, //【拒绝连接】
	EVENT_AUTH_TIMED_OUT, //【认证超时】
	EVENT_ASSOC_TIMED_OUT,//【连接超时】
	EVENT_WPS_BUTTON_PUSHED,
	EVENT_TX_STATUS,
	EVENT_RX_FROM_UNKNOWN,
	EVENT_RX_MGMT,
	EVENT_REMAIN_ON_CHANNEL,
	EVENT_CANCEL_REMAIN_ON_CHANNEL,
	EVENT_RX_PROBE_REQ,
	EVENT_NEW_STA,
	EVENT_EAPOL_RX,
	EVENT_SIGNAL_CHANGE,//【信号变化】
	EVENT_INTERFACE_ENABLED,
	EVENT_INTERFACE_DISABLED, //【网卡接口不可用】
	EVENT_CHANNEL_LIST_CHANGED,
	EVENT_INTERFACE_UNAVAILABLE,
	EVENT_BEST_CHANNEL,
	EVENT_UNPROT_DEAUTH,
	EVENT_UNPROT_DISASSOC,
	EVENT_STATION_LOW_ACK,
	EVENT_IBSS_PEER_LOST,
	EVENT_DRIVER_GTK_REKEY,
	EVENT_SCHED_SCAN_STOPPED,
	EVENT_DRIVER_CLIENT_POLL_OK,
	EVENT_EAPOL_TX_STATUS,
	EVENT_CH_SWITCH,
	EVENT_WNM,
	EVENT_CONNECT_FAILED_REASON,
	EVENT_DFS_RADAR_DETECTED,
	EVENT_DFS_CAC_FINISHED,
	EVENT_DFS_CAC_ABORTED,
	EVENT_DFS_NOP_FINISHED,
	EVENT_SURVEY,
	EVENT_SCAN_STARTED, //【开始扫描】
	EVENT_AVOID_FREQUENCIES,
	EVENT_NEW_PEER_CANDIDATE,
	EVENT_ACS_CHANNEL_SELECTED,
	EVENT_DFS_CAC_STARTED,
}


<p><span style="font-family: Arial, Helvetica, sans-serif;">wpa_supplicant 状态机的切换</span></p>adb logcat | findstr "wpa_supplicant:.wlan0:.State:"


1.一次打开WIFI自动连接的过程
09-29 20:53:59.796  4882  4882 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 20:54:00.155  4882  4882 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 20:54:00.891  4882  4882 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 20:54:02.369  4882  4882 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 20:54:02.415  4882  4882 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 20:54:02.469  4882  4882 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 20:54:02.502  4882  4882 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 20:54:02.522  4882  4882 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->GROUP_HANDSHAKE
09-29 20:54:02.529  4882  4882 D wpa_supplicant: wlan0: State: GROUP_HANDSHAKE -> COMPLETED



2.手动关闭WIFI的过程
09-29 20:56:08.605  5306  5306 D wpa_supplicant: wlan0: State: COMPLETED -> DISCONNECTED
09-29 20:56:08.606  5306  5306 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED



3.打开WIFI 自动连接 手动关闭WIFI全过程
09-29 20:57:25.864  5835  5835 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 20:57:26.556  5835  5835 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 20:57:27.962  5835  5835 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 20:57:28.020  5835  5835 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 20:57:28.060  5835  5835 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 20:57:28.070  5835  5835 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE -> 4WAY_HANDSHAKE
09-29 20:57:28.074  5835  5835 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE -> GROUP_HANDSHAKE
09-29 20:57:28.078  5835  5835 D wpa_supplicant: wlan0: State: GROUP_HANDSHAKE -> COMPLETED
09-29 20:57:36.513  5835  5835 D wpa_supplicant: wlan0: State: COMPLETED -> DISCONNECTED
09-29 20:57:36.513  5835  5835 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED



4.打开WIFI 自动连接到一个开放的WIFI 需要认证才能登陆
09-29 21:00:52.246  7207  7207 D wpa_supplicant: wlan0: State: DISCONNECTED -> INACTIVE
09-29 21:00:52.328  7207  7207 D wpa_supplicant: wlan0: State: INACTIVE -> DISCONNECTED
09-29 21:00:52.605  7207  7207 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:00:53.088  7207  7207 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 21:00:57.258  7207  7207 D wpa_supplicant: wlan0: State: SCANNING -> DISCONNECTED
09-29 21:00:58.702  7207  7207 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 21:01:01.069  7207  7207 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 21:01:01.125  7207  7207 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 21:01:01.127  7207  7207 D wpa_supplicant: wlan0: State: ASSOCIATED -> COMPLETED



5.打开WIFI 未连接任何网络的情况   一直点击Scan也未切换状态
09-29 21:03:53.376  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:03:53.644  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:03:53.999  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 21:03:58.134  8183  8183 D wpa_supplicant: wlan0: State: SCANNING -> DISCONNECTED
09-29 21:03:59.755  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING



6.WIFI已经打开手动输入AP热点密码连接的过程
09-29 21:06:46.472  8183  8183 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 21:06:46.534  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 21:06:46.545  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 21:06:46.557  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:06:46.559  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->GROUP_HANDSHAKE
09-29 21:06:46.561  8183  8183 D wpa_supplicant: wlan0: State: GROUP_HANDSHAKE -> COMPLETED




7.WIFI已经打开手动输入AP热点【错误】密码连接的过程
09-29 21:09:09.160  8183  8183 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 21:09:09.231  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 21:09:09.270  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 21:09:12.599  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE 【第一次密码握手错误】
09-29 21:09:14.806  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:09:17.256  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
==================================连接正确的LOG↓==================================
09-29 21:06:46.557  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:06:46.559  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->GROUP_HANDSHAKE
得出结论: 当密码错误的时候 wpa_supplicant 状态机 会连续retry三次执行 4WAY_HANDSHAKE ->4WAY_HANDSHAKE 过程
==================================连接正确的LOG↑==================================


【三次4WAY_HANDSHAKE都失败后 状态机会从 4WAY_HANDSHAKE 状态 切换为 DISCONNECTED 状态】
09-29 21:09:19.291  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->DISCONNECTED  
09-29 21:09:19.302  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:09:19.894  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 21:09:22.328  8183  8183 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 21:09:22.393  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 21:09:22.440  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 21:09:25.256  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE【第二次密码握手错误】
09-29 21:09:26.255  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:09:29.247  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:09:32.444  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->DISCONNECTED
09-29 21:09:32.469  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:09:32.872  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 21:09:35.325  8183  8183 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 21:09:35.396  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 21:09:35.451  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 21:09:36.443  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE【第三次密码握手错误】
09-29 21:09:39.627  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:09:41.835  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:09:45.474  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->DISCONNECTED
09-29 21:09:45.481  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:09:45.919  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 21:09:48.515  8183  8183 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 21:09:48.587  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 21:09:48.611  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 21:09:52.427  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE【第四次密码握手错误】
09-29 21:09:54.739  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:09:55.655  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE
09-29 21:09:58.623  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->DISCONNECTED
09-29 21:09:58.628  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:09:59.633  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> DISCONNECTED
09-29 21:10:01.385  8183  8183 D wpa_supplicant: wlan0: State: DISCONNECTED -> SCANNING
09-29 21:10:03.809  8183  8183 D wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING
09-29 21:10:03.873  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED
09-29 21:10:03.917  8183  8183 D wpa_supplicant: wlan0: State: ASSOCIATED -> 4WAY_HANDSHAKE
09-29 21:10:06.747  8183  8183 D wpa_supplicant: wlan0: State: 4WAY_HANDSHAKE ->4WAY_HANDSHAKE【第五次密码握手错误】
09-29 21:10:11.325  8183  8183
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值