BluetoothHCICommands.h 6.52 KB
Newer Older
1
2
/*
             LUFA Library
Dean Camera's avatar
Dean Camera committed
3
     Copyright (C) Dean Camera, 2010.
4
5
6
7
8
9
              
  dean [at] fourwalledcubicle [dot] com
      www.fourwalledcubicle.com
*/

/*
Dean Camera's avatar
Dean Camera committed
10
  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11

12
13
14
15
16
17
18
  Permission to use, copy, modify, distribute, and sell this 
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in 
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting 
  documentation, and that the name of the author not be used in 
  advertising or publicity pertaining to distribution of the 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  software without specific, written prior permission.

  The author disclaim all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

#ifndef _BLUETOOTH_HCICOMMANDS_H_
#define _BLUETOOTH_HCICOMMANDS_H_

	/* Includes: */
		#include <avr/io.h>
		#include <string.h>
		#include <stdbool.h>

		#include <LUFA/Drivers/USB/USB.h>

		#include "BluetoothStack.h"
		#include "BluetoothClassCodes.h"

	/* Macros: */
		#define OGF_LINK_CONTROL                               0x01
		#define OGF_CTRLR_BASEBAND                             0x03
		#define OGF_CTRLR_INFORMATIONAL                        0x04

		#define OCF_LINK_CONTROL_INQUIRY                       0x0001
		#define OCF_LINK_CONTROL_INQUIRY_CANCEL                0x0002
		#define OCF_LINK_CONTROL_PERIODIC_INQUIRY              0x0003
		#define OCF_LINK_CONTROL_EXIT_PERIODIC_INQUIRY         0x0004
		#define OCF_LINK_CONTROL_CREATE_CONNECTION             0x0005
		#define OCF_LINK_CONTROL_DISCONNECT                    0x0006
		#define OCF_LINK_CONTROL_CREATE_CONNECTION_CANCEL      0x0008
		#define OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST     0x0009
		#define OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST     0x000A
		#define OCF_LINK_CONTROL_LINK_KEY_REQUEST_REPLY        0x000B
		#define OCF_LINK_CONTROL_LINK_KEY_REQUEST_NEG_REPLY    0x000C
		#define OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY        0x000D
		#define OCF_LINK_CONTROL_PIN_CODE_REQUEST_NEG_REPLY    0x000E
		#define OCF_LINK_CONTROL_CHANGE_CONNECTION_PACKET_TYPE 0x000F
		#define OCF_LINK_CONTROL_REMOTE_NAME_REQUEST           0x0019
		#define OCF_CTRLR_BASEBAND_SET_EVENT_MASK              0x0001
		#define OCF_CTRLR_BASEBAND_RESET                       0x0003
		#define OCF_CTRLR_BASEBAND_WRITE_PIN_TYPE              0x000A
		#define OCF_CTRLR_BASEBAND_WRITE_LOCAL_NAME            0x0013
		#define OCF_CTRLR_BASEBAND_READ_LOCAL_NAME             0x0014
		#define OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE           0x001A
		#define OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE       0x0024
		#define OCF_CTRLR_BASEBAND_WRITE_SIMPLE_PAIRING_MODE   0x0056
		#define OCF_CTRLR_BASEBAND_WRITE_AUTHENTICATION_ENABLE 0x0020
		#define OGF_CTRLR_INFORMATIONAL_READBUFFERSIZE         0x0005
		
		#define EVENT_COMMAND_STATUS                           0x0F
		#define EVENT_COMMAND_COMPLETE                         0x0E
		#define EVENT_CONNECTION_COMPLETE                      0x03
		#define EVENT_CONNECTION_REQUEST                       0x04
		#define EVENT_DISCONNECTION_COMPLETE                   0x05
		#define EVENT_REMOTE_NAME_REQUEST_COMPLETE             0x07
		#define EVENT_PIN_CODE_REQUEST                         0x16
		
		#define ERROR_LIMITED_RESOURCES                        0x0D
