OSDN Git Service

wificond: Use Vendor HAL for mode change
[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_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 class Server : public android::net::wifi::BnWificond {
44  public:
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;
51
52   android::binder::Status RegisterCallback(
53       const android::sp<android::net::wifi::IInterfaceEventCallback>&
54           callback) override;
55   android::binder::Status UnregisterCallback(
56       const android::sp<android::net::wifi::IInterfaceEventCallback>&
57           callback) override;
58
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;
63
64   android::binder::Status unregisterRttClient(
65       const ::android::sp<::android::net::wifi::IRttClient>&
66           rttClient) override;
67
68   android::binder::Status createApInterface(
69       android::sp<android::net::wifi::IApInterface>*
70           created_interface) override;
71
72   android::binder::Status createClientInterface(
73       android::sp<android::net::wifi::IClientInterface>*
74           created_interface) override;
75
76   android::binder::Status tearDownInterfaces() override;
77
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;
82
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();
87
88  private:
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);
108
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_;
114
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_;
120
121   std::unique_ptr<RttControllerImpl> rtt_controller_;
122
123   DISALLOW_COPY_AND_ASSIGN(Server);
124 };
125
126 }  // namespace wificond
127 }  // namespace android
128
129 #endif  // WIFICOND_SERVER_H_