Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35d958c4 authored by Roshan Pius's avatar Roshan Pius
Browse files

wifi: Add Iface related method implementations in WifiChip

Add the iface creation/retrieval/list method implementations in WifiChip.
WifiChip does not yet support the chip mode configuration. So, all
|createIface| method calls succeed today. Once the mode configuration
changes are in place, we will deny iface creation requests depending on
the iface combination supported in the current mode.

The iface objects are all invalidated and deleted on mode switches and
when HAL is stopped.

While there,
Change the |callbacks_| member to std::vector instead of std::set. We
don't really need a set to store the list of callbacks.

Bug: 31943042
Test: Compiles
Change-Id: Ic94864c8b11aabbe569b5157d68d6056364a3c4c
parent 3e2d671a
Loading
Loading
Loading
Loading
+217 −9
Original line number Diff line number Diff line
@@ -20,6 +20,32 @@

#include "failure_reason_util.h"

namespace {
using android::sp;
using android::hardware::hidl_vec;
using android::hardware::hidl_string;

hidl_vec<hidl_string> createHidlVecOfIfaceNames(const std::string& ifname) {
  std::vector<hidl_string> ifnames;
  if (!ifname.empty()) {
    hidl_string hidl_ifname;
    hidl_ifname = ifname.c_str();
    ifnames.emplace_back(hidl_ifname);
  }
  hidl_vec<hidl_string> hidl_ifnames;
  hidl_ifnames.setToExternal(ifnames.data(), ifnames.size());
  return hidl_ifnames;
}

template <typename Iface>
void invalidateAndClear(sp<Iface>& iface) {
  if (iface.get()) {
    iface->invalidate();
    iface.clear();
  }
}
}  // namepsace

