Add bidirectional channel configuration -- remote device is not ACKing sent Configura...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 6 Apr 2010 08:14:08 +0000 (08:14 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 6 Apr 2010 08:14:08 +0000 (08:14 +0000)
Use abbreviations for the structure and function names where possible to try to cut down on the code verbosity.

Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.h
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h
README.txt

index 5ed120a..fbacc25 100644 (file)
@@ -247,11 +247,12 @@ void Bluetooth_DisconnectionComplete(void)
 void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel)\r
 {\r
        uint8_t DataPayload[*PacketLength];\r
+\r
        Pipe_Read_Stream_LE(&DataPayload, *PacketLength);\r
        *PacketLength = 0;\r
 \r
-       BT_ACL_DEBUG("-- Data Payload: ", NULL);\r
-       for (uint16_t B = 0; B < sizeof(DataPayload); B++)\r
-         printf("0x%02X ", DataPayload[B]);\r
-       printf("\r\n"); \r
+       printf_P(PSTR("L2CAP Packet Recetion on channel %02X:\r\n"), Channel->LocalNumber);\r
+       for (uint16_t Byte = 0; Byte < *PacketLength; Byte++)\r
+         printf_P(PSTR("0x%02X "), DataPayload[Byte]);\r
+       puts_P(PSTR("\r\n"));\r
 }\r
index c2c9902..d26ba19 100644 (file)
 #define  INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C\r
 #include "BluetoothACLPackets.h"\r
 \r
-void Bluetooth_ProcessACLPackets(void)\r
+void Bluetooth_ACLTask(void)\r
 {\r
-       Bluetooth_ACL_Header_t        ACLPacketHeader;\r
-       Bluetooth_DataPacket_Header_t DataHeader;\r
+       Bluetooth_ProcessACLPackets();\r
+       \r
+       for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)\r
+       {\r
+               Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i];\r
+       \r
+               bool MustSendConfigReq = true;\r
+       \r
+               switch (ChannelData->State)\r
+               {\r
+                       case Channel_Config_WaitConfig:\r
+                               ChannelData->State = Channel_Config_WaitReqResp;\r
+                               break;\r
+                       case Channel_Config_WaitSendConfig:\r
+                               ChannelData->State = Channel_Config_WaitResp;\r
+                               break;\r
+                       default:\r
+                               MustSendConfigReq  = false;\r
+                               break;\r
+               }\r
+               \r
+               if (MustSendConfigReq)\r
+               {\r
+                       BT_ACL_Header_t              ACLPacketHeader;\r
+                       BT_DataPacket_Header_t       DataHeader;\r
+                       BT_Signal_Header_t           SignalCommandHeader;\r
+                       BT_Signal_ConfigurationReq_t ConfigurationRequest;\r
+\r
+                       ACLPacketHeader.ConnectionHandle     = Bluetooth_Connection.ConnectionHandle;\r
+                       ACLPacketHeader.DataLength           = sizeof(DataHeader) + sizeof(SignalCommandHeader) + sizeof(ConfigurationRequest);\r
+                       DataHeader.PayloadLength             = sizeof(SignalCommandHeader) + sizeof(ConfigurationRequest);\r
+                       DataHeader.DestinationChannel        = BT_CHANNEL_SIGNALING;\r
+                       SignalCommandHeader.Code             = BT_SIGNAL_CONFIGURATION_REQUEST;\r
+                       SignalCommandHeader.Identifier       = ++Bluetooth_Connection.SignallingIdentifier;\r
+                       SignalCommandHeader.Length           = sizeof(ConfigurationRequest);\r
+                       \r
+                       ConfigurationRequest.DestinationChannel = ChannelData->RemoteNumber;\r
+                       ConfigurationRequest.Flags              = 0;\r
+\r
+                       Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
+                       Pipe_Unfreeze();\r
+                       \r
+                       Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));\r
+                       Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));\r
+                       Pipe_Write_Stream_LE(&SignalCommandHeader, sizeof(SignalCommandHeader));\r
+                       Pipe_Write_Stream_LE(&ConfigurationRequest, sizeof(ConfigurationRequest));\r
+\r
+                       Pipe_Freeze();\r
+\r
+                       #if (ACL_DEBUG_LEVEL > 1)\r
+                       BT_ACL_DEBUG("Packet Sent", NULL);\r
+                       BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader.ConnectionHandle & 0x0FFF));\r
+                       BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader.DataLength);\r
+                       BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader.DestinationChannel);\r
+                       BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader.PayloadLength);                    \r
+                       #endif\r
+                       #if (ACL_DEBUG_LEVEL > 0)\r
+                       BT_ACL_DEBUG(">> L2CAP Configuration Request", NULL);\r
+                       #endif\r
+                       #if (ACL_DEBUG_LEVEL > 1)\r
+                       BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);\r
+                       #endif\r
+               }\r
+       }\r
+}\r
+\r
+static void Bluetooth_ProcessACLPackets(void)\r
+{\r
+       BT_ACL_Header_t        ACLPacketHeader;\r
+       BT_DataPacket_Header_t DataHeader;\r
 \r
        Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);\r
        Pipe_Unfreeze();\r
@@ -48,35 +116,35 @@ void Bluetooth_ProcessACLPackets(void)
        Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));\r
        Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader));\r
 \r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("Packet Received", NULL);\r
        BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader.ConnectionHandle & 0x0FFF));\r
        BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader.DataLength);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader.DestinationChannel);\r
        BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader.PayloadLength);\r
