Add HCI debugging with verbosity control to the BluetoothHost demo.
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / Lib / BluetoothStack.h
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 #ifndef _BLUETOOTH_STACK_
32 #define _BLUETOOTH_STACK_
33
34 /* Includes: */
35 #include <LUFA/Drivers/USB/USB.h>
36
37 #include "BluetoothHost.h"
38
39 /* Macros: */
40 #define BLUETOOTH_DATA_IN_PIPE 1
41 #define BLUETOOTH_DATA_OUT_PIPE 2
42 #define BLUETOOTH_EVENTS_PIPE 3
43
44 #define BLUETOOTH_MAX_OPEN_CHANNELS 2
45
46 #define CHANNEL_PSM_SERVICEDISCOVERY 0x0001
47 #define CHANNEL_PSM_UDP 0x0002
48 #define CHANNEL_PSM_RFCOMM 0x0003
49 #define CHANNEL_PSM_TCP 0x0004
50 #define CHANNEL_PSM_IP 0x0009
51 #define CHANNEL_PSM_FTP 0x000A
52 #define CHANNEL_PSM_HTTP 0x000C
53 #define CHANNEL_PSM_UPNP 0x0010
54 #define CHANNEL_PSM_HIDP 0x0011
55
56 #define MAXIMUM_CHANNEL_MTU 255
57
58 /* Enums: */
59 enum BT_ChannelStates_t
60 {
61 Channel_Closed = 0,
62 Channel_WaitConnect = 1,
63 Channel_WaitConnectRsp = 2,
64 Channel_Config_WaitConfig = 3,
65 Channel_Config_WaitSendConfig = 4,
66 Channel_Config_WaitReqResp = 5,
67 Channel_Config_WaitResp = 6,
68 Channel_Config_WaitReq = 7,
69 Channel_Open = 8,
70 Channel_WaitDisconnect = 9,
71 };
72
73 enum Endpoint_ControlStream_RW_ErrorCodes_t
74 {
75 BT_SENDPACKET_NoError = 0,
76 BT_SENDPACKET_NotConnected = 1,
77 BT_SENDPACKET_ChannelNotOpen = 2,
78 };
79
80 /* Type Defines: */
81 typedef struct
82 {
83 uint8_t State;
84 uint16_t LocalNumber;
85 uint16_t RemoteNumber;
86 uint16_t PSM;
87 uint16_t LocalMTU;
88 uint16_t RemoteMTU;
89 } Bluetooth_Channel_t;
90
91 typedef struct
92 {
93 bool IsConnected;
94 uint16_t ConnectionHandle;
95 uint8_t RemoteAddress[6];
96 Bluetooth_Channel_t Channels[BLUETOOTH_MAX_OPEN_CHANNELS];
97 uint8_t SignallingIdentifier;
98 } Bluetooth_Connection_t;
99
100 typedef struct
101 {
102 uint32_t Class;
103 char PINCode[16];
104 char Name[];
105 } Bluetooth_Device_t;
106
107 /* Includes: */
108 #include "BluetoothHCICommands.h"
109 #include "BluetoothACLPackets.h"
110
111 /* Function Prototypes: */
112 void Bluetooth_Stack_Init(void);
113 void Bluetooth_Stack_USBTask(void);
114
115 bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
116 void Bluetooth_ConnectionComplete(void);
117 void Bluetooth_DisconnectionComplete(void);
118 void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel);
119 Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchByRemoteChannel);
120 Bluetooth_Channel_t* Bluetooth_OpenChannel(uint16_t PSM);
121 void Bluetooth_CloseChannel(Bluetooth_Channel_t* Channel);
122 uint8_t Bluetooth_SendPacket(void* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel);
123
124 /* External Variables: */
125 extern Bluetooth_Device_t Bluetooth_DeviceConfiguration;
126 extern Bluetooth_Connection_t Bluetooth_Connection;
127
128 #endif