forked from mfulz_github/qmk_firmware
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.
This commit is contained in:
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];
|
||||
|
||||
/* Closed channels should be ignored as they are not considered valid data */
|
||||
if (ChannelData->State == BT_Channel_Closed)
|
||||
continue;
|
||||
|
||||
bool FoundMatch = false;
|
||||
|
||||
/* Search the current channel for the search key to see if it matches */
|
||||
switch (SearchKey)
|
||||
{
|
||||
case CHANNEL_SEARCH_LOCALNUMBER:
|
||||
|
|
|
@ -111,7 +111,7 @@ RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI)
|
|||
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 ((CurrRFCOMMChannel->DLCI == DLCI) && (CurrRFCOMMChannel->State != RFCOMM_Channel_Closed))
|
||||
if ((CurrRFCOMMChannel->State != RFCOMM_Channel_Closed) && (CurrRFCOMMChannel->DLCI == DLCI))
|
||||
return CurrRFCOMMChannel;
|
||||
}
|
||||
|
||||
|
@ -192,6 +192,7 @@ static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length)
|
|||
{
|
||||
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++)
|
||||
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 (RFCOMMChannel != NULL)
|
||||
RFCOMMChannel->DLCI = 0x00;
|
||||
RFCOMMChannel->State = RFCOMM_Channel_Closed;
|
||||
|
||||
BT_RFCOMM_DEBUG(1, ">> UA Sent");
|
||||
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];
|
||||
|
||||
/* If the channel's DLCI is zero, the channel state entry is free */
|
||||
if (!(CurrRFCOMMChannel->DLCI))
|
||||
/* If the channel's state is closed, the channel state entry is free */
|
||||
if (CurrRFCOMMChannel->State == RFCOMM_Channel_Closed)
|
||||
{
|
||||
CurrRFCOMMChannel->DLCI = FrameAddress->DLCI;
|
||||
CurrRFCOMMChannel->State = RFCOMM_Channel_Open;
|
||||
|
|
|
@ -111,14 +111,14 @@
|
|||
const uint16_t DataLen, const void* Data, Bluetooth_Channel_t* const Channel);
|
||||
|
||||
#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_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_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,
|
||||
const uint8_t* FrameData, Bluetooth_Channel_t* const Channel);
|
||||
|
||||
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -188,8 +188,8 @@ static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader
|
|||
/* 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 DLCI is zero, the channel state entry is free */
|
||||
if (!(RFCOMM_Channels[i].DLCI))
|
||||
/* If the channel's state is closed, the channel state entry is free */
|
||||
if (RFCOMMChannel->State == RFCOMM_Channel_Closed)
|
||||
{
|
||||
RFCOMMChannel = &RFCOMM_Channels[i];
|
||||
RFCOMMChannel->DLCI = Params->DLCI;
|
||||
|
@ -230,6 +230,6 @@ static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue