More endianness porting of the LUFA device mode class drivers.

Add endianness information to the class driver and core structure definitions.

Move out the unused Ethernet_Frame_Info_t structure definition to the RNDIS device demos where it is needed.
pull/1469/head
Dean Camera 13 years ago
parent 7c7778e3ce
commit 85e85befc4

@ -59,7 +59,7 @@ const IP_Address_t ClientIPAddress = {CLIENT_IP_ADDRESS};
void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* const FrameIN, void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* const FrameIN,
Ethernet_Frame_Info_t* const FrameOUT) Ethernet_Frame_Info_t* const FrameOUT)
{ {
DecodeEthernetFrameHeader(FrameIN); DecodeEthernetFrameHeader(FrameIN->FrameData);
/* Cast the incoming Ethernet frame to the Ethernet header type */ /* Cast the incoming Ethernet frame to the Ethernet header type */
Ethernet_Frame_Header_t* FrameINHeader = (Ethernet_Frame_Header_t*)&FrameIN->FrameData; Ethernet_Frame_Header_t* FrameINHeader = (Ethernet_Frame_Header_t*)&FrameIN->FrameData;

@ -37,6 +37,9 @@
#ifndef _ETHERNET_PROTOCOLS_H_ #ifndef _ETHERNET_PROTOCOLS_H_
#define _ETHERNET_PROTOCOLS_H_ #define _ETHERNET_PROTOCOLS_H_
/* Includes: */
#include <LUFA/Drivers/USB/Class/RNDIS.h>
/* Macros: */ /* Macros: */
#define ETHERTYPE_IPV4 0x0800 #define ETHERTYPE_IPV4 0x0800
#define ETHERTYPE_ARP 0x0806 #define ETHERTYPE_ARP 0x0806
@ -72,6 +75,13 @@
#define PROTOCOL_SCTP 132 #define PROTOCOL_SCTP 132
/* Type Defines: */ /* Type Defines: */
/** Type define for an Ethernet frame buffer data and information structure. */
typedef struct
{
uint8_t FrameData[ETHERNET_FRAME_SIZE_MAX]; /**< Ethernet frame contents. */
uint16_t FrameLength; /**< Length in bytes of the Ethernet frame stored in the buffer. */
} Ethernet_Frame_Info_t;
/** Type define for a protocol IP address of a device on a network. */ /** Type define for a protocol IP address of a device on a network. */
typedef struct typedef struct
{ {

@ -51,12 +51,12 @@
/** Decodes an Ethernet frame header and prints its contents to through the USART in a human readable format. /** Decodes an Ethernet frame header and prints its contents to through the USART in a human readable format.
* *
* \param[in] FrameINData Pointer to the start of an Ethernet frame information structure * \param[in] FrameINData Pointer to the start of an Ethernet frame data
*/ */
void DecodeEthernetFrameHeader(Ethernet_Frame_Info_t* const FrameINData) void DecodeEthernetFrameHeader(void* InDataStart)
{ {
#if !defined(NO_DECODE_ETHERNET) #if !defined(NO_DECODE_ETHERNET)
Ethernet_Frame_Header_t* FrameHeader = (Ethernet_Frame_Header_t*)FrameINData->FrameData; Ethernet_Frame_Header_t* FrameHeader = (Ethernet_Frame_Header_t*)InDataStart;
printf_P(PSTR("\r\n")); printf_P(PSTR("\r\n"));
@ -84,10 +84,7 @@ void DecodeEthernetFrameHeader(Ethernet_Frame_Info_t* const FrameINData)
FrameHeader->Destination.Octets[4], FrameHeader->Destination.Octets[4],
FrameHeader->Destination.Octets[5]); FrameHeader->Destination.Octets[5]);
if (SwapEndian_16(FrameINData->FrameLength) > ETHERNET_VER2_MINSIZE) printf_P(PSTR(" + Protocol: 0x%04x\r\n"), SwapEndian_16(FrameHeader->EtherType));
printf_P(PSTR(" + Protocol: 0x%04x\r\n"), SwapEndian_16(FrameHeader->EtherType));
else
printf_P(PSTR(" + Protocol: UNKNOWN E1\r\n"));
#endif #endif
} }

@ -47,7 +47,7 @@
#include "Ethernet.h" #include "Ethernet.h"
/* Function Prototypes: */ /* Function Prototypes: */
void DecodeEthernetFrameHeader(Ethernet_Frame_Info_t* const FrameINData); void DecodeEthernetFrameHeader(void* InDataStart);
void DecodeARPHeader(void* InDataStart); void DecodeARPHeader(void* InDataStart);
void DecodeIPHeader(void* InDataStart); void DecodeIPHeader(void* InDataStart);
void DecodeICMPHeader(void* InDataStart); void DecodeICMPHeader(void* InDataStart);

@ -81,6 +81,13 @@
#define NO_PROCESS -1 #define NO_PROCESS -1
/* Type Defines: */ /* Type Defines: */
/** Type define for an Ethernet frame buffer data and information structure. */
typedef struct
{
uint8_t FrameData[ETHERNET_FRAME_SIZE_MAX]; /**< Ethernet frame contents. */
uint16_t FrameLength; /**< Length in bytes of the Ethernet frame stored in the buffer. */
} Ethernet_Frame_Info_t;
/** Type define for an Ethernet frame header. */ /** Type define for an Ethernet frame header. */
typedef struct typedef struct
{ {

@ -84,10 +84,7 @@ void DecodeEthernetFrameHeader(void* InDataStart)
FrameHeader->Destination.Octets[4], FrameHeader->Destination.Octets[4],
FrameHeader->Destination.Octets[5]); FrameHeader->Destination.Octets[5]);
if (SwapEndian_16(FrameIN.FrameLength) > ETHERNET_VER2_MINSIZE) printf_P(PSTR(" + Protocol: 0x%04x\r\n"), SwapEndian_16(FrameHeader->EtherType));
printf_P(PSTR(" + Protocol: 0x%04x\r\n"), SwapEndian_16(FrameHeader->EtherType));
else
printf_P(PSTR(" + Protocol: UNKNOWN E1\r\n"));
#endif #endif
} }

