mirror of
https://github.com/FreeRTOS/FreeRTOS-Plus-TCP
synced 2025-10-21 15:10:39 +08:00

* use matching endpoint instead of first endpoint * update with @htibosch latest changes * fix formatting * fix misra and spellings * code clean up * wip separation IP * separation IP * separation IP * wip buils separation * fixing unit tests * fix unit tests * fix formatting * wip , next prvProcessNetworkDownEvent * adding build separation to ip utils * fix unit tests * fix formatting * update xCheckRequiresARPResolution * update vARPAgeCache * update vARPAgeCache * misra checks * fix formatting * fix misra * wip s/w: FreeRTOS_recvfrom * wip sockets till prvSocketBindAdd * adding build separation to FreeRTOS_Sockets.c * add build config support to FreeRTOS_inet_pton FreeRTOS_inet_ntop FreeRTOS_GetIPType * adding build config support * fix build issues * check misra * minor fix * fix unit tests * fix unit tests build * Uncrustify: triggered by comment * fix formatting * build separate FreeRTOS_TCP_IP.c * build separate FreeRTOS_TCP_Reception.c * misra fix * build separate FreeRTOS_TCP_State_Handling.c * build separate FreeRTOS_TCP_Transmission.c * build separate FreeRTOS_TCP_Transmission.c fix build * adding build separation for FreeRTOS_TCP_Utils.c and FreeRTOS_TCP_Transmission.c * fix formatting * UDP: Build Separation Changes Changes in UDP files to support IPv4 and IPv6 Build Separation. * fix IPv4 build issues post build sep merge * IPv4 only build * more - fix IPv4 build issues post build sep merge * fix DHCP v4 * fix v6 build * add v6 build checks * separate v4v6 tcp files * fix rebase conflicts * fix formatting * fix build when TCP disabled * add more build checks * adding more ipv4 flags to v4 specific files * fix udp unit tests * add build config build tests to CI * fix formatting * fix build checks yml * DNS: Build Separation Changes Changes for supporting IPv4 and IPv6 build separation in DNS. * Routing: Build Separtion Changes Changes for supporting IPv4 and IPv6 build separation in Routing. * DNS build fix and rebase to latest changes * fix formatting * fix unit tests * fix formatting * fix MISRA * updaating ARP functions to be available on all configs * plus_tcp_demo_cli build config changes * fix formatting, guard FreeRTOS_FillEndPoint inside ipconfigUSE_IPv4 check * more build sepration changes to routing * build separation plus_tcp_demo_cli.c * fixing issues with routing, fix formatting * adding pxFindEndpoint of plus_tcp_demo_cli inside ipconfigUSE_IPv6 != 0 check * minor build fix * moving usDNSType of endpoint struct out of ipconfigUSE_IPv6 check * update code to use IP family while using socket APIs * moving vSetMultiCastIPv4MacAddress to FreeRTOS_IPv4_Utils.c * fix routing * build DNS only if IPv4 is enabled * fix review feedback * fix build * fix build * fix formatting * fix comment * fix wrt reeview feedback * fix unit tests * cleanup FreeRTOS_MatchingEndpoint * fix FreeRTOS_MatchingEndpoint to handle cusstom frames --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: shubnil <103672514+shubnil@users.noreply.github.com>
174 lines
6.6 KiB
C
174 lines
6.6 KiB
C
/*
|
|
* FreeRTOS+TCP <DEVELOPMENT BRANCH>
|
|
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
* the Software without restriction, including without limitation the rights to
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* http://aws.amazon.com/freertos
|
|
* http://www.FreeRTOS.org
|
|
*/
|
|
|
|
/**
|
|
* @file FreeRTOS_UDP_IP.c
|
|
* @brief This file has the source code for the UDP-IP functionality of the FreeRTOS+TCP
|
|
* network stack.
|
|
*/
|
|
|
|
/* Standard includes. */
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
/* FreeRTOS includes. */
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "queue.h"
|
|
#include "semphr.h"
|
|
#include "event_groups.h"
|
|
#include "list.h"
|
|
|
|
/* FreeRTOS+TCP includes. */
|
|
#include "FreeRTOS_IP.h"
|
|
#include "FreeRTOS_Sockets.h"
|
|
#include "FreeRTOS_IP_Private.h"
|
|
#include "FreeRTOS_UDP_IP.h"
|
|
#include "FreeRTOS_ARP.h"
|
|
#include "FreeRTOS_DNS.h"
|
|
#include "FreeRTOS_DHCP.h"
|
|
#include "FreeRTOS_ND.h"
|
|
#include "FreeRTOS_IP_Utils.h"
|
|
#include "NetworkInterface.h"
|
|
#include "NetworkBufferManagement.h"
|
|
|
|
#if ( ipconfigUSE_DNS == 1 )
|
|
#include "FreeRTOS_DNS.h"
|
|
#endif
|
|
|
|
/** @brief The expected IP version and header length coded into the IP header itself. */
|
|
#define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 )
|
|
|
|
/** @brief Part of the Ethernet and IP headers are always constant when sending an IPv4
|
|
* UDP packet. This array defines the constant parts, allowing this part of the
|
|
* packet to be filled in using a simple memcpy() instead of individual writes. */
|
|
/*lint -e708 (Info -- union initialization). */
|
|
UDPPacketHeader_t xDefaultPartUDPPacketHeader =
|
|
{
|
|
/* .ucBytes : */
|
|
{
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Ethernet source MAC address. */
|
|
0x08, 0x00, /* Ethernet frame type. */
|
|
ipIP_VERSION_AND_HEADER_LENGTH_BYTE, /* ucVersionHeaderLength. */
|
|
0x00, /* ucDifferentiatedServicesCode. */
|
|
0x00, 0x00, /* usLength. */
|
|
0x00, 0x00, /* usIdentification. */
|
|
0x00, 0x00, /* usFragmentOffset. */
|
|
ipconfigUDP_TIME_TO_LIVE, /* ucTimeToLive */
|
|
ipPROTOCOL_UDP, /* ucProtocol. */
|
|
0x00, 0x00, /* usHeaderChecksum. */
|
|
0x00, 0x00, 0x00, 0x00 /* Source IP address. */
|
|
}
|
|
};
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/**
|
|
* @brief Process the generated UDP packet and do other checks before sending the
|
|
* packet such as ARP cache check and address resolution.
|
|
*
|
|
* @param[in] pxNetworkBuffer: The network buffer carrying the packet.
|
|
*/
|
|
void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer )
|
|
{
|
|
const UDPPacket_t * pxUDPPacket;
|
|
|
|
/* Map the UDP packet onto the start of the frame. */
|
|
|
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
|
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
|
pxUDPPacket = ( ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );
|
|
|
|
switch( pxUDPPacket->xEthernetHeader.usFrameType )
|
|
{
|
|
#if ( ipconfigUSE_IPv4 != 0 )
|
|
case ipIPv4_FRAME_TYPE:
|
|
vProcessGeneratedUDPPacket_IPv4( pxNetworkBuffer );
|
|
break;
|
|
#endif
|
|
#if ( ipconfigUSE_IPv6 != 0 )
|
|
case ipIPv6_FRAME_TYPE:
|
|
vProcessGeneratedUDPPacket_IPv6( pxNetworkBuffer );
|
|
break;
|
|
#endif
|
|
default:
|
|
/* do nothing, coverity happy */
|
|
break;
|
|
}
|
|
}
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/**
|
|
* @brief Process the received UDP packet.
|
|
*
|
|
* @param[in] pxNetworkBuffer: The network buffer carrying the UDP packet.
|
|
* @param[in] usPort: The port number on which this packet was received.
|
|
* @param[out] pxIsWaitingForARPResolution: If the packet is awaiting ARP resolution,
|
|
* this pointer will be set to pdTRUE. pdFALSE otherwise.
|
|
*
|
|
* @return pdPASS in case the UDP packet could be processed. Else pdFAIL is returned.
|
|
*/
|
|
BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffer,
|
|
uint16_t usPort,
|
|
BaseType_t * pxIsWaitingForARPResolution )
|
|
{
|
|
/* Returning pdPASS means that the packet was consumed, released. */
|
|
BaseType_t xReturn = pdFAIL;
|
|
|
|
configASSERT( pxNetworkBuffer != NULL );
|
|
configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );
|
|
|
|
/* Map the ethernet buffer to the UDPPacket_t struct for easy access to the fields. */
|
|
|
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
|
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
|
const UDPPacket_t * pxUDPPacket = ( ( const UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );
|
|
|
|
switch( pxUDPPacket->xEthernetHeader.usFrameType )
|
|
{
|
|
#if ( ipconfigUSE_IPv4 != 0 )
|
|
case ipIPv4_FRAME_TYPE:
|
|
xReturn = xProcessReceivedUDPPacket_IPv4( pxNetworkBuffer,
|
|
usPort, pxIsWaitingForARPResolution );
|
|
break;
|
|
#endif
|
|
#if ( ipconfigUSE_IPv6 != 0 )
|
|
case ipIPv6_FRAME_TYPE:
|
|
xReturn = xProcessReceivedUDPPacket_IPv6( pxNetworkBuffer,
|
|
usPort, pxIsWaitingForARPResolution );
|
|
break;
|
|
#endif
|
|
default:
|
|
/* do nothing, coverity happy */
|
|
break;
|
|
}
|
|
|
|
return xReturn;
|
|
}
|
|
/*-----------------------------------------------------------*/
|