欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

(八十一)探索hidl-gen使用及IWifi.hal 实现

程序员文章站 2022-06-08 20:42:48
...

1.文件路径

/hardware/interfaces/wifi/1.0/IWifi.hal

/*
 * Copyright 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package aaa@qq.com;

import IWifiChip;
import IWifiEventCallback;

/**
 * This is the root of the HAL module and is the interface returned when
 * loading an implementation of the Wi-Fi HAL. There must be at most one
 * module loaded in the system.
 */
interface IWifi {
  /**
   * Requests notifications of significant events for the HAL. Multiple calls to
   * this must register multiple callbacks each of which must receive all
   * events. |IWifiEventCallback| object registration must be independent of the
   * state of the rest of the HAL and must persist though stops/starts. These
   * objects must be deleted when the corresponding client process is dead.
   *
   * @param callback An instance of the |IWifiEventCallback| HIDL interface
   *        object.
   * @return status WifiStatus of the operation.
   *         Possible status codes:
   *         |WifiStatusCode.SUCCESS|,
   *         |WifiStatusCode.UNKNOWN|
   */
  @entry
  @callflow(next={"*"})
  registerEventCallback(IWifiEventCallback callback)
      generates (WifiStatus status);

  /**
   * Get the current state of the HAL.
   *
   * @return started true if started, false otherwise.
   */
  isStarted() generates (bool started);

  /**
   * Perform any setup that is required to make use of the module. If the module
   * is already started then this must be a noop.
   * Must trigger |IWifiEventCallback.onStart| on success.
   *
   * @return status WifiStatus of the operation.
   *         Possible status codes:
   *         |WifiStatusCode.SUCCESS|,
   *         |WifiStatusCode.NOT_AVAILABLE|,
   *         |WifiStatusCode.UNKNOWN|
   */
  @entry
  @callflow(next={"registerEventCallback", "start", "stop", "getChip"})
  start() generates (WifiStatus status);

  /**
   * Tear down any state, ongoing commands, etc. If the module is already
   * stopped then this must be a noop. If the HAL is already stopped or it
   * succeeds then onStop must be called. After calling this all IWifiChip
   * objects will be considered invalid.
   * Must trigger |IWifiEventCallback.onStop| on success.
   * Must trigger |IWifiEventCallback.onFailure| on failure.
   *
   * Calling stop then start is a valid way of resetting state in the HAL,
   * driver, firmware.
   *
   * @return status WifiStatus of the operation.
   *         Possible status codes:
   *         |WifiStatusCode.SUCCESS|,
   *         |WifiStatusCode.NOT_STARTED|,
   *         |WifiStatusCode.UNKNOWN|
   */
  @exit
  @callflow(next={"registerEventCallback", "start", "stop"})
  stop() generates (WifiStatus status);

  /**
   * Retrieve the list of all chip Id's on the device.
   * The corresponding |IWifiChip| object for any chip can be
   * retrieved using |getChip| method.
   *
   * @return status WifiStatus of the operation.
   *         Possible status codes:
   *         |WifiStatusCode.SUCCESS|,
   *         |WifiStatusCode.NOT_STARTED|,
   *         |WifiStatusCode.UNKNOWN|
   * @return chipIds List of all chip Id's on the device.
   */
  @callflow(next={"*"})
  getChipIds() generates (WifiStatus status, vec<ChipId> chipIds);

  /**
   * Gets a HIDL interface object for the chip corresponding to the
   * provided chipId.
   *
   * @return status WifiStatus of the operation.
   *         Possible status codes:
   *         |WifiStatusCode.SUCCESS|,
   *         |WifiStatusCode.NOT_STARTED|,
   *         |WifiStatusCode.UNKNOWN|
   * @return chip HIDL interface object representing the chip.
   */
  @callflow(next={"*"})
  getChip(ChipId chipId) generates (WifiStatus status, IWifiChip chip);
};

看起来也挺简单的,就是定义了一些未实现的接口,和接口定义差不多。

 

2.对应Android.bp文件

// This file is autogenerated by hidl-gen. Do not edit manually.

filegroup {
    name: "aaa@qq.com_hal",
    srcs: [
        "types.hal",
        "IWifi.hal",
        "IWifiApIface.hal",
        "IWifiChip.hal",
        "IWifiChipEventCallback.hal",
        "IWifiEventCallback.hal",
        "IWifiIface.hal",
        "IWifiNanIface.hal",
        "IWifiNanIfaceEventCallback.hal",
        "IWifiP2pIface.hal",
        "IWifiRttController.hal",
        "IWifiRttControllerEventCallback.hal",
        "IWifiStaIface.hal",
        "IWifiStaIfaceEventCallback.hal",
    ],
}

