none
Desktop computer bluetooth low energy developement without bluetooth hardware RRS feed

  • Question

  • Hi,

    I am new for WDK bluetooth.

    I want to implement a bluetooth low energy based application in the desktop PC without bluetooth hardware inside. I want to know which usb bluetooth hardware I should purchase. 

    Is there any code example (c/c++) to show me how to start?

    Best Regards.

    Thursday, November 29, 2018 1:47 AM

Answers

  • Hi bingwang2018,

    You definitely do not need to learn how to write a driver to write a Bluetooth LE client application.

    You've referenced our legacy desktop APIs. We recommend you use our WinRT APIs that are marked with the DualApiPartionAttribute from desktop. The Windows Bluetooth team is currently investing it's efforts in the WinRT APIs under Windows.Devices.Bluetooth and have current UWP based samples for them, you can use them to inform your own desktop application, as the APIs do work there as well. It's how some of our internal tests are written.

    The document Bluetooth GATT Client and the Bluetooth Low Energy Sample are where you can start.

    Thanks,

    Frank


    Thursday, November 29, 2018 5:06 PM
  • Each API member indicates what OS version it needs. This is an example of a Bluetooth one that's been there from the beginning so the first support was on the first version of Windows 10 from July, 2015 for this member.

    https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.genericattributeprofile.gattcharacteristic 

    Device family
    Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
    API contract
    Windows.Foundation.UniversalApiContract (introduced v1)

    Your original post asked about Bluetooth Low Energy, there are no APIs for Window XP, Windows 7 and Windows 8 that support pairing and discovery of Bluetooth Low Energy devices. The APIs you referenced in that post are for classic Bluetooth devices. This questions been answered on the thread below.

    https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/3b62bdbf-9a55-4c0f-becf-f4e91d4bc027/windows-8-bluetooth-le-and?forum=wdk 

    • Marked as answer by bingwang2018 Friday, November 30, 2018 5:37 AM
    Friday, November 30, 2018 2:23 AM

All replies

  • Are you new to Windows drivers? If so, then starting with Bluetooth is not where I'd start; you might want to start with a simple USB device, instead. You can find the sources to the driver samples here on GitHub

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Thursday, November 29, 2018 2:40 AM
    Moderator
  • Yes, I'm new to Windows drivers. Do you mean before I start the bluetooth low energy application I must learn to Windows drivers developement first?

    I'm wondering if a laptop with a bluetooth adapter inside it. Whether can I implement bluetooth-related function by its existing bluetooth drivers? If it is possible, why I can not implement the same function by adding a bluetooth adapter (for example, csr bluetooth adapter, Qualcomm bluetooth adapter, etc.) to a desktop computer.

    Acutaully what I concerned is just the application level for how to use the existing bluetooth APIs to discover bluetooth LE devices, access theirs' gatt services and so on in the laptop or descktop (especially the desktop). And I found there already are a set of bluetooth APIs in the WDK.

    /**
     * This file has no copyright assigned and is placed in the Public Domain.
     * This file is part of the mingw-w64 runtime package.
     * No warranty is given; refer to the file DISCLAIMER.PD within this package.
     */
    #ifndef _INC_BLUETOOTHAPIS
    #define _INC_BLUETOOTHAPIS
    
    #include <_mingw.h>
    #include <bthdef.h>
    #include <bthsdpdef.h>
    
    #define BLUETOOTH_MAX_NAME_SIZE 248
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    typedef LPVOID HBLUETOOTH_DEVICE_FIND;
    typedef LPVOID HBLUETOOTH_RADIO_FIND;
    typedef LPVOID HBLUETOOTH_AUTHENTICATION_REGISTRATION;
    typedef LPVOID HBLUETOOTH_CONTAINER_ELEMENT;
    
    typedef struct _BLUETOOTH_ADDRESS {
      __C89_NAMELESS union {
        BTH_ADDR ullLong;
        BYTE     rgBytes[6];
      };
    } BLUETOOTH_ADDRESS;
    
    typedef struct _BLUETOOTH_COD_PAIRS {
      ULONG   ulCODMask;
      LPCWSTR pcszDescription;
    } BLUETOOTH_COD_PAIRS;
    
    typedef struct _BLUETOOTH_DEVICE_INFO {
      DWORD             dwSize;
      BLUETOOTH_ADDRESS Address;
      ULONG             ulClassofDevice;
      WINBOOL           fConnected;
      WINBOOL           fRemembered;
      WINBOOL           fAuthenticated;
      SYSTEMTIME        stLastSeen;
      SYSTEMTIME        stLastUsed;
      WCHAR             szName[BLUETOOTH_MAX_NAME_SIZE];
    } BLUETOOTH_DEVICE_INFO, *PBLUETOOTH_DEVICE_INFO;
    
    typedef struct _BLUETOOTH_DEVICE_SEARCH_PARAMS {
      DWORD     dwSize;
      WINBOOL   fReturnAuthenticated;
      WINBOOL   fReturnRemembered;
      WINBOOL   fReturnUnknown;
      WINBOOL   fReturnConnected;
      WINBOOL   fIssueInquiry;
      UCHAR     cTimeoutMultiplier;
      HANDLE    hRadio;
    } BLUETOOTH_DEVICE_SEARCH_PARAMS;
    
    typedef struct _BLUETOOTH_FIND_RADIO_PARAMS {
      DWORD dwSize;
    } BLUETOOTH_FIND_RADIO_PARAMS;
    
    typedef struct _BLUETOOTH_RADIO_INFO {
      DWORD             dwSize;
      BLUETOOTH_ADDRESS address;
      WCHAR             szName[BLUETOOTH_MAX_NAME_SIZE];
      ULONG             ulClassofDevice;
      USHORT            lmpSubversion;
      USHORT            manufacturer;
    } BLUETOOTH_RADIO_INFO, *PBLUETOOTH_RADIO_INFO;
    
    typedef enum _BLUETOOTH_AUTHENTICATION_METHOD {
      BLUETOOTH_AUTHENTICATION_METHOD_LEGACY                 = 0x1,
      BLUETOOTH_AUTHENTICATION_METHOD_OOB,
      BLUETOOTH_AUTHENTICATION_METHOD_NUMERIC_COMPARISON,
      BLUETOOTH_AUTHENTICATION_METHOD_PASSKEY_NOTIFICATION,
      BLUETOOTH_AUTHENTICATION_METHOD_PASSKEY
    } BLUETOOTH_AUTHENTICATION_METHOD;
    
    typedef enum _BLUETOOTH_IO_CAPABILITY {
      BLUETOOTH_IO_CAPABILITY_DISPLAYONLY       = 0x00,
      BLUETOOTH_IO_CAPABILITY_DISPLAYYESNO      = 0x01,
      BLUETOOTH_IO_CAPABILITY_KEYBOARDONLY      = 0x02,
      BLUETOOTH_IO_CAPABILITY_NOINPUTNOOUTPUT   = 0x03,
      BLUETOOTH_IO_CAPABILITY_UNDEFINED         = 0xff
    } BLUETOOTH_IO_CAPABILITY;
    
    typedef enum _BLUETOOTH_AUTHENTICATION_REQUIREMENTS {
      MITMProtectionNotRequired                 = 0x00,
      MITMProtectionRequired                    = 0x01,
      MITMProtectionNotRequiredBonding          = 0x02,
      MITMProtectionRequiredBonding             = 0x03,
      MITMProtectionNotRequiredGeneralBonding   = 0x04,
      MITMProtectionRequiredGeneralBonding      = 0x05,
      MITMProtectionNotDefined                  = 0xff
    } BLUETOOTH_AUTHENTICATION_REQUIREMENTS;
    
    typedef struct _BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS {
      BLUETOOTH_DEVICE_INFO                 deviceInfo;
      BLUETOOTH_AUTHENTICATION_METHOD       authenticationMethod;
      BLUETOOTH_IO_CAPABILITY               ioCapability;
      BLUETOOTH_AUTHENTICATION_REQUIREMENTS authenticationRequirements;
      __C89_NAMELESS union {
        ULONG Numeric_Value;
        ULONG Passkey;
      } ;
    } BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS, *PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS;
    
    #define BLUETOOTH_MAX_SERVICE_NAME_SIZE 256
    #define BLUETOOTH_DEVICE_NAME_SIZE 256
    typedef struct _BLUETOOTH_LOCAL_SERVICE_INFO {
      BOOL              Enabled;
      BLUETOOTH_ADDRESS btAddr;
      WCHAR             szName[BLUETOOTH_MAX_SERVICE_NAME_SIZE];
      WCHAR             szDeviceString[BLUETOOTH_DEVICE_NAME_SIZE];
    } BLUETOOTH_LOCAL_SERVICE_INFO;
    
    #define BTH_MAX_PIN_SIZE 16
    typedef struct _BLUETOOTH_PIN_INFO {
      UCHAR pin[BTH_MAX_PIN_SIZE];
      UCHAR pinLength;
    } BLUETOOTH_PIN_INFO, *PBLUETOOTH_PIN_INFO;
    
    typedef struct _BLUETOOTH_OOB_DATA_INFO {
      UCHAR C[16];
      UCHAR R[16];
    } BLUETOOTH_OOB_DATA_INFO, *PBLUETOOTH_OOB_DATA_INFO;
    
    typedef struct _BLUETOOTH_NUMERIC_COMPARISON_INFO {
      ULONG NumericValue;
    } BLUETOOTH_NUMERIC_COMPARISON_INFO, *PBLUETOOTH_NUMERIC_COMPARISON_INFO;
    
    typedef struct _BLUETOOTH_PASSKEY_INFO {
      ULONG passkey;
    } BLUETOOTH_PASSKEY_INFO, *PBLUETOOTH_PASSKEY_INFO;
    
    typedef struct _BLUETOOTH_AUTHENTICATE_RESPONSE {
      BLUETOOTH_ADDRESS               bthAddressRemote;
      BLUETOOTH_AUTHENTICATION_METHOD authMethod;
      __C89_NAMELESS union {
        BLUETOOTH_PIN_INFO                pinInfo;
        BLUETOOTH_OOB_DATA_INFO           oobInfo;
        BLUETOOTH_NUMERIC_COMPARISON_INFO numericCompInfo;
        BLUETOOTH_PASSKEY_INFO            passkeyInfo;
      };
      UCHAR                           negativeResponse;
    } BLUETOOTH_AUTHENTICATE_RESPONSE, *PBLUETOOTH_AUTHENTICATE_RESPONSE;
    
    typedef WINBOOL (*PFN_DEVICE_CALLBACK)(LPVOID pvParam,PBLUETOOTH_DEVICE_INFO pDevice);
    typedef WINBOOL (*CALLBACK PFN_AUTHENTICATION_CALLBACK_EX)(LPVOID pvParam,PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS pAuthCallbackParams);
    typedef WINBOOL (*PFN_AUTHENTICATION_CALLBACK)(LPVOID pvParam,PBLUETOOTH_DEVICE_INFO pDevice);
    typedef WINBOOL (*PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK)(ULONG uAttribId,LPBYTE pValueStream,ULONG cbStreamSize,LPVOID pvParam);
    
    typedef struct _BLUETOOTH_SELECT_DEVICE_PARAMS {
      DWORD                  dwSize;
      ULONG                  cNumOfClasses;
      BLUETOOTH_COD_PAIRS    *prgClassOfDevices;
      LPWSTR                 pszInfo;
      HWND                   hwndParent;
      BOOL                   fForceAuthentication;
      BOOL                   fShowAuthenticated;
      BOOL                   fShowRemembered;
      BOOL                   fShowUnknown;
      BOOL                   fAddNewDeviceWizard;
      BOOL                   fSkipServicesPage;
      PFN_DEVICE_CALLBACK    pfnDeviceCallback;
      LPVOID                 pvParam;
      DWORD                  cNumDevices;
      PBLUETOOTH_DEVICE_INFO pDevices;
    } BLUETOOTH_SELECT_DEVICE_PARAMS;
    
    DWORD WINAPI BluetoothAuthenticateMultipleDevices(
        HWND hwndParent,
        HANDLE hRadio,
        DWORD cDevices,
        BLUETOOTH_DEVICE_INFO *pbtdi
    );
    
    HRESULT WINAPI BluetoothAuthenticateDeviceEx(
      HWND hwndParentIn,
      HANDLE hRadioIn,
      BLUETOOTH_DEVICE_INFO *pbtdiInout,
      PBLUETOOTH_OOB_DATA_INFO pbtOobData,
      BLUETOOTH_AUTHENTICATION_REQUIREMENTS authenticationRequirement
    );
    
    WINBOOL WINAPI BluetoothDisplayDeviceProperties(
        HWND hwndParent,
        BLUETOOTH_DEVICE_INFO *pbtdi
    );
    
    WINBOOL WINAPI BluetoothEnableDiscovery(
        HANDLE hRadio,
        WINBOOL fEnabled
    );
    
    WINBOOL WINAPI BluetoothEnableIncomingConnections(
        HANDLE hRadio,
        WINBOOL fEnabled
    );
    
    DWORD WINAPI BluetoothEnumerateInstalledServices(
        HANDLE hRadio,
        BLUETOOTH_DEVICE_INFO *pbtdi,
        DWORD *pcServices,
        GUID *pGuidServices
    );
    
    WINBOOL WINAPI BluetoothFindDeviceClose(
        HBLUETOOTH_DEVICE_FIND hFind
    );
    
    HBLUETOOTH_DEVICE_FIND WINAPI BluetoothFindFirstDevice(
        BLUETOOTH_DEVICE_SEARCH_PARAMS *pbtsp,
        BLUETOOTH_DEVICE_INFO *pbtdi
    );
    
    HBLUETOOTH_RADIO_FIND WINAPI BluetoothFindFirstRadio(
      BLUETOOTH_FIND_RADIO_PARAMS *pbtfrp,
      HANDLE *phRadio
    );
    
    WINBOOL WINAPI BluetoothFindNextDevice(
        HBLUETOOTH_DEVICE_FIND hFind,
        BLUETOOTH_DEVICE_INFO *pbtdi
    );
    
    WINBOOL WINAPI BluetoothFindNextRadio(
      HBLUETOOTH_RADIO_FIND hFind,
      HANDLE *phRadio
    );
    
    WINBOOL WINAPI BluetoothFindRadioClose(
        HBLUETOOTH_RADIO_FIND hFind
    );
    
    DWORD WINAPI BluetoothGetDeviceInfo(
        HANDLE hRadio,
        BLUETOOTH_DEVICE_INFO *pbtdi
    );
    
    DWORD WINAPI BluetoothGetRadioInfo(
        HANDLE hRadio,
        PBLUETOOTH_RADIO_INFO pRadioInfo
    );
    
    WINBOOL WINAPI BluetoothIsDiscoverable(
        HANDLE hRadio
    );
    
    WINBOOL WINAPI BluetoothIsConnectable(
        HANDLE hRadio
    );
    
    DWORD WINAPI BluetoothRegisterForAuthentication(
        BLUETOOTH_DEVICE_INFO *pbtdi,
        HBLUETOOTH_AUTHENTICATION_REGISTRATION *phRegHandle,
        PFN_AUTHENTICATION_CALLBACK pfnCallback,
        PVOID pvParam
    );
    
    HRESULT WINAPI BluetoothRegisterForAuthenticationEx(
      const BLUETOOTH_DEVICE_INFO *pbtdiln,
      HBLUETOOTH_AUTHENTICATION_REGISTRATION *phRegHandleOut,
      PFN_AUTHENTICATION_CALLBACK_EX pfnCallbackIn,
      PVOID pvParam
    );
    
    DWORD WINAPI BluetoothRemoveDevice(
        BLUETOOTH_ADDRESS *pAddress
    );
    
    WINBOOL WINAPI BluetoothSdpEnumAttributes(
        LPBYTE pSDPStream,
        ULONG cbStreamSize,
        PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK pfnCallback,
        LPVOID pvParam
    );
    
    DWORD WINAPI BluetoothSdpGetAttributeValue(
      LPBYTE pRecordStream,
      ULONG cbRecordLength,
      USHORT usAttributeId,
      PSDP_ELEMENT_DATA pAttributeData
    );
    
    DWORD WINAPI BluetoothSdpGetContainerElementData(
      LPBYTE pContainerStream,
      ULONG cbContainerLength,
      HBLUETOOTH_CONTAINER_ELEMENT *pElement,
      PSDP_ELEMENT_DATA pData
    );
    
    DWORD BluetoothSdpGetElementData(
      LPBYTE pSdpStream,
      ULONG cbSpdStreamLength,
      PSDP_ELEMENT_DATA pData
    );
    
    DWORD BluetoothSdpGetString(
      LPBYTE pRecordStream,
      ULONG cbRecordLength,
      PSDP_STRING_TYPE_DATA pStringData,
      USHORT usStringOffset,
      PWCHAR pszString,
      PULONG pcchStringLength
    );
    
    WINBOOL WINAPI BluetoothSelectDevices(
        BLUETOOTH_SELECT_DEVICE_PARAMS *pbtsdp
    );
    
    WINBOOL WINAPI BluetoothSelectDevicesFree(
        BLUETOOTH_SELECT_DEVICE_PARAMS *pbtsdp
    );
    
    DWORD WINAPI BluetoothSendAuthenticationResponse(
        HANDLE hRadio,
        BLUETOOTH_DEVICE_INFO *pbtdi,
        LPWSTR pszPasskey
    );
    
    HRESULT WINAPI BluetoothSendAuthenticationResponseEx(
      HANDLE hRadioIn,
      PBLUETOOTH_AUTHENTICATE_RESPONSE pauthResponse
    );
    
    DWORD WINAPI BluetoothSetLocalServiceInfo(
      HANDLE hRadioIn,
      const GUID *pClassGuid,
      ULONG ulInstance,
      const BLUETOOTH_LOCAL_SERVICE_INFO *pServiceInfoIn
    );
    
    DWORD WINAPI BluetoothSetServiceState(
        HANDLE hRadio,
        BLUETOOTH_DEVICE_INFO *pbtdi,
        GUID *pGuidService,
        DWORD dwServiceFlags
    );
    
    WINBOOL WINAPI BluetoothUnregisterAuthentication(
        HBLUETOOTH_AUTHENTICATION_REGISTRATION hRegHandle
    );
    
    DWORD WINAPI BluetoothUpdateDeviceRecord(
        BLUETOOTH_DEVICE_INFO *pbtdi
    );
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif /*_INC_BLUETOOTHAPIS*/


    So do you have any suggestions for me.

    Thanks a lot.

    Thursday, November 29, 2018 6:32 AM
  • Hi bingwang2018,

    You definitely do not need to learn how to write a driver to write a Bluetooth LE client application.

    You've referenced our legacy desktop APIs. We recommend you use our WinRT APIs that are marked with the DualApiPartionAttribute from desktop. The Windows Bluetooth team is currently investing it's efforts in the WinRT APIs under Windows.Devices.Bluetooth and have current UWP based samples for them, you can use them to inform your own desktop application, as the APIs do work there as well. It's how some of our internal tests are written.

    The document Bluetooth GATT Client and the Bluetooth Low Energy Sample are where you can start.

    Thanks,

    Frank


    Thursday, November 29, 2018 5:06 PM
  • Thanks Frank.

    Can the WinRT APIs for bluetooth LE work on XP/Win7/Win8 machines? And in order to use those APIs, must I use the Windows 10 to be the development environment?

    And I found the examples code on the link Bluetooth Low Energy Sammple are written by C#. Can those APIs be used by C/C++?

    Thanks and Best Regards.


    Friday, November 30, 2018 2:10 AM
  • Each API member indicates what OS version it needs. This is an example of a Bluetooth one that's been there from the beginning so the first support was on the first version of Windows 10 from July, 2015 for this member.

    https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.genericattributeprofile.gattcharacteristic 

    Device family
    Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
    API contract
    Windows.Foundation.UniversalApiContract (introduced v1)

    Your original post asked about Bluetooth Low Energy, there are no APIs for Window XP, Windows 7 and Windows 8 that support pairing and discovery of Bluetooth Low Energy devices. The APIs you referenced in that post are for classic Bluetooth devices. This questions been answered on the thread below.

    https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/3b62bdbf-9a55-4c0f-becf-f4e91d4bc027/windows-8-bluetooth-le-and?forum=wdk 

    • Marked as answer by bingwang2018 Friday, November 30, 2018 5:37 AM
    Friday, November 30, 2018 2:23 AM