Change over unix line-endings to dos line endings.
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 7 May 2010 06:40:47 +0000 (06:40 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 7 May 2010 06:40:47 +0000 (06:40 +0000)
17 files changed:
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
LUFA/Drivers/USB/Class/Common/Printer.h
Projects/TemperatureDataLogger/TempLogHostApp/COPYING.LESSER.txt
Projects/TemperatureDataLogger/TempLogHostApp/COPYING.txt
Projects/Webserver/Lib/DataflashManager.h
Projects/Webserver/Lib/SCSI.h
Projects/Webserver/Lib/uip/clock.c
Projects/Webserver/Lib/uip/clock.h
Projects/Webserver/Lib/uip/timer.c
Projects/Webserver/Lib/uip/timer.h
Projects/Webserver/Lib/uip/uip-split.c
Projects/Webserver/Lib/uip/uip-split.h
Projects/Webserver/Lib/uip/uip.c
Projects/Webserver/Lib/uip/uip.h
Projects/Webserver/Lib/uip/uip_arp.c
Projects/Webserver/Lib/uip/uip_arp.h
Projects/Webserver/Lib/uip/uipopt.h

index 8c417ff..7c03a64 100644 (file)
@@ -401,7 +401,7 @@ static inline void Bluetooth_Signal_ConnectionReq(const BT_Signal_Header_t* cons
                        ChannelData->PSM          = ConnectionRequest.PSM;\r
                        ChannelData->LocalMTU     = MAXIMUM_CHANNEL_MTU;\r
                        ChannelData->State        = Channel_Config_WaitConfig;\r
                        ChannelData->PSM          = ConnectionRequest.PSM;\r
                        ChannelData->LocalMTU     = MAXIMUM_CHANNEL_MTU;\r
                        ChannelData->State        = Channel_Config_WaitConfig;\r
-                       
+                       \r
                        ChannelStatus = BT_CONNECTION_SUCCESSFUL;\r
                }\r
                else\r
                        ChannelStatus = BT_CONNECTION_SUCCESSFUL;\r
                }\r
                else\r
index b0c1416..eba7c3a 100644 (file)
@@ -58,7 +58,7 @@
        /* Enable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
                        extern "C" {\r
        /* Enable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
                        extern "C" {\r
-               #endif
+               #endif\r
 \r
        /* Preprocessor Checks: */\r
                #if !defined(__INCLUDE_FROM_PRINTER_DRIVER)\r
 \r
        /* Preprocessor Checks: */\r
                #if !defined(__INCLUDE_FROM_PRINTER_DRIVER)\r
index fc8a5de..b87303c 100644 (file)
-                  GNU LESSER GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-
-  This version of the GNU Lesser General Public License incorporates
-the terms and conditions of version 3 of the GNU General Public
-License, supplemented by the additional permissions listed below.
-
-  0. Additional Definitions. 
-
-  As used herein, "this License" refers to version 3 of the GNU Lesser
-General Public License, and the "GNU GPL" refers to version 3 of the GNU
-General Public License.
-
-  "The Library" refers to a covered work governed by this License,
-other than an Application or a Combined Work as defined below.
-
-  An "Application" is any work that makes use of an interface provided
-by the Library, but which is not otherwise based on the Library.
-Defining a subclass of a class defined by the Library is deemed a mode
-of using an interface provided by the Library.
-
-  A "Combined Work" is a work produced by combining or linking an
-Application with the Library.  The particular version of the Library
-with which the Combined Work was made is also called the "Linked
-Version".
-
-  The "Minimal Corresponding Source" for a Combined Work means the
-Corresponding Source for the Combined Work, excluding any source code
-for portions of the Combined Work that, considered in isolation, are
-based on the Application, and not on the Linked Version.
-
-  The "Corresponding Application Code" for a Combined Work means the
-object code and/or source code for the Application, including any data
-and utility programs needed for reproducing the Combined Work from the
-Application, but excluding the System Libraries of the Combined Work.
-
-  1. Exception to Section 3 of the GNU GPL.
-
-  You may convey a covered work under sections 3 and 4 of this License
-without being bound by section 3 of the GNU GPL.
-
-  2. Conveying Modified Versions.
-
-  If you modify a copy of the Library, and, in your modifications, a
-facility refers to a function or data to be supplied by an Application
-that uses the facility (other than as an argument passed when the
-facility is invoked), then you may convey a copy of the modified
-version:
-
-   a) under this License, provided that you make a good faith effort to
-   ensure that, in the event an Application does not supply the
-   function or data, the facility still operates, and performs
-   whatever part of its purpose remains meaningful, or
-
-   b) under the GNU GPL, with none of the additional permissions of
-   this License applicable to that copy.
-
-  3. Object Code Incorporating Material from Library Header Files.
-
-  The object code form of an Application may incorporate material from
-a header file that is part of the Library.  You may convey such object
-code under terms of your choice, provided that, if the incorporated
-material is not limited to numerical parameters, data structure
-layouts and accessors, or small macros, inline functions and templates
-(ten or fewer lines in length), you do both of the following:
-
-   a) Give prominent notice with each copy of the object code that the
-   Library is used in it and that the Library and its use are
-   covered by this License.
-
-   b) Accompany the object code with a copy of the GNU GPL and this license
-   document.
-
-  4. Combined Works.
-
-  You may convey a Combined Work under terms of your choice that,
-taken together, effectively do not restrict modification of the
-portions of the Library contained in the Combined Work and reverse
-engineering for debugging such modifications, if you also do each of
-the following:
-
-   a) Give prominent notice with each copy of the Combined Work that
-   the Library is used in it and that the Library and its use are
-   covered by this License.
-
-   b) Accompany the Combined Work with a copy of the GNU GPL and this license
-   document.
-
-   c) For a Combined Work that displays copyright notices during
-   execution, include the copyright notice for the Library among
-   these notices, as well as a reference directing the user to the
-   copies of the GNU GPL and this license document.
-
-   d) Do one of the following:
-
-       0) Convey the Minimal Corresponding Source under the terms of this
-       License, and the Corresponding Application Code in a form
-       suitable for, and under terms that permit, the user to
-       recombine or relink the Application with a modified version of
-       the Linked Version to produce a modified Combined Work, in the
-       manner specified by section 6 of the GNU GPL for conveying
-       Corresponding Source.
-
-       1) Use a suitable shared library mechanism for linking with the
-       Library.  A suitable mechanism is one that (a) uses at run time
-       a copy of the Library already present on the user's computer
-       system, and (b) will operate properly with a modified version
-       of the Library that is interface-compatible with the Linked
-       Version. 
-
-   e) Provide Installation Information, but only if you would otherwise
-   be required to provide such information under section 6 of the
-   GNU GPL, and only to the extent that such information is
-   necessary to install and execute a modified version of the
-   Combined Work produced by recombining or relinking the
-   Application with a modified version of the Linked Version. (If
-   you use option 4d0, the Installation Information must accompany
-   the Minimal Corresponding Source and Corresponding Application
-   Code. If you use option 4d1, you must provide the Installation
-   Information in the manner specified by section 6 of the GNU GPL
-   for conveying Corresponding Source.)
-
-  5. Combined Libraries.
-
-  You may place library facilities that are a work based on the
-Library side by side in a single library together with other library
-facilities that are not Applications and are not covered by this
-License, and convey such a combined library under terms of your
-choice, if you do both of the following:
-
-   a) Accompany the combined library with a copy of the same work based
-   on the Library, uncombined with any other library facilities,
-   conveyed under the terms of this License.
-
-   b) Give prominent notice with the combined library that part of it
-   is a work based on the Library, and explaining where to find the
-   accompanying uncombined form of the same work.
-
-  6. Revised Versions of the GNU Lesser General Public License.
-
-  The Free Software Foundation may publish revised and/or new versions
-of the GNU Lesser General Public License from time to time. Such new
-versions will be similar in spirit to the present version, but may
-differ in detail to address new problems or concerns.
-
-  Each version is given a distinguishing version number. If the
-Library as you received it specifies that a certain numbered version
-of the GNU Lesser General Public License "or any later version"
-applies to it, you have the option of following the terms and
-conditions either of that published version or of any later version
-published by the Free Software Foundation. If the Library as you
-received it does not specify a version number of the GNU Lesser
-General Public License, you may choose any version of the GNU Lesser
-General Public License ever published by the Free Software Foundation.
-
-  If the Library as you received it specifies that a proxy can decide
-whether future versions of the GNU Lesser General Public License shall
-apply, that proxy's public statement of acceptance of any version is
-permanent authorization for you to choose that version for the
-Library.
+                  GNU LESSER GENERAL PUBLIC LICENSE\r
+                       Version 3, 29 June 2007\r
+\r
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\r
+ Everyone is permitted to copy and distribute verbatim copies\r
+ of this license document, but changing it is not allowed.\r
+\r
+\r
+  This version of the GNU Lesser General Public License incorporates\r
+the terms and conditions of version 3 of the GNU General Public\r
+License, supplemented by the additional permissions listed below.\r
+\r
+  0. Additional Definitions. \r
+\r
+  As used herein, "this License" refers to version 3 of the GNU Lesser\r
+General Public License, and the "GNU GPL" refers to version 3 of the GNU\r
+General Public License.\r
+\r
+  "The Library" refers to a covered work governed by this License,\r
+other than an Application or a Combined Work as defined below.\r
+\r
+  An "Application" is any work that makes use of an interface provided\r
+by the Library, but which is not otherwise based on the Library.\r
+Defining a subclass of a class defined by the Library is deemed a mode\r
+of using an interface provided by the Library.\r
+\r
+  A "Combined Work" is a work produced by combining or linking an\r
+Application with the Library.  The particular version of the Library\r
+with which the Combined Work was made is also called the "Linked\r
+Version".\r
+\r
+  The "Minimal Corresponding Source" for a Combined Work means the\r
+Corresponding Source for the Combined Work, excluding any source code\r
+for portions of the Combined Work that, considered in isolation, are\r
+based on the Application, and not on the Linked Version.\r
+\r
+  The "Corresponding Application Code" for a Combined Work means the\r
+object code and/or source code for the Application, including any data\r
+and utility programs needed for reproducing the Combined Work from the\r
+Application, but excluding the System Libraries of the Combined Work.\r
+\r
+  1. Exception to Section 3 of the GNU GPL.\r
+\r
+  You may convey a covered work under sections 3 and 4 of this License\r
+without being bound by section 3 of the GNU GPL.\r
+\r
+  2. Conveying Modified Versions.\r
+\r
+  If you modify a copy of the Library, and, in your modifications, a\r
+facility refers to a function or data to be supplied by an Application\r
+that uses the facility (other than as an argument passed when the\r
+facility is invoked), then you may convey a copy of the modified\r
+version:\r
+\r
+   a) under this License, provided that you make a good faith effort to\r
+   ensure that, in the event an Application does not supply the\r
+   function or data, the facility still operates, and performs\r
+   whatever part of its purpose remains meaningful, or\r
+\r
+   b) under the GNU GPL, with none of the additional permissions of\r
+   this License applicable to that copy.\r
+\r
+  3. Object Code Incorporating Material from Library Header Files.\r
+\r
+  The object code form of an Application may incorporate material from\r
+a header file that is part of the Library.  You may convey such object\r
+code under terms of your choice, provided that, if the incorporated\r
+material is not limited to numerical parameters, data structure\r
+layouts and accessors, or small macros, inline functions and templates\r
+(ten or fewer lines in length), you do both of the following:\r
+\r
+   a) Give prominent notice with each copy of the object code that the\r
+   Library is used in it and that the Library and its use are\r
+   covered by this License.\r
+\r
+   b) Accompany the object code with a copy of the GNU GPL and this license\r
+   document.\r
+\r
+  4. Combined Works.\r
+\r
+  You may convey a Combined Work under terms of your choice that,\r
+taken together, effectively do not restrict modification of the\r
+portions of the Library contained in the Combined Work and reverse\r
+engineering for debugging such modifications, if you also do each of\r
+the following:\r
+\r
+   a) Give prominent notice with each copy of the Combined Work that\r
+   the Library is used in it and that the Library and its use are\r
+   covered by this License.\r
+\r
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license\r
+   document.\r
+\r
+   c) For a Combined Work that displays copyright notices during\r
+   execution, include the copyright notice for the Library among\r
+   these notices, as well as a reference directing the user to the\r
+   copies of the GNU GPL and this license document.\r
+\r
+   d) Do one of the following:\r
+\r
+       0) Convey the Minimal Corresponding Source under the terms of this\r
+       License, and the Corresponding Application Code in a form\r
+       suitable for, and under terms that permit, the user to\r
+       recombine or relink the Application with a modified version of\r
+       the Linked Version to produce a modified Combined Work, in the\r
+       manner specified by section 6 of the GNU GPL for conveying\r
+       Corresponding Source.\r
+\r
+       1) Use a suitable shared library mechanism for linking with the\r
+       Library.  A suitable mechanism is one that (a) uses at run time\r
+       a copy of the Library already present on the user's computer\r
+       system, and (b) will operate properly with a modified version\r
+       of the Library that is interface-compatible with the Linked\r
+       Version. \r
+\r
+   e) Provide Installation Information, but only if you would otherwise\r
+   be required to provide such information under section 6 of the\r
+   GNU GPL, and only to the extent that such information is\r
+   necessary to install and execute a modified version of the\r
+   Combined Work produced by recombining or relinking the\r
+   Application with a modified version of the Linked Version. (If\r
+   you use option 4d0, the Installation Information must accompany\r
+   the Minimal Corresponding Source and Corresponding Application\r
+   Code. If you use option 4d1, you must provide the Installation\r
+   Information in the manner specified by section 6 of the GNU GPL\r
+   for conveying Corresponding Source.)\r
+\r
+  5. Combined Libraries.\r
+\r
+  You may place library facilities that are a work based on the\r
+Library side by side in a single library together with other library\r
+facilities that are not Applications and are not covered by this\r
+License, and convey such a combined library under terms of your\r
+choice, if you do both of the following:\r
+\r
+   a) Accompany the combined library with a copy of the same work based\r
+   on the Library, uncombined with any other library facilities,\r
+   conveyed under the terms of this License.\r
+\r
+   b) Give prominent notice with the combined library that part of it\r
+   is a work based on the Library, and explaining where to find the\r
+   accompanying uncombined form of the same work.\r
+\r
+  6. Revised Versions of the GNU Lesser General Public License.\r
+\r
+  The Free Software Foundation may publish revised and/or new versions\r
+of the GNU Lesser General Public License from time to time. Such new\r
+versions will be similar in spirit to the present version, but may\r
+differ in detail to address new problems or concerns.\r
+\r
+  Each version is given a distinguishing version number. If the\r
+Library as you received it specifies that a certain numbered version\r
+of the GNU Lesser General Public License "or any later version"\r
+applies to it, you have the option of following the terms and\r
+conditions either of that published version or of any later version\r
+published by the Free Software Foundation. If the Library as you\r
+received it does not specify a version number of the GNU Lesser\r
+General Public License, you may choose any version of the GNU Lesser\r
+General Public License ever published by the Free Software Foundation.\r
+\r
+  If the Library as you received it specifies that a proxy can decide\r
+whether future versions of the GNU Lesser General Public License shall\r
+apply, that proxy's public statement of acceptance of any version is\r
+permanent authorization for you to choose that version for the\r
+Library.\r
index 94a9ed0..818433e 100644 (file)
-                    GNU GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-                            Preamble
-
-  The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
-  The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works.  By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users.  We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors.  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
-  To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights.  Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received.  You must make sure that they, too, receive
-or can get the source code.  And you must show them these terms so they
-know their rights.
-
-  Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
-  For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software.  For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
-  Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so.  This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software.  The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable.  Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products.  If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
-  Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary.  To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-                       TERMS AND CONDITIONS
-
-  0. Definitions.
-
-  "This License" refers to version 3 of the GNU General Public License.
-
-  "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
-  "The Program" refers to any copyrightable work licensed under this
-License.  Each licensee is addressed as "you".  "Licensees" and
-"recipients" may be individuals or organizations.
-
-  To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy.  The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
-  A "covered work" means either the unmodified Program or a work based
-on the Program.
-
-  To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy.  Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
-  To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies.  Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
-  An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License.  If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
-  1. Source Code.
-
-  The "source code" for a work means the preferred form of the work
-for making modifications to it.  "Object code" means any non-source
-form of a work.
-
-  A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
-  The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form.  A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
-  The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities.  However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work.  For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
-  The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
-  The Corresponding Source for a work in source code form is that
-same work.
-
-  2. Basic Permissions.
-
-  All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met.  This License explicitly affirms your unlimited
-permission to run the unmodified Program.  The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work.  This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
-  You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force.  You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright.  Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
-  Conveying under any other circumstances is permitted solely under
-the conditions stated below.  Sublicensing is not allowed; section 10
-makes it unnecessary.
-
-  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
-  No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
-  When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
-  4. Conveying Verbatim Copies.
-
-  You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
-  You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
-  5. Conveying Modified Source Versions.
-
-  You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
-    a) The work must carry prominent notices stating that you modified
-    it, and giving a relevant date.
-
-    b) The work must carry prominent notices stating that it is
-    released under this License and any conditions added under section
-    7.  This requirement modifies the requirement in section 4 to
-    "keep intact all notices".
-
-    c) You must license the entire work, as a whole, under this
-    License to anyone who comes into possession of a copy.  This
-    License will therefore apply, along with any applicable section 7
-    additional terms, to the whole of the work, and all its parts,
-    regardless of how they are packaged.  This License gives no
-    permission to license the work in any other way, but it does not
-    invalidate such permission if you have separately received it.
-
-    d) If the work has interactive user interfaces, each must display
-    Appropriate Legal Notices; however, if the Program has interactive
-    interfaces that do not display Appropriate Legal Notices, your
-    work need not make them do so.
-
-  A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit.  Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
-  6. Conveying Non-Source Forms.
-
-  You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
-    a) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by the
-    Corresponding Source fixed on a durable physical medium
-    customarily used for software interchange.
-
-    b) Convey the object code in, or embodied in, a physical product
-    (including a physical distribution medium), accompanied by a
-    written offer, valid for at least three years and valid for as
-    long as you offer spare parts or customer support for that product
-    model, to give anyone who possesses the object code either (1) a
-    copy of the Corresponding Source for all the software in the
-    product that is covered by this License, on a durable physical
-    medium customarily used for software interchange, for a price no
-    more than your reasonable cost of physically performing this
-    conveying of source, or (2) access to copy the
-    Corresponding Source from a network server at no charge.
-
-    c) Convey individual copies of the object code with a copy of the
-    written offer to provide the Corresponding Source.  This
-    alternative is allowed only occasionally and noncommercially, and
-    only if you received the object code with such an offer, in accord
-    with subsection 6b.
-
-    d) Convey the object code by offering access from a designated
-    place (gratis or for a charge), and offer equivalent access to the
-    Corresponding Source in the same way through the same place at no
-    further charge.  You need not require recipients to copy the
-    Corresponding Source along with the object code.  If the place to
-    copy the object code is a network server, the Corresponding Source
-    may be on a different server (operated by you or a third party)
-    that supports equivalent copying facilities, provided you maintain
-    clear directions next to the object code saying where to find the
-    Corresponding Source.  Regardless of what server hosts the
-    Corresponding Source, you remain obligated to ensure that it is
-    available for as long as needed to satisfy these requirements.
-
-    e) Convey the object code using peer-to-peer transmission, provided
-    you inform other peers where the object code and Corresponding
-    Source of the work are being offered to the general public at no
-    charge under subsection 6d.
-
-  A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
-  A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling.  In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage.  For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product.  A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
-  "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source.  The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
-  If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information.  But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
-  The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed.  Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
-  Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
-  7. Additional Terms.
-
-  "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law.  If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
-  When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it.  (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.)  You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
-  Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
-    a) Disclaiming warranty or limiting liability differently from the
-    terms of sections 15 and 16 of this License; or
-
-    b) Requiring preservation of specified reasonable legal notices or
-    author attributions in that material or in the Appropriate Legal
-    Notices displayed by works containing it; or
-
-    c) Prohibiting misrepresentation of the origin of that material, or
-    requiring that modified versions of such material be marked in
-    reasonable ways as different from the original version; or
-
-    d) Limiting the use for publicity purposes of names of licensors or
-    authors of the material; or
-
-    e) Declining to grant rights under trademark law for use of some
-    trade names, trademarks, or service marks; or
-
-    f) Requiring indemnification of licensors and authors of that
-    material by anyone who conveys the material (or modified versions of
-    it) with contractual assumptions of liability to the recipient, for
-    any liability that these contractual assumptions directly impose on
-    those licensors and authors.
-
-  All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10.  If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term.  If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
-  If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
-  Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
-  8. Termination.
-
-  You may not propagate or modify a covered work except as expressly
-provided under this License.  Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
-  However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
-  Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
-  Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License.  If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
-  9. Acceptance Not Required for Having Copies.
-
-  You are not required to accept this License in order to receive or
-run a copy of the Program.  Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance.  However,
-nothing other than this License grants you permission to propagate or
-modify any covered work.  These actions infringe copyright if you do
-not accept this License.  Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
-  10. Automatic Licensing of Downstream Recipients.
-
-  Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License.  You are not responsible
-for enforcing compliance by third parties with this License.
-
-  An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations.  If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
-  You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License.  For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
-  11. Patents.
-
-  A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based.  The
-work thus licensed is called the contributor's "contributor version".
-
-  A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version.  For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
-  Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
-  In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement).  To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
-  If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients.  "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
-  If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
-  A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License.  You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
-  Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
-  12. No Surrender of Others' Freedom.
-
-  If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all.  For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
-  13. Use with the GNU Affero General Public License.
-
-  Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work.  The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
-  14. Revised Versions of this License.
-
-  The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-  Each version is given a distinguishing version number.  If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation.  If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
-  If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
-  Later license versions may give you additional or different
-permissions.  However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
-  15. Disclaimer of Warranty.
-
-  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
-  16. Limitation of Liability.
-
-  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
-  17. Interpretation of Sections 15 and 16.
-
-  If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
-                     END OF TERMS AND CONDITIONS
-
-            How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-Also add information on how to contact you by electronic and paper mail.
-
-  If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
-    <program>  Copyright (C) <year>  <name of author>
-    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
-  You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
-
-  The GNU General Public License does not permit incorporating your program
-into proprietary programs.  If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library.  If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.  But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+                    GNU GENERAL PUBLIC LICENSE\r
+                       Version 3, 29 June 2007\r
+\r
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\r
+ Everyone is permitted to copy and distribute verbatim copies\r
+ of this license document, but changing it is not allowed.\r
+\r
+                            Preamble\r
+\r
+  The GNU General Public License is a free, copyleft license for\r
+software and other kinds of works.\r
+\r
+  The licenses for most software and other practical works are designed\r
+to take away your freedom to share and change the works.  By contrast,\r
+the GNU General Public License is intended to guarantee your freedom to\r
+share and change all versions of a program--to make sure it remains free\r
+software for all its users.  We, the Free Software Foundation, use the\r
+GNU General Public License for most of our software; it applies also to\r
+any other work released this way by its authors.  You can apply it to\r
+your programs, too.\r
+\r
+  When we speak of free software, we are referring to freedom, not\r
+price.  Our General Public Licenses are designed to make sure that you\r
+have the freedom to distribute copies of free software (and charge for\r
+them if you wish), that you receive source code or can get it if you\r
+want it, that you can change the software or use pieces of it in new\r
+free programs, and that you know you can do these things.\r
+\r
+  To protect your rights, we need to prevent others from denying you\r
+these rights or asking you to surrender the rights.  Therefore, you have\r
+certain responsibilities if you distribute copies of the software, or if\r
+you modify it: responsibilities to respect the freedom of others.\r
+\r
+  For example, if you distribute copies of such a program, whether\r
+gratis or for a fee, you must pass on to the recipients the same\r
+freedoms that you received.  You must make sure that they, too, receive\r
+or can get the source code.  And you must show them these terms so they\r
+know their rights.\r
+\r
+  Developers that use the GNU GPL protect your rights with two steps:\r
+(1) assert copyright on the software, and (2) offer you this License\r
+giving you legal permission to copy, distribute and/or modify it.\r
+\r
+  For the developers' and authors' protection, the GPL clearly explains\r
+that there is no warranty for this free software.  For both users' and\r
+authors' sake, the GPL requires that modified versions be marked as\r
+changed, so that their problems will not be attributed erroneously to\r
+authors of previous versions.\r
+\r
+  Some devices are designed to deny users access to install or run\r
+modified versions of the software inside them, although the manufacturer\r
+can do so.  This is fundamentally incompatible with the aim of\r
+protecting users' freedom to change the software.  The systematic\r
+pattern of such abuse occurs in the area of products for individuals to\r
+use, which is precisely where it is most unacceptable.  Therefore, we\r
+have designed this version of the GPL to prohibit the practice for those\r
+products.  If such problems arise substantially in other domains, we\r
+stand ready to extend this provision to those domains in future versions\r
+of the GPL, as needed to protect the freedom of users.\r
+\r
+  Finally, every program is threatened constantly by software patents.\r
+States should not allow patents to restrict development and use of\r
+software on general-purpose computers, but in those that do, we wish to\r
+avoid the special danger that patents applied to a free program could\r
+make it effectively proprietary.  To prevent this, the GPL assures that\r
+patents cannot be used to render the program non-free.\r
+\r
+  The precise terms and conditions for copying, distribution and\r
+modification follow.\r
+\r
+                       TERMS AND CONDITIONS\r
+\r
+  0. Definitions.\r
+\r
+  "This License" refers to version 3 of the GNU General Public License.\r
+\r
+  "Copyright" also means copyright-like laws that apply to other kinds of\r
+works, such as semiconductor masks.\r
+\r
+  "The Program" refers to any copyrightable work licensed under this\r
+License.  Each licensee is addressed as "you".  "Licensees" and\r
+"recipients" may be individuals or organizations.\r
+\r
+  To "modify" a work means to copy from or adapt all or part of the work\r
+in a fashion requiring copyright permission, other than the making of an\r
+exact copy.  The resulting work is called a "modified version" of the\r
+earlier work or a work "based on" the earlier work.\r
+\r
+  A "covered work" means either the unmodified Program or a work based\r
+on the Program.\r
+\r
+  To "propagate" a work means to do anything with it that, without\r
+permission, would make you directly or secondarily liable for\r
+infringement under applicable copyright law, except executing it on a\r
+computer or modifying a private copy.  Propagation includes copying,\r
+distribution (with or without modification), making available to the\r
+public, and in some countries other activities as well.\r
+\r
+  To "convey" a work means any kind of propagation that enables other\r
+parties to make or receive copies.  Mere interaction with a user through\r
+a computer network, with no transfer of a copy, is not conveying.\r
+\r
+  An interactive user interface displays "Appropriate Legal Notices"\r
+to the extent that it includes a convenient and prominently visible\r
+feature that (1) displays an appropriate copyright notice, and (2)\r
+tells the user that there is no warranty for the work (except to the\r
+extent that warranties are provided), that licensees may convey the\r
+work under this License, and how to view a copy of this License.  If\r
+the interface presents a list of user commands or options, such as a\r
+menu, a prominent item in the list meets this criterion.\r
+\r
+  1. Source Code.\r
+\r
+  The "source code" for a work means the preferred form of the work\r
+for making modifications to it.  "Object code" means any non-source\r
+form of a work.\r
+\r
+  A "Standard Interface" means an interface that either is an official\r
+standard defined by a recognized standards body, or, in the case of\r
+interfaces specified for a particular programming language, one that\r
+is widely used among developers working in that language.\r
+\r
+  The "System Libraries" of an executable work include anything, other\r
+than the work as a whole, that (a) is included in the normal form of\r
+packaging a Major Component, but which is not part of that Major\r
+Component, and (b) serves only to enable use of the work with that\r
+Major Component, or to implement a Standard Interface for which an\r
+implementation is available to the public in source code form.  A\r
+"Major Component", in this context, means a major essential component\r
+(kernel, window system, and so on) of the specific operating system\r
+(if any) on which the executable work runs, or a compiler used to\r
+produce the work, or an object code interpreter used to run it.\r
+\r
+  The "Corresponding Source" for a work in object code form means all\r
+the source code needed to generate, install, and (for an executable\r
+work) run the object code and to modify the work, including scripts to\r
+control those activities.  However, it does not include the work's\r
+System Libraries, or general-purpose tools or generally available free\r
+programs which are used unmodified in performing those activities but\r
+which are not part of the work.  For example, Corresponding Source\r
+includes interface definition files associated with source files for\r
+the work, and the source code for shared libraries and dynamically\r
+linked subprograms that the work is specifically designed to require,\r
+such as by intimate data communication or control flow between those\r
+subprograms and other parts of the work.\r
+\r
+  The Corresponding Source need not include anything that users\r
+can regenerate automatically from other parts of the Corresponding\r
+Source.\r
+\r
+  The Corresponding Source for a work in source code form is that\r
+same work.\r
+\r
+  2. Basic Permissions.\r
+\r
+  All rights granted under this License are granted for the term of\r
+copyright on the Program, and are irrevocable provided the stated\r
+conditions are met.  This License explicitly affirms your unlimited\r
+permission to run the unmodified Program.  The output from running a\r
+covered work is covered by this License only if the output, given its\r
+content, constitutes a covered work.  This License acknowledges your\r
+rights of fair use or other equivalent, as provided by copyright law.\r
+\r
+  You may make, run and propagate covered works that you do not\r
+convey, without conditions so long as your license otherwise remains\r
+in force.  You may convey covered works to others for the sole purpose\r
+of having them make modifications exclusively for you, or provide you\r
+with facilities for running those works, provided that you comply with\r
+the terms of this License in conveying all material for which you do\r
+not control copyright.  Those thus making or running the covered works\r
+for you must do so exclusively on your behalf, under your direction\r
+and control, on terms that prohibit them from making any copies of\r
+your copyrighted material outside their relationship with you.\r
+\r
+  Conveying under any other circumstances is permitted solely under\r
+the conditions stated below.  Sublicensing is not allowed; section 10\r
+makes it unnecessary.\r
+\r
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\r
+\r
+  No covered work shall be deemed part of an effective technological\r
+measure under any applicable law fulfilling obligations under article\r
+11 of the WIPO copyright treaty adopted on 20 December 1996, or\r
+similar laws prohibiting or restricting circumvention of such\r
+measures.\r
+\r
+  When you convey a covered work, you waive any legal power to forbid\r
+circumvention of technological measures to the extent such circumvention\r
+is effected by exercising rights under this License with respect to\r
+the covered work, and you disclaim any intention to limit operation or\r
+modification of the work as a means of enforcing, against the work's\r
+users, your or third parties' legal rights to forbid circumvention of\r
+technological measures.\r
+\r
+  4. Conveying Verbatim Copies.\r
+\r
+  You may convey verbatim copies of the Program's source code as you\r
+receive it, in any medium, provided that you conspicuously and\r
+appropriately publish on each copy an appropriate copyright notice;\r
+keep intact all notices stating that this License and any\r
+non-permissive terms added in accord with section 7 apply to the code;\r
+keep intact all notices of the absence of any warranty; and give all\r
+recipients a copy of this License along with the Program.\r
+\r
+  You may charge any price or no price for each copy that you convey,\r
+and you may offer support or warranty protection for a fee.\r
+\r
+  5. Conveying Modified Source Versions.\r
+\r
+  You may convey a work based on the Program, or the modifications to\r
+produce it from the Program, in the form of source code under the\r
+terms of section 4, provided that you also meet all of these conditions:\r
+\r
+    a) The work must carry prominent notices stating that you modified\r
+    it, and giving a relevant date.\r
+\r
+    b) The work must carry prominent notices stating that it is\r
+    released under this License and any conditions added under section\r
+    7.  This requirement modifies the requirement in section 4 to\r
+    "keep intact all notices".\r
+\r
+    c) You must license the entire work, as a whole, under this\r
+    License to anyone who comes into possession of a copy.  This\r
+    License will therefore apply, along with any applicable section 7\r
+    additional terms, to the whole of the work, and all its parts,\r
+    regardless of how they are packaged.  This License gives no\r
+    permission to license the work in any other way, but it does not\r
+    invalidate such permission if you have separately received it.\r
+\r
+    d) If the work has interactive user interfaces, each must display\r
+    Appropriate Legal Notices; however, if the Program has interactive\r
+    interfaces that do not display Appropriate Legal Notices, your\r
+    work need not make them do so.\r
+\r
+  A compilation of a covered work with other separate and independent\r
+works, which are not by their nature extensions of the covered work,\r
+and which are not combined with it such as to form a larger program,\r
+in or on a volume of a storage or distribution medium, is called an\r
+"aggregate" if the compilation and its resulting copyright are not\r
+used to limit the access or legal rights of the compilation's users\r
+beyond what the individual works permit.  Inclusion of a covered work\r
+in an aggregate does not cause this License to apply to the other\r
+parts of the aggregate.\r
+\r
+  6. Conveying Non-Source Forms.\r
+\r
+  You may convey a covered work in object code form under the terms\r
+of sections 4 and 5, provided that you also convey the\r
+machine-readable Corresponding Source under the terms of this License,\r
+in one of these ways:\r
+\r
+    a) Convey the object code in, or embodied in, a physical product\r
+    (including a physical distribution medium), accompanied by the\r
+    Corresponding Source fixed on a durable physical medium\r
+    customarily used for software interchange.\r
+\r
+    b) Convey the object code in, or embodied in, a physical product\r
+    (including a physical distribution medium), accompanied by a\r
+    written offer, valid for at least three years and valid for as\r
+    long as you offer spare parts or customer support for that product\r
+    model, to give anyone who possesses the object code either (1) a\r
+    copy of the Corresponding Source for all the software in the\r
+    product that is covered by this License, on a durable physical\r
+    medium customarily used for software interchange, for a price no\r
+    more than your reasonable cost of physically performing this\r
+    conveying of source, or (2) access to copy the\r
+    Corresponding Source from a network server at no charge.\r
+\r
+    c) Convey individual copies of the object code with a copy of the\r
+    written offer to provide the Corresponding Source.  This\r
+    alternative is allowed only occasionally and noncommercially, and\r
+    only if you received the object code with such an offer, in accord\r
+    with subsection 6b.\r
+\r
+    d) Convey the object code by offering access from a designated\r
+    place (gratis or for a charge), and offer equivalent access to the\r
+    Corresponding Source in the same way through the same place at no\r
+    further charge.  You need not require recipients to copy the\r
+    Corresponding Source along with the object code.  If the place to\r
+    copy the object code is a network server, the Corresponding Source\r
+    may be on a different server (operated by you or a third party)\r
+    that supports equivalent copying facilities, provided you maintain\r
+    clear directions next to the object code saying where to find the\r
+    Corresponding Source.  Regardless of what server hosts the\r
+    Corresponding Source, you remain obligated to ensure that it is\r
+    available for as long as needed to satisfy these requirements.\r
+\r
+    e) Convey the object code using peer-to-peer transmission, provided\r
+    you inform other peers where the object code and Corresponding\r
+    Source of the work are being offered to the general public at no\r
+    charge under subsection 6d.\r
+\r
+  A separable portion of the object code, whose source code is excluded\r
+from the Corresponding Source as a System Library, need not be\r
+included in conveying the object code work.\r
+\r
+  A "User Product" is either (1) a "consumer product", which means any\r
+tangible personal property which is normally used for personal, family,\r
+or household purposes, or (2) anything designed or sold for incorporation\r
+into a dwelling.  In determining whether a product is a consumer product,\r
+doubtful cases shall be resolved in favor of coverage.  For a particular\r
+product received by a particular user, "normally used" refers to a\r
+typical or common use of that class of product, regardless of the status\r
+of the particular user or of the way in which the particular user\r
+actually uses, or expects or is expected to use, the product.  A product\r
+is a consumer product regardless of whether the product has substantial\r
+commercial, industrial or non-consumer uses, unless such uses represent\r
+the only significant mode of use of the product.\r
+\r
+  "Installation Information" for a User Product means any methods,\r
+procedures, authorization keys, or other information required to install\r
+and execute modified versions of a covered work in that User Product from\r
+a modified version of its Corresponding Source.  The information must\r
+suffice to ensure that the continued functioning of the modified object\r
+code is in no case prevented or interfered with solely because\r
+modification has been made.\r
+\r
+  If you convey an object code work under this section in, or with, or\r
+specifically for use in, a User Product, and the conveying occurs as\r
+part of a transaction in which the right of possession and use of the\r
+User Product is transferred to the recipient in perpetuity or for a\r
+fixed term (regardless of how the transaction is characterized), the\r
+Corresponding Source conveyed under this section must be accompanied\r
+by the Installation Information.  But this requirement does not apply\r
+if neither you nor any third party retains the ability to install\r
+modified object code on the User Product (for example, the work has\r
+been installed in ROM).\r
+\r
+  The requirement to provide Installation Information does not include a\r
+requirement to continue to provide support service, warranty, or updates\r
+for a work that has been modified or installed by the recipient, or for\r
+the User Product in which it has been modified or installed.  Access to a\r
+network may be denied when the modification itself materially and\r
+adversely affects the operation of the network or violates the rules and\r
+protocols for communication across the network.\r
+\r
+  Corresponding Source conveyed, and Installation Information provided,\r
+in accord with this section must be in a format that is publicly\r
+documented (and with an implementation available to the public in\r
+source code form), and must require no special password or key for\r
+unpacking, reading or copying.\r
+\r
+  7. Additional Terms.\r
+\r
+  "Additional permissions" are terms that supplement the terms of this\r
+License by making exceptions from one or more of its conditions.\r
+Additional permissions that are applicable to the entire Program shall\r
+be treated as though they were included in this License, to the extent\r
+that they are valid under applicable law.  If additional permissions\r
+apply only to part of the Program, that part may be used separately\r
+under those permissions, but the entire Program remains governed by\r
+this License without regard to the additional permissions.\r
+\r
+  When you convey a copy of a covered work, you may at your option\r
+remove any additional permissions from that copy, or from any part of\r
+it.  (Additional permissions may be written to require their own\r
+removal in certain cases when you modify the work.)  You may place\r
+additional permissions on material, added by you to a covered work,\r
+for which you have or can give appropriate copyright permission.\r
+\r
+  Notwithstanding any other provision of this License, for material you\r
+add to a covered work, you may (if authorized by the copyright holders of\r
+that material) supplement the terms of this License with terms:\r
+\r
+    a) Disclaiming warranty or limiting liability differently from the\r
+    terms of sections 15 and 16 of this License; or\r
+\r
+    b) Requiring preservation of specified reasonable legal notices or\r
+    author attributions in that material or in the Appropriate Legal\r
+    Notices displayed by works containing it; or\r
+\r
+    c) Prohibiting misrepresentation of the origin of that material, or\r
+    requiring that modified versions of such material be marked in\r
+    reasonable ways as different from the original version; or\r
+\r
+    d) Limiting the use for publicity purposes of names of licensors or\r
+    authors of the material; or\r
+\r
+    e) Declining to grant rights under trademark law for use of some\r
+    trade names, trademarks, or service marks; or\r
+\r
+    f) Requiring indemnification of licensors and authors of that\r
+    material by anyone who conveys the material (or modified versions of\r
+    it) with contractual assumptions of liability to the recipient, for\r
+    any liability that these contractual assumptions directly impose on\r
+    those licensors and authors.\r
+\r
+  All other non-permissive additional terms are considered "further\r
+restrictions" within the meaning of section 10.  If the Program as you\r
+received it, or any part of it, contains a notice stating that it is\r
+governed by this License along with a term that is a further\r
+restriction, you may remove that term.  If a license document contains\r
+a further restriction but permits relicensing or conveying under this\r
+License, you may add to a covered work material governed by the terms\r
+of that license document, provided that the further restriction does\r
+not survive such relicensing or conveying.\r
+\r
+  If you add terms to a covered work in accord with this section, you\r
+must place, in the relevant source files, a statement of the\r
+additional terms that apply to those files, or a notice indicating\r
+where to find the applicable terms.\r
+\r
+  Additional terms, permissive or non-permissive, may be stated in the\r
+form of a separately written license, or stated as exceptions;\r
+the above requirements apply either way.\r
+\r
+  8. Termination.\r
+\r
+  You may not propagate or modify a covered work except as expressly\r
+provided under this License.  Any attempt otherwise to propagate or\r
+modify it is void, and will automatically terminate your rights under\r
+this License (including any patent licenses granted under the third\r
+paragraph of section 11).\r
+\r
+  However, if you cease all violation of this License, then your\r
+license from a particular copyright holder is reinstated (a)\r
+provisionally, unless and until the copyright holder explicitly and\r
+finally terminates your license, and (b) permanently, if the copyright\r
+holder fails to notify you of the violation by some reasonable means\r
+prior to 60 days after the cessation.\r
+\r
+  Moreover, your license from a particular copyright holder is\r
+reinstated permanently if the copyright holder notifies you of the\r
+violation by some reasonable means, this is the first time you have\r
+received notice of violation of this License (for any work) from that\r
+copyright holder, and you cure the violation prior to 30 days after\r
+your receipt of the notice.\r
+\r
+  Termination of your rights under this section does not terminate the\r
+licenses of parties who have received copies or rights from you under\r
+this License.  If your rights have been terminated and not permanently\r
+reinstated, you do not qualify to receive new licenses for the same\r
+material under section 10.\r
+\r
+  9. Acceptance Not Required for Having Copies.\r
+\r
+  You are not required to accept this License in order to receive or\r
+run a copy of the Program.  Ancillary propagation of a covered work\r
+occurring solely as a consequence of using peer-to-peer transmission\r
+to receive a copy likewise does not require acceptance.  However,\r
+nothing other than this License grants you permission to propagate or\r
+modify any covered work.  These actions infringe copyright if you do\r
+not accept this License.  Therefore, by modifying or propagating a\r
+covered work, you indicate your acceptance of this License to do so.\r
+\r
+  10. Automatic Licensing of Downstream Recipients.\r
+\r
+  Each time you convey a covered work, the recipient automatically\r
+receives a license from the original licensors, to run, modify and\r
+propagate that work, subject to this License.  You are not responsible\r
+for enforcing compliance by third parties with this License.\r
+\r
+  An "entity transaction" is a transaction transferring control of an\r
+organization, or substantially all assets of one, or subdividing an\r
+organization, or merging organizations.  If propagation of a covered\r
+work results from an entity transaction, each party to that\r
+transaction who receives a copy of the work also receives whatever\r
+licenses to the work the party's predecessor in interest had or could\r
+give under the previous paragraph, plus a right to possession of the\r
+Corresponding Source of the work from the predecessor in interest, if\r
+the predecessor has it or can get it with reasonable efforts.\r
+\r
+  You may not impose any further restrictions on the exercise of the\r
+rights granted or affirmed under this License.  For example, you may\r
+not impose a license fee, royalty, or other charge for exercise of\r
+rights granted under this License, and you may not initiate litigation\r
+(including a cross-claim or counterclaim in a lawsuit) alleging that\r
+any patent claim is infringed by making, using, selling, offering for\r
+sale, or importing the Program or any portion of it.\r
+\r
+  11. Patents.\r
+\r
+  A "contributor" is a copyright holder who authorizes use under this\r
+License of the Program or a work on which the Program is based.  The\r
+work thus licensed is called the contributor's "contributor version".\r
+\r
+  A contributor's "essential patent claims" are all patent claims\r
+owned or controlled by the contributor, whether already acquired or\r
+hereafter acquired, that would be infringed by some manner, permitted\r
+by this License, of making, using, or selling its contributor version,\r
+but do not include claims that would be infringed only as a\r
+consequence of further modification of the contributor version.  For\r
+purposes of this definition, "control" includes the right to grant\r
+patent sublicenses in a manner consistent with the requirements of\r
+this License.\r
+\r
+  Each contributor grants you a non-exclusive, worldwide, royalty-free\r
+patent license under the contributor's essential patent claims, to\r
+make, use, sell, offer for sale, import and otherwise run, modify and\r
+propagate the contents of its contributor version.\r
+\r
+  In the following three paragraphs, a "patent license" is any express\r
+agreement or commitment, however denominated, not to enforce a patent\r
+(such as an express permission to practice a patent or covenant not to\r
+sue for patent infringement).  To "grant" such a patent license to a\r
+party means to make such an agreement or commitment not to enforce a\r
+patent against the party.\r
+\r
+  If you convey a covered work, knowingly relying on a patent license,\r
+and the Corresponding Source of the work is not available for anyone\r
+to copy, free of charge and under the terms of this License, through a\r
+publicly available network server or other readily accessible means,\r
+then you must either (1) cause the Corresponding Source to be so\r
+available, or (2) arrange to deprive yourself of the benefit of the\r
+patent license for this particular work, or (3) arrange, in a manner\r
+consistent with the requirements of this License, to extend the patent\r
+license to downstream recipients.  "Knowingly relying" means you have\r
+actual knowledge that, but for the patent license, your conveying the\r
+covered work in a country, or your recipient's use of the covered work\r
+in a country, would infringe one or more identifiable patents in that\r
+country that you have reason to believe are valid.\r
+\r
+  If, pursuant to or in connection with a single transaction or\r
+arrangement, you convey, or propagate by procuring conveyance of, a\r
+covered work, and grant a patent license to some of the parties\r
+receiving the covered work authorizing them to use, propagate, modify\r
+or convey a specific copy of the covered work, then the patent license\r
+you grant is automatically extended to all recipients of the covered\r
+work and works based on it.\r
+\r
+  A patent license is "discriminatory" if it does not include within\r
+the scope of its coverage, prohibits the exercise of, or is\r
+conditioned on the non-exercise of one or more of the rights that are\r
+specifically granted under this License.  You may not convey a covered\r
+work if you are a party to an arrangement with a third party that is\r
+in the business of distributing software, under which you make payment\r
+to the third party based on the extent of your activity of conveying\r
+the work, and under which the third party grants, to any of the\r
+parties who would receive the covered work from you, a discriminatory\r
+patent license (a) in connection with copies of the covered work\r
+conveyed by you (or copies made from those copies), or (b) primarily\r
+for and in connection with specific products or compilations that\r
+contain the covered work, unless you entered into that arrangement,\r
+or that patent license was granted, prior to 28 March 2007.\r
+\r
+  Nothing in this License shall be construed as excluding or limiting\r
+any implied license or other defenses to infringement that may\r
+otherwise be available to you under applicable patent law.\r
+\r
+  12. No Surrender of Others' Freedom.\r
+\r
+  If conditions are imposed on you (whether by court order, agreement or\r
+otherwise) that contradict the conditions of this License, they do not\r
+excuse you from the conditions of this License.  If you cannot convey a\r
+covered work so as to satisfy simultaneously your obligations under this\r
+License and any other pertinent obligations, then as a consequence you may\r
+not convey it at all.  For example, if you agree to terms that obligate you\r
+to collect a royalty for further conveying from those to whom you convey\r
+the Program, the only way you could satisfy both those terms and this\r
+License would be to refrain entirely from conveying the Program.\r
+\r
+  13. Use with the GNU Affero General Public License.\r
+\r
+  Notwithstanding any other provision of this License, you have\r
+permission to link or combine any covered work with a work licensed\r
+under version 3 of the GNU Affero General Public License into a single\r
+combined work, and to convey the resulting work.  The terms of this\r
+License will continue to apply to the part which is the covered work,\r
+but the special requirements of the GNU Affero General Public License,\r
+section 13, concerning interaction through a network will apply to the\r
+combination as such.\r
+\r
+  14. Revised Versions of this License.\r
+\r
+  The Free Software Foundation may publish revised and/or new versions of\r
+the GNU General Public License from time to time.  Such new versions will\r
+be similar in spirit to the present version, but may differ in detail to\r
+address new problems or concerns.\r
+\r
+  Each version is given a distinguishing version number.  If the\r
+Program specifies that a certain numbered version of the GNU General\r
+Public License "or any later version" applies to it, you have the\r
+option of following the terms and conditions either of that numbered\r
+version or of any later version published by the Free Software\r
+Foundation.  If the Program does not specify a version number of the\r
+GNU General Public License, you may choose any version ever published\r
+by the Free Software Foundation.\r
+\r
+  If the Program specifies that a proxy can decide which future\r
+versions of the GNU General Public License can be used, that proxy's\r
+public statement of acceptance of a version permanently authorizes you\r
+to choose that version for the Program.\r
+\r
+  Later license versions may give you additional or different\r
+permissions.  However, no additional obligations are imposed on any\r
+author or copyright holder as a result of your choosing to follow a\r
+later version.\r
+\r
+  15. Disclaimer of Warranty.\r
+\r
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\r
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\r
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY\r
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\r
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\r
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\r
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r
+\r
+  16. Limitation of Liability.\r
+\r
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\r
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\r
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\r
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\r
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\r
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\r
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\r
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\r
+SUCH DAMAGES.\r
+\r
+  17. Interpretation of Sections 15 and 16.\r
+\r
+  If the disclaimer of warranty and limitation of liability provided\r
+above cannot be given local legal effect according to their terms,\r
+reviewing courts shall apply local law that most closely approximates\r
+an absolute waiver of all civil liability in connection with the\r
+Program, unless a warranty or assumption of liability accompanies a\r
+copy of the Program in return for a fee.\r
+\r
+                     END OF TERMS AND CONDITIONS\r
+\r
+            How to Apply These Terms to Your New Programs\r
+\r
+  If you develop a new program, and you want it to be of the greatest\r
+possible use to the public, the best way to achieve this is to make it\r
+free software which everyone can redistribute and change under these terms.\r
+\r
+  To do so, attach the following notices to the program.  It is safest\r
+to attach them to the start of each source file to most effectively\r
+state the exclusion of warranty; and each file should have at least\r
+the "copyright" line and a pointer to where the full notice is found.\r
+\r
+    <one line to give the program's name and a brief idea of what it does.>\r
+    Copyright (C) <year>  <name of author>\r
+\r
+    This program is free software: you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation, either version 3 of the License, or\r
+    (at your option) any later version.\r
+\r
+    This program is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+\r
+Also add information on how to contact you by electronic and paper mail.\r
+\r
+  If the program does terminal interaction, make it output a short\r
+notice like this when it starts in an interactive mode:\r
+\r
+    <program>  Copyright (C) <year>  <name of author>\r
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\r
+    This is free software, and you are welcome to redistribute it\r
+    under certain conditions; type `show c' for details.\r
+\r
+The hypothetical commands `show w' and `show c' should show the appropriate\r
+parts of the General Public License.  Of course, your program's commands\r
+might be different; for a GUI interface, you would use an "about box".\r
+\r
+  You should also get your employer (if you work as a programmer) or school,\r
+if any, to sign a "copyright disclaimer" for the program, if necessary.\r
+For more information on this, and how to apply and follow the GNU GPL, see\r
+<http://www.gnu.org/licenses/>.\r
+\r
+  The GNU General Public License does not permit incorporating your program\r
+into proprietary programs.  If your program is a subroutine library, you\r
+may consider it more useful to permit linking proprietary applications with\r
+the library.  If this is what you want to do, use the GNU Lesser General\r
+Public License instead of this License.  But first, please read\r
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.\r
index 21e1542..f475f44 100644 (file)
@@ -38,7 +38,7 @@
 \r
        /* Includes: */\r
                #include <avr/io.h>\r
 \r
        /* Includes: */\r
                #include <avr/io.h>\r
-               
+               \r
                #include "Descriptors.h"\r
 \r
                #include <LUFA/Common/Common.h>\r
                #include "Descriptors.h"\r
 \r
                #include <LUFA/Common/Common.h>\r
index 5495884..196b5f6 100644 (file)
@@ -42,7 +42,7 @@
 \r
                #include <LUFA/Drivers/USB/USB.h>\r
                #include <LUFA/Drivers/USB/Class/MassStorage.h>\r
 \r
                #include <LUFA/Drivers/USB/USB.h>\r
                #include <LUFA/Drivers/USB/Class/MassStorage.h>\r
-
+\r
                #include "../Descriptors.h"\r
                #include "DataflashManager.h"\r
        \r
                #include "../Descriptors.h"\r
                #include "DataflashManager.h"\r
        \r
index 299a747..4507148 100644 (file)
@@ -1,38 +1,38 @@
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <avr/interrupt.h>
-#include <avr/io.h>
-#include <avr/sfr_defs.h>
-
-#include "clock.h"
-
-//Counted time
-volatile clock_time_t clock_datetime = 0;
-
-//Overflow interrupt
-ISR(TIMER1_COMPA_vect)
+#include <stdint.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+#include <avr/interrupt.h>\r
+#include <avr/io.h>\r
+#include <avr/sfr_defs.h>\r
+\r
+#include "clock.h"\r
+\r
+//Counted time\r
+volatile clock_time_t clock_datetime = 0;\r
+\r
+//Overflow interrupt\r
+ISR(TIMER1_COMPA_vect)\r
 {\r
 {\r
-       clock_datetime += 1;
-}
-
-//Initialise the clock
+       clock_datetime += 1;\r
+}\r
+\r
+//Initialise the clock\r
 void clock_init()\r
 {\r
 void clock_init()\r
 {\r
-       OCR1A  = ((F_CPU / 1024) / 100);
-       TCCR1B = ((1 << WGM12) | (1 << CS12) | (1 << CS10));
-       TIMSK1 = (1 << OCIE1A);
-}
-
-//Return time
+       OCR1A  = ((F_CPU / 1024) / 100);\r
+       TCCR1B = ((1 << WGM12) | (1 << CS12) | (1 << CS10));\r
+       TIMSK1 = (1 << OCIE1A);\r
+}\r
+\r
+//Return time\r
 clock_time_t clock_time()\r
 {\r
 clock_time_t clock_time()\r
 {\r
-       clock_time_t time;
-
-       ATOMIC_BLOCK(ATOMIC_FORCEON)
-       {
-               time = clock_datetime;
-       }
-
-       return time;
-}
+       clock_time_t time;\r
+\r
+       ATOMIC_BLOCK(ATOMIC_FORCEON)\r
+       {\r
+               time = clock_datetime;\r
+       }\r
+\r
+       return time;\r
+}\r
index 3e42e4a..b585f47 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef __CLOCK_ARCH_H__\r
 #define __CLOCK_ARCH_H__\r
 #ifndef __CLOCK_ARCH_H__\r
 #define __CLOCK_ARCH_H__\r
-
+\r
 #include <stdint.h>\r
 #include <util/atomic.h>\r
 \r
 #include <stdint.h>\r
 #include <util/atomic.h>\r
 \r
index 74eedf6..8c270b2 100644 (file)
-/**
- * \addtogroup timer
- * @{
- */
-
-/**
- * \file
- * Timer library implementation.
- * \author
- * Adam Dunkels <adam@sics.se>
- */
-
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
- */
-
-#include "clock.h"
-#include "timer.h"
-
-/*---------------------------------------------------------------------------*/
-/**
- * Set a timer.
- *
- * This function is used to set a timer for a time sometime in the
- * future. The function timer_expired() will evaluate to true after
- * the timer has expired.
- *
- * \param t A pointer to the timer
- * \param interval The interval before the timer expires.
- *
- */
-void
-timer_set(struct timer *t, clock_time_t interval)
-{
-  t->interval = interval;
-  t->start = clock_time();
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Reset the timer with the same interval.
- *
- * This function resets the timer with the same interval that was
- * given to the timer_set() function. The start point of the interval
- * is the exact time that the timer last expired. Therefore, this
- * function will cause the timer to be stable over time, unlike the
- * timer_rester() function.
- *
- * \param t A pointer to the timer.
- *
- * \sa timer_restart()
- */
-void
-timer_reset(struct timer *t)
-{
-  t->start += t->interval;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Restart the timer from the current point in time
- *
- * This function restarts a timer with the same interval that was
- * given to the timer_set() function. The timer will start at the
- * current time.
- *
- * \note A periodic timer will drift if this function is used to reset
- * it. For preioric timers, use the timer_reset() function instead.
- *
- * \param t A pointer to the timer.
- *
- * \sa timer_reset()
- */
-void
-timer_restart(struct timer *t)
-{
-  t->start = clock_time();
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Check if a timer has expired.
- *
- * This function tests if a timer has expired and returns true or
- * false depending on its status.
- *
- * \param t A pointer to the timer
- *
- * \return Non-zero if the timer has expired, zero otherwise.
- *
- */
-int
-timer_expired(struct timer *t)
-{
-  return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
-}
-/*---------------------------------------------------------------------------*/
-
-/** @} */
+/**\r
+ * \addtogroup timer\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Timer library implementation.\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $\r
+ */\r
+\r
+#include "clock.h"\r
+#include "timer.h"\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Set a timer.\r
+ *\r
+ * This function is used to set a timer for a time sometime in the\r
+ * future. The function timer_expired() will evaluate to true after\r
+ * the timer has expired.\r
+ *\r
+ * \param t A pointer to the timer\r
+ * \param interval The interval before the timer expires.\r
+ *\r
+ */\r
+void\r
+timer_set(struct timer *t, clock_time_t interval)\r
+{\r
+  t->interval = interval;\r
+  t->start = clock_time();\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Reset the timer with the same interval.\r
+ *\r
+ * This function resets the timer with the same interval that was\r
+ * given to the timer_set() function. The start point of the interval\r
+ * is the exact time that the timer last expired. Therefore, this\r
+ * function will cause the timer to be stable over time, unlike the\r
+ * timer_rester() function.\r
+ *\r
+ * \param t A pointer to the timer.\r
+ *\r
+ * \sa timer_restart()\r
+ */\r
+void\r
+timer_reset(struct timer *t)\r
+{\r
+  t->start += t->interval;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Restart the timer from the current point in time\r
+ *\r
+ * This function restarts a timer with the same interval that was\r
+ * given to the timer_set() function. The timer will start at the\r
+ * current time.\r
+ *\r
+ * \note A periodic timer will drift if this function is used to reset\r
+ * it. For preioric timers, use the timer_reset() function instead.\r
+ *\r
+ * \param t A pointer to the timer.\r
+ *\r
+ * \sa timer_reset()\r
+ */\r
+void\r
+timer_restart(struct timer *t)\r
+{\r
+  t->start = clock_time();\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/**\r
+ * Check if a timer has expired.\r
+ *\r
+ * This function tests if a timer has expired and returns true or\r
+ * false depending on its status.\r
+ *\r
+ * \param t A pointer to the timer\r
+ *\r
+ * \return Non-zero if the timer has expired, zero otherwise.\r
+ *\r
+ */\r
+int\r
+timer_expired(struct timer *t)\r
+{\r
+  return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+\r
+/** @} */\r
index 057bea4..e28e3ca 100644 (file)
@@ -1,86 +1,86 @@
-/**
- * \defgroup timer Timer library
- *
- * The timer library provides functions for setting, resetting and
- * restarting timers, and for checking if a timer has expired. An
- * application must "manually" check if its timers have expired; this
- * is not done automatically.
- *
- * A timer is declared as a \c struct \c timer and all access to the
- * timer is made by a pointer to the declared timer.
- *
- * \note The timer library uses the \ref clock "Clock library" to
- * measure time. Intervals should be specified in the format used by
- * the clock library.
- *
- * @{
- */
-
-
-/**
- * \file
- * Timer library header file.
- * \author
- * Adam Dunkels <adam@sics.se>
- */
-
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: timer.h,v 1.3 2006/06/11 21:46:39 adam Exp $
- */
-#ifndef __TIMER_H__
-#define __TIMER_H__
-
-#include "clock.h"
-
-/**
- * A timer.
- *
- * This structure is used for declaring a timer. The timer must be set
- * with timer_set() before it can be used.
- *
- * \hideinitializer
- */
-struct timer {
-  clock_time_t start;
-  clock_time_t interval;
-};
-
-void timer_set(struct timer *t, clock_time_t interval);
-void timer_reset(struct timer *t);
-void timer_restart(struct timer *t);
-int timer_expired(struct timer *t);
-
-#endif /* __TIMER_H__ */
-
-/** @} */
+/**\r
+ * \defgroup timer Timer library\r
+ *\r
+ * The timer library provides functions for setting, resetting and\r
+ * restarting timers, and for checking if a timer has expired. An\r
+ * application must "manually" check if its timers have expired; this\r
+ * is not done automatically.\r
+ *\r
+ * A timer is declared as a \c struct \c timer and all access to the\r
+ * timer is made by a pointer to the declared timer.\r
+ *\r
+ * \note The timer library uses the \ref clock "Clock library" to\r
+ * measure time. Intervals should be specified in the format used by\r
+ * the clock library.\r
+ *\r
+ * @{\r
+ */\r
+\r
+\r
+/**\r
+ * \file\r
+ * Timer library header file.\r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: timer.h,v 1.3 2006/06/11 21:46:39 adam Exp $\r
+ */\r
+#ifndef __TIMER_H__\r
+#define __TIMER_H__\r
+\r
+#include "clock.h"\r
+\r
+/**\r
+ * A timer.\r
+ *\r
+ * This structure is used for declaring a timer. The timer must be set\r
+ * with timer_set() before it can be used.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+struct timer {\r
+  clock_time_t start;\r
+  clock_time_t interval;\r
+};\r
+\r
+void timer_set(struct timer *t, clock_time_t interval);\r
+void timer_reset(struct timer *t);\r
+void timer_restart(struct timer *t);\r
+int timer_expired(struct timer *t);\r
+\r
+#endif /* __TIMER_H__ */\r
+\r
+/** @} */\r
index 5924fab..9b1d1ce 100644 (file)
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: uip-split.c,v 1.2 2008/10/14 13:39:12 julienabeille Exp $
- */
-
-#include "uip-split.h"
-
-
-#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
-
-/*-----------------------------------------------------------------------------*/
-void
-uip_split_output(void)
-{
-#if UIP_TCP
-  u16_t tcplen, len1, len2;
-
-  /* We only try to split maximum sized TCP segments. */
-  if(BUF->proto == UIP_PROTO_TCP  && uip_len == UIP_BUFSIZE) {
-  
-    tcplen = uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN;
-    /* Split the segment in two. If the original packet length was
-       odd, we make the second packet one byte larger. */
-    len1 = len2 = tcplen / 2;
-    if(len1 + len2 < tcplen) {
-      ++len2;
-    }
-
-    /* Create the first packet. This is done by altering the length
-       field of the IP header and updating the checksums. */
-    uip_len = len1 + UIP_TCPIP_HLEN + UIP_LLH_LEN;
-#if UIP_CONF_IPV6
-    /* For IPv6, the IP length field does not include the IPv6 IP header
-       length. */
-    BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
-    BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
-#else /* UIP_CONF_IPV6 */
-    BUF->len[0] = (uip_len - UIP_LLH_LEN) >> 8;
-    BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;
-#endif /* UIP_CONF_IPV6 */
-    
-    /* Recalculate the TCP checksum. */
-    BUF->tcpchksum = 0;
-    BUF->tcpchksum = ~(uip_tcpchksum());
-
-#if !UIP_CONF_IPV6
-    /* Recalculate the IP checksum. */
-    BUF->ipchksum = 0;
-    BUF->ipchksum = ~(uip_ipchksum());
-#endif /* UIP_CONF_IPV6 */
-    
-    /* Transmit the first packet. */
-#if UIP_CONF_IPV6
-    tcpip_ipv6_output();
-#else
-       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);
-#endif /* UIP_CONF_IPV6 */
-   
-    /* Now, create the second packet. To do this, it is not enough to
-       just alter the length field, but we must also update the TCP
-       sequence number and point the uip_appdata to a new place in
-       memory. This place is detemined by the length of the first
-       packet (len1). */
-    uip_len = len2 + UIP_TCPIP_HLEN + UIP_LLH_LEN;
-#if UIP_CONF_IPV6
-    /* For IPv6, the IP length field does not include the IPv6 IP header
-       length. */
-    BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
-    BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
-#else /* UIP_CONF_IPV6 */
-    BUF->len[0] = (uip_len  - UIP_LLH_LEN) >> 8;
-    BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;
-#endif /* UIP_CONF_IPV6 */
-    
-    memcpy(uip_appdata, (u8_t *)uip_appdata + len1, len2);
-
-    uip_add32(BUF->seqno, len1);
-    BUF->seqno[0] = uip_acc32[0];
-    BUF->seqno[1] = uip_acc32[1];
-    BUF->seqno[2] = uip_acc32[2];
-    BUF->seqno[3] = uip_acc32[3];
-    
-    /* Recalculate the TCP checksum. */
-    BUF->tcpchksum = 0;
-    BUF->tcpchksum = ~(uip_tcpchksum());
-
-#if !UIP_CONF_IPV6
-    /* Recalculate the IP checksum. */
-    BUF->ipchksum = 0;
-    BUF->ipchksum = ~(uip_ipchksum());
-#endif /* UIP_CONF_IPV6 */
-
-    /* Transmit the second packet. */
-#if UIP_CONF_IPV6
-    tcpip_ipv6_output();
-#else
-       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);
-#endif /* UIP_CONF_IPV6 */
-    return;
-  }
-#endif /* UIP_TCP */
-
-  /*    uip_fw_output();*/
-#if UIP_CONF_IPV6
-       tcpip_ipv6_output();
-#else
-       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);
-#endif /* UIP_CONF_IPV6 */
-}
-
-/*-----------------------------------------------------------------------------*/
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ * This file is part of the Contiki operating system.\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: uip-split.c,v 1.2 2008/10/14 13:39:12 julienabeille Exp $\r
+ */\r
+\r
+#include "uip-split.h"\r
+\r
+\r
+#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
+\r
+/*-----------------------------------------------------------------------------*/\r
+void\r
+uip_split_output(void)\r
+{\r
+#if UIP_TCP\r
+  u16_t tcplen, len1, len2;\r
+\r
+  /* We only try to split maximum sized TCP segments. */\r
+  if(BUF->proto == UIP_PROTO_TCP  && uip_len == UIP_BUFSIZE) {\r
+  \r
+    tcplen = uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN;\r
+    /* Split the segment in two. If the original packet length was\r
+       odd, we make the second packet one byte larger. */\r
+    len1 = len2 = tcplen / 2;\r
+    if(len1 + len2 < tcplen) {\r
+      ++len2;\r
+    }\r
+\r
+    /* Create the first packet. This is done by altering the length\r
+       field of the IP header and updating the checksums. */\r
+    uip_len = len1 + UIP_TCPIP_HLEN + UIP_LLH_LEN;\r
+#if UIP_CONF_IPV6\r
+    /* For IPv6, the IP length field does not include the IPv6 IP header\r
+       length. */\r
+    BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);\r
+    BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);\r
+#else /* UIP_CONF_IPV6 */\r
+    BUF->len[0] = (uip_len - UIP_LLH_LEN) >> 8;\r
+    BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;\r
+#endif /* UIP_CONF_IPV6 */\r
+    \r
+    /* Recalculate the TCP checksum. */\r
+    BUF->tcpchksum = 0;\r
+    BUF->tcpchksum = ~(uip_tcpchksum());\r
+\r
+#if !UIP_CONF_IPV6\r
+    /* Recalculate the IP checksum. */\r
+    BUF->ipchksum = 0;\r
+    BUF->ipchksum = ~(uip_ipchksum());\r
+#endif /* UIP_CONF_IPV6 */\r
+    \r
+    /* Transmit the first packet. */\r
+#if UIP_CONF_IPV6\r
+    tcpip_ipv6_output();\r
+#else\r
+       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+#endif /* UIP_CONF_IPV6 */\r
+   \r
+    /* Now, create the second packet. To do this, it is not enough to\r
+       just alter the length field, but we must also update the TCP\r
+       sequence number and point the uip_appdata to a new place in\r
+       memory. This place is detemined by the length of the first\r
+       packet (len1). */\r
+    uip_len = len2 + UIP_TCPIP_HLEN + UIP_LLH_LEN;\r
+#if UIP_CONF_IPV6\r
+    /* For IPv6, the IP length field does not include the IPv6 IP header\r
+       length. */\r
+    BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);\r
+    BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);\r
+#else /* UIP_CONF_IPV6 */\r
+    BUF->len[0] = (uip_len  - UIP_LLH_LEN) >> 8;\r
+    BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;\r
+#endif /* UIP_CONF_IPV6 */\r
+    \r
+    memcpy(uip_appdata, (u8_t *)uip_appdata + len1, len2);\r
+\r
+    uip_add32(BUF->seqno, len1);\r
+    BUF->seqno[0] = uip_acc32[0];\r
+    BUF->seqno[1] = uip_acc32[1];\r
+    BUF->seqno[2] = uip_acc32[2];\r
+    BUF->seqno[3] = uip_acc32[3];\r
+    \r
+    /* Recalculate the TCP checksum. */\r
+    BUF->tcpchksum = 0;\r
+    BUF->tcpchksum = ~(uip_tcpchksum());\r
+\r
+#if !UIP_CONF_IPV6\r
+    /* Recalculate the IP checksum. */\r
+    BUF->ipchksum = 0;\r
+    BUF->ipchksum = ~(uip_ipchksum());\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+    /* Transmit the second packet. */\r
+#if UIP_CONF_IPV6\r
+    tcpip_ipv6_output();\r
+#else\r
+       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+#endif /* UIP_CONF_IPV6 */\r
+    return;\r
+  }\r
+#endif /* UIP_TCP */\r
+\r
+  /*    uip_fw_output();*/\r
+#if UIP_CONF_IPV6\r
+       tcpip_ipv6_output();\r
+#else\r
+       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+#endif /* UIP_CONF_IPV6 */\r
+}\r
+\r
+/*-----------------------------------------------------------------------------*/\r
index c7274c3..1df837e 100644 (file)
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved. 
- *
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following conditions 
- * are met: 
- * 1. Redistributions of source code must retain the above copyright 
- *    notice, this list of conditions and the following disclaimer. 
- * 2. Redistributions in binary form must reproduce the above copyright 
- *    notice, this list of conditions and the following disclaimer in the 
- *    documentation and/or other materials provided with the distribution. 
- * 3. Neither the name of the Institute nor the names of its contributors 
- *    may be used to endorse or promote products derived from this software 
- *    without specific prior written permission. 
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
- * SUCH DAMAGE. 
- *
- * This file is part of the Contiki operating system.
- * 
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: uip-split.h,v 1.1 2006/06/17 22:41:19 adamdunkels Exp $
- */
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \defgroup uipsplit uIP TCP throughput booster hack
- * @{
- *
- * The basic uIP TCP implementation only allows each TCP connection to
- * have a single TCP segment in flight at any given time. Because of
- * the delayed ACK algorithm employed by most TCP receivers, uIP's
- * limit on the amount of in-flight TCP segments seriously reduces the
- * maximum achievable throughput for sending data from uIP.
- *
- * The uip-split module is a hack which tries to remedy this
- * situation. By splitting maximum sized outgoing TCP segments into
- * two, the delayed ACK algorithm is not invoked at TCP
- * receivers. This improves the throughput when sending data from uIP
- * by orders of magnitude.
- *
- * The uip-split module uses the uip-fw module (uIP IP packet
- * forwarding) for sending packets. Therefore, the uip-fw module must
- * be set up with the appropriate network interfaces for this module
- * to work.
- */
-
-
-/**
- * \file
- * Module for splitting outbound TCP segments in two to avoid the
- * delayed ACK throughput degradation. 
- * \author
- * Adam Dunkels <adam@sics.se>
- *
- */
-
-#ifndef __UIP_SPLIT_H__
-#define __UIP_SPLIT_H__
-
-#include <string.h>
-#include <uip.h>
-
-#include "../../USBHostMode.h"
-
-#include <LUFA/Drivers/USB/Class/RNDIS.h>
-
-/**
- * Handle outgoing packets.
- *
- * This function inspects an outgoing packet in the uip_buf buffer and
- * sends it out using the uip_fw_output() function. If the packet is a
- * full-sized TCP segment it will be split into two segments and
- * transmitted separately. This function should be called instead of
- * the actual device driver output function, or the uip_fw_output()
- * function.
- *
- * The headers of the outgoing packet is assumed to be in the uip_buf
- * buffer and the payload is assumed to be wherever uip_appdata
- * points. The length of the outgoing packet is assumed to be in the
- * uip_len variable.
- *
- */
-void uip_split_output(void);
-void uip_add32(u8_t *op32, u16_t op16);
-#endif /* __UIP_SPLIT_H__ */
-
-/** @} */
-/** @} */
+/*\r
+ * Copyright (c) 2004, Swedish Institute of Computer Science.\r
+ * All rights reserved. \r
+ *\r
+ * Redistribution and use in source and binary forms, with or without \r
+ * modification, are permitted provided that the following conditions \r
+ * are met: \r
+ * 1. Redistributions of source code must retain the above copyright \r
+ *    notice, this list of conditions and the following disclaimer. \r
+ * 2. Redistributions in binary form must reproduce the above copyright \r
+ *    notice, this list of conditions and the following disclaimer in the \r
+ *    documentation and/or other materials provided with the distribution. \r
+ * 3. Neither the name of the Institute nor the names of its contributors \r
+ *    may be used to endorse or promote products derived from this software \r
+ *    without specific prior written permission. \r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND \r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE \r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE \r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL \r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS \r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) \r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT \r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF \r
+ * SUCH DAMAGE. \r
+ *\r
+ * This file is part of the Contiki operating system.\r
+ * \r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ * $Id: uip-split.h,v 1.1 2006/06/17 22:41:19 adamdunkels Exp $\r
+ */\r
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \defgroup uipsplit uIP TCP throughput booster hack\r
+ * @{\r
+ *\r
+ * The basic uIP TCP implementation only allows each TCP connection to\r
+ * have a single TCP segment in flight at any given time. Because of\r
+ * the delayed ACK algorithm employed by most TCP receivers, uIP's\r
+ * limit on the amount of in-flight TCP segments seriously reduces the\r
+ * maximum achievable throughput for sending data from uIP.\r
+ *\r
+ * The uip-split module is a hack which tries to remedy this\r
+ * situation. By splitting maximum sized outgoing TCP segments into\r
+ * two, the delayed ACK algorithm is not invoked at TCP\r
+ * receivers. This improves the throughput when sending data from uIP\r
+ * by orders of magnitude.\r
+ *\r
+ * The uip-split module uses the uip-fw module (uIP IP packet\r
+ * forwarding) for sending packets. Therefore, the uip-fw module must\r
+ * be set up with the appropriate network interfaces for this module\r
+ * to work.\r
+ */\r
+\r
+\r
+/**\r
+ * \file\r
+ * Module for splitting outbound TCP segments in two to avoid the\r
+ * delayed ACK throughput degradation. \r
+ * \author\r
+ * Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+\r
+#ifndef __UIP_SPLIT_H__\r
+#define __UIP_SPLIT_H__\r
+\r
+#include <string.h>\r
+#include <uip.h>\r
+\r
+#include "../../USBHostMode.h"\r
+\r
+#include <LUFA/Drivers/USB/Class/RNDIS.h>\r
+\r
+/**\r
+ * Handle outgoing packets.\r
+ *\r
+ * This function inspects an outgoing packet in the uip_buf buffer and\r
+ * sends it out using the uip_fw_output() function. If the packet is a\r
+ * full-sized TCP segment it will be split into two segments and\r
+ * transmitted separately. This function should be called instead of\r
+ * the actual device driver output function, or the uip_fw_output()\r
+ * function.\r
+ *\r
+ * The headers of the outgoing packet is assumed to be in the uip_buf\r
+ * buffer and the payload is assumed to be wherever uip_appdata\r
+ * points. The length of the outgoing packet is assumed to be in the\r
+ * uip_len variable.\r
+ *\r
+ */\r
+void uip_split_output(void);\r
+void uip_add32(u8_t *op32, u16_t op16);\r
+#endif /* __UIP_SPLIT_H__ */\r
+\r
+/** @} */\r
+/** @} */\r
index 22a7204..b2c4228 100644 (file)
-#define DEBUG_PRINTF(...) /*printf(__VA_ARGS__)*/
-
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \file
- * The uIP TCP/IP stack code.
- * \author Adam Dunkels <adam@dunkels.com>
- */
-
-/*
- * Copyright (c) 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- *    products derived from this software without specific prior
- *    written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack.
- *
- * $Id: uip.c,v 1.15 2008/10/15 08:08:32 adamdunkels Exp $
- *
- */
-
-/*
- * uIP is a small implementation of the IP, UDP and TCP protocols (as
- * well as some basic ICMP stuff). The implementation couples the IP,
- * UDP, TCP and the application layers very tightly. To keep the size
- * of the compiled code down, this code frequently uses the goto
- * statement. While it would be possible to break the uip_process()
- * function into many smaller functions, this would increase the code
- * size because of the overhead of parameter passing and the fact that
- * the optimier would not be as efficient.
- *
- * The principle is that we have a small buffer, called the uip_buf,
- * in which the device driver puts an incoming packet. The TCP/IP
- * stack parses the headers in the packet, and calls the
- * application. If the remote host has sent data to the application,
- * this data is present in the uip_buf and the application read the
- * data from there. It is up to the application to put this data into
- * a byte stream if needed. The application will not be fed with data
- * that is out of sequence.
- *
- * If the application whishes to send data to the peer, it should put
- * its data into the uip_buf. The uip_appdata pointer points to the
- * first available byte. The TCP/IP stack will calculate the
- * checksums, and fill in the necessary header fields and finally send
- * the packet back to the peer.
-*/
-
-#include "uip.h"
-#include "uipopt.h"
-#include "uip_arp.h"
-
-#if !UIP_CONF_IPV6 /* If UIP_CONF_IPV6 is defined, we compile the
-                     uip6.c file instead of this one. Therefore
-                     this #ifndef removes the entire compilation
-                     output of the uip.c file */
-
-
-#if UIP_CONF_IPV6
-#include "net/uip-neighbor.h"
-#endif /* UIP_CONF_IPV6 */
-
-#include <string.h>
-
-/*---------------------------------------------------------------------------*/
-/* Variable definitions. */
-
-
-/* The IP address of this host. If it is defined to be fixed (by
-   setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set
-   here. Otherwise, the address */
-#if UIP_FIXEDADDR > 0
-const uip_ipaddr_t uip_hostaddr =
-  { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
-const uip_ipaddr_t uip_draddr =
-  { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
-const uip_ipaddr_t uip_netmask =
-  { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
-#else
-uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
-#endif /* UIP_FIXEDADDR */
-
-const uip_ipaddr_t uip_broadcast_addr =
-#if UIP_CONF_IPV6
-  { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-      0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
-#else /* UIP_CONF_IPV6 */
-  { { 0xff, 0xff, 0xff, 0xff } };
-#endif /* UIP_CONF_IPV6 */
-const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
-
-#if UIP_FIXEDETHADDR
-const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
-                                         UIP_ETHADDR1,
-                                         UIP_ETHADDR2,
-                                         UIP_ETHADDR3,
-                                         UIP_ETHADDR4,
-                                         UIP_ETHADDR5}};
-#else
-struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
-#endif
-
-#ifndef UIP_CONF_EXTERNAL_BUFFER
-u8_t uip_buf[UIP_BUFSIZE + 2];   /* The packet buffer that contains
-                                   incoming packets. */
-#endif /* UIP_CONF_EXTERNAL_BUFFER */
-
-void *uip_appdata;               /* The uip_appdata pointer points to
-                                   application data. */
-void *uip_sappdata;              /* The uip_appdata pointer points to
-                                   the application data which is to
-                                   be sent. */
-#if UIP_URGDATA > 0
-void *uip_urgdata;               /* The uip_urgdata pointer points to
-                                   urgent data (out-of-band data), if
-                                   present. */
-u16_t uip_urglen, uip_surglen;
-#endif /* UIP_URGDATA > 0 */
-
-u16_t uip_len, uip_slen;
-                             /* The uip_len is either 8 or 16 bits,
-                               depending on the maximum packet
-                               size. */
-
-u8_t uip_flags;     /* The uip_flags variable is used for
-                               communication between the TCP/IP stack
-                               and the application program. */
-struct uip_conn *uip_conn;   /* uip_conn always points to the current
-                               connection. */
-
-struct uip_conn uip_conns[UIP_CONNS];
-                             /* The uip_conns array holds all TCP
-                               connections. */
-u16_t uip_listenports[UIP_LISTENPORTS];
-                             /* The uip_listenports list all currently
-                               listning ports. */
-#if UIP_UDP
-struct uip_udp_conn *uip_udp_conn;
-struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
-#endif /* UIP_UDP */
-
-static u16_t ipid;           /* Ths ipid variable is an increasing
-                               number that is used for the IP ID
-                               field. */
-
-void uip_setipid(u16_t id) { ipid = id; }
-
-static u8_t iss[4];          /* The iss variable is used for the TCP
-                               initial sequence number. */
-
-#if UIP_ACTIVE_OPEN
-static u16_t lastport;       /* Keeps track of the last port used for
-                               a new connection. */
-#endif /* UIP_ACTIVE_OPEN */
-
-/* Temporary variables. */
-u8_t uip_acc32[4];
-static u8_t c, opt;
-static u16_t tmp16;
-
-/* Structures and definitions. */
-#define TCP_FIN 0x01
-#define TCP_SYN 0x02
-#define TCP_RST 0x04
-#define TCP_PSH 0x08
-#define TCP_ACK 0x10
-#define TCP_URG 0x20
-#define TCP_CTL 0x3f
-
-#define TCP_OPT_END     0   /* End of TCP options list */
-#define TCP_OPT_NOOP    1   /* "No-operation" TCP option */
-#define TCP_OPT_MSS     2   /* Maximum segment size TCP option */
-
-#define TCP_OPT_MSS_LEN 4   /* Length of TCP MSS option. */
-
-#define ICMP_ECHO_REPLY 0
-#define ICMP_ECHO       8
-
-#define ICMP_DEST_UNREACHABLE        3
-#define ICMP_PORT_UNREACHABLE        3
-
-#define ICMP6_ECHO_REPLY             129
-#define ICMP6_ECHO                   128
-#define ICMP6_NEIGHBOR_SOLICITATION  135
-#define ICMP6_NEIGHBOR_ADVERTISEMENT 136
-
-#define ICMP6_FLAG_S (1 << 6)
-
-#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
-#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
-
-
-/* Macros. */
-#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
-#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
-#define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
-#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
-
-
-#if UIP_STATISTICS == 1
-struct uip_stats uip_stat;
-#define UIP_STAT(s) s
-#else
-#define UIP_STAT(s)
-#endif /* UIP_STATISTICS == 1 */
-
-#if UIP_LOGGING == 1
-#include <stdio.h>
-void uip_log(char *msg);
-#define UIP_LOG(m) uip_log(m)
-#else
-#define UIP_LOG(m)
-#endif /* UIP_LOGGING == 1 */
-
-#if ! UIP_ARCH_ADD32
-void
-uip_add32(u8_t *op32, u16_t op16)
-{
-  uip_acc32[3] = op32[3] + (op16 & 0xff);
-  uip_acc32[2] = op32[2] + (op16 >> 8);
-  uip_acc32[1] = op32[1];
-  uip_acc32[0] = op32[0];
-  
-  if(uip_acc32[2] < (op16 >> 8)) {
-    ++uip_acc32[1];
-    if(uip_acc32[1] == 0) {
-      ++uip_acc32[0];
-    }
-  }
-  
-  
-  if(uip_acc32[3] < (op16 & 0xff)) {
-    ++uip_acc32[2];
-    if(uip_acc32[2] == 0) {
-      ++uip_acc32[1];
-      if(uip_acc32[1] == 0) {
-       ++uip_acc32[0];
-      }
-    }
-  }
-}
-
-#endif /* UIP_ARCH_ADD32 */
-
-#if ! UIP_ARCH_CHKSUM
-/*---------------------------------------------------------------------------*/
-static u16_t
-chksum(u16_t sum, const u8_t *data, u16_t len)
-{
-  u16_t t;
-  const u8_t *dataptr;
-  const u8_t *last_byte;
-
-  dataptr = data;
-  last_byte = data + len - 1;
-  
-  while(dataptr < last_byte) { /* At least two more bytes */
-    t = (dataptr[0] << 8) + dataptr[1];
-    sum += t;
-    if(sum < t) {
-      sum++;           /* carry */
-    }
-    dataptr += 2;
-  }
-  
-  if(dataptr == last_byte) {
-    t = (dataptr[0] << 8) + 0;
-    sum += t;
-    if(sum < t) {
-      sum++;           /* carry */
-    }
-  }
-
-  /* Return sum in host byte order. */
-  return sum;
-}
-/*---------------------------------------------------------------------------*/
-u16_t
-uip_chksum(u16_t *data, u16_t len)
-{
-  return htons(chksum(0, (u8_t *)data, len));
-}
-/*---------------------------------------------------------------------------*/
-#ifndef UIP_ARCH_IPCHKSUM
-u16_t
-uip_ipchksum(void)
-{
-  u16_t sum;
-
-  sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
-  DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
-  return (sum == 0) ? 0xffff : htons(sum);
-}
-#endif
-/*---------------------------------------------------------------------------*/
-static u16_t
-upper_layer_chksum(u8_t proto)
-{
-  u16_t upper_layer_len;
-  u16_t sum;
-  
-#if UIP_CONF_IPV6
-  upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]);
-#else /* UIP_CONF_IPV6 */
-  upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
-#endif /* UIP_CONF_IPV6 */
-  
-  /* First sum pseudoheader. */
-  
-  /* IP protocol and length fields. This addition cannot carry. */
-  sum = upper_layer_len + proto;
-  /* Sum IP source and destination addresses. */
-  sum = chksum(sum, (u8_t *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
-
-  /* Sum TCP header and data. */
-  sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
-              upper_layer_len);
-    
-  return (sum == 0) ? 0xffff : htons(sum);
-}
-/*---------------------------------------------------------------------------*/
-#if UIP_CONF_IPV6
-u16_t
-uip_icmp6chksum(void)
-{
-  return upper_layer_chksum(UIP_PROTO_ICMP6);
-  
-}
-#endif /* UIP_CONF_IPV6 */
-/*---------------------------------------------------------------------------*/
-u16_t
-uip_tcpchksum(void)
-{
-  return upper_layer_chksum(UIP_PROTO_TCP);
-}
-/*---------------------------------------------------------------------------*/
-#if UIP_UDP_CHECKSUMS
-u16_t
-uip_udpchksum(void)
-{
-  return upper_layer_chksum(UIP_PROTO_UDP);
-}
-#endif /* UIP_UDP_CHECKSUMS */
-#endif /* UIP_ARCH_CHKSUM */
-/*---------------------------------------------------------------------------*/
-void
-uip_init(void)
-{
-  for(c = 0; c < UIP_LISTENPORTS; ++c) {
-    uip_listenports[c] = 0;
-  }
-  for(c = 0; c < UIP_CONNS; ++c) {
-    uip_conns[c].tcpstateflags = UIP_CLOSED;
-  }
-#if UIP_ACTIVE_OPEN
-  lastport = 1024;
-#endif /* UIP_ACTIVE_OPEN */
-
-#if UIP_UDP
-  for(c = 0; c < UIP_UDP_CONNS; ++c) {
-    uip_udp_conns[c].lport = 0;
-  }
-#endif /* UIP_UDP */
-  
-
-  /* IPv4 initialization. */
-#if UIP_FIXEDADDR == 0
-  /*  uip_hostaddr[0] = uip_hostaddr[1] = 0;*/
-#endif /* UIP_FIXEDADDR */
-
-}
-/*---------------------------------------------------------------------------*/
-#if UIP_ACTIVE_OPEN
-struct uip_conn *
-uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
-{
-  register struct uip_conn *conn, *cconn;
-  
-  /* Find an unused local port. */
- again:
-  ++lastport;
-
-  if(lastport >= 32000) {
-    lastport = 4096;
-  }
-
-  /* Check if this port is already in use, and if so try to find
-     another one. */
-  for(c = 0; c < UIP_CONNS; ++c) {
-    conn = &uip_conns[c];
-    if(conn->tcpstateflags != UIP_CLOSED &&
-       conn->lport == htons(lastport)) {
-      goto again;
-    }
-  }
-
-  conn = 0;
-  for(c = 0; c < UIP_CONNS; ++c) {
-    cconn = &uip_conns[c];
-    if(cconn->tcpstateflags == UIP_CLOSED) {
-      conn = cconn;
-      break;
-    }
-    if(cconn->tcpstateflags == UIP_TIME_WAIT) {
-      if(conn == 0 ||
-        cconn->timer > conn->timer) {
-       conn = cconn;
-      }
-    }
-  }
-
-  if(conn == 0) {
-    return 0;
-  }
-  
-  conn->tcpstateflags = UIP_SYN_SENT;
-
-  conn->snd_nxt[0] = iss[0];
-  conn->snd_nxt[1] = iss[1];
-  conn->snd_nxt[2] = iss[2];
-  conn->snd_nxt[3] = iss[3];
-
-  conn->initialmss = conn->mss = UIP_TCP_MSS;
-  
-  conn->len = 1;   /* TCP length of the SYN is one. */
-  conn->nrtx = 0;
-  conn->timer = 1; /* Send the SYN next time around. */
-  conn->rto = UIP_RTO;
-  conn->sa = 0;
-  conn->sv = 16;   /* Initial value of the RTT variance. */
-  conn->lport = htons(lastport);
-  conn->rport = rport;
-  uip_ipaddr_copy(&conn->ripaddr, ripaddr);
-  
-  return conn;
-}
-#endif /* UIP_ACTIVE_OPEN */
-/*---------------------------------------------------------------------------*/
-#if UIP_UDP
-struct uip_udp_conn *
-uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport)
-{
-  register struct uip_udp_conn *conn;
-  
-  /* Find an unused local port. */
- again:
-  ++lastport;
-
-  if(lastport >= 32000) {
-    lastport = 4096;
-  }
-  
-  for(c = 0; c < UIP_UDP_CONNS; ++c) {
-    if(uip_udp_conns[c].lport == htons(lastport)) {
-      goto again;
-    }
-  }
-
-
-  conn = 0;
-  for(c = 0; c < UIP_UDP_CONNS; ++c) {
-    if(uip_udp_conns[c].lport == 0) {
-      conn = &uip_udp_conns[c];
-      break;
-    }
-  }
-
-  if(conn == 0) {
-    return 0;
-  }
-  
-  conn->lport = HTONS(lastport);
-  conn->rport = rport;
-  if(ripaddr == NULL) {
-    memset(&conn->ripaddr, 0, sizeof(uip_ipaddr_t));
-  } else {
-    uip_ipaddr_copy(&conn->ripaddr, ripaddr);
-  }
-  conn->ttl = UIP_TTL;
-  
-  return conn;
-}
-#endif /* UIP_UDP */
-/*---------------------------------------------------------------------------*/
-void
-uip_unlisten(u16_t port)
-{
-  for(c = 0; c < UIP_LISTENPORTS; ++c) {
-    if(uip_listenports[c] == port) {
-      uip_listenports[c] = 0;
-      return;
-    }
-  }
-}
-/*---------------------------------------------------------------------------*/
-void
-uip_listen(u16_t port)
-{
-  for(c = 0; c < UIP_LISTENPORTS; ++c) {
-    if(uip_listenports[c] == 0) {
-      uip_listenports[c] = port;
-      return;
-    }
-  }
-}
-/*---------------------------------------------------------------------------*/
-/* XXX: IP fragment reassembly: not well-tested. */
-
-#if UIP_REASSEMBLY && !UIP_CONF_IPV6
-#define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
-static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
-static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
-static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
-                                   0x0f, 0x07, 0x03, 0x01};
-static u16_t uip_reasslen;
-static u8_t uip_reassflags;
-#define UIP_REASS_FLAG_LASTFRAG 0x01
-static u8_t uip_reasstmr;
-
-#define IP_MF   0x20
-
-static u8_t
-uip_reass(void)
-{
-  u16_t offset, len;
-  u16_t i;
-
-  /* If ip_reasstmr is zero, no packet is present in the buffer, so we
-     write the IP header of the fragment into the reassembly
-     buffer. The timer is updated with the maximum age. */
-  if(uip_reasstmr == 0) {
-    memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN);
-    uip_reasstmr = UIP_REASS_MAXAGE;
-    uip_reassflags = 0;
-    /* Clear the bitmap. */
-    memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap));
-  }
-
-  /* Check if the incoming fragment matches the one currently present
-     in the reasembly buffer. If so, we proceed with copying the
-     fragment into the buffer. */
-  if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&
-     BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&
-     BUF->destipaddr[0] == FBUF->destipaddr[0] &&
-     BUF->destipaddr[1] == FBUF->destipaddr[1] &&
-     BUF->ipid[0] == FBUF->ipid[0] &&
-     BUF->ipid[1] == FBUF->ipid[1]) {
-
-    len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
-    offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;
-
-    /* If the offset or the offset + fragment length overflows the
-       reassembly buffer, we discard the entire packet. */
-    if(offset > UIP_REASS_BUFSIZE ||
-       offset + len > UIP_REASS_BUFSIZE) {
-      uip_reasstmr = 0;
-      goto nullreturn;
-    }
-
-    /* Copy the fragment into the reassembly buffer, at the right
-       offset. */
-    memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
-          (char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
-          len);
-      
-    /* Update the bitmap. */
-    if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
-      /* If the two endpoints are in the same byte, we only update
-        that byte. */
-            
-      uip_reassbitmap[offset / (8 * 8)] |=
-            bitmap_bits[(offset / 8 ) & 7] &
-            ~bitmap_bits[((offset + len) / 8 ) & 7];
-    } else {
-      /* If the two endpoints are in different bytes, we update the
-        bytes in the endpoints and fill the stuff inbetween with
-        0xff. */
-      uip_reassbitmap[offset / (8 * 8)] |=
-       bitmap_bits[(offset / 8 ) & 7];
-      for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
-       uip_reassbitmap[i] = 0xff;
-      }
-      uip_reassbitmap[(offset + len) / (8 * 8)] |=
-       ~bitmap_bits[((offset + len) / 8 ) & 7];
-    }
-    
-    /* If this fragment has the More Fragments flag set to zero, we
-       know that this is the last fragment, so we can calculate the
-       size of the entire packet. We also set the
-       IP_REASS_FLAG_LASTFRAG flag to indicate that we have received
-       the final fragment. */
-
-    if((BUF->ipoffset[0] & IP_MF) == 0) {
-      uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
-      uip_reasslen = offset + len;
-    }
-    
-    /* Finally, we check if we have a full packet in the buffer. We do
-       this by checking if we have the last fragment and if all bits
-       in the bitmap are set. */
-    if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
-      /* Check all bytes up to and including all but the last byte in
-        the bitmap. */
-      for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
-       if(uip_reassbitmap[i] != 0xff) {
-         goto nullreturn;
-       }
-      }
-      /* Check the last byte in the bitmap. It should contain just the
-        right amount of bits. */
-      if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=
-        (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
-       goto nullreturn;
-      }
-
-      /* If we have come this far, we have a full packet in the
-        buffer, so we allocate a pbuf and copy the packet into it. We
-        also reset the timer. */
-      uip_reasstmr = 0;
-      memcpy(BUF, FBUF, uip_reasslen);
-
-      /* Pretend to be a "normal" (i.e., not fragmented) IP packet
-        from now on. */
-      BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
-      BUF->len[0] = uip_reasslen >> 8;
-      BUF->len[1] = uip_reasslen & 0xff;
-      BUF->ipchksum = 0;
-      BUF->ipchksum = ~(uip_ipchksum());
-
-      return uip_reasslen;
-    }
-  }
-
- nullreturn:
-  return 0;
-}
-#endif /* UIP_REASSEMBLY */
-/*---------------------------------------------------------------------------*/
-static void
-uip_add_rcv_nxt(u16_t n)
-{
-  uip_add32(uip_conn->rcv_nxt, n);
-  uip_conn->rcv_nxt[0] = uip_acc32[0];
-  uip_conn->rcv_nxt[1] = uip_acc32[1];
-  uip_conn->rcv_nxt[2] = uip_acc32[2];
-  uip_conn->rcv_nxt[3] = uip_acc32[3];
-}
-/*---------------------------------------------------------------------------*/
-void
-uip_process(u8_t flag)
-{
-  register struct uip_conn *uip_connr = uip_conn;
-
-#if UIP_UDP
-  if(flag == UIP_UDP_SEND_CONN) {
-    goto udp_send;
-  }
-#endif /* UIP_UDP */
-  
-  uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
-
-  /* Check if we were invoked because of a poll request for a
-     particular connection. */
-  if(flag == UIP_POLL_REQUEST) {
-    if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
-       !uip_outstanding(uip_connr)) {
-       uip_len = uip_slen = 0;
-       uip_flags = UIP_POLL;
-       UIP_APPCALL();
-       goto appsend;
-    }
-    goto drop;
-    
-    /* Check if we were invoked because of the perodic timer fireing. */
-  } else if(flag == UIP_TIMER) {
-#if UIP_REASSEMBLY
-    if(uip_reasstmr != 0) {
-      --uip_reasstmr;
-    }
-#endif /* UIP_REASSEMBLY */
-    /* Increase the initial sequence number. */
-    if(++iss[3] == 0) {
-      if(++iss[2] == 0) {
-       if(++iss[1] == 0) {
-         ++iss[0];
-       }
-      }
-    }
-
-    /* Reset the length variables. */
-    uip_len = 0;
-    uip_slen = 0;
-
-    /* Check if the connection is in a state in which we simply wait
-       for the connection to time out. If so, we increase the
-       connection's timer and remove the connection if it times
-       out. */
-    if(uip_connr->tcpstateflags == UIP_TIME_WAIT ||
-       uip_connr->tcpstateflags == UIP_FIN_WAIT_2) {
-      ++(uip_connr->timer);
-      if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {
-       uip_connr->tcpstateflags = UIP_CLOSED;
-      }
-    } else if(uip_connr->tcpstateflags != UIP_CLOSED) {
-      /* If the connection has outstanding data, we increase the
-        connection's timer and see if it has reached the RTO value
-        in which case we retransmit. */
-      if(uip_outstanding(uip_connr)) {
-       if(uip_connr->timer-- == 0) {
-         if(uip_connr->nrtx == UIP_MAXRTX ||
-            ((uip_connr->tcpstateflags == UIP_SYN_SENT ||
-              uip_connr->tcpstateflags == UIP_SYN_RCVD) &&
-             uip_connr->nrtx == UIP_MAXSYNRTX)) {
-           uip_connr->tcpstateflags = UIP_CLOSED;
-
-           /* We call UIP_APPCALL() with uip_flags set to
-              UIP_TIMEDOUT to inform the application that the
-              connection has timed out. */
-           uip_flags = UIP_TIMEDOUT;
-           UIP_APPCALL();
-
-           /* We also send a reset packet to the remote host. */
-           BUF->flags = TCP_RST | TCP_ACK;
-           goto tcp_send_nodata;
-         }
-
-         /* Exponential backoff. */
-         uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?
-                                        4:
-                                        uip_connr->nrtx);
-         ++(uip_connr->nrtx);
-         
-         /* Ok, so we need to retransmit. We do this differently
-            depending on which state we are in. In ESTABLISHED, we
-            call upon the application so that it may prepare the
-            data for the retransmit. In SYN_RCVD, we resend the
-            SYNACK that we sent earlier and in LAST_ACK we have to
-            retransmit our FINACK. */
-         UIP_STAT(++uip_stat.tcp.rexmit);
-         switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
-         case UIP_SYN_RCVD:
-           /* In the SYN_RCVD state, we should retransmit our
-               SYNACK. */
-           goto tcp_send_synack;
-           
-#if UIP_ACTIVE_OPEN
-         case UIP_SYN_SENT:
-           /* In the SYN_SENT state, we retransmit out SYN. */
-           BUF->flags = 0;
-           goto tcp_send_syn;
-#endif /* UIP_ACTIVE_OPEN */
-           
-         case UIP_ESTABLISHED:
-           /* In the ESTABLISHED state, we call upon the application
-               to do the actual retransmit after which we jump into
-               the code for sending out the packet (the apprexmit
-               label). */
-           uip_flags = UIP_REXMIT;
-           UIP_APPCALL();
-           goto apprexmit;
-           
-         case UIP_FIN_WAIT_1:
-         case UIP_CLOSING:
-         case UIP_LAST_ACK:
-           /* In all these states we should retransmit a FINACK. */
-           goto tcp_send_finack;
-           
-         }
-       }
-      } else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
-       /* If there was no need for a retransmission, we poll the
-           application for new data. */
-       uip_len = uip_slen = 0;            
-       uip_flags = UIP_POLL;
-       UIP_APPCALL();
-       goto appsend;
-      }
-    }
-    goto drop;
-  }
-#if UIP_UDP
-  if(flag == UIP_UDP_TIMER) {
-    if(uip_udp_conn->lport != 0) {
-      uip_conn = NULL;
-      uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
-      uip_len = uip_slen = 0;
-      uip_flags = UIP_POLL;
-      UIP_UDP_APPCALL();
-      goto udp_send;
-    } else {
-      goto drop;
-    }
-  }
-#endif
-
-  /* This is where the input processing starts. */
-  UIP_STAT(++uip_stat.ip.recv);
-
-  /* Start of IP input header processing code. */
-  
-#if UIP_CONF_IPV6
-  /* Check validity of the IP header. */
-  if((BUF->vtc & 0xf0) != 0x60)  { /* IP version and header length. */
-    UIP_STAT(++uip_stat.ip.drop);
-    UIP_STAT(++uip_stat.ip.vhlerr);
-    UIP_LOG("ipv6: invalid version.");
-    goto drop;
-  }
-#else /* UIP_CONF_IPV6 */
-  /* Check validity of the IP header. */
-  if(BUF->vhl != 0x45)  { /* IP version and header length. */
-    UIP_STAT(++uip_stat.ip.drop);
-    UIP_STAT(++uip_stat.ip.vhlerr);
-    UIP_LOG("ip: invalid version or header length.");
-    goto drop;
-  }
-#endif /* UIP_CONF_IPV6 */
-  
-  /* Check the size of the packet. If the size reported to us in
-     uip_len is smaller the size reported in the IP header, we assume
-     that the packet has been corrupted in transit. If the size of
-     uip_len is larger than the size reported in the IP packet header,
-     the packet has been padded and we set uip_len to the correct
-     value.. */
-
-  if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {
-    uip_len = (BUF->len[0] << 8) + BUF->len[1];
-#if UIP_CONF_IPV6
-    uip_len += 40; /* The length reported in the IPv6 header is the
-                     length of the payload that follows the
-                     header. However, uIP uses the uip_len variable
-                     for holding the size of the entire packet,
-                     including the IP header. For IPv4 this is not a
-                     problem as the length field in the IPv4 header
-                     contains the length of the entire packet. But
-                     for IPv6 we need to add the size of the IPv6
-                     header (40 bytes). */
-#endif /* UIP_CONF_IPV6 */
-  } else {
-    UIP_LOG("ip: packet shorter than reported in IP header.");
-    goto drop;
-  }
-
-#if !UIP_CONF_IPV6
-  /* Check the fragment flag. */
-  if((BUF->ipoffset[0] & 0x3f) != 0 ||
-     BUF->ipoffset[1] != 0) {
-#if UIP_REASSEMBLY
-    uip_len = uip_reass();
-    if(uip_len == 0) {
-      goto drop;
-    }
-#else /* UIP_REASSEMBLY */
-    UIP_STAT(++uip_stat.ip.drop);
-    UIP_STAT(++uip_stat.ip.fragerr);
-    UIP_LOG("ip: fragment dropped.");
-    goto drop;
-#endif /* UIP_REASSEMBLY */
-  }
-#endif /* UIP_CONF_IPV6 */
-
-  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
-    /* If we are configured to use ping IP address configuration and
-       hasn't been assigned an IP address yet, we accept all ICMP
-       packets. */
-#if UIP_PINGADDRCONF && !UIP_CONF_IPV6
-    if(BUF->proto == UIP_PROTO_ICMP) {
-      UIP_LOG("ip: possible ping config packet received.");
-      goto icmp_input;
-    } else {
-      UIP_LOG("ip: packet dropped since no address assigned.");
-      goto drop;
-    }
-#endif /* UIP_PINGADDRCONF */
-
-  } else {
-    /* If IP broadcast support is configured, we check for a broadcast
-       UDP packet, which may be destined to us. */
-#if UIP_BROADCAST
-    DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());
-    if(BUF->proto == UIP_PROTO_UDP &&
-       uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)
-       /*&&
-        uip_ipchksum() == 0xffff*/) {
-      goto udp_input;
-    }
-#endif /* UIP_BROADCAST */
-    
-    /* Check if the packet is destined for our IP address. */
-#if !UIP_CONF_IPV6
-    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
-      UIP_STAT(++uip_stat.ip.drop);
-      goto drop;
-    }
-#else /* UIP_CONF_IPV6 */
-    /* For IPv6, packet reception is a little trickier as we need to
-       make sure that we listen to certain multicast addresses (all
-       hosts multicast address, and the solicited-node multicast
-       address) as well. However, we will cheat here and accept all
-       multicast packets that are sent to the ff02::/16 addresses. */
-    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) &&
-       BUF->destipaddr.u16[0] != HTONS(0xff02)) {
-      UIP_STAT(++uip_stat.ip.drop);
-      goto drop;
-    }
-#endif /* UIP_CONF_IPV6 */
-  }
-
-#if !UIP_CONF_IPV6
-  if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
-                                   checksum. */
-    UIP_STAT(++uip_stat.ip.drop);
-    UIP_STAT(++uip_stat.ip.chkerr);
-    UIP_LOG("ip: bad checksum.");
-    goto drop;
-  }
-#endif /* UIP_CONF_IPV6 */
-
-  if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so,
-                                      proceed with TCP input
-                                      processing. */
-    goto tcp_input;
-  }
-
-#if UIP_UDP
-  if(BUF->proto == UIP_PROTO_UDP) {
-    goto udp_input;
-  }
-#endif /* UIP_UDP */
-
-#if !UIP_CONF_IPV6
-  /* ICMPv4 processing code follows. */
-  if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from
-                                       here. */
-    UIP_STAT(++uip_stat.ip.drop);
-    UIP_STAT(++uip_stat.ip.protoerr);
-    UIP_LOG("ip: neither tcp nor icmp.");
-    goto drop;
-  }
-
-#if UIP_PINGADDRCONF
- icmp_input:
-#endif /* UIP_PINGADDRCONF */
-  UIP_STAT(++uip_stat.icmp.recv);
-
-  /* ICMP echo (i.e., ping) processing. This is simple, we only change
-     the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP
-     checksum before we return the packet. */
-  if(ICMPBUF->type != ICMP_ECHO) {
-    UIP_STAT(++uip_stat.icmp.drop);
-    UIP_STAT(++uip_stat.icmp.typeerr);
-    UIP_LOG("icmp: not icmp echo.");
-    goto drop;
-  }
-
-  /* If we are configured to use ping IP address assignment, we use
-     the destination IP address of this ping packet and assign it to
-     ourself. */
-#if UIP_PINGADDRCONF
-  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
-    uip_hostaddr = BUF->destipaddr;
-  }
-#endif /* UIP_PINGADDRCONF */
-
-  ICMPBUF->type = ICMP_ECHO_REPLY;
-
-  if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
-    ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
-  } else {
-    ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);
-  }
-
-  /* Swap IP addresses. */
-  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
-  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
-
-  UIP_STAT(++uip_stat.icmp.sent);
-  BUF->ttl = UIP_TTL;
-  goto ip_send_nolen;
-
-  /* End of IPv4 input header processing code. */
-#else /* !UIP_CONF_IPV6 */
-
-  /* This is IPv6 ICMPv6 processing code. */
-  DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);
-
-  if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from
-                                        here. */
-    UIP_STAT(++uip_stat.ip.drop);
-    UIP_STAT(++uip_stat.ip.protoerr);
-    UIP_LOG("ip: neither tcp nor icmp6.");
-    goto drop;
-  }
-
-  UIP_STAT(++uip_stat.icmp.recv);
-
-  /* If we get a neighbor solicitation for our address we should send
-     a neighbor advertisement message back. */
-  if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
-    if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) {
-
-      if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
-       /* Save the sender's address in our neighbor list. */
-       uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
-      }
-      
-      /* We should now send a neighbor advertisement back to where the
-        neighbor solicication came from. */
-      ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;
-      ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */
-      
-      ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
-      
-      uip_ipaddr_copy(&ICMPBUF->destipaddr, &ICMPBUF->srcipaddr);
-      uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr);
-      ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
-      ICMPBUF->options[1] = 1;  /* Options length, 1 = 8 bytes. */
-      memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));
-      ICMPBUF->icmpchksum = 0;
-      ICMPBUF->icmpchksum = ~uip_icmp6chksum();
-      
-      goto send;
-      
-    }
-    goto drop;
-  } else if(ICMPBUF->type == ICMP6_ECHO) {
-    /* ICMP echo (i.e., ping) processing. This is simple, we only
-       change the ICMP type from ECHO to ECHO_REPLY and update the
-       ICMP checksum before we return the packet. */
-
-    ICMPBUF->type = ICMP6_ECHO_REPLY;
-    
-    uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
-    uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
-    ICMPBUF->icmpchksum = 0;
-    ICMPBUF->icmpchksum = ~uip_icmp6chksum();
-    
-    UIP_STAT(++uip_stat.icmp.sent);
-    goto send;
-  } else {
-    DEBUG_PRINTF("Unknown icmp6 message type %d\n", ICMPBUF->type);
-    UIP_STAT(++uip_stat.icmp.drop);
-    UIP_STAT(++uip_stat.icmp.typeerr);
-    UIP_LOG("icmp: unknown ICMP message.");
-    goto drop;
-  }
-
-  /* End of IPv6 ICMP processing. */
-  
-#endif /* !UIP_CONF_IPV6 */
-
-#if UIP_UDP
-  /* UDP input processing. */
- udp_input:
-  /* UDP processing is really just a hack. We don't do anything to the
-     UDP/IP headers, but let the UDP application do all the hard
-     work. If the application sets uip_slen, it has a packet to
-     send. */
-#if UIP_UDP_CHECKSUMS
-  uip_len = uip_len - UIP_IPUDPH_LEN;
-  uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
-  if(UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
-    UIP_STAT(++uip_stat.udp.drop);
-    UIP_STAT(++uip_stat.udp.chkerr);
-    UIP_LOG("udp: bad checksum.");
-    goto drop;
-  }
-#else /* UIP_UDP_CHECKSUMS */
-  uip_len = uip_len - UIP_IPUDPH_LEN;
-#endif /* UIP_UDP_CHECKSUMS */
-
-  /* Demultiplex this UDP packet between the UDP "connections". */
-  for(uip_udp_conn = &uip_udp_conns[0];
-      uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS];
-      ++uip_udp_conn) {
-    /* If the local UDP port is non-zero, the connection is considered
-       to be used. If so, the local port number is checked against the
-       destination port number in the received packet. If the two port
-       numbers match, the remote port number is checked if the
-       connection is bound to a remote port. Finally, if the
-       connection is bound to a remote IP address, the source IP
-       address of the packet is checked. */
-    if(uip_udp_conn->lport != 0 &&
-       UDPBUF->destport == uip_udp_conn->lport &&
-       (uip_udp_conn->rport == 0 ||
-        UDPBUF->srcport == uip_udp_conn->rport) &&
-       (uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||
-       uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||
-       uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr))) {
-      goto udp_found;
-    }
-  }
-  UIP_LOG("udp: no matching connection found");
-#if UIP_CONF_ICMP_DEST_UNREACH && !UIP_CONF_IPV6
-  /* Copy fields from packet header into payload of this ICMP packet. */
-  memcpy(&(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8);
-
-  /* Set the ICMP type and code. */
-  ICMPBUF->type = ICMP_DEST_UNREACHABLE;
-  ICMPBUF->icode = ICMP_PORT_UNREACHABLE;
-
-  /* Calculate the ICMP checksum. */
-  ICMPBUF->icmpchksum = 0;
-  ICMPBUF->icmpchksum = ~uip_chksum((u16_t *)&(ICMPBUF->type), 36);
-
-  /* Set the IP destination address to be the source address of the
-     original packet. */
-  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
-
-  /* Set our IP address as the source address. */
-  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
-
-  /* The size of the ICMP destination unreachable packet is 36 + the
-     size of the IP header (20) = 56. */
-  uip_len = 36 + UIP_IPH_LEN;
-  ICMPBUF->len[0] = 0;
-  ICMPBUF->len[1] = (u8_t)uip_len;
-  ICMPBUF->ttl = UIP_TTL;
-  ICMPBUF->proto = UIP_PROTO_ICMP;
-
-  goto ip_send_nolen;
-#else /* UIP_CONF_ICMP_DEST_UNREACH */
-  goto drop;
-#endif /* UIP_CONF_ICMP_DEST_UNREACH */
-  
- udp_found:
-  uip_conn = NULL;
-  uip_flags = UIP_NEWDATA;
-  uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
-  uip_slen = 0;
-  UIP_UDP_APPCALL();
-
- udp_send:
-  if(uip_slen == 0) {
-    goto drop;
-  }
-  uip_len = uip_slen + UIP_IPUDPH_LEN;
-
-#if UIP_CONF_IPV6
-  /* For IPv6, the IP length field does not include the IPv6 IP header
-     length. */
-  BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
-  BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
-#else /* UIP_CONF_IPV6 */
-  BUF->len[0] = (uip_len >> 8);
-  BUF->len[1] = (uip_len & 0xff);
-#endif /* UIP_CONF_IPV6 */
-
-  BUF->ttl = uip_udp_conn->ttl;
-  BUF->proto = UIP_PROTO_UDP;
-
-  UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);
-  UDPBUF->udpchksum = 0;
-
-  BUF->srcport  = uip_udp_conn->lport;
-  BUF->destport = uip_udp_conn->rport;
-
-  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
-  uip_ipaddr_copy(&BUF->destipaddr, &uip_udp_conn->ripaddr);
-   
-  uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
-
-#if UIP_UDP_CHECKSUMS
-  /* Calculate UDP checksum. */
-  UDPBUF->udpchksum = ~(uip_udpchksum());
-  if(UDPBUF->udpchksum == 0) {
-    UDPBUF->udpchksum = 0xffff;
-  }
-#endif /* UIP_UDP_CHECKSUMS */
-  
-  goto ip_send_nolen;
-#endif /* UIP_UDP */
-  
-  /* TCP input processing. */
- tcp_input:
-  UIP_STAT(++uip_stat.tcp.recv);
-
-  /* Start of TCP input header processing code. */
-  
-  if(uip_tcpchksum() != 0xffff) {   /* Compute and check the TCP
-                                      checksum. */
-    UIP_STAT(++uip_stat.tcp.drop);
-    UIP_STAT(++uip_stat.tcp.chkerr);
-    UIP_LOG("tcp: bad checksum.");
-    goto drop;
-  }
-  
-  /* Demultiplex this segment. */
-  /* First check any active connections. */
-  for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];
-      ++uip_connr) {
-    if(uip_connr->tcpstateflags != UIP_CLOSED &&
-       BUF->destport == uip_connr->lport &&
-       BUF->srcport == uip_connr->rport &&
-       uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->ripaddr)) {
-      goto found;
-    }
-  }
-
-  /* If we didn't find and active connection that expected the packet,
-     either this packet is an old duplicate, or this is a SYN packet
-     destined for a connection in LISTEN. If the SYN flag isn't set,
-     it is an old packet and we send a RST. */
-  if((BUF->flags & TCP_CTL) != TCP_SYN) {
-    goto reset;
-  }
-  
-  tmp16 = BUF->destport;
-  /* Next, check listening connections. */
-  for(c = 0; c < UIP_LISTENPORTS; ++c) {
-    if(tmp16 == uip_listenports[c]) {
-      goto found_listen;
-    }
-  }
-  
-  /* No matching connection found, so we send a RST packet. */
-  UIP_STAT(++uip_stat.tcp.synrst);
-
- reset:
-  /* We do not send resets in response to resets. */
-  if(BUF->flags & TCP_RST) {
-    goto drop;
-  }
-
-  UIP_STAT(++uip_stat.tcp.rst);
-  
-  BUF->flags = TCP_RST | TCP_ACK;
-  uip_len = UIP_IPTCPH_LEN;
-  BUF->tcpoffset = 5 << 4;
-
-  /* Flip the seqno and ackno fields in the TCP header. */
-  c = BUF->seqno[3];
-  BUF->seqno[3] = BUF->ackno[3];
-  BUF->ackno[3] = c;
-  
-  c = BUF->seqno[2];
-  BUF->seqno[2] = BUF->ackno[2];
-  BUF->ackno[2] = c;
-  
-  c = BUF->seqno[1];
-  BUF->seqno[1] = BUF->ackno[1];
-  BUF->ackno[1] = c;
-  
-  c = BUF->seqno[0];
-  BUF->seqno[0] = BUF->ackno[0];
-  BUF->ackno[0] = c;
-
-  /* We also have to increase the sequence number we are
-     acknowledging. If the least significant byte overflowed, we need
-     to propagate the carry to the other bytes as well. */
-  if(++BUF->ackno[3] == 0) {
-    if(++BUF->ackno[2] == 0) {
-      if(++BUF->ackno[1] == 0) {
-       ++BUF->ackno[0];
-      }
-    }
-  }
-  /* Swap port numbers. */
-  tmp16 = BUF->srcport;
-  BUF->srcport = BUF->destport;
-  BUF->destport = tmp16;
-  
-  /* Swap IP addresses. */
-  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
-  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
-  
-  /* And send out the RST packet! */
-  goto tcp_send_noconn;
-
-  /* This label will be jumped to if we matched the incoming packet
-     with a connection in LISTEN. In that case, we should create a new
-     connection and send a SYNACK in return. */
- found_listen:
-  /* First we check if there are any connections avaliable. Unused
-     connections are kept in the same table as used connections, but
-     unused ones have the tcpstate set to CLOSED. Also, connections in
-     TIME_WAIT are kept track of and we'll use the oldest one if no
-     CLOSED connections are found. Thanks to Eddie C. Dost for a very
-     nice algorithm for the TIME_WAIT search. */
-  uip_connr = 0;
-  for(c = 0; c < UIP_CONNS; ++c) {
-    if(uip_conns[c].tcpstateflags == UIP_CLOSED) {
-      uip_connr = &uip_conns[c];
-      break;
-    }
-    if(uip_conns[c].tcpstateflags == UIP_TIME_WAIT) {
-      if(uip_connr == 0 ||
-        uip_conns[c].timer > uip_connr->timer) {
-       uip_connr = &uip_conns[c];
-      }
-    }
-  }
-
-  if(uip_connr == 0) {
-    /* All connections are used already, we drop packet and hope that
-       the remote end will retransmit the packet at a time when we
-       have more spare connections. */
-    UIP_STAT(++uip_stat.tcp.syndrop);
-    UIP_LOG("tcp: found no unused connections.");
-    goto drop;
-  }
-  uip_conn = uip_connr;
-  
-  /* Fill in the necessary fields for the new connection. */
-  uip_connr->rto = uip_connr->timer = UIP_RTO;
-  uip_connr->sa = 0;
-  uip_connr->sv = 4;
-  uip_connr->nrtx = 0;
-  uip_connr->lport = BUF->destport;
-  uip_connr->rport = BUF->srcport;
-  uip_ipaddr_copy(&uip_connr->ripaddr, &BUF->srcipaddr);
-  uip_connr->tcpstateflags = UIP_SYN_RCVD;
-
-  uip_connr->snd_nxt[0] = iss[0];
-  uip_connr->snd_nxt[1] = iss[1];
-  uip_connr->snd_nxt[2] = iss[2];
-  uip_connr->snd_nxt[3] = iss[3];
-  uip_connr->len = 1;
-
-  /* rcv_nxt should be the seqno from the incoming packet + 1. */
-  uip_connr->rcv_nxt[3] = BUF->seqno[3];
-  uip_connr->rcv_nxt[2] = BUF->seqno[2];
-  uip_connr->rcv_nxt[1] = BUF->seqno[1];
-  uip_connr->rcv_nxt[0] = BUF->seqno[0];
-  uip_add_rcv_nxt(1);
-
-  /* Parse the TCP MSS option, if present. */
-  if((BUF->tcpoffset & 0xf0) > 0x50) {
-    for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
-      opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
-      if(opt == TCP_OPT_END) {
-       /* End of options. */
-       break;
-      } else if(opt == TCP_OPT_NOOP) {
-       ++c;
-       /* NOP option. */
-      } else if(opt == TCP_OPT_MSS &&
-               uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
-       /* An MSS option with the right option length. */
-       tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
-         (u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
-       uip_connr->initialmss = uip_connr->mss =
-         tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
-       
-       /* And we are done processing options. */
-       break;
-      } else {
-       /* All other options have a length field, so that we easily
-          can skip past them. */
-       if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
-         /* If the length field is zero, the options are malformed
-            and we don't process them further. */
-         break;
-       }
-       c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
-      }
-    }
-  }
-  
-  /* Our response will be a SYNACK. */
-#if UIP_ACTIVE_OPEN
- tcp_send_synack:
-  BUF->flags = TCP_ACK;
-  
- tcp_send_syn:
-  BUF->flags |= TCP_SYN;
-#else /* UIP_ACTIVE_OPEN */
- tcp_send_synack:
-  BUF->flags = TCP_SYN | TCP_ACK;
-#endif /* UIP_ACTIVE_OPEN */
-  
-  /* We send out the TCP Maximum Segment Size option with our
-     SYNACK. */
-  BUF->optdata[0] = TCP_OPT_MSS;
-  BUF->optdata[1] = TCP_OPT_MSS_LEN;
-  BUF->optdata[2] = (UIP_TCP_MSS) / 256;
-  BUF->optdata[3] = (UIP_TCP_MSS) & 255;
-  uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
-  BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
-  goto tcp_send;
-
-  /* This label will be jumped to if we found an active connection. */
- found:
-  uip_conn = uip_connr;
-  uip_flags = 0;
-  /* We do a very naive form of TCP reset processing; we just accept
-     any RST and kill our connection. We should in fact check if the
-     sequence number of this reset is wihtin our advertised window
-     before we accept the reset. */
-  if(BUF->flags & TCP_RST) {
-    uip_connr->tcpstateflags = UIP_CLOSED;
-    UIP_LOG("tcp: got reset, aborting connection.");
-    uip_flags = UIP_ABORT;
-    UIP_APPCALL();
-    goto drop;
-  }
-  /* Calculate the length of the data, if the application has sent
-     any data to us. */
-  c = (BUF->tcpoffset >> 4) << 2;
-  /* uip_len will contain the length of the actual TCP data. This is
-     calculated by subtracing the length of the TCP header (in
-     c) and the length of the IP header (20 bytes). */
-  uip_len = uip_len - c - UIP_IPH_LEN;
-
-  /* First, check if the sequence number of the incoming packet is
-     what we're expecting next. If not, we send out an ACK with the
-     correct numbers in. */
-  if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
-       ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {
-    if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
-       (BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
-       BUF->seqno[1] != uip_connr->rcv_nxt[1] ||
-       BUF->seqno[2] != uip_connr->rcv_nxt[2] ||
-       BUF->seqno[3] != uip_connr->rcv_nxt[3])) {
-      goto tcp_send_ack;
-    }
-  }
-
-  /* Next, check if the incoming segment acknowledges any outstanding
-     data. If so, we update the sequence number, reset the length of
-     the outstanding data, calculate RTT estimations, and reset the
-     retransmission timer. */
-  if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
-    uip_add32(uip_connr->snd_nxt, uip_connr->len);
-
-    if(BUF->ackno[0] == uip_acc32[0] &&
-       BUF->ackno[1] == uip_acc32[1] &&
-       BUF->ackno[2] == uip_acc32[2] &&
-       BUF->ackno[3] == uip_acc32[3]) {
-      /* Update sequence number. */
-      uip_connr->snd_nxt[0] = uip_acc32[0];
-      uip_connr->snd_nxt[1] = uip_acc32[1];
-      uip_connr->snd_nxt[2] = uip_acc32[2];
-      uip_connr->snd_nxt[3] = uip_acc32[3];
-       
-      /* Do RTT estimation, unless we have done retransmissions. */
-      if(uip_connr->nrtx == 0) {
-       signed char m;
-       m = uip_connr->rto - uip_connr->timer;
-       /* This is taken directly from VJs original code in his paper */
-       m = m - (uip_connr->sa >> 3);
-       uip_connr->sa += m;
-       if(m < 0) {
-         m = -m;
-       }
-       m = m - (uip_connr->sv >> 2);
-       uip_connr->sv += m;
-       uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;
-
-      }
-      /* Set the acknowledged flag. */
-      uip_flags = UIP_ACKDATA;
-      /* Reset the retransmission timer. */
-      uip_connr->timer = uip_connr->rto;
-
-      /* Reset length of outstanding data. */
-      uip_connr->len = 0;
-    }
-    
-  }
-
-  /* Do different things depending on in what state the connection is. */
-  switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
-    /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not
-       implemented, since we force the application to close when the
-       peer sends a FIN (hence the application goes directly from
-       ESTABLISHED to LAST_ACK). */
-  case UIP_SYN_RCVD:
-    /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and
-       we are waiting for an ACK that acknowledges the data we sent
-       out the last time. Therefore, we want to have the UIP_ACKDATA
-       flag set. If so, we enter the ESTABLISHED state. */
-    if(uip_flags & UIP_ACKDATA) {
-      uip_connr->tcpstateflags = UIP_ESTABLISHED;
-      uip_flags = UIP_CONNECTED;
-      uip_connr->len = 0;
-      if(uip_len > 0) {
-        uip_flags |= UIP_NEWDATA;
-        uip_add_rcv_nxt(uip_len);
-      }
-      uip_slen = 0;
-      UIP_APPCALL();
-      goto appsend;
-    }
-    goto drop;
-#if UIP_ACTIVE_OPEN
-  case UIP_SYN_SENT:
-    /* In SYN_SENT, we wait for a SYNACK that is sent in response to
-       our SYN. The rcv_nxt is set to sequence number in the SYNACK
-       plus one, and we send an ACK. We move into the ESTABLISHED
-       state. */
-    if((uip_flags & UIP_ACKDATA) &&
-       (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
-
-      /* Parse the TCP MSS option, if present. */
-      if((BUF->tcpoffset & 0xf0) > 0x50) {
-       for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
-         opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
-         if(opt == TCP_OPT_END) {
-           /* End of options. */
-           break;
-         } else if(opt == TCP_OPT_NOOP) {
-           ++c;
-           /* NOP option. */
-         } else if(opt == TCP_OPT_MSS &&
-                   uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
-           /* An MSS option with the right option length. */
-           tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
-             uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
-           uip_connr->initialmss =
-             uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
-
-           /* And we are done processing options. */
-           break;
-         } else {
-           /* All other options have a length field, so that we easily
-              can skip past them. */
-           if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
-             /* If the length field is zero, the options are malformed
-                and we don't process them further. */
-             break;
-           }
-           c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
-         }
-       }
-      }
-      uip_connr->tcpstateflags = UIP_ESTABLISHED;
-      uip_connr->rcv_nxt[0] = BUF->seqno[0];
-      uip_connr->rcv_nxt[1] = BUF->seqno[1];
-      uip_connr->rcv_nxt[2] = BUF->seqno[2];
-      uip_connr->rcv_nxt[3] = BUF->seqno[3];
-      uip_add_rcv_nxt(1);
-      uip_flags = UIP_CONNECTED | UIP_NEWDATA;
-      uip_connr->len = 0;
-      uip_len = 0;
-      uip_slen = 0;
-      UIP_APPCALL();
-      goto appsend;
-    }
-    /* Inform the application that the connection failed */
-    uip_flags = UIP_ABORT;
-    UIP_APPCALL();
-    /* The connection is closed after we send the RST */
-    uip_conn->tcpstateflags = UIP_CLOSED;
-    goto reset;
-#endif /* UIP_ACTIVE_OPEN */
-    
-  case UIP_ESTABLISHED:
-    /* In the ESTABLISHED state, we call upon the application to feed
-    data into the uip_buf. If the UIP_ACKDATA flag is set, the
-    application should put new data into the buffer, otherwise we are
-    retransmitting an old segment, and the application should put that
-    data into the buffer.
-
-    If the incoming packet is a FIN, we should close the connection on
-    this side as well, and we send out a FIN and enter the LAST_ACK
-    state. We require that there is no outstanding data; otherwise the
-    sequence numbers will be screwed up. */
-
-    if(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
-      if(uip_outstanding(uip_connr)) {
-       goto drop;
-      }
-      uip_add_rcv_nxt(1 + uip_len);
-      uip_flags |= UIP_CLOSE;
-      if(uip_len > 0) {
-       uip_flags |= UIP_NEWDATA;
-      }
-      UIP_APPCALL();
-      uip_connr->len = 1;
-      uip_connr->tcpstateflags = UIP_LAST_ACK;
-      uip_connr->nrtx = 0;
-    tcp_send_finack:
-      BUF->flags = TCP_FIN | TCP_ACK;
-      goto tcp_send_nodata;
-    }
-
-    /* Check the URG flag. If this is set, the segment carries urgent
-       data that we must pass to the application. */
-    if((BUF->flags & TCP_URG) != 0) {
-#if UIP_URGDATA > 0
-      uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
-      if(uip_urglen > uip_len) {
-       /* There is more urgent data in the next segment to come. */
-       uip_urglen = uip_len;
-      }
-      uip_add_rcv_nxt(uip_urglen);
-      uip_len -= uip_urglen;
-      uip_urgdata = uip_appdata;
-      uip_appdata += uip_urglen;
-    } else {
-      uip_urglen = 0;
-#else /* UIP_URGDATA > 0 */
-      uip_appdata = ((char *)uip_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]);
-      uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];
-#endif /* UIP_URGDATA > 0 */
-    }
-
-    /* If uip_len > 0 we have TCP data in the packet, and we flag this
-       by setting the UIP_NEWDATA flag and update the sequence number
-       we acknowledge. If the application has stopped the dataflow
-       using uip_stop(), we must not accept any data packets from the
-       remote host. */
-    if(uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
-      uip_flags |= UIP_NEWDATA;
-      uip_add_rcv_nxt(uip_len);
-    }
-
-    /* Check if the available buffer space advertised by the other end
-       is smaller than the initial MSS for this connection. If so, we
-       set the current MSS to the window size to ensure that the
-       application does not send more data than the other end can
-       handle.
-
-       If the remote host advertises a zero window, we set the MSS to
-       the initial MSS so that the application will send an entire MSS
-       of data. This data will not be acknowledged by the receiver,
-       and the application will retransmit it. This is called the
-       "persistent timer" and uses the retransmission mechanim.
-    */
-    tmp16 = ((u16_t)BUF->wnd[0] << 8) + (u16_t)BUF->wnd[1];
-    if(tmp16 > uip_connr->initialmss ||
-       tmp16 == 0) {
-      tmp16 = uip_connr->initialmss;
-    }
-    uip_connr->mss = tmp16;
-
-    /* If this packet constitutes an ACK for outstanding data (flagged
-       by the UIP_ACKDATA flag, we should call the application since it
-       might want to send more data. If the incoming packet had data
-       from the peer (as flagged by the UIP_NEWDATA flag), the
-       application must also be notified.
-
-       When the application is called, the global variable uip_len
-       contains the length of the incoming data. The application can
-       access the incoming data through the global pointer
-       uip_appdata, which usually points UIP_IPTCPH_LEN + UIP_LLH_LEN
-       bytes into the uip_buf array.
-
-       If the application wishes to send any data, this data should be
-       put into the uip_appdata and the length of the data should be
-       put into uip_len. If the application don't have any data to
-       send, uip_len must be set to 0. */
-    if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
-      uip_slen = 0;
-      UIP_APPCALL();
-
-    appsend:
-      
-      if(uip_flags & UIP_ABORT) {
-       uip_slen = 0;
-       uip_connr->tcpstateflags = UIP_CLOSED;
-       BUF->flags = TCP_RST | TCP_ACK;
-       goto tcp_send_nodata;
-      }
-
-      if(uip_flags & UIP_CLOSE) {
-       uip_slen = 0;
-       uip_connr->len = 1;
-       uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
-       uip_connr->nrtx = 0;
-       BUF->flags = TCP_FIN | TCP_ACK;
-       goto tcp_send_nodata;
-      }
-
-      /* If uip_slen > 0, the application has data to be sent. */
-      if(uip_slen > 0) {
-
-       /* If the connection has acknowledged data, the contents of
-          the ->len variable should be discarded. */
-       if((uip_flags & UIP_ACKDATA) != 0) {
-         uip_connr->len = 0;
-       }
-
-       /* If the ->len variable is non-zero the connection has
-          already data in transit and cannot send anymore right
-          now. */
-       if(uip_connr->len == 0) {
-
-         /* The application cannot send more than what is allowed by
-            the mss (the minumum of the MSS and the available
-            window). */
-         if(uip_slen > uip_connr->mss) {
-           uip_slen = uip_connr->mss;
-         }
-
-         /* Remember how much data we send out now so that we know
-            when everything has been acknowledged. */
-         uip_connr->len = uip_slen;
-       } else {
-
-         /* If the application already had unacknowledged data, we
-            make sure that the application does not send (i.e.,
-            retransmit) out more than it previously sent out. */
-         uip_slen = uip_connr->len;
-       }
-      }
-      uip_connr->nrtx = 0;
-    apprexmit:
-      uip_appdata = uip_sappdata;
-      
-      /* If the application has data to be sent, or if the incoming
-         packet had new data in it, we must send out a packet. */
-      if(uip_slen > 0 && uip_connr->len > 0) {
-       /* Add the length of the IP and TCP headers. */
-       uip_len = uip_connr->len + UIP_TCPIP_HLEN;
-       /* We always set the ACK flag in response packets. */
-       BUF->flags = TCP_ACK | TCP_PSH;
-       /* Send the packet. */
-       goto tcp_send_noopts;
-      }
-      /* If there is no data to send, just send out a pure ACK if
-        there is newdata. */
-      if(uip_flags & UIP_NEWDATA) {
-       uip_len = UIP_TCPIP_HLEN;
-       BUF->flags = TCP_ACK;
-       goto tcp_send_noopts;
-      }
-    }
-    goto drop;
-  case UIP_LAST_ACK:
-    /* We can close this connection if the peer has acknowledged our
-       FIN. This is indicated by the UIP_ACKDATA flag. */
-    if(uip_flags & UIP_ACKDATA) {
-      uip_connr->tcpstateflags = UIP_CLOSED;
-      uip_flags = UIP_CLOSE;
-      UIP_APPCALL();
-    }
-    break;
-    
-  case UIP_FIN_WAIT_1:
-    /* The application has closed the connection, but the remote host
-       hasn't closed its end yet. Thus we do nothing but wait for a
-       FIN from the other side. */
-    if(uip_len > 0) {
-      uip_add_rcv_nxt(uip_len);
-    }
-    if(BUF->flags & TCP_FIN) {
-      if(uip_flags & UIP_ACKDATA) {
-       uip_connr->tcpstateflags = UIP_TIME_WAIT;
-       uip_connr->timer = 0;
-       uip_connr->len = 0;
-      } else {
-       uip_connr->tcpstateflags = UIP_CLOSING;
-      }
-      uip_add_rcv_nxt(1);
-      uip_flags = UIP_CLOSE;
-      UIP_APPCALL();
-      goto tcp_send_ack;
-    } else if(uip_flags & UIP_ACKDATA) {
-      uip_connr->tcpstateflags = UIP_FIN_WAIT_2;
-      uip_connr->len = 0;
-      goto drop;
-    }
-    if(uip_len > 0) {
-      goto tcp_send_ack;
-    }
-    goto drop;
-      
-  case UIP_FIN_WAIT_2:
-    if(uip_len > 0) {
-      uip_add_rcv_nxt(uip_len);
-    }
-    if(BUF->flags & TCP_FIN) {
-      uip_connr->tcpstateflags = UIP_TIME_WAIT;
-      uip_connr->timer = 0;
-      uip_add_rcv_nxt(1);
-      uip_flags = UIP_CLOSE;
-      UIP_APPCALL();
-      goto tcp_send_ack;
-    }
-    if(uip_len > 0) {
-      goto tcp_send_ack;
-    }
-    goto drop;
-
-  case UIP_TIME_WAIT:
-    goto tcp_send_ack;
-    
-  case UIP_CLOSING:
-    if(uip_flags & UIP_ACKDATA) {
-      uip_connr->tcpstateflags = UIP_TIME_WAIT;
-      uip_connr->timer = 0;
-    }
-  }
-  goto drop;
-  
-  /* We jump here when we are ready to send the packet, and just want
-     to set the appropriate TCP sequence numbers in the TCP header. */
- tcp_send_ack:
-  BUF->flags = TCP_ACK;
-
- tcp_send_nodata:
-  uip_len = UIP_IPTCPH_LEN;
-
- tcp_send_noopts:
-  BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
-
-  /* We're done with the input processing. We are now ready to send a
-     reply. Our job is to fill in all the fields of the TCP and IP
-     headers before calculating the checksum and finally send the
-     packet. */
- tcp_send:
-  BUF->ackno[0] = uip_connr->rcv_nxt[0];
-  BUF->ackno[1] = uip_connr->rcv_nxt[1];
-  BUF->ackno[2] = uip_connr->rcv_nxt[2];
-  BUF->ackno[3] = uip_connr->rcv_nxt[3];
-  
-  BUF->seqno[0] = uip_connr->snd_nxt[0];
-  BUF->seqno[1] = uip_connr->snd_nxt[1];
-  BUF->seqno[2] = uip_connr->snd_nxt[2];
-  BUF->seqno[3] = uip_connr->snd_nxt[3];
-
-  BUF->proto = UIP_PROTO_TCP;
-  
-  BUF->srcport  = uip_connr->lport;
-  BUF->destport = uip_connr->rport;
-
-  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
-  uip_ipaddr_copy(&BUF->destipaddr, &uip_connr->ripaddr);
-
-  if(uip_connr->tcpstateflags & UIP_STOPPED) {
-    /* If the connection has issued uip_stop(), we advertise a zero
-       window so that the remote host will stop sending data. */
-    BUF->wnd[0] = BUF->wnd[1] = 0;
-  } else {
-    BUF->wnd[0] = ((UIP_RECEIVE_WINDOW) >> 8);
-    BUF->wnd[1] = ((UIP_RECEIVE_WINDOW) & 0xff);
-  }
-
- tcp_send_noconn:
-  BUF->ttl = UIP_TTL;
-#if UIP_CONF_IPV6
-  /* For IPv6, the IP length field does not include the IPv6 IP header
-     length. */
-  BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
-  BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
-#else /* UIP_CONF_IPV6 */
-  BUF->len[0] = (uip_len >> 8);
-  BUF->len[1] = (uip_len & 0xff);
-#endif /* UIP_CONF_IPV6 */
-
-  BUF->urgp[0] = BUF->urgp[1] = 0;
-  
-  /* Calculate TCP checksum. */
-  BUF->tcpchksum = 0;
-  BUF->tcpchksum = ~(uip_tcpchksum());
-
- ip_send_nolen:
-#if UIP_CONF_IPV6
-  BUF->vtc = 0x60;
-  BUF->tcflow = 0x00;
-  BUF->flow = 0x00;
-#else /* UIP_CONF_IPV6 */
-  BUF->vhl = 0x45;
-  BUF->tos = 0;
-  BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
-  ++ipid;
-  BUF->ipid[0] = ipid >> 8;
-  BUF->ipid[1] = ipid & 0xff;
-  /* Calculate IP checksum. */
-  BUF->ipchksum = 0;
-  BUF->ipchksum = ~(uip_ipchksum());
-  DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum());
-#endif /* UIP_CONF_IPV6 */   
-  UIP_STAT(++uip_stat.tcp.sent);
-#if UIP_CONF_IPV6
- send:
-#endif /* UIP_CONF_IPV6 */
-  DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,
-              (BUF->len[0] << 8) | BUF->len[1]);
-  
-  UIP_STAT(++uip_stat.ip.sent);
-  /* Return and let the caller do the actual transmission. */
-  uip_flags = 0;
-  return;
-
- drop:
-  uip_len = 0;
-  uip_flags = 0;
-  return;
-}
-/*---------------------------------------------------------------------------*/
-u16_t
-htons(u16_t val)
-{
-  return HTONS(val);
-}
-
-u32_t
-htonl(u32_t val)
-{
-  return HTONL(val);
-}
-/*---------------------------------------------------------------------------*/
-void
-uip_send(const void *data, int len)
-{
-  int copylen;
-#define MIN(a,b) ((a) < (b)? (a): (b))
-  copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN -
-               (int)((char *)uip_sappdata - (char *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]));
-  if(copylen > 0) {
-    uip_slen = copylen;
-    if(data != uip_sappdata) {
-      memcpy(uip_sappdata, (data), uip_slen);
-    }
-  }
-}
-/*---------------------------------------------------------------------------*/
-/** @} */
-#endif /* UIP_CONF_IPV6 */
+#define DEBUG_PRINTF(...) /*printf(__VA_ARGS__)*/\r
+\r
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * The uIP TCP/IP stack code.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ *    products derived from this software without specific prior\r
+ *    written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip.c,v 1.15 2008/10/15 08:08:32 adamdunkels Exp $\r
+ *\r
+ */\r
+\r
+/*\r
+ * uIP is a small implementation of the IP, UDP and TCP protocols (as\r
+ * well as some basic ICMP stuff). The implementation couples the IP,\r
+ * UDP, TCP and the application layers very tightly. To keep the size\r
+ * of the compiled code down, this code frequently uses the goto\r
+ * statement. While it would be possible to break the uip_process()\r
+ * function into many smaller functions, this would increase the code\r
+ * size because of the overhead of parameter passing and the fact that\r
+ * the optimier would not be as efficient.\r
+ *\r
+ * The principle is that we have a small buffer, called the uip_buf,\r
+ * in which the device driver puts an incoming packet. The TCP/IP\r
+ * stack parses the headers in the packet, and calls the\r
+ * application. If the remote host has sent data to the application,\r
+ * this data is present in the uip_buf and the application read the\r
+ * data from there. It is up to the application to put this data into\r
+ * a byte stream if needed. The application will not be fed with data\r
+ * that is out of sequence.\r
+ *\r
+ * If the application whishes to send data to the peer, it should put\r
+ * its data into the uip_buf. The uip_appdata pointer points to the\r
+ * first available byte. The TCP/IP stack will calculate the\r
+ * checksums, and fill in the necessary header fields and finally send\r
+ * the packet back to the peer.\r
+*/\r
+\r
+#include "uip.h"\r
+#include "uipopt.h"\r
+#include "uip_arp.h"\r
+\r
+#if !UIP_CONF_IPV6 /* If UIP_CONF_IPV6 is defined, we compile the\r
+                     uip6.c file instead of this one. Therefore\r
+                     this #ifndef removes the entire compilation\r
+                     output of the uip.c file */\r
+\r
+\r
+#if UIP_CONF_IPV6\r
+#include "net/uip-neighbor.h"\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+#include <string.h>\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* Variable definitions. */\r
+\r
+\r
+/* The IP address of this host. If it is defined to be fixed (by\r
+   setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set\r
+   here. Otherwise, the address */\r
+#if UIP_FIXEDADDR > 0\r
+const uip_ipaddr_t uip_hostaddr =\r
+  { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };\r
+const uip_ipaddr_t uip_draddr =\r
+  { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };\r
+const uip_ipaddr_t uip_netmask =\r
+  { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };\r
+#else\r
+uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;\r
+#endif /* UIP_FIXEDADDR */\r
+\r
+const uip_ipaddr_t uip_broadcast_addr =\r
+#if UIP_CONF_IPV6\r
+  { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+      0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };\r
+#else /* UIP_CONF_IPV6 */\r
+  { { 0xff, 0xff, 0xff, 0xff } };\r
+#endif /* UIP_CONF_IPV6 */\r
+const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };\r
+\r
+#if UIP_FIXEDETHADDR\r
+const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,\r
+                                         UIP_ETHADDR1,\r
+                                         UIP_ETHADDR2,\r
+                                         UIP_ETHADDR3,\r
+                                         UIP_ETHADDR4,\r
+                                         UIP_ETHADDR5}};\r
+#else\r
+struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};\r
+#endif\r
+\r
+#ifndef UIP_CONF_EXTERNAL_BUFFER\r
+u8_t uip_buf[UIP_BUFSIZE + 2];   /* The packet buffer that contains\r
+                                   incoming packets. */\r
+#endif /* UIP_CONF_EXTERNAL_BUFFER */\r
+\r
+void *uip_appdata;               /* The uip_appdata pointer points to\r
+                                   application data. */\r
+void *uip_sappdata;              /* The uip_appdata pointer points to\r
+                                   the application data which is to\r
+                                   be sent. */\r
+#if UIP_URGDATA > 0\r
+void *uip_urgdata;               /* The uip_urgdata pointer points to\r
+                                   urgent data (out-of-band data), if\r
+                                   present. */\r
+u16_t uip_urglen, uip_surglen;\r
+#endif /* UIP_URGDATA > 0 */\r
+\r
+u16_t uip_len, uip_slen;\r
+                             /* The uip_len is either 8 or 16 bits,\r
+                               depending on the maximum packet\r
+                               size. */\r
+\r
+u8_t uip_flags;     /* The uip_flags variable is used for\r
+                               communication between the TCP/IP stack\r
+                               and the application program. */\r
+struct uip_conn *uip_conn;   /* uip_conn always points to the current\r
+                               connection. */\r
+\r
+struct uip_conn uip_conns[UIP_CONNS];\r
+                             /* The uip_conns array holds all TCP\r
+                               connections. */\r
+u16_t uip_listenports[UIP_LISTENPORTS];\r
+                             /* The uip_listenports list all currently\r
+                               listning ports. */\r
+#if UIP_UDP\r
+struct uip_udp_conn *uip_udp_conn;\r
+struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];\r
+#endif /* UIP_UDP */\r
+\r
+static u16_t ipid;           /* Ths ipid variable is an increasing\r
+                               number that is used for the IP ID\r
+                               field. */\r
+\r
+void uip_setipid(u16_t id) { ipid = id; }\r
+\r
+static u8_t iss[4];          /* The iss variable is used for the TCP\r
+                               initial sequence number. */\r
+\r
+#if UIP_ACTIVE_OPEN\r
+static u16_t lastport;       /* Keeps track of the last port used for\r
+                               a new connection. */\r
+#endif /* UIP_ACTIVE_OPEN */\r
+\r
+/* Temporary variables. */\r
+u8_t uip_acc32[4];\r
+static u8_t c, opt;\r
+static u16_t tmp16;\r
+\r
+/* Structures and definitions. */\r
+#define TCP_FIN 0x01\r
+#define TCP_SYN 0x02\r
+#define TCP_RST 0x04\r
+#define TCP_PSH 0x08\r
+#define TCP_ACK 0x10\r
+#define TCP_URG 0x20\r
+#define TCP_CTL 0x3f\r
+\r
+#define TCP_OPT_END     0   /* End of TCP options list */\r
+#define TCP_OPT_NOOP    1   /* "No-operation" TCP option */\r
+#define TCP_OPT_MSS     2   /* Maximum segment size TCP option */\r
+\r
+#define TCP_OPT_MSS_LEN 4   /* Length of TCP MSS option. */\r
+\r
+#define ICMP_ECHO_REPLY 0\r
+#define ICMP_ECHO       8\r
+\r
+#define ICMP_DEST_UNREACHABLE        3\r
+#define ICMP_PORT_UNREACHABLE        3\r
+\r
+#define ICMP6_ECHO_REPLY             129\r
+#define ICMP6_ECHO                   128\r
+#define ICMP6_NEIGHBOR_SOLICITATION  135\r
+#define ICMP6_NEIGHBOR_ADVERTISEMENT 136\r
+\r
+#define ICMP6_FLAG_S (1 << 6)\r
+\r
+#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1\r
+#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2\r
+\r
+\r
+/* Macros. */\r
+#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
+#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])\r
+#define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
+#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
+\r
+\r
+#if UIP_STATISTICS == 1\r
+struct uip_stats uip_stat;\r
+#define UIP_STAT(s) s\r
+#else\r
+#define UIP_STAT(s)\r
+#endif /* UIP_STATISTICS == 1 */\r
+\r
+#if UIP_LOGGING == 1\r
+#include <stdio.h>\r
+void uip_log(char *msg);\r
+#define UIP_LOG(m) uip_log(m)\r
+#else\r
+#define UIP_LOG(m)\r
+#endif /* UIP_LOGGING == 1 */\r
+\r
+#if ! UIP_ARCH_ADD32\r
+void\r
+uip_add32(u8_t *op32, u16_t op16)\r
+{\r
+  uip_acc32[3] = op32[3] + (op16 & 0xff);\r
+  uip_acc32[2] = op32[2] + (op16 >> 8);\r
+  uip_acc32[1] = op32[1];\r
+  uip_acc32[0] = op32[0];\r
+  \r
+  if(uip_acc32[2] < (op16 >> 8)) {\r
+    ++uip_acc32[1];\r
+    if(uip_acc32[1] == 0) {\r
+      ++uip_acc32[0];\r
+    }\r
+  }\r
+  \r
+  \r
+  if(uip_acc32[3] < (op16 & 0xff)) {\r
+    ++uip_acc32[2];\r
+    if(uip_acc32[2] == 0) {\r
+      ++uip_acc32[1];\r
+      if(uip_acc32[1] == 0) {\r
+       ++uip_acc32[0];\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+#endif /* UIP_ARCH_ADD32 */\r
+\r
+#if ! UIP_ARCH_CHKSUM\r
+/*---------------------------------------------------------------------------*/\r
+static u16_t\r
+chksum(u16_t sum, const u8_t *data, u16_t len)\r
+{\r
+  u16_t t;\r
+  const u8_t *dataptr;\r
+  const u8_t *last_byte;\r
+\r
+  dataptr = data;\r
+  last_byte = data + len - 1;\r
+  \r
+  while(dataptr < last_byte) { /* At least two more bytes */\r
+    t = (dataptr[0] << 8) + dataptr[1];\r
+    sum += t;\r
+    if(sum < t) {\r
+      sum++;           /* carry */\r
+    }\r
+    dataptr += 2;\r
+  }\r
+  \r
+  if(dataptr == last_byte) {\r
+    t = (dataptr[0] << 8) + 0;\r
+    sum += t;\r
+    if(sum < t) {\r
+      sum++;           /* carry */\r
+    }\r
+  }\r
+\r
+  /* Return sum in host byte order. */\r
+  return sum;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+u16_t\r
+uip_chksum(u16_t *data, u16_t len)\r
+{\r
+  return htons(chksum(0, (u8_t *)data, len));\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#ifndef UIP_ARCH_IPCHKSUM\r
+u16_t\r
+uip_ipchksum(void)\r
+{\r
+  u16_t sum;\r
+\r
+  sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);\r
+  DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);\r
+  return (sum == 0) ? 0xffff : htons(sum);\r
+}\r
+#endif\r
+/*---------------------------------------------------------------------------*/\r
+static u16_t\r
+upper_layer_chksum(u8_t proto)\r
+{\r
+  u16_t upper_layer_len;\r
+  u16_t sum;\r
+  \r
+#if UIP_CONF_IPV6\r
+  upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]);\r
+#else /* UIP_CONF_IPV6 */\r
+  upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;\r
+#endif /* UIP_CONF_IPV6 */\r
+  \r
+  /* First sum pseudoheader. */\r
+  \r
+  /* IP protocol and length fields. This addition cannot carry. */\r
+  sum = upper_layer_len + proto;\r
+  /* Sum IP source and destination addresses. */\r
+  sum = chksum(sum, (u8_t *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));\r
+\r
+  /* Sum TCP header and data. */\r
+  sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],\r
+              upper_layer_len);\r
+    \r
+  return (sum == 0) ? 0xffff : htons(sum);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_CONF_IPV6\r
+u16_t\r
+uip_icmp6chksum(void)\r
+{\r
+  return upper_layer_chksum(UIP_PROTO_ICMP6);\r
+  \r
+}\r
+#endif /* UIP_CONF_IPV6 */\r
+/*---------------------------------------------------------------------------*/\r
+u16_t\r
+uip_tcpchksum(void)\r
+{\r
+  return upper_layer_chksum(UIP_PROTO_TCP);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_UDP_CHECKSUMS\r
+u16_t\r
+uip_udpchksum(void)\r
+{\r
+  return upper_layer_chksum(UIP_PROTO_UDP);\r
+}\r
+#endif /* UIP_UDP_CHECKSUMS */\r
+#endif /* UIP_ARCH_CHKSUM */\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_init(void)\r
+{\r
+  for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+    uip_listenports[c] = 0;\r
+  }\r
+  for(c = 0; c < UIP_CONNS; ++c) {\r
+    uip_conns[c].tcpstateflags = UIP_CLOSED;\r
+  }\r
+#if UIP_ACTIVE_OPEN\r
+  lastport = 1024;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+\r
+#if UIP_UDP\r
+  for(c = 0; c < UIP_UDP_CONNS; ++c) {\r
+    uip_udp_conns[c].lport = 0;\r
+  }\r
+#endif /* UIP_UDP */\r
+  \r
+\r
+  /* IPv4 initialization. */\r
+#if UIP_FIXEDADDR == 0\r
+  /*  uip_hostaddr[0] = uip_hostaddr[1] = 0;*/\r
+#endif /* UIP_FIXEDADDR */\r
+\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_ACTIVE_OPEN\r
+struct uip_conn *\r
+uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)\r
+{\r
+  register struct uip_conn *conn, *cconn;\r
+  \r
+  /* Find an unused local port. */\r
+ again:\r
+  ++lastport;\r
+\r
+  if(lastport >= 32000) {\r
+    lastport = 4096;\r
+  }\r
+\r
+  /* Check if this port is already in use, and if so try to find\r
+     another one. */\r
+  for(c = 0; c < UIP_CONNS; ++c) {\r
+    conn = &uip_conns[c];\r
+    if(conn->tcpstateflags != UIP_CLOSED &&\r
+       conn->lport == htons(lastport)) {\r
+      goto again;\r
+    }\r
+  }\r
+\r
+  conn = 0;\r
+  for(c = 0; c < UIP_CONNS; ++c) {\r
+    cconn = &uip_conns[c];\r
+    if(cconn->tcpstateflags == UIP_CLOSED) {\r
+      conn = cconn;\r
+      break;\r
+    }\r
+    if(cconn->tcpstateflags == UIP_TIME_WAIT) {\r
+      if(conn == 0 ||\r
+        cconn->timer > conn->timer) {\r
+       conn = cconn;\r
+      }\r
+    }\r
+  }\r
+\r
+  if(conn == 0) {\r
+    return 0;\r
+  }\r
+  \r
+  conn->tcpstateflags = UIP_SYN_SENT;\r
+\r
+  conn->snd_nxt[0] = iss[0];\r
+  conn->snd_nxt[1] = iss[1];\r
+  conn->snd_nxt[2] = iss[2];\r
+  conn->snd_nxt[3] = iss[3];\r
+\r
+  conn->initialmss = conn->mss = UIP_TCP_MSS;\r
+  \r
+  conn->len = 1;   /* TCP length of the SYN is one. */\r
+  conn->nrtx = 0;\r
+  conn->timer = 1; /* Send the SYN next time around. */\r
+  conn->rto = UIP_RTO;\r
+  conn->sa = 0;\r
+  conn->sv = 16;   /* Initial value of the RTT variance. */\r
+  conn->lport = htons(lastport);\r
+  conn->rport = rport;\r
+  uip_ipaddr_copy(&conn->ripaddr, ripaddr);\r
+  \r
+  return conn;\r
+}\r
+#endif /* UIP_ACTIVE_OPEN */\r
+/*---------------------------------------------------------------------------*/\r
+#if UIP_UDP\r
+struct uip_udp_conn *\r
+uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport)\r
+{\r
+  register struct uip_udp_conn *conn;\r
+  \r
+  /* Find an unused local port. */\r
+ again:\r
+  ++lastport;\r
+\r
+  if(lastport >= 32000) {\r
+    lastport = 4096;\r
+  }\r
+  \r
+  for(c = 0; c < UIP_UDP_CONNS; ++c) {\r
+    if(uip_udp_conns[c].lport == htons(lastport)) {\r
+      goto again;\r
+    }\r
+  }\r
+\r
+\r
+  conn = 0;\r
+  for(c = 0; c < UIP_UDP_CONNS; ++c) {\r
+    if(uip_udp_conns[c].lport == 0) {\r
+      conn = &uip_udp_conns[c];\r
+      break;\r
+    }\r
+  }\r
+\r
+  if(conn == 0) {\r
+    return 0;\r
+  }\r
+  \r
+  conn->lport = HTONS(lastport);\r
+  conn->rport = rport;\r
+  if(ripaddr == NULL) {\r
+    memset(&conn->ripaddr, 0, sizeof(uip_ipaddr_t));\r
+  } else {\r
+    uip_ipaddr_copy(&conn->ripaddr, ripaddr);\r
+  }\r
+  conn->ttl = UIP_TTL;\r
+  \r
+  return conn;\r
+}\r
+#endif /* UIP_UDP */\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_unlisten(u16_t port)\r
+{\r
+  for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+    if(uip_listenports[c] == port) {\r
+      uip_listenports[c] = 0;\r
+      return;\r
+    }\r
+  }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_listen(u16_t port)\r
+{\r
+  for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+    if(uip_listenports[c] == 0) {\r
+      uip_listenports[c] = port;\r
+      return;\r
+    }\r
+  }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/* XXX: IP fragment reassembly: not well-tested. */\r
+\r
+#if UIP_REASSEMBLY && !UIP_CONF_IPV6\r
+#define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)\r
+static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];\r
+static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];\r
+static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,\r
+                                   0x0f, 0x07, 0x03, 0x01};\r
+static u16_t uip_reasslen;\r
+static u8_t uip_reassflags;\r
+#define UIP_REASS_FLAG_LASTFRAG 0x01\r
+static u8_t uip_reasstmr;\r
+\r
+#define IP_MF   0x20\r
+\r
+static u8_t\r
+uip_reass(void)\r
+{\r
+  u16_t offset, len;\r
+  u16_t i;\r
+\r
+  /* If ip_reasstmr is zero, no packet is present in the buffer, so we\r
+     write the IP header of the fragment into the reassembly\r
+     buffer. The timer is updated with the maximum age. */\r
+  if(uip_reasstmr == 0) {\r
+    memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN);\r
+    uip_reasstmr = UIP_REASS_MAXAGE;\r
+    uip_reassflags = 0;\r
+    /* Clear the bitmap. */\r
+    memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap));\r
+  }\r
+\r
+  /* Check if the incoming fragment matches the one currently present\r
+     in the reasembly buffer. If so, we proceed with copying the\r
+     fragment into the buffer. */\r
+  if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&\r
+     BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&\r
+     BUF->destipaddr[0] == FBUF->destipaddr[0] &&\r
+     BUF->destipaddr[1] == FBUF->destipaddr[1] &&\r
+     BUF->ipid[0] == FBUF->ipid[0] &&\r
+     BUF->ipid[1] == FBUF->ipid[1]) {\r
+\r
+    len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;\r
+    offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;\r
+\r
+    /* If the offset or the offset + fragment length overflows the\r
+       reassembly buffer, we discard the entire packet. */\r
+    if(offset > UIP_REASS_BUFSIZE ||\r
+       offset + len > UIP_REASS_BUFSIZE) {\r
+      uip_reasstmr = 0;\r
+      goto nullreturn;\r
+    }\r
+\r
+    /* Copy the fragment into the reassembly buffer, at the right\r
+       offset. */\r
+    memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],\r
+          (char *)BUF + (int)((BUF->vhl & 0x0f) * 4),\r
+          len);\r
+      \r
+    /* Update the bitmap. */\r
+    if(offset / (8 * 8) == (offset + len) / (8 * 8)) {\r
+      /* If the two endpoints are in the same byte, we only update\r
+        that byte. */\r
+            \r
+      uip_reassbitmap[offset / (8 * 8)] |=\r
+            bitmap_bits[(offset / 8 ) & 7] &\r
+            ~bitmap_bits[((offset + len) / 8 ) & 7];\r
+    } else {\r
+      /* If the two endpoints are in different bytes, we update the\r
+        bytes in the endpoints and fill the stuff inbetween with\r
+        0xff. */\r
+      uip_reassbitmap[offset / (8 * 8)] |=\r
+       bitmap_bits[(offset / 8 ) & 7];\r
+      for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {\r
+       uip_reassbitmap[i] = 0xff;\r
+      }\r
+      uip_reassbitmap[(offset + len) / (8 * 8)] |=\r
+       ~bitmap_bits[((offset + len) / 8 ) & 7];\r
+    }\r
+    \r
+    /* If this fragment has the More Fragments flag set to zero, we\r
+       know that this is the last fragment, so we can calculate the\r
+       size of the entire packet. We also set the\r
+       IP_REASS_FLAG_LASTFRAG flag to indicate that we have received\r
+       the final fragment. */\r
+\r
+    if((BUF->ipoffset[0] & IP_MF) == 0) {\r
+      uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;\r
+      uip_reasslen = offset + len;\r
+    }\r
+    \r
+    /* Finally, we check if we have a full packet in the buffer. We do\r
+       this by checking if we have the last fragment and if all bits\r
+       in the bitmap are set. */\r
+    if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {\r
+      /* Check all bytes up to and including all but the last byte in\r
+        the bitmap. */\r
+      for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {\r
+       if(uip_reassbitmap[i] != 0xff) {\r
+         goto nullreturn;\r
+       }\r
+      }\r
+      /* Check the last byte in the bitmap. It should contain just the\r
+        right amount of bits. */\r
+      if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=\r
+        (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {\r
+       goto nullreturn;\r
+      }\r
+\r
+      /* If we have come this far, we have a full packet in the\r
+        buffer, so we allocate a pbuf and copy the packet into it. We\r
+        also reset the timer. */\r
+      uip_reasstmr = 0;\r
+      memcpy(BUF, FBUF, uip_reasslen);\r
+\r
+      /* Pretend to be a "normal" (i.e., not fragmented) IP packet\r
+        from now on. */\r
+      BUF->ipoffset[0] = BUF->ipoffset[1] = 0;\r
+      BUF->len[0] = uip_reasslen >> 8;\r
+      BUF->len[1] = uip_reasslen & 0xff;\r
+      BUF->ipchksum = 0;\r
+      BUF->ipchksum = ~(uip_ipchksum());\r
+\r
+      return uip_reasslen;\r
+    }\r
+  }\r
+\r
+ nullreturn:\r
+  return 0;\r
+}\r
+#endif /* UIP_REASSEMBLY */\r
+/*---------------------------------------------------------------------------*/\r
+static void\r
+uip_add_rcv_nxt(u16_t n)\r
+{\r
+  uip_add32(uip_conn->rcv_nxt, n);\r
+  uip_conn->rcv_nxt[0] = uip_acc32[0];\r
+  uip_conn->rcv_nxt[1] = uip_acc32[1];\r
+  uip_conn->rcv_nxt[2] = uip_acc32[2];\r
+  uip_conn->rcv_nxt[3] = uip_acc32[3];\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_process(u8_t flag)\r
+{\r
+  register struct uip_conn *uip_connr = uip_conn;\r
+\r
+#if UIP_UDP\r
+  if(flag == UIP_UDP_SEND_CONN) {\r
+    goto udp_send;\r
+  }\r
+#endif /* UIP_UDP */\r
+  \r
+  uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];\r
+\r
+  /* Check if we were invoked because of a poll request for a\r
+     particular connection. */\r
+  if(flag == UIP_POLL_REQUEST) {\r
+    if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&\r
+       !uip_outstanding(uip_connr)) {\r
+       uip_len = uip_slen = 0;\r
+       uip_flags = UIP_POLL;\r
+       UIP_APPCALL();\r
+       goto appsend;\r
+    }\r
+    goto drop;\r
+    \r
+    /* Check if we were invoked because of the perodic timer fireing. */\r
+  } else if(flag == UIP_TIMER) {\r
+#if UIP_REASSEMBLY\r
+    if(uip_reasstmr != 0) {\r
+      --uip_reasstmr;\r
+    }\r
+#endif /* UIP_REASSEMBLY */\r
+    /* Increase the initial sequence number. */\r
+    if(++iss[3] == 0) {\r
+      if(++iss[2] == 0) {\r
+       if(++iss[1] == 0) {\r
+         ++iss[0];\r
+       }\r
+      }\r
+    }\r
+\r
+    /* Reset the length variables. */\r
+    uip_len = 0;\r
+    uip_slen = 0;\r
+\r
+    /* Check if the connection is in a state in which we simply wait\r
+       for the connection to time out. If so, we increase the\r
+       connection's timer and remove the connection if it times\r
+       out. */\r
+    if(uip_connr->tcpstateflags == UIP_TIME_WAIT ||\r
+       uip_connr->tcpstateflags == UIP_FIN_WAIT_2) {\r
+      ++(uip_connr->timer);\r
+      if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {\r
+       uip_connr->tcpstateflags = UIP_CLOSED;\r
+      }\r
+    } else if(uip_connr->tcpstateflags != UIP_CLOSED) {\r
+      /* If the connection has outstanding data, we increase the\r
+        connection's timer and see if it has reached the RTO value\r
+        in which case we retransmit. */\r
+      if(uip_outstanding(uip_connr)) {\r
+       if(uip_connr->timer-- == 0) {\r
+         if(uip_connr->nrtx == UIP_MAXRTX ||\r
+            ((uip_connr->tcpstateflags == UIP_SYN_SENT ||\r
+              uip_connr->tcpstateflags == UIP_SYN_RCVD) &&\r
+             uip_connr->nrtx == UIP_MAXSYNRTX)) {\r
+           uip_connr->tcpstateflags = UIP_CLOSED;\r
+\r
+           /* We call UIP_APPCALL() with uip_flags set to\r
+              UIP_TIMEDOUT to inform the application that the\r
+              connection has timed out. */\r
+           uip_flags = UIP_TIMEDOUT;\r
+           UIP_APPCALL();\r
+\r
+           /* We also send a reset packet to the remote host. */\r
+           BUF->flags = TCP_RST | TCP_ACK;\r
+           goto tcp_send_nodata;\r
+         }\r
+\r
+         /* Exponential backoff. */\r
+         uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?\r
+                                        4:\r
+                                        uip_connr->nrtx);\r
+         ++(uip_connr->nrtx);\r
+         \r
+         /* Ok, so we need to retransmit. We do this differently\r
+            depending on which state we are in. In ESTABLISHED, we\r
+            call upon the application so that it may prepare the\r
+            data for the retransmit. In SYN_RCVD, we resend the\r
+            SYNACK that we sent earlier and in LAST_ACK we have to\r
+            retransmit our FINACK. */\r
+         UIP_STAT(++uip_stat.tcp.rexmit);\r
+         switch(uip_connr->tcpstateflags & UIP_TS_MASK) {\r
+         case UIP_SYN_RCVD:\r
+           /* In the SYN_RCVD state, we should retransmit our\r
+               SYNACK. */\r
+           goto tcp_send_synack;\r
+           \r
+#if UIP_ACTIVE_OPEN\r
+         case UIP_SYN_SENT:\r
+           /* In the SYN_SENT state, we retransmit out SYN. */\r
+           BUF->flags = 0;\r
+           goto tcp_send_syn;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+           \r
+         case UIP_ESTABLISHED:\r
+           /* In the ESTABLISHED state, we call upon the application\r
+               to do the actual retransmit after which we jump into\r
+               the code for sending out the packet (the apprexmit\r
+               label). */\r
+           uip_flags = UIP_REXMIT;\r
+           UIP_APPCALL();\r
+           goto apprexmit;\r
+           \r
+         case UIP_FIN_WAIT_1:\r
+         case UIP_CLOSING:\r
+         case UIP_LAST_ACK:\r
+           /* In all these states we should retransmit a FINACK. */\r
+           goto tcp_send_finack;\r
+           \r
+         }\r
+       }\r
+      } else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {\r
+       /* If there was no need for a retransmission, we poll the\r
+           application for new data. */\r
+       uip_len = uip_slen = 0;            \r
+       uip_flags = UIP_POLL;\r
+       UIP_APPCALL();\r
+       goto appsend;\r
+      }\r
+    }\r
+    goto drop;\r
+  }\r
+#if UIP_UDP\r
+  if(flag == UIP_UDP_TIMER) {\r
+    if(uip_udp_conn->lport != 0) {\r
+      uip_conn = NULL;\r
+      uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
+      uip_len = uip_slen = 0;\r
+      uip_flags = UIP_POLL;\r
+      UIP_UDP_APPCALL();\r
+      goto udp_send;\r
+    } else {\r
+      goto drop;\r
+    }\r
+  }\r
+#endif\r
+\r
+  /* This is where the input processing starts. */\r
+  UIP_STAT(++uip_stat.ip.recv);\r
+\r
+  /* Start of IP input header processing code. */\r
+  \r
+#if UIP_CONF_IPV6\r
+  /* Check validity of the IP header. */\r
+  if((BUF->vtc & 0xf0) != 0x60)  { /* IP version and header length. */\r
+    UIP_STAT(++uip_stat.ip.drop);\r
+    UIP_STAT(++uip_stat.ip.vhlerr);\r
+    UIP_LOG("ipv6: invalid version.");\r
+    goto drop;\r
+  }\r
+#else /* UIP_CONF_IPV6 */\r
+  /* Check validity of the IP header. */\r
+  if(BUF->vhl != 0x45)  { /* IP version and header length. */\r
+    UIP_STAT(++uip_stat.ip.drop);\r
+    UIP_STAT(++uip_stat.ip.vhlerr);\r
+    UIP_LOG("ip: invalid version or header length.");\r
+    goto drop;\r
+  }\r
+#endif /* UIP_CONF_IPV6 */\r
+  \r
+  /* Check the size of the packet. If the size reported to us in\r
+     uip_len is smaller the size reported in the IP header, we assume\r
+     that the packet has been corrupted in transit. If the size of\r
+     uip_len is larger than the size reported in the IP packet header,\r
+     the packet has been padded and we set uip_len to the correct\r
+     value.. */\r
+\r
+  if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {\r
+    uip_len = (BUF->len[0] << 8) + BUF->len[1];\r
+#if UIP_CONF_IPV6\r
+    uip_len += 40; /* The length reported in the IPv6 header is the\r
+                     length of the payload that follows the\r
+                     header. However, uIP uses the uip_len variable\r
+                     for holding the size of the entire packet,\r
+                     including the IP header. For IPv4 this is not a\r
+                     problem as the length field in the IPv4 header\r
+                     contains the length of the entire packet. But\r
+                     for IPv6 we need to add the size of the IPv6\r
+                     header (40 bytes). */\r
+#endif /* UIP_CONF_IPV6 */\r
+  } else {\r
+    UIP_LOG("ip: packet shorter than reported in IP header.");\r
+    goto drop;\r
+  }\r
+\r
+#if !UIP_CONF_IPV6\r
+  /* Check the fragment flag. */\r
+  if((BUF->ipoffset[0] & 0x3f) != 0 ||\r
+     BUF->ipoffset[1] != 0) {\r
+#if UIP_REASSEMBLY\r
+    uip_len = uip_reass();\r
+    if(uip_len == 0) {\r
+      goto drop;\r
+    }\r
+#else /* UIP_REASSEMBLY */\r
+    UIP_STAT(++uip_stat.ip.drop);\r
+    UIP_STAT(++uip_stat.ip.fragerr);\r
+    UIP_LOG("ip: fragment dropped.");\r
+    goto drop;\r
+#endif /* UIP_REASSEMBLY */\r
+  }\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {\r
+    /* If we are configured to use ping IP address configuration and\r
+       hasn't been assigned an IP address yet, we accept all ICMP\r
+       packets. */\r
+#if UIP_PINGADDRCONF && !UIP_CONF_IPV6\r
+    if(BUF->proto == UIP_PROTO_ICMP) {\r
+      UIP_LOG("ip: possible ping config packet received.");\r
+      goto icmp_input;\r
+    } else {\r
+      UIP_LOG("ip: packet dropped since no address assigned.");\r
+      goto drop;\r
+    }\r
+#endif /* UIP_PINGADDRCONF */\r
+\r
+  } else {\r
+    /* If IP broadcast support is configured, we check for a broadcast\r
+       UDP packet, which may be destined to us. */\r
+#if UIP_BROADCAST\r
+    DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());\r
+    if(BUF->proto == UIP_PROTO_UDP &&\r
+       uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)\r
+       /*&&\r
+        uip_ipchksum() == 0xffff*/) {\r
+      goto udp_input;\r
+    }\r
+#endif /* UIP_BROADCAST */\r
+    \r
+    /* Check if the packet is destined for our IP address. */\r
+#if !UIP_CONF_IPV6\r
+    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {\r
+      UIP_STAT(++uip_stat.ip.drop);\r
+      goto drop;\r
+    }\r
+#else /* UIP_CONF_IPV6 */\r
+    /* For IPv6, packet reception is a little trickier as we need to\r
+       make sure that we listen to certain multicast addresses (all\r
+       hosts multicast address, and the solicited-node multicast\r
+       address) as well. However, we will cheat here and accept all\r
+       multicast packets that are sent to the ff02::/16 addresses. */\r
+    if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) &&\r
+       BUF->destipaddr.u16[0] != HTONS(0xff02)) {\r
+      UIP_STAT(++uip_stat.ip.drop);\r
+      goto drop;\r
+    }\r
+#endif /* UIP_CONF_IPV6 */\r
+  }\r
+\r
+#if !UIP_CONF_IPV6\r
+  if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header\r
+                                   checksum. */\r
+    UIP_STAT(++uip_stat.ip.drop);\r
+    UIP_STAT(++uip_stat.ip.chkerr);\r
+    UIP_LOG("ip: bad checksum.");\r
+    goto drop;\r
+  }\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+  if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so,\r
+                                      proceed with TCP input\r
+                                      processing. */\r
+    goto tcp_input;\r
+  }\r
+\r
+#if UIP_UDP\r
+  if(BUF->proto == UIP_PROTO_UDP) {\r
+    goto udp_input;\r
+  }\r
+#endif /* UIP_UDP */\r
+\r
+#if !UIP_CONF_IPV6\r
+  /* ICMPv4 processing code follows. */\r
+  if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from\r
+                                       here. */\r
+    UIP_STAT(++uip_stat.ip.drop);\r
+    UIP_STAT(++uip_stat.ip.protoerr);\r
+    UIP_LOG("ip: neither tcp nor icmp.");\r
+    goto drop;\r
+  }\r
+\r
+#if UIP_PINGADDRCONF\r
+ icmp_input:\r
+#endif /* UIP_PINGADDRCONF */\r
+  UIP_STAT(++uip_stat.icmp.recv);\r
+\r
+  /* ICMP echo (i.e., ping) processing. This is simple, we only change\r
+     the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP\r
+     checksum before we return the packet. */\r
+  if(ICMPBUF->type != ICMP_ECHO) {\r
+    UIP_STAT(++uip_stat.icmp.drop);\r
+    UIP_STAT(++uip_stat.icmp.typeerr);\r
+    UIP_LOG("icmp: not icmp echo.");\r
+    goto drop;\r
+  }\r
+\r
+  /* If we are configured to use ping IP address assignment, we use\r
+     the destination IP address of this ping packet and assign it to\r
+     ourself. */\r
+#if UIP_PINGADDRCONF\r
+  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {\r
+    uip_hostaddr = BUF->destipaddr;\r
+  }\r
+#endif /* UIP_PINGADDRCONF */\r
+\r
+  ICMPBUF->type = ICMP_ECHO_REPLY;\r
+\r
+  if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {\r
+    ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;\r
+  } else {\r
+    ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);\r
+  }\r
+\r
+  /* Swap IP addresses. */\r
+  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);\r
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);\r
+\r
+  UIP_STAT(++uip_stat.icmp.sent);\r
+  BUF->ttl = UIP_TTL;\r
+  goto ip_send_nolen;\r
+\r
+  /* End of IPv4 input header processing code. */\r
+#else /* !UIP_CONF_IPV6 */\r
+\r
+  /* This is IPv6 ICMPv6 processing code. */\r
+  DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);\r
+\r
+  if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from\r
+                                        here. */\r
+    UIP_STAT(++uip_stat.ip.drop);\r
+    UIP_STAT(++uip_stat.ip.protoerr);\r
+    UIP_LOG("ip: neither tcp nor icmp6.");\r
+    goto drop;\r
+  }\r
+\r
+  UIP_STAT(++uip_stat.icmp.recv);\r
+\r
+  /* If we get a neighbor solicitation for our address we should send\r
+     a neighbor advertisement message back. */\r
+  if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {\r
+    if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) {\r
+\r
+      if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {\r
+       /* Save the sender's address in our neighbor list. */\r
+       uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));\r
+      }\r
+      \r
+      /* We should now send a neighbor advertisement back to where the\r
+        neighbor solicication came from. */\r
+      ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;\r
+      ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */\r
+      \r
+      ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;\r
+      \r
+      uip_ipaddr_copy(&ICMPBUF->destipaddr, &ICMPBUF->srcipaddr);\r
+      uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr);\r
+      ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;\r
+      ICMPBUF->options[1] = 1;  /* Options length, 1 = 8 bytes. */\r
+      memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));\r
+      ICMPBUF->icmpchksum = 0;\r
+      ICMPBUF->icmpchksum = ~uip_icmp6chksum();\r
+      \r
+      goto send;\r
+      \r
+    }\r
+    goto drop;\r
+  } else if(ICMPBUF->type == ICMP6_ECHO) {\r
+    /* ICMP echo (i.e., ping) processing. This is simple, we only\r
+       change the ICMP type from ECHO to ECHO_REPLY and update the\r
+       ICMP checksum before we return the packet. */\r
+\r
+    ICMPBUF->type = ICMP6_ECHO_REPLY;\r
+    \r
+    uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);\r
+    uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);\r
+    ICMPBUF->icmpchksum = 0;\r
+    ICMPBUF->icmpchksum = ~uip_icmp6chksum();\r
+    \r
+    UIP_STAT(++uip_stat.icmp.sent);\r
+    goto send;\r
+  } else {\r
+    DEBUG_PRINTF("Unknown icmp6 message type %d\n", ICMPBUF->type);\r
+    UIP_STAT(++uip_stat.icmp.drop);\r
+    UIP_STAT(++uip_stat.icmp.typeerr);\r
+    UIP_LOG("icmp: unknown ICMP message.");\r
+    goto drop;\r
+  }\r
+\r
+  /* End of IPv6 ICMP processing. */\r
+  \r
+#endif /* !UIP_CONF_IPV6 */\r
+\r
+#if UIP_UDP\r
+  /* UDP input processing. */\r
+ udp_input:\r
+  /* UDP processing is really just a hack. We don't do anything to the\r
+     UDP/IP headers, but let the UDP application do all the hard\r
+     work. If the application sets uip_slen, it has a packet to\r
+     send. */\r
+#if UIP_UDP_CHECKSUMS\r
+  uip_len = uip_len - UIP_IPUDPH_LEN;\r
+  uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
+  if(UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {\r
+    UIP_STAT(++uip_stat.udp.drop);\r
+    UIP_STAT(++uip_stat.udp.chkerr);\r
+    UIP_LOG("udp: bad checksum.");\r
+    goto drop;\r
+  }\r
+#else /* UIP_UDP_CHECKSUMS */\r
+  uip_len = uip_len - UIP_IPUDPH_LEN;\r
+#endif /* UIP_UDP_CHECKSUMS */\r
+\r
+  /* Demultiplex this UDP packet between the UDP "connections". */\r
+  for(uip_udp_conn = &uip_udp_conns[0];\r
+      uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS];\r
+      ++uip_udp_conn) {\r
+    /* If the local UDP port is non-zero, the connection is considered\r
+       to be used. If so, the local port number is checked against the\r
+       destination port number in the received packet. If the two port\r
+       numbers match, the remote port number is checked if the\r
+       connection is bound to a remote port. Finally, if the\r
+       connection is bound to a remote IP address, the source IP\r
+       address of the packet is checked. */\r
+    if(uip_udp_conn->lport != 0 &&\r
+       UDPBUF->destport == uip_udp_conn->lport &&\r
+       (uip_udp_conn->rport == 0 ||\r
+        UDPBUF->srcport == uip_udp_conn->rport) &&\r
+       (uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||\r
+       uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||\r
+       uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr))) {\r
+      goto udp_found;\r
+    }\r
+  }\r
+  UIP_LOG("udp: no matching connection found");\r
+#if UIP_CONF_ICMP_DEST_UNREACH && !UIP_CONF_IPV6\r
+  /* Copy fields from packet header into payload of this ICMP packet. */\r
+  memcpy(&(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8);\r
+\r
+  /* Set the ICMP type and code. */\r
+  ICMPBUF->type = ICMP_DEST_UNREACHABLE;\r
+  ICMPBUF->icode = ICMP_PORT_UNREACHABLE;\r
+\r
+  /* Calculate the ICMP checksum. */\r
+  ICMPBUF->icmpchksum = 0;\r
+  ICMPBUF->icmpchksum = ~uip_chksum((u16_t *)&(ICMPBUF->type), 36);\r
+\r
+  /* Set the IP destination address to be the source address of the\r
+     original packet. */\r
+  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);\r
+\r
+  /* Set our IP address as the source address. */\r
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);\r
+\r
+  /* The size of the ICMP destination unreachable packet is 36 + the\r
+     size of the IP header (20) = 56. */\r
+  uip_len = 36 + UIP_IPH_LEN;\r
+  ICMPBUF->len[0] = 0;\r
+  ICMPBUF->len[1] = (u8_t)uip_len;\r
+  ICMPBUF->ttl = UIP_TTL;\r
+  ICMPBUF->proto = UIP_PROTO_ICMP;\r
+\r
+  goto ip_send_nolen;\r
+#else /* UIP_CONF_ICMP_DEST_UNREACH */\r
+  goto drop;\r
+#endif /* UIP_CONF_ICMP_DEST_UNREACH */\r
+  \r
+ udp_found:\r
+  uip_conn = NULL;\r
+  uip_flags = UIP_NEWDATA;\r
+  uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];\r
+  uip_slen = 0;\r
+  UIP_UDP_APPCALL();\r
+\r
+ udp_send:\r
+  if(uip_slen == 0) {\r
+    goto drop;\r
+  }\r
+  uip_len = uip_slen + UIP_IPUDPH_LEN;\r
+\r
+#if UIP_CONF_IPV6\r
+  /* For IPv6, the IP length field does not include the IPv6 IP header\r
+     length. */\r
+  BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);\r
+  BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);\r
+#else /* UIP_CONF_IPV6 */\r
+  BUF->len[0] = (uip_len >> 8);\r
+  BUF->len[1] = (uip_len & 0xff);\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+  BUF->ttl = uip_udp_conn->ttl;\r
+  BUF->proto = UIP_PROTO_UDP;\r
+\r
+  UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);\r
+  UDPBUF->udpchksum = 0;\r
+\r
+  BUF->srcport  = uip_udp_conn->lport;\r
+  BUF->destport = uip_udp_conn->rport;\r
+\r
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);\r
+  uip_ipaddr_copy(&BUF->destipaddr, &uip_udp_conn->ripaddr);\r
+   \r
+  uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];\r
+\r
+#if UIP_UDP_CHECKSUMS\r
+  /* Calculate UDP checksum. */\r
+  UDPBUF->udpchksum = ~(uip_udpchksum());\r
+  if(UDPBUF->udpchksum == 0) {\r
+    UDPBUF->udpchksum = 0xffff;\r
+  }\r
+#endif /* UIP_UDP_CHECKSUMS */\r
+  \r
+  goto ip_send_nolen;\r
+#endif /* UIP_UDP */\r
+  \r
+  /* TCP input processing. */\r
+ tcp_input:\r
+  UIP_STAT(++uip_stat.tcp.recv);\r
+\r
+  /* Start of TCP input header processing code. */\r
+  \r
+  if(uip_tcpchksum() != 0xffff) {   /* Compute and check the TCP\r
+                                      checksum. */\r
+    UIP_STAT(++uip_stat.tcp.drop);\r
+    UIP_STAT(++uip_stat.tcp.chkerr);\r
+    UIP_LOG("tcp: bad checksum.");\r
+    goto drop;\r
+  }\r
+  \r
+  /* Demultiplex this segment. */\r
+  /* First check any active connections. */\r
+  for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];\r
+      ++uip_connr) {\r
+    if(uip_connr->tcpstateflags != UIP_CLOSED &&\r
+       BUF->destport == uip_connr->lport &&\r
+       BUF->srcport == uip_connr->rport &&\r
+       uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->ripaddr)) {\r
+      goto found;\r
+    }\r
+  }\r
+\r
+  /* If we didn't find and active connection that expected the packet,\r
+     either this packet is an old duplicate, or this is a SYN packet\r
+     destined for a connection in LISTEN. If the SYN flag isn't set,\r
+     it is an old packet and we send a RST. */\r
+  if((BUF->flags & TCP_CTL) != TCP_SYN) {\r
+    goto reset;\r
+  }\r
+  \r
+  tmp16 = BUF->destport;\r
+  /* Next, check listening connections. */\r
+  for(c = 0; c < UIP_LISTENPORTS; ++c) {\r
+    if(tmp16 == uip_listenports[c]) {\r
+      goto found_listen;\r
+    }\r
+  }\r
+  \r
+  /* No matching connection found, so we send a RST packet. */\r
+  UIP_STAT(++uip_stat.tcp.synrst);\r
+\r
+ reset:\r
+  /* We do not send resets in response to resets. */\r
+  if(BUF->flags & TCP_RST) {\r
+    goto drop;\r
+  }\r
+\r
+  UIP_STAT(++uip_stat.tcp.rst);\r
+  \r
+  BUF->flags = TCP_RST | TCP_ACK;\r
+  uip_len = UIP_IPTCPH_LEN;\r
+  BUF->tcpoffset = 5 << 4;\r
+\r
+  /* Flip the seqno and ackno fields in the TCP header. */\r
+  c = BUF->seqno[3];\r
+  BUF->seqno[3] = BUF->ackno[3];\r
+  BUF->ackno[3] = c;\r
+  \r
+  c = BUF->seqno[2];\r
+  BUF->seqno[2] = BUF->ackno[2];\r
+  BUF->ackno[2] = c;\r
+  \r
+  c = BUF->seqno[1];\r
+  BUF->seqno[1] = BUF->ackno[1];\r
+  BUF->ackno[1] = c;\r
+  \r
+  c = BUF->seqno[0];\r
+  BUF->seqno[0] = BUF->ackno[0];\r
+  BUF->ackno[0] = c;\r
+\r
+  /* We also have to increase the sequence number we are\r
+     acknowledging. If the least significant byte overflowed, we need\r
+     to propagate the carry to the other bytes as well. */\r
+  if(++BUF->ackno[3] == 0) {\r
+    if(++BUF->ackno[2] == 0) {\r
+      if(++BUF->ackno[1] == 0) {\r
+       ++BUF->ackno[0];\r
+      }\r
+    }\r
+  }\r
\r
+  /* Swap port numbers. */\r
+  tmp16 = BUF->srcport;\r
+  BUF->srcport = BUF->destport;\r
+  BUF->destport = tmp16;\r
+  \r
+  /* Swap IP addresses. */\r
+  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);\r
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);\r
+  \r
+  /* And send out the RST packet! */\r
+  goto tcp_send_noconn;\r
+\r
+  /* This label will be jumped to if we matched the incoming packet\r
+     with a connection in LISTEN. In that case, we should create a new\r
+     connection and send a SYNACK in return. */\r
+ found_listen:\r
+  /* First we check if there are any connections avaliable. Unused\r
+     connections are kept in the same table as used connections, but\r
+     unused ones have the tcpstate set to CLOSED. Also, connections in\r
+     TIME_WAIT are kept track of and we'll use the oldest one if no\r
+     CLOSED connections are found. Thanks to Eddie C. Dost for a very\r
+     nice algorithm for the TIME_WAIT search. */\r
+  uip_connr = 0;\r
+  for(c = 0; c < UIP_CONNS; ++c) {\r
+    if(uip_conns[c].tcpstateflags == UIP_CLOSED) {\r
+      uip_connr = &uip_conns[c];\r
+      break;\r
+    }\r
+    if(uip_conns[c].tcpstateflags == UIP_TIME_WAIT) {\r
+      if(uip_connr == 0 ||\r
+        uip_conns[c].timer > uip_connr->timer) {\r
+       uip_connr = &uip_conns[c];\r
+      }\r
+    }\r
+  }\r
+\r
+  if(uip_connr == 0) {\r
+    /* All connections are used already, we drop packet and hope that\r
+       the remote end will retransmit the packet at a time when we\r
+       have more spare connections. */\r
+    UIP_STAT(++uip_stat.tcp.syndrop);\r
+    UIP_LOG("tcp: found no unused connections.");\r
+    goto drop;\r
+  }\r
+  uip_conn = uip_connr;\r
+  \r
+  /* Fill in the necessary fields for the new connection. */\r
+  uip_connr->rto = uip_connr->timer = UIP_RTO;\r
+  uip_connr->sa = 0;\r
+  uip_connr->sv = 4;\r
+  uip_connr->nrtx = 0;\r
+  uip_connr->lport = BUF->destport;\r
+  uip_connr->rport = BUF->srcport;\r
+  uip_ipaddr_copy(&uip_connr->ripaddr, &BUF->srcipaddr);\r
+  uip_connr->tcpstateflags = UIP_SYN_RCVD;\r
+\r
+  uip_connr->snd_nxt[0] = iss[0];\r
+  uip_connr->snd_nxt[1] = iss[1];\r
+  uip_connr->snd_nxt[2] = iss[2];\r
+  uip_connr->snd_nxt[3] = iss[3];\r
+  uip_connr->len = 1;\r
+\r
+  /* rcv_nxt should be the seqno from the incoming packet + 1. */\r
+  uip_connr->rcv_nxt[3] = BUF->seqno[3];\r
+  uip_connr->rcv_nxt[2] = BUF->seqno[2];\r
+  uip_connr->rcv_nxt[1] = BUF->seqno[1];\r
+  uip_connr->rcv_nxt[0] = BUF->seqno[0];\r
+  uip_add_rcv_nxt(1);\r
+\r
+  /* Parse the TCP MSS option, if present. */\r
+  if((BUF->tcpoffset & 0xf0) > 0x50) {\r
+    for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {\r
+      opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];\r
+      if(opt == TCP_OPT_END) {\r
+       /* End of options. */\r
+       break;\r
+      } else if(opt == TCP_OPT_NOOP) {\r
+       ++c;\r
+       /* NOP option. */\r
+      } else if(opt == TCP_OPT_MSS &&\r
+               uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {\r
+       /* An MSS option with the right option length. */\r
+       tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |\r
+         (u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];\r
+       uip_connr->initialmss = uip_connr->mss =\r
+         tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;\r
+       \r
+       /* And we are done processing options. */\r
+       break;\r
+      } else {\r
+       /* All other options have a length field, so that we easily\r
+          can skip past them. */\r
+       if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {\r
+         /* If the length field is zero, the options are malformed\r
+            and we don't process them further. */\r
+         break;\r
+       }\r
+       c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];\r
+      }\r
+    }\r
+  }\r
+  \r
+  /* Our response will be a SYNACK. */\r
+#if UIP_ACTIVE_OPEN\r
+ tcp_send_synack:\r
+  BUF->flags = TCP_ACK;\r
+  \r
+ tcp_send_syn:\r
+  BUF->flags |= TCP_SYN;\r
+#else /* UIP_ACTIVE_OPEN */\r
+ tcp_send_synack:\r
+  BUF->flags = TCP_SYN | TCP_ACK;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+  \r
+  /* We send out the TCP Maximum Segment Size option with our\r
+     SYNACK. */\r
+  BUF->optdata[0] = TCP_OPT_MSS;\r
+  BUF->optdata[1] = TCP_OPT_MSS_LEN;\r
+  BUF->optdata[2] = (UIP_TCP_MSS) / 256;\r
+  BUF->optdata[3] = (UIP_TCP_MSS) & 255;\r
+  uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;\r
+  BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;\r
+  goto tcp_send;\r
+\r
+  /* This label will be jumped to if we found an active connection. */\r
+ found:\r
+  uip_conn = uip_connr;\r
+  uip_flags = 0;\r
+  /* We do a very naive form of TCP reset processing; we just accept\r
+     any RST and kill our connection. We should in fact check if the\r
+     sequence number of this reset is wihtin our advertised window\r
+     before we accept the reset. */\r
+  if(BUF->flags & TCP_RST) {\r
+    uip_connr->tcpstateflags = UIP_CLOSED;\r
+    UIP_LOG("tcp: got reset, aborting connection.");\r
+    uip_flags = UIP_ABORT;\r
+    UIP_APPCALL();\r
+    goto drop;\r
+  }\r
+  /* Calculate the length of the data, if the application has sent\r
+     any data to us. */\r
+  c = (BUF->tcpoffset >> 4) << 2;\r
+  /* uip_len will contain the length of the actual TCP data. This is\r
+     calculated by subtracing the length of the TCP header (in\r
+     c) and the length of the IP header (20 bytes). */\r
+  uip_len = uip_len - c - UIP_IPH_LEN;\r
+\r
+  /* First, check if the sequence number of the incoming packet is\r
+     what we're expecting next. If not, we send out an ACK with the\r
+     correct numbers in. */\r
+  if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&\r
+       ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {\r
+    if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&\r
+       (BUF->seqno[0] != uip_connr->rcv_nxt[0] ||\r
+       BUF->seqno[1] != uip_connr->rcv_nxt[1] ||\r
+       BUF->seqno[2] != uip_connr->rcv_nxt[2] ||\r
+       BUF->seqno[3] != uip_connr->rcv_nxt[3])) {\r
+      goto tcp_send_ack;\r
+    }\r
+  }\r
+\r
+  /* Next, check if the incoming segment acknowledges any outstanding\r
+     data. If so, we update the sequence number, reset the length of\r
+     the outstanding data, calculate RTT estimations, and reset the\r
+     retransmission timer. */\r
+  if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {\r
+    uip_add32(uip_connr->snd_nxt, uip_connr->len);\r
+\r
+    if(BUF->ackno[0] == uip_acc32[0] &&\r
+       BUF->ackno[1] == uip_acc32[1] &&\r
+       BUF->ackno[2] == uip_acc32[2] &&\r
+       BUF->ackno[3] == uip_acc32[3]) {\r
+      /* Update sequence number. */\r
+      uip_connr->snd_nxt[0] = uip_acc32[0];\r
+      uip_connr->snd_nxt[1] = uip_acc32[1];\r
+      uip_connr->snd_nxt[2] = uip_acc32[2];\r
+      uip_connr->snd_nxt[3] = uip_acc32[3];\r
+       \r
+      /* Do RTT estimation, unless we have done retransmissions. */\r
+      if(uip_connr->nrtx == 0) {\r
+       signed char m;\r
+       m = uip_connr->rto - uip_connr->timer;\r
+       /* This is taken directly from VJs original code in his paper */\r
+       m = m - (uip_connr->sa >> 3);\r
+       uip_connr->sa += m;\r
+       if(m < 0) {\r
+         m = -m;\r
+       }\r
+       m = m - (uip_connr->sv >> 2);\r
+       uip_connr->sv += m;\r
+       uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;\r
+\r
+      }\r
+      /* Set the acknowledged flag. */\r
+      uip_flags = UIP_ACKDATA;\r
+      /* Reset the retransmission timer. */\r
+      uip_connr->timer = uip_connr->rto;\r
+\r
+      /* Reset length of outstanding data. */\r
+      uip_connr->len = 0;\r
+    }\r
+    \r
+  }\r
+\r
+  /* Do different things depending on in what state the connection is. */\r
+  switch(uip_connr->tcpstateflags & UIP_TS_MASK) {\r
+    /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not\r
+       implemented, since we force the application to close when the\r
+       peer sends a FIN (hence the application goes directly from\r
+       ESTABLISHED to LAST_ACK). */\r
+  case UIP_SYN_RCVD:\r
+    /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and\r
+       we are waiting for an ACK that acknowledges the data we sent\r
+       out the last time. Therefore, we want to have the UIP_ACKDATA\r
+       flag set. If so, we enter the ESTABLISHED state. */\r
+    if(uip_flags & UIP_ACKDATA) {\r
+      uip_connr->tcpstateflags = UIP_ESTABLISHED;\r
+      uip_flags = UIP_CONNECTED;\r
+      uip_connr->len = 0;\r
+      if(uip_len > 0) {\r
+        uip_flags |= UIP_NEWDATA;\r
+        uip_add_rcv_nxt(uip_len);\r
+      }\r
+      uip_slen = 0;\r
+      UIP_APPCALL();\r
+      goto appsend;\r
+    }\r
+    goto drop;\r
+#if UIP_ACTIVE_OPEN\r
+  case UIP_SYN_SENT:\r
+    /* In SYN_SENT, we wait for a SYNACK that is sent in response to\r
+       our SYN. The rcv_nxt is set to sequence number in the SYNACK\r
+       plus one, and we send an ACK. We move into the ESTABLISHED\r
+       state. */\r
+    if((uip_flags & UIP_ACKDATA) &&\r
+       (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {\r
+\r
+      /* Parse the TCP MSS option, if present. */\r
+      if((BUF->tcpoffset & 0xf0) > 0x50) {\r
+       for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {\r
+         opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];\r
+         if(opt == TCP_OPT_END) {\r
+           /* End of options. */\r
+           break;\r
+         } else if(opt == TCP_OPT_NOOP) {\r
+           ++c;\r
+           /* NOP option. */\r
+         } else if(opt == TCP_OPT_MSS &&\r
+                   uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {\r
+           /* An MSS option with the right option length. */\r
+           tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |\r
+             uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];\r
+           uip_connr->initialmss =\r
+             uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;\r
+\r
+           /* And we are done processing options. */\r
+           break;\r
+         } else {\r
+           /* All other options have a length field, so that we easily\r
+              can skip past them. */\r
+           if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {\r
+             /* If the length field is zero, the options are malformed\r
+                and we don't process them further. */\r
+             break;\r
+           }\r
+           c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];\r
+         }\r
+       }\r
+      }\r
+      uip_connr->tcpstateflags = UIP_ESTABLISHED;\r
+      uip_connr->rcv_nxt[0] = BUF->seqno[0];\r
+      uip_connr->rcv_nxt[1] = BUF->seqno[1];\r
+      uip_connr->rcv_nxt[2] = BUF->seqno[2];\r
+      uip_connr->rcv_nxt[3] = BUF->seqno[3];\r
+      uip_add_rcv_nxt(1);\r
+      uip_flags = UIP_CONNECTED | UIP_NEWDATA;\r
+      uip_connr->len = 0;\r
+      uip_len = 0;\r
+      uip_slen = 0;\r
+      UIP_APPCALL();\r
+      goto appsend;\r
+    }\r
+    /* Inform the application that the connection failed */\r
+    uip_flags = UIP_ABORT;\r
+    UIP_APPCALL();\r
+    /* The connection is closed after we send the RST */\r
+    uip_conn->tcpstateflags = UIP_CLOSED;\r
+    goto reset;\r
+#endif /* UIP_ACTIVE_OPEN */\r
+    \r
+  case UIP_ESTABLISHED:\r
+    /* In the ESTABLISHED state, we call upon the application to feed\r
+    data into the uip_buf. If the UIP_ACKDATA flag is set, the\r
+    application should put new data into the buffer, otherwise we are\r
+    retransmitting an old segment, and the application should put that\r
+    data into the buffer.\r
+\r
+    If the incoming packet is a FIN, we should close the connection on\r
+    this side as well, and we send out a FIN and enter the LAST_ACK\r
+    state. We require that there is no outstanding data; otherwise the\r
+    sequence numbers will be screwed up. */\r
+\r
+    if(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {\r
+      if(uip_outstanding(uip_connr)) {\r
+       goto drop;\r
+      }\r
+      uip_add_rcv_nxt(1 + uip_len);\r
+      uip_flags |= UIP_CLOSE;\r
+      if(uip_len > 0) {\r
+       uip_flags |= UIP_NEWDATA;\r
+      }\r
+      UIP_APPCALL();\r
+      uip_connr->len = 1;\r
+      uip_connr->tcpstateflags = UIP_LAST_ACK;\r
+      uip_connr->nrtx = 0;\r
+    tcp_send_finack:\r
+      BUF->flags = TCP_FIN | TCP_ACK;\r
+      goto tcp_send_nodata;\r
+    }\r
+\r
+    /* Check the URG flag. If this is set, the segment carries urgent\r
+       data that we must pass to the application. */\r
+    if((BUF->flags & TCP_URG) != 0) {\r
+#if UIP_URGDATA > 0\r
+      uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];\r
+      if(uip_urglen > uip_len) {\r
+       /* There is more urgent data in the next segment to come. */\r
+       uip_urglen = uip_len;\r
+      }\r
+      uip_add_rcv_nxt(uip_urglen);\r
+      uip_len -= uip_urglen;\r
+      uip_urgdata = uip_appdata;\r
+      uip_appdata += uip_urglen;\r
+    } else {\r
+      uip_urglen = 0;\r
+#else /* UIP_URGDATA > 0 */\r
+      uip_appdata = ((char *)uip_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]);\r
+      uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];\r
+#endif /* UIP_URGDATA > 0 */\r
+    }\r
+\r
+    /* If uip_len > 0 we have TCP data in the packet, and we flag this\r
+       by setting the UIP_NEWDATA flag and update the sequence number\r
+       we acknowledge. If the application has stopped the dataflow\r
+       using uip_stop(), we must not accept any data packets from the\r
+       remote host. */\r
+    if(uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) {\r
+      uip_flags |= UIP_NEWDATA;\r
+      uip_add_rcv_nxt(uip_len);\r
+    }\r
+\r
+    /* Check if the available buffer space advertised by the other end\r
+       is smaller than the initial MSS for this connection. If so, we\r
+       set the current MSS to the window size to ensure that the\r
+       application does not send more data than the other end can\r
+       handle.\r
+\r
+       If the remote host advertises a zero window, we set the MSS to\r
+       the initial MSS so that the application will send an entire MSS\r
+       of data. This data will not be acknowledged by the receiver,\r
+       and the application will retransmit it. This is called the\r
+       "persistent timer" and uses the retransmission mechanim.\r
+    */\r
+    tmp16 = ((u16_t)BUF->wnd[0] << 8) + (u16_t)BUF->wnd[1];\r
+    if(tmp16 > uip_connr->initialmss ||\r
+       tmp16 == 0) {\r
+      tmp16 = uip_connr->initialmss;\r
+    }\r
+    uip_connr->mss = tmp16;\r
+\r
+    /* If this packet constitutes an ACK for outstanding data (flagged\r
+       by the UIP_ACKDATA flag, we should call the application since it\r
+       might want to send more data. If the incoming packet had data\r
+       from the peer (as flagged by the UIP_NEWDATA flag), the\r
+       application must also be notified.\r
+\r
+       When the application is called, the global variable uip_len\r
+       contains the length of the incoming data. The application can\r
+       access the incoming data through the global pointer\r
+       uip_appdata, which usually points UIP_IPTCPH_LEN + UIP_LLH_LEN\r
+       bytes into the uip_buf array.\r
+\r
+       If the application wishes to send any data, this data should be\r
+       put into the uip_appdata and the length of the data should be\r
+       put into uip_len. If the application don't have any data to\r
+       send, uip_len must be set to 0. */\r
+    if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {\r
+      uip_slen = 0;\r
+      UIP_APPCALL();\r
+\r
+    appsend:\r
+      \r
+      if(uip_flags & UIP_ABORT) {\r
+       uip_slen = 0;\r
+       uip_connr->tcpstateflags = UIP_CLOSED;\r
+       BUF->flags = TCP_RST | TCP_ACK;\r
+       goto tcp_send_nodata;\r
+      }\r
+\r
+      if(uip_flags & UIP_CLOSE) {\r
+       uip_slen = 0;\r
+       uip_connr->len = 1;\r
+       uip_connr->tcpstateflags = UIP_FIN_WAIT_1;\r
+       uip_connr->nrtx = 0;\r
+       BUF->flags = TCP_FIN | TCP_ACK;\r
+       goto tcp_send_nodata;\r
+      }\r
+\r
+      /* If uip_slen > 0, the application has data to be sent. */\r
+      if(uip_slen > 0) {\r
+\r
+       /* If the connection has acknowledged data, the contents of\r
+          the ->len variable should be discarded. */\r
+       if((uip_flags & UIP_ACKDATA) != 0) {\r
+         uip_connr->len = 0;\r
+       }\r
+\r
+       /* If the ->len variable is non-zero the connection has\r
+          already data in transit and cannot send anymore right\r
+          now. */\r
+       if(uip_connr->len == 0) {\r
+\r
+         /* The application cannot send more than what is allowed by\r
+            the mss (the minumum of the MSS and the available\r
+            window). */\r
+         if(uip_slen > uip_connr->mss) {\r
+           uip_slen = uip_connr->mss;\r
+         }\r
+\r
+         /* Remember how much data we send out now so that we know\r
+            when everything has been acknowledged. */\r
+         uip_connr->len = uip_slen;\r
+       } else {\r
+\r
+         /* If the application already had unacknowledged data, we\r
+            make sure that the application does not send (i.e.,\r
+            retransmit) out more than it previously sent out. */\r
+         uip_slen = uip_connr->len;\r
+       }\r
+      }\r
+      uip_connr->nrtx = 0;\r
+    apprexmit:\r
+      uip_appdata = uip_sappdata;\r
+      \r
+      /* If the application has data to be sent, or if the incoming\r
+         packet had new data in it, we must send out a packet. */\r
+      if(uip_slen > 0 && uip_connr->len > 0) {\r
+       /* Add the length of the IP and TCP headers. */\r
+       uip_len = uip_connr->len + UIP_TCPIP_HLEN;\r
+       /* We always set the ACK flag in response packets. */\r
+       BUF->flags = TCP_ACK | TCP_PSH;\r
+       /* Send the packet. */\r
+       goto tcp_send_noopts;\r
+      }\r
+      /* If there is no data to send, just send out a pure ACK if\r
+        there is newdata. */\r
+      if(uip_flags & UIP_NEWDATA) {\r
+       uip_len = UIP_TCPIP_HLEN;\r
+       BUF->flags = TCP_ACK;\r
+       goto tcp_send_noopts;\r
+      }\r
+    }\r
+    goto drop;\r
+  case UIP_LAST_ACK:\r
+    /* We can close this connection if the peer has acknowledged our\r
+       FIN. This is indicated by the UIP_ACKDATA flag. */\r
+    if(uip_flags & UIP_ACKDATA) {\r
+      uip_connr->tcpstateflags = UIP_CLOSED;\r
+      uip_flags = UIP_CLOSE;\r
+      UIP_APPCALL();\r
+    }\r
+    break;\r
+    \r
+  case UIP_FIN_WAIT_1:\r
+    /* The application has closed the connection, but the remote host\r
+       hasn't closed its end yet. Thus we do nothing but wait for a\r
+       FIN from the other side. */\r
+    if(uip_len > 0) {\r
+      uip_add_rcv_nxt(uip_len);\r
+    }\r
+    if(BUF->flags & TCP_FIN) {\r
+      if(uip_flags & UIP_ACKDATA) {\r
+       uip_connr->tcpstateflags = UIP_TIME_WAIT;\r
+       uip_connr->timer = 0;\r
+       uip_connr->len = 0;\r
+      } else {\r
+       uip_connr->tcpstateflags = UIP_CLOSING;\r
+      }\r
+      uip_add_rcv_nxt(1);\r
+      uip_flags = UIP_CLOSE;\r
+      UIP_APPCALL();\r
+      goto tcp_send_ack;\r
+    } else if(uip_flags & UIP_ACKDATA) {\r
+      uip_connr->tcpstateflags = UIP_FIN_WAIT_2;\r
+      uip_connr->len = 0;\r
+      goto drop;\r
+    }\r
+    if(uip_len > 0) {\r
+      goto tcp_send_ack;\r
+    }\r
+    goto drop;\r
+      \r
+  case UIP_FIN_WAIT_2:\r
+    if(uip_len > 0) {\r
+      uip_add_rcv_nxt(uip_len);\r
+    }\r
+    if(BUF->flags & TCP_FIN) {\r
+      uip_connr->tcpstateflags = UIP_TIME_WAIT;\r
+      uip_connr->timer = 0;\r
+      uip_add_rcv_nxt(1);\r
+      uip_flags = UIP_CLOSE;\r
+      UIP_APPCALL();\r
+      goto tcp_send_ack;\r
+    }\r
+    if(uip_len > 0) {\r
+      goto tcp_send_ack;\r
+    }\r
+    goto drop;\r
+\r
+  case UIP_TIME_WAIT:\r
+    goto tcp_send_ack;\r
+    \r
+  case UIP_CLOSING:\r
+    if(uip_flags & UIP_ACKDATA) {\r
+      uip_connr->tcpstateflags = UIP_TIME_WAIT;\r
+      uip_connr->timer = 0;\r
+    }\r
+  }\r
+  goto drop;\r
+  \r
+  /* We jump here when we are ready to send the packet, and just want\r
+     to set the appropriate TCP sequence numbers in the TCP header. */\r
+ tcp_send_ack:\r
+  BUF->flags = TCP_ACK;\r
+\r
+ tcp_send_nodata:\r
+  uip_len = UIP_IPTCPH_LEN;\r
+\r
+ tcp_send_noopts:\r
+  BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;\r
+\r
+  /* We're done with the input processing. We are now ready to send a\r
+     reply. Our job is to fill in all the fields of the TCP and IP\r
+     headers before calculating the checksum and finally send the\r
+     packet. */\r
+ tcp_send:\r
+  BUF->ackno[0] = uip_connr->rcv_nxt[0];\r
+  BUF->ackno[1] = uip_connr->rcv_nxt[1];\r
+  BUF->ackno[2] = uip_connr->rcv_nxt[2];\r
+  BUF->ackno[3] = uip_connr->rcv_nxt[3];\r
+  \r
+  BUF->seqno[0] = uip_connr->snd_nxt[0];\r
+  BUF->seqno[1] = uip_connr->snd_nxt[1];\r
+  BUF->seqno[2] = uip_connr->snd_nxt[2];\r
+  BUF->seqno[3] = uip_connr->snd_nxt[3];\r
+\r
+  BUF->proto = UIP_PROTO_TCP;\r
+  \r
+  BUF->srcport  = uip_connr->lport;\r
+  BUF->destport = uip_connr->rport;\r
+\r
+  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);\r
+  uip_ipaddr_copy(&BUF->destipaddr, &uip_connr->ripaddr);\r
+\r
+  if(uip_connr->tcpstateflags & UIP_STOPPED) {\r
+    /* If the connection has issued uip_stop(), we advertise a zero\r
+       window so that the remote host will stop sending data. */\r
+    BUF->wnd[0] = BUF->wnd[1] = 0;\r
+  } else {\r
+    BUF->wnd[0] = ((UIP_RECEIVE_WINDOW) >> 8);\r
+    BUF->wnd[1] = ((UIP_RECEIVE_WINDOW) & 0xff);\r
+  }\r
+\r
+ tcp_send_noconn:\r
+  BUF->ttl = UIP_TTL;\r
+#if UIP_CONF_IPV6\r
+  /* For IPv6, the IP length field does not include the IPv6 IP header\r
+     length. */\r
+  BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);\r
+  BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);\r
+#else /* UIP_CONF_IPV6 */\r
+  BUF->len[0] = (uip_len >> 8);\r
+  BUF->len[1] = (uip_len & 0xff);\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+  BUF->urgp[0] = BUF->urgp[1] = 0;\r
+  \r
+  /* Calculate TCP checksum. */\r
+  BUF->tcpchksum = 0;\r
+  BUF->tcpchksum = ~(uip_tcpchksum());\r
+\r
+ ip_send_nolen:\r
+#if UIP_CONF_IPV6\r
+  BUF->vtc = 0x60;\r
+  BUF->tcflow = 0x00;\r
+  BUF->flow = 0x00;\r
+#else /* UIP_CONF_IPV6 */\r
+  BUF->vhl = 0x45;\r
+  BUF->tos = 0;\r
+  BUF->ipoffset[0] = BUF->ipoffset[1] = 0;\r
+  ++ipid;\r
+  BUF->ipid[0] = ipid >> 8;\r
+  BUF->ipid[1] = ipid & 0xff;\r
+  /* Calculate IP checksum. */\r
+  BUF->ipchksum = 0;\r
+  BUF->ipchksum = ~(uip_ipchksum());\r
+  DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum());\r
+#endif /* UIP_CONF_IPV6 */   \r
+  UIP_STAT(++uip_stat.tcp.sent);\r
+#if UIP_CONF_IPV6\r
+ send:\r
+#endif /* UIP_CONF_IPV6 */\r
+  DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,\r
+              (BUF->len[0] << 8) | BUF->len[1]);\r
+  \r
+  UIP_STAT(++uip_stat.ip.sent);\r
+  /* Return and let the caller do the actual transmission. */\r
+  uip_flags = 0;\r
+  return;\r
+\r
+ drop:\r
+  uip_len = 0;\r
+  uip_flags = 0;\r
+  return;\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+u16_t\r
+htons(u16_t val)\r
+{\r
+  return HTONS(val);\r
+}\r
+\r
+u32_t\r
+htonl(u32_t val)\r
+{\r
+  return HTONL(val);\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+void\r
+uip_send(const void *data, int len)\r
+{\r
+  int copylen;\r
+#define MIN(a,b) ((a) < (b)? (a): (b))\r
+  copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN -\r
+               (int)((char *)uip_sappdata - (char *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]));\r
+  if(copylen > 0) {\r
+    uip_slen = copylen;\r
+    if(data != uip_sappdata) {\r
+      memcpy(uip_sappdata, (data), uip_slen);\r
+    }\r
+  }\r
+}\r
+/*---------------------------------------------------------------------------*/\r
+/** @} */\r
+#endif /* UIP_CONF_IPV6 */\r
index a10699d..3e8504c 100644 (file)
-
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \file
- * Header file for the uIP TCP/IP stack.
- * \author  Adam Dunkels <adam@dunkels.com>
- * \author  Julien Abeille <jabeille@cisco.com> (IPv6 related code)
- * \author  Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
- *
- * The uIP TCP/IP stack header file contains definitions for a number
- * of C macros that are used by uIP programs as well as internal uIP
- * structures, TCP/IP header structures and function declarations.
- *
- */
-
-/*
- * Copyright (c) 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- *    products derived from this software without specific prior
- *    written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack.
- *
- * $Id: uip.h,v 1.24 2009/04/06 13:18:50 nvt-se Exp $
- *
- */
-
-#ifndef __UIP_H__
-#define __UIP_H__
-
-#include "uipopt.h"
-
-/**
- * Representation of an IP address.
- *
- */
-#if UIP_CONF_IPV6
-typedef union uip_ip6addr_t {
-  u8_t  u8[16];                        /* Initializer, must come first!!! */
-  u16_t u16[8];
-} uip_ip6addr_t;
-
-typedef uip_ip6addr_t uip_ipaddr_t;
-#else /* UIP_CONF_IPV6 */
-typedef union uip_ip4addr_t {
-  u8_t  u8[4];                 /* Initializer, must come first!!! */
-  u16_t u16[2];
-#if 0
-  u32_t u32;
-#endif
-} uip_ip4addr_t;
-typedef uip_ip4addr_t uip_ipaddr_t;
-#endif /* UIP_CONF_IPV6 */
-
-
-/*---------------------------------------------------------------------------*/
-
-/** \brief 16 bit 802.15.4 address */
-struct uip_802154_shortaddr {
-  u8_t addr[2];
-};
-/** \brief 64 bit 802.15.4 address */
-struct uip_802154_longaddr {
-  u8_t addr[8];
-};
-
-/** \brief 802.11 address */
-struct uip_80211_addr {
-  u8_t addr[6];
-};
-
-/** \brief 802.3 address */
-struct uip_eth_addr {
-  u8_t addr[6];
-};
-
-#if UIP_CONF_LL_802154
-/** \brief 802.15.4 address */
-typedef struct uip_802154_longaddr uip_lladdr_t;
-#define UIP_802154_SHORTADDR_LEN 2
-#define UIP_802154_LONGADDR_LEN  8
-#define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
-#else /*UIP_CONF_LL_802154*/
-#if UIP_CONF_LL_80211
-/** \brief 802.11 address */
-typedef struct uip_80211_addr uip_lladdr_t;
-#define UIP_LLADDR_LEN 6
-#else /*UIP_CONF_LL_80211*/
-/** \brief Ethernet address */
-typedef struct uip_eth_addr uip_lladdr_t;
-#define UIP_LLADDR_LEN 6
-#endif /*UIP_CONF_LL_80211*/
-#endif /*UIP_CONF_LL_802154*/
-
-/*---------------------------------------------------------------------------*/
-/* First, the functions that should be called from the
- * system. Initialization, the periodic timer, and incoming packets are
- * handled by the following three functions.
- */
-/**
- * \defgroup uipconffunc uIP configuration functions
- * @{
- *
- * The uIP configuration functions are used for setting run-time
- * parameters in uIP such as IP addresses.
- */
-
-/**
- * Set the IP address of this host.
- *
- * The IP address is represented as a 4-byte array where the first
- * octet of the IP address is put in the first member of the 4-byte
- * array.
- *
- * Example:
- \code
-
- uip_ipaddr_t addr;
-
- uip_ipaddr(&addr, 192,168,1,2);
- uip_sethostaddr(&addr);
- \endcode
- * \param addr A pointer to an IP address of type uip_ipaddr_t;
- *
- * \sa uip_ipaddr()
- *
- * \hideinitializer
- */
-#define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
-
-/**
- * Get the IP address of this host.
- *
- * The IP address is represented as a 4-byte array where the first
- * octet of the IP address is put in the first member of the 4-byte
- * array.
- *
- * Example:
- \code
- uip_ipaddr_t hostaddr;
-
- uip_gethostaddr(&hostaddr);
- \endcode
- * \param addr A pointer to a uip_ipaddr_t variable that will be
- * filled in with the currently configured IP address.
- *
- * \hideinitializer
- */
-#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
-
-/**
- * Set the default router's IP address.
- *
- * \param addr A pointer to a uip_ipaddr_t variable containing the IP
- * address of the default router.
- *
- * \sa uip_ipaddr()
- *
- * \hideinitializer
- */
-#define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
-
-/**
- * Set the netmask.
- *
- * \param addr A pointer to a uip_ipaddr_t variable containing the IP
- * address of the netmask.
- *
- * \sa uip_ipaddr()
- *
- * \hideinitializer
- */
-#define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
-
-
-/**
- * Get the default router's IP address.
- *
- * \param addr A pointer to a uip_ipaddr_t variable that will be
- * filled in with the IP address of the default router.
- *
- * \hideinitializer
- */
-#define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
-
-/**
- * Get the netmask.
- *
- * \param addr A pointer to a uip_ipaddr_t variable that will be
- * filled in with the value of the netmask.
- *
- * \hideinitializer
- */
-#define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
-
-/** @} */
-
-/**
- * \defgroup uipinit uIP initialization functions
- * @{
- *
- * The uIP initialization functions are used for booting uIP.
- */
-
-/**
- * uIP initialization function.
- *
- * This function should be called at boot up to initilize the uIP
- * TCP/IP stack.
- */
-void uip_init(void);
-
-/**
- * uIP initialization function.
- *
- * This function may be used at boot time to set the initial ip_id.
- */
-void uip_setipid(u16_t id);
-
-/** @} */
-
-/**
- * \defgroup uipdevfunc uIP device driver functions
- * @{
- *
- * These functions are used by a network device driver for interacting
- * with uIP.
- */
-
-/**
- * Process an incoming packet.
- *
- * This function should be called when the device driver has received
- * a packet from the network. The packet from the device driver must
- * be present in the uip_buf buffer, and the length of the packet
- * should be placed in the uip_len variable.
- *
- * When the function returns, there may be an outbound packet placed
- * in the uip_buf packet buffer. If so, the uip_len variable is set to
- * the length of the packet. If no packet is to be sent out, the
- * uip_len variable is set to 0.
- *
- * The usual way of calling the function is presented by the source
- * code below.
- \code
- uip_len = devicedriver_poll();
- if(uip_len > 0) {
- uip_input();
- if(uip_len > 0) {
- devicedriver_send();
- }
- }
- \endcode
- *
- * \note If you are writing a uIP device driver that needs ARP
- * (Address Resolution Protocol), e.g., when running uIP over
- * Ethernet, you will need to call the uIP ARP code before calling
- * this function:
- \code
- #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
- uip_len = ethernet_devicedrver_poll();
- if(uip_len > 0) {
- if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
- uip_arp_ipin();
- uip_input();
- if(uip_len > 0) {
- uip_arp_out();
- ethernet_devicedriver_send();
- }
- } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
- uip_arp_arpin();
- if(uip_len > 0) {
- ethernet_devicedriver_send();
- }
- }
- \endcode
- *
- * \hideinitializer
- */
-#define uip_input()        uip_process(UIP_DATA)
-
-
-/**
- * Periodic processing for a connection identified by its number.
- *
- * This function does the necessary periodic processing (timers,
- * polling) for a uIP TCP conneciton, and should be called when the
- * periodic uIP timer goes off. It should be called for every
- * connection, regardless of whether they are open of closed.
- *
- * When the function returns, it may have an outbound packet waiting
- * for service in the uIP packet buffer, and if so the uip_len
- * variable is set to a value larger than zero. The device driver
- * should be called to send out the packet.
- *
- * The usual way of calling the function is through a for() loop like
- * this:
- \code
- for(i = 0; i < UIP_CONNS; ++i) {
- uip_periodic(i);
- if(uip_len > 0) {
- devicedriver_send();
- }
- }
- \endcode
- *
- * \note If you are writing a uIP device driver that needs ARP
- * (Address Resolution Protocol), e.g., when running uIP over
- * Ethernet, you will need to call the uip_arp_out() function before
- * calling the device driver:
- \code
- for(i = 0; i < UIP_CONNS; ++i) {
- uip_periodic(i);
- if(uip_len > 0) {
- uip_arp_out();
- ethernet_devicedriver_send();
- }
- }
- \endcode
- *
- * \param conn The number of the connection which is to be periodically polled.
- *
- * \hideinitializer
- */
-#if UIP_TCP
-#define uip_periodic(conn) do { uip_conn = &uip_conns[conn];    \
-    uip_process(UIP_TIMER); } while (0)
-
-/**
- *
- *
- */
-#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
-
-/**
- * Perform periodic processing for a connection identified by a pointer
- * to its structure.
- *
- * Same as uip_periodic() but takes a pointer to the actual uip_conn
- * struct instead of an integer as its argument. This function can be
- * used to force periodic processing of a specific connection.
- *
- * \param conn A pointer to the uip_conn struct for the connection to
- * be processed.
- *
- * \hideinitializer
- */
-#define uip_periodic_conn(conn) do { uip_conn = conn;   \
-    uip_process(UIP_TIMER); } while (0)
-
-/**
- * Request that a particular connection should be polled.
- *
- * Similar to uip_periodic_conn() but does not perform any timer
- * processing. The application is polled for new data.
- *
- * \param conn A pointer to the uip_conn struct for the connection to
- * be processed.
- *
- * \hideinitializer
- */
-#define uip_poll_conn(conn) do { uip_conn = conn;       \
-    uip_process(UIP_POLL_REQUEST); } while (0)
-
-#endif /* UIP_TCP */
-
-#if UIP_UDP
-/**
- * Periodic processing for a UDP connection identified by its number.
- *
- * This function is essentially the same as uip_periodic(), but for
- * UDP connections. It is called in a similar fashion as the
- * uip_periodic() function:
- \code
- for(i = 0; i < UIP_UDP_CONNS; i++) {
- uip_udp_periodic(i);
- if(uip_len > 0) {
- devicedriver_send();
- }
- }
- \endcode
- *
- * \note As for the uip_periodic() function, special care has to be
- * taken when using uIP together with ARP and Ethernet:
- \code
- for(i = 0; i < UIP_UDP_CONNS; i++) {
- uip_udp_periodic(i);
- if(uip_len > 0) {
- uip_arp_out();
- ethernet_devicedriver_send();
- }
- }
- \endcode
- *
- * \param conn The number of the UDP connection to be processed.
- *
- * \hideinitializer
- */
-#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
-    uip_process(UIP_UDP_TIMER); } while(0)
-
-/**
- * Periodic processing for a UDP connection identified by a pointer to
- * its structure.
- *
- * Same as uip_udp_periodic() but takes a pointer to the actual
- * uip_conn struct instead of an integer as its argument. This
- * function can be used to force periodic processing of a specific
- * connection.
- *
- * \param conn A pointer to the uip_udp_conn struct for the connection
- * to be processed.
- *
- * \hideinitializer
- */
-#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn;   \
-    uip_process(UIP_UDP_TIMER); } while(0)
-#endif /* UIP_UDP */
-
-/** \brief Abandon the reassembly of the current packet */
-void uip_reass_over(void);
-
-/**
- * The uIP packet buffer.
- *
- * The uip_buf array is used to hold incoming and outgoing
- * packets. The device driver should place incoming data into this
- * buffer. When sending data, the device driver should read the link
- * level headers and the TCP/IP headers from this buffer. The size of
- * the link level headers is configured by the UIP_LLH_LEN define.
- *
- * \note The application data need not be placed in this buffer, so
- * the device driver must read it from the place pointed to by the
- * uip_appdata pointer as illustrated by the following example:
- \code
- void
- devicedriver_send(void)
- {
- hwsend(&uip_buf[0], UIP_LLH_LEN);
- if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
- hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
- } else {
- hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
- hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
- }
- }
- \endcode
-*/
-extern u8_t uip_buf[UIP_BUFSIZE+2];
-
-
-
-/** @} */
-
-/*---------------------------------------------------------------------------*/
-/* Functions that are used by the uIP application program. Opening and
- * closing connections, sending and receiving data, etc. is all
- * handled by the functions below.
- */
-/**
- * \defgroup uipappfunc uIP application functions
- * @{
- *
- * Functions used by an application running of top of uIP.
- */
-
-/**
- * Start listening to the specified port.
- *
- * \note Since this function expects the port number in network byte
- * order, a conversion using HTONS() or htons() is necessary.
- *
- \code
- uip_listen(HTONS(80));
- \endcode
- *
- * \param port A 16-bit port number in network byte order.
- */
-void uip_listen(u16_t port);
-
-/**
- * Stop listening to the specified port.
- *
- * \note Since this function expects the port number in network byte
- * order, a conversion using HTONS() or htons() is necessary.
- *
- \code
- uip_unlisten(HTONS(80));
- \endcode
- *
- * \param port A 16-bit port number in network byte order.
- */
-void uip_unlisten(u16_t port);
-
-/**
- * Connect to a remote host using TCP.
- *
- * This function is used to start a new connection to the specified
- * port on the specified host. It allocates a new connection identifier,
- * sets the connection to the SYN_SENT state and sets the
- * retransmission timer to 0. This will cause a TCP SYN segment to be
- * sent out the next time this connection is periodically processed,
- * which usually is done within 0.5 seconds after the call to
- * uip_connect().
- *
- * \note This function is available only if support for active open
- * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
- *
- * \note Since this function requires the port number to be in network
- * byte order, a conversion using HTONS() or htons() is necessary.
- *
- \code
- uip_ipaddr_t ipaddr;
-
- uip_ipaddr(&ipaddr, 192,168,1,2);
- uip_connect(&ipaddr, HTONS(80));
- \endcode
- *
- * \param ripaddr The IP address of the remote host.
- *
- * \param port A 16-bit port number in network byte order.
- *
- * \return A pointer to the uIP connection identifier for the new connection,
- * or NULL if no connection could be allocated.
- *
- */
-struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port);
-
-
-
-/**
- * \internal
- *
- * Check if a connection has outstanding (i.e., unacknowledged) data.
- *
- * \param conn A pointer to the uip_conn structure for the connection.
- *
- * \hideinitializer
- */
-#define uip_outstanding(conn) ((conn)->len)
-
-/**
- * Send data on the current connection.
- *
- * This function is used to send out a single segment of TCP
- * data. Only applications that have been invoked by uIP for event
- * processing can send data.
- *
- * The amount of data that actually is sent out after a call to this
- * function is determined by the maximum amount of data TCP allows. uIP
- * will automatically crop the data so that only the appropriate
- * amount of data is sent. The function uip_mss() can be used to query
- * uIP for the amount of data that actually will be sent.
- *
- * \note This function does not guarantee that the sent data will
- * arrive at the destination. If the data is lost in the network, the
- * application will be invoked with the uip_rexmit() event being
- * set. The application will then have to resend the data using this
- * function.
- *
- * \param data A pointer to the data which is to be sent.
- *
- * \param len The maximum amount of data bytes to be sent.
- *
- * \hideinitializer
- */
-void uip_send(const void *data, int len);
-
-/**
- * The length of any incoming data that is currently available (if available)
- * in the uip_appdata buffer.
- *
- * The test function uip_data() must first be used to check if there
- * is any data available at all.
- *
- * \hideinitializer
- */
-/*void uip_datalen(void);*/
-#define uip_datalen()       uip_len
-
-/**
- * The length of any out-of-band data (urgent data) that has arrived
- * on the connection.
- *
- * \note The configuration parameter UIP_URGDATA must be set for this
- * function to be enabled.
- *
- * \hideinitializer
- */
-#define uip_urgdatalen()    uip_urglen
-
-/**
- * Close the current connection.
- *
- * This function will close the current connection in a nice way.
- *
- * \hideinitializer
- */
-#define uip_close()         (uip_flags = UIP_CLOSE)
-
-/**
- * Abort the current connection.
- *
- * This function will abort (reset) the current connection, and is
- * usually used when an error has occurred that prevents using the
- * uip_close() function.
- *
- * \hideinitializer
- */
-#define uip_abort()         (uip_flags = UIP_ABORT)
-
-/**
- * Tell the sending host to stop sending data.
- *
- * This function will close our receiver's window so that we stop
- * receiving data for the current connection.
- *
- * \hideinitializer
- */
-#define uip_stop()          (uip_conn->tcpstateflags |= UIP_STOPPED)
-
-/**
- * Find out if the current connection has been previously stopped with
- * uip_stop().
- *
- * \hideinitializer
- */
-#define uip_stopped(conn)   ((conn)->tcpstateflags & UIP_STOPPED)
-
-/**
- * Restart the current connection, if is has previously been stopped
- * with uip_stop().
- *
- * This function will open the receiver's window again so that we
- * start receiving data for the current connection.
- *
- * \hideinitializer
- */
-#define uip_restart()         do { uip_flags |= UIP_NEWDATA;    \
-    uip_conn->tcpstateflags &= ~UIP_STOPPED;                    \
-  } while(0)
-
-
-/* uIP tests that can be made to determine in what state the current
-   connection is, and what the application function should do. */
-
-/**
- * Is the current connection a UDP connection?
- *
- * This function checks whether the current connection is a UDP connection.
- *
- * \hideinitializer
- *
- */
-#define uip_udpconnection() (uip_conn == NULL)
-
-/**
- * Is new incoming data available?
- *
- * Will reduce to non-zero if there is new data for the application
- * present at the uip_appdata pointer. The size of the data is
- * available through the uip_len variable.
- *
- * \hideinitializer
- */
-#define uip_newdata()   (uip_flags & UIP_NEWDATA)
-
-/**
- * Has previously sent data been acknowledged?
- *
- * Will reduce to non-zero if the previously sent data has been
- * acknowledged by the remote host. This means that the application
- * can send new data.
- *
- * \hideinitializer
- */
-#define uip_acked()   (uip_flags & UIP_ACKDATA)
-
-/**
- * Has the connection just been connected?
- *
- * Reduces to non-zero if the current connection has been connected to
- * a remote host. This will happen both if the connection has been
- * actively opened (with uip_connect()) or passively opened (with
- * uip_listen()).
- *
- * \hideinitializer
- */
-#define uip_connected() (uip_flags & UIP_CONNECTED)
-
-/**
- * Has the connection been closed by the other end?
- *
- * Is non-zero if the connection has been closed by the remote
- * host. The application may then do the necessary clean-ups.
- *
- * \hideinitializer
- */
-#define uip_closed()    (uip_flags & UIP_CLOSE)
-
-/**
- * Has the connection been aborted by the other end?
- *
- * Non-zero if the current connection has been aborted (reset) by the
- * remote host.
- *
- * \hideinitializer
- */
-#define uip_aborted()    (uip_flags & UIP_ABORT)
-
-/**
- * Has the connection timed out?
- *
- * Non-zero if the current connection has been aborted due to too many
- * retransmissions.
- *
- * \hideinitializer
- */
-#define uip_timedout()    (uip_flags & UIP_TIMEDOUT)
-
-/**
- * Do we need to retransmit previously data?
- *
- * Reduces to non-zero if the previously sent data has been lost in
- * the network, and the application should retransmit it. The
- * application should send the exact same data as it did the last
- * time, using the uip_send() function.
- *
- * \hideinitializer
- */
-#define uip_rexmit()     (uip_flags & UIP_REXMIT)
-
-/**
- * Is the connection being polled by uIP?
- *
- * Is non-zero if the reason the application is invoked is that the
- * current connection has been idle for a while and should be
- * polled.
- *
- * The polling event can be used for sending data without having to
- * wait for the remote host to send data.
- *
- * \hideinitializer
- */
-#define uip_poll()       (uip_flags & UIP_POLL)
-
-/**
- * Get the initial maximum segment size (MSS) of the current
- * connection.
- *
- * \hideinitializer
- */
-#define uip_initialmss()             (uip_conn->initialmss)
-
-/**
- * Get the current maximum segment size that can be sent on the current
- * connection.
- *
- * The current maximum segment size that can be sent on the
- * connection is computed from the receiver's window and the MSS of
- * the connection (which also is available by calling
- * uip_initialmss()).
- *
- * \hideinitializer
- */
-#define uip_mss()             (uip_conn->mss)
-
-/**
- * Set up a new UDP connection.
- *
- * This function sets up a new UDP connection. The function will
- * automatically allocate an unused local port for the new
- * connection. However, another port can be chosen by using the
- * uip_udp_bind() call, after the uip_udp_new() function has been
- * called.
- *
- * Example:
- \code
- uip_ipaddr_t addr;
- struct uip_udp_conn *c;
- uip_ipaddr(&addr, 192,168,2,1);
- c = uip_udp_new(&addr, HTONS(12345));
- if(c != NULL) {
- uip_udp_bind(c, HTONS(12344));
- }
- \endcode
- * \param ripaddr The IP address of the remote host.
- *
- * \param rport The remote port number in network byte order.
- *
- * \return The uip_udp_conn structure for the new connection or NULL
- * if no connection could be allocated.
- */
-struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport);
-
-/**
- * Removed a UDP connection.
- *
- * \param conn A pointer to the uip_udp_conn structure for the connection.
- *
- * \hideinitializer
- */
-#define uip_udp_remove(conn) (conn)->lport = 0
-
-/**
- * Bind a UDP connection to a local port.
- *
- * \param conn A pointer to the uip_udp_conn structure for the
- * connection.
- *
- * \param port The local port number, in network byte order.
- *
- * \hideinitializer
- */
-#define uip_udp_bind(conn, port) (conn)->lport = port
-
-/**
- * Send a UDP datagram of length len on the current connection.
- *
- * This function can only be called in response to a UDP event (poll
- * or newdata). The data must be present in the uip_buf buffer, at the
- * place pointed to by the uip_appdata pointer.
- *
- * \param len The length of the data in the uip_buf buffer.
- *
- * \hideinitializer
- */
-#define uip_udp_send(len) uip_send((char *)uip_appdata, len)
-
-/** @} */
-
-/* uIP convenience and converting functions. */
-
-/**
- * \defgroup uipconvfunc uIP conversion functions
- * @{
- *
- * These functions can be used for converting between different data
- * formats used by uIP.
- */
-/**
- * Convert an IP address to four bytes separated by commas.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr;
- printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
- \endcode
- *
- * \param a A pointer to a uip_ipaddr_t.
- * \hideinitializer
- */
-#define uip_ipaddr_to_quad(a) (a)->u8[0],(a)->u8[1],(a)->u8[2],(a)->u8[3]
-
-/**
- * Construct an IP address from four bytes.
- *
- * This function constructs an IP address of the type that uIP handles
- * internally from four bytes. The function is handy for specifying IP
- * addresses to use with e.g. the uip_connect() function.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr;
- struct uip_conn *c;
- uip_ipaddr(&ipaddr, 192,168,1,2);
- c = uip_connect(&ipaddr, HTONS(80));
- \endcode
- *
- * \param addr A pointer to a uip_ipaddr_t variable that will be
- * filled in with the IP address.
- *
- * \param addr0 The first octet of the IP address.
- * \param addr1 The second octet of the IP address.
- * \param addr2 The third octet of the IP address.
- * \param addr3 The forth octet of the IP address.
- *
- * \hideinitializer
- */
-#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do {  \
-    (addr)->u8[0] = addr0;                              \
-    (addr)->u8[1] = addr1;                              \
-    (addr)->u8[2] = addr2;                              \
-    (addr)->u8[3] = addr3;                              \
-  } while(0)
-
-/**
- * Construct an IPv6 address from eight 16-bit words.
- *
- * This function constructs an IPv6 address.
- *
- * \hideinitializer
- */
-#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
-    (addr)->u16[0] = HTONS(addr0);                                      \
-    (addr)->u16[1] = HTONS(addr1);                                      \
-    (addr)->u16[2] = HTONS(addr2);                                      \
-    (addr)->u16[3] = HTONS(addr3);                                      \
-    (addr)->u16[4] = HTONS(addr4);                                      \
-    (addr)->u16[5] = HTONS(addr5);                                      \
-    (addr)->u16[6] = HTONS(addr6);                                      \
-    (addr)->u16[7] = HTONS(addr7);                                      \
-  } while(0)
-
-/**
- * Construct an IPv6 address from eight 8-bit words.
- *
- * This function constructs an IPv6 address.
- *
- * \hideinitializer
- */
-#define uip_ip6addr_u8(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7,addr8,addr9,addr10,addr11,addr12,addr13,addr14,addr15) do { \
-    (addr)->u8[0] = addr0;                                       \
-    (addr)->u8[1] = addr1;                                       \
-    (addr)->u8[2] = addr2;                                       \
-    (addr)->u8[3] = addr3;                                       \
-    (addr)->u8[4] = addr4;                                       \
-    (addr)->u8[5] = addr5;                                       \
-    (addr)->u8[6] = addr6;                                       \
-    (addr)->u8[7] = addr7;                                       \
-    (addr)->u8[8] = addr8;                                       \
-    (addr)->u8[9] = addr9;                                       \
-    (addr)->u8[10] = addr10;                                     \
-    (addr)->u8[11] = addr11;                                     \
-    (addr)->u8[12] = addr12;                                     \
-    (addr)->u8[13] = addr13;                                     \
-    (addr)->u8[14] = addr14;                                     \
-    (addr)->u8[15] = addr15;                                     \
-  } while(0)
-
-
-/**
- * Copy an IP address to another IP address.
- *
- * Copies an IP address from one place to another.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr1, ipaddr2;
-
- uip_ipaddr(&ipaddr1, 192,16,1,2);
- uip_ipaddr_copy(&ipaddr2, &ipaddr1);
- \endcode
- *
- * \param dest The destination for the copy.
- * \param src The source from where to copy.
- *
- * \hideinitializer
- */
-#ifndef uip_ipaddr_copy
-#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
-#endif
-
-/**
- * Compare two IP addresses
- *
- * Compares two IP addresses.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr1, ipaddr2;
-
- uip_ipaddr(&ipaddr1, 192,16,1,2);
- if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
- printf("They are the same");
- }
- \endcode
- *
- * \param addr1 The first IP address.
- * \param addr2 The second IP address.
- *
- * \hideinitializer
- */
-#if !UIP_CONF_IPV6
-#define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
-                                     (addr1)->u16[1] == (addr2)->u16[1])
-#else /* !UIP_CONF_IPV6 */
-#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
-#endif /* !UIP_CONF_IPV6 */
-
-/**
- * Compare two IP addresses with netmasks
- *
- * Compares two IP addresses with netmasks. The masks are used to mask
- * out the bits that are to be compared.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr1, ipaddr2, mask;
-
- uip_ipaddr(&mask, 255,255,255,0);
- uip_ipaddr(&ipaddr1, 192,16,1,2);
- uip_ipaddr(&ipaddr2, 192,16,1,3);
- if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
- printf("They are the same");
- }
- \endcode
- *
- * \param addr1 The first IP address.
- * \param addr2 The second IP address.
- * \param mask The netmask.
- *
- * \hideinitializer
- */
-#if !UIP_CONF_IPV6
-#define uip_ipaddr_maskcmp(addr1, addr2, mask)          \
-  (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) ==       \
-    (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) &&      \
-   ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) ==       \
-    (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))
-#else
-#define uip_ipaddr_prefixcmp(addr1, addr2, length) (memcmp(addr1, addr2, length>>3) == 0)
-#endif
-
-
-/**
- * Check if an address is a broadcast address for a network.
- *
- * Checks if an address is the broadcast address for a network. The
- * network is defined by an IP address that is on the network and the
- * network's netmask.
- *
- * \param addr The IP address.
- * \param netaddr The network's IP address.
- * \param netmask The network's netmask.
- *
- * \hideinitializer
- */
-/*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
-  ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
-
-
-
-/**
- * Mask out the network part of an IP address.
- *
- * Masks out the network part of an IP address, given the address and
- * the netmask.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr1, ipaddr2, netmask;
-
- uip_ipaddr(&ipaddr1, 192,16,1,2);
- uip_ipaddr(&netmask, 255,255,255,0);
- uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
- \endcode
- *
- * In the example above, the variable "ipaddr2" will contain the IP
- * address 192.168.1.0.
- *
- * \param dest Where the result is to be placed.
- * \param src The IP address.
- * \param mask The netmask.
- *
- * \hideinitializer
- */
-#define uip_ipaddr_mask(dest, src, mask) do {                           \
-    ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0];        \
-    ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1];        \
-  } while(0)
-
-/**
- * Pick the first octet of an IP address.
- *
- * Picks out the first octet of an IP address.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr;
- u8_t octet;
-
- uip_ipaddr(&ipaddr, 1,2,3,4);
- octet = uip_ipaddr1(&ipaddr);
- \endcode
- *
- * In the example above, the variable "octet" will contain the value 1.
- *
- * \hideinitializer
- */
-#define uip_ipaddr1(addr) ((addr)->u8[0])
-
-/**
- * Pick the second octet of an IP address.
- *
- * Picks out the second octet of an IP address.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr;
- u8_t octet;
-
- uip_ipaddr(&ipaddr, 1,2,3,4);
- octet = uip_ipaddr2(&ipaddr);
- \endcode
- *
- * In the example above, the variable "octet" will contain the value 2.
- *
- * \hideinitializer
- */
-#define uip_ipaddr2(addr) ((addr)->u8[1])
-
-/**
- * Pick the third octet of an IP address.
- *
- * Picks out the third octet of an IP address.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr;
- u8_t octet;
-
- uip_ipaddr(&ipaddr, 1,2,3,4);
- octet = uip_ipaddr3(&ipaddr);
- \endcode
- *
- * In the example above, the variable "octet" will contain the value 3.
- *
- * \hideinitializer
- */
-#define uip_ipaddr3(addr) ((addr)->u8[2])
-
-/**
- * Pick the fourth octet of an IP address.
- *
- * Picks out the fourth octet of an IP address.
- *
- * Example:
- \code
- uip_ipaddr_t ipaddr;
- u8_t octet;
-
- uip_ipaddr(&ipaddr, 1,2,3,4);
- octet = uip_ipaddr4(&ipaddr);
- \endcode
- *
- * In the example above, the variable "octet" will contain the value 4.
- *
- * \hideinitializer
- */
-#define uip_ipaddr4(addr) ((addr)->u8[3])
-
-/**
- * Convert 16-bit quantity from host byte order to network byte order.
- *
- * This macro is primarily used for converting constants from host
- * byte order to network byte order. For converting variables to
- * network byte order, use the htons() function instead.
- *
- * \hideinitializer
- */
-#ifndef HTONS
-#   if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
-#      define HTONS(n) (n)
-#      define HTONL(n) (n)
-#   else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
-#      define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))
-#      define HTONL(n) (((u32_t)HTONS(n) << 16) | HTONS((u32_t)(n) >> 16))
-#   endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
-#else
-#error "HTONS already defined!"
-#endif /* HTONS */
-
-/**
- * Convert 16-bit quantity from host byte order to network byte order.
- *
- * This function is primarily used for converting variables from host
- * byte order to network byte order. For converting constants to
- * network byte order, use the HTONS() macro instead.
- */
-#ifndef htons
-u16_t htons(u16_t val);
-#endif /* htons */
-#ifndef ntohs
-#define ntohs htons
-#endif
-
-#ifndef htonl
-u32_t htonl(u32_t val);
-#endif /* htonl */
-#ifndef ntohl
-#define ntohl htonl
-#endif
-
-/** @} */
-
-/**
- * Pointer to the application data in the packet buffer.
- *
- * This pointer points to the application data when the application is
- * called. If the application wishes to send data, the application may
- * use this space to write the data into before calling uip_send().
- */
-extern void *uip_appdata;
-
-#if UIP_URGDATA > 0
-/* u8_t *uip_urgdata:
- *
- * This pointer points to any urgent data that has been received. Only
- * present if compiled with support for urgent data (UIP_URGDATA).
- */
-extern void *uip_urgdata;
-#endif /* UIP_URGDATA > 0 */
-
-
-/**
- * \defgroup uipdrivervars Variables used in uIP device drivers
- * @{
- *
- * uIP has a few global variables that are used in device drivers for
- * uIP.
- */
-
-/**
- * The length of the packet in the uip_buf buffer.
- *
- * The global variable uip_len holds the length of the packet in the
- * uip_buf buffer.
- *
- * When the network device driver calls the uIP input function,
- * uip_len should be set to the length of the packet in the uip_buf
- * buffer.
- *
- * When sending packets, the device driver should use the contents of
- * the uip_len variable to determine the length of the outgoing
- * packet.
- *
- */
-extern u16_t uip_len;
-
-/**
- * The length of the extension headers
- */
-extern u8_t uip_ext_len;
-/** @} */
-
-#if UIP_URGDATA > 0
-extern u16_t uip_urglen, uip_surglen;
-#endif /* UIP_URGDATA > 0 */
-
-
-/**
- * Representation of a uIP TCP connection.
- *
- * The uip_conn structure is used for identifying a connection. All
- * but one field in the structure are to be considered read-only by an
- * application. The only exception is the appstate field whose purpose
- * is to let the application store application-specific state (e.g.,
- * file pointers) for the connection. The type of this field is
- * configured in the "uipopt.h" header file.
- */
-struct uip_conn {
-  uip_ipaddr_t ripaddr;   /**< The IP address of the remote host. */
-  
-  u16_t lport;        /**< The local TCP port, in network byte order. */
-  u16_t rport;        /**< The local remote TCP port, in network byte
-                        order. */
-  
-  u8_t rcv_nxt[4];    /**< The sequence number that we expect to
-                        receive next. */
-  u8_t snd_nxt[4];    /**< The sequence number that was last sent by
-                         us. */
-  u16_t len;          /**< Length of the data that was previously sent. */
-  u16_t mss;          /**< Current maximum segment size for the
-                        connection. */
-  u16_t initialmss;   /**< Initial maximum segment size for the
-                        connection. */
-  u8_t sa;            /**< Retransmission time-out calculation state
-                        variable. */
-  u8_t sv;            /**< Retransmission time-out calculation state
-                        variable. */
-  u8_t rto;           /**< Retransmission time-out. */
-  u8_t tcpstateflags; /**< TCP state and flags. */
-  u8_t timer;         /**< The retransmission timer. */
-  u8_t nrtx;          /**< The number of retransmissions for the last
-                        segment sent. */
-
-  /** The application state. */
-  uip_tcp_appstate_t appstate;
-};
-
-
-/**
- * Pointer to the current TCP connection.
- *
- * The uip_conn pointer can be used to access the current TCP
- * connection.
- */
-
-extern struct uip_conn *uip_conn;
-#if UIP_TCP
-/* The array containing all uIP connections. */
-extern struct uip_conn uip_conns[UIP_CONNS];
-#endif
-
-/**
- * \addtogroup uiparch
- * @{
- */
-
-/**
- * 4-byte array used for the 32-bit sequence number calculations.
- */
-extern u8_t uip_acc32[4];
-/** @} */
-
-/**
- * Representation of a uIP UDP connection.
- */
-struct uip_udp_conn {
-  uip_ipaddr_t ripaddr;   /**< The IP address of the remote peer. */
-  u16_t lport;        /**< The local port number in network byte order. */
-  u16_t rport;        /**< The remote port number in network byte order. */
-  u8_t  ttl;          /**< Default time-to-live. */
-
-  /** The application state. */
-  uip_udp_appstate_t appstate;
-};
-
-/**
- * The current UDP connection.
- */
-extern struct uip_udp_conn *uip_udp_conn;
-extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
-
-struct uip_router {
-  int (*activate)(void);
-  int (*deactivate)(void);
-  uip_ipaddr_t *(*lookup)(uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop);
-};
-
-#if UIP_CONF_ROUTER
-extern const struct uip_router *uip_router;
-
-/**
- * uIP routing driver registration function.
- */
-void uip_router_register(const struct uip_router *router);
-#endif /*UIP_CONF_ROUTER*/
-
-#if UIP_CONF_ICMP6
-struct uip_icmp6_conn {
-  uip_icmp6_appstate_t appstate;
-};
-extern struct uip_icmp6_conn uip_icmp6_conns;
-#endif /*UIP_CONF_ICMP6*/
-
-/**
- * The uIP TCP/IP statistics.
- *
- * This is the variable in which the uIP TCP/IP statistics are gathered.
- */
-#if UIP_STATISTICS == 1
-extern struct uip_stats uip_stat;
-#define UIP_STAT(s) s
-#else
-#define UIP_STAT(s)
-#endif /* UIP_STATISTICS == 1 */
-
-/**
- * The structure holding the TCP/IP statistics that are gathered if
- * UIP_STATISTICS is set to 1.
- *
- */
-struct uip_stats {
-  struct {
-    uip_stats_t recv;     /**< Number of received packets at the IP
-                            layer. */
-    uip_stats_t sent;     /**< Number of sent packets at the IP
-                            layer. */
-    uip_stats_t forwarded;/**< Number of forwarded packets at the IP 
-                            layer. */
-    uip_stats_t drop;     /**< Number of dropped packets at the IP
-                            layer. */
-    uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong
-                            IP version or header length. */
-    uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
-                            IP length, high byte. */
-    uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
-                            IP length, low byte. */
-    uip_stats_t fragerr;  /**< Number of packets dropped since they
-                            were IP fragments. */
-    uip_stats_t chkerr;   /**< Number of packets dropped due to IP
-                            checksum errors. */
-    uip_stats_t protoerr; /**< Number of packets dropped since they
-                            were neither ICMP, UDP nor TCP. */
-  } ip;                   /**< IP statistics. */
-  struct {
-    uip_stats_t recv;     /**< Number of received ICMP packets. */
-    uip_stats_t sent;     /**< Number of sent ICMP packets. */
-    uip_stats_t drop;     /**< Number of dropped ICMP packets. */
-    uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong
-                            type. */
-    uip_stats_t chkerr;   /**< Number of ICMP packets with a bad
-                            checksum. */
-  } icmp;                 /**< ICMP statistics. */
-#if UIP_TCP
-  struct {
-    uip_stats_t recv;     /**< Number of recived TCP segments. */
-    uip_stats_t sent;     /**< Number of sent TCP segments. */
-    uip_stats_t drop;     /**< Number of dropped TCP segments. */
-    uip_stats_t chkerr;   /**< Number of TCP segments with a bad
-                            checksum. */
-    uip_stats_t ackerr;   /**< Number of TCP segments with a bad ACK
-                            number. */
-    uip_stats_t rst;      /**< Number of recevied TCP RST (reset) segments. */
-    uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */
-    uip_stats_t syndrop;  /**< Number of dropped SYNs due to too few
-                            connections was avaliable. */
-    uip_stats_t synrst;   /**< Number of SYNs for closed ports,
-                            triggering a RST. */
-  } tcp;                  /**< TCP statistics. */
-#endif
-#if UIP_UDP
-  struct {
-    uip_stats_t drop;     /**< Number of dropped UDP segments. */
-    uip_stats_t recv;     /**< Number of recived UDP segments. */
-    uip_stats_t sent;     /**< Number of sent UDP segments. */
-    uip_stats_t chkerr;   /**< Number of UDP segments with a bad
-                            checksum. */
-  } udp;                  /**< UDP statistics. */
-#endif /* UIP_UDP */
-#if UIP_CONF_IPV6
-  struct {
-    uip_stats_t drop;     /**< Number of dropped ND6 packets. */
-    uip_stats_t recv;     /**< Number of recived ND6 packets */
-    uip_stats_t sent;     /**< Number of sent ND6 packets */
-  } nd6;
-#endif /*UIP_CONF_IPV6*/
-};
-
-
-/*---------------------------------------------------------------------------*/
-/* All the stuff below this point is internal to uIP and should not be
- * used directly by an application or by a device driver.
- */
-/*---------------------------------------------------------------------------*/
-
-
-
-/* u8_t uip_flags:
- *
- * When the application is called, uip_flags will contain the flags
- * that are defined in this file. Please read below for more
- * information.
- */
-extern u8_t uip_flags;
-
-/* The following flags may be set in the global variable uip_flags
-   before calling the application callback. The UIP_ACKDATA,
-   UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
-   whereas the others are mutually exclusive. Note that these flags
-   should *NOT* be accessed directly, but only through the uIP
-   functions/macros. */
-
-#define UIP_ACKDATA   1     /* Signifies that the outstanding data was
-                              acked and the application should send
-                              out new data instead of retransmitting
-                              the last data. */
-#define UIP_NEWDATA   2     /* Flags the fact that the peer has sent
-                              us new data. */
-#define UIP_REXMIT    4     /* Tells the application to retransmit the
-                              data that was last sent. */
-#define UIP_POLL      8     /* Used for polling the application, to
-                              check if the application has data that
-                              it wants to send. */
-#define UIP_CLOSE     16    /* The remote host has closed the
-                              connection, thus the connection has
-                              gone away. Or the application signals
-                              that it wants to close the
-                              connection. */
-#define UIP_ABORT     32    /* The remote host has aborted the
-                              connection, thus the connection has
-                              gone away. Or the application signals
-                              that it wants to abort the
-                              connection. */
-#define UIP_CONNECTED 64    /* We have got a connection from a remote
-                               host and have set up a new connection
-                               for it, or an active connection has
-                               been successfully established. */
-
-#define UIP_TIMEDOUT  128   /* The connection has been aborted due to
-                              too many retransmissions. */
-
-
-/**
- * \brief process the options within a hop by hop or destination option header
- * \retval 0: nothing to send,
- * \retval 1: drop pkt
- * \retval 2: ICMP error message to send
-*/
-/*static u8_t
-uip_ext_hdr_options_process(); */
-
-/* uip_process(flag):
- *
- * The actual uIP function which does all the work.
- */
-void uip_process(u8_t flag);
-  
-  /* The following flags are passed as an argument to the uip_process()
-   function. They are used to distinguish between the two cases where
-   uip_process() is called. It can be called either because we have
-   incoming data that should be processed, or because the periodic
-   timer has fired. These values are never used directly, but only in
-   the macros defined in this file. */
-#define UIP_DATA          1     /* Tells uIP that there is incoming
-                                  data in the uip_buf buffer. The
-                                  length of the data is stored in the
-                                  global variable uip_len. */
-#define UIP_TIMER         2     /* Tells uIP that the periodic timer
-                                  has fired. */
-#define UIP_POLL_REQUEST  3     /* Tells uIP that a connection should
-                                  be polled. */
-#define UIP_UDP_SEND_CONN 4     /* Tells uIP that a UDP datagram
-                                  should be constructed in the
-                                  uip_buf buffer. */
-#if UIP_UDP
-#define UIP_UDP_TIMER     5
-#endif /* UIP_UDP */
-
-/* The TCP states used in the uip_conn->tcpstateflags. */
-#define UIP_CLOSED      0
-#define UIP_SYN_RCVD    1
-#define UIP_SYN_SENT    2
-#define UIP_ESTABLISHED 3
-#define UIP_FIN_WAIT_1  4
-#define UIP_FIN_WAIT_2  5
-#define UIP_CLOSING     6
-#define UIP_TIME_WAIT   7
-#define UIP_LAST_ACK    8
-#define UIP_TS_MASK     15
-  
-#define UIP_STOPPED      16
-
-/* The TCP and IP headers. */
-struct uip_tcpip_hdr {
-#if UIP_CONF_IPV6
-  /* IPv6 header. */
-  u8_t vtc,
-    tcflow;
-  u16_t flow;
-  u8_t len[2];
-  u8_t proto, ttl;
-  uip_ip6addr_t srcipaddr, destipaddr;
-#else /* UIP_CONF_IPV6 */
-  /* IPv4 header. */
-  u8_t vhl,
-    tos,
-    len[2],
-    ipid[2],
-    ipoffset[2],
-    ttl,
-    proto;
-  u16_t ipchksum;
-  uip_ipaddr_t srcipaddr, destipaddr;
-#endif /* UIP_CONF_IPV6 */
-  
-  /* TCP header. */
-  u16_t srcport,
-    destport;
-  u8_t seqno[4],
-    ackno[4],
-    tcpoffset,
-    flags,
-    wnd[2];
-  u16_t tcpchksum;
-  u8_t urgp[2];
-  u8_t optdata[4];
-};
-
-/* The ICMP and IP headers. */
-struct uip_icmpip_hdr {
-#if UIP_CONF_IPV6
-  /* IPv6 header. */
-  u8_t vtc,
-    tcf;
-  u16_t flow;
-  u8_t len[2];
-  u8_t proto, ttl;
-  uip_ip6addr_t srcipaddr, destipaddr;
-#else /* UIP_CONF_IPV6 */
-  /* IPv4 header. */
-  u8_t vhl,
-    tos,
-    len[2],
-    ipid[2],
-    ipoffset[2],
-    ttl,
-    proto;
-  u16_t ipchksum;
-  uip_ipaddr_t srcipaddr, destipaddr;
-#endif /* UIP_CONF_IPV6 */
-  
-  /* ICMP header. */
-  u8_t type, icode;
-  u16_t icmpchksum;
-#if !UIP_CONF_IPV6
-  u16_t id, seqno;
-  u8_t payload[1];
-#endif /* !UIP_CONF_IPV6 */
-};
-
-
-/* The UDP and IP headers. */
-struct uip_udpip_hdr {
-#if UIP_CONF_IPV6
-  /* IPv6 header. */
-  u8_t vtc,
-    tcf;
-  u16_t flow;
-  u8_t len[2];
-  u8_t proto, ttl;
-  uip_ip6addr_t srcipaddr, destipaddr;
-#else /* UIP_CONF_IPV6 */
-  /* IP header. */
-  u8_t vhl,
-    tos,
-    len[2],
-    ipid[2],
-    ipoffset[2],
-    ttl,
-    proto;
-  u16_t ipchksum;
-  uip_ipaddr_t srcipaddr, destipaddr;
-#endif /* UIP_CONF_IPV6 */
-  
-  /* UDP header. */
-  u16_t srcport,
-    destport;
-  u16_t udplen;
-  u16_t udpchksum;
-};
-
-/*
- * In IPv6 the length of the L3 headers before the transport header is
- * not fixed, due to the possibility to include extension option headers
- * after the IP header. hence we split here L3 and L4 headers
- */
-/* The IP header */
-struct uip_ip_hdr {
-#if UIP_CONF_IPV6
-  /* IPV6 header */
-  u8_t vtc;
-  u8_t tcflow;
-  u16_t flow;
-  u8_t len[2];
-  u8_t proto, ttl;
-  uip_ip6addr_t srcipaddr, destipaddr;
-#else /* UIP_CONF_IPV6 */
-  /* IPV4 header */
-  u8_t vhl,
-    tos,
-    len[2],
-    ipid[2],
-    ipoffset[2],
-    ttl,
-    proto;
-  u16_t ipchksum;
-  uip_ipaddr_t srcipaddr, destipaddr;
-#endif /* UIP_CONF_IPV6 */
-};
-
-
-/*
- * IPv6 extension option headers: we are able to process
- * the 4 extension headers defined in RFC2460 (IPv6):
- * - Hop by hop option header, destination option header:
- *   These two are not used by any core IPv6 protocol, hence
- *   we just read them and go to the next. They convey options,
- *   the options defined in RFC2460 are Pad1 and PadN, which do
- *   some padding, and that we do not need to read (the length
- *   field in the header is enough)
- * - Routing header: this one is most notably used by MIPv6,
- *   which we do not implement, hence we just read it and go
- *   to the next
- * - Fragmentation header: we read this header and are able to
- *   reassemble packets
- *
- * We do not offer any means to send packets with extension headers
- *
- * We do not implement Authentication and ESP headers, which are
- * used in IPSec and defined in RFC4302,4303,4305,4385
- */
-/* common header part */
-struct uip_ext_hdr {
-  u8_t next;
-  u8_t len;
-};
-
-/* Hop by Hop option header */
-struct uip_hbho_hdr {
-  u8_t next;
-  u8_t len;
-};
-
-/* destination option header */
-struct uip_desto_hdr {
-  u8_t next;
-  u8_t len;
-};
-
-/* We do not define structures for PAD1 and PADN options */
-
-/*
- * routing header
- * the routing header as 4 common bytes, then routing header type
- * specific data there are several types of routing header. Type 0 was
- * deprecated as per RFC5095 most notable other type is 2, used in
- * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
- * parse the 4 first bytes
- */
-struct uip_routing_hdr {
-  u8_t next;
-  u8_t len;
-  u8_t routing_type;
-  u8_t seg_left;
-};
-
-/* fragmentation header */
-struct uip_frag_hdr {
-  u8_t next;
-  u8_t res;
-  u16_t offsetresmore;
-  u32_t id;
-};
-
-/*
- * an option within the destination or hop by hop option headers
- * it contains type an length, which is true for all options but PAD1
- */
-struct uip_ext_hdr_opt {
-  u8_t type;
-  u8_t len;
-};
-
-/* PADN option */
-struct uip_ext_hdr_opt_padn {
-  u8_t opt_type;
-  u8_t opt_len;
-};
-
-/* TCP header */
-struct uip_tcp_hdr {
-  u16_t srcport;
-  u16_t destport;
-  u8_t seqno[4];
-  u8_t ackno[4];
-  u8_t tcpoffset;
-  u8_t flags;
-  u8_t  wnd[2];
-  u16_t tcpchksum;
-  u8_t urgp[2];
-  u8_t optdata[4];
-};
-
-/* The ICMP headers. */
-struct uip_icmp_hdr {
-  u8_t type, icode;
-  u16_t icmpchksum;
-#if !UIP_CONF_IPV6
-  u16_t id, seqno;
-#endif /* !UIP_CONF_IPV6 */
-};
-
-
-/* The UDP headers. */
-struct uip_udp_hdr {
-  u16_t srcport;
-  u16_t destport;
-  u16_t udplen;
-  u16_t udpchksum;
-};
-
-
-/**
- * The buffer size available for user data in the \ref uip_buf buffer.
- *
- * This macro holds the available size for user data in the \ref
- * uip_buf buffer. The macro is intended to be used for checking
- * bounds of available user data.
- *
- * Example:
- \code
- snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
- \endcode
- *
- * \hideinitializer
- */
-#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
-#define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
-
-#define UIP_PROTO_ICMP  1
-#define UIP_PROTO_TCP   6
-#define UIP_PROTO_UDP   17
-#define UIP_PROTO_ICMP6 58
-
-
-#if UIP_CONF_IPV6
-/** @{ */
-/** \brief  extension headers types */
-#define UIP_PROTO_HBHO        0
-#define UIP_PROTO_DESTO       60
-#define UIP_PROTO_ROUTING     43
-#define UIP_PROTO_FRAG        44
-#define UIP_PROTO_NONE        59
-/** @} */
-
-/** @{ */
-/** \brief  Destination and Hop By Hop extension headers option types */
-#define UIP_EXT_HDR_OPT_PAD1  0
-#define UIP_EXT_HDR_OPT_PADN  1
-/** @} */
-
-/** @{ */
-/**
- * \brief Bitmaps for extension header processing
- *
- * When processing extension headers, we should record somehow which one we
- * see, because you cannot have twice the same header, except for destination
- * We store all this in one u8_t bitmap one bit for each header expected. The
- * order in the bitmap is the order recommended in RFC2460
- */
-#define UIP_EXT_HDR_BITMAP_HBHO 0x01
-#define UIP_EXT_HDR_BITMAP_DESTO1 0x02
-#define UIP_EXT_HDR_BITMAP_ROUTING 0x04
-#define UIP_EXT_HDR_BITMAP_FRAG 0x08
-#define UIP_EXT_HDR_BITMAP_AH 0x10
-#define UIP_EXT_HDR_BITMAP_ESP 0x20
-#define UIP_EXT_HDR_BITMAP_DESTO2 0x40
-/** @} */
-
-
-#endif /* UIP_CONF_IPV6 */
-
-
-/* Header sizes. */
-#if UIP_CONF_IPV6
-#define UIP_IPH_LEN    40
-#define UIP_FRAGH_LEN  8
-#else /* UIP_CONF_IPV6 */
-#define UIP_IPH_LEN    20    /* Size of IP header */
-#endif /* UIP_CONF_IPV6 */
-
-#define UIP_UDPH_LEN    8    /* Size of UDP header */
-#define UIP_TCPH_LEN   20    /* Size of TCP header */
-#ifdef UIP_IPH_LEN
-#define UIP_ICMPH_LEN   4    /* Size of ICMP header */
-#endif
-#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN)    /* Size of IP +
-                        * UDP
-                                                          * header */
-#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN)    /* Size of IP +
-                                                          * TCP
-                                                          * header */
-#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
-#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP
-                                                         + IP header */
-#define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN)    /* size of L2
-                                                        + IP header */
-#if UIP_CONF_IPV6
-/**
- * The sums below are quite used in ND. When used for uip_buf, we
- * include link layer length when used for uip_len, we do not, hence
- * we need values with and without LLH_LEN we do not use capital
- * letters as these values are variable
- */
-#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
-#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
-#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
-#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
-#endif /*UIP_CONF_IPV6*/
-
-
-#if UIP_FIXEDADDR
-extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
-#else /* UIP_FIXEDADDR */
-extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
-#endif /* UIP_FIXEDADDR */
-extern const uip_ipaddr_t uip_broadcast_addr;
-extern const uip_ipaddr_t uip_all_zeroes_addr;
-
-#if UIP_FIXEDETHADDR
-extern const uip_lladdr_t uip_lladdr;
-#else
-extern uip_lladdr_t uip_lladdr;
-#endif
-
-
-
-
-#ifdef UIP_CONF_IPV6
-/**
- * \brief Is IPv6 address a the unspecified address
- * a is of type uip_ipaddr_t
- */
-#define uip_is_addr_unspecified(a)               \
-  ((((a)->u16[0]) == 0) &&                       \
-   (((a)->u16[1]) == 0) &&                       \
-   (((a)->u16[2]) == 0) &&                       \
-   (((a)->u16[3]) == 0) &&                       \
-   (((a)->u16[4]) == 0) &&                       \
-   (((a)->u16[5]) == 0) &&                       \
-   (((a)->u16[6]) == 0) &&                       \
-   (((a)->u16[7]) == 0))
-
-/** \brief Is IPv6 address a the link local all-nodes multicast address */
-#define uip_is_addr_linklocal_allnodes_mcast(a)     \
-  ((((a)->u8[0]) == 0xff) &&                        \
-   (((a)->u8[1]) == 0x02) &&                        \
-   (((a)->u16[1]) == 0) &&                          \
-   (((a)->u16[2]) == 0) &&                          \
-   (((a)->u16[3]) == 0) &&                          \
-   (((a)->u16[4]) == 0) &&                          \
-   (((a)->u16[5]) == 0) &&                          \
-   (((a)->u16[6]) == 0) &&                          \
-   (((a)->u8[14]) == 0) &&                          \
-   (((a)->u8[15]) == 0x01))
-
-/** \brief set IP address a to unspecified */
-#define uip_create_unspecified(a) uip_ip6addr(a, 0, 0, 0, 0, 0, 0, 0, 0)
-
-/** \brief set IP address a to the link local all-nodes multicast address */
-#define uip_create_linklocal_allnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001)
-
-/** \brief set IP address a to the link local all-routers multicast address */
-#define uip_create_linklocal_allrouters_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002)
-
-/**
- * \brief  is addr (a) a solicited node multicast address, see RFC3513
- *  a is of type uip_ipaddr_t*
- */
-#define uip_is_addr_solicited_node(a)           \
-  ((((a)->u8[0]) == 0xFF) &&                     \
-  (((a)->u8[1]) == 0x02) &&                     \
-  (((a)->u16[1]) == 0) &&                       \
-  (((a)->u16[2]) == 0) &&                       \
-  (((a)->u16[3]) == 0) &&                       \
-  (((a)->u16[4]) == 0) &&                       \
-  (((a)->u16[5]) == 1) &&                       \
-  (((a)->u8[12]) == 0xFF))
-
-/**
- * \briefput in b the solicited node address corresponding to address a
- * both a and b are of type uip_ipaddr_t*
- * */
-#define uip_create_solicited_node(a, b)    \
-  (((b)->u8[0]) = 0xFF);                        \
-  (((b)->u8[1]) = 0x02);                        \
-  (((b)->u16[1]) = 0);                          \
-  (((b)->u16[2]) = 0);                          \
-  (((b)->u16[3]) = 0);                          \
-  (((b)->u16[4]) = 0);                          \
-  (((b)->u8[10]) = 0);                          \
-  (((b)->u8[11]) = 0x01);                       \
-  (((b)->u8[12]) = 0xFF);                       \
-  (((b)->u8[13]) = ((a)->u8[13]));              \
-  (((b)->u16[7]) = ((a)->u16[7]))
-
-/**
- * \brief is addr (a) a link local unicast address, see RFC3513
- *  i.e. is (a) on prefix FE80::/10
- *  a is of type uip_ipaddr_t*
- */
-#define uip_is_addr_link_local(a) \
-  ((((a)->u8[0]) == 0xFE) && \
-  (((a)->u8[1]) == 0x80))
-
-/**
- * \brief was addr (a) forged based on the mac address m
- * a type is uip_ipaddr_t
- * m type is uiplladdr_t
- */
-#if UIP_CONF_LL_802154
-#define uip_is_addr_mac_addr_based(a, m) \
-  ((((a)->u8[8])  == (((m)->addr[0]) ^ 0x02)) &&   \
-   (((a)->u8[9])  == (m)->addr[1]) &&            \
-   (((a)->u8[10]) == (m)->addr[2]) &&            \
-   (((a)->u8[11]) == (m)->addr[3]) &&            \
-   (((a)->u8[12]) == (m)->addr[4]) &&            \
-   (((a)->u8[13]) == (m)->addr[5]) &&            \
-   (((a)->u8[14]) == (m)->addr[6]) &&            \
-   (((a)->u8[15]) == (m)->addr[7]))
-#else
-
-#define uip_is_addr_mac_addr_based(a, m) \
-  ((((a)->u8[8])  == (((m)->addr[0]) | 0x02)) &&   \
-   (((a)->u8[9])  == (m)->addr[1]) &&            \
-   (((a)->u8[10]) == (m)->addr[2]) &&            \
-   (((a)->u8[11]) == 0xff) &&            \
-   (((a)->u8[12]) == 0xfe) &&            \
-   (((a)->u8[13]) == (m)->addr[3]) &&            \
-   (((a)->u8[14]) == (m)->addr[4]) &&            \
-   (((a)->u8[15]) == (m)->addr[5]))
-   
-#endif /*UIP_CONF_LL_802154*/
-
-/**
- * \brief is address a multicast address, see RFC 3513
- * a is of type uip_ipaddr_t*
- * */
-#define uip_is_addr_mcast(a)                    \
-  (((a)->u8[0]) == 0xFF)
-
-/**
- * \brief is group-id of multicast address a
- * the all nodes group-id
- */
-#define uip_is_mcast_group_id_all_nodes(a) \
-  ((((a)->u16[1])  == 0) &&                 \
-   (((a)->u16[2])  == 0) &&                 \
-   (((a)->u16[3])  == 0) &&                 \
-   (((a)->u16[4])  == 0) &&                 \
-   (((a)->u16[5])  == 0) &&                 \
-   (((a)->u16[6])  == 0) &&                 \
-   (((a)->u8[14])  == 0) &&                 \
-   (((a)->u8[15])  == 1))
-
-/**
- * \brief is group-id of multicast address a
- * the all routers group-id
- */
-#define uip_is_mcast_group_id_all_routers(a) \
-  ((((a)->u16[1])  == 0) &&                 \
-   (((a)->u16[2])  == 0) &&                 \
-   (((a)->u16[3])  == 0) &&                 \
-   (((a)->u16[4])  == 0) &&                 \
-   (((a)->u16[5])  == 0) &&                 \
-   (((a)->u16[6])  == 0) &&                 \
-   (((a)->u8[14])  == 0) &&                 \
-   (((a)->u8[15])  == 2))
-
-
-#endif /*UIP_CONF_IPV6*/
-
-/**
- * Calculate the Internet checksum over a buffer.
- *
- * The Internet checksum is the one's complement of the one's
- * complement sum of all 16-bit words in the buffer.
- *
- * See RFC1071.
- *
- * \param buf A pointer to the buffer over which the checksum is to be
- * computed.
- *
- * \param len The length of the buffer over which the checksum is to
- * be computed.
- *
- * \return The Internet checksum of the buffer.
- */
-u16_t uip_chksum(u16_t *buf, u16_t len);
-
-/**
- * Calculate the IP header checksum of the packet header in uip_buf.
- *
- * The IP header checksum is the Internet checksum of the 20 bytes of
- * the IP header.
- *
- * \return The IP header checksum of the IP header in the uip_buf
- * buffer.
- */
-u16_t uip_ipchksum(void);
-
-/**
- * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
- *
- * The TCP checksum is the Internet checksum of data contents of the
- * TCP segment, and a pseudo-header as defined in RFC793.
- *
- * \return The TCP checksum of the TCP segment in uip_buf and pointed
- * to by uip_appdata.
- */
-u16_t uip_tcpchksum(void);
-
-/**
- * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
- *
- * The UDP checksum is the Internet checksum of data contents of the
- * UDP segment, and a pseudo-header as defined in RFC768.
- *
- * \return The UDP checksum of the UDP segment in uip_buf and pointed
- * to by uip_appdata.
- */
-u16_t uip_udpchksum(void);
-
-/**
- * Calculate the ICMP checksum of the packet in uip_buf.
- *
- * \return The ICMP checksum of the ICMP packet in uip_buf
- */
-u16_t uip_icmp6chksum(void);
-
-
-#endif /* __UIP_H__ */
-
-
-/** @} */
+\r
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Header file for the uIP TCP/IP stack.\r
+ * \author  Adam Dunkels <adam@dunkels.com>\r
+ * \author  Julien Abeille <jabeille@cisco.com> (IPv6 related code)\r
+ * \author  Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)\r
+ *\r
+ * The uIP TCP/IP stack header file contains definitions for a number\r
+ * of C macros that are used by uIP programs as well as internal uIP\r
+ * structures, TCP/IP header structures and function declarations.\r
+ *\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ *    products derived from this software without specific prior\r
+ *    written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip.h,v 1.24 2009/04/06 13:18:50 nvt-se Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __UIP_H__\r
+#define __UIP_H__\r
+\r
+#include "uipopt.h"\r
+\r
+/**\r
+ * Representation of an IP address.\r
+ *\r
+ */\r
+#if UIP_CONF_IPV6\r
+typedef union uip_ip6addr_t {\r
+  u8_t  u8[16];                        /* Initializer, must come first!!! */\r
+  u16_t u16[8];\r
+} uip_ip6addr_t;\r
+\r
+typedef uip_ip6addr_t uip_ipaddr_t;\r
+#else /* UIP_CONF_IPV6 */\r
+typedef union uip_ip4addr_t {\r
+  u8_t  u8[4];                 /* Initializer, must come first!!! */\r
+  u16_t u16[2];\r
+#if 0\r
+  u32_t u32;\r
+#endif\r
+} uip_ip4addr_t;\r
+typedef uip_ip4addr_t uip_ipaddr_t;\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+\r
+/*---------------------------------------------------------------------------*/\r
+\r
+/** \brief 16 bit 802.15.4 address */\r
+struct uip_802154_shortaddr {\r
+  u8_t addr[2];\r
+};\r
+/** \brief 64 bit 802.15.4 address */\r
+struct uip_802154_longaddr {\r
+  u8_t addr[8];\r
+};\r
+\r
+/** \brief 802.11 address */\r
+struct uip_80211_addr {\r
+  u8_t addr[6];\r
+};\r
+\r
+/** \brief 802.3 address */\r
+struct uip_eth_addr {\r
+  u8_t addr[6];\r
+};\r
+\r
+#if UIP_CONF_LL_802154\r
+/** \brief 802.15.4 address */\r
+typedef struct uip_802154_longaddr uip_lladdr_t;\r
+#define UIP_802154_SHORTADDR_LEN 2\r
+#define UIP_802154_LONGADDR_LEN  8\r
+#define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN\r
+#else /*UIP_CONF_LL_802154*/\r
+#if UIP_CONF_LL_80211\r
+/** \brief 802.11 address */\r
+typedef struct uip_80211_addr uip_lladdr_t;\r
+#define UIP_LLADDR_LEN 6\r
+#else /*UIP_CONF_LL_80211*/\r
+/** \brief Ethernet address */\r
+typedef struct uip_eth_addr uip_lladdr_t;\r
+#define UIP_LLADDR_LEN 6\r
+#endif /*UIP_CONF_LL_80211*/\r
+#endif /*UIP_CONF_LL_802154*/\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* First, the functions that should be called from the\r
+ * system. Initialization, the periodic timer, and incoming packets are\r
+ * handled by the following three functions.\r
+ */\r
+/**\r
+ * \defgroup uipconffunc uIP configuration functions\r
+ * @{\r
+ *\r
+ * The uIP configuration functions are used for setting run-time\r
+ * parameters in uIP such as IP addresses.\r
+ */\r
+\r
+/**\r
+ * Set the IP address of this host.\r
+ *\r
+ * The IP address is represented as a 4-byte array where the first\r
+ * octet of the IP address is put in the first member of the 4-byte\r
+ * array.\r
+ *\r
+ * Example:\r
+ \code\r
+\r
+ uip_ipaddr_t addr;\r
+\r
+ uip_ipaddr(&addr, 192,168,1,2);\r
+ uip_sethostaddr(&addr);\r
\r
+ \endcode\r
+ * \param addr A pointer to an IP address of type uip_ipaddr_t;\r
+ *\r
+ * \sa uip_ipaddr()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))\r
+\r
+/**\r
+ * Get the IP address of this host.\r
+ *\r
+ * The IP address is represented as a 4-byte array where the first\r
+ * octet of the IP address is put in the first member of the 4-byte\r
+ * array.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t hostaddr;\r
+\r
+ uip_gethostaddr(&hostaddr);\r
+ \endcode\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the currently configured IP address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)\r
+\r
+/**\r
+ * Set the default router's IP address.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable containing the IP\r
+ * address of the default router.\r
+ *\r
+ * \sa uip_ipaddr()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))\r
+\r
+/**\r
+ * Set the netmask.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable containing the IP\r
+ * address of the netmask.\r
+ *\r
+ * \sa uip_ipaddr()\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))\r
+\r
+\r
+/**\r
+ * Get the default router's IP address.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the IP address of the default router.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)\r
+\r
+/**\r
+ * Get the netmask.\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the value of the netmask.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \defgroup uipinit uIP initialization functions\r
+ * @{\r
+ *\r
+ * The uIP initialization functions are used for booting uIP.\r
+ */\r
+\r
+/**\r
+ * uIP initialization function.\r
+ *\r
+ * This function should be called at boot up to initilize the uIP\r
+ * TCP/IP stack.\r
+ */\r
+void uip_init(void);\r
+\r
+/**\r
+ * uIP initialization function.\r
+ *\r
+ * This function may be used at boot time to set the initial ip_id.\r
+ */\r
+void uip_setipid(u16_t id);\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \defgroup uipdevfunc uIP device driver functions\r
+ * @{\r
+ *\r
+ * These functions are used by a network device driver for interacting\r
+ * with uIP.\r
+ */\r
+\r
+/**\r
+ * Process an incoming packet.\r
+ *\r
+ * This function should be called when the device driver has received\r
+ * a packet from the network. The packet from the device driver must\r
+ * be present in the uip_buf buffer, and the length of the packet\r
+ * should be placed in the uip_len variable.\r
+ *\r
+ * When the function returns, there may be an outbound packet placed\r
+ * in the uip_buf packet buffer. If so, the uip_len variable is set to\r
+ * the length of the packet. If no packet is to be sent out, the\r
+ * uip_len variable is set to 0.\r
+ *\r
+ * The usual way of calling the function is presented by the source\r
+ * code below.\r
+ \code\r
+ uip_len = devicedriver_poll();\r
+ if(uip_len > 0) {\r
+ uip_input();\r
+ if(uip_len > 0) {\r
+ devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \note If you are writing a uIP device driver that needs ARP\r
+ * (Address Resolution Protocol), e.g., when running uIP over\r
+ * Ethernet, you will need to call the uIP ARP code before calling\r
+ * this function:\r
+ \code\r
+ #define BUF ((struct uip_eth_hdr *)&uip_buf[0])\r
+ uip_len = ethernet_devicedrver_poll();\r
+ if(uip_len > 0) {\r
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {\r
+ uip_arp_ipin();\r
+ uip_input();\r
+ if(uip_len > 0) {\r
+ uip_arp_out();\r
+ ethernet_devicedriver_send();\r
+ }\r
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {\r
+ uip_arp_arpin();\r
+ if(uip_len > 0) {\r
+ ethernet_devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_input()        uip_process(UIP_DATA)\r
+\r
+\r
+/**\r
+ * Periodic processing for a connection identified by its number.\r
+ *\r
+ * This function does the necessary periodic processing (timers,\r
+ * polling) for a uIP TCP conneciton, and should be called when the\r
+ * periodic uIP timer goes off. It should be called for every\r
+ * connection, regardless of whether they are open of closed.\r
+ *\r
+ * When the function returns, it may have an outbound packet waiting\r
+ * for service in the uIP packet buffer, and if so the uip_len\r
+ * variable is set to a value larger than zero. The device driver\r
+ * should be called to send out the packet.\r
+ *\r
+ * The usual way of calling the function is through a for() loop like\r
+ * this:\r
+ \code\r
+ for(i = 0; i < UIP_CONNS; ++i) {\r
+ uip_periodic(i);\r
+ if(uip_len > 0) {\r
+ devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \note If you are writing a uIP device driver that needs ARP\r
+ * (Address Resolution Protocol), e.g., when running uIP over\r
+ * Ethernet, you will need to call the uip_arp_out() function before\r
+ * calling the device driver:\r
+ \code\r
+ for(i = 0; i < UIP_CONNS; ++i) {\r
+ uip_periodic(i);\r
+ if(uip_len > 0) {\r
+ uip_arp_out();\r
+ ethernet_devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \param conn The number of the connection which is to be periodically polled.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#if UIP_TCP\r
+#define uip_periodic(conn) do { uip_conn = &uip_conns[conn];    \\r
+    uip_process(UIP_TIMER); } while (0)\r
+\r
+/**\r
+ *\r
+ *\r
+ */\r
+#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)\r
+\r
+/**\r
+ * Perform periodic processing for a connection identified by a pointer\r
+ * to its structure.\r
+ *\r
+ * Same as uip_periodic() but takes a pointer to the actual uip_conn\r
+ * struct instead of an integer as its argument. This function can be\r
+ * used to force periodic processing of a specific connection.\r
+ *\r
+ * \param conn A pointer to the uip_conn struct for the connection to\r
+ * be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_periodic_conn(conn) do { uip_conn = conn;   \\r
+    uip_process(UIP_TIMER); } while (0)\r
+\r
+/**\r
+ * Request that a particular connection should be polled.\r
+ *\r
+ * Similar to uip_periodic_conn() but does not perform any timer\r
+ * processing. The application is polled for new data.\r
+ *\r
+ * \param conn A pointer to the uip_conn struct for the connection to\r
+ * be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_poll_conn(conn) do { uip_conn = conn;       \\r
+    uip_process(UIP_POLL_REQUEST); } while (0)\r
+\r
+#endif /* UIP_TCP */\r
+\r
+#if UIP_UDP\r
+/**\r
+ * Periodic processing for a UDP connection identified by its number.\r
+ *\r
+ * This function is essentially the same as uip_periodic(), but for\r
+ * UDP connections. It is called in a similar fashion as the\r
+ * uip_periodic() function:\r
+ \code\r
+ for(i = 0; i < UIP_UDP_CONNS; i++) {\r
+ uip_udp_periodic(i);\r
+ if(uip_len > 0) {\r
+ devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \note As for the uip_periodic() function, special care has to be\r
+ * taken when using uIP together with ARP and Ethernet:\r
+ \code\r
+ for(i = 0; i < UIP_UDP_CONNS; i++) {\r
+ uip_udp_periodic(i);\r
+ if(uip_len > 0) {\r
+ uip_arp_out();\r
+ ethernet_devicedriver_send();\r
+ }\r
+ }\r
+ \endcode\r
+ *\r
+ * \param conn The number of the UDP connection to be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \\r
+    uip_process(UIP_UDP_TIMER); } while(0)\r
+\r
+/**\r
+ * Periodic processing for a UDP connection identified by a pointer to\r
+ * its structure.\r
+ *\r
+ * Same as uip_udp_periodic() but takes a pointer to the actual\r
+ * uip_conn struct instead of an integer as its argument. This\r
+ * function can be used to force periodic processing of a specific\r
+ * connection.\r
+ *\r
+ * \param conn A pointer to the uip_udp_conn struct for the connection\r
+ * to be processed.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn;   \\r
+    uip_process(UIP_UDP_TIMER); } while(0)\r
+#endif /* UIP_UDP */\r
+\r
+/** \brief Abandon the reassembly of the current packet */\r
+void uip_reass_over(void);\r
+\r
+/**\r
+ * The uIP packet buffer.\r
+ *\r
+ * The uip_buf array is used to hold incoming and outgoing\r
+ * packets. The device driver should place incoming data into this\r
+ * buffer. When sending data, the device driver should read the link\r
+ * level headers and the TCP/IP headers from this buffer. The size of\r
+ * the link level headers is configured by the UIP_LLH_LEN define.\r
+ *\r
+ * \note The application data need not be placed in this buffer, so\r
+ * the device driver must read it from the place pointed to by the\r
+ * uip_appdata pointer as illustrated by the following example:\r
+ \code\r
+ void\r
+ devicedriver_send(void)\r
+ {\r
+ hwsend(&uip_buf[0], UIP_LLH_LEN);\r
+ if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {\r
+ hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);\r
+ } else {\r
+ hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);\r
+ hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);\r
+ }\r
+ }\r
+ \endcode\r
+*/\r
+extern u8_t uip_buf[UIP_BUFSIZE+2];\r
+\r
+\r
+\r
+/** @} */\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* Functions that are used by the uIP application program. Opening and\r
+ * closing connections, sending and receiving data, etc. is all\r
+ * handled by the functions below.\r
+ */\r
+/**\r
+ * \defgroup uipappfunc uIP application functions\r
+ * @{\r
+ *\r
+ * Functions used by an application running of top of uIP.\r
+ */\r
+\r
+/**\r
+ * Start listening to the specified port.\r
+ *\r
+ * \note Since this function expects the port number in network byte\r
+ * order, a conversion using HTONS() or htons() is necessary.\r
+ *\r
+ \code\r
+ uip_listen(HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param port A 16-bit port number in network byte order.\r
+ */\r
+void uip_listen(u16_t port);\r
+\r
+/**\r
+ * Stop listening to the specified port.\r
+ *\r
+ * \note Since this function expects the port number in network byte\r
+ * order, a conversion using HTONS() or htons() is necessary.\r
+ *\r
+ \code\r
+ uip_unlisten(HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param port A 16-bit port number in network byte order.\r
+ */\r
+void uip_unlisten(u16_t port);\r
+\r
+/**\r
+ * Connect to a remote host using TCP.\r
+ *\r
+ * This function is used to start a new connection to the specified\r
+ * port on the specified host. It allocates a new connection identifier,\r
+ * sets the connection to the SYN_SENT state and sets the\r
+ * retransmission timer to 0. This will cause a TCP SYN segment to be\r
+ * sent out the next time this connection is periodically processed,\r
+ * which usually is done within 0.5 seconds after the call to\r
+ * uip_connect().\r
+ *\r
+ * \note This function is available only if support for active open\r
+ * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.\r
+ *\r
+ * \note Since this function requires the port number to be in network\r
+ * byte order, a conversion using HTONS() or htons() is necessary.\r
+ *\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+\r
+ uip_ipaddr(&ipaddr, 192,168,1,2);\r
+ uip_connect(&ipaddr, HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param ripaddr The IP address of the remote host.\r
+ *\r
+ * \param port A 16-bit port number in network byte order.\r
+ *\r
+ * \return A pointer to the uIP connection identifier for the new connection,\r
+ * or NULL if no connection could be allocated.\r
+ *\r
+ */\r
+struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port);\r
+\r
+\r
+\r
+/**\r
+ * \internal\r
+ *\r
+ * Check if a connection has outstanding (i.e., unacknowledged) data.\r
+ *\r
+ * \param conn A pointer to the uip_conn structure for the connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_outstanding(conn) ((conn)->len)\r
+\r
+/**\r
+ * Send data on the current connection.\r
+ *\r
+ * This function is used to send out a single segment of TCP\r
+ * data. Only applications that have been invoked by uIP for event\r
+ * processing can send data.\r
+ *\r
+ * The amount of data that actually is sent out after a call to this\r
+ * function is determined by the maximum amount of data TCP allows. uIP\r
+ * will automatically crop the data so that only the appropriate\r
+ * amount of data is sent. The function uip_mss() can be used to query\r
+ * uIP for the amount of data that actually will be sent.\r
+ *\r
+ * \note This function does not guarantee that the sent data will\r
+ * arrive at the destination. If the data is lost in the network, the\r
+ * application will be invoked with the uip_rexmit() event being\r
+ * set. The application will then have to resend the data using this\r
+ * function.\r
+ *\r
+ * \param data A pointer to the data which is to be sent.\r
+ *\r
+ * \param len The maximum amount of data bytes to be sent.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+void uip_send(const void *data, int len);\r
+\r
+/**\r
+ * The length of any incoming data that is currently available (if available)\r
+ * in the uip_appdata buffer.\r
+ *\r
+ * The test function uip_data() must first be used to check if there\r
+ * is any data available at all.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+/*void uip_datalen(void);*/\r
+#define uip_datalen()       uip_len\r
+\r
+/**\r
+ * The length of any out-of-band data (urgent data) that has arrived\r
+ * on the connection.\r
+ *\r
+ * \note The configuration parameter UIP_URGDATA must be set for this\r
+ * function to be enabled.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_urgdatalen()    uip_urglen\r
+\r
+/**\r
+ * Close the current connection.\r
+ *\r
+ * This function will close the current connection in a nice way.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_close()         (uip_flags = UIP_CLOSE)\r
+\r
+/**\r
+ * Abort the current connection.\r
+ *\r
+ * This function will abort (reset) the current connection, and is\r
+ * usually used when an error has occurred that prevents using the\r
+ * uip_close() function.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_abort()         (uip_flags = UIP_ABORT)\r
+\r
+/**\r
+ * Tell the sending host to stop sending data.\r
+ *\r
+ * This function will close our receiver's window so that we stop\r
+ * receiving data for the current connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_stop()          (uip_conn->tcpstateflags |= UIP_STOPPED)\r
+\r
+/**\r
+ * Find out if the current connection has been previously stopped with\r
+ * uip_stop().\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_stopped(conn)   ((conn)->tcpstateflags & UIP_STOPPED)\r
+\r
+/**\r
+ * Restart the current connection, if is has previously been stopped\r
+ * with uip_stop().\r
+ *\r
+ * This function will open the receiver's window again so that we\r
+ * start receiving data for the current connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_restart()         do { uip_flags |= UIP_NEWDATA;    \\r
+    uip_conn->tcpstateflags &= ~UIP_STOPPED;                    \\r
+  } while(0)\r
+\r
+\r
+/* uIP tests that can be made to determine in what state the current\r
+   connection is, and what the application function should do. */\r
+\r
+/**\r
+ * Is the current connection a UDP connection?\r
+ *\r
+ * This function checks whether the current connection is a UDP connection.\r
+ *\r
+ * \hideinitializer\r
+ *\r
+ */\r
+#define uip_udpconnection() (uip_conn == NULL)\r
+\r
+/**\r
+ * Is new incoming data available?\r
+ *\r
+ * Will reduce to non-zero if there is new data for the application\r
+ * present at the uip_appdata pointer. The size of the data is\r
+ * available through the uip_len variable.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_newdata()   (uip_flags & UIP_NEWDATA)\r
+\r
+/**\r
+ * Has previously sent data been acknowledged?\r
+ *\r
+ * Will reduce to non-zero if the previously sent data has been\r
+ * acknowledged by the remote host. This means that the application\r
+ * can send new data.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_acked()   (uip_flags & UIP_ACKDATA)\r
+\r
+/**\r
+ * Has the connection just been connected?\r
+ *\r
+ * Reduces to non-zero if the current connection has been connected to\r
+ * a remote host. This will happen both if the connection has been\r
+ * actively opened (with uip_connect()) or passively opened (with\r
+ * uip_listen()).\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_connected() (uip_flags & UIP_CONNECTED)\r
+\r
+/**\r
+ * Has the connection been closed by the other end?\r
+ *\r
+ * Is non-zero if the connection has been closed by the remote\r
+ * host. The application may then do the necessary clean-ups.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_closed()    (uip_flags & UIP_CLOSE)\r
+\r
+/**\r
+ * Has the connection been aborted by the other end?\r
+ *\r
+ * Non-zero if the current connection has been aborted (reset) by the\r
+ * remote host.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_aborted()    (uip_flags & UIP_ABORT)\r
+\r
+/**\r
+ * Has the connection timed out?\r
+ *\r
+ * Non-zero if the current connection has been aborted due to too many\r
+ * retransmissions.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_timedout()    (uip_flags & UIP_TIMEDOUT)\r
+\r
+/**\r
+ * Do we need to retransmit previously data?\r
+ *\r
+ * Reduces to non-zero if the previously sent data has been lost in\r
+ * the network, and the application should retransmit it. The\r
+ * application should send the exact same data as it did the last\r
+ * time, using the uip_send() function.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_rexmit()     (uip_flags & UIP_REXMIT)\r
+\r
+/**\r
+ * Is the connection being polled by uIP?\r
+ *\r
+ * Is non-zero if the reason the application is invoked is that the\r
+ * current connection has been idle for a while and should be\r
+ * polled.\r
+ *\r
+ * The polling event can be used for sending data without having to\r
+ * wait for the remote host to send data.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_poll()       (uip_flags & UIP_POLL)\r
+\r
+/**\r
+ * Get the initial maximum segment size (MSS) of the current\r
+ * connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_initialmss()             (uip_conn->initialmss)\r
+\r
+/**\r
+ * Get the current maximum segment size that can be sent on the current\r
+ * connection.\r
+ *\r
+ * The current maximum segment size that can be sent on the\r
+ * connection is computed from the receiver's window and the MSS of\r
+ * the connection (which also is available by calling\r
+ * uip_initialmss()).\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_mss()             (uip_conn->mss)\r
+\r
+/**\r
+ * Set up a new UDP connection.\r
+ *\r
+ * This function sets up a new UDP connection. The function will\r
+ * automatically allocate an unused local port for the new\r
+ * connection. However, another port can be chosen by using the\r
+ * uip_udp_bind() call, after the uip_udp_new() function has been\r
+ * called.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t addr;\r
+ struct uip_udp_conn *c;\r
\r
+ uip_ipaddr(&addr, 192,168,2,1);\r
+ c = uip_udp_new(&addr, HTONS(12345));\r
+ if(c != NULL) {\r
+ uip_udp_bind(c, HTONS(12344));\r
+ }\r
+ \endcode\r
+ * \param ripaddr The IP address of the remote host.\r
+ *\r
+ * \param rport The remote port number in network byte order.\r
+ *\r
+ * \return The uip_udp_conn structure for the new connection or NULL\r
+ * if no connection could be allocated.\r
+ */\r
+struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport);\r
+\r
+/**\r
+ * Removed a UDP connection.\r
+ *\r
+ * \param conn A pointer to the uip_udp_conn structure for the connection.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_remove(conn) (conn)->lport = 0\r
+\r
+/**\r
+ * Bind a UDP connection to a local port.\r
+ *\r
+ * \param conn A pointer to the uip_udp_conn structure for the\r
+ * connection.\r
+ *\r
+ * \param port The local port number, in network byte order.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_bind(conn, port) (conn)->lport = port\r
+\r
+/**\r
+ * Send a UDP datagram of length len on the current connection.\r
+ *\r
+ * This function can only be called in response to a UDP event (poll\r
+ * or newdata). The data must be present in the uip_buf buffer, at the\r
+ * place pointed to by the uip_appdata pointer.\r
+ *\r
+ * \param len The length of the data in the uip_buf buffer.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_udp_send(len) uip_send((char *)uip_appdata, len)\r
+\r
+/** @} */\r
+\r
+/* uIP convenience and converting functions. */\r
+\r
+/**\r
+ * \defgroup uipconvfunc uIP conversion functions\r
+ * @{\r
+ *\r
+ * These functions can be used for converting between different data\r
+ * formats used by uIP.\r
+ */\r
\r
+/**\r
+ * Convert an IP address to four bytes separated by commas.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));\r
+ \endcode\r
+ *\r
+ * \param a A pointer to a uip_ipaddr_t.\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr_to_quad(a) (a)->u8[0],(a)->u8[1],(a)->u8[2],(a)->u8[3]\r
+\r
+/**\r
+ * Construct an IP address from four bytes.\r
+ *\r
+ * This function constructs an IP address of the type that uIP handles\r
+ * internally from four bytes. The function is handy for specifying IP\r
+ * addresses to use with e.g. the uip_connect() function.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ struct uip_conn *c;\r
\r
+ uip_ipaddr(&ipaddr, 192,168,1,2);\r
+ c = uip_connect(&ipaddr, HTONS(80));\r
+ \endcode\r
+ *\r
+ * \param addr A pointer to a uip_ipaddr_t variable that will be\r
+ * filled in with the IP address.\r
+ *\r
+ * \param addr0 The first octet of the IP address.\r
+ * \param addr1 The second octet of the IP address.\r
+ * \param addr2 The third octet of the IP address.\r
+ * \param addr3 The forth octet of the IP address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do {  \\r
+    (addr)->u8[0] = addr0;                              \\r
+    (addr)->u8[1] = addr1;                              \\r
+    (addr)->u8[2] = addr2;                              \\r
+    (addr)->u8[3] = addr3;                              \\r
+  } while(0)\r
+\r
+/**\r
+ * Construct an IPv6 address from eight 16-bit words.\r
+ *\r
+ * This function constructs an IPv6 address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \\r
+    (addr)->u16[0] = HTONS(addr0);                                      \\r
+    (addr)->u16[1] = HTONS(addr1);                                      \\r
+    (addr)->u16[2] = HTONS(addr2);                                      \\r
+    (addr)->u16[3] = HTONS(addr3);                                      \\r
+    (addr)->u16[4] = HTONS(addr4);                                      \\r
+    (addr)->u16[5] = HTONS(addr5);                                      \\r
+    (addr)->u16[6] = HTONS(addr6);                                      \\r
+    (addr)->u16[7] = HTONS(addr7);                                      \\r
+  } while(0)\r
+\r
+/**\r
+ * Construct an IPv6 address from eight 8-bit words.\r
+ *\r
+ * This function constructs an IPv6 address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ip6addr_u8(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7,addr8,addr9,addr10,addr11,addr12,addr13,addr14,addr15) do { \\r
+    (addr)->u8[0] = addr0;                                       \\r
+    (addr)->u8[1] = addr1;                                       \\r
+    (addr)->u8[2] = addr2;                                       \\r
+    (addr)->u8[3] = addr3;                                       \\r
+    (addr)->u8[4] = addr4;                                       \\r
+    (addr)->u8[5] = addr5;                                       \\r
+    (addr)->u8[6] = addr6;                                       \\r
+    (addr)->u8[7] = addr7;                                       \\r
+    (addr)->u8[8] = addr8;                                       \\r
+    (addr)->u8[9] = addr9;                                       \\r
+    (addr)->u8[10] = addr10;                                     \\r
+    (addr)->u8[11] = addr11;                                     \\r
+    (addr)->u8[12] = addr12;                                     \\r
+    (addr)->u8[13] = addr13;                                     \\r
+    (addr)->u8[14] = addr14;                                     \\r
+    (addr)->u8[15] = addr15;                                     \\r
+  } while(0)\r
+\r
+\r
+/**\r
+ * Copy an IP address to another IP address.\r
+ *\r
+ * Copies an IP address from one place to another.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2;\r
+\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ uip_ipaddr_copy(&ipaddr2, &ipaddr1);\r
+ \endcode\r
+ *\r
+ * \param dest The destination for the copy.\r
+ * \param src The source from where to copy.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef uip_ipaddr_copy\r
+#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))\r
+#endif\r
+\r
+/**\r
+ * Compare two IP addresses\r
+ *\r
+ * Compares two IP addresses.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2;\r
+\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {\r
+ printf("They are the same");\r
+ }\r
+ \endcode\r
+ *\r
+ * \param addr1 The first IP address.\r
+ * \param addr2 The second IP address.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#if !UIP_CONF_IPV6\r
+#define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \\r
+                                     (addr1)->u16[1] == (addr2)->u16[1])\r
+#else /* !UIP_CONF_IPV6 */\r
+#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)\r
+#endif /* !UIP_CONF_IPV6 */\r
+\r
+/**\r
+ * Compare two IP addresses with netmasks\r
+ *\r
+ * Compares two IP addresses with netmasks. The masks are used to mask\r
+ * out the bits that are to be compared.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2, mask;\r
+\r
+ uip_ipaddr(&mask, 255,255,255,0);\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ uip_ipaddr(&ipaddr2, 192,16,1,3);\r
+ if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {\r
+ printf("They are the same");\r
+ }\r
+ \endcode\r
+ *\r
+ * \param addr1 The first IP address.\r
+ * \param addr2 The second IP address.\r
+ * \param mask The netmask.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#if !UIP_CONF_IPV6\r
+#define uip_ipaddr_maskcmp(addr1, addr2, mask)          \\r
+  (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) ==       \\r
+    (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) &&      \\r
+   ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) ==       \\r
+    (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))\r
+#else\r
+#define uip_ipaddr_prefixcmp(addr1, addr2, length) (memcmp(addr1, addr2, length>>3) == 0)\r
+#endif\r
+\r
+\r
+/**\r
+ * Check if an address is a broadcast address for a network.\r
+ *\r
+ * Checks if an address is the broadcast address for a network. The\r
+ * network is defined by an IP address that is on the network and the\r
+ * network's netmask.\r
+ *\r
+ * \param addr The IP address.\r
+ * \param netaddr The network's IP address.\r
+ * \param netmask The network's netmask.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+/*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)\r
+  ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/\r
+\r
+\r
+\r
+/**\r
+ * Mask out the network part of an IP address.\r
+ *\r
+ * Masks out the network part of an IP address, given the address and\r
+ * the netmask.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr1, ipaddr2, netmask;\r
+\r
+ uip_ipaddr(&ipaddr1, 192,16,1,2);\r
+ uip_ipaddr(&netmask, 255,255,255,0);\r
+ uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "ipaddr2" will contain the IP\r
+ * address 192.168.1.0.\r
+ *\r
+ * \param dest Where the result is to be placed.\r
+ * \param src The IP address.\r
+ * \param mask The netmask.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr_mask(dest, src, mask) do {                           \\r
+    ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0];        \\r
+    ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1];        \\r
+  } while(0)\r
+\r
+/**\r
+ * Pick the first octet of an IP address.\r
+ *\r
+ * Picks out the first octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr1(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 1.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr1(addr) ((addr)->u8[0])\r
+\r
+/**\r
+ * Pick the second octet of an IP address.\r
+ *\r
+ * Picks out the second octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr2(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 2.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr2(addr) ((addr)->u8[1])\r
+\r
+/**\r
+ * Pick the third octet of an IP address.\r
+ *\r
+ * Picks out the third octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr3(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 3.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr3(addr) ((addr)->u8[2])\r
+\r
+/**\r
+ * Pick the fourth octet of an IP address.\r
+ *\r
+ * Picks out the fourth octet of an IP address.\r
+ *\r
+ * Example:\r
+ \code\r
+ uip_ipaddr_t ipaddr;\r
+ u8_t octet;\r
+\r
+ uip_ipaddr(&ipaddr, 1,2,3,4);\r
+ octet = uip_ipaddr4(&ipaddr);\r
+ \endcode\r
+ *\r
+ * In the example above, the variable "octet" will contain the value 4.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_ipaddr4(addr) ((addr)->u8[3])\r
+\r
+/**\r
+ * Convert 16-bit quantity from host byte order to network byte order.\r
+ *\r
+ * This macro is primarily used for converting constants from host\r
+ * byte order to network byte order. For converting variables to\r
+ * network byte order, use the htons() function instead.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef HTONS\r
+#   if UIP_BYTE_ORDER == UIP_BIG_ENDIAN\r
+#      define HTONS(n) (n)\r
+#      define HTONL(n) (n)\r
+#   else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */\r
+#      define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))\r
+#      define HTONL(n) (((u32_t)HTONS(n) << 16) | HTONS((u32_t)(n) >> 16))\r
+#   endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */\r
+#else\r
+#error "HTONS already defined!"\r
+#endif /* HTONS */\r
+\r
+/**\r
+ * Convert 16-bit quantity from host byte order to network byte order.\r
+ *\r
+ * This function is primarily used for converting variables from host\r
+ * byte order to network byte order. For converting constants to\r
+ * network byte order, use the HTONS() macro instead.\r
+ */\r
+#ifndef htons\r
+u16_t htons(u16_t val);\r
+#endif /* htons */\r
+#ifndef ntohs\r
+#define ntohs htons\r
+#endif\r
+\r
+#ifndef htonl\r
+u32_t htonl(u32_t val);\r
+#endif /* htonl */\r
+#ifndef ntohl\r
+#define ntohl htonl\r
+#endif\r
+\r
+/** @} */\r
+\r
+/**\r
+ * Pointer to the application data in the packet buffer.\r
+ *\r
+ * This pointer points to the application data when the application is\r
+ * called. If the application wishes to send data, the application may\r
+ * use this space to write the data into before calling uip_send().\r
+ */\r
+extern void *uip_appdata;\r
+\r
+#if UIP_URGDATA > 0\r
+/* u8_t *uip_urgdata:\r
+ *\r
+ * This pointer points to any urgent data that has been received. Only\r
+ * present if compiled with support for urgent data (UIP_URGDATA).\r
+ */\r
+extern void *uip_urgdata;\r
+#endif /* UIP_URGDATA > 0 */\r
+\r
+\r
+/**\r
+ * \defgroup uipdrivervars Variables used in uIP device drivers\r
+ * @{\r
+ *\r
+ * uIP has a few global variables that are used in device drivers for\r
+ * uIP.\r
+ */\r
+\r
+/**\r
+ * The length of the packet in the uip_buf buffer.\r
+ *\r
+ * The global variable uip_len holds the length of the packet in the\r
+ * uip_buf buffer.\r
+ *\r
+ * When the network device driver calls the uIP input function,\r
+ * uip_len should be set to the length of the packet in the uip_buf\r
+ * buffer.\r
+ *\r
+ * When sending packets, the device driver should use the contents of\r
+ * the uip_len variable to determine the length of the outgoing\r
+ * packet.\r
+ *\r
+ */\r
+extern u16_t uip_len;\r
+\r
+/**\r
+ * The length of the extension headers\r
+ */\r
+extern u8_t uip_ext_len;\r
+/** @} */\r
+\r
+#if UIP_URGDATA > 0\r
+extern u16_t uip_urglen, uip_surglen;\r
+#endif /* UIP_URGDATA > 0 */\r
+\r
+\r
+/**\r
+ * Representation of a uIP TCP connection.\r
+ *\r
+ * The uip_conn structure is used for identifying a connection. All\r
+ * but one field in the structure are to be considered read-only by an\r
+ * application. The only exception is the appstate field whose purpose\r
+ * is to let the application store application-specific state (e.g.,\r
+ * file pointers) for the connection. The type of this field is\r
+ * configured in the "uipopt.h" header file.\r
+ */\r
+struct uip_conn {\r
+  uip_ipaddr_t ripaddr;   /**< The IP address of the remote host. */\r
+  \r
+  u16_t lport;        /**< The local TCP port, in network byte order. */\r
+  u16_t rport;        /**< The local remote TCP port, in network byte\r
+                        order. */\r
+  \r
+  u8_t rcv_nxt[4];    /**< The sequence number that we expect to\r
+                        receive next. */\r
+  u8_t snd_nxt[4];    /**< The sequence number that was last sent by\r
+                         us. */\r
+  u16_t len;          /**< Length of the data that was previously sent. */\r
+  u16_t mss;          /**< Current maximum segment size for the\r
+                        connection. */\r
+  u16_t initialmss;   /**< Initial maximum segment size for the\r
+                        connection. */\r
+  u8_t sa;            /**< Retransmission time-out calculation state\r
+                        variable. */\r
+  u8_t sv;            /**< Retransmission time-out calculation state\r
+                        variable. */\r
+  u8_t rto;           /**< Retransmission time-out. */\r
+  u8_t tcpstateflags; /**< TCP state and flags. */\r
+  u8_t timer;         /**< The retransmission timer. */\r
+  u8_t nrtx;          /**< The number of retransmissions for the last\r
+                        segment sent. */\r
+\r
+  /** The application state. */\r
+  uip_tcp_appstate_t appstate;\r
+};\r
+\r
+\r
+/**\r
+ * Pointer to the current TCP connection.\r
+ *\r
+ * The uip_conn pointer can be used to access the current TCP\r
+ * connection.\r
+ */\r
+\r
+extern struct uip_conn *uip_conn;\r
+#if UIP_TCP\r
+/* The array containing all uIP connections. */\r
+extern struct uip_conn uip_conns[UIP_CONNS];\r
+#endif\r
+\r
+/**\r
+ * \addtogroup uiparch\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * 4-byte array used for the 32-bit sequence number calculations.\r
+ */\r
+extern u8_t uip_acc32[4];\r
+/** @} */\r
+\r
+/**\r
+ * Representation of a uIP UDP connection.\r
+ */\r
+struct uip_udp_conn {\r
+  uip_ipaddr_t ripaddr;   /**< The IP address of the remote peer. */\r
+  u16_t lport;        /**< The local port number in network byte order. */\r
+  u16_t rport;        /**< The remote port number in network byte order. */\r
+  u8_t  ttl;          /**< Default time-to-live. */\r
+\r
+  /** The application state. */\r
+  uip_udp_appstate_t appstate;\r
+};\r
+\r
+/**\r
+ * The current UDP connection.\r
+ */\r
+extern struct uip_udp_conn *uip_udp_conn;\r
+extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];\r
+\r
+struct uip_router {\r
+  int (*activate)(void);\r
+  int (*deactivate)(void);\r
+  uip_ipaddr_t *(*lookup)(uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop);\r
+};\r
+\r
+#if UIP_CONF_ROUTER\r
+extern const struct uip_router *uip_router;\r
+\r
+/**\r
+ * uIP routing driver registration function.\r
+ */\r
+void uip_router_register(const struct uip_router *router);\r
+#endif /*UIP_CONF_ROUTER*/\r
+\r
+#if UIP_CONF_ICMP6\r
+struct uip_icmp6_conn {\r
+  uip_icmp6_appstate_t appstate;\r
+};\r
+extern struct uip_icmp6_conn uip_icmp6_conns;\r
+#endif /*UIP_CONF_ICMP6*/\r
+\r
+/**\r
+ * The uIP TCP/IP statistics.\r
+ *\r
+ * This is the variable in which the uIP TCP/IP statistics are gathered.\r
+ */\r
+#if UIP_STATISTICS == 1\r
+extern struct uip_stats uip_stat;\r
+#define UIP_STAT(s) s\r
+#else\r
+#define UIP_STAT(s)\r
+#endif /* UIP_STATISTICS == 1 */\r
+\r
+/**\r
+ * The structure holding the TCP/IP statistics that are gathered if\r
+ * UIP_STATISTICS is set to 1.\r
+ *\r
+ */\r
+struct uip_stats {\r
+  struct {\r
+    uip_stats_t recv;     /**< Number of received packets at the IP\r
+                            layer. */\r
+    uip_stats_t sent;     /**< Number of sent packets at the IP\r
+                            layer. */\r
+    uip_stats_t forwarded;/**< Number of forwarded packets at the IP \r
+                            layer. */\r
+    uip_stats_t drop;     /**< Number of dropped packets at the IP\r
+                            layer. */\r
+    uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong\r
+                            IP version or header length. */\r
+    uip_stats_t hblenerr; /**< Number of packets dropped due to wrong\r
+                            IP length, high byte. */\r
+    uip_stats_t lblenerr; /**< Number of packets dropped due to wrong\r
+                            IP length, low byte. */\r
+    uip_stats_t fragerr;  /**< Number of packets dropped since they\r
+                            were IP fragments. */\r
+    uip_stats_t chkerr;   /**< Number of packets dropped due to IP\r
+                            checksum errors. */\r
+    uip_stats_t protoerr; /**< Number of packets dropped since they\r
+                            were neither ICMP, UDP nor TCP. */\r
+  } ip;                   /**< IP statistics. */\r
+  struct {\r
+    uip_stats_t recv;     /**< Number of received ICMP packets. */\r
+    uip_stats_t sent;     /**< Number of sent ICMP packets. */\r
+    uip_stats_t drop;     /**< Number of dropped ICMP packets. */\r
+    uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong\r
+                            type. */\r
+    uip_stats_t chkerr;   /**< Number of ICMP packets with a bad\r
+                            checksum. */\r
+  } icmp;                 /**< ICMP statistics. */\r
+#if UIP_TCP\r
+  struct {\r
+    uip_stats_t recv;     /**< Number of recived TCP segments. */\r
+    uip_stats_t sent;     /**< Number of sent TCP segments. */\r
+    uip_stats_t drop;     /**< Number of dropped TCP segments. */\r
+    uip_stats_t chkerr;   /**< Number of TCP segments with a bad\r
+                            checksum. */\r
+    uip_stats_t ackerr;   /**< Number of TCP segments with a bad ACK\r
+                            number. */\r
+    uip_stats_t rst;      /**< Number of recevied TCP RST (reset) segments. */\r
+    uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */\r
+    uip_stats_t syndrop;  /**< Number of dropped SYNs due to too few\r
+                            connections was avaliable. */\r
+    uip_stats_t synrst;   /**< Number of SYNs for closed ports,\r
+                            triggering a RST. */\r
+  } tcp;                  /**< TCP statistics. */\r
+#endif\r
+#if UIP_UDP\r
+  struct {\r
+    uip_stats_t drop;     /**< Number of dropped UDP segments. */\r
+    uip_stats_t recv;     /**< Number of recived UDP segments. */\r
+    uip_stats_t sent;     /**< Number of sent UDP segments. */\r
+    uip_stats_t chkerr;   /**< Number of UDP segments with a bad\r
+                            checksum. */\r
+  } udp;                  /**< UDP statistics. */\r
+#endif /* UIP_UDP */\r
+#if UIP_CONF_IPV6\r
+  struct {\r
+    uip_stats_t drop;     /**< Number of dropped ND6 packets. */\r
+    uip_stats_t recv;     /**< Number of recived ND6 packets */\r
+    uip_stats_t sent;     /**< Number of sent ND6 packets */\r
+  } nd6;\r
+#endif /*UIP_CONF_IPV6*/\r
+};\r
+\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* All the stuff below this point is internal to uIP and should not be\r
+ * used directly by an application or by a device driver.\r
+ */\r
+/*---------------------------------------------------------------------------*/\r
+\r
+\r
+\r
+/* u8_t uip_flags:\r
+ *\r
+ * When the application is called, uip_flags will contain the flags\r
+ * that are defined in this file. Please read below for more\r
+ * information.\r
+ */\r
+extern u8_t uip_flags;\r
+\r
+/* The following flags may be set in the global variable uip_flags\r
+   before calling the application callback. The UIP_ACKDATA,\r
+   UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,\r
+   whereas the others are mutually exclusive. Note that these flags\r
+   should *NOT* be accessed directly, but only through the uIP\r
+   functions/macros. */\r
+\r
+#define UIP_ACKDATA   1     /* Signifies that the outstanding data was\r
+                              acked and the application should send\r
+                              out new data instead of retransmitting\r
+                              the last data. */\r
+#define UIP_NEWDATA   2     /* Flags the fact that the peer has sent\r
+                              us new data. */\r
+#define UIP_REXMIT    4     /* Tells the application to retransmit the\r
+                              data that was last sent. */\r
+#define UIP_POLL      8     /* Used for polling the application, to\r
+                              check if the application has data that\r
+                              it wants to send. */\r
+#define UIP_CLOSE     16    /* The remote host has closed the\r
+                              connection, thus the connection has\r
+                              gone away. Or the application signals\r
+                              that it wants to close the\r
+                              connection. */\r
+#define UIP_ABORT     32    /* The remote host has aborted the\r
+                              connection, thus the connection has\r
+                              gone away. Or the application signals\r
+                              that it wants to abort the\r
+                              connection. */\r
+#define UIP_CONNECTED 64    /* We have got a connection from a remote\r
+                               host and have set up a new connection\r
+                               for it, or an active connection has\r
+                               been successfully established. */\r
+\r
+#define UIP_TIMEDOUT  128   /* The connection has been aborted due to\r
+                              too many retransmissions. */\r
+\r
+\r
+/**\r
+ * \brief process the options within a hop by hop or destination option header\r
+ * \retval 0: nothing to send,\r
+ * \retval 1: drop pkt\r
+ * \retval 2: ICMP error message to send\r
+*/\r
+/*static u8_t\r
+uip_ext_hdr_options_process(); */\r
+\r
+/* uip_process(flag):\r
+ *\r
+ * The actual uIP function which does all the work.\r
+ */\r
+void uip_process(u8_t flag);\r
+  \r
+  /* The following flags are passed as an argument to the uip_process()\r
+   function. They are used to distinguish between the two cases where\r
+   uip_process() is called. It can be called either because we have\r
+   incoming data that should be processed, or because the periodic\r
+   timer has fired. These values are never used directly, but only in\r
+   the macros defined in this file. */\r
\r
+#define UIP_DATA          1     /* Tells uIP that there is incoming\r
+                                  data in the uip_buf buffer. The\r
+                                  length of the data is stored in the\r
+                                  global variable uip_len. */\r
+#define UIP_TIMER         2     /* Tells uIP that the periodic timer\r
+                                  has fired. */\r
+#define UIP_POLL_REQUEST  3     /* Tells uIP that a connection should\r
+                                  be polled. */\r
+#define UIP_UDP_SEND_CONN 4     /* Tells uIP that a UDP datagram\r
+                                  should be constructed in the\r
+                                  uip_buf buffer. */\r
+#if UIP_UDP\r
+#define UIP_UDP_TIMER     5\r
+#endif /* UIP_UDP */\r
+\r
+/* The TCP states used in the uip_conn->tcpstateflags. */\r
+#define UIP_CLOSED      0\r
+#define UIP_SYN_RCVD    1\r
+#define UIP_SYN_SENT    2\r
+#define UIP_ESTABLISHED 3\r
+#define UIP_FIN_WAIT_1  4\r
+#define UIP_FIN_WAIT_2  5\r
+#define UIP_CLOSING     6\r
+#define UIP_TIME_WAIT   7\r
+#define UIP_LAST_ACK    8\r
+#define UIP_TS_MASK     15\r
+  \r
+#define UIP_STOPPED      16\r
+\r
+/* The TCP and IP headers. */\r
+struct uip_tcpip_hdr {\r
+#if UIP_CONF_IPV6\r
+  /* IPv6 header. */\r
+  u8_t vtc,\r
+    tcflow;\r
+  u16_t flow;\r
+  u8_t len[2];\r
+  u8_t proto, ttl;\r
+  uip_ip6addr_t srcipaddr, destipaddr;\r
+#else /* UIP_CONF_IPV6 */\r
+  /* IPv4 header. */\r
+  u8_t vhl,\r
+    tos,\r
+    len[2],\r
+    ipid[2],\r
+    ipoffset[2],\r
+    ttl,\r
+    proto;\r
+  u16_t ipchksum;\r
+  uip_ipaddr_t srcipaddr, destipaddr;\r
+#endif /* UIP_CONF_IPV6 */\r
+  \r
+  /* TCP header. */\r
+  u16_t srcport,\r
+    destport;\r
+  u8_t seqno[4],\r
+    ackno[4],\r
+    tcpoffset,\r
+    flags,\r
+    wnd[2];\r
+  u16_t tcpchksum;\r
+  u8_t urgp[2];\r
+  u8_t optdata[4];\r
+};\r
+\r
+/* The ICMP and IP headers. */\r
+struct uip_icmpip_hdr {\r
+#if UIP_CONF_IPV6\r
+  /* IPv6 header. */\r
+  u8_t vtc,\r
+    tcf;\r
+  u16_t flow;\r
+  u8_t len[2];\r
+  u8_t proto, ttl;\r
+  uip_ip6addr_t srcipaddr, destipaddr;\r
+#else /* UIP_CONF_IPV6 */\r
+  /* IPv4 header. */\r
+  u8_t vhl,\r
+    tos,\r
+    len[2],\r
+    ipid[2],\r
+    ipoffset[2],\r
+    ttl,\r
+    proto;\r
+  u16_t ipchksum;\r
+  uip_ipaddr_t srcipaddr, destipaddr;\r
+#endif /* UIP_CONF_IPV6 */\r
+  \r
+  /* ICMP header. */\r
+  u8_t type, icode;\r
+  u16_t icmpchksum;\r
+#if !UIP_CONF_IPV6\r
+  u16_t id, seqno;\r
+  u8_t payload[1];\r
+#endif /* !UIP_CONF_IPV6 */\r
+};\r
+\r
+\r
+/* The UDP and IP headers. */\r
+struct uip_udpip_hdr {\r
+#if UIP_CONF_IPV6\r
+  /* IPv6 header. */\r
+  u8_t vtc,\r
+    tcf;\r
+  u16_t flow;\r
+  u8_t len[2];\r
+  u8_t proto, ttl;\r
+  uip_ip6addr_t srcipaddr, destipaddr;\r
+#else /* UIP_CONF_IPV6 */\r
+  /* IP header. */\r
+  u8_t vhl,\r
+    tos,\r
+    len[2],\r
+    ipid[2],\r
+    ipoffset[2],\r
+    ttl,\r
+    proto;\r
+  u16_t ipchksum;\r
+  uip_ipaddr_t srcipaddr, destipaddr;\r
+#endif /* UIP_CONF_IPV6 */\r
+  \r
+  /* UDP header. */\r
+  u16_t srcport,\r
+    destport;\r
+  u16_t udplen;\r
+  u16_t udpchksum;\r
+};\r
+\r
+/*\r
+ * In IPv6 the length of the L3 headers before the transport header is\r
+ * not fixed, due to the possibility to include extension option headers\r
+ * after the IP header. hence we split here L3 and L4 headers\r
+ */\r
+/* The IP header */\r
+struct uip_ip_hdr {\r
+#if UIP_CONF_IPV6\r
+  /* IPV6 header */\r
+  u8_t vtc;\r
+  u8_t tcflow;\r
+  u16_t flow;\r
+  u8_t len[2];\r
+  u8_t proto, ttl;\r
+  uip_ip6addr_t srcipaddr, destipaddr;\r
+#else /* UIP_CONF_IPV6 */\r
+  /* IPV4 header */\r
+  u8_t vhl,\r
+    tos,\r
+    len[2],\r
+    ipid[2],\r
+    ipoffset[2],\r
+    ttl,\r
+    proto;\r
+  u16_t ipchksum;\r
+  uip_ipaddr_t srcipaddr, destipaddr;\r
+#endif /* UIP_CONF_IPV6 */\r
+};\r
+\r
+\r
+/*\r
+ * IPv6 extension option headers: we are able to process\r
+ * the 4 extension headers defined in RFC2460 (IPv6):\r
+ * - Hop by hop option header, destination option header:\r
+ *   These two are not used by any core IPv6 protocol, hence\r
+ *   we just read them and go to the next. They convey options,\r
+ *   the options defined in RFC2460 are Pad1 and PadN, which do\r
+ *   some padding, and that we do not need to read (the length\r
+ *   field in the header is enough)\r
+ * - Routing header: this one is most notably used by MIPv6,\r
+ *   which we do not implement, hence we just read it and go\r
+ *   to the next\r
+ * - Fragmentation header: we read this header and are able to\r
+ *   reassemble packets\r
+ *\r
+ * We do not offer any means to send packets with extension headers\r
+ *\r
+ * We do not implement Authentication and ESP headers, which are\r
+ * used in IPSec and defined in RFC4302,4303,4305,4385\r
+ */\r
+/* common header part */\r
+struct uip_ext_hdr {\r
+  u8_t next;\r
+  u8_t len;\r
+};\r
+\r
+/* Hop by Hop option header */\r
+struct uip_hbho_hdr {\r
+  u8_t next;\r
+  u8_t len;\r
+};\r
+\r
+/* destination option header */\r
+struct uip_desto_hdr {\r
+  u8_t next;\r
+  u8_t len;\r
+};\r
+\r
+/* We do not define structures for PAD1 and PADN options */\r
+\r
+/*\r
+ * routing header\r
+ * the routing header as 4 common bytes, then routing header type\r
+ * specific data there are several types of routing header. Type 0 was\r
+ * deprecated as per RFC5095 most notable other type is 2, used in\r
+ * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to\r
+ * parse the 4 first bytes\r
+ */\r
+struct uip_routing_hdr {\r
+  u8_t next;\r
+  u8_t len;\r
+  u8_t routing_type;\r
+  u8_t seg_left;\r
+};\r
+\r
+/* fragmentation header */\r
+struct uip_frag_hdr {\r
+  u8_t next;\r
+  u8_t res;\r
+  u16_t offsetresmore;\r
+  u32_t id;\r
+};\r
+\r
+/*\r
+ * an option within the destination or hop by hop option headers\r
+ * it contains type an length, which is true for all options but PAD1\r
+ */\r
+struct uip_ext_hdr_opt {\r
+  u8_t type;\r
+  u8_t len;\r
+};\r
+\r
+/* PADN option */\r
+struct uip_ext_hdr_opt_padn {\r
+  u8_t opt_type;\r
+  u8_t opt_len;\r
+};\r
+\r
+/* TCP header */\r
+struct uip_tcp_hdr {\r
+  u16_t srcport;\r
+  u16_t destport;\r
+  u8_t seqno[4];\r
+  u8_t ackno[4];\r
+  u8_t tcpoffset;\r
+  u8_t flags;\r
+  u8_t  wnd[2];\r
+  u16_t tcpchksum;\r
+  u8_t urgp[2];\r
+  u8_t optdata[4];\r
+};\r
+\r
+/* The ICMP headers. */\r
+struct uip_icmp_hdr {\r
+  u8_t type, icode;\r
+  u16_t icmpchksum;\r
+#if !UIP_CONF_IPV6\r
+  u16_t id, seqno;\r
+#endif /* !UIP_CONF_IPV6 */\r
+};\r
+\r
+\r
+/* The UDP headers. */\r
+struct uip_udp_hdr {\r
+  u16_t srcport;\r
+  u16_t destport;\r
+  u16_t udplen;\r
+  u16_t udpchksum;\r
+};\r
+\r
+\r
+/**\r
+ * The buffer size available for user data in the \ref uip_buf buffer.\r
+ *\r
+ * This macro holds the available size for user data in the \ref\r
+ * uip_buf buffer. The macro is intended to be used for checking\r
+ * bounds of available user data.\r
+ *\r
+ * Example:\r
+ \code\r
+ snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);\r
+ \endcode\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)\r
+#define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]\r
+\r
+#define UIP_PROTO_ICMP  1\r
+#define UIP_PROTO_TCP   6\r
+#define UIP_PROTO_UDP   17\r
+#define UIP_PROTO_ICMP6 58\r
+\r
+\r
+#if UIP_CONF_IPV6\r
+/** @{ */\r
+/** \brief  extension headers types */\r
+#define UIP_PROTO_HBHO        0\r
+#define UIP_PROTO_DESTO       60\r
+#define UIP_PROTO_ROUTING     43\r
+#define UIP_PROTO_FRAG        44\r
+#define UIP_PROTO_NONE        59\r
+/** @} */\r
+\r
+/** @{ */\r
+/** \brief  Destination and Hop By Hop extension headers option types */\r
+#define UIP_EXT_HDR_OPT_PAD1  0\r
+#define UIP_EXT_HDR_OPT_PADN  1\r
+/** @} */\r
+\r
+/** @{ */\r
+/**\r
+ * \brief Bitmaps for extension header processing\r
+ *\r
+ * When processing extension headers, we should record somehow which one we\r
+ * see, because you cannot have twice the same header, except for destination\r
+ * We store all this in one u8_t bitmap one bit for each header expected. The\r
+ * order in the bitmap is the order recommended in RFC2460\r
+ */\r
+#define UIP_EXT_HDR_BITMAP_HBHO 0x01\r
+#define UIP_EXT_HDR_BITMAP_DESTO1 0x02\r
+#define UIP_EXT_HDR_BITMAP_ROUTING 0x04\r
+#define UIP_EXT_HDR_BITMAP_FRAG 0x08\r
+#define UIP_EXT_HDR_BITMAP_AH 0x10\r
+#define UIP_EXT_HDR_BITMAP_ESP 0x20\r
+#define UIP_EXT_HDR_BITMAP_DESTO2 0x40\r
+/** @} */\r
+\r
+\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+\r
+/* Header sizes. */\r
+#if UIP_CONF_IPV6\r
+#define UIP_IPH_LEN    40\r
+#define UIP_FRAGH_LEN  8\r
+#else /* UIP_CONF_IPV6 */\r
+#define UIP_IPH_LEN    20    /* Size of IP header */\r
+#endif /* UIP_CONF_IPV6 */\r
+\r
+#define UIP_UDPH_LEN    8    /* Size of UDP header */\r
+#define UIP_TCPH_LEN   20    /* Size of TCP header */\r
+#ifdef UIP_IPH_LEN\r
+#define UIP_ICMPH_LEN   4    /* Size of ICMP header */\r
+#endif\r
+#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN)    /* Size of IP +\r
+                        * UDP\r
+                                                          * header */\r
+#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN)    /* Size of IP +\r
+                                                          * TCP\r
+                                                          * header */\r
+#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN\r
+#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP\r
+                                                         + IP header */\r
+#define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN)    /* size of L2\r
+                                                        + IP header */\r
+#if UIP_CONF_IPV6\r
+/**\r
+ * The sums below are quite used in ND. When used for uip_buf, we\r
+ * include link layer length when used for uip_len, we do not, hence\r
+ * we need values with and without LLH_LEN we do not use capital\r
+ * letters as these values are variable\r
+ */\r
+#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)\r
+#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)\r
+#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)\r
+#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)\r
+#endif /*UIP_CONF_IPV6*/\r
+\r
+\r
+#if UIP_FIXEDADDR\r
+extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;\r
+#else /* UIP_FIXEDADDR */\r
+extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;\r
+#endif /* UIP_FIXEDADDR */\r
+extern const uip_ipaddr_t uip_broadcast_addr;\r
+extern const uip_ipaddr_t uip_all_zeroes_addr;\r
+\r
+#if UIP_FIXEDETHADDR\r
+extern const uip_lladdr_t uip_lladdr;\r
+#else\r
+extern uip_lladdr_t uip_lladdr;\r
+#endif\r
+\r
+\r
+\r
+\r
+#ifdef UIP_CONF_IPV6\r
+/**\r
+ * \brief Is IPv6 address a the unspecified address\r
+ * a is of type uip_ipaddr_t\r
+ */\r
+#define uip_is_addr_unspecified(a)               \\r
+  ((((a)->u16[0]) == 0) &&                       \\r
+   (((a)->u16[1]) == 0) &&                       \\r
+   (((a)->u16[2]) == 0) &&                       \\r
+   (((a)->u16[3]) == 0) &&                       \\r
+   (((a)->u16[4]) == 0) &&                       \\r
+   (((a)->u16[5]) == 0) &&                       \\r
+   (((a)->u16[6]) == 0) &&                       \\r
+   (((a)->u16[7]) == 0))\r
+\r
+/** \brief Is IPv6 address a the link local all-nodes multicast address */\r
+#define uip_is_addr_linklocal_allnodes_mcast(a)     \\r
+  ((((a)->u8[0]) == 0xff) &&                        \\r
+   (((a)->u8[1]) == 0x02) &&                        \\r
+   (((a)->u16[1]) == 0) &&                          \\r
+   (((a)->u16[2]) == 0) &&                          \\r
+   (((a)->u16[3]) == 0) &&                          \\r
+   (((a)->u16[4]) == 0) &&                          \\r
+   (((a)->u16[5]) == 0) &&                          \\r
+   (((a)->u16[6]) == 0) &&                          \\r
+   (((a)->u8[14]) == 0) &&                          \\r
+   (((a)->u8[15]) == 0x01))\r
+\r
+/** \brief set IP address a to unspecified */\r
+#define uip_create_unspecified(a) uip_ip6addr(a, 0, 0, 0, 0, 0, 0, 0, 0)\r
+\r
+/** \brief set IP address a to the link local all-nodes multicast address */\r
+#define uip_create_linklocal_allnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001)\r
+\r
+/** \brief set IP address a to the link local all-routers multicast address */\r
+#define uip_create_linklocal_allrouters_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002)\r
+\r
+/**\r
+ * \brief  is addr (a) a solicited node multicast address, see RFC3513\r
+ *  a is of type uip_ipaddr_t*\r
+ */\r
+#define uip_is_addr_solicited_node(a)           \\r
+  ((((a)->u8[0]) == 0xFF) &&                     \\r
+  (((a)->u8[1]) == 0x02) &&                     \\r
+  (((a)->u16[1]) == 0) &&                       \\r
+  (((a)->u16[2]) == 0) &&                       \\r
+  (((a)->u16[3]) == 0) &&                       \\r
+  (((a)->u16[4]) == 0) &&                       \\r
+  (((a)->u16[5]) == 1) &&                       \\r
+  (((a)->u8[12]) == 0xFF))\r
+\r
+/**\r
+ * \briefput in b the solicited node address corresponding to address a\r
+ * both a and b are of type uip_ipaddr_t*\r
+ * */\r
+#define uip_create_solicited_node(a, b)    \\r
+  (((b)->u8[0]) = 0xFF);                        \\r
+  (((b)->u8[1]) = 0x02);                        \\r
+  (((b)->u16[1]) = 0);                          \\r
+  (((b)->u16[2]) = 0);                          \\r
+  (((b)->u16[3]) = 0);                          \\r
+  (((b)->u16[4]) = 0);                          \\r
+  (((b)->u8[10]) = 0);                          \\r
+  (((b)->u8[11]) = 0x01);                       \\r
+  (((b)->u8[12]) = 0xFF);                       \\r
+  (((b)->u8[13]) = ((a)->u8[13]));              \\r
+  (((b)->u16[7]) = ((a)->u16[7]))\r
+\r
+/**\r
+ * \brief is addr (a) a link local unicast address, see RFC3513\r
+ *  i.e. is (a) on prefix FE80::/10\r
+ *  a is of type uip_ipaddr_t*\r
+ */\r
+#define uip_is_addr_link_local(a) \\r
+  ((((a)->u8[0]) == 0xFE) && \\r
+  (((a)->u8[1]) == 0x80))\r
+\r
+/**\r
+ * \brief was addr (a) forged based on the mac address m\r
+ * a type is uip_ipaddr_t\r
+ * m type is uiplladdr_t\r
+ */\r
+#if UIP_CONF_LL_802154\r
+#define uip_is_addr_mac_addr_based(a, m) \\r
+  ((((a)->u8[8])  == (((m)->addr[0]) ^ 0x02)) &&   \\r
+   (((a)->u8[9])  == (m)->addr[1]) &&            \\r
+   (((a)->u8[10]) == (m)->addr[2]) &&            \\r
+   (((a)->u8[11]) == (m)->addr[3]) &&            \\r
+   (((a)->u8[12]) == (m)->addr[4]) &&            \\r
+   (((a)->u8[13]) == (m)->addr[5]) &&            \\r
+   (((a)->u8[14]) == (m)->addr[6]) &&            \\r
+   (((a)->u8[15]) == (m)->addr[7]))\r
+#else\r
+\r
+#define uip_is_addr_mac_addr_based(a, m) \\r
+  ((((a)->u8[8])  == (((m)->addr[0]) | 0x02)) &&   \\r
+   (((a)->u8[9])  == (m)->addr[1]) &&            \\r
+   (((a)->u8[10]) == (m)->addr[2]) &&            \\r
+   (((a)->u8[11]) == 0xff) &&            \\r
+   (((a)->u8[12]) == 0xfe) &&            \\r
+   (((a)->u8[13]) == (m)->addr[3]) &&            \\r
+   (((a)->u8[14]) == (m)->addr[4]) &&            \\r
+   (((a)->u8[15]) == (m)->addr[5]))\r
+   \r
+#endif /*UIP_CONF_LL_802154*/\r
+\r
+/**\r
+ * \brief is address a multicast address, see RFC 3513\r
+ * a is of type uip_ipaddr_t*\r
+ * */\r
+#define uip_is_addr_mcast(a)                    \\r
+  (((a)->u8[0]) == 0xFF)\r
+\r
+/**\r
+ * \brief is group-id of multicast address a\r
+ * the all nodes group-id\r
+ */\r
+#define uip_is_mcast_group_id_all_nodes(a) \\r
+  ((((a)->u16[1])  == 0) &&                 \\r
+   (((a)->u16[2])  == 0) &&                 \\r
+   (((a)->u16[3])  == 0) &&                 \\r
+   (((a)->u16[4])  == 0) &&                 \\r
+   (((a)->u16[5])  == 0) &&                 \\r
+   (((a)->u16[6])  == 0) &&                 \\r
+   (((a)->u8[14])  == 0) &&                 \\r
+   (((a)->u8[15])  == 1))\r
+\r
+/**\r
+ * \brief is group-id of multicast address a\r
+ * the all routers group-id\r
+ */\r
+#define uip_is_mcast_group_id_all_routers(a) \\r
+  ((((a)->u16[1])  == 0) &&                 \\r
+   (((a)->u16[2])  == 0) &&                 \\r
+   (((a)->u16[3])  == 0) &&                 \\r
+   (((a)->u16[4])  == 0) &&                 \\r
+   (((a)->u16[5])  == 0) &&                 \\r
+   (((a)->u16[6])  == 0) &&                 \\r
+   (((a)->u8[14])  == 0) &&                 \\r
+   (((a)->u8[15])  == 2))\r
+\r
+\r
+#endif /*UIP_CONF_IPV6*/\r
+\r
+/**\r
+ * Calculate the Internet checksum over a buffer.\r
+ *\r
+ * The Internet checksum is the one's complement of the one's\r
+ * complement sum of all 16-bit words in the buffer.\r
+ *\r
+ * See RFC1071.\r
+ *\r
+ * \param buf A pointer to the buffer over which the checksum is to be\r
+ * computed.\r
+ *\r
+ * \param len The length of the buffer over which the checksum is to\r
+ * be computed.\r
+ *\r
+ * \return The Internet checksum of the buffer.\r
+ */\r
+u16_t uip_chksum(u16_t *buf, u16_t len);\r
+\r
+/**\r
+ * Calculate the IP header checksum of the packet header in uip_buf.\r
+ *\r
+ * The IP header checksum is the Internet checksum of the 20 bytes of\r
+ * the IP header.\r
+ *\r
+ * \return The IP header checksum of the IP header in the uip_buf\r
+ * buffer.\r
+ */\r
+u16_t uip_ipchksum(void);\r
+\r
+/**\r
+ * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.\r
+ *\r
+ * The TCP checksum is the Internet checksum of data contents of the\r
+ * TCP segment, and a pseudo-header as defined in RFC793.\r
+ *\r
+ * \return The TCP checksum of the TCP segment in uip_buf and pointed\r
+ * to by uip_appdata.\r
+ */\r
+u16_t uip_tcpchksum(void);\r
+\r
+/**\r
+ * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.\r
+ *\r
+ * The UDP checksum is the Internet checksum of data contents of the\r
+ * UDP segment, and a pseudo-header as defined in RFC768.\r
+ *\r
+ * \return The UDP checksum of the UDP segment in uip_buf and pointed\r
+ * to by uip_appdata.\r
+ */\r
+u16_t uip_udpchksum(void);\r
+\r
+/**\r
+ * Calculate the ICMP checksum of the packet in uip_buf.\r
+ *\r
+ * \return The ICMP checksum of the ICMP packet in uip_buf\r
+ */\r
+u16_t uip_icmp6chksum(void);\r
+\r
+\r
+#endif /* __UIP_H__ */\r
+\r
+\r
+/** @} */\r
index 56dff9c..88c14cc 100644 (file)
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \defgroup uiparp uIP Address Resolution Protocol
- * @{
- *
- * The Address Resolution Protocol ARP is used for mapping between IP
- * addresses and link level addresses such as the Ethernet MAC
- * addresses. ARP uses broadcast queries to ask for the link level
- * address of a known IP address and the host which is configured with
- * the IP address for which the query was meant, will respond with its
- * link level address.
- *
- * \note This ARP implementation only supports Ethernet.
- */
-/**
- * \file
- * Implementation of the ARP Address Resolution Protocol.
- * \author Adam Dunkels <adam@dunkels.com>
- *
- */
-
-/*
- * Copyright (c) 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- *    products derived from this software without specific prior
- *    written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack.
- *
- * $Id: uip_arp.c,v 1.5 2008/02/07 01:35:00 adamdunkels Exp $
- *
- */
-
-
-#include "uip_arp.h"
-
-#include <string.h>
-
-struct arp_hdr {
-  struct uip_eth_hdr ethhdr;
-  u16_t hwtype;
-  u16_t protocol;
-  u8_t hwlen;
-  u8_t protolen;
-  u16_t opcode;
-  struct uip_eth_addr shwaddr;
-  uip_ipaddr_t sipaddr;
-  struct uip_eth_addr dhwaddr;
-  uip_ipaddr_t dipaddr;
-};
-
-struct ethip_hdr {
-  struct uip_eth_hdr ethhdr;
-  /* IP header. */
-  u8_t vhl,
-    tos,
-    len[2],
-    ipid[2],
-    ipoffset[2],
-    ttl,
-    proto;
-  u16_t ipchksum;
-  uip_ipaddr_t srcipaddr, destipaddr;
-};
-
-#define ARP_REQUEST 1
-#define ARP_REPLY   2
-
-#define ARP_HWTYPE_ETH 1
-
-struct arp_entry {
-  uip_ipaddr_t ipaddr;
-  struct uip_eth_addr ethaddr;
-  u8_t time;
-};
-
-static const struct uip_eth_addr broadcast_ethaddr =
-  {{0xff,0xff,0xff,0xff,0xff,0xff}};
-static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff};
-
-static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
-static uip_ipaddr_t ipaddr;
-static u8_t i, c;
-
-static u8_t arptime;
-static u8_t tmpage;
-
-#define BUF   ((struct arp_hdr *)&uip_buf[0])
-#define IPBUF ((struct ethip_hdr *)&uip_buf[0])
-
-#define DEBUG 0
-#if DEBUG
-#include <stdio.h>
-#define PRINTF(...) printf(__VA_ARGS__)
-#else
-#define PRINTF(...)
-#endif
-
-/*-----------------------------------------------------------------------------------*/
-/**
- * Initialize the ARP module.
- *
- */
-/*-----------------------------------------------------------------------------------*/
-void
-uip_arp_init(void)
-{
-  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-    memset(&arp_table[i].ipaddr, 0, 4);
-  }
-}
-/*-----------------------------------------------------------------------------------*/
-/**
- * Periodic ARP processing function.
- *
- * This function performs periodic timer processing in the ARP module
- * and should be called at regular intervals. The recommended interval
- * is 10 seconds between the calls.
- *
- */
-/*-----------------------------------------------------------------------------------*/
-void
-uip_arp_timer(void)
-{
-  struct arp_entry *tabptr = NULL;
-  
-  ++arptime;
-  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-    tabptr = &arp_table[i];
-    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) &&
-       arptime - tabptr->time >= UIP_ARP_MAXAGE) {
-      memset(&tabptr->ipaddr, 0, 4);
-    }
-  }
-
-}
-/*-----------------------------------------------------------------------------------*/
-static void
-uip_arp_update(uip_ipaddr_t *ipaddr, struct uip_eth_addr *ethaddr)
-{
-  register struct arp_entry *tabptr = NULL;
-  /* Walk through the ARP mapping table and try to find an entry to
-     update. If none is found, the IP -> MAC address mapping is
-     inserted in the ARP table. */
-  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-
-    tabptr = &arp_table[i];
-    /* Only check those entries that are actually in use. */
-    if(!uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
-
-      /* Check if the source IP address of the incoming packet matches
-         the IP address in this ARP table entry. */
-      if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) {
-        
-       /* An old entry found, update this and return. */
-       memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
-       tabptr->time = arptime;
-
-       return;
-      }
-    }
-  }
-
-  /* If we get here, no existing ARP table entry was found, so we
-     create one. */
-
-  /* First, we try to find an unused entry in the ARP table. */
-  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-    tabptr = &arp_table[i];
-    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
-      break;
-    }
-  }
-
-  /* If no unused entry is found, we try to find the oldest entry and
-     throw it away. */
-  if(i == UIP_ARPTAB_SIZE) {
-    tmpage = 0;
-    c = 0;
-    for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-      tabptr = &arp_table[i];
-      if(arptime - tabptr->time > tmpage) {
-       tmpage = arptime - tabptr->time;
-       c = i;
-      }
-    }
-    i = c;
-    tabptr = &arp_table[i];
-  }
-
-  /* Now, i is the ARP table entry which we will fill with the new
-     information. */
-  uip_ipaddr_copy(&tabptr->ipaddr, ipaddr);
-  memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
-  tabptr->time = arptime;
-}
-/*-----------------------------------------------------------------------------------*/
-/**
- * ARP processing for incoming IP packets
- *
- * This function should be called by the device driver when an IP
- * packet has been received. The function will check if the address is
- * in the ARP cache, and if so the ARP cache entry will be
- * refreshed. If no ARP cache entry was found, a new one is created.
- *
- * This function expects an IP packet with a prepended Ethernet header
- * in the uip_buf[] buffer, and the length of the packet in the global
- * variable uip_len.
- */
-/*-----------------------------------------------------------------------------------*/
-#if 0
-void
-uip_arp_ipin(void)
-{
-  uip_len -= sizeof(struct uip_eth_hdr);
-       
-  /* Only insert/update an entry if the source IP address of the
-     incoming IP packet comes from a host on the local network. */
-  if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
-     (uip_hostaddr[0] & uip_netmask[0])) {
-    return;
-  }
-  if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=
-     (uip_hostaddr[1] & uip_netmask[1])) {
-    return;
-  }
-  uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
-  
-  return;
-}
-#endif /* 0 */
-/*-----------------------------------------------------------------------------------*/
-/**
- * ARP processing for incoming ARP packets.
- *
- * This function should be called by the device driver when an ARP
- * packet has been received. The function will act differently
- * depending on the ARP packet type: if it is a reply for a request
- * that we previously sent out, the ARP cache will be filled in with
- * the values from the ARP reply. If the incoming ARP packet is an ARP
- * request for our IP address, an ARP reply packet is created and put
- * into the uip_buf[] buffer.
- *
- * When the function returns, the value of the global variable uip_len
- * indicates whether the device driver should send out a packet or
- * not. If uip_len is zero, no packet should be sent. If uip_len is
- * non-zero, it contains the length of the outbound packet that is
- * present in the uip_buf[] buffer.
- *
- * This function expects an ARP packet with a prepended Ethernet
- * header in the uip_buf[] buffer, and the length of the packet in the
- * global variable uip_len.
- */
-/*-----------------------------------------------------------------------------------*/
-void
-uip_arp_arpin(void)
-{
-  if(uip_len < sizeof(struct arp_hdr)) {
-    uip_len = 0;
-    return;
-  }
-  uip_len = 0;
-  
-  switch(BUF->opcode) {
-  case HTONS(ARP_REQUEST):
-    /* ARP request. If it asked for our address, we send out a
-       reply. */
-    /*    if(BUF->dipaddr[0] == uip_hostaddr[0] &&
-         BUF->dipaddr[1] == uip_hostaddr[1]) {*/
-    PRINTF("uip_arp_arpin: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",
-          BUF->dipaddr.u8[0], BUF->dipaddr.u8[1],
-          BUF->dipaddr.u8[2], BUF->dipaddr.u8[3],
-          uip_hostaddr.u8[0], uip_hostaddr.u8[1],
-          uip_hostaddr.u8[2], uip_hostaddr.u8[3]);
-    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
-      /* First, we register the one who made the request in our ARP
-        table, since it is likely that we will do more communication
-        with this host in the future. */
-      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
-      
-      BUF->opcode = HTONS(ARP_REPLY);
-
-      memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
-      memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
-      memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
-      memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
-      
-      uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);
-      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
-
-      BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
-      uip_len = sizeof(struct arp_hdr);
-    }
-    break;
-  case HTONS(ARP_REPLY):
-    /* ARP reply. We insert or update the ARP table if it was meant
-       for us. */
-    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
-      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
-    }
-    break;
-  }
-
-  return;
-}
-/*-----------------------------------------------------------------------------------*/
-/**
- * Prepend Ethernet header to an outbound IP packet and see if we need
- * to send out an ARP request.
- *
- * This function should be called before sending out an IP packet. The
- * function checks the destination IP address of the IP packet to see
- * what Ethernet MAC address that should be used as a destination MAC
- * address on the Ethernet.
- *
- * If the destination IP address is in the local network (determined
- * by logical ANDing of netmask and our IP address), the function
- * checks the ARP cache to see if an entry for the destination IP
- * address is found. If so, an Ethernet header is prepended and the
- * function returns. If no ARP cache entry is found for the
- * destination IP address, the packet in the uip_buf[] is replaced by
- * an ARP request packet for the IP address. The IP packet is dropped
- * and it is assumed that they higher level protocols (e.g., TCP)
- * eventually will retransmit the dropped packet.
- *
- * If the destination IP address is not on the local network, the IP
- * address of the default router is used instead.
- *
- * When the function returns, a packet is present in the uip_buf[]
- * buffer, and the length of the packet is in the global variable
- * uip_len.
- */
-/*-----------------------------------------------------------------------------------*/
-void
-uip_arp_out(void)
-{
-  struct arp_entry *tabptr = NULL;
-  
-  /* Find the destination IP address in the ARP table and construct
-     the Ethernet header. If the destination IP addres isn't on the
-     local network, we use the default router's IP address instead.
-
-     If not ARP table entry is found, we overwrite the original IP
-     packet with an ARP request for the IP address. */
-
-  /* First check if destination is a local broadcast. */
-  if(uip_ipaddr_cmp(&IPBUF->destipaddr, &uip_broadcast_addr)) {
-    memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
-  } else {
-    /* Check if the destination address is on the local network. */
-    if(!uip_ipaddr_maskcmp(&IPBUF->destipaddr, &uip_hostaddr, &uip_netmask)) {
-      /* Destination address was not on the local network, so we need to
-        use the default router's IP address instead of the destination
-        address when determining the MAC address. */
-      uip_ipaddr_copy(&ipaddr, &uip_draddr);
-    } else {
-      /* Else, we use the destination IP address. */
-      uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr);
-    }
-      
-    for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
-      tabptr = &arp_table[i];
-      if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {
-       break;
-      }
-    }
-
-    if(i == UIP_ARPTAB_SIZE) {
-      /* The destination address was not in our ARP table, so we
-        overwrite the IP packet with an ARP request. */
-
-      memset(BUF->ethhdr.dest.addr, 0xff, 6);
-      memset(BUF->dhwaddr.addr, 0x00, 6);
-      memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
-      memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
-    
-      uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);
-      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
-      BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
-      BUF->hwtype = HTONS(ARP_HWTYPE_ETH);
-      BUF->protocol = HTONS(UIP_ETHTYPE_IP);
-      BUF->hwlen = 6;
-      BUF->protolen = 4;
-      BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
-
-      uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
-    
-      uip_len = sizeof(struct arp_hdr);
-      return;
-    }
-
-    /* Build an ethernet header. */
-    memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
-  }
-  memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
-  
-  IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
-
-  uip_len += sizeof(struct uip_eth_hdr);
-}
-/*-----------------------------------------------------------------------------------*/
-
-/** @} */
-/** @} */
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \defgroup uiparp uIP Address Resolution Protocol\r
+ * @{\r
+ *\r
+ * The Address Resolution Protocol ARP is used for mapping between IP\r
+ * addresses and link level addresses such as the Ethernet MAC\r
+ * addresses. ARP uses broadcast queries to ask for the link level\r
+ * address of a known IP address and the host which is configured with\r
+ * the IP address for which the query was meant, will respond with its\r
+ * link level address.\r
+ *\r
+ * \note This ARP implementation only supports Ethernet.\r
+ */\r
\r
+/**\r
+ * \file\r
+ * Implementation of the ARP Address Resolution Protocol.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ *\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ *    products derived from this software without specific prior\r
+ *    written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip_arp.c,v 1.5 2008/02/07 01:35:00 adamdunkels Exp $\r
+ *\r
+ */\r
+\r
+\r
+#include "uip_arp.h"\r
+\r
+#include <string.h>\r
+\r
+struct arp_hdr {\r
+  struct uip_eth_hdr ethhdr;\r
+  u16_t hwtype;\r
+  u16_t protocol;\r
+  u8_t hwlen;\r
+  u8_t protolen;\r
+  u16_t opcode;\r
+  struct uip_eth_addr shwaddr;\r
+  uip_ipaddr_t sipaddr;\r
+  struct uip_eth_addr dhwaddr;\r
+  uip_ipaddr_t dipaddr;\r
+};\r
+\r
+struct ethip_hdr {\r
+  struct uip_eth_hdr ethhdr;\r
+  /* IP header. */\r
+  u8_t vhl,\r
+    tos,\r
+    len[2],\r
+    ipid[2],\r
+    ipoffset[2],\r
+    ttl,\r
+    proto;\r
+  u16_t ipchksum;\r
+  uip_ipaddr_t srcipaddr, destipaddr;\r
+};\r
+\r
+#define ARP_REQUEST 1\r
+#define ARP_REPLY   2\r
+\r
+#define ARP_HWTYPE_ETH 1\r
+\r
+struct arp_entry {\r
+  uip_ipaddr_t ipaddr;\r
+  struct uip_eth_addr ethaddr;\r
+  u8_t time;\r
+};\r
+\r
+static const struct uip_eth_addr broadcast_ethaddr =\r
+  {{0xff,0xff,0xff,0xff,0xff,0xff}};\r
+static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff};\r
+\r
+static struct arp_entry arp_table[UIP_ARPTAB_SIZE];\r
+static uip_ipaddr_t ipaddr;\r
+static u8_t i, c;\r
+\r
+static u8_t arptime;\r
+static u8_t tmpage;\r
+\r
+#define BUF   ((struct arp_hdr *)&uip_buf[0])\r
+#define IPBUF ((struct ethip_hdr *)&uip_buf[0])\r
+\r
+#define DEBUG 0\r
+#if DEBUG\r
+#include <stdio.h>\r
+#define PRINTF(...) printf(__VA_ARGS__)\r
+#else\r
+#define PRINTF(...)\r
+#endif\r
+\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Initialize the ARP module.\r
+ *\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_init(void)\r
+{\r
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+    memset(&arp_table[i].ipaddr, 0, 4);\r
+  }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Periodic ARP processing function.\r
+ *\r
+ * This function performs periodic timer processing in the ARP module\r
+ * and should be called at regular intervals. The recommended interval\r
+ * is 10 seconds between the calls.\r
+ *\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_timer(void)\r
+{\r
+  struct arp_entry *tabptr = NULL;\r
+  \r
+  ++arptime;\r
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+    tabptr = &arp_table[i];\r
+    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) &&\r
+       arptime - tabptr->time >= UIP_ARP_MAXAGE) {\r
+      memset(&tabptr->ipaddr, 0, 4);\r
+    }\r
+  }\r
+\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+static void\r
+uip_arp_update(uip_ipaddr_t *ipaddr, struct uip_eth_addr *ethaddr)\r
+{\r
+  register struct arp_entry *tabptr = NULL;\r
+  /* Walk through the ARP mapping table and try to find an entry to\r
+     update. If none is found, the IP -> MAC address mapping is\r
+     inserted in the ARP table. */\r
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+\r
+    tabptr = &arp_table[i];\r
+    /* Only check those entries that are actually in use. */\r
+    if(!uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {\r
+\r
+      /* Check if the source IP address of the incoming packet matches\r
+         the IP address in this ARP table entry. */\r
+      if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) {\r
+        \r
+       /* An old entry found, update this and return. */\r
+       memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
+       tabptr->time = arptime;\r
+\r
+       return;\r
+      }\r
+    }\r
+  }\r
+\r
+  /* If we get here, no existing ARP table entry was found, so we\r
+     create one. */\r
+\r
+  /* First, we try to find an unused entry in the ARP table. */\r
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+    tabptr = &arp_table[i];\r
+    if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  /* If no unused entry is found, we try to find the oldest entry and\r
+     throw it away. */\r
+  if(i == UIP_ARPTAB_SIZE) {\r
+    tmpage = 0;\r
+    c = 0;\r
+    for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+      tabptr = &arp_table[i];\r
+      if(arptime - tabptr->time > tmpage) {\r
+       tmpage = arptime - tabptr->time;\r
+       c = i;\r
+      }\r
+    }\r
+    i = c;\r
+    tabptr = &arp_table[i];\r
+  }\r
+\r
+  /* Now, i is the ARP table entry which we will fill with the new\r
+     information. */\r
+  uip_ipaddr_copy(&tabptr->ipaddr, ipaddr);\r
+  memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
+  tabptr->time = arptime;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * ARP processing for incoming IP packets\r
+ *\r
+ * This function should be called by the device driver when an IP\r
+ * packet has been received. The function will check if the address is\r
+ * in the ARP cache, and if so the ARP cache entry will be\r
+ * refreshed. If no ARP cache entry was found, a new one is created.\r
+ *\r
+ * This function expects an IP packet with a prepended Ethernet header\r
+ * in the uip_buf[] buffer, and the length of the packet in the global\r
+ * variable uip_len.\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+#if 0\r
+void\r
+uip_arp_ipin(void)\r
+{\r
+  uip_len -= sizeof(struct uip_eth_hdr);\r
+       \r
+  /* Only insert/update an entry if the source IP address of the\r
+     incoming IP packet comes from a host on the local network. */\r
+  if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=\r
+     (uip_hostaddr[0] & uip_netmask[0])) {\r
+    return;\r
+  }\r
+  if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=\r
+     (uip_hostaddr[1] & uip_netmask[1])) {\r
+    return;\r
+  }\r
+  uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));\r
+  \r
+  return;\r
+}\r
+#endif /* 0 */\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * ARP processing for incoming ARP packets.\r
+ *\r
+ * This function should be called by the device driver when an ARP\r
+ * packet has been received. The function will act differently\r
+ * depending on the ARP packet type: if it is a reply for a request\r
+ * that we previously sent out, the ARP cache will be filled in with\r
+ * the values from the ARP reply. If the incoming ARP packet is an ARP\r
+ * request for our IP address, an ARP reply packet is created and put\r
+ * into the uip_buf[] buffer.\r
+ *\r
+ * When the function returns, the value of the global variable uip_len\r
+ * indicates whether the device driver should send out a packet or\r
+ * not. If uip_len is zero, no packet should be sent. If uip_len is\r
+ * non-zero, it contains the length of the outbound packet that is\r
+ * present in the uip_buf[] buffer.\r
+ *\r
+ * This function expects an ARP packet with a prepended Ethernet\r
+ * header in the uip_buf[] buffer, and the length of the packet in the\r
+ * global variable uip_len.\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_arpin(void)\r
+{\r
+  if(uip_len < sizeof(struct arp_hdr)) {\r
+    uip_len = 0;\r
+    return;\r
+  }\r
+  uip_len = 0;\r
+  \r
+  switch(BUF->opcode) {\r
+  case HTONS(ARP_REQUEST):\r
+    /* ARP request. If it asked for our address, we send out a\r
+       reply. */\r
+    /*    if(BUF->dipaddr[0] == uip_hostaddr[0] &&\r
+         BUF->dipaddr[1] == uip_hostaddr[1]) {*/\r
+    PRINTF("uip_arp_arpin: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",\r
+          BUF->dipaddr.u8[0], BUF->dipaddr.u8[1],\r
+          BUF->dipaddr.u8[2], BUF->dipaddr.u8[3],\r
+          uip_hostaddr.u8[0], uip_hostaddr.u8[1],\r
+          uip_hostaddr.u8[2], uip_hostaddr.u8[3]);\r
+    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {\r
+      /* First, we register the one who made the request in our ARP\r
+        table, since it is likely that we will do more communication\r
+        with this host in the future. */\r
+      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);\r
+      \r
+      BUF->opcode = HTONS(ARP_REPLY);\r
+\r
+      memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);\r
+      memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);\r
+      memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);\r
+      memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);\r
+      \r
+      uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);\r
+      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);\r
+\r
+      BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);\r
+      uip_len = sizeof(struct arp_hdr);\r
+    }\r
+    break;\r
+  case HTONS(ARP_REPLY):\r
+    /* ARP reply. We insert or update the ARP table if it was meant\r
+       for us. */\r
+    if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {\r
+      uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);\r
+    }\r
+    break;\r
+  }\r
+\r
+  return;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Prepend Ethernet header to an outbound IP packet and see if we need\r
+ * to send out an ARP request.\r
+ *\r
+ * This function should be called before sending out an IP packet. The\r
+ * function checks the destination IP address of the IP packet to see\r
+ * what Ethernet MAC address that should be used as a destination MAC\r
+ * address on the Ethernet.\r
+ *\r
+ * If the destination IP address is in the local network (determined\r
+ * by logical ANDing of netmask and our IP address), the function\r
+ * checks the ARP cache to see if an entry for the destination IP\r
+ * address is found. If so, an Ethernet header is prepended and the\r
+ * function returns. If no ARP cache entry is found for the\r
+ * destination IP address, the packet in the uip_buf[] is replaced by\r
+ * an ARP request packet for the IP address. The IP packet is dropped\r
+ * and it is assumed that they higher level protocols (e.g., TCP)\r
+ * eventually will retransmit the dropped packet.\r
+ *\r
+ * If the destination IP address is not on the local network, the IP\r
+ * address of the default router is used instead.\r
+ *\r
+ * When the function returns, a packet is present in the uip_buf[]\r
+ * buffer, and the length of the packet is in the global variable\r
+ * uip_len.\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void\r
+uip_arp_out(void)\r
+{\r
+  struct arp_entry *tabptr = NULL;\r
+  \r
+  /* Find the destination IP address in the ARP table and construct\r
+     the Ethernet header. If the destination IP addres isn't on the\r
+     local network, we use the default router's IP address instead.\r
+\r
+     If not ARP table entry is found, we overwrite the original IP\r
+     packet with an ARP request for the IP address. */\r
+\r
+  /* First check if destination is a local broadcast. */\r
+  if(uip_ipaddr_cmp(&IPBUF->destipaddr, &uip_broadcast_addr)) {\r
+    memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);\r
+  } else {\r
+    /* Check if the destination address is on the local network. */\r
+    if(!uip_ipaddr_maskcmp(&IPBUF->destipaddr, &uip_hostaddr, &uip_netmask)) {\r
+      /* Destination address was not on the local network, so we need to\r
+        use the default router's IP address instead of the destination\r
+        address when determining the MAC address. */\r
+      uip_ipaddr_copy(&ipaddr, &uip_draddr);\r
+    } else {\r
+      /* Else, we use the destination IP address. */\r
+      uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr);\r
+    }\r
+      \r
+    for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
+      tabptr = &arp_table[i];\r
+      if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {\r
+       break;\r
+      }\r
+    }\r
+\r
+    if(i == UIP_ARPTAB_SIZE) {\r
+      /* The destination address was not in our ARP table, so we\r
+        overwrite the IP packet with an ARP request. */\r
+\r
+      memset(BUF->ethhdr.dest.addr, 0xff, 6);\r
+      memset(BUF->dhwaddr.addr, 0x00, 6);\r
+      memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);\r
+      memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);\r
+    \r
+      uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);\r
+      uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);\r
+      BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */\r
+      BUF->hwtype = HTONS(ARP_HWTYPE_ETH);\r
+      BUF->protocol = HTONS(UIP_ETHTYPE_IP);\r
+      BUF->hwlen = 6;\r
+      BUF->protolen = 4;\r
+      BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);\r
+\r
+      uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];\r
+    \r
+      uip_len = sizeof(struct arp_hdr);\r
+      return;\r
+    }\r
+\r
+    /* Build an ethernet header. */\r
+    memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);\r
+  }\r
+  memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);\r
+  \r
+  IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);\r
+\r
+  uip_len += sizeof(struct uip_eth_hdr);\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
+/** @} */\r
+/** @} */\r
index 114d431..ea2fd29 100644 (file)
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \addtogroup uiparp
- * @{
- */
-/**
- * \file
- * Macros and definitions for the ARP module.
- * \author Adam Dunkels <adam@dunkels.com>
- */
-  
-
-/*
- * Copyright (c) 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- *    products derived from this software without specific prior
- *    written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack.
- *
- * $Id: uip_arp.h,v 1.2 2006/08/26 23:58:45 oliverschmidt Exp $
- *
- */
-
-#ifndef __UIP_ARP_H__
-#define __UIP_ARP_H__
-
-#include "uip.h"
-
-
-extern struct uip_eth_addr uip_ethaddr;
-
-/**
- * The Ethernet header.
- */
-struct uip_eth_hdr {
-  struct uip_eth_addr dest;
-  struct uip_eth_addr src;
-  u16_t type;
-};
-
-#define UIP_ETHTYPE_ARP  0x0806
-#define UIP_ETHTYPE_IP   0x0800
-#define UIP_ETHTYPE_IPV6 0x86dd
-
-
-/* The uip_arp_init() function must be called before any of the other
-   ARP functions. */
-void uip_arp_init(void);
-
-/* The uip_arp_ipin() function should be called whenever an IP packet
-   arrives from the Ethernet. This function refreshes the ARP table or
-   inserts a new mapping if none exists. The function assumes that an
-   IP packet with an Ethernet header is present in the uip_buf buffer
-   and that the length of the packet is in the uip_len variable. */
-/*void uip_arp_ipin(void);*/
-#define uip_arp_ipin()
-
-/* The uip_arp_arpin() should be called when an ARP packet is received
-   by the Ethernet driver. This function also assumes that the
-   Ethernet frame is present in the uip_buf buffer. When the
-   uip_arp_arpin() function returns, the contents of the uip_buf
-   buffer should be sent out on the Ethernet if the uip_len variable
-   is > 0. */
-void uip_arp_arpin(void);
-
-/* The uip_arp_out() function should be called when an IP packet
-   should be sent out on the Ethernet. This function creates an
-   Ethernet header before the IP header in the uip_buf buffer. The
-   Ethernet header will have the correct Ethernet MAC destination
-   address filled in if an ARP table entry for the destination IP
-   address (or the IP address of the default router) is present. If no
-   such table entry is found, the IP packet is overwritten with an ARP
-   request and we rely on TCP to retransmit the packet that was
-   overwritten. In any case, the uip_len variable holds the length of
-   the Ethernet frame that should be transmitted. */
-void uip_arp_out(void);
-
-/* The uip_arp_timer() function should be called every ten seconds. It
-   is responsible for flushing old entries in the ARP table. */
-void uip_arp_timer(void);
-
-/** @} */
-
-/**
- * \addtogroup uipconffunc
- * @{
- */
-
-
-/**
- * Specifiy the Ethernet MAC address.
- *
- * The ARP code needs to know the MAC address of the Ethernet card in
- * order to be able to respond to ARP queries and to generate working
- * Ethernet headers.
- *
- * \note This macro only specifies the Ethernet MAC address to the ARP
- * code. It cannot be used to change the MAC address of the Ethernet
- * card.
- *
- * \param eaddr A pointer to a struct uip_eth_addr containing the
- * Ethernet MAC address of the Ethernet card.
- *
- * \hideinitializer
- */
-#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \
-                              uip_ethaddr.addr[1] = eaddr.addr[1];\
-                              uip_ethaddr.addr[2] = eaddr.addr[2];\
-                              uip_ethaddr.addr[3] = eaddr.addr[3];\
-                              uip_ethaddr.addr[4] = eaddr.addr[4];\
-                              uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)
-
-/** @} */
-
-
-#endif /* __UIP_ARP_H__ */
-/** @} */
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \addtogroup uiparp\r
+ * @{\r
+ */\r
\r
+/**\r
+ * \file\r
+ * Macros and definitions for the ARP module.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ */\r
+  \r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ *    products derived from this software without specific prior\r
+ *    written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uip_arp.h,v 1.2 2006/08/26 23:58:45 oliverschmidt Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __UIP_ARP_H__\r
+#define __UIP_ARP_H__\r
+\r
+#include "uip.h"\r
+\r
+\r
+extern struct uip_eth_addr uip_ethaddr;\r
+\r
+/**\r
+ * The Ethernet header.\r
+ */\r
+struct uip_eth_hdr {\r
+  struct uip_eth_addr dest;\r
+  struct uip_eth_addr src;\r
+  u16_t type;\r
+};\r
+\r
+#define UIP_ETHTYPE_ARP  0x0806\r
+#define UIP_ETHTYPE_IP   0x0800\r
+#define UIP_ETHTYPE_IPV6 0x86dd\r
+\r
+\r
+/* The uip_arp_init() function must be called before any of the other\r
+   ARP functions. */\r
+void uip_arp_init(void);\r
+\r
+/* The uip_arp_ipin() function should be called whenever an IP packet\r
+   arrives from the Ethernet. This function refreshes the ARP table or\r
+   inserts a new mapping if none exists. The function assumes that an\r
+   IP packet with an Ethernet header is present in the uip_buf buffer\r
+   and that the length of the packet is in the uip_len variable. */\r
+/*void uip_arp_ipin(void);*/\r
+#define uip_arp_ipin()\r
+\r
+/* The uip_arp_arpin() should be called when an ARP packet is received\r
+   by the Ethernet driver. This function also assumes that the\r
+   Ethernet frame is present in the uip_buf buffer. When the\r
+   uip_arp_arpin() function returns, the contents of the uip_buf\r
+   buffer should be sent out on the Ethernet if the uip_len variable\r
+   is > 0. */\r
+void uip_arp_arpin(void);\r
+\r
+/* The uip_arp_out() function should be called when an IP packet\r
+   should be sent out on the Ethernet. This function creates an\r
+   Ethernet header before the IP header in the uip_buf buffer. The\r
+   Ethernet header will have the correct Ethernet MAC destination\r
+   address filled in if an ARP table entry for the destination IP\r
+   address (or the IP address of the default router) is present. If no\r
+   such table entry is found, the IP packet is overwritten with an ARP\r
+   request and we rely on TCP to retransmit the packet that was\r
+   overwritten. In any case, the uip_len variable holds the length of\r
+   the Ethernet frame that should be transmitted. */\r
+void uip_arp_out(void);\r
+\r
+/* The uip_arp_timer() function should be called every ten seconds. It\r
+   is responsible for flushing old entries in the ARP table. */\r
+void uip_arp_timer(void);\r
+\r
+/** @} */\r
+\r
+/**\r
+ * \addtogroup uipconffunc\r
+ * @{\r
+ */\r
+\r
+\r
+/**\r
+ * Specifiy the Ethernet MAC address.\r
+ *\r
+ * The ARP code needs to know the MAC address of the Ethernet card in\r
+ * order to be able to respond to ARP queries and to generate working\r
+ * Ethernet headers.\r
+ *\r
+ * \note This macro only specifies the Ethernet MAC address to the ARP\r
+ * code. It cannot be used to change the MAC address of the Ethernet\r
+ * card.\r
+ *\r
+ * \param eaddr A pointer to a struct uip_eth_addr containing the\r
+ * Ethernet MAC address of the Ethernet card.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \\r
+                              uip_ethaddr.addr[1] = eaddr.addr[1];\\r
+                              uip_ethaddr.addr[2] = eaddr.addr[2];\\r
+                              uip_ethaddr.addr[3] = eaddr.addr[3];\\r
+                              uip_ethaddr.addr[4] = eaddr.addr[4];\\r
+                              uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)\r
+\r
+/** @} */\r
+\r
+\r
+#endif /* __UIP_ARP_H__ */\r
+/** @} */\r
index 244ce1d..7b9d190 100644 (file)
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \defgroup uipopt Configuration options for uIP
- * @{
- *
- * uIP is configured using the per-project configuration file
- * "uipopt.h". This file contains all compile-time options for uIP and
- * should be tweaked to match each specific project. The uIP
- * distribution contains a documented example "uipopt.h" that can be
- * copied and modified for each project.
- */
-
-/**
- * \file
- * Configuration options for uIP.
- * \author Adam Dunkels <adam@dunkels.com>
- *
- * This file is used for tweaking various configuration options for
- * uIP. You should make a copy of this file into one of your project's
- * directories instead of editing this example "uipopt.h" file that
- * comes with the uIP distribution.
- */
-
-/*
- * Copyright (c) 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- *    products derived from this software without specific prior
- *    written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack.
- *
- * $Id: uipopt.h,v 1.11 2009/04/10 00:37:48 adamdunkels Exp $
- *
- */
-
-#ifndef __UIPOPT_H__
-#define __UIPOPT_H__
-
-#ifndef UIP_LITTLE_ENDIAN
-#define UIP_LITTLE_ENDIAN  3412
-#endif /* UIP_LITTLE_ENDIAN */
-#ifndef UIP_BIG_ENDIAN
-#define UIP_BIG_ENDIAN     1234
-#endif /* UIP_BIG_ENDIAN */
-
-/*------------------------------------------------------------------------------*/
-
-/**
- * \defgroup uipoptstaticconf Static configuration options
- * @{
- *
- * These configuration options can be used for setting the IP address
- * settings statically, but only if UIP_FIXEDADDR is set to 1. The
- * configuration options for a specific node includes IP address,
- * netmask and default router as well as the Ethernet address. The
- * netmask, default router and Ethernet address are applicable only
- * if uIP should be run over Ethernet.
- *
- * This options are meaningful only for the IPv4 code.
- *
- * All of these should be changed to suit your project.
- */
-
-/**
- * Determines if uIP should use a fixed IP address or not.
- *
- * If uIP should use a fixed IP address, the settings are set in the
- * uipopt.h file. If not, the macros uip_sethostaddr(),
- * uip_setdraddr() and uip_setnetmask() should be used instead.
- *
- * \hideinitializer
- */
-#define UIP_FIXEDADDR    0
-
-/**
- * Ping IP address assignment.
- *
- * uIP uses a "ping" packets for setting its own IP address if this
- * option is set. If so, uIP will start with an empty IP address and
- * the destination IP address of the first incoming "ping" (ICMP echo)
- * packet will be used for setting the hosts IP address.
- *
- * \note This works only if UIP_FIXEDADDR is 0.
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_PINGADDRCONF
-#define UIP_PINGADDRCONF UIP_CONF_PINGADDRCONF
-#else /* UIP_CONF_PINGADDRCONF */
-#define UIP_PINGADDRCONF 0
-#endif /* UIP_CONF_PINGADDRCONF */
-
-
-/**
- * Specifies if the uIP ARP module should be compiled with a fixed
- * Ethernet MAC address or not.
- *
- * If this configuration option is 0, the macro uip_setethaddr() can
- * be used to specify the Ethernet address at run-time.
- *
- * \hideinitializer
- */
-#define UIP_FIXEDETHADDR 0
-
-/** @} */
-/*------------------------------------------------------------------------------*/
-/**
- * \defgroup uipoptip IP configuration options
- * @{
- *
- */
-/**
- * The IP TTL (time to live) of IP packets sent by uIP.
- *
- * This should normally not be changed.
- */
-#define UIP_TTL         64
-
-/**
- * The maximum time an IP fragment should wait in the reassembly
- * buffer before it is dropped.
- *
- */
-#define UIP_REASS_MAXAGE 60 /*60s*/
-
-/**
- * Turn on support for IP packet reassembly.
- *
- * uIP supports reassembly of fragmented IP packets. This features
- * requires an additional amount of RAM to hold the reassembly buffer
- * and the reassembly code size is approximately 700 bytes.  The
- * reassembly buffer is of the same size as the uip_buf buffer
- * (configured by UIP_BUFSIZE).
- *
- * \note IP packet reassembly is not heavily tested.
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_REASSEMBLY
-#define UIP_REASSEMBLY UIP_CONF_REASSEMBLY
-#else /* UIP_CONF_REASSEMBLY */
-#define UIP_REASSEMBLY 0
-#endif /* UIP_CONF_REASSEMBLY */
-/** @} */
-
-/*------------------------------------------------------------------------------*/
-/**
- * \defgroup uipoptipv6 IPv6 configuration options
- * @{
- *
- */
-
-/** The maximum transmission unit at the IP Layer*/
-#define UIP_LINK_MTU 1280
-
-#ifndef UIP_CONF_IPV6
-/** Do we use IPv6 or not (default: no) */
-#define UIP_CONF_IPV6                 0
-#endif
-
-#ifndef UIP_CONF_IPV6_QUEUE_PKT
-/** Do we do per %neighbor queuing during address resolution (default: no) */
-#define UIP_CONF_IPV6_QUEUE_PKT       0
-#endif
-
-#ifndef UIP_CONF_IPV6_CHECKS 
-/** Do we do IPv6 consistency checks (highly recommended, default: yes) */
-#define UIP_CONF_IPV6_CHECKS          1
-#endif
-
-#ifndef UIP_CONF_IPV6_REASSEMBLY 
-/** Do we do IPv6 fragmentation (default: no) */
-#define UIP_CONF_IPV6_REASSEMBLY      0
-#endif
-
-#ifndef UIP_CONF_NETIF_MAX_ADDRESSES
-/** Default number of IPv6 addresses associated to the node's interface */
-#define UIP_CONF_NETIF_MAX_ADDRESSES  3
-#endif
-
-#ifndef UIP_CONF_ND6_MAX_PREFIXES 
-/** Default number of IPv6 prefixes associated to the node's interface */
-#define UIP_CONF_ND6_MAX_PREFIXES     3
-#endif
-
-#ifndef UIP_CONF_ND6_MAX_NEIGHBORS 
-/** Default number of neighbors that can be stored in the %neighbor cache */
-#define UIP_CONF_ND6_MAX_NEIGHBORS    4  
-#endif
-
-#ifndef UIP_CONF_ND6_MAX_DEFROUTERS
-/** Minimum number of default routers */
-#define UIP_CONF_ND6_MAX_DEFROUTERS   2
-#endif
-/** @} */
-
-/*------------------------------------------------------------------------------*/
-/**
- * \defgroup uipoptudp UDP configuration options
- * @{
- *
- * \note The UDP support in uIP is still not entirely complete; there
- * is no support for sending or receiving broadcast or multicast
- * packets, but it works well enough to support a number of vital
- * applications such as DNS queries, though
- */
-
-/**
- * Toggles whether UDP support should be compiled in or not.
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_UDP
-#define UIP_UDP UIP_CONF_UDP
-#else /* UIP_CONF_UDP */
-#define UIP_UDP           1
-#endif /* UIP_CONF_UDP */
-
-/**
- * Toggles if UDP checksums should be used or not.
- *
- * \note Support for UDP checksums is currently not included in uIP,
- * so this option has no function.
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_UDP_CHECKSUMS
-#define UIP_UDP_CHECKSUMS UIP_CONF_UDP_CHECKSUMS
-#else
-#define UIP_UDP_CHECKSUMS 0
-#endif
-
-/**
- * The maximum amount of concurrent UDP connections.
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_UDP_CONNS
-#define UIP_UDP_CONNS UIP_CONF_UDP_CONNS
-#else /* UIP_CONF_UDP_CONNS */
-#define UIP_UDP_CONNS    10
-#endif /* UIP_CONF_UDP_CONNS */
-
-/**
- * The name of the function that should be called when UDP datagrams arrive.
- *
- * \hideinitializer
- */
-
-
-/** @} */
-/*------------------------------------------------------------------------------*/
-/**
- * \defgroup uipopttcp TCP configuration options
- * @{
- */
-
-/**
- * Toggles whether UDP support should be compiled in or not.
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_TCP
-#define UIP_TCP UIP_CONF_TCP
-#else /* UIP_CONF_UDP */
-#define UIP_TCP           1
-#endif /* UIP_CONF_UDP */
-
-/**
- * Determines if support for opening connections from uIP should be
- * compiled in.
- *
- * If the applications that are running on top of uIP for this project
- * do not need to open outgoing TCP connections, this configuration
- * option can be turned off to reduce the code size of uIP.
- *
- * \hideinitializer
- */
-#ifndef UIP_CONF_ACTIVE_OPEN
-#define UIP_ACTIVE_OPEN 1
-#else /* UIP_CONF_ACTIVE_OPEN */
-#define UIP_ACTIVE_OPEN UIP_CONF_ACTIVE_OPEN
-#endif /* UIP_CONF_ACTIVE_OPEN */
-
-/**
- * The maximum number of simultaneously open TCP connections.
- *
- * Since the TCP connections are statically allocated, turning this
- * configuration knob down results in less RAM used. Each TCP
- * connection requires approximately 30 bytes of memory.
- *
- * \hideinitializer
- */
-#ifndef UIP_CONF_MAX_CONNECTIONS
-#define UIP_CONNS       10
-#else /* UIP_CONF_MAX_CONNECTIONS */
-#define UIP_CONNS UIP_CONF_MAX_CONNECTIONS
-#endif /* UIP_CONF_MAX_CONNECTIONS */
-
-
-/**
- * The maximum number of simultaneously listening TCP ports.
- *
- * Each listening TCP port requires 2 bytes of memory.
- *
- * \hideinitializer
- */
-#ifndef UIP_CONF_MAX_LISTENPORTS
-#define UIP_LISTENPORTS 20
-#else /* UIP_CONF_MAX_LISTENPORTS */
-#define UIP_LISTENPORTS UIP_CONF_MAX_LISTENPORTS
-#endif /* UIP_CONF_MAX_LISTENPORTS */
-
-/**
- * Determines if support for TCP urgent data notification should be
- * compiled in.
- *
- * Urgent data (out-of-band data) is a rarely used TCP feature that
- * very seldom would be required.
- *
- * \hideinitializer
- */
-#if !defined(UIP_URGDATA)
-#define UIP_URGDATA      0
-#endif
-
-/**
- * The initial retransmission timeout counted in timer pulses.
- *
- * This should not be changed.
- */
-#if !defined(UIP_RTO)
-#define UIP_RTO         3
-#endif
-
-/**
- * The maximum number of times a segment should be retransmitted
- * before the connection should be aborted.
- *
- * This should not be changed.
- */
-#if !defined(UIP_MAXRTX)
-#define UIP_MAXRTX      8
-#endif
-
-/**
- * The maximum number of times a SYN segment should be retransmitted
- * before a connection request should be deemed to have been
- * unsuccessful.
- *
- * This should not need to be changed.
- */
-#if !defined(UIP_MAXSYNRTX)
-#define UIP_MAXSYNRTX      5
-#endif
-
-/**
- * The TCP maximum segment size.
- *
- * This is should not be to set to more than
- * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
- */
-#ifdef UIP_CONF_TCP_MSS
-#define UIP_TCP_MSS UIP_CONF_TCP_MSS
-#else
-#define UIP_TCP_MSS     (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
-#endif
-
-/**
- * The size of the advertised receiver's window.
- *
- * Should be set low (i.e., to the size of the uip_buf buffer) if the
- * application is slow to process incoming data, or high (32768 bytes)
- * if the application processes data quickly.
- *
- * \hideinitializer
- */
-#ifndef UIP_CONF_RECEIVE_WINDOW
-#define UIP_RECEIVE_WINDOW UIP_TCP_MSS
-#else
-#define UIP_RECEIVE_WINDOW UIP_CONF_RECEIVE_WINDOW
-#endif
-
-/**
- * How long a connection should stay in the TIME_WAIT state.
- *
- * This configuration option has no real implication, and it should be
- * left untouched.
- */
-#define UIP_TIME_WAIT_TIMEOUT 120
-
-
-/** @} */
-/*------------------------------------------------------------------------------*/
-/**
- * \defgroup uipoptarp ARP configuration options
- * @{
- */
-
-/**
- * The size of the ARP table.
- *
- * This option should be set to a larger value if this uIP node will
- * have many connections from the local network.
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_ARPTAB_SIZE
-#define UIP_ARPTAB_SIZE UIP_CONF_ARPTAB_SIZE
-#else
-#define UIP_ARPTAB_SIZE 8
-#endif
-
-/**
- * The maximum age of ARP table entries measured in 10ths of seconds.
- *
- * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD
- * default).
- */
-#define UIP_ARP_MAXAGE 120
-
-
-/** @} */
-
-/*------------------------------------------------------------------------------*/
-
-/**
- * \defgroup uipoptmac layer 2 options (for ipv6)
- * @{
- */
-
-#define UIP_DEFAULT_PREFIX_LEN 64
-
-/** @} */
-
-/*------------------------------------------------------------------------------*/
-
-/**
- * \defgroup uipoptsics 6lowpan options (for ipv6)
- * @{
- */
-/**
- * Timeout for packet reassembly at the 6lowpan layer
- * (should be < 60s)
- */
-#ifdef SICSLOWPAN_CONF_MAXAGE
-#define SICSLOWPAN_REASS_MAXAGE SICSLOWPAN_CONF_MAXAGE
-#else
-#define SICSLOWPAN_REASS_MAXAGE 20
-#endif
-
-/**
- * Do we compress the IP header or not (default: no)
- */
-#ifndef SICSLOWPAN_CONF_COMPRESSION
-#define SICSLOWPAN_CONF_COMPRESSION 0
-#endif
-
-/**
- * If we use IPHC compression, how many address contexts do we support
- */
-#ifndef SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 
-#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1
-#endif
-
-/**
- * Do we support 6lowpan fragmentation
- */
-#ifndef SICSLOWPAN_CONF_FRAG  
-#define SICSLOWPAN_CONF_FRAG  0
-#endif
-
-/** @} */
-
-/*------------------------------------------------------------------------------*/
-
-/**
- * \defgroup uipoptgeneral General configuration options
- * @{
- */
-
-/**
- * The size of the uIP packet buffer.
- *
- * The uIP packet buffer should not be smaller than 60 bytes, and does
- * not need to be larger than 1514 bytes. Lower size results in lower
- * TCP throughput, larger size results in higher TCP throughput.
- *
- * \hideinitializer
- */
-#ifndef UIP_CONF_BUFFER_SIZE
-#define UIP_BUFSIZE UIP_LINK_MTU + UIP_LLH_LEN
-#else /* UIP_CONF_BUFFER_SIZE */
-#define UIP_BUFSIZE UIP_CONF_BUFFER_SIZE
-#endif /* UIP_CONF_BUFFER_SIZE */
-
-
-/**
- * Determines if statistics support should be compiled in.
- *
- * The statistics is useful for debugging and to show the user.
- *
- * \hideinitializer
- */
-#ifndef UIP_CONF_STATISTICS
-#define UIP_STATISTICS  0
-#else /* UIP_CONF_STATISTICS */
-#define UIP_STATISTICS UIP_CONF_STATISTICS
-#endif /* UIP_CONF_STATISTICS */
-
-/**
- * Determines if logging of certain events should be compiled in.
- *
- * This is useful mostly for debugging. The function uip_log()
- * must be implemented to suit the architecture of the project, if
- * logging is turned on.
- *
- * \hideinitializer
- */
-#ifndef UIP_CONF_LOGGING
-#define UIP_LOGGING     0
-#else /* UIP_CONF_LOGGING */
-#define UIP_LOGGING     UIP_CONF_LOGGING
-#endif /* UIP_CONF_LOGGING */
-
-/**
- * Broadcast support.
- *
- * This flag configures IP broadcast support. This is useful only
- * together with UDP.
- *
- * \hideinitializer
- *
- */
-#ifndef UIP_CONF_BROADCAST
-#define UIP_BROADCAST 0
-#else /* UIP_CONF_BROADCAST */
-#define UIP_BROADCAST UIP_CONF_BROADCAST
-#endif /* UIP_CONF_BROADCAST */
-
-/**
- * Print out a uIP log message.
- *
- * This function must be implemented by the module that uses uIP, and
- * is called by uIP whenever a log message is generated.
- */
-void uip_log(char *msg);
-
-/**
- * The link level header length.
- *
- * This is the offset into the uip_buf where the IP header can be
- * found. For Ethernet, this should be set to 14. For SLIP, this
- * should be set to 0.
- *
- * \note we probably won't use this constant for other link layers than
- * ethernet as they have variable header length (this is due to variable
- * number and type of address fields and to optional security features)
- * E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14
- *       802.11 -> 4 + (6*3/4) + 2
- * \hideinitializer
- */
-#ifdef UIP_CONF_LLH_LEN
-#define UIP_LLH_LEN UIP_CONF_LLH_LEN
-#else /* UIP_LLH_LEN */
-#define UIP_LLH_LEN     14
-#endif /* UIP_CONF_LLH_LEN */
-
-/** @} */
-/*------------------------------------------------------------------------------*/
-/**
- * \defgroup uipoptcpu CPU architecture configuration
- * @{
- *
- * The CPU architecture configuration is where the endianess of the
- * CPU on which uIP is to be run is specified. Most CPUs today are
- * little endian, and the most notable exception are the Motorolas
- * which are big endian. The BYTE_ORDER macro should be changed to
- * reflect the CPU architecture on which uIP is to be run.
- */
-
-/**
- * The byte order of the CPU architecture on which uIP is to be run.
- *
- * This option can be either UIP_BIG_ENDIAN (Motorola byte order) or
- * UIP_LITTLE_ENDIAN (Intel byte order).
- *
- * \hideinitializer
- */
-#ifdef UIP_CONF_BYTE_ORDER
-#define UIP_BYTE_ORDER     UIP_CONF_BYTE_ORDER
-#else /* UIP_CONF_BYTE_ORDER */
-#define UIP_BYTE_ORDER     UIP_LITTLE_ENDIAN
-#endif /* UIP_CONF_BYTE_ORDER */
-
-/** @} */
-/*------------------------------------------------------------------------------*/
-
-#include <ff.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "timer.h"
-
-typedef uint8_t u8_t;
-typedef uint16_t u16_t;
-typedef uint32_t u32_t;
-typedef uint32_t uip_stats_t;
-
-/**
- * \defgroup uipoptapp Application specific configurations
- * @{
- *
- * An uIP application is implemented using a single application
- * function that is called by uIP whenever a TCP/IP event occurs. The
- * name of this function must be registered with uIP at compile time
- * using the UIP_APPCALL definition.
- *
- * uIP applications can store the application state within the
- * uip_conn structure by specifying the type of the application
- * structure by typedef:ing the type uip_tcp_appstate_t and uip_udp_appstate_t.
- *
- * The file containing the definitions must be included in the
- * uipopt.h file.
- *
- * The following example illustrates how this can look.
- \code
-
- void httpd_appcall(void);
- #define UIP_APPCALL     httpd_appcall
-
- struct httpd_state {
- u8_t state;
- u16_t count;
- char *dataptr;
- char *script;
- };
- typedef struct httpd_state uip_tcp_appstate_t
- \endcode
-*/
-#define UIP_UDP_APPCALL uIPManagement_UDPCallback
-void UIP_UDP_APPCALL(void);
-
-/**
- * \var #define UIP_APPCALL
- *
- * The name of the application function that uIP should call in
- * response to TCP/IP events.
- *
- */
-#define UIP_APPCALL     uIPManagement_TCPCallback
-void UIP_APPCALL(void);
-
-/**
- * \var typedef uip_tcp_appstate_t
- *
- * The type of the application state that is to be stored in the
- * uip_conn structure. This usually is typedef:ed to a struct holding
- * application state information.
- */
-typedef union
-{
-       struct
-       {
-               uint8_t  CurrentState;
-               uint8_t  NextState;
-               
-               char     FileName[MAX_URI_LENGTH];
-               FIL      FileHandle;
-               bool     FileOpen;
-               uint32_t ACKedFilePos;
-               uint16_t SentChunkSize;
-       } HTTPServer;
-       
-       struct
-       {
-               uint8_t  CurrentState;
-               uint8_t  NextState;
-               
-               uint8_t  IssuedCommand;
-       } TELNETServer;
-} uip_tcp_appstate_t;
-
-/**
- * \var typedef uip_udp_appstate_t
- *
- * The type of the application state that is to be stored in the
- * uip_conn structure. This usually is typedef:ed to a struct holding
- * application state information.
- */
-typedef union
-{
-       struct
-       {
-               uint8_t      CurrentState;
-               struct timer Timeout;
-               
-               struct
-               {
-                       uint8_t AllocatedIP[4];
-                       uint8_t Netmask[4];
-                       uint8_t GatewayIP[4];
-                       uint8_t ServerIP[4];
-               } DHCPOffer_Data;
-       } DHCPClient;
-} uip_udp_appstate_t;
-/** @} */
-
-#endif /* __UIPOPT_H__ */
-/** @} */
-/** @} */
+/**\r
+ * \addtogroup uip\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * \defgroup uipopt Configuration options for uIP\r
+ * @{\r
+ *\r
+ * uIP is configured using the per-project configuration file\r
+ * "uipopt.h". This file contains all compile-time options for uIP and\r
+ * should be tweaked to match each specific project. The uIP\r
+ * distribution contains a documented example "uipopt.h" that can be\r
+ * copied and modified for each project.\r
+ */\r
+\r
+/**\r
+ * \file\r
+ * Configuration options for uIP.\r
+ * \author Adam Dunkels <adam@dunkels.com>\r
+ *\r
+ * This file is used for tweaking various configuration options for\r
+ * uIP. You should make a copy of this file into one of your project's\r
+ * directories instead of editing this example "uipopt.h" file that\r
+ * comes with the uIP distribution.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ *    products derived from this software without specific prior\r
+ *    written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the uIP TCP/IP stack.\r
+ *\r
+ * $Id: uipopt.h,v 1.11 2009/04/10 00:37:48 adamdunkels Exp $\r
+ *\r
+ */\r
+\r
+#ifndef __UIPOPT_H__\r
+#define __UIPOPT_H__\r
+\r
+#ifndef UIP_LITTLE_ENDIAN\r
+#define UIP_LITTLE_ENDIAN  3412\r
+#endif /* UIP_LITTLE_ENDIAN */\r
+#ifndef UIP_BIG_ENDIAN\r
+#define UIP_BIG_ENDIAN     1234\r
+#endif /* UIP_BIG_ENDIAN */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ * \defgroup uipoptstaticconf Static configuration options\r
+ * @{\r
+ *\r
+ * These configuration options can be used for setting the IP address\r
+ * settings statically, but only if UIP_FIXEDADDR is set to 1. The\r
+ * configuration options for a specific node includes IP address,\r
+ * netmask and default router as well as the Ethernet address. The\r
+ * netmask, default router and Ethernet address are applicable only\r
+ * if uIP should be run over Ethernet.\r
+ *\r
+ * This options are meaningful only for the IPv4 code.\r
+ *\r
+ * All of these should be changed to suit your project.\r
+ */\r
+\r
+/**\r
+ * Determines if uIP should use a fixed IP address or not.\r
+ *\r
+ * If uIP should use a fixed IP address, the settings are set in the\r
+ * uipopt.h file. If not, the macros uip_sethostaddr(),\r
+ * uip_setdraddr() and uip_setnetmask() should be used instead.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_FIXEDADDR    0\r
+\r
+/**\r
+ * Ping IP address assignment.\r
+ *\r
+ * uIP uses a "ping" packets for setting its own IP address if this\r
+ * option is set. If so, uIP will start with an empty IP address and\r
+ * the destination IP address of the first incoming "ping" (ICMP echo)\r
+ * packet will be used for setting the hosts IP address.\r
+ *\r
+ * \note This works only if UIP_FIXEDADDR is 0.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_PINGADDRCONF\r
+#define UIP_PINGADDRCONF UIP_CONF_PINGADDRCONF\r
+#else /* UIP_CONF_PINGADDRCONF */\r
+#define UIP_PINGADDRCONF 0\r
+#endif /* UIP_CONF_PINGADDRCONF */\r
+\r
+\r
+/**\r
+ * Specifies if the uIP ARP module should be compiled with a fixed\r
+ * Ethernet MAC address or not.\r
+ *\r
+ * If this configuration option is 0, the macro uip_setethaddr() can\r
+ * be used to specify the Ethernet address at run-time.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#define UIP_FIXEDETHADDR 0\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \defgroup uipoptip IP configuration options\r
+ * @{\r
+ *\r
+ */\r
+/**\r
+ * The IP TTL (time to live) of IP packets sent by uIP.\r
+ *\r
+ * This should normally not be changed.\r
+ */\r
+#define UIP_TTL         64\r
+\r
+/**\r
+ * The maximum time an IP fragment should wait in the reassembly\r
+ * buffer before it is dropped.\r
+ *\r
+ */\r
+#define UIP_REASS_MAXAGE 60 /*60s*/\r
+\r
+/**\r
+ * Turn on support for IP packet reassembly.\r
+ *\r
+ * uIP supports reassembly of fragmented IP packets. This features\r
+ * requires an additional amount of RAM to hold the reassembly buffer\r
+ * and the reassembly code size is approximately 700 bytes.  The\r
+ * reassembly buffer is of the same size as the uip_buf buffer\r
+ * (configured by UIP_BUFSIZE).\r
+ *\r
+ * \note IP packet reassembly is not heavily tested.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_REASSEMBLY\r
+#define UIP_REASSEMBLY UIP_CONF_REASSEMBLY\r
+#else /* UIP_CONF_REASSEMBLY */\r
+#define UIP_REASSEMBLY 0\r
+#endif /* UIP_CONF_REASSEMBLY */\r
+/** @} */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \defgroup uipoptipv6 IPv6 configuration options\r
+ * @{\r
+ *\r
+ */\r
+\r
+/** The maximum transmission unit at the IP Layer*/\r
+#define UIP_LINK_MTU 1280\r
+\r
+#ifndef UIP_CONF_IPV6\r
+/** Do we use IPv6 or not (default: no) */\r
+#define UIP_CONF_IPV6                 0\r
+#endif\r
+\r
+#ifndef UIP_CONF_IPV6_QUEUE_PKT\r
+/** Do we do per %neighbor queuing during address resolution (default: no) */\r
+#define UIP_CONF_IPV6_QUEUE_PKT       0\r
+#endif\r
+\r
+#ifndef UIP_CONF_IPV6_CHECKS \r
+/** Do we do IPv6 consistency checks (highly recommended, default: yes) */\r
+#define UIP_CONF_IPV6_CHECKS          1\r
+#endif\r
+\r
+#ifndef UIP_CONF_IPV6_REASSEMBLY \r
+/** Do we do IPv6 fragmentation (default: no) */\r
+#define UIP_CONF_IPV6_REASSEMBLY      0\r
+#endif\r
+\r
+#ifndef UIP_CONF_NETIF_MAX_ADDRESSES\r
+/** Default number of IPv6 addresses associated to the node's interface */\r
+#define UIP_CONF_NETIF_MAX_ADDRESSES  3\r
+#endif\r
+\r
+#ifndef UIP_CONF_ND6_MAX_PREFIXES \r
+/** Default number of IPv6 prefixes associated to the node's interface */\r
+#define UIP_CONF_ND6_MAX_PREFIXES     3\r
+#endif\r
+\r
+#ifndef UIP_CONF_ND6_MAX_NEIGHBORS \r
+/** Default number of neighbors that can be stored in the %neighbor cache */\r
+#define UIP_CONF_ND6_MAX_NEIGHBORS    4  \r
+#endif\r
+\r
+#ifndef UIP_CONF_ND6_MAX_DEFROUTERS\r
+/** Minimum number of default routers */\r
+#define UIP_CONF_ND6_MAX_DEFROUTERS   2\r
+#endif\r
+/** @} */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \defgroup uipoptudp UDP configuration options\r
+ * @{\r
+ *\r
+ * \note The UDP support in uIP is still not entirely complete; there\r
+ * is no support for sending or receiving broadcast or multicast\r
+ * packets, but it works well enough to support a number of vital\r
+ * applications such as DNS queries, though\r
+ */\r
+\r
+/**\r
+ * Toggles whether UDP support should be compiled in or not.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_UDP\r
+#define UIP_UDP UIP_CONF_UDP\r
+#else /* UIP_CONF_UDP */\r
+#define UIP_UDP           1\r
+#endif /* UIP_CONF_UDP */\r
+\r
+/**\r
+ * Toggles if UDP checksums should be used or not.\r
+ *\r
+ * \note Support for UDP checksums is currently not included in uIP,\r
+ * so this option has no function.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_UDP_CHECKSUMS\r
+#define UIP_UDP_CHECKSUMS UIP_CONF_UDP_CHECKSUMS\r
+#else\r
+#define UIP_UDP_CHECKSUMS 0\r
+#endif\r
+\r
+/**\r
+ * The maximum amount of concurrent UDP connections.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_UDP_CONNS\r
+#define UIP_UDP_CONNS UIP_CONF_UDP_CONNS\r
+#else /* UIP_CONF_UDP_CONNS */\r
+#define UIP_UDP_CONNS    10\r
+#endif /* UIP_CONF_UDP_CONNS */\r
+\r
+/**\r
+ * The name of the function that should be called when UDP datagrams arrive.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \defgroup uipopttcp TCP configuration options\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * Toggles whether UDP support should be compiled in or not.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_TCP\r
+#define UIP_TCP UIP_CONF_TCP\r
+#else /* UIP_CONF_UDP */\r
+#define UIP_TCP           1\r
+#endif /* UIP_CONF_UDP */\r
+\r
+/**\r
+ * Determines if support for opening connections from uIP should be\r
+ * compiled in.\r
+ *\r
+ * If the applications that are running on top of uIP for this project\r
+ * do not need to open outgoing TCP connections, this configuration\r
+ * option can be turned off to reduce the code size of uIP.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_ACTIVE_OPEN\r
+#define UIP_ACTIVE_OPEN 1\r
+#else /* UIP_CONF_ACTIVE_OPEN */\r
+#define UIP_ACTIVE_OPEN UIP_CONF_ACTIVE_OPEN\r
+#endif /* UIP_CONF_ACTIVE_OPEN */\r
+\r
+/**\r
+ * The maximum number of simultaneously open TCP connections.\r
+ *\r
+ * Since the TCP connections are statically allocated, turning this\r
+ * configuration knob down results in less RAM used. Each TCP\r
+ * connection requires approximately 30 bytes of memory.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_MAX_CONNECTIONS\r
+#define UIP_CONNS       10\r
+#else /* UIP_CONF_MAX_CONNECTIONS */\r
+#define UIP_CONNS UIP_CONF_MAX_CONNECTIONS\r
+#endif /* UIP_CONF_MAX_CONNECTIONS */\r
+\r
+\r
+/**\r
+ * The maximum number of simultaneously listening TCP ports.\r
+ *\r
+ * Each listening TCP port requires 2 bytes of memory.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_MAX_LISTENPORTS\r
+#define UIP_LISTENPORTS 20\r
+#else /* UIP_CONF_MAX_LISTENPORTS */\r
+#define UIP_LISTENPORTS UIP_CONF_MAX_LISTENPORTS\r
+#endif /* UIP_CONF_MAX_LISTENPORTS */\r
+\r
+/**\r
+ * Determines if support for TCP urgent data notification should be\r
+ * compiled in.\r
+ *\r
+ * Urgent data (out-of-band data) is a rarely used TCP feature that\r
+ * very seldom would be required.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#if !defined(UIP_URGDATA)\r
+#define UIP_URGDATA      0\r
+#endif\r
+\r
+/**\r
+ * The initial retransmission timeout counted in timer pulses.\r
+ *\r
+ * This should not be changed.\r
+ */\r
+#if !defined(UIP_RTO)\r
+#define UIP_RTO         3\r
+#endif\r
+\r
+/**\r
+ * The maximum number of times a segment should be retransmitted\r
+ * before the connection should be aborted.\r
+ *\r
+ * This should not be changed.\r
+ */\r
+#if !defined(UIP_MAXRTX)\r
+#define UIP_MAXRTX      8\r
+#endif\r
+\r
+/**\r
+ * The maximum number of times a SYN segment should be retransmitted\r
+ * before a connection request should be deemed to have been\r
+ * unsuccessful.\r
+ *\r
+ * This should not need to be changed.\r
+ */\r
+#if !defined(UIP_MAXSYNRTX)\r
+#define UIP_MAXSYNRTX      5\r
+#endif\r
+\r
+/**\r
+ * The TCP maximum segment size.\r
+ *\r
+ * This is should not be to set to more than\r
+ * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.\r
+ */\r
+#ifdef UIP_CONF_TCP_MSS\r
+#define UIP_TCP_MSS UIP_CONF_TCP_MSS\r
+#else\r
+#define UIP_TCP_MSS     (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)\r
+#endif\r
+\r
+/**\r
+ * The size of the advertised receiver's window.\r
+ *\r
+ * Should be set low (i.e., to the size of the uip_buf buffer) if the\r
+ * application is slow to process incoming data, or high (32768 bytes)\r
+ * if the application processes data quickly.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_RECEIVE_WINDOW\r
+#define UIP_RECEIVE_WINDOW UIP_TCP_MSS\r
+#else\r
+#define UIP_RECEIVE_WINDOW UIP_CONF_RECEIVE_WINDOW\r
+#endif\r
+\r
+/**\r
+ * How long a connection should stay in the TIME_WAIT state.\r
+ *\r
+ * This configuration option has no real implication, and it should be\r
+ * left untouched.\r
+ */\r
+#define UIP_TIME_WAIT_TIMEOUT 120\r
+\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \defgroup uipoptarp ARP configuration options\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * The size of the ARP table.\r
+ *\r
+ * This option should be set to a larger value if this uIP node will\r
+ * have many connections from the local network.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_ARPTAB_SIZE\r
+#define UIP_ARPTAB_SIZE UIP_CONF_ARPTAB_SIZE\r
+#else\r
+#define UIP_ARPTAB_SIZE 8\r
+#endif\r
+\r
+/**\r
+ * The maximum age of ARP table entries measured in 10ths of seconds.\r
+ *\r
+ * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD\r
+ * default).\r
+ */\r
+#define UIP_ARP_MAXAGE 120\r
+\r
+\r
+/** @} */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ * \defgroup uipoptmac layer 2 options (for ipv6)\r
+ * @{\r
+ */\r
+\r
+#define UIP_DEFAULT_PREFIX_LEN 64\r
+\r
+/** @} */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ * \defgroup uipoptsics 6lowpan options (for ipv6)\r
+ * @{\r
+ */\r
+/**\r
+ * Timeout for packet reassembly at the 6lowpan layer\r
+ * (should be < 60s)\r
+ */\r
+#ifdef SICSLOWPAN_CONF_MAXAGE\r
+#define SICSLOWPAN_REASS_MAXAGE SICSLOWPAN_CONF_MAXAGE\r
+#else\r
+#define SICSLOWPAN_REASS_MAXAGE 20\r
+#endif\r
+\r
+/**\r
+ * Do we compress the IP header or not (default: no)\r
+ */\r
+#ifndef SICSLOWPAN_CONF_COMPRESSION\r
+#define SICSLOWPAN_CONF_COMPRESSION 0\r
+#endif\r
+\r
+/**\r
+ * If we use IPHC compression, how many address contexts do we support\r
+ */\r
+#ifndef SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS \r
+#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1\r
+#endif\r
+\r
+/**\r
+ * Do we support 6lowpan fragmentation\r
+ */\r
+#ifndef SICSLOWPAN_CONF_FRAG  \r
+#define SICSLOWPAN_CONF_FRAG  0\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ * \defgroup uipoptgeneral General configuration options\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * The size of the uIP packet buffer.\r
+ *\r
+ * The uIP packet buffer should not be smaller than 60 bytes, and does\r
+ * not need to be larger than 1514 bytes. Lower size results in lower\r
+ * TCP throughput, larger size results in higher TCP throughput.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_BUFFER_SIZE\r
+#define UIP_BUFSIZE UIP_LINK_MTU + UIP_LLH_LEN\r
+#else /* UIP_CONF_BUFFER_SIZE */\r
+#define UIP_BUFSIZE UIP_CONF_BUFFER_SIZE\r
+#endif /* UIP_CONF_BUFFER_SIZE */\r
+\r
+\r
+/**\r
+ * Determines if statistics support should be compiled in.\r
+ *\r
+ * The statistics is useful for debugging and to show the user.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_STATISTICS\r
+#define UIP_STATISTICS  0\r
+#else /* UIP_CONF_STATISTICS */\r
+#define UIP_STATISTICS UIP_CONF_STATISTICS\r
+#endif /* UIP_CONF_STATISTICS */\r
+\r
+/**\r
+ * Determines if logging of certain events should be compiled in.\r
+ *\r
+ * This is useful mostly for debugging. The function uip_log()\r
+ * must be implemented to suit the architecture of the project, if\r
+ * logging is turned on.\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifndef UIP_CONF_LOGGING\r
+#define UIP_LOGGING     0\r
+#else /* UIP_CONF_LOGGING */\r
+#define UIP_LOGGING     UIP_CONF_LOGGING\r
+#endif /* UIP_CONF_LOGGING */\r
+\r
+/**\r
+ * Broadcast support.\r
+ *\r
+ * This flag configures IP broadcast support. This is useful only\r
+ * together with UDP.\r
+ *\r
+ * \hideinitializer\r
+ *\r
+ */\r
+#ifndef UIP_CONF_BROADCAST\r
+#define UIP_BROADCAST 0\r
+#else /* UIP_CONF_BROADCAST */\r
+#define UIP_BROADCAST UIP_CONF_BROADCAST\r
+#endif /* UIP_CONF_BROADCAST */\r
+\r
+/**\r
+ * Print out a uIP log message.\r
+ *\r
+ * This function must be implemented by the module that uses uIP, and\r
+ * is called by uIP whenever a log message is generated.\r
+ */\r
+void uip_log(char *msg);\r
+\r
+/**\r
+ * The link level header length.\r
+ *\r
+ * This is the offset into the uip_buf where the IP header can be\r
+ * found. For Ethernet, this should be set to 14. For SLIP, this\r
+ * should be set to 0.\r
+ *\r
+ * \note we probably won't use this constant for other link layers than\r
+ * ethernet as they have variable header length (this is due to variable\r
+ * number and type of address fields and to optional security features)\r
+ * E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14\r
+ *       802.11 -> 4 + (6*3/4) + 2\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_LLH_LEN\r
+#define UIP_LLH_LEN UIP_CONF_LLH_LEN\r
+#else /* UIP_LLH_LEN */\r
+#define UIP_LLH_LEN     14\r
+#endif /* UIP_CONF_LLH_LEN */\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+/**\r
+ * \defgroup uipoptcpu CPU architecture configuration\r
+ * @{\r
+ *\r
+ * The CPU architecture configuration is where the endianess of the\r
+ * CPU on which uIP is to be run is specified. Most CPUs today are\r
+ * little endian, and the most notable exception are the Motorolas\r
+ * which are big endian. The BYTE_ORDER macro should be changed to\r
+ * reflect the CPU architecture on which uIP is to be run.\r
+ */\r
+\r
+/**\r
+ * The byte order of the CPU architecture on which uIP is to be run.\r
+ *\r
+ * This option can be either UIP_BIG_ENDIAN (Motorola byte order) or\r
+ * UIP_LITTLE_ENDIAN (Intel byte order).\r
+ *\r
+ * \hideinitializer\r
+ */\r
+#ifdef UIP_CONF_BYTE_ORDER\r
+#define UIP_BYTE_ORDER     UIP_CONF_BYTE_ORDER\r
+#else /* UIP_CONF_BYTE_ORDER */\r
+#define UIP_BYTE_ORDER     UIP_LITTLE_ENDIAN\r
+#endif /* UIP_CONF_BYTE_ORDER */\r
+\r
+/** @} */\r
+/*------------------------------------------------------------------------------*/\r
+\r
+#include <ff.h>\r
+#include <stdbool.h>\r
+#include <stdint.h>\r
+\r
+#include "timer.h"\r
+\r
+typedef uint8_t u8_t;\r
+typedef uint16_t u16_t;\r
+typedef uint32_t u32_t;\r
+typedef uint32_t uip_stats_t;\r
+\r
+/**\r
+ * \defgroup uipoptapp Application specific configurations\r
+ * @{\r
+ *\r
+ * An uIP application is implemented using a single application\r
+ * function that is called by uIP whenever a TCP/IP event occurs. The\r
+ * name of this function must be registered with uIP at compile time\r
+ * using the UIP_APPCALL definition.\r
+ *\r
+ * uIP applications can store the application state within the\r
+ * uip_conn structure by specifying the type of the application\r
+ * structure by typedef:ing the type uip_tcp_appstate_t and uip_udp_appstate_t.\r
+ *\r
+ * The file containing the definitions must be included in the\r
+ * uipopt.h file.\r
+ *\r
+ * The following example illustrates how this can look.\r
+ \code\r
+\r
+ void httpd_appcall(void);\r
+ #define UIP_APPCALL     httpd_appcall\r
+\r
+ struct httpd_state {\r
+ u8_t state;\r
+ u16_t count;\r
+ char *dataptr;\r
+ char *script;\r
+ };\r
+ typedef struct httpd_state uip_tcp_appstate_t\r
+ \endcode\r
+*/\r
+#define UIP_UDP_APPCALL uIPManagement_UDPCallback\r
+void UIP_UDP_APPCALL(void);\r
+\r
+/**\r
+ * \var #define UIP_APPCALL\r
+ *\r
+ * The name of the application function that uIP should call in\r
+ * response to TCP/IP events.\r
+ *\r
+ */\r
+#define UIP_APPCALL     uIPManagement_TCPCallback\r
+void UIP_APPCALL(void);\r
+\r
+/**\r
+ * \var typedef uip_tcp_appstate_t\r
+ *\r
+ * The type of the application state that is to be stored in the\r
+ * uip_conn structure. This usually is typedef:ed to a struct holding\r
+ * application state information.\r
+ */\r
+typedef union\r
+{\r
+       struct\r
+       {\r
+               uint8_t  CurrentState;\r
+               uint8_t  NextState;\r
+               \r
+               char     FileName[MAX_URI_LENGTH];\r
+               FIL      FileHandle;\r
+               bool     FileOpen;\r
+               uint32_t ACKedFilePos;\r
+               uint16_t SentChunkSize;\r
+       } HTTPServer;\r
+       \r
+       struct\r
+       {\r
+               uint8_t  CurrentState;\r
+               uint8_t  NextState;\r
+               \r
+               uint8_t  IssuedCommand;\r
+       } TELNETServer;\r
+} uip_tcp_appstate_t;\r
+\r
+/**\r
+ * \var typedef uip_udp_appstate_t\r
+ *\r
+ * The type of the application state that is to be stored in the\r
+ * uip_conn structure. This usually is typedef:ed to a struct holding\r
+ * application state information.\r
+ */\r
+typedef union\r
+{\r
+       struct\r
+       {\r
+               uint8_t      CurrentState;\r
+               struct timer Timeout;\r
+               \r
+               struct\r
+               {\r
+                       uint8_t AllocatedIP[4];\r
+                       uint8_t Netmask[4];\r
+                       uint8_t GatewayIP[4];\r
+                       uint8_t ServerIP[4];\r
+               } DHCPOffer_Data;\r
+       } DHCPClient;\r
+} uip_udp_appstate_t;\r
+/** @} */\r
+\r
+#endif /* __UIPOPT_H__ */\r
+/** @} */\r
+/** @} */\r