[MDA III, XDA III, PDA2k, 9090 Software Upgrading] bigmike:
Fix details

As promised, I will describe the problem with Bluetooth and how I resolved it.

My original idea was to be very detailed, but I changed my mind because not everyone is interested in all the particulars. If you’re interested in specifics you’re welcome to PM me.

First of all, a short description of the problem: anyone who has installed any WM05 version will have noticed that after a while, when the device is in suspend mode (display completely off, no programs are running), the Bluetooth stack (BT from this point on) turns off. Someone pointed out that it turns off when the device switches from the on to the suspend mode. After some tests I realized that this occurs when the device resumes from suspend mode.

There is a strange behavior: the blue led stop blinking, the headset becomes disconnected and the red bar indicating that the BT is off wasn’t displayed on the BT icon in the tray.

I figured out why this happens. Two registry keys control BT:

HKCU\Software\Microsoft\Bluetooth\Settings\ScanMode : 0 = Off - 5 = On - 7 = On + Discoverable

and

HKLM\System\State\Hardware\Bluetooth : 0 = Off - 1 = On

The first is directly controlled by BTIcon.exe and is responsible for the red bar over the BT icon, the second is controlled by the ossvcs.dll, which is a library that controls most of the hardware and is probably developed by HTC with reference to specific hardware. When the BT is turned off by an event (I'll explain later which), the ossvcs.dll consequently changes the associated registry entry. The BT icon remains unaltered because only by tapping on the BT icon and changing the checkboxes on the control panel does the ScanMode value vary. If my memory doesn't fail me, the blue led is not controlled by any registry entries.

After (extenuating) research, I found out how BT is notified to go down. The btd.dll contains a receive thread (receives all incoming data from BT). When the BT driver reports a reception error, the thread shuts itself and the BT stack down. Digging deeper into the driver (the bthuart.dll) I figured out when dll sends back an error. Received data is structured in packets (there exists various types of packets), but when an invalid packet is received, the driver returns an error. Generally no invalid packets are received but when the device “wakes up” an invalid packet is received. This is true either when the phone turns on by itself or when you press the power button. I believe this is caused by poor hardware design, but this is only an unconfirmed idea...

At this point the solution is “easy”: discard all invalid packets and the BT stack will stay on.

After this explanation, it seems like an easy problem to uncover and resolve but believe me; I worked hard every night for a month (maybe more) to find the cause of the BT behavior!

A finale note: when the BT stack is on, the device turns itself on at random, many times a day. This is not related to the “fix”: the same occurs without the patched dll except that in that case after the first resume the BT is turned off, so the device doesn't resume anymore.

I have no idea why this happens... maybe I'll search for the cause in the future...

I hope someone will find this info useful or at least interesting.

Enjoy the new, permanently on, bluetooth stack.

BigMike