Home | History | Annotate | Download | only in default
      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 <android-base/logging.h>
     18 
     19 #include "hidl_return_util.h"
     20 #include "hidl_struct_util.h"
     21 #include "wifi_ap_iface.h"
     22 #include "wifi_status_util.h"
     23 
     24 namespace android {
     25 namespace hardware {
     26 namespace wifi {
     27 namespace V1_2 {
     28 namespace implementation {
     29 using hidl_return_util::validateAndCall;
     30 
     31 WifiApIface::WifiApIface(
     32     const std::string& ifname,
     33     const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
     34     : ifname_(ifname), legacy_hal_(legacy_hal), is_valid_(true) {}
     35 
     36 void WifiApIface::invalidate() {
     37     legacy_hal_.reset();
     38     is_valid_ = false;
     39 }
     40 
     41 bool WifiApIface::isValid() { return is_valid_; }
     42 
     43 std::string WifiApIface::getName() { return ifname_; }
     44 
     45 Return<void> WifiApIface::getName(getName_cb hidl_status_cb) {
     46     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
     47                            &WifiApIface::getNameInternal, hidl_status_cb);
     48 }
     49 
     50 Return<void> WifiApIface::getType(getType_cb hidl_status_cb) {
     51     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
     52                            &WifiApIface::getTypeInternal, hidl_status_cb);
     53 }
     54 
     55 Return<void> WifiApIface::setCountryCode(const hidl_array<int8_t, 2>& code,
     56                                          setCountryCode_cb hidl_status_cb) {
     57     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
     58                            &WifiApIface::setCountryCodeInternal, hidl_status_cb,
     59                            code);
     60 }
     61 
     62 Return<void> WifiApIface::getValidFrequenciesForBand(
     63     WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) {
     64     return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
     65                            &WifiApIface::getValidFrequenciesForBandInternal,
     66                            hidl_status_cb, band);
     67 }
     68 
     69 std::pair<WifiStatus, std::string> WifiApIface::getNameInternal() {
     70     return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
     71 }
     72 
     73 std::pair<WifiStatus, IfaceType> WifiApIface::getTypeInternal() {
     74     return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::AP};
     75 }
     76 
     77 WifiStatus WifiApIface::setCountryCodeInternal(
     78     const std::array<int8_t, 2>& code) {
     79     legacy_hal::wifi_error legacy_status =
     80         legacy_hal_.lock()->setCountryCode(ifname_, code);
     81     return createWifiStatusFromLegacyError(legacy_status);
     82 }
     83 
     84 std::pair<WifiStatus, std::vector<WifiChannelInMhz>>
     85 WifiApIface::getValidFrequenciesForBandInternal(WifiBand band) {
     86     static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t),
     87                   "Size mismatch");
     88     legacy_hal::wifi_error legacy_status;
     89     std::vector<uint32_t> valid_frequencies;
     90     std::tie(legacy_status, valid_frequencies) =
     91         legacy_hal_.lock()->getValidFrequenciesForBand(
     92             ifname_, hidl_struct_util::convertHidlWifiBandToLegacy(band));
     93     return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies};
     94 }
     95 }  // namespace implementation
     96 }  // namespace V1_2
     97 }  // namespace wifi
     98 }  // namespace hardware
     99 }  // namespace android
    100