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_AP_INTERFACE_IMPL_H_
18 #define WIFICOND_AP_INTERFACE_IMPL_H_
19 
20 #include <array>
21 #include <string>
22 #include <vector>
23 
24 #include <linux/if_ether.h>
25 
26 #include <android-base/macros.h>
27 #include <wifi_system/interface_tool.h>
28 
29 #include "wificond/net/netlink_manager.h"
30 
31 #include "android/net/wifi/IApInterface.h"
32 
33 using android::net::wifi::IApInterface;
34 using com::android::server::wifi::wificond::NativeWifiClient;
35 
36 namespace android {
37 namespace wificond {
38 
39 class ApInterfaceBinder;
40 class NetlinkUtils;
41 
42 // Holds the guts of how we control network interfaces capable of exposing an AP
43 // via hostapd.  Because remote processes may hold on to the corresponding
44 // binder object past the lifetime of the local object, we are forced to
45 // keep this object separate from the binder representation of itself.
46 class ApInterfaceImpl {
47  public:
48   ApInterfaceImpl(const std::string& interface_name,
49                   uint32_t interface_index,
50                   NetlinkUtils* netlink_utils,
51                   wifi_system::InterfaceTool* if_tool);
52   ~ApInterfaceImpl();
53 
54   // Get a pointer to the binder representing this ApInterfaceImpl.
55   android::sp<IApInterface> GetBinder() const;
56 
GetInterfaceName()57   std::string GetInterfaceName() { return interface_name_; }
58   std::vector<NativeWifiClient> GetConnectedClients() const;
59   void Dump(std::stringstream* ss) const;
60 
61  private:
62   const std::string interface_name_;
63   const uint32_t interface_index_;
64   NetlinkUtils* const netlink_utils_;
65   wifi_system::InterfaceTool* const if_tool_;
66   const android::sp<ApInterfaceBinder> binder_;
67 
68   // Currently connected access point clients
69   std::vector<NativeWifiClient> connected_clients_;
70 
71   void OnStationEvent(StationEvent event,
72                       const std::array<uint8_t, ETH_ALEN>& mac_address);
73 
74   void OnChannelSwitchEvent(uint32_t frequency, ChannelBandwidth bandwidth);
75 
76   DISALLOW_COPY_AND_ASSIGN(ApInterfaceImpl);
77 };
78 
79 }  // namespace wificond
80 }  // namespace android
81 
82 #endif  // WIFICOND_AP_INTERFACE_IMPL_H_
83