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