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