Make Bluetooth ACL channel searches skip over closed (invalid) channels. RFCOMM channels are considered invalid when the channel state is closed, not when the DLCI is zero - fix incorrect code.

pull/1469/head
Dean Camera 15 years ago
parent d29a408ffd
commit b656540468

@ -85,8 +85,13 @@ Bluetooth_Channel_t* Bluetooth_GetChannelData(const uint16_t SearchValue, const
{ {
Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i]; Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i];
/* Closed channels should be ignored as they are not considered valid data */
if (ChannelData->State == BT_Channel_Closed)
continue;
bool FoundMatch = false; bool FoundMatch = false;
/* Search the current channel for the search key to see if it matches */
switch (SearchKey) switch (SearchKey)
{ {
case CHANNEL_SEARCH_LOCALNUMBER: case CHANNEL_SEARCH_LOCALNUMBER:

@ -111,7 +111,7 @@ RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI)
RFCOMM_Channel_t* CurrRFCOMMChannel = &RFCOMM_Channels[i]; RFCOMM_Channel_t* CurrRFCOMMChannel = &RFCOMM_Channels[i];
/* If the current non-closed channel's DLCI matches the search DLCI, return it to the caller */ /* If the current non-closed channel's DLCI matches the search DLCI, return it to the caller */
if ((CurrRFCOMMChannel->DLCI == DLCI) && (CurrRFCOMMChannel->State != RFCOMM_Channel_Closed)) if ((CurrRFCOMMChannel->State != RFCOMM_Channel_Closed) && (CurrRFCOMMChannel->DLCI == DLCI))
return CurrRFCOMMChannel; return CurrRFCOMMChannel;
} }
@ -192,6 +192,7 @@ static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length)
{ {
uint8_t FCS = 0xFF; uint8_t FCS = 0xFF;
/* Calculate new Frame CRC value via the given data bytes and the CRC table */
for (uint8_t i = 0; i < Length; i++) for (uint8_t i = 0; i < Length; i++)
FCS = pgm_read_byte(&CRC8_Table[FCS ^ ((uint8_t*)FrameStart)[i]]); FCS = pgm_read_byte(&CRC8_Table[FCS ^ ((uint8_t*)FrameStart)[i]]);
@ -213,7 +214,7 @@ static void RFCOMM_ProcessDISC(const RFCOMM_Address_t* const FrameAddress, Bluet
/* If the requested channel is currently open, destroy it */ /* If the requested channel is currently open, destroy it */
if (RFCOMMChannel != NULL) if (RFCOMMChannel != NULL)
RFCOMMChannel->DLCI = 0x00; RFCOMMChannel->State = RFCOMM_Channel_Closed;
BT_RFCOMM_DEBUG(1, ">> UA Sent"); BT_RFCOMM_DEBUG(1, ">> UA Sent");
RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_UA | FRAME_POLL_FINAL), 0, NULL, Channel); RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_UA | FRAME_POLL_FINAL), 0, NULL, Channel);
@ -229,8 +230,8 @@ static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress, Bluet
{ {
RFCOMM_Channel_t* CurrRFCOMMChannel = &RFCOMM_Channels[i]; RFCOMM_Channel_t* CurrRFCOMMChannel = &RFCOMM_Channels[i];
/* If the channel's DLCI is zero, the channel state entry is free */ /* If the channel's state is closed, the channel state entry is free */
if (!(CurrRFCOMMChannel->DLCI)) if (CurrRFCOMMChannel->State == RFCOMM_Channel_Closed)
{ {
CurrRFCOMMChannel->DLCI = FrameAddress->DLCI; CurrRFCOMMChannel->DLCI = FrameAddress->DLCI;
CurrRFCOMMChannel->State = RFCOMM_Channel_Open; CurrRFCOMMChannel->State = RFCOMM_Channel_Open;

@ -111,14 +111,14 @@
const uint16_t DataLen, const void* Data, Bluetooth_Channel_t* const Channel); const uint16_t DataLen, const void* Data, Bluetooth_Channel_t* const Channel);
#if defined(INCLUDE_FROM_RFCOMM_C) #if defined(INCLUDE_FROM_RFCOMM_C)
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length);
static void RFCOMM_ProcessDM(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel); static void RFCOMM_ProcessDM(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel);
static void RFCOMM_ProcessDISC(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel); static void RFCOMM_ProcessDISC(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel);
static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel); static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel);
static void RFCOMM_ProcessUA(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel); static void RFCOMM_ProcessUA(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const Channel);
static void RFCOMM_ProcessUIH(const RFCOMM_Address_t* const FrameAddress, const uint16_t FrameLength, static void RFCOMM_ProcessUIH(const RFCOMM_Address_t* const FrameAddress, const uint16_t FrameLength,
const uint8_t* FrameData, Bluetooth_Channel_t* const Channel); const uint8_t* FrameData, Bluetooth_Channel_t* const Channel);
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length);
#endif #endif
#endif #endif

@ -188,12 +188,12 @@ static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader
/* Find a free entry in the RFCOMM channel multiplexer state array */ /* Find a free entry in the RFCOMM channel multiplexer state array */
for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++) for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)
{ {
/* If the channel's DLCI is zero, the channel state entry is free */ /* If the channel's state is closed, the channel state entry is free */
if (!(RFCOMM_Channels[i].DLCI)) if (RFCOMMChannel->State == RFCOMM_Channel_Closed)
{ {
RFCOMMChannel = &RFCOMM_Channels[i]; RFCOMMChannel = &RFCOMM_Channels[i];
RFCOMMChannel->DLCI = Params->DLCI; RFCOMMChannel->DLCI = Params->DLCI;
RFCOMMChannel->MTU = 0xFFFF; RFCOMMChannel->MTU = 0xFFFF;
RFCOMMChannel->Remote.Signals = 0 | (1 << 0); RFCOMMChannel->Remote.Signals = 0 | (1 << 0);
RFCOMMChannel->Remote.BreakSignal = 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.Signals = RFCOMM_SIGNAL_RTC | RFCOMM_SIGNAL_RTR | RFCOMM_SIGNAL_DV | (1 << 0);
@ -230,6 +230,6 @@ static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader
BT_RFCOMM_DEBUG(1, ">> DPN Response"); BT_RFCOMM_DEBUG(1, ">> DPN Response");
/* Send the PDN response to acknowledge the command */ /* Send the DPN response to acknowledge the command */
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(DPNResponse), &DPNResponse, Channel); RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(DPNResponse), &DPNResponse, Channel);
} }

Loading…
Cancel
Save