blob: 9f5a1b0a3c6dbed61ed3d477a0a11b8180428139 [file] [log] [blame]
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001/*
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 Pius3c4e8a32016-10-03 14:53:58 -070021
Roshan Pius3c4e8a32016-10-03 14:53:58 -070022#include <android-base/macros.h>
Jimmy Chend460df32019-11-29 17:31:22 +020023#include <android/hardware/wifi/1.5/IWifi.h>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070024#include <utils/Looper.h>
25
Roshan Piusd37341f2017-01-31 13:13:28 -080026#include "hidl_callback_util.h"
Roshan Pius79a99752016-10-04 13:03:58 -070027#include "wifi_chip.h"
Roshan Pius200a17d2017-11-01 13:03:35 -070028#include "wifi_feature_flags.h"
Roshan Piusaabe5752016-09-29 09:03:59 -070029#include "wifi_legacy_hal.h"
Jimmy Chen2dddd792019-12-23 17:50:39 +020030#include "wifi_legacy_hal_factory.h"
Roshan Pius52947fb2016-11-18 11:38:07 -080031#include "wifi_mode_controller.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070032
33namespace android {
34namespace hardware {
35namespace wifi {
Jimmy Chend460df32019-11-29 17:31:22 +020036namespace V1_5 {
Roshan Pius79a99752016-10-04 13:03:58 -070037namespace implementation {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070038
Roshan Piusaabe5752016-09-29 09:03:59 -070039/**
40 * Root HIDL interface object used to control the Wifi HAL.
41 */
Jimmy Chend460df32019-11-29 17:31:22 +020042class Wifi : public V1_5::IWifi {
Roshan Piusabcf78f2017-10-06 16:30:38 -070043 public:
Roshan Piusc885df02019-05-21 14:49:05 -070044 Wifi(const std::shared_ptr<wifi_system::InterfaceTool> iface_tool,
Jimmy Chen2dddd792019-12-23 17:50:39 +020045 const std::shared_ptr<legacy_hal::WifiLegacyHalFactory>
46 legacy_hal_factory,
Roshan Pius200a17d2017-11-01 13:03:35 -070047 const std::shared_ptr<mode_controller::WifiModeController>
48 mode_controller,
Roshan Pius99dab382019-02-14 07:57:10 -080049 const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
Roshan Pius200a17d2017-11-01 13:03:35 -070050 const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070051
Roshan Piusabcf78f2017-10-06 16:30:38 -070052 bool isValid();
Roshan Pius56476652016-10-26 14:43:05 -070053
Roshan Piusabcf78f2017-10-06 16:30:38 -070054 // HIDL methods exposed.
55 Return<void> registerEventCallback(
56 const sp<IWifiEventCallback>& event_callback,
57 registerEventCallback_cb hidl_status_cb) override;
58 Return<bool> isStarted() override;
59 Return<void> start(start_cb hidl_status_cb) override;
60 Return<void> stop(stop_cb hidl_status_cb) override;
61 Return<void> getChipIds(getChipIds_cb hidl_status_cb) override;
62 Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override;
xshu5899e8e2018-01-09 15:36:03 -080063 Return<void> debug(const hidl_handle& handle,
64 const hidl_vec<hidl_string>& options) override;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070065
Roshan Piusabcf78f2017-10-06 16:30:38 -070066 private:
67 enum class RunState { STOPPED, STARTED, STOPPING };
Roshan Pius3c4e8a32016-10-03 14:53:58 -070068
Roshan Piusabcf78f2017-10-06 16:30:38 -070069 // Corresponding worker functions for the HIDL methods.
70 WifiStatus registerEventCallbackInternal(
71 const sp<IWifiEventCallback>& event_callback);
72 WifiStatus startInternal();
73 WifiStatus stopInternal(std::unique_lock<std::recursive_mutex>* lock);
74 std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal();
Jimmy Chend460df32019-11-29 17:31:22 +020075 std::pair<WifiStatus, sp<V1_4::IWifiChip>> getChipInternal(ChipId chip_id);
Roshan Pius56476652016-10-26 14:43:05 -070076
Roshan Pius8fc6d172017-11-27 16:08:27 -080077 WifiStatus initializeModeControllerAndLegacyHal();
Roshan Piusabcf78f2017-10-06 16:30:38 -070078 WifiStatus stopLegacyHalAndDeinitializeModeController(
79 std::unique_lock<std::recursive_mutex>* lock);
Jimmy Chen2dddd792019-12-23 17:50:39 +020080 ChipId getChipIdFromWifiChip(sp<WifiChip>& chip);
Roshan Pius52947fb2016-11-18 11:38:07 -080081
Roshan Piusabcf78f2017-10-06 16:30:38 -070082 // Instance is created in this root level |IWifi| HIDL interface object
83 // and shared with all the child HIDL interface objects.
Roshan Piusc885df02019-05-21 14:49:05 -070084 std::shared_ptr<wifi_system::InterfaceTool> iface_tool_;
Jimmy Chen2dddd792019-12-23 17:50:39 +020085 std::shared_ptr<legacy_hal::WifiLegacyHalFactory> legacy_hal_factory_;
Roshan Piusabcf78f2017-10-06 16:30:38 -070086 std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
Jimmy Chen2dddd792019-12-23 17:50:39 +020087 std::vector<std::shared_ptr<legacy_hal::WifiLegacyHal>> legacy_hals_;
Roshan Pius99dab382019-02-14 07:57:10 -080088 std::shared_ptr<iface_util::WifiIfaceUtil> iface_util_;
Roshan Pius200a17d2017-11-01 13:03:35 -070089 std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags_;
Roshan Piusabcf78f2017-10-06 16:30:38 -070090 RunState run_state_;
Jimmy Chen2dddd792019-12-23 17:50:39 +020091 std::vector<sp<WifiChip>> chips_;
Roshan Piusabcf78f2017-10-06 16:30:38 -070092 hidl_callback_util::HidlCallbackHandler<IWifiEventCallback>
93 event_cb_handler_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070094
Roshan Piusabcf78f2017-10-06 16:30:38 -070095 DISALLOW_COPY_AND_ASSIGN(Wifi);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070096};
97
Roshan Pius79a99752016-10-04 13:03:58 -070098} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +020099} // namespace V1_5
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700100} // namespace wifi
101} // namespace hardware
102} // namespace android
103
104#endif // WIFI_H_