当前位置:   article > 正文

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

hidl-gen

1.文件路径

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

  1. /*
  2. * Copyright 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package android.hardware.wifi@1.0;
  17. import IWifiChip;
  18. import IWifiEventCallback;
  19. /**
  20. * This is the root of the HAL module and is the interface returned when
  21. * loading an implementation of the Wi-Fi HAL. There must be at most one
  22. * module loaded in the system.
  23. */
  24. interface IWifi {
  25. /**
  26. * Requests notifications of significant events for the HAL. Multiple calls to
  27. * this must register multiple callbacks each of which must receive all
  28. * events. |IWifiEventCallback| object registration must be independent of the
  29. * state of the rest of the HAL and must persist though stops/starts. These
  30. * objects must be deleted when the corresponding client process is dead.
  31. *
  32. * @param callback An instance of the |IWifiEventCallback| HIDL interface
  33. * object.
  34. * @return status WifiStatus of the operation.
  35. * Possible status codes:
  36. * |WifiStatusCode.SUCCESS|,
  37. * |WifiStatusCode.UNKNOWN|
  38. */
  39. @entry
  40. @callflow(next={"*"})
  41. registerEventCallback(IWifiEventCallback callback)
  42. generates (WifiStatus status);
  43. /**
  44. * Get the current state of the HAL.
  45. *
  46. * @return started true if started, false otherwise.
  47. */
  48. isStarted() generates (bool started);
  49. /**
  50. * Perform any setup that is required to make use of the module. If the module
  51. * is already started then this must be a noop.
  52. * Must trigger |IWifiEventCallback.onStart| on success.
  53. *
  54. * @return status WifiStatus of the operation.
  55. * Possible status codes:
  56. * |WifiStatusCode.SUCCESS|,
  57. * |WifiStatusCode.NOT_AVAILABLE|,
  58. * |WifiStatusCode.UNKNOWN|
  59. */
  60. @entry
  61. @callflow(next={"registerEventCallback", "start", "stop", "getChip"})
  62. start() generates (WifiStatus status);
  63. /**
  64. * Tear down any state, ongoing commands, etc. If the module is already
  65. * stopped then this must be a noop. If the HAL is already stopped or it
  66. * succeeds then onStop must be called. After calling this all IWifiChip
  67. * objects will be considered invalid.
  68. * Must trigger |IWifiEventCallback.onStop| on success.
  69. * Must trigger |IWifiEventCallback.onFailure| on failure.
  70. *
  71. * Calling stop then start is a valid way of resetting state in the HAL,
  72. * driver, firmware.
  73. *
  74. * @return status WifiStatus of the operation.
  75. * Possible status codes:
  76. * |WifiStatusCode.SUCCESS|,
  77. * |WifiStatusCode.NOT_STARTED|,
  78. * |WifiStatusCode.UNKNOWN|
  79. */
  80. @exit
  81. @callflow(next={"registerEventCallback", "start", "stop"})
  82. stop() generates (WifiStatus status);
  83. /**
  84. * Retrieve the list of all chip Id's on the device.
  85. * The corresponding |IWifiChip| object for any chip can be
  86. * retrieved using |getChip| method.
  87. *
  88. * @return status WifiStatus of the operation.
  89. * Possible status codes:
  90. * |WifiStatusCode.SUCCESS|,
  91. * |WifiStatusCode.NOT_STARTED|,
  92. * |WifiStatusCode.UNKNOWN|
  93. * @return chipIds List of all chip Id's on the device.
  94. */
  95. @callflow(next={"*"})
  96. getChipIds() generates (WifiStatus status, vec<ChipId> chipIds);
  97. /**
  98. * Gets a HIDL interface object for the chip corresponding to the
  99. * provided chipId.
  100. *
  101. * @return status WifiStatus of the operation.
  102. * Possible status codes:
  103. * |WifiStatusCode.SUCCESS|,
  104. * |WifiStatusCode.NOT_STARTED|,
  105. * |WifiStatusCode.UNKNOWN|
  106. * @return chip HIDL interface object representing the chip.
  107. */
  108. @callflow(next={"*"})
  109. getChip(ChipId chipId) generates (WifiStatus status, IWifiChip chip);
  110. };

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

 

