aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Host/Incomplete
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-04-05 08:09:12 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-04-05 08:09:12 +0000
commitfa1a092901319b3b41bf09e0c4cb9cbbec470d6b (patch)
treeaa75acf5f00faa999f4622ce8754fe713d312b23 /Demos/Host/Incomplete
parentfd96b288824caaa3ee4e5e03887f016de9df80cf (diff)
downloadlufa-fa1a092901319b3b41bf09e0c4cb9cbbec470d6b.tar.gz
lufa-fa1a092901319b3b41bf09e0c4cb9cbbec470d6b.tar.bz2
lufa-fa1a092901319b3b41bf09e0c4cb9cbbec470d6b.zip
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.
Diffstat (limited to 'Demos/Host/Incomplete')
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c11
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c15
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h3
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c20
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h4
5 files changed, 31 insertions, 22 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
index 312d7166e..338997fc7 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 dd2a3e5cf..a6e59d648 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 4df5861cf..317ebc7eb 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 7f49fc979..4e0330e52 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 20bc95696..b3ac6847e 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;