namespace android {
namespace hardware {
namespace wifi {
@@ -28,11 +54,13 @@ namespace implementation {

WifiChip::WifiChip(ChipId chip_id,
                   const std::weak_ptr<WifiLegacyHal> legacy_hal)
    : chip_id_(chip_id), legacy_hal_(legacy_hal) {}
    : chip_id_(chip_id), legacy_hal_(legacy_hal), is_valid_(true) {}

void WifiChip::invalidate() {
  invalidateAndRemoveAllIfaces();
  legacy_hal_.reset();
  callbacks_.clear();
  is_valid_ = false;
}

Return<ChipId> WifiChip::getId() {
@@ -41,15 +69,15 @@ Return<ChipId> WifiChip::getId() {

Return<void> WifiChip::registerEventCallback(
    const sp<IWifiChipEventCallback>& callback) {
  if (!legacy_hal_.lock())
  if (!is_valid_)
    return Void();
  // TODO(b/31632518): remove the callback when the client is destroyed
  callbacks_.insert(callback);
  callbacks_.emplace_back(callback);
  return Void();
}

Return<void> WifiChip::getAvailableModes(getAvailableModes_cb cb) {
  if (!legacy_hal_.lock()) {
  if (!is_valid_) {
    cb(hidl_vec<ChipMode>());
    return Void();
  } else {
@@ -59,21 +87,23 @@ Return<void> WifiChip::getAvailableModes(getAvailableModes_cb cb) {
}

Return<void> WifiChip::configureChip(uint32_t /*mode_id*/) {
  if (!legacy_hal_.lock())
  if (!is_valid_)
    return Void();

  invalidateAndRemoveAllIfaces();
  // TODO add implementation
  return Void();
}

Return<uint32_t> WifiChip::getMode() {
  if (!legacy_hal_.lock())
  if (!is_valid_)
    return 0;
  // TODO add implementation
  return 0;
}

Return<void> WifiChip::requestChipDebugInfo() {
  if (!legacy_hal_.lock())
  if (!is_valid_)
    return Void();

  IWifiChipEventCallback::ChipDebugInfo result;
@@ -102,7 +132,7 @@ Return<void> WifiChip::requestChipDebugInfo() {
}

Return<void> WifiChip::requestDriverDebugDump() {
  if (!legacy_hal_.lock())
  if (!is_valid_)
    return Void();

  std::pair<wifi_error, std::vector<char>> ret =
@@ -124,7 +154,7 @@ Return<void> WifiChip::requestDriverDebugDump() {
}

Return<void> WifiChip::requestFirmwareDebugDump() {
  if (!legacy_hal_.lock())
  if (!is_valid_)
    return Void();

  std::pair<wifi_error, std::vector<char>> ret =
@@ -145,6 +175,184 @@ Return<void> WifiChip::requestFirmwareDebugDump() {
  return Void();
}

Return<void> WifiChip::createApIface(createApIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  // TODO(b/31997422): Disallow this based on the chip combination.
  std::string ifname = legacy_hal_.lock()->getApIfaceName();
  ap_iface_ = new WifiApIface(ifname, legacy_hal_);
  cb(ap_iface_);
  return Void();
}

Return<void> WifiChip::getApIfaceNames(getApIfaceNames_cb cb) {
  if (!is_valid_) {
    cb(hidl_vec<hidl_string>());
    return Void();
  }

  std::string ifname;
  if (ap_iface_.get()) {
    ifname = legacy_hal_.lock()->getApIfaceName().c_str();
  }
  cb(createHidlVecOfIfaceNames(ifname));
  return Void();
}

Return<void> WifiChip::getApIface(const hidl_string& ifname, getApIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  if (ap_iface_.get() &&
      (ifname.c_str() == legacy_hal_.lock()->getApIfaceName())) {
    cb(ap_iface_);
  } else {
    cb(nullptr);
  }
  return Void();
}

Return<void> WifiChip::createNanIface(createNanIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  // TODO(b/31997422): Disallow this based on the chip combination.
  std::string ifname = legacy_hal_.lock()->getNanIfaceName();
  nan_iface_ = new WifiNanIface(ifname, legacy_hal_);
  cb(nan_iface_);
  return Void();
}

Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb cb) {
  if (!is_valid_) {
    cb(hidl_vec<hidl_string>());
    return Void();
  }

  std::string ifname;
  if (nan_iface_.get()) {
    ifname = legacy_hal_.lock()->getNanIfaceName().c_str();
  }
  cb(createHidlVecOfIfaceNames(ifname));
  return Void();
}

Return<void> WifiChip::getNanIface(const hidl_string& ifname,
                                   getNanIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  if (nan_iface_.get() &&
      (ifname.c_str() == legacy_hal_.lock()->getNanIfaceName())) {
    cb(nan_iface_);
  } else {
    cb(nullptr);
  }
  return Void();
}

Return<void> WifiChip::createP2pIface(createP2pIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  // TODO(b/31997422): Disallow this based on the chip combination.
  std::string ifname = legacy_hal_.lock()->getP2pIfaceName();
  p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_);
  cb(p2p_iface_);
  return Void();
}

Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb cb) {
  if (!is_valid_) {
    cb(hidl_vec<hidl_string>());
    return Void();
  }

  std::string ifname;
  if (p2p_iface_.get()) {
    ifname = legacy_hal_.lock()->getP2pIfaceName().c_str();
  }
  cb(createHidlVecOfIfaceNames(ifname));
  return Void();
}

Return<void> WifiChip::getP2pIface(const hidl_string& ifname,
                                   getP2pIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  if (p2p_iface_.get() &&
      (ifname.c_str() == legacy_hal_.lock()->getP2pIfaceName())) {
    cb(p2p_iface_);
  } else {
    cb(nullptr);
  }
  return Void();
}

Return<void> WifiChip::createStaIface(createStaIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  // TODO(b/31997422): Disallow this based on the chip combination.
  std::string ifname = legacy_hal_.lock()->getStaIfaceName();
  sta_iface_ = new WifiStaIface(ifname, legacy_hal_);
  cb(sta_iface_);
  return Void();
}

Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb cb) {
  if (!is_valid_) {
    cb(hidl_vec<hidl_string>());
    return Void();
  }

  std::string ifname;
  if (sta_iface_.get()) {
    ifname = legacy_hal_.lock()->getStaIfaceName().c_str();
  }
  cb(createHidlVecOfIfaceNames(ifname));
  return Void();
}

Return<void> WifiChip::getStaIface(const hidl_string& ifname,
                                   getStaIface_cb cb) {
  if (!is_valid_) {
    cb(nullptr);
    return Void();
  }

  if (sta_iface_.get() &&
      (ifname.c_str() == legacy_hal_.lock()->getStaIfaceName())) {
    cb(sta_iface_);
  } else {
    cb(nullptr);
  }
  return Void();
}

void WifiChip::invalidateAndRemoveAllIfaces() {
  invalidateAndClear(ap_iface_);
  invalidateAndClear(nan_iface_);
  invalidateAndClear(p2p_iface_);
  invalidateAndClear(sta_iface_);
}

}  // namespace implementation
}  // namespace V1_0
}  // namespace wifi
+28 −2
Original line number Diff line number Diff line
@@ -17,12 +17,16 @@
#ifndef WIFI_CHIP_H_
#define WIFI_CHIP_H_

#include <set>
#include <map>

#include <android-base/macros.h>
#include <android/hardware/wifi/1.0/IWifiChip.h>

#include "wifi_ap_iface.h"
#include "wifi_legacy_hal.h"
#include "wifi_nan_iface.h"
#include "wifi_p2p_iface.h"
#include "wifi_sta_iface.h"

namespace android {
namespace hardware {
@@ -63,11 +67,33 @@ class WifiChip : public IWifiChip {
  Return<void> requestChipDebugInfo() override;
  Return<void> requestDriverDebugDump() override;
  Return<void> requestFirmwareDebugDump() override;
  Return<void> createApIface(createApIface_cb cb) override;
  Return<void> getApIfaceNames(getApIfaceNames_cb cb) override;
  Return<void> getApIface(const hidl_string& ifname, getApIface_cb cb) override;
  Return<void> createNanIface(createNanIface_cb cb) override;
  Return<void> getNanIfaceNames(getNanIfaceNames_cb cb) override;
  Return<void> getNanIface(const hidl_string& ifname,
                           getNanIface_cb cb) override;
  Return<void> createP2pIface(createP2pIface_cb cb) override;
  Return<void> getP2pIfaceNames(getP2pIfaceNames_cb cb) override;
  Return<void> getP2pIface(const hidl_string& ifname,
                           getP2pIface_cb cb) override;
  Return<void> createStaIface(createStaIface_cb cb) override;
  Return<void> getStaIfaceNames(getStaIfaceNames_cb cb) override;
  Return<void> getStaIface(const hidl_string& ifname,
                           getStaIface_cb cb) override;

 private:
  void invalidateAndRemoveAllIfaces();

  ChipId chip_id_;
  std::weak_ptr<WifiLegacyHal> legacy_hal_;
  std::set<sp<IWifiChipEventCallback>> callbacks_;
  std::vector<sp<IWifiChipEventCallback>> callbacks_;
  sp<WifiApIface> ap_iface_;
  sp<WifiNanIface> nan_iface_;
  sp<WifiP2pIface> p2p_iface_;
  sp<WifiStaIface> sta_iface_;
  bool is_valid_;

  DISALLOW_COPY_AND_ASSIGN(WifiChip);
};