[Desire Android Development] Myshkinbob:
Edit 31/07/2011

Updated diff files for gingerbread kernels (HTC and AOSP), and a module for the more recent HTC kernel (2.6.35.10-g308ba26) can be found later in the thread Here.

The current issue...

Note: This isn't related to the sleep mode wifi disconnections caused by MAC addresses that don't begin 00, so far as i'm aware that's been patched for a while now. Wifi remains connected fine in standby mode, but the throughput is only suitable for very light traffic.

Since compiling the cifs module for the HTC official 2.2 kernel on monday i hit a pretty massive problem when listening to music over wifi from a network share - when the screen enters standby, bandwidth drops massively, well below 100kbps. This makes music you're playing from a cifs share over wifi stutter and cut out and basically become pointless.

A little googling and searching these forums i came to find this has been a fairly massive bugbear of the nexus one and htc desire? Any kind of normal bandwidth streaming over wifi is practically useless once that screen goes into standby. Ditto for high speed transfer of large files.

That means difficult VOIP calls, and no internet radio at a decent bitrate, or cifs access to your music library.

Finding a solution...

As luck would have it, the HTC Incredible 2.6.32.15 source code was released on tuesday, and as it's basically the non-GSM variant of the Desire, i was fairly certain the HTC customised bcm4329 source code was the same as the Desire's, and it seems like it is. So armed with HTC's customised bcm4329 module sourcecode and the output of dmesg when the phone was in various states, i had a poke around.

First of all i tried editing the DTIM update interval, so the phone would wait fewer beacons to collect incoming packets while the wifi was in sleep mode, and this improved the situation, barely. In the end i just locked out the phone's deepest wifi sleep mode, PM_MAX, in favour of PM_FAST, the low power mode for wifi used when the screen is active but the phone is relying on the battery alone (There is a third mode, PM_OFF, used when the phone is powered by a usb connection, but as the name implies, all power management is disabled by it, so forget that one).

PM_MAX appears to have a very fixed latency depending upon the DTIM update interval (300ms with DTIM as the default 3), and severely limited bandwidth. PM_FAST appears to be a listen mode or active rx mode, with latency scaling to the bandwidth used. An initial ping at idle will be up to 1000ms (or even no reply) before steadying at 100-300ms. During light streaming it's more of a steady 50-70ms, and during a file transfer it's a very low 5ms. So it looks like PM_FAST keeps the wifi receiver powered up to some extent, and only powers up the transmitter when needed.

You can guess the edit i've made: Essentially my new kernel module tells the phone to keep wifi in low power mode when the screen is switched off, rather than in a full sleep mode.

Just give me the damn kernel module...

Downloads are attached to the bottom of this post.

Files are unsigned, and install with clockworkmod recovery's 'Install zip from sd card' option.

Your wifi driver must match your phone's kernel version. To check your kernel version go to Settings - About Phone - Software Information and look at Kernel version.

Files including _N_ in the name have wifi mode N support for HTC kernels (non HTC kernel versions should include mode N by default).

If you don't see a version of the module that matches your kernel version, post a request in this thread.

The results..

Well obviously now the wifi bandwidth when the screen sleeps is the same as when the screen is active, so streaming data during sleep mode is perfect, wonderful even! However, i was a little concerned with the effect on battery usage when the connection is alive but fully or partially idle.

So i just did some practical testing. Note i'm connected using 802.11g, my router doesn't support mode n, and my signal is a less than ideal -80dBm so i'm probably using a little extra power.

With the original HTC wifi module, my phone lost about 1% charge an hour with wifi permanently enabled, push gmail enabled, and sync for weather and contacts every 15 minutes.

With the new wifi module, and the same conditions (wifi always on, gmail push, sync 15 mins), i lose around 1% an hour still. Excellent, no difference. :)

60 minutes of 200kbit VBR mp3 playback through the speaker with the screen off used about 8% of my battery.

60 minutes of 800kbit FLAC playback through the speaker with the screen off used up 10% of my battery.

volume was set at roughly 75% for both tests.

I didn't do any testing with the earphones, but i suspect they'd be marginally lower on the power usage.

To conclude, from my brief testing this afternoon i couldn't discern a difference in battery usage when the wifi connection is left on but mostly idle, and when data is streaming it doesn't eat the entire battery charge in minutes.

Note to ROM authors

Any rom authors using 2.6.32.15 who would like to include this module in their rom, you're quite welcome to. You don't need to credit me either, although it would be nice. :)