blob: 126b6ca59934f5b9ca569e6c10e2c5b0ae0fd3b5 [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
24namespace android {
25namespace hardware {
26namespace wifi {
Ahmed ElArabawyf501a982019-07-23 15:02:22 -070027namespace V1_4 {
Roshan Pius99dab382019-02-14 07:57:10 -080028namespace implementation {
29namespace iface_util {
30
Roshan Pius356d5a62019-05-17 15:07:34 -070031// Iface event handlers.
32struct IfaceEventHandlers {
33 // Callback to be invoked when the iface is set down & up for MAC address
34 // change.
35 std::function<void(const std::string& iface_name)> on_state_toggle_off_on;
36};
37
Roshan Pius99dab382019-02-14 07:57:10 -080038/**
39 * Util class for common iface operations.
40 */
41class WifiIfaceUtil {
42 public:
Roshan Piusc885df02019-05-21 14:49:05 -070043 WifiIfaceUtil(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
Roshan Pius99dab382019-02-14 07:57:10 -080044 virtual ~WifiIfaceUtil() = default;
45
46 virtual std::array<uint8_t, 6> getFactoryMacAddress(
47 const std::string& iface_name);
48 virtual bool setMacAddress(const std::string& iface_name,
49 const std::array<uint8_t, 6>& mac);
Roshan Pius3b6705f2019-02-14 09:43:43 -080050 // Get or create a random MAC address. The MAC address returned from
51 // this method will remain the same throughout the lifetime of the HAL
52 // daemon. (So, changes on every reboot)
53 virtual std::array<uint8_t, 6> getOrCreateRandomMacAddress();
Roshan Pius99dab382019-02-14 07:57:10 -080054
Roshan Pius356d5a62019-05-17 15:07:34 -070055 // Register for any iface event callbacks for the provided interface.
56 virtual void registerIfaceEventHandlers(const std::string& iface_name,
57 IfaceEventHandlers handlers);
58 virtual void unregisterIfaceEventHandlers(const std::string& iface_name);
Roshan Pius5ba0a902020-04-14 11:55:42 -070059 virtual bool setUpState(const std::string& iface_name, bool request_up);
Nate Jiang63f34ed2020-05-20 23:22:51 -070060 virtual unsigned ifNameToIndex(const std::string& iface_name);
Roshan Pius356d5a62019-05-17 15:07:34 -070061
Roshan Pius99dab382019-02-14 07:57:10 -080062 private:
Roshan Pius3b6705f2019-02-14 09:43:43 -080063 std::array<uint8_t, 6> createRandomMacAddress();
64
Roshan Piusc885df02019-05-21 14:49:05 -070065 std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
Roshan Pius3b6705f2019-02-14 09:43:43 -080066 std::unique_ptr<std::array<uint8_t, 6>> random_mac_address_;
Roshan Pius356d5a62019-05-17 15:07:34 -070067 std::map<std::string, IfaceEventHandlers> event_handlers_map_;
Roshan Pius99dab382019-02-14 07:57:10 -080068};
69
70} // namespace iface_util
71} // namespace implementation
Ahmed ElArabawyf501a982019-07-23 15:02:22 -070072} // namespace V1_4
Roshan Pius99dab382019-02-14 07:57:10 -080073} // namespace wifi
74} // namespace hardware
75} // namespace android
76
77#endif // WIFI_IFACE_UTIL_H_