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);

}

}

相关推荐
阿岳3161 小时前
数据库增量备份和全量备份
android·数据库·adb
Yang-Never2 小时前
Shader -> BitmapShader贴图着色器详解
android·开发语言·kotlin·android studio·贴图·着色器
oioihoii2 小时前
《C++11》nullptr介绍:从NULL说起
android·java·c++
命运之手2 小时前
[ Kotlin ] Integrate ProtoBuffer and GoogleRPC Into KotlinNative
android·kotlin·grpc·proto-buffer·kotlin-native
轩哥.3 小时前
Android控件底色蓝色无法修改、高版本无法安装app、找不到xml、找不到java文件、目录不显示等问题
android
PzZzang24 小时前
zabbix2.0
android·adb
etcix4 小时前
分多个AndroidManifest.xml来控制项目编译
android·xml
pengyu5 小时前
系统化掌握Dart编程之面向对象分析
android·flutter·dart
飘飘燃雪6 小时前
Windows配置adb
android·windows·adb