blob: d0797d64e4082dada28afeaa722f14c44568347e [file] [log] [blame]
Elly Jones15fc20f2012-02-09 14:29:06 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#include "debugd/src/debug_mode_tool.h"
Elly Jones15fc20f2012-02-09 14:29:06 -05006
Eric Carusocc7106c2017-04-27 14:22:42 -07007#include <memory>
8
Mike Frysinger27ce0682017-09-27 17:39:04 -04009#include <base/files/file_util.h>
Ben Chand9a3f042014-05-13 17:22:43 -070010#include <chromeos/dbus/service_constants.h>
Eric Carusocc7106c2017-04-27 14:22:42 -070011#include <dbus/bus.h>
12#include <dbus/message.h>
13#include <dbus/object_proxy.h>
14#include <dbus/property.h>
15#include <shill/dbus-proxies.h>
Elly Jones15fc20f2012-02-09 14:29:06 -050016
17namespace debugd {
18
Ben Chanaf125862017-02-08 23:11:18 -080019namespace {
20
mukesh agrawal83912772015-05-07 16:48:54 -070021const int kFlimflamLogLevelVerbose3 = -3;
22const int kFlimflamLogLevelInfo = 0;
23
Eric Carusocc7106c2017-04-27 14:22:42 -070024const char kSupplicantServiceName[] = "fi.w1.wpa_supplicant1";
Brian Norris807e39d2019-05-08 11:39:32 -070025const char kSupplicantObjectPath[] = "/fi/w1/wpa_supplicant1";
Eric Caruso54532f22017-05-10 10:55:06 -070026const char kSupplicantDebugLevel[] = "DebugLevel";
27
28class SupplicantProxy {
29 public:
30 struct Properties : public dbus::PropertySet {
31 dbus::Property<std::string> debug_level;
32
33 explicit Properties(dbus::ObjectProxy* proxy)
Tom Hughesd6c2d392020-08-24 18:12:11 -070034 : dbus::PropertySet(proxy,
35 kSupplicantServiceName,
Eric Caruso54532f22017-05-10 10:55:06 -070036 dbus::PropertySet::PropertyChangedCallback()) {
37 RegisterProperty(kSupplicantDebugLevel, &debug_level);
38 }
39
40 ~Properties() override = default;
41 };
42
43 explicit SupplicantProxy(scoped_refptr<dbus::Bus> bus)
44 : bus_(bus),
45 properties_(bus->GetObjectProxy(
46 kSupplicantServiceName, dbus::ObjectPath(kSupplicantObjectPath))) {}
Qijiang Fan6bc59e12020-11-11 02:51:06 +090047 SupplicantProxy(const SupplicantProxy&) = delete;
48 SupplicantProxy& operator=(const SupplicantProxy&) = delete;
Eric Caruso54532f22017-05-10 10:55:06 -070049
50 ~SupplicantProxy() {}
51
52 void SetDebugLevel(const std::string& level) {
53 properties_.debug_level.SetAndBlock(level);
54 }
55
56 private:
57 scoped_refptr<dbus::Bus> bus_;
58 Properties properties_;
Eric Caruso54532f22017-05-10 10:55:06 -070059};
Ben Chanaf125862017-02-08 23:11:18 -080060
Mike Frysinger27ce0682017-09-27 17:39:04 -040061// Marvell wifi.
Brian Norris7e19cde2018-03-22 14:44:48 -070062constexpr char kMwifiexDebugFlag[] =
Mike Frysinger27ce0682017-09-27 17:39:04 -040063 "/sys/kernel/debug/mwifiex/mlan0/debug_mask";
64// Enable extra debugging: MSG | FATAL | ERROR | CMD | EVENT.
65constexpr char kMwifiexEnable[] = "0x37";
66// Default debugging level: MSG | FATAL | ERROR.
67constexpr char kMwifiexDisable[] = "0x7";
68
69// Intel wifi.
70constexpr char kIwlwifiDebugFlag[] = "/sys/module/iwlwifi/parameters/debug";
71// Full debugging: see below file for details on each bit:
72// drivers/net/wireless-$(WIFIVERSION)/iwl7000/iwlwifi/iwl-debug.h
73constexpr char kIwlwifiEnable[] = "0xFFFFFFFF";
74// Default debugging: none
75constexpr char kIwlwifiDisable[] = "0x0";
76
Brian Norris7e19cde2018-03-22 14:44:48 -070077// Qualcomm/Atheros wifi.
Brian Norris357cf002019-11-21 18:16:32 -080078constexpr char kAth10kDebugFlag[] =
79 "/sys/module/ath10k_core/parameters/debug_mask";
Brian Norris7e19cde2018-03-22 14:44:48 -070080// Full debugging: see below file for details on each bit:
81// drivers/net/wireless/ath/ath10k/debug.h
82constexpr char kAth10kEnable[] = "0xFFFFFFFF";
83// Default debugging: none
84constexpr char kAth10kDisable[] = "0x0";
85
Brian Norris357cf002019-11-21 18:16:32 -080086// Realtek wifi.
Brian Norris6ed59a32020-08-31 12:27:03 -070087constexpr char kRtw88DebugFlag[] =
88 "/sys/module/rtw88_core/parameters/debug_mask";
Brian Norris357cf002019-11-21 18:16:32 -080089// Full debugging: see below file for details on each bit:
90// drivers/net/wireless/realtek/rtw88/debug.h
91constexpr char kRtw88Enable[] = "0xFFFFFFFF";
92// Default debugging: none
93constexpr char kRtw88Disable[] = "0x0";
94
Mike Frysinger27ce0682017-09-27 17:39:04 -040095void MaybeWriteSysfs(const char* sysfs_path, const char* data) {
96 base::FilePath path(sysfs_path);
97
98 if (base::PathExists(path)) {
99 int len = strlen(data);
100 if (base::WriteFile(path, data, len) != len)
101 PLOG(WARNING) << "Writing to " << path.value() << " failed";
102 }
103}
104void WifiSetDebugLevels(bool enable) {
Tom Hughesd6c2d392020-08-24 18:12:11 -0700105 MaybeWriteSysfs(kIwlwifiDebugFlag, enable ? kIwlwifiEnable : kIwlwifiDisable);
Mike Frysinger27ce0682017-09-27 17:39:04 -0400106
Tom Hughesd6c2d392020-08-24 18:12:11 -0700107 MaybeWriteSysfs(kMwifiexDebugFlag, enable ? kMwifiexEnable : kMwifiexDisable);
Brian Norris7e19cde2018-03-22 14:44:48 -0700108
Tom Hughesd6c2d392020-08-24 18:12:11 -0700109 MaybeWriteSysfs(kAth10kDebugFlag, enable ? kAth10kEnable : kAth10kDisable);
Brian Norris357cf002019-11-21 18:16:32 -0800110
111 MaybeWriteSysfs(kRtw88DebugFlag, enable ? kRtw88Enable : kRtw88Disable);
Mike Frysinger27ce0682017-09-27 17:39:04 -0400112}
113
Ben Chanaf125862017-02-08 23:11:18 -0800114} // namespace
Elly Jones15fc20f2012-02-09 14:29:06 -0500115
Eric Carusocc7106c2017-04-27 14:22:42 -0700116DebugModeTool::DebugModeTool(scoped_refptr<dbus::Bus> bus) : bus_(bus) {}
Elly Jones15fc20f2012-02-09 14:29:06 -0500117
Eric Carusoc93a15c2017-04-24 16:15:12 -0700118void DebugModeTool::SetDebugMode(const std::string& subsystem) {
mukesh agrawal83912772015-05-07 16:48:54 -0700119 std::string flimflam_tags;
Elly Jones15fc20f2012-02-09 14:29:06 -0500120 std::string supplicant_level = "info";
Mike Frysingercbee82a2017-09-27 17:32:31 -0400121 std::string modemmanager_level = "info";
Mike Frysinger27ce0682017-09-27 17:39:04 -0400122 bool wifi_debug = false;
123
Elly Jones15fc20f2012-02-09 14:29:06 -0500124 if (subsystem == "wifi") {
mukesh agrawal83912772015-05-07 16:48:54 -0700125 flimflam_tags = "service+wifi+inet+device+manager";
Elly Jones15fc20f2012-02-09 14:29:06 -0500126 supplicant_level = "msgdump";
Mike Frysinger27ce0682017-09-27 17:39:04 -0400127 wifi_debug = true;
Elly Jones15fc20f2012-02-09 14:29:06 -0500128 } else if (subsystem == "cellular") {
mukesh agrawal83912772015-05-07 16:48:54 -0700129 flimflam_tags = "service+cellular+modem+device+manager";
Mike Frysingercbee82a2017-09-27 17:32:31 -0400130 modemmanager_level = "debug";
Elly Jones15fc20f2012-02-09 14:29:06 -0500131 } else if (subsystem == "ethernet") {
mukesh agrawal83912772015-05-07 16:48:54 -0700132 flimflam_tags = "service+ethernet+device+manager";
Elly Jones15fc20f2012-02-09 14:29:06 -0500133 } else if (subsystem == "none") {
mukesh agrawal83912772015-05-07 16:48:54 -0700134 flimflam_tags = "";
Elly Jones15fc20f2012-02-09 14:29:06 -0500135 }
Eric Carusocc7106c2017-04-27 14:22:42 -0700136
Ben Chan8e9f6d02017-09-26 23:04:21 -0700137 auto shill = std::make_unique<org::chromium::flimflam::ManagerProxy>(bus_);
Eric Carusocc7106c2017-04-27 14:22:42 -0700138 if (shill) {
139 shill->SetDebugTags(flimflam_tags, nullptr);
140 if (flimflam_tags.length()) {
141 shill->SetDebugLevel(kFlimflamLogLevelVerbose3, nullptr);
142 } else {
143 shill->SetDebugLevel(kFlimflamLogLevelInfo, nullptr);
144 }
mukesh agrawal83912772015-05-07 16:48:54 -0700145 }
Eric Carusocc7106c2017-04-27 14:22:42 -0700146
Mike Frysinger27ce0682017-09-27 17:39:04 -0400147 WifiSetDebugLevels(wifi_debug);
148
Eric Caruso54532f22017-05-10 10:55:06 -0700149 SupplicantProxy supplicant(bus_);
150 supplicant.SetDebugLevel(supplicant_level);
Eric Carusocc7106c2017-04-27 14:22:42 -0700151
Ben Chan6f2ec9b2019-05-01 16:13:16 -0700152 SetModemManagerLogging(modemmanager_level);
Yuri Gorsheninc18dee32012-08-16 23:03:46 +0400153}
154
Ben Chan6f2ec9b2019-05-01 16:13:16 -0700155void DebugModeTool::SetModemManagerLogging(const std::string& level) {
Ben Chan1305d032014-04-07 14:08:01 -0700156#if USE_CELLULAR
Ben Chan6f2ec9b2019-05-01 16:13:16 -0700157 static constexpr char kSetLogging[] = "SetLogging";
Yuri Gorsheninc18dee32012-08-16 23:03:46 +0400158
Ben Chan6f2ec9b2019-05-01 16:13:16 -0700159 dbus::ObjectProxy* proxy = bus_->GetObjectProxy(
160 modemmanager::kModemManager1ServiceName,
161 dbus::ObjectPath(modemmanager::kModemManager1ServicePath));
162 dbus::MethodCall method_call(modemmanager::kModemManager1ServiceName,
163 kSetLogging);
Eric Carusocc7106c2017-04-27 14:22:42 -0700164 dbus::MessageWriter writer(&method_call);
165 writer.AppendString(level);
166 proxy->CallMethodAndBlock(&method_call,
167 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
Eric Carusoed335252018-05-25 16:26:11 -0700168#endif // USE_CELLULAR
Eric Carusocc7106c2017-04-27 14:22:42 -0700169}
170
Ben Chan1305d032014-04-07 14:08:01 -0700171} // namespace debugd