Add a new RFCOMM_ChannelSignalsReceived() Bluetooth stack callback from the RFCOMM layer for when the remote device sends new terminal control signals.
Fix RFCOMM_SendData() not aborting correctly when the requested RFCOMM channel is not found.
/** Pointer to the opened Bluetooth ACL channel structure for RFCOMM, used to send and receive data between the\r
* local and remote device once a RFCOMM channel has been opened.\r
*/\r
-Bluetooth_Channel_t* RFCOMMChannel = NULL;\r
+Bluetooth_Channel_t* SerialChannel_ACL = NULL;\r
\r
/** Pointer to the opened RFCOMM logical channel between local and remote device, once a RFCOMM ACL channel has been\r
* negotiated and a logical RFCOMM channel requested.\r
*/\r
-RFCOMM_Channel_t* SerialPortChannel = NULL;\r
+RFCOMM_Channel_t* SerialChannel_RFCOMM = NULL;\r
\r
/** Bluetooth stack callback event for when the Bluetooth stack has fully initialized using the attached\r
* Bluetooth dongle.\r
*/\r
bool Bluetooth_ChannelConnectionRequest(const uint16_t PSM)\r
{\r
- /* Always accept channel connection requests regardless of PSM */\r
- return true;\r
+ /* Only accept connections for channels that will be used for RFCOMM or SDP data */\r
+ return ((PSM == CHANNEL_PSM_RFCOMM) || (PSM == CHANNEL_PSM_SDP));\r
}\r
\r
/** Bluetooth stack callback event for when a Bluetooth ACL channel has been fully created and configured,\r
*\r
* \param[in] Channel Bluetooth ACL data channel information structure for the channel that can now be used\r
*/\r
-void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const Channel)\r
+void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const ACLChannel)\r
{\r
/* Save the RFCOMM channel for later use when we want to send RFCOMM data */\r
- if (Channel->PSM == CHANNEL_PSM_RFCOMM)\r
- RFCOMMChannel = Channel;\r
+ if (ACLChannel->PSM == CHANNEL_PSM_RFCOMM)\r
+ SerialChannel_ACL = ACLChannel;\r
}\r
\r
/** Bluetooth stack callback event for a non-signal ACL packet reception. This callback fires once a connection\r
* \param[in] DataLen Length of the packet data, in bytes\r
* \param[in] Channel Bluetooth ACL data channel information structure for the packet's destination channel\r
*/\r
-void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const Channel)\r
+void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const ACLChannel)\r
{\r
/* Run the correct packet handler based on the received packet's PSM, which indicates the service being carried */\r
- switch (Channel->PSM)\r
+ switch (ACLChannel->PSM)\r
{\r
case CHANNEL_PSM_SDP:\r
/* Service Discovery Protocol packet */\r
- SDP_ProcessPacket(Data, Channel);\r
+ SDP_ProcessPacket(Data, ACLChannel);\r
break;\r
case CHANNEL_PSM_RFCOMM:\r
/* RFCOMM (Serial Port) Protocol packet */\r
- RFCOMM_ProcessPacket(Data, Channel);\r
- break;\r
- default:\r
- /* Unknown Protocol packet */\r
- printf_P(PSTR("Unknown Packet Received (Channel 0x%04X, PSM: 0x%02X, Len: 0x%04X):\r\n"),\r
- Channel->LocalNumber, Channel->PSM, DataLen); \r
+ RFCOMM_ProcessPacket(Data, ACLChannel);\r
break;\r
}\r
}\r
\r
-void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel)\r
+void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const RFCOMMChannel)\r
{\r
/* Save the serial port RFCOMM logical channel for later use */\r
- SerialPortChannel = Channel;\r
+ SerialChannel_RFCOMM = RFCOMMChannel;\r
}\r
\r
/** RFCOMM layer callback for when a packet is received on an open RFCOMM channel.\r
* \param[in] DataLen Length of the received data, in bytes\r
* \param[in] Data Pointer to a buffer where the received data is stored\r
*/\r
-void RFCOMM_DataReceived(RFCOMM_Channel_t* const Channel, uint16_t DataLen, const uint8_t* Data)\r
+void RFCOMM_DataReceived(RFCOMM_Channel_t* const ACLChannel, uint16_t DataLen, const uint8_t* Data)\r
{\r
/* Write the received bytes to the serial port */\r
for (uint8_t i = 0; i < DataLen; i++)\r
putchar(Data[i]);\r
\r
/* Echo the data back to the sending device */\r
- RFCOMM_SendData(DataLen, Data, Channel, RFCOMMChannel);\r
+ RFCOMM_SendData(DataLen, Data, SerialChannel_RFCOMM, SerialChannel_ACL);\r
+}\r
+\r
+void RFCOMM_ChannelSignalsReceived(RFCOMM_Channel_t* const RFCOMMChannel)\r
+{\r
+ // Currently do nothing in response to the remote device sending new terminal control signals\r
}\r
#define LEDMASK_USB_BUSY LEDS_LED2\r
\r
/* External Variables: */\r
- extern Bluetooth_Channel_t* RFCOMMChannel;\r
+ extern Bluetooth_Channel_t* SerialChannel_ACL;\r
+ extern RFCOMM_Channel_t* SerialChannel_RFCOMM;\r
\r
#endif\r
for (;;)
{
- if ((RFCOMMChannel != NULL) && (RFCOMMChannel->State == BT_Channel_Open))
- RFCOMM_ServiceChannels(RFCOMMChannel);
+ RFCOMM_ServiceChannels(SerialChannel_ACL);
Bluetooth_Host_Task();
Bluetooth_Stack_USBTask();
/*
TODO: Make SendPacket respect receiver's MTU
TODO: Make ReceivePacket stitch together MTU fragments (?)
- TODO: Add channel opened/closed callbacks
*/
#define INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C
}
}
+/** Retrieves the channel information structure with the given local or remote channel number from the channel list.
+ *
+ * \param[in] SearchValue Value to search for in the channel structure list
+ * \param[in] SearchKey Key to search within the channel structure, a CHANNEL_SEARCH_* mask
+ *
+ * \return Pointer to the matching channel information structure in the channel table if found, NULL otherwise
+ */
+Bluetooth_Channel_t* Bluetooth_GetChannelData(const uint16_t SearchValue, const uint8_t SearchKey)
+{
+ 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:
+ FoundMatch = (SearchValue == ChannelData->LocalNumber);
+ break;
+ case CHANNEL_SEARCH_REMOTENUMBER:
+ FoundMatch = (SearchValue == ChannelData->RemoteNumber);
+ break;
+ case CHANNEL_SEARCH_PSM:
+ FoundMatch = (SearchValue == ChannelData->PSM);
+ break;
+ }
+
+ if (FoundMatch)
+ return ChannelData;
+ }
+
+ return NULL;
+}
+
/** Sends a packet to the remote device on the specified channel.
*
* \param[in] Data Pointer to a buffer where the data is to be sourced from
*
* \return A value from the \ref BT_SendPacket_ErrorCodes_t enum
*/
-uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Channel_t* const Channel)
+uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Channel_t* const ACLChannel)
{
BT_ACL_Header_t ACLPacketHeader;
BT_DataPacket_Header_t DataHeader;
return BT_SENDPACKET_NotConnected;
/* If the destination channel is not the signalling channel and it is not currently fully open, abort */
- if ((Channel != NULL) && (Channel->State != BT_Channel_Open))
+ if ((ACLChannel == NULL) || (ACLChannel->State != BT_Channel_Open))
return BT_SENDPACKET_ChannelNotOpen;
/* Fill out the packet's header from the remote device connection information structure */
ACLPacketHeader.ConnectionHandle = (Bluetooth_Connection.ConnectionHandle | BT_ACL_FIRST_AUTOFLUSH);
ACLPacketHeader.DataLength = sizeof(DataHeader) + DataLen;
DataHeader.PayloadLength = DataLen;
- DataHeader.DestinationChannel = (Channel == NULL) ? BT_CHANNEL_SIGNALING : Channel->RemoteNumber;
+ DataHeader.DestinationChannel = (ACLChannel == NULL) ? BT_CHANNEL_SIGNALING : ACLChannel->RemoteNumber;
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
*
* \param[in,out] Channel Channel information structure of the channel to close
*/
-void Bluetooth_CloseChannel(Bluetooth_Channel_t* const Channel)
+void Bluetooth_CloseChannel(Bluetooth_Channel_t* const ACLChannel)
{
/* Don't try to close a non-existing or already closed channel */
- if ((Channel == NULL) || (Channel->State == BT_Channel_Closed))
+ if ((ACLChannel == NULL) || (ACLChannel->State == BT_Channel_Closed))
return;
/* Set the channel's state to the start of the teardown process */
- Channel->State = BT_Channel_WaitDisconnect;
+ ACLChannel->State = BT_Channel_WaitDisconnect;
struct
{
PacketData.SignalCommandHeader.Length = sizeof(PacketData.DisconnectionRequest);
/* Fill out the Disconnection Request in the response packet */
- PacketData.DisconnectionRequest.DestinationChannel = Channel->RemoteNumber;
- PacketData.DisconnectionRequest.SourceChannel = Channel->LocalNumber;
+ PacketData.DisconnectionRequest.DestinationChannel = ACLChannel->RemoteNumber;
+ PacketData.DisconnectionRequest.SourceChannel = ACLChannel->LocalNumber;
Bluetooth_SendPacket(&PacketData, sizeof(PacketData), NULL);
*/
void Bluetooth_Stack_Init(void)
{
- /* Reset the HCI state machine - this will eventually reset the adapter and stack when the Bluetooth stack task is called */
+ /* Reset the HCI state machine - this will reset the adapter and stack when the Bluetooth stack task is called */
Bluetooth_State.CurrentHCIState = Bluetooth_Init;
Bluetooth_State.NextHCIState = Bluetooth_Init;
}
Bluetooth_HCITask();
Bluetooth_ACLTask();
}
-
-/** Retrieves the channel information structure with the given local or remote channel number from the channel list.
- *
- * \param[in] SearchValue Value to search for in the channel structure list
- * \param[in] SearchKey Key to search within the channel structure, a CHANNEL_SEARCH_* mask
- *
- * \return Pointer to the matching channel information structure in the channel table if found, NULL otherwise
- */
-Bluetooth_Channel_t* Bluetooth_GetChannelData(const uint16_t SearchValue, const uint8_t SearchKey)
-{
- 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:
- FoundMatch = (SearchValue == ChannelData->LocalNumber);
- break;
- case CHANNEL_SEARCH_REMOTENUMBER:
- FoundMatch = (SearchValue == ChannelData->RemoteNumber);
- break;
- case CHANNEL_SEARCH_PSM:
- FoundMatch = (SearchValue == ChannelData->PSM);
- break;
- }
-
- if (FoundMatch)
- return ChannelData;
- }
-
- return NULL;
-}
void Bluetooth_ConnectionComplete(void);
void Bluetooth_DisconnectionComplete(void);
bool Bluetooth_ChannelConnectionRequest(const uint16_t PSM);
- void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const Channel);
- void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const Channel);
+ void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const ACLChannel);
+ void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const ACLChannel);
Bluetooth_Channel_t* Bluetooth_GetChannelData(const uint16_t SearchValue, const uint8_t SearchKey);
Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM);
- void Bluetooth_CloseChannel(Bluetooth_Channel_t* const Channel);
- uint8_t Bluetooth_SendPacket(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const Channel);
+ void Bluetooth_CloseChannel(Bluetooth_Channel_t* const ACLChannel);
+ uint8_t Bluetooth_SendPacket(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const ACLChannel);
/* External Variables: */
extern Bluetooth_Device_t Bluetooth_DeviceConfiguration;
RFCOMM_Channels[i].State = RFCOMM_Channel_Closed;
}
-void RFCOMM_ServiceChannels(Bluetooth_Channel_t* const BluetoothChannel)
+void RFCOMM_ServiceChannels(Bluetooth_Channel_t* const ACLChannel)
{
+ /* Abort if the RFCOMM ACL channel is not currently open */
+ if ((ACLChannel == NULL) || (ACLChannel->State != BT_Channel_Open))
+ return;
+
+ /* Loop through each of the RFCOMM channels, send any required RFCOMM control commands */
for (uint8_t i = 0; i < RFCOMM_MAX_OPEN_CHANNELS; i++)
{
RFCOMM_Channel_t* RFCOMMChannel = &RFCOMM_Channels[i];
{
/* Indicate that the local signals have been sent, transmit them to the remote device */
RFCOMMChannel->ConfigFlags |= RFCOMM_CONFIG_LOCALSIGNALSSENT;
- RFCOMM_SendChannelSignals(RFCOMMChannel, BluetoothChannel);
+ RFCOMM_SendChannelSignals(RFCOMMChannel, ACLChannel);
}
/* If signals have been configured in both directions, progress to the open state */
}
}
-void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
+void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const ACLChannel)
{
const RFCOMM_Header_t* FrameHeader = (const RFCOMM_Header_t*)Data;
const uint8_t* FrameData = (const uint8_t*)Data + sizeof(RFCOMM_Header_t);
switch (FrameHeader->Control & ~FRAME_POLL_FINAL)
{
case RFCOMM_Frame_DM:
- RFCOMM_ProcessDM(&FrameHeader->Address, Channel);
+ RFCOMM_ProcessDM(&FrameHeader->Address, ACLChannel);
break;
case RFCOMM_Frame_DISC:
- RFCOMM_ProcessDISC(&FrameHeader->Address, Channel);
+ RFCOMM_ProcessDISC(&FrameHeader->Address, ACLChannel);
break;
case RFCOMM_Frame_SABM:
- RFCOMM_ProcessSABM(&FrameHeader->Address, Channel);
+ RFCOMM_ProcessSABM(&FrameHeader->Address, ACLChannel);
break;
case RFCOMM_Frame_UA:
- RFCOMM_ProcessUA(&FrameHeader->Address, Channel);
+ RFCOMM_ProcessUA(&FrameHeader->Address, ACLChannel);
break;
case RFCOMM_Frame_UIH:
- RFCOMM_ProcessUIH(&FrameHeader->Address, FrameDataLen, FrameData, Channel);
+ RFCOMM_ProcessUIH(&FrameHeader->Address, FrameDataLen, FrameData, ACLChannel);
break;
default:
BT_RFCOMM_DEBUG(1, "<< Unknown Frame Received");
}
}
-void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Bluetooth_Channel_t* const BluetoothChannel)
+void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Bluetooth_Channel_t* const ACLChannel)
{
BT_RFCOMM_DEBUG(1, ">> MSC Command");
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", RFCOMMChannel->DLCI);
MSCommand.Params.BreakSignal = RFCOMMChannel->Local.BreakSignal;
/* Send the MSC command to the remote device */
- RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, true, RFCOMM_Frame_UIH, sizeof(MSCommand), &MSCommand, BluetoothChannel);
+ RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, true, RFCOMM_Frame_UIH, sizeof(MSCommand), &MSCommand, ACLChannel);
}
void RFCOMM_SendData(const uint16_t DataLen, const uint8_t* Data, const RFCOMM_Channel_t* const RFCOMMChannel,
- Bluetooth_Channel_t* const BluetoothChannel)
+ Bluetooth_Channel_t* const ACLChannel)
{
if (RFCOMMChannel->State != RFCOMM_Channel_Open)
return;
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", RFCOMMChannel->DLCI);
/* Send the MSC command to the remote device */
- RFCOMM_SendFrame(RFCOMMChannel->DLCI, false, RFCOMM_Frame_UIH, DataLen, Data, BluetoothChannel);
+ RFCOMM_SendFrame(RFCOMMChannel->DLCI, false, RFCOMM_Frame_UIH, DataLen, Data, ACLChannel);
}
RFCOMM_Channel_t* RFCOMM_GetFreeChannelEntry(const uint8_t DLCI)
}
void RFCOMM_SendFrame(const uint8_t DLCI, const bool CommandResponse, const uint8_t Control, const uint16_t DataLen,
- const void* Data, Bluetooth_Channel_t* const Channel)
+ const void* Data, Bluetooth_Channel_t* const ACLChannel)
{
struct
{
ResponsePacket.FCS = RFCOMM_GetFCSValue(&ResponsePacket, CRCLength);
/* Send the completed response packet to the sender */
- Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), Channel);
+ Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), ACLChannel);
}
static uint8_t RFCOMM_GetFCSValue(const void* FrameStart, uint8_t Length)
/* 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]]);
+ FCS = pgm_read_byte(&CRC8_Table[FCS ^ ((const uint8_t*)FrameStart)[i]]);
return ~FCS;
}
-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 ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< DM Received");
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
}
-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 ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< DISC Received");
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
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);
+ RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_UA | FRAME_POLL_FINAL), 0, NULL, ACLChannel);
}
-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 ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< SABM Received");
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->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, Channel);
+ RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_UA | FRAME_POLL_FINAL), 0, NULL, ACLChannel);
return;
}
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);
+ 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, Channel);
+ RFCOMM_SendFrame(FrameAddress->DLCI, true, (RFCOMM_Frame_DM | FRAME_POLL_FINAL), 0, NULL, ACLChannel);
}
}
-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 ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< UA Received");
BT_RFCOMM_DEBUG(2, "-- DLCI 0x%02X", FrameAddress->DLCI);
}
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 ACLChannel)
{
if (FrameAddress->DLCI == RFCOMM_CONTROL_DLCI)
{
- RFCOMM_ProcessControlCommand(FrameData, Channel);
+ RFCOMM_ProcessControlCommand(FrameData, ACLChannel);
return;
}
/* Function Prototypes: */
void RFCOMM_Initialize(void);
- void RFCOMM_ServiceChannels(Bluetooth_Channel_t* const Channel);
- void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const BluetoothChannel);
+ void RFCOMM_ServiceChannels(Bluetooth_Channel_t* const ACLChannel);
+ void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const ACLChannel);
void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel,
- Bluetooth_Channel_t* const BluetoothChannel);
+ Bluetooth_Channel_t* const ACLChannel);
void RFCOMM_SendData(const uint16_t DataLen, const uint8_t* Data,
const RFCOMM_Channel_t* const RFCOMMChannel,
- Bluetooth_Channel_t* const BluetoothChannel);
+ Bluetooth_Channel_t* const ACLChannel);
- void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel);
- void RFCOMM_DataReceived(RFCOMM_Channel_t* const Channel, uint16_t DataLen, const uint8_t* Data);
+ void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const RFCOMMChannel);
+ void RFCOMM_DataReceived(RFCOMM_Channel_t* const RFCOMMChannel, uint16_t DataLen, const uint8_t* Data);
+ void RFCOMM_ChannelSignalsReceived(RFCOMM_Channel_t* const RFCOMMChannel);
RFCOMM_Channel_t* RFCOMM_GetFreeChannelEntry(const uint8_t DLCI);
RFCOMM_Channel_t* RFCOMM_GetChannelData(const uint8_t DLCI);
uint16_t RFCOMM_GetVariableFieldValue(const uint8_t** BufferPos);
void RFCOMM_SendFrame(const uint8_t DLCI, const bool CommandResponse, const uint8_t Control,
- const uint16_t DataLen, const void* Data, Bluetooth_Channel_t* const Channel);
+ const uint16_t DataLen, const void* Data, Bluetooth_Channel_t* const ACLChannel);
#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_ProcessDM(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const ACLChannel);
+ static void RFCOMM_ProcessDISC(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const ACLChannel);
+ static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const ACLChannel);
+ static void RFCOMM_ProcessUA(const RFCOMM_Address_t* const FrameAddress, Bluetooth_Channel_t* const ACLChannel);
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 ACLChannel);
#endif
#endif
#define INCLUDE_FROM_RFCOMM_CONTROL_C\r
#include "RFCOMMControl.h"\r
\r
-void RFCOMM_ProcessControlCommand(const uint8_t* Command, Bluetooth_Channel_t* const Channel)\r
+void RFCOMM_ProcessControlCommand(const uint8_t* Command, Bluetooth_Channel_t* const ACLChannel)\r
{\r
const RFCOMM_Command_t* CommandHeader = (const RFCOMM_Command_t*)Command;\r
const uint8_t* CommandData = (const uint8_t*)Command + sizeof(RFCOMM_Command_t);\r
switch (CommandHeader->Command)\r
{\r
case RFCOMM_Control_Test:\r
- RFCOMM_ProcessTestCommand(CommandHeader, CommandDataLen, CommandData, Channel);\r
+ RFCOMM_ProcessTestCommand(CommandHeader, CommandDataLen, CommandData, ACLChannel);\r
break;\r
case RFCOMM_Control_FlowControlEnable:\r
- RFCOMM_ProcessFCECommand(CommandHeader, CommandData, Channel);\r
+ RFCOMM_ProcessFCECommand(CommandHeader, CommandData, ACLChannel);\r
break;\r
case RFCOMM_Control_FlowControlDisable:\r
- RFCOMM_ProcessFCDCommand(CommandHeader, CommandData, Channel);\r
+ RFCOMM_ProcessFCDCommand(CommandHeader, CommandData, ACLChannel);\r
break;\r
case RFCOMM_Control_ModemStatus:\r
- RFCOMM_ProcessMSCCommand(CommandHeader, CommandDataLen, CommandData, Channel);\r
+ RFCOMM_ProcessMSCCommand(CommandHeader, CommandDataLen, CommandData, ACLChannel);\r
break;\r
case RFCOMM_Control_RemotePortNegotiation:\r
- RFCOMM_ProcessRPNCommand(CommandHeader, CommandData, Channel);\r
+ RFCOMM_ProcessRPNCommand(CommandHeader, CommandData, ACLChannel);\r
break;\r
case RFCOMM_Control_RemoteLineStatus:\r
- RFCOMM_ProcessRLSCommand(CommandHeader, CommandData, Channel);\r
+ RFCOMM_ProcessRLSCommand(CommandHeader, CommandData, ACLChannel);\r
break;\r
case RFCOMM_Control_DLCParameterNegotiation:\r
- RFCOMM_ProcessDPNCommand(CommandHeader, CommandData, Channel);\r
+ RFCOMM_ProcessDPNCommand(CommandHeader, CommandData, ACLChannel);\r
break;\r
default:\r
BT_RFCOMM_DEBUG(1, "<< Unknown Command"); \r
}\r
\r
static void RFCOMM_ProcessTestCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen,\r
- const uint8_t* CommandData, Bluetooth_Channel_t* const Channel)\r
+ const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel)\r
{\r
const uint8_t* Params = (const uint8_t*)CommandData;\r
\r
BT_RFCOMM_DEBUG(1, ">> TEST Response");\r
\r
/* Send the PDN response to acknowledge the command */\r
- RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(TestResponse), &TestResponse, Channel);\r
+ RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(TestResponse), &TestResponse, ACLChannel);\r
}\r
\r
static void RFCOMM_ProcessFCECommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel)\r
+ Bluetooth_Channel_t* const ACLChannel)\r
{\r
BT_RFCOMM_DEBUG(1, "<< FCE Command");\r
}\r
\r
static void RFCOMM_ProcessFCDCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel)\r
+ Bluetooth_Channel_t* const ACLChannel)\r
{\r
BT_RFCOMM_DEBUG(1, "<< FCD Command");\r
}\r
\r
static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen,\r
- const uint8_t* CommandData, Bluetooth_Channel_t* const Channel)\r
+ const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel)\r
{\r
const RFCOMM_MSC_Parameters_t* Params = (const RFCOMM_MSC_Parameters_t*)CommandData;\r
\r
/* If the command contains the optional break signals field, store the value */\r
if (CommandDataLen == sizeof(RFCOMM_MSC_Parameters_t))\r
RFCOMMChannel->Remote.BreakSignal = Params->BreakSignal;\r
+\r
+ /* Notify the user application that the signals have been received */\r
+ RFCOMM_ChannelSignalsReceived(RFCOMMChannel);\r
\r
struct\r
{\r
\r
/* Send the MSC response to acknowledge the command */\r
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH,\r
- (sizeof(MSResponse) - sizeof(MSResponse.Params) + CommandDataLen), &MSResponse, Channel);\r
+ (sizeof(MSResponse) - sizeof(MSResponse.Params) + CommandDataLen), &MSResponse, ACLChannel);\r
}\r
else\r
{\r
}\r
\r
static void RFCOMM_ProcessRPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel)\r
+ Bluetooth_Channel_t* const ACLChannel)\r
{\r
BT_RFCOMM_DEBUG(1, "<< RPN Command");\r
}\r
\r
static void RFCOMM_ProcessRLSCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel)\r
+ Bluetooth_Channel_t* const ACLChannel)\r
{\r
BT_RFCOMM_DEBUG(1, "<< RLS Command");\r
}\r
\r
static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel)\r
+ Bluetooth_Channel_t* const ACLChannel)\r
{\r
const RFCOMM_DPN_Parameters_t* Params = (const RFCOMM_DPN_Parameters_t*)CommandData;\r
\r
BT_RFCOMM_DEBUG(1, ">> DPN Response");\r
\r
/* Send the DPN response to acknowledge the command */\r
- RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(DPNResponse), &DPNResponse, Channel);\r
+ RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(DPNResponse), &DPNResponse, ACLChannel);\r
}\r
\r
#if defined(INCLUDE_FROM_RFCOMM_CONTROL_C)\r
static void RFCOMM_ProcessTestCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen, \r
- const uint8_t* CommandData, Bluetooth_Channel_t* const Channel);\r
+ const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel);\r
static void RFCOMM_ProcessFCECommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel);\r
+ Bluetooth_Channel_t* const ACLChannel);\r
static void RFCOMM_ProcessFCDCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel);\r
+ Bluetooth_Channel_t* const ACLChannel);\r
static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen,\r
- const uint8_t* CommandData, Bluetooth_Channel_t* const Channel);\r
+ const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel);\r
static void RFCOMM_ProcessRPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel);\r
+ Bluetooth_Channel_t* const ACLChannel);\r
static void RFCOMM_ProcessRLSCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel);\r
+ Bluetooth_Channel_t* const ACLChannel);\r
static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,\r
- Bluetooth_Channel_t* const Channel);\r
+ Bluetooth_Channel_t* const ACLChannel);\r
#endif\r
\r
#endif\r
*/
static void SDP_ProcessServiceSearch(const SDP_PDUHeader_t* const SDPHeader, Bluetooth_Channel_t* const Channel)
{
- const void* CurrentParameter = ((void*)SDPHeader + sizeof(SDP_PDUHeader_t));
+ const void* CurrentParameter = ((const void*)SDPHeader + sizeof(SDP_PDUHeader_t));
BT_SDP_DEBUG(1, "<< Service Search");
*/
static void SDP_ProcessServiceAttribute(const SDP_PDUHeader_t* const SDPHeader, Bluetooth_Channel_t* const Channel)
{
- const void* CurrentParameter = ((void*)SDPHeader + sizeof(SDP_PDUHeader_t));
+ const void* CurrentParameter = ((const void*)SDPHeader + sizeof(SDP_PDUHeader_t));
BT_SDP_DEBUG(1, "<< Service Attribute");
*/
static void SDP_ProcessServiceSearchAttribute(const SDP_PDUHeader_t* const SDPHeader, Bluetooth_Channel_t* const Channel)
{
- const void* CurrentParameter = ((void*)SDPHeader + sizeof(SDP_PDUHeader_t));
+ const void* CurrentParameter = ((const void*)SDPHeader + sizeof(SDP_PDUHeader_t));
BT_SDP_DEBUG(1, "<< Service Search Attribute");
*/
static inline uint8_t SDP_ReadData8(const void** BufferPos)
{
- uint8_t Data = *((uint8_t*)*BufferPos);
+ uint8_t Data = *((const uint8_t*)*BufferPos);
*BufferPos += sizeof(uint8_t);
return Data;
*/
static inline uint16_t SDP_ReadData16(const void** BufferPos)
{
- uint16_t Data = SwapEndian_16(*((uint16_t*)*BufferPos));
+ uint16_t Data = SwapEndian_16(*((const uint16_t*)*BufferPos));
*BufferPos += sizeof(uint16_t);
return Data;
*/
static inline uint32_t SDP_ReadData32(const void** BufferPos)
{
- uint32_t Data = SwapEndian_32(*((uint32_t*)*BufferPos));
+ uint32_t Data = SwapEndian_32(*((const uint32_t*)*BufferPos));
*BufferPos += sizeof(uint32_t);
return Data;