Fixed incorrect signature for the ATMEGA32U2 in the DFU bootloader (thanks to Axel...
[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 #include <stdio.h>
39
40 #include <LUFA/Drivers/USB/USB.h>
41 #include <LUFA/Drivers/Peripheral/SerialStream.h>
42
43 #include "BluetoothStack.h"
44 #include "BluetoothClassCodes.h"
45
46 /* Macros: */
47 #define BT_HCI_DEBUG(l, s, ...) do { if (HCI_DEBUG_LEVEL >= l) printf_P(PSTR("(HCI) " s "\r\n"), ##__VA_ARGS__); } while (0)
48 #define HCI_DEBUG_LEVEL 0
49
50 #define OGF_LINK_CONTROL (0x01 << 10)
51 #define OGF_CTRLR_BASEBAND (0x03 << 10)
52 #define OGF_CTRLR_INFORMATIONAL (0x04 << 10)
53
54 #define OCF_LINK_CONTROL_INQUIRY 0x0001
55 #define OCF_LINK_CONTROL_INQUIRY_CANCEL 0x0002
56 #define OCF_LINK_CONTROL_PERIODIC_INQUIRY 0x0003
57 #define OCF_LINK_CONTROL_EXIT_PERIODIC_INQUIRY 0x0004
58 #define OCF_LINK_CONTROL_CREATE_CONNECTION 0x0005
59 #define OCF_LINK_CONTROL_DISCONNECT 0x0006
60 #define OCF_LINK_CONTROL_CREATE_CONNECTION_CANCEL 0x0008
61 #define OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST 0x0009
62 #define OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST 0x000A
63 #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_REPLY 0x000B
64 #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_NEG_REPLY 0x000C
65 #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY 0x000D
66 #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_NEG_REPLY 0x000E
67 #define OCF_LINK_CONTROL_CHANGE_CONNECTION_PACKET_TYPE 0x000F
68 #define OCF_LINK_CONTROL_REMOTE_NAME_REQUEST 0x0019
69 #define OCF_CTRLR_BASEBAND_SET_EVENT_MASK 0x0001
70 #define OCF_CTRLR_BASEBAND_RESET 0x0003
71 #define OCF_CTRLR_BASEBAND_WRITE_PIN_TYPE 0x000A
72 #define OCF_CTRLR_BASEBAND_WRITE_LOCAL_NAME 0x0013
73 #define OCF_CTRLR_BASEBAND_READ_LOCAL_NAME 0x0014
74 #define OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE 0x001A
75 #define OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE 0x0024
76 #define OCF_CTRLR_BASEBAND_WRITE_SIMPLE_PAIRING_MODE 0x0056
77 #define OCF_CTRLR_BASEBAND_WRITE_AUTHENTICATION_ENABLE 0x0020
78 #define OCF_CTRLR_INFORMATIONAL_READBUFFERSIZE 0x0005
79 #define OCF_CTRLR_INFORMATIONAL_READBDADDR 0x0009
80
81 #define EVENT_COMMAND_STATUS 0x0F
82 #define EVENT_COMMAND_COMPLETE 0x0E
83 #define EVENT_CONNECTION_COMPLETE 0x03
84 #define EVENT_CONNECTION_REQUEST 0x04
85 #define EVENT_DISCONNECTION_COMPLETE 0x05
86 #define EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07
87 #define EVENT_PIN_CODE_REQUEST 0x16
88 #define EVENT_LINK_KEY_REQUEST 0x17
89
90 #define ERROR_LIMITED_RESOURCES 0x0D
91 #define ERROR_UNACCEPTABLE_BDADDR 0x0F
92
93 /* Type Defines: */
94 typedef struct
95 {
96 uint16_t OpCode;
97 uint8_t ParameterLength;
98 uint8_t Parameters[];
99 } BT_HCICommand_Header_t;
100
101 typedef struct
102 {
103 uint8_t EventCode;
104 uint8_t ParameterLength;
105 } BT_HCIEvent_Header_t;
106
107 typedef struct
108 {
109 uint8_t Status;
110 uint8_t Packets;
111 uint16_t OpCode;
112 } BT_HCIEvent_CommandStatus_t;
113
114 typedef struct
115 {
116 uint8_t HCIPacketsAllowable;
117 uint16_t Opcode;
118 uint8_t ReturnParams[];
119 } BT_HCIEvent_CommandComplete_t;
120
121 typedef struct
122 {
123 uint8_t RemoteAddress[6];
124 uint8_t ClassOfDevice_Service;
125 uint16_t ClassOfDevice_MajorMinor;
126 uint8_t LinkType;
127 } BT_HCIEvent_ConnectionRequest_t;
128
129 typedef struct
130 {
131 uint8_t Status;
132 uint16_t ConnectionHandle;
133 uint8_t RemoteAddress[6];
134 uint8_t LinkType;
135 uint8_t EncryptionEnabled;
136 } BT_HCIEvent_ConnectionComplete_t;
137
138 typedef struct
139 {
140 uint8_t RemoteAddress[6];
141 } BT_HCIEvent_PinCodeReq_t;
142
143 typedef struct
144 {
145 uint8_t RemoteAddress[6];
146 } BT_HCIEvent_LinkKeyReq_t;
147
148 typedef struct
149 {
150 uint8_t RemoteAddress[6];
151 } BT_HCICommand_LinkKeyNAKResp_t;
152
153 typedef struct
154 {
155 uint8_t RemoteAddress[6];
156 uint8_t PINCodeLength;
157 char PINCode[16];
158 } BT_HCICommand_PinCodeResp_t;
159
160 typedef struct
161 {
162 uint8_t RemoteAddress[6];
163 uint8_t SlaveRole;
164 } BT_HCICommand_AcceptConnectionReq_t;
165
166 typedef struct
167 {
168 uint8_t RemoteAddress[6];
169 uint8_t Reason;
170 } BT_HCICommand_RejectConnectionReq_t;
171
172 /* Enums: */
173 enum BT_ScanEnable_Modes_t
174 {
175 BT_SCANMODE_NoScansEnabled = 0,
176 BT_SCANMODE_InquiryScanOnly = 1,
177 BT_SCANMODE_PageScanOnly = 2,
178 BT_SCANMODE_InquiryAndPageScans = 3,
179 };
180
181 enum BT_HCIStates_t
182 {
183 Bluetooth_ProcessEvents = 0,
184 Bluetooth_Init = 1,
185 Bluetooth_Init_Reset = 2,
186 Bluetooth_Init_ReadBufferSize = 3,
187 Bluetooth_Init_GetBDADDR = 4,
188 Bluetooth_Init_SetLocalName = 5,
189 Bluetooth_Init_SetDeviceClass = 6,
190 Bluetooth_Init_WriteScanEnable = 7,
191 Bluetooth_Init_FinalizeInit = 8,
192 Bluetooth_Conn_AcceptConnection = 9,
193 Bluetooth_Conn_RejectConnection = 10,
194 Bluetooth_Conn_SendPINCode = 11,
195 Bluetooth_Conn_SendLinkKeyNAK = 12,
196 };
197
198 /* Function Prototypes: */
199 void Bluetooth_HCITask(void);
200
201 #if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)
202 static uint8_t Bluetooth_SendHCICommand(const BT_HCICommand_Header_t* const HCICommandHeader, const void* Parameters,
203 const uint16_t ParameterLength);
204 #endif
205
206 #endif