blob: 8cf2c7c1311418835f3288737021168d4a339531 [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
Etan Cohen067e1192020-02-15 17:36:36 -080029#include "android/net/wifi/nl80211/IClientInterface.h"
30#include "android/net/wifi/nl80211/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 Wangc2b0dce2016-11-17 17:54:02 -080033#include "wificond/scanning/scanner_impl.h"
Christopher Wileyc139fbf2016-07-27 13:48:22 -070034
35namespace android {
36namespace wificond {
37
38class ClientInterfaceBinder;
Ningyuan Wang042736e2016-10-05 14:25:22 -070039class ClientInterfaceImpl;
Ningyuan Wang14de8b22016-08-18 15:26:15 -070040class ScanUtils;
Christopher Wileyc139fbf2016-07-27 13:48:22 -070041
Ningyuan Wang042736e2016-10-05 14:25:22 -070042class MlmeEventHandlerImpl : public MlmeEventHandler {
43 public:
44 MlmeEventHandlerImpl(ClientInterfaceImpl* client_interface);
45 ~MlmeEventHandlerImpl() override;
46 void OnConnect(std::unique_ptr<MlmeConnectEvent> event) override;
47 void OnRoam(std::unique_ptr<MlmeRoamEvent> event) override;
48 void OnAssociate(std::unique_ptr<MlmeAssociateEvent> event) override;
Ningyuan Wang57118922017-02-27 13:10:32 -080049 void OnDisconnect(std::unique_ptr<MlmeDisconnectEvent> event) override;
50 void OnDisassociate(std::unique_ptr<MlmeDisassociateEvent> event) override;
Abhishek Srivastavab5a9d342018-09-28 11:03:36 +053051 void OnChSwitchNotify() 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.
Etan Cohen067e1192020-02-15 17:36:36 -080076 android::sp<android::net::wifi::nl80211::IClientInterface> GetBinder() const;
Christopher Wileyc139fbf2016-07-27 13:48:22 -070077
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_; };
Ningyuan Wang3c023a02017-06-22 15:21:15 -070083 virtual bool IsAssociated() const;
Ningyuan Wang8ec76962017-04-07 16:03:33 -070084 void Dump(std::stringstream* ss) const;
David Su78be0fc2018-11-14 17:03:40 -080085 void SendMgmtFrame(
86 const std::vector<uint8_t>& frame,
Etan Cohen067e1192020-02-15 17:36:36 -080087 const sp<::android::net::wifi::nl80211::ISendMgmtFrameEvent>& callback,
David Su78be0fc2018-11-14 17:03:40 -080088 int32_t mcs);
Christopher Wiley66527842016-08-10 09:33:45 -070089
Christopher Wileyc139fbf2016-07-27 13:48:22 -070090 private:
Ningyuan Wang042736e2016-10-05 14:25:22 -070091 bool RefreshAssociateFreq();
Purushottam Kushwaha76fc67a2020-05-14 18:34:27 +053092 bool OnChannelSwitchEvent(uint32_t frequency);
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 Wang042736e2016-10-05 14:25:22 -0700101 const std::unique_ptr<MlmeEventHandlerImpl> mlme_event_handler_;
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700102 const android::sp<ClientInterfaceBinder> binder_;
Ningyuan Wang2c74cae2016-11-29 15:50:14 -0800103 android::sp<ScannerImpl> scanner_;
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700104
Ningyuan Wang2c74cae2016-11-29 15:50:14 -0800105 // Cached information for this connection.
Ningyuan Wang57118922017-02-27 13:10:32 -0800106 bool is_associated_;
David Su61ea3072018-10-02 15:14:29 -0700107 std::array<uint8_t, ETH_ALEN> bssid_;
Ningyuan Wang042736e2016-10-05 14:25:22 -0700108 uint32_t associate_freq_;
109
Ningyuan Wang2c74cae2016-11-29 15:50:14 -0800110 // Capability information for this wiphy/interface.
111 BandInfo band_info_;
112 ScanCapabilities scan_capabilities_;
113 WiphyFeatures wiphy_features_;
114
David Su78be0fc2018-11-14 17:03:40 -0800115 // handler for frame tx status messages
116 bool frame_tx_in_progress_;
117 uint64_t frame_tx_status_cookie_;
118 std::function<void(bool was_acked)> on_frame_tx_status_event_handler_;
Srikanth Marepalli406cff32018-11-13 18:16:38 +0530119
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700120 DISALLOW_COPY_AND_ASSIGN(ClientInterfaceImpl);
Ningyuan Wang042736e2016-10-05 14:25:22 -0700121 friend class MlmeEventHandlerImpl;
Christopher Wileyc139fbf2016-07-27 13:48:22 -0700122};
123
124} // namespace wificond
125} // namespace android
126
127#endif // WIFICOND_CLIENT_INTERFACE_IMPL_H_