Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 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 | |
| 17 | #ifndef WIFI_H_ |
| 18 | #define WIFI_H_ |
| 19 | |
Prabir Pradhan | 84a19f6 | 2021-08-18 08:49:49 -0700 | [diff] [blame] | 20 | // HACK: NAN is a macro defined in math.h, which can be included in various |
| 21 | // headers. This wifi HAL uses an enum called NAN, which does not compile when |
| 22 | // the macro is defined. Undefine NAN to work around it. |
| 23 | #undef NAN |
| 24 | #include <android/hardware/wifi/1.5/IWifi.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 25 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 26 | #include <android-base/macros.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 27 | #include <utils/Looper.h> |
Prabir Pradhan | 84a19f6 | 2021-08-18 08:49:49 -0700 | [diff] [blame] | 28 | #include <functional> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 29 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 30 | #include "hidl_callback_util.h" |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 31 | #include "wifi_chip.h" |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 32 | #include "wifi_feature_flags.h" |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 33 | #include "wifi_legacy_hal.h" |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 34 | #include "wifi_legacy_hal_factory.h" |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 35 | #include "wifi_mode_controller.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 36 | |
| 37 | namespace android { |
| 38 | namespace hardware { |
| 39 | namespace wifi { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 40 | namespace V1_5 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 41 | namespace implementation { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 42 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 43 | /** |
| 44 | * Root HIDL interface object used to control the Wifi HAL. |
| 45 | */ |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 46 | class Wifi : public V1_5::IWifi { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 47 | public: |
Roshan Pius | c885df0 | 2019-05-21 14:49:05 -0700 | [diff] [blame] | 48 | Wifi(const std::shared_ptr<wifi_system::InterfaceTool> iface_tool, |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 49 | const std::shared_ptr<legacy_hal::WifiLegacyHalFactory> |
| 50 | legacy_hal_factory, |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 51 | const std::shared_ptr<mode_controller::WifiModeController> |
| 52 | mode_controller, |
| 53 | const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 54 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 55 | bool isValid(); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 56 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 57 | // HIDL methods exposed. |
| 58 | Return<void> registerEventCallback( |
chenpaul | b690fb8 | 2021-03-16 22:49:18 +0800 | [diff] [blame] | 59 | const sp<V1_0::IWifiEventCallback>& event_callback, |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 60 | registerEventCallback_cb hidl_status_cb) override; |
chenpaul | b690fb8 | 2021-03-16 22:49:18 +0800 | [diff] [blame] | 61 | Return<void> registerEventCallback_1_5( |
| 62 | const sp<V1_5::IWifiEventCallback>& event_callback, |
| 63 | registerEventCallback_1_5_cb hidl_status_cb) override; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 64 | Return<bool> isStarted() override; |
| 65 | Return<void> start(start_cb hidl_status_cb) override; |
| 66 | Return<void> stop(stop_cb hidl_status_cb) override; |
| 67 | Return<void> getChipIds(getChipIds_cb hidl_status_cb) override; |
| 68 | Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 69 | Return<void> debug(const hidl_handle& handle, |
| 70 | const hidl_vec<hidl_string>& options) override; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 71 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 72 | private: |
| 73 | enum class RunState { STOPPED, STARTED, STOPPING }; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 74 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 75 | // Corresponding worker functions for the HIDL methods. |
| 76 | WifiStatus registerEventCallbackInternal( |
chenpaul | b690fb8 | 2021-03-16 22:49:18 +0800 | [diff] [blame] | 77 | const sp<V1_0::IWifiEventCallback>& event_callback __unused); |
| 78 | WifiStatus registerEventCallbackInternal_1_5( |
| 79 | const sp<V1_5::IWifiEventCallback>& event_callback); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 80 | WifiStatus startInternal(); |
| 81 | WifiStatus stopInternal(std::unique_lock<std::recursive_mutex>* lock); |
| 82 | std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal(); |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 83 | std::pair<WifiStatus, sp<V1_4::IWifiChip>> getChipInternal(ChipId chip_id); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 84 | |
Roshan Pius | 8fc6d17 | 2017-11-27 16:08:27 -0800 | [diff] [blame] | 85 | WifiStatus initializeModeControllerAndLegacyHal(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 86 | WifiStatus stopLegacyHalAndDeinitializeModeController( |
| 87 | std::unique_lock<std::recursive_mutex>* lock); |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 88 | ChipId getChipIdFromWifiChip(sp<WifiChip>& chip); |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 89 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 90 | // Instance is created in this root level |IWifi| HIDL interface object |
| 91 | // and shared with all the child HIDL interface objects. |
Roshan Pius | c885df0 | 2019-05-21 14:49:05 -0700 | [diff] [blame] | 92 | std::shared_ptr<wifi_system::InterfaceTool> iface_tool_; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 93 | std::shared_ptr<legacy_hal::WifiLegacyHalFactory> legacy_hal_factory_; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 94 | std::shared_ptr<mode_controller::WifiModeController> mode_controller_; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 95 | std::vector<std::shared_ptr<legacy_hal::WifiLegacyHal>> legacy_hals_; |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 96 | std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags_; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 97 | RunState run_state_; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 98 | std::vector<sp<WifiChip>> chips_; |
chenpaul | b690fb8 | 2021-03-16 22:49:18 +0800 | [diff] [blame] | 99 | hidl_callback_util::HidlCallbackHandler<V1_5::IWifiEventCallback> |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 100 | event_cb_handler_; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 101 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(Wifi); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 105 | } // namespace implementation |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 106 | } // namespace V1_5 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 107 | } // namespace wifi |
| 108 | } // namespace hardware |
| 109 | } // namespace android |
| 110 | |
| 111 | #endif // WIFI_H_ |