More improvements to the incomplete BluetoothHost demo - add Disconnection Event...
[pub/lufa.git] / Demos / Host / Incomplete / BluetoothHost / Lib / BluetoothACLPackets.c
index 3292a53..e8daa05 100644 (file)
 \r
 void Bluetooth_ProcessACLPackets(void)\r
 {\r
-       Bluetooth_ACL_Header_t ACLPacketHeader;\r
+       Bluetooth_ACL_Header_t        ACLPacketHeader;\r
        Bluetooth_DataPacket_Header_t DataHeader;\r
 \r
        Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);\r
-       Pipe_SetPipeToken(PIPE_TOKEN_IN);\r
        Pipe_Unfreeze();\r
        \r
        if (!(Pipe_IsReadWriteAllowed()))\r
@@ -49,11 +48,11 @@ void Bluetooth_ProcessACLPackets(void)
        Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));\r
        Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader));\r
 \r
-       BT_DEBUG("(ACL) Packet Received", NULL);\r
-       BT_DEBUG("(ACL) -- Connection Handle: 0x%04X", ACLPacketHeader.ConnectionHandle);\r
-       BT_DEBUG("(ACL) -- Data Length: 0x%04X", ACLPacketHeader.DataLength);\r
-       BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", DataHeader.DestinationChannel);\r
-       BT_DEBUG("(ACL) -- Payload Length: 0x%04X", DataHeader.PayloadLength);\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
 \r
        if (DataHeader.DestinationChannel == BLUETOOTH_CHANNEL_SIGNALING)\r
        {\r
@@ -69,14 +68,14 @@ void Bluetooth_ProcessACLPackets(void)
                                Bluetooth_ProcessSignalPacket_ConfigurationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
                                break;\r
                        case BLUETOOTH_SIGNAL_INFORMATION_REQUEST:\r
-                               BT_DEBUG("(ACL) -- Information Request, Discarded", NULL);\r
+                               BT_ACL_DEBUG(">> Information Request, Discarded", NULL);\r
 \r
                                Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
                                Pipe_ClearIN();         \r
                                Pipe_Freeze();\r
                                break;\r
                        default:\r
-                               BT_DEBUG("(ACL) >> Unknown Signaling Command 0x%02X", SignalCommandHeader.Code);\r
+                               BT_ACL_DEBUG(">> Unknown Signaling Command 0x%02X", SignalCommandHeader.Code);\r
                                        \r
                                Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
                                Pipe_ClearIN();         \r
@@ -90,10 +89,10 @@ void Bluetooth_ProcessACLPackets(void)
                Pipe_Read_Stream_LE(&DataPayload, sizeof(DataPayload));\r
                DataHeader.PayloadLength = 0;\r
        \r
-               BT_DEBUG("(ACL) -- Data Payload: ", NULL);\r
+               BT_ACL_DEBUG("-- Data Payload: ", NULL);\r
                for (uint16_t B = 0; B < sizeof(DataPayload); B++)\r
                  printf("0x%02X ", DataPayload[B]);\r
-               BT_DEBUG("", NULL);\r
+               printf("\r\n");\r
 \r
                Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
                Pipe_ClearIN();         \r
@@ -109,14 +108,13 @@ static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL
        \r
        Pipe_Read_Stream_LE(&ConnectionRequest, sizeof(ConnectionRequest));\r
 \r
-       BT_DEBUG("(ACL) >> L2CAP Connection Request", NULL);\r
-       BT_DEBUG("(ACL) -- PSM: 0x%04X", ConnectionRequest.PSM);\r
-       BT_DEBUG("(ACL) -- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);\r
+       BT_ACL_DEBUG(">> L2CAP Connection Request", NULL);\r
+       BT_ACL_DEBUG("-- PSM: 0x%04X", ConnectionRequest.PSM);\r
+       BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);\r
        \r
        Pipe_ClearIN();\r
        Pipe_Freeze();\r
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
-       Pipe_SetPipeToken(PIPE_TOKEN_OUT);\r
        Pipe_Unfreeze();\r
        \r
        Bluetooth_SignalCommand_ConnectionResponse_t ConnectionResponse;\r
@@ -143,14 +141,14 @@ static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL
        Pipe_ClearOUT();                \r
        Pipe_Freeze();\r
        \r
-       BT_DEBUG("(ACL) Packet Sent", NULL);\r
-       BT_DEBUG("(ACL) -- Connection Handle: 0x%04X", ACLPacketHeader->ConnectionHandle);\r
-       BT_DEBUG("(ACL) -- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
-       BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
-       BT_DEBUG("(ACL) -- Payload Length: 0x%04X", DataHeader->PayloadLength);                 \r
-       BT_DEBUG("(ACL) >> L2CAP Connection Response", NULL);\r
-       BT_DEBUG("(ACL) -- Source Channel: 0x%04X", ConnectionResponse.SourceChannel);\r
-       BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel);\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
+       BT_ACL_DEBUG(">> L2CAP Connection Response", NULL);\r
+       BT_ACL_DEBUG("-- Source Channel: 0x%04X", ConnectionResponse.SourceChannel);\r
+       BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel);\r
 }\r
 \r
 static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
@@ -161,13 +159,12 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
        \r
        Pipe_Read_Stream_LE(&ConfigurationRequest, sizeof(ConfigurationRequest));\r
 \r
-       BT_DEBUG("(ACL) >> L2CAP Configuration Request", NULL);\r
-       BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);\r
+       BT_ACL_DEBUG(">> L2CAP Configuration Request", NULL);\r
+       BT_ACL_DEBUG("-- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);\r
        \r
        Pipe_ClearIN();\r
        Pipe_Freeze();\r
        Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
-       Pipe_SetPipeToken(PIPE_TOKEN_OUT);\r
        Pipe_Unfreeze();\r
        \r
        Bluetooth_SignalCommand_ConfigurationResponse_t ConfigurationResponse;\r
@@ -183,7 +180,7 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
        if (ChannelData != NULL)\r
          ChannelData->State = Channel_Open;\r
          \r
-        // TODO: Add channel config data to the tail of ConfigurationResponse\r
+       // TODO: Add channel config data to the tail of ConfigurationResponse\r
 \r
        ConfigurationResponse.SourceChannel   = ChannelData->RemoteNumber;\r
        ConfigurationResponse.Flags           = 0x00;\r
@@ -197,10 +194,10 @@ static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_
        Pipe_ClearOUT();                \r
        Pipe_Freeze();\r
        \r
-       BT_DEBUG("(ACL) Packet Sent", NULL);\r
-       BT_DEBUG("(ACL) -- Connection Handle: 0x%04X", ACLPacketHeader->ConnectionHandle);\r
-       BT_DEBUG("(ACL) -- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
-       BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
-       BT_DEBUG("(ACL) -- Payload Length: 0x%04X", DataHeader->PayloadLength);                 \r
-       BT_DEBUG("(ACL) >> L2CAP Configuration Response", NULL);\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
+       BT_ACL_DEBUG(">> L2CAP Configuration Response", NULL);\r
 }\r