Bluetooth demo can now create and maintain logical channels - need to determine why Windows machines refuse to connect.

pull/1469/head
Dean Camera 15 years ago
parent 2a072db703
commit 797130bddc

@ -123,6 +123,9 @@ static void Bluetooth_ProcessACLPackets(void)
case BT_SIGNAL_CONFIGURATION_REQUEST:
Bluetooth_Signal_ConfigurationReq(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BT_SIGNAL_CONFIGURATION_RESPONSE:
Bluetooth_Signal_ConfigurationResp(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BT_SIGNAL_DISCONNECTION_REQUEST:
Bluetooth_Signal_DisconnectionReq(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
@ -143,7 +146,7 @@ static void Bluetooth_ProcessACLPackets(void)
}
else
{
Bluetooth_PacketReceived(&DataHeader.PayloadLength, Bluetooth_GetChannelData(DataHeader.DestinationChannel, true));
Bluetooth_PacketReceived(&DataHeader.PayloadLength, Bluetooth_GetChannelData(DataHeader.DestinationChannel, false));
Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);
Pipe_Discard_Stream(DataHeader.PayloadLength);
@ -165,7 +168,7 @@ uint8_t Bluetooth_SendPacket(void* Data, uint16_t DataLen, Bluetooth_Channel_t*
// TODO: Add packet fragmentation here after retrieving the device's signal channel MTU
ACLPacketHeader.ConnectionHandle = Bluetooth_Connection.ConnectionHandle | (1 << 13);
ACLPacketHeader.ConnectionHandle = (Bluetooth_Connection.ConnectionHandle | BT_ACL_FIRST_AUTOFLUSH);
ACLPacketHeader.DataLength = sizeof(DataHeader) + DataLen;
DataHeader.PayloadLength = DataLen;
DataHeader.DestinationChannel = (Channel == NULL) ? BT_CHANNEL_SIGNALING : Channel->RemoteNumber;
@ -176,6 +179,7 @@ uint8_t Bluetooth_SendPacket(void* Data, uint16_t DataLen, Bluetooth_Channel_t*
Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));
Pipe_Write_Stream_LE(Data, DataLen);
Pipe_ClearOUT();
Pipe_Freeze();
@ -216,8 +220,8 @@ static inline void Bluetooth_Signal_ConnectionReq(BT_ACL_Header_t* ACLPacketHead
ResponsePacket.SignalCommandHeader.Identifier = SignalCommandHeader->Identifier;
ResponsePacket.SignalCommandHeader.Length = sizeof(ResponsePacket.ConnectionResponse);
ResponsePacket.ConnectionResponse.Result = (ChannelData == NULL) ? BT_CONNECTION_REFUSED_RESOURCES : BT_CONNECTION_SUCCESSFUL;
ResponsePacket.ConnectionResponse.DestinationChannel = ChannelData->LocalNumber;
ResponsePacket.ConnectionResponse.SourceChannel = ChannelData->RemoteNumber;
ResponsePacket.ConnectionResponse.DestinationChannel = ChannelData->RemoteNumber;
ResponsePacket.ConnectionResponse.SourceChannel = ChannelData->LocalNumber;
ResponsePacket.ConnectionResponse.Status = 0x00;
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), NULL);
@ -259,7 +263,7 @@ static inline void Bluetooth_Signal_ConfigurationReq(BT_ACL_Header_t* ACLPacketH
BT_ACL_DEBUG(1, "<< L2CAP Configuration Request", NULL);
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);
BT_ACL_DEBUG(2, "-- Options Len: 0x%04X", ConfigurationRequest.DestinationChannel);
BT_ACL_DEBUG(2, "-- Options Len: 0x%04X", (DataHeader->PayloadLength - sizeof(*SignalCommandHeader)));
BT_ACL_DEBUG(2, "-- Remote MTU: 0x%04X", ChannelData->RemoteMTU);
struct
@ -298,6 +302,40 @@ static inline void Bluetooth_Signal_ConfigurationReq(BT_ACL_Header_t* ACLPacketH
BT_ACL_DEBUG(2, "-- Result: 0x%02X", ResponsePacket.ConfigurationResponse.Result);
}
static inline void Bluetooth_Signal_ConfigurationResp(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader)
{
BT_Signal_ConfigurationResp_t ConfigurationResponse;
Pipe_Read_Stream_LE(&ConfigurationResponse, sizeof(ConfigurationResponse));
Pipe_ClearIN();
Pipe_Freeze();
BT_ACL_DEBUG(1, "<< L2CAP Configuration Response", NULL);
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConfigurationResponse.SourceChannel);
BT_ACL_DEBUG(2, "-- Result: 0x%02X", ConfigurationResponse.Result);
if (ConfigurationResponse.Result == BT_CONFIGURATION_SUCCESSFUL)
{
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationResponse.SourceChannel, true);
if (ChannelData != NULL)
{
switch (ChannelData->State)
{
case Channel_Config_WaitReqResp:
ChannelData->State = Channel_Config_WaitReq;
break;
case Channel_Config_WaitResp:
ChannelData->State = Channel_Open;
break;
}
}
}
}
static inline void Bluetooth_Signal_DisconnectionReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader)
@ -324,8 +362,8 @@ static inline void Bluetooth_Signal_DisconnectionReq(BT_ACL_Header_t* ACLPacketH
ResponsePacket.SignalCommandHeader.Code = BT_SIGNAL_DISCONNECTION_RESPONSE;
ResponsePacket.SignalCommandHeader.Identifier = SignalCommandHeader->Identifier;
ResponsePacket.SignalCommandHeader.Length = sizeof(ResponsePacket.DisconnectionResponse);
ResponsePacket.DisconnectionResponse.DestinationChannel = ChannelData->LocalNumber;
ResponsePacket.DisconnectionResponse.SourceChannel = ChannelData->RemoteNumber;
ResponsePacket.DisconnectionResponse.DestinationChannel = ChannelData->RemoteNumber;
ResponsePacket.DisconnectionResponse.SourceChannel = ChannelData->LocalNumber;
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), NULL);

