blob: 164aca73a092c730ebc7022935c135e6f3d4a735 [file] [log] [blame]
Roshan Pius99dab382019-02-14 07:57:10 -08001/*
2 * Copyright (C) 2019 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#include <android-base/macros.h>
19#include <private/android_filesystem_config.h>
20
21#include "wifi_iface_util.h"
22
23namespace android {
24namespace hardware {
25namespace wifi {
26namespace V1_3 {
27namespace implementation {
28namespace iface_util {
29
Roshan Pius3b6705f2019-02-14 09:43:43 -080030WifiIfaceUtil::WifiIfaceUtil() : random_mac_address_(nullptr) {}
Roshan Pius99dab382019-02-14 07:57:10 -080031
32std::array<uint8_t, 6> WifiIfaceUtil::getFactoryMacAddress(
33 const std::string& iface_name) {
34 return iface_tool_.GetFactoryMacAddress(iface_name.c_str());
35}
36
37bool WifiIfaceUtil::setMacAddress(const std::string& iface_name,
38 const std::array<uint8_t, 6>& mac) {
39 if (!iface_tool_.SetUpState(iface_name.c_str(), false)) {
40 LOG(ERROR) << "SetUpState(false) failed.";
41 return false;
42 }
43 if (!iface_tool_.SetMacAddress(iface_name.c_str(), mac)) {
44 LOG(ERROR) << "SetMacAddress failed.";
45 return false;
46 }
47 if (!iface_tool_.SetUpState(iface_name.c_str(), true)) {
48 LOG(ERROR) << "SetUpState(true) failed.";
49 return false;
50 }
51 LOG(DEBUG) << "Successfully SetMacAddress.";
52 return true;
53}
54
Roshan Pius3b6705f2019-02-14 09:43:43 -080055std::array<uint8_t, 6> WifiIfaceUtil::getOrCreateRandomMacAddress() {
56 if (random_mac_address_) {
57 return *random_mac_address_.get();
58 }
59 random_mac_address_ =
60 std::make_unique<std::array<uint8_t, 6>>(createRandomMacAddress());
61 return *random_mac_address_.get();
62}
63
64std::array<uint8_t, 6> WifiIfaceUtil::createRandomMacAddress() {
65 // TODO: Generate random MAC address here.
66 return {};
67}
Roshan Pius99dab382019-02-14 07:57:10 -080068} // namespace iface_util
69} // namespace implementation
70} // namespace V1_3
71} // namespace wifi
72} // namespace hardware
73} // namespace android