Home Keep Wi-Fi power-management off during SSH/SFTP sessions

Keep Wi-Fi power-management off during SSH/SFTP sessions

Nokia N900 – Maemo
This is a dirty workaround, but no one seems to find a more elegant way.
Put these lines in your /etc/ssh/sshd_config

Code:
Compression no #optional
UseDNS no #optional
ForceCommand /usr/lib/openssh/ssh-session

Create /usr/lib/openssh/ssh-session

Code:
#!/bin/sh
if [ $USER = root ]; then
  IFCONFIG=ifconfig
  MGMT=/usr/lib/openssh/ssh-power-management
else
  IFCONFIG="sudo ifconfig"
  MGMT="sudo /usr/lib/openssh/ssh-power-management"
fi
WLAN_IP=$($IFCONFIG wlan0 | sed -n 's/.*inet addr:([0-9.]+).*/1/p')
SSH_IP=$(echo $SSH_CONNECTION | cut -d ' ' -f 3)
if [ "$WLAN_IP" = "$SSH_IP" ]; then
  ps -f | grep /usr/lib/openssh/ssh-power-management | grep -qv grep
  if [ $? -eq 1 ]; then
    $MGMT &
  fi
fi
if [ -n "$SSH_ORIGINAL_COMMAND" ]; then
  eval $SSH_ORIGINAL_COMMAND
else
  $SHELL
fi

Create /usr/lib/openssh/ssh-power-management

Code:
#!/bin/sh
if [ $USER = root ]; then
  IWCONFIG="iwconfig"
else
  IWCONFIG="sudo iwconfig"
fi
while [ $(lsof -a -i4 -a -i :ssh | grep ESTABLISHED | wc -l) -gt 0 ]; do
  $IWCONFIG wlan0 power off
  $IWCONFIG wlan0 txpower 100mW
  sleep 20
done
$IWCONFIG wlan0 power on
$IWCONFIG wlan0 txpower 10mW

You need to have wireless-tools installed (and sudser if you don’t want to add an appropriate entry to /etc/sudoers.d/).
Then run

Code:
sudo chmod +x /usr/lib/openssh/ssh-session
sudo chmod +x /usr/lib/openssh/ssh-power-management
sudo /etc/init.d/ssh restart

Authentication process will remain slow and you’ll notice a small gap after login; then the lags will disappear until you close all active ssh/sftp connections.
The 20 seconds timeout for invoking iwconfig isn’t meant to be precise, test and report your measures.
—————————
If you use ssh server only at home, you may also want to do this:
Create /etc/network/if-up.d/ssh (replace YOUR_AP_ESSID with the name of your access point)

Code:
#!/bin/sh
if [ "$ICD_CONNECTION_TYPE" = "WLAN_INFRA" ] ; then
        KEY="/system/osso/connectivity/IAP/$ICD_CONNECTION_ID/name"
        AP=$(/usr/bin/gconftool -g "$KEY")
        if [ "$AP" = "YOUR_AP_ESSID" ] ; then
                /etc/init.d/ssh start
        fi
fi
exit 0

and /etc/network/if-down.d/ssh

Code:
#!/bin/sh
/etc/init.d/ssh stop
exit 0

Comment out the corresponding lines in /etc/event.d/sshd

Code:
#start on stopped rcS
console output
#respawn
pre-start script
    if [ ! -d /var/run/sshd ] ; then
        mkdir /var/run/sshd
        chmod 755 /var/run/sshd
    fi
end script
exec /usr/sbin/sshd -D

Then run

Code:
sudo chmod +x /etc/network/if-*.d/ssh
sudo update-rc.d -f ssh remove

 
Source Maemo.Org

About ReadWrite’s Editorial Process

The ReadWrite Editorial policy involves closely monitoring the gambling and blockchain industries for major developments, new product and brand launches, game releases and other newsworthy events. Editors assign relevant stories to in-house staff writers with expertise in each particular topic area. Before publication, articles go through a rigorous round of editing for accuracy, clarity, and to ensure adherence to ReadWrite's style guidelines.

Get the biggest iGaming headlines of the day delivered to your inbox

    By signing up, you agree to our Terms and Privacy Policy. Unsubscribe anytime.

    Gambling News

    Explore the latest in online gambling with our curated updates. We cut through the noise to deliver concise, relevant insights, keeping you informed about the ever-changing world of iGaming and its most important trends.

    In-Depth Strategy Guides

    Elevate your game with tailored strategies for sports betting, table games, slots, and poker. Learn how to maximize bonuses, refine your tactics, and boost your chances to beat the house.

    Unbiased Expert Reviews

    Honest and transparent reviews of sportsbooks, casinos and poker rooms crafted through industry expertise and in-depth analysis. Delve into intricacies, get the best bonus deals, and stay ahead with our trustworthy guides.