2.对应Android.bp文件

  1. // This file is autogenerated by hidl-gen. Do not edit manually.
  2. filegroup {
  3. name: "android.hardware.wifi@1.0_hal",
  4. srcs: [
  5. "types.hal",
  6. "IWifi.hal",
  7. "IWifiApIface.hal",
  8. "IWifiChip.hal",
  9. "IWifiChipEventCallback.hal",
  10. "IWifiEventCallback.hal",
  11. "IWifiIface.hal",
  12. "IWifiNanIface.hal",
  13. "IWifiNanIfaceEventCallback.hal",
  14. "IWifiP2pIface.hal",
  15. "IWifiRttController.hal",
  16. "IWifiRttControllerEventCallback.hal",
  17. "IWifiStaIface.hal",
  18. "IWifiStaIfaceEventCallback.hal",
  19. ],
  20. }
  21. genrule {
  22. name: "android.hardware.wifi@1.0_genc++",
  23. tools: ["hidl-gen"],
  24. cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.wifi@1.0",
  25. srcs: [
  26. ":android.hardware.wifi@1.0_hal",
  27. ],
  28. out: [
  29. "android/hardware/wifi/1.0/types.cpp",
  30. "android/hardware/wifi/1.0/WifiAll.cpp",
  31. "android/hardware/wifi/1.0/WifiApIfaceAll.cpp",
  32. "android/hardware/wifi/1.0/WifiChipAll.cpp",
  33. "android/hardware/wifi/1.0/WifiChipEventCallbackAll.cpp",
  34. "android/hardware/wifi/1.0/WifiEventCallbackAll.cpp",
  35. "android/hardware/wifi/1.0/WifiIfaceAll.cpp",
  36. "android/hardware/wifi/1.0/WifiNanIfaceAll.cpp",
  37. "android/hardware/wifi/1.0/WifiNanIfaceEventCallbackAll.cpp",
  38. "android/hardware/wifi/1.0/WifiP2pIfaceAll.cpp",
  39. "android/hardware/wifi/1.0/WifiRttControllerAll.cpp",
  40. "android/hardware/wifi/1.0/WifiRttControllerEventCallbackAll.cpp",
  41. "android/hardware/wifi/1.0/WifiStaIfaceAll.cpp",
  42. "android/hardware/wifi/1.0/WifiStaIfaceEventCallbackAll.cpp",
  43. ],
  44. }
  45. genrule {
  46. name: "android.hardware.wifi@1.0_genc++_headers",
  47. tools: ["hidl-gen"],
  48. cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.wifi@1.0",
  49. srcs: [
  50. ":android.hardware.wifi@1.0_hal",
  51. ],
  52. out: [
  53. "android/hardware/wifi/1.0/types.h",
  54. "android/hardware/wifi/1.0/hwtypes.h",
  55. "android/hardware/wifi/1.0/IWifi.h",
  56. "android/hardware/wifi/1.0/IHwWifi.h",
  57. "android/hardware/wifi/1.0/BnHwWifi.h",
  58. "android/hardware/wifi/1.0/BpHwWifi.h",
  59. "android/hardware/wifi/1.0/BsWifi.h",
  60. "android/hardware/wifi/1.0/IWifiApIface.h",
  61. "android/hardware/wifi/1.0/IHwWifiApIface.h",
  62. "android/hardware/wifi/1.0/BnHwWifiApIface.h",
  63. "android/hardware/wifi/1.0/BpHwWifiApIface.h",
  64. "android/hardware/wifi/1.0/BsWifiApIface.h",
  65. "android/hardware/wifi/1.0/IWifiChip.h",
  66. "android/hardware/wifi/1.0/IHwWifiChip.h",
  67. "android/hardware/wifi/1.0/BnHwWifiChip.h",
  68. "android/hardware/wifi/1.0/BpHwWifiChip.h",
  69. "android/hardware/wifi/1.0/BsWifiChip.h",
  70. "android/hardware/wifi/1.0/IWifiChipEventCallback.h",
  71. "android/hardware/wifi/1.0/IHwWifiChipEventCallback.h",
  72. "android/hardware/wifi/1.0/BnHwWifiChipEventCallback.h",
  73. "android/hardware/wifi/1.0/BpHwWifiChipEventCallback.h",
  74. "android/hardware/wifi/1.0/BsWifiChipEventCallback.h",
  75. "android/hardware/wifi/1.0/IWifiEventCallback.h",
  76. "android/hardware/wifi/1.0/IHwWifiEventCallback.h",
  77. "android/hardware/wifi/1.0/BnHwWifiEventCallback.h",
  78. "android/hardware/wifi/1.0/BpHwWifiEventCallback.h",
  79. "android/hardware/wifi/1.0/BsWifiEventCallback.h",
  80. "android/hardware/wifi/1.0/IWifiIface.h",
  81. "android/hardware/wifi/1.0/IHwWifiIface.h",
  82. "android/hardware/wifi/1.0/BnHwWifiIface.h",
  83. "android/hardware/wifi/1.0/BpHwWifiIface.h",
  84. "android/hardware/wifi/1.0/BsWifiIface.h",
  85. "android/hardware/wifi/1.0/IWifiNanIface.h",
  86. "android/hardware/wifi/1.0/IHwWifiNanIface.h",
  87. "android/hardware/wifi/1.0/BnHwWifiNanIface.h",
  88. "android/hardware/wifi/1.0/BpHwWifiNanIface.h",
  89. "android/hardware/wifi/1.0/BsWifiNanIface.h",
  90. "android/hardware/wifi/1.0/IWifiNanIfaceEventCallback.h",
  91. "android/hardware/wifi/1.0/IHwWifiNanIfaceEventCallback.h",
  92. "android/hardware/wifi/1.0/BnHwWifiNanIfaceEventCallback.h",
  93. "android/hardware/wifi/1.0/BpHwWifiNanIfaceEventCallback.h",
  94. "android/hardware/wifi/1.0/BsWifiNanIfaceEventCallback.h",
  95. "android/hardware/wifi/1.0/IWifiP2pIface.h",
  96. "android/hardware/wifi/1.0/IHwWifiP2pIface.h",
  97. "android/hardware/wifi/1.0/BnHwWifiP2pIface.h",
  98. "android/hardware/wifi/1.0/BpHwWifiP2pIface.h",
  99. "android/hardware/wifi/1.0/BsWifiP2pIface.h",
  100. "android/hardware/wifi/1.0/IWifiRttController.h",
  101. "android/hardware/wifi/1.0/IHwWifiRttController.h",
  102. "android/hardware/wifi/1.0/BnHwWifiRttController.h",
  103. "android/hardware/wifi/1.0/BpHwWifiRttController.h",
  104. "android/hardware/wifi/1.0/BsWifiRttController.h",
  105. "android/hardware/wifi/1.0/IWifiRttControllerEventCallback.h",
  106. "android/hardware/wifi/1.0/IHwWifiRttControllerEventCallback.h",
  107. "android/hardware/wifi/1.0/BnHwWifiRttControllerEventCallback.h",
  108. "android/hardware/wifi/1.0/BpHwWifiRttControllerEventCallback.h",
  109. "android/hardware/wifi/1.0/BsWifiRttControllerEventCallback.h",
  110. "android/hardware/wifi/1.0/IWifiStaIface.h",
  111. "android/hardware/wifi/1.0/IHwWifiStaIface.h",
  112. "android/hardware/wifi/1.0/BnHwWifiStaIface.h",
  113. "android/hardware/wifi/1.0/BpHwWifiStaIface.h",
  114. "android/hardware/wifi/1.0/BsWifiStaIface.h",
  115. "android/hardware/wifi/1.0/IWifiStaIfaceEventCallback.h",
  116. "android/hardware/wifi/1.0/IHwWifiStaIfaceEventCallback.h",
  117. "android/hardware/wifi/1.0/BnHwWifiStaIfaceEventCallback.h",
  118. "android/hardware/wifi/1.0/BpHwWifiStaIfaceEventCallback.h",
  119. "android/hardware/wifi/1.0/BsWifiStaIfaceEventCallback.h",
  120. ],
  121. }
  122. cc_library {
  123. name: "android.hardware.wifi@1.0",
  124. defaults: ["hidl-module-defaults"],
  125. generated_sources: ["android.hardware.wifi@1.0_genc++"],
  126. generated_headers: ["android.hardware.wifi@1.0_genc++_headers"],
  127. export_generated_headers: ["android.hardware.wifi@1.0_genc++_headers"],
  128. vendor_available: true,
  129. vndk: {
  130. enabled: true,
  131. },
  132. shared_libs: [
  133. "libhidlbase",
  134. "libhidltransport",
  135. "libhwbinder",
  136. "liblog",
  137. "libutils",
  138. "libcutils",
  139. ],
  140. export_shared_lib_headers: [
  141. "libhidlbase",
  142. "libhidltransport",
  143. "libhwbinder",
  144. "libutils",
  145. ],
  146. }

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

