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>
18 #include <hidl/HidlLazyUtils.h>
19 #include <hidl/HidlTransportSupport.h>
20 #include <signal.h>
21 #include <utils/Looper.h>
22 #include <utils/StrongPointer.h>
23
24 #include "wifi.h"
25 #include "wifi_feature_flags.h"
26 #include "wifi_legacy_hal.h"
27 #include "wifi_legacy_hal_factory.h"
28 #include "wifi_mode_controller.h"
29
30 using android::hardware::configureRpcThreadpool;
31 using android::hardware::joinRpcThreadpool;
32 using android::hardware::LazyServiceRegistrar;
33 using android::hardware::wifi::V1_5::implementation::feature_flags::
34 WifiFeatureFlags;
35 using android::hardware::wifi::V1_5::implementation::legacy_hal::WifiLegacyHal;
36 using android::hardware::wifi::V1_5::implementation::legacy_hal::
37 WifiLegacyHalFactory;
38 using android::hardware::wifi::V1_5::implementation::mode_controller::
39 WifiModeController;
40
41 #ifdef LAZY_SERVICE
42 const bool kLazyService = true;
43 #else
44 const bool kLazyService = false;
45 #endif
46
main(int,char ** argv)47 int main(int /*argc*/, char** argv) {
48 signal(SIGPIPE, SIG_IGN);
49 android::base::InitLogging(
50 argv, android::base::LogdLogger(android::base::SYSTEM));
51 LOG(INFO) << "Wifi Hal is booting up...";
52
53 configureRpcThreadpool(1, true /* callerWillJoin */);
54
55 const auto iface_tool =
56 std::make_shared<android::wifi_system::InterfaceTool>();
57 const auto legacy_hal_factory =
58 std::make_shared<WifiLegacyHalFactory>(iface_tool);
59
60 // Setup hwbinder service
61 android::sp<android::hardware::wifi::V1_5::IWifi> service =
62 new android::hardware::wifi::V1_5::implementation::Wifi(
63 iface_tool, legacy_hal_factory,
64 std::make_shared<WifiModeController>(),
65 std::make_shared<WifiFeatureFlags>());
66 if (kLazyService) {
67 auto registrar = LazyServiceRegistrar::getInstance();
68 CHECK_EQ(registrar.registerService(service), android::NO_ERROR)
69 << "Failed to register wifi HAL";
70 } else {
71 CHECK_EQ(service->registerAsService(), android::NO_ERROR)
72 << "Failed to register wifi HAL";
73 }
74
75 joinRpcThreadpool();
76
77 LOG(INFO) << "Wifi Hal is terminating...";
78 return 0;
79 }
80