Android O wifi turn on -- start supplicant

Android O wifi turn on -- load driver后续

1. frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java

    class InitialState extends State {
...
        public boolean processMessage(Message message) {
            logStateAndMessage(message, this);
            switch (message.what) {
                case CMD_START_SUPPLICANT:
...
                    if (!mWifiNative.enableSupplicant()) {
...
}

2. frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java

    public boolean enableSupplicant() {
        return mWificondControl.enableSupplicant();
    }

3. frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java

    public boolean enableSupplicant() {
        if (mClientInterface == null) {
            Log.e(TAG, "No valid wificond client interface handler");
            return false;
        }

        try {
            return mClientInterface.enableSupplicant();
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to enable supplicant due to remote exception");
        }
        return false;
    }

4. system/connectivity/wificond/client_interface_binder.cpp

Status ClientInterfaceBinder::enableSupplicant(bool* success) {
  *success = impl_ && impl_->EnableSupplicant();
  return Status::ok();
}

5. system/connectivity/wificond/client_interface_impl.cpp

bool ClientInterfaceImpl::EnableSupplicant() {
  return supplicant_manager_->StartSupplicant();
}

6. frameworks/opt/net/wifi/libwifi_system/supplicant_manager.cpp

bool SupplicantManager::StartSupplicant() {
  char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
  int count = 200; /* wait at most 20 seconds for completion */
  const prop_info* pi;
  unsigned serial = 0;

  /* Check whether already running */
  if (property_get(kSupplicantInitProperty, supp_status, NULL) &&
      strcmp(supp_status, "running") == 0) {
    return true;
  }
....
}

 

分析:

1.WificondControl.java与wificond

2. wificond与libwifi_system

WifiCondControl.java

   public IClientInterface setupDriverForClientMode() {

        mWificond = mWifiInjector.makeWificond();
        if (mWificond == null) {
            Log.e(TAG, "Failed to get reference to wificond");
            return null;
        }

        IClientInterface clientInterface = null;
        try {
            clientInterface = mWificond.createClientInterface();
        } 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 Handlers
        mClientInterface = clientInterface;
...
}


WifiInjector.java
    private static final String WIFICOND_SERVICE_NAME = "wificond";

    public IWificond makeWificond() {
        // We depend on being able to refresh our binder in WifiStateMachine, so don't cache it.
        IBinder binder = ServiceManager.getService(WIFICOND_SERVICE_NAME);
        return IWificond.Stub.asInterface(binder);
    }

wificond.rc
service wificond /system/bin/wificond
    class main
    user wifi
    group wifi net_raw net_admin

system/connectivity/wificond/aidl/android/net/wifi/IWificond.aidl

    @nullable IClientInterface createClientInterface();

 

wificond/Main.cpp
int main(int argc, char** argv) {
  android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
  LOG(INFO) << "wificond is starting up...";

...
  android::wificond::NetlinkManager netlink_manager(event_dispatcher.get());
  if (!netlink_manager.Start()) {
    LOG(ERROR) << "Failed to start netlink manager";
  }
  android::wificond::NetlinkUtils netlink_utils(&netlink_manager);
  android::wificond::ScanUtils scan_utils(&netlink_manager);
  unique_ptr<android::wificond::Server> server(new android::wificond::Server(
      unique_ptr<InterfaceTool>(new InterfaceTool),
      unique_ptr<SupplicantManager>(new SupplicantManager()),
      unique_ptr<HostapdManager>(new HostapdManager()),
      &netlink_utils,
      &scan_utils));
  server->CleanUpSystemState();
  RegisterServiceOrCrash(server.get());

  event_dispatcher->Poll();
...
}

void RegisterServiceOrCrash(const android::sp<android::IBinder>& service) {
  android::sp<android::IServiceManager> sm = android::defaultServiceManager();
  CHECK_EQ(sm != NULL, true) << "Could not obtain IServiceManager";

  CHECK_EQ(sm->addService(android::String16(kServiceName), service),
           android::NO_ERROR);
}

 

wificond/Server.cpp
Server::Server(unique_ptr<InterfaceTool> if_tool,
               unique_ptr<SupplicantManager> supplicant_manager,
               unique_ptr<HostapdManager> hostapd_manager,
               NetlinkUtils* netlink_utils,
               ScanUtils* scan_utils)
    : if_tool_(std::move(if_tool)),
      supplicant_manager_(std::move(supplicant_manager)),
      hostapd_manager_(std::move(hostapd_manager)),
      netlink_utils_(netlink_utils),
      scan_utils_(scan_utils) {
}

Status Server::createClientInterface(sp<IClientInterface>* created_interface) {
  InterfaceInfo interface;
  if (!SetupInterface(&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(),
      supplicant_manager_.get(),
      netlink_utils_,
      scan_utils_));

  *created_interface = client_interface->GetBinder();
  client_interfaces_.push_back(std::move(client_interface));
  BroadcastClientInterfaceReady(client_interfaces_.back()->GetBinder());

  return Status::ok();
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值