filegroup-"android.hardware.wifi@1.0_hal":包含了该目录下所有的hal文件

genrule-"android.hardware.wifi@1.0_genc++":使用上面的filegroup作为src编译出对应的cpp文件

genrule-"android.hardware.wifi@1.0_genc++_headers":使用上面的filegroup作为src编译出对应的.h文件

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

  1. cc_library {
  2. name: "android.hardware.wifi@1.0",
  3. defaults: ["hidl-module-defaults"],
  4. generated_sources: ["android.hardware.wifi@1.0_genc++"],
  5. generated_headers: ["android.hardware.wifi@1.0_genc++_headers"],
  6. export_generated_headers: ["android.hardware.wifi@1.0_genc++_headers"],
  7. vendor_available: true,
  8. vndk: {
  9. enabled: true,
  10. },
  11. shared_libs: [
  12. "libhidlbase",
  13. "libhidltransport",
  14. "libhwbinder",
  15. "liblog",
  16. "libutils",
  17. "libcutils",
  18. ],
  19. export_shared_lib_headers: [
  20. "libhidlbase",
  21. "libhidltransport",
  22. "libhwbinder",
  23. "libutils",
  24. ],
  25. }

 

2.1 hidl-gen

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

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

先期准备

  1. 1)source build/envsetup.sh
  2. 2)lunch
  3. 3)make hidl-gen -j4
  4. //[100% 460/460] Install: out/host/linux-x86/bin/hidl-gen

 

2.1.1 生成c++-sources

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

 

2.1.2 生成c++-headers

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

 

2.1.3 生成Android.bp

cmd: "$(location hidl-gen) -o $(genDir) -Landroidbp -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.wifi@1.0"

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

2.1.4 生成Android.mk

 

2.1.5 生成androidbp-impl

 hidl-gen -o ./test_hidl_wifi/ -Landroidbp-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.wifi@1.0

  1. cc_library_shared {
  2. name: "android.hardware.wifi@1.0-impl",
  3. relative_install_path: "hw",
  4. proprietary: true,
  5. srcs: [
  6. "Wifi.cpp",
  7. "WifiApIface.cpp",
  8. "WifiChip.cpp",
  9. "WifiChipEventCallback.cpp",
  10. "WifiEventCallback.cpp",
  11. "WifiIface.cpp",
  12. "WifiNanIface.cpp",
  13. "WifiNanIfaceEventCallback.cpp",
  14. "WifiP2pIface.cpp",
  15. "WifiRttController.cpp",
  16. "WifiRttControllerEventCallback.cpp",
  17. "WifiStaIface.cpp",
  18. "WifiStaIfaceEventCallback.cpp",
  19. ],
  20. shared_libs: [
  21. "libhidlbase",
  22. "libhidltransport",
  23. "libutils",
  24. "android.hardware.wifi@1.0",
  25. ],
  26. }

 

2.1.6 生成c++-impl

生成HIDL的默认实现。

