Sunday, June 27, 2010

Workaround for Stuck Beacon Problem

Stuck beacon is a notorious problem on madwifi (the wireless driver DD-WRT used for Atheros routers).  If you never experienced any wireless interruptions with DD-WRT then just ignore this article. However, if you're annoyed by this stuck beacon problem with constantly dropping wireless connection, then I hope this can be of help.

I personally prefer the open source ath9k driver which doesn't suffer from this, but some important feature like WDS is missing from ath9k. So to each its own, DD-WRT has the perfect reason to stick with madwifi and I don't expect the switch to ath9k anytime soon. And, seems that the problem only happens under certain circumstance. In my case, the connection drops with an Atheros wireless N card -- same card works great with stock firmware -- but works fine with another Intel WiFI 1000 11N card. So if a stable wireless connection is very important, the best solution might be flashing back to stock firmware or just try another card.

Below is a quick hack, not a completely fix but would make life a little easier. The idea is to watch the output of dmesg and when the "stuck beacon" error messages flood, reset the wireless interface to bring it back to life.

  1. The watchdog script
    When wireless connection is dropeed, a typical out from dmesg would like this

    ath_bstuck_tasklet : Entering
    Resetting; Code: 01
    ath_bstuck_tasklet : Entering
    Resetting; Code: 01
    ath_bstuck_tasklet : Entering
    Resetting; Code: 01
    ath_bstuck_tasklet : Entering
    Resetting; Code: 01
    ath_bstuck_tasklet : Entering
    Resetting; Code: 01
    ath_bstuck_tasklet : Entering
    Resetting; Code: 01

    the same error message will keep repeating and flood the kernel log. So we can use this as a trigger and reset wireless interface when the error occurs.

    Below is the /opt/usr/local/bin/wifi-watchdog.sh script

    #!/bin/sh

    dmesg | tail -n 5 | grep -q ath_bstuck_tasklet || exit

    echo fixing...
    #a log file
    echo `date` >> /tmp/wifi-wathdog.log

    ifconfig ath0 down
    #for VAP, bring additional interface(s) down
    #ifconfig ath0.1 down
    sleep 2
    ifconfig ath0 up
    #bring it back
    #ifconfig ath0.1 up

    Set permissions
    chmod a+x /opt/usr/local/bin/wifi-watchdog.sh

  2. Set cron job
    With the watchdog script ready, we can use cron to set it run every one minute.
    Add a new job:

    * * * * * /opt/usr/local/bin/wifi-watchdog.sh

    and it's done. Again, its not a completely fix just save the trouble of resetting the router each time.

10 comments:

unknowngunman said...

i'll be trying this when i get home. otherwise, i hate to admit, i'll be going back to the stock firmware...

Anonymous said...

Im on the dd-wrt firmware that came with the router and getting network not in range. I need to reboot to get it to work again. I hope this helps because it sucks having to reboot every time.

Anonymous said...

Great post!
I am wondering if the 'Stuck Beacon' problem still exist till date (late Feb 2011) or this has already been fixed... I hope so :)
I am considering to purchase WZR-HP-G300NH to run dd-wrt but I can't afford disconnection.
Any ideas?

On the other note, let me ask you, did you get a change to install tonido-app (http://www.tonido.com/application_download.html) on WZR-HP-G300NH.
Any insight if this is possible or not?
I don't want to get the plug device.

Mike said...

I'm still having issues, using their latest (alpha release, only after previous release suffered from same problem):

DD-WRT v24SP2-MULTI (04/12/11) std - build 16783

Anonymous said...

Just found i'm having this problem with the wndr3700 v2

Anonymous said...

FWIW, have same problem with my new WNDR3700v2.
Firmware: DD-WRT v24-sp2 (06/14/11) std

Running the watchdog for now to see if I can find a culprit among my clients. Worst case it will be back to stock firmware.

Anonymous said...

I'm the same poster as above.
I went back to the stock firmware but just couldn't live with its limitations. So I went back to DD-WRT with watchdog. Amazingly, it's now been running for 6 days already without any drop. The watchdog logfile is still empty.
AFAIK the only thing that is different from previous attempt, is that I'm now using channel 2 instead of channel 1.

Anonymous said...

Same problem as September 19th., 2011 commenter. Same version and firmware.

Kuma said...

Still same beacon problem on my Netgear WNDR3700v1 having wrt build 17201. For now using custom channels 2 (due to neighbors with monster routers), mixed network model and... an usb printer and an usb hard drive.

It is usually under heavy load on the wireless from random computers. No solution yet, sorry.

Anonymous said...

is there a way to add this job via the web interface? Thank you

Post a Comment