blob: b449077e9ebacc1274f0364b4c0bd3fe3ac89bd9 [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#ifndef WIFI_IFACE_UTIL_H_
18#define WIFI_IFACE_UTIL_H_
19
20#include <wifi_system/interface_tool.h>
21
22#include <android/hardware/wifi/1.0/IWifi.h>
23
Roshan Pius8c1a67b2021-03-02 10:00:23 -080024#include "wifi_legacy_hal.h"
25
Roshan Pius99dab382019-02-14 07:57:10 -080026namespace android {
27namespace hardware {
28namespace wifi {
Jimmy Chend460df32019-11-29 17:31:22 +020029namespace V1_5 {
Roshan Pius99dab382019-02-14 07:57:10 -080030namespace implementation {
31namespace iface_util {
32
Roshan Pius356d5a62019-05-17 15:07:34 -070033// Iface event handlers.
34struct IfaceEventHandlers {
35 // Callback to be invoked when the iface is set down & up for MAC address
36 // change.
37 std::function<void(const std::string& iface_name)> on_state_toggle_off_on;
38};
39
Roshan Pius99dab382019-02-14 07:57:10 -080040/**
41 * Util class for common iface operations.
42 */
43class WifiIfaceUtil {
44 public:
Roshan Pius8c1a67b2021-03-02 10:00:23 -080045 WifiIfaceUtil(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool,
46 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal);
Roshan Pius99dab382019-02-14 07:57:10 -080047 virtual ~WifiIfaceUtil() = default;
48
49 virtual std::array<uint8_t, 6> getFactoryMacAddress(
50 const std::string& iface_name);
51 virtual bool setMacAddress(const std::string& iface_name,
52 const std::array<uint8_t, 6>& mac);
Roshan Pius3b6705f2019-02-14 09:43:43 -080053 // Get or create a random MAC address. The MAC address returned from
54 // this method will remain the same throughout the lifetime of the HAL
55 // daemon. (So, changes on every reboot)
56 virtual std::array<uint8_t, 6> getOrCreateRandomMacAddress();
Roshan Pius99dab382019-02-14 07:57:10 -080057
Roshan Pius356d5a62019-05-17 15:07:34 -070058 // Register for any iface event callbacks for the provided interface.
59 virtual void registerIfaceEventHandlers(const std::string& iface_name,
60 IfaceEventHandlers handlers);
61 virtual void unregisterIfaceEventHandlers(const std::string& iface_name);
Roshan Pius5ba0a902020-04-14 11:55:42 -070062 virtual bool setUpState(const std::string& iface_name, bool request_up);
Nate Jiang63f34ed2020-05-20 23:22:51 -070063 virtual unsigned ifNameToIndex(const std::string& iface_name);
Roshan Pius356d5a62019-05-17 15:07:34 -070064
leslc92aa852020-11-16 15:20:33 +080065 virtual bool createBridge(const std::string& br_name);
66
67 virtual bool deleteBridge(const std::string& br_name);
68
69 virtual bool addIfaceToBridge(const std::string& br_name,
70 const std::string& if_name);
71
72 virtual bool removeIfaceFromBridge(const std::string& br_name,
73 const std::string& if_name);
74
Roshan Pius99dab382019-02-14 07:57:10 -080075 private:
Roshan Pius3b6705f2019-02-14 09:43:43 -080076 std::array<uint8_t, 6> createRandomMacAddress();
77
Roshan Piusc885df02019-05-21 14:49:05 -070078 std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
Roshan Pius8c1a67b2021-03-02 10:00:23 -080079 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
Roshan Pius3b6705f2019-02-14 09:43:43 -080080 std::unique_ptr<std::array<uint8_t, 6>> random_mac_address_;
Roshan Pius356d5a62019-05-17 15:07:34 -070081 std::map<std::string, IfaceEventHandlers> event_handlers_map_;
Roshan Pius99dab382019-02-14 07:57:10 -080082};
83
84} // namespace iface_util
85} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +020086} // namespace V1_5
Roshan Pius99dab382019-02-14 07:57:10 -080087} // namespace wifi
88} // namespace hardware
89} // namespace android
90
91#endif // WIFI_IFACE_UTIL_H_