看下Wifi.h和Wifi.cpp

  1. #ifndef ANDROID_HARDWARE_WIFI_V1_0_WIFI_H
  2. #define ANDROID_HARDWARE_WIFI_V1_0_WIFI_H
  3. #include <android/hardware/wifi/1.0/IWifi.h>
  4. #include <hidl/MQDescriptor.h>
  5. #include <hidl/Status.h>
  6. namespace android {
  7. namespace hardware {
  8. namespace wifi {
  9. namespace V1_0 {
  10. namespace implementation {
  11. using ::android::hardware::hidl_array;
  12. using ::android::hardware::hidl_memory;
  13. using ::android::hardware::hidl_string;
  14. using ::android::hardware::hidl_vec;
  15. using ::android::hardware::Return;
  16. using ::android::hardware::Void;
  17. using ::android::sp;
  18. struct Wifi : public IWifi {
  19. // Methods from IWifi follow.
  20. Return<void> registerEventCallback(const sp<IWifiEventCallback>& callback, registerEventCallback_cb _hidl_cb) override;
  21. Return<bool> isStarted() override;
  22. Return<void> start(start_cb _hidl_cb) override;
  23. Return<void> stop(stop_cb _hidl_cb) override;
  24. Return<void> getChipIds(getChipIds_cb _hidl_cb) override;
  25. Return<void> getChip(uint32_t chipId, getChip_cb _hidl_cb) override;
  26. // Methods from ::android::hidl::base::V1_0::IBase follow.
  27. };
  28. // FIXME: most likely delete, this is only for passthrough implementations
  29. // extern "C" IWifi* HIDL_FETCH_IWifi(const char* name);
  30. } // namespace implementation
  31. } // namespace V1_0
  32. } // namespace wifi
  33. } // namespace hardware
  34. } // namespace android
  35. #endif // ANDROID_HARDWARE_WIFI_V1_0_WIFI_H

 

  1. #include "Wifi.h"
  2. namespace android {
  3. namespace hardware {
  4. namespace wifi {
  5. namespace V1_0 {
  6. namespace implementation {
  7. // Methods from IWifi follow.
  8. Return<void> Wifi::registerEventCallback(const sp<IWifiEventCallback>& callback, registerEventCallback_cb _hidl_cb) {
  9. // TODO implement
  10. return Void();
  11. }
  12. Return<bool> Wifi::isStarted() {
  13. // TODO implement
  14. return bool {};
  15. }
  16. Return<void> Wifi::start(start_cb _hidl_cb) {
  17. // TODO implement
  18. return Void();
  19. }
  20. Return<void> Wifi::stop(stop_cb _hidl_cb) {
  21. // TODO implement
  22. return Void();
  23. }
  24. Return<void> Wifi::getChipIds(getChipIds_cb _hidl_cb) {
  25. // TODO implement
  26. return Void();
  27. }
  28. Return<void> Wifi::getChip(uint32_t chipId, getChip_cb _hidl_cb) {
  29. // TODO implement
  30. return Void();
  31. }
  32. // Methods from ::android::hidl::base::V1_0::IBase follow.
  33. //IWifi* HIDL_FETCH_IWifi(const char* /* name */) {
  34. // return new Wifi();
  35. //}
  36. } // namespace implementation
  37. } // namespace V1_0
  38. } // namespace wifi
  39. } // namespace hardware
  40. } // namespace android

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

  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <android-base/logging.h>
  17. #include "hidl_return_util.h"
  18. #include "wifi.h"
  19. #include "wifi_status_util.h"
  20. namespace {
  21. // Chip ID to use for the only supported chip.
  22. static constexpr android::hardware::wifi::V1_0::ChipId kChipId = 0;
  23. } // namespace
  24. namespace android {
  25. namespace hardware {
  26. namespace wifi {
  27. namespace V1_1 {
  28. namespace implementation {
  29. using hidl_return_util::validateAndCall;
  30. using hidl_return_util::validateAndCallWithLock;
  31. Wifi::Wifi()
  32. : legacy_hal_(new legacy_hal::WifiLegacyHal()),
  33. mode_controller_(new mode_controller::WifiModeController()),
  34. run_state_(RunState::STOPPED) {}
  35. bool Wifi::isValid() {
  36. // This object is always valid.
  37. return true;
  38. }
  39. Return<void> Wifi::registerEventCallback(
  40. const sp<IWifiEventCallback>& event_callback,
  41. registerEventCallback_cb hidl_status_cb) {
  42. return validateAndCall(this,
  43. WifiStatusCode::ERROR_UNKNOWN,
  44. &Wifi::registerEventCallbackInternal,
  45. hidl_status_cb,
  46. event_callback);
  47. }
  48. Return<bool> Wifi::isStarted() {
  49. return run_state_ != RunState::STOPPED;
  50. }
  51. Return<void> Wifi::start(start_cb hidl_status_cb) {
  52. return validateAndCall(this,
  53. WifiStatusCode::ERROR_UNKNOWN,
  54. &Wifi::startInternal,
  55. hidl_status_cb);
  56. }
  57. Return<void> Wifi::stop(stop_cb hidl_status_cb) {
  58. return validateAndCallWithLock(this, WifiStatusCode::ERROR_UNKNOWN,
  59. &Wifi::stopInternal, hidl_status_cb);
  60. }
  61. Return<void> Wifi::getChipIds(getChipIds_cb hidl_status_cb) {
  62. return validateAndCall(this,
  63. WifiStatusCode::ERROR_UNKNOWN,
  64. &Wifi::getChipIdsInternal,
  65. hidl_status_cb);
  66. }
  67. Return<void> Wifi::getChip(ChipId chip_id, getChip_cb hidl_status_cb) {
  68. return validateAndCall(this,
  69. WifiStatusCode::ERROR_UNKNOWN,
  70. &Wifi::getChipInternal,
  71. hidl_status_cb,
  72. chip_id);
  73. }
  74. WifiStatus Wifi::registerEventCallbackInternal(
  75. const sp<IWifiEventCallback>& event_callback) {
  76. if (!event_cb_handler_.addCallback(event_callback)) {
  77. return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
  78. }
  79. return createWifiStatus(WifiStatusCode::SUCCESS);
  80. }
  81. WifiStatus Wifi::startInternal() {
  82. if (run_state_ == RunState::STARTED) {
  83. return createWifiStatus(WifiStatusCode::SUCCESS);
  84. } else if (run_state_ == RunState::STOPPING) {
  85. return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE,
  86. "HAL is stopping");
  87. }
  88. WifiStatus wifi_status = initializeLegacyHal();
  89. if (wifi_status.code == WifiStatusCode::SUCCESS) {
  90. // Create the chip instance once the HAL is started.
  91. chip_ = new WifiChip(kChipId, legacy_hal_, mode_controller_);
  92. run_state_ = RunState::STARTED;
  93. for (const auto& callback : event_cb_handler_.getCallbacks()) {
  94. if (!callback->onStart().isOk()) {
  95. LOG(ERROR) << "Failed to invoke onStart callback";
  96. };
  97. }
  98. LOG(INFO) << "Wifi HAL started";
  99. } else {
  100. for (const auto& callback : event_cb_handler_.getCallbacks()) {
  101. if (!callback->onFailure(wifi_status).isOk()) {
  102. LOG(ERROR) << "Failed to invoke onFailure callback";
  103. }
  104. }
  105. LOG(ERROR) << "Wifi HAL start failed";
  106. }
  107. return wifi_status;
  108. }
  109. WifiStatus Wifi::stopInternal(
  110. /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock) {
  111. if (run_state_ == RunState::STOPPED) {
  112. return createWifiStatus(WifiStatusCode::SUCCESS);
  113. } else if (run_state_ == RunState::STOPPING) {
  114. return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE,
  115. "HAL is stopping");
  116. }
  117. // Clear the chip object and its child objects since the HAL is now
  118. // stopped.
  119. if (chip_.get()) {
  120. chip_->invalidate();
  121. chip_.clear();
  122. }
  123. WifiStatus wifi_status = stopLegacyHalAndDeinitializeModeController(lock);
  124. if (wifi_status.code == WifiStatusCode::SUCCESS) {
  125. for (const auto& callback : event_cb_handler_.getCallbacks()) {
  126. if (!callback->onStop().isOk()) {
  127. LOG(ERROR) << "Failed to invoke onStop callback";
  128. };
  129. }
  130. LOG(INFO) << "Wifi HAL stopped";
  131. } else {
  132. for (const auto& callback : event_cb_handler_.getCallbacks()) {
  133. if (!callback->onFailure(wifi_status).isOk()) {
  134. LOG(ERROR) << "Failed to invoke onFailure callback";
  135. }
  136. }
  137. LOG(ERROR) << "Wifi HAL stop failed";
  138. }
  139. return wifi_status;
  140. }
  141. std::pair<WifiStatus, std::vector<ChipId>> Wifi::getChipIdsInternal() {
  142. std::vector<ChipId> chip_ids;
  143. if (chip_.get()) {
  144. chip_ids.emplace_back(kChipId);
  145. }
  146. return {createWifiStatus(WifiStatusCode::SUCCESS), std::move(chip_ids)};
  147. }
  148. std::pair<WifiStatus, sp<IWifiChip>> Wifi::getChipInternal(ChipId chip_id) {
  149. if (!chip_.get()) {
  150. return {createWifiStatus(WifiStatusCode::ERROR_NOT_STARTED), nullptr};
  151. }
  152. if (chip_id != kChipId) {
  153. return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
  154. }
  155. return {createWifiStatus(WifiStatusCode::SUCCESS), chip_};
  156. }
  157. WifiStatus Wifi::initializeLegacyHal() {
  158. legacy_hal::wifi_error legacy_status = legacy_hal_->initialize();
  159. if (legacy_status != legacy_hal::WIFI_SUCCESS) {
  160. LOG(ERROR) << "Failed to initialize legacy HAL: "
  161. << legacyErrorToString(legacy_status);
  162. return createWifiStatusFromLegacyError(legacy_status);
  163. }
  164. return createWifiStatus(WifiStatusCode::SUCCESS);
  165. }
  166. WifiStatus Wifi::stopLegacyHalAndDeinitializeModeController(
  167. /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock) {
  168. run_state_ = RunState::STOPPING;
  169. legacy_hal::wifi_error legacy_status =
  170. legacy_hal_->stop(lock, [&]() { run_state_ = RunState::STOPPED; });
  171. if (legacy_status != legacy_hal::WIFI_SUCCESS) {
  172. LOG(ERROR) << "Failed to stop legacy HAL: "
  173. << legacyErrorToString(legacy_status);
  174. return createWifiStatusFromLegacyError(legacy_status);
  175. }
  176. if (!mode_controller_->deinitialize()) {
  177. LOG(ERROR) << "Failed to deinitialize firmware mode controller";
  178. return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
  179. }
  180. return createWifiStatus(WifiStatusCode::SUCCESS);
  181. }
  182. } // namespace implementation
  183. } // namespace V1_1
  184. } // namespace wifi
  185. } // namespace hardware
  186. } // namespace android