-#endif\r
+       #endif\r
 \r
        if (DataHeader.DestinationChannel == BT_CHANNEL_SIGNALING)\r
        {\r
-               Bluetooth_SignalCommand_Header_t SignalCommandHeader;\r
+               BT_Signal_Header_t SignalCommandHeader;\r
                Pipe_Read_Stream_LE(&SignalCommandHeader, sizeof(SignalCommandHeader));\r
 \r
                switch (SignalCommandHeader.Code)\r
                {\r
                        case BT_SIGNAL_CONNECTION_REQUEST:\r
-                               Bluetooth_SignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
+                               Bluetooth_Signal_ConnectionReq(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
                                break;\r
                        case BT_SIGNAL_CONFIGURATION_REQUEST:\r
-                               Bluetooth_SignalPacket_ConfigurationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
+                               Bluetooth_Signal_ConfigurationReq(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
                                break;\r
                        case BT_SIGNAL_DISCONNECTION_REQUEST:\r
-                               Bluetooth_SignalPacket_DisconnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
+                               Bluetooth_Signal_DisconnectionReq(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
                                break;                  \r
                        case BT_SIGNAL_ECHO_REQUEST:\r
-                               Bluetooth_SignalPacket_EchoRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
+                               Bluetooth_Signal_EchoReq(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
                                break;\r
                        case BT_SIGNAL_INFORMATION_REQUEST:\r
-                               Bluetooth_SignalPacket_InformationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
+                               Bluetooth_Signal_InformationReq(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
                                break;\r
                        default:\r
                                #if (ACL_DEBUG_LEVEL > 0)\r
@@ -100,15 +168,21 @@ void Bluetooth_ProcessACLPackets(void)
        }\r
 }\r
 \r
-void Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel)\r
+uint8_t Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel)\r
 {\r
-       Bluetooth_ACL_Header_t        ACLPacketHeader;\r
-       Bluetooth_DataPacket_Header_t DataHeader;\r
+       BT_ACL_Header_t        ACLPacketHeader;\r
+       BT_DataPacket_Header_t DataHeader;\r
+\r
+       if (Bluetooth_Connection.IsConnected)\r
+         return BT_SENDPACKET_NotConnected;\r
+\r
+       if (Channel->State != Channel_Open)\r
+         return BT_SENDPACKET_ChannelNotOpen;\r
 \r
        ACLPacketHeader.ConnectionHandle      = Bluetooth_Connection.ConnectionHandle;\r
        ACLPacketHeader.DataLength            = sizeof(DataHeader) + DataLen;\r
-       DataHeader.PayloadLength              = DataLen;\r
        DataHeader.DestinationChannel         = Channel->RemoteNumber;\r
+       DataHeader.PayloadLength              = DataLen;\r
 \r
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
        Pipe_Unfreeze();\r
@@ -118,30 +192,32 @@ void Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t*
        Pipe_Write_Stream_LE(Data, DataLen);\r
 \r
        Pipe_Freeze();\r
+       \r
+       return BT_SENDPACKET_NoError;\r
 }\r
 \r
-static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                            Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                            Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_ConnectionReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                  BT_DataPacket_Header_t* DataHeader,\r
+                                                  BT_Signal_Header_t* SignalCommandHeader)\r
 {\r
-       Bluetooth_SignalCommand_ConnectionRequest_t ConnectionRequest;\r
+       BT_Signal_ConnectionReq_t ConnectionRequest;\r
        \r
        Pipe_Read_Stream_LE(&ConnectionRequest, sizeof(ConnectionRequest));\r
 \r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG("<< L2CAP Connection Request", NULL);\r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- PSM: 0x%04X", ConnectionRequest.PSM);\r
        BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);\r
-#endif\r
+       #endif\r
        \r
        Pipe_ClearIN();\r
        Pipe_Freeze();\r
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
        Pipe_Unfreeze();\r
        \r
-       Bluetooth_SignalCommand_ConnectionResponse_t ConnectionResponse;\r
+       BT_Signal_ConnectionResp_t ConnectionResponse;\r
 \r
        ACLPacketHeader->DataLength           = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);\r
        DataHeader->PayloadLength             = sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);\r
@@ -164,44 +240,45 @@ static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header
        Pipe_ClearOUT();                \r
        Pipe_Freeze();\r
        \r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("Packet Sent", NULL);\r
        BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));\r
        BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
        BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);                   \r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG(">> L2CAP Connection Response", NULL);\r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionResponse.SourceChannel);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel);\r
-#endif\r
+       #endif\r
 }\r
 \r
-static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                               Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                               Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_ConfigurationReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                     BT_DataPacket_Header_t* DataHeader,\r
+                                                     BT_Signal_Header_t* SignalCommandHeader)\r
 {\r
-       Bluetooth_SignalCommand_ConfigurationRequest_t ConfigurationRequest;\r
+       BT_Signal_ConfigurationReq_t ConfigurationRequest;\r
        Pipe_Read_Stream_LE(&ConfigurationRequest, sizeof(ConfigurationRequest));\r
        \r
        // TODO: Process/Discard configuration options here\r
+       Pipe_Discard_Stream(DataHeader->PayloadLength - sizeof(*SignalCommandHeader));\r
 \r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG("<< L2CAP Configuration Request", NULL);\r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);\r
-#endif\r
+       #endif\r
        \r
        Pipe_ClearIN();\r
        Pipe_Freeze();\r
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
        Pipe_Unfreeze();\r
        \r
-       Bluetooth_SignalCommand_ConfigurationResponse_t ConfigurationResponse;\r
+       BT_Signal_ConfigurationResp_t ConfigurationResponse;\r
 \r
        ACLPacketHeader->DataLength           = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);\r
        DataHeader->PayloadLength             = sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);\r
@@ -212,7 +289,20 @@ static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Hea
        Bluetooth_Channel_t* ChannelData      = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, false);\r
 \r
        if (ChannelData != NULL)\r
