Add user callback function to the Bluetooth host demo to filter out connections from...
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / Lib / BluetoothHCICommands.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_HCICOMMANDS_H_
32 #define _BLUETOOTH_HCICOMMANDS_H_
33
34 /* Includes: */
35 #include <avr/io.h>
36 #include <string.h>
37 #include <stdbool.h>
38
39 #include <LUFA/Drivers/USB/USB.h>
40
41 #include "BluetoothStack.h"
42 #include "BluetoothClassCodes.h"
43
44 /* Macros: */
45 #define BT_HCI_DEBUG(s, ...) printf_P(PSTR("(HCI) " s "\r\n"), __VA_ARGS__)
46
47 #define OGF_LINK_CONTROL 0x01
48 #define OGF_CTRLR_BASEBAND 0x03
49 #define OGF_CTRLR_INFORMATIONAL 0x04
50
51 #define OCF_LINK_CONTROL_INQUIRY 0x0001
52 #define OCF_LINK_CONTROL_INQUIRY_CANCEL 0x0002
53 #define OCF_LINK_CONTROL_PERIODIC_INQUIRY 0x0003
54 #define OCF_LINK_CONTROL_EXIT_PERIODIC_INQUIRY 0x0004
55 #define OCF_LINK_CONTROL_CREATE_CONNECTION 0x0005
56 #define OCF_LINK_CONTROL_DISCONNECT 0x0006
57 #define OCF_LINK_CONTROL_CREATE_CONNECTION_CANCEL 0x0008
58 #define OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST 0x0009
59 #define OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST 0x000A
60 #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_REPLY 0x000B
61 #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_NEG_REPLY 0x000C
62 #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY 0x000D
63 #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_NEG_REPLY 0x000E
64 #define OCF_LINK_CONTROL_CHANGE_CONNECTION_PACKET_TYPE 0x000F
65 #define OCF_LINK_CONTROL_REMOTE_NAME_REQUEST 0x0019
66 #define OCF_CTRLR_BASEBAND_SET_EVENT_MASK 0x0001
67 #define OCF_CTRLR_BASEBAND_RESET 0x0003
68 #define OCF_CTRLR_BASEBAND_WRITE_PIN_TYPE 0x000A
69 #define OCF_CTRLR_BASEBAND_WRITE_LOCAL_NAME 0x0013
70 #define OCF_CTRLR_BASEBAND_READ_LOCAL_NAME 0x0014
71 #define OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE 0x001A
72 #define OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE 0x0024
73 #define OCF_CTRLR_BASEBAND_WRITE_SIMPLE_PAIRING_MODE 0x0056
74 #define OCF_CTRLR_BASEBAND_WRITE_AUTHENTICATION_ENABLE 0x0020
75 #define OGF_CTRLR_INFORMATIONAL_READBUFFERSIZE 0x0005
76
77 #define EVENT_COMMAND_STATUS 0x0F
78 #define EVENT_COMMAND_COMPLETE 0x0E
79 #define EVENT_CONNECTION_COMPLETE 0x03
80 #define EVENT_CONNECTION_REQUEST 0x04
81 #define EVENT_DISCONNECTION_COMPLETE 0x05
82 #define EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07
83 #define EVENT_PIN_CODE_REQUEST 0x16
84
85 #define ERROR_LIMITED_RESOURCES 0x0D
86 #define ERROR_UNACCEPTABLE_BDADDR 0x0F
87
88 /* Type Defines: */
89 typedef struct
90 {
91 struct
92 {
93 int OCF : 10;
94 int OGF : 6;
95 } OpCode;
96
97 uint8_t ParameterLength;
98 uint8_t Parameters[];
99 } Bluetooth_HCICommand_Header_t;
100
101 typedef struct
102 {
103 uint8_t EventCode;
104 uint8_t ParameterLength;
105 } Bluetooth_HCIEvent_Header_t;
106
107 typedef struct
108 {
109 uint8_t Status;
110 uint8_t Packets;
111
112 struct
113 {
114 int OCF : 10;
115 int OGF : 6;
116 } OpCode;
117 } Bluetooth_HCIEvent_CommandStatus_t;
118
119 typedef struct
120 {
121 uint8_t HCLPacketsAllowable;
122 uint16_t Opcode;
123 uint8_t ReturnParams[];
124 } Bluetooth_HCIEvent_CommandComplete_t;
125
126 typedef struct
127 {
128 uint8_t RemoteAddress[6];
129 uint8_t ClassOfDevice_Service;
130 uint16_t ClassOfDevice_MajorMinor;
131 uint8_t LinkType;
132 } Bluetooth_HCIEvent_ConnectionRequest_t;
133
134 typedef struct
135 {
136 uint8_t Status;
137 uint16_t ConnectionHandle;
138 uint8_t RemoteAddress[6];
139 uint8_t LinkType;
140 uint8_t EncryptionEnabled;
141 } Bluetooth_HCIEvent_ConnectionComplete_t;
142
143 typedef struct
144 {
145 uint8_t RemoteAddress[6];
146 } Bluetooth_HCIEvent_PinCodeRequest_t;
147
148 typedef struct
149 {
150 uint8_t RemoteAddress[6];
151 uint8_t SlaveRole;
152 } Bluetooth_HCICommand_AcceptConnectionRequest_t;
153
154 typedef struct
155 {
156 uint8_t RemoteAddress[6];
157 uint8_t Reason;
158 } Bluetooth_HCICommand_RejectConnectionRequest_t;
159
160 typedef struct
161 {
162 uint8_t RemoteAddress[6];
163 uint8_t PINCodeLength;
164 char PINCode[16];
165 } Bluetooth_HCICommand_PinCodeResponse_t;
166
167 /* Enums: */
168 enum Bluetooth_ScanEnable_Modes_t
169 {
170 BT_SCANMODE_NoScansEnabled = 0,
171 BT_SCANMODE_InquiryScanOnly = 1,
172 BT_SCANMODE_PageScanOnly = 2,
173 BT_SCANMODE_InquiryAndPageScans = 3,
174 };
175
176 enum BluetoothStack_States_t
177 {
178 Bluetooth_ProcessEvents = 0,
179 Bluetooth_Init = 1,
180 Bluetooth_Init_Reset = 2,
181 Bluetooth_Init_SetLocalName = 3,
182 Bluetooth_Init_SetDeviceClass = 4,
183 Bluetooth_Init_WriteScanEnable = 5,
184 Bluetooth_Conn_AcceptConnection = 6,
185 Bluetooth_Conn_RejectConnection = 7,
186 Bluetooth_Conn_SendPINCode = 8,
187 };
188
189 /* External Variables: */
190 extern uint8_t Bluetooth_HCIProcessingState;
191
192 /* Function Prototypes: */
193 void Bluetooth_ProcessHCICommands(void);
194 void Bluetooth_ProcessHCIEvents(void);
195
196 bool CALLBACK_Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
197
198 #if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)
199 static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);
200 #endif
201
202 #endif