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