#618878 [pm-utils] power.d/wireless broken

Package:
pm-utils
Source:
pm-utils
Submitter:
Florian Kriener
Date:
2023-12-21 18:01:00 UTC
Severity:
normal
Tags:
#618878#5
Date:
2011-03-19 10:12:00 UTC
From:
To:
--- Please enter the report below this line. ---
I noticed that pm-utils did not turn on wireless power management
when unplugging from ac on my laptop. I investigated a bit and
found out, that the power.d/wireless skript uses a "heuristic"
method for finding out if a network interface is a wireless
interface. The line in question is

# Skip if not a wireless card.
[ -d "/sys/class/net/$1/wireless" ] || return 1

Apparently, the directory /sys/class/net/$1/wireless has gone
away, or is not available on every platform at least. Therefor I
think it's best to use /sys/class/ieee80211 instead.

The patch below corrects the script accordingly. The new skript
works fine on my box but I cannot test it on different hardware
and it might need some adjustments in the final loop for other
network cards since I am not sure what it means, when one
ieee80211/* device has multiple ../device/net/* devices.


diff --git a/wireless b/wireless
index b4be69c..de70084 100755
--- a/wireless
+++ b/wireless
@@ -16,12 +16,10 @@ get_wireless_params() {
     unset iwpriv iwconfig iwlevel

     # Don't do anything if we cannot find a driver for this iface.
-    [ -L "/sys/class/net/$1/device/driver" ] || return 1
-    # Skip if not a wireless card.
-    [ -d "/sys/class/net/$1/wireless" ] || return 1
+    [ -L "/sys/class/ieee80211/$1/device/driver" ] || return 1
     # Also don't do anything if the device is disabled
-    [ "$(cat /sys/class/net/$1/device/enable)" = "1" ] || return 1
-    driver="$(readlink "/sys/class/net/$1/device/driver")"
+    [ "$(cat /sys/class/ieee80211/$1/device/enable)" = "1" ] || return 1
+    driver="$(readlink "/sys/class/ieee80211/$1/device/driver")"
     driver=${driver##*/}
     case $driver in
         ipw2100) iwpriv_ac="set_power 0"
@@ -31,7 +29,7 @@ get_wireless_params() {
         ipw3945)
             iwpriv_ac="set_power 6"
             iwpriv_batt="set_power 7";;
-        iwl*) if [ -f "/sys/class/net/$1/device/power_level" ]; then
+        iwl*) if [ -f "/sys/class/ieee80211/$1/device/power_level" ]; then
                  iwlevel_ac=0
                  iwlevel_batt=3
               else
@@ -53,19 +51,21 @@ get_wireless_params() {
 }

 wireless_powersave() {
-    for dev in /sys/class/net/*; do
-        get_wireless_params "${dev##*/}" "$1" || continue
+    for phy in /sys/class/ieee80211/*; do
+        get_wireless_params "${phy##*/}" "$1" || continue
        ret=0
-       printf "Turning powersave for %s %s..." "${dev##*/}" "$1"
-       if [ "$have_iwconfig" = true -a "$iwconfig" ]; then
-           iwconfig "${dev##*/}" $iwconfig || ret=1
-       fi
-        if [ "$have_iwpriv" = true -a "$iwpriv" ]; then
-           iwpriv "${dev##*/}" $iwpriv || ret=1
-       fi
+        for dev in $phy/device/net/*; do
+            printf "Turning powersave for %s %s..." "${dev##*/}" "$1"
+            if [ "$have_iwconfig" = true -a "$iwconfig" ]; then
+                iwconfig "${dev##*/}" $iwconfig || ret=1
+            fi
+            if [ "$have_iwpriv" = true -a "$iwpriv" ]; then
+                iwpriv "${dev##*/}" $iwpriv || ret=1
+            fi
+        done
         if [ "$iwlevel" ]; then
-           echo "$iwlevel" > "$dev/device/power_level" || ret=1
-       fi
+            echo "$iwlevel" > "$phy/device/power_level" || ret=1
+        fi
        [ "$ret" -eq 0 ] && echo Done. || echo Failed.
     done
 }
