Documentation improvements - put driver example code into its own section, fix incorr...
[pub/USBasp.git] / Demos / Device / ClassDriver / RNDISEthernet / Lib / TCP.h
index b5152b3..4f2cdae 100644 (file)
@@ -1,21 +1,21 @@
 /*
              LUFA Library
      Copyright (C) Dean Camera, 2010.
 /*
              LUFA Library
      Copyright (C) Dean Camera, 2010.
-              
+
   dean [at] fourwalledcubicle [dot] com
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
 */
 
 /*
   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
-  Permission to use, copy, modify, distribute, and sell this 
+  Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
   software and its documentation for any purpose is hereby granted
-  without fee, provided that the above copyright notice appear in 
+  without fee, provided that the above copyright notice appear in
   all copies and that both that the copyright notice and this
   all copies and that both that the copyright notice and this
-  permission notice and warranty disclaimer appear in supporting 
-  documentation, and that the name of the author not be used in 
-  advertising or publicity pertaining to distribution of the 
+  permission notice and warranty disclaimer appear in supporting
+  documentation, and that the name of the author not be used in
+  advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
   The author disclaim all warranties with regard to this
   software without specific, written prior permission.
 
   The author disclaim all warranties with regard to this
        /* Includes: */
                #include <avr/io.h>
                #include <stdbool.h>
        /* Includes: */
                #include <avr/io.h>
                #include <stdbool.h>
-               
+
                #include "EthernetProtocols.h"
                #include "Ethernet.h"
                #include "ProtocolDecoders.h"
                #include "EthernetProtocols.h"
                #include "Ethernet.h"
                #include "ProtocolDecoders.h"
-               
+
        /* Macros: */
                /** Maximum number of TCP ports which can be open at the one time. */
                #define MAX_OPEN_TCP_PORTS              1
        /* Macros: */
                /** Maximum number of TCP ports which can be open at the one time. */
                #define MAX_OPEN_TCP_PORTS              1
 
                /** TCP window size, giving the maximum number of bytes which can be buffered at the one time. */
                #define TCP_WINDOW_SIZE                 512
 
                /** TCP window size, giving the maximum number of bytes which can be buffered at the one time. */
                #define TCP_WINDOW_SIZE                 512
-               
+
                /** Port number for HTTP transmissions. */
                #define TCP_PORT_HTTP                   SwapEndian_16(80)
                /** Port number for HTTP transmissions. */
                #define TCP_PORT_HTTP                   SwapEndian_16(80)
-               
+
                /** Data direction indicator for a TCP application buffer, indicating data from host-to-device. */
                #define TCP_PACKETDIR_IN                false
 
                /** Data direction indicator for a TCP application buffer, indicating data from device-to-host. */
                #define TCP_PACKETDIR_OUT               true
                /** Data direction indicator for a TCP application buffer, indicating data from host-to-device. */
                #define TCP_PACKETDIR_IN                false
 
                /** Data direction indicator for a TCP application buffer, indicating data from device-to-host. */
                #define TCP_PACKETDIR_OUT               true
-               
+
                /** Congestion Window Reduced TCP flag mask. */
                #define TCP_FLAG_CWR                    (1 << 7)
 
                /** Congestion Window Reduced TCP flag mask. */
                #define TCP_FLAG_CWR                    (1 << 7)
 
@@ -86,7 +86,7 @@
 
                /** Connection Finalize TCP flag mask. */
                #define TCP_FLAG_FIN                    (1 << 0)
 
                /** Connection Finalize TCP flag mask. */
                #define TCP_FLAG_FIN                    (1 << 0)
-               
+
                /** Application macro: Determines if the given application buffer contains a packet received from the host
                 *
                 *  \param[in] Buffer  Application buffer to check
                /** Application macro: Determines if the given application buffer contains a packet received from the host
                 *
                 *  \param[in] Buffer  Application buffer to check
                 *
                 *  \return Boolean true if the buffer has been captured by the application for device-to-host transmissions, false otherwise
                 */
                 *
                 *  \return Boolean true if the buffer has been captured by the application for device-to-host transmissions, false otherwise
                 */