84
		#define ERROR_UNACCEPTABLE_BDADDR                      0x0F
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
		
	/* Type Defines: */
		typedef struct
		{
			struct
			{
				int OCF : 10;
				int OGF : 6;
			} OpCode;

			uint8_t  ParameterLength;
			uint8_t  Parameters[];
		} Bluetooth_HCICommand_Header_t;

		typedef struct
		{
			uint8_t  EventCode;
			uint8_t  ParameterLength;
		} Bluetooth_HCIEvent_Header_t;

		typedef struct
		{
107
108
			uint8_t Status;
			uint8_t Packets;
109
110
111
112
113
114

			struct
			{
				int OCF : 10;
				int OGF : 6;
			} OpCode;
115
		} Bluetooth_HCIEvent_CommandStatus_t;
116
		
117
118
119
120
121
122
123
		typedef struct
		{
			uint8_t  HCLPacketsAllowable;
			uint16_t Opcode;
			uint8_t  ReturnParams[];
		} Bluetooth_HCIEvent_CommandComplete_t;

124
125
126
127
128
129
		typedef struct
		{
			uint8_t  RemoteAddress[6];
			uint8_t  ClassOfDevice_Service;
			uint16_t ClassOfDevice_MajorMinor;
			uint8_t  LinkType;
130
		} Bluetooth_HCIEvent_ConnectionRequest_t;
131
132
133
134
135
136
137
138

		typedef struct
		{
			uint8_t  Status;
			uint16_t ConnectionHandle;
			uint8_t  RemoteAddress[6];
			uint8_t  LinkType;
			uint8_t  EncryptionEnabled;
139
140
141
142
143
144
		} Bluetooth_HCIEvent_ConnectionComplete_t;
		
		typedef struct
		{
			uint8_t  RemoteAddress[6];
		} Bluetooth_HCIEvent_PinCodeRequest_t;
145
146
147
148
149
		
		typedef struct
		{
			uint8_t  RemoteAddress[6];
			uint8_t  SlaveRole;
150
		} Bluetooth_HCICommand_AcceptConnectionRequest_t;
151
152
153
154
155
		
		typedef struct
		{
			uint8_t  RemoteAddress[6];
			uint8_t  Reason;
156
		} Bluetooth_HCICommand_RejectConnectionRequest_t;
157
158
159
160
161
162

		typedef struct
		{
			uint8_t  RemoteAddress[6];
			uint8_t  PINCodeLength;
			char     PINCode[16];
163
		} Bluetooth_HCICommand_PinCodeResponse_t;
164
165
166
167
		
	/* Enums: */
		enum Bluetooth_ScanEnable_Modes_t
		{
168
169
170
171
			BT_SCANMODE_NoScansEnabled       = 0,
			BT_SCANMODE_InquiryScanOnly      = 1,
			BT_SCANMODE_PageScanOnly         = 2,
			BT_SCANMODE_InquiryAndPageScans  = 3,
172
173
174
175
		};

		enum BluetoothStack_States_t
		{
176
177
178
179
180
181
182
183
184
			Bluetooth_ProcessEvents          = 0,
			Bluetooth_Init                   = 1,
			Bluetooth_Init_Reset             = 2,
			Bluetooth_Init_SetLocalName      = 3,
			Bluetooth_Init_SetDeviceClass    = 4,
			Bluetooth_Init_WriteScanEnable   = 5,
			Bluetooth_Conn_AcceptConnection  = 6,
			Bluetooth_Conn_RejectConnection  = 7,
			Bluetooth_Conn_SendPINCode       = 8,
185
186
187
188
189
190
191
		};
		
	/* External Variables: */
		extern uint8_t Bluetooth_HCIProcessingState;

	/* Function Prototypes: */
		void Bluetooth_ProcessHCICommands(void);
192
		void Bluetooth_ProcessHCIEvents(void);
193
		
194
195
196
197
		bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
		void Bluetooth_ConnectionComplete(void);
		void Bluetooth_DisconnectionComplete(void);
			
198
		#if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)
199
			static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);
200
201
202
		#endif
		
#endif