Add information request/response signal handler to the Bluetooth Host demo.

Ensure that the AVRISP-MKII project's Windows avrdude compatibility define is named properly in all parts of the code.
pull/1469/head
Dean Camera 15 years ago
parent 083d797aca
commit ee74b4948f

@ -56,35 +56,33 @@ void Bluetooth_ProcessACLPackets(void)
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader.PayloadLength);
#endif
if (DataHeader.DestinationChannel == BLUETOOTH_CHANNEL_SIGNALING)
if (DataHeader.DestinationChannel == BT_CHANNEL_SIGNALING)
{
Bluetooth_SignalCommand_Header_t SignalCommandHeader;
Pipe_Read_Stream_LE(&SignalCommandHeader, sizeof(SignalCommandHeader));
switch (SignalCommandHeader.Code)
{
case BLUETOOTH_SIGNAL_CONNECTION_REQUEST:
case BT_SIGNAL_CONNECTION_REQUEST:
Bluetooth_SignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST:
case BT_SIGNAL_CONFIGURATION_REQUEST:
Bluetooth_SignalPacket_ConfigurationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BLUETOOTH_SIGNAL_DISCONNECTION_REQUEST:
case BT_SIGNAL_DISCONNECTION_REQUEST:
Bluetooth_SignalPacket_DisconnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BLUETOOTH_SIGNAL_ECHO_REQUEST:
case BT_SIGNAL_ECHO_REQUEST:
Bluetooth_SignalPacket_EchoRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
case BLUETOOTH_SIGNAL_INFORMATION_REQUEST:
BT_ACL_DEBUG("<< Information Request", NULL);
Pipe_Discard_Stream(ACLPacketHeader.DataLength);
Pipe_ClearIN();
Pipe_Freeze();
case BT_SIGNAL_INFORMATION_REQUEST:
Bluetooth_SignalPacket_InformationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);
break;
default:
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG("<< Unknown Signaling Command 0x%02X", SignalCommandHeader.Code);
#endif
Pipe_Discard_Stream(ACLPacketHeader.DataLength);
Pipe_ClearIN();
Pipe_Freeze();
@ -116,7 +114,9 @@ static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header
Pipe_Read_Stream_LE(&ConnectionRequest, sizeof(ConnectionRequest));
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG("<< L2CAP Connection Request", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- PSM: 0x%04X", ConnectionRequest.PSM);
BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);
@ -131,14 +131,13 @@ static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header
ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);
DataHeader->PayloadLength = sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);
DataHeader->DestinationChannel = BLUETOOTH_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BLUETOOTH_SIGNAL_CONNECTION_RESPONSE;
DataHeader->DestinationChannel = BT_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BT_SIGNAL_CONNECTION_RESPONSE;
SignalCommandHeader->Length = sizeof(ConnectionResponse);
Bluetooth_Channel_t* ChannelData = Bluetooth_InitChannelData(ConnectionRequest.SourceChannel, ConnectionRequest.PSM);
ConnectionResponse.Result = (ChannelData == NULL) ? BLUETOOTH_CONNECTION_REFUSED_RESOURCES :
BLUETOOTH_CONNECTION_SUCCESSFUL;
ConnectionResponse.Result = (ChannelData == NULL) ? BT_CONNECTION_REFUSED_RESOURCES : BT_CONNECTION_SUCCESSFUL;
ConnectionResponse.DestinationChannel = ChannelData->LocalNumber;
ConnectionResponse.SourceChannel = ChannelData->RemoteNumber;
ConnectionResponse.Status = 0x00;
@ -158,7 +157,9 @@ static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG(">> L2CAP Connection Response", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionResponse.SourceChannel);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel);
@ -170,10 +171,13 @@ static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Hea
Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
{
Bluetooth_SignalCommand_ConfigurationRequest_t ConfigurationRequest;
Pipe_Read_Stream_LE(&ConfigurationRequest, sizeof(ConfigurationRequest));
// TODO: Process/Discard configuration options here
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG("<< L2CAP Configuration Request", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);
#endif
@ -187,8 +191,8 @@ static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Hea
ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);
DataHeader->PayloadLength = sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);
DataHeader->DestinationChannel = BLUETOOTH_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE;
DataHeader->DestinationChannel = BT_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BT_SIGNAL_CONFIGURATION_RESPONSE;
SignalCommandHeader->Length = sizeof(ConfigurationResponse);
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, false);
@ -200,7 +204,7 @@ static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Hea
ConfigurationResponse.SourceChannel = ChannelData->RemoteNumber;
ConfigurationResponse.Flags = 0x00;
ConfigurationResponse.Result = (ChannelData != NULL) ? BLUETOOTH_CONFIGURATION_SUCCESSFUL : BLUETOOTH_CONFIGURATION_REJECTED;
ConfigurationResponse.Result = (ChannelData != NULL) ? BT_CONFIGURATION_SUCCESSFUL : BT_CONFIGURATION_REJECTED;
Pipe_Write_Stream_LE(ACLPacketHeader, sizeof(*ACLPacketHeader));
Pipe_Write_Stream_LE(DataHeader, sizeof(*DataHeader));
@ -217,7 +221,12 @@ static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Hea
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG(">> L2CAP Configuration Response", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Result: 0x%02X", ConfigurationResponse.Result);
#endif
}
static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
@ -228,7 +237,9 @@ static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Hea
Pipe_Read_Stream_LE(&DisconnectionRequest, sizeof(DisconnectionRequest));
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG("<< L2CAP Disconnection Request", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DisconnectionRequest.DestinationChannel);
BT_ACL_DEBUG("-- Source Channel: 0x%04X", DisconnectionRequest.SourceChannel);
@ -243,8 +254,8 @@ static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Hea
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;
DataHeader->DestinationChannel = BT_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BT_SIGNAL_DISCONNECTION_RESPONSE;
SignalCommandHeader->Length = sizeof(DisconnectionResponse);
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(DisconnectionRequest.SourceChannel, true);
@ -270,7 +281,9 @@ static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Hea
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG(">> L2CAP Disconnection Response", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Source Channel: 0x%04X", DisconnectionResponse.SourceChannel);
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DisconnectionResponse.DestinationChannel);
@ -281,7 +294,9 @@ static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* AC
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
{
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG("<< L2CAP Echo Request", NULL);
#endif
Pipe_ClearIN();
Pipe_Freeze();
@ -290,8 +305,8 @@ static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* AC
ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader);
DataHeader->PayloadLength = sizeof(*SignalCommandHeader);
DataHeader->DestinationChannel = BLUETOOTH_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BLUETOOTH_SIGNAL_ECHO_RESPONSE;
DataHeader->DestinationChannel = BT_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BT_SIGNAL_ECHO_RESPONSE;
SignalCommandHeader->Length = 0;
Pipe_Write_Stream_LE(ACLPacketHeader, sizeof(*ACLPacketHeader));
@ -308,5 +323,82 @@ static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* AC
BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);
BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);
#endif
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG(">> L2CAP Echo Response", NULL);
#endif
}
static inline void Bluetooth_SignalPacket_InformationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader)
{
Bluetooth_SignalCommand_InformationRequest_t InformationRequest;
Pipe_Read_Stream_LE(&InformationRequest, sizeof(InformationRequest));
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG("<< Information Request", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Info Type: 0x%04X", InformationRequest.InfoType);
#endif
Pipe_ClearIN();
Pipe_Freeze();
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
Pipe_Unfreeze();
Bluetooth_SignalCommand_InformationResponse_t InformationResponse;
uint8_t ResponseData[4];
uint8_t ResponseLen;
switch (InformationRequest.InfoType)
{
case BT_INFOREQ_MTU:
InformationResponse.Result = BT_INFORMATION_SUCCESSFUL;
ResponseLen = 2;
*((uint16_t*)&ResponseData) = 65533;
break;
case BT_INFOREQ_EXTENDEDFEATURES:
InformationResponse.Result = BT_INFORMATION_SUCCESSFUL;
ResponseLen = 4;
*((uint32_t*)&ResponseData) = 0;
break;
default:
InformationResponse.Result = BT_INFORMATION_NOTSUPPORTED;
ResponseLen = 0;
break;
}
ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(InformationResponse) +
ResponseLen;
DataHeader->PayloadLength = sizeof(*SignalCommandHeader) + sizeof(InformationResponse) + ResponseLen;
DataHeader->DestinationChannel = BT_CHANNEL_SIGNALING;
SignalCommandHeader->Code = BT_SIGNAL_INFORMATION_RESPONSE;
SignalCommandHeader->Length = sizeof(InformationResponse) + ResponseLen;
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(&InformationResponse, sizeof(InformationResponse));
Pipe_Write_Stream_LE(ResponseData, ResponseLen);
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
#if (ACL_DEBUG_LEVEL > 0)
BT_ACL_DEBUG(">> L2CAP Information Response", NULL);
#endif
#if (ACL_DEBUG_LEVEL > 1)
BT_ACL_DEBUG("-- Result: 0x%02X", InformationResponse.Result);
#endif
}

@ -41,29 +41,35 @@
#include "BluetoothStack.h"
/* Macros: */
#define BT_ACL_DEBUG(s, ...) printf_P(PSTR("(ACL) " s "\r\n"), __VA_ARGS__)
#define ACL_DEBUG_LEVEL 1
#define BT_ACL_DEBUG(s, ...) printf_P(PSTR("(ACL) " s "\r\n"), __VA_ARGS__)
#define ACL_DEBUG_LEVEL 2
#define BLUETOOTH_CHANNEL_SIGNALING 0x0001
#define BLUETOOTH_CHANNEL_CONNECTIONLESS 0x0002
#define BT_CHANNEL_SIGNALING 0x0001
#define BT_CHANNEL_CONNECTIONLESS 0x0002
#define BLUETOOTH_SIGNAL_CONNECTION_REQUEST 0x02
#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 BT_SIGNAL_CONNECTION_REQUEST 0x02
#define BT_SIGNAL_CONNECTION_RESPONSE 0x03
#define BT_SIGNAL_CONFIGURATION_REQUEST 0x04
#define BT_SIGNAL_CONFIGURATION_RESPONSE 0x05
#define BT_SIGNAL_DISCONNECTION_REQUEST 0x06
#define BT_SIGNAL_DISCONNECTION_RESPONSE 0x07
#define BT_SIGNAL_ECHO_REQUEST 0x08
#define BT_SIGNAL_ECHO_RESPONSE 0x09
#define BT_SIGNAL_INFORMATION_REQUEST 0x0A
#define BT_SIGNAL_INFORMATION_RESPONSE 0x0B
#define BLUETOOTH_CONNECTION_SUCCESSFUL 0x0000
#define BLUETOOTH_CONNECTION_REFUSED_RESOURCES 0x0004
#define BT_INFOREQ_MTU 0x0001
#define BT_INFOREQ_EXTENDEDFEATURES 0x0002
#define BLUETOOTH_CONFIGURATION_SUCCESSFUL 0x0000
#define BLUETOOTH_CONFIGURATION_REJECTED 0x0002
#define BLUETOOTH_CONFIGURATION_UNKNOWNOPTIONS 0x0003
#define BT_INFORMATION_SUCCESSFUL 0x0000
#define BT_INFORMATION_NOTSUPPORTED 0x0001
#define BT_CONNECTION_SUCCESSFUL 0x0000
#define BT_CONNECTION_REFUSED_RESOURCES 0x0004
#define BT_CONFIGURATION_SUCCESSFUL 0x0000
#define BT_CONFIGURATION_REJECTED 0x0002
#define BT_CONFIGURATION_UNKNOWNOPTIONS 0x0003
/* Type Defines: */
typedef struct
@ -115,7 +121,6 @@
{
uint16_t DestinationChannel;
uint16_t Flags;
uint8_t Options[];
} Bluetooth_SignalCommand_ConfigurationRequest_t;
typedef struct
@ -123,9 +128,19 @@
uint16_t SourceChannel;
uint16_t Flags;
uint16_t Result;
uint8_t Config;
} Bluetooth_SignalCommand_ConfigurationResponse_t;
typedef struct
{
uint16_t InfoType;
} Bluetooth_SignalCommand_InformationRequest_t;
typedef struct
{
uint16_t InfoType;
uint16_t Result;
} Bluetooth_SignalCommand_InformationResponse_t;
/* Function Prototypes: */
void Bluetooth_ProcessACLPackets(void);
@ -142,6 +157,9 @@
static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
static inline void Bluetooth_SignalPacket_InformationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,
Bluetooth_DataPacket_Header_t* DataHeader,
Bluetooth_SignalCommand_Header_t* SignalCommandHeader);
#endif
#endif

