Create an Installable Stream Device Driver for the Extension Layer (Compact 2013)
3/26/2014
To install an extension layer on top of the Bluetooth stack, you must create the extension layer as an installable stream device driver. Stream device drivers use common APIs to manage a device.
To implement an installable stream device driver for a Bluetooth stack extension layer, you must perform the following tasks:
- Initialize the driver in XXX_Init
- Deinitialize the driver in XXX_Deinit
- Read data from the device in XXX_Read
- Write data to the device in XXX_Write
- Prepare the device for reading and writing in XXX_Open
- Close a handle to the device to stop using the stream interface driver in XXX_Close
- Send a command to a device in XXX_IOControl
- Move the data pointer in the device in XXX_Seek
- Restore power to the device in XXX_PowerUp
- Suspend power to the device XXX_PowerDown
Note
The XXX_ function prefix is a placeholder for the three character identifier of the driver. While implementation of these APIs is required by the Device Manager, a Bluetooth stack extension layer may not require complete implementation of each one. For example, the L2capdev sample source code implements placeholders for the XXX_Read, XXX_Write, XXX_Seek, XXX_PowerUp, and XXX_PowerDown functions.
For more information about stream interface drivers, see Planning your Device Driver. For start-to-finish instructions about how to create a stream driver, see Building and Testing Your Device Driver
Initialize the Driver
When Device Manager initializes the stream driver, the stream driver calls the corresponding driver creation function of the Bluetooth stack extension layer interface.
The following example code from the L2capdev sample shows how to implement the L2C_Init function.
extern "C" DWORD L2C_Init (DWORD Index) {
DebugInit();
return (DWORD)(l2capdev_CreateDriverInstance () == ERROR_SUCCESS);
}
Deinitialize the Driver
The pattern of uninitialization resembles that of initialization. When the Device Manager uninitializes the stream driver, the stream driver calls the corresponding driver closing function of the Bluetooth stack extension layer interface.
The following example code from the L2capdev sample shows how to implement the L2C_Deinit function.
extern "C" BOOL L2C_Deinit(DWORD dwData) {
l2capdev_CloseDriverInstance ();
DebugDeInit();
return TRUE;
}
Loading the Extension Layer from an Application
After you have defined the Bluetooth stack extension layer functions in the source code, and you have created an installable stream device driver, you have to load the driver from an application. The application can be a simple, stand-alone executable program with the sole purpose of loading the driver and stack extension layer.
There are five basic steps that your application must follow in order to properly load, test, and unload the Bluetooth stack extension layer driver:
- Call ActivateDeviceEx , which prompts the Device Manager to load your driver DLL.
- Call CreateFile to open the driver DLL.
- Make any calls to the driver to perform tests. Typically you do this by calling XXX_IOControl with various parameters to test the extension layer functionality.
- Call CloseHandle to close the driver DLL.
- Call DeactivateDevice , which prompts the Device Manager to unload your driver DLL.
For detailed example code for these steps, see Building and Testing Your Device Driver.
The L2capapi sample located in the %_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\L2capapi directory is an example of how an application can load the L2capdev extension layer DLL.
See Also
Concepts
Bluetooth Stack Extension Layer
Implement the Bluetooth Stack Data Structures
Implement Functions that Setup and Shutdown the Extension Layer