自学内容网 自学内容网

android wifi framework与wpa_supplicant的交互

android frmework直接与wpa_supplicant进行交互,使用aidl或者hidl

二、事件

framework注册事件的地方:

packages/modules/Wifi/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java

class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallback.Stub {

        public void onStateChanged(int newState, byte bssid, int id, ArrayList<Byte> ssid..);

        public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated, int reasonCode);

        private void handleAssocRejectEvent(AssocRejectEventInfo assocRejectInfo)

}

注册此事件的地方

packages/modules/Wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java

这儿还需要进一步看是调用的哪个?这儿有v1、v2等

private boolean trySetupStaIfaceV1_4(String ifaceName,ISupplicantStaIface iface)  {

        SupplicantStaIfaceHalCallbackV1_4 callbackV14 =

                new SupplicantStaIfaceHalCallbackV1_4(ifaceName);

        if (!registerCallbackV1_4(getStaIfaceMockableV1_4(iface), callbackV14)) {

                throw new RemoteException("Init StaIface V1_4 failed.");

        }

        /* keep this in a store to avoid recycling by garbage collector. */

        mISupplicantStaIfaceCallbacks.put(ifaceName, callbackV14);

        return true;

}

setupIface->setupStaIface->vendor_setupIface(new SupplicantStaIfaceHalCallback)

setupStaIface->trySetupStaIfaceV1_1->trySetupStaIfaceV1_2->....

hidl定义callback和接口的地方

hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.hal 

ISupplicantStaIfaceCallback在v1.1里有onDisconnected回调,后续的v1.2->v1.3->v1.4 的ISupplicantCallback.hal 都继承前面的版本

zheli

这里还有连接wifi失败时的ReasonCode、StatusCode、还有连接State

ReasonCode常见的有:

DEAUTH_LEAVING = 3、UNSPECIFIED = 1、INVALID_IE = 13、STA_LEAVING = 36、TIMEOUT = 39

State常见的有:

DISCONNECTED = 0、AUTHENTICATING = 4等

hardware/interfaces/wifi/supplicant/1.0/ISupplicantIface.hal

ISupplicantIface.hal 里有listNetworks、addNetwork接口

hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIface.hal

ISupplicantStaIface.hal里有定义接口 

registerCallback(ISupplicantStaIfaceCallback callback)、reassociate、disconnect、setPowerSave、getMacAddress、setBtCoexistenceMode、setCountryCode等

hardware/interfaces/wifi/supplicant/1.0/ISupplicantCallback.hal

ISupplicantCallback.hal里有onInterfaceCreated、onInterfaceRemoved接口

wpa_supplicant接口事件注册的地方

以连接失败为例:

external/wpa_supplicant_8/wpa_supplicant/hidl/1.4/hidl_manager.h

这里include了很多hidl生成的.h文件,可以在out目录下查看

hidl_manager.h

#include <android/hardware/wifi/supplicant/1.0/ISupplicantCallback.h>

#include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.h>

#include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetworkCallback.h>

#include <android/hardware/wifi/supplicant/1.4/ISupplicantStaIfaceCallback.h>

#include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.h>

#include <android/hardware/wifi/supplicant/1.4/ISupplicantStaNetworkCallback.h>

在out目录下类似:

./soong/.intermediates/hardware/interfaces/wifi/supplicant/1.4/

android.hardware.wifi.supplicant@1.4_genc++_headers/gen/android/hardware/wifi/、supplicant/1.4/ISupplicantStaIfaceCallback.h

external/wpa_supplicant_8/wpa_supplicant/hidl/1.4/hidl_manager.cpp

void HidlManager::notifyDisconnectReason(struct wpa_supplicant *wpa_s) {

        callWithEachStaIfaceCallback(

                &ISupplicantStaIfaceCallback::onDisconnected,  wpa_s->disconnect_reason);

}

如果连接密码失败,可以看下大致的如下路径 :

events.wpa_supplicant_event_disassoc_finish  (wpa_supplicant/events.c)

notify.wpas_notify_disconnect_reason->  (wpa_supplicant/notify.c)

hidl.wpas_hidl_notify_disconnect_reason->  (wpa_supplicant/hidl/1.4/hidl.cpp)

hidl_manager->notifyDisconnectReason

events.c

static void wpa_supplicant_event_disassoc_finish () {

        if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {

                wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - ""pre-shared key may be incorrect");

                wpas_auth_failed(wpa_s, "WRONG_KEY");

                wpas_notify_disconnect_reason(wpa_s);

        }

}

        


原文地址:https://blog.csdn.net/yudelian/article/details/145141374

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!