那么现在我们来反向走读
framework如何通知WPAS执行一些操作的
以 开启wifi 为例,代码走到 WifiNative 之后(不要问我为什么会走到这里)
// WifiNative.java
public boolean connectToNetwork(@NonNull String ifaceName, WifiConfiguration configuration) {
// Abort ongoing scan before connect() to unblock connection request.
mWifiCondManager.abortScan(ifaceName);
return mSupplicantStaIfaceHal.connectToNetwork(ifaceName, configuration);
}
//SupplicantStaIfaceHal.java
/**
* Hal calls for bring up/shut down of the supplicant daemon and for
* sending requests to the supplicant daemon
*/
/**
* checkSupplicantStaNetworkAndLogFailure 方法
* 根据ifacename从hashmap中取出对应的SupplicantStaNetworkHal
*/
public boolean connectToNetwork(@NonNull String ifaceName, @NonNull WifiConfiguration config) {
SupplicantStaNetworkHal networkHandle = checkSupplicantStaNetworkAndLogFailure(ifaceName, "connectToNetwork");
if (!networkHandle.select()) {
loge("Failed to select network configuration: " + config.getKey());
return false;
}
return true;
}
//SupplicantStaNetworkHal.java
/**
* Wrapper class for ISupplicantStaNetwork HAL calls. Gets and sets supplicant sta network variables
* and interacts with networks.
*/
/**
* Trigger a connection to this network.
* @return true if it succeeds, false otherwise.
*/
public boolean select() {
synchronized (mLock) {
final String methodStr = "select";
if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false;
try {
SupplicantStatus status = mISupplicantStaNetwork.select();
return checkStatusAndLogFailure(status, methodStr);
} catch (RemoteException e) {
handleRemoteException(e, methodStr);
return false;
}
}
}
private ISupplicantStaNetwork mISupplicantStaNetwork;
最终,是由 ISupplicantStaNetwork.select() 来完成
ISupplicantStaNetwork 是 framework 与 hal 的联络人
external\wpa_supplicant_8\wpa_supplicant\hidl\1.3\sta_network.h 中
声明了 StaNetwork 这个类
/**
* Implementation of StaNetwork hidl object. Each unique hidl
* object is used for control operations on a specific network
* controlled by wpa_supplicant.
*/
classStaNetwork : public V1_3::ISupplicantStaNetwork
//StaNetwork.select()的具体实现如下
SupplicantStatusStaNetwork::selectInternal()
{
structwpa_ssid*wpa_ssid=retrieveNetworkPtr();
if (wpa_ssid->disabled==2) {
return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
}
structwpa_supplicant*wpa_s=retrieveIfacePtr();
wpa_s->scan_min_time.sec=0;
wpa_s->scan_min_time.usec=0;
wpa_supplicant_select_network(wpa_s, wpa_ssid);
return {SupplicantStatusCode::SUCCESS, ""};
}
wpa_supplicant_select_network 写在 supplicant 层
这样,连接指令(其实没有指令机制,,,之前想错了)就从framework传到了supplicant
至于,连接动作怎么走到 WifiNative 的,可以看我写的这篇博客
WiFi 启动流程