-         ChannelData->State = Channel_Open;\r
+       {\r
+               switch (ChannelData->State)\r
+               {\r
+                       case Channel_Config_WaitConfig:\r
+                               ChannelData->State = Channel_Config_WaitSendConfig;\r
+                               break;\r
+                       case Channel_Config_WaitReqResp:\r
+                               ChannelData->State = Channel_Config_WaitResp;\r
+                               break;\r
+                       case Channel_Config_WaitReq:\r
+                               ChannelData->State = Channel_Open;\r
+                               break;\r
+               }\r
+       }\r
          \r
        // TODO: Add channel config data to the tail of ConfigurationResponse\r
 \r
@@ -228,43 +318,43 @@ static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Hea
        Pipe_ClearOUT();\r
        Pipe_Freeze();\r
        \r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("Packet Sent", NULL);\r
        BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));\r
        BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
        BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);                   \r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG(">> L2CAP Configuration Response", NULL);\r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- Result: 0x%02X", ConfigurationResponse.Result);\r
-#endif\r
+       #endif\r
 }\r
 \r
-static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                               Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                               Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_DisconnectionReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                     BT_DataPacket_Header_t* DataHeader,\r
+                                                     BT_Signal_Header_t* SignalCommandHeader)\r
 {\r
-       Bluetooth_SignalCommand_DisconnectionRequest_t DisconnectionRequest;\r
+       BT_Signal_DisconnectionReq_t DisconnectionRequest;\r
        \r
        Pipe_Read_Stream_LE(&DisconnectionRequest, sizeof(DisconnectionRequest));\r
 \r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG("<< L2CAP Disconnection Request", NULL);\r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DisconnectionRequest.DestinationChannel);\r
        BT_ACL_DEBUG("-- Source Channel: 0x%04X", DisconnectionRequest.SourceChannel);\r
-#endif\r
+       #endif\r
        \r
        Pipe_ClearIN();\r
        Pipe_Freeze();\r
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
        Pipe_Unfreeze();\r
        \r
-       Bluetooth_SignalCommand_DisconnectionResponse_t DisconnectionResponse;\r
+       BT_Signal_DisconnectionResp_t DisconnectionResponse;\r
 \r
        ACLPacketHeader->DataLength           = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(DisconnectionResponse);\r
        DataHeader->PayloadLength             = sizeof(*SignalCommandHeader) + sizeof(DisconnectionResponse);\r
@@ -288,29 +378,29 @@ static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Hea
        Pipe_ClearOUT();\r
        Pipe_Freeze();\r
        \r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("Packet Sent", NULL);\r
        BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));\r
        BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
        BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);                   \r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG(">> L2CAP Disconnection Response", NULL);\r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- Source Channel: 0x%04X", DisconnectionResponse.SourceChannel);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DisconnectionResponse.DestinationChannel);\r
-#endif\r
+       #endif\r
 }\r
 \r
-static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                      Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                      Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_EchoReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                            BT_DataPacket_Header_t* DataHeader,\r
+                                            BT_Signal_Header_t* SignalCommandHeader)\r
 {\r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG("<< L2CAP Echo Request", NULL);\r
-#endif\r
+       #endif\r
        \r
        Pipe_ClearIN();\r
        Pipe_Freeze();\r
@@ -330,39 +420,39 @@ static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* AC
        Pipe_ClearOUT();                \r
        Pipe_Freeze();\r
        \r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("Packet Sent", NULL);\r
        BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));\r
        BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
        BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);                   \r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG(">> L2CAP Echo Response", NULL);\r
-#endif\r
+       #endif\r
 }\r
 \r
