blob: 435358e79792d0dc86a14cfd37b0c637a879f1f1 [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
Prabir Pradhandda60442021-08-18 08:49:49 -070020// 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
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080024#include <android/hardware/wifi/1.6/IWifi.h>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070025
Roshan Pius3c4e8a32016-10-03 14:53:58 -070026#include <android-base/macros.h>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070027#include <utils/Looper.h>
Prabir Pradhandda60442021-08-18 08:49:49 -070028#include <functional>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070029
Roshan Piusd37341f2017-01-31 13:13:28 -080030#include "hidl_callback_util.h"
Roshan Pius79a99752016-10-04 13:03:58 -070031#include "wifi_chip.h"
Roshan Pius200a17d2017-11-01 13:03:35 -070032#include "wifi_feature_flags.h"
Roshan Piusaabe5752016-09-29 09:03:59 -070033#include "wifi_legacy_hal.h"
Jimmy Chen2dddd792019-12-23 17:50:39 +020034#include "wifi_legacy_hal_factory.h"
Roshan Pius52947fb2016-11-18 11:38:07 -080035#include "wifi_mode_controller.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070036
37namespace android {
38namespace hardware {
39namespace wifi {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080040namespace V1_6 {
Roshan Pius79a99752016-10-04 13:03:58 -070041namespace implementation {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070042
Roshan Piusaabe5752016-09-29 09:03:59 -070043/**
44 * Root HIDL interface object used to control the Wifi HAL.
45 */
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080046class Wifi : public V1_6::IWifi {
47 public:
Roshan Piusc885df02019-05-21 14:49:05 -070048 Wifi(const std::shared_ptr<wifi_system::InterfaceTool> iface_tool,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080049 const std::shared_ptr<legacy_hal::WifiLegacyHalFactory> legacy_hal_factory,
50 const std::shared_ptr<mode_controller::WifiModeController> mode_controller,
Roshan Pius200a17d2017-11-01 13:03:35 -070051 const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070052
Roshan Piusabcf78f2017-10-06 16:30:38 -070053 bool isValid();
Roshan Pius56476652016-10-26 14:43:05 -070054
Roshan Piusabcf78f2017-10-06 16:30:38 -070055 // HIDL methods exposed.
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080056 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;
Roshan Piusabcf78f2017-10-06 16:30:38 -070060 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;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080065 Return<void> debug(const hidl_handle& handle, const hidl_vec<hidl_string>& options) override;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070066
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080067 private:
Roshan Piusabcf78f2017-10-06 16:30:38 -070068 enum class RunState { STOPPED, STARTED, STOPPING };
Roshan Pius3c4e8a32016-10-03 14:53:58 -070069
Roshan Piusabcf78f2017-10-06 16:30:38 -070070 // Corresponding worker functions for the HIDL methods.
71 WifiStatus registerEventCallbackInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080072 const sp<V1_0::IWifiEventCallback>& event_callback __unused);
chenpaulb690fb82021-03-16 22:49:18 +080073 WifiStatus registerEventCallbackInternal_1_5(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080074 const sp<V1_5::IWifiEventCallback>& event_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -070075 WifiStatus startInternal();
76 WifiStatus stopInternal(std::unique_lock<std::recursive_mutex>* lock);
77 std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal();
Jimmy Chend460df32019-11-29 17:31:22 +020078 std::pair<WifiStatus, sp<V1_4::IWifiChip>> getChipInternal(ChipId chip_id);
Roshan Pius56476652016-10-26 14:43:05 -070079
Roshan Pius8fc6d172017-11-27 16:08:27 -080080 WifiStatus initializeModeControllerAndLegacyHal();
Roshan Piusabcf78f2017-10-06 16:30:38 -070081 WifiStatus stopLegacyHalAndDeinitializeModeController(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080082 std::unique_lock<std::recursive_mutex>* lock);
Jimmy Chen2dddd792019-12-23 17:50:39 +020083 ChipId getChipIdFromWifiChip(sp<WifiChip>& chip);
Roshan Pius52947fb2016-11-18 11:38:07 -080084
Roshan Piusabcf78f2017-10-06 16:30:38 -070085 // Instance is created in this root level |IWifi| HIDL interface object
86 // and shared with all the child HIDL interface objects.
Roshan Piusc885df02019-05-21 14:49:05 -070087 std::shared_ptr<wifi_system::InterfaceTool> iface_tool_;
Jimmy Chen2dddd792019-12-23 17:50:39 +020088 std::shared_ptr<legacy_hal::WifiLegacyHalFactory> legacy_hal_factory_;
Roshan Piusabcf78f2017-10-06 16:30:38 -070089 std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
Jimmy Chen2dddd792019-12-23 17:50:39 +020090 std::vector<std::shared_ptr<legacy_hal::WifiLegacyHal>> legacy_hals_;
Roshan Pius200a17d2017-11-01 13:03:35 -070091 std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags_;
Roshan Piusabcf78f2017-10-06 16:30:38 -070092 RunState run_state_;
Jimmy Chen2dddd792019-12-23 17:50:39 +020093 std::vector<sp<WifiChip>> chips_;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080094 hidl_callback_util::HidlCallbackHandler<V1_5::IWifiEventCallback> event_cb_handler_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070095
Roshan Piusabcf78f2017-10-06 16:30:38 -070096 DISALLOW_COPY_AND_ASSIGN(Wifi);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070097};
98
Roshan Pius79a99752016-10-04 13:03:58 -070099} // namespace implementation
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800100} // namespace V1_6
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700101} // namespace wifi
102} // namespace hardware
103} // namespace android
104
105#endif // WIFI_H_