1.wifi断开 wlan-driver最先知道。
2.wlan-driver在与路由器连接的时候(未断开时), 会有周期性的beacon帧来维持连接,AP端一旦遇到突发事情,会立刻通过802.11协议的 deauth 帧/ reject 帧等 通知到 driver。
3. wlan-driver一旦收到802协议的 deauth帧/reject帧等后,马上断开与AP的连接。
4. 紧接着,wlan-driver的上层WifiStateMachine内部广播通知系统外部网络环境,系统跟Settings开始同步处理此次的断开。
external/wpa_supplicant_8/hostapd/src/drivers/driver_nl80211.c
static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,void *global_priv, int hostapd,const u8 *set_addr,
const char *driver_params){
if (nl80211_init_bss(bss))
goto failed;
}
static int nl80211_init_bss(struct i802_bss *bss)
{
...
nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,process_bss_event, bss);
}
external/wpa_supplicant_8/src/drivers/driver_nl80211_event.c
int process_bss_event(struct nl_msg *msg, void *arg)
{
switch (gnlh->cmd) {
case NL80211_CMD_FRAME:
case NL80211_CMD_FRAME_TX_STATUS:
mlme_event(bss, gnlh->cmd, tb[NL80211_ATTR_FRAME],
tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT],
tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK],
tb[NL80211_ATTR_COOKIE],
tb[NL80211_ATTR_RX_SIGNAL_DBM],
tb[NL80211_ATTR_STA_WME]);
break;
}
external/wpa_supplicant_8/wpa_supplicant/events.c
void wpa_supplicant_event(void *ctx, enum wpa_event_type event,union wpa_event_data *data)
{
case EVENT_AUTH:
case ....
...
}
wpa_supplicant_set_state --wpa_supplicant.c
wpas_notify_state_changed -- hidi_manager.cpp
wpas_hidl_notify_state_changed -- hidl.cpp
external/wpa_supplicant_8/wpa_supplicant/hidl/1.1/hidl.cpp
{
....
hidl_manager->notifyStateChange(wpa_s);
}
external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/hidl_manager.cpp
{
....
callWithEachStaIfaceCallback(
wpa_s->ifname, std::bind(
&ISupplicantStaIfaceCallback::onStateChanged,
std::placeholders::_1,
static_cast(
wpa_s->wpa_state),
bssid, hidl_network_id, hidl_ssid));
}
frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
public void onStateChanged(int newState, byte[/* 6 */] bssid, int id,ArrayList ssid) {
mWifiMonitor.broadcastSupplicantStateChangeEvent( mIfaceName,
getCurrentNetworkId(mIfaceName), wifiSsid, bssidStr, newSupplicantState);
}
frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiMonitor.java
public void broadcastSupplicantStateChangeEvent(String iface, int networkId, WifiSsid wifiSsid,....)
{
sendMessage(iface, SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,new StateChangeResult(networkId, wifiSsid, bssid, newSupplicantState));
}
frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java
class ConnectModeState extends State {
{
.....
case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
SupplicantState state = handleSupplicantStateChange(message);
if (state == SupplicantState.DISCONNECTED
&& mNetworkInfo.getState() != NetworkInfo.State.DISCONNECTED) {
if (mVerboseLoggingEnabled) {
log("Missed CTRL-EVENT-DISCONNECTED, disconnect");
}
handleNetworkDisconnect();
transitionTo(mDisconnectedState);
}
if (state == SupplicantState.COMPLETED) {
mIpClient.confirmConfiguration();
mWifiScoreReport.noteIpCheck();
}
}
class DisconnectingState extends State {
case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
handleNetworkDisconnect();
transitionTo(mDisconnectedState);
}