Rename Bluetooth stack function parameters to clearly indicate what sort of Bluetooth channel (ACL, RFCOMM) is required for each parameter, to make the code easier to read.

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.
pull/1469/head
Dean Camera 14 years ago
parent ba711d6759
commit 6276d5f82a

@ -40,12 +40,12 @@
/** Pointer to the opened Bluetooth ACL channel structure for RFCOMM, used to send and receive data between the
* local and remote device once a RFCOMM channel has been opened.
*/
Bluetooth_Channel_t* RFCOMMChannel = NULL;
Bluetooth_Channel_t* SerialChannel_ACL = NULL;
/** Pointer to the opened RFCOMM logical channel between local and remote device, once a RFCOMM ACL channel has been
* negotiated and a logical RFCOMM channel requested.
*/
RFCOMM_Channel_t* SerialPortChannel = NULL;
RFCOMM_Channel_t* SerialChannel_RFCOMM = NULL;
/** Bluetooth stack callback event for when the Bluetooth stack has fully initialized using the attached
* Bluetooth dongle.
@ -115,8 +115,8 @@ void Bluetooth_DisconnectionComplete(void)
*/
bool Bluetooth_ChannelConnectionRequest(const uint16_t PSM)
{
/* Always accept channel connection requests regardless of PSM */
return true;
/* Only accept connections for channels that will be used for RFCOMM or SDP data */
return ((PSM == CHANNEL_PSM_RFCOMM) || (PSM == CHANNEL_PSM_SDP));
}
/** Bluetooth stack callback event for when a Bluetooth ACL channel has been fully created and configured,
@ -124,11 +124,11 @@ bool Bluetooth_ChannelConnectionRequest(const uint16_t PSM)
*
* \param[in] Channel Bluetooth ACL data channel information structure for the channel that can now be used
*/
void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const Channel)
void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const ACLChannel)
{
/* Save the RFCOMM channel for later use when we want to send RFCOMM data */
if (Channel->PSM == CHANNEL_PSM_RFCOMM)
RFCOMMChannel = Channel;
if (ACLChannel->PSM == CHANNEL_PSM_RFCOMM)
SerialChannel_ACL = ACLChannel;
}
/** Bluetooth stack callback event for a non-signal ACL packet reception. This callback fires once a connection
@ -138,31 +138,26 @@ void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const Channel)
* \param[in] DataLen Length of the packet data, in bytes
* \param[in] Channel Bluetooth ACL data channel information structure for the packet's destination channel
*/
void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const Channel)
void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const ACLChannel)
{
/* Run the correct packet handler based on the received packet's PSM, which indicates the service being carried */
switch (Channel->PSM)
switch (ACLChannel->PSM)
{
case CHANNEL_PSM_SDP:
/* Service Discovery Protocol packet */
SDP_ProcessPacket(Data, Channel);
SDP_ProcessPacket(Data, ACLChannel);
break;
case CHANNEL_PSM_RFCOMM:
/* RFCOMM (Serial Port) Protocol packet */
RFCOMM_ProcessPacket(Data, Channel);
break;
default:
/* Unknown Protocol packet */
printf_P(PSTR("Unknown Packet Received (Channel 0x%04X, PSM: 0x%02X, Len: 0x%04X):\r\n"),
Channel->LocalNumber, Channel->PSM, DataLen);
RFCOMM_ProcessPacket(Data, ACLChannel);
break;
}
}
void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel)
void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const RFCOMMChannel)
{
/* Save the serial port RFCOMM logical channel for later use */
SerialPortChannel = Channel;
SerialChannel_RFCOMM = RFCOMMChannel;
}
/** RFCOMM layer callback for when a packet is received on an open RFCOMM channel.
@ -171,12 +166,17 @@ void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel)
* \param[in] DataLen Length of the received data, in bytes
* \param[in] Data Pointer to a buffer where the received data is stored
*/
void RFCOMM_DataReceived(RFCOMM_Channel_t* const Channel, uint16_t DataLen, const uint8_t* Data)
void RFCOMM_DataReceived(RFCOMM_Channel_t* const ACLChannel, uint16_t DataLen, const uint8_t* Data)
{
/* Write the received bytes to the serial port */
for (uint8_t i = 0; i < DataLen; i++)
putchar(Data[i]);
/* Echo the data back to the sending device */
RFCOMM_SendData(DataLen, Data, Channel, RFCOMMChannel);
RFCOMM_SendData(DataLen, Data, SerialChannel_RFCOMM, SerialChannel_ACL);
}
void RFCOMM_ChannelSignalsReceived(RFCOMM_Channel_t* const RFCOMMChannel)
{
// Currently do nothing in response to the remote device sending new terminal control signals
}

@ -65,6 +65,7 @@
#define LEDMASK_USB_BUSY LEDS_LED2
/* External Variables: */
extern Bluetooth_Channel_t* RFCOMMChannel;
extern Bluetooth_Channel_t* SerialChannel_ACL;
extern RFCOMM_Channel_t* SerialChannel_RFCOMM;
#endif

