}
}
+RFCOMM_Channel_t* RFCOMM_OpenChannel(Bluetooth_Channel_t* const BluetoothChannel)
+{
+ return NULL;
+}
+
void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Bluetooth_Channel_t* const BluetoothChannel)
{
BT_RFCOMM_DEBUG(1, ">> MSC Command");
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, true, RFCOMM_Frame_UIH, sizeof(MSCommand), &MSCommand, BluetoothChannel);
}
+RFCOMM_Channel_t* RFCOMM_GetFreeChannelEntry(const uint8_t DLCI)
+{
+ /* Find a free entry in the RFCOMM channel multiplexer state array */
+ for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)
+ {
+ RFCOMM_Channel_t* RFCOMMChannel = &RFCOMM_Channels[i];
+
+ /* If the channel's state is closed, the channel state entry is free */
+ if (RFCOMMChannel->State == RFCOMM_Channel_Closed)
+ {
+ RFCOMMChannel->DLCI = DLCI;
+ RFCOMMChannel->State = RFCOMM_Channel_Configure;
+ RFCOMMChannel->Priority = 7 + (RFCOMMChannel->DLCI & 0xF8);
+ RFCOMMChannel->MTU = 0xFFFF;
+ RFCOMMChannel->Remote.Signals = 0 | (1 << 0);
+ RFCOMMChannel->Remote.BreakSignal = 0 | (1 << 0);
+ RFCOMMChannel->Local.Signals = RFCOMM_SIGNAL_RTC | RFCOMM_SIGNAL_RTR | RFCOMM_SIGNAL_DV | (1 << 0);
+ RFCOMMChannel->Local.BreakSignal = 0 | (1 << 0);
+ RFCOMMChannel->ConfigFlags = 0;
+
+ return RFCOMMChannel;
+ }
+ }
+
+ return NULL;
+}
+
RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI)
{
/* Search through the RFCOMM channel list, looking for the specified channel */
BT_RFCOMM_DEBUG(1, "<< SABM Received");
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
- RFCOMM_Channel_t* RFCOMMChannel;
-
- if (FrameAddress->DLCI != RFCOMM_CONTROL_DLCI)
+ if (FrameAddress->DLCI == RFCOMM_CONTROL_DLCI)
{
- /* Find a free entry in the RFCOMM channel multiplexer state array */
- for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)
- {
- /* If the channel's state is closed, the channel state entry is free */
- if (RFCOMM_Channels[i].State == RFCOMM_Channel_Closed)
- {
- RFCOMMChannel = &RFCOMM_Channels[i];
- RFCOMMChannel->DLCI = FrameAddress->DLCI;
- RFCOMMChannel->State = RFCOMM_Channel_Configure;
- RFCOMMChannel->Priority = 7 + (RFCOMMChannel->DLCI & 0xF8);
- RFCOMMChannel->MTU = 0xFFFF;
- RFCOMMChannel->Remote.Signals = 0 | (1 << 0);
- RFCOMMChannel->Remote.BreakSignal = 0 | (1 << 0);
- RFCOMMChannel->Local.Signals = RFCOMM_SIGNAL_RTC | RFCOMM_SIGNAL_RTR | RFCOMM_SIGNAL_DV | (1 << 0);
- RFCOMMChannel->Local.BreakSignal = 0 | (1 << 0);
- RFCOMMChannel->ConfigFlags = 0;
- break;
- }
- }
+ 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, Channel);
+
+ return;
}
+
+ /* Find the existing channel's entry in the channel table */
+ RFCOMM_Channel_t* RFCOMMChannel = RFCOMM_GetChannelData(FrameAddress->DLCI);
- if (RFCOMMChannel || (FrameAddress->DLCI == RFCOMM_CONTROL_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");
/* Check if the channel has no corresponding entry - remote did not open it first */\r
if (RFCOMMChannel == NULL)\r
{\r
- /* Find a free entry in the RFCOMM channel multiplexer state array */\r
- for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)\r
- {\r
- /* If the channel's state is closed, the channel state entry is free */\r
- if (RFCOMM_Channels[i].State == RFCOMM_Channel_Closed)\r
- {\r
- RFCOMMChannel = &RFCOMM_Channels[i];\r
- RFCOMMChannel->DLCI = Params->DLCI;\r
- RFCOMMChannel->MTU = 0xFFFF;\r
- RFCOMMChannel->Remote.Signals = 0 | (1 << 0);\r
- RFCOMMChannel->Remote.BreakSignal = 0 | (1 << 0);\r
- RFCOMMChannel->Local.Signals = RFCOMM_SIGNAL_RTC | RFCOMM_SIGNAL_RTR | RFCOMM_SIGNAL_DV | (1 << 0);\r
- RFCOMMChannel->Local.BreakSignal = 0 | (1 << 0);\r
- RFCOMMChannel->ConfigFlags = 0;\r
- break;\r
- }\r
- }\r
+ /* Create a new entry in the channel table for the new channel */\r
+ RFCOMMChannel = RFCOMM_GetFreeChannelEntry(Params->DLCI);\r
\r
/* No free entry was found, discard the request */\r
if (RFCOMMChannel == NULL)\r