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/nl80211/IApInterface.h"
32 
33 using android::net::wifi::nl80211::IApInterface;
34 using android::net::wifi::nl80211::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   void Dump(std::stringstream* ss) const;
59 
60  private:
61   const std::string interface_name_;
62   const uint32_t interface_index_;
63   NetlinkUtils* const netlink_utils_;
64   wifi_system::InterfaceTool* const if_tool_;
65   const android::sp<ApInterfaceBinder> binder_;
66 
67   void OnStationEvent(StationEvent event,
68                       const std::array<uint8_t, ETH_ALEN>& mac_address);
69 
70   void OnChannelSwitchEvent(uint32_t frequency, ChannelBandwidth bandwidth);
71 
72   DISALLOW_COPY_AND_ASSIGN(ApInterfaceImpl);
73 };
74 
75 }  // namespace wificond
76 }  // namespace android
77 
78 #endif  // WIFICOND_AP_INTERFACE_IMPL_H_
79