1 /*
2 * Copyright (C) 2022 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 <android/binder_manager.h>
19 #include <android/binder_process.h>
20 #include <signal.h>
21
22 #include "wifi.h"
23 #include "wifi_feature_flags.h"
24 #include "wifi_legacy_hal.h"
25 #include "wifi_legacy_hal_factory.h"
26 #include "wifi_mode_controller.h"
27
28 using aidl::android::hardware::wifi::feature_flags::WifiFeatureFlags;
29 using aidl::android::hardware::wifi::legacy_hal::WifiLegacyHal;
30 using aidl::android::hardware::wifi::legacy_hal::WifiLegacyHalFactory;
31 using aidl::android::hardware::wifi::mode_controller::WifiModeController;
32
33 #ifdef LAZY_SERVICE
34 const bool kLazyService = true;
35 #else
36 const bool kLazyService = false;
37 #endif
38
main(int,char ** argv)39 int main(int /*argc*/, char** argv) {
40 signal(SIGPIPE, SIG_IGN);
41 android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
42 LOG(INFO) << "Wifi Hal is booting up...";
43
44 // Prepare the RPC-serving thread pool. Allocate 1 thread in the pool,
45 // which our main thread will join below.
46 ABinderProcess_setThreadPoolMaxThreadCount(1);
47
48 const auto iface_tool = std::make_shared<::android::wifi_system::InterfaceTool>();
49 const auto legacy_hal_factory = std::make_shared<WifiLegacyHalFactory>(iface_tool);
50
51 // Setup binder service
52 std::shared_ptr<aidl::android::hardware::wifi::Wifi> service =
53 ndk::SharedRefBase::make<aidl::android::hardware::wifi::Wifi>(
54 iface_tool, legacy_hal_factory, std::make_shared<WifiModeController>(),
55 std::make_shared<WifiFeatureFlags>());
56 std::string instance =
57 std::string() + aidl::android::hardware::wifi::Wifi::descriptor + "/default";
58 if (kLazyService) {
59 auto result =
60 AServiceManager_registerLazyService(service->asBinder().get(), instance.c_str());
61 CHECK_EQ(result, STATUS_OK) << "Failed to register lazy wifi HAL";
62 } else {
63 auto result = AServiceManager_addService(service->asBinder().get(), instance.c_str());
64 CHECK_EQ(result, STATUS_OK) << "Failed to register wifi HAL";
65 }
66
67 ABinderProcess_startThreadPool();
68 LOG(INFO) << "Joining RPC thread pool";
69 ABinderProcess_joinThreadPool();
70
71 LOG(INFO) << "Wifi Hal is terminating...";
72 return 0;
73 }
74