Share via


Protocol Extension Sample

This sample Bluetooth protocol stack layer illustrates the process of creating a Bluetooth protocol extension for Windows CE. This sample extension connects to various layers of the Bluetooth stack by putting itself on top of the HCI layer and exposing an interface for creating baseband connections. The functionality for generating a link key between two devices in the pairing process is provided.

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

The compiled sample generates a Bthlink.dll. This DLL is loaded by Btpair.exe.

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 (
               L"BTL1:",
               0, 0, NULL,
               OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 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 (
    this, BTH_CONTROL_DEVICEONLY,
    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:

  • BTHLINK_IOCTL_CONNECT
  • BTHLINK_IOCTL_DISCONNECT

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 (
          hFile, BTHLINK_IOCTL_DISCONNECT,
          &p, sizeof(p), NULL, 0, NULL, NULL
         );
DeregisterDevice (hDev);

Sample Location

%_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\Bthlink

**Note   **This sample has not been thoroughly tested and is not intended for production use.

See Also

Bluetooth | Bluetooth Samples

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.