1c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley/* 2c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * Copyright (C) 2016 The Android Open Source Project 3c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * 4c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * Licensed under the Apache License, Version 2.0 (the "License"); 5c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * you may not use this file except in compliance with the License. 6c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * You may obtain a copy of the License at 7c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * 8c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * http://www.apache.org/licenses/LICENSE-2.0 9c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * 10c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * Unless required by applicable law or agreed to in writing, software 11c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * distributed under the License is distributed on an "AS IS" BASIS, 12c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * See the License for the specific language governing permissions and 14c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley * limitations under the License. 15c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley */ 16c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 17c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley#ifndef WIFICOND_CLIENT_INTERFACE_IMPL_H_ 18c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley#define WIFICOND_CLIENT_INTERFACE_IMPL_H_ 19c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 20c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley#include <string> 21c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 22c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley#include <android-base/macros.h> 23c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley#include <utils/StrongPointer.h> 244fc3792b547087f9fd425393cd3159d2f74fa831Christopher Wiley#include <wifi_system/interface_tool.h> 25537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley#include <wifi_system/supplicant_manager.h> 26c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 27c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley#include "android/net/wifi/IClientInterface.h" 28042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang#include "wificond/net/mlme_event_handler.h" 292c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang#include "wificond/net/netlink_utils.h" 30c2b0dce5c32b4e6baf5d923b604529ea0ed97c5fNingyuan Wang#include "wificond/scanning/scanner_impl.h" 31c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 32c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wileynamespace android { 33c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wileynamespace wificond { 34c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 35c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wileyclass ClientInterfaceBinder; 36042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wangclass ClientInterfaceImpl; 3714de8b2ce5ef49218e48002a3ac0728847e90372Ningyuan Wangclass ScanUtils; 38c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 39042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wangclass MlmeEventHandlerImpl : public MlmeEventHandler { 40042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang public: 41042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang MlmeEventHandlerImpl(ClientInterfaceImpl* client_interface); 42042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang ~MlmeEventHandlerImpl() override; 43042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang void OnConnect(std::unique_ptr<MlmeConnectEvent> event) override; 44042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang void OnRoam(std::unique_ptr<MlmeRoamEvent> event) override; 45042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang void OnAssociate(std::unique_ptr<MlmeAssociateEvent> event) override; 465711892b76b3ba2dea53aec0769ca36cb04b3cecNingyuan Wang void OnDisconnect(std::unique_ptr<MlmeDisconnectEvent> event) override; 475711892b76b3ba2dea53aec0769ca36cb04b3cecNingyuan Wang void OnDisassociate(std::unique_ptr<MlmeDisassociateEvent> event) override; 48042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang 49042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang private: 50042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang ClientInterfaceImpl* client_interface_; 51042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang}; 52042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang 53c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley// Holds the guts of how we control network interfaces capable of connecting to 54c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley// access points via wpa_supplicant. 55c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley// 56c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley// Because remote processes may hold on to the corresponding 57c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley// binder object past the lifetime of the local object, we are forced to 58c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley// keep this object separate from the binder representation of itself. 59c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wileyclass ClientInterfaceImpl { 60c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley public: 61537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley ClientInterfaceImpl( 622c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang uint32_t wiphy_index, 63537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley const std::string& interface_name, 64537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley uint32_t interface_index, 65537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley const std::vector<uint8_t>& interface_mac_addr, 664fc3792b547087f9fd425393cd3159d2f74fa831Christopher Wiley android::wifi_system::InterfaceTool* if_tool, 67537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley android::wifi_system::SupplicantManager* supplicant_manager, 68a12253e46c1328548c4b37d7f365b4009a6e5776Ningyuan Wang NetlinkUtils* netlink_utils, 69537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley ScanUtils* scan_utils); 70c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley ~ClientInterfaceImpl(); 71c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 72c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley // Get a pointer to the binder representing this ClientInterfaceImpl. 73c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley android::sp<android::net::wifi::IClientInterface> GetBinder() const; 74c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 7566527843f7df41d152e09b21dec2f0d931db08dbChristopher Wiley bool EnableSupplicant(); 7666527843f7df41d152e09b21dec2f0d931db08dbChristopher Wiley bool DisableSupplicant(); 77a12253e46c1328548c4b37d7f365b4009a6e5776Ningyuan Wang bool GetPacketCounters(std::vector<int32_t>* out_packet_counters); 78b52f635f890b0370349014890fcb6bc49ebabd66Ningyuan Wang bool SignalPoll(std::vector<int32_t>* out_signal_poll_results); 79cc77f636f4c790dd8a7ecefc3bbe8568fc8b040bNingyuan Wang const std::vector<uint8_t>& GetMacAddress(); 80e5d0d670dc5a22816a2ec944e2384fd42634aa06Ningyuan Wang const std::string& GetInterfaceName() const { return interface_name_; } 81c2b0dce5c32b4e6baf5d923b604529ea0ed97c5fNingyuan Wang const android::sp<ScannerImpl> GetScanner() { return scanner_; }; 82e5d0d670dc5a22816a2ec944e2384fd42634aa06Ningyuan Wang bool requestANQP( 83e5d0d670dc5a22816a2ec944e2384fd42634aa06Ningyuan Wang const ::std::vector<uint8_t>& bssid, 84e5d0d670dc5a22816a2ec944e2384fd42634aa06Ningyuan Wang const ::android::sp<::android::net::wifi::IANQPDoneCallback>& callback); 858ec7696f5111abb46d12a6bd1f2e27d8b8291b34Ningyuan Wang bool IsAssociated() const; 868ec7696f5111abb46d12a6bd1f2e27d8b8291b34Ningyuan Wang void Dump(std::stringstream* ss) const; 8766527843f7df41d152e09b21dec2f0d931db08dbChristopher Wiley 88c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley private: 89042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang bool RefreshAssociateFreq(); 9014de8b2ce5ef49218e48002a3ac0728847e90372Ningyuan Wang 912c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang const uint32_t wiphy_index_; 92c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley const std::string interface_name_; 939bc59a058868140e33bc7c46c9232c8d9b9148caNingyuan Wang const uint32_t interface_index_; 94c62360e419c9d6aac905f8c2bcdf9107eb137e66Roshan Pius const std::vector<uint8_t> interface_mac_addr_; 954fc3792b547087f9fd425393cd3159d2f74fa831Christopher Wiley android::wifi_system::InterfaceTool* const if_tool_; 96537c1ba391765b3aa7750450c208c650a02c04f0Christopher Wiley android::wifi_system::SupplicantManager* const supplicant_manager_; 97a12253e46c1328548c4b37d7f365b4009a6e5776Ningyuan Wang NetlinkUtils* const netlink_utils_; 9814de8b2ce5ef49218e48002a3ac0728847e90372Ningyuan Wang ScanUtils* const scan_utils_; 99042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang const std::unique_ptr<MlmeEventHandlerImpl> mlme_event_handler_; 100c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley const android::sp<ClientInterfaceBinder> binder_; 1012c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang android::sp<ScannerImpl> scanner_; 102c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 1032c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang // Cached information for this connection. 1045711892b76b3ba2dea53aec0769ca36cb04b3cecNingyuan Wang bool is_associated_; 105042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang std::vector<uint8_t> bssid_; 106042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang uint32_t associate_freq_; 107042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang 1082c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang // Capability information for this wiphy/interface. 1092c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang BandInfo band_info_; 1102c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang ScanCapabilities scan_capabilities_; 1112c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang WiphyFeatures wiphy_features_; 1122c74cae9b5e0f0e72250fd5f82928768496a5f37Ningyuan Wang 113c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley DISALLOW_COPY_AND_ASSIGN(ClientInterfaceImpl); 114042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang friend class MlmeEventHandlerImpl; 115c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley}; 116c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 117c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley} // namespace wificond 118c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley} // namespace android 119c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley 120c139fbf821d3c62523afbcf0950ebc2d1abaa93dChristopher Wiley#endif // WIFICOND_CLIENT_INTERFACE_IMPL_H_ 121