aboutsummaryrefslogtreecommitdiffstats
path: root/Demos
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-07-02 03:06:16 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-07-02 03:06:16 +0000
commit31a34154dbbc20adc523eb08678977d218ae8135 (patch)
tree613bc0069075d8a365a07f60159f2d784c387e1d /Demos
parentfbabecee66b93596acc6f99a92be4a9dd3a750ce (diff)
downloadlufa-31a34154dbbc20adc523eb08678977d218ae8135.tar.gz
lufa-31a34154dbbc20adc523eb08678977d218ae8135.tar.bz2
lufa-31a34154dbbc20adc523eb08678977d218ae8135.zip
Move out RFCOMM channel structure init code to a seperate routine, to save on compiled code space and to prevent copy-paste errors.
Diffstat (limited to 'Demos')
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c15
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c71
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h3
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.c19
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.h1
5 files changed, 62 insertions, 47 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
index 73b709de0..2ad3ed515 100644
--- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
+++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
@@ -58,12 +58,15 @@ int main(void)
for (;;)
{
- Bluetooth_Channel_t* RFCOMMChannel = Bluetooth_GetChannelData(CHANNEL_PSM_RFCOMM, CHANNEL_SEARCH_PSM);
-
- /* If an RFCOMM channel is open, service the RFCOMM logical channels */
- if (RFCOMMChannel)
- RFCOMM_ServiceChannels(RFCOMMChannel);
-
+ if (Bluetooth_Connection.IsConnected)
+ {
+ Bluetooth_Channel_t* RFCOMMChannel = Bluetooth_GetChannelData(CHANNEL_PSM_RFCOMM, CHANNEL_SEARCH_PSM);
+
+ /* If an RFCOMM channel is open, service the RFCOMM logical channels */
+ if (RFCOMMChannel)
+ RFCOMM_ServiceChannels(RFCOMMChannel);
+ }
+
Bluetooth_Stack_USBTask();
Bluetooth_Host_Task();
USB_USBTask();
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
index 271f2dc28..e0446c0e7 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
@@ -129,6 +129,11 @@ void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
}
}
+RFCOMM_Channel_t* RFCOMM_OpenChannel(Bluetooth_Channel_t* const BluetoothChannel)
+{
+ return NULL;
+}
+
void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Bluetooth_Channel_t* const BluetoothChannel)
{
BT_RFCOMM_DEBUG(1, ">> MSC Command");
@@ -151,6 +156,33 @@ void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Blue
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, true, RFCOMM_Frame_UIH, sizeof(MSCommand), &MSCommand, BluetoothChannel);
}
+RFCOMM_Channel_t* RFCOMM_GetFreeChannelEntry(const uint8_t DLCI)
+{
+ /* Find a free entry in the RFCOMM channel multiplexer state array */
+ for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)
+ {
+ RFCOMM_Channel_t* RFCOMMChannel = &RFCOMM_Channels[i];
+
+ /* If the channel's state is closed, the channel state entry is free */
+ if (RFCOMMChannel->State == RFCOMM_Channel_Closed)
+ {
+ RFCOMMChannel->DLCI = DLCI;
+ RFCOMMChannel->State = RFCOMM_Channel_Configure;
+ RFCOMMChannel->Priority = 7 + (RFCOMMChannel->DLCI & 0xF8);
+ RFCOMMChannel->MTU = 0xFFFF;
+ RFCOMMChannel->Remote.Signals = 0 | (1 << 0);
+ RFCOMMChannel->Remote.BreakSignal = 0 | (1 << 0);
+ RFCOMMChannel->Local.Signals = RFCOMM_SIGNAL_RTC | RFCOMM_SIGNAL_RTR | RFCOMM_SIGNAL_DV | (1 << 0);
+ RFCOMMChannel->Local.BreakSignal = 0 | (1 << 0);
+ RFCOMMChannel->ConfigFlags = 0;
+
+ return RFCOMMChannel;
+ }
+ }
+
+ return NULL;
+}
+
RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI)
{
/* Search through the RFCOMM channel list, looking for the specified channel */
@@ -268,32 +300,25 @@ static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress, Bluet
BT_RFCOMM_DEBUG(1, "<< SABM Received");
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
- RFCOMM_Channel_t* RFCOMMChannel;
-
- if (FrameAddress->DLCI != RFCOMM_CONTROL_DLCI)
+ if (FrameAddress->DLCI == RFCOMM_CONTROL_DLCI)
{
- /* Find a free entry in the RFCOMM channel multiplexer state array */
- for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)
- {
- /* If the channel's state is closed, the channel state entry is free */
- if (RFCOMM_Channels[i].State == RFCOMM_Channel_Closed)
- {
- RFCOMMChannel = &RFCOMM_Channels[i];
- RFCOMMChannel->DLCI = FrameAddress->DLCI;
- RFCOMMChannel->State = RFCOMM_Channel_Configure;
- RFCOMMChannel->Priority = 7 + (RFCOMMChannel->DLCI & 0xF8);
- RFCOMMChannel->MTU = 0xFFFF;
- RFCOMMChannel->Remote.Signals = 0 | (1 << 0);
- RFCOMMChannel->Remote.BreakSignal = 0 | (1 << 0);
- RFCOMMChannel->Local.Signals = RFCOMM_SIGNAL_RTC | RFCOMM_SIGNAL_RTR | RFCOMM_SIGNAL_DV | (1 << 0);
- RFCOMMChannel->Local.BreakSignal = 0 | (1 << 0);
- RFCOMMChannel->ConfigFlags = 0;
- break;
- }
- }
+ BT_RFCOMM_DEBUG(1, ">> UA Sent");
+
+ /* Free channel found, or request was to the control channel - accept SABM by sending a UA frame */
+ RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_UA | FRAME_POLL_FINAL), 0, NULL, Channel);
+
+ return;
}
+
+ /* Find the existing channel's entry in the channel table */
+ RFCOMM_Channel_t* RFCOMMChannel = RFCOMM_GetChannelData(FrameAddress->DLCI);
- if (RFCOMMChannel || (FrameAddress->DLCI == RFCOMM_CONTROL_DLCI))
+ /* Existing entry not found, create a new entry for the channel */
+ if (RFCOMMChannel == NULL)
+ RFCOMMChannel = RFCOMM_GetFreeChannelEntry(FrameAddress->DLCI);
+
+ /* If space was found in the channel table for the new channel, ACK the request */
+ if (RFCOMMChannel != NULL)
{
BT_RFCOMM_DEBUG(1, ">> UA Sent");
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
index e7ed7ecd3..e557858f2 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
@@ -106,8 +106,9 @@
void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel,
Bluetooth_Channel_t* const BluetoothChannel);
- RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI);
+ RFCOMM_Channel_t* RFCOMM_GetFreeChannelEntry(const uint8_t DLCI);
+ RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI);
uint16_t RFCOMM_GetVariableFieldValue(const uint8_t** BufferPos);
void RFCOMM_SendFrame(const uint8_t DLCI, const bool CommandResponse, const uint8_t Control,
const uint16_t DataLen, const void* Data, Bluetooth_Channel_t* const Channel);
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.c b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.c
index 2495bb49e..e5bce54d2 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.c
@@ -195,23 +195,8 @@ static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader
/* Check if the channel has no corresponding entry - remote did not open it first */
if (RFCOMMChannel == NULL)
{
- /* Find a free entry in the RFCOMM channel multiplexer state array */
- for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)
- {
- /* If the channel's state is closed, the channel state entry is free */
- if (RFCOMM_Channels[i].State == RFCOMM_Channel_Closed)
- {
- RFCOMMChannel = &RFCOMM_Channels[i];
- RFCOMMChannel->DLCI = Params->DLCI;
- RFCOMMChannel->MTU = 0xFFFF;
- RFCOMMChannel->Remote.Signals = 0 | (1 << 0);
- RFCOMMChannel->Remote.BreakSignal = 0 | (1 << 0);
- RFCOMMChannel->Local.Signals = RFCOMM_SIGNAL_RTC | RFCOMM_SIGNAL_RTR | RFCOMM_SIGNAL_DV | (1 << 0);
- RFCOMMChannel->Local.BreakSignal = 0 | (1 << 0);
- RFCOMMChannel->ConfigFlags = 0;
- break;
- }
- }
+ /* Create a new entry in the channel table for the new channel */
+ RFCOMMChannel = RFCOMM_GetFreeChannelEntry(Params->DLCI);
/* No free entry was found, discard the request */
if (RFCOMMChannel == NULL)
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.h b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.h
index 7928d94cb..a5e3fbe55 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.h
@@ -59,6 +59,7 @@
#define RFCOMM_CONFIG_REMOTESIGNALS (1 << 0)
#define RFCOMM_CONFIG_LOCALSIGNALS (1 << 1)
#define RFCOMM_CONFIG_LOCALSIGNALSSENT (1 << 2)
+ #define RFCOMM_CONFIG_ABMMODESET (1 << 3)
/* Enums: */
enum RFCOMM_Control_Commands_t