Commit 083d797a authored by Dean Camera's avatar Dean Camera
Browse files

Add Bluetooth signalling echo request/response handlers, disconnection request/response handlers.

Add Bluetooth connection request/complete/disconnection callbacks.

Remove debugging from HCI layer, as it is now operational -- add guards to ACL debug statements to reduce logging chattyness so that the overall command sequences can be observed and debugged.
parent fa1a0929
...@@ -195,3 +195,30 @@ void Bluetooth_Host_Task(void) ...@@ -195,3 +195,30 @@ void Bluetooth_Host_Task(void)
break; break;
} }
} }
bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress)
{
printf_P(PSTR("Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"),
RemoteAddress[5], RemoteAddress[4],
RemoteAddress[3], RemoteAddress[2],
RemoteAddress[1], RemoteAddress[0]);
/* Always accept connections from remote devices */
return true;
}
void Bluetooth_ConnectionComplete(void)
{
printf_P(PSTR("Connection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"),
Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],
Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
}
void Bluetooth_DisconnectionComplete(void)
{
printf_P(PSTR("Disconnection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X\r\n"),
Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],
Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
}
...@@ -48,11 +48,13 @@ void Bluetooth_ProcessACLPackets(void) ...@@ -48,11 +48,13 @@ void Bluetooth_ProcessACLPackets(void)
Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader)); Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader)); Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader));
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("Packet Received", NULL); BT_ACL_DEBUG("Packet Received", NULL);
BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader.ConnectionHandle & 0x0FFF)); BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader.ConnectionHandle & 0x0FFF));
BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader.DataLength); BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader.DataLength);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader.DestinationChannel); BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader.DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader.PayloadLength); BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader.PayloadLength);
#endif
if (DataHeader.DestinationChannel == BLUETOOTH_CHANNEL_SIGNALING) if (DataHeader.DestinationChannel == BLUETOOTH_CHANNEL_SIGNALING)
{ {
...@@ -62,20 +64,26 @@ void Bluetooth_ProcessACLPackets(void) ...@@ -62,20 +64,26 @@ void Bluetooth_ProcessACLPackets(void)
switch (SignalCommandHeader.Code) switch (SignalCommandHeader.Code)
{ {
case BLUETOOTH_SIGNAL_CONNECTION_REQUEST: case BLUETOOTH_SIGNAL_CONNECTION_REQUEST:
Bluetooth_ProcessSignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader); Bluetooth_SignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break; break;
case BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST: case BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST:
Bluetooth_ProcessSignalPacket_ConfigurationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader); Bluetooth_SignalPacket_ConfigurationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BLUETOOTH_SIGNAL_DISCONNECTION_REQUEST:
Bluetooth_SignalPacket_DisconnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BLUETOOTH_SIGNAL_ECHO_REQUEST:
Bluetooth_SignalPacket_EchoRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break; break;
case BLUETOOTH_SIGNAL_INFORMATION_REQUEST: case BLUETOOTH_SIGNAL_INFORMATION_REQUEST:
BT_ACL_DEBUG(">> Information Request, Discarded", NULL); BT_ACL_DEBUG("<< Information Request", NULL);
Pipe_Discard_Stream(ACLPacketHeader.DataLength); Pipe_Discard_Stream(ACLPacketHeader.DataLength);
Pipe_ClearIN(); Pipe_ClearIN();
Pipe_Freeze(); Pipe_Freeze();
break; break;
default: default:
BT_ACL_DEBUG(">> Unknown Signaling Command 0x%02X", SignalCommandHeader.Code); BT_ACL_DEBUG("<< Unknown Signaling Command 0x%02X", SignalCommandHeader.Code);
Pipe_Discard_Stream(ACLPacketHeader.DataLength); Pipe_Discard_Stream(ACLPacketHeader.DataLength);
Pipe_ClearIN(); Pipe_ClearIN();
...@@ -100,17 +108,19 @@ void Bluetooth_ProcessACLPackets(void) ...@@ -100,17 +108,19 @@ void Bluetooth_ProcessACLPackets(void)
} }
} }
static inline void Bluetooth_ProcessSignalPacket_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)
{ {
Bluetooth_SignalCommand_ConnectionRequest_t ConnectionRequest; Bluetooth_SignalCommand_ConnectionRequest_t ConnectionRequest;
Pipe_Read_Stream_LE(&ConnectionRequest, sizeof(ConnectionRequest)); Pipe_Read_Stream_LE(&ConnectionRequest, sizeof(ConnectionRequest));
BT_ACL_DEBUG(">> L2CAP Connection Request", NULL); BT_ACL_DEBUG("<< L2CAP Connection Request", NULL);
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- PSM: 0x%04X", ConnectionRequest.PSM); BT_ACL_DEBUG("-- PSM: 0x%04X", ConnectionRequest.PSM);
BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel); BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);
#endif
Pipe_ClearIN(); Pipe_ClearIN();
Pipe_Freeze(); Pipe_Freeze();
...@@ -141,26 +151,32 @@ static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL ...@@ -141,26 +151,32 @@ static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL
Pipe_ClearOUT(); Pipe_ClearOUT();
Pipe_Freeze(); Pipe_Freeze();
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("Packet Sent", NULL); BT_ACL_DEBUG("Packet Sent", NULL);
BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF)); BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));
BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength); BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel); BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength); BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
BT_ACL_DEBUG(">> L2CAP Connection Response", NULL); BT_ACL_DEBUG(">> L2CAP Connection Response", NULL);
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionResponse.SourceChannel); BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionResponse.SourceChannel);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel); BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel);
#endif
} }
static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader, static inline void Bluetooth_SignalPacket_ConfigurationRequest(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)
{ {
Bluetooth_SignalCommand_ConfigurationRequest_t ConfigurationRequest; Bluetooth_SignalCommand_ConfigurationRequest_t ConfigurationRequest;
Pipe_Read_Stream_LE(&ConfigurationRequest, sizeof(ConfigurationRequest)); Pipe_Read_Stream_LE(&ConfigurationRequest, sizeof(ConfigurationRequest));
BT_ACL_DEBUG(">> L2CAP Configuration Request", NULL); BT_ACL_DEBUG("<< L2CAP Configuration Request", NULL);
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel); BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);
#endif
Pipe_ClearIN(); Pipe_ClearIN();
Pipe_Freeze(); Pipe_Freeze();
...@@ -175,7 +191,7 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ ...@@ -175,7 +191,7 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
SignalCommandHeader->Code = BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE; SignalCommandHeader->Code = BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE;
SignalCommandHeader->Length = sizeof(ConfigurationResponse); SignalCommandHeader->Length = sizeof(ConfigurationResponse);
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, CHANNEL_LOOKUP_BY_DESTINATION); Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, false);
if (ChannelData != NULL) if (ChannelData != NULL)
ChannelData->State = Channel_Open; ChannelData->State = Channel_Open;
...@@ -191,13 +207,106 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ ...@@ -191,13 +207,106 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
Pipe_Write_Stream_LE(SignalCommandHeader, sizeof(*SignalCommandHeader)); Pipe_Write_Stream_LE(SignalCommandHeader, sizeof(*SignalCommandHeader));
Pipe_Write_Stream_LE(&ConfigurationResponse, sizeof(ConfigurationResponse)); Pipe_Write_Stream_LE(&ConfigurationResponse, sizeof(ConfigurationResponse));
Pipe_ClearOUT(); Pipe_ClearOUT();
Pipe_Freeze(); Pipe_Freeze();
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("Packet Sent", NULL); BT_ACL_DEBUG("Packet Sent", NULL);
BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF)); BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));
BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength); BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel); BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength); BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
BT_ACL_DEBUG(">> L2CAP Configuration Response", NULL); BT_ACL_DEBUG(">> L2CAP Configuration Response", NULL);
} }
static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
{
Bluetooth_SignalCommand_DisconnectionRequest_t DisconnectionRequest;
Pipe_Read_Stream_LE(&DisconnectionRequest, sizeof(DisconnectionRequest));
BT_ACL_DEBUG("<< L2CAP Disconnection Request", NULL);
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DisconnectionRequest.DestinationChannel);
BT_ACL_DEBUG("-- Source Channel: 0x%04X", DisconnectionRequest.SourceChannel);
#endif
Pipe_ClearIN();
Pipe_Freeze();
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
Pipe_Unfreeze();
Bluetooth_SignalCommand_DisconnectionResponse_t DisconnectionResponse;
ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(DisconnectionResponse);
DataHeader->PayloadLength = sizeof(*SignalCommandHeader) + sizeof(DisconnectionResponse);
DataHeader->DestinationChannel = BLUETOOTH_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BLUETOOTH_SIGNAL_DISCONNECTION_RESPONSE;
SignalCommandHeader->Length = sizeof(DisconnectionResponse);
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(DisconnectionRequest.SourceChannel, true);
if (ChannelData != NULL)
ChannelData->State = Channel_Closed;
DisconnectionResponse.DestinationChannel = ChannelData->LocalNumber;
DisconnectionResponse.SourceChannel = ChannelData->RemoteNumber;
Pipe_Write_Stream_LE(ACLPacketHeader, sizeof(*ACLPacketHeader));
Pipe_Write_Stream_LE(DataHeader, sizeof(*DataHeader));
Pipe_Write_Stream_LE(SignalCommandHeader, sizeof(*SignalCommandHeader));
Pipe_Write_Stream_LE(&DisconnectionResponse, sizeof(DisconnectionResponse));
Pipe_ClearOUT();
Pipe_Freeze();
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("Packet Sent", NULL);
BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));
BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
BT_ACL_DEBUG(">> L2CAP Disconnection Response", NULL);
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Source Channel: 0x%04X", DisconnectionResponse.SourceChannel);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DisconnectionResponse.DestinationChannel);
#endif
}
static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
{
BT_ACL_DEBUG("<< L2CAP Echo Request", NULL);
Pipe_ClearIN();
Pipe_Freeze();
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
Pipe_Unfreeze();
ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader);
DataHeader->PayloadLength = sizeof(*SignalCommandHeader);
DataHeader->DestinationChannel = BLUETOOTH_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BLUETOOTH_SIGNAL_ECHO_RESPONSE;
SignalCommandHeader->Length = 0;
Pipe_Write_Stream_LE(ACLPacketHeader, sizeof(*ACLPacketHeader));
Pipe_Write_Stream_LE(DataHeader, sizeof(*DataHeader));
Pipe_Write_Stream_LE(SignalCommandHeader, sizeof(*SignalCommandHeader));
Pipe_ClearOUT();
Pipe_Freeze();
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("Packet Sent", NULL);
BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));
BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
BT_ACL_DEBUG(">> L2CAP Echo Response", NULL);
}
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
/* Macros: */ /* Macros: */
#define BT_ACL_DEBUG(s, ...) printf_P(PSTR("(ACL) " s "\r\n"), __VA_ARGS__) #define BT_ACL_DEBUG(s, ...) printf_P(PSTR("(ACL) " s "\r\n"), __VA_ARGS__)
#define ACL_DEBUG_LEVEL 1
#define BLUETOOTH_CHANNEL_SIGNALING 0x0001 #define BLUETOOTH_CHANNEL_SIGNALING 0x0001
#define BLUETOOTH_CHANNEL_CONNECTIONLESS 0x0002 #define BLUETOOTH_CHANNEL_CONNECTIONLESS 0x0002
...@@ -50,7 +51,12 @@ ...@@ -50,7 +51,12 @@
#define BLUETOOTH_SIGNAL_CONNECTION_RESPONSE 0x03 #define BLUETOOTH_SIGNAL_CONNECTION_RESPONSE 0x03
#define BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST 0x04 #define BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST 0x04
#define BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE 0x05 #define BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE 0x05
#define BLUETOOTH_SIGNAL_DISCONNECTION_REQUEST 0x06
#define BLUETOOTH_SIGNAL_DISCONNECTION_RESPONSE 0x07
#define BLUETOOTH_SIGNAL_ECHO_REQUEST 0x08
#define BLUETOOTH_SIGNAL_ECHO_RESPONSE 0x09
#define BLUETOOTH_SIGNAL_INFORMATION_REQUEST 0x0A #define BLUETOOTH_SIGNAL_INFORMATION_REQUEST 0x0A
#define BLUETOOTH_SIGNAL_INFORMATION_RESPONSE 0x0B
#define BLUETOOTH_CONNECTION_SUCCESSFUL 0x0000 #define BLUETOOTH_CONNECTION_SUCCESSFUL 0x0000
#define BLUETOOTH_CONNECTION_REFUSED_RESOURCES 0x0004 #define BLUETOOTH_CONNECTION_REFUSED_RESOURCES 0x0004
...@@ -92,7 +98,19 @@ ...@@ -92,7 +98,19 @@
uint16_t Result; uint16_t Result;
uint16_t Status; uint16_t Status;
} Bluetooth_SignalCommand_ConnectionResponse_t; } Bluetooth_SignalCommand_ConnectionResponse_t;
typedef struct
{
uint16_t DestinationChannel;
uint16_t SourceChannel;
} Bluetooth_SignalCommand_DisconnectionRequest_t;
typedef struct
{
uint16_t DestinationChannel;
uint16_t SourceChannel;
} Bluetooth_SignalCommand_DisconnectionResponse_t;
typedef struct typedef struct
{ {
uint16_t DestinationChannel; uint16_t DestinationChannel;
...@@ -112,12 +130,18 @@ ...@@ -112,12 +130,18 @@
void Bluetooth_ProcessACLPackets(void); void Bluetooth_ProcessACLPackets(void);
#if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C) #if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C)
static inline void Bluetooth_ProcessSignalPacket_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);
static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader, static inline void Bluetooth_SignalPacket_EchoRequest(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);
static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
#endif #endif
#endif #endif
...@@ -86,23 +86,15 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -86,23 +86,15 @@ void Bluetooth_ProcessHCICommands(void)
Pipe_Read_Stream_LE(&EventParams, HCIEventHeader.ParameterLength); Pipe_Read_Stream_LE(&EventParams, HCIEventHeader.ParameterLength);
Pipe_ClearIN(); Pipe_ClearIN();
BT_HCI_DEBUG("Event Code: 0x%02X", HCIEventHeader.EventCode);
switch (HCIEventHeader.EventCode) switch (HCIEventHeader.EventCode)
{ {
case EVENT_COMMAND_COMPLETE: case EVENT_COMMAND_COMPLETE:
Bluetooth_HCIProcessingState = Bluetooth_HCINextState; Bluetooth_HCIProcessingState = Bluetooth_HCINextState;
BT_HCI_DEBUG(">> Command Complete (Opcode 0x%04x)",
((Bluetooth_HCIEvent_CommandComplete_t*)&EventParams)->Opcode);
break; break;
case EVENT_COMMAND_STATUS: case EVENT_COMMAND_STATUS:
/* If the execution of a command failed, reset the stack */ /* If the execution of a command failed, reset the stack */
if (((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status) if (((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status)
Bluetooth_HCIProcessingState = Bluetooth_Init; Bluetooth_HCIProcessingState = Bluetooth_Init;
BT_HCI_DEBUG(">> Command Status: 0x%02X",
((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status);
break; break;
case EVENT_CONNECTION_REQUEST: case EVENT_CONNECTION_REQUEST:
/* Need to store the remote device's BT address in a temporary buffer for later use */ /* Need to store the remote device's BT address in a temporary buffer for later use */
...@@ -115,12 +107,8 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -115,12 +107,8 @@ void Bluetooth_ProcessHCICommands(void)
/* Only accept the connection if it is a ACL (data) connection, a device is not already connected /* Only accept the connection if it is a ACL (data) connection, a device is not already connected
and the user application has indicated that the connection should be allowed */ and the user application has indicated that the connection should be allowed */
Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected || !(IsACLConnection) || Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected || !(IsACLConnection) ||
!(CALLBACK_Bluetooth_ConnectionRequest(Bluetooth_TempDeviceAddress))) ? !(Bluetooth_ConnectionRequest(Bluetooth_TempDeviceAddress))) ?
Bluetooth_Conn_RejectConnection : Bluetooth_Conn_AcceptConnection; Bluetooth_Conn_RejectConnection : Bluetooth_Conn_AcceptConnection;
BT_HCI_DEBUG(">> Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X",
Bluetooth_TempDeviceAddress[5], Bluetooth_TempDeviceAddress[4], Bluetooth_TempDeviceAddress[3],
Bluetooth_TempDeviceAddress[2], Bluetooth_TempDeviceAddress[1], Bluetooth_TempDeviceAddress[0]);
break; break;
case EVENT_PIN_CODE_REQUEST: case EVENT_PIN_CODE_REQUEST:
/* Need to store the remote device's BT address in a temporary buffer for later use */ /* Need to store the remote device's BT address in a temporary buffer for later use */
...@@ -129,10 +117,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -129,10 +117,6 @@ void Bluetooth_ProcessHCICommands(void)
sizeof(Bluetooth_TempDeviceAddress)); sizeof(Bluetooth_TempDeviceAddress));
Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode; Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode;
BT_HCI_DEBUG(">> PIN Request from Device %02X:%02X:%02X:%02X:%02X:%02X",
Bluetooth_TempDeviceAddress[5], Bluetooth_TempDeviceAddress[4], Bluetooth_TempDeviceAddress[3],
Bluetooth_TempDeviceAddress[2], Bluetooth_TempDeviceAddress[1], Bluetooth_TempDeviceAddress[0]);
break; break;
case EVENT_CONNECTION_COMPLETE: case EVENT_CONNECTION_COMPLETE:
/* Need to store the remote device's BT address in a temporary buffer for later use */ /* Need to store the remote device's BT address in a temporary buffer for later use */
...@@ -143,19 +127,15 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -143,19 +127,15 @@ void Bluetooth_ProcessHCICommands(void)
/* Store the created connection handle and indicate that the connection has been established */ /* Store the created connection handle and indicate that the connection has been established */
Bluetooth_Connection.ConnectionHandle = ((Bluetooth_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle; Bluetooth_Connection.ConnectionHandle = ((Bluetooth_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle;
Bluetooth_Connection.IsConnected = true; Bluetooth_Connection.IsConnected = true;
BT_HCI_DEBUG(">> Connection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X, Handle 0x%04x", Bluetooth_ConnectionComplete();
Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],
Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0],
Bluetooth_Connection.ConnectionHandle);
break; break;
case EVENT_DISCONNECTION_COMPLETE: case EVENT_DISCONNECTION_COMPLETE:
BT_HCI_DEBUG(">> Disconnection Complete", NULL);
/* Device disconnected, indicate connection information no longer valid */ /* Device disconnected, indicate connection information no longer valid */
Bluetooth_Connection.IsConnected = false; Bluetooth_Connection.IsConnected = false;
Bluetooth_DisconnectionComplete();
Bluetooth_HCIProcessingState = Bluetooth_Init; Bluetooth_HCIProcessingState = Bluetooth_Init;
break; break;
} }
...@@ -176,8 +156,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -176,8 +156,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_RESET}, OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_RESET},
ParameterLength: 0, ParameterLength: 0,
}; };
BT_HCI_DEBUG("Enter State: Bluetooth_Init_Reset", NULL);
/* Send the command to reset the bluetooth dongle controller */ /* Send the command to reset the bluetooth dongle controller */
Bluetooth_SendHCICommand(NULL, 0); Bluetooth_SendHCICommand(NULL, 0);
...@@ -192,9 +170,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -192,9 +170,6 @@ void Bluetooth_ProcessHCICommands(void)
ParameterLength: 248, ParameterLength: 248,
}; };
BT_HCI_DEBUG("Enter State: Bluetooth_Init_SetLocalName", NULL);
BT_HCI_DEBUG("-- Name: %s", Bluetooth_DeviceConfiguration.Name);
/* Send the command to set the bluetooth dongle's name for other devices to see */ /* Send the command to set the bluetooth dongle's name for other devices to see */
Bluetooth_SendHCICommand(Bluetooth_DeviceConfiguration.Name, strlen(Bluetooth_DeviceConfiguration.Name)); Bluetooth_SendHCICommand(Bluetooth_DeviceConfiguration.Name, strlen(Bluetooth_DeviceConfiguration.Name));
...@@ -208,8 +183,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -208,8 +183,6 @@ void Bluetooth_ProcessHCICommands(void)
ParameterLength: 3, ParameterLength: 3,
}; };
BT_HCI_DEBUG("Enter State: Bluetooth_Init_SetDeviceClass", NULL);
/* Send the command to set the class of the device for other devices to see */ /* Send the command to set the class of the device for other devices to see */
Bluetooth_SendHCICommand(&Bluetooth_DeviceConfiguration.Class, 3); Bluetooth_SendHCICommand(&Bluetooth_DeviceConfiguration.Class, 3);
...@@ -222,8 +195,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -222,8 +195,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE}, OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE},
ParameterLength: 1, ParameterLength: 1,
}; };
BT_HCI_DEBUG("Enter State: Bluetooth_Init_WriteScanEnable", NULL);
uint8_t Interval = BT_SCANMODE_InquiryAndPageScans; uint8_t Interval = BT_SCANMODE_InquiryAndPageScans;
...@@ -239,8 +210,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -239,8 +210,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST}, OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST},
ParameterLength: sizeof(Bluetooth_HCICommand_AcceptConnectionRequest_t), ParameterLength: sizeof(Bluetooth_HCICommand_AcceptConnectionRequest_t),
}; };
BT_HCI_DEBUG("Enter State: Bluetooth_Conn_AcceptConnection", NULL);
/* Copy over the temporary BT device address saved from the Connection Request event, indicate slave /* Copy over the temporary BT device address saved from the Connection Request event, indicate slave
connection role */ connection role */
...@@ -260,8 +229,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -260,8 +229,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST}, OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST},
ParameterLength: sizeof(Bluetooth_HCICommand_RejectConnectionRequest_t), ParameterLength: sizeof(Bluetooth_HCICommand_RejectConnectionRequest_t),
}; };
BT_HCI_DEBUG("Enter State: Bluetooth_Conn_RejectConnection", NULL);
/* Copy over the temporary BT device address saved from the Connection Request event, indicate failure /* Copy over the temporary BT device address saved from the Connection Request event, indicate failure
to accept the connection due to limited device resources or incorrect device address */ to accept the connection due to limited device resources or incorrect device address */
...@@ -280,9 +247,6 @@ void Bluetooth_ProcessHCICommands(void) ...@@ -280,9 +247,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY}, OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY},
ParameterLength: sizeof(Bluetooth_HCICommand_PinCodeResponse_t), ParameterLength: sizeof(Bluetooth_HCICommand_PinCodeResponse_t),
}; };