+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);
+}
+