3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 #include "BluetoothStack.h"
33 /** Bluetooth device connection information structure. Once connected to a remote device, this structure tracks the
34 * connection state of the individual L2CAP channels.
36 Bluetooth_Connection_t Bluetooth_Connection
= { IsConnected
: false };
38 /** Bluetooth device state information structure. This structure contains details on the current Bluetooth stack
41 Bluetooth_Stack_State_t Bluetooth_State
= { IsInitialized
: false };
43 /** Bluetooth stack initialization function. This function must be called once to initialize the Bluetooth stack,
44 * ready for connection to remote devices.
46 * \note This function only begins the initialization process; the stack is initialized as the main Bluetooth stack
47 * management task is repeatedly called. The initialization process ends when the IsInitialized element of the
48 * \ref Bluetooth_State structure becomes true and the \ref Bluetooth_StackInitialized() callback fires.
50 void Bluetooth_Stack_Init(void)
52 /* Reset the HCI state machine - this will eventually reset the adapter and stack when the Bluetooth stack task is called */
53 Bluetooth_State
.CurrentHCIState
= Bluetooth_Init
;
54 Bluetooth_State
.NextHCIState
= Bluetooth_Init
;
57 /** Bluetooth stack management task. This task must be repeatedly called to maintain the Bluetooth stack and any connection
58 * to remote Bluetooth devices, including both the HCI control layer and the ACL channel layer.
60 void Bluetooth_Stack_USBTask(void)
62 if (USB_HostState
!= HOST_STATE_Configured
)
69 /** Retrieves the channel information structure with the given local or remote channel number from the channel list.
71 * \param[in] SearchValue Value to search for in the channel structure list
72 * \param[in] SearchKey Key to search within the channel structure, a CHANNEL_SEARCH_* mask
74 * \return Pointer to the matching channel information structure in the channel table if found, NULL otherwise
76 Bluetooth_Channel_t
* Bluetooth_GetChannelData(const uint16_t SearchValue
, const uint8_t SearchKey
)
78 for (uint8_t i
= 0; i
< BLUETOOTH_MAX_OPEN_CHANNELS
; i
++)
80 Bluetooth_Channel_t
* ChannelData
= &Bluetooth_Connection
.Channels
[i
];
82 bool FoundMatch
= false;
86 case CHANNEL_SEARCH_LOCALNUMBER
:
87 FoundMatch
= (SearchValue
== ChannelData
->LocalNumber
);
89 case CHANNEL_SEARCH_REMOTENUMBER
:
90 FoundMatch
= (SearchValue
== ChannelData
->RemoteNumber
);
92 case CHANNEL_SEARCH_PSM
:
93 FoundMatch
= (SearchValue
== ChannelData
->PSM
);