-static inline void Bluetooth_SignalPacket_InformationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                             Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                             Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
+static inline void Bluetooth_Signal_InformationReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                   BT_DataPacket_Header_t* DataHeader,\r
+                                                   BT_Signal_Header_t* SignalCommandHeader)\r
 {\r
-       Bluetooth_SignalCommand_InformationRequest_t InformationRequest;\r
+       BT_Signal_InformationReq_t InformationRequest;\r
 \r
        Pipe_Read_Stream_LE(&InformationRequest, sizeof(InformationRequest));\r
 \r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG("<< Information Request", NULL);\r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- Info Type: 0x%04X", InformationRequest.InfoType);\r
-#endif\r
+       #endif\r
        \r
        Pipe_ClearIN();\r
        Pipe_Freeze();\r
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
        Pipe_Unfreeze();\r
        \r
-       Bluetooth_SignalCommand_InformationResponse_t InformationResponse;\r
+       BT_Signal_InformationResp_t InformationResponse;\r
        uint8_t ResponseData[4];\r
        uint8_t ResponseLen;\r
 \r
@@ -402,17 +492,17 @@ static inline void Bluetooth_SignalPacket_InformationRequest(Bluetooth_ACL_Heade
        Pipe_ClearOUT();                \r
        Pipe_Freeze();\r
 \r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("Packet Sent", NULL);\r
        BT_ACL_DEBUG("-- Connection Handle: 0x%04X", (ACLPacketHeader->ConnectionHandle & 0x0FFF));\r
        BT_ACL_DEBUG("-- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
        BT_ACL_DEBUG("-- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
        BT_ACL_DEBUG("-- Payload Length: 0x%04X", DataHeader->PayloadLength);                   \r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 0)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 0)\r
        BT_ACL_DEBUG(">> L2CAP Information Response", NULL);    \r
-#endif\r
-#if (ACL_DEBUG_LEVEL > 1)\r
+       #endif\r
+       #if (ACL_DEBUG_LEVEL > 1)\r
        BT_ACL_DEBUG("-- Result: 0x%02X", InformationResponse.Result);\r
-#endif\r
+       #endif\r
 }\r
index f6f8f76..6038ea4 100644 (file)
@@ -42,7 +42,7 @@
                \r
        /* Macros: */\r
                #define BT_ACL_DEBUG(s, ...)              printf_P(PSTR("(ACL) " s "\r\n"), __VA_ARGS__)\r
-               #define ACL_DEBUG_LEVEL                   2\r
+               #define ACL_DEBUG_LEVEL                   1\r
 \r
                #define BT_CHANNEL_SIGNALING              0x0001\r
                #define BT_CHANNEL_CONNECTIONLESS         0x0002\r
                {\r
                        uint16_t ConnectionHandle;\r
                        uint16_t DataLength;\r
-               } Bluetooth_ACL_Header_t;\r
+               } BT_ACL_Header_t;\r
 \r
                typedef struct\r
                {\r
                        uint16_t PayloadLength;\r
                        uint16_t DestinationChannel;\r
-               } Bluetooth_DataPacket_Header_t;\r
+               } BT_DataPacket_Header_t;\r
                \r
                typedef struct\r
                {\r
                        uint8_t  Code;\r
                        uint8_t  Identifier;\r
                        uint16_t Length;\r
-               } Bluetooth_SignalCommand_Header_t;\r
+               } BT_Signal_Header_t;\r
                \r
                typedef struct\r
                {\r
                        uint16_t PSM;\r
                        uint16_t SourceChannel;\r
-               } Bluetooth_SignalCommand_ConnectionRequest_t;\r
+               } BT_Signal_ConnectionReq_t;\r
 \r
                typedef struct\r
                {\r
                        uint16_t SourceChannel;\r
                        uint16_t Result;\r
                        uint16_t Status;\r
-               } Bluetooth_SignalCommand_ConnectionResponse_t;\r
+               } BT_Signal_ConnectionResp_t;\r
 \r
                typedef struct\r
                {\r
                        uint16_t DestinationChannel;\r
                        uint16_t SourceChannel;\r
-               } Bluetooth_SignalCommand_DisconnectionRequest_t;\r
+               } BT_Signal_DisconnectionReq_t;\r
                \r
                typedef struct\r
                {\r
                        uint16_t DestinationChannel;\r
                        uint16_t SourceChannel;\r
-               } Bluetooth_SignalCommand_DisconnectionResponse_t;              \r
+               } BT_Signal_DisconnectionResp_t;                \r
 \r
                typedef struct\r
                {\r
                        uint16_t DestinationChannel;\r
                        uint16_t Flags;\r
-               } Bluetooth_SignalCommand_ConfigurationRequest_t;\r
+               } BT_Signal_ConfigurationReq_t;\r
 \r
                typedef struct\r
                {\r
                        uint16_t SourceChannel;\r
                        uint16_t Flags;\r
                        uint16_t Result;\r
-               } Bluetooth_SignalCommand_ConfigurationResponse_t;\r
+               } BT_Signal_ConfigurationResp_t;\r
 \r
                typedef struct\r
                {\r
                        uint16_t InfoType;\r
-               } Bluetooth_SignalCommand_InformationRequest_t;\r
+               } BT_Signal_InformationReq_t;\r
                \r
                typedef struct\r
                {\r
                        uint16_t InfoType;\r
                        uint16_t Result;\r
-               } Bluetooth_SignalCommand_InformationResponse_t;\r
+               } BT_Signal_InformationResp_t;\r
 \r
        /* Function Prototypes: */\r
-               void Bluetooth_ProcessACLPackets(void);\r
-               void Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel);\r
+               void    Bluetooth_ACLTask(void);\r
+               uint8_t Bluetooth_SendPacket(uint8_t* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel);\r
                \r
                #if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C)\r
-                       static inline void Bluetooth_SignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                                  Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                                  Bluetooth_SignalCommand_Header_t* SignalCommandHeader);\r
-                       static inline void Bluetooth_SignalPacket_EchoRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                                  Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                                  Bluetooth_SignalCommand_Header_t* SignalCommandHeader);\r
-                       static inline void Bluetooth_SignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                                  Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                                  Bluetooth_SignalCommand_Header_t* SignalCommandHeader);\r
-                       static inline void Bluetooth_SignalPacket_DisconnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                                  Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                                  Bluetooth_SignalCommand_Header_t* SignalCommandHeader);\r
-                       static inline void Bluetooth_SignalPacket_InformationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                                  Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                                  Bluetooth_SignalCommand_Header_t* SignalCommandHeader);\r
+                       static void Bluetooth_ProcessACLPackets(void);\r
+\r
+                       static inline void Bluetooth_Signal_ConnectionReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                              BT_DataPacket_Header_t* DataHeader,\r
+                                                              BT_Signal_Header_t* SignalCommandHeader);\r
+                       static inline void Bluetooth_Signal_EchoReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                        BT_DataPacket_Header_t* DataHeader,\r
+                                                        BT_Signal_Header_t* SignalCommandHeader);\r
+                       static inline void Bluetooth_Signal_ConfigurationReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                                 BT_DataPacket_Header_t* DataHeader,\r
+                                                                 BT_Signal_Header_t* SignalCommandHeader);\r
+                       static inline void Bluetooth_Signal_DisconnectionReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                                 BT_DataPacket_Header_t* DataHeader,\r
+                                                                 BT_Signal_Header_t* SignalCommandHeader);\r
+                       static inline void Bluetooth_Signal_InformationReq(BT_ACL_Header_t* ACLPacketHeader,\r
+                                                               BT_DataPacket_Header_t* DataHeader,\r
+                                                               BT_Signal_Header_t* SignalCommandHeader);\r
                #endif\r
                \r
 #endif\r