genrule {
    name: "aaa@qq.com_genc++",
    tools: ["hidl-gen"],
    cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport aaa@qq.com",
    srcs: [
        ":aaa@qq.com_hal",
    ],
    out: [
        "android/hardware/wifi/1.0/types.cpp",
        "android/hardware/wifi/1.0/WifiAll.cpp",
        "android/hardware/wifi/1.0/WifiApIfaceAll.cpp",
        "android/hardware/wifi/1.0/WifiChipAll.cpp",
        "android/hardware/wifi/1.0/WifiChipEventCallbackAll.cpp",
        "android/hardware/wifi/1.0/WifiEventCallbackAll.cpp",
        "android/hardware/wifi/1.0/WifiIfaceAll.cpp",
        "android/hardware/wifi/1.0/WifiNanIfaceAll.cpp",
        "android/hardware/wifi/1.0/WifiNanIfaceEventCallbackAll.cpp",
        "android/hardware/wifi/1.0/WifiP2pIfaceAll.cpp",
        "android/hardware/wifi/1.0/WifiRttControllerAll.cpp",
        "android/hardware/wifi/1.0/WifiRttControllerEventCallbackAll.cpp",
        "android/hardware/wifi/1.0/WifiStaIfaceAll.cpp",
        "android/hardware/wifi/1.0/WifiStaIfaceEventCallbackAll.cpp",
    ],
}

genrule {
    name: "aaa@qq.com_genc++_headers",
    tools: ["hidl-gen"],
    cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport aaa@qq.com",
    srcs: [
        ":aaa@qq.com_hal",
    ],
    out: [
        "android/hardware/wifi/1.0/types.h",
        "android/hardware/wifi/1.0/hwtypes.h",
        "android/hardware/wifi/1.0/IWifi.h",
        "android/hardware/wifi/1.0/IHwWifi.h",
        "android/hardware/wifi/1.0/BnHwWifi.h",
        "android/hardware/wifi/1.0/BpHwWifi.h",
        "android/hardware/wifi/1.0/BsWifi.h",
        "android/hardware/wifi/1.0/IWifiApIface.h",
        "android/hardware/wifi/1.0/IHwWifiApIface.h",
        "android/hardware/wifi/1.0/BnHwWifiApIface.h",
        "android/hardware/wifi/1.0/BpHwWifiApIface.h",
        "android/hardware/wifi/1.0/BsWifiApIface.h",
        "android/hardware/wifi/1.0/IWifiChip.h",
        "android/hardware/wifi/1.0/IHwWifiChip.h",
        "android/hardware/wifi/1.0/BnHwWifiChip.h",
        "android/hardware/wifi/1.0/BpHwWifiChip.h",
        "android/hardware/wifi/1.0/BsWifiChip.h",
        "android/hardware/wifi/1.0/IWifiChipEventCallback.h",
        "android/hardware/wifi/1.0/IHwWifiChipEventCallback.h",
        "android/hardware/wifi/1.0/BnHwWifiChipEventCallback.h",
        "android/hardware/wifi/1.0/BpHwWifiChipEventCallback.h",
        "android/hardware/wifi/1.0/BsWifiChipEventCallback.h",
        "android/hardware/wifi/1.0/IWifiEventCallback.h",
        "android/hardware/wifi/1.0/IHwWifiEventCallback.h",
        "android/hardware/wifi/1.0/BnHwWifiEventCallback.h",
        "android/hardware/wifi/1.0/BpHwWifiEventCallback.h",
        "android/hardware/wifi/1.0/BsWifiEventCallback.h",
        "android/hardware/wifi/1.0/IWifiIface.h",
        "android/hardware/wifi/1.0/IHwWifiIface.h",
        "android/hardware/wifi/1.0/BnHwWifiIface.h",
        "android/hardware/wifi/1.0/BpHwWifiIface.h",
        "android/hardware/wifi/1.0/BsWifiIface.h",
        "android/hardware/wifi/1.0/IWifiNanIface.h",
        "android/hardware/wifi/1.0/IHwWifiNanIface.h",
        "android/hardware/wifi/1.0/BnHwWifiNanIface.h",
        "android/hardware/wifi/1.0/BpHwWifiNanIface.h",
        "android/hardware/wifi/1.0/BsWifiNanIface.h",
        "android/hardware/wifi/1.0/IWifiNanIfaceEventCallback.h",
        "android/hardware/wifi/1.0/IHwWifiNanIfaceEventCallback.h",
        "android/hardware/wifi/1.0/BnHwWifiNanIfaceEventCallback.h",
        "android/hardware/wifi/1.0/BpHwWifiNanIfaceEventCallback.h",
        "android/hardware/wifi/1.0/BsWifiNanIfaceEventCallback.h",
        "android/hardware/wifi/1.0/IWifiP2pIface.h",
        "android/hardware/wifi/1.0/IHwWifiP2pIface.h",
        "android/hardware/wifi/1.0/BnHwWifiP2pIface.h",
        "android/hardware/wifi/1.0/BpHwWifiP2pIface.h",
        "android/hardware/wifi/1.0/BsWifiP2pIface.h",
        "android/hardware/wifi/1.0/IWifiRttController.h",
        "android/hardware/wifi/1.0/IHwWifiRttController.h",
        "android/hardware/wifi/1.0/BnHwWifiRttController.h",
        "android/hardware/wifi/1.0/BpHwWifiRttController.h",
        "android/hardware/wifi/1.0/BsWifiRttController.h",
        "android/hardware/wifi/1.0/IWifiRttControllerEventCallback.h",
        "android/hardware/wifi/1.0/IHwWifiRttControllerEventCallback.h",
        "android/hardware/wifi/1.0/BnHwWifiRttControllerEventCallback.h",
        "android/hardware/wifi/1.0/BpHwWifiRttControllerEventCallback.h",
        "android/hardware/wifi/1.0/BsWifiRttControllerEventCallback.h",
        "android/hardware/wifi/1.0/IWifiStaIface.h",
        "android/hardware/wifi/1.0/IHwWifiStaIface.h",
        "android/hardware/wifi/1.0/BnHwWifiStaIface.h",
        "android/hardware/wifi/1.0/BpHwWifiStaIface.h",
        "android/hardware/wifi/1.0/BsWifiStaIface.h",
        "android/hardware/wifi/1.0/IWifiStaIfaceEventCallback.h",
        "android/hardware/wifi/1.0/IHwWifiStaIfaceEventCallback.h",
        "android/hardware/wifi/1.0/BnHwWifiStaIfaceEventCallback.h",
        "android/hardware/wifi/1.0/BpHwWifiStaIfaceEventCallback.h",
        "android/hardware/wifi/1.0/BsWifiStaIfaceEventCallback.h",
    ],
}

cc_library {
    name: "aaa@qq.com",
    defaults: ["hidl-module-defaults"],
    generated_sources: ["aaa@qq.com_genc++"],
    generated_headers: ["aaa@qq.com_genc++_headers"],
    export_generated_headers: ["aaa@qq.com_genc++_headers"],
    vendor_available: true,
    vndk: {
        enabled: true,
    },
    shared_libs: [
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
        "liblog",
        "libutils",
        "libcutils",
    ],
    export_shared_lib_headers: [
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
        "libutils",
    ],
}

简单地看下这个Android.bp文件:

filegroup-"aaa@qq.com_hal":包含了该目录下所有的hal文件

genrule-"aaa@qq.com_genc++":使用上面的filegroup作为src编译出对应的cpp文件

genrule-"aaa@qq.com_genc++_headers":使用上面的filegroup作为src编译出对应的.h文件

之后下面的抬头“aaa@qq.com”经常看到,调用到wifi hal的都会声明到这个。

cc_library {
    name: "aaa@qq.com",
    defaults: ["hidl-module-defaults"],
    generated_sources: ["aaa@qq.com_genc++"],
    generated_headers: ["aaa@qq.com_genc++_headers"],
    export_generated_headers: ["aaa@qq.com_genc++_headers"],
    vendor_available: true,
    vndk: {
        enabled: true,
    },
    shared_libs: [
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
        "liblog",
        "libutils",
        "libcutils",
    ],
    export_shared_lib_headers: [
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
        "libutils",
    ],
}

 

2.1 hidl-gen

注意到Android.bp文件中有如下命令是可以生成对应资源的,试一试。

cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport aaa@qq.com"

先期准备

1)source build/envsetup.sh

2)lunch

3)make hidl-gen -j4

//[100% 460/460] Install: out/host/linux-x86/bin/hidl-gen

(八十一)探索hidl-gen使用及IWifi.hal 实现

 

2.1.1 生成c++-sources

cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport aaa@qq.com"

(八十一)探索hidl-gen使用及IWifi.hal 实现

 

2.1.2 生成c++-headers

cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport aaa@qq.com"

(八十一)探索hidl-gen使用及IWifi.hal 实现

 

2.1.3 生成Android.bp

cmd: "$(location hidl-gen) -o $(genDir) -Landroidbp -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport aaa@qq.com"

(八十一)探索hidl-gen使用及IWifi.hal 实现

生成的Android.bp文件是和之前一摸一样的。

2.1.4 生成Android.mk

(八十一)探索hidl-gen使用及IWifi.hal 实现

 

2.1.5 生成androidbp-impl

 hidl-gen -o ./test_hidl_wifi/ -Landroidbp-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport aaa@qq.com

cc_library_shared {
    name: "aaa@qq.com",
    relative_install_path: "hw",
    proprietary: true,
    srcs: [
        "Wifi.cpp",
        "WifiApIface.cpp",
        "WifiChip.cpp",
        "WifiChipEventCallback.cpp",
        "WifiEventCallback.cpp",
        "WifiIface.cpp",
        "WifiNanIface.cpp",
        "WifiNanIfaceEventCallback.cpp",
        "WifiP2pIface.cpp",
        "WifiRttController.cpp",
        "WifiRttControllerEventCallback.cpp",
        "WifiStaIface.cpp",
        "WifiStaIfaceEventCallback.cpp",
    ],
    shared_libs: [
        "libhidlbase",
        "libhidltransport",
        "libutils",
        "aaa@qq.com",
    ],
}

 

2.1.6 生成c++-impl

(八十一)探索hidl-gen使用及IWifi.hal 实现生成HIDL的默认实现。

看下Wifi.h和Wifi.cpp

#ifndef ANDROID_HARDWARE_WIFI_V1_0_WIFI_H
#define ANDROID_HARDWARE_WIFI_V1_0_WIFI_H

#include <android/hardware/wifi/1.0/IWifi.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>

namespace android {
namespace hardware {
namespace wifi {
namespace V1_0 {
namespace implementation {

using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;

struct Wifi : public IWifi {
    // Methods from IWifi follow.
    Return<void> registerEventCallback(const sp<IWifiEventCallback>& callback, registerEventCallback_cb _hidl_cb) override;
    Return<bool> isStarted() override;
    Return<void> start(start_cb _hidl_cb) override;
    Return<void> stop(stop_cb _hidl_cb) override;
    Return<void> getChipIds(getChipIds_cb _hidl_cb) override;
    Return<void> getChip(uint32_t chipId, getChip_cb _hidl_cb) override;

    // Methods from ::android::hidl::base::V1_0::IBase follow.

};

// FIXME: most likely delete, this is only for passthrough implementations
// extern "C" IWifi* HIDL_FETCH_IWifi(const char* name);

}  // namespace implementation
}  // namespace V1_0
}  // namespace wifi
}  // namespace hardware
}  // namespace android

#endif  // ANDROID_HARDWARE_WIFI_V1_0_WIFI_H

 

#include "Wifi.h"

namespace android {
namespace hardware {
namespace wifi {
namespace V1_0 {
namespace implementation {

// Methods from IWifi follow.
Return<void> Wifi::registerEventCallback(const sp<IWifiEventCallback>& callback, registerEventCallback_cb _hidl_cb) {
    // TODO implement
    return Void();
}

Return<bool> Wifi::isStarted() {
    // TODO implement
    return bool {};
}

Return<void> Wifi::start(start_cb _hidl_cb) {
    // TODO implement
    return Void();
}

Return<void> Wifi::stop(stop_cb _hidl_cb) {
    // TODO implement
    return Void();
}

Return<void> Wifi::getChipIds(getChipIds_cb _hidl_cb) {
    // TODO implement
    return Void();
}

Return<void> Wifi::getChip(uint32_t chipId, getChip_cb _hidl_cb) {
    // TODO implement
    return Void();
}


// Methods from ::android::hidl::base::V1_0::IBase follow.

//IWifi* HIDL_FETCH_IWifi(const char* /* name */) {
//    return new Wifi();
//}

}  // namespace implementation
}  // namespace V1_0
}  // namespace wifi
}  // namespace hardware
}  // namespace android

都是空实现,结合hidl是framework和vendor的桥梁,所以实现应该是由vendor实现的?1.1的wifi hal版本中有默认的实现。

(八十一)探索hidl-gen使用及IWifi.hal 实现

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <android-base/logging.h>

#include "hidl_return_util.h"
#include "wifi.h"
#include "wifi_status_util.h"

namespace {
// Chip ID to use for the only supported chip.
static constexpr android::hardware::wifi::V1_0::ChipId kChipId = 0;
}  // namespace

namespace android {
namespace hardware {
namespace wifi {
namespace V1_1 {
namespace implementation {
using hidl_return_util::validateAndCall;
using hidl_return_util::validateAndCallWithLock;

Wifi::Wifi()
    : legacy_hal_(new legacy_hal::WifiLegacyHal()),
      mode_controller_(new mode_controller::WifiModeController()),
      run_state_(RunState::STOPPED) {}

bool Wifi::isValid() {
  // This object is always valid.
  return true;
}

Return<void> Wifi::registerEventCallback(
    const sp<IWifiEventCallback>& event_callback,
    registerEventCallback_cb hidl_status_cb) {
  return validateAndCall(this,
                         WifiStatusCode::ERROR_UNKNOWN,
                         &Wifi::registerEventCallbackInternal,
                         hidl_status_cb,
                         event_callback);
}

Return<bool> Wifi::isStarted() {
  return run_state_ != RunState::STOPPED;
}

Return<void> Wifi::start(start_cb hidl_status_cb) {
  return validateAndCall(this,
                         WifiStatusCode::ERROR_UNKNOWN,
                         &Wifi::startInternal,
                         hidl_status_cb);
}

Return<void> Wifi::stop(stop_cb hidl_status_cb) {
  return validateAndCallWithLock(this, WifiStatusCode::ERROR_UNKNOWN,
                                 &Wifi::stopInternal, hidl_status_cb);
}

Return<void> Wifi::getChipIds(getChipIds_cb hidl_status_cb) {
  return validateAndCall(this,
                         WifiStatusCode::ERROR_UNKNOWN,
                         &Wifi::getChipIdsInternal,
                         hidl_status_cb);
}

Return<void> Wifi::getChip(ChipId chip_id, getChip_cb hidl_status_cb) {
  return validateAndCall(this,
                         WifiStatusCode::ERROR_UNKNOWN,
                         &Wifi::getChipInternal,
                         hidl_status_cb,
                         chip_id);
}

WifiStatus Wifi::registerEventCallbackInternal(
    const sp<IWifiEventCallback>& event_callback) {
  if (!event_cb_handler_.addCallback(event_callback)) {
    return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
  }
  return createWifiStatus(WifiStatusCode::SUCCESS);
}

WifiStatus Wifi::startInternal() {
  if (run_state_ == RunState::STARTED) {
    return createWifiStatus(WifiStatusCode::SUCCESS);
  } else if (run_state_ == RunState::STOPPING) {
    return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE,
                            "HAL is stopping");
  }
  WifiStatus wifi_status = initializeLegacyHal();
  if (wifi_status.code == WifiStatusCode::SUCCESS) {
    // Create the chip instance once the HAL is started.
    chip_ = new WifiChip(kChipId, legacy_hal_, mode_controller_);
    run_state_ = RunState::STARTED;
    for (const auto& callback : event_cb_handler_.getCallbacks()) {
      if (!callback->onStart().isOk()) {
        LOG(ERROR) << "Failed to invoke onStart callback";
      };
    }
    LOG(INFO) << "Wifi HAL started";
  } else {
    for (const auto& callback : event_cb_handler_.getCallbacks()) {
      if (!callback->onFailure(wifi_status).isOk()) {
        LOG(ERROR) << "Failed to invoke onFailure callback";
      }
    }
    LOG(ERROR) << "Wifi HAL start failed";
  }
  return wifi_status;
}

WifiStatus Wifi::stopInternal(
    /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock) {
  if (run_state_ == RunState::STOPPED) {
    return createWifiStatus(WifiStatusCode::SUCCESS);
  } else if (run_state_ == RunState::STOPPING) {
    return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE,
                            "HAL is stopping");
  }
  // Clear the chip object and its child objects since the HAL is now
  // stopped.
  if (chip_.get()) {
    chip_->invalidate();
    chip_.clear();
  }
  WifiStatus wifi_status = stopLegacyHalAndDeinitializeModeController(lock);
  if (wifi_status.code == WifiStatusCode::SUCCESS) {
    for (const auto& callback : event_cb_handler_.getCallbacks()) {
      if (!callback->onStop().isOk()) {
        LOG(ERROR) << "Failed to invoke onStop callback";
      };
    }
    LOG(INFO) << "Wifi HAL stopped";
  } else {
    for (const auto& callback : event_cb_handler_.getCallbacks()) {
      if (!callback->onFailure(wifi_status).isOk()) {
        LOG(ERROR) << "Failed to invoke onFailure callback";
      }
    }
    LOG(ERROR) << "Wifi HAL stop failed";
  }
  return wifi_status;
}

std::pair<WifiStatus, std::vector<ChipId>> Wifi::getChipIdsInternal() {
  std::vector<ChipId> chip_ids;
  if (chip_.get()) {
    chip_ids.emplace_back(kChipId);
  }
  return {createWifiStatus(WifiStatusCode::SUCCESS), std::move(chip_ids)};
}

std::pair<WifiStatus, sp<IWifiChip>> Wifi::getChipInternal(ChipId chip_id) {
  if (!chip_.get()) {
    return {createWifiStatus(WifiStatusCode::ERROR_NOT_STARTED), nullptr};
  }
  if (chip_id != kChipId) {
    return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
  }
  return {createWifiStatus(WifiStatusCode::SUCCESS), chip_};
}

WifiStatus Wifi::initializeLegacyHal() {
  legacy_hal::wifi_error legacy_status = legacy_hal_->initialize();
  if (legacy_status != legacy_hal::WIFI_SUCCESS) {
    LOG(ERROR) << "Failed to initialize legacy HAL: "
               << legacyErrorToString(legacy_status);
    return createWifiStatusFromLegacyError(legacy_status);
  }
  return createWifiStatus(WifiStatusCode::SUCCESS);
}

WifiStatus Wifi::stopLegacyHalAndDeinitializeModeController(
    /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock) {
  run_state_ = RunState::STOPPING;
  legacy_hal::wifi_error legacy_status =
      legacy_hal_->stop(lock, [&]() { run_state_ = RunState::STOPPED; });
  if (legacy_status != legacy_hal::WIFI_SUCCESS) {
    LOG(ERROR) << "Failed to stop legacy HAL: "
               << legacyErrorToString(legacy_status);
    return createWifiStatusFromLegacyError(legacy_status);
  }
  if (!mode_controller_->deinitialize()) {
    LOG(ERROR) << "Failed to deinitialize firmware mode controller";
    return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
  }
  return createWifiStatus(WifiStatusCode::SUCCESS);
}
}  // namespace implementation
}  // namespace V1_1
}  // namespace wifi
}  // namespace hardware
}  // namespace android

2.1.7 生成hash

/aosp/android_aosp/hardware/interfaces$ vim current.txt

默认与WiFi相关的hash如下所示:

b9be36719a8ad534000a51ea07be91be94c405bf1e038ae825acf65087ffd378 aaa@qq.com::IWifi
ee0224ee18813506d9d6f13d8c8e4679f053c290a443a52a7c52a5d3c852262b aaa@qq.com::IWifiApIface
f3eecc489deb4c74892f59eb7adb769063bd5c354ac132b626a5f42b363d36bc aaa@qq.com::IWifiChip
a1b988377645a58e5e2542ca2bad4e17c21a4a389213d05de2f0e32d57b7d339 aaa@qq.com::IWifiChipEventCallback
5ed6760ce77e84bc6c49d1acb3f7d8117c9176b3f06514bc44ad3af84c80dcfe aaa@qq.com::IWifiEventCallback
6b9ad43a5efbe6ca214f751e22ce43cf5cd4d5d5f2cba80f24ccd3755a72401c aaa@qq.com::IWifiIface
ba5aa74f1ba714f0093864227923492808795bda6199c4ea0891322d27f8c931 aaa@qq.com::IWifiNanIface
325c94f3e1a565b56bbc74faddbd0ba7cb824f263dccf9dfff2daf62b86ed774 aaa@qq.com::IWifiNanIfaceEventCallback
c2c3f0372b41780fb6dfe83c022296806c2024d7046682fd201de5aa9b791c7a aaa@qq.com::IWifiP2pIface
766e9765f5c9c759b2a763c2288353fb5deff3389c2cc28f81d79c939704ce8b aaa@qq.com::IWifiRttController
72ab6f3e120cbf07aa6f8e87ca89112bdeb36b7fbb96bce5af3712323ab8b8e6 aaa@qq.com::IWifiRttControllerEventCallback
3b8093d39ef1e10e43c5538afbf5ff6e39b8d8168ebbe1998d993e89e25f14a5 aaa@qq.com::IWifiStaIface
7fbfc551c3e23c8b4398c3e16e452b516457e6921424a53474cbf373ca306fa9 aaa@qq.com::IWifiStaIfaceEventCallback
e20d5132d6d23e072c15de065b5e2aa13ff965031246a2c82581732bae56bf6d aaa@qq.com::types
f7e55c08187d8c855068a1ee3d0c8daeee7570292d96509c21a8756d4f5cfb9b aaa@qq.com::ISupplicant
56b5c7267cb3d3337f44eb8b0b38ff4c6260dcc70e07687fcab94b1ccea8d159 aaa@qq.com::ISupplicantCallback
35ba7bcdf18f24a866a7e5429548f06768bb20a257f75b10a397c4d825ef8438 aaa@qq.com::ISupplicantIface
cda01008c06922fa37c1213e9bb831a109b3174532805616fb7161edc403866f aaa@qq.com::ISupplicantNetwork
4907410338c5e8dbeec4b5edc2608ea323f5561945f8810af81810c47b019184 aaa@qq.com::ISupplicantP2pIface
8b63f5efa2e3be3a7cb8a428760d82285a4ab79bcbdea6ef90aa547555e582d4 aaa@qq.com::ISupplicantP2pIfaceCallback
56128f74560571b6777d59453f35c6b35693ee377e2a23c807708906928f09de aaa@qq.com::ISupplicantP2pNetwork
2067c22197bca9743dab66a6f561a8a8375c67b4f76aed05f776839499bd4c8f aaa@qq.com::ISupplicantP2pNetworkCallback
7752e1de93aaf5fed37011c219ac247069f6af320b0810daa98510584a10e7b4 aaa@qq.com::ISupplicantStaIface
d781c8d7e7b3fe5cca8cf6e1d8806e770982ae5358c7816ed51b0f0ec272e70d aaa@qq.com::ISupplicantStaIfaceCallback
b12ef0bdd8a4d247a8a6e960b227ed32383f2b0241f55d67fcea6eff6a6737fa aaa@qq.com::ISupplicantStaNetwork
d8f0877ae1d321c1d884c7631dfe36cab0ec8a4b2863d4b687f85d3549a63bcc aaa@qq.com::ISupplicantStaNetworkCallback
fe3c3c2f572b72f15f8594c538b0577bd5c28722c31879cfe6231330cddb6747 aaa@qq.com::types

