blob: c4ab7732bdadcc7e8ae0057aee189b7f4c771f92 [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>
Jong Wook Kimda830c92018-07-23 15:29:38 -070023#include <android/hardware/wifi/1.3/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"
Roshan Pius52947fb2016-11-18 11:38:07 -080030#include "wifi_mode_controller.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070031
32namespace android {
33namespace hardware {
34namespace wifi {
Jong Wook Kimda830c92018-07-23 15:29:38 -070035namespace V1_3 {
Roshan Pius79a99752016-10-04 13:03:58 -070036namespace implementation {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070037
Roshan Piusaabe5752016-09-29 09:03:59 -070038/**
39 * Root HIDL interface object used to control the Wifi HAL.
40 */
Jong Wook Kimda830c92018-07-23 15:29:38 -070041class Wifi : public V1_3::IWifi {
Roshan Piusabcf78f2017-10-06 16:30:38 -070042 public:
Roshan Pius200a17d2017-11-01 13:03:35 -070043 Wifi(const std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
44 const std::shared_ptr<mode_controller::WifiModeController>
45 mode_controller,
Roshan Pius99dab382019-02-14 07:57:10 -080046 const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
Roshan Pius200a17d2017-11-01 13:03:35 -070047 const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070048
Roshan Piusabcf78f2017-10-06 16:30:38 -070049 bool isValid();
Roshan Pius56476652016-10-26 14:43:05 -070050
Roshan Piusabcf78f2017-10-06 16:30:38 -070051 // HIDL methods exposed.
52 Return<void> registerEventCallback(
53 const sp<IWifiEventCallback>& event_callback,
54 registerEventCallback_cb hidl_status_cb) override;
55 Return<bool> isStarted() override;
56 Return<void> start(start_cb hidl_status_cb) override;
57 Return<void> stop(stop_cb hidl_status_cb) override;
58 Return<void> getChipIds(getChipIds_cb hidl_status_cb) override;
59 Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override;
xshu5899e8e2018-01-09 15:36:03 -080060 Return<void> debug(const hidl_handle& handle,
61 const hidl_vec<hidl_string>& options) override;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070062
Roshan Piusabcf78f2017-10-06 16:30:38 -070063 private:
64 enum class RunState { STOPPED, STARTED, STOPPING };
Roshan Pius3c4e8a32016-10-03 14:53:58 -070065
Roshan Piusabcf78f2017-10-06 16:30:38 -070066 // Corresponding worker functions for the HIDL methods.
67 WifiStatus registerEventCallbackInternal(
68 const sp<IWifiEventCallback>& event_callback);
69 WifiStatus startInternal();
70 WifiStatus stopInternal(std::unique_lock<std::recursive_mutex>* lock);
71 std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal();
72 std::pair<WifiStatus, sp<IWifiChip>> getChipInternal(ChipId chip_id);
Roshan Pius56476652016-10-26 14:43:05 -070073
Roshan Pius8fc6d172017-11-27 16:08:27 -080074 WifiStatus initializeModeControllerAndLegacyHal();
Roshan Piusabcf78f2017-10-06 16:30:38 -070075 WifiStatus stopLegacyHalAndDeinitializeModeController(
76 std::unique_lock<std::recursive_mutex>* lock);
Roshan Pius52947fb2016-11-18 11:38:07 -080077
Roshan Piusabcf78f2017-10-06 16:30:38 -070078 // Instance is created in this root level |IWifi| HIDL interface object
79 // and shared with all the child HIDL interface objects.
80 std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
81 std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
Roshan Pius99dab382019-02-14 07:57:10 -080082 std::shared_ptr<iface_util::WifiIfaceUtil> iface_util_;
Roshan Pius200a17d2017-11-01 13:03:35 -070083 std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags_;
Roshan Piusabcf78f2017-10-06 16:30:38 -070084 RunState run_state_;
85 sp<WifiChip> chip_;
86 hidl_callback_util::HidlCallbackHandler<IWifiEventCallback>
87 event_cb_handler_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070088
Roshan Piusabcf78f2017-10-06 16:30:38 -070089 DISALLOW_COPY_AND_ASSIGN(Wifi);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070090};
91
Roshan Pius79a99752016-10-04 13:03:58 -070092} // namespace implementation
Jong Wook Kimda830c92018-07-23 15:29:38 -070093} // namespace V1_3
Roshan Pius3c4e8a32016-10-03 14:53:58 -070094} // namespace wifi
95} // namespace hardware
96} // namespace android
97
98#endif // WIFI_H_