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 | #include <android-base/logging.h> |
Peter Kalauskas | 1f6e6e3 | 2019-01-14 17:11:31 -0800 | [diff] [blame] | 18 | #include <hidl/HidlLazyUtils.h> |
Martijn Coenen | 4faa7f5 | 2016-12-28 17:08:07 +0100 | [diff] [blame] | 19 | #include <hidl/HidlTransportSupport.h> |
lesl | 75915c3 | 2020-11-30 19:09:31 +0800 | [diff] [blame^] | 20 | #include <signal.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 21 | #include <utils/Looper.h> |
| 22 | #include <utils/StrongPointer.h> |
| 23 | |
| 24 | #include "wifi.h" |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 25 | #include "wifi_feature_flags.h" |
| 26 | #include "wifi_legacy_hal.h" |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 27 | #include "wifi_legacy_hal_factory.h" |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 28 | #include "wifi_mode_controller.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 29 | |
Martijn Coenen | 4faa7f5 | 2016-12-28 17:08:07 +0100 | [diff] [blame] | 30 | using android::hardware::configureRpcThreadpool; |
| 31 | using android::hardware::joinRpcThreadpool; |
Peter Kalauskas | 1f6e6e3 | 2019-01-14 17:11:31 -0800 | [diff] [blame] | 32 | using android::hardware::LazyServiceRegistrar; |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 33 | using android::hardware::wifi::V1_5::implementation::feature_flags:: |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 34 | WifiFeatureFlags; |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 35 | using android::hardware::wifi::V1_5::implementation::iface_util::WifiIfaceUtil; |
| 36 | using android::hardware::wifi::V1_5::implementation::legacy_hal::WifiLegacyHal; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 37 | using android::hardware::wifi::V1_5::implementation::legacy_hal:: |
| 38 | WifiLegacyHalFactory; |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 39 | using android::hardware::wifi::V1_5::implementation::mode_controller:: |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 40 | WifiModeController; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 41 | |
Peter Kalauskas | 1f6e6e3 | 2019-01-14 17:11:31 -0800 | [diff] [blame] | 42 | #ifdef LAZY_SERVICE |
| 43 | const bool kLazyService = true; |
| 44 | #else |
| 45 | const bool kLazyService = false; |
| 46 | #endif |
| 47 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 48 | int main(int /*argc*/, char** argv) { |
lesl | 75915c3 | 2020-11-30 19:09:31 +0800 | [diff] [blame^] | 49 | signal(SIGPIPE, SIG_IGN); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 50 | android::base::InitLogging( |
| 51 | argv, android::base::LogdLogger(android::base::SYSTEM)); |
| 52 | LOG(INFO) << "Wifi Hal is booting up..."; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 53 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 54 | configureRpcThreadpool(1, true /* callerWillJoin */); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 55 | |
Roshan Pius | c885df0 | 2019-05-21 14:49:05 -0700 | [diff] [blame] | 56 | const auto iface_tool = |
| 57 | std::make_shared<android::wifi_system::InterfaceTool>(); |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 58 | const auto legacy_hal_factory = |
| 59 | std::make_shared<WifiLegacyHalFactory>(iface_tool); |
| 60 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 61 | // Setup hwbinder service |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 62 | android::sp<android::hardware::wifi::V1_5::IWifi> service = |
| 63 | new android::hardware::wifi::V1_5::implementation::Wifi( |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 64 | iface_tool, legacy_hal_factory, |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 65 | std::make_shared<WifiModeController>(), |
Roshan Pius | c885df0 | 2019-05-21 14:49:05 -0700 | [diff] [blame] | 66 | std::make_shared<WifiIfaceUtil>(iface_tool), |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 67 | std::make_shared<WifiFeatureFlags>()); |
Peter Kalauskas | 1f6e6e3 | 2019-01-14 17:11:31 -0800 | [diff] [blame] | 68 | if (kLazyService) { |
Peter Kalauskas | caed24b | 2019-08-14 12:11:57 -0700 | [diff] [blame] | 69 | auto registrar = LazyServiceRegistrar::getInstance(); |
Peter Kalauskas | 1f6e6e3 | 2019-01-14 17:11:31 -0800 | [diff] [blame] | 70 | CHECK_EQ(registrar.registerService(service), android::NO_ERROR) |
| 71 | << "Failed to register wifi HAL"; |
| 72 | } else { |
| 73 | CHECK_EQ(service->registerAsService(), android::NO_ERROR) |
| 74 | << "Failed to register wifi HAL"; |
| 75 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 76 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 77 | joinRpcThreadpool(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 78 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 79 | LOG(INFO) << "Wifi Hal is terminating..."; |
| 80 | return 0; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 81 | } |