forked from mfulz_github/qmk_firmware
		
	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.
This commit is contained in:
		
							parent
							
								
									fa1a092901
								
							
						
					
					
						commit
						083d797aca
					
				@ -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)
 | 
				
			|||||||
	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)
 | 
				
			|||||||
		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,7 +108,7 @@ 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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -108,9 +116,11 @@ static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	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,17 +151,21 @@ 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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -159,8 +173,10 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	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_
 | 
				
			|||||||
	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;
 | 
				
			||||||
@ -194,10 +210,103 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
 | 
				
			|||||||
	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 @@
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
	/* 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 @@
 | 
				
			|||||||
		#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
 | 
				
			||||||
@ -93,6 +99,18 @@
 | 
				
			|||||||
			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,10 +130,16 @@
 | 
				
			|||||||
		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_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_DataPacket_Header_t* DataHeader,
 | 
				
			||||||
                                                                  Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
 | 
					                                                                  Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
 | 
				
			||||||
		#endif
 | 
							#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
				
			|||||||
						/* 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)
 | 
				
			|||||||
						       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 */
 | 
				
			||||||
@ -144,18 +128,14 @@ void Bluetooth_ProcessHCICommands(void)
 | 
				
			|||||||
						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;					
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@ -177,8 +157,6 @@ void Bluetooth_ProcessHCICommands(void)
 | 
				
			|||||||
				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)
 | 
				
			|||||||
					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)
 | 
				
			|||||||
					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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -223,8 +196,6 @@ void Bluetooth_ProcessHCICommands(void)
 | 
				
			|||||||
				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;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			/* Send the command to set the remote device scanning mode */
 | 
								/* Send the command to set the remote device scanning mode */
 | 
				
			||||||
@ -240,8 +211,6 @@ void Bluetooth_ProcessHCICommands(void)
 | 
				
			|||||||
					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 */
 | 
				
			||||||
			Bluetooth_HCICommand_AcceptConnectionRequest_t AcceptConnectionParams;
 | 
								Bluetooth_HCICommand_AcceptConnectionRequest_t AcceptConnectionParams;
 | 
				
			||||||
@ -261,8 +230,6 @@ void Bluetooth_ProcessHCICommands(void)
 | 
				
			|||||||
					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 */
 | 
				
			||||||
			Bluetooth_HCICommand_RejectConnectionRequest_t RejectConnectionParams;
 | 
								Bluetooth_HCICommand_RejectConnectionRequest_t RejectConnectionParams;
 | 
				
			||||||
@ -281,9 +248,6 @@ void Bluetooth_ProcessHCICommands(void)
 | 
				
			|||||||
					ParameterLength: sizeof(Bluetooth_HCICommand_PinCodeResponse_t),
 | 
										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
 | 
								/* Copy over the temporary BT device address saved from the PIN Code Request event, copy over the
 | 
				
			||||||
			   local PIN authentication code to the response */
 | 
								   local PIN authentication code to the response */
 | 
				
			||||||
			Bluetooth_HCICommand_PinCodeResponse_t PINCodeRequestParams;
 | 
								Bluetooth_HCICommand_PinCodeResponse_t PINCodeRequestParams;
 | 
				
			||||||
 | 
				
			|||||||
@ -42,8 +42,6 @@
 | 
				
			|||||||
		#include "BluetoothClassCodes.h"
 | 
							#include "BluetoothClassCodes.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Macros: */
 | 
						/* Macros: */
 | 
				
			||||||
		#define BT_HCI_DEBUG(s, ...)                           printf_P(PSTR("(HCI) " s "\r\n"), __VA_ARGS__)
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
		#define OGF_LINK_CONTROL                               0x01
 | 
							#define OGF_LINK_CONTROL                               0x01
 | 
				
			||||||
		#define OGF_CTRLR_BASEBAND                             0x03
 | 
							#define OGF_CTRLR_BASEBAND                             0x03
 | 
				
			||||||
		#define OGF_CTRLR_INFORMATIONAL                        0x04
 | 
							#define OGF_CTRLR_INFORMATIONAL                        0x04
 | 
				
			||||||
@ -193,7 +191,9 @@
 | 
				
			|||||||
		void Bluetooth_ProcessHCICommands(void);
 | 
							void Bluetooth_ProcessHCICommands(void);
 | 
				
			||||||
		void Bluetooth_ProcessHCIEvents(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)
 | 
							#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);
 | 
				
			||||||
 | 
				
			|||||||
@ -54,21 +54,14 @@ void Bluetooth_Stack_USBTask(void)
 | 
				
			|||||||
	Bluetooth_ProcessACLPackets();
 | 
						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* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Bluetooth_Channel_t* CurrentChannelStructure;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
 | 
						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)
 | 
							if (CurrentChannelNumber == ChannelNumber)
 | 
				
			||||||
		  return CurrentChannelStructure;
 | 
							  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* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Bluetooth_Channel_t* CurrentChannelStructure;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
 | 
						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)
 | 
							if (CurrentChannelStructure->State == Channel_Closed)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
@ -46,8 +46,8 @@
 | 
				
			|||||||
		#define BLUETOOTH_MAX_OPEN_CHANNELS              2
 | 
							#define BLUETOOTH_MAX_OPEN_CHANNELS              2
 | 
				
			||||||
		#define BLUETOOTH_CHANNELNUMBER_BASEOFFSET       0x0040
 | 
							#define BLUETOOTH_CHANNELNUMBER_BASEOFFSET       0x0040
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		#define CHANNEL_LOOKUP_BY_SOURCE                 true
 | 
							#define CHANNEL_PSM_SERVICEDISCOVERY             0x0001
 | 
				
			||||||
		#define CHANNEL_LOOKUP_BY_DESTINATION            false
 | 
							#define CHANNEL_PSM_RFCOMM                       0x0003
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	/* Enums: */
 | 
						/* Enums: */
 | 
				
			||||||
		enum Bluetooth_Channel_State_t
 | 
							enum Bluetooth_Channel_State_t
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user