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 tech industry for major developments, new product launches, AI breakthroughs, video game releases and other newsworthy events. Editors assign relevant stories to staff writers or freelance contributors 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 tech headlines of the day delivered to your inbox

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

    Tech News

    Explore the latest in tech with our Tech News. We cut through the noise for concise, relevant updates, keeping you informed about the rapidly evolving tech landscape with curated content that separates signal from noise.

    In-Depth Tech Stories

    Explore tech impact in In-Depth Stories. Narrative data journalism offers comprehensive analyses, revealing stories behind data. Understand industry trends for a deeper perspective on tech's intricate relationships with society.

    Expert Reviews

    Empower decisions with Expert Reviews, merging industry expertise and insightful analysis. Delve into tech intricacies, get the best deals, and stay ahead with our trustworthy guide to navigating the ever-changing tech market.