2.1.7 生成hash

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

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

  1. b9be36719a8ad534000a51ea07be91be94c405bf1e038ae825acf65087ffd378 android.hardware.wifi@1.0::IWifi
  2. ee0224ee18813506d9d6f13d8c8e4679f053c290a443a52a7c52a5d3c852262b android.hardware.wifi@1.0::IWifiApIface
  3. f3eecc489deb4c74892f59eb7adb769063bd5c354ac132b626a5f42b363d36bc android.hardware.wifi@1.0::IWifiChip
  4. a1b988377645a58e5e2542ca2bad4e17c21a4a389213d05de2f0e32d57b7d339 android.hardware.wifi@1.0::IWifiChipEventCallback
  5. 5ed6760ce77e84bc6c49d1acb3f7d8117c9176b3f06514bc44ad3af84c80dcfe android.hardware.wifi@1.0::IWifiEventCallback
  6. 6b9ad43a5efbe6ca214f751e22ce43cf5cd4d5d5f2cba80f24ccd3755a72401c android.hardware.wifi@1.0::IWifiIface
  7. ba5aa74f1ba714f0093864227923492808795bda6199c4ea0891322d27f8c931 android.hardware.wifi@1.0::IWifiNanIface
  8. 325c94f3e1a565b56bbc74faddbd0ba7cb824f263dccf9dfff2daf62b86ed774 android.hardware.wifi@1.0::IWifiNanIfaceEventCallback
  9. c2c3f0372b41780fb6dfe83c022296806c2024d7046682fd201de5aa9b791c7a android.hardware.wifi@1.0::IWifiP2pIface
  10. 766e9765f5c9c759b2a763c2288353fb5deff3389c2cc28f81d79c939704ce8b android.hardware.wifi@1.0::IWifiRttController
  11. 72ab6f3e120cbf07aa6f8e87ca89112bdeb36b7fbb96bce5af3712323ab8b8e6 android.hardware.wifi@1.0::IWifiRttControllerEventCallback
  12. 3b8093d39ef1e10e43c5538afbf5ff6e39b8d8168ebbe1998d993e89e25f14a5 android.hardware.wifi@1.0::IWifiStaIface
  13. 7fbfc551c3e23c8b4398c3e16e452b516457e6921424a53474cbf373ca306fa9 android.hardware.wifi@1.0::IWifiStaIfaceEventCallback
  14. e20d5132d6d23e072c15de065b5e2aa13ff965031246a2c82581732bae56bf6d android.hardware.wifi@1.0::types
  15. f7e55c08187d8c855068a1ee3d0c8daeee7570292d96509c21a8756d4f5cfb9b android.hardware.wifi.supplicant@1.0::ISupplicant
  16. 56b5c7267cb3d3337f44eb8b0b38ff4c6260dcc70e07687fcab94b1ccea8d159 android.hardware.wifi.supplicant@1.0::ISupplicantCallback
  17. 35ba7bcdf18f24a866a7e5429548f06768bb20a257f75b10a397c4d825ef8438 android.hardware.wifi.supplicant@1.0::ISupplicantIface
  18. cda01008c06922fa37c1213e9bb831a109b3174532805616fb7161edc403866f android.hardware.wifi.supplicant@1.0::ISupplicantNetwork
  19. 4907410338c5e8dbeec4b5edc2608ea323f5561945f8810af81810c47b019184 android.hardware.wifi.supplicant@1.0::ISupplicantP2pIface
  20. 8b63f5efa2e3be3a7cb8a428760d82285a4ab79bcbdea6ef90aa547555e582d4 android.hardware.wifi.supplicant@1.0::ISupplicantP2pIfaceCallback
  21. 56128f74560571b6777d59453f35c6b35693ee377e2a23c807708906928f09de android.hardware.wifi.supplicant@1.0::ISupplicantP2pNetwork
  22. 2067c22197bca9743dab66a6f561a8a8375c67b4f76aed05f776839499bd4c8f android.hardware.wifi.supplicant@1.0::ISupplicantP2pNetworkCallback
  23. 7752e1de93aaf5fed37011c219ac247069f6af320b0810daa98510584a10e7b4 android.hardware.wifi.supplicant@1.0::ISupplicantStaIface
  24. d781c8d7e7b3fe5cca8cf6e1d8806e770982ae5358c7816ed51b0f0ec272e70d android.hardware.wifi.supplicant@1.0::ISupplicantStaIfaceCallback
  25. b12ef0bdd8a4d247a8a6e960b227ed32383f2b0241f55d67fcea6eff6a6737fa android.hardware.wifi.supplicant@1.0::ISupplicantStaNetwork
  26. d8f0877ae1d321c1d884c7631dfe36cab0ec8a4b2863d4b687f85d3549a63bcc android.hardware.wifi.supplicant@1.0::ISupplicantStaNetworkCallback
  27. fe3c3c2f572b72f15f8594c538b0577bd5c28722c31879cfe6231330cddb6747 android.hardware.wifi.supplicant@1.0::types

