Fixed broken USE_RAM_DESCRIPTORS compile time option when the FIXED_NUM_CONFIGURATION...
[pub/USBasp.git] / Demos / Device / ClassDriver / RNDISEthernet / Lib / ProtocolDecoders.c
index e0bf6ec..57e71cb 100644 (file)
@@ -1,24 +1,24 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
-              
+     Copyright (C) Dean Camera, 2015.
+
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2015  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
-  Permission to use, copy, modify, distribute, and sell this 
+  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 
+  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 
+  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
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
@@ -31,7 +31,7 @@
 /* Protocol decoders for Ethernet, TCP, IP, ICMP and ARP. Each of these routines
    accepts a header to the appropriate protocol and prints out pertinent information
    on the packet through the serial port.
-   
+
    To disable printing of a specific protocol, define the token NO_DECODE_{Protocol}
    in the project makefile, and pass it to the compiler using the -D switch.
 */
  *  Packet decoding routines can be disabled by defining NO_DECODE_{Protocol Name} in the project makefile
  *  and passing it to the compiler via the -D switch.
  */
+
 #include "ProtocolDecoders.h"
 
 /** 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] InDataStart  Pointer to the start of an Ethernet frame of data
  */
-void DecodeEthernetFrameHeader(Ethernet_Frame_Info_t* FrameINData)
+void DecodeEthernetFrameHeader(void* InDataStart)
 {
        #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("  ETHERNET\r\n"));
-       printf_P(PSTR("  + Frame Size: %u\r\n"), FrameINData->FrameLength);
 
        if (!(MAC_COMPARE(&FrameHeader->Destination, &ServerMACAddress)) &&
            !(MAC_COMPARE(&FrameHeader->Destination, &BroadcastMACAddress)))
@@ -84,10 +83,7 @@ void DecodeEthernetFrameHeader(Ethernet_Frame_Info_t* FrameINData)
                                                                             FrameHeader->Destination.Octets[4],
                                                                             FrameHeader->Destination.Octets[5]);
 
-       if (SwapEndian_16(FrameINData->FrameLength) > ETHERNET_VER2_MINSIZE)
-         printf_P(PSTR("  + Protocol: 0x%04x\r\n"), SwapEndian_16(FrameHeader->EtherType));
-       else
-         printf_P(PSTR("  + Protocol: UNKNOWN E1\r\n"));
+       printf_P(PSTR("  + Protocol: 0x%04x\r\n"), SwapEndian_16(FrameHeader->EtherType));
        #endif
 }
 
@@ -98,7 +94,7 @@ void DecodeEthernetFrameHeader(Ethernet_Frame_Info_t* FrameINData)
 void DecodeARPHeader(void* InDataStart)
 {
        #if !defined(NO_DECODE_ARP)
-       ARP_Header_t* ARPHeader = (ARP_Header_t*)InDataStart;   
+       ARP_Header_t* ARPHeader = (ARP_Header_t*)InDataStart;
 
        printf_P(PSTR("   \\\r\n    ARP\r\n"));
 
@@ -106,12 +102,12 @@ void DecodeARPHeader(void* InDataStart)
            !(MAC_COMPARE(&ARPHeader->THA, &ServerMACAddress)))
        {
                printf_P(PSTR("    + NOT ADDRESSED TO DEVICE\r\n"));
-               return;         
+               return;
        }
 
        printf_P(PSTR("    + Protocol: %x\r\n"), SwapEndian_16(ARPHeader->ProtocolType));
        printf_P(PSTR("    + Operation: %u\r\n"), SwapEndian_16(ARPHeader->Operation));
-       
+
        if (SwapEndian_16(ARPHeader->ProtocolType) == ETHERTYPE_IPV4)
        {
                printf_P(PSTR("    + SHA MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n"), ARPHeader->SHA.Octets[0],
@@ -163,14 +159,14 @@ void DecodeIPHeader(void* InDataStart)
        printf_P(PSTR("    + Header Length: %u Bytes\r\n"), HeaderLengthBytes);
        printf_P(PSTR("    + Packet Version: %u\r\n"), IPHeader->Version);
        printf_P(PSTR("    + Total Length: %u\r\n"), SwapEndian_16(IPHeader->TotalLength));
-       
+
        printf_P(PSTR("    + Protocol: %u\r\n"), IPHeader->Protocol);
        printf_P(PSTR("    + TTL: %u\r\n"), IPHeader->TTL);
-       
+
        printf_P(PSTR("    + IP Src: %u.%u.%u.%u\r\n"), IPHeader->SourceAddress.Octets[0],
                                                        IPHeader->SourceAddress.Octets[1],
                                                        IPHeader->SourceAddress.Octets[2],
-                                                       IPHeader->SourceAddress.Octets[3]);     
+                                                       IPHeader->SourceAddress.Octets[3]);
 
        printf_P(PSTR("    + IP Dst: %u.%u.%u.%u\r\n"), IPHeader->DestinationAddress.Octets[0],
                                                        IPHeader->DestinationAddress.Octets[1],
@@ -215,9 +211,9 @@ void DecodeTCPHeader(void* InDataStart)
 
        printf_P(PSTR("     + Sequence Number: %lu\r\n"), SwapEndian_32(TCPHeader->SequenceNumber));
        printf_P(PSTR("     + Acknowledgment Number: %lu\r\n"), SwapEndian_32(TCPHeader->AcknowledgmentNumber));
-       
+
        printf_P(PSTR("     + Flags: 0x%02X\r\n"), TCPHeader->Flags);
-       
+
        if (TCP_GetPortState(TCPHeader->DestinationPort) == TCP_Port_Closed)
          printf_P(PSTR("     + NOT LISTENING ON DESTINATION PORT\r\n"));
        #endif
@@ -272,9 +268,10 @@ void DecodeDHCPHeader(void* InDataStart)
                                        break;
                        }
                }
-               
+
                DHCPOptions += ((DHCPOptions[0] == DHCP_OPTION_PAD) ? 1 : (DHCPOptions[1] + 2));
        }
 
        #endif
 }
+