]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Labs/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
Sync FreeRTOS-Labs -CLI -TCP -Trace with the version in FreeRTOS-Plus.
[freertos] / FreeRTOS-Labs / Source / FreeRTOS-Plus-TCP / FreeRTOS_IP.c
index d6c36f31c5fef417c7bff7f08c173041e8f94756..c94f55dd74d5ecdd829f090f21a822194551c9d8 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * FreeRTOS+TCP 191100 experimental\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ * FreeRTOS+TCP V2.2.0\r
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
  * this software and associated documentation files (the "Software"), to deal in\r
@@ -65,7 +65,9 @@ a constant. */
 \r
 \r
 /* Time delay between repeated attempts to initialise the network hardware. */\r
-#define ipINITIALISATION_RETRY_DELAY   ( pdMS_TO_TICKS( 3000 ) )\r
+#ifndef ipINITIALISATION_RETRY_DELAY\r
+       #define ipINITIALISATION_RETRY_DELAY    ( pdMS_TO_TICKS( 3000 ) )\r
+#endif\r
 \r
 /* Defines how often the ARP timer callback function is executed.  The time is\r
 shorted in the Windows simulator as simulated time is not real time. */\r
@@ -394,6 +396,12 @@ struct freertos_sockaddr xAddress;
                                prvHandleEthernetPacket( ( NetworkBufferDescriptor_t * ) ( xReceivedEvent.pvData ) );\r
                                break;\r
 \r
+                       case eNetworkTxEvent:\r
+                               /* Send a network packet. The ownership will  be transferred to\r
+                               the driver, which will release it after delivery. */\r
+                               xNetworkInterfaceOutput( ( NetworkBufferDescriptor_t * ) ( xReceivedEvent.pvData ), pdTRUE );\r
+                               break;\r
+\r
                        case eARPTimerEvent :\r
                                /* The ARP timer has expired, process the ARP cache. */\r
                                vARPAgeCache();\r
@@ -820,20 +828,20 @@ void *pvReturn;
 /*-----------------------------------------------------------*/\r
 \r
 NetworkBufferDescriptor_t *pxDuplicateNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer,\r
-       BaseType_t xNewLength )\r
+       size_t uxNewLength )\r
 {\r
 NetworkBufferDescriptor_t * pxNewBuffer;\r
 \r
        /* This function is only used when 'ipconfigZERO_COPY_TX_DRIVER' is set to 1.\r
        The transmit routine wants to have ownership of the network buffer\r
        descriptor, because it will pass the buffer straight to DMA. */\r
-       pxNewBuffer = pxGetNetworkBufferWithDescriptor( ( size_t ) xNewLength, ( TickType_t ) 0 );\r
+       pxNewBuffer = pxGetNetworkBufferWithDescriptor( uxNewLength, ( TickType_t ) 0 );\r
 \r
        if( pxNewBuffer != NULL )\r
        {\r
                /* Set the actual packet size in case a bigger buffer than requested\r
                was returned. */\r
-               pxNewBuffer->xDataLength = xNewLength;\r
+               pxNewBuffer->xDataLength = uxNewLength;\r
 \r
                /* Copy the original packet information. */\r
                pxNewBuffer->ulIPAddress = pxNetworkBuffer->ulIPAddress;\r
@@ -986,7 +994,10 @@ BaseType_t xReturn = pdFALSE;
 \r
                                /* Added to prevent ARP flood to gateway.  Ensure the\r
                                gateway is on the same subnet as the IP address. */\r
-                               configASSERT( ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) == ( xNetworkAddressing.ulGatewayAddress & xNetworkAddressing.ulNetMask ) );\r
+                               if( xNetworkAddressing.ulGatewayAddress != 0ul )\r
+                               {\r
+                                       configASSERT( ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) == ( xNetworkAddressing.ulGatewayAddress & xNetworkAddressing.ulNetMask ) );\r
+                               }\r
                        }\r
                        #endif /* ipconfigUSE_DHCP == 1 */\r
 \r
@@ -1111,7 +1122,8 @@ void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress, const uint3
                                pxNetworkBuffer->pucEthernetBuffer[ ipSOCKET_OPTIONS_OFFSET ] = FREERTOS_SO_UDPCKSUM_OUT;\r
                                pxNetworkBuffer->ulIPAddress = ulIPAddress;\r
                                pxNetworkBuffer->usPort = ipPACKET_CONTAINS_ICMP_DATA;\r
-                               pxNetworkBuffer->xDataLength = xNumberOfBytesToSend + sizeof( ICMPHeader_t );\r
+                               /* xDataLength is the size of the total packet, including the Ethernet header. */\r
+                               pxNetworkBuffer->xDataLength = xNumberOfBytesToSend + sizeof( ICMPPacket_t );\r
 \r
                                /* Send to the stack. */\r
                                xStackTxEvent.pvData = pxNetworkBuffer;\r
@@ -1600,23 +1612,24 @@ uint8_t ucProtocol;
 \r
                                        /* Only proceed if the payload length indicated in the header\r
                                        appears to be valid. */\r
-                                       if ( pxNetworkBuffer->xDataLength >= sizeof( UDPPacket_t ) )\r
+                                       if ( ( pxNetworkBuffer->xDataLength >= sizeof( UDPPacket_t ) ) && ( FreeRTOS_ntohs( pxUDPPacket->xUDPHeader.usLength ) >= sizeof( UDPHeader_t ) ) )\r
                                        {\r
-                                               /* Ensure that downstream UDP packet handling has the lesser\r
-                                                * of: the actual network buffer Ethernet frame length, or\r
-                                                * the sender's UDP packet header payload length, minus the\r
-                                                * size of the UDP header.\r
-                                                *\r
-                                                * The size of the UDP packet structure in this implementation\r
-                                                * includes the size of the Ethernet header, the size of\r
-                                                * the IP header, and the size of the UDP header.\r
+                                       size_t uxPayloadSize_1, uxPayloadSize_2;\r
+                                               /* The UDP payload size can be calculated by subtracting the\r
+                                                * header size from `xDataLength`.\r
+                                                * However, the `xDataLength` may be longer that expected,\r
+                                                * e.g. when a small packet is padded with zero's.\r
+                                                * The UDP header contains a field `usLength` reflecting\r
+                                                * the payload size plus the UDP header ( 8 bytes ).\r
+                                                * Set `xDataLength` to the size of the headers,\r
+                                                * plus the lower of the two calculated payload sizes.\r
                                                 */\r
 \r
-                                               pxNetworkBuffer->xDataLength -= sizeof( UDPPacket_t );\r
-                                               if( ( FreeRTOS_ntohs( pxUDPPacket->xUDPHeader.usLength ) - sizeof( UDPHeader_t ) ) <\r
-                                                               pxNetworkBuffer->xDataLength )\r
+                                               uxPayloadSize_1 = pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t );\r
+                                               uxPayloadSize_2 = FreeRTOS_ntohs( pxUDPPacket->xUDPHeader.usLength ) - sizeof( UDPHeader_t );\r
+                                               if( uxPayloadSize_1 > uxPayloadSize_2 )\r
                                                {\r
-                                                       pxNetworkBuffer->xDataLength = FreeRTOS_ntohs( pxUDPPacket->xUDPHeader.usLength ) - sizeof( UDPHeader_t );\r
+                                                       pxNetworkBuffer->xDataLength = uxPayloadSize_2 + sizeof( UDPPacket_t );\r
                                                }\r
 \r
                                                /* Fields in pxNetworkBuffer (usPort, ulIPAddress) are network order. */\r