From be9fe45d8ec440f7750de0f4870b28de39b10a3b Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri, 18 Dec 2020 13:09:46 -0800 Subject: [PATCH 01/33] Fix compiler warnings when the TCP Window is not used (#124) * Fix warnings when TCP window is not used * Uncrustify --- FreeRTOS_IP.c | 4 ++++ FreeRTOS_TCP_IP.c | 13 ++++++++++--- tools/tcp_utilities/tcp_mem_stats.c | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 9b57525c4e..2cf9f5d7f5 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -354,6 +354,8 @@ static BaseType_t xIPTaskInitialised = pdFALSE; /*-----------------------------------------------------------*/ +#include "random.h" + /* Coverity wants to make pvParameters const, which would make it incompatible. Leave the * function signature as is. */ @@ -434,6 +436,8 @@ static void prvIPTask( void * pvParameters ) iptraceNETWORK_EVENT_RECEIVED( xReceivedEvent.eEventType ); + vAddBytesToPool( xReceivedEvent.eEventType ); + switch( xReceivedEvent.eEventType ) { case eNetworkDownEvent: diff --git a/FreeRTOS_TCP_IP.c b/FreeRTOS_TCP_IP.c index 314d2b24bf..c62ca7e5a5 100644 --- a/FreeRTOS_TCP_IP.c +++ b/FreeRTOS_TCP_IP.c @@ -1498,6 +1498,12 @@ uxIndex += ( size_t ) ucLen; } } + + #if ( ipconfigUSE_TCP_WIN == 0 ) + /* Avoid compiler warnings when TCP window is not used. */ + ( void ) xHasSYNFlag; + #endif + return uxIndex; } /*-----------------------------------------------------------*/ @@ -2595,11 +2601,12 @@ TCPHeader_t * pxTCPHeader = &pxProtocolHeaders->xTCPHeader; const TCPWindow_t * pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow; UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength; - /* memcpy() helper variables for MISRA Rule 21.15 compliance*/ - const void * pvCopySource; - void * pvCopyDest; #if ( ipconfigUSE_TCP_WIN == 1 ) + /* memcpy() helper variables for MISRA Rule 21.15 compliance*/ + const void * pvCopySource; + void * pvCopyDest; + if( uxOptionsLength != 0U ) { /* TCP options must be sent because a packet which is out-of-order diff --git a/tools/tcp_utilities/tcp_mem_stats.c b/tools/tcp_utilities/tcp_mem_stats.c index b3aa87c54e..6a426339d1 100644 --- a/tools/tcp_utilities/tcp_mem_stats.c +++ b/tools/tcp_utilities/tcp_mem_stats.c @@ -49,7 +49,7 @@ #ifndef ipconfigTCP_MEM_STATS_MAX_ALLOCATION #define ipconfigTCP_MEM_STATS_MAX_ALLOCATION 128u - #pragma warning "ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?" +// #pragma warning "ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?" #endif #if ( ipconfigUSE_TCP_MEM_STATS != 0 ) From f39f440e82cbd9b9110750c02b4b893f1e8f9f41 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Wed, 6 Jan 2021 04:44:29 +0800 Subject: [PATCH 02/33] Move local variables to inner loop in prvNetworkInterfaceInput() (#144) Co-authored-by: Hein Tibosch Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- portable/NetworkInterface/STM32Fxx/NetworkInterface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/portable/NetworkInterface/STM32Fxx/NetworkInterface.c b/portable/NetworkInterface/STM32Fxx/NetworkInterface.c index b483fc158a..6f262127af 100644 --- a/portable/NetworkInterface/STM32Fxx/NetworkInterface.c +++ b/portable/NetworkInterface/STM32Fxx/NetworkInterface.c @@ -900,9 +900,6 @@ static void prvPassEthMessages( NetworkBufferDescriptor_t * pxDescriptor ) static BaseType_t prvNetworkInterfaceInput( void ) { - NetworkBufferDescriptor_t * pxCurDescriptor; - NetworkBufferDescriptor_t * pxNewDescriptor = NULL; - #if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 ) NetworkBufferDescriptor_t * pxFirstDescriptor = NULL; NetworkBufferDescriptor_t * pxLastDescriptor = NULL; @@ -916,7 +913,10 @@ static BaseType_t prvNetworkInterfaceInput( void ) while( ( pxDMARxDescriptor->Status & ETH_DMARXDESC_OWN ) == 0u ) { + NetworkBufferDescriptor_t * pxCurDescriptor; + NetworkBufferDescriptor_t * pxNewDescriptor = NULL; BaseType_t xAccepted = pdTRUE; + /* Get the Frame Length of the received packet: subtract 4 bytes of the CRC */ xReceivedLength = ( ( pxDMARxDescriptor->Status & ETH_DMARXDESC_FL ) >> ETH_DMARXDESC_FRAMELENGTHSHIFT ) - 4; From e6967683c220a087dff887fa6beedd533ec8583e Mon Sep 17 00:00:00 2001 From: Mark Tuttle Date: Thu, 7 Jan 2021 12:51:01 -0500 Subject: [PATCH 03/33] Update litani submodule (#147) Co-authored-by: Mark R. Tuttle --- test/litani | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/litani b/test/litani index fcc583c4a5..3fc5e02bc1 160000 --- a/test/litani +++ b/test/litani @@ -1 +1 @@ -Subproject commit fcc583c4a5d5b9bebbefce5626256283fab1edda +Subproject commit 3fc5e02bc17483352546ac4c81078fde64cab674 From 307bacbf494caa4e318a597fad4b55daa6971309 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon, 11 Jan 2021 14:10:52 -0800 Subject: [PATCH 04/33] Fix doxygen check (#149) * Update doxygen version * update the config file --- .github/workflows/ci.yml | 2 +- docs/doxygen/config.doxyfile | 192 +++++++++++++++++++++-------------- 2 files changed, 118 insertions(+), 76 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1876550c0..1021c26fec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,7 @@ jobs: - uses: actions/checkout@v2 - name: Install Doxygen run: | - wget -qO- "http://doxygen.nl/files/doxygen-1.8.20.linux.bin.tar.gz" | sudo tar --strip-components=1 -xz -C /usr/local + wget -qO- "http://doxygen.nl/files/doxygen-1.9.1.linux.bin.tar.gz" | sudo tar --strip-components=1 -xz -C /usr/local sudo apt-get install -y libclang-9-dev - name: Run Doxygen And Verify Stdout Is Empty run: | diff --git a/docs/doxygen/config.doxyfile b/docs/doxygen/config.doxyfile index 7d4821e1f1..d19f0d7b41 100644 --- a/docs/doxygen/config.doxyfile +++ b/docs/doxygen/config.doxyfile @@ -1,4 +1,4 @@ -# Doxyfile 1.8.20 +# Doxyfile 1.9.1 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. @@ -32,13 +32,13 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "FreeRTOS-Plus-TCP" +PROJECT_NAME = FreeRTOS-Plus-TCP # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = "V2.3.2" +PROJECT_NUMBER = V2.3.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a @@ -323,7 +323,10 @@ OPTIMIZE_OUTPUT_SLICE = NO # Note: For files without extension you can use no_extension as a placeholder. # # Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. +# the files are not read by doxygen. When specifying no_extension you should add +# * to the FILE_PATTERNS. +# +# Note see also the list of default file extension mappings. EXTENSION_MAPPING = @@ -468,7 +471,7 @@ LOOKUP_CACHE_SIZE = 0 # DOT_NUM_THREADS setting. # Minimum value: 0, maximum value: 32, default value: 1. -# NUM_PROC_THREADS = 1 +NUM_PROC_THREADS = 1 #--------------------------------------------------------------------------- # Build related configuration options @@ -533,6 +536,13 @@ EXTRACT_LOCAL_METHODS = NO EXTRACT_ANON_NSPACES = NO +# If this flag is set to YES, the name of an unnamed parameter in a declaration +# will be determined by the corresponding definition. By default unnamed +# parameters remain unnamed in the output. +# The default value is: YES. + +RESOLVE_UNNAMED_PARAMS = YES + # If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all # undocumented members inside documented classes or files. If set to NO these # members will be included in the various overviews, but no documentation @@ -570,11 +580,18 @@ HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES, upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# (including Cygwin) and Mac users are advised to set this option to NO. +# With the correct setting of option CASE_SENSE_NAMES doxygen will better be +# able to match the capabilities of the underlying filesystem. In case the +# filesystem is case sensitive (i.e. it supports files in the same directory +# whose names only differ in casing), the option must be set to YES to properly +# deal with such files in case they appear in the input. For filesystems that +# are not case sensitive the option should be be set to NO to properly deal with +# output files written for symbols that only differ in casing, such as for two +# classes, one named CLASS and the other named Class, and to also support +# references to files without having to specify the exact matching casing. On +# Windows (including Cygwin) and MacOS, users should typically set this option +# to NO, whereas on Linux or other Unix flavors it should typically be set to +# YES. # The default value is: system dependent. CASE_SENSE_NAMES = NO @@ -813,7 +830,10 @@ WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO # If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when -# a warning is encountered. +# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS +# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but +# at the end of the doxygen process doxygen will return with a non-zero status. +# Possible values are: NO, YES and FAIL_ON_WARNINGS. # The default value is: NO. WARN_AS_ERROR = NO @@ -844,7 +864,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = ./ \ +INPUT = ./ \ ./docs/doxygen \ ./include \ ./portable \ @@ -861,8 +881,8 @@ INPUT = ./ \ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: https://www.gnu.org/software/libiconv/) for the list of -# possible encodings. +# documentation (see: +# https://www.gnu.org/software/libiconv/) for the list of possible encodings. # The default value is: UTF-8. INPUT_ENCODING = UTF-8 @@ -875,13 +895,15 @@ INPUT_ENCODING = UTF-8 # need to set EXTENSION_MAPPING for the extension otherwise the files are not # read by doxygen. # +# Note the list of default checked file patterns might differ from the list of +# default file extension mappings. +# # If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, # *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, # *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, # *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment), -# *.doc (to be provided as doxygen C comment), *.txt (to be provided as doxygen -# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, -# *.vhdl, *.ucf, *.qsf and *.ice. +# *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl, +# *.ucf, *.qsf and *.ice. FILE_PATTERNS = *.c \ *.h \ @@ -1098,15 +1120,21 @@ USE_HTAGS = NO VERBATIM_HEADERS = YES # If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the -# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the -# cost of reduced performance. This can be particularly helpful with template -# rich C++ code for which doxygen's built-in parser lacks the necessary type -# information. +# clang parser (see: +# http://clang.llvm.org/) for more accurate parsing at the cost of reduced +# performance. This can be particularly helpful with template rich C++ code for +# which doxygen's built-in parser lacks the necessary type information. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. # The default value is: NO. -# CLANG_ASSISTED_PARSING = NO +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled and the CLANG_ADD_INC_PATHS tag is set to +# YES then doxygen will add the directory of each input to the include path. +# The default value is: YES. + +CLANG_ADD_INC_PATHS = YES # If clang assisted parsing is enabled you can provide the compiler with command # line options that you would normally use when invoking the compiler. Note that @@ -1114,20 +1142,20 @@ VERBATIM_HEADERS = YES # specified with INPUT and INCLUDE_PATH. # This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. -# CLANG_OPTIONS = +CLANG_OPTIONS = # If clang assisted parsing is enabled you can provide the clang parser with the # path to the directory containing a file called compile_commands.json. This # file is the compilation database (see: # http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the # options used when the source files were built. This is equivalent to -# specifying the "-p" option to a clang tool, such as clang-check. These options +# specifying the -p option to a clang tool, such as clang-check. These options # will then be passed to the parser. Any options specified with CLANG_OPTIONS # will be added as well. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. -# CLANG_DATABASE_PATH = +CLANG_DATABASE_PATH = #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index @@ -1140,13 +1168,6 @@ VERBATIM_HEADERS = YES ALPHABETICAL_INDEX = YES -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - # In case all classes in a project start with a common prefix, all classes will # be put under the same header in the alphabetical index. The IGNORE_PREFIX tag # can be used to specify a prefix (or a list of prefixes) that should be ignored @@ -1317,10 +1338,11 @@ HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: https://developer.apple.com/xcode/), introduced with OSX -# 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in +# environment (see: +# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To +# create a documentation set, doxygen will generate a Makefile in the HTML +# output directory. Running make will produce the docset in that directory and +# running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at # startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy # genXcode/_index.html for more information. @@ -1362,8 +1384,8 @@ DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # additional HTML index files: index.hhp, index.hhc, and index.hhk. The # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. +# (see: +# https://www.microsoft.com/en-us/download/details.aspx?id=21138) on Windows. # # The HTML Help Workshop contains a compiler that can convert all HTML output # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML @@ -1438,7 +1460,8 @@ QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace -# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). +# (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1446,8 +1469,8 @@ QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual- -# folders). +# Folders (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1455,16 +1478,16 @@ QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom -# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- -# filters). +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- -# filters). +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = @@ -1476,9 +1499,9 @@ QHP_CUST_FILTER_ATTRS = QHP_SECT_FILTER_ATTRS = -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. +# The QHG_LOCATION tag can be used to specify the location (absolute path +# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to +# run qhelpgenerator on the generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = @@ -1564,7 +1587,7 @@ EXT_LINKS_IN_WINDOW = NO # The default value is: png. # This tag requires that the tag GENERATE_HTML is set to YES. -# HTML_FORMULA_FORMAT = png +HTML_FORMULA_FORMAT = png # Use this tag to change the font size of LaTeX formulas included as images in # the HTML documentation. When you change the font size after a successful @@ -1590,7 +1613,7 @@ FORMULA_TRANSPARENT = YES # to create new LaTeX commands to be used in formulas as building blocks. See # the section "Including formulas" for details. -# FORMULA_MACROFILE = +FORMULA_MACROFILE = # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see # https://www.mathjax.org) which uses client side JavaScript for the rendering @@ -1605,7 +1628,7 @@ USE_MATHJAX = NO # When MathJax is enabled you can set the default output format to be used for # the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. +# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. # Possible values are: HTML-CSS (which is slower, but has the best # compatibility), NativeMML (i.e. MathML) and SVG. # The default value is: HTML-CSS. @@ -1635,7 +1658,8 @@ MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. @@ -1682,7 +1706,8 @@ SERVER_BASED_SEARCH = NO # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: https://xapian.org/). +# Xapian (see: +# https://xapian.org/). # # See the section "External Indexing and Searching" for details. # The default value is: NO. @@ -1695,8 +1720,9 @@ EXTERNAL_SEARCH = NO # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: https://xapian.org/). See the section "External Indexing and -# Searching" for details. +# Xapian (see: +# https://xapian.org/). See the section "External Indexing and Searching" for +# details. # This tag requires that the tag SEARCHENGINE is set to YES. SEARCHENGINE_URL = @@ -2198,15 +2224,15 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = "DOXYGEN=1" \ - "ipconfigUSE_DHCP=1" \ - "ipconfigUSE_DNS=1" \ - "ipconfigUSE_LLMNR=1" \ - "ipconfigUSE_NBNS=1" \ - "ipconfigDNS_USE_CALLBACKS=1" \ - "ipconfigSUPPORT_SELECT_FUNCTION=1" \ - "ipconfigUSE_TCP=1" \ - "ipconfigUSE_TCP_WIN=1" +PREDEFINED = DOXYGEN=1 \ + ipconfigUSE_DHCP=1 \ + ipconfigUSE_DNS=1 \ + ipconfigUSE_LLMNR=1 \ + ipconfigUSE_NBNS=1 \ + ipconfigDNS_USE_CALLBACKS=1 \ + ipconfigSUPPORT_SELECT_FUNCTION=1 \ + ipconfigUSE_TCP=1 \ + ipconfigUSE_TCP_WIN=1 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The @@ -2383,10 +2409,32 @@ UML_LOOK = NO # but if the number exceeds 15, the total amount of fields shown is limited to # 10. # Minimum value: 0, maximum value: 100, default value: 10. -# This tag requires that the tag HAVE_DOT is set to YES. +# This tag requires that the tag UML_LOOK is set to YES. UML_LIMIT_NUM_FIELDS = 10 +# If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and +# methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS +# tag is set to YES, doxygen will add type and arguments for attributes and +# methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen +# will not generate fields with class member information in the UML graphs. The +# class diagrams will look similar to the default class diagrams but using UML +# notation for the relationships. +# Possible values are: NO, YES and NONE. +# The default value is: NO. +# This tag requires that the tag UML_LOOK is set to YES. + +DOT_UML_DETAILS = NO + +# The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters +# to display on a single line. If the actual line length exceeds this threshold +# significantly it will wrapped across multiple lines. Some heuristics are apply +# to avoid ugly line breaks. +# Minimum value: 0, maximum value: 1000, default value: 17. +# This tag requires that the tag HAVE_DOT is set to YES. + +DOT_WRAP_THRESHOLD = 17 + # If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and # collaboration graphs will show the relations between templates and their # instances. @@ -2576,17 +2624,11 @@ DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES -# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot +# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate # files that are used to generate the various graphs. +# +# Note: This setting is not only used for dot files but also for msc and +# plantuml temporary files. # The default value is: YES. -# This tag requires that the tag HAVE_DOT is set to YES. DOT_CLEANUP = YES - -# Aliases - -ALIASES += transportcallback="@ingroup mqtt_callback_types" -ALIASES += transportstruct="@ingroup mqtt_struct_types" -ALIASES += transportpage="@page mqtt_transport_interface Transport Interface" -ALIASES += transportsectionimplementation="@section mqtt_transport_interface_implementation Implementing the Transport Interface" -ALIASES += transportsectionoverview="@section mqtt_transport_interface_overview Transport Interface Overview" From b80e0964ca9bbceb4836a5cdfc473d153405ebe7 Mon Sep 17 00:00:00 2001 From: Thomas Pedersen Date: Wed, 13 Jan 2021 18:29:58 -0800 Subject: [PATCH 05/33] TCP_WIN: fix compile warning on x86_64 (#148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * TCP_WIN: fix compile warning on x86_64 Fix the following warning when building for 64 bit: warning: conversion from ‘long unsigned int’ to ‘uint32_t’ {aka ‘unsigned int’} changes value from ‘18446744073709551615’ to ‘4294967295’ [-Woverflow] uint32_t ulReturn = ~0UL; ^ * Update FreeRTOS_TCP_WIN.c Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Co-authored-by: Thomas Pedersen Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- FreeRTOS_TCP_WIN.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FreeRTOS_TCP_WIN.c b/FreeRTOS_TCP_WIN.c index 7670c3eea6..adff6b0d50 100644 --- a/FreeRTOS_TCP_WIN.c +++ b/FreeRTOS_TCP_WIN.c @@ -1631,7 +1631,7 @@ { TCPSegment_t * pxSegment; uint32_t ulMaxTime; - uint32_t ulReturn = ~0UL; + uint32_t ulReturn = ( ( uint32_t ) ~0UL ); /* Fetches data to be sent-out now. From 4a05a0ac7e66267652c762baf0d037d68011aed4 Mon Sep 17 00:00:00 2001 From: Hartmut Schaefer Date: Thu, 14 Jan 2021 07:02:40 +0100 Subject: [PATCH 06/33] fix deprecated volatile compound assignment (#152) * fixed deprecated volatile compound assignment C++20 deprecates some undefined or unclear use cases of 'volatile' like compound assignments and compliant compilers warn about those deprecated operations. In vStreamBufferMoveMid the deprecated compound assignment and other direct accesses to volatile 'StreamBuffer_t->uxMid' is replaced using a local variable stored back when done. * Uncrustify Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Co-authored-by: Aniruddha Kanhere --- include/FreeRTOS_Stream_Buffer.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/FreeRTOS_Stream_Buffer.h b/include/FreeRTOS_Stream_Buffer.h index c2f814b32d..ad333ccbee 100644 --- a/include/FreeRTOS_Stream_Buffer.h +++ b/include/FreeRTOS_Stream_Buffer.h @@ -163,6 +163,7 @@ { /* Increment uxMid, but no further than uxHead */ size_t uxSize = uxStreamBufferMidSpace( pxBuffer ); + size_t uxMid = pxBuffer->uxMid; size_t uxMoveCount = uxCount; if( uxMoveCount > uxSize ) @@ -170,12 +171,14 @@ uxMoveCount = uxSize; } - pxBuffer->uxMid += uxMoveCount; + uxMid += uxMoveCount; - if( pxBuffer->uxMid >= pxBuffer->LENGTH ) + if( uxMid >= pxBuffer->LENGTH ) { - pxBuffer->uxMid -= pxBuffer->LENGTH; + uxMid -= pxBuffer->LENGTH; } + + pxBuffer->uxMid = uxMid; } /*-----------------------------------------------------------*/ From f3650e4c52bf97e39673c5fc13fb2fb7067d2109 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Sat, 16 Jan 2021 05:44:26 +0800 Subject: [PATCH 07/33] FreeRTOS_ARP.c : store local addresses only (#120) * FreeRTOS_ARP.c : store local addresses only * Added the function xARPWaitResolution() * Added an entry to lexicon.txt. * Ran Uncrustify * Update unit test file * Update * Declared xARPWaitResolution() in FreeRTOS_IP.h * Compare the result of xIsCallingFromIPTask() with pdFALSE in stead of 0 Co-authored-by: Hein Tibosch Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Co-authored-by: Aniruddha Kanhere --- .github/lexicon.txt | 1 + FreeRTOS_ARP.c | 84 ++++++++++++++++++----- include/FreeRTOS_IP.h | 2 + test/unit-test/FreeRTOS_TCP_Unit_test.c | 4 ++ test/unit-test/stubs/FreeRTOS_ARP_stubs.c | 17 +++++ 5 files changed, 90 insertions(+), 18 deletions(-) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index b827c6564c..d0e086990f 100644 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -1239,6 +1239,7 @@ uxstreambufferget uxstreambuffermidspace uxtail uxtaskgetsystemstate +uxtickstowait uxtimeout uxtimeoutstate uxtotaldatalength diff --git a/FreeRTOS_ARP.c b/FreeRTOS_ARP.c index 91baca8a4b..9295f126ed 100644 --- a/FreeRTOS_ARP.c +++ b/FreeRTOS_ARP.c @@ -271,12 +271,8 @@ void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, uint8_t ucMinAgeFound = 0U; #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 0 ) - - /* Only process the IP address if it is on the local network. - * Unless: when '*ipLOCAL_IP_ADDRESS_POINTER' equals zero, the IP-address - * and netmask are still unknown. */ - if( ( ( ulIPAddress & xNetworkAddressing.ulNetMask ) == ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) ) || - ( *ipLOCAL_IP_ADDRESS_POINTER == 0UL ) ) + /* Only process the IP address if it is on the local network. */ + if( ( ulIPAddress & xNetworkAddressing.ulNetMask ) == ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) ) #else /* If ipconfigARP_STORES_REMOTE_ADDRESSES is non-zero, IP addresses with @@ -492,16 +488,6 @@ eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, ulAddressToLookup = *pulIPAddress; - #if ( ipconfigUSE_LLMNR == 1 ) - if( ulAddressToLookup == ipLLMNR_IP_ADDR ) /* Is in network byte order. */ - { - /* The LLMNR IP-address has a fixed virtual MAC address. */ - ( void ) memcpy( pxMACAddress->ucBytes, xLLMNR_MacAdress.ucBytes, sizeof( MACAddress_t ) ); - eReturn = eARPCacheHit; - } - else - #endif - if( xIsIPv4Multicast( ulAddressToLookup ) != 0 ) { /* Get the lowest 23 bits of the IP-address. */ @@ -522,6 +508,12 @@ eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, * can be done. */ eReturn = eCantSendPacket; } + else if( *ipLOCAL_IP_ADDRESS_POINTER == *pulIPAddress ) + { + /* The address of this device. May be useful for the loopback device. */ + eReturn = eARPCacheHit; + memcpy( pxMACAddress->ucBytes, ipLOCAL_MAC_ADDRESS, sizeof( pxMACAddress->ucBytes ) ); + } else { eReturn = eARPCacheMiss; @@ -747,7 +739,7 @@ void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress ) } #endif /* if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES ) */ - if( xIsCallingFromIPTask() != 0 ) + if( xIsCallingFromIPTask() != pdFALSE ) { iptraceNETWORK_INTERFACE_OUTPUT( pxNetworkBuffer->xDataLength, pxNetworkBuffer->pucEthernetBuffer ); /* Only the IP-task is allowed to call this function directly. */ @@ -769,7 +761,63 @@ void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress ) } } } -/*--------------------------------------*/ +/*-----------------------------------------------------------*/ + +/** + * @brief Wait for address resolution: look-up the IP-address in the ARP-cache, and if + * needed send an ARP request, and wait for a reply. This function is useful when + * called before FreeRTOS_sendto(). + * + * @param[in] ulIPAddress: The IP-address to look-up. + * @param[in] uxTicksToWait: The maximum number of clock ticks to wait for a reply. + * + * @return Zero when successful. + */ +BaseType_t xARPWaitResolution( uint32_t ulIPAddress, + TickType_t uxTicksToWait ) +{ + BaseType_t xResult = -pdFREERTOS_ERRNO_EADDRNOTAVAIL; + TimeOut_t xTimeOut; + MACAddress_t xMACAddress; + eARPLookupResult_t xLookupResult; + size_t uxSendCount = ipconfigMAX_ARP_RETRANSMISSIONS; + + /* The IP-task is not supposed to call this function. */ + configASSERT( xIsCallingFromIPTask() == pdFALSE ); + + xLookupResult = eARPGetCacheEntry( &( ulIPAddress ), &( xMACAddress ) ); + + if( xLookupResult == eARPCacheMiss ) + { + const TickType_t uxSleepTime = pdMS_TO_TICKS( 250U ); + + /* We might use ipconfigMAX_ARP_RETRANSMISSIONS here. */ + vTaskSetTimeOutState( &xTimeOut ); + + while( uxSendCount > 0 ) + { + FreeRTOS_OutputARPRequest( ulIPAddress ); + + vTaskDelay( uxSleepTime ); + + xLookupResult = eARPGetCacheEntry( &( ulIPAddress ), &( xMACAddress ) ); + + if( ( xTaskCheckForTimeOut( &( xTimeOut ), &( uxTicksToWait ) ) == pdTRUE ) || + ( xLookupResult != eARPCacheMiss ) ) + { + break; + } + } + } + + if( xLookupResult == eARPCacheHit ) + { + xResult = 0; + } + + return xResult; +} +/*-----------------------------------------------------------*/ /** * @brief Generate an ARP request packet by copying various constant details to diff --git a/include/FreeRTOS_IP.h b/include/FreeRTOS_IP.h index 3354d6ae4f..48a900e359 100644 --- a/include/FreeRTOS_IP.h +++ b/include/FreeRTOS_IP.h @@ -330,6 +330,8 @@ uint32_t FreeRTOS_GetGatewayAddress( void ); uint32_t FreeRTOS_GetDNSServerAddress( void ); uint32_t FreeRTOS_GetNetmask( void ); + BaseType_t xARPWaitResolution( uint32_t ulIPAddress, + TickType_t uxTicksToWait ); void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress ); BaseType_t FreeRTOS_IsNetworkUp( void ); diff --git a/test/unit-test/FreeRTOS_TCP_Unit_test.c b/test/unit-test/FreeRTOS_TCP_Unit_test.c index a5782caf62..9bf19303e9 100644 --- a/test/unit-test/FreeRTOS_TCP_Unit_test.c +++ b/test/unit-test/FreeRTOS_TCP_Unit_test.c @@ -5,6 +5,10 @@ #include #include +#include "FreeRTOS.h" +#include "task.h" +#include "list.h" + /* Include header file(s) which have declaration * of functions under test */ #include "FreeRTOS_IP.h" diff --git a/test/unit-test/stubs/FreeRTOS_ARP_stubs.c b/test/unit-test/stubs/FreeRTOS_ARP_stubs.c index 7b4b0b3b84..79b33a1701 100644 --- a/test/unit-test/stubs/FreeRTOS_ARP_stubs.c +++ b/test/unit-test/stubs/FreeRTOS_ARP_stubs.c @@ -12,6 +12,23 @@ NetworkAddressingParameters_t xNetworkAddressing = { 0, 0, 0, 0, 0 }; /* The expected IP version and header length coded into the IP header itself. */ #define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 ) +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) +{ +} +/*-----------------------------------------------------------*/ + +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, + TickType_t * const pxTicksToWait ) +{ + return pdTRUE; +} +/*-----------------------------------------------------------*/ + +void vTaskDelay( const TickType_t xTicksToDelay ) +{ +} +/*-----------------------------------------------------------*/ + BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress ) { BaseType_t xReturn; From 2ecc851165ffa84acaa30e2348e54934471bea53 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Thu, 28 Jan 2021 11:53:54 -0800 Subject: [PATCH 08/33] Remove unnecessary #ifndef (#186) * Add entropy * remove warning * Remove unnecessary ifndef * Remove unwanted changes --- FreeRTOS_IP.c | 25 +++++++++---------------- tools/tcp_utilities/tcp_mem_stats.c | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 2cf9f5d7f5..319dc08311 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -354,8 +354,6 @@ static BaseType_t xIPTaskInitialised = pdFALSE; /*-----------------------------------------------------------*/ -#include "random.h" - /* Coverity wants to make pvParameters const, which would make it incompatible. Leave the * function signature as is. */ @@ -436,8 +434,6 @@ static void prvIPTask( void * pvParameters ) iptraceNETWORK_EVENT_RECEIVED( xReceivedEvent.eEventType ); - vAddBytesToPool( xReceivedEvent.eEventType ); - switch( xReceivedEvent.eEventType ) { case eNetworkDownEvent: @@ -1157,18 +1153,15 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES configASSERT( ipconfigBUFFER_PADDING == 14 ); } - #ifndef _lint - { - /* Check if MTU is big enough. */ - configASSERT( ( ( size_t ) ipconfigNETWORK_MTU ) >= ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + ipconfigTCP_MSS ) ); - /* Check structure packing is correct. */ - configASSERT( sizeof( EthernetHeader_t ) == ipEXPECTED_EthernetHeader_t_SIZE ); - configASSERT( sizeof( ARPHeader_t ) == ipEXPECTED_ARPHeader_t_SIZE ); - configASSERT( sizeof( IPHeader_t ) == ipEXPECTED_IPHeader_t_SIZE ); - configASSERT( sizeof( ICMPHeader_t ) == ipEXPECTED_ICMPHeader_t_SIZE ); - configASSERT( sizeof( UDPHeader_t ) == ipEXPECTED_UDPHeader_t_SIZE ); - } - #endif /* ifndef _lint */ + /* Check if MTU is big enough. */ + configASSERT( ( ( size_t ) ipconfigNETWORK_MTU ) >= ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + ipconfigTCP_MSS ) ); + /* Check structure packing is correct. */ + configASSERT( sizeof( EthernetHeader_t ) == ipEXPECTED_EthernetHeader_t_SIZE ); + configASSERT( sizeof( ARPHeader_t ) == ipEXPECTED_ARPHeader_t_SIZE ); + configASSERT( sizeof( IPHeader_t ) == ipEXPECTED_IPHeader_t_SIZE ); + configASSERT( sizeof( ICMPHeader_t ) == ipEXPECTED_ICMPHeader_t_SIZE ); + configASSERT( sizeof( UDPHeader_t ) == ipEXPECTED_UDPHeader_t_SIZE ); + /* Attempt to create the queue used to communicate with the IP task. */ xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) ); configASSERT( xNetworkEventQueue != NULL ); diff --git a/tools/tcp_utilities/tcp_mem_stats.c b/tools/tcp_utilities/tcp_mem_stats.c index 6a426339d1..b3aa87c54e 100644 --- a/tools/tcp_utilities/tcp_mem_stats.c +++ b/tools/tcp_utilities/tcp_mem_stats.c @@ -49,7 +49,7 @@ #ifndef ipconfigTCP_MEM_STATS_MAX_ALLOCATION #define ipconfigTCP_MEM_STATS_MAX_ALLOCATION 128u -// #pragma warning "ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?" + #pragma warning "ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?" #endif #if ( ipconfigUSE_TCP_MEM_STATS != 0 ) From 82fa2385bce496b3767e1eefc1232f246349e163 Mon Sep 17 00:00:00 2001 From: evpopov Date: Tue, 2 Feb 2021 20:07:13 -0500 Subject: [PATCH 09/33] Don't Fragment Flags patch. (#179) * Moves all IP flag defines in FreeRTOS_IP_Private.h so that they are accessible to all protocols Adds definitions for the IP fragmentation flags Modifies the fragmentation check for incoming frames to drop both the first and later fragments. Sets the "don't fragment" flag for all outgoing IP frames ( ICMP, DNS, UDP, TCP ) Removes ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT as it appears obsolete. The stack never outputs fragments. * Uncrustified * Uncrustify * Fixes the fragment offset and fragmentation flags masks ( 0x0FFF and 0xF000 -> 0x1FFF and 0xE000 ) Adds a configuration define ( ipconfigADVERTISE_DONT_FRAGMENT_FLAG ) as suggested by htibosch with a default value of zero for backwards compatibility Updates the comment that explains the discarding of incoming fragments as discussed with Aniruddha Kanhere * Adds the 'U' qualifier as requested by hs2gh fixes a typo in FreeRTOSIPConfigDefaults.h * Shortens the comment in FreeRTOSIPConfigDefaults as per htibosch's suggestion. * Renames ipconfigADVERTISE_DONT_FRAGMENT to ipconfigFORCE_IP_DONT_FRAGMENT * same as last commit, simply forgot to save this before pushing. Co-authored-by: Emil Popov Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- FreeRTOS_DNS.c | 9 +++++++++ FreeRTOS_IP.c | 28 ++++++++++++++-------------- FreeRTOS_TCP_IP.c | 10 +++++++++- FreeRTOS_UDP_IP.c | 9 +++++++++ include/FreeRTOSIPConfigDefaults.h | 12 ++++++++++++ include/FreeRTOS_IP_Private.h | 24 +++++++++++++++++++++--- 6 files changed, 74 insertions(+), 18 deletions(-) diff --git a/FreeRTOS_DNS.c b/FreeRTOS_DNS.c index 6bc06f22e1..c6f36457f2 100644 --- a/FreeRTOS_DNS.c +++ b/FreeRTOS_DNS.c @@ -1947,6 +1947,15 @@ pxIPHeader->ulSourceIPAddress = *ipLOCAL_IP_ADDRESS_POINTER; pxIPHeader->ucTimeToLive = ipconfigUDP_TIME_TO_LIVE; pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier ); + + /* The stack doesn't support fragments, so the fragment offset field must always be zero. + * The header was never memset to zero, so set both the fragment offset and fragmentation flags in one go. + */ + #if ( ipconfigFORCE_IP_DONT_FRAGMENT != 0 ) + pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT; + #else + pxIPHeader->usFragmentOffset = 0U; + #endif usPacketIdentifier++; pxUDPHeader->usLength = FreeRTOS_htons( ( uint32_t ) lNetLength + ipSIZE_OF_UDP_HEADER ); vFlip_16( pxUDPHeader->usSourcePort, pxUDPHeader->usDestinationPort ); diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 319dc08311..59ca413885 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -115,16 +115,6 @@ #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer #endif -#if ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 ) - #if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) - /** @brief The bits in the two byte IP header field that make up the fragment offset value. */ - #define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0xff0f ) - #else - /** @brief The bits in the two byte IP header field that make up the fragment offset value. */ - #define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x0fff ) - #endif /* ipconfigBYTE_ORDER */ -#endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ - /** @brief The maximum time the IP task is allowed to remain in the Blocked state if no * events are posted to the network event queue. */ #ifndef ipconfigMAX_IP_TASK_SLEEP_TIME @@ -1850,10 +1840,11 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP * This method may decrease the usage of sparse network buffers. */ uint32_t ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress; - /* Ensure that the incoming packet is not fragmented (only outgoing - * packets can be fragmented) as these are the only handled IP frames - * currently. */ - if( ( pxIPHeader->usFragmentOffset & ipFRAGMENT_OFFSET_BIT_MASK ) != 0U ) + /* Ensure that the incoming packet is not fragmented because the stack + * doesn't not support IP fragmentation. All but the last fragment coming in will have their + * "more fragments" flag set and the last fragment will have a non-zero offset. + * We need to drop the packet in either of those cases. */ + if( ( ( pxIPHeader->usFragmentOffset & ipFRAGMENT_OFFSET_BIT_MASK ) != 0U ) || ( ( pxIPHeader->usFragmentOffset & ipFRAGMENT_FLAGS_MORE_FRAGMENTS ) != 0U ) ) { /* Can not handle, fragmented packet. */ eReturn = eReleaseBuffer; @@ -2246,6 +2237,15 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, pxIPHeader->ulDestinationIPAddress = pxIPHeader->ulSourceIPAddress; pxIPHeader->ulSourceIPAddress = *ipLOCAL_IP_ADDRESS_POINTER; + /* The stack doesn't support fragments, so the fragment offset field must always be zero. + * The header was never memset to zero, so set both the fragment offset and fragmentation flags in one go. + */ + #if ( ipconfigFORCE_IP_DONT_FRAGMENT != 0 ) + pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT; + #else + pxIPHeader->usFragmentOffset = 0U; + #endif + /* Update the checksum because the ucTypeOfMessage member in the header * has been changed to ipICMP_ECHO_REPLY. This is faster than calling * usGenerateChecksum(). */ diff --git a/FreeRTOS_TCP_IP.c b/FreeRTOS_TCP_IP.c index c62ca7e5a5..abbf923de3 100644 --- a/FreeRTOS_TCP_IP.c +++ b/FreeRTOS_TCP_IP.c @@ -962,7 +962,15 @@ /* Just an increasing number. */ pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier ); usPacketIdentifier++; - pxIPHeader->usFragmentOffset = 0U; + + /* The stack doesn't support fragments, so the fragment offset field must always be zero. + * The header was never memset to zero, so set both the fragment offset and fragmentation flags in one go. + */ + #if ( ipconfigFORCE_IP_DONT_FRAGMENT != 0 ) + pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT; + #else + pxIPHeader->usFragmentOffset = 0U; + #endif /* Important: tell NIC driver how many bytes must be sent. */ pxNetworkBuffer->xDataLength = ulLen + ipSIZE_OF_ETH_HEADER; diff --git a/FreeRTOS_UDP_IP.c b/FreeRTOS_UDP_IP.c index 9f34fd31ef..8a79ff83da 100644 --- a/FreeRTOS_UDP_IP.c +++ b/FreeRTOS_UDP_IP.c @@ -195,6 +195,15 @@ void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuff pxIPHeader->usLength = FreeRTOS_htons( pxIPHeader->usLength ); pxIPHeader->ulDestinationIPAddress = pxNetworkBuffer->ulIPAddress; + /* The stack doesn't support fragments, so the fragment offset field must always be zero. + * The header was never memset to zero, so set both the fragment offset and fragmentation flags in one go. + */ + #if ( ipconfigFORCE_IP_DONT_FRAGMENT != 0 ) + pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT; + #else + pxIPHeader->usFragmentOffset = 0U; + #endif + #if ( ipconfigUSE_LLMNR == 1 ) { /* LLMNR messages are typically used on a LAN and they're diff --git a/include/FreeRTOSIPConfigDefaults.h b/include/FreeRTOSIPConfigDefaults.h index bbbab54da5..dcbabb2159 100644 --- a/include/FreeRTOSIPConfigDefaults.h +++ b/include/FreeRTOSIPConfigDefaults.h @@ -336,6 +336,18 @@ #define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS 1 #endif +/* Configuration to control whether all outgoing IP datagrams get their + * "don't fragment" flag set. + * If set to 1, the stack will set the "don't fragment" flag on all outgoing IP + * packets. If a packet needs to be fragmented somewhere along it's path, it will get + * discarded instead of fragmented. + * If set to 0, the stack will clear the "don't fragment" flag an all outgoing IP + * packets therefore allowing fragmentation if it is needed. + */ +#ifndef ipconfigFORCE_IP_DONT_FRAGMENT + #define ipconfigFORCE_IP_DONT_FRAGMENT 0 +#endif + /* Configuration to control whether UDP packets with * checksum value of zero should be passed up the software * stack OR should be dropped. diff --git a/include/FreeRTOS_IP_Private.h b/include/FreeRTOS_IP_Private.h index c800441889..92ba8ba020 100644 --- a/include/FreeRTOS_IP_Private.h +++ b/include/FreeRTOS_IP_Private.h @@ -382,9 +382,6 @@ #define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 ) #define ipSOCKET_OPTIONS_OFFSET ( 6 ) -/* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h - * setting. */ - #define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET_IPv4 : ipIP_PAYLOAD_OFFSET ) /* The offset into a UDP packet at which the UDP data (payload) starts. */ #define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) ) @@ -418,6 +415,27 @@ #endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */ + #if ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 ) + #if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) + /* The bits in the two byte IP header field that make up the fragment offset value. */ + #define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0xff1fU ) + /* The bits in the two byte IP header field that make up the flags value. */ + #define ipFRAGMENT_FLAGS_BIT_MASK ( ( uint16_t ) 0x00e0U ) + /* Don't Fragment Flag */ + #define ipFRAGMENT_FLAGS_DONT_FRAGMENT ( ( uint16_t ) 0x0040U ) + /* More Fragments Flag */ + #define ipFRAGMENT_FLAGS_MORE_FRAGMENTS ( ( uint16_t ) 0x0020U ) + #else + /* The bits in the two byte IP header field that make up the fragment offset value. */ + #define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x1fffU ) + /* The bits in the two byte IP header field that make up the flags value. */ + #define ipFRAGMENT_FLAGS_BIT_MASK ( ( uint16_t ) 0xe000U ) + /* Don't Fragment Flag */ + #define ipFRAGMENT_FLAGS_DONT_FRAGMENT ( ( uint16_t ) 0x4000U ) + /* More Fragments Flag */ + #define ipFRAGMENT_FLAGS_MORE_FRAGMENTS ( ( uint16_t ) 0x2000U ) + #endif /* ipconfigBYTE_ORDER */ + #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ /* For convenience, a MAC address of all zeros and another of all 0xffs are * defined const for quick reference. */ From 9e364b986643c980a41c3ca681fdee26fe6fbbf3 Mon Sep 17 00:00:00 2001 From: Thomas Pedersen Date: Mon, 8 Feb 2021 08:54:32 -0800 Subject: [PATCH 10/33] fix IP buffer padding check on 64bit (#146) * fix IP buffer padding check on 64bit On 64 bit systems, FreeRTOS_IPInit() would assert ipconfigBUFFER_PADDING was equal to 14 to "make sure there is enough space in pucEthernetBuffer to store a pointer." This prevents the driver from requesting additional padding, so make the assert greater than or equal to 14. Also use the final ipBUFFER_PADDING value instead of ipconfigBUFFER_PADDING, which is probably what was intended? * Update after comments Co-authored-by: Thomas Pedersen Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- FreeRTOS_IP.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 59ca413885..6a41d99c21 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -1140,7 +1140,10 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES { /* This is a 64-bit platform, make sure there is enough space in * pucEthernetBuffer to store a pointer. */ - configASSERT( ipconfigBUFFER_PADDING == 14 ); + configASSERT( ipconfigBUFFER_PADDING >= 14 ); + + /* But it must have this strange alignment: */ + configASSERT( ( ( ( ipconfigBUFFER_PADDING ) + 2 ) % 4 ) == 0 ); } /* Check if MTU is big enough. */ From 20cbc94ae2e522028b5f8eadd3b6631e4f9ce9a1 Mon Sep 17 00:00:00 2001 From: shrewmouse1 <34042878+shrewmouse1@users.noreply.github.com> Date: Mon, 8 Feb 2021 13:30:07 -0500 Subject: [PATCH 11/33] Update readme.md (#189) Just fixing the "table of 3 types of STH32H7" so that it renders in github webpage. I had a tough time reading that table until I looked at the md source. You could also just put code fences around it: ~~~ /** * RAM area H747 H743 H742 Location * ------------------------------------------------ * DTCM 128k 128k 128k 0x20000000 * AXI-SRAM 511k 511k 384k 0x24000000 * * SRAM1 128k 128k 32k 0x30000000 * SRAM2 128k 128k 16k 0x30020000 * SRAM3 32k 32k - 0x30040000 * SRAM4 64k 64k 64k 0x38000000 * Backup SRAM 4k 4k 4k 0x38800000 */ ~~~ Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- portable/NetworkInterface/STM32Hxx/readme.md | 22 +++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/portable/NetworkInterface/STM32Hxx/readme.md b/portable/NetworkInterface/STM32Hxx/readme.md index ef3bc343df..6ea5356337 100644 --- a/portable/NetworkInterface/STM32Hxx/readme.md +++ b/portable/NetworkInterface/STM32Hxx/readme.md @@ -54,18 +54,16 @@ Here is an example of the changes to the linker file: } >AXI_RAM Here is a table of 3 types of STH32H7 : -/** - * RAM area H747 H743 H742 Location - * ------------------------------------------------ - * DTCM 128k 128k 128k 0x20000000 - * AXI-SRAM 511k 511k 384k 0x24000000 - * - * SRAM1 128k 128k 32k 0x30000000 - * SRAM2 128k 128k 16k 0x30020000 - * SRAM3 32k 32k - 0x30040000 - * SRAM4 64k 64k 64k 0x38000000 - * Backup SRAM 4k 4k 4k 0x38800000 - */ + +|RAM area |H747|H743|H742|Location | +|-----------|----|----|----|----------| +|DTCM |128k|128k|128k|0x20000000| +|AXI-SRAM |511k|511k|384k|0x24000000| +|SRAM1 |128k|128k|32k |0x30000000| +|SRAM2 |128k|128k|16k |0x30020000| +|SRAM3 |32k | 32k| - |0x30040000| +|SRAM4 |64k |64k |64k |0x38000000| +|Backup SRAM|4k |4k |4k |0x38800000| Please make sure that the addresses and lengths are correct for your model of STM32H7xx. From 7a5614424296e462fa32633c9b4d19a22a9e2e0e Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Mon, 8 Feb 2021 13:37:49 -0800 Subject: [PATCH 12/33] Update files referencing aws_application_version.h to use iot_application_version.h (#188) * Update files referencing aws_application_version.h to use iot_application_version.h * Remove pic32 ethernet _Command_Version function to remove dependency on iot_application_version.h from amazon-freertos repository. --- .../pic32mzef/NetworkInterface_eth.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c b/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c index 8107a55b22..2a918d9dac 100644 --- a/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c +++ b/portable/NetworkInterface/pic32mzef/NetworkInterface_eth.c @@ -195,15 +195,11 @@ static int _Command_NetInfo( SYS_CMD_DEVICE_NODE * pCmdIO, int argc, char ** argv ); - static int _Command_Version( SYS_CMD_DEVICE_NODE * pCmdIO, - int argc, - char ** argv ); static const SYS_CMD_DESCRIPTOR macCmdTbl[] = { { "macinfo", _Command_MacInfo, ": Check MAC statistics" }, { "netinfo", _Command_NetInfo, ": Net info" }, - { "version", _Command_Version, ": Version info" }, }; #endif /* (PIC32_MAC_DEBUG_COMMANDS != 0) */ @@ -877,15 +873,5 @@ return true; } - #include "aws_application_version.h" - - static int _Command_Version( SYS_CMD_DEVICE_NODE * pCmdIO, - int argc, - char ** argv ) - { - configPRINTF( ( "App version - maj: %d, min: %d, build: %d\r\n", xAppFirmwareVersion.u.x.ucMajor, xAppFirmwareVersion.u.x.ucMinor, xAppFirmwareVersion.u.x.usBuild ) ); - return 0; - } - #endif /* (PIC32_MAC_DEBUG_COMMANDS != 0) */ #endif /* #ifdef PIC32_USE_ETHERNET */ From a4d261ca49af9f77484e234b9a217dd6eeb99539 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon, 8 Feb 2021 20:49:28 -0500 Subject: [PATCH 13/33] Remove function defs from header files (#190) * Add entropy * remove warning * Remove function defs from headers * Some corrections * More fixes and uncrustify * Remove the BaseType min function * Doxygen * Fix one CBMC proof * More cbmc proof fixes * More cbmc fixes * Some doxygen additions * Update last CBMC proof * Doxygen comments * Doxygen updates * Doxygen and spell check * Spell check and unit-test * Unit test fix * Update after comments * Update 2 after comments * Move function around * Uncrustify * Update after comments Co-authored-by: Gary Wicker <14828980+gkwicker@users.noreply.github.com> --- .github/lexicon.txt | 3 + FreeRTOS_IP.c | 355 ++++++++++++++++++ FreeRTOS_Sockets.c | 49 ++- FreeRTOS_Stream_Buffer.c | 220 +++++++++++ include/FreeRTOS_IP.h | 81 +--- include/FreeRTOS_IP_Private.h | 146 ++----- include/FreeRTOS_Sockets.h | 19 +- include/FreeRTOS_Stream_Buffer.h | 179 +-------- .../cbmc/proofs/ARP/ARPAgeCache/Makefile.json | 1 + .../ARPGenerateRequestPacket/Makefile.json | 1 + .../Configurations.json | 1 + .../Configurations.json | 1 + .../Configurations.json | 1 + test/cbmc/proofs/CheckOptions/Makefile.json | 1 + .../TCP/prvTCPHandleState/Makefile.json | 3 +- .../TCP/prvTCPPrepareSend/Makefile.json | 1 + .../TCP/prvTCPReturnPacket/Makefile.json | 2 + .../TCPReturnPacket_harness.c | 26 +- .../vProcessGeneratedUDPPacket/Makefile.json | 1 + .../ProcessReceivedTCPPacket/Makefile.json | 1 + test/unit-test/FreeRTOS_TCP_Unit_test.c | 2 +- test/unit-test/TCPFilePaths.cmake | 8 + test/unit-test/stubs/FreeRTOS_ARP_stubs.c | 176 ++++----- test/unit-test/unit_test_build.cmake | 3 + 24 files changed, 801 insertions(+), 480 deletions(-) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index d0e086990f..98538a49fe 100644 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -91,6 +91,7 @@ callbacklist calloc camen carriersense +castingmacrofunctions cbmc ccfg cchannel @@ -620,6 +621,7 @@ posix pparam ppkt ppointer +ppucdata ppucrecvdata ppxnetworkbuffer pr @@ -714,6 +716,7 @@ pullups pulnetmask pulnumber pulvalue +pvargument pvbuffer pvdata pvdestination diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 6a41d99c21..05c4be25be 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -3412,6 +3412,361 @@ const char * FreeRTOS_strerror_r( BaseType_t xErrnum, } /*-----------------------------------------------------------*/ +/** + * @brief Get the highest value of two int32's. + * @param[in] a: the first value. + * @param[in] b: the second value. + * @return The highest of the two values. + */ +int32_t FreeRTOS_max_int32( int32_t a, + int32_t b ) +{ + return ( a >= b ) ? a : b; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Get the highest value of two uint32_t's. + * @param[in] a: the first value. + * @param[in] b: the second value. + * @return The highest of the two values. + */ +uint32_t FreeRTOS_max_uint32( uint32_t a, + uint32_t b ) +{ + return ( a >= b ) ? a : b; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Get the lowest value of two int32_t's. + * @param[in] a: the first value. + * @param[in] b: the second value. + * @return The lowest of the two values. + */ +int32_t FreeRTOS_min_int32( int32_t a, + int32_t b ) +{ + return ( a <= b ) ? a : b; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Get the lowest value of two uint32_t's. + * @param[in] a: the first value. + * @param[in] b: the second value. + * @return The lowest of the two values. + */ +uint32_t FreeRTOS_min_uint32( uint32_t a, + uint32_t b ) +{ + return ( a <= b ) ? a : b; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Round-up a number to a multiple of 'd'. + * @param[in] a: the first value. + * @param[in] d: the second value. + * @return A multiple of d. + */ +uint32_t FreeRTOS_round_up( uint32_t a, + uint32_t d ) +{ + return d * ( ( a + d - 1U ) / d ); +} +/*-----------------------------------------------------------*/ + +/** + * @brief Round-down a number to a multiple of 'd'. + * @param[in] a: the first value. + * @param[in] d: the second value. + * @return A multiple of d. + */ +uint32_t FreeRTOS_round_down( uint32_t a, + uint32_t d ) +{ + return d * ( a / d ); +} +/*-----------------------------------------------------------*/ + +/** + * @defgroup CastingMacroFunctions Utility casting functions + * @brief These functions are used to cast various types of pointers + * to other types. A major use would be to map various + * headers/packets on to the incoming byte stream. + * + * @param[in] pvArgument: Pointer to be casted to another type. + * + * @retval Casted pointer will be returned without violating MISRA + * rules. + * @{ + */ + +/** + * @brief Cast a given pointer to EthernetHeader_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ) +{ + return ( EthernetHeader_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to EthernetHeader_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ) +{ + return ( const EthernetHeader_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to IPHeader_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPHeader_t ) +{ + return ( IPHeader_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to IPHeader_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPHeader_t ) +{ + return ( const IPHeader_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to ICMPHeader_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ) +{ + return ( ICMPHeader_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to ICMPHeader_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ) +{ + return ( const ICMPHeader_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to ARPPacket_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( ARPPacket_t ) +{ + return ( ARPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to ARPPacket_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ARPPacket_t ) +{ + return ( const ARPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to IPPacket_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPPacket_t ) +{ + return ( IPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to IPPacket_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPPacket_t ) +{ + return ( const IPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to ICMPPacket_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPPacket_t ) +{ + return ( ICMPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to UDPPacket_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( UDPPacket_t ) +{ + return ( UDPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to UDPPacket_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( UDPPacket_t ) +{ + return ( const UDPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to TCPPacket_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPPacket_t ) +{ + return ( TCPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to TCPPacket_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TCPPacket_t ) +{ + return ( const TCPPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to ProtocolPacket_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ) +{ + return ( ProtocolPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to ProtocolPacket_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ) +{ + return ( const ProtocolPacket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to ProtocolHeaders_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ) +{ + return ( ProtocolHeaders_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to ProtocolHeaders_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ) +{ + return ( const ProtocolHeaders_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to FreeRTOS_Socket_t type pointer. + */ +ipDECL_CAST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ) +{ + return ( FreeRTOS_Socket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to FreeRTOS_Socket_t type pointer. + */ +ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ) +{ + return ( const FreeRTOS_Socket_t * ) pvArgument; +} +/*-----------------------------------------------------------*/ + +#if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) + +/** + * @brief Cast a given pointer to SocketSelect_t type pointer. + */ + ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelect_t ) + { + return ( SocketSelect_t * ) pvArgument; + } + /*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to SocketSelect_t type pointer. + */ + ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelect_t ) + { + return ( const SocketSelect_t * ) pvArgument; + } + /*-----------------------------------------------------------*/ + +/** + * @brief Cast a given pointer to SocketSelectMessage_t type pointer. + */ + ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ) + { + return ( SocketSelectMessage_t * ) pvArgument; + } + /*-----------------------------------------------------------*/ + +/** + * @brief Cast a given constant pointer to SocketSelectMessage_t type pointer. + */ + ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ) + { + return ( const SocketSelectMessage_t * ) pvArgument; + } + /*-----------------------------------------------------------*/ +#endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */ +/** @} */ + +/** + * @brief Convert character array (of size 4) to equivalent 32-bit value. + * @param[in] pucPtr: The character array. + * @return 32-bit equivalent value extracted from the character array. + * + * @note Going by MISRA rules, these utility functions should not be defined + * if they are not being used anywhere. But their use depends on the + * application and hence these functions are defined unconditionally. + */ +uint32_t ulChar2u32( const uint8_t * pucPtr ) +{ + return ( ( ( uint32_t ) pucPtr[ 0 ] ) << 24 ) | + ( ( ( uint32_t ) pucPtr[ 1 ] ) << 16 ) | + ( ( ( uint32_t ) pucPtr[ 2 ] ) << 8 ) | + ( ( ( uint32_t ) pucPtr[ 3 ] ) ); +} +/*-----------------------------------------------------------*/ + +/** + * @brief Convert character array (of size 2) to equivalent 16-bit value. + * @param[in] pucPtr: The character array. + * @return 16-bit equivalent value extracted from the character array. + * + * @note Going by MISRA rules, these utility functions should not be defined + * if they are not being used anywhere. But their use depends on the + * application and hence these functions are defined unconditionally. + */ +uint16_t usChar2u16( const uint8_t * pucPtr ) +{ + return ( uint16_t ) + ( ( ( ( uint32_t ) pucPtr[ 0 ] ) << 8 ) | + ( ( ( uint32_t ) pucPtr[ 1 ] ) ) ); +} +/*-----------------------------------------------------------*/ + /* Provide access to private members for verification. */ #ifdef FREERTOS_TCP_ENABLE_VERIFICATION #include "aws_freertos_ip_verification_access_ip_define.h" diff --git a/FreeRTOS_Sockets.c b/FreeRTOS_Sockets.c index 2ed1e9a107..c854bf460d 100644 --- a/FreeRTOS_Sockets.c +++ b/FreeRTOS_Sockets.c @@ -99,11 +99,14 @@ { return ( F_TCP_UDP_Handler_t * ) pvArgument; } + /*-----------------------------------------------------------*/ + static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( F_TCP_UDP_Handler_t ) { return ( const F_TCP_UDP_Handler_t * ) pvArgument; } -#endif + /*-----------------------------------------------------------*/ +#endif /* if ( ipconfigUSE_CALLBACKS != 0 ) */ /** @@ -115,7 +118,7 @@ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( NetworkBufferDescriptor_t ) { return ( NetworkBufferDescriptor_t * ) pvArgument; } - +/*-----------------------------------------------------------*/ /** * @brief Utility function to cast pointer of a type to pointer of type StreamBuffer_t. @@ -3294,17 +3297,24 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) if( pxBuffer != NULL ) { - BaseType_t xSpace = ( BaseType_t ) uxStreamBufferGetSpace( pxBuffer ); - BaseType_t xRemain = ( BaseType_t ) pxBuffer->LENGTH - ( BaseType_t ) pxBuffer->uxHead; + size_t uxSpace = uxStreamBufferGetSpace( pxBuffer ); + size_t uxRemain = pxBuffer->LENGTH - pxBuffer->uxHead; + + if( uxRemain <= uxSpace ) + { + *pxLength = uxRemain; + } + else + { + *pxLength = uxSpace; + } - *pxLength = FreeRTOS_min_BaseType( xSpace, xRemain ); pucReturn = &( pxBuffer->ucArray[ pxBuffer->uxHead ] ); } } return pucReturn; } - #endif /* ipconfigUSE_TCP */ /*-----------------------------------------------------------*/ @@ -4356,6 +4366,33 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) #endif /* ipconfigUSE_TCP */ /*-----------------------------------------------------------*/ +/** + * @brief Check whether a given socket is valid or not. Validity is defined + * as the socket not being NULL and not being Invalid. + * @param[in] xSocket: The socket to be checked. + * @return pdTRUE if the socket is valid, else pdFALSE. + * + */ +BaseType_t xSocketValid( Socket_t xSocket ) +{ + BaseType_t xReturnValue = pdFALSE; + + /* + * There are two values which can indicate an invalid socket: + * FREERTOS_INVALID_SOCKET and NULL. In order to compare against + * both values, the code cannot be compliant with rule 11.4, + * hence the Coverity suppression statement below. + */ + /* coverity[misra_c_2012_rule_11_4_violation] */ + if( ( xSocket != FREERTOS_INVALID_SOCKET ) && ( xSocket != NULL ) ) + { + xReturnValue = pdTRUE; + } + + return xReturnValue; +} +/*-----------------------------------------------------------*/ + #if 0 /** diff --git a/FreeRTOS_Stream_Buffer.c b/FreeRTOS_Stream_Buffer.c index c824c4fd65..73e2ed30a5 100644 --- a/FreeRTOS_Stream_Buffer.c +++ b/FreeRTOS_Stream_Buffer.c @@ -43,6 +43,226 @@ #include "FreeRTOS_IP_Private.h" +/** + * @brief Get the space between lower and upper value provided to the function. + * @param[in] pxBuffer: The circular stream buffer. + * @param[in] uxLower: The lower value. + * @param[in] uxUpper: The upper value. + * @return The space between uxLower and uxUpper, which equals to the distance + * minus 1. + */ +size_t uxStreamBufferSpace( const StreamBuffer_t * pxBuffer, + const size_t uxLower, + const size_t uxUpper ) +{ + size_t uxCount; + + uxCount = pxBuffer->LENGTH + uxUpper - uxLower - 1U; + + if( uxCount >= pxBuffer->LENGTH ) + { + uxCount -= pxBuffer->LENGTH; + } + + return uxCount; +} + +/** + * @brief Get the distance between lower and upper value provided to the function. + * @param[in] pxBuffer: The circular stream buffer. + * @param[in] uxLower: The lower value. + * @param[in] uxUpper: The upper value. + * @return The distance between uxLower and uxUpper. + */ +size_t uxStreamBufferDistance( const StreamBuffer_t * pxBuffer, + const size_t uxLower, + const size_t uxUpper ) +{ + size_t uxCount; + + uxCount = pxBuffer->LENGTH + uxUpper - uxLower; + + if( uxCount >= pxBuffer->LENGTH ) + { + uxCount -= pxBuffer->LENGTH; + } + + return uxCount; +} + +/** + * @brief Get the number of items which can be added to the buffer at + * the head before reaching the tail. + * @param[in] pxBuffer: The circular stream buffer. + * @return The number of items which can still be added to uxHead + * before hitting on uxTail + */ +size_t uxStreamBufferGetSpace( const StreamBuffer_t * pxBuffer ) +{ + size_t uxHead = pxBuffer->uxHead; + size_t uxTail = pxBuffer->uxTail; + + return uxStreamBufferSpace( pxBuffer, uxHead, uxTail ); +} +/*-----------------------------------------------------------*/ + +/** + * @brief Get the distance between the pointer in free space and the tail. + * @param[in] pxBuffer: The circular stream buffer. + * @return Distance between uxFront and uxTail or the number of items + * which can still be added to uxFront, before hitting on uxTail. + */ +size_t uxStreamBufferFrontSpace( const StreamBuffer_t * pxBuffer ) +{ + size_t uxFront = pxBuffer->uxFront; + size_t uxTail = pxBuffer->uxTail; + + return uxStreamBufferSpace( pxBuffer, uxFront, uxTail ); +} +/*-----------------------------------------------------------*/ + +/** + * @brief Get the number of items which can be read from the tail before + * reaching the head. + * @param[in] pxBuffer: The circular stream buffer. + * @return The number of items which can be read from the tail before + * reaching the head. + */ +size_t uxStreamBufferGetSize( const StreamBuffer_t * pxBuffer ) +{ + size_t uxHead = pxBuffer->uxHead; + size_t uxTail = pxBuffer->uxTail; + + return uxStreamBufferDistance( pxBuffer, uxTail, uxHead ); +} +/*-----------------------------------------------------------*/ + +/** + * @brief Get the space between the mid pointer and the head in the stream + * buffer. + * @param[in] pxBuffer: The circular stream buffer. + * @return The space between the mid pointer and the head. + */ +size_t uxStreamBufferMidSpace( const StreamBuffer_t * pxBuffer ) +{ + size_t uxHead = pxBuffer->uxHead; + size_t uxMid = pxBuffer->uxMid; + + return uxStreamBufferDistance( pxBuffer, uxMid, uxHead ); +} +/*-----------------------------------------------------------*/ + +/** + * @brief Move Clear the stream buffer. + * @param[in] pxBuffer: The circular stream buffer. + */ +void vStreamBufferClear( StreamBuffer_t * pxBuffer ) +{ + /* Make the circular buffer empty */ + pxBuffer->uxHead = 0U; + pxBuffer->uxTail = 0U; + pxBuffer->uxFront = 0U; + pxBuffer->uxMid = 0U; +} + +/*-----------------------------------------------------------*/ + +/** + * @brief Move the mid pointer forward by given byte count + * @param[in] pxBuffer: The circular stream buffer. + * @param[in] uxCount: The byte count by which the mid pointer is to be moved. + */ +void vStreamBufferMoveMid( StreamBuffer_t * pxBuffer, + size_t uxCount ) +{ + /* Increment uxMid, but no further than uxHead */ + size_t uxSize = uxStreamBufferMidSpace( pxBuffer ); + size_t uxMid = pxBuffer->uxMid; + size_t uxMoveCount = uxCount; + + if( uxMoveCount > uxSize ) + { + uxMoveCount = uxSize; + } + + uxMid += uxMoveCount; + + if( uxMid >= pxBuffer->LENGTH ) + { + uxMid -= pxBuffer->LENGTH; + } + + pxBuffer->uxMid = uxMid; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Check whether the value in left is less than or equal to the + * value in right from the perspective of the circular stream + * buffer. + * @param[in] pxBuffer: The circular stream buffer. + * @param[in] uxLeft: The left pointer in the stream buffer. + * @param[in] uxRight: The right value pointer in the stream buffer. + * @return pdTRUE if uxLeft <= uxRight, else pdFALSE. + */ +BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t * pxBuffer, + const size_t uxLeft, + const size_t uxRight ) +{ + BaseType_t xReturn; + size_t uxTail = pxBuffer->uxTail; + + /* Returns true if ( uxLeft < uxRight ) */ + if( ( ( ( uxLeft < uxTail ) ? 1U : 0U ) ^ ( ( uxRight < uxTail ) ? 1U : 0U ) ) != 0U ) + { + if( uxRight < uxTail ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + else + { + if( uxLeft <= uxRight ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +/** + * @brief Get the pointer to data and the amount of data which can be read in one go. + * + * @param[in] pxBuffer: The circular stream buffer. + * @param[out] ppucData: Pointer to the data pointer which will point to the + * data which can be read. + * + * @return The number of bytes which can be read in one go (which might be less than + * actual number of available bytes since this is a circular buffer and tail + * can loop back to the start of the buffer). + */ +size_t uxStreamBufferGetPtr( StreamBuffer_t * pxBuffer, + uint8_t ** ppucData ) +{ + size_t uxNextTail = pxBuffer->uxTail; + size_t uxSize = uxStreamBufferGetSize( pxBuffer ); + + *ppucData = pxBuffer->ucArray + uxNextTail; + + return FreeRTOS_min_uint32( uxSize, pxBuffer->LENGTH - uxNextTail ); +} +/*-----------------------------------------------------------*/ + /** * @brief Adds data to a stream buffer. * diff --git a/include/FreeRTOS_IP.h b/include/FreeRTOS_IP.h index 48a900e359..665da6e119 100644 --- a/include/FreeRTOS_IP.h +++ b/include/FreeRTOS_IP.h @@ -198,75 +198,18 @@ #define FreeRTOS_ntohs( x ) FreeRTOS_htons( x ) #define FreeRTOS_ntohl( x ) FreeRTOS_htonl( x ) - #if ( ipconfigHAS_INLINE_FUNCTIONS == 1 ) - - static portINLINE int32_t FreeRTOS_max_int32( int32_t a, - int32_t b ); - static portINLINE uint32_t FreeRTOS_max_uint32( uint32_t a, - uint32_t b ); - static portINLINE int32_t FreeRTOS_min_int32( int32_t a, - int32_t b ); - static portINLINE uint32_t FreeRTOS_min_uint32( uint32_t a, - uint32_t b ); - static portINLINE uint32_t FreeRTOS_round_up( uint32_t a, - uint32_t d ); - static portINLINE uint32_t FreeRTOS_round_down( uint32_t a, - uint32_t d ); - static portINLINE BaseType_t FreeRTOS_min_BaseType( BaseType_t a, - BaseType_t b ); - - static portINLINE int32_t FreeRTOS_max_int32( int32_t a, - int32_t b ) - { - return ( a >= b ) ? a : b; - } - static portINLINE uint32_t FreeRTOS_max_uint32( uint32_t a, - uint32_t b ) - { - return ( a >= b ) ? a : b; - } - static portINLINE int32_t FreeRTOS_min_int32( int32_t a, - int32_t b ) - { - return ( a <= b ) ? a : b; - } - static portINLINE uint32_t FreeRTOS_min_uint32( uint32_t a, - uint32_t b ) - { - return ( a <= b ) ? a : b; - } - static portINLINE uint32_t FreeRTOS_round_up( uint32_t a, - uint32_t d ) - { - return d * ( ( a + d - 1U ) / d ); - } - static portINLINE uint32_t FreeRTOS_round_down( uint32_t a, - uint32_t d ) - { - return d * ( a / d ); - } - - static portINLINE BaseType_t FreeRTOS_min_BaseType( BaseType_t a, - BaseType_t b ) - { - return ( a <= b ) ? a : b; - } - - #else /* if ( ipconfigHAS_INLINE_FUNCTIONS == 1 ) */ - - #define FreeRTOS_max_int32( a, b ) ( ( ( ( int32_t ) ( a ) ) >= ( ( int32_t ) ( b ) ) ) ? ( ( int32_t ) ( a ) ) : ( ( int32_t ) ( b ) ) ) - #define FreeRTOS_max_uint32( a, b ) ( ( ( ( uint32_t ) ( a ) ) >= ( ( uint32_t ) ( b ) ) ) ? ( ( uint32_t ) ( a ) ) : ( ( uint32_t ) ( b ) ) ) - - #define FreeRTOS_min_int32( a, b ) ( ( ( ( int32_t ) a ) <= ( ( int32_t ) b ) ) ? ( ( int32_t ) a ) : ( ( int32_t ) b ) ) - #define FreeRTOS_min_uint32( a, b ) ( ( ( ( uint32_t ) a ) <= ( ( uint32_t ) b ) ) ? ( ( uint32_t ) a ) : ( ( uint32_t ) b ) ) - -/* Round-up: divide a by d and round=up the result. */ - #define FreeRTOS_round_up( a, d ) ( ( ( uint32_t ) ( d ) ) * ( ( ( ( uint32_t ) ( a ) ) + ( ( uint32_t ) ( d ) ) - 1UL ) / ( ( uint32_t ) ( d ) ) ) ) - #define FreeRTOS_round_down( a, d ) ( ( ( uint32_t ) ( d ) ) * ( ( ( uint32_t ) ( a ) ) / ( ( uint32_t ) ( d ) ) ) ) - - #define FreeRTOS_min_BaseType( a, b ) ( ( ( BaseType_t ) ( a ) ) <= ( ( BaseType_t ) ( b ) ) ? ( ( BaseType_t ) ( a ) ) : ( ( BaseType_t ) ( b ) ) ) - - #endif /* ipconfigHAS_INLINE_FUNCTIONS */ + int32_t FreeRTOS_max_int32( int32_t a, + int32_t b ); + uint32_t FreeRTOS_max_uint32( uint32_t a, + uint32_t b ); + int32_t FreeRTOS_min_int32( int32_t a, + int32_t b ); + uint32_t FreeRTOS_min_uint32( uint32_t a, + uint32_t b ); + uint32_t FreeRTOS_round_up( uint32_t a, + uint32_t d ); + uint32_t FreeRTOS_round_down( uint32_t a, + uint32_t d ); #define ipMS_TO_MIN_TICKS( xTimeInMs ) ( ( pdMS_TO_TICKS( ( xTimeInMs ) ) < ( ( TickType_t ) 1U ) ) ? ( ( TickType_t ) 1U ) : pdMS_TO_TICKS( ( xTimeInMs ) ) ) diff --git a/include/FreeRTOS_IP_Private.h b/include/FreeRTOS_IP_Private.h index 92ba8ba020..e065de1d28 100644 --- a/include/FreeRTOS_IP_Private.h +++ b/include/FreeRTOS_IP_Private.h @@ -88,15 +88,8 @@ #include "pack_struct_end.h" typedef struct xETH_HEADER EthernetHeader_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ) - { - return ( EthernetHeader_t * ) pvArgument; - } - - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ) - { - return ( const EthernetHeader_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( EthernetHeader_t ); #include "pack_struct_start.h" @@ -132,14 +125,8 @@ #include "pack_struct_end.h" typedef struct xIP_HEADER IPHeader_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPHeader_t ) - { - return ( IPHeader_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPHeader_t ) - { - return ( const IPHeader_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPHeader_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPHeader_t ); #include "pack_struct_start.h" @@ -154,14 +141,8 @@ #include "pack_struct_end.h" typedef struct xICMP_HEADER ICMPHeader_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ) - { - return ( ICMPHeader_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ) - { - return ( const ICMPHeader_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ICMPHeader_t ); #include "pack_struct_start.h" @@ -208,14 +189,8 @@ #include "pack_struct_end.h" typedef struct xARP_PACKET ARPPacket_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ARPPacket_t ) - { - return ( ARPPacket_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ARPPacket_t ) - { - return ( const ARPPacket_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( ARPPacket_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ARPPacket_t ); #include "pack_struct_start.h" @@ -227,14 +202,8 @@ #include "pack_struct_end.h" typedef struct xIP_PACKET IPPacket_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPPacket_t ) - { - return ( IPPacket_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPPacket_t ) - { - return ( const IPPacket_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPPacket_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPPacket_t ); #include "pack_struct_start.h" @@ -247,11 +216,7 @@ #include "pack_struct_end.h" typedef struct xICMP_PACKET ICMPPacket_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPPacket_t ) - { - return ( ICMPPacket_t * ) pvArgument; - } - + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPPacket_t ); #include "pack_struct_start.h" struct xUDP_PACKET @@ -263,14 +228,8 @@ #include "pack_struct_end.h" typedef struct xUDP_PACKET UDPPacket_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( UDPPacket_t ) - { - return ( UDPPacket_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( UDPPacket_t ) - { - return ( const UDPPacket_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( UDPPacket_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( UDPPacket_t ); #include "pack_struct_start.h" struct xTCP_PACKET @@ -282,15 +241,8 @@ #include "pack_struct_end.h" typedef struct xTCP_PACKET TCPPacket_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPPacket_t ) - { - return ( TCPPacket_t * ) pvArgument; - } - - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TCPPacket_t ) - { - return ( const TCPPacket_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPPacket_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TCPPacket_t ); /** @@ -305,14 +257,8 @@ ICMPPacket_t xICMPPacket; /**< Union member: ICMP packet struct */ } ProtocolPacket_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ) - { - return ( ProtocolPacket_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ) - { - return ( const ProtocolPacket_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t ); /** * Union for protocol headers to save space (RAM). Any packet cannot have more than one of @@ -325,15 +271,8 @@ TCPHeader_t xTCPHeader; /**< Union member: TCP header */ } ProtocolHeaders_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ) - { - return ( ProtocolHeaders_t * ) pvArgument; - } - - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ) - { - return ( const ProtocolHeaders_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t ); /* The maximum UDP payload length. */ #define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER ) @@ -815,14 +754,8 @@ } u; /**< Union of TCP/UDP socket */ } FreeRTOS_Socket_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ) - { - return ( FreeRTOS_Socket_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ) - { - return ( const FreeRTOS_Socket_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t ); #if ( ipconfigUSE_TCP == 1 ) @@ -900,22 +833,9 @@ * if they are not being used anywhere. But their use depends on the * application and hence these functions are defined unconditionally. */ - static portINLINE uint32_t ulChar2u32( const uint8_t * apChr ); - static portINLINE uint32_t ulChar2u32( const uint8_t * apChr ) - { - return ( ( ( uint32_t ) apChr[ 0 ] ) << 24 ) | - ( ( ( uint32_t ) apChr[ 1 ] ) << 16 ) | - ( ( ( uint32_t ) apChr[ 2 ] ) << 8 ) | - ( ( ( uint32_t ) apChr[ 3 ] ) ); - } + extern uint32_t ulChar2u32( const uint8_t * pucPtr ); - static portINLINE uint16_t usChar2u16( const uint8_t * apChr ); - static portINLINE uint16_t usChar2u16( const uint8_t * apChr ) - { - return ( uint16_t ) - ( ( ( ( uint32_t ) apChr[ 0 ] ) << 8 ) | - ( ( ( uint32_t ) apChr[ 1 ] ) ) ); - } + extern uint16_t usChar2u16( const uint8_t * pucPtr ); /* Check a single socket for retransmissions and timeouts */ BaseType_t xTCPSocketCheck( FreeRTOS_Socket_t * pxSocket ); @@ -980,14 +900,8 @@ EventGroupHandle_t xSelectGroup; } SocketSelect_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelect_t ) - { - return ( SocketSelect_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelect_t ) - { - return ( const SocketSelect_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelect_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelect_t ); extern void vSocketSelect( SocketSelect_t * pxSocketSet ); @@ -998,14 +912,8 @@ SocketSelect_t * pxSocketSet; /**< The event group for the socket select functionality. */ } SocketSelectMessage_t; - static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ) - { - return ( SocketSelectMessage_t * ) pvArgument; - } - static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ) - { - return ( const SocketSelectMessage_t * ) pvArgument; - } + extern ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ); + extern ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t ); #endif /* ipconfigSUPPORT_SELECT_FUNCTION */ diff --git a/include/FreeRTOS_Sockets.h b/include/FreeRTOS_Sockets.h index ac5218cbec..2bcad8a5d5 100644 --- a/include/FreeRTOS_Sockets.h +++ b/include/FreeRTOS_Sockets.h @@ -219,24 +219,7 @@ typedef struct xSOCKET * Socket_t; typedef struct xSOCKET const * ConstSocket_t; - static portINLINE BaseType_t xSocketValid( Socket_t xSocket ) - { - BaseType_t xReturnValue = pdFALSE; - - /* - * There are two values which can indicate an invalid socket: - * FREERTOS_INVALID_SOCKET and NULL. In order to compare against - * both values, the code cannot be compliant with rule 11.4, - * hence the Coverity suppression statement below. - */ - /* coverity[misra_c_2012_rule_11_4_violation] */ - if( ( xSocket != FREERTOS_INVALID_SOCKET ) && ( xSocket != NULL ) ) - { - xReturnValue = pdTRUE; - } - - return xReturnValue; - } + extern BaseType_t xSocketValid( Socket_t xSocket ); #if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) diff --git a/include/FreeRTOS_Stream_Buffer.h b/include/FreeRTOS_Stream_Buffer.h index ad333ccbee..224fb65aed 100644 --- a/include/FreeRTOS_Stream_Buffer.h +++ b/include/FreeRTOS_Stream_Buffer.h @@ -53,185 +53,42 @@ uint8_t ucArray[ sizeof( size_t ) ]; /**< array big enough to store any pointer address */ } StreamBuffer_t; - static portINLINE void vStreamBufferClear( StreamBuffer_t * pxBuffer ); - static portINLINE void vStreamBufferClear( StreamBuffer_t * pxBuffer ) - { - /* Make the circular buffer empty */ - pxBuffer->uxHead = 0U; - pxBuffer->uxTail = 0U; - pxBuffer->uxFront = 0U; - pxBuffer->uxMid = 0U; - } - + void vStreamBufferClear( StreamBuffer_t * pxBuffer ); /*-----------------------------------------------------------*/ - static portINLINE size_t uxStreamBufferSpace( const StreamBuffer_t * pxBuffer, - const size_t uxLower, - const size_t uxUpper ); - static portINLINE size_t uxStreamBufferSpace( const StreamBuffer_t * pxBuffer, - const size_t uxLower, - const size_t uxUpper ) - { -/* Returns the space between uxLower and uxUpper, which equals to the distance minus 1 */ - size_t uxCount; - - uxCount = pxBuffer->LENGTH + uxUpper - uxLower - 1U; - - if( uxCount >= pxBuffer->LENGTH ) - { - uxCount -= pxBuffer->LENGTH; - } - - return uxCount; - } + size_t uxStreamBufferSpace( const StreamBuffer_t * pxBuffer, + const size_t uxLower, + const size_t uxUpper ); /*-----------------------------------------------------------*/ - static portINLINE size_t uxStreamBufferDistance( const StreamBuffer_t * pxBuffer, - const size_t uxLower, - const size_t uxUpper ); - static portINLINE size_t uxStreamBufferDistance( const StreamBuffer_t * pxBuffer, - const size_t uxLower, - const size_t uxUpper ) - { -/* Returns the distance between uxLower and uxUpper */ - size_t uxCount; - - uxCount = pxBuffer->LENGTH + uxUpper - uxLower; - - if( uxCount >= pxBuffer->LENGTH ) - { - uxCount -= pxBuffer->LENGTH; - } - - return uxCount; - } + size_t uxStreamBufferDistance( const StreamBuffer_t * pxBuffer, + const size_t uxLower, + const size_t uxUpper ); /*-----------------------------------------------------------*/ - static portINLINE size_t uxStreamBufferGetSpace( const StreamBuffer_t * pxBuffer ); - static portINLINE size_t uxStreamBufferGetSpace( const StreamBuffer_t * pxBuffer ) - { -/* Returns the number of items which can still be added to uxHead - * before hitting on uxTail */ - size_t uxHead = pxBuffer->uxHead; - size_t uxTail = pxBuffer->uxTail; - - return uxStreamBufferSpace( pxBuffer, uxHead, uxTail ); - } + size_t uxStreamBufferGetSpace( const StreamBuffer_t * pxBuffer ); /*-----------------------------------------------------------*/ - static portINLINE size_t uxStreamBufferFrontSpace( const StreamBuffer_t * pxBuffer ); - static portINLINE size_t uxStreamBufferFrontSpace( const StreamBuffer_t * pxBuffer ) - { -/* Distance between uxFront and uxTail - * or the number of items which can still be added to uxFront, - * before hitting on uxTail */ - - size_t uxFront = pxBuffer->uxFront; - size_t uxTail = pxBuffer->uxTail; - - return uxStreamBufferSpace( pxBuffer, uxFront, uxTail ); - } + size_t uxStreamBufferFrontSpace( const StreamBuffer_t * pxBuffer ); /*-----------------------------------------------------------*/ - static portINLINE size_t uxStreamBufferGetSize( const StreamBuffer_t * pxBuffer ); - static portINLINE size_t uxStreamBufferGetSize( const StreamBuffer_t * pxBuffer ) - { -/* Returns the number of items which can be read from uxTail - * before reaching uxHead */ - size_t uxHead = pxBuffer->uxHead; - size_t uxTail = pxBuffer->uxTail; - - return uxStreamBufferDistance( pxBuffer, uxTail, uxHead ); - } + size_t uxStreamBufferGetSize( const StreamBuffer_t * pxBuffer ); /*-----------------------------------------------------------*/ - static portINLINE size_t uxStreamBufferMidSpace( const StreamBuffer_t * pxBuffer ); - static portINLINE size_t uxStreamBufferMidSpace( const StreamBuffer_t * pxBuffer ) - { -/* Returns the distance between uxHead and uxMid */ - size_t uxHead = pxBuffer->uxHead; - size_t uxMid = pxBuffer->uxMid; - - return uxStreamBufferDistance( pxBuffer, uxMid, uxHead ); - } + size_t uxStreamBufferMidSpace( const StreamBuffer_t * pxBuffer ); /*-----------------------------------------------------------*/ - static portINLINE void vStreamBufferMoveMid( StreamBuffer_t * pxBuffer, - size_t uxCount ); - static portINLINE void vStreamBufferMoveMid( StreamBuffer_t * pxBuffer, - size_t uxCount ) - { -/* Increment uxMid, but no further than uxHead */ - size_t uxSize = uxStreamBufferMidSpace( pxBuffer ); - size_t uxMid = pxBuffer->uxMid; - size_t uxMoveCount = uxCount; - - if( uxMoveCount > uxSize ) - { - uxMoveCount = uxSize; - } - - uxMid += uxMoveCount; - - if( uxMid >= pxBuffer->LENGTH ) - { - uxMid -= pxBuffer->LENGTH; - } - - pxBuffer->uxMid = uxMid; - } + void vStreamBufferMoveMid( StreamBuffer_t * pxBuffer, + size_t uxCount ); /*-----------------------------------------------------------*/ - static portINLINE BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t * pxBuffer, - const size_t uxLeft, - const size_t uxRight ); - static portINLINE BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t * pxBuffer, - const size_t uxLeft, - const size_t uxRight ) - { - BaseType_t xReturn; - size_t uxTail = pxBuffer->uxTail; - - /* Returns true if ( uxLeft < uxRight ) */ - if( ( ( ( uxLeft < uxTail ) ? 1U : 0U ) ^ ( ( uxRight < uxTail ) ? 1U : 0U ) ) != 0U ) - { - if( uxRight < uxTail ) - { - xReturn = pdTRUE; - } - else - { - xReturn = pdFALSE; - } - } - else - { - if( uxLeft <= uxRight ) - { - xReturn = pdTRUE; - } - else - { - xReturn = pdFALSE; - } - } - - return xReturn; - } + BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t * pxBuffer, + const size_t uxLeft, + const size_t uxRight ); /*-----------------------------------------------------------*/ - static portINLINE size_t uxStreamBufferGetPtr( StreamBuffer_t * pxBuffer, - uint8_t ** ppucData ); - static portINLINE size_t uxStreamBufferGetPtr( StreamBuffer_t * pxBuffer, - uint8_t ** ppucData ) - { - size_t uxNextTail = pxBuffer->uxTail; - size_t uxSize = uxStreamBufferGetSize( pxBuffer ); - - *ppucData = pxBuffer->ucArray + uxNextTail; - - return FreeRTOS_min_uint32( uxSize, pxBuffer->LENGTH - uxNextTail ); - } + size_t uxStreamBufferGetPtr( StreamBuffer_t * pxBuffer, + uint8_t ** ppucData ); /* * Add bytes to a stream buffer. diff --git a/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json b/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json index 8d1438c828..b096b3160b 100644 --- a/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json +++ b/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json @@ -9,6 +9,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto" ], diff --git a/test/cbmc/proofs/ARP/ARPGenerateRequestPacket/Makefile.json b/test/cbmc/proofs/ARP/ARPGenerateRequestPacket/Makefile.json index 3c588741cb..5a8c65f71d 100644 --- a/test/cbmc/proofs/ARP/ARPGenerateRequestPacket/Makefile.json +++ b/test/cbmc/proofs/ARP/ARPGenerateRequestPacket/Makefile.json @@ -7,6 +7,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto" ], "DEF": diff --git a/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json b/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json index b0c93322ad..e8b71ca0f8 100644 --- a/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json @@ -35,6 +35,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto" ], #That is the minimal required size for an ARPPacket_t plus offset in the buffer. diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json index 8cbf156395..988257c86f 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json @@ -9,6 +9,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto", "$(FREERTOS_PLUS_TCP)/portable/BufferManagement/BufferAllocation_1.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json index b995601a24..e82d297bde 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json @@ -10,6 +10,7 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/portable/BufferManagement/BufferAllocation_2.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto" diff --git a/test/cbmc/proofs/CheckOptions/Makefile.json b/test/cbmc/proofs/CheckOptions/Makefile.json index 1f90c77e8b..b57a8e6fd2 100644 --- a/test/cbmc/proofs/CheckOptions/Makefile.json +++ b/test/cbmc/proofs/CheckOptions/Makefile.json @@ -4,6 +4,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_TCP_WIN.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_TCP_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_Stream_Buffer.goto", diff --git a/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json b/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json index 61cd679916..6243308854 100644 --- a/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json +++ b/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json @@ -39,7 +39,8 @@ "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/FreeRTOS_TCP_IP.goto" + "$(FREERTOS_PLUS_TCP)/FreeRTOS_TCP_IP.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json b/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json index 2ba001dfb7..241279ab30 100644 --- a/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json +++ b/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json @@ -36,6 +36,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_TCP_IP.goto" ], "DEF": diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json b/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json index 47e58ab237..4b09d607c3 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json @@ -37,6 +37,8 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_Stream_Buffer.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_TCP_IP.goto" ], "DEF": diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c b/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c index 5b16730f7f..d938bbeb94 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c @@ -45,8 +45,8 @@ void publicTCPReturnPacket( FreeRTOS_Socket_t * pxSocket, BaseType_t xReleaseAfterSend ); /* Abstraction of pxDuplicateNetworkBufferWithDescriptor*/ -NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer, - BaseType_t xNewLength ) +NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer, + size_t xNewLength ) { NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); @@ -59,6 +59,28 @@ NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( NetworkBuffe return pxNetworkBuffer; } +uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, + size_t uxBufferLength, + BaseType_t xOutgoingPacket ) +{ + __CPROVER_assert( pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL" ); + __CPROVER_r_ok( pucEthernetBuffer, uxBufferLength ); + + uint16_t usReturn; + return usReturn; +} + +uint16_t usGenerateChecksum( uint16_t usSum, + const uint8_t * pucNextData, + size_t uxByteCount ) +{ + __CPROVER_assert( pucNextData != NULL, "The next data pointer cannot be NULL" ); + __CPROVER_r_ok( pucNextData, uxByteCount ); + + uint16_t usReturn; + return usReturn; +} + void harness() { FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); diff --git a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/Makefile.json b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/Makefile.json index f39ff8ca5b..4baf82b1f3 100644 --- a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/Makefile.json +++ b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/Makefile.json @@ -6,6 +6,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_UDP_IP.goto" ], "INSTFLAGS": diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json index 04a390c42c..9d2fa86c13 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json +++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json @@ -9,6 +9,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_TCP_IP.goto" ], "INSTFLAGS": diff --git a/test/unit-test/FreeRTOS_TCP_Unit_test.c b/test/unit-test/FreeRTOS_TCP_Unit_test.c index 9bf19303e9..49afa38ec1 100644 --- a/test/unit-test/FreeRTOS_TCP_Unit_test.c +++ b/test/unit-test/FreeRTOS_TCP_Unit_test.c @@ -4,7 +4,7 @@ /* Include standard libraries */ #include #include - +#include #include "FreeRTOS.h" #include "task.h" #include "list.h" diff --git a/test/unit-test/TCPFilePaths.cmake b/test/unit-test/TCPFilePaths.cmake index 266959efe3..ac1b42fdb2 100644 --- a/test/unit-test/TCPFilePaths.cmake +++ b/test/unit-test/TCPFilePaths.cmake @@ -21,3 +21,11 @@ set( TCP_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../portable/Compiler/MSVC" "${CMAKE_CURRENT_LIST_DIR}/stubs" ) +set( KERNEL_SOURCES + "${CMAKE_CURRENT_LIST_DIR}/../FreeRTOS-Kernel/croutine.c" + "${CMAKE_CURRENT_LIST_DIR}/../FreeRTOS-Kernel/event_groups.c" + "${CMAKE_CURRENT_LIST_DIR}/../FreeRTOS-Kernel/list.c" + "${CMAKE_CURRENT_LIST_DIR}/../FreeRTOS-Kernel/queue.c" + "${CMAKE_CURRENT_LIST_DIR}/../FreeRTOS-Kernel/stream_buffer.c" + "${CMAKE_CURRENT_LIST_DIR}/../FreeRTOS-Kernel/tasks.c" + "${CMAKE_CURRENT_LIST_DIR}/../FreeRTOS-Kernel/timers.c" ) diff --git a/test/unit-test/stubs/FreeRTOS_ARP_stubs.c b/test/unit-test/stubs/FreeRTOS_ARP_stubs.c index 79b33a1701..032dcbbebb 100644 --- a/test/unit-test/stubs/FreeRTOS_ARP_stubs.c +++ b/test/unit-test/stubs/FreeRTOS_ARP_stubs.c @@ -1,139 +1,109 @@ -/* IPv4 multi-cast addresses range from 224.0.0.0.0 to 240.0.0.0. */ -#define ipFIRST_MULTI_CAST_IPv4 0xE0000000UL -#define ipLAST_MULTI_CAST_IPv4 0xF0000000UL +/* Include Unity header */ +#include -/* For convenience, a MAC address of all 0xffs is defined const for quick - * reference. */ -const MACAddress_t xBroadcastMACAddress = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; +/* Include standard libraries */ +#include +#include +#include +#include "FreeRTOS.h" +#include "task.h" +#include "list.h" -/* Structure that stores the netmask, gateway address and DNS server addresses. */ -NetworkAddressingParameters_t xNetworkAddressing = { 0, 0, 0, 0, 0 }; +#include "FreeRTOS_IP.h" -/* The expected IP version and header length coded into the IP header itself. */ -#define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 ) +volatile BaseType_t xInsideInterrupt = pdFALSE; -void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) +size_t xPortGetMinimumEverFreeHeapSize( void ) { + return 0; } -/*-----------------------------------------------------------*/ -BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, - TickType_t * const pxTicksToWait ) +const char * pcApplicationHostnameHook( void ) { - return pdTRUE; } -/*-----------------------------------------------------------*/ - -void vTaskDelay( const TickType_t xTicksToDelay ) +uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress, + uint16_t usSourcePort, + uint32_t ulDestinationAddress, + uint16_t usDestinationPort ) { } -/*-----------------------------------------------------------*/ - -BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress ) +BaseType_t xNetworkInterfaceInitialise( void ) { - BaseType_t xReturn; - uint32_t ulIP = FreeRTOS_ntohl( ulIPAddress ); - - if( ( ulIP >= ipFIRST_MULTI_CAST_IPv4 ) && ( ulIP < ipLAST_MULTI_CAST_IPv4 ) ) - { - xReturn = pdTRUE; - } - else - { - xReturn = pdFALSE; - } - - return xReturn; } -/*-----------------------------------------------------------*/ - -void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress, - MACAddress_t * pxMACAddress ) +void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) { - uint32_t ulIP = FreeRTOS_ntohl( ulIPAddress ); - - pxMACAddress->ucBytes[ 0 ] = ( uint8_t ) 0x01U; - pxMACAddress->ucBytes[ 1 ] = ( uint8_t ) 0x00U; - pxMACAddress->ucBytes[ 2 ] = ( uint8_t ) 0x5EU; - pxMACAddress->ucBytes[ 3 ] = ( uint8_t ) ( ( ulIP >> 16 ) & 0x7fU ); /* Use 7 bits. */ - pxMACAddress->ucBytes[ 4 ] = ( uint8_t ) ( ( ulIP >> 8 ) & 0xffU ); /* Use 8 bits. */ - pxMACAddress->ucBytes[ 5 ] = ( uint8_t ) ( ( ulIP ) & 0xffU ); /* Use 8 bits. */ } -/*-----------------------------------------------------------*/ - -TickType_t xTaskGetTickCount( void ) +BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber ) { - TickType_t xTicks; - - return xTicks; } - -BaseType_t xSendEventToIPTask( eIPEvent_t eEvent ) +void vApplicationDaemonTaskStartupHook( void ) { - return 0; } -/*-----------------------------------------------------------*/ - -BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, - BaseType_t bReleaseAfterSend ) +void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, + StackType_t ** ppxTimerTaskStackBuffer, + uint32_t * pulTimerTaskStackSize ) { - return pdPASS; } -/*-----------------------------------------------------------*/ - -NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, - TickType_t xBlockTimeTicks ) +void vPortDeleteThread( void * pvTaskToDelete ) { - return NULL; } -/*-----------------------------------------------------------*/ - -BaseType_t xIsCallingFromIPTask( void ) +void vApplicationIdleHook( void ) { - BaseType_t xReturn = 0; - - return xReturn; } -/*-----------------------------------------------------------*/ - -void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +void vApplicationTickHook( void ) { } -/*-----------------------------------------------------------*/ - -BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, - TickType_t uxTimeout ) +unsigned long ulGetRunTimeCounterValue( void ) +{ +} +void vPortEndScheduler( void ) +{ +} +BaseType_t xPortStartScheduler( void ) +{ +} +void vPortEnterCritical( void ) { - BaseType_t xReturn; +} +void vPortExitCritical( void ) +{ +} - return xReturn; +void * pvPortMalloc( size_t xWantedSize ) +{ + return malloc( xWantedSize ); } -/*-----------------------------------------------------------*/ -NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer, - size_t uxNewLength ) +void vPortFree( void * pv ) { - NetworkBufferDescriptor_t * pxNewBuffer; + free( pv ); +} - return pxNewBuffer; +StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + TaskFunction_t pxCode, + void * pvParameters ) +{ +} +void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber ) +{ +} +void vPortCloseRunningThread( void * pvTaskToDelete, + volatile BaseType_t * pxPendYield ) +{ +} +void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, + StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize ) +{ +} +void vConfigureTimerForRunTimeStats( void ) +{ } -/*-----------------------------------------------------------*/ -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. */ - } -}; +BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, + BaseType_t bReleaseAfterSend ) +{ + return pdPASS; +} +/*-----------------------------------------------------------*/ diff --git a/test/unit-test/unit_test_build.cmake b/test/unit-test/unit_test_build.cmake index bf5f334c88..48cdc14720 100644 --- a/test/unit-test/unit_test_build.cmake +++ b/test/unit-test/unit_test_build.cmake @@ -28,6 +28,9 @@ list(APPEND mock_define_list # list the files you would like to test here list(APPEND real_source_files ${TCP_SOURCES} + ${KERNEL_SOURCES} + ${MODULE_ROOT_DIR}/test/unit-test/stubs/FreeRTOS_ARP_stubs.c + ${MODULE_ROOT_DIR}/portable/BufferManagement/BufferAllocation_2.c ) # list the directories the module under test includes list(APPEND real_include_directories From ffc9612721df715ce0a93c0f83b6b61d0a176e76 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Sat, 13 Feb 2021 02:32:04 +0800 Subject: [PATCH 14/33] Do not release a network buffer if it equals to NULL (#191) Co-authored-by: Hein Tibosch Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- FreeRTOS_TCP_IP.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/FreeRTOS_TCP_IP.c b/FreeRTOS_TCP_IP.c index abbf923de3..bd51860cf3 100644 --- a/FreeRTOS_TCP_IP.c +++ b/FreeRTOS_TCP_IP.c @@ -810,12 +810,14 @@ { pxNetworkBuffer = pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, ( size_t ) pxNetworkBuffer->xDataLength ); - if( pxNetworkBuffer == NULL ) + if( pxNetworkBuffer != NULL ) + { + xDoRelease = pdTRUE; + } + else { FreeRTOS_debug_printf( ( "prvTCPReturnPacket: duplicate failed\n" ) ); } - - xDoRelease = pdTRUE; } } #endif /* ipconfigZERO_COPY_TX_DRIVER */ From 245d1c517700ed82f37ade1175081179638cfadd Mon Sep 17 00:00:00 2001 From: alfred gedeon <28123637+alfred2g@users.noreply.github.com> Date: Mon, 15 Feb 2021 17:51:51 -0800 Subject: [PATCH 15/33] Circumvent Qemu MPS2 networking bug (#142) * Add support for MPS2 networking with lan9118/lan9220 * Fix uncrustify errors * Enable network interrupt handling * Add network interrupt support to Qemu MPS2 AN385 * Fix function comment * Fix Uncrustify errors * Fix Uncrustify errors * Fix Uncrustify Errors * Fix typo * Cirumvent Qemu MPS2 network bug * Remove commented code, add doxygen comment --- .../MPS2_AN385/NetworkInterface.c | 66 +++++++++++-------- .../ether_lan9118/smsc9220_eth_drv.c | 55 +++++++++++++++- 2 files changed, 94 insertions(+), 27 deletions(-) diff --git a/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c b/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c index c3169fc205..1cfa0ef74d 100644 --- a/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c +++ b/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c @@ -72,7 +72,6 @@ #define niMAX_TX_ATTEMPTS ( 5 ) - /* ============================= Static Prototypes ========================= */ static void rx_task( void * pvParameters ); @@ -96,15 +95,13 @@ static struct smsc9220_eth_dev_t SMSC9220_ETH_DEV = static void print_hex( unsigned const char * const bin_data, size_t len ); - /* ============================= Extern Variables ========================== */ /* defined in main_networking.c */ extern uint8_t ucMACAddress[ SMSC9220_HWADDR_SIZE ]; /* 6 bytes */ - /* ============================= Static Variables ========================== */ static TaskHandle_t xRxHanderTask = NULL; - +static SemaphoreHandle_t xSemaphore = NULL; /* ============================= Static Functions ========================== */ @@ -168,10 +165,31 @@ static void set_mac( const uint8_t * addr ) } } +void EthernetISR( void ) +{ + const struct smsc9220_eth_dev_t * dev = &SMSC9220_ETH_DEV; + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + + configASSERT( xRxHanderTask ); + + if( smsc9220_get_interrupt( dev, + SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ) ) + { + configASSERT( xSemaphore ); + xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ); + + smsc9220_disable_interrupt( dev, + SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ); + smsc9220_clear_interrupt( dev, + SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ); + } + + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); +} + /** - * @brief function to poll the netwrok card(qemu emulation) as we faced some - * problems with the network interrupt being fired for no reason at - * a very high rate which made the program not progress + * @brief function to wait on a semaphore from the interrupt handler of the + * network card when data is available */ static void rx_task( void * pvParameters ) { @@ -184,20 +202,13 @@ static void rx_task( void * pvParameters ) for( ; ; ) { - if( ( smsc9220_get_interrupt( dev, - SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ) ) ) - { /* data received */ - smsc9220_clear_interrupt( dev, - SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ); - xResult = pdPASS; - } - else - { - vTaskDelay( xBlockTime ); - continue; - } + configASSERT( xSemaphore ); + xSemaphoreTake( xSemaphore, + portMAX_DELAY ); packet_rx(); + smsc9220_clear_interrupt( dev, + SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ); smsc9220_enable_interrupt( dev, SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ); } } @@ -210,9 +221,8 @@ static void packet_rx() uint32_t data_read; FreeRTOS_debug_printf( ( "Enter\n" ) ); - data_read = low_level_input( &pxNetworkBuffer ); - if( data_read > 0 ) + while( ( data_read = low_level_input( &pxNetworkBuffer ) ) ) { xRxEvent.pvData = ( void * ) pxNetworkBuffer; @@ -234,7 +244,7 @@ static uint32_t low_level_input( NetworkBufferDescriptor_t ** pxNetworkBuffer ) FreeRTOS_debug_printf( ( "Enter\n" ) ); - message_length = smsc9220_peek_next_packet_size( dev ); + message_length = smsc9220_peek_next_packet_size2( dev ); if( message_length != 0 ) { @@ -245,11 +255,11 @@ static uint32_t low_level_input( NetworkBufferDescriptor_t ** pxNetworkBuffer ) { ( *pxNetworkBuffer )->xDataLength = message_length; - received_bytes = smsc9220_receive_by_chunks( dev, - ( *pxNetworkBuffer )->pucEthernetBuffer, - message_length ); /* not used */ + received_bytes = smsc9220_receive_by_chunks2( dev, + ( *pxNetworkBuffer )->pucEthernetBuffer, + message_length ); /* not used */ ( *pxNetworkBuffer )->xDataLength = received_bytes; - FreeRTOS_debug_printf( ( "incoming data < < < < < < < < < < read: %d length: %d\n", + FreeRTOS_debug_printf( ( "Incoming data < < < < < < < < < < read: %d length: %d\n", received_bytes, message_length ) ); print_hex( ( *pxNetworkBuffer )->pucEthernetBuffer, @@ -273,6 +283,8 @@ BaseType_t xNetworkInterfaceInitialise( void ) enum smsc9220_error_t err; FreeRTOS_debug_printf( ( "Enter\n" ) ); + xSemaphore = xSemaphoreCreateBinary(); + configASSERT( xSemaphore ); if( xRxHanderTask == NULL ) { @@ -283,6 +295,7 @@ BaseType_t xNetworkInterfaceInitialise( void ) configMAX_PRIORITIES - 4, &xRxHanderTask ); configASSERT( xReturn != 0 ); + configASSERT( xRxHanderTask ); } err = smsc9220_init( dev, wait_ms_function ); @@ -307,6 +320,7 @@ BaseType_t xNetworkInterfaceInitialise( void ) set_mac( ucMACAddress ); NVIC_SetPriority( ETHERNET_IRQn, configMAC_INTERRUPT_PRIORITY ); smsc9220_enable_interrupt( dev, SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL ); + NVIC_EnableIRQ( ETHERNET_IRQn ); } FreeRTOS_debug_printf( ( "Exit\n" ) ); diff --git a/portable/NetworkInterface/MPS2_AN385/ether_lan9118/smsc9220_eth_drv.c b/portable/NetworkInterface/MPS2_AN385/ether_lan9118/smsc9220_eth_drv.c index 8a8305b1a3..5980d791eb 100644 --- a/portable/NetworkInterface/MPS2_AN385/ether_lan9118/smsc9220_eth_drv.c +++ b/portable/NetworkInterface/MPS2_AN385/ether_lan9118/smsc9220_eth_drv.c @@ -219,7 +219,9 @@ enum rx_fifo_status_bits_t */ enum irq_cfg_bits_t { - IRQ_CFG_IRQ_EN_INDEX = 8U + IRQ_CFG_IRQ_TYPE = 0U, + IRQ_CFG_IRQ_POL = 4U, + IRQ_CFG_IRQ_EN_INDEX = 8U, }; #define IRQ_CFG_INT_DEAS_MASK 0xFFU @@ -718,6 +720,8 @@ void smsc9220_init_irqs( const struct smsc9220_eth_dev_t * dev ) IRQ_CFG_INT_DEAS_POS, IRQ_CFG_INT_DEAS_10US ); /* enable interrupts */ + SET_BIT( register_map->irq_cfg, IRQ_CFG_IRQ_TYPE ); + SET_BIT( register_map->irq_cfg, IRQ_CFG_IRQ_POL ); SET_BIT( register_map->irq_cfg, IRQ_CFG_IRQ_EN_INDEX ); } @@ -1198,6 +1202,55 @@ uint32_t smsc9220_receive_by_chunks( const struct smsc9220_eth_dev_t * dev, return packet_length_byte; } +/*! + * @brief second version to circumvent a bug + * in quemu where the peeked message + * size is different than the actual message size + */ +uint32_t smsc9220_receive_by_chunks2( const struct smsc9220_eth_dev_t * dev, + char * data, + uint32_t dlen ) +{ + uint32_t rxfifo_inf = 0; + uint32_t rxfifo_stat = 0; + /*uint32_t packet_length_byte = 0; */ + struct smsc9220_eth_reg_map_t * register_map = + ( struct smsc9220_eth_reg_map_t * ) dev->cfg->base; + + if( !data ) + { + return 0; /* Invalid input parameter, cannot read */ + } + + dev->data->current_rx_size_words = dlen; + + empty_rx_fifo( dev, ( uint8_t * ) data, dlen ); + dev->data->current_rx_size_words = 0; + return dlen; +} + +/*! + * @brief second version to circumvent a bug + * in quemu where the peeked message + * size is different than the actual message size + */ +uint32_t smsc9220_peek_next_packet_size2( const struct + smsc9220_eth_dev_t * dev ) +{ + uint32_t packet_size = 0; + struct smsc9220_eth_reg_map_t * register_map = + ( struct smsc9220_eth_reg_map_t * ) dev->cfg->base; + + if( smsc9220_get_rxfifo_data_used_space( dev ) ) + { + packet_size = GET_BIT_FIELD( register_map->rx_status_port, + RX_FIFO_STATUS_PKT_LENGTH_MASK, + RX_FIFO_STATUS_PKT_LENGTH_POS ); + } + + return packet_size; +} + uint32_t smsc9220_peek_next_packet_size( const struct smsc9220_eth_dev_t * dev ) { From 38c4054b45b556ccc2544f4e1593c37247284b9b Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri, 19 Feb 2021 08:59:58 -0800 Subject: [PATCH 16/33] Add a project for static analysis (#195) * Add entropy * remove warning * Remove unwanted changes * Update tcp_mem_stats.c * Add Coverity * Remove unused files * Add some features * clean up * More clean up * Unwanted additions removal * Clean up * Add 32-bit compile option * Update after comments * Uncrustify --- test/Coverity/CMakeLists.txt | 61 ++++ test/Coverity/ConfigFiles/FreeRTOSConfig.h | 119 +++++++ test/Coverity/ConfigFiles/FreeRTOSIPConfig.h | 310 ++++++++++++++++++ test/Coverity/ConfigFiles/pack_struct_end.h | 35 ++ test/Coverity/ConfigFiles/pack_struct_start.h | 33 ++ test/Coverity/ConfigFiles/portmacro.h | 161 +++++++++ test/Coverity/Portable.c | 112 +++++++ 7 files changed, 831 insertions(+) create mode 100644 test/Coverity/CMakeLists.txt create mode 100644 test/Coverity/ConfigFiles/FreeRTOSConfig.h create mode 100644 test/Coverity/ConfigFiles/FreeRTOSIPConfig.h create mode 100644 test/Coverity/ConfigFiles/pack_struct_end.h create mode 100644 test/Coverity/ConfigFiles/pack_struct_start.h create mode 100644 test/Coverity/ConfigFiles/portmacro.h create mode 100644 test/Coverity/Portable.c diff --git a/test/Coverity/CMakeLists.txt b/test/Coverity/CMakeLists.txt new file mode 100644 index 0000000000..e423334534 --- /dev/null +++ b/test/Coverity/CMakeLists.txt @@ -0,0 +1,61 @@ +# Minimum required version of CMake +cmake_minimum_required ( VERSION 3.13.0 ) + +# Name of the project +project ( "FreeRTOS+TCP Static analysis" + VERSION 1.0.0 + LANGUAGES C ) + +# Allow the project to be organized into folders. +set_property( GLOBAL PROPERTY USE_FOLDERS ON ) + +# Use C90. +set( CMAKE_C_STANDARD 90 ) +set( CMAKE_C_STANDARD_REQUIRED ON ) + +# Do not allow in-source build. +if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) + message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) +endif() + +# Set global path variables. +get_filename_component(__MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) +set( MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "FreeRTOS-Plus-TCP repository root." ) + +# Set the kernel directory +set( KERNEL_DIRECTORY ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel ) + +# If the kernel is not submoduled, download it. +if( NOT EXISTS ${KERNEL_DIRECTORY}/include ) + # Inform the user of the actions + message( STATUS "FreeRTOS-Kernel is required for this build. Submoduling it..." ) + execute_process( COMMAND git submodule update --init --checkout ${KERNEL_DIRECTORY} + WORKING_DIRECTORY ${MODULE_ROOT_DIR} ) +endif() + +# Add kernel sources to a list +file( GLOB KERNEL_SOURCES + ${KERNEL_DIRECTORY}/*.c ) + +# Add TCP sources to a list +file( GLOB TCP_SOURCES + ${MODULE_ROOT_DIR}/*.c ) + +# A better way would be to create a library such that all other dependencies are +# ignored by the static analysis tool. But, since +TCP is very closely linked +# with the FreeRTOS-Kernel, an executable had to be created. + +# Add the executable for static analysis +add_executable( StaticAnalysis ${TCP_SOURCES} + ${KERNEL_SOURCES} + ${CMAKE_CURRENT_LIST_DIR}/Portable.c + ${MODULE_ROOT_DIR}/portable/BufferManagement/BufferAllocation_2.c ) + +# Link the include directories with the target +target_include_directories( StaticAnalysis + PUBLIC "${KERNEL_DIRECTORY}/include" + PUBLIC "${MODULE_ROOT_DIR}/test/Coverity/ConfigFiles" + PUBLIC "${MODULE_ROOT_DIR}/include" ) + +# Uncomment the below line if the desired platform is 32-bit +# set_target_properties( StaticAnalysis PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" ) diff --git a/test/Coverity/ConfigFiles/FreeRTOSConfig.h b/test/Coverity/ConfigFiles/FreeRTOSConfig.h new file mode 100644 index 0000000000..ac5afdbe8b --- /dev/null +++ b/test/Coverity/ConfigFiles/FreeRTOSConfig.h @@ -0,0 +1,119 @@ +/* + * FreeRTOS Kernel V10.3.0 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- +* Application specific definitions. +* +* These definitions should be adjusted for your particular hardware and +* application requirements. +* +* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE +* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See +* http://www.freertos.org/a00110.html +*----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 +#define configUSE_IDLE_HOOK 1 +#define configUSE_TICK_HOOK 1 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 1 +#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 12 ) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 20 +#define configUSE_MALLOC_FAILED_HOOK 1 +#define configUSE_APPLICATION_TASK_TAG 1 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_ALTERNATIVE_API 0 +#define configUSE_QUEUE_SETS 1 +#define configUSE_TASK_NOTIFICATIONS 1 +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) + +/* Software timer related configuration options. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define configTIMER_QUEUE_LENGTH 20 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +#define configMAX_PRIORITIES ( 7 ) + +/* Run time stats gathering configuration options. */ +unsigned long ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */ +void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */ +#define configGENERATE_RUN_TIME_STATS 1 +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats() +#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue() + +/* Co-routine related configuration options. */ +#define configUSE_CO_ROUTINES 1 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* This demo makes use of one or more example stats formatting functions. These + * format the raw data provided by the uxTaskGetSystemState() function in to human + * readable ASCII form. See the notes in the implementation of vTaskList() within + * FreeRTOS/Source/tasks.c for limitations. */ +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 + +/* Set the following definitions to 1 to include the API function, or zero + * to exclude the API function. In most cases the linker will remove unused + * functions anyway. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTaskAbortDelay 1 + +/* Config assert should be defined while developing. For the static analysis + * though this should be left undefined. */ +#define configASSERT( x ) + +#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0 + +#endif /* FREERTOS_CONFIG_H */ diff --git a/test/Coverity/ConfigFiles/FreeRTOSIPConfig.h b/test/Coverity/ConfigFiles/FreeRTOSIPConfig.h new file mode 100644 index 0000000000..f0dad0cb82 --- /dev/null +++ b/test/Coverity/ConfigFiles/FreeRTOSIPConfig.h @@ -0,0 +1,310 @@ +/* + * FreeRTOS Kernel V10.2.0 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * 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 + */ + + +/***************************************************************************** +* +* See the following URL for configuration information. +* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html +* +*****************************************************************************/ + +#ifndef FREERTOS_IP_CONFIG_H +#define FREERTOS_IP_CONFIG_H + +#define _static + +#define ipconfigUSE_ARP_REMOVE_ENTRY 1 +#define ipconfigUSE_ARP_REVERSED_LOOKUP 1 + +/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to + * 1 then FreeRTOS_debug_printf should be defined to the function used to print + * out the debugging messages. */ +#define ipconfigHAS_DEBUG_PRINTF 0 +#if ( ipconfigHAS_DEBUG_PRINTF == 1 ) + #define FreeRTOS_debug_printf( X ) configPRINTF( X ) +#endif + +/* Set to 1 to print out non debugging messages, for example the output of the + * FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1 + * then FreeRTOS_printf should be set to the function used to print out the + * messages. */ +#define ipconfigHAS_PRINTF 0 +#if ( ipconfigHAS_PRINTF == 1 ) + #define FreeRTOS_printf( X ) configPRINTF( X ) +#endif + +/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing + * on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */ +#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN + +/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums) + * then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software + * stack repeating the checksum calculations. */ +#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1 + +/* Several API's will block until the result is known, or the action has been + * performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be + * set per socket, using setsockopt(). If not set, the times below will be + * used as defaults. */ +#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 ) +#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 ) + +/* Include support for DNS caching. For TCP, having a small DNS cache is very + * useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low + * and also DNS may use small timeouts. If a DNS reply comes in after the DNS + * socket has been destroyed, the result will be stored into the cache. The next + * call to FreeRTOS_gethostbyname() will return immediately, without even creating + * a socket. + */ +#define ipconfigUSE_DNS_CACHE ( 1 ) +#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 6 ) +#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 ) + +/* The IP stack executes it its own task (although any application task can make + * use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY + * sets the priority of the task that executes the IP stack. The priority is a + * standard FreeRTOS task priority so can take any value from 0 (the lowest + * priority) to (configMAX_PRIORITIES - 1) (the highest priority). + * configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in + * FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to + * the priority assigned to the task executing the IP stack relative to the + * priority assigned to tasks that use the IP stack. */ +#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) + +/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP + * task. This setting is less important when the FreeRTOS Win32 simulator is used + * as the Win32 simulator only stores a fixed amount of information on the task + * stack. FreeRTOS includes optional stack overflow detection, see: + * http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */ +#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 ) + +/* ipconfigRAND32() is called by the IP stack to generate random numbers for + * things such as a DHCP transaction number or initial sequence number. Random + * number generation is performed via this macro to allow applications to use their + * own random number generation method. For example, it might be possible to + * generate a random number by sampling noise on an analogue input. */ +extern uint32_t ulRand(); +#define ipconfigRAND32() ulRand() + +/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the + * network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK + * is not set to 1 then the network event hook will never be called. See: + * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml. + */ +#define ipconfigUSE_NETWORK_EVENT_HOOK 1 + +/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but + * a network buffer cannot be obtained then the calling task is held in the Blocked + * state (so other tasks can continue to executed) until either a network buffer + * becomes available or the send block time expires. If the send block time expires + * then the send operation is aborted. The maximum allowable send block time is + * capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the + * maximum allowable send block time prevents prevents a deadlock occurring when + * all the network buffers are in use and the tasks that process (and subsequently + * free) the network buffers are themselves blocked waiting for a network buffer. + * ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in + * milliseconds can be converted to a time in ticks by dividing the time in + * milliseconds by portTICK_PERIOD_MS. */ +#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS ) + +/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP + * address, netmask, DNS server address and gateway address from a DHCP server. If + * ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The + * stack will revert to using the static IP address even when ipconfigUSE_DHCP is + * set to 1 if a valid configuration cannot be obtained from a DHCP server for any + * reason. The static configuration used is that passed into the stack by the + * FreeRTOS_IPInit() function call. */ +#define ipconfigUSE_DHCP 1 +#define ipconfigDHCP_REGISTER_HOSTNAME 1 +#define ipconfigDHCP_USES_UNICAST 1 + +/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must + * provide an implementation of the DHCP callback function, + * xApplicationDHCPUserHook(). */ +#define ipconfigUSE_DHCP_HOOK 0 + +/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at + * increasing time intervals until either a reply is received from a DHCP server + * and accepted, or the interval between transmissions reaches + * ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the + * static IP address passed as a parameter to FreeRTOS_IPInit() if the + * re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without + * a DHCP reply being received. */ +#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD \ + ( 120000U / portTICK_PERIOD_MS ) + +/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP + * stack can only send a UDP message to a remove IP address if it knowns the MAC + * address associated with the IP address, or the MAC address of the router used to + * contact the remote IP address. When a UDP message is received from a remote IP + * address the MAC address and IP address are added to the ARP cache. When a UDP + * message is sent to a remote IP address that does not already appear in the ARP + * cache then the UDP message is replaced by a ARP message that solicits the + * required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum + * number of entries that can exist in the ARP table at any one time. */ +#define ipconfigARP_CACHE_ENTRIES 6 + +/* ARP requests that do not result in an ARP response will be re-transmitted a + * maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is + * aborted. */ +#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 ) + +/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP + * table being created or refreshed and the entry being removed because it is stale. + * New ARP requests are sent for ARP cache entries that are nearing their maximum + * age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is + * equal to 1500 seconds (or 25 minutes). */ +#define ipconfigMAX_ARP_AGE 150 + +/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling + * routines, which are relatively large. To save code space the full + * FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster + * alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr() + * takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter. + * FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets + * (for example, 192, 168, 0, 1) as its parameters. If + * ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and + * FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is + * not set to 1 then only FreeRTOS_indet_addr_quick() is available. */ +#define ipconfigINCLUDE_FULL_INET_ADDR 1 + +/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that + * are available to the IP stack. The total number of network buffers is limited + * to ensure the total amount of RAM that can be consumed by the IP stack is capped + * to a pre-determinable value. */ +#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60 + +/* A FreeRTOS queue is used to send events from application tasks to the IP + * stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can + * be queued for processing at any one time. The event queue must be a minimum of + * 5 greater than the total number of network buffers. */ +#define ipconfigEVENT_QUEUE_LENGTH \ + ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 ) + +/* The address of a socket is the combination of its IP address and its port + * number. FreeRTOS_bind() is used to manually allocate a port number to a socket + * (to 'bind' the socket to a port), but manual binding is not normally necessary + * for client sockets (those sockets that initiate outgoing connections rather than + * wait for incoming connections on a known port number). If + * ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling + * FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP + * stack automatically binding the socket to a port number from the range + * socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If + * ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto() + * on a socket that has not yet been bound will result in the send operation being + * aborted. */ +#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1 + +/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */ +#define ipconfigUDP_TIME_TO_LIVE 128 +/* Also defined in FreeRTOSIPConfigDefaults.h. */ +#define ipconfigTCP_TIME_TO_LIVE 128 + +/* USE_TCP: Use TCP and all its features. */ +#define ipconfigUSE_TCP ( 1 ) + +/* USE_WIN: Let TCP use windowing mechanism. */ +#define ipconfigUSE_TCP_WIN ( 1 ) + +/* The MTU is the maximum number of bytes the payload of a network frame can + * contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a + * lower value can save RAM, depending on the buffer management scheme used. If + * ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must + * be divisible by 8. */ +#define ipconfigNETWORK_MTU 1200U + +/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used + * through the FreeRTOS_gethostbyname() API function. */ +#define ipconfigUSE_DNS 1 + +/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will + * generate replies to incoming ICMP echo (ping) requests. */ +#define ipconfigREPLY_TO_INCOMING_PINGS 1 + +/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the + * FreeRTOS_SendPingRequest() API function is available. */ +#define ipconfigSUPPORT_OUTGOING_PINGS 0 + +/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select() + * (and associated) API function is available. */ +#define ipconfigSUPPORT_SELECT_FUNCTION 1 + +/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames + * that are not in Ethernet II format will be dropped. This option is included for + * potential future IP stack developments. */ +#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1 + +/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the + * responsibility of the Ethernet interface to filter out packets that are of no + * interest. If the Ethernet interface does not implement this functionality, then + * set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack + * perform the filtering instead (it is much less efficient for the stack to do it + * because the packet will already have been passed into the stack). If the + * Ethernet driver does all the necessary filtering in hardware then software + * filtering can be removed by using a value other than 1 or 0. */ +#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1 + +/* The windows simulator cannot really simulate MAC interrupts, and needs to + * block occasionally to allow other tasks to run. */ +#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS ) + +/* Advanced only: in order to access 32-bit fields in the IP packets with + * 32-bit memory instructions, all packets will be stored 32-bit-aligned, + * plus 16-bits. This has to do with the contents of the IP-packets: all + * 32-bit fields are 32-bit-aligned, plus 16-bit. */ +#define ipconfigPACKET_FILLER_SIZE 2U + +/* Define the size of the pool of TCP window descriptors. On the average, each + * TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6 + * outstanding packets (for Rx and Tx). When using up to 10 TP sockets + * simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */ +#define ipconfigTCP_WIN_SEG_COUNT 240 + +/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed + * maximum size. Define the size of Rx buffer for TCP sockets. */ +#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 ) + +/* Define the size of Tx buffer for TCP sockets. */ +#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 ) + +/* When using call-back handlers, the driver may check if the handler points to + * real program memory (RAM or flash) or just has a random non-zero value. */ +#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL ) + +/* Include support for TCP keep-alive messages. */ +#define ipconfigTCP_KEEP_ALIVE ( 1 ) +#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */ + +/* The socket semaphore is used to unblock the MQTT task. */ +#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 0 ) + +#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 ) +#define ipconfigUSE_CALLBACKS ( 0 ) + + +#define portINLINE + +void vApplicationMQTTGetKeys( const char ** ppcRootCA, + const char ** ppcClientCert, + const char ** ppcClientPrivateKey ); + +#endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/Coverity/ConfigFiles/pack_struct_end.h b/test/Coverity/ConfigFiles/pack_struct_end.h new file mode 100644 index 0000000000..584f3dcdfc --- /dev/null +++ b/test/Coverity/ConfigFiles/pack_struct_end.h @@ -0,0 +1,35 @@ +/* + * FreeRTOS+TCP V2.3.2 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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 + */ + +/***************************************************************************** +* +* See the following URL for an explanation of this file: +* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html +* +*****************************************************************************/ + +/* Keyword required to appear after any structure which has packed + * placement in memory. */ +__attribute__( ( packed ) ); diff --git a/test/Coverity/ConfigFiles/pack_struct_start.h b/test/Coverity/ConfigFiles/pack_struct_start.h new file mode 100644 index 0000000000..9b71fcb38a --- /dev/null +++ b/test/Coverity/ConfigFiles/pack_struct_start.h @@ -0,0 +1,33 @@ +/* + * FreeRTOS+TCP V2.3.2 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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 + */ + +/***************************************************************************** +* +* See the following URL for an explanation of this file: +* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Compiler_Porting.html +* +*****************************************************************************/ + +/* Nothing to do here. */ diff --git a/test/Coverity/ConfigFiles/portmacro.h b/test/Coverity/ConfigFiles/portmacro.h new file mode 100644 index 0000000000..30ac3e6040 --- /dev/null +++ b/test/Coverity/ConfigFiles/portmacro.h @@ -0,0 +1,161 @@ +/* + * FreeRTOS Kernel V10.3.0 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * 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://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef PORTMACRO_H +#define PORTMACRO_H + +/****************************************************************************** +* Defines +******************************************************************************/ +/* Type definitions. */ +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE size_t +#define portBASE_TYPE long +#define portPOINTER_SIZE_TYPE size_t + +typedef portSTACK_TYPE StackType_t; +typedef long BaseType_t; +typedef unsigned long UBaseType_t; + + +#if ( configUSE_16_BIT_TICKS == 1 ) + typedef uint16_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffff +#else + typedef uint32_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL + +/* 32/64-bit tick type on a 32/64-bit architecture, so reads of the tick + * count do not need to be guarded with a critical section. */ + #define portTICK_TYPE_IS_ATOMIC 1 +#endif + +/* Hardware specifics. */ +#define portSTACK_GROWTH ( -1 ) +#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) +#define portINLINE + +#if defined( __x86_64__ ) || defined( _M_X64 ) + #define portBYTE_ALIGNMENT 8 +#else + #define portBYTE_ALIGNMENT 4 +#endif + +#define portYIELD() vPortGenerateSimulatedInterrupt( portINTERRUPT_YIELD ) + + +extern volatile BaseType_t xInsideInterrupt; +#define portSOFTWARE_BARRIER() while( xInsideInterrupt != pdFALSE ) + + +/* Simulated interrupts return pdFALSE if no context switch should be performed, + * or a non-zero number if a context switch should be performed. */ +#define portYIELD_FROM_ISR( x ) ( void ) x +#define portEND_SWITCHING_ISR( x ) portYIELD_FROM_ISR( ( x ) ) + +void vPortCloseRunningThread( void * pvTaskToDelete, + volatile BaseType_t * pxPendYield ); +void vPortDeleteThread( void * pvThreadToDelete ); +#define portCLEAN_UP_TCB( pxTCB ) vPortDeleteThread( pxTCB ) +#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) ) +#define portDISABLE_INTERRUPTS() vPortEnterCritical() +#define portENABLE_INTERRUPTS() vPortExitCritical() + +/* Critical section handling. */ +void vPortEnterCritical( void ); +void vPortExitCritical( void ); + +#define portENTER_CRITICAL() vPortEnterCritical() +#define portEXIT_CRITICAL() vPortExitCritical() + +#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 +#endif + +#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 + +/* Check the configuration. */ + #if ( configMAX_PRIORITIES > 32 ) + #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. + #endif + +/* Store/clear the ready priorities in a bit map. */ + #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) + #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) + + +/*-----------------------------------------------------------*/ + + #ifdef __GNUC__ + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \ + __asm volatile ( "bsr %1, %0\n\t" \ + : "=r" ( uxTopPriority ) : "rm" ( uxReadyPriorities ) : "cc" ) + #else + +/* BitScanReverse returns the bit position of the most significant '1' + * in the word. */ + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) ) + #endif /* __GNUC__ */ + +#endif /* taskRECORD_READY_PRIORITY */ + +#ifndef __GNUC__ + __pragma( warning( disable: 4211 ) ) /* Nonstandard extension used, as extern is only nonstandard to MSVC. */ +#endif + + +/* Task function macros as described on the FreeRTOS.org WEB site. */ +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) + +#define portINTERRUPT_YIELD ( 0UL ) +#define portINTERRUPT_TICK ( 1UL ) + +/* + * Raise a simulated interrupt represented by the bit mask in ulInterruptMask. + * Each bit can be used to represent an individual interrupt - with the first + * two bits being used for the Yield and Tick interrupts respectively. + */ +void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber ); + +/* + * Install an interrupt handler to be called by the simulated interrupt handler + * thread. The interrupt number must be above any used by the kernel itself + * (at the time of writing the kernel was using interrupt numbers 0, 1, and 2 + * as defined above). The number must also be lower than 32. + * + * Interrupt handler functions must return a non-zero value if executing the + * handler resulted in a task switch being required. + */ +void vPortSetInterruptHandler( uint32_t ulInterruptNumber, + uint32_t ( * pvHandler )( void ) ); + +#endif /* ifndef PORTMACRO_H */ diff --git a/test/Coverity/Portable.c b/test/Coverity/Portable.c new file mode 100644 index 0000000000..d35ae29adb --- /dev/null +++ b/test/Coverity/Portable.c @@ -0,0 +1,112 @@ +/* Include standard libraries */ +#include +#include +#include +#include "FreeRTOS.h" +#include "task.h" +#include "list.h" + +#include "FreeRTOS_IP.h" + +volatile BaseType_t xInsideInterrupt = pdFALSE; + +/* Provide a main function for the build to succeed. */ +int main() +{ + return 0; +} + +size_t xPortGetMinimumEverFreeHeapSize( void ) +{ + return 0; +} + +const char * pcApplicationHostnameHook( void ) +{ +} +uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress, + uint16_t usSourcePort, + uint32_t ulDestinationAddress, + uint16_t usDestinationPort ) +{ +} +BaseType_t xNetworkInterfaceInitialise( void ) +{ +} +void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) +{ +} +BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber ) +{ +} +void vApplicationDaemonTaskStartupHook( void ) +{ +} +void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, + StackType_t ** ppxTimerTaskStackBuffer, + uint32_t * pulTimerTaskStackSize ) +{ +} +void vPortDeleteThread( void * pvTaskToDelete ) +{ +} +void vApplicationIdleHook( void ) +{ +} +void vApplicationTickHook( void ) +{ +} +unsigned long ulGetRunTimeCounterValue( void ) +{ +} +void vPortEndScheduler( void ) +{ +} +BaseType_t xPortStartScheduler( void ) +{ +} +void vPortEnterCritical( void ) +{ +} +void vPortExitCritical( void ) +{ +} + +void * pvPortMalloc( size_t xWantedSize ) +{ + return malloc( xWantedSize ); +} + +void vPortFree( void * pv ) +{ + free( pv ); +} + +StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + TaskFunction_t pxCode, + void * pvParameters ) +{ +} +void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber ) +{ +} +void vPortCloseRunningThread( void * pvTaskToDelete, + volatile BaseType_t * pxPendYield ) +{ +} +void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, + StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize ) +{ +} +void vConfigureTimerForRunTimeStats( void ) +{ +} + + +BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, + BaseType_t bReleaseAfterSend ) +{ + return pdPASS; +} +/*-----------------------------------------------------------*/ From c35ee3e35e99efc99dcf16521d7dd4ce2118f32a Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 13:54:25 -0500 Subject: [PATCH 17/33] Create uncrustify.yml --- .github/workflows/uncrustify.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/uncrustify.yml diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml new file mode 100644 index 0000000000..d8f6ac5f28 --- /dev/null +++ b/.github/workflows/uncrustify.yml @@ -0,0 +1,20 @@ +name: Uncrustify the source code + +on: + issue_comment: + types: [created] + +jobs: + Uncrustify: + name: Run_Uncrustify + if: ${{ github.event.issue.pull_request }} + # && contains(github.event.comment.body, 'confirm Uncrustify') + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Install Uncrustify + run: sudo apt-get install uncrustify + - name: Run Uncrustify + run: | + uncrustify --version + find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + From 894fe96528aee5ea2dcec97a65443168a5030c41 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:15:07 -0500 Subject: [PATCH 18/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index d8f6ac5f28..f26c866fd1 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -12,9 +12,22 @@ jobs: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo - name: Install Uncrustify run: sudo apt-get install uncrustify - name: Run Uncrustify run: | uncrustify --version find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + + - name: Commit files + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git commit -m "Add changes" -a + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} From be69988fbd434c6cb396433115905d0982ab108e Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:21:22 -0500 Subject: [PATCH 19/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index f26c866fd1..769e0682ef 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -23,6 +23,7 @@ jobs: find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + - name: Commit files run: | + git add . git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git commit -m "Add changes" -a From 2ba96b23fc5d8db9ddc4fc3c4570e041dd267b91 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:27:26 -0500 Subject: [PATCH 20/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 769e0682ef..81c4b73ae8 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -21,14 +21,8 @@ jobs: run: | uncrustify --version find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + - - name: Commit files - run: | - git add . - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git commit -m "Add changes" -a - - name: Push changes - uses: ad-m/github-push-action@master + - name: GitHub Action for committing changes to a repository + uses: devops-infra/action-commit-push@0.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} + commit_message: Uncrustify From bfe82322ad8bcad94f799110ec3045b36cd1630f Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:31:08 -0500 Subject: [PATCH 21/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 81c4b73ae8..683898495d 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -26,3 +26,5 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} commit_message: Uncrustify + +target_branch: From 9152cdec42e8a68ad2ad65cb852d3462c37da3e7 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:31:57 -0500 Subject: [PATCH 22/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 683898495d..21724f92b9 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -12,9 +12,9 @@ jobs: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - with: - persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token - fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + #with: + # persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + # fetch-depth: 0 # otherwise, you will failed to push refs to dest repo - name: Install Uncrustify run: sudo apt-get install uncrustify - name: Run Uncrustify @@ -26,5 +26,4 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} commit_message: Uncrustify - -target_branch: + target_branch: ${{ github.ref }} From 40410e15a68a0002db18a16df812fb8938612f67 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:37:49 -0500 Subject: [PATCH 23/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 21724f92b9..d2b68bb8bd 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -21,8 +21,9 @@ jobs: run: | uncrustify --version find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + + find . -type f -name "*" -print0 | xargs -0 sed -i "s/Aniruddha/Kanhere/g" - name: GitHub Action for committing changes to a repository - uses: devops-infra/action-commit-push@0.1 + uses: devops-infra/action-commit-push@master with: github_token: ${{ secrets.GITHUB_TOKEN }} commit_message: Uncrustify From d7e314ca032ed9e13fd370b18cb21fd29758b3ac Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:40:54 -0500 Subject: [PATCH 24/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index d2b68bb8bd..1b49b79a25 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -27,4 +27,3 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} commit_message: Uncrustify - target_branch: ${{ github.ref }} From 0a27eb9d0f2b2592cffa913dc62470129168dc46 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:50:51 -0500 Subject: [PATCH 25/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 1b49b79a25..015acb089a 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -23,7 +23,9 @@ jobs: find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + find . -type f -name "*" -print0 | xargs -0 sed -i "s/Aniruddha/Kanhere/g" - name: GitHub Action for committing changes to a repository - uses: devops-infra/action-commit-push@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - commit_message: Uncrustify + run: | + git config --global user.name 'Aniruddha Kanhere' + git config --global user.email '60444055+AniruddhaKanhere@users.noreply.github.com' + git add -A + git commit -m "test" + git push From 48beb6bba72ef2c7442a6f11db9b97804f02cbd0 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:53:24 -0500 Subject: [PATCH 26/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 015acb089a..1a7f9860cb 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -21,7 +21,6 @@ jobs: run: | uncrustify --version find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + - find . -type f -name "*" -print0 | xargs -0 sed -i "s/Aniruddha/Kanhere/g" - name: GitHub Action for committing changes to a repository run: | git config --global user.name 'Aniruddha Kanhere' From faed2e1244cb0b59d4af5d29c5f27027a692f371 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 14:55:25 -0500 Subject: [PATCH 27/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 1a7f9860cb..b50d804822 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -21,6 +21,7 @@ jobs: run: | uncrustify --version find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + + echo "hello there" > hello.txt - name: GitHub Action for committing changes to a repository run: | git config --global user.name 'Aniruddha Kanhere' From 6b98a33aa7cbb8ea71795d44a0288e504dfc17a5 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 15:42:07 -0500 Subject: [PATCH 28/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index b50d804822..e32c8eecae 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -11,10 +11,24 @@ jobs: # && contains(github.event.comment.body, 'confirm Uncrustify') runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 - #with: - # persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token - # fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: get pullrequest url + run: | + echo ${{ github.event.issue.pull_request.url }} + - name: get upstream branch + id: upstreambranch + run: | + echo "::set-output name=branchname::$(curl -v -H "Accept: application/vnd.github.sailor-v-preview+json" -u ${{ secrets.PAT }} ${{ github.event.issue.pull_request.url }} | jq '.head.ref' | sed 's/\"//g')" + - name: echo upstream branch + run: | + echo ${{ steps.upstreambranch.outputs }} + - name: Checkout upstream repo + uses: actions/checkout@v2 + with: + ref: ${{ steps.upstreambranch.outputs.branchname }} - name: Install Uncrustify run: sudo apt-get install uncrustify - name: Run Uncrustify From d6214651fa2721c77610c775ae9e4db4d84932bd Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sun, 28 Feb 2021 15:51:50 -0500 Subject: [PATCH 29/33] Update uncrustify.yml --- .github/workflows/uncrustify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index e32c8eecae..f6eb973f4a 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -21,7 +21,7 @@ jobs: - name: get upstream branch id: upstreambranch run: | - echo "::set-output name=branchname::$(curl -v -H "Accept: application/vnd.github.sailor-v-preview+json" -u ${{ secrets.PAT }} ${{ github.event.issue.pull_request.url }} | jq '.head.ref' | sed 's/\"//g')" + echo "::set-output name=branchname::$(curl -v -H "Accept: application/vnd.github.sailor-v-preview+json" --url ${{ secrets.PAT }} ${{ github.event.issue.pull_request.url }} | jq '.head.ref' | sed 's/\"//g')" - name: echo upstream branch run: | echo ${{ steps.upstreambranch.outputs }} From 5666cc9ba074c4191c078971ba56cf0577d78df0 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere Date: Tue, 20 Apr 2021 15:00:37 -0700 Subject: [PATCH 30/33] Error code corrected. --- FreeRTOS_Sockets.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/FreeRTOS_Sockets.c b/FreeRTOS_Sockets.c index c854bf460d..f86ba79160 100644 --- a/FreeRTOS_Sockets.c +++ b/FreeRTOS_Sockets.c @@ -3615,9 +3615,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) } else if( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eESTABLISHED ) { - /*_RB_ Is this comment correct? The socket is not of a type that - * supports the listen() operation. */ - xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP; + /* The socket is not connected. */ + xResult = -pdFREERTOS_ERRNO_ENOMEDIUM; } else { @@ -3626,7 +3625,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) /* Let the IP-task perform the shutdown of the connection. */ pxSocket->u.xTCP.usTimeout = 1U; ( void ) xSendEventToIPTask( eTCPTimerEvent ); - xResult = 0; + xResult = pdFREERTOS_ERRNO_NONE; } ( void ) xHow; From c6aac65b8312d2dd159ebf88b899ff79493e6b94 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere Date: Tue, 20 Apr 2021 15:04:42 -0700 Subject: [PATCH 31/33] Remove not needed files --- .github/workflows/uncrustify.yml | 45 -------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 .github/workflows/uncrustify.yml diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml deleted file mode 100644 index f6eb973f4a..0000000000 --- a/.github/workflows/uncrustify.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Uncrustify the source code - -on: - issue_comment: - types: [created] - -jobs: - Uncrustify: - name: Run_Uncrustify - if: ${{ github.event.issue.pull_request }} - # && contains(github.event.comment.body, 'confirm Uncrustify') - runs-on: ubuntu-18.04 - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: get pullrequest url - run: | - echo ${{ github.event.issue.pull_request.url }} - - name: get upstream branch - id: upstreambranch - run: | - echo "::set-output name=branchname::$(curl -v -H "Accept: application/vnd.github.sailor-v-preview+json" --url ${{ secrets.PAT }} ${{ github.event.issue.pull_request.url }} | jq '.head.ref' | sed 's/\"//g')" - - name: echo upstream branch - run: | - echo ${{ steps.upstreambranch.outputs }} - - name: Checkout upstream repo - uses: actions/checkout@v2 - with: - ref: ${{ steps.upstreambranch.outputs.branchname }} - - name: Install Uncrustify - run: sudo apt-get install uncrustify - - name: Run Uncrustify - run: | - uncrustify --version - find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + - echo "hello there" > hello.txt - - name: GitHub Action for committing changes to a repository - run: | - git config --global user.name 'Aniruddha Kanhere' - git config --global user.email '60444055+AniruddhaKanhere@users.noreply.github.com' - git add -A - git commit -m "test" - git push From d2dd5da03e1bd3bd4d4a6574658ecdcb3466283a Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere Date: Tue, 20 Apr 2021 15:06:45 -0700 Subject: [PATCH 32/33] typo fixed --- FreeRTOS_Sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FreeRTOS_Sockets.c b/FreeRTOS_Sockets.c index f86ba79160..ba4cc2a94a 100644 --- a/FreeRTOS_Sockets.c +++ b/FreeRTOS_Sockets.c @@ -3616,7 +3616,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) else if( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eESTABLISHED ) { /* The socket is not connected. */ - xResult = -pdFREERTOS_ERRNO_ENOMEDIUM; + xResult = -pdFREERTOS_ERRNO_ENOTCONN; } else { From c8c0178b5755f0b2ea3ef3af1cd36c0e6fbfcb69 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Tue, 20 Apr 2021 20:57:55 -0700 Subject: [PATCH 33/33] revert back a change --- FreeRTOS_Sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FreeRTOS_Sockets.c b/FreeRTOS_Sockets.c index a00aa974c6..9ef7263124 100644 --- a/FreeRTOS_Sockets.c +++ b/FreeRTOS_Sockets.c @@ -3626,7 +3626,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) /* Let the IP-task perform the shutdown of the connection. */ pxSocket->u.xTCP.usTimeout = 1U; ( void ) xSendEventToIPTask( eTCPTimerEvent ); - xResult = pdFREERTOS_ERRNO_NONE; + xResult = 0; } ( void ) xHow;