aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Host/Incomplete/BluetoothHost/Lib
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-06-07 09:07:18 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-06-07 09:07:18 +0000
commit34e0fed4ca7e2804d4e0ed5f1d36e08dca659ba0 (patch)
treeefcd69450b0711a353d120315884317bee1ae36a /Demos/Host/Incomplete/BluetoothHost/Lib
parent361e1ec1d83d5b6d97890f2a27b9c9ae24e561ee (diff)
downloadlufa-34e0fed4ca7e2804d4e0ed5f1d36e08dca659ba0.tar.gz
lufa-34e0fed4ca7e2804d4e0ed5f1d36e08dca659ba0.tar.bz2
lufa-34e0fed4ca7e2804d4e0ed5f1d36e08dca659ba0.zip
Make the RFCOMM_SendFrame() function correctly generate frames from the input parameters, change addressing to use the raw DLCI address plus flags.
Diffstat (limited to 'Demos/Host/Incomplete/BluetoothHost/Lib')
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c34
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h15
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c4
3 files changed, 37 insertions, 16 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
index c0209d56f..e69a27e4e 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
@@ -98,13 +98,12 @@ void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
static void RFCOMM_ProcessSABM(const RFCOMM_Header_t* const FrameHeader, Bluetooth_Channel_t* const Channel)
{
BT_RFCOMM_DEBUG(1, "<< SABM Received");
- BT_RFCOMM_DEBUG(2, "-- Address 0x%02X", FrameHeader->Address);
+ BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameHeader->Address.DLCI);
// TODO: Reset channel send/receive state here
BT_RFCOMM_DEBUG(1, ">> UA Sent");
-
- RFCOMM_SendFrame(FrameHeader->Address, RFCOMM_Frame_UA, 0, NULL, Channel);
+ RFCOMM_SendFrame(FrameHeader->Address.DLCI, true, (RFCOMM_Frame_UA | FRAME_POLL_FINAL), 0, NULL, Channel);
}
static void RFCOMM_ProcessUA(const RFCOMM_Header_t* const FrameHeader, Bluetooth_Channel_t* const Channel)
@@ -139,20 +138,25 @@ static void RFCOMM_ProcessUIH(const RFCOMM_Header_t* const FrameHeader, Bluetoot
BT_RFCOMM_DEBUG(2, "-- Address 0x%02X", FrameHeader->Address);
}
-static void RFCOMM_SendFrame(const uint8_t Address, const uint8_t Type, const uint16_t DataLen, const uint8_t* Data,
+static void RFCOMM_SendFrame(const uint8_t DLCI, const bool CommandResponse, const uint8_t Control, const uint16_t DataLen, const uint8_t* Data,
Bluetooth_Channel_t* const Channel)
{
struct
{
RFCOMM_Header_t FrameHeader;
- uint8_t Size[1 + (DataLen >= 128)];
+ uint8_t Size[(DataLen < 128) ? 1 : 2];
uint8_t Data[DataLen];
uint8_t FCS;
} ResponsePacket;
/* Set the frame header values to the specified address and frame type */
- ResponsePacket.FrameHeader.Address = Address;
- ResponsePacket.FrameHeader.Control = Type;
+ ResponsePacket.FrameHeader.Control = Control;
+ ResponsePacket.FrameHeader.Address = (RFCOMM_Address_t)
+ {
+ .EA = true,
+ .CR = CommandResponse,
+ .DLCI = DLCI,
+ };
/* Set the lower 7 bits of the packet length */
ResponsePacket.Size[0] = (DataLen << 1);
@@ -166,9 +170,12 @@ static void RFCOMM_SendFrame(const uint8_t Address, const uint8_t Type, const ui
/* Copy over the packet data from the source buffer to the response packet buffer */
memcpy(ResponsePacket.Data, Data, DataLen);
- /* Calculate the frame checksum from all fields except the FCS field itself */
- ResponsePacket.FCS = RFCOMM_GetFCSValue(&ResponsePacket, sizeof(ResponsePacket) - sizeof(ResponsePacket.FCS));
-
+ /* Calculate the frame checksum from the appropriate fields */
+ if ((Control & ~FRAME_POLL_FINAL) == RFCOMM_Frame_UIH)
+ ResponsePacket.FCS = RFCOMM_GetFCSValue(&ResponsePacket, sizeof(ResponsePacket.FrameHeader));
+ else
+ ResponsePacket.FCS = RFCOMM_GetFCSValue(&ResponsePacket, sizeof(ResponsePacket.FrameHeader) + sizeof(ResponsePacket.Size));
+
/* Send the completed response packet to the sender */
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), Channel);
}
@@ -179,9 +186,12 @@ static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint16_t Length)
uint8_t FCS = 0xFF;
while (Length--)
- FCS = pgm_read_byte(CRC8_Table[FCS ^ *(CurrPos++)]);
+ {
+ FCS = pgm_read_byte(&CRC8_Table[FCS ^ *CurrPos]);
+ CurrPos++;
+ }
- return ~FCS;
+ return (0xFF - FCS);
}
static uint16_t RFCOMM_GetFrameDataLength(const uint8_t** BufferPos)
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
index dd30d5535..d25b7370f 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
@@ -68,8 +68,15 @@
/* Type Defines: */
typedef struct
{
- uint8_t Address;
- uint8_t Control;
+ unsigned char EA : 1;
+ unsigned char CR : 1;
+ unsigned char DLCI : 6;
+ } RFCOMM_Address_t;
+
+ typedef struct
+ {
+ RFCOMM_Address_t Address;
+ uint8_t Control;
} RFCOMM_Header_t;
/* Function Prototypes: */
@@ -83,8 +90,8 @@
static void RFCOMM_ProcessDISC(const RFCOMM_Header_t* const FrameHeader, Bluetooth_Channel_t* const Channel);
static void RFCOMM_ProcessUIH(const RFCOMM_Header_t* const FrameHeader, Bluetooth_Channel_t* const Channel);
- static void RFCOMM_SendFrame(const uint8_t Address, const uint8_t Type, const uint16_t DataLen,
- const uint8_t* Data, Bluetooth_Channel_t* const Channel);
+ static void RFCOMM_SendFrame(const uint8_t DLCI, const bool CommandResponse, const uint8_t Control,
+ const uint16_t DataLen, const uint8_t* Data, Bluetooth_Channel_t* const Channel);
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint16_t Length);
static uint16_t RFCOMM_GetFrameDataLength(const uint8_t** BufferPos);
#endif
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c
index 6d8f27036..5223d29b1 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c
@@ -36,6 +36,10 @@
* what services are available.
*/
+/*
+ TODO: Honor remote device's buffer size constraints via continuation state
+ */
+
#define INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C
#include "ServiceDiscoveryProtocol.h"