Merge commit '60b30c0363
' as 'lib/lufa'
This commit is contained in:
commit
8655d4f494
1455 changed files with 394541 additions and 0 deletions
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2017.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2017 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
|
||||
without fee, 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 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
|
||||
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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief LUFA Library Configuration Header File
|
||||
*
|
||||
* This header file is used to configure LUFA's compile time options,
|
||||
* as an alternative to the compile time constants supplied through
|
||||
* a makefile.
|
||||
*
|
||||
* For information on what each token does, refer to the LUFA
|
||||
* manual section "Summary of Compile Tokens".
|
||||
*/
|
||||
|
||||
#ifndef _LUFA_CONFIG_H_
|
||||
#define _LUFA_CONFIG_H_
|
||||
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
|
||||
/* Non-USB Related Configuration Tokens: */
|
||||
// #define DISABLE_TERMINAL_CODES
|
||||
|
||||
/* USB Class Driver Related Tokens: */
|
||||
// #define HID_HOST_BOOT_PROTOCOL_ONLY
|
||||
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
|
||||
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
|
||||
// #define HID_MAX_COLLECTIONS {Insert Value Here}
|
||||
// #define HID_MAX_REPORTITEMS {Insert Value Here}
|
||||
// #define HID_MAX_REPORT_IDS {Insert Value Here}
|
||||
// #define NO_CLASS_DRIVER_AUTOFLUSH
|
||||
|
||||
/* General USB Driver Related Tokens: */
|
||||
// #define ORDERED_EP_CONFIG
|
||||
#define USE_STATIC_OPTIONS (USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
|
||||
// #define USB_DEVICE_ONLY
|
||||
#define USB_HOST_ONLY
|
||||
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
|
||||
// #define NO_LIMITED_CONTROLLER_CONNECT
|
||||
// #define NO_SOF_EVENTS
|
||||
|
||||
/* USB Device Mode Driver Related Tokens: */
|
||||
// #define USE_RAM_DESCRIPTORS
|
||||
// #define USE_FLASH_DESCRIPTORS
|
||||
// #define USE_EEPROM_DESCRIPTORS
|
||||
// #define NO_INTERNAL_SERIAL
|
||||
// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here}
|
||||
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
|
||||
// #define FIXED_NUM_CONFIGURATIONS {Insert Value Here}
|
||||
// #define CONTROL_ONLY_DEVICE
|
||||
// #define INTERRUPT_CONTROL_ENDPOINT
|
||||
// #define NO_DEVICE_REMOTE_WAKEUP
|
||||
// #define NO_DEVICE_SELF_POWER
|
||||
|
||||
/* USB Host Mode Driver Related Tokens: */
|
||||
// #define HOST_STATE_AS_GPIOR {Insert Value Here}
|
||||
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
|
||||
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
|
||||
// #define NO_AUTO_VBUS_MANAGEMENT
|
||||
// #define INVERTED_VBUS_ENABLE_LINE
|
||||
|
||||
#else
|
||||
|
||||
#error Unsupported architecture for this LUFA configuration file.
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2017.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2017 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
|
||||
without fee, 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 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
|
||||
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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Configuration Descriptor processing routines, to determine the correct pipe configurations
|
||||
* needed to communication with an attached USB device. Descriptors are special computer-readable structures
|
||||
* which the host requests upon device enumeration, to determine the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "ConfigDescriptor.h"
|
||||
|
||||
/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This
|
||||
* routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate
|
||||
* with compatible devices.
|
||||
*
|
||||
* This routine searches for a RNDIS interface descriptor containing bulk data IN and OUT endpoints, and an interrupt event endpoint.
|
||||
*
|
||||
* \return An error code from the \ref RNDISHost_GetConfigDescriptorDataCodes_t enum.
|
||||
*/
|
||||
uint8_t ProcessConfigurationDescriptor(void)
|
||||
{
|
||||
uint8_t ConfigDescriptorData[512];
|
||||
void* CurrConfigLocation = ConfigDescriptorData;
|
||||
uint16_t CurrConfigBytesRem;
|
||||
|
||||
USB_Descriptor_Interface_t* RNDISControlInterface = NULL;
|
||||
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
|
||||
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
|
||||
USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL;
|
||||
|
||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||
switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||
{
|
||||
case HOST_GETCONFIG_Successful:
|
||||
break;
|
||||
case HOST_GETCONFIG_InvalidData:
|
||||
return InvalidConfigDataReturned;
|
||||
case HOST_GETCONFIG_BuffOverflow:
|
||||
return DescriptorTooLarge;
|
||||
default:
|
||||
return ControlError;
|
||||
}
|
||||
|
||||
while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint))
|
||||
{
|
||||
/* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
|
||||
if (!(RNDISControlInterface) ||
|
||||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Check if we have already found the control interface's notification endpoint or not */
|
||||
if (NotificationEndpoint)
|
||||
{
|
||||
/* Get the next RNDIS data interface from the configuration descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoCompatibleInterfaceFound;
|
||||
}
|
||||
|
||||
/* Clear any found endpoints */
|
||||
DataINEndpoint = NULL;
|
||||
DataOUTEndpoint = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the next RNDIS control interface from the configuration descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoCompatibleInterfaceFound;
|
||||
}
|
||||
|
||||
/* Save the interface in case we need to refer back to it later */
|
||||
RNDISControlInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t);
|
||||
|
||||
/* Clear any found endpoints */
|
||||
NotificationEndpoint = NULL;
|
||||
}
|
||||
|
||||
/* Skip the remainder of the loop as we have not found an endpoint yet */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Retrieve the endpoint address from the endpoint descriptor */
|
||||
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
|
||||
|
||||
/* If the endpoint is a IN type endpoint */
|
||||
if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
|
||||
{
|
||||
/* Check if the found endpoint is a interrupt or bulk type descriptor */
|
||||
if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT)
|
||||
NotificationEndpoint = EndpointData;
|
||||
else
|
||||
DataINEndpoint = EndpointData;
|
||||
}
|
||||
else
|
||||
{
|
||||
DataOUTEndpoint = EndpointData;
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure the RNDIS data IN pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_DATA_IN_PIPE, EP_TYPE_BULK, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, 1);
|
||||
|
||||
/* Configure the RNDIS data OUT pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_DATA_OUT_PIPE, EP_TYPE_BULK, DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, 1);
|
||||
|
||||
/* Configure the RNDIS notification pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_NOTIFICATION_PIPE, EP_TYPE_INTERRUPT, NotificationEndpoint->EndpointAddress, NotificationEndpoint->EndpointSize, 1);
|
||||
Pipe_SetInterruptPeriod(NotificationEndpoint->PollingIntervalMS);
|
||||
|
||||
/* Valid data found, return success */
|
||||
return SuccessfulConfigRead;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next Interface descriptor of the correct CDC control Class, Subclass and Protocol values.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextCDCControlInterface(void* CurrentDescriptor)
|
||||
{
|
||||
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
|
||||
|
||||
if (Header->Type == DTYPE_Interface)
|
||||
{
|
||||
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
|
||||
|
||||
/* Check the CDC descriptor class, subclass and protocol, break out if correct control interface found */
|
||||
if ((Interface->Class == CDC_CSCP_CDCClass) &&
|
||||
(Interface->SubClass == CDC_CSCP_ACMSubclass) &&
|
||||
(Interface->Protocol == CDC_CSCP_VendorSpecificProtocol))
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next Interface descriptor of the correct CDC data Class, Subclass and Protocol values.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextCDCDataInterface(void* CurrentDescriptor)
|
||||
{
|
||||
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
|
||||
|
||||
if (Header->Type == DTYPE_Interface)
|
||||
{
|
||||
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
|
||||
|
||||
/* Check the CDC descriptor class, subclass and protocol, break out if correct data interface found */
|
||||
if ((Interface->Class == CDC_CSCP_CDCDataClass) &&
|
||||
(Interface->SubClass == CDC_CSCP_NoDataSubclass) &&
|
||||
(Interface->Protocol == CDC_CSCP_NoDataProtocol))
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
|
||||
* descriptor processing if an incompatible descriptor configuration is found.
|
||||
*
|
||||
* This comparator searches for the next bulk IN or OUT endpoint, or interrupt IN endpoint within the current interface,
|
||||
* aborting the search if another interface descriptor is found before the required endpoint (so that it may be compared
|
||||
* using a different comparator to determine if it is another CDC class interface).
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DComp_NextCDCDataInterfaceEndpoint(void* CurrentDescriptor)
|
||||
{
|
||||
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
|
||||
|
||||
if (Header->Type == DTYPE_Endpoint)
|
||||
{
|
||||
USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
|
||||
|
||||
/* Check the endpoint type, break out if correct BULK or INTERRUPT type endpoint found */
|
||||
if (((Endpoint->Attributes & EP_TYPE_MASK) == EP_TYPE_BULK) ||
|
||||
((Endpoint->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT))
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
}
|
||||
else if (Header->Type == DTYPE_Interface)
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Fail;
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2017.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2017 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
|
||||
without fee, 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 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
|
||||
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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for ConfigDescriptor.c.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIGDESCRIPTOR_H_
|
||||
#define _CONFIGDESCRIPTOR_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "RNDISEthernetHost.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Pipe address for the RNDIS data IN pipe. */
|
||||
#define RNDIS_DATA_IN_PIPE (PIPE_DIR_IN | 1)
|
||||
|
||||
/** Pipe address for the RNDIS data OUT pipe. */
|
||||
#define RNDIS_DATA_OUT_PIPE (PIPE_DIR_OUT | 2)
|
||||
|
||||
/** Pipe address for the RNDIS notification IN pipe. */
|
||||
#define RNDIS_NOTIFICATION_PIPE (PIPE_DIR_IN | 3)
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
|
||||
enum RNDISHost_GetConfigDescriptorDataCodes_t
|
||||
{
|
||||
SuccessfulConfigRead = 0, /**< Configuration Descriptor was processed successfully */
|
||||
ControlError = 1, /**< A control request to the device failed to complete successfully */
|
||||
DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */
|
||||
InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */
|
||||
NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t ProcessConfigurationDescriptor(void);
|
||||
|
||||
uint8_t DComp_NextCDCControlInterface(void* CurrentDescriptor);
|
||||
uint8_t DComp_NextCDCDataInterface(void* CurrentDescriptor);
|
||||
uint8_t DComp_NextCDCDataInterfaceEndpoint(void* CurrentDescriptor);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2017.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2017 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
|
||||
without fee, 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 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
|
||||
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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* RNDIS Device commands, to issue RNDIS commands to the device for
|
||||
* the control and data transfer between the host and RNDIS device.
|
||||
*/
|
||||
|
||||
#include "RNDISCommands.h"
|
||||
|
||||
/** Current RNDIS Request ID, for associating sent commands with received data */
|
||||
uint32_t RequestID = 0;
|
||||
|
||||
|
||||
/** Function to send the given encapsulated RNDIS command to the device.
|
||||
*
|
||||
* \param[in] Buffer Source command data buffer to send to the device
|
||||
* \param[in] Length Number of bytes to send
|
||||
*
|
||||
* \return A value from the USB_Host_SendControlErrorCodes_t enum
|
||||
*/
|
||||
uint8_t RNDIS_SendEncapsulatedCommand(void* const Buffer,
|
||||
const uint16_t Length)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),
|
||||
.bRequest = RNDIS_REQ_SendEncapsulatedCommand,
|
||||
.wValue = 0,
|
||||
.wIndex = 0,
|
||||
.wLength = Length,
|
||||
};
|
||||
|
||||
/* Select the control pipe for the request transfer */
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
|
||||
return USB_Host_SendControlRequest(Buffer);
|
||||
}
|
||||
|
||||
/** Function to receive the given encapsulated RNDIS response from the device.
|
||||
*
|
||||
* \param[out] Buffer Destination command data buffer to write read data from the device to
|
||||
* \param[in] Length Number of bytes to read
|
||||
*
|
||||
* \return A value from the USB_Host_SendControlErrorCodes_t enum
|
||||
*/
|
||||
uint8_t RNDIS_GetEncapsulatedResponse(void* const Buffer,
|
||||
const uint16_t Length)
|
||||
{
|
||||
USB_ControlRequest = (USB_Request_Header_t)
|
||||
{
|
||||
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
|
||||
.bRequest = RNDIS_REQ_GetEncapsulatedResponse,
|
||||
.wValue = 0,
|
||||
.wIndex = 0,
|
||||
.wLength = Length,
|
||||
};
|
||||
|
||||
/* Select the control pipe for the request transfer */
|
||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||
|
||||
return USB_Host_SendControlRequest(Buffer);
|
||||
}
|
||||
|
||||
/** Sends a RNDIS KEEPALIVE command to the device, to ensure that it does not enter standby mode after periods
|
||||
* of long inactivity.
|
||||
*
|
||||
* \return A value from the USB_Host_SendControlErrorCodes_t enum or RNDIS_COMMAND_FAILED if the device returned a
|
||||
* logical command failure
|
||||
*/
|
||||
uint8_t RNDIS_SendKeepAlive(void)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
RNDIS_KeepAlive_Message_t KeepAliveMessage;
|
||||
RNDIS_KeepAlive_Complete_t KeepAliveMessageResponse;
|
||||
|
||||
KeepAliveMessage.MessageType = REMOTE_NDIS_KEEPALIVE_MSG;
|
||||
KeepAliveMessage.MessageLength = sizeof(RNDIS_KeepAlive_Message_t);
|
||||
KeepAliveMessage.RequestId = RequestID++;
|
||||
|
||||
if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&KeepAliveMessage,
|
||||
sizeof(RNDIS_KeepAlive_Message_t))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&KeepAliveMessageResponse,
|
||||
sizeof(RNDIS_KeepAlive_Complete_t))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
return HOST_SENDCONTROL_Successful;
|
||||
}
|
||||
|
||||
/** Initializes the attached RNDIS device's RNDIS interface.
|
||||
*
|
||||
* \param[in] HostMaxPacketSize Size of the packet buffer on the host
|
||||
* \param[out] DeviceMaxPacketSize Pointer to where the packet buffer size of the device is to be stored
|
||||
*
|
||||
* \return A value from the USB_Host_SendControlErrorCodes_t enum or RNDIS_COMMAND_FAILED if the device returned a
|
||||
* logical command failure
|
||||
*/
|
||||
uint8_t RNDIS_InitializeDevice(const uint16_t HostMaxPacketSize,
|
||||
uint16_t* const DeviceMaxPacketSize)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
RNDIS_Initialize_Message_t InitMessage;
|
||||
RNDIS_Initialize_Complete_t InitMessageResponse;
|
||||
|
||||
InitMessage.MessageType = REMOTE_NDIS_INITIALIZE_MSG;
|
||||
InitMessage.MessageLength = sizeof(RNDIS_Initialize_Message_t);
|
||||
InitMessage.RequestId = RequestID++;
|
||||
|
||||
InitMessage.MajorVersion = REMOTE_NDIS_VERSION_MAJOR;
|
||||
InitMessage.MinorVersion = REMOTE_NDIS_VERSION_MINOR;
|
||||
InitMessage.MaxTransferSize = HostMaxPacketSize;
|
||||
|
||||
if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&InitMessage,
|
||||
sizeof(RNDIS_Initialize_Message_t))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&InitMessageResponse,
|
||||
sizeof(RNDIS_Initialize_Complete_t))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
if (InitMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
|
||||
return RNDIS_COMMAND_FAILED;
|
||||
|
||||
*DeviceMaxPacketSize = InitMessageResponse.MaxTransferSize;
|
||||
|
||||
return HOST_SENDCONTROL_Successful;
|
||||
}
|
||||
|
||||
/** Sets a given RNDIS property of an attached RNDIS device.
|
||||
*
|
||||
* \param[in] Oid OID number of the parameter to set
|
||||
* \param[in] Buffer Pointer to where the property data is to be sourced from
|
||||
* \param[in] Length Length in bytes of the property data to sent to the device
|
||||
*
|
||||
* \return A value from the USB_Host_SendControlErrorCodes_t enum or RNDIS_COMMAND_FAILED if the device returned a
|
||||
* logical command failure
|
||||
*/
|
||||
uint8_t RNDIS_SetRNDISProperty(const uint32_t Oid,
|
||||
void* Buffer,
|
||||
const uint16_t Length)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
struct
|
||||
{
|
||||
RNDIS_Set_Message_t SetMessage;
|
||||
uint8_t ContiguousBuffer[Length];
|
||||
} SetMessageData;
|
||||
|
||||
RNDIS_Set_Complete_t SetMessageResponse;
|
||||
|
||||
SetMessageData.SetMessage.MessageType = REMOTE_NDIS_SET_MSG;
|
||||
SetMessageData.SetMessage.MessageLength = sizeof(RNDIS_Set_Message_t) + Length;
|
||||
SetMessageData.SetMessage.RequestId = RequestID++;
|
||||
|
||||
SetMessageData.SetMessage.Oid = Oid;
|
||||
SetMessageData.SetMessage.InformationBufferLength = Length;
|
||||
SetMessageData.SetMessage.InformationBufferOffset = (sizeof(RNDIS_Set_Message_t) - sizeof(RNDIS_Message_Header_t));
|
||||
SetMessageData.SetMessage.DeviceVcHandle = 0;
|
||||
|
||||
memcpy(SetMessageData.ContiguousBuffer, Buffer, Length);
|
||||
|
||||
if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&SetMessageData,
|
||||
SetMessageData.SetMessage.MessageLength)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&SetMessageResponse,
|
||||
sizeof(RNDIS_Set_Complete_t))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
if (SetMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
|
||||
return RNDIS_COMMAND_FAILED;
|
||||
|
||||
return HOST_SENDCONTROL_Successful;
|
||||
}
|
||||
|
||||
/** Gets a given RNDIS property of an attached RNDIS device.
|
||||
*
|
||||
* \param[in] Oid OID number of the parameter to get
|
||||
* \param[in] Buffer Pointer to where the property data is to be written to
|
||||
* \param[in] MaxLength Length in bytes of the destination buffer size
|
||||
*
|
||||
* \return A value from the USB_Host_SendControlErrorCodes_t enum or RNDIS_COMMAND_FAILED if the device returned a
|
||||
* logical command failure
|
||||
*/
|
||||
uint8_t RNDIS_QueryRNDISProperty(const uint32_t Oid,
|
||||
void* Buffer,
|
||||
const uint16_t MaxLength)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
RNDIS_Query_Message_t QueryMessage;
|
||||
|
||||
struct
|
||||
{
|
||||
RNDIS_Query_Complete_t QueryMessageResponse;
|
||||
uint8_t ContiguousBuffer[MaxLength];
|
||||
} QueryMessageResponseData;
|
||||
|
||||
QueryMessage.MessageType = REMOTE_NDIS_QUERY_MSG;
|
||||
QueryMessage.MessageLength = sizeof(RNDIS_Query_Message_t);
|
||||
QueryMessage.RequestId = RequestID++;
|
||||
|
||||
QueryMessage.Oid = Oid;
|
||||
QueryMessage.InformationBufferLength = 0;
|
||||
QueryMessage.InformationBufferOffset = 0;
|
||||
QueryMessage.DeviceVcHandle = 0;
|
||||
|
||||
if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&QueryMessage,
|
||||
sizeof(RNDIS_Query_Message_t))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&QueryMessageResponseData,
|
||||
sizeof(QueryMessageResponseData))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
if (QueryMessageResponseData.QueryMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
|
||||
return RNDIS_COMMAND_FAILED;
|
||||
|
||||
memcpy(Buffer, &QueryMessageResponseData.ContiguousBuffer, MaxLength);
|
||||
|
||||
return HOST_SENDCONTROL_Successful;
|
||||
}
|
||||
|
||||
/** Retrieves the size of a received packet, discarding the remainder of the RNDIS packet header to leave only the
|
||||
* packet contents for processing by the host.
|
||||
*
|
||||
* \param[out] PacketLength Size of the packet currently in the pipe
|
||||
*
|
||||
* \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t RNDIS_GetPacketLength(uint16_t* const PacketLength)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
Pipe_SelectPipe(RNDIS_DATA_IN_PIPE);
|
||||
Pipe_SetPipeToken(PIPE_TOKEN_IN);
|
||||
Pipe_Unfreeze();
|
||||
|
||||
if (!(Pipe_IsReadWriteAllowed()))
|
||||
{
|
||||
*PacketLength = 0;
|
||||
Pipe_Freeze();
|
||||
return PIPE_RWSTREAM_NoError;
|
||||
}
|
||||
|
||||
RNDIS_Packet_Message_t DeviceMessage;
|
||||
|
||||
if ((ErrorCode = Pipe_Read_Stream_LE(&DeviceMessage, sizeof(RNDIS_Packet_Message_t), NULL)) != PIPE_RWSTREAM_NoError)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
*PacketLength = (uint16_t)DeviceMessage.DataLength;
|
||||
|
||||
Pipe_Discard_Stream(DeviceMessage.DataOffset - (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)),
|
||||
NULL);
|
||||
|
||||
Pipe_Freeze();
|
||||
|
||||
return PIPE_RWSTREAM_NoError;
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2017.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2017 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
|
||||
without fee, 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 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
|
||||
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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for RNDISCommands.c.
|
||||
*/
|
||||
|
||||
#ifndef _RNDIS_COMMANDS_H_
|
||||
#define _RNDIS_COMMANDS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "../RNDISEthernetHost.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Additional error code for RNDIS functions when a device returns a logical command failure. */
|
||||
#define RNDIS_COMMAND_FAILED 0xC0
|
||||
|
||||
/* Function Prototypes: */
|
||||
uint8_t RNDIS_SendEncapsulatedCommand(void* const Buffer,
|
||||
const uint16_t Length);
|
||||
uint8_t RNDIS_GetEncapsulatedResponse(void* const Buffer,
|
||||
const uint16_t Length);
|
||||
|
||||
uint8_t RNDIS_SendKeepAlive(void);
|
||||
uint8_t RNDIS_InitializeDevice(const uint16_t HostMaxPacketSize,
|
||||
uint16_t* const DeviceMaxPacketSize);
|
||||
uint8_t RNDIS_SetRNDISProperty(const uint32_t Oid,
|
||||
void* Buffer,
|
||||
const uint16_t Length);
|
||||
uint8_t RNDIS_QueryRNDISProperty(const uint32_t Oid,
|
||||
void* Buffer,
|
||||
const uint16_t MaxLength);
|
||||
uint8_t RNDIS_GetPacketLength(uint16_t* const PacketLength);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2017.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2017 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
|
||||
without fee, 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 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
|
||||
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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the RNDISEthernetHost demo. This file contains the main tasks of
|
||||
* the demo and is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "RNDISEthernetHost.h"
|
||||
|
||||
/** Main program entry point. This routine configures the hardware required by the application, then
|
||||
* enters a loop to run the application tasks in sequence.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
SetupHardware();
|
||||
|
||||
puts_P(PSTR(ESC_FG_CYAN "RNDIS Host Demo running.\r\n" ESC_FG_WHITE));
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
GlobalInterruptEnable();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
RNDISHost_Task();
|
||||
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
#endif
|
||||
|
||||
/* Hardware Initialization */
|
||||
Serial_Init(9600, false);
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
|
||||
/* Create a stdio stream for the serial port for stdin and stdout */
|
||||
Serial_CreateStream(NULL);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceAttached(void)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and
|
||||
* stops the library USB task management process.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceUnattached(void)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_GREEN "\r\nDevice Unattached.\r\n" ESC_FG_WHITE));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully
|
||||
* enumerated by the host and is now ready to be used by the application.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationComplete(void)
|
||||
{
|
||||
puts_P(PSTR("Getting Config Data.\r\n"));
|
||||
|
||||
uint8_t ErrorCode;
|
||||
|
||||
/* Get and process the configuration descriptor data */
|
||||
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
|
||||
{
|
||||
if (ErrorCode == ControlError)
|
||||
puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n"));
|
||||
else
|
||||
puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));
|
||||
|
||||
printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
|
||||
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"
|
||||
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t DeviceMaxPacketSize;
|
||||
if ((ErrorCode = RNDIS_InitializeDevice(1024, &DeviceMaxPacketSize)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Error Initializing Device.\r\n"
|
||||
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
USB_Host_SetDeviceConfiguration(0);
|
||||
return;
|
||||
}
|
||||
|
||||
printf_P(PSTR("Device Max Transfer Size: %lu bytes.\r\n"), DeviceMaxPacketSize);
|
||||
|
||||
/* We set the default filter to only receive packets we would be interested in */
|
||||
uint32_t PacketFilter = (REMOTE_NDIS_PACKET_DIRECTED | REMOTE_NDIS_PACKET_BROADCAST | REMOTE_NDIS_PACKET_ALL_MULTICAST);
|
||||
if ((ErrorCode = RNDIS_SetRNDISProperty(OID_GEN_CURRENT_PACKET_FILTER,
|
||||
&PacketFilter, sizeof(PacketFilter))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Error Setting Device Packet Filter.\r\n"
|
||||
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
USB_Host_SetDeviceConfiguration(0);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t VendorID;
|
||||
if ((ErrorCode = RNDIS_QueryRNDISProperty(OID_GEN_VENDOR_ID,
|
||||
&VendorID, sizeof(VendorID))) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Error Getting Vendor ID.\r\n"
|
||||
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
USB_Host_SetDeviceConfiguration(0);
|
||||
return;
|
||||
}
|
||||
|
||||
printf_P(PSTR("Device Vendor ID: 0x%08lX\r\n"), VendorID);
|
||||
|
||||
puts_P(PSTR("RNDIS Device Enumerated.\r\n"));
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */
|
||||
void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
|
||||
{
|
||||
USB_Disable();
|
||||
|
||||
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
|
||||
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while
|
||||
* enumerating an attached USB device.
|
||||
*/
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
|
||||
const uint8_t SubErrorCode)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
|
||||
" -- Error Code %d\r\n"
|
||||
" -- Sub Error Code %d\r\n"
|
||||
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Task to read in data received from the attached RNDIS device and print it to the serial port.
|
||||
*/
|
||||
void RNDISHost_Task(void)
|
||||
{
|
||||
if (USB_HostState != HOST_STATE_Configured)
|
||||
return;
|
||||
|
||||
uint8_t ErrorCode;
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||||
|
||||
uint16_t PacketLength;
|
||||
if ((ErrorCode = RNDIS_GetPacketLength(&PacketLength)) != HOST_SENDCONTROL_Successful)
|
||||
{
|
||||
printf_P(PSTR(ESC_FG_RED "Packet Reception Error.\r\n"
|
||||
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(PacketLength))
|
||||
return;
|
||||
|
||||
Pipe_Unfreeze();
|
||||
|
||||
printf_P(PSTR("***PACKET (Size %d)***\r\n"), PacketLength);
|
||||
|
||||
if (PacketLength > 1024)
|
||||
{
|
||||
puts_P(PSTR(ESC_FG_RED "Packet too large.\r\n" ESC_FG_WHITE));
|
||||
Pipe_Discard_Stream(PacketLength, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t PacketBuffer[PacketLength];
|
||||
|
||||
Pipe_Read_Stream_LE(&PacketBuffer, PacketLength, NULL);
|
||||
|
||||
for (uint16_t i = 0; i < PacketLength; i++)
|
||||
printf("0x%02x ", PacketBuffer[i]);
|
||||
}
|
||||
|
||||
Pipe_ClearIN();
|
||||
Pipe_Freeze();
|
||||
|
||||
printf("\r\n\r\n");
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2017.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2017 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
|
||||
without fee, 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 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
|
||||
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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for RNDISEthernetHost.c.
|
||||
*/
|
||||
|
||||
#ifndef _RNDIS_HOST_H_
|
||||
#define _RNDIS_HOST_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <LUFA/Drivers/Misc/TerminalCodes.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Peripheral/Serial.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.h>
|
||||
#include <LUFA/Platform/Platform.h>
|
||||
|
||||
#include "Lib/RNDISCommands.h"
|
||||
|
||||
#include "ConfigDescriptor.h"
|
||||
|
||||
/* Macros: */
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
|
||||
#define LEDMASK_USB_NOTREADY LEDS_LED1
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
|
||||
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
|
||||
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
|
||||
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
|
||||
|
||||
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
|
||||
#define LEDMASK_USB_BUSY LEDS_LED2
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void RNDISHost_Task(void);
|
||||
|
||||
void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
|
||||
void EVENT_USB_Host_DeviceAttached(void);
|
||||
void EVENT_USB_Host_DeviceUnattached(void);
|
||||
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
|
||||
const uint8_t SubErrorCode);
|
||||
void EVENT_USB_Host_DeviceEnumerationComplete(void);
|
||||
|
||||
#endif
|
||||
|
63
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/RNDISHost.txt
Normal file
63
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/RNDISHost.txt
Normal file
|
@ -0,0 +1,63 @@
|
|||
/** \file
|
||||
*
|
||||
* This file contains special DoxyGen information for the generation of the main page and other special
|
||||
* documentation pages. It is not a project source file.
|
||||
*/
|
||||
|
||||
/** \mainpage RNDIS Host Demo
|
||||
*
|
||||
* \section Sec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* \li Series 7 USB AVRs (AT90USBxxx7)
|
||||
*
|
||||
* \section Sec_Info USB Information:
|
||||
*
|
||||
* The following table gives a rundown of the USB utilization of this demo.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td><b>USB Mode:</b></td>
|
||||
* <td>Host</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Class:</b></td>
|
||||
* <td>Communications Device Class (CDC)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Subclass:</b></td>
|
||||
* <td>Remote NDIS (Microsoft Proprietary CDC Class Networking Standard)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Relevant Standards:</b></td>
|
||||
* <td>Microsoft RNDIS Specification</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Supported USB Speeds:</b></td>
|
||||
* <td>Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section Sec_Description Project Description:
|
||||
*
|
||||
* RNDIS host demonstration application. This gives a simple reference
|
||||
* application for implementing a RNDIS Ethernet host, for USB devices such as
|
||||
* modems.
|
||||
*
|
||||
* This demo will enumerate an attached USB RNDIS device, print out its vendor ID
|
||||
* and any received packets in raw form through the serial USART.
|
||||
*
|
||||
* \section Sec_Options Project Options
|
||||
*
|
||||
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>
|
||||
* None
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
|
53
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/asf.xml
Normal file
53
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/asf.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<asf xmlversion="1.0">
|
||||
<project caption="RNDIS Ethernet Host Demo (Low Level APIs)" id="lufa.demos.host.lowlevel.rndis.example.avr8">
|
||||
<require idref="lufa.demos.host.lowlevel.rndis"/>
|
||||
<require idref="lufa.boards.dummy.avr8"/>
|
||||
<generator value="as5_8"/>
|
||||
|
||||
<device-support value="at90usb1287"/>
|
||||
<config name="lufa.drivers.board.name" value="none"/>
|
||||
|
||||
<build type="define" name="F_CPU" value="16000000UL"/>
|
||||
<build type="define" name="F_USB" value="16000000UL"/>
|
||||
</project>
|
||||
|
||||
<module type="application" id="lufa.demos.host.lowlevel.rndis" caption="RNDIS Ethernet Host Demo (Low Level APIs)">
|
||||
<info type="description" value="summary">
|
||||
Microsoft RNDIS Ethernet Host demo, implementing a RNDIS host that can send and receive Ethernet data to and from an attached device. This demo uses the Low Level LUFA APIs to manually implement a USB Class for demonstration purposes without using the simpler in-built LUFA Class Driver APIs.
|
||||
</info>
|
||||
|
||||
<info type="gui-flag" value="move-to-root"/>
|
||||
|
||||
<info type="keyword" value="Technology">
|
||||
<keyword value="Low Level APIs"/>
|
||||
<keyword value="USB Host"/>
|
||||
<keyword value="RNDIS Class"/>
|
||||
</info>
|
||||
|
||||
<device-support-alias value="lufa_avr8"/>
|
||||
<device-support-alias value="lufa_xmega"/>
|
||||
<device-support-alias value="lufa_uc3"/>
|
||||
|
||||
<build type="distribute" subtype="user-file" value="doxyfile"/>
|
||||
<build type="distribute" subtype="user-file" value="RNDISHost.txt"/>
|
||||
|
||||
<build type="c-source" value="RNDISEthernetHost.c"/>
|
||||
<build type="c-source" value="ConfigDescriptor.c"/>
|
||||
<build type="header-file" value="RNDISEthernetHost.h"/>
|
||||
<build type="header-file" value="ConfigDescriptor.h"/>
|
||||
|
||||
<build type="c-source" value="Lib/RNDISCommands.c"/>
|
||||
<build type="header-file" value="Lib/RNDISCommands.h"/>
|
||||
|
||||
<build type="module-config" subtype="path" value="Config"/>
|
||||
<build type="header-file" value="Config/LUFAConfig.h"/>
|
||||
|
||||
<require idref="lufa.common"/>
|
||||
<require idref="lufa.platform"/>
|
||||
<require idref="lufa.drivers.usb"/>
|
||||
<require idref="lufa.drivers.peripheral.usart"/>
|
||||
<require idref="lufa.drivers.misc.ansi"/>
|
||||
<require idref="lufa.drivers.board"/>
|
||||
<require idref="lufa.drivers.board.leds"/>
|
||||
</module>
|
||||
</asf>
|
2395
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/doxyfile
Normal file
2395
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/doxyfile
Normal file
File diff suppressed because it is too large
Load diff
43
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/makefile
Normal file
43
lib/lufa/Demos/Host/LowLevel/RNDISEthernetHost/makefile
Normal file
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# LUFA Library
|
||||
# Copyright (C) Dean Camera, 2017.
|
||||
#
|
||||
# dean [at] fourwalledcubicle [dot] com
|
||||
# www.lufa-lib.org
|
||||
#
|
||||
# --------------------------------------
|
||||
# LUFA Project Makefile.
|
||||
# --------------------------------------
|
||||
|
||||
# Run "make help" for target help.
|
||||
|
||||
MCU = at90usb1287
|
||||
ARCH = AVR8
|
||||
BOARD = USBKEY
|
||||
F_CPU = 8000000
|
||||
F_USB = $(F_CPU)
|
||||
OPTIMIZATION = s
|
||||
TARGET = RNDISEthernetHost
|
||||
SRC = $(TARGET).c ConfigDescriptor.c Lib/RNDISCommands.c $(LUFA_SRC_USB) $(LUFA_SRC_SERIAL)
|
||||
LUFA_PATH = ../../../../LUFA
|
||||
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/
|
||||
LD_FLAGS =
|
||||
|
||||
# Default target
|
||||
all:
|
||||
|
||||
# Include LUFA-specific DMBS extension modules
|
||||
DMBS_LUFA_PATH ?= $(LUFA_PATH)/Build/LUFA
|
||||
include $(DMBS_LUFA_PATH)/lufa-sources.mk
|
||||
include $(DMBS_LUFA_PATH)/lufa-gcc.mk
|
||||
|
||||
# Include common DMBS build system modules
|
||||
DMBS_PATH ?= $(LUFA_PATH)/Build/DMBS/DMBS
|
||||
include $(DMBS_PATH)/core.mk
|
||||
include $(DMBS_PATH)/cppcheck.mk
|
||||
include $(DMBS_PATH)/doxygen.mk
|
||||
include $(DMBS_PATH)/dfu.mk
|
||||
include $(DMBS_PATH)/gcc.mk
|
||||
include $(DMBS_PATH)/hid.mk
|
||||
include $(DMBS_PATH)/avrdude.mk
|
||||
include $(DMBS_PATH)/atprogram.mk
|
Loading…
Add table
Add a link
Reference in a new issue