Add const keyword to the demo function parameters where possible.
[pub/lufa.git] / Demos / Host / Incomplete / BluetoothHost / Lib / BluetoothStack.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 #include "BluetoothStack.h"
32
33 /** Bluetooth device connection information structure. Once connected to a remote device, this structure tracks the
34 * connection state of the individual L2CAP channels.
35 */
36 Bluetooth_Connection_t Bluetooth_Connection = {IsConnected: false};
37
38 /** Bluetooth configuration structure. This structure configures the bluetooth stack's user alterable settings. */
39 Bluetooth_Device_t Bluetooth_DeviceConfiguration =
40 {
41 Class: (DEVICE_CLASS_SERVICE_CAPTURING | DEVICE_CLASS_MAJOR_COMPUTER | DEVICE_CLASS_MINOR_COMPUTER_PALM),
42 PINCode: "0000",
43 Name: "LUFA Bluetooth Demo"
44 };
45
46 /** Bluetooth stack initialization function. This function must be called once to initialize the Bluetooth stack,
47 * ready for connection to remote devices.
48 *
49 * \note This function only begins the initialization process; the stack is initialized as the main Bluetooth stack
50 * management task is repeatedly called. The initialization process ends when the \ref Bluetooth_HCIProcessingState
51 * global enters the Bluetooth_ProcessEvents state.
52 */
53 void Bluetooth_Stack_Init(void)
54 {
55 /* Reset the HCI state machine - this will eventually reset the adapter and stack when the Bluetooth stack task is called */
56 Bluetooth_HCIProcessingState = Bluetooth_Init;
57 }
58
59 /** Bluetooth stack management task. This task must be repeatedly called to maintain the Bluetooth stack and any connection
60 * to remote Bluetooth devices, including both the HCI control layer and the ACL channel layer.
61 */
62 void Bluetooth_Stack_USBTask(void)
63 {
64 Bluetooth_HCITask();
65 Bluetooth_ACLTask();
66 }
67
68 /** Retrieves the channel information structure with the given local or remote channel number from the channel list.
69 *
70 * \param[in] ChannelNumber Channel number to search for in the channel list
71 * \param[in] SearchByRemoteChannel Indicated whether to search for a channel information structure by the given remote channel
72 * or local channel number
73 *
74 * \return Pointer to the matching channel information structure in the channel table if found, NULL otherwise
75 */
76 Bluetooth_Channel_t* Bluetooth_GetChannelData(const uint16_t ChannelNumber, const bool SearchByRemoteChannel)
77 {
78 for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
79 {
80 Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i];
81
82 /* Fetch the channel number that is to be matched against from the current channel information struct */
83 uint16_t SearchChannelNumber = (SearchByRemoteChannel) ? ChannelData->RemoteNumber : ChannelData->LocalNumber;
84
85 if (SearchChannelNumber == ChannelNumber)
86 return ChannelData;
87 }
88
89 return NULL;
90 }