OSDN Git Service

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