index 9d67b70..3d5b14a 100644 (file)
   this software.\r
 */\r
 \r
+#define  INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C\r
 #include "BluetoothHCICommands.h"\r
 \r
-static Bluetooth_HCICommand_Header_t HCICommandHeader;\r
+static BT_HCICommand_Header_t HCICommandHeader;\r
 \r
        uint8_t                       Bluetooth_HCIProcessingState;\r
 static uint8_t                       Bluetooth_HCINextState;\r
 static uint8_t                       Bluetooth_TempDeviceAddress[6];\r
 \r
-static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength)\r
-{\r
-       /* Need to reserve the amount of bytes given in the header for the complete payload */\r
-       uint8_t CommandBuffer[sizeof(HCICommandHeader) + HCICommandHeader.ParameterLength];\r
-\r
-       USB_ControlRequest = (USB_Request_Header_t)\r
-               {\r
-                       .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_DEVICE),\r
-                       .bRequest      = 0,\r
-                       .wValue        = 0,\r
-                       .wIndex        = 0,\r
-                       .wLength       = sizeof(CommandBuffer)\r
-               };\r
-\r
-       /* Copy over the HCI command header to the allocated buffer */\r
-       memcpy(CommandBuffer, &HCICommandHeader, sizeof(HCICommandHeader));\r
-       \r
-       /* Zero out the parameter section of the response to ensure that any padding bytes do not expose private RAM contents */\r
-       memset(&CommandBuffer[sizeof(HCICommandHeader)], 0x00, HCICommandHeader.ParameterLength);\r
-\r
-       /* Copy over the command parameters (if any) to the command buffer - note, the number of actual source parameter bytes\r
-          may differ to those in the header; any difference in length is filled with 0x00 padding bytes */\r
-       memcpy(&CommandBuffer[sizeof(HCICommandHeader)], Parameters, ParameterLength);\r
-       \r
-       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
-       return USB_Host_SendControlRequest(CommandBuffer);\r
-}\r
-\r
-void Bluetooth_ProcessHCICommands(void)\r
+void Bluetooth_HCITask(void)\r
 {\r
        switch (Bluetooth_HCIProcessingState)\r
        {\r
@@ -74,7 +47,7 @@ void Bluetooth_ProcessHCICommands(void)
                        \r
                        if (Pipe_IsReadWriteAllowed())\r
                        {\r
-                               Bluetooth_HCIEvent_Header_t HCIEventHeader;\r
+                               BT_HCIEvent_Header_t HCIEventHeader;\r
 \r
                                /* Read in the event header to fetch the event code and payload length */\r
                                Pipe_Read_Stream_LE(&HCIEventHeader, sizeof(HCIEventHeader));\r
@@ -93,16 +66,16 @@ void Bluetooth_ProcessHCICommands(void)
                                                break;\r
                                        case EVENT_COMMAND_STATUS:\r
                                                /* If the execution of a command failed, reset the stack */\r
-                                               if (((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status)\r
+                                               if (((BT_HCIEvent_CommandStatus_t*)&EventParams)->Status)\r
                                                  Bluetooth_HCIProcessingState = Bluetooth_Init;\r
                                                break;\r
                                        case EVENT_CONNECTION_REQUEST:\r
                                                /* Need to store the remote device's BT address in a temporary buffer for later use */\r
                                                memcpy(Bluetooth_TempDeviceAddress,\r
-                                                      &((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->RemoteAddress,\r
+                                                      &((BT_HCIEvent_ConnectionRequest_t*)&EventParams)->RemoteAddress,\r
                                                       sizeof(Bluetooth_TempDeviceAddress));\r
                                                           \r
-                                               bool IsACLConnection = (((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType == 0x01);\r
+                                               bool IsACLConnection = (((BT_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType == 0x01);\r
 \r
                                                /* Only accept the connection if it is a ACL (data) connection, a device is not already connected\r
                                                   and the user application has indicated that the connection should be allowed */\r
@@ -113,7 +86,7 @@ void Bluetooth_ProcessHCICommands(void)
                                        case EVENT_PIN_CODE_REQUEST:\r
                                                /* Need to store the remote device's BT address in a temporary buffer for later use */\r
                                                memcpy(Bluetooth_TempDeviceAddress,\r
-                                                      &((Bluetooth_HCIEvent_PinCodeRequest_t*)&EventParams)->RemoteAddress,\r
+                                                      &((BT_HCIEvent_PinCodeReq_t*)&EventParams)->RemoteAddress,\r
                                                       sizeof(Bluetooth_TempDeviceAddress));\r
 \r
                                                Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode;\r
@@ -121,11 +94,11 @@ void Bluetooth_ProcessHCICommands(void)
                                        case EVENT_CONNECTION_COMPLETE:\r
                                                /* Need to store the remote device's BT address in a temporary buffer for later use */\r
                                                memcpy(Bluetooth_Connection.RemoteAddress,\r
-                                                      &((Bluetooth_HCIEvent_ConnectionComplete_t*)&EventParams)->RemoteAddress,\r
+                                                      &((BT_HCIEvent_ConnectionComplete_t*)&EventParams)->RemoteAddress,\r
                                                       sizeof(Bluetooth_TempDeviceAddress));\r
 \r
                                                /* Store the created connection handle and indicate that the connection has been established */\r
-                                               Bluetooth_Connection.ConnectionHandle = ((Bluetooth_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle;\r
+                                               Bluetooth_Connection.ConnectionHandle = ((BT_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle;\r
                                                Bluetooth_Connection.IsConnected      = true;\r
                                                \r
                                                Bluetooth_ConnectionComplete();                                         \r
@@ -151,7 +124,7 @@ void Bluetooth_ProcessHCICommands(void)
                        Bluetooth_HCIProcessingState = Bluetooth_Init_Reset; \r
                        break;\r
                case Bluetooth_Init_Reset:\r
-                       HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
+                       HCICommandHeader = (BT_HCICommand_Header_t)\r
                        {\r
                                OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_RESET},\r
                                ParameterLength: 0,\r
@@ -164,7 +137,7 @@ void Bluetooth_ProcessHCICommands(void)
                        Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
                        break;\r
                case Bluetooth_Init_SetLocalName:\r
-                       HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
+                       HCICommandHeader = (BT_HCICommand_Header_t)\r
                                {\r
                                        OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_LOCAL_NAME},\r
                                        ParameterLength: 248,\r
@@ -177,7 +150,7 @@ void Bluetooth_ProcessHCICommands(void)
                        Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
                        break;\r
                case Bluetooth_Init_SetDeviceClass:\r
-                       HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
+                       HCICommandHeader = (BT_HCICommand_Header_t)\r
                                {\r
                                        OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE},\r
                                        ParameterLength: 3,\r
@@ -190,7 +163,7 @@ void Bluetooth_ProcessHCICommands(void)
                        Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
                        break;\r
                case Bluetooth_Init_WriteScanEnable:\r
-                       HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
+                       HCICommandHeader = (BT_HCICommand_Header_t)\r
                        {\r
                                OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE},\r
                                ParameterLength: 1,\r
@@ -205,60 +178,88 @@ void Bluetooth_ProcessHCICommands(void)
                        Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
                        break;\r
                case Bluetooth_Conn_AcceptConnection:\r
-                       HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
+                       HCICommandHeader = (BT_HCICommand_Header_t)\r
                                {\r
                                        OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST},\r
-                                       ParameterLength: sizeof(Bluetooth_HCICommand_AcceptConnectionRequest_t),\r
+                                       ParameterLength: sizeof(BT_HCICommand_AcceptConnectionReq_t),\r
                                };\r
 \r
                        /* Copy over the temporary BT device address saved from the Connection Request event, indicate slave\r
                           connection role */\r
-                       Bluetooth_HCICommand_AcceptConnectionRequest_t AcceptConnectionParams;\r
+                       BT_HCICommand_AcceptConnectionReq_t AcceptConnectionParams;\r
                        memcpy(AcceptConnectionParams.RemoteAddress, Bluetooth_TempDeviceAddress,\r
                               sizeof(AcceptConnectionParams.RemoteAddress));\r
                        AcceptConnectionParams.SlaveRole = true;\r
 \r
                        /* Send the command to accept the remote connection request */\r
-                       Bluetooth_SendHCICommand(&AcceptConnectionParams, sizeof(Bluetooth_HCICommand_AcceptConnectionRequest_t));\r
+                       Bluetooth_SendHCICommand(&AcceptConnectionParams, sizeof(BT_HCICommand_AcceptConnectionReq_t));\r
                        \r
                        Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
                        break;\r
                case Bluetooth_Conn_RejectConnection:\r
-                       HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
+                       HCICommandHeader = (BT_HCICommand_Header_t)\r
                                {\r
                                        OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST},\r
-                                       ParameterLength: sizeof(Bluetooth_HCICommand_RejectConnectionRequest_t),\r
+                                       ParameterLength: sizeof(BT_HCICommand_RejectConnectionReq_t),\r
                                };\r
 \r
                        /* Copy over the temporary BT device address saved from the Connection Request event, indicate failure\r
                           to accept the connection due to limited device resources or incorrect device address */\r
-                       Bluetooth_HCICommand_RejectConnectionRequest_t RejectConnectionParams;\r
+                       BT_HCICommand_RejectConnectionReq_t RejectConnectionParams;\r
                        memcpy(RejectConnectionParams.RemoteAddress, Bluetooth_TempDeviceAddress, sizeof(RejectConnectionParams.RemoteAddress));\r
                        RejectConnectionParams.Reason = Bluetooth_Connection.IsConnected ? ERROR_LIMITED_RESOURCES : ERROR_UNACCEPTABLE_BDADDR;\r
 \r
                        /* Send the command to reject the remote connection request */\r
-                       Bluetooth_SendHCICommand(&RejectConnectionParams, sizeof(Bluetooth_HCICommand_RejectConnectionRequest_t));\r
+                       Bluetooth_SendHCICommand(&RejectConnectionParams, sizeof(BT_HCICommand_RejectConnectionReq_t));\r
                \r
                        Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
                        break;\r
                case Bluetooth_Conn_SendPINCode:\r
-                       HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
+                       HCICommandHeader = (BT_HCICommand_Header_t)\r
                                {\r
                                        OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY},\r
-                                       ParameterLength: sizeof(Bluetooth_HCICommand_PinCodeResponse_t),\r
+                                       ParameterLength: sizeof(BT_HCICommand_PinCodeResp_t),\r
                                };\r
 \r
                        /* Copy over the temporary BT device address saved from the PIN Code Request event, copy over the\r
                           local PIN authentication code to the response */\r
-                       Bluetooth_HCICommand_PinCodeResponse_t PINCodeRequestParams;\r
+                       BT_HCICommand_PinCodeResp_t PINCodeRequestParams;\r
                        memcpy(PINCodeRequestParams.RemoteAddress, Bluetooth_TempDeviceAddress, sizeof(PINCodeRequestParams.RemoteAddress));\r
                        PINCodeRequestParams.PINCodeLength = strlen(Bluetooth_DeviceConfiguration.PINCode);\r
                        memcpy(PINCodeRequestParams.PINCode, Bluetooth_DeviceConfiguration.PINCode, sizeof(PINCodeRequestParams.PINCode));\r
                        \r
                        /* Send the command to transmit the device's local PIN number for authentication */\r
-                       Bluetooth_SendHCICommand(&PINCodeRequestParams, sizeof(Bluetooth_HCICommand_PinCodeResponse_t));\r
+                       Bluetooth_SendHCICommand(&PINCodeRequestParams, sizeof(BT_HCICommand_PinCodeResp_t));\r
 \r
                        Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
                        break;\r
        }\r
 }\r
+\r
+static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength)\r
+{\r
+       /* Need to reserve the amount of bytes given in the header for the complete payload */\r
+       uint8_t CommandBuffer[sizeof(HCICommandHeader) + HCICommandHeader.ParameterLength];\r
+\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+               {\r
+                       .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_DEVICE),\r
+                       .bRequest      = 0,\r
+                       .wValue        = 0,\r
+                       .wIndex        = 0,\r
+                       .wLength       = sizeof(CommandBuffer)\r
+               };\r
+\r
+       /* Copy over the HCI command header to the allocated buffer */\r
+       memcpy(CommandBuffer, &HCICommandHeader, sizeof(HCICommandHeader));\r
+       \r
+       /* Zero out the parameter section of the response to ensure that any padding bytes do not expose private RAM contents */\r
+       memset(&CommandBuffer[sizeof(HCICommandHeader)], 0x00, HCICommandHeader.ParameterLength);\r
+\r
+       /* Copy over the command parameters (if any) to the command buffer - note, the number of actual source parameter bytes\r
+          may differ to those in the header; any difference in length is filled with 0x00 padding bytes */\r
+       memcpy(&CommandBuffer[sizeof(HCICommandHeader)], Parameters, ParameterLength);\r
+       \r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+       return USB_Host_SendControlRequest(CommandBuffer);\r
+}\r
index f64bba0..9c1adf0 100644 (file)
 \r
                        uint8_t  ParameterLength;\r
                        uint8_t  Parameters[];\r
-               } Bluetooth_HCICommand_Header_t;\r
+               } BT_HCICommand_Header_t;\r
 \r
                typedef struct\r
                {\r
                        uint8_t  EventCode;\r
                        uint8_t  ParameterLength;\r
-               } Bluetooth_HCIEvent_Header_t;\r
+               } BT_HCIEvent_Header_t;\r
 \r
                typedef struct\r
                {\r
                                int OCF : 10;\r
                                int OGF : 6;\r
                        } OpCode;\r
-               } Bluetooth_HCIEvent_CommandStatus_t;\r
+               } BT_HCIEvent_CommandStatus_t;\r
                \r
                typedef struct\r
                {\r
                        uint8_t  HCLPacketsAllowable;\r
                        uint16_t Opcode;\r
                        uint8_t  ReturnParams[];\r
-               } Bluetooth_HCIEvent_CommandComplete_t;\r
+               } BT_HCIEvent_CommandComplete_t;\r
 \r
                typedef struct\r
                {\r
                        uint8_t  ClassOfDevice_Service;\r
                        uint16_t ClassOfDevice_MajorMinor;\r
                        uint8_t  LinkType;\r
-               } Bluetooth_HCIEvent_ConnectionRequest_t;\r
+               } BT_HCIEvent_ConnectionRequest_t;\r
 \r
                typedef struct\r
                {\r
                        uint8_t  RemoteAddress[6];\r
                        uint8_t  LinkType;\r
                        uint8_t  EncryptionEnabled;\r
-               } Bluetooth_HCIEvent_ConnectionComplete_t;\r
+               } BT_HCIEvent_ConnectionComplete_t;\r
                \r
                typedef struct\r
                {\r
                        uint8_t  RemoteAddress[6];\r
-               } Bluetooth_HCIEvent_PinCodeRequest_t;\r
+               } BT_HCIEvent_PinCodeReq_t;\r
                \r
                typedef struct\r
                {\r
                        uint8_t  RemoteAddress[6];\r
                        uint8_t  SlaveRole;\r
-               } Bluetooth_HCICommand_AcceptConnectionRequest_t;\r
+               } BT_HCICommand_AcceptConnectionReq_t;\r
                \r
                typedef struct\r
                {\r
                        uint8_t  RemoteAddress[6];\r
                        uint8_t  Reason;\r
-               } Bluetooth_HCICommand_RejectConnectionRequest_t;\r
+               } BT_HCICommand_RejectConnectionReq_t;\r
 \r
                typedef struct\r
                {\r
                        uint8_t  RemoteAddress[6];\r
                        uint8_t  PINCodeLength;\r
                        char     PINCode[16];\r
-               } Bluetooth_HCICommand_PinCodeResponse_t;\r
+               } BT_HCICommand_PinCodeResp_t;\r
                \r
        /* Enums: */\r
-               enum Bluetooth_ScanEnable_Modes_t\r
+               enum BT_ScanEnable_Modes_t\r
                {\r
                        BT_SCANMODE_NoScansEnabled       = 0,\r
                        BT_SCANMODE_InquiryScanOnly      = 1,\r
                        BT_SCANMODE_InquiryAndPageScans  = 3,\r
                };\r
 \r
-               enum BluetoothStack_States_t\r
+               enum BT_HCIStates_t\r
                {\r
                        Bluetooth_ProcessEvents          = 0,\r
                        Bluetooth_Init                   = 1,\r
                extern uint8_t Bluetooth_HCIProcessingState;\r
 \r
        /* Function Prototypes: */\r
-               void Bluetooth_ProcessHCICommands(void);\r
-               void Bluetooth_ProcessHCIEvents(void);\r
+               void Bluetooth_HCITask(void);\r
                        \r
                #if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)\r
                        static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint16_t ParameterLength);\r
index 5da4d0b..1d3d199 100644 (file)
@@ -50,21 +50,20 @@ void Bluetooth_Stack_Init(void)
 \r
 void Bluetooth_Stack_USBTask(void)\r
 {\r
-       Bluetooth_ProcessHCICommands();\r
-       Bluetooth_ProcessACLPackets();\r
+       Bluetooth_HCITask();\r
+       Bluetooth_ACLTask();\r
 }\r
 \r
 Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource)\r
 {\r
        for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)\r
        {\r
-               Bluetooth_Channel_t* CurrentChannelStructure = &Bluetooth_Connection.Channels[i];\r
+               Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i];\r
        \r
