client_interface_impl.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #ifndef WIFICOND_CLIENT_INTERFACE_IMPL_H_
  17. #define WIFICOND_CLIENT_INTERFACE_IMPL_H_
  18. #include <array>
  19. #include <string>
  20. #include <linux/if_ether.h>
  21. #include <android-base/macros.h>
  22. #include <utils/StrongPointer.h>
  23. #include <wifi_system/interface_tool.h>
  24. #include "android/net/wifi/IClientInterface.h"
  25. #include "android/net/wifi/ISendMgmtFrameEvent.h"
  26. #include "wificond/net/mlme_event_handler.h"
  27. #include "wificond/net/netlink_utils.h"
  28. #include "wificond/scanning/offload/offload_service_utils.h"
  29. #include "wificond/scanning/scanner_impl.h"
  30. namespace android {
  31. namespace wificond {
  32. class ClientInterfaceBinder;
  33. class ClientInterfaceImpl;
  34. class ScanUtils;
  35. class MlmeEventHandlerImpl : public MlmeEventHandler {
  36. public:
  37. MlmeEventHandlerImpl(ClientInterfaceImpl* client_interface);
  38. ~MlmeEventHandlerImpl() override;
  39. void OnConnect(std::unique_ptr<MlmeConnectEvent> event) override;
  40. void OnRoam(std::unique_ptr<MlmeRoamEvent> event) override;
  41. void OnAssociate(std::unique_ptr<MlmeAssociateEvent> event) override;
  42. void OnDisconnect(std::unique_ptr<MlmeDisconnectEvent> event) override;
  43. void OnDisassociate(std::unique_ptr<MlmeDisassociateEvent> event) override;
  44. private:
  45. ClientInterfaceImpl* client_interface_;
  46. };
  47. // Holds the guts of how we control network interfaces capable of connecting to
  48. // access points via wpa_supplicant.
  49. //
  50. // Because remote processes may hold on to the corresponding
  51. // binder object past the lifetime of the local object, we are forced to
  52. // keep this object separate from the binder representation of itself.
  53. class ClientInterfaceImpl {
  54. public:
  55. ClientInterfaceImpl(
  56. uint32_t wiphy_index,
  57. const std::string& interface_name,
  58. uint32_t interface_index,
  59. const std::array<uint8_t, ETH_ALEN>& interface_mac_addr,
  60. android::wifi_system::InterfaceTool* if_tool,
  61. NetlinkUtils* netlink_utils,
  62. ScanUtils* scan_utils);
  63. virtual ~ClientInterfaceImpl();
  64. // Get a pointer to the binder representing this ClientInterfaceImpl.
  65. android::sp<android::net::wifi::IClientInterface> GetBinder() const;
  66. bool GetPacketCounters(std::vector<int32_t>* out_packet_counters);
  67. bool SignalPoll(std::vector<int32_t>* out_signal_poll_results);
  68. const std::array<uint8_t, ETH_ALEN>& GetMacAddress();
  69. const std::string& GetInterfaceName() const { return interface_name_; }
  70. const android::sp<ScannerImpl> GetScanner() { return scanner_; };
  71. bool SetMacAddress(const std::array<uint8_t, ETH_ALEN>& mac);
  72. virtual bool IsAssociated() const;
  73. void Dump(std::stringstream* ss) const;
  74. void SendMgmtFrame(
  75. const std::vector<uint8_t>& frame,
  76. const sp<::android::net::wifi::ISendMgmtFrameEvent>& callback,
  77. int32_t mcs);
  78. private:
  79. bool RefreshAssociateFreq();
  80. const uint32_t wiphy_index_;
  81. const std::string interface_name_;
  82. const uint32_t interface_index_;
  83. const std::array<uint8_t, ETH_ALEN> interface_mac_addr_;
  84. android::wifi_system::InterfaceTool* const if_tool_;
  85. NetlinkUtils* const netlink_utils_;
  86. ScanUtils* const scan_utils_;
  87. const std::shared_ptr<OffloadServiceUtils> offload_service_utils_;
  88. const std::unique_ptr<MlmeEventHandlerImpl> mlme_event_handler_;
  89. const android::sp<ClientInterfaceBinder> binder_;
  90. android::sp<ScannerImpl> scanner_;
  91. // Cached information for this connection.
  92. bool is_associated_;
  93. std::array<uint8_t, ETH_ALEN> bssid_;
  94. uint32_t associate_freq_;
  95. // Capability information for this wiphy/interface.
  96. BandInfo band_info_;
  97. ScanCapabilities scan_capabilities_;
  98. WiphyFeatures wiphy_features_;
  99. // handler for frame tx status messages
  100. bool frame_tx_in_progress_;
  101. uint64_t frame_tx_status_cookie_;
  102. std::function<void(bool was_acked)> on_frame_tx_status_event_handler_;
  103. DISALLOW_COPY_AND_ASSIGN(ClientInterfaceImpl);
  104. friend class MlmeEventHandlerImpl;
  105. };
  106. } // namespace wificond
  107. } // namespace android
  108. #endif // WIFICOND_CLIENT_INTERFACE_IMPL_H_