Skip to content
Snippets Groups Projects
Commit b9c7d196 authored by Dean Camera's avatar Dean Camera
Browse files

Add packet reception and send routines to the ACL layer of the incomplete Bluetooth Host demo.

parent ee74b494
Branches
Tags
No related merge requests found
...@@ -196,6 +196,13 @@ void Bluetooth_Host_Task(void) ...@@ -196,6 +196,13 @@ void Bluetooth_Host_Task(void)
} }
} }
/** Bluetooth stack callback event for a Bluetooth connection request. When this callback fires, the
* user application must indicate if the connection is to be allowed or rejected.
*
* \param RemoteAddress Bluetooth address of the remote device attempting the connection
*
* \return Boolean true to accept the connection, false to reject it
*/
bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress) bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress)
{ {
printf_P(PSTR("Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"), printf_P(PSTR("Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"),
...@@ -207,6 +214,9 @@ bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress) ...@@ -207,6 +214,9 @@ bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress)
return true; return true;
} }
/** Bluetooth stack callback event for a completed Bluetooth connection. When this callback is made,
* the connection information can be accessed through the global \ref Bluetooth_Connection structure.
*/
void Bluetooth_ConnectionComplete(void) void Bluetooth_ConnectionComplete(void)
{ {
printf_P(PSTR("Connection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"), printf_P(PSTR("Connection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"),
...@@ -215,6 +225,11 @@ void Bluetooth_ConnectionComplete(void) ...@@ -215,6 +225,11 @@ void Bluetooth_ConnectionComplete(void)
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]); Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
} }
/** Bluetooth stack callback event for a completed Bluetooth disconnection. When this callback is made,
* the connection information in the global \ref Bluetooth_Connection structure is invalidated with the
* exception of the RemoteAddress element, which can be used to determine the address of the device that
* was disconnected.
*/
void Bluetooth_DisconnectionComplete(void) void Bluetooth_DisconnectionComplete(void)
{ {
printf_P(PSTR("Disconnection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"), printf_P(PSTR("Disconnection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"),
...@@ -222,3 +237,21 @@ void Bluetooth_DisconnectionComplete(void) ...@@ -222,3 +237,21 @@ void Bluetooth_DisconnectionComplete(void)
Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2], Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]); Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
} }
/** Bluetooth stack callback event for a non-signal ACL packet reception. This callback fires once a connection
* to a remote Bluetooth device has been made, and the remote device has sent a non-signalling ACL packet.
*
* \param PacketLength Length of the packet data, in bytes - this must be decremented as data is read
* \param Channel Bluetooth ACL data channel information structure for the packet's destination channel
*/
void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel)
{
uint8_t DataPayload[*PacketLength];
Pipe_Read_Stream_LE(&DataPayload, *PacketLength);
*PacketLength = 0;
BT_ACL_DEBUG("-- Data Payload: ", NULL);
for (uint16_t B = 0; B < sizeof(DataPayload); B++)
printf("0x%02X ", DataPayload[B]);
printf("\r\n");
}
...@@ -91,21 +91,35 @@ void Bluetooth_ProcessACLPackets(void) ...@@ -91,21 +91,35 @@ void Bluetooth_ProcessACLPackets(void)
} }
else else
{ {
uint8_t DataPayload[DataHeader.PayloadLength]; Bluetooth_PacketReceived(&DataHeader.PayloadLength, Bluetooth_GetChannelData(DataHeader.DestinationChannel, true));
Pipe_Read_Stream_LE(&DataPayload, sizeof(DataPayload));
DataHeader.PayloadLength = 0;
BT_ACL_DEBUG("-- Data Payload: ", NULL); Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);
for (uint16_t B = 0; B < sizeof(DataPayload); B++) Pipe_Discard_Stream(DataHeader.PayloadLength);
printf("0x%02X ", DataPayload[B]);
printf("\r\n");
Pipe_Discard_Stream(ACLPacketHeader.DataLength);
Pipe_ClearIN(); Pipe_ClearIN();
Pipe_Freeze(); Pipe_Freeze();
} }
} }
void Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel)
{
Bluetooth_ACL_Header_t ACLPacketHeader;
Bluetooth_DataPacket_Header_t DataHeader;
ACLPacketHeader.ConnectionHandle = Bluetooth_Connection.ConnectionHandle;
ACLPacketHeader.DataLength = sizeof(DataHeader) + DataLen;
DataHeader.PayloadLength = DataLen;
DataHeader.DestinationChannel = Channel->RemoteNumber;
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
Pipe_Unfreeze();
Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));
Pipe_Write_Stream_LE(Data, DataLen);
Pipe_Freeze();
}
static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader, static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader, Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader) Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
......
...@@ -143,6 +143,7 @@ ...@@ -143,6 +143,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
void Bluetooth_ProcessACLPackets(void); void Bluetooth_ProcessACLPackets(void);
void Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel);
#if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C) #if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C)
static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader, static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
......
...@@ -191,10 +191,6 @@ ...@@ -191,10 +191,6 @@
void Bluetooth_ProcessHCICommands(void); void Bluetooth_ProcessHCICommands(void);
void Bluetooth_ProcessHCIEvents(void); void Bluetooth_ProcessHCIEvents(void);
bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
void Bluetooth_ConnectionComplete(void);
void Bluetooth_DisconnectionComplete(void);
#if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C) #if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)
static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength); static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);
#endif #endif
......
...@@ -35,8 +35,6 @@ ...@@ -35,8 +35,6 @@
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>
#include "BluetoothHost.h" #include "BluetoothHost.h"
#include "BluetoothHCICommands.h"
#include "BluetoothACLPackets.h"
/* Macros: */ /* Macros: */
#define BLUETOOTH_DATA_IN_PIPE 1 #define BLUETOOTH_DATA_IN_PIPE 1
...@@ -85,6 +83,10 @@ ...@@ -85,6 +83,10 @@
char Name[]; char Name[];
} Bluetooth_Device_t; } Bluetooth_Device_t;
/* Includes: */
#include "BluetoothHCICommands.h"
#include "BluetoothACLPackets.h"
/* Function Prototypes: */ /* Function Prototypes: */
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource); Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource);
Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM); Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM);
...@@ -92,6 +94,11 @@ ...@@ -92,6 +94,11 @@
void Bluetooth_Stack_Init(void); void Bluetooth_Stack_Init(void);
void Bluetooth_Stack_USBTask(void); void Bluetooth_Stack_USBTask(void);
bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
void Bluetooth_ConnectionComplete(void);
void Bluetooth_DisconnectionComplete(void);
void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel);
/* External Variables: */ /* External Variables: */
extern Bluetooth_Device_t Bluetooth_DeviceConfiguration; extern Bluetooth_Device_t Bluetooth_DeviceConfiguration;
extern Bluetooth_Connection_t Bluetooth_Connection; extern Bluetooth_Connection_t Bluetooth_Connection;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment