Add user callback function to the Bluetooth host demo to filter out connections from remote devices. Add in ability to reject connections based on their bluetooth device address.

Clean up RelayBoard project code.

Make AVRISP project clear the XMEGA target's reset register twice; this does not appear to take affect properly the first time under some circumstances.
pull/1469/head
Dean Camera 15 years ago
parent fd96b28882
commit fa1a092901

@ -36,13 +36,6 @@
#include "BluetoothHost.h"
Bluetooth_Device_t Bluetooth_DeviceConfiguration =
{
Class: (DEVICE_CLASS_SERVICE_CAPTURING | DEVICE_CLASS_MAJOR_COMPUTER | DEVICE_CLASS_MINOR_COMPUTER_PALM),
PINCode: "0000",
Name: "LUFA Bluetooth Demo"
};
/** Main program entry point. This routine configures the hardware required by the application, then
* enters a loop to run the application tasks in sequence.
*/
@ -56,7 +49,7 @@ int main(void)
for (;;)
{
Bluetooth_Stack_Task();
Bluetooth_Stack_USBTask();
Bluetooth_Host_Task();
USB_USBTask();
}
@ -196,7 +189,7 @@ void Bluetooth_Host_Task(void)
puts_P(PSTR("Bluetooth Dongle Enumerated.\r\n"));
/* Initialize the Bluetooth stack */
Bluetooth_State_Init();
Bluetooth_Stack_Init();
USB_HostState = HOST_STATE_Configured;
break;

@ -109,10 +109,13 @@ void Bluetooth_ProcessHCICommands(void)
memcpy(Bluetooth_TempDeviceAddress,
&((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->RemoteAddress,
sizeof(Bluetooth_TempDeviceAddress));
/* Only accept the connection if it is a ACL (data) connection */
Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected ||
(((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType != 0x01)) ?
bool IsACLConnection = (((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType == 0x01);
/* 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_Conn_RejectConnection : Bluetooth_Conn_AcceptConnection;
BT_HCI_DEBUG(">> Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X",
@ -261,10 +264,10 @@ void Bluetooth_ProcessHCICommands(void)
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 */
to accept the connection due to limited device resources or incorrect device address */
Bluetooth_HCICommand_RejectConnectionRequest_t RejectConnectionParams;
memcpy(RejectConnectionParams.RemoteAddress, Bluetooth_TempDeviceAddress, sizeof(RejectConnectionParams.RemoteAddress));
RejectConnectionParams.Reason = ERROR_LIMITED_RESOURCES;
RejectConnectionParams.Reason = Bluetooth_Connection.IsConnected ? ERROR_LIMITED_RESOURCES : ERROR_UNACCEPTABLE_BDADDR;
/* Send the command to reject the remote connection request */
Bluetooth_SendHCICommand(&RejectConnectionParams, sizeof(Bluetooth_HCICommand_RejectConnectionRequest_t));

@ -83,6 +83,7 @@
#define EVENT_PIN_CODE_REQUEST 0x16
#define ERROR_LIMITED_RESOURCES 0x0D
#define ERROR_UNACCEPTABLE_BDADDR 0x0F
/* Type Defines: */
typedef struct
@ -191,6 +192,8 @@
/* Function Prototypes: */
void Bluetooth_ProcessHCICommands(void);
void Bluetooth_ProcessHCIEvents(void);
bool CALLBACK_Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
#if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)
static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);

@ -30,26 +30,36 @@
#include "BluetoothStack.h"
/** Bluetooth device connection information structure. Once connected to a remote device, this structure tracks the
* connection state of the individual L2CAP channels.
*/
Bluetooth_Connection_t Bluetooth_Connection = {IsConnected: false};
Bluetooth_Device_t Bluetooth_DeviceConfiguration ATTR_WEAK =
/** Bluetooth configuration structure. This structure configures the bluetooth stack's user alterable settings. */
Bluetooth_Device_t Bluetooth_DeviceConfiguration =
{
Class: DEVICE_CLASS_MAJOR_MISC,
Class: (DEVICE_CLASS_SERVICE_CAPTURING | DEVICE_CLASS_MAJOR_COMPUTER | DEVICE_CLASS_MINOR_COMPUTER_PALM),
PINCode: "0000",
Name: "LUFA BT Device"
Name: "LUFA Bluetooth Demo"
};
void Bluetooth_State_Init(void)
void Bluetooth_Stack_Init(void)
{
Bluetooth_HCIProcessingState = Bluetooth_Init;
}
void Bluetooth_Stack_Task(void)
void Bluetooth_Stack_USBTask(void)
{
Bluetooth_ProcessHCICommands();
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;

@ -89,8 +89,8 @@
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource);
Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM);
void Bluetooth_State_Init(void);
void Bluetooth_Stack_Task(void);
void Bluetooth_Stack_Init(void);
void Bluetooth_Stack_USBTask(void);
/* External Variables: */
extern Bluetooth_Device_t Bluetooth_DeviceConfiguration;

@ -11,6 +11,7 @@
* Project Homepage: http://www.fourwalledcubicle.com/LUFA.php \n
* Author's Website: http://www.fourwalledcubicle.com \n
* Development Blog: http://www.fourwalledcubicle.com/blog \n
* Commercial Licences: http://fourwalledcubicle.com/PurchaseLUFA.php \n
*
* \section Sec_ProjectHelp Assistance With LUFA
* Discussion Group: http://groups.google.com/group/myusb-support-list \n

@ -42,7 +42,7 @@
#include <LUFA/Drivers/USB/USB.h>
/* Macros: */
#if !defined(WIN_LIBUSB_COMPAT)
#if !defined(LIBUSB_FILTERDRV_COMPAT)
/** Endpoint number of the AVRISP data OUT endpoint. */
#define AVRISP_DATA_OUT_EPNUM 2

@ -179,6 +179,10 @@ static void XPROGProtocol_LeaveXPROGMode(void)
XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);
XPROGTarget_SendByte(0x00);
/* Do it twice to make sure it takes affect (silicon bug?) */
XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);
XPROGTarget_SendByte(0x00);
XPROGTarget_DisableTargetPDI();
}
else