@ -58,8 +58,7 @@ int main(void)
for (;;)
{
if ((RFCOMMChannel != NULL) && (RFCOMMChannel->State == BT_Channel_Open))
RFCOMM_ServiceChannels(RFCOMMChannel);
RFCOMM_ServiceChannels(SerialChannel_ACL);
Bluetooth_Host_Task();
Bluetooth_Stack_USBTask();

@ -38,7 +38,6 @@
/*
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
@ -205,6 +204,46 @@ static void Bluetooth_ProcessIncommingACLPackets(void)
}
}
/** 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
@ -214,7 +253,7 @@ static void Bluetooth_ProcessIncommingACLPackets(void)
*
* \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;
@ -224,14 +263,14 @@ uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Chann
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);
@ -329,14 +368,14 @@ Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM)
*
* \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
{
@ -350,8 +389,8 @@ void Bluetooth_CloseChannel(Bluetooth_Channel_t* const Channel)
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);

@ -55,7 +55,7 @@ Bluetooth_Stack_State_t Bluetooth_State = { IsInitialized: false };
*/
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;
}
@ -71,43 +71,3 @@ void Bluetooth_Stack_USBTask(void)
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;
}

@ -155,13 +155,13 @@
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;

@ -73,8 +73,13 @@ void RFCOMM_Initialize(void)
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];
@ -86,7 +91,7 @@ void RFCOMM_ServiceChannels(Bluetooth_Channel_t* const BluetoothChannel)
{
/* 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 */
@ -100,7 +105,7 @@ void RFCOMM_ServiceChannels(Bluetooth_Channel_t* const BluetoothChannel)
}
}
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);
@ -110,19 +115,19 @@ void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
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");
@ -130,7 +135,7 @@ void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
}
}
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);
@ -149,11 +154,11 @@ void RFCOMM_SendChannelSignals(const RFCOMM_Channel_t* const RFCOMMChannel, Blue
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;
@ -162,7 +167,7 @@ void RFCOMM_SendData(const uint16_t DataLen, const uint8_t* Data, const RFCOMM_C
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)
@ -232,7 +237,7 @@ 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 void* Data, Bluetooth_Channel_t* const ACLChannel)
{
struct
{
@ -269,7 +274,7 @@ void RFCOMM_SendFrame(const uint8_t DLCI, const bool CommandResponse, const uint
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)
@ -278,18 +283,18 @@ 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);
@ -301,10 +306,10 @@ static void RFCOMM_ProcessDISC(const RFCOMM_Address_t* const FrameAddress, Bluet
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);
@ -314,7 +319,7 @@ static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress, Bluet
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;
}
@ -332,29 +337,29 @@ static void RFCOMM_ProcessSABM(const RFCOMM_Address_t* const FrameAddress, Bluet
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;
}

