Bluetooth stacks on Windows Mobile

When you need to Access to the Bluetooth hardware on Windows Mobile, You should have into account your device’s implementation so You can read the information propertly. There are at least two Bluetooth stacks (implementations) types on Windows Mobil from Microsoft and BroadComm.

Both implementations are the same for the end user, but at low level they use different application interfaces. The Microsoft’s Bluetooth stack has a Win32 API which main function is BthGetHardwareStatus. As I always comment on demos or presentations, the Windows Mobile documentation depends on the underlying Windows CE version, in this case that method belongs to Windows CE .NET 4.2.

To use statically the Microsoft’s Bluetooth implementation you must to include the header Bt_api.h and its dependencies: Btdrt.lib y btdrtstubs.lib, as shown on Picture 1.

 

Picture 1. Additional dependencies.

By other hand, the Broadcomm’s Bluetooth stack SDK can be downloaded from here. You need to include the header BtSdkCE.h from that SDK and add a reference to its dependency: BtSdkCE30.lib. The method to start using this implementation is IsDeviceReady().

Now, let’s jump into code. First, activate the Bluetooth functionality in your device (Smartphone or Pocket PC) to be able to access the Microsoft or Broadcomm hardware, in this sample activation is shown on Picture 2. If you don’t activate the hardware, the code provided won’t read the hardware information.

 

Picture 2. Bluetooth activation.

After activating Bluetooth, start a new Smart Device C++ project  and copy /paste the following code:

/*

      Author: Javier Andrés Cáceres Alvis

      2009

      This code is for academic purposes only.

.

*/

#include "stdafx.h"

#include <windows.h>

#include <commctrl.h>

#include <Bt_api.h>

#define MIN_HW_VALUE 32

void ParseManufacturer(unsigned short usManufacturer, TCHAR *pszValue)

{

      switch(usManufacturer)

      {

            /*

            ... Many others

            */

            case 13:

                  wcscpy(pszValue,TEXT("TexasInstruments"));

                  break;                 

            default:

                  wcscpy(pszValue,TEXT("Unknown"));

      }                      

}

int _tmain(int argc, _TCHAR* argv[])

{

      int errorCode=0;

      int btStatus=0;

      errorCode=BthGetHardwareStatus(&btStatus);

      if(errorCode==ERROR_SUCCESS)

      {

            if(btStatus!=HCI_HARDWARE_NOT_PRESENT && btStatus!=HCI_HARDWARE_UNKNOWN)

            {

                  HRESULT     retValue=E_FAIL;            

                  unsigned char phci_version;

                  unsigned short phci_revision;

                  unsigned char plmp_version;

                  unsigned short plmp_subversion;

                  unsigned short pmanufacturer;

                  unsigned char plmp_features;

                        if(BthReadLocalVersion(&phci_version,&phci_revision,&plmp_version,

                                                       &plmp_subversion,&pmanufacturer,&plmp_features)==ERROR_SUCCESS)

                        {

                             TCHAR pszManufacturer[MIN_HW_VALUE];

                             ParseManufacturer(pmanufacturer,pszManufacturer);

                             wsprintf(TEXT("The manufacturer is: %s"),pszManufacturer);

                        }

            }

      }

      return 0;

}

The above code is simple, it uses the Microsoft stack and only accesses to Texas Instruments hardware. But, what about this code running on BroadComm devices? Well, it won’t break, but it won’t be able to read device information using the method BthReadLocalVersion. In this exercise I used to HP devices with different stacks: a HP iPAQ h4150 and a HP iPAQ Voice Messenger (Picture 3), with Broadcomm and Microsoft implementations, correspondingly.

 

Picture 3. Broadcomm and Microsoft stacks.

Finally, the next code works for Broadcomm’s stack implementations:

                        if(!bRetValue)

                        {

                             CBtIf broadInfo;

                             if(broadInfo.IsDeviceReady())

                             {

                                   DEV_VER_INFO dvInfo=(DEV_VER_INFO) sizeof(DEV_VER_INFO);

                                   GetLocalDeviceVersionInfo(&dvInfo);

                                   if(broadInfo.IsDeviceConnectable())

                                   {

                                         if(broadInfo.IsDeviceDiscoverable())

                                         {

                                         }

                                   }

                             }

                        }

Well, this is the end for now, I hope it saves you time.

Greetings,

Javier Andrés Cáceres Alvis

http://speechflow.spaces.live.com/
/en-us/blogs/author/javierandrescaceres/
Pour de plus amples informations sur les optimisations de compilation, consultez notre Avertissement concernant les optimisations.
Catégories: