blob: 92712fd961bc239717c59a8a628a92931c0697ba [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>
21#include <set>
22#include <thread>
23
24#include <android/hardware/wifi/1.0/IWifi.h>
25#include <android-base/macros.h>
26#include <hardware_legacy/wifi_hal.h>
27#include <utils/Looper.h>
28
29#include "wifi_hal_state.h"
30
31namespace android {
32namespace hardware {
33namespace wifi {
34
35class WifiChip;
36
37class Wifi : public V1_0::IWifi {
38 public:
39 Wifi(sp<Looper>& looper);
40
41 Return<void> registerEventCallback(
42 const sp<V1_0::IWifiEventCallback>& callback) override;
43
44 Return<bool> isStarted() override;
45 Return<void> start() override;
46 Return<void> stop() override;
47
48 Return<void> getChip(getChip_cb cb) override;
49
50 private:
51 const wifi_interface_handle kInterfaceNotFoundHandle = nullptr;
52 /** Get a HAL interface handle by name */
53 wifi_interface_handle FindInterfaceHandle(const std::string& ifname);
54
55 /**
56 * Called to indicate that the HAL implementation cleanup may be complete and
57 * the rest of HAL cleanup should be performed.
58 */
59 void FinishHalCleanup();
60
61 /**
62 * Entry point for HAL event loop thread. Handles cleanup when terminating.
63 */
64 void DoHalEventLoop();
65
66 std::set<sp<V1_0::IWifiEventCallback>> callbacks_;
67 sp<WifiChip> chip_;
68
69 WifiHalState state_;
70 std::thread event_loop_thread_;
71
72 // Variables to hold state while stopping the HAL
73 bool awaiting_hal_cleanup_command_;
74 bool awaiting_hal_event_loop_termination_;
75
76 DISALLOW_COPY_AND_ASSIGN(Wifi);
77};
78
79} // namespace wifi
80} // namespace hardware
81} // namespace android
82
83#endif // WIFI_H_