Massive cleanups to the incomplete BluetoothHost demo, to make the HCL layer code...
[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 OGF_LINK_CONTROL 0x01
46 #define OGF_CTRLR_BASEBAND 0x03
47 #define OGF_CTRLR_INFORMATIONAL 0x04
48
49 #define OCF_LINK_CONTROL_INQUIRY 0x0001
50 #define OCF_LINK_CONTROL_INQUIRY_CANCEL 0x0002
51 #define OCF_LINK_CONTROL_PERIODIC_INQUIRY 0x0003
52 #define OCF_LINK_CONTROL_EXIT_PERIODIC_INQUIRY 0x0004
53 #define OCF_LINK_CONTROL_CREATE_CONNECTION 0x0005
54 #define OCF_LINK_CONTROL_DISCONNECT 0x0006
55 #define OCF_LINK_CONTROL_CREATE_CONNECTION_CANCEL 0x0008
56 #define OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST 0x0009
57 #define OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST 0x000A
58 #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_REPLY 0x000B
59 #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_NEG_REPLY 0x000C
60 #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY 0x000D
61 #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_NEG_REPLY 0x000E
62 #define OCF_LINK_CONTROL_CHANGE_CONNECTION_PACKET_TYPE 0x000F
63 #define OCF_LINK_CONTROL_REMOTE_NAME_REQUEST 0x0019
64 #define OCF_CTRLR_BASEBAND_SET_EVENT_MASK 0x0001
65 #define OCF_CTRLR_BASEBAND_RESET 0x0003
66 #define OCF_CTRLR_BASEBAND_WRITE_PIN_TYPE 0x000A
67 #define OCF_CTRLR_BASEBAND_WRITE_LOCAL_NAME 0x0013
68 #define OCF_CTRLR_BASEBAND_READ_LOCAL_NAME 0x0014
69 #define OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE 0x001A
70 #define OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE 0x0024
71 #define OCF_CTRLR_BASEBAND_WRITE_SIMPLE_PAIRING_MODE 0x0056
72 #define OCF_CTRLR_BASEBAND_WRITE_AUTHENTICATION_ENABLE 0x0020
73 #define OGF_CTRLR_INFORMATIONAL_READBUFFERSIZE 0x0005
74
75 #define EVENT_COMMAND_STATUS 0x0F
76 #define EVENT_COMMAND_COMPLETE 0x0E
77 #define EVENT_CONNECTION_COMPLETE 0x03
78 #define EVENT_CONNECTION_REQUEST 0x04
79 #define EVENT_DISCONNECTION_COMPLETE 0x05
80 #define EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07
81 #define EVENT_PIN_CODE_REQUEST 0x16
82
83 #define ERROR_LIMITED_RESOURCES 0x0D
84
85 /* Type Defines: */
86 typedef struct
87 {
88 struct
89 {
90 int OCF : 10;
91 int OGF : 6;
92 } OpCode;
93
94 uint8_t ParameterLength;
95 uint8_t Parameters[];
96 } Bluetooth_HCICommand_Header_t;
97
98 typedef struct
99 {
100 uint8_t EventCode;
101 uint8_t ParameterLength;
102 } Bluetooth_HCIEvent_Header_t;
103
104 typedef struct
105 {
106 uint8_t Status;
107 uint8_t Packets;
108
109 struct
110 {
111 int OCF : 10;
112 int OGF : 6;
113 } OpCode;
114 } Bluetooth_HCIEvent_CommandStatus_t;
115
116 typedef struct
117 {
118 uint8_t HCLPacketsAllowable;
119 uint16_t Opcode;
120 uint8_t ReturnParams[];
121 } Bluetooth_HCIEvent_CommandComplete_t;
122
123 typedef struct
124 {
125 uint8_t RemoteAddress[6];
126 uint8_t ClassOfDevice_Service;
127 uint16_t ClassOfDevice_MajorMinor;
128 uint8_t LinkType;
129 } Bluetooth_HCIEvent_ConnectionRequest_t;
130
131 typedef struct
132 {
133 uint8_t Status;
134 uint16_t ConnectionHandle;
135 uint8_t RemoteAddress[6];
136 uint8_t LinkType;
137 uint8_t EncryptionEnabled;
138 } Bluetooth_HCIEvent_ConnectionComplete_t;
139
140 typedef struct
141 {
142 uint8_t RemoteAddress[6];
143 } Bluetooth_HCIEvent_PinCodeRequest_t;
144
145 typedef struct
146 {
147 uint8_t RemoteAddress[6];
148 uint8_t SlaveRole;
149 } Bluetooth_HCICommand_AcceptConnectionRequest_t;
150
151 typedef struct
152 {
153 uint8_t RemoteAddress[6];
154 uint8_t Reason;
155 } Bluetooth_HCICommand_RejectConnectionRequest_t;
156
157 typedef struct
158 {
159 uint8_t RemoteAddress[6];
160 uint8_t PINCodeLength;
161 char PINCode[16];
162 } Bluetooth_HCICommand_PinCodeResponse_t;
163
164 /* Enums: */
165 enum Bluetooth_ScanEnable_Modes_t
166 {
167 NoScansEnabled = 0,
168 InquiryScanOnly = 1,
169 PageScanOnly = 2,
170 InquiryAndPageScans = 3,
171 };
172
173 enum BluetoothStack_States_t
174 {
175 Bluetooth_ProcessEvents = 0,
176 Bluetooth_Init = 1,
177 Bluetooth_Init_Reset = 2,
178 Bluetooth_Init_ReadBufferSize = 3,
179 Bluetooth_Init_SetLocalName = 4,
180 Bluetooth_Init_SetDeviceClass = 5,
181 Bluetooth_Init_WriteScanEnable = 6,
182 Bluetooth_Conn_AcceptConnection = 7,
183 Bluetooth_Conn_RejectConnection = 8,
184 Bluetooth_Conn_SendPINCode = 9,
185 };
186
187 /* External Variables: */
188 extern uint8_t Bluetooth_HCIProcessingState;
189
190 /* Function Prototypes: */
191 void Bluetooth_ProcessHCICommands(void);
192 void Bluetooth_ProcessHCIEvents(void);
193
194 #if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)
195 static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint8_t ParamLength);
196 #endif
197
198 #endif