blob: 1ade2d8b9bc7bda3594800741ee13d29757b156c [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>
Roshan Piusdbd83ef2017-06-20 12:05:40 -070023#include <android/hardware/wifi/1.1/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 Piusaabe5752016-09-29 09:03:59 -070028#include "wifi_legacy_hal.h"
Roshan Pius52947fb2016-11-18 11:38:07 -080029#include "wifi_mode_controller.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070030
31namespace android {
32namespace hardware {
33namespace wifi {
Roshan Piusdbd83ef2017-06-20 12:05:40 -070034namespace V1_1 {
Roshan Pius79a99752016-10-04 13:03:58 -070035namespace implementation {
Roshan Piusdbd83ef2017-06-20 12:05:40 -070036using namespace android::hardware::wifi::V1_0;
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 */
Roshan Piusdbd83ef2017-06-20 12:05:40 -070041class Wifi : public V1_1::IWifi {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070042 public:
Roshan Piusaabe5752016-09-29 09:03:59 -070043 Wifi();
Roshan Pius3c4e8a32016-10-03 14:53:58 -070044
Roshan Pius56476652016-10-26 14:43:05 -070045 bool isValid();
46
Roshan Piusaabe5752016-09-29 09:03:59 -070047 // HIDL methods exposed.
Roshan Pius3c4e8a32016-10-03 14:53:58 -070048 Return<void> registerEventCallback(
Roshan Pius56476652016-10-26 14:43:05 -070049 const sp<IWifiEventCallback>& event_callback,
50 registerEventCallback_cb hidl_status_cb) override;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070051 Return<bool> isStarted() override;
Roshan Pius503582e2016-10-11 08:25:30 -070052 Return<void> start(start_cb hidl_status_cb) override;
53 Return<void> stop(stop_cb hidl_status_cb) override;
54 Return<void> getChipIds(getChipIds_cb hidl_status_cb) override;
55 Return<void> getChip(ChipId chip_id, getChip_cb hidl_status_cb) override;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070056
57 private:
Roshan Piusaabe5752016-09-29 09:03:59 -070058 enum class RunState { STOPPED, STARTED, STOPPING };
Roshan Pius3c4e8a32016-10-03 14:53:58 -070059
Roshan Pius56476652016-10-26 14:43:05 -070060 // Corresponding worker functions for the HIDL methods.
61 WifiStatus registerEventCallbackInternal(
62 const sp<IWifiEventCallback>& event_callback);
63 WifiStatus startInternal();
64 WifiStatus stopInternal();
65 std::pair<WifiStatus, std::vector<ChipId>> getChipIdsInternal();
66 std::pair<WifiStatus, sp<IWifiChip>> getChipInternal(ChipId chip_id);
67
Roshan Pius52947fb2016-11-18 11:38:07 -080068 WifiStatus initializeLegacyHal();
69 WifiStatus stopLegacyHalAndDeinitializeModeController();
70
Roshan Piusaabe5752016-09-29 09:03:59 -070071 // Instance is created in this root level |IWifi| HIDL interface object
72 // and shared with all the child HIDL interface objects.
Roshan Pius6cedc972016-10-28 10:11:17 -070073 std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
Roshan Pius52947fb2016-11-18 11:38:07 -080074 std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
Roshan Piusaabe5752016-09-29 09:03:59 -070075 RunState run_state_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070076 sp<WifiChip> chip_;
Roshan Piusd37341f2017-01-31 13:13:28 -080077 hidl_callback_util::HidlCallbackHandler<IWifiEventCallback> event_cb_handler_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070078
Roshan Pius3c4e8a32016-10-03 14:53:58 -070079 DISALLOW_COPY_AND_ASSIGN(Wifi);
80};
81
Roshan Pius79a99752016-10-04 13:03:58 -070082} // namespace implementation
Roshan Piusdbd83ef2017-06-20 12:05:40 -070083} // namespace V1_1
Roshan Pius3c4e8a32016-10-03 14:53:58 -070084} // namespace wifi
85} // namespace hardware
86} // namespace android
87
88#endif // WIFI_H_