Vista + Windows 7


The Microsoft Bluetooth stack on Windows Vista added support for programming L2CAP and SCO connections.  Also added are a set of IOCTL codes for accessing the stack in various other ways.  Fifteen the codes are listed at http://msdn.microsoft.com/en-us/library/ff536601.aspx “Bluetooth Profile Driver I/O Function Codes” and are all supported from Vista onwards.  One more is defined at http://msdn.microsoft.com/en-us/library/ff536593.aspx “Bluetooth Vendor Commands and Events”, and is supported by “Microsoft Windows Vista SP2 and later operating system versions”

I have previously used the IOCTL_BTH_GET_LOCAL_INFO code for bug 30326 “Windows 7 BluetoothRadio HCI and LMP version numbers” which allows us to get the attached controllers HCI and LMP version numbers.

However when one looks at the Windows SDK header file (bthioctl.h) that defines these codes, we find more listed than are documented at MSDN.  The 15 above are as expected are defined for Vista (no service-pack) and later, these include IOCTL_BTH_GET_LOCAL_INFO, IOCTL_BTH_GET_DEVICE_INFO, IOCTL_BTH_SDP_CONNECT, also present are the ones for the L2CAP and SCO interfaces (e.g. IOCTL_INTERNAL_BTH_SUBMIT_BRB).  We then see the single code (IOCTL_BTH_HCI_VENDOR_COMMAND) which is included on Windows 7, and on Windows Vista with Service Pack 2 or with the Windows Vista Feature Pack for Wireless (KB942567).

Finally we see five that are defined there but not enabled in any current platform, these include IOCTL_BTH_EIR_GET_RECORDS and IOCTL_BTH_EIR_SUBMIT_RECORD.  These are disabled with the comment (sic):

#ifdef FULL_EIR_SUPPORT // in WUR this funcitonality is disabled

I’ve done some investigation to find out which codes are truly supported on which platforms.  I tested all user-level codes from 0 to 255 (i.e. 0x410300 to 0x4103FC).  On XP, as expected, all codes fail and return error 50 which is ERROR_NOT_SUPPORTED.  On Windows 7 again –we find the support matches the documentation.  All the ones disabled with that comment return that same error code, with only the sixteen documented working (all the others fail).

I guess this is not too surprising but i would have been nice to find that these extra features were present. :-,)

So to confirm on Windows 7 the supported user-level codes are:

0x410000 IOCTL_BTH_GET_LOCAL_INFO
0x410004 IOCTL_BTH_GET_RADIO_INFO
0x410008 IOCTL_BTH_GET_DEVICE_INFO
0×41000C IOCTL_BTH_DISCONNECT_DEVICE
0x410050 IOCTL_BTH_HCI_VENDOR_COMMAND
0x410200 IOCTL_BTH_SDP_CONNECT
0x410204 IOCTL_BTH_SDP_DISCONNECT
0x410208 IOCTL_BTH_SDP_SERVICE_SEARCH
0×41020C IOCTL_BTH_SDP_ATTRIBUTE_SEARCH
0x410210 IOCTL_BTH_SDP_SERVICE_ATTRIBUTE_SEARCH
0x410214 IOCTL_BTH_SDP_SUBMIT_RECORD
0x410218 IOCTL_BTH_SDP_REMOVE_RECORD
0×41021C IOCTL_BTH_SDP_SUBMIT_RECORD_WITH_INFO
Advertisements

 I’ve added support for Secure Simple Pairing (SSP) for Windows 7 and Vista SP2 using the Microsoft stack.  When a Windows 7/etc PC has a Bluetooth version 2.1 dongle (radio/controller) attached and a version 2.1 device is to be atempts to authenticate then one of the new SSP authentication methods will be used.  Previously we had support only for the original Bluetooth PIN authentication method and thus BluetoothWin32Authentication would ignore SSP authentication attempts.  It aims to supports all the authentication methods, although I’ve managed to test only the NumericalComparison/JustWorks methods, and not Passkey, PasskeyNotification and OutOfBand methods.

From the BluetoothWin32Authentication class documentation:

[…] the callback includes a parameter of type BluetoothWin32AuthenticationEventArgs. Various authentication methods are available in Bluetooth version 2.1 and later. Which one is being used is indicated by the AuthenticationMethod property. If it is Legacy then the callback method should set the Pin property.

For the other authentication methods e.g. NumericComparison or OutOfBand the callback method should use one or more of the other properties and methods e.g. NumberOrPasskeyAsString, NumberOrPasskey, Confirm, ResponseNumberOrPasskey, ConfirmOob etc.

