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 #ifndef WIFICOND_SERVER_H_ 18 #define WIFICOND_SERVER_H_ 19 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include <android-base/macros.h> 25 #include <wifi_system/interface_tool.h> 26 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" 31 32 #include "wificond/ap_interface_impl.h" 33 #include "wificond/client_interface_impl.h" 34 #include "wificond/rtt/rtt_controller_impl.h" 35 36 namespace android { 37 namespace wificond { 38 39 class NL80211Packet; 40 class NetlinkUtils; 41 class ScanUtils; 42 43 struct InterfaceInfo; 44 45 class Server : public android::net::wifi::BnWificond { 46 public: 47 Server(std::unique_ptr<wifi_system::InterfaceTool> if_tool, 48 std::unique_ptr<wifi_system::SupplicantManager> supplicant_man, 49 std::unique_ptr<wifi_system::HostapdManager> hostapd_man, 50 NetlinkUtils* netlink_utils, 51 ScanUtils* scan_utils); 52 ~Server() override = default; 53 54 android::binder::Status RegisterCallback( 55 const android::sp<android::net::wifi::IInterfaceEventCallback>& 56 callback) override; 57 android::binder::Status UnregisterCallback( 58 const android::sp<android::net::wifi::IInterfaceEventCallback>& 59 callback) override; 60 61 android::binder::Status registerRttClient( 62 const ::android::sp<::android::net::wifi::IRttClient>& rtt_client, 63 ::android::sp<::android::net::wifi::IRttController>* 64 out_rtt_controller) override; 65 66 android::binder::Status unregisterRttClient( 67 const ::android::sp<::android::net::wifi::IRttClient>& 68 rttClient) override; 69 70 android::binder::Status createApInterface( 71 android::sp<android::net::wifi::IApInterface>* 72 created_interface) override; 73 74 android::binder::Status createClientInterface( 75 android::sp<android::net::wifi::IClientInterface>* 76 created_interface) override; 77 78 android::binder::Status tearDownInterfaces() override; 79 80 android::binder::Status GetClientInterfaces( 81 std::vector<android::sp<android::IBinder>>* out_client_ifs) override; 82 android::binder::Status GetApInterfaces( 83 std::vector<android::sp<android::IBinder>>* out_ap_ifs) override; 84 status_t dump(int fd, const Vector<String16>& args) override; 85 86 // Call this once on startup. It ignores all the invariants held 87 // in wificond and tries to restore ourselves to a blank state by 88 // killing userspace daemons and cleaning up the interface state. 89 void CleanUpSystemState(); 90 91 private: 92 // Request interface information from kernel and setup local interface object. 93 // This assumes that interface should be in STATION mode. Even if we setup 94 // interface on behalf of createApInterace(), it is Hostapd that configure 95 // the interface to Ap mode later. 96 // Returns true on success, false otherwise. 97 bool SetupInterface(InterfaceInfo* interface); 98 bool RefreshWiphyIndex(); 99 void LogSupportedBands(); 100 void OnRegDomainChanged(std::string& country_code); 101 void BroadcastClientInterfaceReady( 102 android::sp<android::net::wifi::IClientInterface> network_interface); 103 void BroadcastApInterfaceReady( 104 android::sp<android::net::wifi::IApInterface> network_interface); 105 void BroadcastClientInterfaceTornDown( 106 android::sp<android::net::wifi::IClientInterface> network_interface); 107 void BroadcastApInterfaceTornDown( 108 android::sp<android::net::wifi::IApInterface> network_interface); 109 void MarkDownAllInterfaces(); 110 111 const std::unique_ptr<wifi_system::InterfaceTool> if_tool_; 112 const std::unique_ptr<wifi_system::SupplicantManager> supplicant_manager_; 113 const std::unique_ptr<wifi_system::HostapdManager> hostapd_manager_; 114 NetlinkUtils* const netlink_utils_; 115 ScanUtils* const scan_utils_; 116 117 uint32_t wiphy_index_; 118 std::vector<std::unique_ptr<ApInterfaceImpl>> ap_interfaces_; 119 std::vector<std::unique_ptr<ClientInterfaceImpl>> client_interfaces_; 120 std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>> 121 interface_event_callbacks_; 122 123 std::unique_ptr<RttControllerImpl> rtt_controller_; 124 125 // Cached interface list from kernel. 126 std::vector<InterfaceInfo> interfaces_; 127 128 DISALLOW_COPY_AND_ASSIGN(Server); 129 }; 130 131 } // namespace wificond 132 } // namespace android 133 134 #endif // WIFICOND_SERVER_H_ 135