@ -305,6 +305,8 @@
* a USB endpoint). See the USB Audio specification for more details. * a USB endpoint). See the USB Audio specification for more details.
* *
* \see \ref USB_Audio_StdDescriptor_InputTerminal_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_InputTerminal_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -333,6 +335,8 @@
* *
* \see \ref USB_Audio_Descriptor_InputTerminal_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_InputTerminal_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -363,6 +367,8 @@
* a USB endpoint). See the USB Audio specification for more details. * a USB endpoint). See the USB Audio specification for more details.
* *
* \see \ref USB_Audio_StdDescriptor_OutputTerminal_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_OutputTerminal_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -389,6 +395,8 @@
* *
* \see \ref USB_Audio_Descriptor_OutputTerminal_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_OutputTerminal_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -417,6 +425,8 @@
* details. * details.
* *
* \see \ref USB_Audio_StdDescriptor_Interface_AC_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_Interface_AC_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -440,6 +450,8 @@
* *
* \see \ref USB_Audio_Descriptor_Interface_AC_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_Interface_AC_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -466,6 +478,8 @@
* specification for more details. * specification for more details.
* *
* \see \ref USB_Audio_StdDescriptor_FeatureUnit_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_FeatureUnit_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -491,6 +505,8 @@
* *
* \see \ref USB_Audio_Descriptor_FeatureUnit_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_FeatureUnit_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -518,6 +534,8 @@
* how audio streams within the device are formatted. See the USB Audio specification for more details. * how audio streams within the device are formatted. See the USB Audio specification for more details.
* *
* \see \ref USB_Audio_StdDescriptor_Interface_AS_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_Interface_AS_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -539,6 +557,8 @@
* *
* \see \ref USB_Audio_Descriptor_Interface_AS_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_Interface_AS_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -567,6 +587,8 @@
* the continuous or discrete sample frequencies. * the continuous or discrete sample frequencies.
* *
* \see \ref USB_Audio_StdDescriptor_Format_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_Format_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -592,6 +614,8 @@
* *
* Type define for a 24bit audio sample frequency structure. As GCC does not contain a built in 24-bit datatype, * Type define for a 24bit audio sample frequency structure. As GCC does not contain a built in 24-bit datatype,
* this this structure is used to build up the value instead. Fill this structure with the \ref AUDIO_SAMPLE_FREQ() macro. * this this structure is used to build up the value instead. Fill this structure with the \ref AUDIO_SAMPLE_FREQ() macro.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -611,6 +635,8 @@
* *
* \see \ref USB_Audio_Descriptor_Format_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_Format_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -642,6 +668,8 @@
* descriptor with a few Audio-class-specific extensions. See the USB Audio specification for more details. * descriptor with a few Audio-class-specific extensions. See the USB Audio specification for more details.
* *
* \see \ref USB_Audio_StdDescriptor_StreamEndpoint_Std_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_StreamEndpoint_Std_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -658,6 +686,8 @@
* *
* \see \ref USB_Audio_Descriptor_StreamEndpoint_Std_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_StreamEndpoint_Std_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -689,6 +719,8 @@
* class-specific extended endpoint descriptor. See the USB Audio specification for more details. * class-specific extended endpoint descriptor. See the USB Audio specification for more details.
* *
* \see \ref USB_Audio_StdDescriptor_StreamEndpoint_Spc_t for the version of this type with standard element names. * \see \ref USB_Audio_StdDescriptor_StreamEndpoint_Spc_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -711,6 +743,8 @@
* *
* \see \ref USB_Audio_Descriptor_StreamEndpoint_Spc_t for the version of this type with non-standard LUFA specific * \see \ref USB_Audio_Descriptor_StreamEndpoint_Spc_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -231,6 +231,8 @@
* See the CDC class specification for more details. * See the CDC class specification for more details.
* *
* \see \ref USB_CDC_StdDescriptor_FunctionalHeader_t for the version of this type with standard element names. * \see \ref USB_CDC_StdDescriptor_FunctionalHeader_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -251,6 +253,8 @@
* *
* \see \ref USB_CDC_Descriptor_FunctionalHeader_t for the version of this type with non-standard LUFA specific * \see \ref USB_CDC_Descriptor_FunctionalHeader_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -270,6 +274,8 @@
* supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details. * supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details.
* *
* \see \ref USB_CDC_StdDescriptor_FunctionalACM_t for the version of this type with standard element names. * \see \ref USB_CDC_StdDescriptor_FunctionalACM_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -290,6 +296,8 @@
* *
* \see \ref USB_CDC_Descriptor_FunctionalACM_t for the version of this type with non-standard LUFA specific * \see \ref USB_CDC_Descriptor_FunctionalACM_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -312,6 +320,8 @@
* CDC control and data interfaces are related. See the CDC class specification for more details. * CDC control and data interfaces are related. See the CDC class specification for more details.
* *
* \see \ref USB_CDC_StdDescriptor_FunctionalUnion_t for the version of this type with standard element names. * \see \ref USB_CDC_StdDescriptor_FunctionalUnion_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -330,6 +340,8 @@
* *
* \see \ref USB_CDC_Descriptor_FunctionalUnion_t for the version of this type with non-standard LUFA specific * \see \ref USB_CDC_Descriptor_FunctionalUnion_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -348,6 +360,8 @@
* *
* Type define for a CDC Line Encoding structure, used to hold the various encoding parameters for a virtual * Type define for a CDC Line Encoding structure, used to hold the various encoding parameters for a virtual
* serial port. * serial port.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -574,6 +574,8 @@
* specification for details on the structure elements. * specification for details on the structure elements.
* *
* \see \ref USB_HID_StdDescriptor_HID_t for the version of this type with standard element names. * \see \ref USB_HID_StdDescriptor_HID_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -595,6 +597,8 @@
* *
* \see \ref USB_HID_Descriptor_HID_t for the version of this type with non-standard LUFA specific * \see \ref USB_HID_Descriptor_HID_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -103,6 +103,8 @@
* See the USB Audio specification for more details. * See the USB Audio specification for more details.
* *
* \see \ref USB_MIDI_StdDescriptor_AudioInterface_AS_t for the version of this type with standard element names. * \see \ref USB_MIDI_StdDescriptor_AudioInterface_AS_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -123,6 +125,8 @@
* *
* \see \ref USB_MIDI_Descriptor_AudioInterface_AS_t for the version of this type with non-standard LUFA specific * \see \ref USB_MIDI_Descriptor_AudioInterface_AS_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -143,6 +147,8 @@
* a physical input jack, or a logical jack (receiving input data internally, or from the host via an endpoint). * a physical input jack, or a logical jack (receiving input data internally, or from the host via an endpoint).
* *
* \see \ref USB_MIDI_StdDescriptor_InputJack_t for the version of this type with standard element names. * \see \ref USB_MIDI_StdDescriptor_InputJack_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -162,6 +168,8 @@
* *
* \see \ref USB_MIDI_Descriptor_InputJack_t for the version of this type with non-standard LUFA specific * \see \ref USB_MIDI_Descriptor_InputJack_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -184,6 +192,8 @@
* a physical output jack, or a logical jack (sending output data internally, or to the host via an endpoint). * a physical output jack, or a logical jack (sending output data internally, or to the host via an endpoint).
* *
* \see \ref USB_MIDI_StdDescriptor_OutputJack_t for the version of this type with standard element names. * \see \ref USB_MIDI_StdDescriptor_OutputJack_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -207,6 +217,8 @@
* *
* \see \ref USB_MIDI_Descriptor_OutputJack_t for the version of this type with non-standard LUFA specific * \see \ref USB_MIDI_Descriptor_OutputJack_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -234,6 +246,8 @@
* class-specific extended MIDI endpoint descriptor. See the USB Audio specification for more details. * class-specific extended MIDI endpoint descriptor. See the USB Audio specification for more details.
* *
* \see \ref USB_MIDI_StdDescriptor_Jack_Endpoint_t for the version of this type with standard element names. * \see \ref USB_MIDI_StdDescriptor_Jack_Endpoint_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -252,6 +266,8 @@
* *
* \see \ref USB_MIDI_Descriptor_Jack_Endpoint_t for the version of this type with non-standard LUFA specific * \see \ref USB_MIDI_Descriptor_Jack_Endpoint_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -269,6 +285,8 @@
/** \brief MIDI Class Driver Event Packet. /** \brief MIDI Class Driver Event Packet.
* *
* Type define for a USB MIDI event packet, used to encapsulate sent and received MIDI messages from a USB MIDI interface. * Type define for a USB MIDI event packet, used to encapsulate sent and received MIDI messages from a USB MIDI interface.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -256,7 +256,10 @@
/* Type Defines: */ /* Type Defines: */
/** \brief Mass Storage Class Command Block Wrapper. /** \brief Mass Storage Class Command Block Wrapper.
* *
* Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */ * Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct typedef struct
{ {
uint32_t Signature; /**< Command block signature, must be \ref MS_CBW_SIGNATURE to indicate a valid Command Block. */ uint32_t Signature; /**< Command block signature, must be \ref MS_CBW_SIGNATURE to indicate a valid Command Block. */
@ -271,6 +274,8 @@
/** \brief Mass Storage Class Command Status Wrapper. /** \brief Mass Storage Class Command Status Wrapper.
* *
* Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol. * Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -208,17 +208,6 @@
}; };
/* Type Defines: */ /* Type Defines: */
/** \brief Ethernet Frame Packet Information Structure.
*
* Type define for an Ethernet frame buffer data and information structure. This can be used to conveniently
* store both the size and data in an Ethernet frame.
*/
typedef struct
{
uint8_t FrameData[ETHERNET_FRAME_SIZE_MAX]; /**< Ethernet frame contents. */
uint16_t FrameLength; /**< Length in bytes of the Ethernet frame stored in the buffer. */
} Ethernet_Frame_Info_t;
/** \brief MAC Address Structure. /** \brief MAC Address Structure.
* *
* Type define for a physical MAC address of a device on a network. * Type define for a physical MAC address of a device on a network.
@ -231,6 +220,8 @@
/** \brief RNDIS Common Message Header Structure. /** \brief RNDIS Common Message Header Structure.
* *
* Type define for a RNDIS message header, sent before RNDIS messages. * Type define for a RNDIS message header, sent before RNDIS messages.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -241,6 +232,8 @@
/** \brief RNDIS Message Structure. /** \brief RNDIS Message Structure.
* *
* Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter. * Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -260,6 +253,8 @@
/** \brief RNDIS Initialization Message Structure. /** \brief RNDIS Initialization Message Structure.
* *
* Type define for a RNDIS Initialize command message. * Type define for a RNDIS Initialize command message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -275,6 +270,8 @@
/** \brief RNDIS Initialize Complete Message Structure. /** \brief RNDIS Initialize Complete Message Structure.
* *
* Type define for a RNDIS Initialize Complete response message. * Type define for a RNDIS Initialize Complete response message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -297,6 +294,8 @@
/** \brief RNDIS Keep Alive Message Structure. /** \brief RNDIS Keep Alive Message Structure.
* *
* Type define for a RNDIS Keep Alive command message. * Type define for a RNDIS Keep Alive command message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -308,6 +307,8 @@
/** \brief RNDIS Keep Alive Complete Message Structure. /** \brief RNDIS Keep Alive Complete Message Structure.
* *
* Type define for a RNDIS Keep Alive Complete response message. * Type define for a RNDIS Keep Alive Complete response message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -320,6 +321,8 @@
/** \brief RNDIS Reset Complete Message Structure. /** \brief RNDIS Reset Complete Message Structure.
* *
* Type define for a RNDIS Reset Complete response message. * Type define for a RNDIS Reset Complete response message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -333,6 +336,8 @@
/** \brief RNDIS OID Property Set Message Structure. /** \brief RNDIS OID Property Set Message Structure.
* *
* Type define for a RNDIS OID Property Set command message. * Type define for a RNDIS OID Property Set command message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -349,6 +354,8 @@
/** \brief RNDIS OID Property Set Complete Message Structure. /** \brief RNDIS OID Property Set Complete Message Structure.
* *
* Type define for a RNDIS OID Property Set Complete response message. * Type define for a RNDIS OID Property Set Complete response message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -361,6 +368,8 @@
/** \brief RNDIS OID Property Query Message Structure. /** \brief RNDIS OID Property Query Message Structure.
* *
* Type define for a RNDIS OID Property Query command message. * Type define for a RNDIS OID Property Query command message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -377,6 +386,8 @@
/** \brief RNDIS OID Property Query Complete Message Structure. /** \brief RNDIS OID Property Query Complete Message Structure.
* *
* Type define for a RNDIS OID Property Query Complete response message. * Type define for a RNDIS OID Property Query Complete response message.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -138,6 +138,8 @@
* *
* Type define for a PIMA container, use to send commands and receive responses to and from an * Type define for a PIMA container, use to send commands and receive responses to and from an
* attached Still Image device. * attached Still Image device.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -276,9 +276,9 @@ void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDC
{ {
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = CDC_NOTIF_SerialState, .bRequest = CDC_NOTIF_SerialState,
.wValue = 0, .wValue = CPU_TO_LE16(0),
.wIndex = 0, .wIndex = CPU_TO_LE16(0),
.wLength = sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost), .wLength = CPU_TO_LE16(sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost)),
}; };
Endpoint_Write_Stream_LE(&Notification, sizeof(USB_Request_Header_t), NULL); Endpoint_Write_Stream_LE(&Notification, sizeof(USB_Request_Header_t), NULL);

@ -124,17 +124,15 @@ void MS_Device_USBTask(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
if (MSInterfaceInfo->State.CommandBlock.Flags & MS_COMMAND_DIR_DATA_IN) if (MSInterfaceInfo->State.CommandBlock.Flags & MS_COMMAND_DIR_DATA_IN)
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber); Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
MSInterfaceInfo->State.CommandStatus.Status = CALLBACK_MS_Device_SCSICommandReceived(MSInterfaceInfo) ? bool SCSICommandResult = CALLBACK_MS_Device_SCSICommandReceived(MSInterfaceInfo);
MS_SCSI_COMMAND_Pass : MS_SCSI_COMMAND_Fail;
MSInterfaceInfo->State.CommandStatus.Signature = MS_CSW_SIGNATURE; MSInterfaceInfo->State.CommandStatus.Status = (SCSICommandResult) ? MS_SCSI_COMMAND_Pass : MS_SCSI_COMMAND_Fail;
MSInterfaceInfo->State.CommandStatus.Signature = CPU_TO_LE32(MS_CSW_SIGNATURE);
MSInterfaceInfo->State.CommandStatus.Tag = MSInterfaceInfo->State.CommandBlock.Tag; MSInterfaceInfo->State.CommandStatus.Tag = MSInterfaceInfo->State.CommandBlock.Tag;
MSInterfaceInfo->State.CommandStatus.DataTransferResidue = MSInterfaceInfo->State.CommandBlock.DataTransferLength; MSInterfaceInfo->State.CommandStatus.DataTransferResidue = MSInterfaceInfo->State.CommandBlock.DataTransferLength;
if ((MSInterfaceInfo->State.CommandStatus.Status == MS_SCSI_COMMAND_Fail) && if (!(SCSICommandResult) && (le32_to_cpu(MSInterfaceInfo->State.CommandStatus.DataTransferResidue)))
(MSInterfaceInfo->State.CommandStatus.DataTransferResidue)) Endpoint_StallTransaction();
{
Endpoint_StallTransaction();
}
MS_Device_ReturnCommandStatus(MSInterfaceInfo); MS_Device_ReturnCommandStatus(MSInterfaceInfo);
} }
@ -167,11 +165,15 @@ static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* const MSInte
(sizeof(MS_CommandBlockWrapper_t) - 16), &BytesProcessed) == (sizeof(MS_CommandBlockWrapper_t) - 16), &BytesProcessed) ==
ENDPOINT_RWSTREAM_IncompleteTransfer) ENDPOINT_RWSTREAM_IncompleteTransfer)
{ {
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
if (MSInterfaceInfo->State.IsMassStoreReset) if (MSInterfaceInfo->State.IsMassStoreReset)
return false; return false;
} }
if ((MSInterfaceInfo->State.CommandBlock.Signature != MS_CBW_SIGNATURE) || if ((MSInterfaceInfo->State.CommandBlock.Signature != CPU_TO_LE32(MS_CBW_SIGNATURE)) ||
(MSInterfaceInfo->State.CommandBlock.LUN >= MSInterfaceInfo->Config.TotalLUNs) || (MSInterfaceInfo->State.CommandBlock.LUN >= MSInterfaceInfo->Config.TotalLUNs) ||
(MSInterfaceInfo->State.CommandBlock.Flags & 0x1F) || (MSInterfaceInfo->State.CommandBlock.Flags & 0x1F) ||
(MSInterfaceInfo->State.CommandBlock.SCSICommandLength == 0) || (MSInterfaceInfo->State.CommandBlock.SCSICommandLength == 0) ||
@ -189,6 +191,10 @@ static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* const MSInte
MSInterfaceInfo->State.CommandBlock.SCSICommandLength, &BytesProcessed) == MSInterfaceInfo->State.CommandBlock.SCSICommandLength, &BytesProcessed) ==
ENDPOINT_RWSTREAM_IncompleteTransfer) ENDPOINT_RWSTREAM_IncompleteTransfer)
{ {
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
if (MSInterfaceInfo->State.IsMassStoreReset) if (MSInterfaceInfo->State.IsMassStoreReset)
return false; return false;
} }
@ -229,6 +235,10 @@ static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* const MSInt
sizeof(MS_CommandStatusWrapper_t), &BytesProcessed) == sizeof(MS_CommandStatusWrapper_t), &BytesProcessed) ==
ENDPOINT_RWSTREAM_IncompleteTransfer) ENDPOINT_RWSTREAM_IncompleteTransfer)
{ {
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
if (MSInterfaceInfo->State.IsMassStoreReset) if (MSInterfaceInfo->State.IsMassStoreReset)
return; return;
} }

@ -39,33 +39,33 @@
static const uint32_t PROGMEM AdapterSupportedOIDList[] = static const uint32_t PROGMEM AdapterSupportedOIDList[] =
{ {
OID_GEN_SUPPORTED_LIST, CPU_TO_LE32(OID_GEN_SUPPORTED_LIST),
OID_GEN_PHYSICAL_MEDIUM, CPU_TO_LE32(OID_GEN_PHYSICAL_MEDIUM),
OID_GEN_HARDWARE_STATUS, CPU_TO_LE32(OID_GEN_HARDWARE_STATUS),
OID_GEN_MEDIA_SUPPORTED, CPU_TO_LE32(OID_GEN_MEDIA_SUPPORTED),
OID_GEN_MEDIA_IN_USE, CPU_TO_LE32(OID_GEN_MEDIA_IN_USE),
OID_GEN_MAXIMUM_FRAME_SIZE, CPU_TO_LE32(OID_GEN_MAXIMUM_FRAME_SIZE),
OID_GEN_MAXIMUM_TOTAL_SIZE, CPU_TO_LE32(OID_GEN_MAXIMUM_TOTAL_SIZE),
OID_GEN_LINK_SPEED, CPU_TO_LE32(OID_GEN_LINK_SPEED),
OID_GEN_TRANSMIT_BLOCK_SIZE, CPU_TO_LE32(OID_GEN_TRANSMIT_BLOCK_SIZE),
OID_GEN_RECEIVE_BLOCK_SIZE, CPU_TO_LE32(OID_GEN_RECEIVE_BLOCK_SIZE),
OID_GEN_VENDOR_ID, CPU_TO_LE32(OID_GEN_VENDOR_ID),
OID_GEN_VENDOR_DESCRIPTION, CPU_TO_LE32(OID_GEN_VENDOR_DESCRIPTION),
OID_GEN_CURRENT_PACKET_FILTER, CPU_TO_LE32(OID_GEN_CURRENT_PACKET_FILTER),
OID_GEN_MAXIMUM_TOTAL_SIZE, CPU_TO_LE32(OID_GEN_MAXIMUM_TOTAL_SIZE),
OID_GEN_MEDIA_CONNECT_STATUS, CPU_TO_LE32(OID_GEN_MEDIA_CONNECT_STATUS),
OID_GEN_XMIT_OK, CPU_TO_LE32(OID_GEN_XMIT_OK),
OID_GEN_RCV_OK, CPU_TO_LE32(OID_GEN_RCV_OK),
OID_GEN_XMIT_ERROR, CPU_TO_LE32(OID_GEN_XMIT_ERROR),
OID_GEN_RCV_ERROR, CPU_TO_LE32(OID_GEN_RCV_ERROR),
OID_GEN_RCV_NO_BUFFER, CPU_TO_LE32(OID_GEN_RCV_NO_BUFFER),
OID_802_3_PERMANENT_ADDRESS, CPU_TO_LE32(OID_802_3_PERMANENT_ADDRESS),
OID_802_3_CURRENT_ADDRESS, CPU_TO_LE32(OID_802_3_CURRENT_ADDRESS),
OID_802_3_MULTICAST_LIST, CPU_TO_LE32(OID_802_3_MULTICAST_LIST),
OID_802_3_MAXIMUM_LIST_SIZE, CPU_TO_LE32(OID_802_3_MAXIMUM_LIST_SIZE),
OID_802_3_RCV_ERROR_ALIGNMENT, CPU_TO_LE32(OID_802_3_RCV_ERROR_ALIGNMENT),
OID_802_3_XMIT_ONE_COLLISION, CPU_TO_LE32(OID_802_3_XMIT_ONE_COLLISION),
OID_802_3_XMIT_MORE_COLLISIONS, CPU_TO_LE32(OID_802_3_XMIT_MORE_COLLISIONS),
}; };
void RNDIS_Device_ProcessControlRequest(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) void RNDIS_Device_ProcessControlRequest(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
@ -97,14 +97,14 @@ void RNDIS_Device_ProcessControlRequest(USB_ClassInfo_RNDIS_Device_t* const RNDI
if (!(MessageHeader->MessageLength)) if (!(MessageHeader->MessageLength))
{ {
RNDISInterfaceInfo->State.RNDISMessageBuffer[0] = 0; RNDISInterfaceInfo->State.RNDISMessageBuffer[0] = 0;
MessageHeader->MessageLength = 1; MessageHeader->MessageLength = CPU_TO_LE32(1);
} }
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
Endpoint_Write_Control_Stream_LE(RNDISInterfaceInfo->State.RNDISMessageBuffer, MessageHeader->MessageLength); Endpoint_Write_Control_Stream_LE(RNDISInterfaceInfo->State.RNDISMessageBuffer, le32_to_cpu(MessageHeader->MessageLength));
Endpoint_ClearOUT(); Endpoint_ClearOUT();
MessageHeader->MessageLength = 0; MessageHeader->MessageLength = CPU_TO_LE32(0);
} }
break; break;
@ -171,9 +171,9 @@ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo
{ {
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = RNDIS_NOTIF_ResponseAvailable, .bRequest = RNDIS_NOTIF_ResponseAvailable,
.wValue = 0, .wValue = CPU_TO_LE16(0),
.wIndex = 0, .wIndex = CPU_TO_LE16(0),
.wLength = 0, .wLength = CPU_TO_LE16(0),
}; };
Endpoint_Write_Stream_LE(&Notification, sizeof(USB_Request_Header_t), NULL); Endpoint_Write_Stream_LE(&Notification, sizeof(USB_Request_Header_t), NULL);
@ -191,115 +191,114 @@ void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_Device_t* const
RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
switch (MessageHeader->MessageType) switch (le32_to_cpu(MessageHeader->MessageType))
{ {
case REMOTE_NDIS_INITIALIZE_MSG: case REMOTE_NDIS_INITIALIZE_MSG:
RNDISInterfaceInfo->State.ResponseReady = true; RNDISInterfaceInfo->State.ResponseReady = true;
RNDIS_Initialize_Message_t* INITIALIZE_Message = RNDIS_Initialize_Message_t* INITIALIZE_Message =
(RNDIS_Initialize_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; (RNDIS_Initialize_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
RNDIS_Initialize_Complete_t* INITIALIZE_Response = RNDIS_Initialize_Complete_t* INITIALIZE_Response =
(RNDIS_Initialize_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; (RNDIS_Initialize_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
INITIALIZE_Response->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT; INITIALIZE_Response->MessageType = CPU_TO_LE32(REMOTE_NDIS_INITIALIZE_CMPLT);
INITIALIZE_Response->MessageLength = sizeof(RNDIS_Initialize_Complete_t); INITIALIZE_Response->MessageLength = CPU_TO_LE32(sizeof(RNDIS_Initialize_Complete_t));
INITIALIZE_Response->RequestId = INITIALIZE_Message->RequestId; INITIALIZE_Response->RequestId = INITIALIZE_Message->RequestId;
INITIALIZE_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; INITIALIZE_Response->Status = CPU_TO_LE32(REMOTE_NDIS_STATUS_SUCCESS);
INITIALIZE_Response->MajorVersion = REMOTE_NDIS_VERSION_MAJOR; INITIALIZE_Response->MajorVersion = CPU_TO_LE32(REMOTE_NDIS_VERSION_MAJOR);
INITIALIZE_Response->MinorVersion = REMOTE_NDIS_VERSION_MINOR; INITIALIZE_Response->MinorVersion = CPU_TO_LE32(REMOTE_NDIS_VERSION_MINOR);
INITIALIZE_Response->DeviceFlags = REMOTE_NDIS_DF_CONNECTIONLESS; INITIALIZE_Response->DeviceFlags = CPU_TO_LE32(REMOTE_NDIS_DF_CONNECTIONLESS);
INITIALIZE_Response->Medium = REMOTE_NDIS_MEDIUM_802_3; INITIALIZE_Response->Medium = CPU_TO_LE32(REMOTE_NDIS_MEDIUM_802_3);
INITIALIZE_Response->MaxPacketsPerTransfer = 1; INITIALIZE_Response->MaxPacketsPerTransfer = CPU_TO_LE32(1);
INITIALIZE_Response->MaxTransferSize = (sizeof(RNDIS_Packet_Message_t) + ETHERNET_FRAME_SIZE_MAX); INITIALIZE_Response->MaxTransferSize = CPU_TO_LE32(sizeof(RNDIS_Packet_Message_t) + ETHERNET_FRAME_SIZE_MAX);
INITIALIZE_Response->PacketAlignmentFactor = 0; INITIALIZE_Response->PacketAlignmentFactor = CPU_TO_LE32(0);
INITIALIZE_Response->AFListOffset = 0; INITIALIZE_Response->AFListOffset = CPU_TO_LE32(0);
INITIALIZE_Response->AFListSize = 0; INITIALIZE_Response->AFListSize = CPU_TO_LE32(0);
RNDISInterfaceInfo->State.CurrRNDISState = RNDIS_Initialized; RNDISInterfaceInfo->State.CurrRNDISState = RNDIS_Initialized;
break; break;
case REMOTE_NDIS_HALT_MSG: case REMOTE_NDIS_HALT_MSG:
RNDISInterfaceInfo->State.ResponseReady = false; RNDISInterfaceInfo->State.ResponseReady = false;
MessageHeader->MessageLength = 0;
RNDISInterfaceInfo->State.CurrRNDISState = RNDIS_Uninitialized; MessageHeader->MessageLength = CPU_TO_LE32(0);
RNDISInterfaceInfo->State.CurrRNDISState = RNDIS_Uninitialized;
break; break;
case REMOTE_NDIS_QUERY_MSG: case REMOTE_NDIS_QUERY_MSG:
RNDISInterfaceInfo->State.ResponseReady = true; RNDISInterfaceInfo->State.ResponseReady = true;
RNDIS_Query_Message_t* QUERY_Message = (RNDIS_Query_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
RNDIS_Query_Complete_t* QUERY_Response = (RNDIS_Query_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
uint32_t Query_Oid = QUERY_Message->Oid;
void* QueryData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) + RNDIS_Query_Message_t* QUERY_Message = (RNDIS_Query_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
QUERY_Message->InformationBufferOffset]; RNDIS_Query_Complete_t* QUERY_Response = (RNDIS_Query_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
void* ResponseData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Query_Complete_t)]; uint32_t Query_Oid = CPU_TO_LE32(QUERY_Message->Oid);
uint16_t ResponseSize;
QUERY_Response->MessageType = REMOTE_NDIS_QUERY_CMPLT; void* QueryData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) +
QUERY_Response->MessageLength = sizeof(RNDIS_Query_Complete_t); le32_to_cpu(QUERY_Message->InformationBufferOffset)];
void* ResponseData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Query_Complete_t)];
uint16_t ResponseSize;
if (RNDIS_Device_ProcessNDISQuery(RNDISInterfaceInfo, Query_Oid, QueryData, QUERY_Message->InformationBufferLength, QUERY_Response->MessageType = CPU_TO_LE32(REMOTE_NDIS_QUERY_CMPLT);
if (RNDIS_Device_ProcessNDISQuery(RNDISInterfaceInfo, Query_Oid, QueryData, le32_to_cpu(QUERY_Message->InformationBufferLength),
ResponseData, &ResponseSize)) ResponseData, &ResponseSize))
{ {
QUERY_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; QUERY_Response->Status = CPU_TO_LE32(REMOTE_NDIS_STATUS_SUCCESS);
QUERY_Response->MessageLength += ResponseSize; QUERY_Response->MessageLength = cpu_to_le32(sizeof(RNDIS_Query_Complete_t) + ResponseSize);
QUERY_Response->InformationBufferLength = ResponseSize; QUERY_Response->InformationBufferLength = CPU_TO_LE32(ResponseSize);
QUERY_Response->InformationBufferOffset = (sizeof(RNDIS_Query_Complete_t) - sizeof(RNDIS_Message_Header_t)); QUERY_Response->InformationBufferOffset = CPU_TO_LE32(sizeof(RNDIS_Query_Complete_t) - sizeof(RNDIS_Message_Header_t));
} }
else else
{ {
QUERY_Response->Status = REMOTE_NDIS_STATUS_NOT_SUPPORTED; QUERY_Response->Status = CPU_TO_LE32(REMOTE_NDIS_STATUS_NOT_SUPPORTED);
QUERY_Response->MessageLength = CPU_TO_LE32(sizeof(RNDIS_Query_Complete_t));
QUERY_Response->InformationBufferLength = 0; QUERY_Response->InformationBufferLength = CPU_TO_LE32(0);
QUERY_Response->InformationBufferOffset = 0; QUERY_Response->InformationBufferOffset = CPU_TO_LE32(0);
} }
break; break;
case REMOTE_NDIS_SET_MSG: case REMOTE_NDIS_SET_MSG:
RNDISInterfaceInfo->State.ResponseReady = true; RNDISInterfaceInfo->State.ResponseReady = true;
RNDIS_Set_Message_t* SET_Message = (RNDIS_Set_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; RNDIS_Set_Message_t* SET_Message = (RNDIS_Set_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
RNDIS_Set_Complete_t* SET_Response = (RNDIS_Set_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; RNDIS_Set_Complete_t* SET_Response = (RNDIS_Set_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
uint32_t SET_Oid = SET_Message->Oid; uint32_t SET_Oid = le32_to_cpu(SET_Message->Oid);
SET_Response->MessageType = REMOTE_NDIS_SET_CMPLT; SET_Response->MessageType = CPU_TO_LE32(REMOTE_NDIS_SET_CMPLT);
SET_Response->MessageLength = sizeof(RNDIS_Set_Complete_t); SET_Response->MessageLength = CPU_TO_LE32(sizeof(RNDIS_Set_Complete_t));
SET_Response->RequestId = SET_Message->RequestId; SET_Response->RequestId = SET_Message->RequestId;
void* SetData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) + void* SetData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) +
SET_Message->InformationBufferOffset]; le32_to_cpu(SET_Message->InformationBufferOffset)];
SET_Response->Status = RNDIS_Device_ProcessNDISSet(RNDISInterfaceInfo, SET_Oid, SetData, SET_Response->Status = RNDIS_Device_ProcessNDISSet(RNDISInterfaceInfo, SET_Oid, SetData,
SET_Message->InformationBufferLength) ? le32_to_cpu(SET_Message->InformationBufferLength)) ?
REMOTE_NDIS_STATUS_SUCCESS : REMOTE_NDIS_STATUS_NOT_SUPPORTED; REMOTE_NDIS_STATUS_SUCCESS : REMOTE_NDIS_STATUS_NOT_SUPPORTED;
break; break;
case REMOTE_NDIS_RESET_MSG: case REMOTE_NDIS_RESET_MSG:
RNDISInterfaceInfo->State.ResponseReady = true; RNDISInterfaceInfo->State.ResponseReady = true;
RNDIS_Reset_Complete_t* RESET_Response = (RNDIS_Reset_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; RNDIS_Reset_Complete_t* RESET_Response = (RNDIS_Reset_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
RESET_Response->MessageType = REMOTE_NDIS_RESET_CMPLT; RESET_Response->MessageType = CPU_TO_LE32(REMOTE_NDIS_RESET_CMPLT);
RESET_Response->MessageLength = sizeof(RNDIS_Reset_Complete_t); RESET_Response->MessageLength = CPU_TO_LE32(sizeof(RNDIS_Reset_Complete_t));
RESET_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; RESET_Response->Status = CPU_TO_LE32(REMOTE_NDIS_STATUS_SUCCESS);
RESET_Response->AddressingReset = 0; RESET_Response->AddressingReset = CPU_TO_LE32(0);
break; break;
case REMOTE_NDIS_KEEPALIVE_MSG: case REMOTE_NDIS_KEEPALIVE_MSG:
RNDISInterfaceInfo->State.ResponseReady = true; RNDISInterfaceInfo->State.ResponseReady = true;
RNDIS_KeepAlive_Message_t* KEEPALIVE_Message = RNDIS_KeepAlive_Message_t* KEEPALIVE_Message =
(RNDIS_KeepAlive_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; (RNDIS_KeepAlive_Message_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
RNDIS_KeepAlive_Complete_t* KEEPALIVE_Response = RNDIS_KeepAlive_Complete_t* KEEPALIVE_Response =
(RNDIS_KeepAlive_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; (RNDIS_KeepAlive_Complete_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
KEEPALIVE_Response->MessageType = REMOTE_NDIS_KEEPALIVE_CMPLT; KEEPALIVE_Response->MessageType = CPU_TO_LE32(REMOTE_NDIS_KEEPALIVE_CMPLT);
KEEPALIVE_Response->MessageLength = sizeof(RNDIS_KeepAlive_Complete_t); KEEPALIVE_Response->MessageLength = CPU_TO_LE32(sizeof(RNDIS_KeepAlive_Complete_t));
KEEPALIVE_Response->RequestId = KEEPALIVE_Message->RequestId; KEEPALIVE_Response->RequestId = KEEPALIVE_Message->RequestId;
KEEPALIVE_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; KEEPALIVE_Response->Status = CPU_TO_LE32(REMOTE_NDIS_STATUS_SUCCESS);
break; break;
} }
@ -327,27 +326,27 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RN
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
/* Indicate that the device is a true ethernet link */ /* Indicate that the device is a true ethernet link */
*((uint32_t*)ResponseData) = 0; *((uint32_t*)ResponseData) = CPU_TO_LE32(0);
return true; return true;
case OID_GEN_HARDWARE_STATUS: case OID_GEN_HARDWARE_STATUS:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
*((uint32_t*)ResponseData) = NDIS_HardwareStatus_Ready; *((uint32_t*)ResponseData) = CPU_TO_LE32(NDIS_HardwareStatus_Ready);
return true; return true;
case OID_GEN_MEDIA_SUPPORTED: case OID_GEN_MEDIA_SUPPORTED:
case OID_GEN_MEDIA_IN_USE: case OID_GEN_MEDIA_IN_USE:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
*((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIUM_802_3; *((uint32_t*)ResponseData) = CPU_TO_LE32(REMOTE_NDIS_MEDIUM_802_3);
return true; return true;
case OID_GEN_VENDOR_ID: case OID_GEN_VENDOR_ID:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
/* Vendor ID 0x0xFFFFFF is reserved for vendors who have not purchased a NDIS VID */ /* Vendor ID 0x0xFFFFFF is reserved for vendors who have not purchased a NDIS VID */
*((uint32_t*)ResponseData) = 0x00FFFFFF; *((uint32_t*)ResponseData) = CPU_TO_LE32(0x00FFFFFF);
return true; return true;
case OID_GEN_MAXIMUM_FRAME_SIZE: case OID_GEN_MAXIMUM_FRAME_SIZE:
@ -355,7 +354,7 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RN
case OID_GEN_RECEIVE_BLOCK_SIZE: case OID_GEN_RECEIVE_BLOCK_SIZE:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
*((uint32_t*)ResponseData) = ETHERNET_FRAME_SIZE_MAX; *((uint32_t*)ResponseData) = CPU_TO_LE32(ETHERNET_FRAME_SIZE_MAX);
return true; return true;
case OID_GEN_VENDOR_DESCRIPTION: case OID_GEN_VENDOR_DESCRIPTION:
@ -367,14 +366,14 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RN
case OID_GEN_MEDIA_CONNECT_STATUS: case OID_GEN_MEDIA_CONNECT_STATUS:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
*((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIA_STATE_CONNECTED; *((uint32_t*)ResponseData) = CPU_TO_LE32(REMOTE_NDIS_MEDIA_STATE_CONNECTED);
return true; return true;
case OID_GEN_LINK_SPEED: case OID_GEN_LINK_SPEED:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
/* Indicate 10Mb/s link speed */ /* Indicate 10Mb/s link speed */
*((uint32_t*)ResponseData) = 100000; *((uint32_t*)ResponseData) = CPU_TO_LE32(100000);
return true; return true;
case OID_802_3_PERMANENT_ADDRESS: case OID_802_3_PERMANENT_ADDRESS:
@ -388,13 +387,13 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RN
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
/* Indicate only one multicast address supported */ /* Indicate only one multicast address supported */
*((uint32_t*)ResponseData) = 1; *((uint32_t*)ResponseData) = CPU_TO_LE32(1);
return true; return true;
case OID_GEN_CURRENT_PACKET_FILTER: case OID_GEN_CURRENT_PACKET_FILTER:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
*((uint32_t*)ResponseData) = RNDISInterfaceInfo->State.CurrPacketFilter; *((uint32_t*)ResponseData) = cpu_to_le32(RNDISInterfaceInfo->State.CurrPacketFilter);
return true; return true;
case OID_GEN_XMIT_OK: case OID_GEN_XMIT_OK:
@ -408,14 +407,14 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RN
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
/* Unused statistic OIDs - always return 0 for each */ /* Unused statistic OIDs - always return 0 for each */
*((uint32_t*)ResponseData) = 0; *((uint32_t*)ResponseData) = CPU_TO_LE32(0);
return true; return true;
case OID_GEN_MAXIMUM_TOTAL_SIZE: case OID_GEN_MAXIMUM_TOTAL_SIZE:
*ResponseSize = sizeof(uint32_t); *ResponseSize = sizeof(uint32_t);
/* Indicate maximum overall buffer (Ethernet frame and RNDIS header) the adapter can handle */ /* Indicate maximum overall buffer (Ethernet frame and RNDIS header) the adapter can handle */
*((uint32_t*)ResponseData) = (RNDIS_MESSAGE_BUFFER_SIZE + ETHERNET_FRAME_SIZE_MAX); *((uint32_t*)ResponseData) = CPU_TO_LE32(RNDIS_MESSAGE_BUFFER_SIZE + ETHERNET_FRAME_SIZE_MAX);
return true; return true;
default: default:
@ -433,9 +432,9 @@ static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_Device_t* const RNDI
switch (OId) switch (OId)
{ {
case OID_GEN_CURRENT_PACKET_FILTER: case OID_GEN_CURRENT_PACKET_FILTER:
RNDISInterfaceInfo->State.CurrPacketFilter = *((uint32_t*)SetData); RNDISInterfaceInfo->State.CurrPacketFilter = le32_to_cpu(*((uint32_t*)SetData));
RNDISInterfaceInfo->State.CurrRNDISState = ((RNDISInterfaceInfo->State.CurrPacketFilter) ? RNDISInterfaceInfo->State.CurrRNDISState = le32_to_cpu((RNDISInterfaceInfo->State.CurrPacketFilter) ?
RNDIS_Data_Initialized : RNDIS_Data_Initialized); RNDIS_Data_Initialized : RNDIS_Data_Initialized);
return true; return true;
case OID_802_3_MULTICAST_LIST: case OID_802_3_MULTICAST_LIST:
@ -479,16 +478,16 @@ uint8_t RNDIS_Device_ReadPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfa
RNDIS_Packet_Message_t RNDISPacketHeader; RNDIS_Packet_Message_t RNDISPacketHeader;
Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL); Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
if (RNDISPacketHeader.DataLength > ETHERNET_FRAME_SIZE_MAX) if (le32_to_cpu(RNDISPacketHeader.DataLength) > ETHERNET_FRAME_SIZE_MAX)
{ {
Endpoint_StallTransaction(); Endpoint_StallTransaction();
return RNDIS_ERROR_LOGICAL_CMD_FAILED; return RNDIS_ERROR_LOGICAL_CMD_FAILED;
} }
*PacketLength = (uint16_t)RNDISPacketHeader.DataLength; *PacketLength = (uint16_t)le32_to_cpu(RNDISPacketHeader.DataLength);
Endpoint_Read_Stream_LE(Buffer, RNDISPacketHeader.DataLength, NULL); Endpoint_Read_Stream_LE(Buffer, *PacketLength, NULL);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
return ENDPOINT_RWSTREAM_NoError; return ENDPOINT_RWSTREAM_NoError;
@ -515,10 +514,10 @@ uint8_t RNDIS_Device_SendPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfa
memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t)); memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t));
RNDISPacketHeader.MessageType = REMOTE_NDIS_PACKET_MSG; RNDISPacketHeader.MessageType = CPU_TO_LE32(REMOTE_NDIS_PACKET_MSG);
RNDISPacketHeader.MessageLength = (sizeof(RNDIS_Packet_Message_t) + PacketLength); RNDISPacketHeader.MessageLength = cpu_to_le32(sizeof(RNDIS_Packet_Message_t) + PacketLength);
RNDISPacketHeader.DataOffset = (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)); RNDISPacketHeader.DataOffset = CPU_TO_LE32(sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t));
RNDISPacketHeader.DataLength = PacketLength; RNDISPacketHeader.DataLength = cpu_to_le32(PacketLength);
Endpoint_Write_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL); Endpoint_Write_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
Endpoint_Write_Stream_LE(Buffer, PacketLength, NULL); Endpoint_Write_Stream_LE(Buffer, PacketLength, NULL);

