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> 21 22 #include <android-base/macros.h> 23 #include <android/hardware/wifi/1.5/IWifi.h> 24 #include <utils/Looper.h> 25 26 #include "hidl_callback_util.h" 27 #include "wifi_chip.h" 28 #include "wifi_feature_flags.h" 29 #include "wifi_legacy_hal.h" 30 #include "wifi_legacy_hal_factory.h" 31 #include "wifi_mode_controller.h" 32 33 namespace android { 34 namespace hardware { 35 namespace wifi { 36 namespace V1_5 { 37 namespace implementation { 38 39 /** 40 * Root HIDL interface object used to control the Wifi HAL. 41 */ 42 class Wifi : public V1_5::IWifi { 43 public: 44 Wifi(const std::shared_ptr<wifi_system::InterfaceTool> iface_tool, 45 const std::shared_ptr<legacy_hal::WifiLegacyHalFactory> 46 legacy_hal_factory, 47 const std::shared_ptr<mode_controller::WifiModeController> 48 mode_controller, 49 const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags); 50 51 bool isValid(); 52 53 // HIDL methods exposed. 54 Return<void> registerEventCallback( 55 const sp<V1_0::IWifiEventCallback>& event_callback, 56 registerEventCallback_cb hidl_status_cb) override; 57 Return<void> registerEventCallback_1_5( 58 const sp<V1_5::IWifiEventCallback>& event_callback, 59 registerEventCallback_1_5_cb hidl_status_cb) override; 60 Return<bool> isStarted() override; 61 Return<void> start(start_cb hidl_status_cb) override; 62 Return<void> stop(stop_cb hidl_status_cb) override; 63 Return<void> getChipIds(getChipIds_cb hidl_status_cb) override; 64 Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override; 65 Return<void> debug(const hidl_handle& handle, 66 const hidl_vec<hidl_string>& options) override; 67 68 private: 69 enum class RunState { STOPPED, STARTED, STOPPING }; 70 71 // Corresponding worker functions for the HIDL methods. 72 WifiStatus registerEventCallbackInternal( 73 const sp<V1_0::IWifiEventCallback>& event_callback __unused); 74 WifiStatus registerEventCallbackInternal_1_5( 75 const sp<V1_5::IWifiEventCallback>& event_callback); 76 WifiStatus startInternal(); 77 WifiStatus stopInternal(std::unique_lock<std::recursive_mutex>* lock); 78 std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal(); 79 std::pair<WifiStatus, sp<V1_4::IWifiChip>> getChipInternal(ChipId chip_id); 80 81 WifiStatus initializeModeControllerAndLegacyHal(); 82 WifiStatus stopLegacyHalAndDeinitializeModeController( 83 std::unique_lock<std::recursive_mutex>* lock); 84 ChipId getChipIdFromWifiChip(sp<WifiChip>& chip); 85 86 // Instance is created in this root level |IWifi| HIDL interface object 87 // and shared with all the child HIDL interface objects. 88 std::shared_ptr<wifi_system::InterfaceTool> iface_tool_; 89 std::shared_ptr<legacy_hal::WifiLegacyHalFactory> legacy_hal_factory_; 90 std::shared_ptr<mode_controller::WifiModeController> mode_controller_; 91 std::vector<std::shared_ptr<legacy_hal::WifiLegacyHal>> legacy_hals_; 92 std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags_; 93 RunState run_state_; 94 std::vector<sp<WifiChip>> chips_; 95 hidl_callback_util::HidlCallbackHandler<V1_5::IWifiEventCallback> 96 event_cb_handler_; 97 98 DISALLOW_COPY_AND_ASSIGN(Wifi); 99 }; 100 101 } // namespace implementation 102 } // namespace V1_5 103 } // namespace wifi 104 } // namespace hardware 105 } // namespace android 106 107 #endif // WIFI_H_ 108