@ -24,7 +24,7 @@
* - Standardized the naming scheme given to configuration descriptor sub-elements in the Device mode demos, bootloaders
* and projects
* - All Class Driver Host mode demos now correctly set the board LEDs to READY once the enumeration process has completed
* - Added WIN_LIBUSB_COMPAT compile time option to the AVRISP programmer project to make the code compatible with Windows
* - Added LIBUSB_FILTERDRV_COMPAT compile time option to the AVRISP programmer project to make the code compatible with Windows
* builds of avrdude at the expense of AVRStudio compatibility
*
* <b>Fixed:</b>

@ -97,7 +97,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
#if defined(WIN_LIBUSB_COMPAT)
#if defined(LIBUSB_FILTERDRV_COMPAT)
if (!(Endpoint_ConfigureEndpoint(AVRISP_DATA_IN_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_IN, AVRISP_DATA_EPSIZE,
ENDPOINT_BANK_SINGLE)))

@ -274,7 +274,7 @@
* to report a fixed 5V target voltage to the host regardless of the real target voltage.</td>
* </tr>
* <tr>
* <td>WIN_LIBUSB_COMPAT</td>
* <td>LIBUSB_FILTERDRV_COMPAT</td>
* <td>Makefile CDEFS</td>
* <td>Define to switch to a non-standard endpoint scheme, breaking compatibility with AVRStudio under Windows but making
* the code compatible with Windows builds of avrdude using the libUSB driver. Linux platforms are not affected by this

