OSDN Git Service

Add RTTController and corresponding aidl interface to wificond am: eb59d4dd54
[android-x86/system-connectivity-wificond.git] / server.h
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_hal/driver_tool.h>
26 #include <wifi_system/hal_tool.h>
27 #include <wifi_system/interface_tool.h>
28
29 #include "android/net/wifi/BnWificond.h"
30 #include "android/net/wifi/IApInterface.h"
31 #include "android/net/wifi/IClientInterface.h"
32 #include "android/net/wifi/IInterfaceEventCallback.h"
33
34 #include "wificond/ap_interface_impl.h"
35 #include "wificond/client_interface_impl.h"
36 #include "wificond/rtt/rtt_controller_impl.h"
37
38 namespace android {
39 namespace wificond {
40
41 class NL80211Packet;
42 class NetlinkUtils;
43 class ScanUtils;
44
45 class Server : public android::net::wifi::BnWificond {
46  public:
47   Server(std::unique_ptr<wifi_system::HalTool> hal_tool,
48          std::unique_ptr<wifi_system::InterfaceTool> if_tool,
49          std::unique_ptr<wifi_hal::DriverTool> driver_tool,
50          std::unique_ptr<wifi_system::SupplicantManager> supplicant_man,
51          std::unique_ptr<wifi_system::HostapdManager> hostapd_man,
52          NetlinkUtils* netlink_utils,
53          ScanUtils* scan_utils);
54   ~Server() override = default;
55
56   android::binder::Status RegisterCallback(
57       const android::sp<android::net::wifi::IInterfaceEventCallback>&
58           callback) override;
59   android::binder::Status UnregisterCallback(
60       const android::sp<android::net::wifi::IInterfaceEventCallback>&
61           callback) override;
62
63   android::binder::Status registerRttClient(
64       const ::android::sp<::android::net::wifi::IRttClient>& rtt_client,
65       ::android::sp<::android::net::wifi::IRttController>*
66           out_rtt_controller) override;
67
68   android::binder::Status unregisterRttClient(
69       const ::android::sp<::android::net::wifi::IRttClient>&
70           rttClient) override;
71
72   android::binder::Status createApInterface(
73       android::sp<android::net::wifi::IApInterface>*
74           created_interface) override;
75
76   android::binder::Status createClientInterface(
77       android::sp<android::net::wifi::IClientInterface>*
78           created_interface) override;
79
80   android::binder::Status tearDownInterfaces() override;
81
82   android::binder::Status GetClientInterfaces(
83       std::vector<android::sp<android::IBinder>>* out_client_ifs) override;
84   android::binder::Status GetApInterfaces(
85       std::vector<android::sp<android::IBinder>>* out_ap_ifs) override;
86
87   // Call this once on startup.  It ignores all the invariants held
88   // in wificond and tries to restore ourselves to a blank state by
89   // killing userspace daemons and cleaning up the interface state.
90   void CleanUpSystemState();
91
92  private:
93   // Does the actual work of setting up an interface for a particular mode.
94   //
95   // |mode| is one of WIFI_GET_FW_PATH_* defined in hardware_legacy/wifi.h.
96   // |interface_name| is a pointer to a string to store the name of Linux
97   //     network interface that has been setup.
98   //
99   // Returns true on success, false otherwise.
100   bool SetupInterfaceForMode(int mode,
101                              std::string* interface_name,
102                              uint32_t* interface_index,
103                              std::vector<uint8_t>* interface_mac_addr);
104   bool RefreshWiphyIndex();
105   void BroadcastClientInterfaceReady(
106       android::sp<android::net::wifi::IClientInterface> network_interface);
107   void BroadcastApInterfaceReady(
108       android::sp<android::net::wifi::IApInterface> network_interface);
109   void BroadcastClientInterfaceTornDown(
110       android::sp<android::net::wifi::IClientInterface> network_interface);
111   void BroadcastApInterfaceTornDown(
112       android::sp<android::net::wifi::IApInterface> network_interface);
113
114   const std::unique_ptr<wifi_system::HalTool> hal_tool_;
115   const std::unique_ptr<wifi_system::InterfaceTool> if_tool_;
116   const std::unique_ptr<wifi_hal::DriverTool> driver_tool_;
117   const std::unique_ptr<wifi_system::SupplicantManager> supplicant_manager_;
118   const std::unique_ptr<wifi_system::HostapdManager> hostapd_manager_;
119   NetlinkUtils* const netlink_utils_;
120   ScanUtils* const scan_utils_;
121
122   uint32_t wiphy_index_;
123   std::vector<std::unique_ptr<ApInterfaceImpl>> ap_interfaces_;
124   std::vector<std::unique_ptr<ClientInterfaceImpl>> client_interfaces_;
125   std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>>
126       interface_event_callbacks_;
127
128   std::unique_ptr<RttControllerImpl> rtt_controller_;
129
130   DISALLOW_COPY_AND_ASSIGN(Server);
131 };
132
133 }  // namespace wificond
134 }  // namespace android
135
136 #endif  // WIFICOND_SERVER_H_