@ -101,33 +101,34 @@
/* 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

@ -38,7 +38,7 @@
#define INCLUDE_FROM_RFCOMM_CONTROL_C
#include "RFCOMMControl.h"
void RFCOMM_ProcessControlCommand(const uint8_t* Command, Bluetooth_Channel_t* const Channel)
void RFCOMM_ProcessControlCommand(const uint8_t* Command, Bluetooth_Channel_t* const ACLChannel)
{
const RFCOMM_Command_t* CommandHeader = (const RFCOMM_Command_t*)Command;
const uint8_t* CommandData = (const uint8_t*)Command + sizeof(RFCOMM_Command_t);
@ -47,25 +47,25 @@ void RFCOMM_ProcessControlCommand(const uint8_t* Command, Bluetooth_Channel_t* c
switch (CommandHeader->Command)
{
case RFCOMM_Control_Test:
RFCOMM_ProcessTestCommand(CommandHeader, CommandDataLen, CommandData, Channel);
RFCOMM_ProcessTestCommand(CommandHeader, CommandDataLen, CommandData, ACLChannel);
break;
case RFCOMM_Control_FlowControlEnable:
RFCOMM_ProcessFCECommand(CommandHeader, CommandData, Channel);
RFCOMM_ProcessFCECommand(CommandHeader, CommandData, ACLChannel);
break;
case RFCOMM_Control_FlowControlDisable:
RFCOMM_ProcessFCDCommand(CommandHeader, CommandData, Channel);
RFCOMM_ProcessFCDCommand(CommandHeader, CommandData, ACLChannel);
break;
case RFCOMM_Control_ModemStatus:
RFCOMM_ProcessMSCCommand(CommandHeader, CommandDataLen, CommandData, Channel);
RFCOMM_ProcessMSCCommand(CommandHeader, CommandDataLen, CommandData, ACLChannel);
break;
case RFCOMM_Control_RemotePortNegotiation:
RFCOMM_ProcessRPNCommand(CommandHeader, CommandData, Channel);
RFCOMM_ProcessRPNCommand(CommandHeader, CommandData, ACLChannel);
break;
case RFCOMM_Control_RemoteLineStatus:
RFCOMM_ProcessRLSCommand(CommandHeader, CommandData, Channel);
RFCOMM_ProcessRLSCommand(CommandHeader, CommandData, ACLChannel);
break;
case RFCOMM_Control_DLCParameterNegotiation:
RFCOMM_ProcessDPNCommand(CommandHeader, CommandData, Channel);
RFCOMM_ProcessDPNCommand(CommandHeader, CommandData, ACLChannel);
break;
default:
BT_RFCOMM_DEBUG(1, "<< Unknown Command");
@ -74,7 +74,7 @@ void RFCOMM_ProcessControlCommand(const uint8_t* Command, Bluetooth_Channel_t* c
}
static void RFCOMM_ProcessTestCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen,
const uint8_t* CommandData, Bluetooth_Channel_t* const Channel)
const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel)
{
const uint8_t* Params = (const uint8_t*)CommandData;
@ -95,23 +95,23 @@ static void RFCOMM_ProcessTestCommand(const RFCOMM_Command_t* const CommandHeade
BT_RFCOMM_DEBUG(1, ">> TEST Response");
/* Send the PDN response to acknowledge the command */
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(TestResponse), &TestResponse, Channel);
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH, sizeof(TestResponse), &TestResponse, ACLChannel);
}
static void RFCOMM_ProcessFCECommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel)
Bluetooth_Channel_t* const ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< FCE Command");
}
static void RFCOMM_ProcessFCDCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel)
Bluetooth_Channel_t* const ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< FCD Command");
}
static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen,
const uint8_t* CommandData, Bluetooth_Channel_t* const Channel)
const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel)
{
const RFCOMM_MSC_Parameters_t* Params = (const RFCOMM_MSC_Parameters_t*)CommandData;
@ -139,6 +139,9 @@ static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader
/* If the command contains the optional break signals field, store the value */
if (CommandDataLen == sizeof(RFCOMM_MSC_Parameters_t))
RFCOMMChannel->Remote.BreakSignal = Params->BreakSignal;
/* Notify the user application that the signals have been received */
RFCOMM_ChannelSignalsReceived(RFCOMMChannel);
struct
{
@ -156,7 +159,7 @@ static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader
/* Send the MSC response to acknowledge the command */
RFCOMM_SendFrame(RFCOMM_CONTROL_DLCI, false, RFCOMM_Frame_UIH,
(sizeof(MSResponse) - sizeof(MSResponse.Params) + CommandDataLen), &MSResponse, Channel);
(sizeof(MSResponse) - sizeof(MSResponse.Params) + CommandDataLen), &MSResponse, ACLChannel);
}
else
{
@ -166,19 +169,19 @@ static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader
}
static void RFCOMM_ProcessRPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel)
Bluetooth_Channel_t* const ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< RPN Command");
}
static void RFCOMM_ProcessRLSCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel)
Bluetooth_Channel_t* const ACLChannel)
{
BT_RFCOMM_DEBUG(1, "<< RLS Command");
}
static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel)
Bluetooth_Channel_t* const ACLChannel)
{
const RFCOMM_DPN_Parameters_t* Params = (const RFCOMM_DPN_Parameters_t*)CommandData;
@ -227,5 +230,5 @@ static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader
BT_RFCOMM_DEBUG(1, ">> DPN Response");
/* 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, ACLChannel);
}

@ -119,19 +119,19 @@
#if defined(INCLUDE_FROM_RFCOMM_CONTROL_C)
static void RFCOMM_ProcessTestCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen,
const uint8_t* CommandData, Bluetooth_Channel_t* const Channel);
const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel);
static void RFCOMM_ProcessFCECommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel);
Bluetooth_Channel_t* const ACLChannel);
static void RFCOMM_ProcessFCDCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel);
Bluetooth_Channel_t* const ACLChannel);
static void RFCOMM_ProcessMSCCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t CommandDataLen,
const uint8_t* CommandData, Bluetooth_Channel_t* const Channel);
const uint8_t* CommandData, Bluetooth_Channel_t* const ACLChannel);
static void RFCOMM_ProcessRPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel);
Bluetooth_Channel_t* const ACLChannel);
static void RFCOMM_ProcessRLSCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel);
Bluetooth_Channel_t* const ACLChannel);
static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* const CommandHeader, const uint8_t* CommandData,
Bluetooth_Channel_t* const Channel);
Bluetooth_Channel_t* const ACLChannel);
#endif
#endif

@ -90,7 +90,7 @@ void SDP_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
*/
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");
@ -171,7 +171,7 @@ static void SDP_ProcessServiceSearch(const SDP_PDUHeader_t* const SDPHeader, Blu
*/
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");
@ -261,7 +261,7 @@ static void SDP_ProcessServiceAttribute(const SDP_PDUHeader_t* const SDPHeader,
*/
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");

@ -146,7 +146,7 @@
*/
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;
@ -160,7 +160,7 @@
*/
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;
@ -174,7 +174,7 @@
*/
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;

Loading…
Cancel
Save