Add new tag for the LUFA-120219-BETA release.
[pub/USBasp.git] / Demos / Device / ClassDriver / RNDISEthernet / Lib / ARP.c
index 0f108c2..7023825 100644 (file)
@@ -1,85 +1,87 @@
-/*\r
-             LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
-              \r
-  dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
-  software without specific, written prior permission.\r
-\r
-  The author disclaim all warranties with regard to this\r
-  software, including all implied warranties of merchantability\r
-  and fitness.  In no event shall the author be liable for any\r
-  special, indirect or consequential damages or any damages\r
-  whatsoever resulting from loss of use, data or profits, whether\r
-  in an action of contract, negligence or other tortious action,\r
-  arising out of or in connection with the use or performance of\r
-  this software.\r
-*/\r
-\r
-/** \file\r
- *\r
- *  Address Resolution Protocol (ARP) packet handling routines. This protocol handles the\r
- *  conversion of physical MAC addresses to protocol IP addresses between the host and the\r
- *  device.\r
- */\r
\r
-#include "ARP.h"\r
-\r
-/** Processes an ARP packet inside an Ethernet frame, and writes the appropriate response\r
- *  to the output Ethernet frame if the host is requesting the IP or MAC address of the\r
- *  virtual server device on the network.\r
- *\r
- *  \param InDataStart   Pointer to the start of the incoming packet's ARP header\r
- *  \param OutDataStart  Pointer to the start of the outgoing packet's ARP header\r
- *\r
- *  \return The number of bytes written to the out Ethernet frame if any, NO_RESPONSE otherwise\r
- */\r
-int16_t ARP_ProcessARPPacket(void* InDataStart, void* OutDataStart)\r
-{\r
-       DecodeARPHeader(InDataStart);\r
-\r
-       ARP_Header_t* ARPHeaderIN  = (ARP_Header_t*)InDataStart;\r
-       ARP_Header_t* ARPHeaderOUT = (ARP_Header_t*)OutDataStart;\r
-\r
-       /* Ensure that the ARP request is a IPv4 request packet */\r
-       if ((SwapEndian_16(ARPHeaderIN->ProtocolType) == ETHERTYPE_IPV4) &&\r
-           (SwapEndian_16(ARPHeaderIN->Operation) == ARP_OPERATION_REQUEST))\r
-       {\r
-               /* If the ARP packet is requesting the MAC or IP of the virtual webserver, return the response */\r
-               if (IP_COMPARE(&ARPHeaderIN->TPA, &ServerIPAddress) || \r
-                   MAC_COMPARE(&ARPHeaderIN->THA, &ServerMACAddress))\r
-               {\r
-                       /* Fill out the ARP response header */\r
-                       ARPHeaderOUT->HardwareType = ARPHeaderIN->HardwareType;\r
-                       ARPHeaderOUT->ProtocolType = ARPHeaderIN->ProtocolType;\r
-                       ARPHeaderOUT->HLEN         = ARPHeaderIN->HLEN;\r
-                       ARPHeaderOUT->PLEN         = ARPHeaderIN->PLEN;\r
-                       ARPHeaderOUT->Operation    = SwapEndian_16(ARP_OPERATION_REPLY);\r
-\r
-                       /* Copy over the sender MAC/IP to the target fields for the response */\r
-                       ARPHeaderOUT->THA = ARPHeaderIN->SHA;\r
-                       ARPHeaderOUT->TPA = ARPHeaderIN->SPA;\r
-\r
-                       /* Copy over the new sender MAC/IP - MAC and IP addresses of the virtual webserver */\r
-                       ARPHeaderOUT->SHA = ServerMACAddress;\r
-                       ARPHeaderOUT->SPA = ServerIPAddress;\r
-\r
-                       /* Return the size of the response so far */\r
-                       return sizeof(ARP_Header_t);\r
-               }\r
-       }\r
-       \r
-       return NO_RESPONSE;\r
-}\r
+/*
+             LUFA Library
+     Copyright (C) Dean Camera, 2012.
+
+  dean [at] fourwalledcubicle [dot] com
+           www.lufa-lib.org
+*/
+
+/*
+  Copyright 2012  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
+ *
+ *  Address Resolution Protocol (ARP) packet handling routines. This protocol handles the
+ *  conversion of physical MAC addresses to protocol IP addresses between the host and the
+ *  device.
+ */
+
+#include "ARP.h"
+
+/** Processes an ARP packet inside an Ethernet frame, and writes the appropriate response
+ *  to the output Ethernet frame if the host is requesting the IP or MAC address of the
+ *  virtual server device on the network.
+ *
+ *  \param[in] InDataStart   Pointer to the start of the incoming packet's ARP header
+ *  \param[out] OutDataStart  Pointer to the start of the outgoing packet's ARP header
+ *
+ *  \return The number of bytes written to the out Ethernet frame if any, NO_RESPONSE otherwise
+ */
+int16_t ARP_ProcessARPPacket(void* InDataStart,
+                             void* OutDataStart)
+{
+       DecodeARPHeader(InDataStart);
+
+       ARP_Header_t* ARPHeaderIN  = (ARP_Header_t*)InDataStart;
+       ARP_Header_t* ARPHeaderOUT = (ARP_Header_t*)OutDataStart;
+
+       /* Ensure that the ARP request is a IPv4 request packet */
+       if ((SwapEndian_16(ARPHeaderIN->ProtocolType) == ETHERTYPE_IPV4) &&
+           (SwapEndian_16(ARPHeaderIN->Operation) == ARP_OPERATION_REQUEST))
+       {
+               /* If the ARP packet is requesting the MAC or IP of the virtual webserver, return the response */
+               if (IP_COMPARE(&ARPHeaderIN->TPA, &ServerIPAddress) ||
+                   MAC_COMPARE(&ARPHeaderIN->THA, &ServerMACAddress))
+               {
+                       /* Fill out the ARP response header */
+                       ARPHeaderOUT->HardwareType = ARPHeaderIN->HardwareType;
+                       ARPHeaderOUT->ProtocolType = ARPHeaderIN->ProtocolType;
+                       ARPHeaderOUT->HLEN         = ARPHeaderIN->HLEN;
+                       ARPHeaderOUT->PLEN         = ARPHeaderIN->PLEN;
+                       ARPHeaderOUT->Operation    = SwapEndian_16(ARP_OPERATION_REPLY);
+
+                       /* Copy over the sender MAC/IP to the target fields for the response */
+                       ARPHeaderOUT->THA = ARPHeaderIN->SHA;
+                       ARPHeaderOUT->TPA = ARPHeaderIN->SPA;
+
+                       /* Copy over the new sender MAC/IP - MAC and IP addresses of the virtual webserver */
+                       ARPHeaderOUT->SHA = ServerMACAddress;
+                       ARPHeaderOUT->SPA = ServerIPAddress;
+
+                       /* Return the size of the response so far */
+                       return sizeof(ARP_Header_t);
+               }
+       }
+
+       return NO_RESPONSE;
+}
+