@ -77,8 +77,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
/** Event handler for the library USB Unhandled Control Packet event. */
void EVENT_USB_Device_UnhandledControlRequest(void)
{
const uint8_t serial[5] = { 0, 0, 0, 0, 1 };
uint8_t data[2] = { 0, 0 };
const uint8_t SerialNumber[5] = { 0, 0, 0, 0, 1 };
uint8_t ControlData[2] = { 0, 0 };
switch (USB_ControlRequest.bRequest)
{
@ -89,20 +89,22 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
Endpoint_ClearSETUP();
Endpoint_Read_Control_Stream_LE(data, sizeof(data));
Endpoint_Read_Control_Stream_LE(ControlData, sizeof(ControlData));
Endpoint_ClearIN();
switch (USB_ControlRequest.wValue)
{
case 0x303:
if (data[1]) PORTC &= ~RELAY1; else PORTC |= RELAY1; break;
if (ControlData[1]) PORTC &= ~RELAY1; else PORTC |= RELAY1;
break;
case 0x306:
if (data[1]) PORTC &= ~RELAY2; else PORTC |= RELAY2; break;
if (ControlData[1]) PORTC &= ~RELAY2; else PORTC |= RELAY2;
break;
case 0x309:
if (data[1]) PORTC &= ~RELAY3; else PORTC |= RELAY3; break;
if (ControlData[1]) PORTC &= ~RELAY3; else PORTC |= RELAY3;
break;
case 0x30c:
if (data[1]) PORTC &= ~RELAY4; else PORTC |= RELAY4; break;
default:
if (ControlData[1]) PORTC &= ~RELAY4; else PORTC |= RELAY4;
break;
}
}
@ -118,22 +120,24 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
switch (USB_ControlRequest.wValue)
{
case 0x301:
Endpoint_Write_Control_Stream_LE(serial, sizeof(serial));
Endpoint_Write_Control_Stream_LE(SerialNumber, sizeof(SerialNumber));
break;
case 0x303:
if (PORTC & RELAY1) data[1] = 2; else data[1] = 3; break;
ControlData[1] = (PORTC & RELAY1) ? 2 : 3;
break;
case 0x306:
if (PORTC & RELAY2) data[1] = 2; else data[1] = 3; break;
ControlData[1] = (PORTC & RELAY2) ? 2 : 3;
break;
case 0x309:
if (PORTC & RELAY3) data[1] = 2; else data[1] = 3; break;
ControlData[1] = (PORTC & RELAY3) ? 2 : 3;
break;
case 0x30c:
if (PORTC & RELAY4) data[1] = 2; else data[1] = 3; break;
default:
ControlData[1] = (PORTC & RELAY4) ? 2 : 3;
break;
}
if (data[1])
Endpoint_Write_Control_Stream_LE(data, sizeof(data));
if (ControlData[1])
Endpoint_Write_Control_Stream_LE(ControlData, sizeof(ControlData));
Endpoint_ClearOUT();
}

Loading…
Cancel
Save