diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c index 312d7166e1ea92d21f6fc2a7c0b1546f0c8c1639..338997fc73a0f703f8fb776ca55dc6af143fb0bd 100644 --- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c +++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c @@ -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; diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c index dd2a3e5cfc721290e68abb6ebc53c0005a76a98c..a6e59d64835b4c2f44a23d4dd9cac70b6d5bf3ed 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c @@ -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)); diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h index 4df5861cfdd9d46a3ff985eb3d24b8c5df623b55..317ebc7eb98e7df751d5d1f2b98b19abc66031ce 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h @@ -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); diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c index 7f49fc979a58de8752ff4f25181eb80b6af98b89..4e0330e527a15ab33fe83e2a4d329177db52857b 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c @@ -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; diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h index 20bc9569627d05b54a3a8299ca743c89b8a5398e..b3ac6847e03acf96e07ae6af7ce33994d7781e21 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h @@ -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; diff --git a/LUFA/ManPages/LibraryResources.txt b/LUFA/ManPages/LibraryResources.txt index 436d0ec354815a59a14857d59b1fd7121076cd23..f189d0a97fca8ba09157effdf7827761ad6379e0 100644 --- a/LUFA/ManPages/LibraryResources.txt +++ b/LUFA/ManPages/LibraryResources.txt @@ -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 diff --git a/Projects/AVRISP-MKII/Descriptors.h b/Projects/AVRISP-MKII/Descriptors.h index 9f6a4120898fb8aa9ba19db42833f010470b7a8d..3a48283641d6d5b60585ba5b70d37f610497c044 100644 --- a/Projects/AVRISP-MKII/Descriptors.h +++ b/Projects/AVRISP-MKII/Descriptors.h @@ -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 diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c index ef86e30f2aa79d2913eaea3cb4b357caa77a11c9..cc521ce87d636183a4fd2d28122ee097720fbc8d 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c @@ -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 diff --git a/Projects/RelayBoard/RelayBoard.c b/Projects/RelayBoard/RelayBoard.c index 0936c4d7e83d047ce9af509808cf904950a6ce9e..a496679aea25c49e21015884a12188da7ffc207b 100644 --- a/Projects/RelayBoard/RelayBoard.c +++ b/Projects/RelayBoard/RelayBoard.c @@ -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(); }