@ -73,6 +73,8 @@
#define BT_CONFIG_OPTION_MTU 1
#define BT_ACL_FIRST_AUTOFLUSH (1 << 13)
/* Type Defines: */
typedef struct
{
@ -146,7 +148,7 @@
typedef struct
{
uint8_t Type;
uint16_t Length;
uint8_t Length;
} BT_Config_Option_Header_t;
/* Function Prototypes: */
@ -164,6 +166,9 @@
static inline void Bluetooth_Signal_ConfigurationReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_ConfigurationResp(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_DisconnectionReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);

@ -54,13 +54,13 @@ void Bluetooth_Stack_USBTask(void)
Bluetooth_ACLTask();
}
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource)
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchByRemoteChannel)
{
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i];
uint16_t CurrentChannelNumber = (SearchBySource) ? ChannelData->RemoteNumber : ChannelData->LocalNumber;
uint16_t CurrentChannelNumber = (SearchByRemoteChannel) ? ChannelData->RemoteNumber : ChannelData->LocalNumber;
if (CurrentChannelNumber == ChannelNumber)
return ChannelData;
@ -70,22 +70,29 @@ Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool Searc
}
Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM)
{
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(RemoteChannelNumber, false);
if (ChannelData == NULL)
{
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i];
if (Bluetooth_Connection.Channels[i].State == Channel_Closed)
{
ChannelData = &Bluetooth_Connection.Channels[i];
ChannelData->LocalNumber = (BLUETOOTH_CHANNELNUMBER_BASEOFFSET + i);
break;
}
}
}
if (ChannelData->State == Channel_Closed)
if (ChannelData != NULL)
{
ChannelData->RemoteNumber = RemoteChannelNumber;
ChannelData->LocalNumber = (BLUETOOTH_CHANNELNUMBER_BASEOFFSET + i);
ChannelData->PSM = PSM;
ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;
ChannelData->State = Channel_Config_WaitConfig;
return ChannelData;
}
}
return NULL;
return ChannelData;
}

@ -103,7 +103,7 @@
#include "BluetoothACLPackets.h"
/* Function Prototypes: */
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource);
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchByRemoteChannel);
Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM);
void Bluetooth_Stack_Init(void);

@ -8,7 +8,7 @@
* \mainpage
*
* \image html LUFA.png
* <div align="center"><small><i>Logo design by <b>Ryo Yamauchi</b></i></small></div>
* <div align="center"><small><i>Logo design by <b>Ryo</b> - http://ryophotography.wordpress.com</i></small></div>
* \n
*
* <b>LUFA is donationware. For author and donation information, see \ref Page_Donating.</b>

Loading…
Cancel
Save