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