-               uint16_t CurrentChannelNumber = (SearchBySource) ? CurrentChannelStructure->RemoteNumber :\r
-                                                                  CurrentChannelStructure->LocalNumber;\r
+               uint16_t CurrentChannelNumber = (SearchBySource) ? ChannelData->RemoteNumber : ChannelData->LocalNumber;\r
        \r
                if (CurrentChannelNumber == ChannelNumber)\r
-                 return CurrentChannelStructure;\r
+                 return ChannelData;\r
        }\r
 \r
        return NULL;\r
@@ -74,16 +73,16 @@ Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uin
 {\r
        for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)\r
        {\r
-               Bluetooth_Channel_t* CurrentChannelStructure = &Bluetooth_Connection.Channels[i];\r
+               Bluetooth_Channel_t* ChannelData = &Bluetooth_Connection.Channels[i];\r
        \r
-               if (CurrentChannelStructure->State == Channel_Closed)\r
+               if (ChannelData->State == Channel_Closed)\r
                {\r
-                       CurrentChannelStructure->RemoteNumber = RemoteChannelNumber;\r
-                       CurrentChannelStructure->LocalNumber  = (BLUETOOTH_CHANNELNUMBER_BASEOFFSET + i);\r
-                       CurrentChannelStructure->PSM          = PSM;\r
-                       CurrentChannelStructure->State        = Channel_Config;\r
+                       ChannelData->RemoteNumber = RemoteChannelNumber;\r
+                       ChannelData->LocalNumber  = (BLUETOOTH_CHANNELNUMBER_BASEOFFSET + i);\r
+                       ChannelData->PSM          = PSM;\r
+                       ChannelData->State        = Channel_Config_WaitConfig;\r
                        \r
-                       return CurrentChannelStructure;\r
+                       return ChannelData;\r
                }               \r
        }\r
 \r
