(一百四十九)Android P WificondControl的setupInterfaceForClientMode

本文主要是介绍(一百四十九)Android P WificondControl的setupInterfaceForClientMode,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.回顾

之前在(一百四十八)Android P wifi启动过程中的sta interface创建 中梳理了sta interface的创建流程,之后还有

           if (mWificondControl.setupInterfaceForClientMode(iface.name) == null) {Log.e(TAG, "Failed to setup iface in wificond on " + iface);teardownInterface(iface.name);mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToWificond();return null;}if (!mSupplicantStaIfaceHal.setupIface(iface.name)) {Log.e(TAG, "Failed to setup iface in supplicant on " + iface);teardownInterface(iface.name);mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToSupplicant();return null;}

先梳理下WificondControl的setupInterfaceForClientMode

 

2.流程梳理

WificondControl

    /*** Setup interface for client mode via wificond.* @return An IClientInterface as wificond client interface binder handler.* Returns null on failure.*/public IClientInterface setupInterfaceForClientMode(@NonNull String ifaceName) {Log.d(TAG, "Setting up interface for client mode");if (!retrieveWificondAndRegisterForDeath()) {return null;}IClientInterface clientInterface = null;try {clientInterface = mWificond.createClientInterface(ifaceName);} catch (RemoteException e1) {Log.e(TAG, "Failed to get IClientInterface due to remote exception");return null;}if (clientInterface == null) {Log.e(TAG, "Could not get IClientInterface instance from wificond");return null;}Binder.allowBlocking(clientInterface.asBinder());// Refresh HandlersmClientInterfaces.put(ifaceName, clientInterface);try {IWifiScannerImpl wificondScanner = clientInterface.getWifiScannerImpl();if (wificondScanner == null) {Log.e(TAG, "Failed to get WificondScannerImpl");return null;}mWificondScanners.put(ifaceName, wificondScanner);Binder.allowBlocking(wificondScanner.asBinder());ScanEventHandler scanEventHandler = new ScanEventHandler(ifaceName);mScanEventHandlers.put(ifaceName,  scanEventHandler);wificondScanner.subscribeScanEvents(scanEventHandler);PnoScanEventHandler pnoScanEventHandler = new PnoScanEventHandler(ifaceName);mPnoScanEventHandlers.put(ifaceName,  pnoScanEventHandler);wificondScanner.subscribePnoScanEvents(pnoScanEventHandler);} catch (RemoteException e) {Log.e(TAG, "Failed to refresh wificond scanner due to remote exception");}return clientInterface;}

system/connectivity/wificond/server.cpp

Status Server::createClientInterface(const std::string& iface_name,sp<IClientInterface>* created_interface) {InterfaceInfo interface;if (!SetupInterface(iface_name, &interface)) {return Status::ok();  // Logging was done internally}unique_ptr<ClientInterfaceImpl> client_interface(new ClientInterfaceImpl(wiphy_index_,interface.name,interface.index,interface.mac_address,if_tool_.get(),netlink_utils_,scan_utils_));*created_interface = client_interface->GetBinder();BroadcastClientInterfaceReady(client_interface->GetBinder());client_interfaces_[iface_name] = std::move(client_interface);return Status::ok();
}bool Server::SetupInterface(const std::string& iface_name,InterfaceInfo* interface) {if (!RefreshWiphyIndex()) {return false;}netlink_utils_->SubscribeRegDomainChange(wiphy_index_,std::bind(&Server::OnRegDomainChanged,this,_1));interfaces_.clear();if (!netlink_utils_->GetInterfaces(wiphy_index_, &interfaces_)) {LOG(ERROR) << "Failed to get interfaces info from kernel";return false;}for (const auto& iface : interfaces_) {if (iface.name == iface_name) {*interface = iface;return true;}}LOG(ERROR) << "No usable interface found";return false;
}

这边会从kernel获取所有的interface,然后对照name看有没有对应的,如果有的话,返回一个对应的iface.

看下interfaces是何时初始化的

netlink_utils_

bool NetlinkUtils::GetInterfaces(uint32_t wiphy_index,vector<InterfaceInfo>* interface_info) {NL80211Packet get_interfaces(netlink_manager_->GetFamilyId(),NL80211_CMD_GET_INTERFACE,netlink_manager_->GetSequenceNumber(),getpid());get_interfaces.AddFlag(NLM_F_DUMP);get_interfaces.AddAttribute(NL80211Attr<uint32_t>(NL80211_ATTR_WIPHY, wiphy_index));vector<unique_ptr<const NL80211Packet>> response;if (!netlink_manager_->SendMessageAndGetResponses(get_interfaces, &response)) {LOG(ERROR) << "NL80211_CMD_GET_INTERFACE dump failed";return false;}if (response.empty()) {LOG(ERROR) << "No interface is found";return false;}for (auto& packet : response) {if (packet->GetMessageType() == NLMSG_ERROR) {LOG(ERROR) << "Receive ERROR message: "<< strerror(packet->GetErrorCode());return false;}if (packet->GetMessageType() != netlink_manager_->GetFamilyId()) {LOG(ERROR) << "Wrong message type for new interface message: "<< packet->GetMessageType();return false;}if (packet->GetCommand() != NL80211_CMD_NEW_INTERFACE) {LOG(ERROR) << "Wrong command in response to "<< "an interface dump request: "<< static_cast<int>(packet->GetCommand());return false;}// In some situations, it has been observed that the kernel tells us// about a pseudo interface that does not have a real netdev.  In this// case, responses will have a NL80211_ATTR_WDEV, and not the expected// IFNAME/IFINDEX. In this case we just skip these pseudo interfaces.uint32_t if_index;if (!packet->GetAttributeValue(NL80211_ATTR_IFINDEX, &if_index)) {LOG(DEBUG) << "Failed to get interface index";continue;}// Today we don't check NL80211_ATTR_IFTYPE because at this point of time// driver always reports that interface is in STATION mode. Even when we// are asking interfaces infomation on behalf of tethering, it is still so// because hostapd is supposed to set interface to AP mode later.string if_name;if (!packet->GetAttributeValue(NL80211_ATTR_IFNAME, &if_name)) {LOG(WARNING) << "Failed to get interface name";continue;}vector<uint8_t> if_mac_addr;if (!packet->GetAttributeValue(NL80211_ATTR_MAC, &if_mac_addr)) {LOG(WARNING) << "Failed to get interface mac address";continue;}interface_info->emplace_back(if_index, if_name, if_mac_addr);}return true;
}

通过netlink_manager_发送包,然后依次解析返回回来的包得到if_index/if_name/if_mac_addr压栈到interface_info,最后封装成一个client_interface

这流程很熟悉,之前在(五十七)Android O WiFi的扫描流程梳理续——梳理java与c++之间的aidl-cpp通信 梳理过

这边相当于搭好了从上到kernel的通信道路,这时sta iface应该已经确实创建好了,感觉中间哪里看漏了一步。

 

3.总结

WificondControl的setupInterfaceForClientMode看起来就是在wificond初始化一下interface的通信,获取可以和kernel通信的接口,方便下发scan命令

 

这篇关于(一百四十九)Android P WificondControl的setupInterfaceForClientMode的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/511398

相关文章

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

Android kotlin语言实现删除文件的解决方案

《Androidkotlin语言实现删除文件的解决方案》:本文主要介绍Androidkotlin语言实现删除文件的解决方案,在项目开发过程中,尤其是需要跨平台协作的项目,那么删除用户指定的文件的... 目录一、前言二、适用环境三、模板内容1.权限申请2.Activity中的模板一、前言在项目开发过程中,尤

Android数据库Room的实际使用过程总结

《Android数据库Room的实际使用过程总结》这篇文章主要给大家介绍了关于Android数据库Room的实际使用过程,详细介绍了如何创建实体类、数据访问对象(DAO)和数据库抽象类,需要的朋友可以... 目录前言一、Room的基本使用1.项目配置2.创建实体类(Entity)3.创建数据访问对象(DAO

Android WebView的加载超时处理方案

《AndroidWebView的加载超时处理方案》在Android开发中,WebView是一个常用的组件,用于在应用中嵌入网页,然而,当网络状况不佳或页面加载过慢时,用户可能会遇到加载超时的问题,本... 目录引言一、WebView加载超时的原因二、加载超时处理方案1. 使用Handler和Timer进行超

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

Android平台播放RTSP流的几种方案探究(VLC VS ExoPlayer VS SmartPlayer)

技术背景 好多开发者需要遴选Android平台RTSP直播播放器的时候,不知道如何选的好,本文针对常用的方案,做个大概的说明: 1. 使用VLC for Android VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影

android-opencv-jni

//------------------start opencv--------------------@Override public void onResume(){ super.onResume(); //通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是 //OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk