blob: 01227418a11ff04b41be2fb93e8fb4c58b9551ee [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
Roshan Pius3c4e8a32016-10-03 14:53:58 -070024#include <android-base/macros.h>
Roshan Pius79a99752016-10-04 13:03:58 -070025#include <android/hardware/wifi/1.0/IWifi.h>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070026#include <hardware_legacy/wifi_hal.h>
27#include <utils/Looper.h>
28
29#include "wifi_hal_state.h"
Roshan Pius79a99752016-10-04 13:03:58 -070030#include "wifi_chip.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070031
32namespace android {
33namespace hardware {
34namespace wifi {
Roshan Pius79a99752016-10-04 13:03:58 -070035namespace V1_0 {
36namespace implementation {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070037
Roshan Pius79a99752016-10-04 13:03:58 -070038class Wifi : public IWifi {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070039 public:
40 Wifi(sp<Looper>& looper);
41
42 Return<void> registerEventCallback(
Roshan Pius79a99752016-10-04 13:03:58 -070043 const sp<IWifiEventCallback>& callback) override;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070044
45 Return<bool> isStarted() override;
46 Return<void> start() override;
47 Return<void> stop() override;
48
49 Return<void> getChip(getChip_cb cb) override;
50
51 private:
52 const wifi_interface_handle kInterfaceNotFoundHandle = nullptr;
53 /** Get a HAL interface handle by name */
54 wifi_interface_handle FindInterfaceHandle(const std::string& ifname);
55
56 /**
57 * Called to indicate that the HAL implementation cleanup may be complete and
58 * the rest of HAL cleanup should be performed.
59 */
60 void FinishHalCleanup();
61
62 /**
63 * Entry point for HAL event loop thread. Handles cleanup when terminating.
64 */
65 void DoHalEventLoop();
66
Roshan Pius79a99752016-10-04 13:03:58 -070067 std::set<sp<IWifiEventCallback>> callbacks_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070068 sp<WifiChip> chip_;
69
70 WifiHalState state_;
71 std::thread event_loop_thread_;
72
73 // Variables to hold state while stopping the HAL
74 bool awaiting_hal_cleanup_command_;
75 bool awaiting_hal_event_loop_termination_;
76
77 DISALLOW_COPY_AND_ASSIGN(Wifi);
78};
79
Roshan Pius79a99752016-10-04 13:03:58 -070080} // namespace implementation
81} // namespace V1_0
Roshan Pius3c4e8a32016-10-03 14:53:58 -070082} // namespace wifi
83} // namespace hardware
84} // namespace android
85
86#endif // WIFI_H_