@ -199,7 +199,7 @@ CDEFS += -DENABLE_ISP_PROTOCOL
CDEFS += -DENABLE_XPROG_PROTOCOL
#CDEFS += -DXPROG_VIA_HARDWARE_USART
#CDEFS += -DNO_VTARGET_DETECT
#CDEFS += -DWIN_LIBUSB_COMPAT
#CDEFS += -DLIBUSB_FILTERDRV_COMPAT
# Place -D or -U options here for ASM sources

@ -191,7 +191,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
ENDPOINT_DIR_OUT, AVRISP_DATA_EPSIZE,
ENDPOINT_BANK_SINGLE);
#if defined(WIN_LIBUSB_COMPAT)
#if defined(LIBUSB_FILTERDRV_COMPAT)
EndpointConfigSuccess &= Endpoint_ConfigureEndpoint(AVRISP_DATA_IN_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_IN, AVRISP_DATA_EPSIZE,
ENDPOINT_BANK_SINGLE);

@ -79,7 +79,7 @@
* <td>Defines the maximum number of bytes which can be buffered in each Ring Buffer.</td>
* </tr>
* <tr>
* <td>WIN_LIBUSB_COMPAT</td>
* <td>LIBUSB_FILTERDRV_COMPAT</td>
* <td>Makefile CDEFS</td>
* <td>Define to switch to a non-standard endpoint scheme, breaking compatibility with AVRStudio under Windows but making
* the code compatible with Windows builds of avrdude using the libUSB driver. Linux platforms are not affected by this

Loading…
Cancel
Save