-               #define TCP_APP_HAVE_CAPTURED_BUFFER(Buffer) (!(Buffer->Ready) && Buffer->InUse && \
-                                  
-                           (Buffer->Direction == TCP_PACKETDIR_OUT))
+               #define TCP_APP_HAVE_CAPTURED_BUFFER(Buffer) (!(Buffer->Ready) && Buffer->InUse && (Buffer->Direction == TCP_PACKETDIR_OUT))
 
                /** Application macro: Indicates if the application can lock the buffer for multiple continued device-to-host transmissions.
                 *
 
                /** Application macro: Indicates if the application can lock the buffer for multiple continued device-to-host transmissions.
                 *
                 *  \param[in] Buffer  Application buffer to clear
                 */
                #define TCP_APP_CLEAR_BUFFER(Buffer)         MACROS{ Buffer->Ready = false; Buffer->Length = 0; }MACROE
                 *  \param[in] Buffer  Application buffer to clear
                 */
                #define TCP_APP_CLEAR_BUFFER(Buffer)         MACROS{ Buffer->Ready = false; Buffer->Length = 0; }MACROE
-               
+
                /** Application macro: Closes an open connection to a host.
                 *
                 *  \param[in] Connection  Open TCP connection to close
                /** Application macro: Closes an open connection to a host.
                 *
                 *  \param[in] Connection  Open TCP connection to close
                        TCP_Port_Closed            = 0, /**< TCP port closed, no connections to a host may be made on this port. */
                        TCP_Port_Open              = 1, /**< TCP port open, connections to a host may be made on this port. */
                };
                        TCP_Port_Closed            = 0, /**< TCP port closed, no connections to a host may be made on this port. */
                        TCP_Port_Open              = 1, /**< TCP port open, connections to a host may be made on this port. */
                };
-       
+
                /** Enum for possible TCP connection states. */
                enum TCP_ConnectionStates_t
                {
                /** Enum for possible TCP connection states. */
                enum TCP_ConnectionStates_t
                {
                        TCP_Connection_Closing     = 7, /**< Unused */
                        TCP_Connection_LastACK     = 8, /**< Unused */
                        TCP_Connection_TimeWait    = 9, /**< Unused */
                        TCP_Connection_Closing     = 7, /**< Unused */
                        TCP_Connection_LastACK     = 8, /**< Unused */
                        TCP_Connection_TimeWait    = 9, /**< Unused */
-                       TCP_Connection_Closed      = 10, /**< Connection closed in both directions */                   
+                       TCP_Connection_Closed      = 10, /**< Connection closed in both directions */
                };
                };
-       
+
        /* Type Defines: */
                /** Type define for a TCP connection buffer structure, including size, data and direction. */
                typedef struct
        /* Type Defines: */
                /** Type define for a TCP connection buffer structure, including size, data and direction. */
                typedef struct
                /** Type define for a TCP connection information structure. */
                typedef struct
                {
                /** Type define for a TCP connection information structure. */
                typedef struct
                {
-                       uint32_t               SequenceNumberIn; /**< Current TCP sequence number for host-to-device */ 
+                       uint32_t               SequenceNumberIn; /**< Current TCP sequence number for host-to-device */
                        uint32_t               SequenceNumberOut; /**< Current TCP sequence number for device-to-host */
                        TCP_ConnectionBuffer_t Buffer; /**< Connection application data buffer */
                } TCP_ConnectionInfo_t;
                        uint32_t               SequenceNumberOut; /**< Current TCP sequence number for device-to-host */
                        TCP_ConnectionBuffer_t Buffer; /**< Connection application data buffer */
                } TCP_ConnectionInfo_t;
                {
                        uint16_t               SourcePort; /**< Source port of the TCP packet */
                        uint16_t               DestinationPort; /**< Destination port of the TCP packet */
                {
                        uint16_t               SourcePort; /**< Source port of the TCP packet */
                        uint16_t               DestinationPort; /**< Destination port of the TCP packet */
-                       
+
                        uint32_t               SequenceNumber; /**< Data sequence number of the packet */
                        uint32_t               AcknowledgmentNumber; /**< Data acknowledgment number of the packet */
                        uint32_t               SequenceNumber; /**< Data sequence number of the packet */
                        uint32_t               AcknowledgmentNumber; /**< Data acknowledgment number of the packet */
-                       
+
                        unsigned char          Reserved : 4; /**< Reserved, must be all 0 */
                        unsigned char          DataOffset : 4; /**< Offset of the data from the start of the header, in 4 byte chunks */
                        uint8_t                Flags; /**< TCP packet flags */
                        uint16_t               WindowSize; /**< Current data window size (bytes remaining in reception buffer) */
                        unsigned char          Reserved : 4; /**< Reserved, must be all 0 */
                        unsigned char          DataOffset : 4; /**< Offset of the data from the start of the header, in 4 byte chunks */
                        uint8_t                Flags; /**< TCP packet flags */
                        uint16_t               WindowSize; /**< Current data window size (bytes remaining in reception buffer) */
-                       
+
                        uint16_t               Checksum; /**< TCP checksum */
                        uint16_t               UrgentPointer; /**< Urgent data pointer */
                } TCP_Header_t;
                        uint16_t               Checksum; /**< TCP checksum */
                        uint16_t               UrgentPointer; /**< Urgent data pointer */
                } TCP_Header_t;
