/*\r
- * FreeRTOS+TCP V2.0.11\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
\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
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
/*-----------------------------------------------------------*/\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
\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
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
\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