aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Host/Incomplete
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-04-05 12:13:33 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-04-05 12:13:33 +0000
commit083d797acaa58f792960a1cb9d7d8d41c3c956a7 (patch)
tree2335216af3b26e4a27e1fbfc726153ab736747bb /Demos/Host/Incomplete
parentfa1a092901319b3b41bf09e0c4cb9cbbec470d6b (diff)
downloadlufa-083d797acaa58f792960a1cb9d7d8d41c3c956a7.tar.gz
lufa-083d797acaa58f792960a1cb9d7d8d41c3c956a7.tar.bz2
lufa-083d797acaa58f792960a1cb9d7d8d41c3c956a7.zip
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.
Diffstat (limited to 'Demos/Host/Incomplete')
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c27
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c137
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h36
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c46
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h8
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c17
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h10
7 files changed, 198 insertions, 83 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
index 338997fc7..a3ca0aaa4 100644
--- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
+++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
@@ -195,3 +195,30 @@ void Bluetooth_Host_Task(void)
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]);
+}
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
index e8daa0533..ed39d5cfa 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
@@ -48,11 +48,13 @@ void Bluetooth_ProcessACLPackets(void)
Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader));
+#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("Packet Received", 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
if (DataHeader.DestinationChannel == BLUETOOTH_CHANNEL_SIGNALING)
{
@@ -62,20 +64,26 @@ void Bluetooth_ProcessACLPackets(void)
switch (SignalCommandHeader.Code)
{
case BLUETOOTH_SIGNAL_CONNECTION_REQUEST:
- Bluetooth_ProcessSignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
+ Bluetooth_SignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
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;
case BLUETOOTH_SIGNAL_INFORMATION_REQUEST:
- BT_ACL_DEBUG(">> Information Request, Discarded", NULL);
+ BT_ACL_DEBUG("<< Information Request", NULL);
Pipe_Discard_Stream(ACLPacketHeader.DataLength);
Pipe_ClearIN();
Pipe_Freeze();
break;
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_ClearIN();
@@ -100,17 +108,19 @@ void Bluetooth_ProcessACLPackets(void)
}
}
-static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
- Bluetooth_DataPacket_Header_t* DataHeader,
- Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
+static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
+ Bluetooth_DataPacket_Header_t* DataHeader,
+ Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
{
Bluetooth_SignalCommand_ConnectionRequest_t 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("-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);
+#endif
Pipe_ClearIN();
Pipe_Freeze();
@@ -141,26 +151,32 @@ static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL
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 Connection Response", NULL);
+#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionResponse.SourceChannel);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel);
+#endif
}
-static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
- Bluetooth_DataPacket_Header_t* DataHeader,
- 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)
{
Bluetooth_SignalCommand_ConfigurationRequest_t 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);
+#endif
Pipe_ClearIN();
Pipe_Freeze();
@@ -175,7 +191,7 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
SignalCommandHeader->Code = BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE;
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)
ChannelData->State = Channel_Open;
@@ -191,13 +207,106 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
Pipe_Write_Stream_LE(SignalCommandHeader, sizeof(*SignalCommandHeader));
Pipe_Write_Stream_LE(&ConfigurationResponse, sizeof(ConfigurationResponse));
- Pipe_ClearOUT();
+ 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 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);
+}
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h
index c0fd1f620..9c7bd26b0 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h
@@ -42,6 +42,7 @@
/* Macros: */
#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_CONNECTIONLESS 0x0002
@@ -50,7 +51,12 @@
#define BLUETOOTH_SIGNAL_CONNECTION_RESPONSE 0x03
#define BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST 0x04
#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_RESPONSE 0x0B
#define BLUETOOTH_CONNECTION_SUCCESSFUL 0x0000
#define BLUETOOTH_CONNECTION_REFUSED_RESOURCES 0x0004
@@ -92,10 +98,22 @@
uint16_t Result;
uint16_t Status;
} 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
+ {
+ uint16_t DestinationChannel;
uint16_t Flags;
uint8_t Options[];
} Bluetooth_SignalCommand_ConfigurationRequest_t;
@@ -112,12 +130,18 @@
void Bluetooth_ProcessACLPackets(void);
#if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C)
- static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
- Bluetooth_DataPacket_Header_t* DataHeader,
- Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
- static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
- Bluetooth_DataPacket_Header_t* DataHeader,
- Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
+ static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
+ Bluetooth_DataPacket_Header_t* DataHeader,
+ Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
+ static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
+ Bluetooth_DataPacket_Header_t* DataHeader,
+ 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
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c
index a6e59d648..9d67b70be 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c
@@ -86,23 +86,15 @@ void Bluetooth_ProcessHCICommands(void)
Pipe_Read_Stream_LE(&EventParams, HCIEventHeader.ParameterLength);
Pipe_ClearIN();
- BT_HCI_DEBUG("Event Code: 0x%02X", HCIEventHeader.EventCode);
-
switch (HCIEventHeader.EventCode)
{
case EVENT_COMMAND_COMPLETE:
Bluetooth_HCIProcessingState = Bluetooth_HCINextState;
-
- BT_HCI_DEBUG(">> Command Complete (Opcode 0x%04x)",
- ((Bluetooth_HCIEvent_CommandComplete_t*)&EventParams)->Opcode);
break;
case EVENT_COMMAND_STATUS:
/* If the execution of a command failed, reset the stack */
if (((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status)
Bluetooth_HCIProcessingState = Bluetooth_Init;
-
- BT_HCI_DEBUG(">> Command Status: 0x%02X",
- ((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status);
break;
case EVENT_CONNECTION_REQUEST:
/* Need to store the remote device's BT address in a temporary buffer for later use */
@@ -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
and the user application has indicated that the connection should be allowed */
Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected || !(IsACLConnection) ||
- !(CALLBACK_Bluetooth_ConnectionRequest(Bluetooth_TempDeviceAddress))) ?
+ !(Bluetooth_ConnectionRequest(Bluetooth_TempDeviceAddress))) ?
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;
case EVENT_PIN_CODE_REQUEST:
/* Need to store the remote device's BT address in a temporary buffer for later use */
@@ -129,10 +117,6 @@ void Bluetooth_ProcessHCICommands(void)
sizeof(Bluetooth_TempDeviceAddress));
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;
case EVENT_CONNECTION_COMPLETE:
/* Need to store the remote device's BT address in a temporary buffer for later use */
@@ -143,19 +127,15 @@ void Bluetooth_ProcessHCICommands(void)
/* Store the created connection handle and indicate that the connection has been established */
Bluetooth_Connection.ConnectionHandle = ((Bluetooth_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle;
Bluetooth_Connection.IsConnected = true;
-
- BT_HCI_DEBUG(">> Connection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X, Handle 0x%04x",
- 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);
+
+ Bluetooth_ConnectionComplete();
break;
case EVENT_DISCONNECTION_COMPLETE:
- BT_HCI_DEBUG(">> Disconnection Complete", NULL);
-
/* Device disconnected, indicate connection information no longer valid */
Bluetooth_Connection.IsConnected = false;
+ Bluetooth_DisconnectionComplete();
+
Bluetooth_HCIProcessingState = Bluetooth_Init;
break;
}
@@ -176,8 +156,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_RESET},
ParameterLength: 0,
};
-
- BT_HCI_DEBUG("Enter State: Bluetooth_Init_Reset", NULL);
/* Send the command to reset the bluetooth dongle controller */
Bluetooth_SendHCICommand(NULL, 0);
@@ -192,9 +170,6 @@ void Bluetooth_ProcessHCICommands(void)
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 */
Bluetooth_SendHCICommand(Bluetooth_DeviceConfiguration.Name, strlen(Bluetooth_DeviceConfiguration.Name));
@@ -208,8 +183,6 @@ void Bluetooth_ProcessHCICommands(void)
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 */
Bluetooth_SendHCICommand(&Bluetooth_DeviceConfiguration.Class, 3);
@@ -222,8 +195,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE},
ParameterLength: 1,
};
-
- BT_HCI_DEBUG("Enter State: Bluetooth_Init_WriteScanEnable", NULL);
uint8_t Interval = BT_SCANMODE_InquiryAndPageScans;
@@ -239,8 +210,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST},
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
connection role */
@@ -260,8 +229,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST},
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
to accept the connection due to limited device resources or incorrect device address */
@@ -280,9 +247,6 @@ void Bluetooth_ProcessHCICommands(void)
OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY},
ParameterLength: sizeof(Bluetooth_HCICommand_PinCodeResponse_t),
};
-
- BT_HCI_DEBUG("Enter State: Bluetooth_Conn_SendPINCode", NULL);
- BT_HCI_DEBUG("-- PIN: %s", Bluetooth_DeviceConfiguration.PINCode);
/* Copy over the temporary BT device address saved from the PIN Code Request event, copy over the
local PIN authentication code to the response */
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h
index 317ebc7eb..2295e558c 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h
@@ -42,8 +42,6 @@
#include "BluetoothClassCodes.h"
/* Macros: */
- #define BT_HCI_DEBUG(s, ...) printf_P(PSTR("(HCI) " s "\r\n"), __VA_ARGS__)
-
#define OGF_LINK_CONTROL 0x01
#define OGF_CTRLR_BASEBAND 0x03
#define OGF_CTRLR_INFORMATIONAL 0x04
@@ -193,8 +191,10 @@
void Bluetooth_ProcessHCICommands(void);
void Bluetooth_ProcessHCIEvents(void);
- bool CALLBACK_Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
-
+ bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
+ void Bluetooth_ConnectionComplete(void);
+ void Bluetooth_DisconnectionComplete(void);
+
#if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)
static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);
#endif
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c
index 4e0330e52..5da4d0b16 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c
@@ -54,21 +54,14 @@ void Bluetooth_Stack_USBTask(void)
Bluetooth_ProcessACLPackets();
}
-bool CALLBACK_Bluetooth_ConnectionRequest(uint8_t* RemoteAddress)
-{
- /* Always accept connections from remote devices */
- return true;
-}
-
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource)
{
- Bluetooth_Channel_t* CurrentChannelStructure;
-
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
- CurrentChannelStructure = &Bluetooth_Connection.Channels[i];
+ Bluetooth_Channel_t* CurrentChannelStructure = &Bluetooth_Connection.Channels[i];
- uint16_t CurrentChannelNumber = ((SearchBySource) ? CurrentChannelStructure->RemoteNumber : CurrentChannelStructure->LocalNumber);
+ uint16_t CurrentChannelNumber = (SearchBySource) ? CurrentChannelStructure->RemoteNumber :
+ CurrentChannelStructure->LocalNumber;
if (CurrentChannelNumber == ChannelNumber)
return CurrentChannelStructure;
@@ -79,11 +72,9 @@ Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool Searc
Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM)
{
- Bluetooth_Channel_t* CurrentChannelStructure;
-
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
- CurrentChannelStructure = &Bluetooth_Connection.Channels[i];
+ Bluetooth_Channel_t* CurrentChannelStructure = &Bluetooth_Connection.Channels[i];
if (CurrentChannelStructure->State == Channel_Closed)
{
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h
index b3ac6847e..1cc0d9242 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h
@@ -39,15 +39,15 @@
#include "BluetoothACLPackets.h"
/* Macros: */
- #define BLUETOOTH_DATA_IN_PIPE 1
- #define BLUETOOTH_DATA_OUT_PIPE 2
- #define BLUETOOTH_EVENTS_PIPE 3
+ #define BLUETOOTH_DATA_IN_PIPE 1
+ #define BLUETOOTH_DATA_OUT_PIPE 2
+ #define BLUETOOTH_EVENTS_PIPE 3
#define BLUETOOTH_MAX_OPEN_CHANNELS 2
#define BLUETOOTH_CHANNELNUMBER_BASEOFFSET 0x0040
- #define CHANNEL_LOOKUP_BY_SOURCE true
- #define CHANNEL_LOOKUP_BY_DESTINATION false
+ #define CHANNEL_PSM_SERVICEDISCOVERY 0x0001
+ #define CHANNEL_PSM_RFCOMM 0x0003
/* Enums: */
enum Bluetooth_Channel_State_t