Wifi框架中WifiMonitor负责上报wpa_supplicant的消息给WifiStateMachine,WifiNative负责将WifiStateMachine的消息下发给wpa_supplicant执行.

本文先来简单介绍WifiMonitor如何处理事件以及怎么分发事件。(未完待续)

(1)

在WifiStateMachine中InitialState状态收到CMD_START_SUPPLICANT消息时候

if (mWifiNative.startSupplicant(mP2pSupported)) {
setWifiState(WIFI_STATE_ENABLING);
if (DBG) log("Supplicant start successful");
mWifiMonitor.startMonitoring(mInterfaceName);
transitionTo(mSupplicantStartingState);
} else {……}

(2)

startMonitoring这是一个同步函数

WifiMonitor的事件发放-LMLPHP

(3)

关注ensureConnectedLocked函数

WifiMonitor的事件发放-LMLPHP

(4)

一个跟踪的线程类MonitorThread

private class MonitorThread extends Thread {
private final LocalLog mLocalLog = mWifiNative.getLocalLog(); public MonitorThread() {
super("WifiMonitor");
} public void run() {
if (DBG) {
Log.d(TAG, "MonitorThread start with mConnected=" + mConnected);
}
//noinspection InfiniteLoopStatement
for (;;) {
if (!mConnected) {
if (DBG) Log.d(TAG, "MonitorThread exit because mConnected is false");
break;
}
String eventStr = mWifiNative.waitForEvent(); // Skip logging the common but mostly uninteresting events
if (!eventStr.contains(BSS_ADDED_STR) && !eventStr.contains(BSS_REMOVED_STR)) {
if (DBG) Log.d(TAG, "Event [" + eventStr + "]");
mLocalLog.log("Event [" + eventStr + "]");
} if (dispatchEvent(eventStr)) {
if (DBG) Log.d(TAG, "Disconnecting from the supplicant, no more events");
break;
}
}
}
}

(5)

然后事件被dispatchEvent函数分发。

ispatchEvent函数有两个,一个是一个参数,一个是两个参数的。

 private boolean dispatchEvent(String eventStr, String iface)
2 private synchronized boolean dispatchEvent(String eventStr)

(版权所有,转载请告知)

05-27 18:23