mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-16 21:01:31 +00:00
Refactor out RFCOMM packet send code into a seperate function.
This commit is contained in:
parent
7aec6cba1a
commit
361e1ec1d8
@ -102,29 +102,9 @@ static void RFCOMM_ProcessSABM(const RFCOMM_Header_t* const FrameHeader, Bluetoo
|
|||||||
|
|
||||||
// TODO: Reset channel send/receive state here
|
// TODO: Reset channel send/receive state here
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
RFCOMM_Header_t FrameHeader;
|
|
||||||
uint8_t FrameLength;
|
|
||||||
uint8_t FCS;
|
|
||||||
} ResponsePacket;
|
|
||||||
|
|
||||||
/* Copy over the same frame header as the sent packet to copy the logical RFCOMM channel address */
|
|
||||||
ResponsePacket.FrameHeader.Address = FrameHeader->Address;
|
|
||||||
|
|
||||||
/* Set the frame type to an Unnumbered Acknowledgement to acknowledge the SABM request */
|
|
||||||
ResponsePacket.FrameHeader.Control = RFCOMM_Frame_UA;
|
|
||||||
|
|
||||||
/* Set the length to 0 (LSB indicates end of 8-bit length field) */
|
|
||||||
ResponsePacket.FrameLength = 0x01;
|
|
||||||
|
|
||||||
/* Calculate the frame checksum from all fields except the FCS field itself */
|
|
||||||
ResponsePacket.FCS = RFCOMM_GetFCSValue(&ResponsePacket, sizeof(ResponsePacket) - sizeof(ResponsePacket.FCS));
|
|
||||||
|
|
||||||
BT_RFCOMM_DEBUG(1, ">> UA Sent");
|
BT_RFCOMM_DEBUG(1, ">> UA Sent");
|
||||||
|
|
||||||
/* Send the completed response packet to the sender */
|
RFCOMM_SendFrame(FrameHeader->Address, RFCOMM_Frame_UA, 0, NULL, Channel);
|
||||||
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), Channel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RFCOMM_ProcessUA(const RFCOMM_Header_t* const FrameHeader, Bluetooth_Channel_t* const Channel)
|
static void RFCOMM_ProcessUA(const RFCOMM_Header_t* const FrameHeader, Bluetooth_Channel_t* const Channel)
|
||||||
@ -159,6 +139,40 @@ static void RFCOMM_ProcessUIH(const RFCOMM_Header_t* const FrameHeader, Bluetoot
|
|||||||
BT_RFCOMM_DEBUG(2, "-- Address 0x%02X", FrameHeader->Address);
|
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,
|
||||||
|
Bluetooth_Channel_t* const Channel)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
RFCOMM_Header_t FrameHeader;
|
||||||
|
uint8_t Size[1 + (DataLen >= 128)];
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* Set the lower 7 bits of the packet length */
|
||||||
|
ResponsePacket.Size[0] = (DataLen << 1);
|
||||||
|
|
||||||
|
/* Terminate the size field if size is 7 bits or lower, otherwise set the upper 8 bits of the length */
|
||||||
|
if (DataLen < 128)
|
||||||
|
ResponsePacket.Size[0] |= 0x01;
|
||||||
|
else
|
||||||
|
ResponsePacket.Size[1] = (DataLen >> 7);
|
||||||
|
|
||||||
|
/* 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));
|
||||||
|
|
||||||
|
/* Send the completed response packet to the sender */
|
||||||
|
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), Channel);
|
||||||
|
}
|
||||||
|
|
||||||
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint16_t Length)
|
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint16_t Length)
|
||||||
{
|
{
|
||||||
const uint8_t* CurrPos = FrameStart;
|
const uint8_t* CurrPos = FrameStart;
|
||||||
|
@ -68,13 +68,7 @@
|
|||||||
/* Type Defines: */
|
/* Type Defines: */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
struct
|
uint8_t Address;
|
||||||
{
|
|
||||||
unsigned char LogicalChannel : 6;
|
|
||||||
unsigned char PollResponse : 1;
|
|
||||||
unsigned char LastAddressOctet : 1;
|
|
||||||
} Address;
|
|
||||||
|
|
||||||
uint8_t Control;
|
uint8_t Control;
|
||||||
} RFCOMM_Header_t;
|
} RFCOMM_Header_t;
|
||||||
|
|
||||||
@ -89,6 +83,8 @@
|
|||||||
static void RFCOMM_ProcessDISC(const RFCOMM_Header_t* const FrameHeader, Bluetooth_Channel_t* const Channel);
|
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_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 uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint16_t Length);
|
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint16_t Length);
|
||||||
static uint16_t RFCOMM_GetFrameDataLength(const uint8_t** BufferPos);
|
static uint16_t RFCOMM_GetFrameDataLength(const uint8_t** BufferPos);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user