this software.\r
*/\r
\r
+/*\r
+ TODO: Make SendPacket respect receiver's MTU\r
+ TODO: Make ReceivePacket stitch together MTU fragments (?)\r
+ TODO: Add channel opened/closed callbacks\r
+ */\r
+\r
#define INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C\r
#include "BluetoothACLPackets.h"\r
\r
\r
Bluetooth_SendPacket(&PacketData, sizeof(PacketData), NULL);\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Configuration Request", NULL);\r
+ BT_ACL_DEBUG(1, ">> L2CAP Configuration Request");\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", PacketData.ConfigurationRequest.DestinationChannel);\r
}\r
}\r
Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));\r
Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader));\r
\r
- BT_ACL_DEBUG(2, "", NULL);\r
- BT_ACL_DEBUG(2, "Packet Received", NULL);\r
+ BT_ACL_DEBUG(2, "");\r
+ BT_ACL_DEBUG(2, "Packet Received");\r
BT_ACL_DEBUG(2, "-- Connection Handle: 0x%04X", (ACLPacketHeader.ConnectionHandle & 0x0FFF));\r
BT_ACL_DEBUG(2, "-- Data Length: 0x%04X", ACLPacketHeader.DataLength);\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", DataHeader.DestinationChannel);\r
Bluetooth_Signal_InformationReq(&SignalCommandHeader);\r
break;\r
case BT_SIGNAL_COMMAND_REJECT:\r
- BT_ACL_DEBUG(1, "<< Command Reject", NULL);\r
+ BT_ACL_DEBUG(1, "<< Command Reject");\r
\r
uint16_t RejectReason;\r
Pipe_Read_Stream_LE(&RejectReason, sizeof(RejectReason));\r
Pipe_ClearIN();\r
Pipe_Freeze();\r
\r
- Bluetooth_PacketReceived(PacketData, DataHeader.PayloadLength, Bluetooth_GetChannelData(DataHeader.DestinationChannel, false));\r
+ Bluetooth_PacketReceived(PacketData, DataHeader.PayloadLength,\r
+ Bluetooth_GetChannelData(DataHeader.DestinationChannel, CHANNEL_SEARCH_LOCALNUMBER));\r
}\r
}\r
\r
/** Sends a packet to the remote device on the specified channel.\r
*\r
- * \param Data Pointer to a buffer where the data is to be sourced from\r
- * \param DataLen Length of the data to send\r
- * \param Channel Channel information structure containing the destination channel's information, NULL to send\r
- * to the remote device's signalling channel\r
+ * \param[in] Data Pointer to a buffer where the data is to be sourced from\r
+ * \param[in] DataLen Length of the data to send\r
+ * \param[in] Channel Channel information structure containing the destination channel's information, NULL to send\r
+ * to the remote device's signalling channel\r
*\r
* \return A value from the \ref BT_SendPacket_ErrorCodes_t enum\r
*/\r
-uint8_t Bluetooth_SendPacket(void* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel)\r
+uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Channel_t* const Channel)\r
{\r
BT_ACL_Header_t ACLPacketHeader;\r
BT_DataPacket_Header_t DataHeader;\r
\r
Pipe_Freeze();\r
\r
- BT_ACL_DEBUG(2, "", NULL);\r
- BT_ACL_DEBUG(2, "Packet Sent", NULL);\r
+ BT_ACL_DEBUG(2, "");\r
+ BT_ACL_DEBUG(2, "Packet Sent");\r
BT_ACL_DEBUG(2, "-- Connection Handle: 0x%04X", (ACLPacketHeader.ConnectionHandle & 0x0FFF));\r
BT_ACL_DEBUG(2, "-- Data Length: 0x%04X", ACLPacketHeader.DataLength);\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", DataHeader.DestinationChannel);\r
* repeatedly called. The returned channel is unusable by the user application until its State\r
* element has progressed to the Open state.\r
*\r
- * \param PSM PSM of the service that the channel is to be opened for\r
+ * \param[in] PSM PSM of the service that the channel is to be opened for\r
*\r
* \return Pointer to the channel information structure of the opened channel, or NULL if no free channels\r
*/\r
-Bluetooth_Channel_t* Bluetooth_OpenChannel(uint16_t PSM)\r
+Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM)\r
{\r
Bluetooth_Channel_t* ChannelData = NULL;\r
\r
\r
Bluetooth_SendPacket(&PacketData, sizeof(PacketData), NULL);\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Connection Request", NULL);\r
+ BT_ACL_DEBUG(1, ">> L2CAP Connection Request");\r
BT_ACL_DEBUG(2, "-- PSM 0x%04X", PacketData.ConnectionRequest.PSM);\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", PacketData.ConnectionRequest.SourceChannel);\r
\r
* returned channel is unusable by the user application upon return however the channel is not completely\r
* closed until its State element has progressed to the Closed state.\r
*\r
- * \param Channel Channel information structure of the channel to close\r
+ * \param[in,out] Channel Channel information structure of the channel to close\r
*/\r
-void Bluetooth_CloseChannel(Bluetooth_Channel_t* Channel)\r
+void Bluetooth_CloseChannel(Bluetooth_Channel_t* const Channel)\r
{\r
/* Don't try to close a non-existing or already closed channel */\r
if ((Channel == NULL) || (Channel->State == Channel_Closed))\r
\r
Bluetooth_SendPacket(&PacketData, sizeof(PacketData), NULL);\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Disconnection Request", NULL);\r
+ BT_ACL_DEBUG(1, ">> L2CAP Disconnection Request");\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", PacketData.DisconnectionRequest.DestinationChannel); \r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", PacketData.DisconnectionRequest.SourceChannel); \r
}\r
\r
/** Internal Bluetooth stack Signal Command processing routine for a Connection Request command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_ConnectionReq(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_ConnectionReq(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
BT_Signal_ConnectionReq_t ConnectionRequest;\r
\r
Pipe_ClearIN();\r
Pipe_Freeze();\r
\r
- BT_ACL_DEBUG(1, "<< L2CAP Connection Request", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Connection Request");\r
BT_ACL_DEBUG(2, "-- PSM: 0x%04X", ConnectionRequest.PSM);\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);\r
\r
/* Try to retrieve the existing channel's information structure if it exists */\r
- Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionRequest.SourceChannel, true);\r
+ Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionRequest.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);\r
\r
/* If an existing channel item with the correct remote channel number was not found, find a free channel entry */\r
if (ChannelData == NULL)\r
}\r
}\r
}\r
+ \r
+ uint8_t ChannelStatus = BT_CONNECTION_REFUSED_RESOURCES;\r
\r
/* Reset the channel item contents only if a channel entry was found for it */\r
if (ChannelData != NULL)\r
{\r
- ChannelData->RemoteNumber = ConnectionRequest.SourceChannel;\r
- ChannelData->PSM = ConnectionRequest.PSM;\r
- ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;\r
- ChannelData->State = Channel_Config_WaitConfig;\r
+ /* Check if the user application will allow the connection based on its PSM */\r
+ if (Bluetooth_ChannelConnectionRequest(ConnectionRequest.PSM))\r
+ {\r
+ ChannelData->RemoteNumber = ConnectionRequest.SourceChannel;\r
+ ChannelData->PSM = ConnectionRequest.PSM;\r
+ ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;\r
+ ChannelData->State = Channel_Config_WaitConfig;\r
+
+ ChannelStatus = BT_CONNECTION_SUCCESSFUL;\r
+ }\r
+ else\r
+ {\r
+ ChannelStatus = BT_CONNECTION_REFUSED_PSM; \r
+ }\r
}\r
\r
struct\r
/* Fill out the Connection Response in the response packet */\r
ResponsePacket.ConnectionResponse.DestinationChannel = ChannelData->LocalNumber;\r
ResponsePacket.ConnectionResponse.SourceChannel = ChannelData->RemoteNumber;\r
- ResponsePacket.ConnectionResponse.Result = (ChannelData == NULL) ? BT_CONNECTION_REFUSED_RESOURCES :\r
- BT_CONNECTION_SUCCESSFUL;\r
+ ResponsePacket.ConnectionResponse.Result = ChannelStatus;\r
ResponsePacket.ConnectionResponse.Status = 0x00;\r
\r
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), NULL);\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Connection Response", NULL);\r
+ BT_ACL_DEBUG(1, ">> L2CAP Connection Response");\r
BT_ACL_DEBUG(2, "-- Result: 0x%02X", ResponsePacket.ConnectionResponse.Result);\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", ResponsePacket.ConnectionResponse.DestinationChannel);\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ResponsePacket.ConnectionResponse.SourceChannel);\r
\r
/** Internal Bluetooth stack Signal Command processing routine for a Connection Response command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_ConnectionResp(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_ConnectionResp(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
BT_Signal_ConnectionResp_t ConnectionResponse;\r
\r
Pipe_ClearIN();\r
Pipe_Freeze();\r
\r
- BT_ACL_DEBUG(1, "<< L2CAP Connection Response", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Connection Response");\r
BT_ACL_DEBUG(2, "-- Result: 0x%02X", ConnectionResponse.Result); \r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConnectionResponse.SourceChannel); \r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel); \r
\r
/* Search for the referenced channel in the channel information list */\r
- Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionResponse.SourceChannel, false);\r
+ Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionResponse.SourceChannel, CHANNEL_SEARCH_LOCALNUMBER);\r
\r
/* Only progress if the referenced channel data was found */\r
if (ChannelData != NULL)\r
\r
/** Internal Bluetooth stack Signal Command processing routine for a Configuration Request command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_ConfigurationReq(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_ConfigurationReq(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
BT_Signal_ConfigurationReq_t ConfigurationRequest;\r
\r
Pipe_Freeze();\r
\r
/* Search for the referenced channel in the channel information list */\r
- Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, false);\r
+ Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, CHANNEL_SEARCH_LOCALNUMBER);\r
\r
- BT_ACL_DEBUG(1, "<< L2CAP Configuration Request", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Configuration Request");\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);\r
BT_ACL_DEBUG(2, "-- Remote MTU: 0x%04X", ChannelData->RemoteMTU);\r
BT_ACL_DEBUG(2, "-- Options Len: 0x%04X", OptionsLen);\r
while (OptionPos < OptionsLen)\r
{\r
BT_Config_Option_Header_t* OptionHeader = (BT_Config_Option_Header_t*)&Options[OptionPos];\r
- void* OptionData = &Options[OptionPos + sizeof(*OptionHeader)];\r
+ void* OptionData = &Options[OptionPos + sizeof(BT_Config_Option_Header_t)];\r
\r
BT_ACL_DEBUG(2, "-- Option Type: 0x%04X", OptionHeader->Type);\r
- BT_ACL_DEBUG(2, "-- Option Length: 0x%04X", (sizeof(*OptionHeader) + OptionHeader->Length));\r
+ BT_ACL_DEBUG(2, "-- Option Length: 0x%04X", (sizeof(BT_Config_Option_Header_t) + OptionHeader->Length));\r
\r
/* Store the remote MTU option's value if present */\r
if (OptionHeader->Type == BT_CONFIG_OPTION_MTU)\r
ChannelData->RemoteMTU = *((uint16_t*)OptionData);\r
\r
/* Progress to the next option in the packet */\r
- OptionPos += (sizeof(*OptionHeader) + OptionHeader->Length);\r
+ OptionPos += (sizeof(BT_Config_Option_Header_t) + OptionHeader->Length);\r
}\r
}\r
\r
}\r
}\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Configuration Response", NULL);\r
+ BT_ACL_DEBUG(1, ">> L2CAP Configuration Response");\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ResponsePacket.ConfigurationResponse.SourceChannel);\r
BT_ACL_DEBUG(2, "-- Result: 0x%02X", ResponsePacket.ConfigurationResponse.Result);\r
}\r
\r
/** Internal Bluetooth stack Signal Command processing routine for a Configuration Response command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_ConfigurationResp(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_ConfigurationResp(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
BT_Signal_ConfigurationResp_t ConfigurationResponse;\r
\r
Pipe_ClearIN();\r
Pipe_Freeze();\r
\r
- BT_ACL_DEBUG(1, "<< L2CAP Configuration Response", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Configuration Response");\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConfigurationResponse.SourceChannel);\r
BT_ACL_DEBUG(2, "-- Result: 0x%02X", ConfigurationResponse.Result);\r
\r
/* Search for the referenced channel in the channel information list */\r
- Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationResponse.SourceChannel, true);\r
+ Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationResponse.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);\r
\r
/* Only update the channel's state if it was found in the channel list */\r
if (ChannelData != NULL)\r
\r
/** Internal Bluetooth stack Signal Command processing routine for a Disconnection Request command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_DisconnectionReq(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_DisconnectionReq(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
BT_Signal_DisconnectionReq_t DisconnectionRequest;\r
\r
Pipe_Read_Stream_LE(&DisconnectionRequest, sizeof(DisconnectionRequest));\r
\r
- BT_ACL_DEBUG(1, "<< L2CAP Disconnection Request", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Disconnection Request");\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", DisconnectionRequest.DestinationChannel);\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", DisconnectionRequest.SourceChannel);\r
\r
Pipe_Freeze();\r
\r
/* Search for the referenced channel in the channel information list */\r
- Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(DisconnectionRequest.SourceChannel, true);\r
+ Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(DisconnectionRequest.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);\r
\r
struct\r
{\r
if (ChannelData != NULL)\r
ChannelData->State = Channel_Closed;\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Disconnection Response", NULL);\r
+ BT_ACL_DEBUG(1, ">> L2CAP Disconnection Response");\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ResponsePacket.DisconnectionResponse.SourceChannel);\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", ResponsePacket.DisconnectionResponse.DestinationChannel);\r
}\r
\r
/** Internal Bluetooth stack Signal Command processing routine for a Disconnection Response command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_DisconnectionResp(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_DisconnectionResp(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
BT_Signal_DisconnectionResp_t DisconnectionResponse;\r
\r
Pipe_Read_Stream_LE(&DisconnectionResponse, sizeof(DisconnectionResponse));\r
\r
- BT_ACL_DEBUG(1, "<< L2CAP Disconnection Response", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Disconnection Response");\r
BT_ACL_DEBUG(2, "-- Destination Channel: 0x%04X", DisconnectionResponse.DestinationChannel);\r
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", DisconnectionResponse.SourceChannel);\r
\r
Pipe_Freeze();\r
\r
/* Search for the referenced channel in the channel information list */\r
- Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(DisconnectionResponse.SourceChannel, true);\r
+ Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(DisconnectionResponse.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);\r
\r
/* If the channel was found in the channel list, close it */ \r
if (ChannelData != NULL)\r
\r
/** Internal Bluetooth stack Signal Command processing routine for an Echo Request command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_EchoReq(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_EchoReq(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
- BT_ACL_DEBUG(1, "<< L2CAP Echo Request", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Echo Request");\r
\r
Pipe_ClearIN();\r
Pipe_Freeze();\r
\r
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), NULL);\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Echo Response", NULL);\r
+ BT_ACL_DEBUG(1, ">> L2CAP Echo Response");\r
}\r
\r
/** Internal Bluetooth stack Signal Command processing routine for an Information Request command.\r
*\r
- * \param SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
+ * \param[in] SignalCommandHeader Pointer to the start of the received packet's Signal Command header\r
*/\r
-static inline void Bluetooth_Signal_InformationReq(BT_Signal_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_InformationReq(const BT_Signal_Header_t* const SignalCommandHeader)\r
{\r
BT_Signal_InformationReq_t InformationRequest;\r
\r
Pipe_Read_Stream_LE(&InformationRequest, sizeof(InformationRequest));\r
\r
- BT_ACL_DEBUG(1, "<< L2CAP Information Request", NULL);\r
+ BT_ACL_DEBUG(1, "<< L2CAP Information Request");\r
BT_ACL_DEBUG(2, "-- Info Type: 0x%04X", InformationRequest.InfoType);\r
\r
Pipe_ClearIN();\r
\r
Bluetooth_SendPacket(&ResponsePacket, (sizeof(ResponsePacket) - sizeof(ResponsePacket.Data) + DataLen), NULL);\r
\r
- BT_ACL_DEBUG(1, ">> L2CAP Information Response", NULL); \r
+ BT_ACL_DEBUG(1, ">> L2CAP Information Response"); \r
BT_ACL_DEBUG(2, "-- Result: 0x%02X", ResponsePacket.InformationResponse.Result);\r
}\r