@@ -76,4 +76,4 @@ case $1 in
     *) exit $NA ;;
 esac

Debian Release: wheezy/sid
  500 unstable        www.debian-multimedia.org
  500 unstable        ftp.de.debian.org
  500 testing         ftp.de.debian.org
  100 experimental-snapshots qt-kde.debian.net
    1 experimental    ftp.de.debian.org
--- Package information. ---
Depends             (Version) | Installed
=============================-+-===========
powermgmt-base                | 1.31
kbd                           |
 OR console-tools             | 1:0.2.3dbs-70


Recommends      (Version) | Installed
=========================-+-===========
vbetool                   | 1.1-2
procps                    | 1:3.2.8-10
hdparm                    | 9.32-1


Suggests            (Version) | Installed
=============================-+-===========
cpufrequtils                  | 007-1
wireless-tools                | 30~pre9-5
ethtool                       | 1:2.6.37-1
radeontool                    |

#618878#10
Date:
2011-09-23 11:09:20 UTC
From:
To:
--- Please enter the report below this line. ---
an iwlagn (Intel Corporation Centrino Advanced-N 6230) device, I can't
find any /sys/class/ieee80211/$1/device/power_level file:

root@laptop:~# LANG=C ls -l
/sys/class/ieee80211/phy0/device/power_level

ls: cannot access /sys/class/ieee80211/phy0/device/power_level: No such
file or directory

BTW, physical device files can be accessed through the phy80211 symlink
present in the /sys/class/net/wlan0/ directory:

root@laptop:~# LANG=C ls -l /sys/class/net/wlan0/phy*
lrwxrwxrwx 1 root root 0 Sep 23 09:07 /sys/class/net/wlan0/phy80211 ->
../../ieee80211/phy0

The presence of such symlink can be used to determine whether the
interface is wireless or not; currently it seems that power saving
features can only be enabled with the iwconfig method (though "iw dev
wlan0 set power_save on" does also work).

This is what I applied to get it working:

======================== BEGIN DIFF ========================
--- wireless.orig       2011-04-12 13:27:38.000000000 +0200
+++ wireless    2011-09-20 21:53:38.425880522 +0200
@@ -18,7 +18,7 @@
     # Don't do anything if we cannot find a driver for this iface.
     [ -L "/sys/class/net/$1/device/driver" ] || return 1
     # Skip if not a wireless card.
-    [ -d "/sys/class/net/$1/wireless" ] || return 1
+    [ -d "/sys/class/net/$1/phy80211" ] || return 1
     # Also don't do anything if the device is disabled
     [ "$(cat /sys/class/net/$1/device/enable)" = "1" ] || return 1
     driver="$(readlink "/sys/class/net/$1/device/driver")"
@@ -76,4 +76,4 @@
     *) exit $NA ;;
 esac

Debian Release: wheezy/sid
990 testing-proposed-updates ftp.de.debian.org
990 testing security.debian.org
990 testing ftp.de.debian.org
500 unstable www.debian-multimedia.org
500 unstable ftp.de.debian.org
500 testing www.debian-multimedia.org
500 stable security.debian.org
500 stable ftp.de.debian.org
--- Package information. ---
Depends (Version) | Installed
=============================-+-===========
powermgmt-base | 1.31


Recommends (Version) | Installed
============================-+-===========
vbetool | 1.1-2
procps | 1:3.2.8-11
hdparm | 9.32-1
kbd |
OR console-tools | 1:0.2.3dbs-70


Suggests (Version) | Installed
=============================-+-===========
cpufrequtils | 007-2
wireless-tools | 30~pre9-5
ethtool | 1:3.0-1
radeontool |

#618878#15
Date:
2012-02-05 05:49:02 UTC
From:
To:
APT has just upgraded my pm-utils package without this bug getting
fixed, and I've had to patch power.d/wireless again.

So I'm just confirming that I can reproduce this issue, that Mau's patch
fixes it for me, and that I'd like to see it included in the next
version of the package.

