blob: e2beec2c6268fe4a133a6d3d82278314c6d7a948 [file] [log] [blame]
Roshan Pius3e2d6712016-10-06 13:16:23 -07001/*
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
Roshan Pius3e2d6712016-10-06 13:16:23 -070017#include <android-base/logging.h>
18
Roshan Pius907d4a22016-10-27 12:48:12 -070019#include "hidl_return_util.h"
Roshan Pius7f4574d2017-02-22 09:48:03 -080020#include "hidl_struct_util.h"
Roshan Pius907d4a22016-10-27 12:48:12 -070021#include "wifi_ap_iface.h"
Roshan Pius734fea02016-10-11 08:30:28 -070022#include "wifi_status_util.h"
Roshan Pius3e2d6712016-10-06 13:16:23 -070023
24namespace android {
25namespace hardware {
26namespace wifi {
27namespace V1_0 {
28namespace implementation {
Roshan Pius907d4a22016-10-27 12:48:12 -070029using hidl_return_util::validateAndCall;
Roshan Pius3e2d6712016-10-06 13:16:23 -070030
Roshan Pius6cedc972016-10-28 10:11:17 -070031WifiApIface::WifiApIface(
32 const std::string& ifname,
33 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
Roshan Pius3e2d6712016-10-06 13:16:23 -070034 : ifname_(ifname), legacy_hal_(legacy_hal), is_valid_(true) {}
35
36void WifiApIface::invalidate() {
37 legacy_hal_.reset();
38 is_valid_ = false;
39}
40
Roshan Pius907d4a22016-10-27 12:48:12 -070041bool WifiApIface::isValid() {
42 return is_valid_;
43}
44
Roshan Pius734fea02016-10-11 08:30:28 -070045Return<void> WifiApIface::getName(getName_cb hidl_status_cb) {
Roshan Pius907d4a22016-10-27 12:48:12 -070046 return validateAndCall(this,
47 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
48 &WifiApIface::getNameInternal,
49 hidl_status_cb);
Roshan Pius3e2d6712016-10-06 13:16:23 -070050}
51
Roshan Pius734fea02016-10-11 08:30:28 -070052Return<void> WifiApIface::getType(getType_cb hidl_status_cb) {
Roshan Pius907d4a22016-10-27 12:48:12 -070053 return validateAndCall(this,
54 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
55 &WifiApIface::getTypeInternal,
56 hidl_status_cb);
57}
58
Roshan Pius32fc12e2017-01-25 17:44:42 -080059Return<void> WifiApIface::setCountryCode(const hidl_array<int8_t, 2>& code,
60 setCountryCode_cb hidl_status_cb) {
61 return validateAndCall(this,
62 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
63 &WifiApIface::setCountryCodeInternal,
64 hidl_status_cb,
65 code);
66}
67
Roshan Pius7f4574d2017-02-22 09:48:03 -080068Return<void> WifiApIface::getValidFrequenciesForBand(
69 WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) {
70 return validateAndCall(this,
71 WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
72 &WifiApIface::getValidFrequenciesForBandInternal,
73 hidl_status_cb,
74 band);
75}
76
Roshan Pius907d4a22016-10-27 12:48:12 -070077std::pair<WifiStatus, std::string> WifiApIface::getNameInternal() {
78 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
79}
80
81std::pair<WifiStatus, IfaceType> WifiApIface::getTypeInternal() {
82 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::AP};
Roshan Pius3e2d6712016-10-06 13:16:23 -070083}
84
Roshan Pius32fc12e2017-01-25 17:44:42 -080085WifiStatus WifiApIface::setCountryCodeInternal(
86 const std::array<int8_t, 2>& code) {
87 legacy_hal::wifi_error legacy_status =
88 legacy_hal_.lock()->setCountryCode(code);
89 return createWifiStatusFromLegacyError(legacy_status);
90}
91
Roshan Pius7f4574d2017-02-22 09:48:03 -080092std::pair<WifiStatus, std::vector<WifiChannelInMhz>>
93WifiApIface::getValidFrequenciesForBandInternal(WifiBand band) {
94 static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch");
95 legacy_hal::wifi_error legacy_status;
96 std::vector<uint32_t> valid_frequencies;
97 std::tie(legacy_status, valid_frequencies) =
98 legacy_hal_.lock()->getValidFrequenciesForBand(
99 hidl_struct_util::convertHidlWifiBandToLegacy(band));
100 return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies};
101}
Roshan Pius3e2d6712016-10-06 13:16:23 -0700102} // namespace implementation
103} // namespace V1_0
104} // namespace wifi
105} // namespace hardware
106} // namespace android