blob: 832eb5cf06edd078931164dc51bd7996b30d13ce [file] [log] [blame]
Tomasz Wasilczyka5c83a52020-06-16 15:58:19 -07001/*
2 * Copyright (C) 2020 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 <libnetdevice/ethtool.h>
18
19#include "ifreqs.h"
20
21#include <linux/ethtool.h>
Tomasz Wasilczyk426708b2024-10-10 11:34:36 -070022#include <linux/sockios.h>
Tomasz Wasilczyka5c83a52020-06-16 15:58:19 -070023
24namespace android::netdevice::ethtool {
25
26std::optional<uint32_t> getValue(const std::string& ifname, uint32_t command) {
27 struct ethtool_value valueop = {};
28 valueop.cmd = command;
29
30 auto ifr = ifreqs::fromName(ifname);
Tomasz Wasilczyk426708b2024-10-10 11:34:36 -070031 ifr.ifr_data = reinterpret_cast<caddr_t>(&valueop);
Tomasz Wasilczyka5c83a52020-06-16 15:58:19 -070032
33 if (!ifreqs::send(SIOCETHTOOL, ifr)) return std::nullopt;
34 return valueop.data;
35}
36
37bool setValue(const std::string& ifname, uint32_t command, uint32_t value) {
38 struct ethtool_value valueop = {};
39 valueop.cmd = command;
40 valueop.data = value;
41
42 auto ifr = ifreqs::fromName(ifname);
Tomasz Wasilczyk426708b2024-10-10 11:34:36 -070043 ifr.ifr_data = reinterpret_cast<caddr_t>(&valueop);
Tomasz Wasilczyka5c83a52020-06-16 15:58:19 -070044
45 return ifreqs::send(SIOCETHTOOL, ifr);
46}
47
48} // namespace android::netdevice::ethtool