summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
diff options
context:
space:
mode:
authorlundinc <lundinc@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2020-08-12 19:11:51 +0000
committerlundinc <lundinc@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2020-08-12 19:11:51 +0000
commit42255af1e27a3157d541f0812eaca447c569ca49 (patch)
tree5c8702c2f0dc1cb9be1a4d5ff285897d96b97dd2 /FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
parentf5221dff43de249079c2da081723cb7a456f981f (diff)
downloadfreertos-master.tar.gz
commit 70dcbe4527a45ab4fea6d58c016e7d3032f31e8cHEADmaster
Author: Ming Yue <mingyue86010@gmail.com> Date: Tue Aug 11 17:06:59 2020 -0700 Remove unused wolfSSL files. (#197) * Remove unused wolfSSL files. * Add back some removed ciphers. * Update VS project file. commit 0e0edd96e8236b2ea4a6e6018812807be828c77f Author: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Date: Tue Aug 11 10:50:30 2020 -0700 Use new QEMU test project to improve stream/message buffer tests (#168) * Add Eclipse/GCC project that targets the LM3S8962 QEMU model. * Get the Cortex-M QEMU project working. * Continue working on making stream buffer demo more robust and QEMU project. * Rename directory CORTEX_LM3S8986_QEMU to CORTEX_LM3S6965_QEMU. Work on making the Stream Buffer tests more robust. Check in before adding in the trace recorder. * Rename CORTEX_LM3S6969_QEMU to CORTEX_LM3S6969_GCC_QEMU. * Make the StreamBufferDemo.c common demo file (test file) more robust to other test tasks running at an equally high priority. * Work in progress checkin only - comments in main.c are incorrect. * Correct comments at the top of FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c Make the message buffer tests more robust in the case the a message buffer becomes full when prvSenderTask() has a higher priority than the reader task. * Disable trace recorder in the LM3S6965 QEMU demo. * I'm dropping FreeRTOS-Kernel reference update, since this seems to break the CMBC CI. Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit 157a7fc39f19583ac8481e93fa3e1c91b1e1860c Author: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Sun Aug 9 22:21:44 2020 -0700 Use chacheable RAM in IAR project for MPU_M7_NUCLEO_H743ZI2 project (#193) This change updates the IAR project for Nucleo H743ZI2 to use the cacheable DTC RAM and enables L1 cache. In order to ensure the correct functioning of cache, the project sets configTEX_S_C_B_SRAM in FreeRTOSConfig.h to not mark the RAM as shareable. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> commit f3e43556f90f01b82918ad533b0c616489331919 Author: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Sun Aug 9 16:23:53 2020 -0700 Add MPU demo projects for NUCLEO-H743ZI2 board (#155) * Add MPU demo projects for NUCLEO-H743ZI2 board It contains projects for Keil uVision, STM32CubeIDE and IAR EW. This demo shows the use of newly added support for 16 MPU regions. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> * Delete not needed CMSIS files Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> commit 94aa31c3cbae7c929b8a412768b74631f4a6b461 Author: TakayukiMatsuo <62984531+TakayukiMatsuo@users.noreply.github.com> Date: Sat Aug 8 07:58:14 2020 +0900 Update wolfSSL to the latest version(v.4.4.0) (#186) * deleted old version wolfSSL before updating * updated wolfSSL to the latest version(v4.4.0) * updated wolfSSL to the latest version(v4.4.0) * added macros for timing resistance Co-authored-by: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Co-authored-by: Ming Yue <mingyue86010@gmail.com> commit 68518f5866aac58793c737d9a46dd07a6a816aaf Author: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Date: Fri Aug 7 14:59:24 2020 -0700 Removed a 16MByte flash image file that was checked in by mistake (several years ago). (#173) Remove the copies of lwIP that are no longer reference from demo projects. Co-authored-by: Carl Lundin <53273776+lundinc2@users.noreply.github.com> commit d4bf09480a2c77b1a25cce35b32293be61ab586f Author: m17336 <45935231+m17336@users.noreply.github.com> Date: Thu Aug 6 22:37:08 2020 +0300 Update previous AVR ATmega0 and AVR Dx projecs + addition of equivalent projects in MPLAB.X and IAR (#180) * Updated indentation in AVR_ATMega4809_Atmel_Studio and AVR_Dx_Atmel_Studio projects, plus small fixes in their readme files. * Added AVR_ATMega4809_IAR, AVR_ATMega4809_MPLAB.X, AVR_Dx_IAR and AVR_Dx_MPLAB.X demo projects. * Removed build artefacts and added .gitignore files in AVR_ATMega4809_MPLAB.X and AVR_Dx_MPLAB.X projects. Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit f32a0647c8228ddd066f5d69a85b2e49086e4c95 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon Aug 3 16:45:10 2020 -0700 Remove CBMC patch which is not used anymore (#187) * Delete 0002-Change-FreeRTOS_IP_Private.h-union-to-struct.patch * Delete 0002-Change-FreeRTOS_IP_Private.h-union-to-struct.patch commit 08af68ef9049279b265c3d00e9c48fb9594129a8 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Sat Aug 1 16:38:23 2020 -0700 Remove dependency of CBMC on Patches (#181) * Changes to DHCP * CBMC DNS changes * Changes for TCP_IP * Changes to TCP_WIN * Define away static to nothing * Remove patches * Changes after Mark's comments v1 * Update MakefileCommon.json * Correction! commit a7fec906a415363338449447daf10d7517b78848 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 29 17:39:36 2020 -0700 Misc changes (#183) commit 07cf5e07e4a05d6775a2f9e753269f43f82cf6ba Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 29 16:15:38 2020 -0700 MISRA compliance changes for FreeRTOS+TCP headers (#165) * misra changes * Update FreeRTOS_IP_Private.h * Update FreeRTOS_IP_Private.h commit e903ac0fed7ce59916899e404f3e5ae5b08d1478 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 29 16:03:14 2020 -0700 UPD MISRA changes (#164) Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit 97551bf44e7dc7dc1e4484a8fd30f699255e8569 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 29 15:52:00 2020 -0700 MISRA changes in FreeRTOS_TCP_WIN.c (#162) commit f2611cc5e5999c4c87e040a8c2d2e6b5e77a16a6 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 29 15:38:37 2020 -0700 MISRA compliance changes in FreeRTOS_Sockets{.c/.h} (#161) * MISRA changes Sockets * add other changes * Update FreeRTOSIPConfig.h * Update FreeRTOSIPConfig.h * Update FreeRTOSIPConfig.h * Update FreeRTOSIPConfig.h * correction * Add 'U' * Update FreeRTOS_Sockets.h * Update FreeRTOS_Sockets.h * Update FreeRTOS_Sockets.c * Update FreeRTOS_Sockets.h * Update after Gary's comments * Correction reverted commit ae4d4d38d9b2685bae159b4c87619cdb157c0bf7 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 29 13:56:57 2020 -0700 MISRA compliance changes for FreeRTOS_TCP_IP.c (#160) * MISRA tcp-ip changes * Changes after Hein's comments on original PR * Update FreeRTOS_TCP_IP.c Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit a457f43c66eb0f4be9d8f8678c0e3fb8d7ebd57b Author: Carl Lundin <53273776+lundinc2@users.noreply.github.com> Date: Tue Jul 28 13:01:38 2020 -0700 Add missing error state assignment. (#166) commit 915af50524e15a78ceb6c62b3d33f6562621ee46 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Mon Jul 27 17:30:53 2020 -0700 Add Atmel Studio projects for ATMega4809 and AVR128DA48 (#159) * Added explicit cast to allow roll over and avoid integer promotion during cycles counters comparison in recmutex.c. * Fixed type mismatch between declaration and definition of function xAreSemaphoreTasksStillRunning( void ). * Added Atmel Studio demo projects for ATMega4809 and AVR128DA48. * Per https://www.freertos.org/upgrading-to-FreeRTOS-V8.html, I'm updating portBASE_TYPE to BaseType_t. Signed-off-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> * Update register test for ATmega4809 - to cover r28, r29, r31. - call public API taskYIELD() instead of portYIELD(). * Update ATmega4809 readme.md to include info for serial port setup, and minor wording fix. Co-authored-by: Alexandru Niculae - M17336 <alexandru.niculae@microchip.com> commit 4a7a48790d64127f85cc763721b575c51c452833 Author: Carl Lundin <53273776+lundinc2@users.noreply.github.com> Date: Thu Jul 23 10:22:33 2020 -0700 Add Uncrustify file used for Kernel. (#163) commit e0d62163b08769fd74f020709c398f994088ca96 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 22 18:06:23 2020 -0700 Sync with +TCP amazon-FreeRTOS (#158) * DNS.c commit * IP.c commit * Add various source & header files commit 8e36bee30eef2107e128edb58e83ee46e8241a91 Author: Nathan Chong <52972368+nchong-at-aws@users.noreply.github.com> Date: Tue Jul 21 12:51:20 2020 -0400 Prove buffer lemmas (#124) * Prove buffer lemmas * Update queue proofs to latest kernel source All changes were syntactic due to uncrustify code-formatting * Strengthen prvCopyDataToQueue proof * Add extract script for diff comparison Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit c720c18ada40b502436ea811e8d03dca919726d8 Author: Hein Tibosch <hein_tibosch@yahoo.es> Date: Tue Jul 14 05:35:44 2020 +0800 FreeRTOS+TCP Adding the combined driver for SAM4E and SAME70 v2 (#78) * Adding a combined +TCP driver for SAM4E and SAME70 * Changes after review from Aniruddha Co-authored-by: Hein Tibosch <hein@htibosch.net> Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> commit 4237049b12d9bb6b03694fecf6ea26a353e637c8 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon Jul 13 12:07:56 2020 -0700 Add changes from 2225-2227 amazon-FreeRTOS (#134) commit 7caa32863458c4470d3c620945c30824199f524c Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri Jul 10 23:32:30 2020 -0700 Add Full TCP test suite - not using secure sockets (#131) * Add Full-TCP suite * delete unnecessary files * Change after Joshua's comments commit d7667a0034841f2968f9f9f805030cc608bfbce1 Author: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Fri Jul 3 15:45:44 2020 -0700 Remove unnecessary semicolon from the linker file (#121) This was creating problem with the onboard LPCLink debug probe. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> commit 529c481c39506d0b331bfd0cdea35e5d1aeaaad0 Author: Nathan Chong <52972368+nchong-at-aws@users.noreply.github.com> Date: Thu Jul 2 15:55:20 2020 -0400 Add VeriFast kernel queue proofs (#117) commit d5fedeaa96b5b1d3c0f6b9b52a8064ab72ff2821 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jul 1 13:56:27 2020 -0700 Add checks in FreeRTOS_Socket.c (#104) * Add fail-safes to FreeRTOS_Socket.c * Use all 'pd' errors * Correction after Hein's comments * Correction after Hein's comments v2 * Changes after Hein's comments * Update after Gary's comments commit a9b2aac4e9fda2a259380156df9cc0af51384d2d Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri Jun 26 12:09:36 2020 -0700 Folder structure change + Fix broken Projects (#103) * Update folder structure * Correct project files * Move test folder * Some changes after Yuki's comments commit 98bfc38bf3404414878dc68ea41753bea4e24c8e Author: Hein Tibosch <hein_tibosch@yahoo.es> Date: Thu Jun 25 13:01:45 2020 +0800 FreeRTOS+TCP : add memory statistics and dump packets, v3 (#83) * FreeRTOS+TCP : add memory statistics and dump packets, v3 * Two changes as requested by Aniruddha Co-authored-by: Hein Tibosch <hein@htibosch.net> Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> commit 072a173c9df31c75ff64bde440f3f316cedb9033 Author: S.Burch <8697966+wholl0p@users.noreply.github.com> Date: Mon Jun 22 23:39:26 2020 +0200 Fixed Imports for Infineon XMC1100 Board (#88) Co-authored-by: RichardBarry <3073890+RichardBarry@users.noreply.github.com> commit 2df5eeef5763045c4c74ff0e2a4091b7d19bea89 Author: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Date: Mon Jun 8 14:22:46 2020 -0700 Feature/multiple direct to task notifications (#73) * Add TaskNotifyArray.c with the single task tests updated to use the task notification array up to the point where the timer is created. * Continue working on TaskNotifyArray.c to test the new task notification indexes. Next TaskNotifyArray.c will be refactored to break the tests up a bit. * Refactor and update the comments in TaskNotifyArray.c - no functional changes. * Change from the task notify "array" to task notification "indexed" nomenclature in the new task notification API functions that work on one particular task notification with the array of task notifications. * Update the implementation of the taskNOTIFY_TAKE() and taskNOTIFY_WAIT() trace macros to take the array index of the task notification they are acting on. Rename configNUMBER_OF_TASK_NOTIFICATIONS to configTASK_NOTIFICATION_ARRAY_ENTRIES. Add FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c to the Visual Studio project - the file implements tests specific to the behaviour of the indexed task notification functions and should be used in addition to the tests already provided in FreeRTOS/Demo/Common/Minimal/TaskNotify.c. commit b9e4ecfaf7286d8493d4a96a93fbb325534ad97b Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri Jun 5 11:10:58 2020 -0700 Remove Empty and Un-referenced folder from Demo (#86) commit f11bcc8acc57a23fb03603762e758c25b9d0efb7 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Jun 3 16:52:31 2020 -0700 Fix a Bug and corresponding CBMC patch (#84) * Update remove-static-in-freertos-tcp-ip.patch * Update FreeRTOS_TCP_IP.c * Update remove-static-in-freertos-tcp-ip.patch * Update remove-static-in-freertos-tcp-ip.patch Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit bb9f92f771e5f6ea2b9b09c7e89130a75e562eb7 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Wed Jun 3 10:46:55 2020 -0700 Submodule FreeRTOS/Source 10bbbcf0b..6199b72fb (#82) commit 6efc39f44be5b269168836e95aebbdb8ae77dce3 Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Tue Jun 2 15:09:25 2020 -0700 Add Project for running integration tests v2 (#80) * Project for integration tests * relative paths in project files * relative paths in project files-1 * relative paths in project files-2 * addressed comments * addressed comments v2 Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit 0eb5909fb02bac9dc074ff1bc2fe338d77f73764 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Thu May 28 17:05:24 2020 -0700 readme.md for ATmega328PB Xplained Mini. (#76) readme.md to get users jump started. commit cb7edd2323a77f3dbea144c1f48f95582becc99e Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Thu May 28 10:11:58 2020 -0700 Sync with a:FR (#75) * AFR sync * AFR sync: CBMC * AFR sync: CBMC: remove .bak files * AFR sync: CBMC: more cleanup * Corrected CBMC proofs * Corrected CBMC patches * Corrected CBMC patches-1 * Corrected CBMC patches-2 * remove .bak files (3) Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit 6557291e5407ca7ec6beca53fced1aaa620c5c02 Author: alfred gedeon <alfred2g@hotmail.com> Date: Wed May 27 14:44:33 2020 -0700 Test: Add Linux Networking support with demo application (#71) * Test: Add Linux Networking support with demo application * Test: revert files affected by uncrustify * Test: revert files affected by uncrustify Co-authored-by: Alfred Gedeon <gedeonag@amazon.com> Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit 8b079bc394e7b205d72210ce9e052404d782938f Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Wed May 27 10:44:03 2020 -0700 ATmega328PB Xplained Mini -- demo project for ATmega port. (#70) * Bootstrap a demo from START. No driver is added in this commit. * Add FreeRTOS source code to project. Remove unnecessary folder nesting. Heap_4 is used here. * Copy over main.c, FreeRTOSConfig.h, and regtest.{c, h}. This commit compiles, but will need some work on timer used. * This port has 2KB RAM. We are using 1KB for heap. Further decreasing minimum stack size, and also use stack overflow check 1 to save some stack space. * Preserve EEPROM set to false. * End of the line. * Reduce register test stack size. 32 8-bit register + 10 bytes for stack frame cost. Round up to 50. * Adding Queue test in Integer test. - g3 to easy debugging. - mainCHECK_PERIOD is set to 1000 ticks. Note that this port for now use WDT as tick timer, and period is set to 15ms. - vErrorChecks, is of highest priority. So if this task gets run before other tasks, the very first check will fail. * Avoid false alarm. Since we don't know in which order the tasks are scheduled, clearing any error for the first entry of vErrorChecks. Signed-off-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> * ParTest.c to init, set, toggle onboard user LED at PB5. * Added a task to blink onboard user LED. Need a magic number for stack size. Signed-off-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> * Explicitly setting timing slicing to 0. This is to avoid unecessary context switch when multiple tasks are of the same priority. Signed-off-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> * Add taskYIELD() at the end of the loop in each register test task. This is to give other tasks of the same priority a chance to run, regardless of scheduling algorithm. Signed-off-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> * minor, update comment in main.c. commit 95a3a02f95749fb7a600723076e291f9dee7426c Author: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri May 22 16:26:59 2020 -0700 FreeRTOS-Plus: Unit testing Infrastructure and examples (#72) * Added CMock as submodule * Makefile added * Removed TEMP from Makefile * Added configuration files and header files * Update Makefile * Test runner working * make clean * Example added with README * Update README.md * Restored +TCP files * Cleared +TCP changes * removed comments from Makefile * Update README.md * Update README.md * Update README.md * Updated Test/Unit-test/readme.md commit 5003d17feda25490e655c0f1c15d2b13e395c9f7 Author: Hein Tibosch <hein_tibosch@yahoo.es> Date: Wed May 6 14:16:56 2020 -0400 FreeRTOS+TCP : renewing DHCP lease while network is down (#53) Co-authored-by: Hein Tibosch <hein@htibosch.net> Co-authored-by: Gary Wicker <14828980+gkwicker@users.noreply.github.com> commit d95624c5d6ba95ec0474867d7165de2c28ed41b7 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Tue May 5 09:57:18 2020 -0700 Move CBMC proofs to FreeRTOS+ directory (#64) * move CBMC proofs to FreeRTOS+ directory * Failing proofs corrected * ParseDNSReply proof added back * removed queue_init.h from -Plus/Test Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit 95ae7c65758a9473ea16ab08182f056f72331de2 Author: markrtuttle <tuttle@acm.org> Date: Wed Apr 29 04:27:45 2020 +0000 Change cbmc-viewer invocation in CBMC makefile (#63) * Exclude FreeRTOS/Demo from CBMC proof reports. The script cbmc-viewer generates the CBMC proof reports. The script searches source files for symbol definitions and annotates source files with coverage information. This patch causes cbmc-viewer to ignore the directory FreeRTOS/Demo containing 348M of data. The script now terminates in a few seconds. * Make report default target for CBMC Makefile. Modify the Makefile for CBMC proofs to generate the report by default (and not just property checking) and modify property checking to ignore failures (due to property assertions failing) and terminating report generation. Co-authored-by: Mark R. Tuttle <mrtuttle@amazon.com> commit d421ccc89f6f6473dfdd566a00567b0e1fd4cfc3 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Sat Apr 25 16:57:35 2020 -0700 Reword readme.md under ./Test. (#61) commit 38412865985235b90dbd9da9708b68c4de5918f5 Author: Carl Lundin <53273776+lundinc2@users.noreply.github.com> Date: Sat Apr 25 16:56:54 2020 -0700 Removed a:FR reference. (#60) commit 4db195c916c7b13c82ab3a34a499fe606f266810 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Tue Apr 21 15:40:08 2020 -0700 Adding FreeRTOS+TCP CBMC proofs to FreeRTOS/FreeRTOS (#56) ParseDNSReply is to be added in the next PR. commit 40a31b6d35a866a3a6c551d95bf08dae855da5bd Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon Apr 13 13:58:33 2020 -0700 'uL' -> 'UL' commit 5b3a289b69fc92089aa8bd4d1b44ab816f326f73 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon Apr 13 13:50:53 2020 -0700 Changes after Gary's comments commit edf68637dd22470a8d4f59fecc15b51379bcfeda Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri Apr 10 16:26:03 2020 -0700 Update FreeRTOS_ARP.c commit 35f3ac32a8899dd714a8a48952a4224fbcebc4aa Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri Apr 10 15:56:18 2020 -0700 correct debug output commit 5e12a70db4b6a8e68a434489683306f040252efa Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri Apr 10 15:44:45 2020 -0700 Debugging flag check added commit 4e8ac8de25ac4088b9c789b88a77cd39df4d9167 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Thu Apr 9 16:57:19 2020 -0700 Comment style consistency and Yuhui's suggestions commit e43f7cd086096ad60491fedba69927a1e1a82f20 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Thu Apr 9 16:47:41 2020 -0700 Cleanup commit ab3b51c7a0d880a6bf453ec63ae604e15050f310 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Thu Apr 9 16:33:03 2020 -0700 Update after Gary's comments commit 97f7009699ffb972c0745dfdb526d1fa4e0faf84 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Apr 8 14:30:15 2020 -0700 Update after richard's comments commit a9fcafc074cec559dd67961ef44273df6180c2db Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Apr 8 14:07:39 2020 -0700 Corrected the formatting - visual studio had messed up the formatting commit c381861014a8043ce30723fc5a8cf5107719c8df Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Apr 8 13:01:12 2020 -0700 commit 2 after gary's comments commit 75677a8d85fa802cca9058d6e23796d5043a0982 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Apr 8 12:51:10 2020 -0700 Commit after Gary's comments commit 666c0da366030109db2c0c5e7253cebb2f899db7 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Apr 8 10:56:01 2020 -0700 Update after Yuhui's comments - removed (void) from before memcpy, memset etc. - corrected memcpy style as suggested by Yuhui - Added logging for xNetworkInterfaceOutput. No need to configASSERT commit 4a1148d15b6b8169d2412f8179f734683b179795 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Apr 1 16:05:36 2020 -0700 Coverity + MISRA compliance Modified code to conform to the MISRA directives more closely. commit fa74f7dccf6b1a356993c6a894f8e1173b8c8157 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Thu Apr 2 20:26:10 2020 -0700 Removing writes to read-only PLIC interrupt pending registers. Signed-off-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> commit 5b9777e11e16609648fb98d2f9a47553ab238950 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Mar 31 10:45:23 2020 -0700 A readme file to introduce what ./Test directory is about. commit 211bb4cbd9ae6dfa95e8d8501f37d272bde5ab26 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Mar 24 15:14:24 2020 -0700 Ignore whitespace when working with patches. commit 8156f64d1c45dd59ef12279f19a99f03e79e1f8a Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Feb 25 18:04:23 2020 -0800 Copying CBMC proofs from aws/amazon-freertos repo ./tools/cbmc to this repo ./FreeRTOS/Test/CBMC as is. The commit ID in aws/amazon-freertos is 0c8e0217f2a43bdeb364b58ae01c6c259e03ef1b. commit 9f316c246baafa15c542a5aea81a94f26e3d6507 Author: David Vrabel <david.vrabel@cambridgeconsultants.com> Date: Mon Mar 16 11:21:46 2020 +0000 Demo/Posix_GCC: add demo application for Posix port using GCC This is largely a copy of the Windows demo application with a few key changes: - heap_3 (use malloc()/free()) so tools like valgrind "just work". - printf() wrapped in a mutex to prevent deadlocks on the internal pthread mutexes inside printf(). SCons (https://scons.org/) is used as the build system. This will be built as a 64-bit application, but note that the memory allocation trace points only record the lower 32-bits of the address. commit f78f919b3e2f0d707531a301a8ca07cd02bc4778 Author: Markus Rinne <markus.ka.rinne@gmail.com> Date: Thu Mar 19 21:00:24 2020 +0200 Fix function comments commit 1cd2d38d960a3576addb224582c88489bade5141 Author: David Chalco <david@chalco.io> Date: Fri Mar 20 10:29:05 2020 -0700 unix separators for path and remove .exe suffix from risc compiler (works on windows/mac) commit 938b19419eded12817737ab0644e94ed2ba7e95d Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Thu Mar 19 18:23:09 2020 -0700 Removing ./FreeRTOS-Labs directory, since: - IoT libraries are now in LTS branch. - FAT/POSIX/Light-weight MQTT are in https://github.com/FreeRTOS/FreeRTOS-Labs. commit 1a4abbc9e91b13fd6394464ade59d5e048320c7c Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Mar 17 19:30:02 2020 -0700 Maintenance -- clean up readme.txt and add url to GitHub. (#38) * Removing readme.txt, as now we have README.md in place. The only information missing from README.md is about FAQ. * Adding FAQ information in README.md. * Adding a .url to root to redict user to FreeRTOS github home page. commit 47bb466aa19395b7785bcb830e2e4dd35f6bafc5 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Mar 17 13:07:44 2020 -0700 Update issue templates Template maintenance. - adding title prefix. - adding examples to "additional context" section. commit f506290041f56867765f8efa70ed2862125bdb7c Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Mar 17 10:15:07 2020 -0700 Create SECURITY.md Apply the recommended SECURITY.md from AWS to our repo. commit 8982a2f80a80a2a0a47cf82de07b52101bd9d606 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Fri Mar 13 12:50:10 2020 -0700 Add ./lib directory to make sure Zynq project compiles. commit ecf0f12aa14ad6fdafe1ef37257cbb4e03e2abd5 Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Wed Mar 11 10:19:48 2020 -0700 Sync up with Amazon-freertos repo (10th March 2020) (#34) * Sync up with amazon-freertos * Sync up with amazon-freertos * Sync up with amazon-freertos commit 0acffef047973e2e61c2201fd69cd9bbd317f674 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Mar 10 10:20:48 2020 -0700 GitHub PR template. (#29) commit c40a6da2e4cb8042b56d1b174051cbbe9813781a Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon Mar 9 11:18:48 2020 -0700 pass payload length when calling UDP callback (#30) * pass payload length when calling UDP callback commit 12d580e93d4d9074b9a867632f0681a511b4ad12 Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Fri Mar 6 18:16:51 2020 -0800 Update issue templates Initial issue template. Created following https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser. If change is needed, we could go another round. commit 9debffb5e0e42ff716f58b2270b3af09652294af Author: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Fri Mar 6 17:27:46 2020 -0800 Update README.md to remove dead link. See the conversation https://github.com/FreeRTOS/FreeRTOS/commit/42c627b2b88cb3b487fea983d8b566a8bbae54fa#comments . Linkage for both ```./FreeRTOS/Source``` and ```./FreeRTOS/Demo``` are removed, since it looks weird to only provide linkage to Demo. commit 7e1a4bf563240501fc45167aee9d929c533939dd Author: AniruddhaKanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri Mar 6 15:18:09 2020 -0800 Fix DHCP option Client-identifier (#28) commit 42c627b2b88cb3b487fea983d8b566a8bbae54fa Author: Yuhui.Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Fri Mar 6 09:15:11 2020 -0800 Update readme and revert relative URL. (#27) * Reordering: bumping cloning instruction up. * Rewording readme.md to be clear kernel code is a submodule of this repository. * Reverting relative URL, since user cannot click through on GitHub page. (With URL, user could still download the correct version of the code. Reverting simply due to UI issue.) commit 5751ae9b60e248ebd0b4dd7c58df54364d2bb9d5 Author: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Fri Mar 6 09:11:42 2020 -0800 Update CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso project (#26) This commit updates the project for LPC55S69 so that it works with the latest version of MCUXpresso and SDK. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> commit a9ffffe1f01f45f79e127c15727784984077932f Author: Carl Lundin <53273776+lundinc2@users.noreply.github.com> Date: Thu Mar 5 17:16:13 2020 -0800 Using Relative URL For Submoduling. (#24) commit 52c82076b38fe73d1dc46c97abf74ae9b803696c Author: Carl Lundin <53273776+lundinc2@users.noreply.github.com> Date: Thu Mar 5 09:16:31 2020 -0800 use relative path to point to bundled toolchain instead (#25) commit b877e4ec478de2c24d07ab46241070d7c66f375c Author: lundinc2 <53273776+lundinc2@users.noreply.github.com> Date: Tue Feb 25 13:18:38 2020 -0800 Moved vulnerability reporting and code of conduct to top of CONTRIBUTING.md (#20) commit bef165d46799fb8faa58aaa224f80c16b6538e69 Author: Yuhui.Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Feb 18 22:06:38 2020 -0800 Linking test source file from relative path. (#19) commit 89e7bbe292afd3912d1f0b2402cc506878bad869 Author: Yuhui.Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Tue Feb 18 17:47:55 2020 -0800 A preliminary .gitignore file, to prevent us checking in files unnecessary. (#18) https://github.com/github/gitignore. commit c2a98127acb48c4562233230e66ca5c282688579 Author: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Date: Sun Feb 16 13:19:53 2020 -0800 Minor wording changes in the 'previous releases' section of the readme.me file. (#17) commit 24c772d1439e5c291c0a29fce0a46996ca8afaa9 Author: Yuhui.Zheng <10982575+yuhui-zheng@users.noreply.github.com> Date: Fri Feb 14 12:47:01 2020 -0800 Submodule kernel directory. (#16) * Removing FreeRTOS/Source in readiness for submoduling. * Submoduling kernel. * README.md update due to submoduling. When releasing, please follow these steps: 1. in local directory, clean directory and check "git status" shows "nothing to commit, working tree clean" for ALL subdirectories. 2. copy source code and instructions only to an empty folder. Git related should not be in this folder -- this covers .git, .gitignore, .github, .gitmodules, gitmessages, ...... 3. zip the folder from step 2. (create both .zip and .7z) 4. attach .zip and .7z to the release. (e.g. attach these two in new release -- https://github.com/FreeRTOS/FreeRTOS/releases/new) 5. PLEASE download both, unzip, diff with your local git repo. (should not see any difference other than git related.) And, sanity check a couple of projects. commit c3f8b91652392dc55e0d7067b90a40de5f5f0837 Author: Rashed Talukder <9218468+rashedtalukder@users.noreply.github.com> Date: Thu Feb 13 17:47:14 2020 -0800 Update readme. Fixed typos and cli commands (#14) commit 4723b825f2989213c1cdb2ebf4d6793e0292e363 Author: Julian Poidevin <julian-poidevin@users.noreply.github.com> Date: Fri Feb 14 02:43:36 2020 +0100 Fixed wrong git clone SSH command (#13) Replaced bad https URL with proper SSH URL commit fc819b821715c42602819e58499846147a6394f5 Author: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Date: Thu Feb 13 17:42:22 2020 -0800 Correct the xTimerCreate() documentation which said NULL was returned if the timer period was passed into the function as 0, whereas that is not the case. (#15) Add a note to the documentation for both the xTimerCreate() and xTimerCreateStatic() functions that the timer period must be greater than 0. commit 1c711ab530b5f0dbd811d7d62e0a3763706ffff4 Author: Rashed Talukder <9218468+rashedtalukder@users.noreply.github.com> Date: Wed Feb 12 23:00:18 2020 -0800 Updated contributions guidelines (#12) commit 84fcc0d5317d96c6b086034093c8c1c83e050819 Author: Cobus van Eeden <35851496+cobusve@users.noreply.github.com> Date: Wed Feb 12 15:05:06 2020 -0800 Updates to Markdown files and readme.txt (#11) git-svn-id: http://svn.code.sf.net/p/freertos/code/trunk@2826 1d2547de-c912-0410-9cb9-b8ca96c0e9e2
Diffstat (limited to 'FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c')
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c1801
1 files changed, 989 insertions, 812 deletions
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
index 70487b9d0..0ce010d42 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
@@ -48,101 +48,94 @@
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_UDP_IP.h"
-#include "FreeRTOS_TCP_IP.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkInterface.h"
#include "NetworkBufferManagement.h"
#include "FreeRTOS_ARP.h"
-#include "FreeRTOS_TCP_WIN.h"
+
+
+#include "FreeRTOSIPConfigDefaults.h"
/* Just make sure the contents doesn't get compiled if TCP is not enabled. */
#if ipconfigUSE_TCP == 1
-/* This compile-time test was moved to here because some macro's
-were unknown within 'FreeRTOSIPConfigDefaults.h'. It tests whether
-the defined MTU size can contain at least a complete TCP packet. */
-
-#if ( ( ipconfigTCP_MSS + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) > ipconfigNETWORK_MTU )
- #error The ipconfigTCP_MSS setting in FreeRTOSIPConfig.h is too large.
-#endif
+/*lint -e750 local macro not referenced [MISRA 2012 Rule 2.5, advisory] */
/*
* The meaning of the TCP flags:
*/
-#define ipTCP_FLAG_FIN 0x0001u /* No more data from sender */
-#define ipTCP_FLAG_SYN 0x0002u /* Synchronize sequence numbers */
-#define ipTCP_FLAG_RST 0x0004u /* Reset the connection */
-#define ipTCP_FLAG_PSH 0x0008u /* Push function: please push buffered data to the recv application */
-#define ipTCP_FLAG_ACK 0x0010u /* Acknowledgment field is significant */
-#define ipTCP_FLAG_URG 0x0020u /* Urgent pointer field is significant */
-#define ipTCP_FLAG_ECN 0x0040u /* ECN-Echo */
-#define ipTCP_FLAG_CWR 0x0080u /* Congestion Window Reduced */
-#define ipTCP_FLAG_NS 0x0100u /* ECN-nonce concealment protection */
-#define ipTCP_FLAG_RSV 0x0E00u /* Reserved, keep 0 */
+#define tcpTCP_FLAG_FIN ( ( uint8_t ) 0x01U ) /* No more data from sender */
+#define tcpTCP_FLAG_SYN ( ( uint8_t ) 0x02U ) /* Synchronize sequence numbers */
+#define tcpTCP_FLAG_RST ( ( uint8_t ) 0x04U ) /* Reset the connection */
+#define tcpTCP_FLAG_PSH ( ( uint8_t ) 0x08U ) /* Push function: please push buffered data to the recv application */
+#define tcpTCP_FLAG_ACK ( ( uint8_t ) 0x10U ) /* Acknowledgment field is significant */
+#define tcpTCP_FLAG_URG ( ( uint8_t ) 0x20U ) /* Urgent pointer field is significant */
+#define tcpTCP_FLAG_ECN ( ( uint8_t ) 0x40U ) /* ECN-Echo */
+#define tcpTCP_FLAG_CWR ( ( uint8_t ) 0x80U ) /* Congestion Window Reduced */
/* A mask to filter all protocol flags. */
-#define ipTCP_FLAG_CTRL 0x001Fu
+#define tcpTCP_FLAG_CTRL ( ( uint8_t ) 0x1FU )
/*
* A few values of the TCP options:
*/
-#define TCP_OPT_END 0u /* End of TCP options list */
-#define TCP_OPT_NOOP 1u /* "No-operation" TCP option */
-#define TCP_OPT_MSS 2u /* Maximum segment size TCP option */
-#define TCP_OPT_WSOPT 3u /* TCP Window Scale Option (3-byte long) */
-#define TCP_OPT_SACK_P 4u /* Advertize that SACK is permitted */
-#define TCP_OPT_SACK_A 5u /* SACK option with first/last */
-#define TCP_OPT_TIMESTAMP 8u /* Time-stamp option */
+#define tcpTCP_OPT_END 0U /* End of TCP options list */
+#define tcpTCP_OPT_NOOP 1U /* "No-operation" TCP option */
+#define tcpTCP_OPT_MSS 2U /* Maximum segment size TCP option */
+#define tcpTCP_OPT_WSOPT 3U /* TCP Window Scale Option (3-byte long) */
+#define tcpTCP_OPT_SACK_P 4U /* Advertize that SACK is permitted */
+#define tcpTCP_OPT_SACK_A 5U /* SACK option with first/last */
+#define tcpTCP_OPT_TIMESTAMP 8U /* Time-stamp option */
-#define TCP_OPT_MSS_LEN 4u /* Length of TCP MSS option. */
-#define TCP_OPT_WSOPT_LEN 3u /* Length of TCP WSOPT option. */
+#define tcpTCP_OPT_MSS_LEN 4U /* Length of TCP MSS option. */
+#define tcpTCP_OPT_WSOPT_LEN 3U /* Length of TCP WSOPT option. */
-#define TCP_OPT_TIMESTAMP_LEN 10 /* fixed length of the time-stamp option */
+#define tcpTCP_OPT_TIMESTAMP_LEN 10 /* fixed length of the time-stamp option */
#ifndef ipconfigTCP_ACK_EARLIER_PACKET
#define ipconfigTCP_ACK_EARLIER_PACKET 1
#endif
/*
- * The macro NOW_CONNECTED() is use to determine if the connection makes a
+ * The macro tcpNOW_CONNECTED() is use to determine if the connection makes a
* transition from connected to non-connected and vice versa.
- * NOW_CONNECTED() returns true when the status has one of these values:
+ * tcpNOW_CONNECTED() returns true when the status has one of these values:
* eESTABLISHED, eFIN_WAIT_1, eFIN_WAIT_2, eCLOSING, eLAST_ACK, eTIME_WAIT
* Technically the connection status is closed earlier, but the library wants
* to prevent that the socket will be deleted before the last ACK has been
* and thus causing a 'RST' packet on either side.
*/
-#define NOW_CONNECTED( status )\
- ( ( status >= eESTABLISHED ) && ( status != eCLOSE_WAIT ) )
+#define tcpNOW_CONNECTED( status )\
+ ( ( ( ( status ) >= ( BaseType_t ) eESTABLISHED ) && ( ( status ) != ( BaseType_t ) eCLOSE_WAIT ) ) ? 1 : 0 )
/*
* The highest 4 bits in the TCP offset byte indicate the total length of the
* TCP header, divided by 4.
*/
-#define VALID_BITS_IN_TCP_OFFSET_BYTE ( 0xF0u )
+#define tcpVALID_BITS_IN_TCP_OFFSET_BYTE ( 0xF0U )
/*
* Acknowledgements to TCP data packets may be delayed as long as more is being expected.
* A normal delay would be 200ms. Here a much shorter delay of 20 ms is being used to
* gain performance.
*/
-#define DELAYED_ACK_SHORT_DELAY_MS ( 2 )
-#define DELAYED_ACK_LONGER_DELAY_MS ( 20 )
+#define tcpDELAYED_ACK_SHORT_DELAY_MS ( 2 ) /* Should not become smaller than 1. */
+#define tcpDELAYED_ACK_LONGER_DELAY_MS ( 20 )
/*
* The MSS (Maximum Segment Size) will be taken as large as possible. However, packets with
* an MSS of 1460 bytes won't be transported through the internet. The MSS will be reduced
* to 1400 bytes.
*/
-#define REDUCED_MSS_THROUGH_INTERNET ( 1400 )
+#define tcpREDUCED_MSS_THROUGH_INTERNET ( 1400 )
/*
* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as
* the number 5 (words) in the higher niblle of the TCP-offset byte.
*/
-#define TCP_OFFSET_LENGTH_BITS ( 0xf0u )
-#define TCP_OFFSET_STANDARD_LENGTH ( 0x50u )
+#define tcpTCP_OFFSET_LENGTH_BITS ( 0xf0U )
+#define tcpTCP_OFFSET_STANDARD_LENGTH ( 0x50U )
/*
* Each TCP socket is checked regularly to see if it can send data packets.
@@ -158,35 +151,18 @@ the defined MTU size can contain at least a complete TCP packet. */
* When a TCP timer expires, retries and keep-alive messages will be checked.
*/
#ifndef tcpMAXIMUM_TCP_WAKEUP_TIME_MS
- #define tcpMAXIMUM_TCP_WAKEUP_TIME_MS 20000u
+ #define tcpMAXIMUM_TCP_WAKEUP_TIME_MS 20000U
#endif
-/*
- * The names of the different TCP states may be useful in logging.
- */
-#if( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) )
- static const char *pcStateNames[] = {
- "eCLOSED",
- "eTCP_LISTEN",
- "eCONNECT_SYN",
- "eSYN_FIRST",
- "eSYN_RECEIVED",
- "eESTABLISHED",
- "eFIN_WAIT_1",
- "eFIN_WAIT_2",
- "eCLOSE_WAIT",
- "eCLOSING",
- "eLAST_ACK",
- "eTIME_WAIT",
- "eUNKNOWN",
-};
-#endif /* ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) */
+/* Two macro's that were introduced to work with both IPv4 and IPv6. */
+#define xIPHeaderSize( pxNetworkBuffer ) ( ipSIZE_OF_IPv4_HEADER )
+#define uxIPHeaderSizeSocket( pxSocket ) ( ipSIZE_OF_IPv4_HEADER )
/*
* Returns true if the socket must be checked. Non-active sockets are waiting
* for user action, either connect() or close().
*/
-static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus );
+static BaseType_t prvTCPSocketIsActive( eIPTCPState_t xStatus );
/*
* Either sends a SYN or calls prvTCPSendRepeated (for regular messages).
@@ -201,7 +177,7 @@ static int32_t prvTCPSendRepeated( FreeRTOS_Socket_t *pxSocket, NetworkBufferDes
/*
* Return or send a packet to the other party.
*/
-static void prvTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
+static void prvTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxDescriptor,
uint32_t ulLen, BaseType_t xReleaseAfterSend );
/*
@@ -225,27 +201,35 @@ static BaseType_t prvTCPPrepareConnect( FreeRTOS_Socket_t *pxSocket );
/*
* Parse the TCP option(s) received, if present.
*/
-static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer );
+_static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer );
/*
* Identify and deal with a single TCP header option, advancing the pointer to
* the header. This function returns pdTRUE or pdFALSE depending on whether the
* caller should continue to parse more header options or break the loop.
*/
-static BaseType_t prvSingleStepTCPHeaderOptions( const unsigned char ** const ppucPtr, const unsigned char ** const ppucLast, FreeRTOS_Socket_t ** const ppxSocket, TCPWindow_t ** const ppxTCPWindow);
+_static size_t prvSingleStepTCPHeaderOptions( const uint8_t * const pucPtr,
+ size_t uxTotalLength,
+ FreeRTOS_Socket_t * const pxSocket,
+ BaseType_t xHasSYNFlag );
+
+#if( ipconfigUSE_TCP_WIN == 1 )
+ /*
+ * Skip past TCP header options when doing Selective ACK, until there are no
+ * more options left.
+ */
+ _static void prvReadSackOption( const uint8_t * const pucPtr,
+ size_t uxIndex,
+ FreeRTOS_Socket_t * const pxSocket );
+#endif/* ( ipconfigUSE_TCP_WIN == 1 ) */
-/*
- * Skip past TCP header options when doing Selective ACK, until there are no
- * more options left.
- */
-static void prvSkipPastRemainingOptions( const unsigned char ** const ppucPtr, FreeRTOS_Socket_t ** const ppxSocket, unsigned char * const ppucLen );
/*
* Set the initial properties in the options fields, like the preferred
* value of MSS and whether SACK allowed. Will be transmitted in the state
* 'eCONNECT_SYN'.
*/
-static UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t *pxSocket, TCPPacket_t * pxTCPPacket );
+static UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t *pxSocket, TCPHeader_t *pxTCPHeader );
/*
* For anti-hang protection and TCP keep-alive messages. Called in two places:
@@ -273,31 +257,31 @@ static void prvTCPAddTxData( FreeRTOS_Socket_t *pxSocket );
/*
* Called to handle the closure of a TCP connection.
*/
-static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer );
+static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer );
/*
* Called from prvTCPHandleState(). Find the TCP payload data and check and
* return its length.
*/
-static BaseType_t prvCheckRxData( NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData );
+static BaseType_t prvCheckRxData( const NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData );
/*
* Called from prvTCPHandleState(). Check if the payload data may be accepted.
* If so, it will be added to the socket's reception queue.
*/
-static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, uint8_t *pucRecvData,
+static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, const uint8_t *pucRecvData,
NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength );
/*
* Set the TCP options (if any) for the outgoing packet.
*/
-static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer );
+static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer );
/*
* Called from prvTCPHandleState() as long as the TCP status is eSYN_RECEIVED to
* eCONNECT_SYN.
*/
-static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
+static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer,
uint32_t ulReceiveLength, UBaseType_t uxOptionsLength );
/*
@@ -312,7 +296,7 @@ static BaseType_t prvHandleEstablished( FreeRTOS_Socket_t *pxSocket, NetworkBuff
* be checked if it would better be postponed for efficiency.
*/
static BaseType_t prvSendData( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, BaseType_t xSendLength );
+ uint32_t ulReceiveLength, BaseType_t xByteCount );
/*
* The heart of all: check incoming packet for valid data and acks and do what
@@ -325,7 +309,7 @@ static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferD
* payload, just flags).
*/
static BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t *pxNetworkBuffer,
- uint8_t ucTCPFlags );
+ uint8_t ucTCPFlags );
/*
* A "challenge ACK" is as per https://tools.ietf.org/html/rfc5961#section-3.2,
@@ -365,43 +349,42 @@ static BaseType_t prvTCPSocketCopy( FreeRTOS_Socket_t *pxNewSocket, FreeRTOS_Soc
static BaseType_t prvTCPStatusAgeCheck( FreeRTOS_Socket_t *pxSocket );
#endif
-static NetworkBufferDescriptor_t *prvTCPBufferResize( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
+static NetworkBufferDescriptor_t *prvTCPBufferResize( const FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
int32_t lDataLen, UBaseType_t uxOptionsLength );
-#if( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) )
- const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState );
-#endif
-
#if( ipconfigUSE_TCP_WIN != 0 )
- static uint8_t prvWinScaleFactor( FreeRTOS_Socket_t *pxSocket );
+ static uint8_t prvWinScaleFactor( const FreeRTOS_Socket_t *pxSocket );
#endif
-/*
- * Generate a randomized TCP Initial Sequence Number per RFC.
- */
-extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
- uint16_t usSourcePort,
- uint32_t ulDestinationAddress,
- uint16_t usDestinationPort );
-
/*-----------------------------------------------------------*/
/* prvTCPSocketIsActive() returns true if the socket must be checked.
* Non-active sockets are waiting for user action, either connect()
* or close(). */
-static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus )
+static BaseType_t prvTCPSocketIsActive( eIPTCPState_t xStatus )
{
- switch( uxStatus )
+BaseType_t xResult;
+ switch( xStatus )
{
case eCLOSED:
case eCLOSE_WAIT:
case eFIN_WAIT_2:
case eCLOSING:
case eTIME_WAIT:
- return pdFALSE;
+ xResult = pdFALSE;
+ break;
+ case eTCP_LISTEN:
+ case eCONNECT_SYN:
+ case eSYN_FIRST:
+ case eSYN_RECEIVED:
+ case eESTABLISHED:
+ case eFIN_WAIT_1:
+ case eLAST_ACK:
default:
- return pdTRUE;
+ xResult = pdTRUE;
+ break;
}
+ return xResult;
}
/*-----------------------------------------------------------*/
@@ -410,7 +393,9 @@ static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus )
static BaseType_t prvTCPStatusAgeCheck( FreeRTOS_Socket_t *pxSocket )
{
BaseType_t xResult;
- switch( pxSocket->u.xTCP.ucTCPState )
+ eIPTCPState_t eState = ipNUMERIC_CAST( eIPTCPState_t, pxSocket->u.xTCP.ucTCPState );
+
+ switch( eState )
{
case eESTABLISHED:
/* If the 'ipconfigTCP_KEEP_ALIVE' option is enabled, sockets in
@@ -423,6 +408,14 @@ static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus )
/* These 3 states may last for ever, up to the owner. */
xResult = pdFALSE;
break;
+ case eCONNECT_SYN:
+ case eSYN_FIRST:
+ case eSYN_RECEIVED:
+ case eFIN_WAIT_1:
+ case eFIN_WAIT_2:
+ case eCLOSING:
+ case eLAST_ACK:
+ case eTIME_WAIT:
default:
/* All other (non-connected) states will get anti-hanging
protection. */
@@ -436,7 +429,7 @@ static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus )
TickType_t xAge = xTaskGetTickCount( ) - pxSocket->u.xTCP.xLastActTime;
/* ipconfigTCP_HANG_PROTECTION_TIME is in units of seconds. */
- if( xAge > ( ipconfigTCP_HANG_PROTECTION_TIME * configTICK_RATE_HZ ) )
+ if( xAge > ( ( TickType_t ) ipconfigTCP_HANG_PROTECTION_TIME * ( TickType_t ) configTICK_RATE_HZ ) )
{
#if( ipconfigHAS_DEBUG_PRINTF == 1 )
{
@@ -461,7 +454,7 @@ static BaseType_t prvTCPSocketIsActive( UBaseType_t uxStatus )
accept() it anymore, it will be deleted now. Called from
the IP-task, so it's safe to call the internal Close
function: vSocketClose(). */
- vSocketClose( pxSocket );
+ ( void ) vSocketClose( pxSocket );
}
/* Return a negative value to tell to inform the caller
xTCPTimerCheck()
@@ -494,14 +487,14 @@ BaseType_t xTCPSocketCheck( FreeRTOS_Socket_t *pxSocket )
BaseType_t xResult = 0;
BaseType_t xReady = pdFALSE;
- if( ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) && ( pxSocket->u.xTCP.txStream != NULL ) )
+ if( ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eESTABLISHED ) && ( pxSocket->u.xTCP.txStream != NULL ) )
{
/* The API FreeRTOS_send() might have added data to the TX stream. Add
- this data to the windowing system to it can be transmitted. */
+ this data to the windowing system so it can be transmitted. */
prvTCPAddTxData( pxSocket );
}
- #if ipconfigUSE_TCP_WIN == 1
+ #if( ipconfigUSE_TCP_WIN == 1 )
{
if( pxSocket->u.xTCP.pxAckMessage != NULL )
{
@@ -512,16 +505,16 @@ BaseType_t xReady = pdFALSE;
/* Earlier data was received but not yet acknowledged. This
function is called when the TCP timer for the socket expires, the
ACK may be sent now. */
- if( pxSocket->u.xTCP.ucTCPState != eCLOSED )
+ if( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eCLOSED )
{
- if( xTCPWindowLoggingLevel > 1 && ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) )
+ if( ( xTCPWindowLoggingLevel > 1 ) && ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) )
{
FreeRTOS_debug_printf( ( "Send[%u->%u] del ACK %lu SEQ %lu (len %u)\n",
pxSocket->usLocalPort,
pxSocket->u.xTCP.usRemotePort,
pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber,
pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber - pxSocket->u.xTCP.xTCPWindow.tx.ulFirstSequenceNumber,
- ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) );
+ ( unsigned ) ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) );
}
prvTCPReturnPacket( pxSocket, pxSocket->u.xTCP.pxAckMessage, ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER, ipconfigZERO_COPY_TX_DRIVER );
@@ -534,7 +527,7 @@ BaseType_t xReady = pdFALSE;
}
#endif /* ipconfigZERO_COPY_TX_DRIVER */
}
- if( prvTCPNextTimeout( pxSocket ) > 1 )
+ if( prvTCPNextTimeout( pxSocket ) > 1U )
{
/* Tell the code below that this function is ready. */
xReady = pdTRUE;
@@ -559,14 +552,14 @@ BaseType_t xReady = pdFALSE;
if( xReady == pdFALSE )
{
/* The second task of this regular socket check is sending out data. */
- if( ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) ||
- ( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN ) )
+ if( ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eESTABLISHED ) ||
+ ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN ) )
{
- prvTCPSendPacket( pxSocket );
+ ( void ) prvTCPSendPacket( pxSocket );
}
/* Set the time-out for the next wakeup for this socket. */
- prvTCPNextTimeout( pxSocket );
+ ( void ) prvTCPNextTimeout( pxSocket );
#if( ipconfigTCP_HANG_PROTECTION == 1 )
{
@@ -589,12 +582,11 @@ static int32_t prvTCPSendPacket( FreeRTOS_Socket_t *pxSocket )
{
int32_t lResult = 0;
UBaseType_t uxOptionsLength;
-TCPPacket_t *pxTCPPacket;
NetworkBufferDescriptor_t *pxNetworkBuffer;
- if( pxSocket->u.xTCP.ucTCPState != eCONNECT_SYN )
+ if( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eCONNECT_SYN )
{
- /* The connection is in s state other than SYN. */
+ /* The connection is in a state other than SYN. */
pxNetworkBuffer = NULL;
/* prvTCPSendRepeated() will only create a network buffer if necessary,
@@ -608,7 +600,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
}
else
{
- if( pxSocket->u.xTCP.ucRepCount >= 3u )
+ if( pxSocket->u.xTCP.ucRepCount >= 3U )
{
/* The connection is in the SYN status. The packet will be repeated
to most 3 times. When there is no response, the socket get the
@@ -620,25 +612,27 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
}
else if( ( pxSocket->u.xTCP.bits.bConnPrepared != pdFALSE_UNSIGNED ) || ( prvTCPPrepareConnect( pxSocket ) == pdTRUE ) )
{
+ ProtocolHeaders_t *pxProtocolHeaders;
+ const UBaseType_t uxHeaderSize = ipSIZE_OF_IPv4_HEADER;
/* Or else, if the connection has been prepared, or can be prepared
now, proceed to send the packet with the SYN flag.
prvTCPPrepareConnect() prepares 'xPacket' and returns pdTRUE if
the Ethernet address of the peer or the gateway is found. */
- pxTCPPacket = ( TCPPacket_t * )pxSocket->u.xTCP.xPacket.u.ucLastPacket;
+ pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) );
/* About to send a SYN packet. Call prvSetSynAckOptions() to set
the proper options: The size of MSS and whether SACK's are
allowed. */
- uxOptionsLength = prvSetSynAckOptions( pxSocket, pxTCPPacket );
+ uxOptionsLength = prvSetSynAckOptions( pxSocket, &( pxProtocolHeaders->xTCPHeader ) );
/* Return the number of bytes to be sent. */
- lResult = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
+ lResult = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
/* Set the TCP offset field: ipSIZE_OF_TCP_HEADER equals 20 and
uxOptionsLength is always a multiple of 4. The complete expression
would be:
ucTCPOffset = ( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) / 4 ) << 4 */
- pxTCPPacket->xTCPHeader.ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
+ pxProtocolHeaders->xTCPHeader.ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
/* Repeat Count is used for a connecting socket, to limit the number
of tries. */
@@ -649,6 +643,10 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
pseudo network buffer descriptor before it will be sent. */
prvTCPReturnPacket( pxSocket, NULL, ( uint32_t ) lResult, pdFALSE );
}
+ else
+ {
+ /* Nothing to do. */
+ }
}
/* Return the total number of bytes sent. */
@@ -664,10 +662,10 @@ static int32_t prvTCPSendRepeated( FreeRTOS_Socket_t *pxSocket, NetworkBufferDes
{
UBaseType_t uxIndex;
int32_t lResult = 0;
-UBaseType_t uxOptionsLength = 0u;
+UBaseType_t uxOptionsLength = 0U;
int32_t xSendLength;
- for( uxIndex = 0u; uxIndex < ( UBaseType_t ) SEND_REPEATED_COUNT; uxIndex++ )
+ for( uxIndex = 0U; uxIndex < ( UBaseType_t ) SEND_REPEATED_COUNT; uxIndex++ )
{
/* prvTCPPrepareSend() might allocate a network buffer if there is data
to be sent. */
@@ -700,13 +698,15 @@ int32_t xSendLength;
* called 'xTCP.xPacket'. A temporary xNetworkBuffer will be used to pass
* the data to the NIC.
*/
-static void prvTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulLen, BaseType_t xReleaseAfterSend )
+static void prvTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxDescriptor, uint32_t ulLen, BaseType_t xReleaseAfterSend )
{
TCPPacket_t * pxTCPPacket;
IPHeader_t *pxIPHeader;
+BaseType_t xDoRelease = xReleaseAfterSend;
EthernetHeader_t *pxEthernetHeader;
uint32_t ulFrontSpace, ulSpace, ulSourceAddress, ulWinSize;
-TCPWindow_t *pxTCPWindow;
+const TCPWindow_t *pxTCPWindow;
+NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor;
NetworkBufferDescriptor_t xTempBuffer;
/* For sending, a pseudo network buffer will be used, as explained above. */
@@ -716,31 +716,34 @@ NetworkBufferDescriptor_t xTempBuffer;
#if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
{
- xTempBuffer.pxNextBuffer = NULL;
+ pxNetworkBuffer->pxNextBuffer = NULL;
}
#endif
- xTempBuffer.pucEthernetBuffer = pxSocket->u.xTCP.xPacket.u.ucLastPacket;
- xTempBuffer.xDataLength = sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket );
- xReleaseAfterSend = pdFALSE;
+ pxNetworkBuffer->pucEthernetBuffer = pxSocket->u.xTCP.xPacket.u.ucLastPacket;
+ pxNetworkBuffer->xDataLength = sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket );
+ xDoRelease = pdFALSE;
}
#if( ipconfigZERO_COPY_TX_DRIVER != 0 )
{
- if( xReleaseAfterSend == pdFALSE )
+ if( xDoRelease == pdFALSE )
{
- pxNetworkBuffer = pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, ( BaseType_t ) pxNetworkBuffer->xDataLength );
+ pxNetworkBuffer = pxDuplicateNetworkBufferWithDescriptor( pxNetworkBuffer, ( size_t ) pxNetworkBuffer->xDataLength );
if( pxNetworkBuffer == NULL )
{
FreeRTOS_debug_printf( ( "prvTCPReturnPacket: duplicate failed\n" ) );
}
- xReleaseAfterSend = pdTRUE;
+ xDoRelease = pdTRUE;
}
}
#endif /* ipconfigZERO_COPY_TX_DRIVER */
+ #ifndef __COVERITY__
if( pxNetworkBuffer != NULL )
+ #endif
{
- pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
+ /* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
+ pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
pxIPHeader = &pxTCPPacket->xIPHeader;
pxEthernetHeader = &pxTCPPacket->xEthernetHeader;
@@ -773,7 +776,7 @@ NetworkBufferDescriptor_t xTempBuffer;
space left. The socket will wait until the application has read
or flushed the incoming data, and 'zero-window' will be
advertised. */
- ulSpace = 0u;
+ ulSpace = 0U;
}
/* If possible, advertise an RX window size of at least 1 MSS, otherwise
@@ -801,34 +804,6 @@ NetworkBufferDescriptor_t xTempBuffer;
pxTCPPacket->xTCPHeader.usWindow = FreeRTOS_htons( ( uint16_t ) ulWinSize );
- #if( ipconfigHAS_DEBUG_PRINTF != 0 )
- {
- if( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE )
- {
- if( ( xTCPWindowLoggingLevel != 0 ) && ( pxSocket->u.xTCP.bits.bWinChange != pdFALSE_UNSIGNED ) )
- {
- size_t uxFrontSpace;
-
- if(pxSocket->u.xTCP.rxStream != NULL)
- {
- uxFrontSpace = uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream ) ;
- }
- else
- {
- uxFrontSpace = 0u;
- }
-
- FreeRTOS_debug_printf( ( "%s: %lxip:%u: [%lu < %lu] winSize %ld\n",
- pxSocket->u.xTCP.bits.bLowWater ? "STOP" : "GO ",
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- pxSocket->u.xTCP.bits.bLowWater ? pxSocket->u.xTCP.uxLittleSpace : uxFrontSpace, pxSocket->u.xTCP.uxEnoughSpace,
- (int32_t) ( pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulCurrentSequenceNumber ) ) );
- }
- }
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
-
/* The new window size has been advertised, switch off the flag. */
pxSocket->u.xTCP.bits.bWinChange = pdFALSE_UNSIGNED;
@@ -837,31 +812,31 @@ NetworkBufferDescriptor_t xTempBuffer;
highest sequence number minus 1 that the socket will accept. */
pxSocket->u.xTCP.ulHighestRxAllowed = pxTCPWindow->rx.ulCurrentSequenceNumber + ulSpace;
- #if( ipconfigTCP_KEEP_ALIVE == 1 )
- if( pxSocket->u.xTCP.bits.bSendKeepAlive != pdFALSE_UNSIGNED )
- {
- /* Sending a keep-alive packet, send the current sequence number
- minus 1, which will be recognised as a keep-alive packet an
- responded to by acknowledging the last byte. */
- pxSocket->u.xTCP.bits.bSendKeepAlive = pdFALSE_UNSIGNED;
- pxSocket->u.xTCP.bits.bWaitKeepAlive = pdTRUE_UNSIGNED;
-
- pxTCPPacket->xTCPHeader.ulSequenceNumber = pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber - 1UL;
- pxTCPPacket->xTCPHeader.ulSequenceNumber = FreeRTOS_htonl( pxTCPPacket->xTCPHeader.ulSequenceNumber );
- }
- else
- #endif
+ #if( ipconfigTCP_KEEP_ALIVE == 1 )
+ if( pxSocket->u.xTCP.bits.bSendKeepAlive != pdFALSE_UNSIGNED )
+ {
+ /* Sending a keep-alive packet, send the current sequence number
+ minus 1, which will be recognised as a keep-alive packet an
+ responded to by acknowledging the last byte. */
+ pxSocket->u.xTCP.bits.bSendKeepAlive = pdFALSE_UNSIGNED;
+ pxSocket->u.xTCP.bits.bWaitKeepAlive = pdTRUE_UNSIGNED;
+
+ pxTCPPacket->xTCPHeader.ulSequenceNumber = pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber - 1UL;
+ pxTCPPacket->xTCPHeader.ulSequenceNumber = FreeRTOS_htonl( pxTCPPacket->xTCPHeader.ulSequenceNumber );
+ }
+ else
+ #endif
{
pxTCPPacket->xTCPHeader.ulSequenceNumber = FreeRTOS_htonl( pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber );
- if( ( pxTCPPacket->xTCPHeader.ucTCPFlags & ( uint8_t ) ipTCP_FLAG_FIN ) != 0u )
+ if( ( pxTCPPacket->xTCPHeader.ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_FIN ) != 0U )
{
/* Suppress FIN in case this packet carries earlier data to be
retransmitted. */
uint32_t ulDataLen = ( uint32_t ) ( ulLen - ( ipSIZE_OF_TCP_HEADER + ipSIZE_OF_IPv4_HEADER ) );
if( ( pxTCPWindow->ulOurSequenceNumber + ulDataLen ) != pxTCPWindow->tx.ulFINSequenceNumber )
{
- pxTCPPacket->xTCPHeader.ucTCPFlags &= ( ( uint8_t ) ~ipTCP_FLAG_FIN );
+ pxTCPPacket->xTCPHeader.ucTCPFlags &= ( ( uint8_t ) ~tcpTCP_FLAG_FIN );
FreeRTOS_debug_printf( ( "Suppress FIN for %lu + %lu < %lu\n",
pxTCPWindow->ulOurSequenceNumber - pxTCPWindow->tx.ulFirstSequenceNumber,
ulDataLen,
@@ -882,12 +857,12 @@ NetworkBufferDescriptor_t xTempBuffer;
pxIPHeader->ucTimeToLive = ( uint8_t ) ipconfigTCP_TIME_TO_LIVE;
pxIPHeader->usLength = FreeRTOS_htons( ulLen );
- if( ( pxSocket == NULL ) || ( *ipLOCAL_IP_ADDRESS_POINTER == 0ul ) )
+ if( ( pxSocket == NULL ) || ( *ipLOCAL_IP_ADDRESS_POINTER == 0UL ) )
{
/* When pxSocket is NULL, this function is called by prvTCPSendReset()
and the IP-addresses must be swapped.
Also swap the IP-addresses in case the IP-tack doesn't have an
- IP-address yet, i.e. when ( *ipLOCAL_IP_ADDRESS_POINTER == 0ul ). */
+ IP-address yet, i.e. when ( *ipLOCAL_IP_ADDRESS_POINTER == 0UL ). */
ulSourceAddress = pxIPHeader->ulDestinationIPAddress;
}
else
@@ -901,41 +876,44 @@ NetworkBufferDescriptor_t xTempBuffer;
/* Just an increasing number. */
pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier );
usPacketIdentifier++;
- pxIPHeader->usFragmentOffset = 0u;
+ pxIPHeader->usFragmentOffset = 0U;
+
+ /* Important: tell NIC driver how many bytes must be sent. */
+ pxNetworkBuffer->xDataLength = ulLen + ipSIZE_OF_ETH_HEADER;
#if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 )
{
/* calculate the IP header checksum, in case the driver won't do that. */
- pxIPHeader->usHeaderChecksum = 0x00u;
- pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0UL, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipSIZE_OF_IPv4_HEADER );
+ pxIPHeader->usHeaderChecksum = 0x00U;
+ pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0U, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), ipSIZE_OF_IPv4_HEADER );
pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
/* calculate the TCP checksum for an outgoing packet. */
- usGenerateProtocolChecksum( (uint8_t*)pxTCPPacket, pxNetworkBuffer->xDataLength, pdTRUE );
+ ( void ) usGenerateProtocolChecksum( ( uint8_t * ) pxTCPPacket, pxNetworkBuffer->xDataLength, pdTRUE );
/* A calculated checksum of 0 must be inverted as 0 means the checksum
is disabled. */
- if( pxTCPPacket->xTCPHeader.usChecksum == 0x00u )
+ if( pxTCPPacket->xTCPHeader.usChecksum == 0U )
{
pxTCPPacket->xTCPHeader.usChecksum = 0xffffU;
}
}
#endif
- #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
- pxNetworkBuffer->pxNextBuffer = NULL;
- #endif
-
- /* Important: tell NIC driver how many bytes must be sent. */
- pxNetworkBuffer->xDataLength = ulLen + ipSIZE_OF_ETH_HEADER;
+ #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
+ {
+ pxNetworkBuffer->pxNextBuffer = NULL;
+ }
+ #endif
/* Fill in the destination MAC addresses. */
- memcpy( ( void * ) &( pxEthernetHeader->xDestinationAddress ), ( void * ) &( pxEthernetHeader->xSourceAddress ),
- sizeof( pxEthernetHeader->xDestinationAddress ) );
+ ( void ) memcpy( &( pxEthernetHeader->xDestinationAddress ),
+ &( pxEthernetHeader->xSourceAddress ),
+ sizeof( pxEthernetHeader->xDestinationAddress ) );
/* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */
- memcpy( ( void * ) &( pxEthernetHeader->xSourceAddress) , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
-
+ ( void ) memcpy( &( pxEthernetHeader->xSourceAddress ), ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
+
#if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES )
{
if( pxNetworkBuffer->xDataLength < ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES )
@@ -944,7 +922,7 @@ NetworkBufferDescriptor_t xTempBuffer;
for( xIndex = ( BaseType_t ) pxNetworkBuffer->xDataLength; xIndex < ( BaseType_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; xIndex++ )
{
- pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0u;
+ pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0U;
}
pxNetworkBuffer->xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES;
}
@@ -952,15 +930,15 @@ NetworkBufferDescriptor_t xTempBuffer;
#endif
/* Send! */
- xNetworkInterfaceOutput( pxNetworkBuffer, xReleaseAfterSend );
+ ( void ) xNetworkInterfaceOutput( pxNetworkBuffer, xDoRelease );
- if( xReleaseAfterSend == pdFALSE )
+ if( xDoRelease == pdFALSE )
{
/* Swap-back some fields, as pxBuffer probably points to a socket field
containing the packet header. */
vFlip_16( pxTCPPacket->xTCPHeader.usSourcePort, pxTCPPacket->xTCPHeader.usDestinationPort);
pxTCPPacket->xIPHeader.ulSourceIPAddress = pxTCPPacket->xIPHeader.ulDestinationIPAddress;
- memcpy( pxEthernetHeader->xSourceAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
+ ( void ) memcpy( pxEthernetHeader->xSourceAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
}
else
{
@@ -978,16 +956,18 @@ NetworkBufferDescriptor_t xTempBuffer;
*/
static void prvTCPCreateWindow( FreeRTOS_Socket_t *pxSocket )
{
- if( xTCPWindowLoggingLevel )
- FreeRTOS_debug_printf( ( "Limits (using): TCP Win size %lu Water %lu <= %lu <= %lu\n",
- pxSocket->u.xTCP.uxRxWinSize * ipconfigTCP_MSS,
- pxSocket->u.xTCP.uxLittleSpace ,
- pxSocket->u.xTCP.uxEnoughSpace,
- pxSocket->u.xTCP.uxRxStreamSize ) );
+ if( xTCPWindowLoggingLevel != 0 )
+ {
+ FreeRTOS_debug_printf( ( "Limits (using): TCP Win size %u Water %u <= %u <= %u\n",
+ ( unsigned ) pxSocket->u.xTCP.uxRxWinSize * ipconfigTCP_MSS,
+ ( unsigned ) pxSocket->u.xTCP.uxLittleSpace ,
+ ( unsigned ) pxSocket->u.xTCP.uxEnoughSpace,
+ ( unsigned ) pxSocket->u.xTCP.uxRxStreamSize ) );
+ }
vTCPWindowCreate(
&pxSocket->u.xTCP.xTCPWindow,
- ipconfigTCP_MSS * pxSocket->u.xTCP.uxRxWinSize,
- ipconfigTCP_MSS * pxSocket->u.xTCP.uxTxWinSize,
+ ( ( size_t ) ipconfigTCP_MSS ) * pxSocket->u.xTCP.uxRxWinSize,
+ ( ( size_t ) ipconfigTCP_MSS ) * pxSocket->u.xTCP.uxTxWinSize,
pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber,
pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber,
( uint32_t ) pxSocket->u.xTCP.usInitMSS );
@@ -1013,7 +993,7 @@ uint32_t ulInitialSequenceNumber = 0;
#if( ipconfigHAS_PRINTF != 0 )
{
/* Only necessary for nicer logging. */
- memset( xEthAddress.ucBytes, '\0', sizeof( xEthAddress.ucBytes ) );
+ ( void ) memset( xEthAddress.ucBytes, 0, sizeof( xEthAddress.ucBytes ) );
}
#endif /* ipconfigHAS_PRINTF != 0 */
@@ -1045,8 +1025,8 @@ uint32_t ulInitialSequenceNumber = 0;
/* And issue a (new) ARP request */
FreeRTOS_OutputARPRequest( ulRemoteIP );
-
xReturn = pdFALSE;
+ break;
}
if( xReturn != pdFALSE )
@@ -1058,7 +1038,7 @@ uint32_t ulInitialSequenceNumber = 0;
pxSocket->u.xTCP.usRemotePort );
/* Check for a random number generation error. */
- if( 0 == ulInitialSequenceNumber )
+ if( ulInitialSequenceNumber == 0UL )
{
xReturn = pdFALSE;
}
@@ -1066,30 +1046,34 @@ uint32_t ulInitialSequenceNumber = 0;
if( xReturn != pdFALSE )
{
+ uint16_t usLength;
+
/* The MAC-address of the peer (or gateway) has been found,
- now prepare the initial TCP packet and some fields in the socket. */
- pxTCPPacket = ( TCPPacket_t * )pxSocket->u.xTCP.xPacket.u.ucLastPacket;
+ * now prepare the initial TCP packet and some fields in the socket. Map
+ * the buffer onto the TCPPacket_t struct to easily access it's field. */
+ pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxSocket->u.xTCP.xPacket.u.ucLastPacket );
pxIPHeader = &pxTCPPacket->xIPHeader;
/* reset the retry counter to zero. */
- pxSocket->u.xTCP.ucRepCount = 0u;
+ pxSocket->u.xTCP.ucRepCount = 0U;
/* And remember that the connect/SYN data are prepared. */
pxSocket->u.xTCP.bits.bConnPrepared = pdTRUE_UNSIGNED;
/* Now that the Ethernet address is known, the initial packet can be
prepared. */
- memset( pxSocket->u.xTCP.xPacket.u.ucLastPacket, '\0', sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) );
+ ( void ) memset( pxSocket->u.xTCP.xPacket.u.ucLastPacket, 0, sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) );
/* Write the Ethernet address in Source, because it will be swapped by
prvTCPReturnPacket(). */
- memcpy( &pxTCPPacket->xEthernetHeader.xSourceAddress, &xEthAddress, sizeof( xEthAddress ) );
+ ( void ) memcpy( &pxTCPPacket->xEthernetHeader.xSourceAddress, &xEthAddress, sizeof( xEthAddress ) );
/* 'ipIPv4_FRAME_TYPE' is already in network-byte-order. */
pxTCPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE;
- pxIPHeader->ucVersionHeaderLength = 0x45u;
- pxIPHeader->usLength = FreeRTOS_htons( sizeof( TCPPacket_t ) - sizeof( pxTCPPacket->xEthernetHeader ) );
+ pxIPHeader->ucVersionHeaderLength = 0x45U;
+ usLength = ( uint16_t ) ( sizeof( TCPPacket_t ) - sizeof( pxTCPPacket->xEthernetHeader ) );
+ pxIPHeader->usLength = FreeRTOS_htons( usLength );
pxIPHeader->ucTimeToLive = ( uint8_t ) ipconfigTCP_TIME_TO_LIVE;
pxIPHeader->ucProtocol = ( uint8_t ) ipPROTOCOL_TCP;
@@ -1104,17 +1088,17 @@ uint32_t ulInitialSequenceNumber = 0;
/* We are actively connecting, so the peer's Initial Sequence Number (ISN)
isn't known yet. */
- pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = 0ul;
+ pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = 0UL;
/* Start with ISN (Initial Sequence Number). */
pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber;
/* The TCP header size is 20 bytes, divided by 4 equals 5, which is put in
the high nibble of the TCP offset field. */
- pxTCPPacket->xTCPHeader.ucTCPOffset = 0x50u;
+ pxTCPPacket->xTCPHeader.ucTCPOffset = 0x50U;
/* Only set the SYN flag. */
- pxTCPPacket->xTCPHeader.ucTCPFlags = ipTCP_FLAG_SYN;
+ pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN;
/* Set the values of usInitMSS / usCurMSS for this socket. */
prvSocketSetMSS( pxSocket );
@@ -1133,19 +1117,20 @@ uint32_t ulInitialSequenceNumber = 0;
*/
#if( ipconfigHAS_DEBUG_PRINTF != 0 )
- static const char *prvTCPFlagMeaning( UBaseType_t xFlags)
+ static const char *prvTCPFlagMeaning( UBaseType_t xFlags )
{
static char retString[10];
- snprintf(retString, sizeof( retString ), "%c%c%c%c%c%c%c%c%c",
- ( xFlags & ipTCP_FLAG_FIN ) ? 'F' : '.', /* 0x0001: No more data from sender */
- ( xFlags & ipTCP_FLAG_SYN ) ? 'S' : '.', /* 0x0002: Synchronize sequence numbers */
- ( xFlags & ipTCP_FLAG_RST ) ? 'R' : '.', /* 0x0004: Reset the connection */
- ( xFlags & ipTCP_FLAG_PSH ) ? 'P' : '.', /* 0x0008: Push function: please push buffered data to the recv application */
- ( xFlags & ipTCP_FLAG_ACK ) ? 'A' : '.', /* 0x0010: Acknowledgment field is significant */
- ( xFlags & ipTCP_FLAG_URG ) ? 'U' : '.', /* 0x0020: Urgent pointer field is significant */
- ( xFlags & ipTCP_FLAG_ECN ) ? 'E' : '.', /* 0x0040: ECN-Echo */
- ( xFlags & ipTCP_FLAG_CWR ) ? 'C' : '.', /* 0x0080: Congestion Window Reduced */
- ( xFlags & ipTCP_FLAG_NS ) ? 'N' : '.'); /* 0x0100: ECN-nonce concealment protection */
+ size_t uxFlags = ( size_t ) xFlags;
+ ( void ) snprintf(retString,
+ sizeof( retString ), "%c%c%c%c%c%c%c%c",
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_FIN ) != 0 ) ? 'F' : '.', /* 0x0001: No more data from sender */
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_SYN ) != 0 ) ? 'S' : '.', /* 0x0002: Synchronize sequence numbers */
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_RST ) != 0 ) ? 'R' : '.', /* 0x0004: Reset the connection */
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_PSH ) != 0 ) ? 'P' : '.', /* 0x0008: Push function: please push buffered data to the recv application */
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_ACK ) != 0 ) ? 'A' : '.', /* 0x0010: Acknowledgment field is significant */
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_URG ) != 0 ) ? 'U' : '.', /* 0x0020: Urgent pointer field is significant */
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_ECN ) != 0 ) ? 'E' : '.', /* 0x0040: ECN-Echo */
+ ( ( uxFlags & ( size_t ) tcpTCP_FLAG_CWR ) != 0 ) ? 'C' : '.'); /* 0x0080: Congestion Window Reduced */
return retString;
}
/*-----------------------------------------------------------*/
@@ -1157,231 +1142,287 @@ uint32_t ulInitialSequenceNumber = 0;
* that: ((pxTCPHeader->ucTCPOffset & 0xf0) > 0x50), meaning that the TP header
* is longer than the usual 20 (5 x 4) bytes.
*/
-static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
+_static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{
-TCPPacket_t * pxTCPPacket;
-TCPHeader_t * pxTCPHeader;
-const unsigned char *pucPtr;
-const unsigned char *pucLast;
-TCPWindow_t *pxTCPWindow;
-BaseType_t xShouldContinueLoop;
+size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer );
+const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) );
+const TCPHeader_t * pxTCPHeader;
+const uint8_t *pucPtr;
+BaseType_t xHasSYNFlag;
+/* Offset in the network packet where the first option byte is stored. */
+size_t uxOptionOffset = uxTCPHeaderOffset + ( sizeof( TCPHeader_t ) - sizeof( pxTCPHeader->ucOptdata ) );
+size_t uxOptionsLength;
+size_t uxResult;
+uint8_t ucLength;
+
+ pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
- pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
- pxTCPHeader = &pxTCPPacket->xTCPHeader;
/* A character pointer to iterate through the option data */
pucPtr = pxTCPHeader->ucOptdata;
- pucLast = pucPtr + (((pxTCPHeader->ucTCPOffset >> 4) - 5) << 2);
- pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
-
- /* Validate options size calculation. */
- if( pucLast > ( pxNetworkBuffer->pucEthernetBuffer + pxNetworkBuffer->xDataLength ) )
+ if( pxTCPHeader->ucTCPOffset <= ( 5U << 4U ) )
{
- return;
+ /* Avoid integer underflow in computation of ucLength. */
}
-
- /* The comparison with pucLast is only necessary in case the option data are
- corrupted, we don't like to run into invalid memory and crash. */
- xShouldContinueLoop = pdTRUE;
- while( ( pucPtr < pucLast ) && ( xShouldContinueLoop == pdTRUE ) )
+ else
{
- xShouldContinueLoop = prvSingleStepTCPHeaderOptions( &pucPtr, &pucLast, &pxSocket, &pxTCPWindow );
+ ucLength = ( ( ( pxTCPHeader->ucTCPOffset >> 4U ) - 5U ) << 2U );
+ uxOptionsLength = ( size_t ) ucLength;
+ if( pxNetworkBuffer->xDataLength > uxOptionOffset )
+ {
+ /* Validate options size calculation. */
+ if( ( pxNetworkBuffer->xDataLength > uxOptionOffset ) &&
+ ( uxOptionsLength <= ( pxNetworkBuffer->xDataLength - uxOptionOffset ) ) )
+ {
+ if( ( pxTCPHeader->ucTCPFlags & tcpTCP_FLAG_SYN ) != ( uint8_t ) 0U )
+ {
+ xHasSYNFlag = pdTRUE;
+ }
+ else
+ {
+ xHasSYNFlag = pdFALSE;
+ }
+ /* The length check is only necessary in case the option data are
+ corrupted, we don't like to run into invalid memory and crash. */
+ for( ;; )
+ {
+ if( uxOptionsLength == 0U )
+ {
+ /* coverity[break_stmt] : Break statement terminating the loop */
+ break;
+ }
+ uxResult = prvSingleStepTCPHeaderOptions( pucPtr, uxOptionsLength, pxSocket, xHasSYNFlag );
+ if( uxResult == 0UL )
+ {
+ break;
+ }
+ uxOptionsLength -= uxResult;
+ pucPtr = &( pucPtr[ uxResult ] );
+ }
+ }
+ }
}
-}
+ return;
+}
/*-----------------------------------------------------------*/
-static BaseType_t prvSingleStepTCPHeaderOptions( const unsigned char ** const ppucPtr, const unsigned char ** const ppucLast, FreeRTOS_Socket_t ** const ppxSocket, TCPWindow_t ** const ppxTCPWindow)
+_static size_t prvSingleStepTCPHeaderOptions( const uint8_t * const pucPtr,
+ size_t uxTotalLength,
+ FreeRTOS_Socket_t * const pxSocket,
+ BaseType_t xHasSYNFlag )
{
- UBaseType_t uxNewMSS;
- UBaseType_t xRemainingOptionsBytes = ( *ppucLast ) - ( *ppucPtr );
- unsigned char ucLen;
+UBaseType_t uxNewMSS;
+size_t uxRemainingOptionsBytes = uxTotalLength;
+uint8_t ucLen;
+size_t uxIndex;
+TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
+BaseType_t xReturn = pdFALSE;
- if( ( *ppucPtr )[ 0 ] == TCP_OPT_END )
+ if( pucPtr[ 0U ] == tcpTCP_OPT_END )
{
/* End of options. */
- return pdFALSE;
+ uxIndex = 0U;
}
- if( ( *ppucPtr )[ 0 ] == TCP_OPT_NOOP)
+ else if( pucPtr[ 0U ] == tcpTCP_OPT_NOOP )
{
/* NOP option, inserted to make the length a multiple of 4. */
- ( *ppucPtr )++;
- return pdTRUE;
+ uxIndex = 1U;
}
-
- /* Any other well-formed option must be at least two bytes: the option
- type byte followed by a length byte. */
- if( xRemainingOptionsBytes < 2 )
+ else if( uxRemainingOptionsBytes < 2U )
{
- return pdFALSE;
+ /* Any other well-formed option must be at least two bytes: the option
+ type byte followed by a length byte. */
+ uxIndex = 0U;
}
#if( ipconfigUSE_TCP_WIN != 0 )
- else if( ( *ppucPtr )[ 0 ] == TCP_OPT_WSOPT )
+ else if( pucPtr[ 0 ] == tcpTCP_OPT_WSOPT )
{
+ /* The TCP Window Scale Option. */
/* Confirm that the option fits in the remaining buffer space. */
- if( ( xRemainingOptionsBytes < TCP_OPT_WSOPT_LEN ) || ( ( *ppucPtr )[ 1 ] != TCP_OPT_WSOPT_LEN ) )
+ if( ( uxRemainingOptionsBytes < tcpTCP_OPT_WSOPT_LEN ) || ( pucPtr[ 1 ] != tcpTCP_OPT_WSOPT_LEN ) )
{
- return pdFALSE;
+ uxIndex = 0U;
+ }
+ else
+ {
+ /* Option is only valid in SYN phase. */
+ if( xHasSYNFlag != 0 )
+ {
+ pxSocket->u.xTCP.ucPeerWinScaleFactor = pucPtr[ 2 ];
+ pxSocket->u.xTCP.bits.bWinScaling = pdTRUE_UNSIGNED;
+ }
+ uxIndex = tcpTCP_OPT_WSOPT_LEN;
}
-
- ( *ppxSocket )->u.xTCP.ucPeerWinScaleFactor = ( *ppucPtr )[ 2 ];
- ( *ppxSocket )->u.xTCP.bits.bWinScaling = pdTRUE_UNSIGNED;
- ( *ppucPtr ) += TCP_OPT_WSOPT_LEN;
}
#endif /* ipconfigUSE_TCP_WIN */
- else if( ( *ppucPtr )[ 0 ] == TCP_OPT_MSS )
+ else if( pucPtr[ 0 ] == tcpTCP_OPT_MSS )
{
/* Confirm that the option fits in the remaining buffer space. */
- if( ( xRemainingOptionsBytes < TCP_OPT_MSS_LEN )|| ( ( *ppucPtr )[ 1 ] != TCP_OPT_MSS_LEN ) )
+ if( ( uxRemainingOptionsBytes < tcpTCP_OPT_MSS_LEN ) || ( pucPtr[ 1 ] != tcpTCP_OPT_MSS_LEN ) )
{
- return pdFALSE;
+ uxIndex = 0U;
}
-
- /* An MSS option with the correct option length. FreeRTOS_htons()
- is not needed here because usChar2u16() already returns a host
- endian number. */
- uxNewMSS = usChar2u16( ( *ppucPtr ) + 2 );
-
- if( ( *ppxSocket )->u.xTCP.usInitMSS != uxNewMSS )
+ else
{
- /* Perform a basic check on the the new MSS. */
- if( uxNewMSS == 0 )
+ /* An MSS option with the correct option length. FreeRTOS_htons()
+ is not needed here because usChar2u16() already returns a host
+ endian number. */
+ uxNewMSS = usChar2u16( &( pucPtr[ 2 ] ) );
+
+ if( pxSocket->u.xTCP.usInitMSS != uxNewMSS )
{
- return pdFALSE;
- }
+ /* Perform a basic check on the the new MSS. */
+ if( uxNewMSS == 0U )
+ {
+ uxIndex = 0U;
- FreeRTOS_debug_printf( ( "MSS change %u -> %lu\n", ( *ppxSocket )->u.xTCP.usInitMSS, uxNewMSS ) );
- }
+ /* Return Condition found. */
+ xReturn = pdTRUE;
+ }
+ else
+ {
+ FreeRTOS_debug_printf( ( "MSS change %u -> %lu\n", pxSocket->u.xTCP.usInitMSS, uxNewMSS ) );
+ }
+ }
- if( ( *ppxSocket )->u.xTCP.usInitMSS > uxNewMSS )
- {
- /* our MSS was bigger than the MSS of the other party: adapt it. */
- ( *ppxSocket )->u.xTCP.bits.bMssChange = pdTRUE_UNSIGNED;
- if( ( ( *ppxTCPWindow ) != NULL ) && ( ( *ppxSocket )->u.xTCP.usCurMSS > uxNewMSS ) )
+ /* If a 'return' condition has not been found. */
+ if( xReturn == pdFALSE )
{
- /* The peer advertises a smaller MSS than this socket was
- using. Use that as well. */
- FreeRTOS_debug_printf( ( "Change mss %d => %lu\n", ( *ppxSocket )->u.xTCP.usCurMSS, uxNewMSS ) );
- ( *ppxSocket )->u.xTCP.usCurMSS = ( uint16_t ) uxNewMSS;
+ if( pxSocket->u.xTCP.usInitMSS > uxNewMSS )
+ {
+ /* our MSS was bigger than the MSS of the other party: adapt it. */
+ pxSocket->u.xTCP.bits.bMssChange = pdTRUE_UNSIGNED;
+ if( pxSocket->u.xTCP.usCurMSS > uxNewMSS )
+ {
+ /* The peer advertises a smaller MSS than this socket was
+ using. Use that as well. */
+ FreeRTOS_debug_printf( ( "Change mss %d => %lu\n", pxSocket->u.xTCP.usCurMSS, uxNewMSS ) );
+ pxSocket->u.xTCP.usCurMSS = ( uint16_t ) uxNewMSS;
+ }
+ pxTCPWindow->xSize.ulRxWindowLength = ( ( uint32_t ) uxNewMSS ) * ( pxTCPWindow->xSize.ulRxWindowLength / ( ( uint32_t ) uxNewMSS ) );
+ pxTCPWindow->usMSSInit = ( uint16_t ) uxNewMSS;
+ pxTCPWindow->usMSS = ( uint16_t ) uxNewMSS;
+ pxSocket->u.xTCP.usInitMSS = ( uint16_t ) uxNewMSS;
+ pxSocket->u.xTCP.usCurMSS = ( uint16_t ) uxNewMSS;
+ }
+
+ uxIndex = tcpTCP_OPT_MSS_LEN;
}
- ( *ppxTCPWindow )->xSize.ulRxWindowLength = ( ( uint32_t ) uxNewMSS ) * ( ( *ppxTCPWindow )->xSize.ulRxWindowLength / ( ( uint32_t ) uxNewMSS ) );
- ( *ppxTCPWindow )->usMSSInit = ( uint16_t ) uxNewMSS;
- ( *ppxTCPWindow )->usMSS = ( uint16_t ) uxNewMSS;
- ( *ppxSocket )->u.xTCP.usInitMSS = ( uint16_t ) uxNewMSS;
- ( *ppxSocket )->u.xTCP.usCurMSS = ( uint16_t ) uxNewMSS;
}
-
- #if( ipconfigUSE_TCP_WIN != 1 )
- /* Without scaled windows, MSS is the only interesting option. */
- return pdFALSE;
- #else
- /* Or else we continue to check another option: selective ACK. */
- ( *ppucPtr ) += TCP_OPT_MSS_LEN;
- #endif /* ipconfigUSE_TCP_WIN != 1 */
}
else
{
/* All other options have a length field, so that we easily
can skip past them. */
- ucLen = ( *ppucPtr )[ 1 ];
- if( ( ucLen < 2 ) || ( ucLen > xRemainingOptionsBytes ) )
+ ucLen = pucPtr[ 1 ];
+ if( ( ucLen < ( uint8_t ) 2U ) || ( uxRemainingOptionsBytes < ( size_t ) ucLen ) )
{
/* If the length field is too small or too big, the options are
* malformed, don't process them further.
*/
- return pdFALSE;
+ uxIndex = 0U;
}
-
- #if( ipconfigUSE_TCP_WIN == 1 )
+ else
{
- /* Selective ACK: the peer has received a packet but it is missing
- * earlier packets. At least this packet does not need retransmission
- * anymore. ulTCPWindowTxSack( ) takes care of this administration.
- */
- if( ( *ppucPtr )[0] == TCP_OPT_SACK_A )
+ uxIndex = 0U;
+
+ #if( ipconfigUSE_TCP_WIN == 1 )
{
- ucLen -= 2;
- ( *ppucPtr ) += 2;
-
- while( ucLen >= 8 )
+ /* Selective ACK: the peer has received a packet but it is missing
+ * earlier packets. At least this packet does not need retransmission
+ * anymore. ulTCPWindowTxSack( ) takes care of this administration.
+ */
+ if( pucPtr[ 0U ] == tcpTCP_OPT_SACK_A )
{
- prvSkipPastRemainingOptions( ppucPtr, ppxSocket, &ucLen );
+ ucLen -= 2U;
+ uxIndex += 2U;
+
+ while( ucLen >= ( uint8_t ) 8U )
+ {
+ prvReadSackOption( pucPtr, uxIndex, pxSocket );
+ uxIndex += 8U;
+ ucLen -= 8U;
+ }
+ /* ucLen should be 0 by now. */
}
- /* ucLen should be 0 by now. */
}
- }
- #endif /* ipconfigUSE_TCP_WIN == 1 */
+ #endif /* ipconfigUSE_TCP_WIN == 1 */
- ( *ppucPtr ) += ucLen;
+ uxIndex += ( size_t ) ucLen;
+ }
}
- return pdTRUE;
+ return uxIndex;
}
-
/*-----------------------------------------------------------*/
-static void prvSkipPastRemainingOptions( const unsigned char ** const ppucPtr, FreeRTOS_Socket_t ** const ppxSocket, unsigned char * const pucLen )
-{
-uint32_t ulFirst = ulChar2u32( ( *ppucPtr ) );
-uint32_t ulLast = ulChar2u32( ( *ppucPtr ) + 4 );
-uint32_t ulCount = ulTCPWindowTxSack( &( *ppxSocket )->u.xTCP.xTCPWindow, ulFirst, ulLast );
- /* ulTCPWindowTxSack( ) returns the number of bytes which have been acked
- * starting from the head position. Advance the tail pointer in txStream.
- */
- if( ( ( *ppxSocket )->u.xTCP.txStream != NULL ) && ( ulCount > 0 ) )
+#if( ipconfigUSE_TCP_WIN == 1 )
+ _static void prvReadSackOption( const uint8_t * const pucPtr,
+ size_t uxIndex,
+ FreeRTOS_Socket_t * const pxSocket )
{
- /* Just advancing the tail index, 'ulCount' bytes have been confirmed. */
- uxStreamBufferGet( ( *ppxSocket )->u.xTCP.txStream, 0, NULL, ( size_t ) ulCount, pdFALSE );
- ( *ppxSocket )->xEventBits |= eSOCKET_SEND;
+ uint32_t ulFirst = ulChar2u32( &( pucPtr[ uxIndex ] ) );
+ uint32_t ulLast = ulChar2u32( &( pucPtr[ uxIndex + 4U ] ) );
+ uint32_t ulCount = ulTCPWindowTxSack( &( pxSocket->u.xTCP.xTCPWindow ), ulFirst, ulLast );;
- #if ipconfigSUPPORT_SELECT_FUNCTION == 1
+ /* ulTCPWindowTxSack( ) returns the number of bytes which have been acked
+ * starting from the head position. Advance the tail pointer in txStream.
+ */
+ if( ( pxSocket->u.xTCP.txStream != NULL ) && ( ulCount > 0U ) )
{
- if( ( *ppxSocket )->xSelectBits & eSELECT_WRITE )
+ /* Just advancing the tail index, 'ulCount' bytes have been confirmed. */
+ ( void ) uxStreamBufferGet( pxSocket->u.xTCP.txStream, 0, NULL, ( size_t ) ulCount, pdFALSE );
+ pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_SEND;
+
+ #if ipconfigSUPPORT_SELECT_FUNCTION == 1
{
- /* The field 'xEventBits' is used to store regular socket events
- * (at most 8), as well as 'select events', which will be left-shifted.
- */
- ( *ppxSocket )->xEventBits |= ( eSELECT_WRITE << SOCKET_EVENT_BIT_COUNT );
+ if( ( pxSocket->xSelectBits & ( EventBits_t ) eSELECT_WRITE ) != 0U )
+ {
+ /* The field 'xEventBits' is used to store regular socket events
+ * (at most 8), as well as 'select events', which will be left-shifted.
+ */
+ pxSocket->xEventBits |= ( ( EventBits_t ) eSELECT_WRITE ) << SOCKET_EVENT_BIT_COUNT;
+ }
}
- }
- #endif
+ #endif
- /* In case the socket owner has installed an OnSent handler, call it now.
- */
- #if( ipconfigUSE_CALLBACKS == 1 )
- {
- if( ipconfigIS_VALID_PROG_ADDRESS( ( *ppxSocket )->u.xTCP.pxHandleSent ) )
+ /* In case the socket owner has installed an OnSent handler,
+ call it now. */
+ #if( ipconfigUSE_CALLBACKS == 1 )
{
- ( *ppxSocket )->u.xTCP.pxHandleSent( (Socket_t )( *ppxSocket ), ulCount );
+ if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleSent ) )
+ {
+ pxSocket->u.xTCP.pxHandleSent( pxSocket, ulCount );
+ }
}
+ #endif /* ipconfigUSE_CALLBACKS == 1 */
}
- #endif /* ipconfigUSE_CALLBACKS == 1 */
}
- ( *ppucPtr ) += 8;
- ( *pucLen ) -= 8;
-}
+#endif /* ( ipconfigUSE_TCP_WIN != 0 ) */
/*-----------------------------------------------------------*/
#if( ipconfigUSE_TCP_WIN != 0 )
- static uint8_t prvWinScaleFactor( FreeRTOS_Socket_t *pxSocket )
+ static uint8_t prvWinScaleFactor( const FreeRTOS_Socket_t *pxSocket )
{
size_t uxWinSize;
uint8_t ucFactor;
/* 'xTCP.uxRxWinSize' is the size of the reception window in units of MSS. */
uxWinSize = pxSocket->u.xTCP.uxRxWinSize * ( size_t ) pxSocket->u.xTCP.usInitMSS;
- ucFactor = 0u;
- while( uxWinSize > 0xfffful )
+ ucFactor = 0U;
+ while( uxWinSize > 0xffffUL )
{
/* Divide by two and increase the binary factor by 1. */
uxWinSize >>= 1;
ucFactor++;
}
- FreeRTOS_debug_printf( ( "prvWinScaleFactor: uxRxWinSize %lu MSS %lu Factor %u\n",
- pxSocket->u.xTCP.uxRxWinSize,
- pxSocket->u.xTCP.usInitMSS,
+ FreeRTOS_debug_printf( ( "prvWinScaleFactor: uxRxWinSize %u MSS %u Factor %u\n",
+ ( unsigned ) pxSocket->u.xTCP.uxRxWinSize,
+ ( unsigned ) pxSocket->u.xTCP.usInitMSS,
ucFactor ) );
return ucFactor;
@@ -1395,50 +1436,45 @@ uint32_t ulCount = ulTCPWindowTxSack( &( *ppxSocket )->u.xTCP.xTCPWindow, ulFirs
* communicate what MSS (Maximum Segment Size) they intend to use. MSS is the
* nett size of the payload, always smaller than MTU.
*/
-static UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t *pxSocket, TCPPacket_t * pxTCPPacket )
+static UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t *pxSocket, TCPHeader_t * pxTCPHeader )
{
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
uint16_t usMSS = pxSocket->u.xTCP.usInitMSS;
UBaseType_t uxOptionsLength;
/* We send out the TCP Maximum Segment Size option with our SYN[+ACK]. */
- pxTCPHeader->ucOptdata[ 0 ] = ( uint8_t ) TCP_OPT_MSS;
- pxTCPHeader->ucOptdata[ 1 ] = ( uint8_t ) TCP_OPT_MSS_LEN;
+ pxTCPHeader->ucOptdata[ 0 ] = ( uint8_t ) tcpTCP_OPT_MSS;
+ pxTCPHeader->ucOptdata[ 1 ] = ( uint8_t ) tcpTCP_OPT_MSS_LEN;
pxTCPHeader->ucOptdata[ 2 ] = ( uint8_t ) ( usMSS >> 8 );
- pxTCPHeader->ucOptdata[ 3 ] = ( uint8_t ) ( usMSS & 0xffu );
+ pxTCPHeader->ucOptdata[ 3 ] = ( uint8_t ) ( usMSS & 0xffU );
#if( ipconfigUSE_TCP_WIN != 0 )
{
pxSocket->u.xTCP.ucMyWinScaleFactor = prvWinScaleFactor( pxSocket );
- pxTCPHeader->ucOptdata[ 4 ] = TCP_OPT_NOOP;
- pxTCPHeader->ucOptdata[ 5 ] = ( uint8_t ) ( TCP_OPT_WSOPT );
- pxTCPHeader->ucOptdata[ 6 ] = ( uint8_t ) ( TCP_OPT_WSOPT_LEN );
+ pxTCPHeader->ucOptdata[ 4 ] = tcpTCP_OPT_NOOP;
+ pxTCPHeader->ucOptdata[ 5 ] = ( uint8_t ) ( tcpTCP_OPT_WSOPT );
+ pxTCPHeader->ucOptdata[ 6 ] = ( uint8_t ) ( tcpTCP_OPT_WSOPT_LEN );
pxTCPHeader->ucOptdata[ 7 ] = ( uint8_t ) pxSocket->u.xTCP.ucMyWinScaleFactor;
- uxOptionsLength = 8u;
+ uxOptionsLength = 8U;
}
#else
{
- uxOptionsLength = 4u;
+ uxOptionsLength = 4U;
}
#endif
- #if( ipconfigUSE_TCP_WIN == 0 )
- {
- return uxOptionsLength;
- }
- #else
+ #if( ipconfigUSE_TCP_WIN != 0 )
{
- pxTCPHeader->ucOptdata[ uxOptionsLength + 0 ] = TCP_OPT_NOOP;
- pxTCPHeader->ucOptdata[ uxOptionsLength + 1 ] = TCP_OPT_NOOP;
- pxTCPHeader->ucOptdata[ uxOptionsLength + 2 ] = TCP_OPT_SACK_P; /* 4: Sack-Permitted Option. */
- pxTCPHeader->ucOptdata[ uxOptionsLength + 3 ] = 2; /* 2: length of this option. */
- uxOptionsLength += 4u;
+ pxTCPHeader->ucOptdata[ uxOptionsLength ] = tcpTCP_OPT_NOOP;
+ pxTCPHeader->ucOptdata[ uxOptionsLength + 1U ] = tcpTCP_OPT_NOOP;
+ pxTCPHeader->ucOptdata[ uxOptionsLength + 2U ] = tcpTCP_OPT_SACK_P; /* 4: Sack-Permitted Option. */
+ pxTCPHeader->ucOptdata[ uxOptionsLength + 3U ] = 2U; /* 2: length of this option. */
+ uxOptionsLength += 4U;
- return uxOptionsLength; /* bytes, not words. */
}
#endif /* ipconfigUSE_TCP_WIN == 0 */
+ return uxOptionsLength; /* bytes, not words. */
}
/*
@@ -1458,7 +1494,7 @@ static void prvTCPTouchSocket( FreeRTOS_Socket_t *pxSocket )
{
pxSocket->u.xTCP.bits.bWaitKeepAlive = pdFALSE_UNSIGNED;
pxSocket->u.xTCP.bits.bSendKeepAlive = pdFALSE_UNSIGNED;
- pxSocket->u.xTCP.ucKeepRepCount = 0u;
+ pxSocket->u.xTCP.ucKeepRepCount = 0U;
pxSocket->u.xTCP.xLastAliveTime = xTaskGetTickCount();
}
#endif
@@ -1476,8 +1512,8 @@ static void prvTCPTouchSocket( FreeRTOS_Socket_t *pxSocket )
void vTCPStateChange( FreeRTOS_Socket_t *pxSocket, enum eTCP_STATE eTCPState )
{
FreeRTOS_Socket_t *xParent = NULL;
-BaseType_t bBefore = ( BaseType_t ) NOW_CONNECTED( pxSocket->u.xTCP.ucTCPState ); /* Was it connected ? */
-BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it connected now ? */
+BaseType_t bBefore = ipNUMERIC_CAST( BaseType_t, tcpNOW_CONNECTED( ( BaseType_t ) pxSocket->u.xTCP.ucTCPState ) ); /* Was it connected ? */
+BaseType_t bAfter = ipNUMERIC_CAST( BaseType_t, tcpNOW_CONNECTED( ( BaseType_t ) eTCPState ) ); /* Is it connected now ? */
#if( ipconfigHAS_DEBUG_PRINTF != 0 )
BaseType_t xPreviousState = ( BaseType_t ) pxSocket->u.xTCP.ucTCPState;
#endif
@@ -1511,22 +1547,22 @@ BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it co
xParent->u.xTCP.pxPeerSocket = pxSocket;
}
- xParent->xEventBits |= eSOCKET_ACCEPT;
+ xParent->xEventBits |= ( EventBits_t ) eSOCKET_ACCEPT;
#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
{
/* Library support FreeRTOS_select(). Receiving a new
connection is being translated as a READ event. */
- if( ( xParent->xSelectBits & eSELECT_READ ) != 0 )
+ if( ( xParent->xSelectBits & ( ( EventBits_t ) eSELECT_READ ) ) != 0U )
{
- xParent->xEventBits |= ( eSELECT_READ << SOCKET_EVENT_BIT_COUNT );
+ xParent->xEventBits |= ( ( EventBits_t ) eSELECT_READ ) << SOCKET_EVENT_BIT_COUNT;
}
}
#endif
#if( ipconfigUSE_CALLBACKS == 1 )
{
- if( ( ipconfigIS_VALID_PROG_ADDRESS( xParent->u.xTCP.pxHandleConnected ) != pdFALSE ) &&
+ if( ( ipconfigIS_VALID_PROG_ADDRESS( xParent->u.xTCP.pxHandleConnected ) ) &&
( xParent->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) )
{
/* The listening socket does not become connected itself, in stead
@@ -1548,13 +1584,13 @@ BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it co
}
else
{
- pxSocket->xEventBits |= eSOCKET_CONNECT;
+ pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_CONNECT;
#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
{
- if( pxSocket->xSelectBits & eSELECT_WRITE )
+ if( ( pxSocket->xSelectBits & ( ( EventBits_t ) eSELECT_WRITE ) ) != 0U )
{
- pxSocket->xEventBits |= ( eSELECT_WRITE << SOCKET_EVENT_BIT_COUNT );
+ pxSocket->xEventBits |= ( ( EventBits_t ) eSELECT_WRITE ) << SOCKET_EVENT_BIT_COUNT;
}
}
#endif
@@ -1563,20 +1599,20 @@ BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it co
else /* bAfter == pdFALSE, connection is closed. */
{
/* Notify/wake-up the socket-owner by setting a semaphore. */
- pxSocket->xEventBits |= eSOCKET_CLOSED;
+ pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_CLOSED;
#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
{
- if( ( pxSocket->xSelectBits & eSELECT_EXCEPT ) != 0 )
+ if( ( pxSocket->xSelectBits & ( EventBits_t ) eSELECT_EXCEPT ) != 0U )
{
- pxSocket->xEventBits |= ( eSELECT_EXCEPT << SOCKET_EVENT_BIT_COUNT );
+ pxSocket->xEventBits |= ( ( EventBits_t ) eSELECT_EXCEPT ) << SOCKET_EVENT_BIT_COUNT;
}
}
#endif
}
#if( ipconfigUSE_CALLBACKS == 1 )
{
- if( ( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleConnected ) != pdFALSE ) && ( xConnected == NULL ) )
+ if( ( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleConnected ) ) && ( xConnected == NULL ) )
{
/* The 'connected' state has changed, call the user handler. */
xConnected = pxSocket;
@@ -1584,18 +1620,18 @@ BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it co
}
#endif /* ipconfigUSE_CALLBACKS */
- if( prvTCPSocketIsActive( ( UBaseType_t ) pxSocket->u.xTCP.ucTCPState ) == pdFALSE )
+ if( prvTCPSocketIsActive( ipNUMERIC_CAST( eIPTCPState_t, pxSocket->u.xTCP.ucTCPState ) ) == 0 )
{
/* Now the socket isn't in an active state anymore so it
won't need further attention of the IP-task.
Setting time-out to zero means that the socket won't get checked during
timer events. */
- pxSocket->u.xTCP.usTimeout = 0u;
+ pxSocket->u.xTCP.usTimeout = 0U;
}
}
else
{
- if( eTCPState == eCLOSED )
+ if( ( ( BaseType_t ) eTCPState ) == ( ( BaseType_t ) eCLOSED ) )
{
/* Socket goes to status eCLOSED because of a RST.
When nobody owns the socket yet, delete it. */
@@ -1605,7 +1641,7 @@ BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it co
FreeRTOS_debug_printf( ( "vTCPStateChange: Closing socket\n" ) );
if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED )
{
- FreeRTOS_closesocket( pxSocket );
+ ( void ) FreeRTOS_closesocket( pxSocket );
}
}
}
@@ -1614,18 +1650,20 @@ BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it co
/* Fill in the new state. */
pxSocket->u.xTCP.ucTCPState = ( uint8_t ) eTCPState;
- /* touch the alive timers because moving to another state. */
+ /* Touch the alive timers because moving to another state. */
prvTCPTouchSocket( pxSocket );
#if( ipconfigHAS_DEBUG_PRINTF == 1 )
{
- if( ( xTCPWindowLoggingLevel >= 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE ) )
- FreeRTOS_debug_printf( ( "Socket %d -> %lxip:%u State %s->%s\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.ulRemoteIP,
- pxSocket->u.xTCP.usRemotePort,
- FreeRTOS_GetTCPStateName( ( UBaseType_t ) xPreviousState ),
- FreeRTOS_GetTCPStateName( ( UBaseType_t ) eTCPState ) ) );
+ if( ( xTCPWindowLoggingLevel >= 0 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) ) )
+ {
+ FreeRTOS_debug_printf( ( "Socket %d -> %lxip:%u State %s->%s\n",
+ pxSocket->usLocalPort,
+ pxSocket->u.xTCP.ulRemoteIP,
+ pxSocket->u.xTCP.usRemotePort,
+ FreeRTOS_GetTCPStateName( ( UBaseType_t ) xPreviousState ),
+ FreeRTOS_GetTCPStateName( ( UBaseType_t ) eTCPState ) ) );
+ }
}
#endif /* ipconfigHAS_DEBUG_PRINTF */
@@ -1645,31 +1683,50 @@ BaseType_t bAfter = ( BaseType_t ) NOW_CONNECTED( eTCPState ); /* Is it co
}
/*-----------------------------------------------------------*/
-static NetworkBufferDescriptor_t *prvTCPBufferResize( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
+static NetworkBufferDescriptor_t *prvTCPBufferResize( const FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
int32_t lDataLen, UBaseType_t uxOptionsLength )
{
NetworkBufferDescriptor_t *pxReturn;
-int32_t lNeeded;
+size_t uxNeeded;
BaseType_t xResize;
if( xBufferAllocFixedSize != pdFALSE )
{
/* Network buffers are created with a fixed size and can hold the largest
MTU. */
- lNeeded = ( int32_t ) ipTOTAL_ETHERNET_FRAME_SIZE;
+ uxNeeded = ( size_t ) ipTOTAL_ETHERNET_FRAME_SIZE;
/* and therefore, the buffer won't be too small.
Only ask for a new network buffer in case none was supplied. */
- xResize = ( pxNetworkBuffer == NULL );
+ if( pxNetworkBuffer == NULL )
+ {
+ xResize = pdTRUE;
+ }
+ else
+ {
+ xResize = pdFALSE;
+ }
}
else
{
/* Network buffers are created with a variable size. See if it must
grow. */
- lNeeded = FreeRTOS_max_int32( ( int32_t ) sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ),
- ( int32_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength ) + lDataLen );
+ uxNeeded = ipNUMERIC_CAST( size_t, ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ) + lDataLen;
+
+ if( uxNeeded < sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) )
+ {
+ uxNeeded = sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket );
+ }
+
/* In case we were called from a TCP timer event, a buffer must be
created. Otherwise, test 'xDataLength' of the provided buffer. */
- xResize = ( pxNetworkBuffer == NULL ) || ( pxNetworkBuffer->xDataLength < (size_t)lNeeded );
+ if( ( pxNetworkBuffer == NULL ) || ( pxNetworkBuffer->xDataLength < uxNeeded ) )
+ {
+ xResize = pdTRUE;
+ }
+ else
+ {
+ xResize = pdFALSE;
+ }
}
if( xResize != pdFALSE )
@@ -1677,18 +1734,18 @@ BaseType_t xResize;
/* The caller didn't provide a network buffer or the provided buffer is
too small. As we must send-out a data packet, a buffer will be created
here. */
- pxReturn = pxGetNetworkBufferWithDescriptor( ( uint32_t ) lNeeded, 0u );
+ pxReturn = pxGetNetworkBufferWithDescriptor( uxNeeded, 0U );
if( pxReturn != NULL )
{
/* Set the actual packet size, in case the returned buffer is larger. */
- pxReturn->xDataLength = lNeeded;
+ pxReturn->xDataLength = uxNeeded;
/* Copy the existing data to the new created buffer. */
- if( pxNetworkBuffer )
+ if( pxNetworkBuffer != NULL )
{
/* Either from the previous buffer... */
- memcpy( pxReturn->pucEthernetBuffer, pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength );
+ ( void ) memcpy( pxReturn->pucEthernetBuffer, pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength );
/* ...and release it. */
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
@@ -1696,18 +1753,19 @@ BaseType_t xResize;
else
{
/* Or from the socket field 'xTCP.xPacket'. */
- memcpy( pxReturn->pucEthernetBuffer, pxSocket->u.xTCP.xPacket.u.ucLastPacket, sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) );
+ ( void ) memcpy( pxReturn->pucEthernetBuffer, pxSocket->u.xTCP.xPacket.u.ucLastPacket, sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) );
}
}
}
else
{
/* xResize is false, the network buffer provided was big enough. */
+ configASSERT( pxNetworkBuffer != NULL ); /* to tell lint: when xResize is false, pxNetworkBuffer is not NULL. */
pxReturn = pxNetworkBuffer;
/* Thanks to Andrey Ivanov from swissEmbedded for reporting that the
xDataLength member must get the correct length too! */
- pxNetworkBuffer->xDataLength = ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength ) + ( size_t ) lDataLen;
+ pxNetworkBuffer->xDataLength = ( size_t ) ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ) + ( size_t ) lDataLen;
}
return pxReturn;
@@ -1721,7 +1779,7 @@ static int32_t prvTCPPrepareSend( FreeRTOS_Socket_t *pxSocket, NetworkBufferDesc
{
int32_t lDataLen;
uint8_t *pucEthernetBuffer, *pucSendData;
-TCPPacket_t *pxTCPPacket;
+ProtocolHeaders_t *pxProtocolHeaders;
size_t uxOffset;
uint32_t ulDataGot, ulDistance;
TCPWindow_t *pxTCPWindow;
@@ -1739,11 +1797,12 @@ int32_t lStreamPos;
pucEthernetBuffer = pxSocket->u.xTCP.xPacket.u.ucLastPacket;
}
- pxTCPPacket = ( TCPPacket_t * ) ( pucEthernetBuffer );
- pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
+ /* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+ pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
+ pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
lDataLen = 0;
lStreamPos = 0;
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ipTCP_FLAG_ACK;
+ pxProtocolHeaders->xTCPHeader.ucTCPFlags |= tcpTCP_FLAG_ACK;
if( pxSocket->u.xTCP.txStream != NULL )
{
@@ -1751,7 +1810,7 @@ int32_t lStreamPos;
along with the position in the txStream.
Why check for MSS > 1 ?
Because some TCP-stacks (like uIP) use it for flow-control. */
- if( pxSocket->u.xTCP.usCurMSS > 1u )
+ if( pxSocket->u.xTCP.usCurMSS > 1U )
{
lDataLen = ( int32_t ) ulTCPWindowTxGet( pxTCPWindow, pxSocket->u.xTCP.ulWindowSize, &lStreamPos );
}
@@ -1766,9 +1825,12 @@ int32_t lStreamPos;
{
*ppxNetworkBuffer = pxNewBuffer;
pucEthernetBuffer = pxNewBuffer->pucEthernetBuffer;
- pxTCPPacket = ( TCPPacket_t * ) ( pucEthernetBuffer );
- pucSendData = pucEthernetBuffer + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength;
+ /* Map the byte stream onto ProtocolHeaders_t struct for easy
+ * access to the fields. */
+ pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
+
+ pucSendData = &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ] );
/* Translate the position in txStream to an offset from the tail
marker. */
@@ -1782,8 +1844,8 @@ int32_t lStreamPos;
{
if( ulDataGot != ( uint32_t ) lDataLen )
{
- FreeRTOS_debug_printf( ( "uxStreamBufferGet: pos %lu offs %lu only %lu != %lu\n",
- lStreamPos, uxOffset, ulDataGot, lDataLen ) );
+ FreeRTOS_debug_printf( ( "uxStreamBufferGet: pos %d offs %u only %u != %d\n",
+ ( int ) lStreamPos, ( unsigned ) uxOffset, ( unsigned ) ulDataGot, ( int ) lDataLen ) );
}
}
#endif
@@ -1804,14 +1866,15 @@ int32_t lStreamPos;
size_t uxMid = pxSocket->u.xTCP.txStream->uxMid;
size_t uxTail = pxSocket->u.xTCP.txStream->uxTail;
- FreeRTOS_debug_printf( ( "CheckClose %lu <= %lu (%lu <= %lu <= %lu)\n", ulDataGot, ulDistance,
- uxTail, uxMid, uxHead ) );
+ FreeRTOS_debug_printf( ( "CheckClose %u <= %u (%u <= %u <= %u)\n",
+ ( unsigned ) ulDataGot, ( unsigned ) ulDistance,
+ ( unsigned ) uxTail, ( unsigned ) uxMid, ( unsigned ) uxHead ) );
}
#endif
/* Although the socket sends a FIN, it will stay in
ESTABLISHED until all current data has been received or
delivered. */
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ipTCP_FLAG_FIN;
+ pxProtocolHeaders->xTCPHeader.ucTCPFlags |= tcpTCP_FLAG_FIN;
pxTCPWindow->tx.ulFINSequenceNumber = pxTCPWindow->ulOurSequenceNumber + ( uint32_t ) lDataLen;
pxSocket->u.xTCP.bits.bFinSent = pdTRUE_UNSIGNED;
}
@@ -1824,14 +1887,14 @@ int32_t lStreamPos;
}
}
- if( ( lDataLen >= 0 ) && ( pxSocket->u.xTCP.ucTCPState == eESTABLISHED ) )
+ if( ( lDataLen >= 0 ) && ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eESTABLISHED ) )
{
/* See if the socket owner wants to shutdown this connection. */
if( ( pxSocket->u.xTCP.bits.bUserShutdown != pdFALSE_UNSIGNED ) &&
( xTCPWindowTxDone( pxTCPWindow ) != pdFALSE ) )
{
pxSocket->u.xTCP.bits.bUserShutdown = pdFALSE_UNSIGNED;
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ipTCP_FLAG_FIN;
+ pxProtocolHeaders->xTCPHeader.ucTCPFlags |= tcpTCP_FLAG_FIN;
pxSocket->u.xTCP.bits.bFinSent = pdTRUE_UNSIGNED;
pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED;
pxTCPWindow->tx.ulFINSequenceNumber = pxTCPWindow->tx.ulCurrentSequenceNumber;
@@ -1840,7 +1903,7 @@ int32_t lStreamPos;
#if( ipconfigTCP_KEEP_ALIVE != 0 )
{
- if( pxSocket->u.xTCP.ucKeepRepCount > 3u )
+ if( pxSocket->u.xTCP.ucKeepRepCount > 3U ) /*_RB_ Magic number. */
{
FreeRTOS_debug_printf( ( "keep-alive: giving up %lxip:%u\n",
pxSocket->u.xTCP.ulRemoteIP, /* IP address of remote machine. */
@@ -1854,21 +1917,23 @@ int32_t lStreamPos;
we might want to send a keep-alive message. */
TickType_t xAge = xTaskGetTickCount( ) - pxSocket->u.xTCP.xLastAliveTime;
TickType_t xMax;
- xMax = ( ( TickType_t ) ipconfigTCP_KEEP_ALIVE_INTERVAL * configTICK_RATE_HZ );
- if( pxSocket->u.xTCP.ucKeepRepCount )
+ xMax = ( ( TickType_t ) ipconfigTCP_KEEP_ALIVE_INTERVAL * ( TickType_t ) configTICK_RATE_HZ );
+ if( pxSocket->u.xTCP.ucKeepRepCount != ( uint8_t ) 0U )
{
- xMax = ( 3u * configTICK_RATE_HZ );
+ xMax = ( TickType_t ) ( 3U * configTICK_RATE_HZ );
}
if( xAge > xMax )
{
pxSocket->u.xTCP.xLastAliveTime = xTaskGetTickCount( );
- if( xTCPWindowLoggingLevel )
+ if( xTCPWindowLoggingLevel != 0 )
+ {
FreeRTOS_debug_printf( ( "keep-alive: %lxip:%u count %u\n",
pxSocket->u.xTCP.ulRemoteIP,
pxSocket->u.xTCP.usRemotePort,
pxSocket->u.xTCP.ucKeepRepCount ) );
+ }
pxSocket->u.xTCP.bits.bSendKeepAlive = pdTRUE_UNSIGNED;
- pxSocket->u.xTCP.usTimeout = ( ( uint16_t ) pdMS_TO_TICKS( 2500 ) );
+ pxSocket->u.xTCP.usTimeout = ( ( uint16_t ) pdMS_TO_TICKS( 2500U ) );
pxSocket->u.xTCP.ucKeepRepCount++;
}
}
@@ -1882,17 +1947,17 @@ int32_t lStreamPos;
( pxSocket->u.xTCP.bits.bWinChange != pdFALSE_UNSIGNED ) ||
( pxSocket->u.xTCP.bits.bSendKeepAlive != pdFALSE_UNSIGNED ) )
{
- pxTCPPacket->xTCPHeader.ucTCPFlags &= ( ( uint8_t ) ~ipTCP_FLAG_PSH );
- pxTCPPacket->xTCPHeader.ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
+ pxProtocolHeaders->xTCPHeader.ucTCPFlags &= ( ( uint8_t ) ~tcpTCP_FLAG_PSH );
+ pxProtocolHeaders->xTCPHeader.ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 ); /*_RB_ "2" needs comment. */
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ( uint8_t ) ipTCP_FLAG_ACK;
+ pxProtocolHeaders->xTCPHeader.ucTCPFlags |= ( uint8_t ) tcpTCP_FLAG_ACK;
- if( lDataLen != 0l )
+ if( lDataLen != 0L )
{
- pxTCPPacket->xTCPHeader.ucTCPFlags |= ( uint8_t ) ipTCP_FLAG_PSH;
+ pxProtocolHeaders->xTCPHeader.ucTCPFlags |= ( uint8_t ) tcpTCP_FLAG_PSH;
}
- lDataLen += ( int32_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
+ lDataLen += ipNUMERIC_CAST( int32_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
}
return lDataLen;
@@ -1906,16 +1971,16 @@ static TickType_t prvTCPNextTimeout ( FreeRTOS_Socket_t *pxSocket )
{
TickType_t ulDelayMs = ( TickType_t ) tcpMAXIMUM_TCP_WAKEUP_TIME_MS;
- if( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN )
+ if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN )
{
/* The socket is actively connecting to a peer. */
- if( pxSocket->u.xTCP.bits.bConnPrepared )
+ if( pxSocket->u.xTCP.bits.bConnPrepared != pdFALSE_UNSIGNED )
{
/* Ethernet address has been found, use progressive timeout for
active connect(). */
- if( pxSocket->u.xTCP.ucRepCount < 3u )
+ if( pxSocket->u.xTCP.ucRepCount < 3U )
{
- ulDelayMs = ( 3000UL << ( pxSocket->u.xTCP.ucRepCount - 1u ) );
+ ulDelayMs = ( 3000UL << ( pxSocket->u.xTCP.ucRepCount - 1U ) );
}
else
{
@@ -1931,13 +1996,13 @@ TickType_t ulDelayMs = ( TickType_t ) tcpMAXIMUM_TCP_WAKEUP_TIME_MS;
FreeRTOS_debug_printf( ( "Connect[%lxip:%u]: next timeout %u: %lu ms\n",
pxSocket->u.xTCP.ulRemoteIP, pxSocket->u.xTCP.usRemotePort,
pxSocket->u.xTCP.ucRepCount, ulDelayMs ) );
- pxSocket->u.xTCP.usTimeout = ( uint16_t )pdMS_TO_MIN_TICKS( ulDelayMs );
+ pxSocket->u.xTCP.usTimeout = ( uint16_t )ipMS_TO_MIN_TICKS( ulDelayMs );
}
- else if( pxSocket->u.xTCP.usTimeout == 0u )
+ else if( pxSocket->u.xTCP.usTimeout == 0U )
{
/* Let the sliding window mechanism decide what time-out is appropriate. */
BaseType_t xResult = xTCPWindowTxHasData( &pxSocket->u.xTCP.xTCPWindow, pxSocket->u.xTCP.ulWindowSize, &ulDelayMs );
- if( ulDelayMs == 0u )
+ if( ulDelayMs == 0U )
{
if( xResult != ( BaseType_t )0 )
{
@@ -1952,7 +2017,7 @@ TickType_t ulDelayMs = ( TickType_t ) tcpMAXIMUM_TCP_WAKEUP_TIME_MS;
{
/* ulDelayMs contains the time to wait before a re-transmission. */
}
- pxSocket->u.xTCP.usTimeout = ( uint16_t )pdMS_TO_MIN_TICKS( ulDelayMs );
+ pxSocket->u.xTCP.usTimeout = ( uint16_t ) ipMS_TO_MIN_TICKS( ulDelayMs );
}
else
{
@@ -1972,9 +2037,9 @@ int32_t lCount, lLength;
/* A txStream has been created already, see if the socket has new data for
the sliding window.
- uxStreamBufferMidSpace() returns the distance between rxHead and rxMid. It contains new
- Tx data which has not been passed to the sliding window yet. The oldest
- data not-yet-confirmed can be found at rxTail. */
+ uxStreamBufferMidSpace() returns the distance between rxHead and rxMid. It
+ contains new Tx data which has not been passed to the sliding window yet.
+ The oldest data not-yet-confirmed can be found at rxTail. */
lLength = ( int32_t ) uxStreamBufferMidSpace( pxSocket->u.xTCP.txStream );
if( lLength > 0 )
@@ -2006,18 +2071,20 @@ int32_t lCount, lLength;
* Before being called, it has been checked that both reception and transmission
* are complete.
*/
-static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
+static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
+/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
+TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
BaseType_t xSendLength = 0;
uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
- if( ( ucTCPFlags & ipTCP_FLAG_FIN ) != 0u )
+ if( ( ucTCPFlags & tcpTCP_FLAG_FIN ) != 0U )
{
- pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulFINSequenceNumber + 1u;
+ pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulFINSequenceNumber + 1U;
}
if( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED )
{
@@ -2028,7 +2095,7 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
else
{
/* We did send a FIN already, see if it's ACK'd. */
- if( ulAckNr == pxTCPWindow->tx.ulFINSequenceNumber + 1u )
+ if( ulAckNr == ( pxTCPWindow->tx.ulFINSequenceNumber + 1UL ) )
{
pxSocket->u.xTCP.bits.bFinAcked = pdTRUE_UNSIGNED;
}
@@ -2037,7 +2104,7 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
if( pxSocket->u.xTCP.bits.bFinAcked == pdFALSE_UNSIGNED )
{
pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->tx.ulFINSequenceNumber;
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK | ipTCP_FLAG_FIN;
+ pxTCPHeader->ucTCPFlags = ( uint8_t ) tcpTCP_FLAG_ACK | ( uint8_t ) tcpTCP_FLAG_FIN;
/* And wait for the final ACK. */
vTCPStateChange( pxSocket, eLAST_ACK );
@@ -2045,12 +2112,12 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
else
{
/* Our FIN has been ACK'd, the outgoing sequence number is now fixed. */
- pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->tx.ulFINSequenceNumber + 1u;
+ pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->tx.ulFINSequenceNumber + 1U;
if( pxSocket->u.xTCP.bits.bFinRecv == pdFALSE_UNSIGNED )
{
/* We have sent out a FIN but the peer hasn't replied with a FIN
yet. Do nothing for the moment. */
- pxTCPHeader->ucTCPFlags = 0u;
+ pxTCPHeader->ucTCPFlags = 0U;
}
else
{
@@ -2058,13 +2125,13 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
{
/* This is the third of the three-way hand shake: the last
ACK. */
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK;
+ pxTCPHeader->ucTCPFlags = tcpTCP_FLAG_ACK;
}
else
{
/* The other party started the closure, so we just wait for the
last ACK. */
- pxTCPHeader->ucTCPFlags = 0u;
+ pxTCPHeader->ucTCPFlags = 0U;
}
/* And wait for the user to close this socket. */
@@ -2074,9 +2141,9 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
pxTCPWindow->ulOurSequenceNumber = pxTCPWindow->tx.ulCurrentSequenceNumber;
- if( pxTCPHeader->ucTCPFlags != 0u )
+ if( pxTCPHeader->ucTCPFlags != 0U )
{
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength );
+ xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength );
}
pxTCPHeader->ucTCPOffset = ( uint8_t ) ( ( ipSIZE_OF_TCP_HEADER + pxTCPWindow->ucOptionLength ) << 2 );
@@ -2101,28 +2168,37 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
* The first thing that will be done is find the TCP payload data
* and check the length of this data.
*/
-static BaseType_t prvCheckRxData( NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData )
+static BaseType_t prvCheckRxData( const NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &( pxTCPPacket->xTCPHeader );
+/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
+const TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength;
+/* Map the buffer onto an IPHeader_t struct for easy access to fields. */
+const IPHeader_t *pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
+const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER;
+uint16_t usLength;
+
/* Determine the length and the offset of the user-data sent to this
node.
The size of the TCP header is given in a multiple of 4-byte words (single
byte, needs no ntoh() translation). A shift-right 2: is the same as
(offset >> 4) * 4. */
- lTCPHeaderLength = ( BaseType_t ) ( ( pxTCPHeader->ucTCPOffset & VALID_BITS_IN_TCP_OFFSET_BYTE ) >> 2 );
+ lTCPHeaderLength = ipNUMERIC_CAST( BaseType_t, ( pxTCPHeader->ucTCPOffset & tcpVALID_BITS_IN_TCP_OFFSET_BYTE ) >> 2 );
/* Let pucRecvData point to the first byte received. */
- *ppucRecvData = pxNetworkBuffer->pucEthernetBuffer + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + lTCPHeaderLength;
+ *ppucRecvData = &( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderLength + ( size_t ) lTCPHeaderLength ] );
/* Calculate lReceiveLength - the length of the TCP data received. This is
equal to the total packet length minus:
( LinkLayer length (14) + IP header length (20) + size of TCP header(20 +) ).*/
- lReceiveLength = ( ( int32_t ) pxNetworkBuffer->xDataLength ) - ( int32_t ) ipSIZE_OF_ETH_HEADER;
- lLength = ( int32_t )FreeRTOS_htons( pxTCPPacket->xIPHeader.usLength );
+ lReceiveLength = ipNUMERIC_CAST( int32_t, pxNetworkBuffer->xDataLength ) - ( int32_t ) ipSIZE_OF_ETH_HEADER;
+
+ usLength = FreeRTOS_htons( pxIPHeader->usLength );
+ lLength = ( int32_t ) usLength;
if( lReceiveLength > lLength )
{
@@ -2133,9 +2209,9 @@ int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength;
/* Subtract the size of the TCP and IP headers and the actual data size is
known. */
- if( lReceiveLength > ( lTCPHeaderLength + ( int32_t ) ipSIZE_OF_IPv4_HEADER ) )
+ if( lReceiveLength > ( lTCPHeaderLength + ( int32_t ) xIPHeaderLength ) )
{
- lReceiveLength -= ( lTCPHeaderLength + ( int32_t ) ipSIZE_OF_IPv4_HEADER );
+ lReceiveLength -= ( lTCPHeaderLength + ( int32_t ) xIPHeaderLength );
}
else
{
@@ -2148,7 +2224,7 @@ int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength;
pointer points to the sequence number of the octet following the urgent
data. This field is only be interpreted in segments with the URG control
bit set. */
- if( ( pxTCPHeader->ucTCPFlags & ipTCP_FLAG_URG ) != 0u )
+ if( ( pxTCPHeader->ucTCPFlags & tcpTCP_FLAG_URG ) != 0U )
{
/* Although we ignore the urgent data, we have to skip it. */
lUrgentLength = ( int32_t ) FreeRTOS_htons( pxTCPHeader->usUrgent );
@@ -2166,11 +2242,13 @@ int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength;
* The second thing is to do is check if the payload data may be accepted
* If so, they will be added to the reception queue.
*/
-static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, uint8_t *pucRecvData,
+static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, const uint8_t *pucRecvData,
NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
+/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
+const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
uint32_t ulSequenceNumber, ulSpace;
int32_t lOffset, lStored;
@@ -2178,16 +2256,16 @@ BaseType_t xResult = 0;
ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber );
- if( ( ulReceiveLength > 0u ) && ( pxSocket->u.xTCP.ucTCPState >= eSYN_RECEIVED ) )
+ if( ( ulReceiveLength > 0U ) && ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eSYN_RECEIVED ) )
{
/* See if way may accept the data contents and forward it to the socket
owner.
If it can't be "accept"ed it may have to be stored and send a selective
- ack (SACK) option to confirm it. In that case, xTCPWindowRxStore() will be
+ ack (SACK) option to confirm it. In that case, lTCPAddRxdata() will be
called later to store an out-of-order packet (in case lOffset is
negative). */
- if ( pxSocket->u.xTCP.rxStream )
+ if ( pxSocket->u.xTCP.rxStream != NULL )
{
ulSpace = ( uint32_t )uxStreamBufferGetSpace ( pxSocket->u.xTCP.rxStream );
}
@@ -2208,12 +2286,12 @@ BaseType_t xResult = 0;
if( lStored != ( int32_t ) ulReceiveLength )
{
- FreeRTOS_debug_printf( ( "lTCPAddRxdata: stored %ld / %lu bytes??\n", lStored, ulReceiveLength ) );
+ FreeRTOS_debug_printf( ( "lTCPAddRxdata: stored %ld / %lu bytes? ?\n", lStored, ulReceiveLength ) );
/* Received data could not be stored. The socket's flag
bMallocError has been set. The socket now has the status
eCLOSE_WAIT and a RST packet will be sent back. */
- prvTCPSendReset( pxNetworkBuffer );
+ ( void ) prvTCPSendReset( pxNetworkBuffer );
xResult = -1;
}
}
@@ -2225,9 +2303,9 @@ BaseType_t xResult = 0;
/* Now lTCPAddRxdata() will move the rxHead pointer forward
so data becomes available to the user immediately
In case the low-water mark is reached, bLowWater will be set. */
- if( ( xResult == 0 ) && ( pxTCPWindow->ulUserDataLength > 0 ) )
+ if( ( xResult == 0 ) && ( pxTCPWindow->ulUserDataLength > 0UL ) )
{
- lTCPAddRxdata( pxSocket, 0ul, NULL, pxTCPWindow->ulUserDataLength );
+ ( void ) lTCPAddRxdata( pxSocket, 0UL, NULL, pxTCPWindow->ulUserDataLength );
pxTCPWindow->ulUserDataLength = 0;
}
}
@@ -2235,7 +2313,7 @@ BaseType_t xResult = 0;
}
else
{
- pxTCPWindow->ucOptionLength = 0u;
+ pxTCPWindow->ucOptionLength = 0U;
}
return xResult;
@@ -2243,34 +2321,38 @@ BaseType_t xResult = 0;
/*-----------------------------------------------------------*/
/* Set the TCP options (if any) for the outgoing packet. */
-static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
+static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
+/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
+TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
+const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength;
- #if( ipconfigUSE_TCP_WIN == 1 )
- if( uxOptionsLength != 0u )
+#if( ipconfigUSE_TCP_WIN == 1 )
+ if( uxOptionsLength != 0U )
+ {
+ /* TCP options must be sent because a packet which is out-of-order
+ was received. */
+ if( xTCPWindowLoggingLevel >= 0 )
{
- /* TCP options must be sent because a packet which is out-of-order
- was received. */
- if( xTCPWindowLoggingLevel >= 0 )
- FreeRTOS_debug_printf( ( "SACK[%d,%d]: optlen %lu sending %lu - %lu\n",
- pxSocket->usLocalPort,
- pxSocket->u.xTCP.usRemotePort,
- uxOptionsLength,
- FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 1 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber,
- FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 2 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber ) );
- memcpy( pxTCPHeader->ucOptdata, pxTCPWindow->ulOptionsData, ( size_t ) uxOptionsLength );
-
- /* The header length divided by 4, goes into the higher nibble,
- effectively a shift-left 2. */
- pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
+ FreeRTOS_debug_printf( ( "SACK[%d,%d]: optlen %lu sending %lu - %lu\n",
+ pxSocket->usLocalPort,
+ pxSocket->u.xTCP.usRemotePort,
+ uxOptionsLength,
+ FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 1 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber,
+ FreeRTOS_ntohl( pxTCPWindow->ulOptionsData[ 2 ] ) - pxSocket->u.xTCP.xTCPWindow.rx.ulFirstSequenceNumber ) );
}
- else
- #endif /* ipconfigUSE_TCP_WIN */
- if( ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) && ( pxSocket->u.xTCP.bits.bMssChange != pdFALSE_UNSIGNED ) )
+ ( void ) memcpy( pxTCPHeader->ucOptdata, pxTCPWindow->ulOptionsData, ( size_t ) uxOptionsLength );
+
+ /* The header length divided by 4, goes into the higher nibble,
+ effectively a shift-left 2. */
+ pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
+ }
+ else
+#endif /* ipconfigUSE_TCP_WIN */
+ if( ( pxSocket->u.xTCP.ucTCPState >= ( EventBits_t ) eESTABLISHED ) && ( pxSocket->u.xTCP.bits.bMssChange != pdFALSE_UNSIGNED ) )
{
/* TCP options must be sent because the MSS has changed. */
pxSocket->u.xTCP.bits.bMssChange = pdFALSE_UNSIGNED;
@@ -2279,13 +2361,17 @@ UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength;
FreeRTOS_debug_printf( ( "MSS: sending %d\n", pxSocket->u.xTCP.usCurMSS ) );
}
- pxTCPHeader->ucOptdata[ 0 ] = TCP_OPT_MSS;
- pxTCPHeader->ucOptdata[ 1 ] = TCP_OPT_MSS_LEN;
+ pxTCPHeader->ucOptdata[ 0 ] = tcpTCP_OPT_MSS;
+ pxTCPHeader->ucOptdata[ 1 ] = tcpTCP_OPT_MSS_LEN;
pxTCPHeader->ucOptdata[ 2 ] = ( uint8_t ) ( ( pxSocket->u.xTCP.usCurMSS ) >> 8 );
- pxTCPHeader->ucOptdata[ 3 ] = ( uint8_t ) ( ( pxSocket->u.xTCP.usCurMSS ) & 0xffu );
- uxOptionsLength = 4u;
+ pxTCPHeader->ucOptdata[ 3 ] = ( uint8_t ) ( ( pxSocket->u.xTCP.usCurMSS ) & 0xffU );
+ uxOptionsLength = 4U;
pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
}
+ else
+ {
+ /* Nothing. */
+ }
return uxOptionsLength;
}
@@ -2297,33 +2383,42 @@ UBaseType_t uxOptionsLength = pxTCPWindow->ucOptionLength;
* Called from the states: eSYN_RECEIVED and eCONNECT_SYN
* If the flags received are correct, the socket will move to eESTABLISHED.
*/
-static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
+static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer,
uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
+/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
+TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber );
BaseType_t xSendLength = 0;
/* Either expect a ACK or a SYN+ACK. */
- uint16_t usExpect = ( uint16_t ) ipTCP_FLAG_ACK;
- if( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN )
+ uint8_t ucExpect = tcpTCP_FLAG_ACK;
+ if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN )
{
- usExpect |= ( uint16_t ) ipTCP_FLAG_SYN;
+ ucExpect |= tcpTCP_FLAG_SYN;
}
- if( ( ucTCPFlags & 0x17u ) != usExpect )
+ const uint8_t ucFlagsMask = tcpTCP_FLAG_ACK | tcpTCP_FLAG_RST | tcpTCP_FLAG_SYN | tcpTCP_FLAG_FIN;
+
+ if( ( ucTCPFlags & ucFlagsMask ) != ucExpect )
{
/* eSYN_RECEIVED: flags 0010 expected, not 0002. */
/* eSYN_RECEIVED: flags ACK expected, not SYN. */
FreeRTOS_debug_printf( ( "%s: flags %04X expected, not %04X\n",
- pxSocket->u.xTCP.ucTCPState == eSYN_RECEIVED ? "eSYN_RECEIVED" : "eCONNECT_SYN",
- usExpect, ucTCPFlags ) );
+ ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eSYN_RECEIVED ) ? "eSYN_RECEIVED" : "eCONNECT_SYN",
+ ucExpect, ucTCPFlags ) );
vTCPStateChange( pxSocket, eCLOSE_WAIT );
- pxTCPHeader->ucTCPFlags |= ipTCP_FLAG_RST;
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
+ /* Send RST with the expected sequence and ACK numbers,
+ otherwise the packet will be ignored. */
+ pxTCPWindow->ulOurSequenceNumber = FreeRTOS_htonl( pxTCPHeader->ulAckNr );
+ pxTCPWindow->rx.ulCurrentSequenceNumber = ulSequenceNumber;
+
+ pxTCPHeader->ucTCPFlags |= tcpTCP_FLAG_RST;
+ xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
}
else
@@ -2331,34 +2426,42 @@ BaseType_t xSendLength = 0;
pxTCPWindow->usPeerPortNumber = pxSocket->u.xTCP.usRemotePort;
pxTCPWindow->usOurPortNumber = pxSocket->usLocalPort;
- if( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN )
+ if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN )
{
- TCPPacket_t *pxLastTCPPacket = ( TCPPacket_t * ) ( pxSocket->u.xTCP.xPacket.u.ucLastPacket );
+ /* Map the Last packet onto the ProtocolHeader_t struct for easy access to the fields. */
+ ProtocolHeaders_t *pxLastHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
/* Clear the SYN flag in lastPacket. */
- pxLastTCPPacket->xTCPHeader.ucTCPFlags = ipTCP_FLAG_ACK;
+ pxLastHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_ACK;
+ pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_ACK;
- /* This socket was the one connecting actively so now perofmr the
+ /* This socket was the one connecting actively so now perform the
synchronisation. */
vTCPWindowInit( &pxSocket->u.xTCP.xTCPWindow,
ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber, ( uint32_t ) pxSocket->u.xTCP.usCurMSS );
- pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + 1u;
+ pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + 1U;
+ pxTCPWindow->rx.ulCurrentSequenceNumber = ulSequenceNumber + 1U;
pxTCPWindow->tx.ulCurrentSequenceNumber++; /* because we send a TCP_SYN [ | TCP_ACK ]; */
pxTCPWindow->ulNextTxSequenceNumber++;
}
- else if( ulReceiveLength == 0u )
+ else if( ulReceiveLength == 0U )
{
pxTCPWindow->rx.ulCurrentSequenceNumber = ulSequenceNumber;
}
+ else
+ {
+ /* Nothing. */
+ }
/* The SYN+ACK has been confirmed, increase the next sequence number by
1. */
- pxTCPWindow->ulOurSequenceNumber = pxTCPWindow->tx.ulFirstSequenceNumber + 1u;
+ pxTCPWindow->ulOurSequenceNumber = pxTCPWindow->tx.ulFirstSequenceNumber + 1U;
#if( ipconfigUSE_TCP_WIN == 1 )
{
FreeRTOS_debug_printf( ( "TCP: %s %d => %lxip:%d set ESTAB (scaling %u)\n",
- pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN ? "active" : "passive",
+ ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN ) ? "active" : "passive",
pxSocket->usLocalPort,
pxSocket->u.xTCP.ulRemoteIP,
pxSocket->u.xTCP.usRemotePort,
@@ -2366,10 +2469,10 @@ BaseType_t xSendLength = 0;
}
#endif /* ipconfigUSE_TCP_WIN */
- if( ( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN ) || ( ulReceiveLength != 0u ) )
+ if( ( pxSocket->u.xTCP.ucTCPState == ( EventBits_t ) eCONNECT_SYN ) || ( ulReceiveLength != 0UL ) )
{
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK;
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
+ pxTCPHeader->ucTCPFlags = tcpTCP_FLAG_ACK;
+ xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ( size_t ) ipSIZE_OF_TCP_HEADER + uxOptionsLength );
pxTCPHeader->ucTCPOffset = ( uint8_t ) ( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
}
#if( ipconfigUSE_TCP_WIN != 0 )
@@ -2403,45 +2506,49 @@ BaseType_t xSendLength = 0;
static BaseType_t prvHandleEstablished( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
+/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
+TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber ), ulCount;
BaseType_t xSendLength = 0, xMayClose = pdFALSE, bRxComplete, bTxDone;
int32_t lDistance, lSendResult;
+uint16_t usWindow;
/* Remember the window size the peer is advertising. */
- pxSocket->u.xTCP.ulWindowSize = FreeRTOS_ntohs( pxTCPHeader->usWindow );
+ usWindow = FreeRTOS_ntohs( pxTCPHeader->usWindow );
+ pxSocket->u.xTCP.ulWindowSize = ( uint32_t ) usWindow;
#if( ipconfigUSE_TCP_WIN != 0 )
{
pxSocket->u.xTCP.ulWindowSize =
( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor );
}
- #endif
+ #endif /* ipconfigUSE_TCP_WIN */
- if( ( ucTCPFlags & ( uint8_t ) ipTCP_FLAG_ACK ) != 0u )
+ if( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_ACK ) != 0U )
{
- ulCount = ulTCPWindowTxAck( pxTCPWindow, FreeRTOS_ntohl( pxTCPPacket->xTCPHeader.ulAckNr ) );
+ ulCount = ulTCPWindowTxAck( pxTCPWindow, FreeRTOS_ntohl( pxTCPHeader->ulAckNr ) );
/* ulTCPWindowTxAck() returns the number of bytes which have been acked,
starting at 'tx.ulCurrentSequenceNumber'. Advance the tail pointer in
txStream. */
- if( ( pxSocket->u.xTCP.txStream != NULL ) && ( ulCount > 0u ) )
+ if( ( pxSocket->u.xTCP.txStream != NULL ) && ( ulCount > 0U ) )
{
/* Just advancing the tail index, 'ulCount' bytes have been
confirmed, and because there is new space in the txStream, the
user/owner should be woken up. */
/* _HT_ : only in case the socket's waiting? */
- if( uxStreamBufferGet( pxSocket->u.xTCP.txStream, 0u, NULL, ( size_t ) ulCount, pdFALSE ) != 0u )
+ if( uxStreamBufferGet( pxSocket->u.xTCP.txStream, 0U, NULL, ( size_t ) ulCount, pdFALSE ) != 0U )
{
- pxSocket->xEventBits |= eSOCKET_SEND;
+ pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_SEND;
#if ipconfigSUPPORT_SELECT_FUNCTION == 1
{
- if( ( pxSocket->xSelectBits & eSELECT_WRITE ) != 0 )
+ if( ( pxSocket->xSelectBits & ( ( EventBits_t ) eSELECT_WRITE ) ) != 0U )
{
- pxSocket->xEventBits |= ( eSELECT_WRITE << SOCKET_EVENT_BIT_COUNT );
+ pxSocket->xEventBits |= ( ( EventBits_t ) eSELECT_WRITE ) << SOCKET_EVENT_BIT_COUNT;
}
}
#endif
@@ -2451,7 +2558,7 @@ int32_t lDistance, lSendResult;
{
if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleSent ) )
{
- pxSocket->u.xTCP.pxHandleSent( ( Socket_t )pxSocket, ulCount );
+ pxSocket->u.xTCP.pxHandleSent( ( Socket_t ) pxSocket, ulCount );
}
}
#endif /* ipconfigUSE_CALLBACKS == 1 */
@@ -2468,7 +2575,7 @@ int32_t lDistance, lSendResult;
pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber = pxTCPWindow->tx.ulCurrentSequenceNumber;
- if( ( pxSocket->u.xTCP.bits.bFinAccepted != pdFALSE_UNSIGNED ) || ( ( ucTCPFlags & ( uint8_t ) ipTCP_FLAG_FIN ) != 0u ) )
+ if( ( pxSocket->u.xTCP.bits.bFinAccepted != pdFALSE_UNSIGNED ) || ( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_FIN ) != 0U ) )
{
/* Peer is requesting to stop, see if we're really finished. */
xMayClose = pdTRUE;
@@ -2478,7 +2585,7 @@ int32_t lDistance, lSendResult;
{
/* xTCPWindowTxDone returns true when all Tx queues are empty. */
bRxComplete = xTCPWindowRxEmpty( pxTCPWindow );
- bTxDone = xTCPWindowTxDone( pxTCPWindow );
+ bTxDone = xTCPWindowTxDone( pxTCPWindow );
if( ( bRxComplete == 0 ) || ( bTxDone == 0 ) )
{
@@ -2491,7 +2598,7 @@ int32_t lDistance, lSendResult;
}
else
{
- lDistance = ( int32_t ) ( ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber );
+ lDistance = ipNUMERIC_CAST( int32_t, ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber );
if( lDistance > 1 )
{
@@ -2520,11 +2627,11 @@ int32_t lDistance, lSendResult;
if( xMayClose == pdFALSE )
{
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_ACK;
+ pxTCPHeader->ucTCPFlags = tcpTCP_FLAG_ACK;
- if( ulReceiveLength != 0u )
+ if( ulReceiveLength != 0U )
{
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
+ xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
/* TCP-offsett equals '( ( length / 4 ) << 4 )', resulting in a shift-left 2 */
pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
@@ -2539,7 +2646,7 @@ int32_t lDistance, lSendResult;
can not send-out both TCP options and also a full packet. Sending
options (SACK) is always more urgent than sending data, which can be
sent later. */
- if( uxOptionsLength == 0u )
+ if( uxOptionsLength == 0U )
{
/* prvTCPPrepareSend might allocate a bigger network buffer, if
necessary. */
@@ -2561,13 +2668,16 @@ int32_t lDistance, lSendResult;
* checked if it would better be postponed for efficiency.
*/
static BaseType_t prvSendData( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer,
- uint32_t ulReceiveLength, BaseType_t xSendLength )
+ uint32_t ulReceiveLength, BaseType_t xByteCount )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &pxTCPPacket->xTCPHeader;
-TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
+/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) );
+const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
+const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
/* Find out what window size we may advertised. */
int32_t lRxSpace;
+BaseType_t xSendLength = xByteCount;
#if( ipconfigUSE_TCP_WIN == 1 )
#if( ipconfigTCP_ACK_EARLIER_PACKET == 0 )
const int32_t lMinLength = 0;
@@ -2578,7 +2688,7 @@ int32_t lRxSpace;
/* Set the time-out field, so that we'll be called by the IP-task in case no
next message will be received. */
- lRxSpace = (int32_t)( pxSocket->u.xTCP.ulHighestRxAllowed - pxTCPWindow->rx.ulCurrentSequenceNumber );
+ lRxSpace = ipNUMERIC_CAST( int32_t, pxSocket->u.xTCP.ulHighestRxAllowed - pxTCPWindow->rx.ulCurrentSequenceNumber );
#if ipconfigUSE_TCP_WIN == 1
{
@@ -2590,17 +2700,18 @@ int32_t lRxSpace;
/* In case we're receiving data continuously, we might postpone sending
an ACK to gain performance. */
- if( ( ulReceiveLength > 0 ) && /* Data was sent to this socket. */
+ /* lint e9007 is OK because 'uxIPHeaderSizeSocket()' has no side-effects. */
+ if( ( ulReceiveLength > 0U ) && /* Data was sent to this socket. */
( lRxSpace >= lMinLength ) && /* There is Rx space for more data. */
( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED ) && /* Not in a closure phase. */
- ( xSendLength == ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) ) && /* No Tx data or options to be sent. */
- ( pxSocket->u.xTCP.ucTCPState == eESTABLISHED ) && /* Connection established. */
- ( pxTCPHeader->ucTCPFlags == ipTCP_FLAG_ACK ) ) /* There are no other flags than an ACK. */
+ ( xSendLength == ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER ) ) && /* No Tx data or options to be sent. */
+ ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eESTABLISHED ) && /* Connection established. */
+ ( pxTCPHeader->ucTCPFlags == tcpTCP_FLAG_ACK ) ) /* There are no other flags than an ACK. */
{
if( pxSocket->u.xTCP.pxAckMessage != *ppxNetworkBuffer )
{
/* There was still a delayed in queue, delete it. */
- if( pxSocket->u.xTCP.pxAckMessage != 0 )
+ if( pxSocket->u.xTCP.pxAckMessage != NULL )
{
vReleaseNetworkBufferAndDescriptor( pxSocket->u.xTCP.pxAckMessage );
}
@@ -2608,19 +2719,19 @@ int32_t lRxSpace;
pxSocket->u.xTCP.pxAckMessage = *ppxNetworkBuffer;
}
if( ( ulReceiveLength < ( uint32_t ) pxSocket->u.xTCP.usCurMSS ) || /* Received a small message. */
- ( lRxSpace < ( int32_t ) ( 2U * pxSocket->u.xTCP.usCurMSS ) ) ) /* There are less than 2 x MSS space in the Rx buffer. */
+ ( lRxSpace < ipNUMERIC_CAST( int32_t, 2U * pxSocket->u.xTCP.usCurMSS ) ) ) /* There are less than 2 x MSS space in the Rx buffer. */
{
- pxSocket->u.xTCP.usTimeout = ( uint16_t ) pdMS_TO_MIN_TICKS( DELAYED_ACK_SHORT_DELAY_MS );
+ pxSocket->u.xTCP.usTimeout = ( uint16_t ) tcpDELAYED_ACK_SHORT_DELAY_MS;
}
else
{
/* Normally a delayed ACK should wait 200 ms for a next incoming
packet. Only wait 20 ms here to gain performance. A slow ACK
for full-size message. */
- pxSocket->u.xTCP.usTimeout = ( uint16_t ) pdMS_TO_MIN_TICKS( DELAYED_ACK_LONGER_DELAY_MS );
+ pxSocket->u.xTCP.usTimeout = ( uint16_t ) ipMS_TO_MIN_TICKS( tcpDELAYED_ACK_LONGER_DELAY_MS );
}
- if( ( xTCPWindowLoggingLevel > 1 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE ) )
+ if( ( xTCPWindowLoggingLevel > 1 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) ) )
{
FreeRTOS_debug_printf( ( "Send[%u->%u] del ACK %lu SEQ %lu (len %lu) tmout %u d %lu\n",
pxSocket->usLocalPort,
@@ -2645,6 +2756,10 @@ int32_t lRxSpace;
pxSocket->u.xTCP.pxAckMessage = NULL;
}
+ else
+ {
+ /* The ack will not be postponed, and there was no stored ack ( in 'pxAckMessage' ). */
+ }
}
#else
{
@@ -2657,7 +2772,7 @@ int32_t lRxSpace;
if( xSendLength != 0 )
{
- if( ( xTCPWindowLoggingLevel > 1 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE ) )
+ if( ( xTCPWindowLoggingLevel > 1 ) && ( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) ) )
{
FreeRTOS_debug_printf( ( "Send[%u->%u] imm ACK %lu SEQ %lu (len %lu)\n",
pxSocket->usLocalPort,
@@ -2700,8 +2815,10 @@ int32_t lRxSpace;
*/
static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer )
{
-TCPPacket_t *pxTCPPacket = ( TCPPacket_t * ) ( (*ppxNetworkBuffer)->pucEthernetBuffer );
-TCPHeader_t *pxTCPHeader = &( pxTCPPacket->xTCPHeader );
+/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
+ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ &( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) );
+TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
BaseType_t xSendLength = 0;
uint32_t ulReceiveLength; /* Number of bytes contained in the TCP message. */
uint8_t *pucRecvData;
@@ -2712,7 +2829,7 @@ uint32_t ulSequenceNumber = FreeRTOS_ntohl (pxTCPHeader->ulSequenceNumber);
1. in the SYN phase, we shall communicate the MSS
2. in case of a SACK, Selective ACK, ack a segment which comes in
out-of-order. */
-UBaseType_t uxOptionsLength = 0u;
+UBaseType_t uxOptionsLength = 0U;
uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
@@ -2720,9 +2837,9 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
pucRecvData will point to the first byte of the TCP payload. */
ulReceiveLength = ( uint32_t ) prvCheckRxData( *ppxNetworkBuffer, &pucRecvData );
- if( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED )
+ if( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eESTABLISHED )
{
- if ( pxTCPWindow->rx.ulCurrentSequenceNumber == ulSequenceNumber + 1u )
+ if ( pxTCPWindow->rx.ulCurrentSequenceNumber == ( ulSequenceNumber + 1UL ) )
{
/* This is most probably a keep-alive message from peer. Setting
'bWinChange' doesn't cause a window-size-change, the flag is used
@@ -2733,7 +2850,7 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
/* Keep track of the highest sequence number that might be expected within
this connection. */
- if( ( ( int32_t ) ( ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulHighestSequenceNumber ) ) > 0 )
+ if( ( ipNUMERIC_CAST( int32_t, ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulHighestSequenceNumber ) ) > 0L )
{
pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + ulReceiveLength;
}
@@ -2747,7 +2864,7 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
{
uxOptionsLength = prvSetOptions( pxSocket, *ppxNetworkBuffer );
- if( ( pxSocket->u.xTCP.ucTCPState == eSYN_RECEIVED ) && ( ( ucTCPFlags & ipTCP_FLAG_CTRL ) == ipTCP_FLAG_SYN ) )
+ if( ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eSYN_RECEIVED ) && ( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_CTRL ) == ( uint8_t ) tcpTCP_FLAG_SYN ) )
{
FreeRTOS_debug_printf( ( "eSYN_RECEIVED: ACK expected, not SYN: peer missed our SYN+ACK\n" ) );
@@ -2758,7 +2875,7 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
vTCPStateChange( pxSocket, eSYN_FIRST );
}
- if( ( ( ucTCPFlags & ipTCP_FLAG_FIN ) != 0u ) && ( pxSocket->u.xTCP.bits.bFinRecv == pdFALSE_UNSIGNED ) )
+ if( ( ( ucTCPFlags & tcpTCP_FLAG_FIN ) != 0U ) && ( pxSocket->u.xTCP.bits.bFinRecv == pdFALSE_UNSIGNED ) )
{
/* It's the first time a FIN has been received, remember its
sequence number. */
@@ -2773,7 +2890,7 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
}
}
- switch (pxSocket->u.xTCP.ucTCPState)
+ switch( ipNUMERIC_CAST( eIPTCPState_t, pxSocket->u.xTCP.ucTCPState ) )
{
case eCLOSED: /* (server + client) no connection state at all. */
/* Nothing to do for a closed socket, except waiting for the
@@ -2792,10 +2909,10 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
/* A new socket has been created, reply with a SYN+ACK.
Acknowledge with seq+1 because the SYN is seen as pseudo data
with len = 1. */
- uxOptionsLength = prvSetSynAckOptions( pxSocket, pxTCPPacket );
- pxTCPHeader->ucTCPFlags = ipTCP_FLAG_SYN | ipTCP_FLAG_ACK;
+ uxOptionsLength = prvSetSynAckOptions( pxSocket, pxTCPHeader );
+ pxTCPHeader->ucTCPFlags = ( uint8_t ) tcpTCP_FLAG_SYN | ( uint8_t ) tcpTCP_FLAG_ACK;
- xSendLength = ( BaseType_t ) ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
+ xSendLength = ipNUMERIC_CAST( BaseType_t, uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength );
/* Set the TCP offset field: ipSIZE_OF_TCP_HEADER equals 20 and
uxOptionsLength is a multiple of 4. The complete expression is:
@@ -2803,8 +2920,10 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
pxTCPHeader->ucTCPOffset = ( uint8_t )( ( ipSIZE_OF_TCP_HEADER + uxOptionsLength ) << 2 );
vTCPStateChange( pxSocket, eSYN_RECEIVED );
- pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + 1u;
- pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->ulNextTxSequenceNumber = pxTCPWindow->tx.ulFirstSequenceNumber + 1u; /* because we send a TCP_SYN. */
+ pxTCPWindow->rx.ulHighestSequenceNumber = ulSequenceNumber + 1UL;
+ pxTCPWindow->rx.ulCurrentSequenceNumber = ulSequenceNumber + 1UL;
+ pxTCPWindow->ulNextTxSequenceNumber = pxTCPWindow->tx.ulFirstSequenceNumber + 1UL;
+ pxTCPWindow->tx.ulCurrentSequenceNumber = pxTCPWindow->tx.ulFirstSequenceNumber + 1UL; /* because we send a TCP_SYN. */
}
break;
@@ -2813,7 +2932,7 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
/* Fall through */
case eSYN_RECEIVED: /* (server) we've had a SYN, replied with SYN+SCK
expect a ACK and do nothing. */
- xSendLength = prvHandleSynReceived( pxSocket, ppxNetworkBuffer, ulReceiveLength, uxOptionsLength );
+ xSendLength = prvHandleSynReceived( pxSocket, *( ppxNetworkBuffer ), ulReceiveLength, uxOptionsLength );
break;
case eESTABLISHED: /* (server + client) an open connection, data
@@ -2858,6 +2977,7 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
'bFinSent', 'bFinRecv', and 'bFinAcked'. */
break;
default:
+ /* No more known states. */
break;
}
}
@@ -2872,40 +2992,41 @@ TCPWindow_t *pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
/*-----------------------------------------------------------*/
static BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t *pxNetworkBuffer,
- uint8_t ucTCPFlags )
+ uint8_t ucTCPFlags )
{
-#if( ipconfigIGNORE_UNKNOWN_PACKETS == 0 )
- {
- TCPPacket_t *pxTCPPacket = ( TCPPacket_t * )( pxNetworkBuffer->pucEthernetBuffer );
- const BaseType_t xSendLength = ( BaseType_t )
- ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER + 0u ); /* Plus 0 options. */
+#if( ipconfigIGNORE_UNKNOWN_PACKETS == 1 )
+ /* Configured to ignore unknown packets just suppress a compiler warning. */
+ ( void ) pxNetworkBuffer;
+ ( void ) ucTCPFlags;
+#else
+ {
+ /* Map the ethernet buffer onto the TCPPacket_t struct for easy access to the fields. */
+ TCPPacket_t *pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ const uint32_t ulSendLength = ( uint32_t )
+ ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */
- pxTCPPacket->xTCPHeader.ucTCPFlags = ucTCPFlags;
- pxTCPPacket->xTCPHeader.ucTCPOffset = ( ipSIZE_OF_TCP_HEADER + 0u ) << 2;
+ pxTCPPacket->xTCPHeader.ucTCPFlags = ucTCPFlags;
+ pxTCPPacket->xTCPHeader.ucTCPOffset = ( ipSIZE_OF_TCP_HEADER ) << 2;
- prvTCPReturnPacket( NULL, pxNetworkBuffer, ( uint32_t )xSendLength, pdFALSE );
- }
+ prvTCPReturnPacket( NULL, pxNetworkBuffer, ulSendLength, pdFALSE );
+ }
#endif /* !ipconfigIGNORE_UNKNOWN_PACKETS */
- /* Remove compiler warnings if ipconfigIGNORE_UNKNOWN_PACKETS == 1. */
- ( void )pxNetworkBuffer;
- ( void )ucTCPFlags;
-
- /* The packet was not consumed. */
- return pdFAIL;
+ /* The packet was not consumed. */
+ return pdFAIL;
}
/*-----------------------------------------------------------*/
static BaseType_t prvTCPSendChallengeAck( NetworkBufferDescriptor_t *pxNetworkBuffer )
{
- return prvTCPSendSpecialPacketHelper( pxNetworkBuffer, ipTCP_FLAG_ACK );
+ return prvTCPSendSpecialPacketHelper( pxNetworkBuffer, tcpTCP_FLAG_ACK );
}
/*-----------------------------------------------------------*/
static BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t *pxNetworkBuffer )
{
- return prvTCPSendSpecialPacketHelper( pxNetworkBuffer,
- ipTCP_FLAG_ACK | ipTCP_FLAG_RST );
+ return prvTCPSendSpecialPacketHelper( pxNetworkBuffer,
+ ( uint8_t ) tcpTCP_FLAG_ACK | ( uint8_t ) tcpTCP_FLAG_RST );
}
/*-----------------------------------------------------------*/
@@ -2913,16 +3034,17 @@ static void prvSocketSetMSS( FreeRTOS_Socket_t *pxSocket )
{
uint32_t ulMSS = ipconfigTCP_MSS;
- if( ( ( FreeRTOS_ntohl( pxSocket->u.xTCP.ulRemoteIP ) ^ *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) != 0ul )
+ if( ( ( FreeRTOS_ntohl( pxSocket->u.xTCP.ulRemoteIP ) ^ *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) != 0UL )
{
/* Data for this peer will pass through a router, and maybe through
the internet. Limit the MSS to 1400 bytes or less. */
- ulMSS = FreeRTOS_min_uint32( ( uint32_t ) REDUCED_MSS_THROUGH_INTERNET, ulMSS );
+ ulMSS = FreeRTOS_min_uint32( ( uint32_t ) tcpREDUCED_MSS_THROUGH_INTERNET, ulMSS );
}
FreeRTOS_debug_printf( ( "prvSocketSetMSS: %lu bytes for %lxip:%u\n", ulMSS, pxSocket->u.xTCP.ulRemoteIP, pxSocket->u.xTCP.usRemotePort ) );
- pxSocket->u.xTCP.usInitMSS = pxSocket->u.xTCP.usCurMSS = ( uint16_t ) ulMSS;
+ pxSocket->u.xTCP.usInitMSS = ( uint16_t ) ulMSS;
+ pxSocket->u.xTCP.usCurMSS = ( uint16_t ) ulMSS;
}
/*-----------------------------------------------------------*/
@@ -2937,215 +3059,235 @@ uint32_t ulMSS = ipconfigTCP_MSS;
* prvTCPReturnPacket() // Prepare for returning
* xNetworkInterfaceOutput() // Sends data to the NIC
*/
-BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t *pxNetworkBuffer )
+BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t *pxDescriptor )
{
+/* Function might modify the parameter. */
+NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor;
+
+/* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */
+const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
FreeRTOS_Socket_t *pxSocket;
-TCPPacket_t * pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
-uint16_t ucTCPFlags;
+uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags;
uint32_t ulLocalIP;
-uint16_t xLocalPort;
+uint16_t xLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort );
+uint16_t xRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort );
uint32_t ulRemoteIP;
-uint16_t xRemotePort;
-uint32_t ulSequenceNumber;
-uint32_t ulAckNumber;
+uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber );
+uint32_t ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr );;
BaseType_t xResult = pdPASS;
-configASSERT(pxNetworkBuffer);
-configASSERT(pxNetworkBuffer->pucEthernetBuffer);
+configASSERT( pxNetworkBuffer != NULL );
+configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );
+const IPHeader_t *pxIPHeader;
/* Check for a minimum packet size. */
- if( pxNetworkBuffer->xDataLength >= ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) )
+ if( pxNetworkBuffer->xDataLength < ( ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) + ipSIZE_OF_TCP_HEADER ) )
{
- ucTCPFlags = pxTCPPacket->xTCPHeader.ucTCPFlags;
- ulLocalIP = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulDestinationIPAddress );
- xLocalPort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usDestinationPort );
- ulRemoteIP = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress );
- xRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort );
- ulSequenceNumber = FreeRTOS_ntohl( pxTCPPacket->xTCPHeader.ulSequenceNumber );
- ulAckNumber = FreeRTOS_ntohl( pxTCPPacket->xTCPHeader.ulAckNr );
-
- /* Find the destination socket, and if not found: return a socket listing to
- the destination PORT. */
- pxSocket = ( FreeRTOS_Socket_t * )pxTCPSocketLookup( ulLocalIP, xLocalPort, ulRemoteIP, xRemotePort );
+ xResult = pdFAIL;
}
else
{
- return pdFAIL;
- }
-
- if( ( pxSocket == NULL ) || ( prvTCPSocketIsActive( ( UBaseType_t ) pxSocket->u.xTCP.ucTCPState ) == pdFALSE ) )
- {
- /* A TCP messages is received but either there is no socket with the
- given port number or the there is a socket, but it is in one of these
- non-active states: eCLOSED, eCLOSE_WAIT, eFIN_WAIT_2, eCLOSING, or
- eTIME_WAIT. */
+ /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */
+ pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
+ ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress );
+ ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress );
- FreeRTOS_debug_printf( ( "TCP: No active socket on port %d (%lxip:%d)\n", xLocalPort, ulRemoteIP, xRemotePort ) );
+ /* Find the destination socket, and if not found: return a socket listing to
+ the destination PORT. */
+ pxSocket = ( FreeRTOS_Socket_t * ) pxTCPSocketLookup( ulLocalIP, xLocalPort, ulRemoteIP, xRemotePort );
- /* Send a RST to all packets that can not be handled. As a result
- the other party will get a ECONN error. There are two exceptions:
- 1) A packet that already has the RST flag set.
- 2) A packet that only has the ACK flag set.
- A packet with only the ACK flag set might be the last ACK in
- a three-way hand-shake that closes a connection. */
- if( ( ( ucTCPFlags & ipTCP_FLAG_CTRL ) != ipTCP_FLAG_ACK ) &&
- ( ( ucTCPFlags & ipTCP_FLAG_RST ) == 0u ) )
+ if( ( pxSocket == NULL ) || ( prvTCPSocketIsActive( ipNUMERIC_CAST( eIPTCPState_t, pxSocket->u.xTCP.ucTCPState ) ) == pdFALSE ) )
{
- prvTCPSendReset( pxNetworkBuffer );
- }
+ /* A TCP messages is received but either there is no socket with the
+ given port number or the there is a socket, but it is in one of these
+ non-active states: eCLOSED, eCLOSE_WAIT, eFIN_WAIT_2, eCLOSING, or
+ eTIME_WAIT. */
- /* The packet can't be handled. */
- xResult = pdFAIL;
- }
- else
- {
- pxSocket->u.xTCP.ucRepCount = 0u;
+ FreeRTOS_debug_printf( ( "TCP: No active socket on port %d (%lxip:%d)\n", xLocalPort, ulRemoteIP, xRemotePort ) );
- if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN )
+ /* Send a RST to all packets that can not be handled. As a result
+ the other party will get a ECONN error. There are two exceptions:
+ 1) A packet that already has the RST flag set.
+ 2) A packet that only has the ACK flag set.
+ A packet with only the ACK flag set might be the last ACK in
+ a three-way hand-shake that closes a connection. */
+ if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_ACK ) &&
+ ( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U ) )
+ {
+ ( void ) prvTCPSendReset( pxNetworkBuffer );
+ }
+
+ /* The packet can't be handled. */
+ xResult = pdFAIL;
+ }
+ else
{
- /* The matching socket is in a listening state. Test if the peer
- has set the SYN flag. */
- if( ( ucTCPFlags & ipTCP_FLAG_CTRL ) != ipTCP_FLAG_SYN )
+ pxSocket->u.xTCP.ucRepCount = 0U;
+
+ if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eTCP_LISTEN )
{
- /* What happens: maybe after a reboot, a client doesn't know the
- connection had gone. Send a RST in order to get a new connect
- request. */
- #if( ipconfigHAS_DEBUG_PRINTF == 1 )
+ /* The matching socket is in a listening state. Test if the peer
+ has set the SYN flag. */
+ if( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_SYN )
{
- FreeRTOS_debug_printf( ( "TCP: Server can't handle flags: %s from %lxip:%u to port %u\n",
- prvTCPFlagMeaning( ( UBaseType_t ) ucTCPFlags ), ulRemoteIP, xRemotePort, xLocalPort ) );
- }
- #endif /* ipconfigHAS_DEBUG_PRINTF */
+ /* What happens: maybe after a reboot, a client doesn't know the
+ connection had gone. Send a RST in order to get a new connect
+ request. */
+ #if( ipconfigHAS_DEBUG_PRINTF == 1 )
+ {
+ FreeRTOS_debug_printf( ( "TCP: Server can't handle flags: %s from %lxip:%u to port %u\n",
+ prvTCPFlagMeaning( ( UBaseType_t ) ucTCPFlags ), ulRemoteIP, xRemotePort, xLocalPort ) );
+ }
+ #endif /* ipconfigHAS_DEBUG_PRINTF */
- if( ( ucTCPFlags & ipTCP_FLAG_RST ) == 0u )
+ if( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U )
+ {
+ ( void ) prvTCPSendReset( pxNetworkBuffer );
+ }
+ xResult = pdFAIL;
+ }
+ else
{
- prvTCPSendReset( pxNetworkBuffer );
+ /* prvHandleListen() will either return a newly created socket
+ (if bReuseSocket is false), otherwise it returns the current
+ socket which will later get connected. */
+ pxSocket = prvHandleListen( pxSocket, pxNetworkBuffer );
+
+ if( pxSocket == NULL )
+ {
+ xResult = pdFAIL;
+ }
}
- xResult = pdFAIL;
- }
+ } /* if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN ). */
else
{
- /* prvHandleListen() will either return a newly created socket
- (if bReuseSocket is false), otherwise it returns the current
- socket which will later get connected. */
- pxSocket = prvHandleListen( pxSocket, pxNetworkBuffer );
+ /* This is not a socket in listening mode. Check for the RST
+ flag. */
+ if( ( ucTCPFlags & tcpTCP_FLAG_RST ) != 0U )
+ {
+ FreeRTOS_debug_printf( ( "TCP: RST received from %lxip:%u for %u\n", ulRemoteIP, xRemotePort, xLocalPort ) );
+
+ /* Implement https://tools.ietf.org/html/rfc5961#section-3.2. */
+ if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN )
+ {
+ /* Per the above RFC, "In the SYN-SENT state ... the RST is
+ acceptable if the ACK field acknowledges the SYN." */
+ if( ulAckNumber == ( pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber + 1UL ) )
+ {
+ vTCPStateChange( pxSocket, eCLOSED );
+ }
+ }
+ else
+ {
+ /* Check whether the packet matches the next expected sequence number. */
+ if( ulSequenceNumber == pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber )
+ {
+ vTCPStateChange( pxSocket, eCLOSED );
+ }
+ /* Otherwise, check whether the packet is within the receive window. */
+ else if( ( ulSequenceNumber > pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) &&
+ ( ulSequenceNumber < ( pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber +
+ pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength ) ) )
+ {
+ /* Send a challenge ACK. */
+ ( void ) prvTCPSendChallengeAck( pxNetworkBuffer );
+ }
+ else
+ {
+ /* Nothing. */
+ }
+ }
- if( pxSocket == NULL )
+ /* Otherwise, do nothing. In any case, the packet cannot be handled. */
+ xResult = pdFAIL;
+ }
+ else if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) == tcpTCP_FLAG_SYN ) && ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eESTABLISHED ) )
{
+ /* SYN flag while this socket is already connected. */
+ FreeRTOS_debug_printf( ( "TCP: SYN unexpected from %lxip:%u\n", ulRemoteIP, xRemotePort ) );
+
+ /* The packet cannot be handled. */
xResult = pdFAIL;
}
- }
- } /* if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN ). */
- else
- {
- /* This is not a socket in listening mode. Check for the RST
- flag. */
- if( ( ucTCPFlags & ipTCP_FLAG_RST ) != 0u )
- {
- FreeRTOS_debug_printf( ( "TCP: RST received from %lxip:%u for %u\n", ulRemoteIP, xRemotePort, xLocalPort ) );
-
- /* Implement https://tools.ietf.org/html/rfc5961#section-3.2. */
- if( pxSocket->u.xTCP.ucTCPState == eCONNECT_SYN )
- {
- /* Per the above RFC, "In the SYN-SENT state ... the RST is
- acceptable if the ACK field acknowledges the SYN." */
- if( ulAckNumber == pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber + 1 )
- {
- vTCPStateChange( pxSocket, eCLOSED );
- }
- }
- else
- {
- /* Check whether the packet matches the next expected sequence number. */
- if( ulSequenceNumber == pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber )
- {
- vTCPStateChange( pxSocket, eCLOSED );
- }
- /* Otherwise, check whether the packet is within the receive window. */
- else if( ulSequenceNumber > pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber &&
- ulSequenceNumber < ( pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber +
- pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength ) )
- {
- /* Send a challenge ACK. */
- prvTCPSendChallengeAck( pxNetworkBuffer );
- }
- }
-
- /* Otherwise, do nothing. In any case, the packet cannot be handled. */
- xResult = pdFAIL;
- }
- else if( ( ( ucTCPFlags & ipTCP_FLAG_CTRL ) == ipTCP_FLAG_SYN ) && ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) )
- {
- /* SYN flag while this socket is already connected. */
- FreeRTOS_debug_printf( ( "TCP: SYN unexpected from %lxip:%u\n", ulRemoteIP, xRemotePort ) );
-
- /* The packet cannot be handled. */
- xResult = pdFAIL;
- }
- else
- {
- /* Update the copy of the TCP header only (skipping eth and IP
- headers). It might be used later on, whenever data must be sent
- to the peer. */
- const BaseType_t lOffset = ( BaseType_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER );
- memcpy( pxSocket->u.xTCP.xPacket.u.ucLastPacket + lOffset, pxNetworkBuffer->pucEthernetBuffer + lOffset, ipSIZE_OF_TCP_HEADER );
+ else
+ {
+ /* Update the copy of the TCP header only (skipping eth and IP
+ headers). It might be used later on, whenever data must be sent
+ to the peer. */
+ const size_t lOffset = ipNUMERIC_CAST( size_t, ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) );
+ ( void ) memcpy( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ lOffset ] ),
+ &( pxNetworkBuffer->pucEthernetBuffer[ lOffset ] ),
+ ipSIZE_OF_TCP_HEADER );
+ }
}
}
- }
- if( xResult != pdFAIL )
- {
- /* Touch the alive timers because we received a message for this
- socket. */
- prvTCPTouchSocket( pxSocket );
-
- /* Parse the TCP option(s), if present. */
- /* _HT_ : if we're in the SYN phase, and peer does not send a MSS option,
- then we MUST assume an MSS size of 536 bytes for backward compatibility. */
-
- /* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as
- the number 5 (words) in the higher niblle of the TCP-offset byte. */
- if( ( pxTCPPacket->xTCPHeader.ucTCPOffset & TCP_OFFSET_LENGTH_BITS ) > TCP_OFFSET_STANDARD_LENGTH )
+ if( xResult != pdFAIL )
{
- prvCheckOptions( pxSocket, pxNetworkBuffer );
- }
+ uint16_t usWindow;
+ /* pxSocket is not NULL when xResult != pdFAIL. */
+ configASSERT( pxSocket != NULL );
+ /* Touch the alive timers because we received a message for this
+ socket. */
+ prvTCPTouchSocket( pxSocket );
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- pxSocket->u.xTCP.ulWindowSize = FreeRTOS_ntohs( pxTCPPacket->xTCPHeader.usWindow );
- pxSocket->u.xTCP.ulWindowSize =
- ( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor );
- }
- #endif
+ /* Parse the TCP option(s), if present. */
+ /* _HT_ : if we're in the SYN phase, and peer does not send a MSS option,
+ then we MUST assume an MSS size of 536 bytes for backward compatibility. */
- /* In prvTCPHandleState() the incoming messages will be handled
- depending on the current state of the connection. */
- if( prvTCPHandleState( pxSocket, &pxNetworkBuffer ) > 0 )
- {
- /* prvTCPHandleState() has sent a message, see if there are more to
- be transmitted. */
+ /* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as
+ the number 5 (words) in the higher nibble of the TCP-offset byte. */
+ if( ( pxProtocolHeaders->xTCPHeader.ucTCPOffset & tcpTCP_OFFSET_LENGTH_BITS ) > tcpTCP_OFFSET_STANDARD_LENGTH )
+ {
+ prvCheckOptions( pxSocket, pxNetworkBuffer );
+ }
+
+ usWindow = FreeRTOS_ntohs( pxProtocolHeaders->xTCPHeader.usWindow );
+ pxSocket->u.xTCP.ulWindowSize = (uint32_t ) usWindow;
#if( ipconfigUSE_TCP_WIN == 1 )
{
- prvTCPSendRepeated( pxSocket, &pxNetworkBuffer );
+ /* rfc1323 : The Window field in a SYN (i.e., a <SYN> or <SYN,ACK>)
+ segment itself is never scaled. */
+ if( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_SYN ) == 0U )
+ {
+ pxSocket->u.xTCP.ulWindowSize =
+ ( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor );
+ }
}
#endif /* ipconfigUSE_TCP_WIN */
- }
- if( pxNetworkBuffer != NULL )
- {
- /* We must check if the buffer is unequal to NULL, because the
- socket might keep a reference to it in case a delayed ACK must be
- sent. */
- vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
- pxNetworkBuffer = NULL;
- }
+ /* In prvTCPHandleState() the incoming messages will be handled
+ depending on the current state of the connection. */
+ if( prvTCPHandleState( pxSocket, &pxNetworkBuffer ) > 0 )
+ {
+ /* prvTCPHandleState() has sent a message, see if there are more to
+ be transmitted. */
+ #if( ipconfigUSE_TCP_WIN == 1 )
+ {
+ ( void ) prvTCPSendRepeated( pxSocket, &pxNetworkBuffer );
+ }
+ #endif /* ipconfigUSE_TCP_WIN */
+ }
- /* And finally, calculate when this socket wants to be woken up. */
- prvTCPNextTimeout ( pxSocket );
- /* Return pdPASS to tell that the network buffer is 'consumed'. */
- xResult = pdPASS;
- }
+ if( pxNetworkBuffer != NULL )
+ {
+ /* We must check if the buffer is unequal to NULL, because the
+ socket might keep a reference to it in case a delayed ACK must be
+ sent. */
+ vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
+ #ifndef _lint
+ /* Clear pointers that are freed. */
+ pxNetworkBuffer = NULL;
+ #endif
+ }
+ /* And finally, calculate when this socket wants to be woken up. */
+ ( void ) prvTCPNextTimeout ( pxSocket );
+ /* Return pdPASS to tell that the network buffer is 'consumed'. */
+ xResult = pdPASS;
+ }
+ }
/* pdPASS being returned means the buffer has been consumed. */
return xResult;
}
@@ -3153,7 +3295,8 @@ configASSERT(pxNetworkBuffer->pucEthernetBuffer);
static FreeRTOS_Socket_t *prvHandleListen( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
{
-TCPPacket_t * pxTCPPacket = ( TCPPacket_t * ) ( pxNetworkBuffer->pucEthernetBuffer );
+/* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
+const TCPPacket_t * pxTCPPacket = ipPOINTER_CAST( const TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
FreeRTOS_Socket_t *pxReturn = NULL;
uint32_t ulInitialSequenceNumber;
@@ -3166,7 +3309,7 @@ uint32_t ulInitialSequenceNumber;
/* A pure SYN (without ACK) has come in, create a new socket to answer
it. */
- if( 0 != ulInitialSequenceNumber )
+ if( ulInitialSequenceNumber != 0UL )
{
if( pxSocket->u.xTCP.bits.bReuseSocket != pdFALSE_UNSIGNED )
{
@@ -3188,8 +3331,8 @@ uint32_t ulInitialSequenceNumber;
pxSocket->usLocalPort,
pxSocket->u.xTCP.usChildCount,
pxSocket->u.xTCP.usBacklog,
- pxSocket->u.xTCP.usChildCount == 1 ? "" : "ren" ) );
- prvTCPSendReset( pxNetworkBuffer );
+ ( pxSocket->u.xTCP.usChildCount == 1U ) ? "" : "ren" ) );
+ ( void ) prvTCPSendReset( pxNetworkBuffer );
}
else
{
@@ -3199,7 +3342,7 @@ uint32_t ulInitialSequenceNumber;
if( ( pxNewSocket == NULL ) || ( pxNewSocket == FREERTOS_INVALID_SOCKET ) )
{
FreeRTOS_debug_printf( ( "TCP: Listen: new socket failed\n" ) );
- prvTCPSendReset( pxNetworkBuffer );
+ ( void ) prvTCPSendReset( pxNetworkBuffer );
}
else if( prvTCPSocketCopy( pxNewSocket, pxSocket ) != pdFALSE )
{
@@ -3209,18 +3352,26 @@ uint32_t ulInitialSequenceNumber;
lack of resources). */
pxReturn = pxNewSocket;
}
+ else
+ {
+ /* Copying failed somehow. */
+ }
}
}
}
- if( ( 0 != ulInitialSequenceNumber ) && ( pxReturn != NULL ) )
+ if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) )
{
+ /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */
+ const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *,
+ &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
+
pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort );
pxReturn->u.xTCP.ulRemoteIP = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress );
pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber;
/* Here is the SYN action. */
- pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxTCPPacket->xTCPHeader.ulSequenceNumber );
+ pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber );
prvSocketSetMSS( pxReturn );
prvTCPCreateWindow( pxReturn );
@@ -3229,7 +3380,7 @@ uint32_t ulInitialSequenceNumber;
/* Make a copy of the header up to the TCP header. It is needed later
on, whenever data must be sent to the peer. */
- memcpy( pxReturn->u.xTCP.xPacket.u.ucLastPacket, pxNetworkBuffer->pucEthernetBuffer, sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) );
+ ( void ) memcpy( pxReturn->u.xTCP.xPacket.u.ucLastPacket, pxNetworkBuffer->pucEthernetBuffer, sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) );
}
return pxReturn;
}
@@ -3241,6 +3392,7 @@ uint32_t ulInitialSequenceNumber;
static BaseType_t prvTCPSocketCopy( FreeRTOS_Socket_t *pxNewSocket, FreeRTOS_Socket_t *pxSocket )
{
struct freertos_sockaddr xAddress;
+BaseType_t xResult;
pxNewSocket->xReceiveBlockTime = pxSocket->xReceiveBlockTime;
pxNewSocket->xSendBlockTime = pxSocket->xSendBlockTime;
@@ -3271,10 +3423,10 @@ struct freertos_sockaddr xAddress;
{
/* Child socket of listening sockets will inherit the Socket Set
Otherwise the owner has no chance of including it into the set. */
- if( pxSocket->pxSocketSet )
+ if( pxSocket->pxSocketSet != NULL )
{
pxNewSocket->pxSocketSet = pxSocket->pxSocketSet;
- pxNewSocket->xSelectBits = pxSocket->xSelectBits | eSELECT_READ | eSELECT_EXCEPT;
+ pxNewSocket->xSelectBits = pxSocket->xSelectBits | ( ( EventBits_t ) eSELECT_READ ) | ( ( EventBits_t ) eSELECT_EXCEPT );
}
}
#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
@@ -3299,7 +3451,7 @@ struct freertos_sockaddr xAddress;
/* A reference to the new socket may be stored and the socket is marked
as 'passable'. */
- /* When bPassAccept is pdTRUE_UNSIGNED this socket may be returned in a call to
+ /* When bPassAccept is true, this socket may be returned in a call to
accept(). */
pxNewSocket->u.xTCP.bits.bPassAccept = pdTRUE_UNSIGNED;
if(pxSocket->u.xTCP.pxPeerSocket == NULL )
@@ -3315,17 +3467,21 @@ struct freertos_sockaddr xAddress;
pxSocket->usLocalPort,
pxSocket->u.xTCP.usChildCount,
pxSocket->u.xTCP.usBacklog,
- pxSocket->u.xTCP.usChildCount == 1u ? "" : "ren" ) );
+ ( pxSocket->u.xTCP.usChildCount == 1U ) ? "" : "ren" ) );
/* Now bind the child socket to the same port as the listening socket. */
if( vSocketBind ( pxNewSocket, &xAddress, sizeof( xAddress ), pdTRUE ) != 0 )
{
FreeRTOS_debug_printf( ( "TCP: Listen: new socket bind error\n" ) );
- vSocketClose( pxNewSocket );
- return pdFALSE;
+ ( void ) vSocketClose( pxNewSocket );
+ xResult = pdFALSE;
+ }
+ else
+ {
+ xResult = pdTRUE;
}
- return pdTRUE;
+ return xResult;
}
/*-----------------------------------------------------------*/
@@ -3333,11 +3489,31 @@ struct freertos_sockaddr xAddress;
const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState )
{
- if( ulState >= ( UBaseType_t ) ARRAY_SIZE( pcStateNames ) )
+ static const char * const pcStateNames[] =
+ {
+ "eCLOSED",
+ "eTCP_LISTEN",
+ "eCONNECT_SYN",
+ "eSYN_FIRST",
+ "eSYN_RECEIVED",
+ "eESTABLISHED",
+ "eFIN_WAIT_1",
+ "eFIN_WAIT_2",
+ "eCLOSE_WAIT",
+ "eCLOSING",
+ "eLAST_ACK",
+ "eTIME_WAIT",
+ "eUNKNOWN",
+ };
+ BaseType_t xIndex = ( BaseType_t ) ulState;
+
+ if( ( xIndex < 0 ) || ( xIndex >= ARRAY_SIZE( pcStateNames ) ) )
{
- ulState = ( UBaseType_t ) ARRAY_SIZE( pcStateNames ) - 1u;
+ /* The last item is called 'eUNKNOWN' */
+ xIndex = ARRAY_SIZE( pcStateNames );
+ xIndex--;
}
- return pcStateNames[ ulState ];
+ return pcStateNames[ xIndex ];
}
#endif /* ( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) ) */
@@ -3349,21 +3525,22 @@ struct freertos_sockaddr xAddress;
*/
BaseType_t xTCPCheckNewClient( FreeRTOS_Socket_t *pxSocket )
{
-TickType_t xLocalPort = FreeRTOS_htons( pxSocket->usLocalPort );
-ListItem_t *pxIterator;
+TickType_t uxLocalPort = ( TickType_t ) FreeRTOS_htons( pxSocket->usLocalPort );
+const ListItem_t *pxIterator;
FreeRTOS_Socket_t *pxFound;
BaseType_t xResult = pdFALSE;
+const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) );
/* Here xBoundTCPSocketsList can be accessed safely IP-task is the only one
who has access. */
- for( pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList );
- pxIterator != ( ListItem_t * ) listGET_END_MARKER( &xBoundTCPSocketsList );
- pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) )
+ for( pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList );
+ pxIterator != pxEndTCP;
+ pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) )
{
- if( listGET_LIST_ITEM_VALUE( pxIterator ) == xLocalPort )
+ if( listGET_LIST_ITEM_VALUE( pxIterator ) == ( configLIST_VOLATILE TickType_t ) uxLocalPort )
{
- pxFound = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator );
- if( ( pxFound->ucProtocol == FREERTOS_IPPROTO_TCP ) && ( pxFound->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) )
+ pxFound = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ if( ( pxFound->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ) && ( pxFound->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) )
{
pxSocket->u.xTCP.pxPeerSocket = pxFound;
FreeRTOS_debug_printf( ( "xTCPCheckNewClient[0]: client on port %u\n", pxSocket->usLocalPort ) );
@@ -3379,8 +3556,8 @@ BaseType_t xResult = pdFALSE;
#endif /* ipconfigUSE_TCP == 1 */
/* Provide access to private members for testing. */
-#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
- #include "iot_freertos_tcp_test_access_tcp_define.h"
+#ifdef FREERTOS_ENABLE_UNIT_TESTS
+ #include "freertos_tcp_test_access_tcp_define.h"
#endif
/* Provide access to private members for verification. */