index b529ea4..8d356d8 100644 (file)
                #define CHANNEL_PSM_RFCOMM                       0x0003\r
                \r
        /* Enums: */\r
-               enum Bluetooth_Channel_State_t\r
+               enum BT_ChannelStates_t\r
                {\r
-                       Channel_Closed          = 0,\r
-                       Channel_WaitConnect     = 1,\r
-                       Channel_WaitConnectRsp  = 2,\r
-                       Channel_Config          = 3,\r
-                       Channel_Open            = 4,\r
-                       Channel_WaitDisconnect  = 5,\r
+                       Channel_Closed                = 0,\r
+                       Channel_WaitConnect           = 1,\r
+                       Channel_WaitConnectRsp        = 2,\r
+                       Channel_Config_WaitConfig     = 3,\r
+                       Channel_Config_WaitSendConfig = 4,\r
+                       Channel_Config_WaitReqResp    = 5,\r
+                       Channel_Config_WaitResp       = 6,\r
+                       Channel_Config_WaitReq        = 7,\r
+                       Channel_Open                  = 8,\r
+                       Channel_WaitDisconnect        = 9,\r
+               };\r
+\r
+               enum Endpoint_ControlStream_RW_ErrorCodes_t\r
+               {\r
+                       BT_SENDPACKET_NoError            = 0,\r
+                       BT_SENDPACKET_NotConnected       = 1,\r
+                       BT_SENDPACKET_ChannelNotOpen     = 2,\r
                };\r
 \r
        /* Type Defines: */\r
@@ -65,7 +76,7 @@
                        uint16_t LocalNumber;\r
                        uint16_t RemoteNumber;\r
                        uint16_t PSM;\r
-                       uint16_t MTU;\r
+                       uint16_t RemoteMTU;\r
                } Bluetooth_Channel_t;\r
 \r
                typedef struct\r
@@ -74,6 +85,7 @@
                        uint16_t            ConnectionHandle;\r
                        uint8_t             RemoteAddress[6];\r
                        Bluetooth_Channel_t Channels[BLUETOOTH_MAX_OPEN_CHANNELS];\r
+                       uint8_t             SignallingIdentifier;\r
                } Bluetooth_Connection_t;\r
                \r
                typedef struct\r
index 3eed421..f5dab3e 100644 (file)
@@ -5,11 +5,16 @@
                     |___|___|_||_n_|    Framework for AVRs\r
                   =========================================\r
                             Written by Dean Camera\r
+                    dean [at] fourwalledcubicle [dot] com\r
+\r
                   http://www.fourwalledcubicle.com/LUFA.php\r
                   =========================================\r
-                                 \r
-                 LUFA IS DONATION SUPPORTED. TO SUPPORT LUFA, \r
-                    PLEASE DONATE AT FOURWALLEDCUBICLE.COM.\r
+\r
+                 LUFA IS DONATION SUPPORTED. To support LUFA, \r
+               please donate at http://www.fourwalledcubicle.com.\r
+\r
+                  For Commercial Licensing information, see\r
+                 http://fourwalledcubicle.com/PurchaseLUFA.php\r
 \r
 \r
 This package contains the complete LUFA library, demos, user-submitted projects\r