static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen, const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel) { const RFCOMM_MSC_Parameters_t* Params = (const RFCOMM_MSC_Parameters_t*)CommandData; BT_RFCOMM_DEBUG(1, "<< MSC %s", (CommandHeader->CR) ? "Command" : "Response"); BT_RFCOMM_DEBUG(2, "-- DLCI: 0x%02X", Params->Channel.DLCI); /* Ignore status flags sent to the control channel */ if (Params->Channel.DLCI == RFCOMM_CONTROL_DLCI) return; /* Retrieve existing channel configuration data, if already opened */ RFCOMM_Channel_t* RFCOMMChannel = RFCOMM_GetChannelData(Params->Channel.DLCI); /* If the channel does not exist, abort */ if (RFCOMMChannel == NULL) return; /* Check if the MSC packet is a command or a response */ if (CommandHeader->CR) { /* Save the new channel signals to the channel state structure */ RFCOMMChannel->Remote.Signals = Params->Signals; RFCOMMChannel->ConfigFlags |= RFCOMM_CONFIG_REMOTESIGNALS; /* If the command contains the optional break signals field, store the value */ if (CommandDataLen == sizeof(RFCOMM_MSC_Parameters_t)) RFCOMMChannel->Remote.BreakSignal = Params->BreakSignal; /* Notify the user application that the signals have been received */ RFCOMM_ChannelSignalsReceived(RFCOMMChannel); struct { RFCOMM_Command_t CommandHeader; uint8_t Length; RFCOMM_MSC_Parameters_t Params; } MSResponse; /* Fill out the MS response data */ MSResponse.CommandHeader = (RFCOMM_Command_t){.Command = RFCOMM_Control_ModemStatus, .EA = true, .CR = false}; MSResponse.Length = (CommandDataLen << 1) | 0x01; memcpy(&MSResponse.Params, Params, sizeof(RFCOMM_MSC_Parameters_t)); BT_RFCOMM_DEBUG(1, ">> MSC Response"); /* Send the MSC response to acknowledge the command */ RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, (sizeof(MSResponse) - sizeof(MSResponse.Params) + CommandDataLen), &MSResponse, ACLChannel); } else {
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_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); }
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); } }