试下如何生成:

(八十一)探索hidl-gen使用及IWifi.hal 实现

对比下hidl-gen生成的和原来的IWifi是否一样:

原来:

b9be36719a8ad534000a51ea07be91be94c405bf1e038ae825acf65087ffd378 aaa@qq.com::IWifi

现在:

b9be36719a8ad534000a51ea07be91be94c405bf1e038ae825acf65087ffd378 aaa@qq.com::IWifi
 

啊哈,一样的,没毛病。

也可以加::制定具体hidl接口生成hash

(八十一)探索hidl-gen使用及IWifi.hal 实现

 

3. 注册服务

1.1/default/service.cpp

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include <utils/Looper.h>
#include <utils/StrongPointer.h>

#include "wifi.h"

using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;

int main(int /*argc*/, char** argv) {
  android::base::InitLogging(argv,
                             android::base::LogdLogger(android::base::SYSTEM));
  LOG(INFO) << "Wifi Hal is booting up...";

  configureRpcThreadpool(1, true /* callerWillJoin */);

  // Setup hwbinder service
  android::sp<android::hardware::wifi::V1_1::IWifi> service =
      new android::hardware::wifi::V1_1::implementation::Wifi();
  CHECK_EQ(service->registerAsService(), android::NO_ERROR)
      << "Failed to register wifi HAL";

  joinRpcThreadpool();

  LOG(INFO) << "Wifi Hal is terminating...";
  return 0;
}

 

相关标签: hal