试下如何生成:

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

原来:

b9be36719a8ad534000a51ea07be91be94c405bf1e038ae825acf65087ffd378 android.hardware.wifi@1.0::IWifi

现在:

b9be36719a8ad534000a51ea07be91be94c405bf1e038ae825acf65087ffd378 android.hardware.wifi@1.0::IWifi
 

啊哈,一样的,没毛病。

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

 

3. 注册服务

1.1/default/service.cpp

  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <android-base/logging.h>
  17. #include <hidl/HidlTransportSupport.h>
  18. #include <utils/Looper.h>
  19. #include <utils/StrongPointer.h>
  20. #include "wifi.h"
  21. using android::hardware::configureRpcThreadpool;
  22. using android::hardware::joinRpcThreadpool;
  23. int main(int /*argc*/, char** argv) {
  24. android::base::InitLogging(argv,
  25. android::base::LogdLogger(android::base::SYSTEM));
  26. LOG(INFO) << "Wifi Hal is booting up...";
  27. configureRpcThreadpool(1, true /* callerWillJoin */);
  28. // Setup hwbinder service
  29. android::sp<android::hardware::wifi::V1_1::IWifi> service =
  30. new android::hardware::wifi::V1_1::implementation::Wifi();
  31. CHECK_EQ(service->registerAsService(), android::NO_ERROR)
  32. << "Failed to register wifi HAL";
  33. joinRpcThreadpool();
  34. LOG(INFO) << "Wifi Hal is terminating...";
  35. return 0;
  36. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/255950
推荐阅读
相关标签
  

闽ICP备14008679号