Add svn:eol-style property to source files, so that the line endings are correctly converted to the target system's native end of line style.
This commit is contained in:
parent
e331b531c6
commit
071e02c6b6
839 changed files with 274562 additions and 274562 deletions
|
|
@ -1,245 +1,245 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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;
|
||||
uint8_t FoundEndpoints = 0;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Get the CDC control interface from the configuration descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoRNDISInterfaceFound;
|
||||
}
|
||||
|
||||
/* Get the IN and OUT data and IN notification endpoints for the RNDIS interface */
|
||||
while (FoundEndpoints != ((1 << RNDIS_NOTIFICATIONPIPE) | (1 << RNDIS_DATAPIPE_IN) | (1 << RNDIS_DATAPIPE_OUT)))
|
||||
{
|
||||
/* Fetch the next bulk or interrupt endpoint from the current RNDIS interface */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Check to see if the control interface's notification pipe has been found, if so search for the data interface */
|
||||
if (FoundEndpoints & (1 << RNDIS_NOTIFICATIONPIPE))
|
||||
{
|
||||
/* Get the next CDC data interface from the configuration descriptor (RNDIS class has two CDC interfaces) */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoRNDISInterfaceFound;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear the found endpoints mask, since any already processed endpoints aren't in the CDC interface we need */
|
||||
FoundEndpoints = 0;
|
||||
|
||||
/* Disable any already configured pipes from the invalid RNDIS interfaces */
|
||||
Pipe_SelectPipe(RNDIS_NOTIFICATIONPIPE);
|
||||
Pipe_DisablePipe();
|
||||
Pipe_SelectPipe(RNDIS_DATAPIPE_IN);
|
||||
Pipe_DisablePipe();
|
||||
Pipe_SelectPipe(RNDIS_DATAPIPE_OUT);
|
||||
Pipe_DisablePipe();
|
||||
|
||||
/* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoRNDISInterfaceFound;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fetch the next bulk or interrupt endpoint from the current CDC interface */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoEndpointFound;
|
||||
}
|
||||
}
|
||||
|
||||
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
|
||||
|
||||
/* Check if the found endpoint is a interrupt or bulk type descriptor */
|
||||
if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT)
|
||||
{
|
||||
/* If the endpoint is a IN type interrupt endpoint */
|
||||
if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
|
||||
{
|
||||
/* Configure the notification pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_NOTIFICATIONPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS);
|
||||
|
||||
/* Set the flag indicating that the notification pipe has been found */
|
||||
FoundEndpoints |= (1 << RNDIS_NOTIFICATIONPIPE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check if the endpoint is a bulk IN or bulk OUT endpoint */
|
||||
if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
|
||||
{
|
||||
/* Configure the data IN pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
/* Set the flag indicating that the data IN pipe has been found */
|
||||
FoundEndpoints |= (1 << RNDIS_DATAPIPE_IN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Configure the data OUT pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
/* Set the flag indicating that the data OUT pipe has been found */
|
||||
FoundEndpoints |= (1 << RNDIS_DATAPIPE_OUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
/* Check the CDC descriptor class, subclass and protocol, break out if correct control interface found */
|
||||
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == CDC_CONTROL_CLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == CDC_CONTROL_SUBCLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == CDC_CONTROL_PROTOCOL))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
/* Check the CDC descriptor class, subclass and protocol, break out if correct data interface found */
|
||||
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == CDC_DATA_CLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == CDC_DATA_SUBCLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == CDC_DATA_PROTOCOL))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
|
||||
{
|
||||
uint8_t EndpointType = (DESCRIPTOR_CAST(CurrentDescriptor,
|
||||
USB_Descriptor_Endpoint_t).Attributes & EP_TYPE_MASK);
|
||||
|
||||
if ((EndpointType == EP_TYPE_BULK) || (EndpointType == EP_TYPE_INTERRUPT))
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Fail;
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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;
|
||||
uint8_t FoundEndpoints = 0;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Get the CDC control interface from the configuration descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoRNDISInterfaceFound;
|
||||
}
|
||||
|
||||
/* Get the IN and OUT data and IN notification endpoints for the RNDIS interface */
|
||||
while (FoundEndpoints != ((1 << RNDIS_NOTIFICATIONPIPE) | (1 << RNDIS_DATAPIPE_IN) | (1 << RNDIS_DATAPIPE_OUT)))
|
||||
{
|
||||
/* Fetch the next bulk or interrupt endpoint from the current RNDIS interface */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Check to see if the control interface's notification pipe has been found, if so search for the data interface */
|
||||
if (FoundEndpoints & (1 << RNDIS_NOTIFICATIONPIPE))
|
||||
{
|
||||
/* Get the next CDC data interface from the configuration descriptor (RNDIS class has two CDC interfaces) */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoRNDISInterfaceFound;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear the found endpoints mask, since any already processed endpoints aren't in the CDC interface we need */
|
||||
FoundEndpoints = 0;
|
||||
|
||||
/* Disable any already configured pipes from the invalid RNDIS interfaces */
|
||||
Pipe_SelectPipe(RNDIS_NOTIFICATIONPIPE);
|
||||
Pipe_DisablePipe();
|
||||
Pipe_SelectPipe(RNDIS_DATAPIPE_IN);
|
||||
Pipe_DisablePipe();
|
||||
Pipe_SelectPipe(RNDIS_DATAPIPE_OUT);
|
||||
Pipe_DisablePipe();
|
||||
|
||||
/* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoRNDISInterfaceFound;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fetch the next bulk or interrupt endpoint from the current CDC interface */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
/* Descriptor not found, error out */
|
||||
return NoEndpointFound;
|
||||
}
|
||||
}
|
||||
|
||||
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
|
||||
|
||||
/* Check if the found endpoint is a interrupt or bulk type descriptor */
|
||||
if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT)
|
||||
{
|
||||
/* If the endpoint is a IN type interrupt endpoint */
|
||||
if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
|
||||
{
|
||||
/* Configure the notification pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_NOTIFICATIONPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS);
|
||||
|
||||
/* Set the flag indicating that the notification pipe has been found */
|
||||
FoundEndpoints |= (1 << RNDIS_NOTIFICATIONPIPE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check if the endpoint is a bulk IN or bulk OUT endpoint */
|
||||
if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
|
||||
{
|
||||
/* Configure the data IN pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
/* Set the flag indicating that the data IN pipe has been found */
|
||||
FoundEndpoints |= (1 << RNDIS_DATAPIPE_IN);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Configure the data OUT pipe */
|
||||
Pipe_ConfigurePipe(RNDIS_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT,
|
||||
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
|
||||
|
||||
/* Set the flag indicating that the data OUT pipe has been found */
|
||||
FoundEndpoints |= (1 << RNDIS_DATAPIPE_OUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
/* Check the CDC descriptor class, subclass and protocol, break out if correct control interface found */
|
||||
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == CDC_CONTROL_CLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == CDC_CONTROL_SUBCLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == CDC_CONTROL_PROTOCOL))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
/* Check the CDC descriptor class, subclass and protocol, break out if correct data interface found */
|
||||
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == CDC_DATA_CLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == CDC_DATA_SUBCLASS) &&
|
||||
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == CDC_DATA_PROTOCOL))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
|
||||
{
|
||||
uint8_t EndpointType = (DESCRIPTOR_CAST(CurrentDescriptor,
|
||||
USB_Descriptor_Endpoint_t).Attributes & EP_TYPE_MASK);
|
||||
|
||||
if ((EndpointType == EP_TYPE_BULK) || (EndpointType == EP_TYPE_INTERRUPT))
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Fail;
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,82 +1,82 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for ConfigDescriptor.c.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIGDESCRIPTOR_H_
|
||||
#define _CONFIGDESCRIPTOR_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "RNDISEthernetHost.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Interface Class value for the CDC class */
|
||||
#define CDC_CONTROL_CLASS 0x02
|
||||
|
||||
/** Interface Class value for the CDC Communication Interface subclass */
|
||||
#define CDC_CONTROL_SUBCLASS 0x02
|
||||
|
||||
/** Interface Class value for the CDC RNDIS vendor specific protocol */
|
||||
#define CDC_CONTROL_PROTOCOL 0xFF
|
||||
|
||||
/** Interface Class value for the CDC data class */
|
||||
#define CDC_DATA_CLASS 0x0A
|
||||
|
||||
/** Interface Class value for the CDC data subclass */
|
||||
#define CDC_DATA_SUBCLASS 0x00
|
||||
|
||||
/** Interface Class value for the CDC data protocol */
|
||||
#define CDC_DATA_PROTOCOL 0x00
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the 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 */
|
||||
NoRNDISInterfaceFound = 4, /**< A compatible RNDIS interface was not found in the device's Configuration Descriptor */
|
||||
NoEndpointFound = 5, /**< Compatible RNDIS endpoints were not found in the device's RNDIS interface */
|
||||
};
|
||||
|
||||
/* 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
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for ConfigDescriptor.c.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIGDESCRIPTOR_H_
|
||||
#define _CONFIGDESCRIPTOR_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include "RNDISEthernetHost.h"
|
||||
|
||||
/* Macros: */
|
||||
/** Interface Class value for the CDC class */
|
||||
#define CDC_CONTROL_CLASS 0x02
|
||||
|
||||
/** Interface Class value for the CDC Communication Interface subclass */
|
||||
#define CDC_CONTROL_SUBCLASS 0x02
|
||||
|
||||
/** Interface Class value for the CDC RNDIS vendor specific protocol */
|
||||
#define CDC_CONTROL_PROTOCOL 0xFF
|
||||
|
||||
/** Interface Class value for the CDC data class */
|
||||
#define CDC_DATA_CLASS 0x0A
|
||||
|
||||
/** Interface Class value for the CDC data subclass */
|
||||
#define CDC_DATA_SUBCLASS 0x00
|
||||
|
||||
/** Interface Class value for the CDC data protocol */
|
||||
#define CDC_DATA_PROTOCOL 0x00
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the 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 */
|
||||
NoRNDISInterfaceFound = 4, /**< A compatible RNDIS interface was not found in the device's Configuration Descriptor */
|
||||
NoEndpointFound = 5, /**< Compatible RNDIS endpoints were not found in the device's RNDIS interface */
|
||||
};
|
||||
|
||||
/* 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
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,302 +1,302 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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 = 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 = 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 ContigiousBuffer[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.ContigiousBuffer, 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 ContigiousBuffer[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.ContigiousBuffer, 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_DATAPIPE_IN);
|
||||
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))) != 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)));
|
||||
|
||||
Pipe_Freeze();
|
||||
|
||||
return PIPE_RWSTREAM_NoError;
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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 = 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 = 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 ContigiousBuffer[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.ContigiousBuffer, 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 ContigiousBuffer[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.ContigiousBuffer, 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_DATAPIPE_IN);
|
||||
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))) != 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)));
|
||||
|
||||
Pipe_Freeze();
|
||||
|
||||
return PIPE_RWSTREAM_NoError;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,212 +1,212 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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 "RNDISConstants.h"
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a RNDIS message header, sent before RNDIS messages */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */
|
||||
uint32_t MessageLength; /**< Total length of the RNDIS message, in bytes */
|
||||
} RNDIS_Message_Header_t;
|
||||
|
||||
/** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t DataOffset;
|
||||
uint32_t DataLength;
|
||||
uint32_t OOBDataOffset;
|
||||
uint32_t OOBDataLength;
|
||||
uint32_t NumOOBDataElements;
|
||||
uint32_t PerPacketInfoOffset;
|
||||
uint32_t PerPacketInfoLength;
|
||||
uint32_t VcHandle;
|
||||
uint32_t Reserved;
|
||||
} RNDIS_Packet_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Initialize command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
|
||||
uint32_t MajorVersion;
|
||||
uint32_t MinorVersion;
|
||||
uint32_t MaxTransferSize;
|
||||
} RNDIS_Initialize_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Initialize complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
|
||||
uint32_t MajorVersion;
|
||||
uint32_t MinorVersion;
|
||||
uint32_t DeviceFlags;
|
||||
uint32_t Medium;
|
||||
uint32_t MaxPacketsPerTransfer;
|
||||
uint32_t MaxTransferSize;
|
||||
uint32_t PacketAlignmentFactor;
|
||||
uint32_t AFListOffset;
|
||||
uint32_t AFListSize;
|
||||
} RNDIS_Initialize_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Keepalive command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
} RNDIS_KeepAlive_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Keepalive complete message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
} RNDIS_KeepAlive_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Reset complete message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t Status;
|
||||
|
||||
uint32_t AddressingReset;
|
||||
} RNDIS_Reset_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Set command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
|
||||
uint32_t Oid;
|
||||
uint32_t InformationBufferLength;
|
||||
uint32_t InformationBufferOffset;
|
||||
uint32_t DeviceVcHandle;
|
||||
} RNDIS_Set_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Set complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
} RNDIS_Set_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Query command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
|
||||
uint32_t Oid;
|
||||
uint32_t InformationBufferLength;
|
||||
uint32_t InformationBufferOffset;
|
||||
uint32_t DeviceVcHandle;
|
||||
} RNDIS_Query_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Query complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
|
||||
uint32_t InformationBufferLength;
|
||||
uint32_t InformationBufferOffset;
|
||||
} RNDIS_Query_Complete_t;
|
||||
|
||||
/* Macros: */
|
||||
/** RNDIS request to issue a host-to-device NDIS command */
|
||||
#define REQ_SendEncapsulatedCommand 0x00
|
||||
|
||||
/** RNDIS request to issue a device-to-host NDIS response */
|
||||
#define REQ_GetEncapsulatedResponse 0x01
|
||||
|
||||
/** Implemented RNDIS Version Major */
|
||||
#define REMOTE_NDIS_VERSION_MAJOR 0x01
|
||||
|
||||
/** Implemented RNDIS Version Minor */
|
||||
#define REMOTE_NDIS_VERSION_MINOR 0x00
|
||||
|
||||
/** Pipe number for the RNDIS data IN pipe */
|
||||
#define RNDIS_DATAPIPE_IN 1
|
||||
|
||||
/** Pipe number for the RNDIS data OUT pipe */
|
||||
#define RNDIS_DATAPIPE_OUT 2
|
||||
|
||||
/** Pipe number for the RNDIS notification pipe */
|
||||
#define RNDIS_NOTIFICATIONPIPE 3
|
||||
|
||||
/** 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
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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 "RNDISConstants.h"
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a RNDIS message header, sent before RNDIS messages */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */
|
||||
uint32_t MessageLength; /**< Total length of the RNDIS message, in bytes */
|
||||
} RNDIS_Message_Header_t;
|
||||
|
||||
/** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t DataOffset;
|
||||
uint32_t DataLength;
|
||||
uint32_t OOBDataOffset;
|
||||
uint32_t OOBDataLength;
|
||||
uint32_t NumOOBDataElements;
|
||||
uint32_t PerPacketInfoOffset;
|
||||
uint32_t PerPacketInfoLength;
|
||||
uint32_t VcHandle;
|
||||
uint32_t Reserved;
|
||||
} RNDIS_Packet_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Initialize command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
|
||||
uint32_t MajorVersion;
|
||||
uint32_t MinorVersion;
|
||||
uint32_t MaxTransferSize;
|
||||
} RNDIS_Initialize_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Initialize complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
|
||||
uint32_t MajorVersion;
|
||||
uint32_t MinorVersion;
|
||||
uint32_t DeviceFlags;
|
||||
uint32_t Medium;
|
||||
uint32_t MaxPacketsPerTransfer;
|
||||
uint32_t MaxTransferSize;
|
||||
uint32_t PacketAlignmentFactor;
|
||||
uint32_t AFListOffset;
|
||||
uint32_t AFListSize;
|
||||
} RNDIS_Initialize_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Keepalive command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
} RNDIS_KeepAlive_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Keepalive complete message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
} RNDIS_KeepAlive_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Reset complete message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t Status;
|
||||
|
||||
uint32_t AddressingReset;
|
||||
} RNDIS_Reset_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Set command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
|
||||
uint32_t Oid;
|
||||
uint32_t InformationBufferLength;
|
||||
uint32_t InformationBufferOffset;
|
||||
uint32_t DeviceVcHandle;
|
||||
} RNDIS_Set_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Set complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
} RNDIS_Set_Complete_t;
|
||||
|
||||
/** Type define for a RNDIS Query command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
|
||||
uint32_t Oid;
|
||||
uint32_t InformationBufferLength;
|
||||
uint32_t InformationBufferOffset;
|
||||
uint32_t DeviceVcHandle;
|
||||
} RNDIS_Query_Message_t;
|
||||
|
||||
/** Type define for a RNDIS Query complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MessageType;
|
||||
uint32_t MessageLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Status;
|
||||
|
||||
uint32_t InformationBufferLength;
|
||||
uint32_t InformationBufferOffset;
|
||||
} RNDIS_Query_Complete_t;
|
||||
|
||||
/* Macros: */
|
||||
/** RNDIS request to issue a host-to-device NDIS command */
|
||||
#define REQ_SendEncapsulatedCommand 0x00
|
||||
|
||||
/** RNDIS request to issue a device-to-host NDIS response */
|
||||
#define REQ_GetEncapsulatedResponse 0x01
|
||||
|
||||
/** Implemented RNDIS Version Major */
|
||||
#define REMOTE_NDIS_VERSION_MAJOR 0x01
|
||||
|
||||
/** Implemented RNDIS Version Minor */
|
||||
#define REMOTE_NDIS_VERSION_MINOR 0x00
|
||||
|
||||
/** Pipe number for the RNDIS data IN pipe */
|
||||
#define RNDIS_DATAPIPE_IN 1
|
||||
|
||||
/** Pipe number for the RNDIS data OUT pipe */
|
||||
#define RNDIS_DATAPIPE_OUT 2
|
||||
|
||||
/** Pipe number for the RNDIS notification pipe */
|
||||
#define RNDIS_NOTIFICATIONPIPE 3
|
||||
|
||||
/** 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
|
||||
|
|
|
|||
|
|
@ -1,112 +1,112 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* RNDIS specification related constants. For more information on these
|
||||
* constants, please refer to the Microsoft RNDIS specification.
|
||||
*/
|
||||
|
||||
#ifndef _RNDIS_CONSTANTS_DEVICE_H_
|
||||
#define _RNDIS_CONSTANTS_DEVICE_H_
|
||||
|
||||
/* Macros: */
|
||||
#define REMOTE_NDIS_PACKET_MSG 0x00000001UL
|
||||
#define REMOTE_NDIS_INITIALIZE_MSG 0x00000002UL
|
||||
#define REMOTE_NDIS_HALT_MSG 0x00000003UL
|
||||
#define REMOTE_NDIS_QUERY_MSG 0x00000004UL
|
||||
#define REMOTE_NDIS_SET_MSG 0x00000005UL
|
||||
#define REMOTE_NDIS_RESET_MSG 0x00000006UL
|
||||
#define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007UL
|
||||
#define REMOTE_NDIS_KEEPALIVE_MSG 0x00000008UL
|
||||
|
||||
#define REMOTE_NDIS_INITIALIZE_CMPLT 0x80000002UL
|
||||
#define REMOTE_NDIS_QUERY_CMPLT 0x80000004UL
|
||||
#define REMOTE_NDIS_SET_CMPLT 0x80000005UL
|
||||
#define REMOTE_NDIS_RESET_CMPLT 0x80000006UL
|
||||
#define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008UL
|
||||
|
||||
#define REMOTE_NDIS_STATUS_SUCCESS 0x00000000UL
|
||||
#define REMOTE_NDIS_STATUS_FAILURE 0xC0000001UL
|
||||
#define REMOTE_NDIS_STATUS_INVALID_DATA 0xC0010015UL
|
||||
#define REMOTE_NDIS_STATUS_NOT_SUPPORTED 0xC00000BBUL
|
||||
#define REMOTE_NDIS_STATUS_MEDIA_CONNECT 0x4001000BUL
|
||||
#define REMOTE_NDIS_STATUS_MEDIA_DISCONNECT 0x4001000CUL
|
||||
|
||||
#define REMOTE_NDIS_MEDIA_STATE_CONNECTED 0x00000000UL
|
||||
#define REMOTE_NDIS_MEDIA_STATE_DISCONNECTED 0x00000001UL
|
||||
|
||||
#define REMOTE_NDIS_MEDIUM_802_3 0x00000000UL
|
||||
|
||||
#define REMOTE_NDIS_DF_CONNECTIONLESS 0x00000001UL
|
||||
#define REMOTE_NDIS_DF_CONNECTION_ORIENTED 0x00000002UL
|
||||
|
||||
#define REMOTE_NDIS_PACKET_DIRECTED 0x00000001UL
|
||||
#define REMOTE_NDIS_PACKET_MULTICAST 0x00000002UL
|
||||
#define REMOTE_NDIS_PACKET_ALL_MULTICAST 0x00000004UL
|
||||
#define REMOTE_NDIS_PACKET_BROADCAST 0x00000008UL
|
||||
#define REMOTE_NDIS_PACKET_SOURCE_ROUTING 0x00000010UL
|
||||
#define REMOTE_NDIS_PACKET_PROMISCUOUS 0x00000020UL
|
||||
#define REMOTE_NDIS_PACKET_SMT 0x00000040UL
|
||||
#define REMOTE_NDIS_PACKET_ALL_LOCAL 0x00000080UL
|
||||
#define REMOTE_NDIS_PACKET_GROUP 0x00001000UL
|
||||
#define REMOTE_NDIS_PACKET_ALL_FUNCTIONAL 0x00002000UL
|
||||
#define REMOTE_NDIS_PACKET_FUNCTIONAL 0x00004000UL
|
||||
#define REMOTE_NDIS_PACKET_MAC_FRAME 0x00008000UL
|
||||
|
||||
#define OID_GEN_SUPPORTED_LIST 0x00010101UL
|
||||
#define OID_GEN_HARDWARE_STATUS 0x00010102UL
|
||||
#define OID_GEN_MEDIA_SUPPORTED 0x00010103UL
|
||||
#define OID_GEN_MEDIA_IN_USE 0x00010104UL
|
||||
#define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106UL
|
||||
#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111UL
|
||||
#define OID_GEN_LINK_SPEED 0x00010107UL
|
||||
#define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010AUL
|
||||
#define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010BUL
|
||||
#define OID_GEN_VENDOR_ID 0x0001010CUL
|
||||
#define OID_GEN_VENDOR_DESCRIPTION 0x0001010DUL
|
||||
#define OID_GEN_CURRENT_PACKET_FILTER 0x0001010EUL
|
||||
#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111UL
|
||||
#define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114UL
|
||||
#define OID_GEN_PHYSICAL_MEDIUM 0x00010202UL
|
||||
#define OID_GEN_XMIT_OK 0x00020101UL
|
||||
#define OID_GEN_RCV_OK 0x00020102UL
|
||||
#define OID_GEN_XMIT_ERROR 0x00020103UL
|
||||
#define OID_GEN_RCV_ERROR 0x00020104UL
|
||||
#define OID_GEN_RCV_NO_BUFFER 0x00020105UL
|
||||
#define OID_802_3_PERMANENT_ADDRESS 0x01010101UL
|
||||
#define OID_802_3_CURRENT_ADDRESS 0x01010102UL
|
||||
#define OID_802_3_MULTICAST_LIST 0x01010103UL
|
||||
#define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104UL
|
||||
#define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101UL
|
||||
#define OID_802_3_XMIT_ONE_COLLISION 0x01020102UL
|
||||
#define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103UL
|
||||
|
||||
#endif
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* RNDIS specification related constants. For more information on these
|
||||
* constants, please refer to the Microsoft RNDIS specification.
|
||||
*/
|
||||
|
||||
#ifndef _RNDIS_CONSTANTS_DEVICE_H_
|
||||
#define _RNDIS_CONSTANTS_DEVICE_H_
|
||||
|
||||
/* Macros: */
|
||||
#define REMOTE_NDIS_PACKET_MSG 0x00000001UL
|
||||
#define REMOTE_NDIS_INITIALIZE_MSG 0x00000002UL
|
||||
#define REMOTE_NDIS_HALT_MSG 0x00000003UL
|
||||
#define REMOTE_NDIS_QUERY_MSG 0x00000004UL
|
||||
#define REMOTE_NDIS_SET_MSG 0x00000005UL
|
||||
#define REMOTE_NDIS_RESET_MSG 0x00000006UL
|
||||
#define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007UL
|
||||
#define REMOTE_NDIS_KEEPALIVE_MSG 0x00000008UL
|
||||
|
||||
#define REMOTE_NDIS_INITIALIZE_CMPLT 0x80000002UL
|
||||
#define REMOTE_NDIS_QUERY_CMPLT 0x80000004UL
|
||||
#define REMOTE_NDIS_SET_CMPLT 0x80000005UL
|
||||
#define REMOTE_NDIS_RESET_CMPLT 0x80000006UL
|
||||
#define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008UL
|
||||
|
||||
#define REMOTE_NDIS_STATUS_SUCCESS 0x00000000UL
|
||||
#define REMOTE_NDIS_STATUS_FAILURE 0xC0000001UL
|
||||
#define REMOTE_NDIS_STATUS_INVALID_DATA 0xC0010015UL
|
||||
#define REMOTE_NDIS_STATUS_NOT_SUPPORTED 0xC00000BBUL
|
||||
#define REMOTE_NDIS_STATUS_MEDIA_CONNECT 0x4001000BUL
|
||||
#define REMOTE_NDIS_STATUS_MEDIA_DISCONNECT 0x4001000CUL
|
||||
|
||||
#define REMOTE_NDIS_MEDIA_STATE_CONNECTED 0x00000000UL
|
||||
#define REMOTE_NDIS_MEDIA_STATE_DISCONNECTED 0x00000001UL
|
||||
|
||||
#define REMOTE_NDIS_MEDIUM_802_3 0x00000000UL
|
||||
|
||||
#define REMOTE_NDIS_DF_CONNECTIONLESS 0x00000001UL
|
||||
#define REMOTE_NDIS_DF_CONNECTION_ORIENTED 0x00000002UL
|
||||
|
||||
#define REMOTE_NDIS_PACKET_DIRECTED 0x00000001UL
|
||||
#define REMOTE_NDIS_PACKET_MULTICAST 0x00000002UL
|
||||
#define REMOTE_NDIS_PACKET_ALL_MULTICAST 0x00000004UL
|
||||
#define REMOTE_NDIS_PACKET_BROADCAST 0x00000008UL
|
||||
#define REMOTE_NDIS_PACKET_SOURCE_ROUTING 0x00000010UL
|
||||
#define REMOTE_NDIS_PACKET_PROMISCUOUS 0x00000020UL
|
||||
#define REMOTE_NDIS_PACKET_SMT 0x00000040UL
|
||||
#define REMOTE_NDIS_PACKET_ALL_LOCAL 0x00000080UL
|
||||
#define REMOTE_NDIS_PACKET_GROUP 0x00001000UL
|
||||
#define REMOTE_NDIS_PACKET_ALL_FUNCTIONAL 0x00002000UL
|
||||
#define REMOTE_NDIS_PACKET_FUNCTIONAL 0x00004000UL
|
||||
#define REMOTE_NDIS_PACKET_MAC_FRAME 0x00008000UL
|
||||
|
||||
#define OID_GEN_SUPPORTED_LIST 0x00010101UL
|
||||
#define OID_GEN_HARDWARE_STATUS 0x00010102UL
|
||||
#define OID_GEN_MEDIA_SUPPORTED 0x00010103UL
|
||||
#define OID_GEN_MEDIA_IN_USE 0x00010104UL
|
||||
#define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106UL
|
||||
#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111UL
|
||||
#define OID_GEN_LINK_SPEED 0x00010107UL
|
||||
#define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010AUL
|
||||
#define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010BUL
|
||||
#define OID_GEN_VENDOR_ID 0x0001010CUL
|
||||
#define OID_GEN_VENDOR_DESCRIPTION 0x0001010DUL
|
||||
#define OID_GEN_CURRENT_PACKET_FILTER 0x0001010EUL
|
||||
#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111UL
|
||||
#define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114UL
|
||||
#define OID_GEN_PHYSICAL_MEDIUM 0x00010202UL
|
||||
#define OID_GEN_XMIT_OK 0x00020101UL
|
||||
#define OID_GEN_RCV_OK 0x00020102UL
|
||||
#define OID_GEN_XMIT_ERROR 0x00020103UL
|
||||
#define OID_GEN_RCV_ERROR 0x00020104UL
|
||||
#define OID_GEN_RCV_NO_BUFFER 0x00020105UL
|
||||
#define OID_802_3_PERMANENT_ADDRESS 0x01010101UL
|
||||
#define OID_802_3_CURRENT_ADDRESS 0x01010102UL
|
||||
#define OID_802_3_MULTICAST_LIST 0x01010103UL
|
||||
#define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104UL
|
||||
#define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101UL
|
||||
#define OID_802_3_XMIT_ONE_COLLISION 0x01020102UL
|
||||
#define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103UL
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,272 +1,272 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
RNDIS_Host_Task();
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
SerialStream_Init(9600, false);
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
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_ShutDown();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void PrintIncomingPackets(void)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t PacketBuffer[PacketLength];
|
||||
|
||||
Pipe_Read_Stream_LE(&PacketBuffer, PacketLength);
|
||||
|
||||
for (uint16_t i = 0; i < PacketLength; i++)
|
||||
printf("%02x ", PacketBuffer[i]);
|
||||
}
|
||||
|
||||
Pipe_ClearIN();
|
||||
Pipe_Freeze();
|
||||
|
||||
printf("\r\n\r\n");
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** Task to set the configuration of the attached device after it has been enumerated, and to read in
|
||||
* data received from the attached RNDIS device and print it to the serial port.
|
||||
*/
|
||||
void RNDIS_Host_Task(void)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
switch (USB_HostState)
|
||||
{
|
||||
case HOST_STATE_Addressed:
|
||||
puts_P(PSTR("Getting Config Data.\r\n"));
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
printf_P(PSTR("Device Vendor ID: 0x%08lX\r\n"), VendorID);
|
||||
|
||||
puts_P(PSTR("RNDIS Device Enumerated.\r\n"));
|
||||
|
||||
USB_HostState = HOST_STATE_Configured;
|
||||
break;
|
||||
case HOST_STATE_Configured:
|
||||
PrintIncomingPackets();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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);
|
||||
sei();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
RNDIS_Host_Task();
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
/* Hardware Initialization */
|
||||
SerialStream_Init(9600, false);
|
||||
LEDs_Init();
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
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_ShutDown();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void PrintIncomingPackets(void)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t PacketBuffer[PacketLength];
|
||||
|
||||
Pipe_Read_Stream_LE(&PacketBuffer, PacketLength);
|
||||
|
||||
for (uint16_t i = 0; i < PacketLength; i++)
|
||||
printf("%02x ", PacketBuffer[i]);
|
||||
}
|
||||
|
||||
Pipe_ClearIN();
|
||||
Pipe_Freeze();
|
||||
|
||||
printf("\r\n\r\n");
|
||||
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||
}
|
||||
|
||||
/** Task to set the configuration of the attached device after it has been enumerated, and to read in
|
||||
* data received from the attached RNDIS device and print it to the serial port.
|
||||
*/
|
||||
void RNDIS_Host_Task(void)
|
||||
{
|
||||
uint8_t ErrorCode;
|
||||
|
||||
switch (USB_HostState)
|
||||
{
|
||||
case HOST_STATE_Addressed:
|
||||
puts_P(PSTR("Getting Config Data.\r\n"));
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Indicate error via status LEDs */
|
||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||
|
||||
/* Wait until USB device disconnected */
|
||||
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
||||
break;
|
||||
}
|
||||
|
||||
printf_P(PSTR("Device Vendor ID: 0x%08lX\r\n"), VendorID);
|
||||
|
||||
puts_P(PSTR("RNDIS Device Enumerated.\r\n"));
|
||||
|
||||
USB_HostState = HOST_STATE_Configured;
|
||||
break;
|
||||
case HOST_STATE_Configured:
|
||||
PrintIncomingPackets();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,97 +1,97 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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/Version.h>
|
||||
#include <LUFA/Drivers/Misc/TerminalCodes.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Peripheral/SerialStream.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.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
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a RNDIS notification message, for transmission to the RNDIS host via the notification
|
||||
* Endpoint.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bmRequestType; /**< Notification type, a mask of values from SrdRequestType.h */
|
||||
uint8_t bNotification; /**< Notification index, indicating what the RNDIS notification relates to */
|
||||
uint16_t wValue; /**< Two byte notification value parameter */
|
||||
uint16_t wIndex; /**< Two byte notification index parameter */
|
||||
uint16_t wLength; /**< Size of data payload following the notification header */
|
||||
} USB_Notification_t;
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void PrintIncomingPackets(void);
|
||||
void RNDIS_Host_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
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 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.
|
||||
*/
|
||||
|
||||
/** \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/Version.h>
|
||||
#include <LUFA/Drivers/Misc/TerminalCodes.h>
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Drivers/Peripheral/SerialStream.h>
|
||||
#include <LUFA/Drivers/Board/LEDs.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
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a RNDIS notification message, for transmission to the RNDIS host via the notification
|
||||
* Endpoint.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bmRequestType; /**< Notification type, a mask of values from SrdRequestType.h */
|
||||
uint8_t bNotification; /**< Notification index, indicating what the RNDIS notification relates to */
|
||||
uint16_t wValue; /**< Two byte notification value parameter */
|
||||
uint16_t wIndex; /**< Two byte notification index parameter */
|
||||
uint16_t wLength; /**< Size of data payload following the notification header */
|
||||
} USB_Notification_t;
|
||||
|
||||
/* Function Prototypes: */
|
||||
void SetupHardware(void);
|
||||
void PrintIncomingPackets(void);
|
||||
void RNDIS_Host_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
|
||||
|
|
|
|||
|
|
@ -1,62 +1,62 @@
|
|||
/** \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 SSec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 USB AVRs
|
||||
*
|
||||
* \section SSec_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>Usable Speeds:</b></td>
|
||||
* <td>Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section SSec_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 SSec_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>
|
||||
/** \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 SSec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* - Series 7 USB AVRs
|
||||
*
|
||||
* \section SSec_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>Usable Speeds:</b></td>
|
||||
* <td>Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section SSec_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 SSec_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>
|
||||
*/
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue