server.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_SERVER_H_
  17. #define WIFICOND_SERVER_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include <android-base/macros.h>
  22. #include <wifi_system/interface_tool.h>
  23. #include "android/net/wifi/BnWificond.h"
  24. #include "android/net/wifi/IApInterface.h"
  25. #include "android/net/wifi/IClientInterface.h"
  26. #include "android/net/wifi/IInterfaceEventCallback.h"
  27. #include "wificond/ap_interface_impl.h"
  28. #include "wificond/client_interface_impl.h"
  29. namespace android {
  30. namespace wificond {
  31. class NL80211Packet;
  32. class NetlinkUtils;
  33. class ScanUtils;
  34. struct InterfaceInfo;
  35. class Server : public android::net::wifi::BnWificond {
  36. public:
  37. Server(std::unique_ptr<wifi_system::InterfaceTool> if_tool,
  38. NetlinkUtils* netlink_utils,
  39. ScanUtils* scan_utils);
  40. ~Server() override = default;
  41. android::binder::Status RegisterCallback(
  42. const android::sp<android::net::wifi::IInterfaceEventCallback>&
  43. callback) override;
  44. android::binder::Status UnregisterCallback(
  45. const android::sp<android::net::wifi::IInterfaceEventCallback>&
  46. callback) override;
  47. // Returns a vector of available frequencies for 2.4GHz channels.
  48. android::binder::Status getAvailable2gChannels(
  49. ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
  50. // Returns a vector of available frequencies for 5GHz non-DFS channels.
  51. android::binder::Status getAvailable5gNonDFSChannels(
  52. ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
  53. // Returns a vector of available frequencies for DFS channels.
  54. android::binder::Status getAvailableDFSChannels(
  55. ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
  56. android::binder::Status createApInterface(
  57. const std::string& iface_name,
  58. android::sp<android::net::wifi::IApInterface>*
  59. created_interface) override;
  60. android::binder::Status createClientInterface(
  61. const std::string& iface_name,
  62. android::sp<android::net::wifi::IClientInterface>*
  63. created_interface) override;
  64. android::binder::Status tearDownApInterface(
  65. const std::string& iface_name,
  66. bool* out_success) override;
  67. android::binder::Status tearDownClientInterface(
  68. const std::string& iface_name,
  69. bool* out_success) override;
  70. android::binder::Status tearDownInterfaces() override;
  71. android::binder::Status GetClientInterfaces(
  72. std::vector<android::sp<android::IBinder>>* out_client_ifs) override;
  73. android::binder::Status GetApInterfaces(
  74. std::vector<android::sp<android::IBinder>>* out_ap_ifs) override;
  75. status_t dump(int fd, const Vector<String16>& args) override;
  76. private:
  77. // Request interface information from kernel and setup local interface object.
  78. // This assumes that interface should be in STATION mode. Even if we setup
  79. // interface on behalf of createApInterace(), it is Hostapd that configure
  80. // the interface to Ap mode later.
  81. // Returns true on success, false otherwise.
  82. bool SetupInterface(const std::string& iface_name, InterfaceInfo* interface);
  83. bool RefreshWiphyIndex(const std::string& iface_num);
  84. void LogSupportedBands();
  85. void OnRegDomainChanged(std::string& country_code);
  86. void BroadcastClientInterfaceReady(
  87. android::sp<android::net::wifi::IClientInterface> network_interface);
  88. void BroadcastApInterfaceReady(
  89. android::sp<android::net::wifi::IApInterface> network_interface);
  90. void BroadcastClientInterfaceTornDown(
  91. android::sp<android::net::wifi::IClientInterface> network_interface);
  92. void BroadcastApInterfaceTornDown(
  93. android::sp<android::net::wifi::IApInterface> network_interface);
  94. void MarkDownAllInterfaces();
  95. const std::unique_ptr<wifi_system::InterfaceTool> if_tool_;
  96. NetlinkUtils* const netlink_utils_;
  97. ScanUtils* const scan_utils_;
  98. uint32_t wiphy_index_;
  99. std::map<std::string, std::unique_ptr<ApInterfaceImpl>> ap_interfaces_;
  100. std::map<std::string, std::unique_ptr<ClientInterfaceImpl>> client_interfaces_;
  101. std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>>
  102. interface_event_callbacks_;
  103. // Cached interface list from kernel.
  104. std::vector<InterfaceInfo> interfaces_;
  105. DISALLOW_COPY_AND_ASSIGN(Server);
  106. };
  107. } // namespace wificond
  108. } // namespace android
  109. #endif // WIFICOND_SERVER_H_