@ -254,6 +254,8 @@
* uses LUFA-specific element names to make each element's purpose clearer. * uses LUFA-specific element names to make each element's purpose clearer.
* *
* \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names. * \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -269,6 +271,8 @@
* uses the relevant standard's given element names to ensure compatibility with the standard. * uses the relevant standard's given element names to ensure compatibility with the standard.
* *
* \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names. * \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -284,6 +288,8 @@
* element's purpose clearer. * element's purpose clearer.
* *
* \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names. * \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -333,6 +339,8 @@
* to ensure compatibility with the standard. * to ensure compatibility with the standard.
* *
* \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names. * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -381,6 +389,8 @@
* to make each element's purpose clearer. * to make each element's purpose clearer.
* *
* \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names. * \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -410,6 +420,8 @@
* to ensure compatibility with the standard. * to ensure compatibility with the standard.
* *
* \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names. * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -438,6 +450,8 @@
* to make each element's purpose clearer. * to make each element's purpose clearer.
* *
* \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names. * \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -464,6 +478,8 @@
* to ensure compatibility with the standard. * to ensure compatibility with the standard.
* *
* \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names. * \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -498,6 +514,8 @@
* function. Read the ECN for more information. * function. Read the ECN for more information.
* *
* \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names. * \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -528,6 +546,8 @@
* *
* \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific * \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -551,6 +571,8 @@
* to make each element's purpose clearer. * to make each element's purpose clearer.
* *
* \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names. * \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -577,6 +599,8 @@
* *
* \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific * \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -610,6 +634,8 @@
* This structure uses LUFA-specific element names to make each element's purpose clearer. * This structure uses LUFA-specific element names to make each element's purpose clearer.
* *
* \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names. * \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {
@ -645,6 +671,8 @@
* *
* \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific * \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific
* element names. * element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/ */
typedef struct typedef struct
{ {

@ -84,6 +84,8 @@
* inside of the \ref EVENT_USB_Device_ControlRequest() event, or for filling up with a control request to * inside of the \ref EVENT_USB_Device_ControlRequest() event, or for filling up with a control request to
* issue when in Host mode before calling \ref USB_Host_SendControlRequest(). * issue when in Host mode before calling \ref USB_Host_SendControlRequest().
* *
* \note The contents of this structure is automatically endian-corrected for the current CPU architecture.
*
* \ingroup Group_USBManagement * \ingroup Group_USBManagement
*/ */
extern USB_Request_Header_t USB_ControlRequest; extern USB_Request_Header_t USB_ControlRequest;

Loading…
Cancel
Save