-               
+
        /* Function Prototypes: */
        /* Function Prototypes: */
-               void                  TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo);
+               void                  TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo);
                void                  TCP_Init(void);
                void                  TCP_Init(void);
-               bool                  TCP_SetPortState(uint16_t Port, uint8_t State, void (*Handler)(TCP_ConnectionState_t*, TCP_ConnectionBuffer_t*));
-               uint8_t               TCP_GetPortState(uint16_t Port);
-               bool                  TCP_SetConnectionState(uint16_t Port, IP_Address_t RemoteAddress, uint16_t RemotePort, uint8_t State);
-               uint8_t               TCP_GetConnectionState(uint16_t Port, IP_Address_t RemoteAddress, uint16_t RemotePort);
-               TCP_ConnectionInfo_t* TCP_GetConnectionInfo(uint16_t Port, IP_Address_t RemoteAddress, uint16_t RemotePort);
-               int16_t               TCP_ProcessTCPPacket(void* IPHeaderInStart, void* TCPHeaderInStart, void* TCPHeaderOutStart);
+               bool                  TCP_SetPortState(const uint16_t Port,
+                                                      const uint8_t State,
+                                                      void (*Handler)(TCP_ConnectionState_t*, TCP_ConnectionBuffer_t*));
+               uint8_t               TCP_GetPortState(const uint16_t Port);
+               bool                  TCP_SetConnectionState(const uint16_t Port,
+                                                            const IP_Address_t RemoteAddress,
+                                                            const uint16_t RemotePort,
+                                                            const uint8_t State);
+               uint8_t               TCP_GetConnectionState(const uint16_t Port,
+                                                            const IP_Address_t RemoteAddress,
+                                                            const uint16_t RemotePort);
+               TCP_ConnectionInfo_t* TCP_GetConnectionInfo(const uint16_t Port,
+                                                           const IP_Address_t RemoteAddress,
+                                                           const uint16_t RemotePort);
+               int16_t               TCP_ProcessTCPPacket(void* IPHeaderInStart,
+                                                          void* TCPHeaderInStart,
+                                                          void* TCPHeaderOutStart);
 
                #if defined(INCLUDE_FROM_TCP_C)
 
                #if defined(INCLUDE_FROM_TCP_C)
-                       static uint16_t TCP_Checksum16(void* TCPHeaderOutStart, IP_Address_t SourceAddress,
-                                                                                  IP_Address_t DestinationAddress, uint16_t TCPOutSize);
+                       static uint16_t TCP_Checksum16(void* TCPHeaderOutStart,
+                                                      const IP_Address_t SourceAddress,
+                                                                                  const IP_Address_t DestinationAddress,
+                                                      uint16_t TCPOutSize);
                #endif
 
 #endif
                #endif
 
 #endif
+