android11 wpa_supplicant_8 解析

阎祖鹤
2023-12-01

编译:m wpa_supplicant

位置: external\wpa_supplicant_8

配置文件:
/vendor/etc/wifi/wpa_config.txt
/vendor/etc/wifi/wpa_supplicant_rtk.conf
/data/vendor/wifi/wpa/wpa_supplicant.conf

After wpa_supplicant has configured the network device, higher level configuration such as DHCP may proceed

0. 进程启动
入口函数 main -> read_wpa_param_config
module_name = [realtek], 读取参数之后进入 main_loop。

1. 服务注册
Supplicant 是 HIDL的实现类 。也就是服务类 。

wpa_supplicant_init -> wpas_notify_supplicant_initialized ->
wpas_hidl_init -> HidlManager::registerHidlService 注册服务。

被谁启动
java层的 :ISupplicant.getService() ?

问题: 在关闭wifi的情况下,是否会注册服务?
流程是:
1 先调用 ISupplicant.getService() ,启动 supplicant daemon,
注册了回调函数,后面服务注册成功之后会执行回调函数,然后我们才取得这个服务。

入口函数 main -> read_wpa_param_config
module_name = [realtek], 读取参数之后进入 main_loop。

2. 服务启动

通过system/hwservicemanager/ServiceManager.cpp 的 registerForNotifications 注册一个服务可用的回调。

Supplicant服务可用的回调在SupplicantStaIfaceHal#mServiceNotificationCallback。

wpa_supplicant: Current wifi chip is RTL8822CE

Architecture

The wpa_supplicant system consists of the following components:

wpa_supplicant.conf

the configuration file describing all networks that the user wants the computer to connect to.

wpa_supplicant

the program that directly interacts with the network interface.

wpa_cli

the client program that provides a high-level interface to the functionality of the daemon.

wpa_passphrase

a utility needed to construct wpa_supplicant.conf files that include encrypted passwords.

packages/modules/Wifi/framework/java/android/net/wifi/SupplicantState.java

hardware/interfaces/wifi/supplicant/aidl/android/hardware/wifi/supplicant/ISupplicantStaIfaceCallback.aidl


 /**
     * Used to indicate an association rejection received from the AP
     * to which the connection is being attempted.
     *
     * @param assocRejectData Association Rejection related information.
     */
    void onAssociationRejected(in AssociationRejectionData assocRejectData);

    /**
     * Used to indicate the timeout of authentication to an AP.
     *
     * @param bssid BSSID of the corresponding AP.
     */
    void onAuthenticationTimeout(in byte[] bssid);

    /**
     * Used to indicate the success of a WPS connection attempt.
     */
    void onWpsEventSuccess();


  /**
     * Indicates an EAP authentication failure.
     * @param bssid BSSID of the access point.
     * @param errorCode Error code for EAP authentication failure.
     *        Either standard error code (enum EapErrorCode) or
     *        private error code defined by network provider.
     */
    void onEapFailure(in byte[] bssid, in int errorCode);

ISupplicantStaIface.registerCallback

实现:

wpa_supplicant/hidl/1.3/hidl_manager.cpp

external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c

wpa_supplicant state callback :
com.android.server.wifi.SupplicantStaIfaceCallbackImpl#onStateChanged(int, byte[], int, java.util.ArrayList<java.lang.Byte>, boolean)

then mWifiMonitor broadcasts these events using broadcastSupplicantStateChangeEvent 。

// Map of all the callbacks registered for STA interface specific
	// hidl objects controlled by wpa_supplicant.  This map is keyed in by
	// the corresponding |ifname|.
	std::map<
	    const std::string,
	    std::vector<android::sp<ISupplicantStaIfaceCallback>>>
	    sta_iface_callbacks_map_;

wpa_supplicant_add_iface ->
wpas_notify_iface_added ->

HidlManager::registerInterface

目前使用的是 StaIface::registerCallback_1_3

StaIface::registerCallback

StaIface::registerCallbackInternal

HidlManager::addStaIfaceCallbackHidlObject

把这个 callback 放入这个 ifname 对应的 sta_iface_callbacks_map_中 。

最终在方法 registerForDeathAndAddCallbackHidlObjectToList 中把 callback 放入sta_iface_callbacks_map_里面 ,key为 ifaceName .

 类似资料: