#include <avr/io.h>\r
#include <string.h>\r
#include <stdbool.h>\r
+ #include <stdio.h>\r
\r
#include <LUFA/Drivers/USB/USB.h>\r
+ #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
\r
#include "BluetoothStack.h"\r
#include "BluetoothClassCodes.h"\r
\r
/* Macros: */\r
- #define BT_HCI_DEBUG(s, ...) printf_P(PSTR("(HCI) " s "\r\n"), __VA_ARGS__)\r
- \r
- #define OGF_LINK_CONTROL 0x01\r
- #define OGF_CTRLR_BASEBAND 0x03\r
- #define OGF_CTRLR_INFORMATIONAL 0x04\r
+ #define BT_HCI_DEBUG(l, s, ...) do { if (HCI_DEBUG_LEVEL >= l) printf_P(PSTR("(HCI) " s "\r\n"), ##__VA_ARGS__); } while (0)\r
+ #define HCI_DEBUG_LEVEL 0\r
+\r
+ #define OGF_LINK_CONTROL (0x01 << 10)\r
+ #define OGF_CTRLR_BASEBAND (0x03 << 10)\r
+ #define OGF_CTRLR_INFORMATIONAL (0x04 << 10)\r
\r
#define OCF_LINK_CONTROL_INQUIRY 0x0001\r
#define OCF_LINK_CONTROL_INQUIRY_CANCEL 0x0002\r
#define OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE 0x0024\r
#define OCF_CTRLR_BASEBAND_WRITE_SIMPLE_PAIRING_MODE 0x0056\r
#define OCF_CTRLR_BASEBAND_WRITE_AUTHENTICATION_ENABLE 0x0020\r
- #define OGF_CTRLR_INFORMATIONAL_READBUFFERSIZE 0x0005\r
+ #define OCF_CTRLR_INFORMATIONAL_READBUFFERSIZE 0x0005\r
+ #define OCF_CTRLR_INFORMATIONAL_READBDADDR 0x0009\r
\r
#define EVENT_COMMAND_STATUS 0x0F\r
#define EVENT_COMMAND_COMPLETE 0x0E\r
#define EVENT_DISCONNECTION_COMPLETE 0x05\r
#define EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07\r
#define EVENT_PIN_CODE_REQUEST 0x16\r
+ #define EVENT_LINK_KEY_REQUEST 0x17\r
\r
#define ERROR_LIMITED_RESOURCES 0x0D\r
+ #define ERROR_UNACCEPTABLE_BDADDR 0x0F\r
\r
/* Type Defines: */\r
typedef struct\r
{\r
- struct\r
- {\r
- int OCF : 10;\r
- int OGF : 6;\r
- } OpCode;\r
-\r
+ uint16_t OpCode;\r
uint8_t ParameterLength;\r
uint8_t Parameters[];\r
- } Bluetooth_HCICommand_Header_t;\r
+ } BT_HCICommand_Header_t;\r
\r
typedef struct\r
{\r
uint8_t EventCode;\r
uint8_t ParameterLength;\r
- } Bluetooth_HCIEvent_Header_t;\r
+ } BT_HCIEvent_Header_t;\r
\r
typedef struct\r
{\r
- uint8_t Status;\r
- uint8_t Packets;\r
-\r
- struct\r
- {\r
- int OCF : 10;\r
- int OGF : 6;\r
- } OpCode;\r
- } Bluetooth_HCIEvent_CommandStatus_t;\r
+ uint8_t Status;\r
+ uint8_t Packets;\r
+ uint16_t OpCode;\r
+ } BT_HCIEvent_CommandStatus_t;\r
\r
typedef struct\r
{\r
- uint8_t HCLPacketsAllowable;\r
+ uint8_t HCIPacketsAllowable;\r
uint16_t Opcode;\r
uint8_t ReturnParams[];\r
- } Bluetooth_HCIEvent_CommandComplete_t;\r
+ } BT_HCIEvent_CommandComplete_t;\r
\r
typedef struct\r
{\r
uint8_t ClassOfDevice_Service;\r
uint16_t ClassOfDevice_MajorMinor;\r
uint8_t LinkType;\r
- } Bluetooth_HCIEvent_ConnectionRequest_t;\r
+ } BT_HCIEvent_ConnectionRequest_t;\r
\r
typedef struct\r
{\r
uint8_t RemoteAddress[6];\r
uint8_t LinkType;\r
uint8_t EncryptionEnabled;\r
- } Bluetooth_HCIEvent_ConnectionComplete_t;\r
+ } BT_HCIEvent_ConnectionComplete_t;\r
\r
typedef struct\r
{\r
uint8_t RemoteAddress[6];\r
- } Bluetooth_HCIEvent_PinCodeRequest_t;\r
- \r
+ } BT_HCIEvent_PinCodeReq_t;\r
+\r
typedef struct\r
{\r
uint8_t RemoteAddress[6];\r
- uint8_t SlaveRole;\r
- } Bluetooth_HCICommand_AcceptConnectionRequest_t;\r
- \r
+ } BT_HCIEvent_LinkKeyReq_t;\r
+ \r
typedef struct\r
{\r
uint8_t RemoteAddress[6];\r
- uint8_t Reason;\r
- } Bluetooth_HCICommand_RejectConnectionRequest_t;\r
+ } BT_HCICommand_LinkKeyNAKResp_t;\r
\r
typedef struct\r
{\r
uint8_t RemoteAddress[6];\r
uint8_t PINCodeLength;\r
char PINCode[16];\r
- } Bluetooth_HCICommand_PinCodeResponse_t;\r
+ } BT_HCICommand_PinCodeResp_t;\r
+ \r
+ typedef struct\r
+ {\r
+ uint8_t RemoteAddress[6];\r
+ uint8_t SlaveRole;\r
+ } BT_HCICommand_AcceptConnectionReq_t;\r
\r
+ typedef struct\r
+ {\r
+ uint8_t RemoteAddress[6];\r
+ uint8_t Reason;\r
+ } BT_HCICommand_RejectConnectionReq_t; \r
+\r
/* Enums: */\r
- enum Bluetooth_ScanEnable_Modes_t\r
+ enum BT_ScanEnable_Modes_t\r
{\r
BT_SCANMODE_NoScansEnabled = 0,\r
BT_SCANMODE_InquiryScanOnly = 1,\r
BT_SCANMODE_InquiryAndPageScans = 3,\r
};\r
\r
- enum BluetoothStack_States_t\r
+ enum BT_HCIStates_t\r
{\r
Bluetooth_ProcessEvents = 0,\r
Bluetooth_Init = 1,\r
Bluetooth_Init_Reset = 2,\r
- Bluetooth_Init_SetLocalName = 3,\r
- Bluetooth_Init_SetDeviceClass = 4,\r
- Bluetooth_Init_WriteScanEnable = 5,\r
- Bluetooth_Conn_AcceptConnection = 6,\r
- Bluetooth_Conn_RejectConnection = 7,\r
- Bluetooth_Conn_SendPINCode = 8,\r
+ Bluetooth_Init_ReadBufferSize = 3,\r
+ Bluetooth_Init_GetBDADDR = 4,\r
+ Bluetooth_Init_SetLocalName = 5,\r
+ Bluetooth_Init_SetDeviceClass = 6,\r
+ Bluetooth_Init_WriteScanEnable = 7,\r
+ Bluetooth_Init_FinalizeInit = 8,\r
+ Bluetooth_Conn_AcceptConnection = 9,\r
+ Bluetooth_Conn_RejectConnection = 10,\r
+ Bluetooth_Conn_SendPINCode = 11,\r
+ Bluetooth_Conn_SendLinkKeyNAK = 12,\r
};\r
\r
- /* External Variables: */\r
- extern uint8_t Bluetooth_HCIProcessingState;\r
-\r
/* Function Prototypes: */\r
- void Bluetooth_ProcessHCICommands(void);\r
- void Bluetooth_ProcessHCIEvents(void);\r
-\r
+ void Bluetooth_HCITask(void);\r
+ \r
#if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)\r
- static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);\r
+ static uint8_t Bluetooth_SendHCICommand(const BT_HCICommand_Header_t* const HCICommandHeader, const void* Parameters,\r
+ const uint16_t ParameterLength);\r
#endif\r
\r
#endif\r