Make Bluetooth ACL channel searches skip over closed (invalid) channels. RFCOMM chann...
authorDean Camera <dean@fourwalledcubicle.com>
Sat, 26 Jun 2010 15:07:13 +0000 (15:07 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sat, 26 Jun 2010 15:07:13 +0000 (15:07 +0000)
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c
Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c
Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h
Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMMControl.c

index 1a66798..07d867b 100644 (file)
@@ -84,9 +84,14 @@ Bluetooth_Channel_t* Bluetooth_GetChannelData(const uint16_t SearchValue, const
        for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_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;
                
+               /* Search the current channel for the search key to see if it matches */
                switch (SearchKey)
                {
                        case CHANNEL_SEARCH_LOCALNUMBER:
index 7c39cb0..c7b3e8d 100644 (file)
@@ -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;
index 7b1f45b..edd93f9 100644 (file)
                                                       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
index 01fab78..5e9c86b 100644 (file)
@@ -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 */\r
                for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)\r
                {\r
-                       /* If the channel's DLCI is zero, the channel state entry is free */\r
-                       if (!(RFCOMM_Channels[i].DLCI))\r
+                       /* If the channel's state is closed, the channel state entry is free */\r
+                       if (RFCOMMChannel->State == RFCOMM_Channel_Closed)\r
                        {\r
-                               RFCOMMChannel       = &RFCOMM_Channels[i];\r
-                               RFCOMMChannel->DLCI = Params->DLCI;\r
-                               RFCOMMChannel->MTU  = 0xFFFF;\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
@@ -230,6 +230,6 @@ static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader
        \r
        BT_RFCOMM_DEBUG(1, ">> DPN Response");\r
 \r
-       /* Send the PDN response to acknowledge the command */\r
+       /* Send the DPN response to acknowledge the command */\r
        RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(DPNResponse), &DPNResponse, Channel);\r
 }\r