For more information see the class documentation and the user guide (http://32feet.codeplex.com/wikipage?title=BluetoothWin32Authentication)

Let me have your feedback.

No changes to BluetoothSecurity.PairRequest nor BluetoothWin32Authentication.New(BluetoothAddress,String).  Those will be considered in the future based on your feedback.  This also affects BluetoothClient.SetPin etc.



UPDATED: Renamed to NumberOrPasskey from  NumberOrPasscode etc

In the Microsoft Bluetooth API on Win32 (desktop Windows) there’s no simple way to get only the in-range-discoverable devices (as I’ve noted previously one can specify whether one wants remembered and/or unknown devices, but the ‘unknown-only’ result has had any remembered devices removed from it!)  This has prevented us from providing the DiscoverDevice(discoverableOnly=true) feature that we provide on every other platform.  We also haven’t been able to provide the ‘live’ discovery feature for in-range devices as provided through class BluetoothComponent.

I’ve recently implemented support for using the native Bluetooth events on this platform (I first implemented this code a long time ago, and see below for why I didn’t use it earlier).  So now that we have support for the events we can implement both of the features discussed above.  Briefly the events are provided through the RegisterDeviceNotifications API and the events are raised as Window Messages.  Thus we create a window on which to receive the messages, creating a new message-loop in most cases for the window, and call the API to enable the events.

Thus when ‘live’ discovery is requested via BluetoothComponent, we run a normal discovery process so that the Bluetooth hardware searches for devices, and we monitor the native events at the same time and use the resulting events to know which devices are in-range (and obviously in discoverable mode) and raise the respective BluetoothComponent events.

We also use this functionality to provided the “discoverableOnly” feature.  By monitoring the native events we make a list of all the devices that are range, and at the same time we run a discovery asking for all remembered and unknown devices — which make Windows return the union of all remembered and in-range devices — then we filter that list leaving only the devices in it that we saw ‘in-range’ events for.  Phew a lot of work for a simple thing. 😦

We should note however that this is useful only on Windows 7 (and perhaps Vista — I haven’t tested); it not useful on Windows XP.  The native events aren’t raised there correctly so we can’t use them to provide this functionality. 😦

This code is in the repository now, please test it and let me hear your feedback.  (Download the code from http://32feet.codeplex.com/SourceControl/list/changesets, build the FX2 project (only), and reference and use it with your application.  Test BluetoothClient.DiscoverDevices(discoverableOnly=true) and BluetoothComponent.DiscoverDevicesAsync(discoverableOnly=true).  One can see the native events directly with BluetoothWin32Events — currently it exposed the Radio-In-Range and Radio-Out-Of-Range event only, we don’t expose the HCI or L2CAP events etc.

Differences between Windows XP and 7

The Radio-In-Range event (on Window 7 at least) raises lots of apparently duplicate events, so we need to do some filtering to provide both functions.  On Windows XP however the native event is not useful for device discovery; when a discovery process is run we do not see Radio-In-Range events for all discoverable devices, it seems like there are no events for devices we’ve seen before.

It seem that one only reliably gets Radio-In-Range events when a connection is made to a particular remote device (e.g. for BluetoothClient.Connect or BluetoothDeviceInfo.GetServiceRecords).  So it seems that the event isn’t raised for discovered devices, but only for devices connected to.  During discovery Windows connects to the newly seen devices to then to get their Device Name — which isn’t transferred in the discovery process in earlier Bluetooth versions.  That’s why we do see events for new devices during discovery.

So that’s why this code has been “on the shelve” for a while.  When tested on Windows XP no useful events were raised.  With Windows 7 reliable events are raised during discovery so we can use it now!

As discussed previously BluetoothWin32Authentication didn’t work on Windows 7.  I have fixed it — changing it to use the new API on Windows 7 and the old API on older Win32 platforms.  See my document Bluetooth in Windows 7 for more details.

There have been questions if our library is supported on Windows 7 and to a lesser extent on Windows Vista.  I’ve completed a bank of testing and as far as I can see there are no issues with the core functionality.  I’ve tested BluetoothClient, BluetoothListener, and BluetoothSecurity and all seem to operate correctly.  This is not too unexpected as MSDN doesn’t list any changes to the main support.

MSDN does describe changes in the support for authentication, both for Windows 7 and for Windows Vista with the Feature Pack for Wirelss, and its not too unsurprising then that 32feet.NET class BluetoothWin32Authentication appears not to work on Windows 7.  At least for the two peer devices I tested with Windows XP and Windows Mobile 6.

So we need to investigate BluetoothRegisterForAuthenticationEx (http://msdn.microsoft.com/en-us/library/cc766820(VS.85).aspx) etc.  Let me know if this is affecting you.