#618878#20
Date:
2012-11-17 23:24:33 UTC
From:
To:
I am getting this issue on my new Acer laptop. The configuration is as
follows:

 * Linux 3.6 (linux-image-3.6-trunk-amd64) which is needed for the
   HD4000 graphics card
 * pm-utils 1.4.1-9
 * An Atheros wireless card running with the atk9k driver
   03:00.0 Network controller: Atheros Communications Inc. AR9462 Wireless Network Adapter (rev 01)

And like for the original reporter, there is no 'wireless' directory in
wlan0:

$ ls -l /sys/class/net/wlan0
lrwxrwxrwx 1 root root 0 Nov 16 01:55 /sys/class/net/wlan0 -> ../../devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlan0

$ ls -l /sys/class/net/wlan0/
-r--r--r-- 1 root root 4096 Nov 17 21:01 addr_assign_type
-r--r--r-- 1 root root 4096 Nov 16 01:55 addr_len
-r--r--r-- 1 root root 4096 Nov 16 01:55 address
-r--r--r-- 1 root root 4096 Nov 17 21:01 broadcast
-r--r--r-- 1 root root 4096 Nov 17 21:01 carrier
-r--r--r-- 1 root root 4096 Nov 17 21:01 dev_id
lrwxrwxrwx 1 root root    0 Nov 16 01:55 device -> ../../../0000:03:00.0
-r--r--r-- 1 root root 4096 Nov 17 21:01 dormant
-r--r--r-- 1 root root 4096 Nov 17 21:01 duplex
-rw-r--r-- 1 root root 4096 Nov 17 21:01 flags
-rw-r--r-- 1 root root 4096 Nov 17 21:01 ifalias
-r--r--r-- 1 root root 4096 Nov 16 01:55 ifindex
-r--r--r-- 1 root root 4096 Nov 17 21:01 iflink
-r--r--r-- 1 root root 4096 Nov 17 21:01 link_mode
-rw-r--r-- 1 root root 4096 Nov 17 21:01 mtu
-rw-r--r-- 1 root root 4096 Nov 17 21:01 netdev_group
-r--r--r-- 1 root root 4096 Nov 17 21:01 operstate
lrwxrwxrwx 1 root root    0 Nov 16 01:55 phy80211 -> ../../ieee80211/phy0
drwxr-xr-x 2 root root    0 Nov 17 21:01 power
drwxr-xr-x 7 root root    0 Nov 17 21:01 queues
-r--r--r-- 1 root root 4096 Nov 17 21:01 speed
drwxr-xr-x 2 root root    0 Nov 17 21:01 statistics
lrwxrwxrwx 1 root root    0 Nov 16 01:55 subsystem -> ../../../../../../class/net
-rw-r--r-- 1 root root 4096 Nov 17 21:01 tx_queue_len
-r--r--r-- 1 root root 4096 Nov 16 01:55 type
-rw-r--r-- 1 root root 4096 Nov 16 01:55 uevent


Note that one side-effect of the power-save mode is frequent high
latency when using ssh. So it would be nice to at least avoid that while
on A/C power.

For now I simply removed the 'wireless' directory check from the script.

#618878#25
Date:
2014-11-15 01:57:38 UTC
From:
To:
Please note that the script is still broken (in wheezy) for a very
related reason:
never exists, only does:
See:
https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/1299975
http://anonscm.debian.org/cgit/collab-maint/pm-utils.git/diff/?id=d33ba310

#618878#30
Date:
2023-12-21 17:56:09 UTC
From:
To:
Dear submitter,

as the package pm-utils has just been removed from the Debian archive
unstable we hereby close the associated bug reports.  We are sorry
that we couldn't deal with your issue properly.

For details on the removal, please see https://bugs.debian.org/1058701

The version of this package that was in Debian prior to this removal
can still be found using https://snapshot.debian.org/.

Please note that the changes have been done on the master archive and
will not propagate to any mirrors until the next dinstall run at the
earliest.

This message was generated automatically; if you believe that there is
a problem with it please contact the archive administrators by mailing
ftpmaster@ftp-master.debian.org.

Debian distribution maintenance software
pp.
Thorsten Alteholz (the ftpmaster behind the curtain)