From 21dea1aba3e8308ab9b1a62a6735bed47f13d522 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 30 Jun 2015 00:47:42 +0200 Subject: ported usb-eth to new lufa --- lib/lufa-descriptor-rndis.c | 280 +++++++++++++++++++++----------------------- lib/lufa-descriptor-rndis.h | 39 ++++-- usb-eth/Makefile | 7 +- usb-eth/usb-eth.c | 43 ++++--- 4 files changed, 194 insertions(+), 175 deletions(-) diff --git a/lib/lufa-descriptor-rndis.c b/lib/lufa-descriptor-rndis.c index 635b1f5..f8caf0b 100644 --- a/lib/lufa-descriptor-rndis.c +++ b/lib/lufa-descriptor-rndis.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2012. + Copyright (C) Dean Camera, 2014. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -18,7 +18,7 @@ advertising or publicity pertaining to distribution of the software without specific, written prior permission. - The author disclaim all warranties with regard to this + The author disclaims 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 @@ -44,24 +44,24 @@ */ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { - .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, + .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, - .USBSpecification = VERSION_BCD(01.10), - .Class = CDC_CSCP_CDCClass, - .SubClass = CDC_CSCP_NoSpecificSubclass, - .Protocol = CDC_CSCP_NoSpecificProtocol, + .USBSpecification = VERSION_BCD(1,1,0), + .Class = CDC_CSCP_CDCClass, + .SubClass = CDC_CSCP_NoSpecificSubclass, + .Protocol = CDC_CSCP_NoSpecificProtocol, - .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, + .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, - .VendorID = 0x03EB, - .ProductID = 0x204C, - .ReleaseNumber = VERSION_BCD(00.01), + .VendorID = 0x03EB, + .ProductID = 0x204C, + .ReleaseNumber = VERSION_BCD(0,0,1), - .ManufacturerStrIndex = 0x01, - .ProductStrIndex = 0x02, - .SerialNumStrIndex = NO_DESCRIPTOR, + .ManufacturerStrIndex = STRING_ID_Manufacturer, + .ProductStrIndex = STRING_ID_Product, + .SerialNumStrIndex = NO_DESCRIPTOR, - .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS + .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS }; /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage @@ -71,107 +71,107 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = */ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { - .Config = - { - .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, + .Config = + { + .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, - .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), - .TotalInterfaces = 2, + .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), + .TotalInterfaces = 2, - .ConfigurationNumber = 1, - .ConfigurationStrIndex = NO_DESCRIPTOR, + .ConfigurationNumber = 1, + .ConfigurationStrIndex = NO_DESCRIPTOR, - .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), + .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), - .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) - }, + .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) + }, - .CDC_CCI_Interface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + .CDC_CCI_Interface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = 0, - .AlternateSetting = 0, + .InterfaceNumber = INTERFACE_ID_CDC_CCI, + .AlternateSetting = 0, - .TotalEndpoints = 1, + .TotalEndpoints = 1, - .Class = CDC_CSCP_CDCClass, - .SubClass = CDC_CSCP_ACMSubclass, - .Protocol = CDC_CSCP_VendorSpecificProtocol, + .Class = CDC_CSCP_CDCClass, + .SubClass = CDC_CSCP_ACMSubclass, + .Protocol = CDC_CSCP_VendorSpecificProtocol, - .InterfaceStrIndex = NO_DESCRIPTOR - }, + .InterfaceStrIndex = NO_DESCRIPTOR + }, - .CDC_Functional_Header = - { - .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface}, - .Subtype = CDC_DSUBTYPE_CSInterface_Header, + .CDC_Functional_Header = + { + .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface}, + .Subtype = CDC_DSUBTYPE_CSInterface_Header, - .CDCSpecification = VERSION_BCD(01.10), - }, + .CDCSpecification = VERSION_BCD(1,1,0), + }, - .CDC_Functional_ACM = - { - .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface}, - .Subtype = CDC_DSUBTYPE_CSInterface_ACM, + .CDC_Functional_ACM = + { + .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface}, + .Subtype = CDC_DSUBTYPE_CSInterface_ACM, - .Capabilities = 0x00, - }, + .Capabilities = 0x00, + }, - .CDC_Functional_Union = - { - .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface}, - .Subtype = CDC_DSUBTYPE_CSInterface_Union, + .CDC_Functional_Union = + { + .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface}, + .Subtype = CDC_DSUBTYPE_CSInterface_Union, - .MasterInterfaceNumber = 0, - .SlaveInterfaceNumber = 1, - }, + .MasterInterfaceNumber = INTERFACE_ID_CDC_CCI, + .SlaveInterfaceNumber = INTERFACE_ID_CDC_DCI, + }, - .CDC_NotificationEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + .CDC_NotificationEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - .EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM), - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = CDC_NOTIFICATION_EPSIZE, - .PollingIntervalMS = 0xFF - }, + .EndpointAddress = CDC_NOTIFICATION_EPADDR, + .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = CDC_NOTIFICATION_EPSIZE, + .PollingIntervalMS = 0xFF + }, - .CDC_DCI_Interface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + .CDC_DCI_Interface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = 1, - .AlternateSetting = 0, + .InterfaceNumber = INTERFACE_ID_CDC_DCI, + .AlternateSetting = 0, - .TotalEndpoints = 2, + .TotalEndpoints = 2, - .Class = CDC_CSCP_CDCDataClass, - .SubClass = CDC_CSCP_NoDataSubclass, - .Protocol = CDC_CSCP_NoDataProtocol, + .Class = CDC_CSCP_CDCDataClass, + .SubClass = CDC_CSCP_NoDataSubclass, + .Protocol = CDC_CSCP_NoDataProtocol, - .InterfaceStrIndex = NO_DESCRIPTOR - }, + .InterfaceStrIndex = NO_DESCRIPTOR + }, - .RNDIS_DataOutEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + .RNDIS_DataOutEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - .EndpointAddress = (ENDPOINT_DIR_OUT | CDC_RX_EPNUM), - .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = CDC_TXRX_EPSIZE, - .PollingIntervalMS = 0x01 - }, + .EndpointAddress = CDC_RX_EPADDR, + .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = CDC_TXRX_EPSIZE, + .PollingIntervalMS = 0x05 + }, - .RNDIS_DataInEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + .RNDIS_DataInEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - .EndpointAddress = (ENDPOINT_DIR_IN | CDC_TX_EPNUM), - .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = CDC_TXRX_EPSIZE, - .PollingIntervalMS = 0x01 - } + .EndpointAddress = CDC_TX_EPADDR, + .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = CDC_TXRX_EPSIZE, + .PollingIntervalMS = 0x05 + } }; /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests @@ -180,40 +180,30 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = */ const USB_Descriptor_String_t PROGMEM LanguageString = { - .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, + .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, - .UnicodeString = {LANGUAGE_ID_ENG} + .UnicodeString = {LANGUAGE_ID_ENG} }; /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. */ -const USB_Descriptor_String_t PROGMEM ManufacturerString = -{ #ifndef USB_MANUFACTURER - .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, - .UnicodeString = L"Dean Camera" +const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera"); #else - .Header = {.Size = USB_STRING_LEN(USB_MANUFACTURER_LEN), .Type = DTYPE_String}, - .UnicodeString = USB_MANUFACTURER +const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(USB_MANUFACTURER); #endif -}; /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. */ -const USB_Descriptor_String_t PROGMEM ProductString = -{ #ifndef USB_PRODUCT - .Header = {.Size = USB_STRING_LEN(23), .Type = DTYPE_String}, - .UnicodeString = L"LUFA USB-RS232 Adapter" +const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA RNDIS CDC Demo"); #else - .Header = {.Size = USB_STRING_LEN(USB_PRODUCT_LEN), .Type = DTYPE_String}, - .UnicodeString = USB_PRODUCT +const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(USB_PRODUCT); #endif -}; /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" * documentation) by the application code so that the address and size of a requested descriptor can be given @@ -225,43 +215,43 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, const void** const DescriptorAddress) { - const uint8_t DescriptorType = (wValue >> 8); - const uint8_t DescriptorNumber = (wValue & 0xFF); - - const void* Address = NULL; - uint16_t Size = NO_DESCRIPTOR; - - switch (DescriptorType) - { - case DTYPE_Device: - Address = &DeviceDescriptor; - Size = sizeof(USB_Descriptor_Device_t); - break; - case DTYPE_Configuration: - Address = &ConfigurationDescriptor; - Size = sizeof(USB_Descriptor_Configuration_t); - break; - case DTYPE_String: - switch (DescriptorNumber) - { - case 0x00: - Address = &LanguageString; - Size = pgm_read_byte(&LanguageString.Header.Size); - break; - case 0x01: - Address = &ManufacturerString; - Size = pgm_read_byte(&ManufacturerString.Header.Size); - break; - case 0x02: - Address = &ProductString; - Size = pgm_read_byte(&ProductString.Header.Size); - break; - } - - break; - } - - *DescriptorAddress = Address; - return Size; + const uint8_t DescriptorType = (wValue >> 8); + const uint8_t DescriptorNumber = (wValue & 0xFF); + + const void* Address = NULL; + uint16_t Size = NO_DESCRIPTOR; + + switch (DescriptorType) + { + case DTYPE_Device: + Address = &DeviceDescriptor; + Size = sizeof(USB_Descriptor_Device_t); + break; + case DTYPE_Configuration: + Address = &ConfigurationDescriptor; + Size = sizeof(USB_Descriptor_Configuration_t); + break; + case DTYPE_String: + switch (DescriptorNumber) + { + case STRING_ID_Language: + Address = &LanguageString; + Size = pgm_read_byte(&LanguageString.Header.Size); + break; + case STRING_ID_Manufacturer: + Address = &ManufacturerString; + Size = pgm_read_byte(&ManufacturerString.Header.Size); + break; + case STRING_ID_Product: + Address = &ProductString; + Size = pgm_read_byte(&ProductString.Header.Size); + break; + } + + break; + } + + *DescriptorAddress = Address; + return Size; } diff --git a/lib/lufa-descriptor-rndis.h b/lib/lufa-descriptor-rndis.h index 7c40d87..9390ef2 100644 --- a/lib/lufa-descriptor-rndis.h +++ b/lib/lufa-descriptor-rndis.h @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2012. + Copyright (C) Dean Camera, 2014. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -18,7 +18,7 @@ advertising or publicity pertaining to distribution of the software without specific, written prior permission. - The author disclaim all warranties with regard to this + The author disclaims 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 @@ -42,14 +42,14 @@ #include /* Macros: */ - /** Endpoint number of the CDC device-to-host notification IN endpoint. */ - #define CDC_NOTIFICATION_EPNUM 3 + /** Endpoint address of the CDC device-to-host notification IN endpoint. */ + #define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 3) - /** Endpoint number of the CDC device-to-host data IN endpoint. */ - #define CDC_TX_EPNUM 1 + /** Endpoint address of the CDC device-to-host data IN endpoint. */ + #define CDC_TX_EPADDR (ENDPOINT_DIR_IN | 1) - /** Endpoint number of the CDC host-to-device data OUT endpoint. */ - #define CDC_RX_EPNUM 2 + /** Endpoint address of the CDC host-to-device data OUT endpoint. */ + #define CDC_RX_EPADDR (ENDPOINT_DIR_OUT | 2) /** Size in bytes of the CDC device-to-host notification IN endpoint. */ #define CDC_NOTIFICATION_EPSIZE 8 @@ -79,6 +79,27 @@ USB_Descriptor_Endpoint_t RNDIS_DataInEndpoint; } USB_Descriptor_Configuration_t; + /** Enum for the device interface descriptor IDs within the device. Each interface descriptor + * should have a unique ID index associated with it, which can be used to refer to the + * interface from other descriptors. + */ + enum InterfaceDescriptors_t + { + INTERFACE_ID_CDC_CCI = 0, /**< CDC CCI interface descriptor ID */ + INTERFACE_ID_CDC_DCI = 1, /**< CDC DCI interface descriptor ID */ + }; + + /** Enum for the device string descriptor IDs within the device. Each string descriptor should + * have a unique ID index associated with it, which can be used to refer to the string from + * other descriptors. + */ + enum StringDescriptors_t + { + STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */ + STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */ + STRING_ID_Product = 2, /**< Product string ID */ + }; + /* Function Prototypes: */ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, diff --git a/usb-eth/Makefile b/usb-eth/Makefile index 23c51f7..f7f6eb5 100644 --- a/usb-eth/Makefile +++ b/usb-eth/Makefile @@ -27,16 +27,15 @@ LIBS := util led lufa-descriptor-rndis EXTERNAL_LIBS := lufa SPREADAVR_PATH := .. -LUFA_PATH := $(SPREADAVR_PATH)/contrib/LUFA-120219 - +LUFA_PATH := $(SPREADAVR_PATH)/contrib/lufa-LUFA-140928 LUFA_OPTS = -D USB_DEVICE_ONLY LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 LUFA_OPTS += -D USE_FLASH_DESCRIPTORS LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" -D USB_MANUFACTURER_LEN=7 -LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-eth example\"" -D USB_PRODUCT_LEN=27 +LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" +LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-eth example\"" LUFA_COMPONENTS := USB USBCLASS diff --git a/usb-eth/usb-eth.c b/usb-eth/usb-eth.c index 71e4a3b..67fb861 100644 --- a/usb-eth/usb-eth.c +++ b/usb-eth/usb-eth.c @@ -31,7 +31,7 @@ /* LUFA Library - Copyright (C) Dean Camera, 2012. + Copyright (C) Dean Camera, 2014. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org @@ -43,6 +43,8 @@ #define ADAPTER_MAC_ADDR {0x02, 0x00, 0x02, 0x00, 0x02, 0x00} #define MY_MAC_ADDR {0x01, 0x02, 0x03, 0x04, 0x05, 0x06} +static uint8_t RNDIS_Message_Buffer[192]; + /** LUFA RNDIS Class driver interface configuration and state information. This structure is * passed to all RNDIS Class driver functions, so that multiple instances of the same class * within a device can be differentiated from one another. @@ -51,22 +53,29 @@ USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface = { .Config = { - .ControlInterfaceNumber = 0, - - .DataINEndpointNumber = CDC_TX_EPNUM, - .DataINEndpointSize = CDC_TXRX_EPSIZE, - .DataINEndpointDoubleBank = false, - - .DataOUTEndpointNumber = CDC_RX_EPNUM, - .DataOUTEndpointSize = CDC_TXRX_EPSIZE, - .DataOUTEndpointDoubleBank = false, - - .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, - .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, - .NotificationEndpointDoubleBank = false, - - .AdapterVendorDescription = "LUFA RNDIS Adapter", + .ControlInterfaceNumber = INTERFACE_ID_CDC_CCI, + .DataINEndpoint = + { + .Address = CDC_TX_EPADDR, + .Size = CDC_TXRX_EPSIZE, + .Banks = 1, + }, + .DataOUTEndpoint = + { + .Address = CDC_RX_EPADDR, + .Size = CDC_TXRX_EPSIZE, + .Banks = 1, + }, + .NotificationEndpoint = + { + .Address = CDC_NOTIFICATION_EPADDR, + .Size = CDC_NOTIFICATION_EPSIZE, + .Banks = 1, + }, + .AdapterVendorDescription = "LUFA RNDIS Demo Adapter", .AdapterMACAddress = {ADAPTER_MAC_ADDR}, + .MessageBuffer = RNDIS_Message_Buffer, + .MessageBufferLength = sizeof(RNDIS_Message_Buffer), }, }; @@ -126,7 +135,7 @@ int main(void) RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface, eth_recv_buf.data, eth_recv_buf.len); led_off(); } - + RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface); USB_USBTask(); } -- cgit v1.2.3