Compartilhar via


Setting Up and Shutting Down a Bluetooth Extension Layer (Windows CE 5.0)

Send Feedback

After you write the extension layer according to the guidelines described in Implementing Commands, Callbacks, and Events Handlers for an Extension Layer, you need to facilitate the initializing, instantiating, deinitializing, and deleting of the extension layer.

All Bluetooth stack layers, from HCI and up, follow the same guidelines for exporting interfaces and connecting to lower layers of the stack.

Note   The functions described in this section are templates for creating and deleting a driver instance.

To initialize, instantiate, deinitialize, and delete the extension layer

  1. To initialize the extension layer, write a function called **ExtensionLayer_InitializeOnce.

    The following code example shows the function signature for **ExtensionLayer_InitializeOnce.

    int ExtensionLayer_InitializeOnce (void);
    

    This function can be called from DllMain during driver load. **ExtensionLayer_InitializeOnce should not perform anything beyond the initialization of synchronization primitives or I/O. It must be called only once and should check if the driver has been initialized. If the driver initialization has already occurred, it should be deinitialized by calling the **ExtensionLayer_CloseDriverInstance function (discussed later).

  2. To create an instance of the extension layer, write a function ExtensionLayer_CreateDriverInstance.

    The following code example shows the function signature for ExtensionLayer_CreateDriverInstance.

    int ExtensionLayer_CreateDriverInstance (void);
    

    This function is used to initialize the stack layer. It is called after ExtensionLayer_InitializeOnce and can count on synchronization primitives being initialized. It can be called out of sequence with ExtensionLayer_CloseDriverInstance and must maintain state and protect against duplicate calls.

    Implement this function to initialize the stack layer and perform the following tasks:

    • Connect to the lower layer in the protocol stack.
    • Prepare for connection requests from upper layers of the stack.
    • Initialize hardware appropriately.

    The stack layer must be in an operational state for this function to complete successfully.

  3. To deinitialize the extension layer, write a function ExtensionLayer_UninitializeOnce.

    The following code example shows the function declaration for the ExtensionLayer_UnInitializeOnce.

    int ExtensionLayer_UnInitialize (void);
    

    This function is called during driver unload from DllMain. ExtensionLayer_UnInitializeOnce should only perform deinitialization of existing synchronization primitives. It must be called only once when the driver is in a shutdown state. The driver is unloaded immediately after the call to this function.

    A driver can be reinitialized, by using Extensionlayer_InitializeOnce, only after calling ExtensionLayer_UnInitializeOnce.

  4. To delete the instance of the extension layer created by calling ExtensionLayer_CreateDriverInstance, write a function **ExtensionLayer_CloseDriverInstance.

    The following code example shows the function signature for ExtensionLayer_CloseDriverInstance.

    int ExtensionLayer_CloseDriverInstance (void);
    

    Implement this function to shutdown the stack layer and perform the following tasks:

    • Close all connections.
    • Release the interface to the lower layer.
    • Notify the upper layers that the layer is shutting down.
    • Destroy all threads.
    • Free memory allocated by ExtensionLayer_CreateDriverInstance.

See Also

Creating a Bluetooth Stack Extension Layer | Bluetooth OS Design Development | Host Controller Interface | How to Develop and Load a Bluetooth HCI Stack Extension Layer

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.