一、wificond介绍
wificond是Android 8.0 开始增加的组件,wifi的scan、scan_results是通过wificond去跟kernel通信,wificond是一个独立的进程,代码位于system/connectivity/wificond中,wificond进程通过标准的nl80211命令与Wi-Fi驱动程序进行通信。
nl80211: 用于对无线设备进行配置管理,它是一个基本Netlink的用户态协议(User态),代码位置:
kernel/include/uapi/linux/nl80211.h
kernel/net/wireless/nl80211.h
kernel/net/wireless/nl80211.c
二、wificond相关接口
IWificond
Service interface that exposes primitives for controlling the WiFi subsystems of a device.
公开用于控制设备的 WiFi 子系统的基元的服务接口。
IWificond文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IWificond.aidl
IWificond定义:
interface IWificond{}
IWificond接口定义:
IApInterface createApInterface(@utf8InCpp String iface_name):Create a network interface suitable for use as an AP.
IClientInterface createClientInterface(@utf8InCpp String iface_name):Create a network interface suitable for use as a WiFi client.
boolean tearDownApInterface(@utf8InCpp String iface_name):Remove a previously created AP network interface.
boolean tearDownClientInterface(@utf8InCpp String iface_name):Remove a previously created STA network interface.
void tearDownInterfaces():Tear down all existing interfaces. This should enable clients to create future interfaces immediately after this method returns.
List<IBinder> GetClientInterfaces():list of the currently configured IClientInterface instances.
List<IBinder> GetApInterfaces():list of the currently configured IApInterface instances.
int[] getAvailable2gChannels():Returns an array of available frequencies for 2.4GHz channels. Returrns null on failure.
int[] getAvailable5gNonDFSChannels():Returns an array of available frequencies for 5GHz non-DFS channels. Returrns null on failure.
int[] getAvailableDFSChannels():Returns an array of available frequencies for DFS channels. This also includes passive only frequecies which are not for DFS channels. Returrns null on failure.
int[] getAvailable6gChannels():Returns an array of available frequencies for 6GHz channels. Returrns null on failure.
int[] getAvailable60gChannels():Returns an array of available frequencies for 60GHz channels. Returrns null on failure.
void RegisterCallback(IInterfaceEventCallback callback):Register a callback to receive interface status updates. Multiple callbacks can be registered simultaneously. Duplicate registrations of the same callback will be ignored.
void UnregisterCallback(IInterfaceEventCallback callback):Remove a callback from the set of registered callbacks. This must be the same instance as previously registered. Requests to remove unknown callbacks will be ignored.
void registerWificondEventCallback(IWificondEventCallback callback):Register a callback to receive wificond event. Multiple callbacks can be registered simultaneously. Duplicate registrations of the same callback will be ignored.
void unregisterWificondEventCallback(IWificondEventCallback callback):Remove a callback from the set of registered wificond event callbacks. This must be the same instance as previously registered. Requests to remove unknown callbacks will be ignored.
DeviceWiphyCapabilities getDeviceWiphyCapabilities(@utf8InCpp String iface_name):return a device wiphy capabilities for an interface
void notifyCountryCodeChanged():Notify wificond country code changed. It is being used when the driver doesn't support
IWifiScannerImpl
IWifiScannerImpl文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IWifiScannerImpl.aidl
IWifiScannerImpl定义:
interface IWifiScannerImpl {}
IWifiScannerImpl接口定义:
Type of scan request. This is used in |SingleScanSettings.scan_type|.
const int SCAN_TYPE_LOW_SPAN = 0
const int SCAN_TYPE_LOW_POWER = 1
const int SCAN_TYPE_HIGH_ACCURACY = 2:
const int SCAN_TYPE_DEFAULT = -1;
NativeScanResult[] getScanResults():Get the latest single scan results from kernel.
NativeScanResult[] getPnoScanResults():Get the latest pno scan results from the interface which has most recently
int getMaxSsidsPerScan():Get the max number of SSIDs that the driver supports per scan.
boolean scan(in SingleScanSettings scanSettings):Request a single scan using a SingleScanSettings parcelable object.
void subscribeScanEvents(IScanEvent handler):Subscribe single scanning events. Scanner assumes there is only one subscriber. This call will replace any existing |handler|.
void unsubscribeScanEvents():Unsubscribe single scanning events .
void subscribePnoScanEvents(IPnoScanEvent handler):Subscribe Pno scanning events. Scanner assumes there is only one subscriber. This call will replace any existing |handler|.
void unsubscribePnoScanEvents():Unsubscribe Pno scanning events .
boolean startPnoScan(in PnoSettings pnoSettings):Request a scheduled scan.
boolean stopPnoScan():Stop any existing scheduled scan. Returns true on success. Returns false on failure or there is no existing scheduled scan.
void abortScan():Abort ongoing scan.
IWificondEventCallback
A callback for receiving events related to this chip.
用于接收与此芯片相关的事件的回调。
IWificondEventCallback文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IWificondEventCallback.aidl
IWificondEventCallback定义:
interface IWificondEventCallback {}
IWificondEventCallback接口定义:
void OnAck(int elapsedTimeMs):Called when the management frame was successfully sent and ACKed by the recipient.
void OnFailure(int reason):Called when the send failed.
const int SEND_MGMT_FRAME_ERROR_UNKNOWN = 1:Unknown error.
const int SEND_MGMT_FRAME_ERROR_MCS_UNSUPPORTED = 2:Specifying the MCS rate is not supported by this device.
const int SEND_MGMT_FRAME_ERROR_NO_ACK = 3:Driver reported that no ACK was received for the transmitted frame.
const int SEND_MGMT_FRAME_ERROR_TIMEOUT = 4:Timed out while waiting for a response from the driver about the status of the transmitted frame.
const int SEND_MGMT_FRAME_ERROR_ALREADY_STARTED = 5:An existing transmission is in progress. Another frame cannot be sent until the first transmission completes.
ISendMgmtFrameEvent
A callback to notify the results of sending a management frame.
用于通知发送管理帧的结果的回调。
ISendMgmtFrameEvent文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/ISendMgmtFrameEvent.aidl
ISendMgmtFrameEvent定义:
interface ISendMgmtFrameEvent {}
ISendMgmtFrameEvent 接口定义:
void OnRegDomainChanged(@utf8InCpp String countryCode);
IScanEvent
A callback for receiving scanning events.
用于接收扫描事件的回调。
IScanEvent文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IScanEvent.aidl
IScanEvent定义:
interface IScanEvent{}
IScanEvent接口定义:
void OnScanResultReady();
void OnScanFailed();
IPnoScanEvent
A callback for receiving pno scanning events.
用于接收 pno 扫描事件的回调。
IPnoScanEvent文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IPnoScanEvent.aidl
IPnoScanEvent定义:
interface IPnoScanEvent{}
IPnoScanEvent接口定义:
void OnPnoNetworkFound();
void OnPnoScanFailed();
IInterfaceEventCallback
A callback for receiving events related to this chip.
用于接收与此芯片相关的事件的回调。
IInterfaceEventCallback文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IInterfaceEventCallback.aidl
IInterfaceEventCallback定义:
interface IInterfaceEventCallback{}
IInterfaceEventCallback接口定义:
void OnClientInterfaceReady(IClientInterface network_interface);
void OnApInterfaceReady(IApInterface network_interface);
void OnClientTorndownEvent(IClientInterface network_interface);
void OnApTorndownEvent(IApInterface network_interface);
IClientInterface
IClientInterface represents a network interface that can be used to connect to access points and obtain internet connectivity.
IClientInterface 表示可用于连接到接入点并获得互联网连接的网络接口。
IClientInterface文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IClientInterface.aidl
IClientInterface定义:
interface IClientInterface{}
IClientInterface接口定义:
int[] getPacketCounters():Get packet counters for this interface.
int[] signalPoll():Do signal poll for this interface.
byte[] getMacAddress():Get the MAC address of this interface.
String getInterfaceName():Retrieve the name of the network interface corresponding to this IClientInterface instance (e.g. "wlan0")
IWifiScannerImpl getWifiScannerImpl():Get a WifiScanner interface associated with this interface.
void SendMgmtFrame(in byte[] frame, in ISendMgmtFrameEvent callback, int mcs):Sends an arbitrary 802.11 management frame on the current channel.
IApInterfaceEventCallback
A callback for receiving events related to soft AP.
用于接收与软AP相关的事件的回调。
IApInterfaceEventCallback文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IApInterfaceEventCallback.aidl
IApInterfaceEventCallback定义:
interface IApInterfaceEventCallback{}
IApInterfaceEventCallback接口定义:
void onConnectedClientsChanged(in NativeWifiClient client, in boolean isConnected):Signals that the stations associated to this soft Ap have changed.
void onSoftApChannelSwitched(int frequency, int bandwidth):Signals a channel switch event for this soft Ap.
IApInterface
IApInterface represents a network interface configured to act as a WiFi access point.
IApInterface 表示配置为充当 WiFi 接入点的网络接口。
IApInterface文件路径:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IApInterface.aidl
IApInterface定义:
interface IApInterface{}
IApInterface 接口定义:
boolean registerCallback(IApInterfaceEventCallback callback):Register a callback object for this interface.
String getInterfaceName():Retrieve the name of the network interface corresponding to this IApInterface instance (e.g. "wlan0")
三、wificond相关类
ScannerImpl
Scanner在wificond HAL的实现类,实现了IWifiScannerImpl AIDL接口。
ScannerImpl文件路径:
system/connectivity/wificond/scanning/scanner_impl.cpp
system/connectivity/wificond/scanning/scanner_impl.h
ScannerImpl定义:
class ScannerImpl : public android::net::wifi::nl80211::BnWifiScannerImpl {}
ScanUtils
Provides scanning helper functions.
提供扫描帮助程序功能。
ScannerImpl文件路径:
system/connectivity/wificond/scan_utils.cpp
system/connectivity/wificond/scan_utils.h
ScannerImpl定义:
class ScanUtils {}
NetlinkManager
wificond通过NetlinkManager与内核交互。
NetlinkManager文件路径:
system/connectivity/wificond/net/netlink_manager.cpp
system/connectivity/wificond/net/netlink_manager.h
NetlinkManager定义:
class NetlinkManager {}
Server
Server文件路径:
system/connectivity/wificond/Server.cpp
system/connectivity/wificond/Server.h
Server定义:
class Server : public android::net::wifi::nl80211::BnWificond {}
ClientInterfaceBinder
ClientInterfaceBinder 文件路径:
system/connectivity/wificond/client_interface_binder.cpp
system/connectivity/wificond/client_interface_binder.h
ClientInterfaceBinder 定义:
class ClientInterfaceBinder : public android::net::wifi::nl80211::BnClientInterface {}
ClientInterfaceImpl
Holds the guts of how we control network interfaces capable of connecting to access points via wpa_supplicant.
ApInterfaceImpl文件路径:
system/connectivity/wificond/client_interface_impl.cpp
system/connectivity/wificond/client_interface_impl.h
ApInterfaceImpl定义:
class ClientInterfaceImpl {}
class MlmeEventHandlerImpl : public MlmeEventHandler {}
ApInterfaceImpl
ApInterfaceImpl文件路径:
system/connectivity/wificond/ap_interface_impl.cpp
system/connectivity/wificond/ap_interface_impl.h
ApInterfaceImpl定义:
class ApInterfaceImpl {}
NativeScanResult
This is the class to represent a scan result for wificond internal use.
NativeScanResult文件路径:
system/connectivity/wificond/scanning/scan_result.cpp
system/connectivity/wificond/scanning/scan_result.h
NativeScanResult定义:
class NativeScanResult : public ::android::Parcelable {}
NativeWifiClient
NativeWifiClient文件路径:
system/connectivity/wificond/client/native_wifi_client.cpp
system/connectivity/wificond/client/native_wifi_client.h
NativeWifiClient定义:
class NativeWifiClient : public ::android::Parcelable {}
四、wificond方法
Status ScannerImpl::scan(const SingleScanSettings& scan_settings, bool* out_success):
Status ScannerImpl::startPnoScan(const PnoSettings& pno_settings, bool* out_success) :
void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, vector<vector<uint8_t>>* scan_ssids, vector<vector<uint8_t>>* match_ssids, vector<uint32_t>* freqs, vector<uint8_t>* match_security) :
bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) :
Status ScannerImpl::stopPnoScan(bool* out_success) :
bool ScannerImpl::StopPnoScanDefault() :
Status ScannerImpl::abortScan() :
Status ScannerImpl::subscribeScanEvents(const sp<IScanEvent>& handler) :
Status ScannerImpl::unsubscribeScanEvents() :
Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) :
五、wificond流程
1、scan流程
Android13 wificond scan流程分析-CSDN博客