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"
44 class Server : public android::net::wifi::BnWificond {
46 Server(std::unique_ptr<wifi_system::InterfaceTool> if_tool,
47 std::unique_ptr<wifi_system::SupplicantManager> supplicant_man,
48 std::unique_ptr<wifi_system::HostapdManager> hostapd_man,
49 NetlinkUtils* netlink_utils,
50 ScanUtils* scan_utils);
51 ~Server() override = default;
53 android::binder::Status RegisterCallback(
54 const android::sp<android::net::wifi::IInterfaceEventCallback>&
56 android::binder::Status UnregisterCallback(
57 const android::sp<android::net::wifi::IInterfaceEventCallback>&
60 android::binder::Status createApInterface(
61 android::sp<android::net::wifi::IApInterface>*
62 created_interface) override;
64 android::binder::Status createClientInterface(
65 android::sp<android::net::wifi::IClientInterface>*
66 created_interface) override;
68 android::binder::Status tearDownInterfaces() override;
70 android::binder::Status GetClientInterfaces(
71 std::vector<android::sp<android::IBinder>>* out_client_ifs) override;
72 android::binder::Status GetApInterfaces(
73 std::vector<android::sp<android::IBinder>>* out_ap_ifs) override;
74 status_t dump(int fd, const Vector<String16>& args) override;
76 // Call this once on startup. It ignores all the invariants held
77 // in wificond and tries to restore ourselves to a blank state by
78 // killing userspace daemons and cleaning up the interface state.
79 void CleanUpSystemState();
82 // Request interface information from kernel and setup local interface object.
83 // This assumes that interface should be in STATION mode. Even if we setup
84 // interface on behalf of createApInterace(), it is Hostapd that configure
85 // the interface to Ap mode later.
86 // Returns true on success, false otherwise.
87 bool SetupInterface(InterfaceInfo* interface);
88 bool RefreshWiphyIndex();
89 void LogSupportedBands();
90 void OnRegDomainChanged(std::string& country_code);
91 void BroadcastClientInterfaceReady(
92 android::sp<android::net::wifi::IClientInterface> network_interface);
93 void BroadcastApInterfaceReady(
94 android::sp<android::net::wifi::IApInterface> network_interface);
95 void BroadcastClientInterfaceTornDown(
96 android::sp<android::net::wifi::IClientInterface> network_interface);
97 void BroadcastApInterfaceTornDown(
98 android::sp<android::net::wifi::IApInterface> network_interface);
99 void MarkDownAllInterfaces();
101 const std::unique_ptr<wifi_system::InterfaceTool> if_tool_;
102 const std::unique_ptr<wifi_system::SupplicantManager> supplicant_manager_;
103 const std::unique_ptr<wifi_system::HostapdManager> hostapd_manager_;
104 NetlinkUtils* const netlink_utils_;
105 ScanUtils* const scan_utils_;
107 uint32_t wiphy_index_;
108 std::vector<std::unique_ptr<ApInterfaceImpl>> ap_interfaces_;
109 std::vector<std::unique_ptr<ClientInterfaceImpl>> client_interfaces_;
110 std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>>
111 interface_event_callbacks_;
113 // Cached interface list from kernel.
114 std::vector<InterfaceInfo> interfaces_;
116 DISALLOW_COPY_AND_ASSIGN(Server);
119 } // namespace wificond
120 } // namespace android
122 #endif // WIFICOND_SERVER_H_