设备WiFi 断开的原因有多种多样,但断开流程大体不变;
所以遇到wif i断开问题不要慌,不要慌,本文将毫无保留分享处理断开问题思路,
这里抛砖引玉,给你们走出困境中一些实用的指南tips。
还是老三样,先上流程图
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);
}