+ BT_RFCOMM_DEBUG(1, "<< DM Received");
+ BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
+}
+
+static void RFCOMM_ProcessDISC(const RFCOMM_Address_t* const FrameAddress,
+ Bluetooth_Channel_t* const ACLChannel)
+{
+ BT_RFCOMM_DEBUG(1, "<< DISC Received");
+ BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
+
+ RFCOMM_Channel_t* RFCOMMChannel = RFCOMM_GetChannelData(FrameAddress->DLCI);
+
+ /* If the requested channel is currently open, destroy it */
+ if (RFCOMMChannel != NULL)
+ RFCOMMChannel->State = RFCOMM_Channel_Closed;
+
+ BT_RFCOMM_DEBUG(1, ">> UA Sent");
+ RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_UA | FRAME_POLL_FINAL), 0, NULL, ACLChannel);
+}
+
+static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress,
+ Bluetooth_Channel_t* const ACLChannel)
+{
+ BT_RFCOMM_DEBUG(1, "<< SABM Received");
+ BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
+
+ if (FrameAddress->DLCI == RFCOMM_CONTROL_DLCI)
+ {
+ 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, ACLChannel);
+
+ return;
+ }
+
+ /* Find the existing channel's entry in the channel table */
+ RFCOMM_Channel_t* RFCOMMChannel = RFCOMM_GetChannelData(FrameAddress->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");
+
+ /* 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, ACLChannel);
+ }
+ else
+ {
+ BT_RFCOMM_DEBUG(1, ">> DM Sent");
+
+ /* No free channel in the multiplexer - decline the SABM by sending a DM frame */
+ RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_DM | FRAME_POLL_FINAL), 0, NULL, ACLChannel);
+ }
+}
+
+static void RFCOMM_ProcessUA(const RFCOMM_Address_t* const FrameAddress,
+ Bluetooth_Channel_t* const ACLChannel)
+{
+ BT_RFCOMM_DEBUG(1, "<< UA Received");
+ BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
+}
+
+static void RFCOMM_ProcessUIH(const RFCOMM_Address_t* const FrameAddress,
+ const uint16_t FrameLength,
+ const uint8_t* FrameData,
+ Bluetooth_Channel_t* const ACLChannel)
+{
+ if (FrameAddress->DLCI == RFCOMM_CONTROL_DLCI)
+ {
+ RFCOMM_ProcessControlCommand(FrameData, ACLChannel);
+ return;
+ }
+
+ BT_RFCOMM_DEBUG(1, "<< UIH Received");
+ BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
+ BT_RFCOMM_DEBUG(2, "-- Length 0x%02X", FrameLength);
+
+ RFCOMM_Channel_t* RFCOMMChannel = RFCOMM_GetChannelData(FrameAddress->DLCI);
+
+ if (RFCOMMChannel != NULL)
+ RFCOMM_DataReceived(RFCOMMChannel, FrameLength, FrameData);