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 | |
| 20 | #include <functional> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 21 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 22 | #include <android-base/macros.h> |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 23 | #include <android/hardware/wifi/1.2/IWifi.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 24 | #include <utils/Looper.h> |
| 25 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 26 | #include "hidl_callback_util.h" |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 27 | #include "wifi_chip.h" |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 28 | #include "wifi_feature_flags.h" |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 29 | #include "wifi_legacy_hal.h" |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 30 | #include "wifi_mode_controller.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | namespace hardware { |
| 34 | namespace wifi { |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 35 | namespace V1_2 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 36 | namespace implementation { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 37 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Root HIDL interface object used to control the Wifi HAL. |
| 40 | */ |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 41 | class Wifi : public V1_2::IWifi { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 42 | public: |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 43 | Wifi(const std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 44 | const std::shared_ptr<mode_controller::WifiModeController> |
| 45 | mode_controller, |
| 46 | const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 47 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 48 | bool isValid(); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 49 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 50 | // HIDL methods exposed. |
| 51 | Return<void> registerEventCallback( |
| 52 | const sp<IWifiEventCallback>& event_callback, |
| 53 | registerEventCallback_cb hidl_status_cb) override; |
| 54 | Return<bool> isStarted() override; |
| 55 | Return<void> start(start_cb hidl_status_cb) override; |
| 56 | Return<void> stop(stop_cb hidl_status_cb) override; |
| 57 | Return<void> getChipIds(getChipIds_cb hidl_status_cb) override; |
| 58 | Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 59 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 60 | private: |
| 61 | enum class RunState { STOPPED, STARTED, STOPPING }; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 62 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 63 | // Corresponding worker functions for the HIDL methods. |
| 64 | WifiStatus registerEventCallbackInternal( |
| 65 | const sp<IWifiEventCallback>& event_callback); |
| 66 | WifiStatus startInternal(); |
| 67 | WifiStatus stopInternal(std::unique_lock<std::recursive_mutex>* lock); |
| 68 | std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal(); |
| 69 | std::pair<WifiStatus, sp<IWifiChip>> getChipInternal(ChipId chip_id); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 70 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 71 | WifiStatus initializeLegacyHal(); |
| 72 | WifiStatus stopLegacyHalAndDeinitializeModeController( |
| 73 | std::unique_lock<std::recursive_mutex>* lock); |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 74 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 75 | // Instance is created in this root level |IWifi| HIDL interface object |
| 76 | // and shared with all the child HIDL interface objects. |
| 77 | std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; |
| 78 | std::shared_ptr<mode_controller::WifiModeController> mode_controller_; |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 79 | std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags_; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 80 | RunState run_state_; |
| 81 | sp<WifiChip> chip_; |
| 82 | hidl_callback_util::HidlCallbackHandler<IWifiEventCallback> |
| 83 | event_cb_handler_; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 84 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(Wifi); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 88 | } // namespace implementation |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 89 | } // namespace V1_2 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 90 | } // namespace wifi |
| 91 | } // namespace hardware |
| 92 | } // namespace android |
| 93 | |
| 94 | #endif // WIFI_H_ |