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 #include "wificond/ap_interface_binder.h"
     18 
     19 #include <android-base/logging.h>
     20 #include <wifi_system/hostapd_manager.h>
     21 
     22 #include "wificond/ap_interface_impl.h"
     23 
     24 using android::net::wifi::IApInterfaceEventCallback;
     25 
     26 namespace android {
     27 namespace wificond {
     28 
     29 ApInterfaceBinder::ApInterfaceBinder(ApInterfaceImpl* impl)
     30     : impl_{impl}, ap_interface_event_callback_(nullptr) {}
     31 
     32 ApInterfaceBinder::~ApInterfaceBinder() {
     33 }
     34 
     35 void ApInterfaceBinder::NotifyNumAssociatedStationsChanged(int num_stations) {
     36   if (ap_interface_event_callback_ != nullptr) {
     37     ap_interface_event_callback_->onNumAssociatedStationsChanged(num_stations);
     38   }
     39 }
     40 
     41 void ApInterfaceBinder::NotifySoftApChannelSwitched(
     42     int frequency, ChannelBandwidth channel_bandwidth) {
     43   if (ap_interface_event_callback_ == nullptr) {
     44     return;
     45   }
     46 
     47   int bandwidth;
     48   switch (channel_bandwidth) {
     49     case ChannelBandwidth::BW_INVALID:
     50       bandwidth = IApInterfaceEventCallback::BANDWIDTH_INVALID;
     51       break;
     52     case ChannelBandwidth::BW_20_NOHT:
     53       bandwidth = IApInterfaceEventCallback::BANDWIDTH_20_NOHT;
     54       break;
     55     case ChannelBandwidth::BW_20:
     56       bandwidth = IApInterfaceEventCallback::BANDWIDTH_20;
     57       break;
     58     case ChannelBandwidth::BW_40:
     59       bandwidth = IApInterfaceEventCallback::BANDWIDTH_40;
     60       break;
     61     case ChannelBandwidth::BW_80:
     62       bandwidth = IApInterfaceEventCallback::BANDWIDTH_80;
     63       break;
     64     case ChannelBandwidth::BW_80P80:
     65       bandwidth = IApInterfaceEventCallback::BANDWIDTH_80P80;
     66       break;
     67     case ChannelBandwidth::BW_160:
     68       bandwidth = IApInterfaceEventCallback::BANDWIDTH_160;
     69       break;
     70     default:
     71       bandwidth = IApInterfaceEventCallback::BANDWIDTH_INVALID;
     72   }
     73   ap_interface_event_callback_->onSoftApChannelSwitched(frequency, bandwidth);
     74 }
     75 
     76 binder::Status ApInterfaceBinder::startHostapd(
     77     const sp<IApInterfaceEventCallback>& callback, bool* out_success) {
     78   *out_success = false;
     79   if (!impl_) {
     80     LOG(WARNING) << "Cannot start hostapd on dead ApInterface.";
     81     return binder::Status::ok();
     82   }
     83   *out_success = impl_->StartHostapd();
     84   if (*out_success) {
     85     ap_interface_event_callback_ = callback;
     86   }
     87   return binder::Status::ok();
     88 }
     89 
     90 binder::Status ApInterfaceBinder::stopHostapd(bool* out_success) {
     91   *out_success = false;
     92   if (!impl_) {
     93     LOG(WARNING) << "Cannot stop hostapd on dead ApInterface.";
     94     return binder::Status::ok();
     95   }
     96   *out_success = impl_->StopHostapd();
     97   ap_interface_event_callback_.clear();
     98   return binder::Status::ok();
     99 }
    100 
    101 binder::Status ApInterfaceBinder::getInterfaceName(std::string* out_name) {
    102   if (!impl_) {
    103     LOG(WARNING) << "Cannot get interface name from dead ApInterface";
    104     return binder::Status::ok();
    105   }
    106   *out_name = impl_->GetInterfaceName();
    107   return binder::Status::ok();
    108 }
    109 
    110 binder::Status ApInterfaceBinder::getNumberOfAssociatedStations(
    111     int* out_num_of_stations) {
    112   if (!impl_) {
    113     LOG(WARNING) << "Cannot get number of associated stations "
    114                  << "from dead ApInterface";
    115     *out_num_of_stations = -1;
    116     return binder::Status::ok();
    117   }
    118   *out_num_of_stations = impl_->GetNumberOfAssociatedStations();
    119   return binder::Status::ok();
    120 }
    121 
    122 }  // namespace wificond
    123 }  // namespace android
    124