Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 1 | // 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 Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 5 | #include "debugd/src/debug_mode_tool.h" |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 6 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 9 | #include <base/files/file_util.h> |
Ben Chan | d9a3f04 | 2014-05-13 17:22:43 -0700 | [diff] [blame] | 10 | #include <chromeos/dbus/service_constants.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 11 | #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 Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 16 | |
| 17 | namespace debugd { |
| 18 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 19 | namespace { |
| 20 | |
mukesh agrawal | 8391277 | 2015-05-07 16:48:54 -0700 | [diff] [blame] | 21 | const int kFlimflamLogLevelVerbose3 = -3; |
| 22 | const int kFlimflamLogLevelInfo = 0; |
| 23 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 24 | const char kSupplicantServiceName[] = "fi.w1.wpa_supplicant1"; |
Brian Norris | 807e39d | 2019-05-08 11:39:32 -0700 | [diff] [blame] | 25 | const char kSupplicantObjectPath[] = "/fi/w1/wpa_supplicant1"; |
Eric Caruso | 54532f2 | 2017-05-10 10:55:06 -0700 | [diff] [blame] | 26 | const char kSupplicantDebugLevel[] = "DebugLevel"; |
| 27 | |
| 28 | class SupplicantProxy { |
| 29 | public: |
| 30 | struct Properties : public dbus::PropertySet { |
| 31 | dbus::Property<std::string> debug_level; |
| 32 | |
| 33 | explicit Properties(dbus::ObjectProxy* proxy) |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 34 | : dbus::PropertySet(proxy, |
| 35 | kSupplicantServiceName, |
Eric Caruso | 54532f2 | 2017-05-10 10:55:06 -0700 | [diff] [blame] | 36 | 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 Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 47 | SupplicantProxy(const SupplicantProxy&) = delete; |
| 48 | SupplicantProxy& operator=(const SupplicantProxy&) = delete; |
Eric Caruso | 54532f2 | 2017-05-10 10:55:06 -0700 | [diff] [blame] | 49 | |
| 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 Caruso | 54532f2 | 2017-05-10 10:55:06 -0700 | [diff] [blame] | 59 | }; |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 60 | |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 61 | // Marvell wifi. |
Brian Norris | 7e19cde | 2018-03-22 14:44:48 -0700 | [diff] [blame] | 62 | constexpr char kMwifiexDebugFlag[] = |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 63 | "/sys/kernel/debug/mwifiex/mlan0/debug_mask"; |
| 64 | // Enable extra debugging: MSG | FATAL | ERROR | CMD | EVENT. |
| 65 | constexpr char kMwifiexEnable[] = "0x37"; |
| 66 | // Default debugging level: MSG | FATAL | ERROR. |
| 67 | constexpr char kMwifiexDisable[] = "0x7"; |
| 68 | |
| 69 | // Intel wifi. |
| 70 | constexpr 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 |
| 73 | constexpr char kIwlwifiEnable[] = "0xFFFFFFFF"; |
| 74 | // Default debugging: none |
| 75 | constexpr char kIwlwifiDisable[] = "0x0"; |
| 76 | |
Brian Norris | 7e19cde | 2018-03-22 14:44:48 -0700 | [diff] [blame] | 77 | // Qualcomm/Atheros wifi. |
Brian Norris | 357cf00 | 2019-11-21 18:16:32 -0800 | [diff] [blame] | 78 | constexpr char kAth10kDebugFlag[] = |
| 79 | "/sys/module/ath10k_core/parameters/debug_mask"; |
Brian Norris | 7e19cde | 2018-03-22 14:44:48 -0700 | [diff] [blame] | 80 | // Full debugging: see below file for details on each bit: |
| 81 | // drivers/net/wireless/ath/ath10k/debug.h |
| 82 | constexpr char kAth10kEnable[] = "0xFFFFFFFF"; |
| 83 | // Default debugging: none |
| 84 | constexpr char kAth10kDisable[] = "0x0"; |
| 85 | |
Brian Norris | 357cf00 | 2019-11-21 18:16:32 -0800 | [diff] [blame] | 86 | // Realtek wifi. |
Brian Norris | 6ed59a3 | 2020-08-31 12:27:03 -0700 | [diff] [blame] | 87 | constexpr char kRtw88DebugFlag[] = |
| 88 | "/sys/module/rtw88_core/parameters/debug_mask"; |
Brian Norris | 357cf00 | 2019-11-21 18:16:32 -0800 | [diff] [blame] | 89 | // Full debugging: see below file for details on each bit: |
| 90 | // drivers/net/wireless/realtek/rtw88/debug.h |
| 91 | constexpr char kRtw88Enable[] = "0xFFFFFFFF"; |
| 92 | // Default debugging: none |
| 93 | constexpr char kRtw88Disable[] = "0x0"; |
| 94 | |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 95 | void 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 | } |
| 104 | void WifiSetDebugLevels(bool enable) { |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 105 | MaybeWriteSysfs(kIwlwifiDebugFlag, enable ? kIwlwifiEnable : kIwlwifiDisable); |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 106 | |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 107 | MaybeWriteSysfs(kMwifiexDebugFlag, enable ? kMwifiexEnable : kMwifiexDisable); |
Brian Norris | 7e19cde | 2018-03-22 14:44:48 -0700 | [diff] [blame] | 108 | |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 109 | MaybeWriteSysfs(kAth10kDebugFlag, enable ? kAth10kEnable : kAth10kDisable); |
Brian Norris | 357cf00 | 2019-11-21 18:16:32 -0800 | [diff] [blame] | 110 | |
| 111 | MaybeWriteSysfs(kRtw88DebugFlag, enable ? kRtw88Enable : kRtw88Disable); |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 112 | } |
| 113 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 114 | } // namespace |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 115 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 116 | DebugModeTool::DebugModeTool(scoped_refptr<dbus::Bus> bus) : bus_(bus) {} |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 117 | |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 118 | void DebugModeTool::SetDebugMode(const std::string& subsystem) { |
mukesh agrawal | 8391277 | 2015-05-07 16:48:54 -0700 | [diff] [blame] | 119 | std::string flimflam_tags; |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 120 | std::string supplicant_level = "info"; |
Mike Frysinger | cbee82a | 2017-09-27 17:32:31 -0400 | [diff] [blame] | 121 | std::string modemmanager_level = "info"; |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 122 | bool wifi_debug = false; |
| 123 | |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 124 | if (subsystem == "wifi") { |
mukesh agrawal | 8391277 | 2015-05-07 16:48:54 -0700 | [diff] [blame] | 125 | flimflam_tags = "service+wifi+inet+device+manager"; |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 126 | supplicant_level = "msgdump"; |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 127 | wifi_debug = true; |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 128 | } else if (subsystem == "cellular") { |
mukesh agrawal | 8391277 | 2015-05-07 16:48:54 -0700 | [diff] [blame] | 129 | flimflam_tags = "service+cellular+modem+device+manager"; |
Mike Frysinger | cbee82a | 2017-09-27 17:32:31 -0400 | [diff] [blame] | 130 | modemmanager_level = "debug"; |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 131 | } else if (subsystem == "ethernet") { |
mukesh agrawal | 8391277 | 2015-05-07 16:48:54 -0700 | [diff] [blame] | 132 | flimflam_tags = "service+ethernet+device+manager"; |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 133 | } else if (subsystem == "none") { |
mukesh agrawal | 8391277 | 2015-05-07 16:48:54 -0700 | [diff] [blame] | 134 | flimflam_tags = ""; |
Elly Jones | 15fc20f | 2012-02-09 14:29:06 -0500 | [diff] [blame] | 135 | } |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 136 | |
Ben Chan | 8e9f6d0 | 2017-09-26 23:04:21 -0700 | [diff] [blame] | 137 | auto shill = std::make_unique<org::chromium::flimflam::ManagerProxy>(bus_); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 138 | 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 agrawal | 8391277 | 2015-05-07 16:48:54 -0700 | [diff] [blame] | 145 | } |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 146 | |
Mike Frysinger | 27ce068 | 2017-09-27 17:39:04 -0400 | [diff] [blame] | 147 | WifiSetDebugLevels(wifi_debug); |
| 148 | |
Eric Caruso | 54532f2 | 2017-05-10 10:55:06 -0700 | [diff] [blame] | 149 | SupplicantProxy supplicant(bus_); |
| 150 | supplicant.SetDebugLevel(supplicant_level); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 151 | |
Ben Chan | 6f2ec9b | 2019-05-01 16:13:16 -0700 | [diff] [blame] | 152 | SetModemManagerLogging(modemmanager_level); |
Yuri Gorshenin | c18dee3 | 2012-08-16 23:03:46 +0400 | [diff] [blame] | 153 | } |
| 154 | |
Ben Chan | 6f2ec9b | 2019-05-01 16:13:16 -0700 | [diff] [blame] | 155 | void DebugModeTool::SetModemManagerLogging(const std::string& level) { |
Ben Chan | 1305d03 | 2014-04-07 14:08:01 -0700 | [diff] [blame] | 156 | #if USE_CELLULAR |
Ben Chan | 6f2ec9b | 2019-05-01 16:13:16 -0700 | [diff] [blame] | 157 | static constexpr char kSetLogging[] = "SetLogging"; |
Yuri Gorshenin | c18dee3 | 2012-08-16 23:03:46 +0400 | [diff] [blame] | 158 | |
Ben Chan | 6f2ec9b | 2019-05-01 16:13:16 -0700 | [diff] [blame] | 159 | dbus::ObjectProxy* proxy = bus_->GetObjectProxy( |
| 160 | modemmanager::kModemManager1ServiceName, |
| 161 | dbus::ObjectPath(modemmanager::kModemManager1ServicePath)); |
| 162 | dbus::MethodCall method_call(modemmanager::kModemManager1ServiceName, |
| 163 | kSetLogging); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 164 | dbus::MessageWriter writer(&method_call); |
| 165 | writer.AppendString(level); |
| 166 | proxy->CallMethodAndBlock(&method_call, |
| 167 | dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); |
Eric Caruso | ed33525 | 2018-05-25 16:26:11 -0700 | [diff] [blame] | 168 | #endif // USE_CELLULAR |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Ben Chan | 1305d03 | 2014-04-07 14:08:01 -0700 | [diff] [blame] | 171 | } // namespace debugd |