forked from mfulz_github/qmk_firmware
Make the RFCOMM_SendFrame() function correctly generate frames from the input parameters, change addressing to use the raw DLCI address plus flags.
This commit is contained in:
parent
361e1ec1d8
commit
34e0fed4ca
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
* - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller: http://noisybox.net/electronics/wingdinger/
|
||||
* - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master
|
||||
* - Generic HID Device Creator: http://generichid.sourceforge.net/
|
||||
* - Ghetto Drum, a MIDI drum controller: http://noisybox.net/art/gdrum/
|
||||
* - IR Remote to Keyboard decoder: http://netzhansa.blogspot.com/2010/04/our-living-room-hi-fi-setup-needs-mp3.html
|
||||
* - LED Panel controller: http://projects.peterpolidoro.net/caltech/panelscontroller/panelscontroller.htm
|
||||
* - Linux Secure Storage Dongle: http://github.com/TomMD/teensy
|
||||
|
|
Loading…
Reference in New Issue