Added incomplete PrinterHost demo application.
[pub/lufa.git] / Demos / Host / Incomplete / BluetoothHost / BluetoothACLPackets.c
diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothACLPackets.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothACLPackets.c
deleted file mode 100644 (file)
index 7697f88..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
-  software without specific, written prior permission.\r
-\r
-  The author disclaim all warranties with regard to this\r
-  software, including all implied warranties of merchantability\r
-  and fitness.  In no event shall the author be liable for any\r
-  special, indirect or consequential damages or any damages\r
-  whatsoever resulting from loss of use, data or profits, whether\r
-  in an action of contract, negligence or other tortious action,\r
-  arising out of or in connection with the use or performance of\r
-  this software.\r
-*/\r
-\r
-#define  INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C\r
-#include "BluetoothACLPackets.h"\r
-\r
-void Bluetooth_ProcessACLPackets(void)\r
-{\r
-       Bluetooth_ACL_Header_t ACLPacketHeader;\r
-       Bluetooth_DataPacket_Header_t DataHeader;\r
-\r
-       Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);\r
-       Pipe_SetToken(PIPE_TOKEN_IN);\r
-       Pipe_Unfreeze();\r
-       \r
-       if (!(Pipe_IsReadWriteAllowed()))\r
-       {\r
-               Pipe_Freeze();\r
-               return;\r
-       }\r
-         \r
-       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
-\r
-       if (DataHeader.DestinationChannel == BLUETOOTH_CHANNEL_SIGNALING)\r
-       {\r
-               Bluetooth_SignalCommand_Header_t SignalCommandHeader;\r
-               Pipe_Read_Stream_LE(&SignalCommandHeader, sizeof(SignalCommandHeader));\r
-\r
-               switch (SignalCommandHeader.Code)\r
-               {\r
-                       case BLUETOOTH_SIGNAL_CONNECTION_REQUEST:\r
-                               Bluetooth_ProcessSignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
-                               break;\r
-                       case BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST:\r
-                               Bluetooth_ProcessSignalPacket_ConfigurationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
-                               break;\r
-                       case BLUETOOTH_SIGNAL_INFORMATION_REQUEST:\r
-                               BT_DEBUG("(ACL) -- Information Request, Discarded");\r
-\r
-                               Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
-                               Pipe_ClearIN();         \r
-                               Pipe_Freeze();\r
-                               break;\r
-                       default:\r
-                               BT_DEBUG("(ACL) >> Unknown Signalling Command 0x%02X", SignalCommandHeader.Code);\r
-                                       \r
-                               Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
-                               Pipe_ClearIN();         \r
-                               Pipe_Freeze();\r
-                               break;\r
-               }\r
-       }\r
-       else\r
-       {\r
-               uint8_t DataPayload[DataHeader.PayloadLength];\r
-               Pipe_Read_Stream_LE(&DataPayload, sizeof(DataPayload));\r
-               DataHeader.PayloadLength = 0;\r
-       \r
-               BT_DEBUG("(ACL) -- Data Payload: ", NULL);\r
-               for (uint16_t B = 0; B < sizeof(DataPayload); B++)\r
-                 printf("0x%02X ", DataPayload[B]);\r
-               BT_DEBUG("", NULL);\r
-\r
-               Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
-               Pipe_ClearIN();         \r
-               Pipe_Freeze();\r
-       }\r
-}\r
-\r
-static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                                   Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                                   Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
-{\r
-       Bluetooth_SignalCommand_ConnectionRequest_t ConnectionRequest;\r
-       \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
-       \r
-       Pipe_ClearIN();\r
-       Pipe_Freeze();\r
-       Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
-       Pipe_SetToken(PIPE_TOKEN_OUT);\r
-       Pipe_Unfreeze();\r
-       \r
-       Bluetooth_SignalCommand_ConnectionResponse_t ConnectionResponse;\r
-\r
-       ACLPacketHeader->DataLength           = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);\r
-       DataHeader->PayloadLength             = sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);\r
-       DataHeader->DestinationChannel        = BLUETOOTH_CHANNEL_SIGNALING;\r
-       SignalCommandHeader->Code             = BLUETOOTH_SIGNAL_CONNECTION_RESPONSE;\r
-       SignalCommandHeader->Length           = sizeof(ConnectionResponse);\r
-       \r
-       Bluetooth_Channel_t* ChannelData      = Bluetooth_InitChannelData(ConnectionRequest.SourceChannel, ConnectionRequest.PSM);\r
-       \r
-       ConnectionResponse.Result             = (ChannelData == NULL) ? BLUETOOTH_CONNECTION_REFUSED_RESOURCES :\r
-                                                                                                                                   BLUETOOTH_CONNECTION_SUCCESSFUL;\r
-       ConnectionResponse.DestinationChannel = ChannelData->LocalNumber;\r
-       ConnectionResponse.SourceChannel      = ChannelData->RemoteNumber;\r
-       ConnectionResponse.Status             = 0x00;\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(&ConnectionResponse, sizeof(ConnectionResponse));\r
-       \r
-       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
-}\r
-\r
-static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
-                                                                      Bluetooth_DataPacket_Header_t* DataHeader,\r
-                                                                      Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
-{\r
-       Bluetooth_SignalCommand_ConfigurationRequest_t ConfigurationRequest;\r
-       \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
-       \r
-       Pipe_ClearIN();\r
-       Pipe_Freeze();\r
-       Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
-       Pipe_SetToken(PIPE_TOKEN_OUT);\r
-       Pipe_Unfreeze();\r
-       \r
-       Bluetooth_SignalCommand_ConfigurationResponse_t ConfigurationResponse;\r
-\r
-       ACLPacketHeader->DataLength           = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);\r
-       DataHeader->PayloadLength             = sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);\r
-       DataHeader->DestinationChannel        = BLUETOOTH_CHANNEL_SIGNALING;\r
-       SignalCommandHeader->Code             = BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE;\r
-       SignalCommandHeader->Length           = sizeof(ConfigurationResponse);\r
-       \r
-       Bluetooth_Channel_t* ChannelData      = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, CHANNEL_LOOKUP_BY_DESTINATION);\r
-\r
-       if (ChannelData != NULL)\r
-         ChannelData->State = Channel_Open;\r
-         \r
-        // TODO: Add channel config data to the tail of ConfigurationResponse\r
-\r
-       ConfigurationResponse.SourceChannel   = ChannelData->RemoteNumber;\r
-       ConfigurationResponse.Flags           = 0x00;\r
-       ConfigurationResponse.Result          = (ChannelData != NULL) ? BLUETOOTH_CONFIGURATION_SUCCESSFUL : BLUETOOTH_CONFIGURATION_REJECTED;\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(&ConfigurationResponse, sizeof(ConfigurationResponse));\r
-       \r
-       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
-}\r