Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 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> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 21 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 22 | #include <android-base/macros.h> |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 23 | #include <android/hardware/wifi/1.1/IWifi.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 24 | #include <utils/Looper.h> |
| 25 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 26 | #include "hidl_callback_util.h" |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 27 | #include "wifi_chip.h" |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 28 | #include "wifi_legacy_hal.h" |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 29 | #include "wifi_mode_controller.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | namespace hardware { |
| 33 | namespace wifi { |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 34 | namespace V1_1 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 35 | namespace implementation { |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 36 | using namespace android::hardware::wifi::V1_0; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 37 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Root HIDL interface object used to control the Wifi HAL. |
| 40 | */ |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 41 | class Wifi : public V1_1::IWifi { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 42 | public: |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 43 | Wifi(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 44 | |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 45 | bool isValid(); |
| 46 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 47 | // HIDL methods exposed. |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 48 | Return<void> registerEventCallback( |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 49 | const sp<IWifiEventCallback>& event_callback, |
| 50 | registerEventCallback_cb hidl_status_cb) override; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 51 | Return<bool> isStarted() override; |
Roshan Pius | 503582e | 2016-10-11 08:25:30 -0700 | [diff] [blame] | 52 | 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 Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 56 | |
| 57 | private: |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 58 | enum class RunState { STOPPED, STARTED, STOPPING }; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 59 | |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 60 | // 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 Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 68 | WifiStatus initializeLegacyHal(); |
| 69 | WifiStatus stopLegacyHalAndDeinitializeModeController(); |
| 70 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 71 | // Instance is created in this root level |IWifi| HIDL interface object |
| 72 | // and shared with all the child HIDL interface objects. |
Roshan Pius | 6cedc97 | 2016-10-28 10:11:17 -0700 | [diff] [blame] | 73 | std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 74 | std::shared_ptr<mode_controller::WifiModeController> mode_controller_; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 75 | RunState run_state_; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 76 | sp<WifiChip> chip_; |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 77 | hidl_callback_util::HidlCallbackHandler<IWifiEventCallback> event_cb_handler_; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 78 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 79 | DISALLOW_COPY_AND_ASSIGN(Wifi); |
| 80 | }; |
| 81 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 82 | } // namespace implementation |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 83 | } // namespace V1_1 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 84 | } // namespace wifi |
| 85 | } // namespace hardware |
| 86 | } // namespace android |
| 87 | |
| 88 | #endif // WIFI_H_ |