blob: e07b18bbe574dd183d4b5e11f95f7928c23e051a [file] [log] [blame]
Christopher Wileyc139fbf2016-07-27 13:48:22 -07001/*
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_CLIENT_INTERFACE_IMPL_H_
18#define WIFICOND_CLIENT_INTERFACE_IMPL_H_
19
David Su61ea3072018-10-02 15:14:29 -070020#include <array>
Christopher Wileyc139fbf2016-07-27 13:48:22 -070021#include <string>
22
David Su61ea3072018-10-02 15:14:29 -070023#include <linux/if_ether.h>
24
Christopher Wileyc139fbf2016-07-27 13:48:22 -070025#include <android-base/macros.h>
26#include <utils/StrongPointer.h>
Christopher Wiley4fc37922016-09-22 08:57:40 -070027#include <wifi_system/interface_tool.h>
Christopher Wileyc139fbf2016-07-27 13:48:22 -070028
29#include "android/net/wifi/IClientInterface.h"
David Su78be0fc2018-11-14 17:03:40 -080030#include "android/net/wifi/ISendMgmtFrameEvent.h"
Ningyuan Wang042736e2016-10-05 14:25:22 -070031#include "wificond/net/mlme_event_handler.h"
Ningyuan Wang2c74cae2016-11-29 15:50:14 -080032#include "wificond/net/netlink_utils.h"
Ningyuan Wang7a3d8dd2017-07-11 10:33:01 -070033#include "wificond/scanning/offload/offload_service_utils.h"
Ningyuan Wangc2b0dce2016-11-17 17:54:02 -080034#include "wificond/scanning/scanner_impl.h"
Christopher Wileyc139fbf2016-07-27 13:48:22 -070035
36namespace android {
37namespace wificond {
38
39class ClientInterfaceBinder;
Ningyuan Wang042736e2016-10-05 14:25:22 -070040class ClientInterfaceImpl;
Ningyuan Wang14de8b22016-08-18 15:26:15 -070041class ScanUtils;
Christopher Wileyc139fbf2016-07-27 13:48:22 -070042
Ningyuan Wang042736e2016-10-05 14:25:22 -070043class MlmeEventHandlerImpl : public MlmeEventHandler {
44 public:
45 MlmeEventHandlerImpl(ClientInterfaceImpl* client_interface);
46 ~MlmeEventHandlerImpl() override;
47 void OnConnect(std::unique_ptr<MlmeConnectEvent> event) override;
48 void OnRoam(std::unique_ptr<MlmeRoamEvent> event) override;
49 void OnAssociate(std::unique_ptr<MlmeAssociateEvent> event) override;
Ningyuan Wang57118922017-02-27 13:10:32 -080050 void OnDisconnect(std::unique_ptr<MlmeDisconnectEvent> event) override;
51 void OnDisassociate(std::unique_ptr<MlmeDisassociateEvent> event) override;
Ningyuan Wang042736e2016-10-05 14:25:22 -070052
53 private:
54 ClientInterfaceImpl* client_interface_;
55};
56
Christopher Wileyc139fbf2016-07-27 13:48:22 -070057// Holds the guts of how we control network interfaces capable of connecting to
58// access points via wpa_supplicant.
59//
60// Because remote processes may hold on to the corresponding
61// binder object past the lifetime of the local object, we are forced to
62// keep this object separate from the binder representation of itself.
63class ClientInterfaceImpl {
64 public:
Christopher Wiley537c1ba2016-08-23 10:56:06 -070065 ClientInterfaceImpl(
Ningyuan Wang2c74cae2016-11-29 15:50:14 -080066 uint32_t wiphy_index,
Christopher Wiley537c1ba2016-08-23 10:56:06 -070067 const std::string& interface_name,
68 uint32_t interface_index,
David Su61ea3072018-10-02 15:14:29 -070069 const std::array<uint8_t, ETH_ALEN>& interface_mac_addr,
Christopher Wiley4fc37922016-09-22 08:57:40 -070070 android::wifi_system::InterfaceTool* if_tool,
Ningyuan Wanga12253e2016-09-15 10:53:07 -070071 NetlinkUtils* netlink_utils,
Christopher Wiley537c1ba2016-08-23 10:56:06 -070072 ScanUtils* scan_utils);
Ningyuan Wang3c023a02017-06-22 15:21:15 -070073 virtual ~ClientInterfaceImpl();
Christopher Wileyc139fbf2016-07-27 13:48:22 -070074
75 // Get a pointer to the binder representing this ClientInterfaceImpl.
76 android::sp<android::net::wifi::IClientInterface> GetBinder() const;
77
Ningyuan Wanga12253e2016-09-15 10:53:07 -070078 bool GetPacketCounters(std::vector<int32_t>* out_packet_counters);
Ningyuan Wangb52f6352016-09-16 15:39:41 -070079 bool SignalPoll(std::vector<int32_t>* out_signal_poll_results);
David Su61ea3072018-10-02 15:14:29 -070080 const std::array<uint8_t, ETH_ALEN>& GetMacAddress();
Ningyuan Wange5d0d672016-09-29 11:13:45 -070081 const std::string& GetInterfaceName() const { return interface_name_; }
Ningyuan Wangc2b0dce2016-11-17 17:54:02 -080082 const android::sp<ScannerImpl> GetScanner() { return scanner_; };
David Su61ea3072018-10-02 15:14:29 -070083 bool SetMacAddress(const std::array<uint8_t, ETH_ALEN>& mac);
Ningyuan Wang3c023a02017-06-22 15:21:15 -070084 virtual bool IsAssociated() const;
Ningyuan Wang8ec76962017-04-07 16:03:33 -070085 void Dump(std::stringstream* ss) const;
David Su78be0fc2018-11-14 17:03:40 -080086 void SendMgmtFrame(
87 const std::vector<uint8_t>& frame,
88 const sp<::android::net::wifi::ISendMgmtFrameEvent>& callback,
89 int32_t mcs);
Christopher Wiley66527842016-08-10 09:33:45 -070090
Christopher Wileyc139fbf2016-07-27 13:48:22 -070091 private:
Ningyuan Wang042736e2016-10-05 14:25:22 -070092 bool RefreshAssociateFreq();
Ningyuan Wang14de8b22016-08-18 15:26:15 -070093
Ningyuan Wang2c74cae2016-11-29 15:50:14 -080094 const uint32_t wiphy_index_;
Christopher Wileyc139fbf2016-07-27 13:48:22 -070095 const std::string interface_name_;
Ningyuan Wang9bc59a02016-08-11 09:59:22 -070096 const uint32_t interface_index_;
David Su61ea3072018-10-02 15:14:29 -070097 const std::array<uint8_t, ETH_ALEN> interface_mac_addr_;
Christopher Wiley4fc37922016-09-22 08:57:40 -070098 android::wifi_system::InterfaceTool* const if_tool_;
Ningyuan Wanga12253e2016-09-15 10:53:07 -070099 NetlinkUtils* const netlink_utils_;
Ningyuan Wang14de8b22016-08-18 15:26:15 -0700100 ScanUtils* const scan_utils_;
Ningyuan Wang7a3d8dd2017-07-11 10:33:01 -0700101 const std::shared_ptr<OffloadServiceUtils> offload_service_utils_;
Ningyuan Wang042736e2016-10-05 14:25:22 -0700102 const std::unique_ptr<MlmeEventHandlerImpl> mlme_event_handler_;
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700103 const android::sp<ClientInterfaceBinder> binder_;
Ningyuan Wang2c74cae2016-11-29 15:50:14 -0800104 android::sp<ScannerImpl> scanner_;
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700105
Ningyuan Wang2c74cae2016-11-29 15:50:14 -0800106 // Cached information for this connection.
Ningyuan Wang57118922017-02-27 13:10:32 -0800107 bool is_associated_;
David Su61ea3072018-10-02 15:14:29 -0700108 std::array<uint8_t, ETH_ALEN> bssid_;
Ningyuan Wang042736e2016-10-05 14:25:22 -0700109 uint32_t associate_freq_;
110
Ningyuan Wang2c74cae2016-11-29 15:50:14 -0800111 // Capability information for this wiphy/interface.
112 BandInfo band_info_;
113 ScanCapabilities scan_capabilities_;
114 WiphyFeatures wiphy_features_;
115
David Su78be0fc2018-11-14 17:03:40 -0800116 // handler for frame tx status messages
117 bool frame_tx_in_progress_;
118 uint64_t frame_tx_status_cookie_;
119 std::function<void(bool was_acked)> on_frame_tx_status_event_handler_;
120
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700121 DISALLOW_COPY_AND_ASSIGN(ClientInterfaceImpl);
Ningyuan Wang042736e2016-10-05 14:25:22 -0700122 friend class MlmeEventHandlerImpl;
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700123};
124
125} // namespace wificond
126} // namespace android
127
128#endif // WIFICOND_CLIENT_INTERFACE_IMPL_H_