}\r
}\r
\r
+/** Bluetooth stack callback event for a Bluetooth connection request. When this callback fires, the\r
+ * user application must indicate if the connection is to be allowed or rejected.\r
+ *\r
+ * \param RemoteAddress Bluetooth address of the remote device attempting the connection\r
+ *\r
+ * \return Boolean true to accept the connection, false to reject it\r
+ */\r
bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress)\r
{\r
printf_P(PSTR("Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"),\r
return true;\r
}\r
\r
+/** Bluetooth stack callback event for a completed Bluetooth connection. When this callback is made,\r
+ * the connection information can be accessed through the global \ref Bluetooth_Connection structure.\r
+ */\r
void Bluetooth_ConnectionComplete(void)\r
{\r
printf_P(PSTR("Connection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"), \r
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);\r
}\r
\r
+/** Bluetooth stack callback event for a completed Bluetooth disconnection. When this callback is made,\r
+ * the connection information in the global \ref Bluetooth_Connection structure is invalidated with the\r
+ * exception of the RemoteAddress element, which can be used to determine the address of the device that\r
+ * was disconnected.\r
+ */\r
void Bluetooth_DisconnectionComplete(void)\r
{\r
printf_P(PSTR("Disconnection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"), \r
Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],\r
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);\r
}\r
+\r
+/** Bluetooth stack callback event for a non-signal ACL packet reception. This callback fires once a connection\r
+ * to a remote Bluetooth device has been made, and the remote device has sent a non-signalling ACL packet.\r
+ *\r
+ * \param PacketLength Length of the packet data, in bytes - this must be decremented as data is read\r
+ * \param Channel Bluetooth ACL data channel information structure for the packet's destination channel\r
+ */\r
+void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel)\r
+{\r
+ uint8_t DataPayload[*PacketLength];\r
+ Pipe_Read_Stream_LE(&DataPayload, *PacketLength);\r
+ *PacketLength = 0;\r
+\r
+ BT_ACL_DEBUG("-- Data Payload: ", NULL);\r
+ for (uint16_t B = 0; B < sizeof(DataPayload); B++)\r
+ printf("0x%02X ", DataPayload[B]);\r
+ printf("\r\n"); \r
+}\r
}\r
else\r
{\r
- uint8_t DataPayload[DataHeader.PayloadLength];\r
- Pipe_Read_Stream_LE(&DataPayload, sizeof(DataPayload));\r
- DataHeader.PayloadLength = 0;\r
+ Bluetooth_PacketReceived(&DataHeader.PayloadLength, Bluetooth_GetChannelData(DataHeader.DestinationChannel, true));\r
\r
- BT_ACL_DEBUG("-- Data Payload: ", NULL);\r
- for (uint16_t B = 0; B < sizeof(DataPayload); B++)\r
- printf("0x%02X ", DataPayload[B]);\r
- printf("\r\n");\r
-\r
- Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
- Pipe_ClearIN(); \r
+ Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);\r
+ Pipe_Discard_Stream(DataHeader.PayloadLength);\r
+ Pipe_ClearIN();\r
Pipe_Freeze();\r
}\r
}\r
\r
+void Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel)\r
+{\r
+ Bluetooth_ACL_Header_t ACLPacketHeader;\r
+ Bluetooth_DataPacket_Header_t DataHeader;\r
+\r
+ ACLPacketHeader.ConnectionHandle = Bluetooth_Connection.ConnectionHandle;\r
+ ACLPacketHeader.DataLength = sizeof(DataHeader) + DataLen;\r
+ DataHeader.PayloadLength = DataLen;\r
+ DataHeader.DestinationChannel = Channel->RemoteNumber;\r
+\r
+ Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
+ Pipe_Unfreeze();\r
+ \r
+ Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));\r
+ Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));\r
+ Pipe_Write_Stream_LE(Data, DataLen);\r
+\r
+ Pipe_Freeze();\r
+}\r
+\r
static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
Bluetooth_DataPacket_Header_t* DataHeader,\r
Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
\r
/* Function Prototypes: */\r
void Bluetooth_ProcessACLPackets(void);\r
-\r
+ void Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel);\r
+ \r
#if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C)\r
static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
Bluetooth_DataPacket_Header_t* DataHeader,\r
/* Function Prototypes: */\r
void Bluetooth_ProcessHCICommands(void);\r
void Bluetooth_ProcessHCIEvents(void);\r
- \r
- bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);\r
- void Bluetooth_ConnectionComplete(void);\r
- void Bluetooth_DisconnectionComplete(void);\r
\r
#if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)\r
static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);\r
#include <LUFA/Drivers/USB/USB.h>\r
\r
#include "BluetoothHost.h"\r
- #include "BluetoothHCICommands.h"\r
- #include "BluetoothACLPackets.h"\r
\r
/* Macros: */\r
#define BLUETOOTH_DATA_IN_PIPE 1\r
char PINCode[16];\r
char Name[];\r
} Bluetooth_Device_t;\r
+ \r
+ /* Includes: */\r
+ #include "BluetoothHCICommands.h"\r
+ #include "BluetoothACLPackets.h" \r
\r
/* Function Prototypes: */\r
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource);\r
void Bluetooth_Stack_Init(void);\r
void Bluetooth_Stack_USBTask(void);\r
\r
+ bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);\r
+ void Bluetooth_ConnectionComplete(void);\r
+ void Bluetooth_DisconnectionComplete(void);\r
+ void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel);\r
+\r
/* External Variables: */\r
extern Bluetooth_Device_t Bluetooth_DeviceConfiguration;\r
extern Bluetooth_Connection_t Bluetooth_Connection;\r