IO Control and Other Common Stack Functions (Windows Embedded CE 6.0)
1/6/2010
All Bluetooth stack layers have certain common stack management functions.
typedef int (*BT_LAYER_IO_CONTROL) (
HANDLE hDeviceContext,
int fSelector,
int cInBuffer,
char *pInBuffer,
int cOutBuffer,
char *pOutBuffer,
int *pcDataReturned
);
The above function is used to pass control information down the stack.
The Bluetooth stack event is used to notify upper layers of a condition such as shutdown.
typedef int (*BT_LAYER_STACK_EVENT_IND) (
void *pUserContext,
int iEvent,
void *pEventContext
);
The Bluetooth stack event can carry the following information up to the layer's clients.
Event | Code |
---|---|
BTH_STACK_NONE |
0 |
BTH_STACK_RESET |
1 |
BTH_STACK_DOWN |
2 |
BTH_STACK_UP |
3 |
BTH_STACK_DISCONNECT |
4 |
BTH_STACK_FLOW_ON |
5 |
BTH_STACK_FLOW_OFF |
6 |
BTH_STACK_HOST_BUFFER |
7 |
Stack layers should propagate relevant events up to their own clients. They do not have to propagate every event. For example, L2CAP does not support host buffer flow. It puts itself in a disconnected state when BTH_STACK_FLOW_ON is received, and turns itself back on at BTH_STACK_FLOW_OFF. Clients are notified using STACK_DOWN and STACK_UP states.
A BTH_STACK_RESET event is issued when the card resets. On receiving this event, the stack layers must assume the card has reinitialized and its state was lost. All connections must be closed and the card reconfigured appropriately.
BTH_STACK_DOWN means the hardware was removed. Connections and other state information must be destroyed.
BTH_STACK_UP is sent when the card is inserted.
BTH_STACK_DISCONNECT is sent on final shutdown, when the stack is about to be unloaded. This event should be treated as a PROCESS_DETACH event in DllMain, although it is not sent in that context. All state information must be destroyed at that point, not just adapter state or active connections.
Note
The L2CAP currently does not support host flow control and will disconnect if it receives flow-control related events from the HCI.
The following call is used to abort a currently executing call.
typedef int (*BT_LAYER_ABORT_CALL) (
HANDLE hDeviceContext,
void *pCallContext
);
There are no guarantees that the abort will complete because the call may have already executed – depending on whether the call has executed, this will put you in a very typical race condition.
The following callback notifies the user that a lower level could not complete the call because of an error condition.
typedef int (*BT_LAYER_CALL_ABORTED) (void *pCallContext, int iError);