• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.3/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_mode_controller.h"
31 
32 namespace android {
33 namespace hardware {
34 namespace wifi {
35 namespace V1_3 {
36 namespace implementation {
37 
38 /**
39  * Root HIDL interface object used to control the Wifi HAL.
40  */
41 class Wifi : public V1_3::IWifi {
42    public:
43     Wifi(const std::shared_ptr<wifi_system::InterfaceTool> iface_tool,
44          const std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
45          const std::shared_ptr<mode_controller::WifiModeController>
46              mode_controller,
47          const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
48          const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags);
49 
50     bool isValid();
51 
52     // HIDL methods exposed.
53     Return<void> registerEventCallback(
54         const sp<IWifiEventCallback>& event_callback,
55         registerEventCallback_cb hidl_status_cb) override;
56     Return<bool> isStarted() override;
57     Return<void> start(start_cb hidl_status_cb) override;
58     Return<void> stop(stop_cb hidl_status_cb) override;
59     Return<void> getChipIds(getChipIds_cb hidl_status_cb) override;
60     Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override;
61     Return<void> debug(const hidl_handle& handle,
62                        const hidl_vec<hidl_string>& options) override;
63 
64    private:
65     enum class RunState { STOPPED, STARTED, STOPPING };
66 
67     // Corresponding worker functions for the HIDL methods.
68     WifiStatus registerEventCallbackInternal(
69         const sp<IWifiEventCallback>& event_callback);
70     WifiStatus startInternal();
71     WifiStatus stopInternal(std::unique_lock<std::recursive_mutex>* lock);
72     std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal();
73     std::pair<WifiStatus, sp<IWifiChip>> getChipInternal(ChipId chip_id);
74 
75     WifiStatus initializeModeControllerAndLegacyHal();
76     WifiStatus stopLegacyHalAndDeinitializeModeController(
77         std::unique_lock<std::recursive_mutex>* lock);
78 
79     // Instance is created in this root level |IWifi| HIDL interface object
80     // and shared with all the child HIDL interface objects.
81     std::shared_ptr<wifi_system::InterfaceTool> iface_tool_;
82     std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
83     std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
84     std::shared_ptr<iface_util::WifiIfaceUtil> iface_util_;
85     std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags_;
86     RunState run_state_;
87     sp<WifiChip> chip_;
88     hidl_callback_util::HidlCallbackHandler<IWifiEventCallback>
89         event_cb_handler_;
90 
91     DISALLOW_COPY_AND_ASSIGN(Wifi);
92 };
93 
94 }  // namespace implementation
95 }  // namespace V1_3
96 }  // namespace wifi
97 }  // namespace hardware
98 }  // namespace android
99 
100 #endif  // WIFI_H_
101