From 292fc9b65eba6b874dd4c29087cf499123f8bd0c Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 20 Jul 2009 14:23:47 +0000 Subject: Move unfinished SideShow source files to nested Lib directory for clarity. --- .../Incomplete/Sideshow/Lib/SideshowApplications.c | 72 +++ .../Incomplete/Sideshow/Lib/SideshowApplications.h | 63 +++ .../Incomplete/Sideshow/Lib/SideshowCommands.c | 490 +++++++++++++++++++++ .../Incomplete/Sideshow/Lib/SideshowCommands.h | 165 +++++++ .../Incomplete/Sideshow/Lib/SideshowCommon.c | 70 +++ .../Incomplete/Sideshow/Lib/SideshowCommon.h | 101 +++++ .../Incomplete/Sideshow/Lib/SideshowContent.c | 76 ++++ .../Incomplete/Sideshow/Lib/SideshowContent.h | 124 ++++++ 8 files changed, 1161 insertions(+) create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.c create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.h create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.c create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.h create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.c create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.h create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.c create mode 100644 Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.h (limited to 'Demos/Device/Incomplete/Sideshow/Lib') diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.c b/Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.c new file mode 100644 index 000000000..f2789c4a7 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.c @@ -0,0 +1,72 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "SideshowApplications.h" + +SideShow_Application_t InstalledApplications[MAX_APPLICATIONS]; + + +uint8_t SideShow_GetTotalApplications(void) +{ + uint8_t TotalInstalledApps = 0; + + for (uint8_t App = 0; App < ARRAY_ELEMENTS(InstalledApplications); App++) + { + if (InstalledApplications[App].InUse) + TotalInstalledApps++; + } + + return TotalInstalledApps; +} + +SideShow_Application_t* SideShow_GetFreeApplication(void) +{ + for (uint8_t App = 0; App < ARRAY_ELEMENTS(InstalledApplications); App++) + { + if (!(InstalledApplications[App].InUse)) + return &InstalledApplications[App]; + } + + return NULL; +} + +SideShow_Application_t* SideShow_GetApplicationFromGUID(GUID_t* GUID) +{ + for (uint8_t App = 0; App < ARRAY_ELEMENTS(InstalledApplications); App++) + { + if (InstalledApplications[App].InUse) + { + if (memcmp(&InstalledApplications[App].ApplicationID, GUID, sizeof(GUID_t)) == 0) + return &InstalledApplications[App]; + } + } + + return NULL; +} diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.h b/Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.h new file mode 100644 index 000000000..133acf994 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowApplications.h @@ -0,0 +1,63 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#ifndef _SIDESHOW_APPLICATIONS_H_ +#define _SIDESHOW_APPLICATIONS_H_ + + /* Includes: */ + #include + #include + #include + + #include "SideshowCommon.h" + + /* Type Defines: */ + typedef struct + { + bool InUse; + GUID_t ApplicationID; + GUID_t EndpointID; + UNICODE_STRING_t(50) ApplicationName; + uint32_t CachePolicy; + uint32_t OnlineOnly; + bool HaveContent; + uint32_t CurrentContentID; + uint8_t CurrentContent[MAX_CONTENTBUFFER_PER_APP]; + } SideShow_Application_t; + + /* External Variables: */ + extern SideShow_Application_t InstalledApplications[MAX_APPLICATIONS]; + + /* Function Prototypes: */ + uint8_t SideShow_GetTotalApplications(void); + SideShow_Application_t* SideShow_GetFreeApplication(void); + SideShow_Application_t* SideShow_GetApplicationFromGUID(GUID_t* GUID); + +#endif diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.c b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.c new file mode 100644 index 000000000..2726d50da --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.c @@ -0,0 +1,490 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define INCLUDE_FROM_SIDESHOWCOMMANDS_H +#include "SideshowCommands.h" + +UNICODE_STRING_t(80) UserSID = {LengthInBytes: sizeof(SECURITY_INTERACTIVE_RID_SID), + UnicodeString: SECURITY_INTERACTIVE_RID_SID}; + +Unicode_String_t DeviceName = {LengthInBytes: sizeof(L"LUFA Sideshow Device"), + UnicodeString: L"LUFA Sideshow Device"}; + +Unicode_String_t Manufacturer = {LengthInBytes: sizeof(L"Dean Camera"), + UnicodeString: L"Dean Camera"}; + +Unicode_String_t SupportedLanguage = {LengthInBytes: sizeof(L"en-US:1"), + UnicodeString: L"en-US:1"}; + +void Sideshow_ProcessCommandPacket(void) +{ + SideShow_PacketHeader_t PacketHeader; + + Endpoint_SelectEndpoint(SIDESHOW_OUT_EPNUM); + Endpoint_Read_Stream_LE(&PacketHeader, sizeof(SideShow_PacketHeader_t)); + + PacketHeader.Type.Response = true; + + printf("\r\nCmd: %lX", (PacketHeader.Type.TypeLong & 0x00FFFFFF)); + + switch (PacketHeader.Type.TypeLong & 0x00FFFFFF) + { + case SIDESHOW_CMD_PING: + SideShow_Ping(&PacketHeader); + break; + case SIDESHOW_CMD_SYNC: + SideShow_Sync(&PacketHeader); + break; + case SIDESHOW_CMD_GET_CURRENT_USER: + SideShow_GetCurrentUser(&PacketHeader); + break; + case SIDESHOW_CMD_SET_CURRENT_USER: + SideShow_SetCurrentUser(&PacketHeader); + break; + case SIDESHOW_CMD_GET_CAPABILITIES: + SideShow_GetCapabilities(&PacketHeader); + break; + case SIDESHOW_CMD_GET_DEVICE_NAME: + SideShow_GetString(&PacketHeader, &DeviceName); + break; + case SIDESHOW_CMD_GET_MANUFACTURER: + SideShow_GetString(&PacketHeader, &Manufacturer); + break; + case SIDESHOW_CMD_GET_APPLICATION_ORDER: + SideShow_GetApplicationOrder(&PacketHeader); + break; + case SIDESHOW_CMD_GET_SUPPORTED_ENDPOINTS: + SideShow_GetSupportedEndpoints(&PacketHeader); + break; + case SIDESHOW_CMD_ADD_APPLICATION: + SideShow_AddApplication(&PacketHeader); + break; + case SIDESHOW_CMD_ADD_CONTENT: + SideShow_AddContent(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_CONTENT: + SideShow_DeleteContent(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_ALL_CONTENT: + SideShow_DeleteAllContent(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_APPLICATION: + SideShow_DeleteApplication(&PacketHeader); + break; + case SIDESHOW_CMD_DELETE_ALL_APPLICATIONS: + SideShow_DeleteAllApplications(&PacketHeader); + break; + default: + PacketHeader.Length -= sizeof(SideShow_PacketHeader_t); + + Endpoint_Discard_Stream(PacketHeader.Length); + Endpoint_ClearOUT(); + + PacketHeader.Length = sizeof(SideShow_PacketHeader_t); + PacketHeader.Type.NAK = true; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(&PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); + + printf(" UNK"); + } +} + +static void SideShow_Ping(SideShow_PacketHeader_t* PacketHeader) +{ + Endpoint_ClearOUT(); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} + +static void SideShow_Sync(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ProtocolGUID; + + Endpoint_Read_Stream_LE(&ProtocolGUID, sizeof(GUID_t)); + Endpoint_ClearOUT(); + + if (memcmp(&ProtocolGUID, (uint32_t[])STANDARD_PROTOCOL_GUID, sizeof(GUID_t)) != 0) + PacketHeader->Type.NAK = true; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_Write_Stream_LE(&ProtocolGUID, sizeof(GUID_t)); + Endpoint_ClearIN(); +} + +static void SideShow_GetCurrentUser(SideShow_PacketHeader_t* PacketHeader) +{ + Endpoint_ClearOUT(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + sizeof(uint32_t) + UserSID.LengthInBytes; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + SideShow_Write_Unicode_String(&UserSID); + Endpoint_ClearIN(); +} + +static void SideShow_SetCurrentUser(SideShow_PacketHeader_t* PacketHeader) +{ + SideShow_Read_Unicode_String(&UserSID, sizeof(UserSID.UnicodeString)); + Endpoint_ClearOUT(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} + +static void SideShow_GetCapabilities(SideShow_PacketHeader_t* PacketHeader) +{ + SideShow_PropertyKey_t Property; + SideShow_PropertyData_t PropertyData; + + Endpoint_Read_Stream_LE(&Property, sizeof(SideShow_PropertyKey_t)); + Endpoint_ClearOUT(); + + printf(" ID: %lu", Property.PropertyID); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + if (memcmp(&Property.PropertyGUID, (uint32_t[])SIDESHOW_PROPERTY_GUID, sizeof(GUID_t)) == 0) + { + switch (Property.PropertyID) + { + case PROPERTY_SIDESHOW_SCREENTYPE: + PropertyData.DataType = VT_I4; + PropertyData.Data.Data32 = ScreenText; + PacketHeader->Length += sizeof(uint32_t); + + break; + case PROPERTY_SIDESHOW_SCREENWIDTH: + case PROPERTY_SIDESHOW_CLIENTWIDTH: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = 16; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_SCREENHEIGHT: + case PROPERTY_SIDESHOW_CLIENTHEIGHT: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = 2; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_COLORDEPTH: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = 1; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_COLORTYPE: + PropertyData.DataType = VT_UI2; + PropertyData.Data.Data16 = BlackAndWhiteDisplay; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_DATACACHE: + PropertyData.DataType = VT_BOOL; + PropertyData.Data.Data16 = false; + PacketHeader->Length += sizeof(uint16_t); + + break; + case PROPERTY_SIDESHOW_SUPPORTEDLANGS: + case PROPERTY_SIDESHOW_CURRENTLANG: + PropertyData.DataType = VT_LPWSTR; + PropertyData.Data.DataPointer = &SupportedLanguage; + PacketHeader->Length += SupportedLanguage.LengthInBytes; + + break; + default: + PropertyData.DataType = VT_EMPTY; + break; + } + } + else if (memcmp(&Property.PropertyGUID, (uint32_t[])DEVICE_PROPERTY_GUID, sizeof(GUID_t)) == 0) + { + switch (Property.PropertyID) + { + case PROPERTY_DEVICE_DEVICETYPE: + PropertyData.DataType = VT_UI4; + PropertyData.Data.Data32 = GenericDevice; + PacketHeader->Length += sizeof(uint32_t); + + break; + } + } + else + { + PacketHeader->Type.NAK = true; + + printf(" WRONG GUID"); + printf(" %lX %lX %lX %lX", Property.PropertyGUID.Chunks[0], Property.PropertyGUID.Chunks[1], + Property.PropertyGUID.Chunks[2], Property.PropertyGUID.Chunks[3]); + } + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + + if (!(PacketHeader->Type.NAK)) + { + switch (PropertyData.DataType) + { + case VT_UI4: + case VT_I4: + Endpoint_Write_Stream_LE(&PropertyData.Data.Data32, sizeof(uint32_t)); + break; + case VT_UI2: + case VT_I2: + case VT_BOOL: + Endpoint_Write_Stream_LE(&PropertyData.Data.Data16, sizeof(uint16_t)); + break; + case VT_LPWSTR: + SideShow_Write_Unicode_String((Unicode_String_t*)PropertyData.Data.Data16); + break; + } + } + + Endpoint_ClearIN(); + return; +} + +static void SideShow_GetString(SideShow_PacketHeader_t* PacketHeader, void* UnicodeStruct) +{ + Endpoint_ClearOUT(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + + sizeof(uint32_t) + ((Unicode_String_t*)UnicodeStruct)->LengthInBytes; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + SideShow_Write_Unicode_String(UnicodeStruct); + Endpoint_ClearIN(); +} + +static void SideShow_GetApplicationOrder(SideShow_PacketHeader_t* PacketHeader) +{ + uint8_t TotalInstalledApplications = SideShow_GetTotalApplications(); + uint16_t GadgetGUIDBytes = (TotalInstalledApplications * sizeof(GUID_t)); + + Endpoint_ClearOUT(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + + sizeof(uint32_t) + GadgetGUIDBytes; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_Write_DWord_LE(TotalInstalledApplications); + + for (uint8_t App = 0; App < MAX_APPLICATIONS; App++) + { + if (InstalledApplications[App].InUse == true) + Endpoint_Write_Stream_LE(&InstalledApplications[App].ApplicationID, sizeof(GUID_t)); + } + + Endpoint_ClearIN(); +} + +static void SideShow_GetSupportedEndpoints(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t SupportedEndpointGUID = (GUID_t){Chunks: SIMPLE_CONTENT_FORMAT_GUID}; + + Endpoint_ClearOUT(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + sizeof(uint32_t) + sizeof(GUID_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_Write_DWord_LE(1); + Endpoint_Write_Stream_LE(&SupportedEndpointGUID, sizeof(GUID_t)); + Endpoint_ClearIN(); +} + +static void SideShow_AddApplication(SideShow_PacketHeader_t* PacketHeader) +{ + SideShow_Application_t* CurrApp; + GUID_t ApplicationID; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + + CurrApp = SideShow_GetApplicationFromGUID(&ApplicationID); + + if (CurrApp == NULL) + CurrApp = SideShow_GetFreeApplication(); + + if (CurrApp == NULL) + { + PacketHeader->Length -= sizeof(SideShow_PacketHeader_t) + sizeof(GUID_t); + + Endpoint_Discard_Stream(PacketHeader->Length); + Endpoint_ClearOUT(); + + PacketHeader->Type.NAK = true; + } + else + { + CurrApp->ApplicationID = ApplicationID; + Endpoint_Read_Stream_LE(&CurrApp->EndpointID, sizeof(GUID_t)); + SideShow_Read_Unicode_String(&CurrApp->ApplicationName, sizeof(CurrApp->ApplicationName.UnicodeString)); + Endpoint_Read_Stream_LE(&CurrApp->CachePolicy, sizeof(uint32_t)); + Endpoint_Read_Stream_LE(&CurrApp->OnlineOnly, sizeof(uint32_t)); + SideShow_Discard_Byte_Stream(); + SideShow_Discard_Byte_Stream(); + SideShow_Discard_Byte_Stream(); + Endpoint_ClearOUT(); + + CurrApp->InUse = true; + CurrApp->HaveContent = false; + CurrApp->CurrentContentID = 1; + } + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} + +static void SideShow_DeleteApplication(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationGUID; + + Endpoint_Read_Stream_LE(&ApplicationGUID, sizeof(GUID_t)); + Endpoint_ClearOUT(); + + SideShow_Application_t* AppToDelete = SideShow_GetApplicationFromGUID(&ApplicationGUID); + + if (AppToDelete != NULL) + { + AppToDelete->InUse = false; + } + else + PacketHeader->Type.NAK = true; + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} + +static void SideShow_DeleteAllApplications(SideShow_PacketHeader_t* PacketHeader) +{ + Endpoint_ClearOUT(); + + for (uint8_t App = 0; App < MAX_APPLICATIONS; App++) + InstalledApplications[App].InUse = false; + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} + +static void SideShow_AddContent(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationID; + GUID_t EndpointID; + SideShow_Application_t* Application; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&EndpointID, sizeof(GUID_t)); + + Application = SideShow_GetApplicationFromGUID(&ApplicationID); + + if (Application == NULL) + { + SideShow_Discard_Byte_Stream(); + PacketHeader->Type.NAK = true; + } + else if (!(SideShow_AddSimpleContent(PacketHeader, Application))) + { + PacketHeader->Type.NAK = true; + } + + Endpoint_ClearOUT(); + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} + +static void SideShow_DeleteContent(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationID; + GUID_t EndpointID; + uint32_t ContentID; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&EndpointID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&ContentID, sizeof(uint32_t)); + Endpoint_ClearOUT(); + + SideShow_Application_t* Application = SideShow_GetApplicationFromGUID(&ApplicationID); + + if ((Application != NULL) && (Application->CurrentContentID == ContentID)) + Application->HaveContent = false; + else + PacketHeader->Type.NAK = true; + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} + +static void SideShow_DeleteAllContent(SideShow_PacketHeader_t* PacketHeader) +{ + GUID_t ApplicationID; + GUID_t EndpointID; + + Endpoint_Read_Stream_LE(&ApplicationID, sizeof(GUID_t)); + Endpoint_Read_Stream_LE(&EndpointID, sizeof(GUID_t)); + Endpoint_ClearOUT(); + + SideShow_Application_t* Application = SideShow_GetApplicationFromGUID(&ApplicationID); + + if (Application != NULL) + Application->HaveContent = false; + else + PacketHeader->Type.NAK = true; + + PacketHeader->Length = sizeof(SideShow_PacketHeader_t); + + Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); + Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); + Endpoint_ClearIN(); +} diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.h b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.h new file mode 100644 index 000000000..197bc9588 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommands.h @@ -0,0 +1,165 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#ifndef _SIDESHOW_COMMANDS_H_ +#define _SIDESHOW_COMMANDS_H_ + + /* Includes: */ + #include + #include + #include + + #include "Sideshow.h" + #include "SideshowCommon.h" + #include "SideshowApplications.h" + #include "SideshowContent.h" + + /* Enumerations: */ + enum SideShow_PropertyKey_Types_t + { + VT_EMPTY = 0, + VT_NULL = 1, + VT_I2 = 2, + VT_I4 = 3, + VT_R4 = 4, + VT_R8 = 5, + VT_CY = 6, + VT_DATE = 7, + VT_BSTR = 8, + VT_DISPATCH = 9, + VT_ERROR = 10, + VT_BOOL = 11, + VT_VARIANT = 12, + VT_UNKNOWN = 13, + VT_UI1 = 17, + VT_UI2 = 18, + VT_UI4 = 19, + VT_LPWSTR = 31, + }; + + enum SideShow_ScreenTypeText_t + { + ScreenBitmap = 0, + ScreenText = 1, + }; + + enum SideShow_ColorTypes_t + { + ColorDisplay = 0, + GrayscaleDisplay = 1, + BlackAndWhiteDisplay = 2, + }; + + enum SideShow_DeviceTypes_t + { + GenericDevice = 0, + CameraDevice = 1, + MediaPlayerDevice = 2, + PhoneDevice = 3, + VideoDevice = 4, + PIMDevice = 5, + AudioRecorderDevice = 6 + }; + + /* Type Defines: */ + typedef struct + { + GUID_t PropertyGUID; + uint32_t PropertyID; + } SideShow_PropertyKey_t; + + typedef struct + { + uint32_t DataType; + + union + { + void* DataPointer; + uint8_t Data8; + uint16_t Data16; + uint32_t Data32; + } Data; + } SideShow_PropertyData_t; + + /* Macros: */ + #define SIDESHOW_CMD_PING 0x001 + #define SIDESHOW_CMD_SET_CURRENT_USER 0x100 + #define SIDESHOW_CMD_GET_CURRENT_USER 0x101 + #define SIDESHOW_CMD_GET_CAPABILITIES 0x103 + #define SIDESHOW_CMD_GET_APPLICATION_ORDER 0x104 + #define SIDESHOW_CMD_ADD_APPLICATION 0x10D + #define SIDESHOW_CMD_DELETE_APPLICATION 0x10E + #define SIDESHOW_CMD_DELETE_ALL_APPLICATIONS 0x10F + #define SIDESHOW_CMD_ADD_CONTENT 0x114 + #define SIDESHOW_CMD_DELETE_CONTENT 0x115 + #define SIDESHOW_CMD_DELETE_ALL_CONTENT 0x116 + #define SIDESHOW_CMD_GET_SUPPORTED_ENDPOINTS 0x117 + #define SIDESHOW_CMD_GET_DEVICE_NAME 0x500 + #define SIDESHOW_CMD_GET_MANUFACTURER 0x501 + #define SIDESHOW_CMD_SYNC 0x502 + + #define PROPERTY_SIDESHOW_DEVICEID 1 + #define PROPERTY_SIDESHOW_SCREENTYPE 2 + #define PROPERTY_SIDESHOW_SCREENWIDTH 3 + #define PROPERTY_SIDESHOW_SCREENHEIGHT 4 + #define PROPERTY_SIDESHOW_COLORDEPTH 5 + #define PROPERTY_SIDESHOW_COLORTYPE 6 + #define PROPERTY_SIDESHOW_DATACACHE 7 + #define PROPERTY_SIDESHOW_SUPPORTEDLANGS 8 + #define PROPERTY_SIDESHOW_CURRENTLANG 9 + #define PROPERTY_SIDESHOW_SUPPORTEDTHEMES 10 + #define PROPERTY_SIDESHOW_IMAGEFORMAT 14 + #define PROPERTY_SIDESHOW_CLIENTWIDTH 15 + #define PROPERTY_SIDESHOW_CLIENTHEIGHT 16 + #define PROPERTY_SIDESHOW_DEVICEICON 17 + + #define PROPERTY_DEVICE_DEVICETYPE 15 + + /* Function Prototypes: */ + void Sideshow_ProcessCommandPacket(void); + + #if defined(INCLUDE_FROM_SIDESHOWCOMMANDS_H) + static void SideShow_Ping(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_Sync(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetCurrentUser(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_SetCurrentUser(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetCapabilities(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetString(SideShow_PacketHeader_t* PacketHeader, void* UnicodeStruct); + static void SideShow_GetApplicationOrder(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_GetSupportedEndpoints(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_AddApplication(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteApplication(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteAllApplications(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_AddContent(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteContent(SideShow_PacketHeader_t* PacketHeader); + static void SideShow_DeleteAllContent(SideShow_PacketHeader_t* PacketHeader); + #endif + +#endif diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.c b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.c new file mode 100644 index 000000000..a45dbd971 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.c @@ -0,0 +1,70 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "SideshowCommon.h" + +uint16_t SideShow_Read_Unicode_String(void* UnicodeString, uint16_t MaxBytes) +{ + Unicode_String_t* UnicodeStruct = (Unicode_String_t*)UnicodeString; + uint32_t UnicodeCharsToRead; + + Endpoint_Read_Stream_LE(&UnicodeCharsToRead, sizeof(uint32_t)); + + int UnicodeData[UnicodeCharsToRead]; + + UnicodeStruct->LengthInBytes = (UnicodeCharsToRead << 1); + + Endpoint_Read_Stream_LE(&UnicodeData, UnicodeStruct->LengthInBytes); + + if (UnicodeStruct->LengthInBytes > MaxBytes) + UnicodeStruct->LengthInBytes = MaxBytes; + + memcpy(&UnicodeStruct->UnicodeString, &UnicodeData, UnicodeStruct->LengthInBytes); + + return ((UnicodeCharsToRead << 1) + sizeof(uint32_t)); +} + +void SideShow_Write_Unicode_String(void* UnicodeString) +{ + Unicode_String_t* UnicodeStruct = (Unicode_String_t*)UnicodeString; + + uint32_t StringSizeInCharacters = (UnicodeStruct->LengthInBytes >> 1); + + Endpoint_Write_Stream_LE(&StringSizeInCharacters, sizeof(uint32_t)); + Endpoint_Write_Stream_LE(&UnicodeStruct->UnicodeString, UnicodeStruct->LengthInBytes); +} + +void SideShow_Discard_Byte_Stream(void) +{ + uint32_t StreamSize; + + Endpoint_Read_Stream_LE(&StreamSize, sizeof(uint32_t)); + Endpoint_Discard_Stream(StreamSize); +} diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.h b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.h new file mode 100644 index 000000000..cea81ce66 --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowCommon.h @@ -0,0 +1,101 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#ifndef _SIDESHOW_COMMON_H_ +#define _SIDESHOW_COMMON_H_ + + /* Includes: */ + #include + #include + + #include + + /* Macros: */ + #define ARRAY_ELEMENTS(x) (sizeof(x) / sizeof(x[0])) + + #define UNICODE_STRING_t(x) struct \ + { \ + uint16_t LengthInBytes; \ + int UnicodeString[x]; \ + } + + // {A33F248B-882F-4531-82C2-ED3B90C5C520} + #define STANDARD_PROTOCOL_GUID {0xA33F248B, 0x4531882F, 0x3BEDC282, 0x20C5C590} + // {A9A5353F-2D4B-47CE-93EE-759F3A7DDA4F} + #define SIMPLE_CONTENT_FORMAT_GUID {0xA9A5353F, 0x47CE2D4B, 0x9F75EE93, 0x4FDA7D3A} + // {8ABC88A8-857B-4ad7-A35A-B5942F492B99} + #define SIDESHOW_PROPERTY_GUID {0x8ABC88A8, 0x4AD7857B, 0x94B55AA3, 0x992B492F} + // {26D4979A-E643-4626-9E2B-736DC0C92FDC} + #define DEVICE_PROPERTY_GUID {0x26D4979A, 0x4626E643, 0x6D732B9E, 0xDC2FC9C0} + + #define SECURITY_INTERACTIVE_RID_SID L"S-1-5-4" + + #define MAX_APPLICATIONS 4 + #define MAX_CONTENTBUFFER_PER_APP 1024 + + /* Type Defines: */ + typedef struct + { + uint32_t Chunks[4]; + } GUID_t; + + typedef struct + { + uint16_t LengthInBytes; + int UnicodeString[]; + } Unicode_String_t; + + typedef union + { + uint32_t TypeLong; + + struct + { + uint8_t TypeBytes[3]; + + int ErrorCode : 6; + int NAK : 1; + int Response : 1; + }; + } SideShowPacketType_t; + + typedef struct + { + uint32_t Length; + SideShowPacketType_t Type; + uint16_t Number; + } SideShow_PacketHeader_t; + + /* Function Prototypes: */ + uint16_t SideShow_Read_Unicode_String(void* UnicodeString, uint16_t MaxBytes); + void SideShow_Write_Unicode_String(void* UnicodeString); + void SideShow_Discard_Byte_Stream(void); + +#endif \ No newline at end of file diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.c b/Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.c new file mode 100644 index 000000000..9b8b375ec --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.c @@ -0,0 +1,76 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define INCLUDE_FROM_SIDESHOWCONTENT_C +#include "SideshowContent.h" + +bool SideShow_AddSimpleContent(SideShow_PacketHeader_t* PacketHeader, SideShow_Application_t* Application) +{ + uint32_t ContentSize; + uint32_t ContentID; + + Endpoint_Read_Stream_LE(&ContentID, sizeof(uint32_t)); + + PacketHeader->Length -= sizeof(uint32_t); + + if (Application->CurrentContentID != ContentID) + { + Endpoint_Discard_Stream(PacketHeader->Length); + + return false; + } + + Endpoint_Read_Stream_LE(&ContentSize, sizeof(uint32_t)); + Endpoint_Read_Stream_LE(&Application->CurrentContent, sizeof(XML_START_TAG) - 1); + + PacketHeader->Length -= sizeof(uint32_t) + (sizeof(XML_START_TAG) - 1); + + if (!(memcmp(&Application->CurrentContent, XML_START_TAG, (sizeof(XML_START_TAG) - 1)))) + { + SideShow_ProcessXMLContent(&Application->CurrentContent, (ContentSize - (sizeof(XML_END_TAG) - 1))); + + Endpoint_Discard_Stream(sizeof(XML_END_TAG) - 1); + + Application->HaveContent = true; + } + else + { + printf(" BINARY"); + Endpoint_Discard_Stream(ContentSize); + } + + return true; +} + +static void SideShow_ProcessXMLContent(void* ContentData, uint32_t ContentSize) +{ + printf(" XML"); + Endpoint_Discard_Stream(ContentSize); +} diff --git a/Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.h b/Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.h new file mode 100644 index 000000000..a9333a8ed --- /dev/null +++ b/Demos/Device/Incomplete/Sideshow/Lib/SideshowContent.h @@ -0,0 +1,124 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#ifndef _SIDESHOW_CONTENT_H_ +#define _SIDESHOW_CONTENT_H_ + + /* Includes: */ + #include + #include + #include + + #include "SideshowCommon.h" + #include "SideshowApplications.h" + + /* Enums: */ + enum SideShow_ContentTypes_t + { + Content_Menu = 0, + Content_Content = 1, + Content_MenuItem = 2, + Content_Button = 3, + Content_Text = 4, + Content_EndOfContent = 5 + }; + + enum SideShow_ActionTypes_t + { + TODO + }; + + enum SideShow_AlignmentTypes_t + { + TODO2 + }; + + /* Type Defines: */ + typedef struct + { + uint8_t ContentType; + uint8_t ContentSize; + } SideShow_Content_Header_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint32_t ItemID; + uint8_t ActionType; + char Title[]; + } SideShow_Content_Menu_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint32_t ItemID; + uint32_t Target; + bool IsSelected; + char Text[]; + } SideShow_Content_MenuItem_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint8_t Key; + uint32_t Target; + } SideShow_Content_Button_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + uint32_t ItemID; + uint32_t AssociatedMenuID; + char Title[]; + } SideShow_Content_Content_t; + + typedef struct + { + SideShow_Content_Header_t Header; + + char Text[]; + } SideShow_Content_Text_t; + + /* Defines: */ + #define XML_START_TAG "" + #define XML_END_TAG "" + + /* Function Prototypes: */ + bool SideShow_AddSimpleContent(SideShow_PacketHeader_t* PacketHeader, SideShow_Application_t* Application); + + #if defined(INCLUDE_FROM_SIDESHOWCONTENT_C) + static void SideShow_ProcessXMLContent(void* ContentData, uint32_t ContentSize); + #endif + +#endif \ No newline at end of file -- cgit v1.2.3