2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef WIFICOND_SERVER_H_
18 #define WIFICOND_SERVER_H_
24 #include <android-base/macros.h>
25 #include <wifi_system/interface_tool.h>
27 #include "android/net/wifi/BnWificond.h"
28 #include "android/net/wifi/IApInterface.h"
29 #include "android/net/wifi/IClientInterface.h"
30 #include "android/net/wifi/IInterfaceEventCallback.h"
32 #include "wificond/ap_interface_impl.h"
33 #include "wificond/client_interface_impl.h"
34 #include "wificond/rtt/rtt_controller_impl.h"
43 class Server : public android::net::wifi::BnWificond {
45 Server(std::unique_ptr<wifi_system::InterfaceTool> if_tool,
46 std::unique_ptr<wifi_system::SupplicantManager> supplicant_man,
47 std::unique_ptr<wifi_system::HostapdManager> hostapd_man,
48 NetlinkUtils* netlink_utils,
49 ScanUtils* scan_utils);
50 ~Server() override = default;
52 android::binder::Status RegisterCallback(
53 const android::sp<android::net::wifi::IInterfaceEventCallback>&
55 android::binder::Status UnregisterCallback(
56 const android::sp<android::net::wifi::IInterfaceEventCallback>&
59 android::binder::Status registerRttClient(
60 const ::android::sp<::android::net::wifi::IRttClient>& rtt_client,
61 ::android::sp<::android::net::wifi::IRttController>*
62 out_rtt_controller) override;
64 android::binder::Status unregisterRttClient(
65 const ::android::sp<::android::net::wifi::IRttClient>&
68 android::binder::Status createApInterface(
69 android::sp<android::net::wifi::IApInterface>*
70 created_interface) override;
72 android::binder::Status createClientInterface(
73 android::sp<android::net::wifi::IClientInterface>*
74 created_interface) override;
76 android::binder::Status tearDownInterfaces() override;
78 android::binder::Status GetClientInterfaces(
79 std::vector<android::sp<android::IBinder>>* out_client_ifs) override;
80 android::binder::Status GetApInterfaces(
81 std::vector<android::sp<android::IBinder>>* out_ap_ifs) override;
83 // Call this once on startup. It ignores all the invariants held
84 // in wificond and tries to restore ourselves to a blank state by
85 // killing userspace daemons and cleaning up the interface state.
86 void CleanUpSystemState();
89 // Request interface information from kernel and setup local interface object.
90 // This assumes that interface should be in STATION mode. Even if we setup
91 // interface on behalf of createApInterace(), it is Hostapd that configure
92 // the interface to Ap mode later.
93 // Returns true on success, false otherwise.
94 bool SetupInterface(std::string* interface_name,
95 uint32_t* interface_index,
96 std::vector<uint8_t>* interface_mac_addr);
97 bool RefreshWiphyIndex();
98 void LogSupportedBands();
99 void OnRegDomainChanged(std::string& country_code);
100 void BroadcastClientInterfaceReady(
101 android::sp<android::net::wifi::IClientInterface> network_interface);
102 void BroadcastApInterfaceReady(
103 android::sp<android::net::wifi::IApInterface> network_interface);
104 void BroadcastClientInterfaceTornDown(
105 android::sp<android::net::wifi::IClientInterface> network_interface);
106 void BroadcastApInterfaceTornDown(
107 android::sp<android::net::wifi::IApInterface> network_interface);
109 const std::unique_ptr<wifi_system::InterfaceTool> if_tool_;
110 const std::unique_ptr<wifi_system::SupplicantManager> supplicant_manager_;
111 const std::unique_ptr<wifi_system::HostapdManager> hostapd_manager_;
112 NetlinkUtils* const netlink_utils_;
113 ScanUtils* const scan_utils_;
115 uint32_t wiphy_index_;
116 std::vector<std::unique_ptr<ApInterfaceImpl>> ap_interfaces_;
117 std::vector<std::unique_ptr<ClientInterfaceImpl>> client_interfaces_;
118 std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>>
119 interface_event_callbacks_;
121 std::unique_ptr<RttControllerImpl> rtt_controller_;
123 DISALLOW_COPY_AND_ASSIGN(Server);
126 } // namespace wificond
127 } // namespace android
129 #endif // WIFICOND_SERVER_H_