Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Protocol Extension Sample (Windows CE 5.0)

Windows CE 5.0
Send Feedback

The Bthlink, Btscosnd, L2capapi, and L2capdev samples illustrate the process of creating a Bluetooth protocol extension for Windows CE. These sample extensions connect to various layers of the Bluetooth stack by putting itself above the HCI layer and exposing an interface for creating baseband connections.

For more information see, How to Develop and Load a Bluetooth HCI Stack Extension Layer.

Note   These samples have not been thoroughly tested and are not intended for production use.

For example, BthLink provides the functionality to generate a link key between two devices in the pairing process. The compiled sample generates a Bthlink.dll. This DLL is loaded by Btpair.exe.

Note   This sample is used by the Querying and Pairing Sample.

Loading the Extension

The DLL of this protocol layer is loaded with the standard stream driver loading procedure.

HANDLE HDev= RegisterDevice (L"BTL", 1, L"bthlink.dll", NULL);
HANDLE hFile = CreateFile (
               0, 0, NULL,

Initializing the Extension

The BL_INIT function is called to create an instance of the bthlink object. The instance is created with the bthlink_CreateDriverInstance call.

To register the protocol layer extension, the HCI_EstablishDeviceContext function is called. This function passes the information regarding the new layer down to the next protocol layer. The following example code shows how HCI_EstablishDeviceContext does this.

HCI_EstablishDeviceContext (
    NULL, 0, 0,
    &hei, &hc, &hci_if, &cHciHeaders,&cHciTrilers,&hHCI)

The HEI data structure is used to register the event handlers that will be handled by this new layer. The following example code shows how to use HEI to register the event handlers.

hei.hci_ConnectionCompleteEvent = bthlink_CreateConnection_Out;
hei.hci_DisconnectionCompleeEvent = bthlink_DisconnectionCompleteEvent;
hei.hci_StackEvent = bthlink_hStackEvent;

The HC data structure is used to register the callback functions this new layer supports. The following example code shows how to use the HC structure to register the callback functions.

hc.hci_CreateConnection_Out = bthlink_CreateConnection_Out;
hc.hci_Disconnect_Out = bthlink_Disconnect_Out;
hc.hci_CallAborted = bthlink_hCallAborted;

Creating a Link Key

If the extension layer installs successfully, two IOCTL functions are established:


When BHLINK_IOCTL_CONNECT calls DeviceIoControl, the connect function establishes the callback function context for HCI_CreateConnection_In. A connection is created by establishing a link key between the two devices.

Destroying the Extension

The following example code is used to destroy the extension.

DeviceIoControl (
          &p, sizeof(p), NULL, 0, NULL, NULL
DeregisterDevice (hDev);

Sample Location

The following table shows the location for the protocol extension samples.

%_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\BthlinkHCI extension layer that generates a link key between two devices in the pairing process.

The compiled sample generates a Bthlink.dll.

%_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\BtscosndHCI extension layer that implements an audio driver that sends and recieves Bluetooth SCO audio data.

The compiled sample generates a Btscosnd.lib.

%_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\L2capdevL2CAP extension layer that is implemented as a driver in device.exe.

The compiled sample generates a L2capdev.dll.

%_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\L2capapiUser application accessible API that communicates with L2capdev.

The compiled sample generates the static library L2capapi.dll.

See Also

Bluetooth Application Development | Bluetooth Samples

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.

© 2015 Microsoft