diff options
author | lundinc <lundinc@1d2547de-c912-0410-9cb9-b8ca96c0e9e2> | 2020-08-12 19:11:51 +0000 |
---|---|---|
committer | lundinc <lundinc@1d2547de-c912-0410-9cb9-b8ca96c0e9e2> | 2020-08-12 19:11:51 +0000 |
commit | 42255af1e27a3157d541f0812eaca447c569ca49 (patch) | |
tree | 5c8702c2f0dc1cb9be1a4d5ff285897d96b97dd2 /FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c | |
parent | f5221dff43de249079c2da081723cb7a456f981f (diff) | |
download | freertos-master.tar.gz |
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_Sockets.c')
-rw-r--r-- | FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c | 1992 |
1 files changed, 1201 insertions, 791 deletions
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c index bb68d2b38..25d1dbd75 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c @@ -41,6 +41,13 @@ #include "FreeRTOS_DNS.h" #include "NetworkBufferManagement.h" +/* A tool to measure RAM usage. By default, it is disabled +and it won't add any code. +See also tools/tcp_mem_stats.md */ + +/*lint -e766 Header files is sometimes not used, depending on the configuration. */ +#include "tcp_mem_stats.h" + /* The ItemValue of the sockets xBoundSocketListItem member holds the socket's port number. */ #define socketSET_SOCKET_PORT( pxSocket, usPort ) listSET_LIST_ITEM_VALUE( ( &( ( pxSocket )->xBoundSocketListItem ) ), ( usPort ) ) @@ -66,33 +73,19 @@ range 1024-65535" excluding those already in use (inbound or outbound). */ #define socketAUTO_PORT_ALLOCATION_MAX_NUMBER ( ( uint16_t ) 0xffff ) /* The number of octets that make up an IP address. */ -#define socketMAX_IP_ADDRESS_OCTETS 4u +#define socketMAX_IP_ADDRESS_OCTETS 4U /* A block time of 0 simply means "don't block". */ #define socketDONT_BLOCK ( ( TickType_t ) 0 ) #if( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) ) - #define ipTCP_TIMER_PERIOD_MS ( 1000 ) -#endif - -/* The next private port number to use when binding a client socket is stored in -the usNextPortToUse[] array - which has either 1 or two indexes depending on -whether TCP is being supported. */ -#if( ipconfigUSE_TCP == 1 ) - #define socketPROTOCOL_COUNT 2 -#else - #define socketPROTOCOL_COUNT 1 + #define ipTCP_TIMER_PERIOD_MS ( 1000U ) #endif -/* Indexes into the usNextPortToUse[] array for UDP and TCP sockets -respectively. */ -#define socketNEXT_UDP_PORT_NUMBER_INDEX 0 -#define socketNEXT_TCP_PORT_NUMBER_INDEX 1 - /* Some helper macro's for defining the 20/80 % limits of uxLittleSpace / uxEnoughSpace. */ -#define sock20_PERCENT 20 -#define sock80_PERCENT 80 -#define sock100_PERCENT 100 +#define sock20_PERCENT 20U +#define sock80_PERCENT 80U +#define sock100_PERCENT 100U /*-----------------------------------------------------------*/ @@ -114,7 +107,13 @@ static const ListItem_t * pxListFindListItemWithValue( const List_t *pxList, Tic * Return pdTRUE only if pxSocket is valid and bound, as far as can be * determined. */ -static BaseType_t prvValidSocket( FreeRTOS_Socket_t *pxSocket, BaseType_t xProtocol, BaseType_t xIsBound ); +static BaseType_t prvValidSocket( const FreeRTOS_Socket_t *pxSocket, BaseType_t xProtocol, BaseType_t xIsBound ); + +/* + * Internal function prvSockopt_so_buffer(): sets FREERTOS_SO_SNDBUF or + * FREERTOS_SO_RCVBUF properties of a socket. + */ +static BaseType_t prvSockopt_so_buffer( FreeRTOS_Socket_t *pxSocket, int32_t lOptionName, const void *pvOptionValue ); /* * Before creating a socket, check the validity of the parameters used @@ -134,14 +133,14 @@ static BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xType, * Called from FreeRTOS_send(): some checks which will be done before * sending a TCP packed. */ - static int32_t prvTCPSendCheck( FreeRTOS_Socket_t *pxSocket, size_t xDataLength ); + static int32_t prvTCPSendCheck( FreeRTOS_Socket_t *pxSocket, size_t uxDataLength ); #endif /* ipconfigUSE_TCP */ #if( ipconfigUSE_TCP == 1 ) /* * When a child socket gets closed, make sure to update the child-count of the parent */ - static void prvTCPSetSocketCount( FreeRTOS_Socket_t *pxSocketToDelete ); + static void prvTCPSetSocketCount( FreeRTOS_Socket_t const * pxSocketToDelete ); #endif /* ipconfigUSE_TCP == 1 */ #if( ipconfigUSE_TCP == 1 ) @@ -149,20 +148,28 @@ static BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xType, * Called from FreeRTOS_connect(): make some checks and if allowed, send a * message to the IP-task to start connecting to a remote socket */ - static BaseType_t prvTCPConnectStart( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr *pxAddress ); + static BaseType_t prvTCPConnectStart( FreeRTOS_Socket_t * pxSocket, struct freertos_sockaddr const * pxAddress ); +#endif /* ipconfigUSE_TCP */ + +#if( ipconfigUSE_TCP == 1 ) + /* + * Check if it makes any sense to wait for a connect event. + * It may return: -EINPROGRESS, -EAGAIN, or 0 for OK. + */ + static BaseType_t bMayConnect( FreeRTOS_Socket_t const * pxSocket ); #endif /* ipconfigUSE_TCP */ #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) /* Executed by the IP-task, it will check all sockets belonging to a set */ - static FreeRTOS_Socket_t *prvFindSelectedSocket( SocketSelect_t *pxSocketSet ); + static void prvFindSelectedSocket( SocketSelect_t *pxSocketSet ); #endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */ /*-----------------------------------------------------------*/ /* The list that contains mappings between sockets and port numbers. Accesses to this list must be protected by critical sections of one kind or another. */ -List_t xBoundUDPSocketsList; +static List_t xBoundUDPSocketsList; #if ipconfigUSE_TCP == 1 List_t xBoundTCPSocketsList; @@ -170,15 +177,15 @@ List_t xBoundUDPSocketsList; /*-----------------------------------------------------------*/ -static BaseType_t prvValidSocket( FreeRTOS_Socket_t *pxSocket, BaseType_t xProtocol, BaseType_t xIsBound ) +static BaseType_t prvValidSocket( const FreeRTOS_Socket_t *pxSocket, BaseType_t xProtocol, BaseType_t xIsBound ) { -BaseType_t xReturn = pdTRUE; +BaseType_t xReturn; if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { xReturn = pdFALSE; } - else if( ( xIsBound != pdFALSE ) && ( socketSOCKET_IS_BOUND( pxSocket ) == pdFALSE ) ) + else if( ( xIsBound != pdFALSE ) && !socketSOCKET_IS_BOUND( pxSocket ) ) { /* The caller expects the socket to be bound, but it isn't. */ xReturn = pdFALSE; @@ -188,12 +195,16 @@ BaseType_t xReturn = pdTRUE; /* Socket has a wrong type (UDP != TCP). */ xReturn = pdFALSE; } + else + { + xReturn = pdTRUE; + } return xReturn; } /*-----------------------------------------------------------*/ -BaseType_t vNetworkSocketsInit( void ) +void vNetworkSocketsInit( void ) { vListInitialise( &xBoundUDPSocketsList ); @@ -202,15 +213,13 @@ BaseType_t vNetworkSocketsInit( void ) vListInitialise( &xBoundTCPSocketsList ); } #endif /* ipconfigUSE_TCP == 1 */ - - return pdTRUE; } /*-----------------------------------------------------------*/ static BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol, size_t *pxSocketSize ) { BaseType_t xReturn = pdPASS; -FreeRTOS_Socket_t *pxSocket; +FreeRTOS_Socket_t const *pxSocket = NULL; /* Asserts must not appear before it has been determined that the network task is ready - otherwise the asserts will fail. */ @@ -237,7 +246,7 @@ FreeRTOS_Socket_t *pxSocket; if( xType != FREERTOS_SOCK_DGRAM ) { xReturn = pdFAIL; - configASSERT( xReturn ); + configASSERT( xReturn == pdPASS ); } /* In case a UDP socket is created, do not allocate space for TCP data. */ *pxSocketSize = ( sizeof( *pxSocket ) - sizeof( pxSocket->u ) ) + sizeof( pxSocket->u.xUDP ); @@ -248,7 +257,7 @@ FreeRTOS_Socket_t *pxSocket; if( xType != FREERTOS_SOCK_STREAM ) { xReturn = pdFAIL; - configASSERT( xReturn ); + configASSERT( xReturn == pdPASS ); } *pxSocketSize = ( sizeof( *pxSocket ) - sizeof( pxSocket->u ) ) + sizeof( pxSocket->u.xTCP ); @@ -257,11 +266,12 @@ FreeRTOS_Socket_t *pxSocket; else { xReturn = pdFAIL; - configASSERT( xReturn ); + configASSERT( xReturn == pdPASS ); } } /* In case configASSERT() is not used */ ( void )xDomain; + ( void )pxSocket; /* Was only use fot sizeof. */ return xReturn; } /*-----------------------------------------------------------*/ @@ -284,80 +294,93 @@ Socket_t xReturn; size depends on the type of socket: UDP sockets need less space. A define 'pvPortMallocSocket' will used to allocate the necessary space. By default it points to the FreeRTOS function 'pvPortMalloc()'. */ - pxSocket = ( FreeRTOS_Socket_t * ) pvPortMallocSocket( uxSocketSize ); + pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, pvPortMallocSocket( uxSocketSize ) ); if( pxSocket == NULL ) { - pxSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET; + xReturn = FREERTOS_INVALID_SOCKET; iptraceFAILED_TO_CREATE_SOCKET(); } - else if( ( xEventGroup = xEventGroupCreate() ) == NULL ) - { - vPortFreeSocket( pxSocket ); - pxSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET; - iptraceFAILED_TO_CREATE_EVENT_GROUP(); - } else { - /* Clear the entire space to avoid nulling individual entries */ - memset( pxSocket, '\0', uxSocketSize ); - - pxSocket->xEventGroup = xEventGroup; - - /* Initialise the socket's members. The semaphore will be created - if the socket is bound to an address, for now the pointer to the - semaphore is just set to NULL to show it has not been created. */ - if( xProtocol == FREERTOS_IPPROTO_UDP ) + xEventGroup = xEventGroupCreate(); + if( xEventGroup == NULL ) { - vListInitialise( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); - - #if( ipconfigUDP_MAX_RX_PACKETS > 0 ) + vPortFreeSocket( pxSocket ); + xReturn = FREERTOS_INVALID_SOCKET; + iptraceFAILED_TO_CREATE_EVENT_GROUP(); + } + else + { + if( xProtocol == FREERTOS_IPPROTO_UDP ) + { + iptraceMEM_STATS_CREATE( tcpSOCKET_UDP, pxSocket, uxSocketSize + sizeof( StaticEventGroup_t ) ); + } + else { - pxSocket->u.xUDP.uxMaxPackets = ( UBaseType_t ) ipconfigUDP_MAX_RX_PACKETS; + /* Lint wants at least a comment, in case the macro is empty. */ + iptraceMEM_STATS_CREATE( tcpSOCKET_TCP, pxSocket, uxSocketSize + sizeof( StaticEventGroup_t ) ); } - #endif /* ipconfigUDP_MAX_RX_PACKETS > 0 */ - } - vListInitialiseItem( &( pxSocket->xBoundSocketListItem ) ); - listSET_LIST_ITEM_OWNER( &( pxSocket->xBoundSocketListItem ), ( void * ) pxSocket ); + /* Clear the entire space to avoid nulling individual entries. */ + ( void ) memset( pxSocket, 0, uxSocketSize ); - pxSocket->xReceiveBlockTime = ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME; - pxSocket->xSendBlockTime = ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME; - pxSocket->ucSocketOptions = ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT; - pxSocket->ucProtocol = ( uint8_t ) xProtocol; /* protocol: UDP or TCP */ + pxSocket->xEventGroup = xEventGroup; - #if( ipconfigUSE_TCP == 1 ) - { - if( xProtocol == FREERTOS_IPPROTO_TCP ) + /* Initialise the socket's members. The semaphore will be created + if the socket is bound to an address, for now the pointer to the + semaphore is just set to NULL to show it has not been created. */ + if( xProtocol == FREERTOS_IPPROTO_UDP ) { - /* StreamSize is expressed in number of bytes */ - /* Round up buffer sizes to nearest multiple of MSS */ - pxSocket->u.xTCP.usInitMSS = pxSocket->u.xTCP.usCurMSS = ipconfigTCP_MSS; - pxSocket->u.xTCP.uxRxStreamSize = ( size_t ) ipconfigTCP_RX_BUFFER_LENGTH; - pxSocket->u.xTCP.uxTxStreamSize = ( size_t ) FreeRTOS_round_up( ipconfigTCP_TX_BUFFER_LENGTH, ipconfigTCP_MSS ); - /* Use half of the buffer size of the TCP windows */ - #if ( ipconfigUSE_TCP_WIN == 1 ) + vListInitialise( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); + + #if( ipconfigUDP_MAX_RX_PACKETS > 0U ) { - pxSocket->u.xTCP.uxRxWinSize = FreeRTOS_max_uint32( 1UL, ( uint32_t ) ( pxSocket->u.xTCP.uxRxStreamSize / 2 ) / ipconfigTCP_MSS ); - pxSocket->u.xTCP.uxTxWinSize = FreeRTOS_max_uint32( 1UL, ( uint32_t ) ( pxSocket->u.xTCP.uxTxStreamSize / 2 ) / ipconfigTCP_MSS ); + pxSocket->u.xUDP.uxMaxPackets = ( UBaseType_t ) ipconfigUDP_MAX_RX_PACKETS; } - #else - { - pxSocket->u.xTCP.uxRxWinSize = 1u; - pxSocket->u.xTCP.uxTxWinSize = 1u; + #endif /* ipconfigUDP_MAX_RX_PACKETS > 0 */ + } + + vListInitialiseItem( &( pxSocket->xBoundSocketListItem ) ); + listSET_LIST_ITEM_OWNER( &( pxSocket->xBoundSocketListItem ), ipPOINTER_CAST( void *, pxSocket ) ); + + pxSocket->xReceiveBlockTime = ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME; + pxSocket->xSendBlockTime = ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME; + pxSocket->ucSocketOptions = ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT; + pxSocket->ucProtocol = ( uint8_t ) xProtocol; /* protocol: UDP or TCP */ + + #if( ipconfigUSE_TCP == 1 ) + { + if( xProtocol == FREERTOS_IPPROTO_TCP ) + { + /* StreamSize is expressed in number of bytes */ + /* Round up buffer sizes to nearest multiple of MSS */ + pxSocket->u.xTCP.usCurMSS = ( uint16_t ) ipconfigTCP_MSS; + pxSocket->u.xTCP.usInitMSS = ( uint16_t ) ipconfigTCP_MSS; + pxSocket->u.xTCP.uxRxStreamSize = ( size_t ) ipconfigTCP_RX_BUFFER_LENGTH; + pxSocket->u.xTCP.uxTxStreamSize = ( size_t ) FreeRTOS_round_up( ipconfigTCP_TX_BUFFER_LENGTH, ipconfigTCP_MSS ); + /* Use half of the buffer size of the TCP windows */ + #if ( ipconfigUSE_TCP_WIN == 1 ) + { + pxSocket->u.xTCP.uxRxWinSize = FreeRTOS_max_uint32( 1UL, ( uint32_t ) ( pxSocket->u.xTCP.uxRxStreamSize / 2U ) / ipconfigTCP_MSS ); + pxSocket->u.xTCP.uxTxWinSize = FreeRTOS_max_uint32( 1UL, ( uint32_t ) ( pxSocket->u.xTCP.uxTxStreamSize / 2U ) / ipconfigTCP_MSS ); + } + #else + { + pxSocket->u.xTCP.uxRxWinSize = 1U; + pxSocket->u.xTCP.uxTxWinSize = 1U; + } + #endif + /* The above values are just defaults, and can be overridden by + calling FreeRTOS_setsockopt(). No buffers will be allocated until a + socket is connected and data is exchanged. */ } - #endif - /* The above values are just defaults, and can be overridden by - calling FreeRTOS_setsockopt(). No buffers will be allocated until a - socket is connected and data is exchanged. */ } + #endif /* ipconfigUSE_TCP == 1 */ + xReturn = pxSocket; } - #endif /* ipconfigUSE_TCP == 1 */ } - - xReturn = ( Socket_t ) pxSocket; } - /* Remove compiler warnings in the case the configASSERT() is not defined. */ ( void ) xDomain; @@ -371,18 +394,23 @@ Socket_t xReturn; { SocketSelect_t *pxSocketSet; - pxSocketSet = ( SocketSelect_t * ) pvPortMalloc( sizeof( *pxSocketSet ) ); + pxSocketSet = ipPOINTER_CAST( SocketSelect_t *, pvPortMalloc( sizeof( *pxSocketSet ) ) ); if( pxSocketSet != NULL ) { - memset( pxSocketSet, '\0', sizeof( *pxSocketSet ) ); + ( void ) memset( pxSocketSet, 0, sizeof( *pxSocketSet ) ); pxSocketSet->xSelectGroup = xEventGroupCreate(); if( pxSocketSet->xSelectGroup == NULL ) { - vPortFree( ( void* ) pxSocketSet ); + vPortFree( pxSocketSet ); pxSocketSet = NULL; } + else + { + /* Lint wants at least a comment, in case the macro is empty. */ + iptraceMEM_STATS_CREATE( tcpSOCKET_SET, pxSocketSet, sizeof( *pxSocketSet ) + sizeof( StaticEventGroup_t ) ); + } } return ( SocketSet_t ) pxSocketSet; @@ -397,8 +425,10 @@ Socket_t xReturn; { SocketSelect_t *pxSocketSet = ( SocketSelect_t*) xSocketSet; + iptraceMEM_STATS_DELETE( pxSocketSet ); + vEventGroupDelete( pxSocketSet->xSelectGroup ); - vPortFree( ( void* ) pxSocketSet ); + vPortFree( pxSocketSet ); } #endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */ @@ -407,7 +437,7 @@ Socket_t xReturn; #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) /* Add a socket to a set */ - void FreeRTOS_FD_SET( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xSelectBits ) + void FreeRTOS_FD_SET( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xBitsToSet ) { FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; SocketSelect_t *pxSocketSet = ( SocketSelect_t * ) xSocketSet; @@ -417,18 +447,15 @@ Socket_t xReturn; /* Make sure we're not adding bits which are reserved for internal use, such as eSELECT_CALL_IP */ - pxSocket->xSelectBits |= ( xSelectBits & eSELECT_ALL ); + pxSocket->xSelectBits |= xBitsToSet & ( ( EventBits_t ) eSELECT_ALL ); - if( ( pxSocket->xSelectBits & eSELECT_ALL ) != 0 ) + if( ( pxSocket->xSelectBits & ( ( EventBits_t ) eSELECT_ALL ) ) != ( EventBits_t ) 0U ) { /* Adding a socket to a socket set. */ pxSocket->pxSocketSet = ( SocketSelect_t * ) xSocketSet; /* Now have the IP-task call vSocketSelect() to see if the set contains - any sockets which are 'ready' and set the proper bits. - By setting 'bApiCalled = false', vSocketSelect() knows that it was - not called from a user API */ - pxSocketSet->bApiCalled = pdFALSE; + any sockets which are 'ready' and set the proper bits. */ prvFindSelectedSocket( pxSocketSet ); } } @@ -439,22 +466,22 @@ Socket_t xReturn; #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) /* Clear select bits for a socket If the mask becomes 0, remove the socket from the set */ - void FreeRTOS_FD_CLR( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xSelectBits ) + void FreeRTOS_FD_CLR( Socket_t xSocket, SocketSet_t xSocketSet, EventBits_t xBitsToClear ) { FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; configASSERT( pxSocket != NULL ); configASSERT( xSocketSet != NULL ); - pxSocket->xSelectBits &= ~( xSelectBits & eSELECT_ALL ); - if( ( pxSocket->xSelectBits & eSELECT_ALL ) != 0 ) + pxSocket->xSelectBits &= ~( xBitsToClear & ( ( EventBits_t ) eSELECT_ALL ) ); + if( ( pxSocket->xSelectBits & ( ( EventBits_t ) eSELECT_ALL ) ) != ( EventBits_t ) 0U ) { pxSocket->pxSocketSet = ( SocketSelect_t *)xSocketSet; } else { /* disconnect it from the socket set */ - pxSocket->pxSocketSet = ( SocketSelect_t *)NULL; + pxSocket->pxSocketSet = NULL; } } @@ -468,7 +495,7 @@ Socket_t xReturn; EventBits_t FreeRTOS_FD_ISSET( Socket_t xSocket, SocketSet_t xSocketSet ) { EventBits_t xReturn; - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; configASSERT( pxSocket != NULL ); configASSERT( xSocketSet != NULL ); @@ -477,7 +504,7 @@ Socket_t xReturn; { /* Make sure we're not adding bits which are reserved for internal use. */ - xReturn = pxSocket->xSocketBits & eSELECT_ALL; + xReturn = pxSocket->xSocketBits & ( ( EventBits_t ) eSELECT_ALL ); } else { @@ -499,7 +526,7 @@ Socket_t xReturn; TimeOut_t xTimeOut; TickType_t xRemainingTime; SocketSelect_t *pxSocketSet = ( SocketSelect_t*) xSocketSet; - BaseType_t xResult; + EventBits_t uxResult; configASSERT( xSocketSet != NULL ); @@ -513,13 +540,13 @@ Socket_t xReturn; { /* Find a socket which might have triggered the bit This function might return immediately or block for a limited time */ - xResult = ( BaseType_t ) xEventGroupWaitBits( pxSocketSet->xSelectGroup, eSELECT_ALL, pdFALSE, pdFALSE, xRemainingTime ); + uxResult = xEventGroupWaitBits( pxSocketSet->xSelectGroup, ( ( EventBits_t ) eSELECT_ALL ), pdFALSE, pdFALSE, xRemainingTime ); #if( ipconfigSUPPORT_SIGNALS != 0 ) { - if( ( xResult & eSELECT_INTR ) != 0u ) + if( ( uxResult & ( ( EventBits_t ) eSELECT_INTR ) ) != 0U ) { - xEventGroupClearBits( pxSocketSet->xSelectGroup, eSELECT_INTR ); + ( void ) xEventGroupClearBits( pxSocketSet->xSelectGroup, ( EventBits_t ) eSELECT_INTR ); FreeRTOS_debug_printf( ( "FreeRTOS_select: interrupted\n" ) ); break; } @@ -527,12 +554,11 @@ Socket_t xReturn; #endif /* ipconfigSUPPORT_SIGNALS */ /* Have the IP-task find the socket which had an event */ - pxSocketSet->bApiCalled = pdTRUE; prvFindSelectedSocket( pxSocketSet ); - xResult = ( BaseType_t ) xEventGroupGetBits( pxSocketSet->xSelectGroup ); + uxResult = xEventGroupGetBits( pxSocketSet->xSelectGroup ); - if( xResult != 0 ) + if( uxResult != 0U ) { break; } @@ -544,7 +570,7 @@ Socket_t xReturn; } } - return xResult; + return ( BaseType_t ) uxResult; } #endif /* ipconfigSUPPORT_SELECT_FUNCTION */ @@ -554,36 +580,51 @@ Socket_t xReturn; /* Send a message to the IP-task to have it check all sockets belonging to 'pxSocketSet' */ - static FreeRTOS_Socket_t *prvFindSelectedSocket( SocketSelect_t *pxSocketSet ) + static void prvFindSelectedSocket( SocketSelect_t *pxSocketSet ) { IPStackEvent_t xSelectEvent; - FreeRTOS_Socket_t *xReturn; + #if( ipconfigSELECT_USES_NOTIFY != 0 ) + SocketSelectMessage_t xSelectMessage; + #endif xSelectEvent.eEventType = eSocketSelectEvent; - xSelectEvent.pvData = ( void * ) pxSocketSet; + #if( ipconfigSELECT_USES_NOTIFY != 0 ) + { + xSelectMessage.pxSocketSet = pxSocketSet; + xSelectMessage.xTaskhandle = xTaskGetCurrentTaskHandle(); + xSelectEvent.pvData = &( xSelectMessage ); + } + #else + { + xSelectEvent.pvData = pxSocketSet; + + /* while the IP-task works on the request, the API will block on + 'eSELECT_CALL_IP'. So clear it first. */ + ( void ) xEventGroupClearBits( pxSocketSet->xSelectGroup, ( BaseType_t ) eSELECT_CALL_IP ); + } + #endif - /* while the IP-task works on the request, the API will block on - 'eSELECT_CALL_IP'. So clear it first. */ - xEventGroupClearBits( pxSocketSet->xSelectGroup, eSELECT_CALL_IP ); /* Now send the socket select event */ if( xSendEventStructToIPTask( &xSelectEvent, ( TickType_t ) portMAX_DELAY ) == pdFAIL ) { /* Oops, we failed to wake-up the IP task. No use to wait for it. */ FreeRTOS_debug_printf( ( "prvFindSelectedSocket: failed\n" ) ); - xReturn = NULL; } else { /* As soon as the IP-task is ready, it will set 'eSELECT_CALL_IP' to wakeup the calling API */ - xEventGroupWaitBits( pxSocketSet->xSelectGroup, eSELECT_CALL_IP, pdTRUE, pdFALSE, portMAX_DELAY ); - - /* Return 'pxSocket' which is set by the IP-task */ - xReturn = pxSocketSet->pxSocket; + #if( ipconfigSELECT_USES_NOTIFY != 0 ) + { + ( void ) ulTaskNotifyTake( pdFALSE, portMAX_DELAY ); + } + #else + { + ( void ) xEventGroupWaitBits( pxSocketSet->xSelectGroup, ( BaseType_t ) eSELECT_CALL_IP, pdTRUE, pdFALSE, portMAX_DELAY ); + } + #endif } - - return xReturn; } #endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */ @@ -594,11 +635,11 @@ Socket_t xReturn; * In this library, the function can only be used with connectionsless sockets * (UDP) */ -int32_t FreeRTOS_recvfrom( Socket_t xSocket, void *pvBuffer, size_t xBufferLength, BaseType_t xFlags, struct freertos_sockaddr *pxSourceAddress, socklen_t *pxSourceAddressLength ) +int32_t FreeRTOS_recvfrom( Socket_t xSocket, void *pvBuffer, size_t uxBufferLength, BaseType_t xFlags, struct freertos_sockaddr *pxSourceAddress, socklen_t *pxSourceAddressLength ) { -BaseType_t lPacketCount = 0; +BaseType_t lPacketCount; NetworkBufferDescriptor_t *pxNetworkBuffer; -FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; +FreeRTOS_Socket_t const * pxSocket = xSocket; TickType_t xRemainingTime = ( TickType_t ) 0; /* Obsolete assignment, but some compilers output a warning if its not done. */ BaseType_t xTimed = pdFALSE; TimeOut_t xTimeOut; @@ -607,167 +648,172 @@ EventBits_t xEventBits = ( EventBits_t ) 0; if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_UDP, pdTRUE ) == pdFALSE ) { - return -pdFREERTOS_ERRNO_EINVAL; + lReturn = -pdFREERTOS_ERRNO_EINVAL; } + else + { + lPacketCount = ( BaseType_t ) listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); - lPacketCount = ( BaseType_t ) listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); + /* The function prototype is designed to maintain the expected Berkeley + sockets standard, but this implementation does not use all the parameters. */ + ( void ) pxSourceAddressLength; - /* The function prototype is designed to maintain the expected Berkeley - sockets standard, but this implementation does not use all the parameters. */ - ( void ) pxSourceAddressLength; - - while( lPacketCount == 0 ) - { - if( xTimed == pdFALSE ) + while( lPacketCount == 0 ) { - /* Check to see if the socket is non blocking on the first - iteration. */ - xRemainingTime = pxSocket->xReceiveBlockTime; - - if( xRemainingTime == ( TickType_t ) 0 ) + if( xTimed == pdFALSE ) { - #if( ipconfigSUPPORT_SIGNALS != 0 ) + /* Check to see if the socket is non blocking on the first + iteration. */ + xRemainingTime = pxSocket->xReceiveBlockTime; + + if( xRemainingTime == ( TickType_t ) 0 ) { - /* Just check for the interrupt flag. */ - xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_INTR, - pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, socketDONT_BLOCK ); + #if( ipconfigSUPPORT_SIGNALS != 0 ) + { + /* Just check for the interrupt flag. */ + xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_INTR, + pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, socketDONT_BLOCK ); + } + #endif /* ipconfigSUPPORT_SIGNALS */ + break; } - #endif /* ipconfigSUPPORT_SIGNALS */ - break; - } - if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 ) - { - break; - } + if( ( ( ( UBaseType_t ) xFlags ) & ( ( UBaseType_t ) FREERTOS_MSG_DONTWAIT ) ) != 0U ) + { + break; + } - /* To ensure this part only executes once. */ - xTimed = pdTRUE; + /* To ensure this part only executes once. */ + xTimed = pdTRUE; - /* Fetch the current time. */ - vTaskSetTimeOutState( &xTimeOut ); - } + /* Fetch the current time. */ + vTaskSetTimeOutState( &xTimeOut ); + } - /* Wait for arrival of data. While waiting, the IP-task may set the - 'eSOCKET_RECEIVE' bit in 'xEventGroup', if it receives data for this - socket, thus unblocking this API call. */ - xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_RECEIVE | eSOCKET_INTR, - pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); + /* Wait for arrival of data. While waiting, the IP-task may set the + 'eSOCKET_RECEIVE' bit in 'xEventGroup', if it receives data for this + socket, thus unblocking this API call. */ + xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, ( ( EventBits_t ) eSOCKET_RECEIVE ) | ( ( EventBits_t ) eSOCKET_INTR ), + pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); - #if( ipconfigSUPPORT_SIGNALS != 0 ) - { - if( ( xEventBits & eSOCKET_INTR ) != 0 ) + #if( ipconfigSUPPORT_SIGNALS != 0 ) { - if( ( xEventBits & eSOCKET_RECEIVE ) != 0 ) + if( ( xEventBits & ( EventBits_t ) eSOCKET_INTR ) != 0U ) { - /* Shouldn't have cleared the eSOCKET_RECEIVE flag. */ - xEventGroupSetBits( pxSocket->xEventGroup, eSOCKET_RECEIVE ); + if( ( xEventBits & ( EventBits_t ) eSOCKET_RECEIVE ) != 0U ) + { + /* Shouldn't have cleared the eSOCKET_RECEIVE flag. */ + ( void ) xEventGroupSetBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_RECEIVE ); + } + break; } + } + #else + { + ( void ) xEventBits; + } + #endif /* ipconfigSUPPORT_SIGNALS */ + + lPacketCount = ( BaseType_t ) listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); + + if( lPacketCount != 0 ) + { break; } - } - #else - { - ( void ) xEventBits; - } - #endif /* ipconfigSUPPORT_SIGNALS */ - lPacketCount = ( BaseType_t ) listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); + /* Has the timeout been reached ? */ + if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) != pdFALSE ) + { + break; + } + } /* while( lPacketCount == 0 ) */ if( lPacketCount != 0 ) { - break; - } + taskENTER_CRITICAL(); + { + /* The owner of the list item is the network buffer. */ + pxNetworkBuffer = ipPOINTER_CAST( NetworkBufferDescriptor_t *, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) ); - /* Has the timeout been reached ? */ - if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) ) - { - break; - } - } /* while( lPacketCount == 0 ) */ + if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_MSG_PEEK ) == 0U ) + { + /* Remove the network buffer from the list of buffers waiting to + be processed by the socket. */ + ( void ) uxListRemove( &( pxNetworkBuffer->xBufferListItem ) ); + } + } + taskEXIT_CRITICAL(); - if( lPacketCount != 0 ) - { - taskENTER_CRITICAL(); - { - /* The owner of the list item is the network buffer. */ - pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); + /* The returned value is the length of the payload data, which is + calculated at the total packet size minus the headers. + The validity of `xDataLength` prvProcessIPPacket has been confirmed + in 'prvProcessIPPacket()'. */ + lReturn = ( int32_t ) ( pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t ) ); - if( ( xFlags & FREERTOS_MSG_PEEK ) == 0 ) + if( pxSourceAddress != NULL ) { - /* Remove the network buffer from the list of buffers waiting to - be processed by the socket. */ - uxListRemove( &( pxNetworkBuffer->xBufferListItem ) ); + pxSourceAddress->sin_port = pxNetworkBuffer->usPort; + pxSourceAddress->sin_addr = pxNetworkBuffer->ulIPAddress; } - } - taskEXIT_CRITICAL(); - /* The returned value is the length of the payload data, which is - calculated at the total packet size minus the headers. - The validity of `xDataLength` prvProcessIPPacket has been confirmed - in 'prvProcessIPPacket()'. */ - lReturn = ( int32_t ) ( pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t ) ); - - if( pxSourceAddress != NULL ) - { - pxSourceAddress->sin_port = pxNetworkBuffer->usPort; - pxSourceAddress->sin_addr = pxNetworkBuffer->ulIPAddress; - } - - if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 ) - { - /* The zero copy flag is not set. Truncate the length if it won't - fit in the provided buffer. */ - if( lReturn > ( int32_t ) xBufferLength ) + if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_ZERO_COPY ) == 0U ) { - iptraceRECVFROM_DISCARDING_BYTES( ( xBufferLength - lReturn ) ); - lReturn = ( int32_t )xBufferLength; - } + /* The zero copy flag is not set. Truncate the length if it won't + fit in the provided buffer. */ + if( lReturn > ( int32_t ) uxBufferLength ) + { + iptraceRECVFROM_DISCARDING_BYTES( ( uxBufferLength - lReturn ) ); + lReturn = ( int32_t ) uxBufferLength; + } - /* Copy the received data into the provided buffer, then release the - network buffer. */ - memcpy( pvBuffer, ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ), ( size_t )lReturn ); + /* Copy the received data into the provided buffer, then release the + network buffer. */ + ( void ) memcpy( pvBuffer, &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ), ( size_t )lReturn ); - if( ( xFlags & FREERTOS_MSG_PEEK ) == 0 ) + if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_MSG_PEEK ) == 0U ) + { + vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); + } + } + else { - vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); + /* The zero copy flag was set. pvBuffer is not a buffer into which + the received data can be copied, but a pointer that must be set to + point to the buffer in which the received data has already been + placed. */ + *( ( void** ) pvBuffer ) = ipPOINTER_CAST( void *, &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ) ); } + } + #if( ipconfigSUPPORT_SIGNALS != 0 ) + else if( ( xEventBits & ( EventBits_t ) eSOCKET_INTR ) != 0U ) + { + lReturn = -pdFREERTOS_ERRNO_EINTR; + iptraceRECVFROM_INTERRUPTED(); + } + #endif /* ipconfigSUPPORT_SIGNALS */ else { - /* The zero copy flag was set. pvBuffer is not a buffer into which - the received data can be copied, but a pointer that must be set to - point to the buffer in which the received data has already been - placed. */ - *( ( void** ) pvBuffer ) = ( void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ) ); + lReturn = -pdFREERTOS_ERRNO_EWOULDBLOCK; + iptraceRECVFROM_TIMEOUT(); } - - } -#if( ipconfigSUPPORT_SIGNALS != 0 ) - else if( ( xEventBits & eSOCKET_INTR ) != 0 ) - { - lReturn = -pdFREERTOS_ERRNO_EINTR; - iptraceRECVFROM_INTERRUPTED(); - } -#endif /* ipconfigSUPPORT_SIGNALS */ - else - { - lReturn = -pdFREERTOS_ERRNO_EWOULDBLOCK; - iptraceRECVFROM_TIMEOUT(); } return lReturn; } /*-----------------------------------------------------------*/ -int32_t FreeRTOS_sendto( Socket_t xSocket, const void *pvBuffer, size_t xTotalDataLength, BaseType_t xFlags, const struct freertos_sockaddr *pxDestinationAddress, socklen_t xDestinationAddressLength ) +int32_t FreeRTOS_sendto( Socket_t xSocket, const void *pvBuffer, size_t uxTotalDataLength, BaseType_t xFlags, const struct freertos_sockaddr *pxDestinationAddress, socklen_t xDestinationAddressLength ) { NetworkBufferDescriptor_t *pxNetworkBuffer; IPStackEvent_t xStackTxEvent = { eStackTxEvent, NULL }; TimeOut_t xTimeOut; TickType_t xTicksToWait; int32_t lReturn = 0; -FreeRTOS_Socket_t *pxSocket; +FreeRTOS_Socket_t const * pxSocket; +const size_t uxMaxPayloadLength = ( size_t ) ipMAX_UDP_PAYLOAD_LENGTH; +const size_t uxPayloadOffset = ( size_t ) ipUDP_PAYLOAD_OFFSET_IPv4; + pxSocket = ( FreeRTOS_Socket_t * ) xSocket; @@ -775,15 +821,15 @@ FreeRTOS_Socket_t *pxSocket; sockets standard, but this implementation does not use all the parameters. */ ( void ) xDestinationAddressLength; - configASSERT( pvBuffer ); + configASSERT( pvBuffer != NULL ); - if( xTotalDataLength <= ( size_t ) ipMAX_UDP_PAYLOAD_LENGTH ) + if( uxTotalDataLength <= ( size_t ) uxMaxPayloadLength ) { /* If the socket is not already bound to an address, bind it now. Passing NULL as the address parameter tells FreeRTOS_bind() to select the address to bind to. */ - if( ( socketSOCKET_IS_BOUND( pxSocket ) != pdFALSE ) || - ( FreeRTOS_bind( xSocket, NULL, 0u ) == 0 ) ) + if( socketSOCKET_IS_BOUND( pxSocket ) || + ( FreeRTOS_bind( xSocket, NULL, 0U ) == 0 ) ) { xTicksToWait = pxSocket->xSendBlockTime; @@ -799,12 +845,12 @@ FreeRTOS_Socket_t *pxSocket; } #endif /* ipconfigUSE_CALLBACKS */ - if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 ) + if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_MSG_DONTWAIT ) != 0U ) { xTicksToWait = ( TickType_t ) 0; } - if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 ) + if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_ZERO_COPY ) == 0U ) { /* Zero copy is not set, so obtain a network buffer into which the payload will be copied. */ @@ -812,11 +858,11 @@ FreeRTOS_Socket_t *pxSocket; /* Block until a buffer becomes available, or until a timeout has been reached */ - pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( xTotalDataLength + sizeof( UDPPacket_t ), xTicksToWait ); + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( uxPayloadOffset + uxTotalDataLength, xTicksToWait ); if( pxNetworkBuffer != NULL ) { - memcpy( ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ), ( void * ) pvBuffer, xTotalDataLength ); + ( void ) memcpy( &( pxNetworkBuffer->pucEthernetBuffer[ uxPayloadOffset ] ), pvBuffer, uxTotalDataLength ); if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdTRUE ) { @@ -830,13 +876,13 @@ FreeRTOS_Socket_t *pxSocket; /* When zero copy is used, pvBuffer is a pointer to the payload of a buffer that has already been obtained from the stack. Obtain the network buffer pointer from the buffer. */ - pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( (void*)pvBuffer ); + pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( ( void * ) pvBuffer ); } if( pxNetworkBuffer != NULL ) { /* xDataLength is the size of the total packet, including the Ethernet header. */ - pxNetworkBuffer->xDataLength = xTotalDataLength + sizeof( UDPPacket_t ); + pxNetworkBuffer->xDataLength = uxTotalDataLength + sizeof( UDPPacket_t ); pxNetworkBuffer->usPort = pxDestinationAddress->sin_port; pxNetworkBuffer->usBoundPort = ( uint16_t ) socketGET_SOCKET_PORT( pxSocket ); pxNetworkBuffer->ulIPAddress = pxDestinationAddress->sin_addr; @@ -852,12 +898,12 @@ FreeRTOS_Socket_t *pxSocket; if( xSendEventStructToIPTask( &xStackTxEvent, xTicksToWait ) == pdPASS ) { /* The packet was successfully sent to the IP task. */ - lReturn = ( int32_t ) xTotalDataLength; + lReturn = ( int32_t ) uxTotalDataLength; #if( ipconfigUSE_CALLBACKS == 1 ) { if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xUDP.pxHandleSent ) ) { - pxSocket->u.xUDP.pxHandleSent( ( Socket_t )pxSocket, xTotalDataLength ); + pxSocket->u.xUDP.pxHandleSent( xSocket, uxTotalDataLength ); } } #endif /* ipconfigUSE_CALLBACKS */ @@ -866,7 +912,7 @@ FreeRTOS_Socket_t *pxSocket; { /* If the buffer was allocated in this function, release it. */ - if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 ) + if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_ZERO_COPY ) == 0U ) { vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); } @@ -884,6 +930,7 @@ FreeRTOS_Socket_t *pxSocket; } else { + /* No comment. */ iptraceSENDTO_SOCKET_NOT_BOUND(); } } @@ -898,13 +945,13 @@ FreeRTOS_Socket_t *pxSocket; /*-----------------------------------------------------------*/ /* - * FreeRTOS_bind() : binds a sockt to a local port number. If port 0 is + * FreeRTOS_bind() : binds a socket to a local port number. If port 0 is * provided, a system provided port number will be assigned. This function can * be used for both UDP and TCP sockets. The actual binding will be performed * by the IP-task to avoid mutual access to the bound-socket-lists * (xBoundUDPSocketsList or xBoundTCPSocketsList). */ -BaseType_t FreeRTOS_bind( Socket_t xSocket, struct freertos_sockaddr * pxAddress, socklen_t xAddressLength ) +BaseType_t FreeRTOS_bind( Socket_t xSocket, struct freertos_sockaddr const * pxAddress, socklen_t xAddressLength ) { IPStackEvent_t xBindEvent; FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; @@ -912,13 +959,15 @@ BaseType_t xReturn = 0; ( void ) xAddressLength; + configASSERT( xIsCallingFromIPTask() == pdFALSE ); + if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) { xReturn = -pdFREERTOS_ERRNO_EINVAL; } /* Once a socket is bound to a port, it can not be bound to a different port number */ - else if( socketSOCKET_IS_BOUND( pxSocket) != pdFALSE ) + else if( socketSOCKET_IS_BOUND( pxSocket) ) { /* The socket is already bound. */ FreeRTOS_debug_printf( ( "vSocketBind: Socket already bound to %d\n", pxSocket->usLocalPort ) ); @@ -929,7 +978,7 @@ BaseType_t xReturn = 0; /* Prepare a messages to the IP-task in order to perform the binding. The desired port number will be passed in usLocalPort. */ xBindEvent.eEventType = eSocketBindEvent; - xBindEvent.pvData = ( void * ) xSocket; + xBindEvent.pvData = xSocket; if( pxAddress != NULL ) { pxSocket->usLocalPort = FreeRTOS_ntohs( pxAddress->sin_port ); @@ -937,7 +986,7 @@ BaseType_t xReturn = 0; else { /* Caller wants to bind to a random port number. */ - pxSocket->usLocalPort = 0u; + pxSocket->usLocalPort = 0U; } /* portMAX_DELAY is used as a the time-out parameter, as binding *must* @@ -953,8 +1002,8 @@ BaseType_t xReturn = 0; { /* The IP-task will set the 'eSOCKET_BOUND' bit when it has done its job. */ - xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_BOUND, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, portMAX_DELAY ); - if( socketSOCKET_IS_BOUND( pxSocket ) == pdFALSE ) + ( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_BOUND, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, portMAX_DELAY ); + if( !socketSOCKET_IS_BOUND( pxSocket ) ) { xReturn = -pdFREERTOS_ERRNO_EINVAL; } @@ -969,10 +1018,11 @@ BaseType_t xReturn = 0; * 'xInternal' is used for TCP sockets only: it allows to have several * (connected) child sockets bound to the same server port. */ -BaseType_t vSocketBind( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr * pxAddress, size_t uxAddressLength, BaseType_t xInternal ) +BaseType_t vSocketBind( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr * pxBindAddress, size_t uxAddressLength, BaseType_t xInternal ) { BaseType_t xReturn = 0; /* In Berkeley sockets, 0 means pass for bind(). */ List_t *pxSocketList; +struct freertos_sockaddr * pxAddress = pxBindAddress; #if( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 ) struct freertos_sockaddr xAddress; #endif /* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND */ @@ -992,89 +1042,102 @@ List_t *pxSocketList; sockets standard, but this implementation does not use all the parameters. */ ( void ) uxAddressLength; - configASSERT( pxSocket ); + configASSERT( pxSocket != NULL ); configASSERT( pxSocket != FREERTOS_INVALID_SOCKET ); #if( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 ) { /* pxAddress will be NULL if sendto() was called on a socket without the socket being bound to an address. In this case, automatically allocate - an address and port to the socket. */ + an address to the socket. There is a small chance that the allocated + port will already be in use - if that is the case, then the check below + [pxListFindListItemWithValue()] will result in an error being returned. */ if( pxAddress == NULL ) { pxAddress = &xAddress; /* Put the port to zero to be assigned later. */ - pxAddress->sin_port = 0u; + pxAddress->sin_port = 0U; } } #endif /* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 */ /* Sockets must be bound before calling FreeRTOS_sendto() if ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is not set to 1. */ - configASSERT( pxAddress ); + configASSERT( pxAddress != NULL ); + #if( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 1 ) + /* pxAddress is not NULL, no testing needed. */ + #else if( pxAddress != NULL ) + #endif { - if( pxAddress->sin_port == 0u ) + /* Add a do-while loop to facilitate use of 'break' statements. */ + do { - pxAddress->sin_port = prvGetPrivatePortNumber( ( BaseType_t )pxSocket->ucProtocol ); - if( 0 == pxAddress->sin_port ) + if( pxAddress->sin_port == 0U ) { - return -pdFREERTOS_ERRNO_EADDRNOTAVAIL; + pxAddress->sin_port = prvGetPrivatePortNumber( ( BaseType_t ) pxSocket->ucProtocol ); + if( pxAddress->sin_port == ( uint16_t ) 0U ) + { + xReturn = -pdFREERTOS_ERRNO_EADDRNOTAVAIL; + break; + } } - } - /* If vSocketBind() is called from the API FreeRTOS_bind() it has been - confirmed that the socket was not yet bound to a port. If it is called - from the IP-task, no such check is necessary. */ + /* If vSocketBind() is called from the API FreeRTOS_bind() it has been + confirmed that the socket was not yet bound to a port. If it is called + from the IP-task, no such check is necessary. */ - /* Check to ensure the port is not already in use. If the bind is - called internally, a port MAY be used by more than one socket. */ - if( ( ( xInternal == pdFALSE ) || ( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) ) && - ( pxListFindListItemWithValue( pxSocketList, ( TickType_t ) pxAddress->sin_port ) != NULL ) ) - { - FreeRTOS_debug_printf( ( "vSocketBind: %sP port %d in use\n", - pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ? "TC" : "UD", - FreeRTOS_ntohs( pxAddress->sin_port ) ) ); - xReturn = -pdFREERTOS_ERRNO_EADDRINUSE; - } - else - { - /* Allocate the port number to the socket. - This macro will set 'xBoundSocketListItem->xItemValue' */ - socketSET_SOCKET_PORT( pxSocket, pxAddress->sin_port ); + /* Check to ensure the port is not already in use. If the bind is + called internally, a port MAY be used by more than one socket. */ + if( ( ( xInternal == pdFALSE ) || ( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) ) && + ( pxListFindListItemWithValue( pxSocketList, ( TickType_t ) pxAddress->sin_port ) != NULL ) ) + { + FreeRTOS_debug_printf( ( "vSocketBind: %sP port %d in use\n", + ( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ) ? "TC" : "UD", + FreeRTOS_ntohs( pxAddress->sin_port ) ) ); + xReturn = -pdFREERTOS_ERRNO_EADDRINUSE; + } + else + { + /* Allocate the port number to the socket. + This macro will set 'xBoundSocketListItem->xItemValue' */ + socketSET_SOCKET_PORT( pxSocket, pxAddress->sin_port ); - /* And also store it in a socket field 'usLocalPort' in host-byte-order, - mostly used for logging and debugging purposes */ - pxSocket->usLocalPort = FreeRTOS_ntohs( pxAddress->sin_port ); + /* And also store it in a socket field 'usLocalPort' in host-byte-order, + mostly used for logging and debugging purposes */ + pxSocket->usLocalPort = FreeRTOS_ntohs( pxAddress->sin_port ); - /* Add the socket to the list of bound ports. */ - { - /* If the network driver can iterate through 'xBoundUDPSocketsList', - by calling xPortHasUDPSocket() then the IP-task must temporarily - suspend the scheduler to keep the list in a consistent state. */ - #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 ) + /* Add the socket to the list of bound ports. */ { - vTaskSuspendAll(); - } - #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ + /* If the network driver can iterate through 'xBoundUDPSocketsList', + by calling xPortHasUDPSocket() then the IP-task must temporarily + suspend the scheduler to keep the list in a consistent state. */ + #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 ) + { + vTaskSuspendAll(); + } + #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ - /* Add the socket to 'xBoundUDPSocketsList' or 'xBoundTCPSocketsList' */ - vListInsertEnd( pxSocketList, &( pxSocket->xBoundSocketListItem ) ); + /* Add the socket to 'xBoundUDPSocketsList' or 'xBoundTCPSocketsList' */ + vListInsertEnd( pxSocketList, &( pxSocket->xBoundSocketListItem ) ); - #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 ) - { - xTaskResumeAll(); + #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 ) + { + ( void ) xTaskResumeAll(); + } + #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ } - #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ } - } + } while( ipFALSE_BOOL ); } + #if( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND == 0 ) else { xReturn = -pdFREERTOS_ERRNO_EADDRNOTAVAIL; FreeRTOS_debug_printf( ( "vSocketBind: Socket no addr\n" ) ); } + #endif if( xReturn != 0 ) { @@ -1099,7 +1162,7 @@ BaseType_t xResult; #endif IPStackEvent_t xCloseEvent; xCloseEvent.eEventType = eSocketCloseEvent; -xCloseEvent.pvData = ( void * ) xSocket; +xCloseEvent.pvData = xSocket; if( ( xSocket == NULL ) || ( xSocket == FREERTOS_INVALID_SOCKET ) ) { @@ -1165,11 +1228,13 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; /* Free the input and output streams */ if( pxSocket->u.xTCP.rxStream != NULL ) { + iptraceMEM_STATS_DELETE( pxSocket->u.xTCP.rxStream ); vPortFreeLarge( pxSocket->u.xTCP.rxStream ); } if( pxSocket->u.xTCP.txStream != NULL ) { + iptraceMEM_STATS_DELETE( pxSocket->u.xTCP.txStream ); vPortFreeLarge( pxSocket->u.xTCP.txStream ); } @@ -1182,7 +1247,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; /* Socket must be unbound first, to ensure no more packets are queued on it. */ - if( socketSOCKET_IS_BOUND( pxSocket ) != pdFALSE ) + if( socketSOCKET_IS_BOUND( pxSocket ) ) { /* If the network driver can iterate through 'xBoundUDPSocketsList', by calling xPortHasUDPSocket(), then the IP-task must temporarily @@ -1193,11 +1258,11 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; } #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ - uxListRemove( &( pxSocket->xBoundSocketListItem ) ); + ( void ) uxListRemove( &( pxSocket->xBoundSocketListItem ) ); #if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 ) { - xTaskResumeAll(); + ( void ) xTaskResumeAll(); } #endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */ } @@ -1208,13 +1273,13 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; { while( listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) > 0U ) { - pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); - uxListRemove( &( pxNetworkBuffer->xBufferListItem ) ); + pxNetworkBuffer = ipPOINTER_CAST( NetworkBufferDescriptor_t *, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) ); + ( void ) uxListRemove( &( pxNetworkBuffer->xBufferListItem ) ); vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); } } - if( pxSocket->xEventGroup ) + if( pxSocket->xEventGroup != NULL ) { vEventGroupDelete( pxSocket->xEventGroup ); } @@ -1234,9 +1299,10 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; #endif /* ( ipconfigUSE_TCP == 1 ) && ( ipconfigHAS_DEBUG_PRINTF != 0 ) */ /* Anf finally, after all resources have been freed, free the socket space */ + iptraceMEM_STATS_DELETE( pxSocket ); vPortFreeSocket( pxSocket ); - return 0; + return NULL; } /* Tested */ /*-----------------------------------------------------------*/ @@ -1248,28 +1314,28 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; * parent. When a listening parent socket is closed, make sure no child-sockets * keep a pointer to it. */ - static void prvTCPSetSocketCount( FreeRTOS_Socket_t *pxSocketToDelete ) + static void prvTCPSetSocketCount( FreeRTOS_Socket_t const * pxSocketToDelete ) { const ListItem_t *pxIterator; - const MiniListItem_t *pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xBoundTCPSocketsList ); + const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); FreeRTOS_Socket_t *pxOtherSocket; uint16_t usLocalPort = pxSocketToDelete->usLocalPort; - for( pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd ); - pxIterator != ( const ListItem_t * ) pxEnd; - pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) ) + for( pxIterator = listGET_NEXT( pxEnd ); + pxIterator != pxEnd; + pxIterator = listGET_NEXT( pxIterator ) ) { - pxOtherSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator ); - if( ( pxOtherSocket->u.xTCP.ucTCPState == eTCP_LISTEN ) && + pxOtherSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); + if( ( pxOtherSocket->u.xTCP.ucTCPState == ( uint8_t ) eTCP_LISTEN ) && ( pxOtherSocket->usLocalPort == usLocalPort ) && - ( pxOtherSocket->u.xTCP.usChildCount ) ) + ( pxOtherSocket->u.xTCP.usChildCount != 0U ) ) { pxOtherSocket->u.xTCP.usChildCount--; FreeRTOS_debug_printf( ( "Lost: Socket %u now has %u / %u child%s\n", pxOtherSocket->usLocalPort, pxOtherSocket->u.xTCP.usChildCount, pxOtherSocket->u.xTCP.usBacklog, - pxOtherSocket->u.xTCP.usChildCount == 1u ? "" : "ren" ) ); + ( pxOtherSocket->u.xTCP.usChildCount == 1U ) ? "" : "ren" ) ); break; } } @@ -1279,11 +1345,51 @@ NetworkBufferDescriptor_t *pxNetworkBuffer; /*-----------------------------------------------------------*/ -BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, int32_t lLevel, int32_t lOptionName, const void *pvOptionValue, size_t xOptionLength ) +static BaseType_t prvSockopt_so_buffer( FreeRTOS_Socket_t *pxSocket, int32_t lOptionName, const void *pvOptionValue ) +{ +uint32_t ulNewValue; +BaseType_t xReturn; + + if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) + { + FreeRTOS_debug_printf( ( "Set SO_%sBUF: wrong socket type\n", + ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); + xReturn = -pdFREERTOS_ERRNO_EINVAL; + } + else if( ( ( lOptionName == FREERTOS_SO_SNDBUF ) && ( pxSocket->u.xTCP.txStream != NULL ) ) || + ( ( lOptionName == FREERTOS_SO_RCVBUF ) && ( pxSocket->u.xTCP.rxStream != NULL ) ) ) + { + FreeRTOS_debug_printf( ( "Set SO_%sBUF: buffer already created\n", + ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); + xReturn = -pdFREERTOS_ERRNO_EINVAL; + } + else + { + ulNewValue = *( ipPOINTER_CAST( const uint32_t *, pvOptionValue ) ); + + if( lOptionName == FREERTOS_SO_SNDBUF ) + { + /* Round up to nearest MSS size */ + ulNewValue = FreeRTOS_round_up( ulNewValue, ( uint32_t ) pxSocket->u.xTCP.usInitMSS ); + pxSocket->u.xTCP.uxTxStreamSize = ulNewValue; + } + else + { + pxSocket->u.xTCP.uxRxStreamSize = ulNewValue; + } + xReturn = 0; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +/* FreeRTOS_setsockopt calls itself, but in a very limited way, +only when FREERTOS_SO_WIN_PROPERTIES is being set. */ +BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, int32_t lLevel, int32_t lOptionName, const void *pvOptionValue, size_t uxOptionLength ) { /* The standard Berkeley function returns 0 for success. */ BaseType_t xReturn = -pdFREERTOS_ERRNO_EINVAL; -BaseType_t lOptionValue; FreeRTOS_Socket_t *pxSocket; pxSocket = ( FreeRTOS_Socket_t * ) xSocket; @@ -1291,29 +1397,33 @@ FreeRTOS_Socket_t *pxSocket; /* The function prototype is designed to maintain the expected Berkeley sockets standard, but this implementation does not use all the parameters. */ ( void ) lLevel; - ( void ) xOptionLength; - - configASSERT( xSocket ); + ( void ) uxOptionLength; + + if( ( pxSocket == NULL ) || ( pxSocket == FREERTOS_INVALID_SOCKET ) ) + { + xReturn = -pdFREERTOS_ERRNO_EINVAL; + return xReturn; + } switch( lOptionName ) { case FREERTOS_SO_RCVTIMEO : /* Receive time out. */ - pxSocket->xReceiveBlockTime = *( ( TickType_t * ) pvOptionValue ); + pxSocket->xReceiveBlockTime = *( ipPOINTER_CAST( const TickType_t *, pvOptionValue ) ); xReturn = 0; break; case FREERTOS_SO_SNDTIMEO : - pxSocket->xSendBlockTime = *( ( TickType_t * ) pvOptionValue ); + pxSocket->xSendBlockTime = *( ipPOINTER_CAST( const TickType_t *, pvOptionValue ) ); if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_UDP ) { /* The send time out is capped for the reason stated in the comments where ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS is defined in FreeRTOSIPConfig.h (assuming an official configuration file is being used. */ - if( pxSocket->xSendBlockTime > ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) + if( pxSocket->xSendBlockTime > ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ) ) { - pxSocket->xSendBlockTime = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS; + pxSocket->xSendBlockTime = ( ( TickType_t ) ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ); } } else @@ -1324,24 +1434,24 @@ FreeRTOS_Socket_t *pxSocket; } xReturn = 0; break; - #if( ipconfigUDP_MAX_RX_PACKETS > 0 ) + #if( ipconfigUDP_MAX_RX_PACKETS > 0U ) case FREERTOS_SO_UDP_MAX_RX_PACKETS: if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_UDP ) { break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - pxSocket->u.xUDP.uxMaxPackets = *( ( UBaseType_t * ) pvOptionValue ); + pxSocket->u.xUDP.uxMaxPackets = *( ( const UBaseType_t * ) pvOptionValue ); xReturn = 0; break; #endif /* ipconfigUDP_MAX_RX_PACKETS */ case FREERTOS_SO_UDPCKSUM_OUT : - /* Turn calculating of the UDP checksum on/off for this socket. */ - lOptionValue = ( BaseType_t ) pvOptionValue; + /* Turn calculating of the UDP checksum on/off for this socket. If pvOptionValue + * is anything else than NULL, the checksum generation will be turned on. */ - if( lOptionValue == 0 ) + if( pvOptionValue == NULL ) { - pxSocket->ucSocketOptions &= ( uint8_t ) ~FREERTOS_SO_UDPCKSUM_OUT; + pxSocket->ucSocketOptions &= ~( ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT ); } else { @@ -1388,22 +1498,23 @@ FreeRTOS_Socket_t *pxSocket; { #if ipconfigUSE_TCP == 1 case FREERTOS_SO_TCP_CONN_HANDLER: - pxSocket->u.xTCP.pxHandleConnected = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnTCPConnected; + pxSocket->u.xTCP.pxHandleConnected = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPConnected; break; case FREERTOS_SO_TCP_RECV_HANDLER: - pxSocket->u.xTCP.pxHandleReceive = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnTCPReceive; + pxSocket->u.xTCP.pxHandleReceive = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPReceive; break; case FREERTOS_SO_TCP_SENT_HANDLER: - pxSocket->u.xTCP.pxHandleSent = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnTCPSent; + pxSocket->u.xTCP.pxHandleSent = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPSent; break; #endif /* ipconfigUSE_TCP */ case FREERTOS_SO_UDP_RECV_HANDLER: - pxSocket->u.xUDP.pxHandleReceive = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnUDPReceive; + pxSocket->u.xUDP.pxHandleReceive = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnUDPReceive; break; case FREERTOS_SO_UDP_SENT_HANDLER: - pxSocket->u.xUDP.pxHandleSent = ((F_TCP_UDP_Handler_t *)pvOptionValue)->pxOnUDPSent; + pxSocket->u.xUDP.pxHandleSent = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnUDPSent; break; default: + /* Should it throw an error here? */ break; } } @@ -1418,9 +1529,9 @@ FreeRTOS_Socket_t *pxSocket; sleeps. */ case FREERTOS_SO_SET_SEMAPHORE: { - pxSocket->pxUserSemaphore = *( ( SemaphoreHandle_t * ) pvOptionValue ); - xReturn = 0; + pxSocket->pxUserSemaphore = *( ipPOINTER_CAST( SemaphoreHandle_t *, pvOptionValue ) ); } + xReturn = 0; break; #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */ @@ -1430,7 +1541,8 @@ FreeRTOS_Socket_t *pxSocket; /* Each socket can have a callback function that is executed when there is an event the socket's owner might want to process. */ - pxSocket->pxUserWakeCallback = ( SocketWakeupCallback_t ) pvOptionValue; + /* The type cast of the pointer expression "A" to type "B" removes const qualifier from the pointed to type. */ + pxSocket->pxUserWakeCallback = ( const SocketWakeupCallback_t ) pvOptionValue; xReturn = 0; } break; @@ -1438,7 +1550,7 @@ FreeRTOS_Socket_t *pxSocket; case FREERTOS_SO_SET_LOW_HIGH_WATER: { - LowHighWater_t *pxLowHighWater = ( LowHighWater_t * ) pvOptionValue; + const LowHighWater_t *pxLowHighWater = ipPOINTER_CAST( const LowHighWater_t *, pvOptionValue ); if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) { @@ -1464,42 +1576,13 @@ FreeRTOS_Socket_t *pxSocket; case FREERTOS_SO_SNDBUF: /* Set the size of the send buffer, in units of MSS (TCP only) */ case FREERTOS_SO_RCVBUF: /* Set the size of the receive buffer, in units of MSS (TCP only) */ { - uint32_t ulNewValue; - - if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) - { - FreeRTOS_debug_printf( ( "Set SO_%sBUF: wrong socket type\n", - ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); - break; /* will return -pdFREERTOS_ERRNO_EINVAL */ - } - - if( ( ( lOptionName == FREERTOS_SO_SNDBUF ) && ( pxSocket->u.xTCP.txStream != NULL ) ) || - ( ( lOptionName == FREERTOS_SO_RCVBUF ) && ( pxSocket->u.xTCP.rxStream != NULL ) ) ) - { - FreeRTOS_debug_printf( ( "Set SO_%sBUF: buffer already created\n", - ( lOptionName == FREERTOS_SO_SNDBUF ) ? "SND" : "RCV" ) ); - break; /* will return -pdFREERTOS_ERRNO_EINVAL */ - } - - ulNewValue = *( ( uint32_t * ) pvOptionValue ); - - if( lOptionName == FREERTOS_SO_SNDBUF ) - { - /* Round up to nearest MSS size */ - ulNewValue = FreeRTOS_round_up( ulNewValue, ( uint32_t ) pxSocket->u.xTCP.usInitMSS ); - pxSocket->u.xTCP.uxTxStreamSize = ulNewValue; - } - else - { - pxSocket->u.xTCP.uxRxStreamSize = ulNewValue; - } + xReturn = prvSockopt_so_buffer( pxSocket, lOptionName, pvOptionValue ); } - xReturn = 0; break; case FREERTOS_SO_WIN_PROPERTIES: /* Set all buffer and window properties in one call, parameter is pointer to WinProperties_t */ { - WinProperties_t* pxProps; + const WinProperties_t* pxProps; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) { @@ -1513,16 +1596,18 @@ FreeRTOS_Socket_t *pxSocket; break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - pxProps = ( ( WinProperties_t * ) pvOptionValue ); + pxProps = ipPOINTER_CAST( const WinProperties_t *, pvOptionValue ); - if ( FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDBUF, &( pxProps->lTxBufSize ), sizeof( pxProps->lTxBufSize ) ) != 0 ) + xReturn = prvSockopt_so_buffer( pxSocket, FREERTOS_SO_SNDBUF, &( pxProps->lTxBufSize ) ); + if ( xReturn != 0 ) { - break; /* will return -pdFREERTOS_ERRNO_EINVAL */ + break; /* will return an error. */ } - if ( FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVBUF, &( pxProps->lRxBufSize ), sizeof( pxProps->lRxBufSize ) ) != 0 ) + xReturn = prvSockopt_so_buffer( pxSocket, FREERTOS_SO_RCVBUF, &( pxProps->lRxBufSize ) ); + if ( xReturn != 0 ) { - break; /* will return -pdFREERTOS_ERRNO_EINVAL */ + break; /* will return an error. */ } #if( ipconfigUSE_TCP_WIN == 1 ) @@ -1532,8 +1617,8 @@ FreeRTOS_Socket_t *pxSocket; } #else { - pxSocket->u.xTCP.uxRxWinSize = 1u; - pxSocket->u.xTCP.uxTxWinSize = 1u; + pxSocket->u.xTCP.uxRxWinSize = 1U; + pxSocket->u.xTCP.uxTxWinSize = 1U; } #endif @@ -1555,13 +1640,13 @@ FreeRTOS_Socket_t *pxSocket; { break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - if( *( ( BaseType_t * ) pvOptionValue ) != 0 ) + if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) { - pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE_UNSIGNED; + pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE; } else { - pxSocket->u.xTCP.bits.bReuseSocket = pdFALSE_UNSIGNED; + pxSocket->u.xTCP.bits.bReuseSocket = pdFALSE; } } xReturn = 0; @@ -1574,13 +1659,13 @@ FreeRTOS_Socket_t *pxSocket; break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - if( *( ( BaseType_t * ) pvOptionValue ) != 0 ) + if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) { - pxSocket->u.xTCP.bits.bCloseAfterSend = pdTRUE_UNSIGNED; + pxSocket->u.xTCP.bits.bCloseAfterSend = pdTRUE; } else { - pxSocket->u.xTCP.bits.bCloseAfterSend = pdFALSE_UNSIGNED; + pxSocket->u.xTCP.bits.bCloseAfterSend = pdFALSE; } } xReturn = 0; @@ -1593,21 +1678,21 @@ FreeRTOS_Socket_t *pxSocket; break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - if( *( ( BaseType_t * ) pvOptionValue ) != 0 ) + if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) { - pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED; + pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdTRUE; } else { - pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdFALSE_UNSIGNED; + pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdFALSE; } if( ( pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize == pdFALSE_UNSIGNED ) && - ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) && + ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eESTABLISHED ) && ( FreeRTOS_outstanding( pxSocket ) != 0 ) ) { - pxSocket->u.xTCP.usTimeout = 1u; /* to set/clear bSendFullSize */ - xSendEventToIPTask( eTCPTimerEvent ); + pxSocket->u.xTCP.usTimeout = 1U; /* to set/clear bSendFullSize */ + ( void ) xSendEventToIPTask( eTCPTimerEvent ); } } xReturn = 0; @@ -1619,19 +1704,18 @@ FreeRTOS_Socket_t *pxSocket; { break; /* will return -pdFREERTOS_ERRNO_EINVAL */ } - - if( *( ( BaseType_t * ) pvOptionValue ) != 0 ) + if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 ) { - pxSocket->u.xTCP.bits.bRxStopped = pdTRUE_UNSIGNED; + pxSocket->u.xTCP.bits.bRxStopped = pdTRUE; } else { - pxSocket->u.xTCP.bits.bRxStopped = pdFALSE_UNSIGNED; + pxSocket->u.xTCP.bits.bRxStopped = pdFALSE; } - pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED; - pxSocket->u.xTCP.usTimeout = 1u; /* to set/clear bRxStopped */ - xSendEventToIPTask( eTCPTimerEvent ); + pxSocket->u.xTCP.bits.bWinChange = pdTRUE; + pxSocket->u.xTCP.usTimeout = 1U; /* to set/clear bRxStopped */ + ( void ) xSendEventToIPTask( eTCPTimerEvent ); } xReturn = 0; break; @@ -1653,7 +1737,7 @@ FreeRTOS_Socket_t *pxSocket; static uint16_t prvGetPrivatePortNumber( BaseType_t xProtocol ) { const uint16_t usEphemeralPortCount = - socketAUTO_PORT_ALLOCATION_MAX_NUMBER - socketAUTO_PORT_ALLOCATION_START_NUMBER + 1; + socketAUTO_PORT_ALLOCATION_MAX_NUMBER - ( socketAUTO_PORT_ALLOCATION_START_NUMBER - 1U ); uint16_t usIterations = usEphemeralPortCount; uint32_t ulRandomSeed = 0; uint16_t usResult = 0; @@ -1704,7 +1788,7 @@ const List_t *pxList; usIterations--; } - while( usIterations > 0 ); + while( usIterations > 0U ); return usResult; } @@ -1719,10 +1803,10 @@ const ListItem_t * pxResult = NULL; if( ( xIPIsNetworkTaskReady() != pdFALSE ) && ( pxList != NULL ) ) { const ListItem_t *pxIterator; - const MiniListItem_t *pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( pxList ); - for( pxIterator = ( const ListItem_t * ) listGET_NEXT( pxEnd ); - pxIterator != ( const ListItem_t * ) pxEnd; - pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) ) + const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t*, listGET_END_MARKER( pxList ) ); + for( pxIterator = listGET_NEXT( pxEnd ); + pxIterator != pxEnd; + pxIterator = listGET_NEXT( pxIterator ) ) { if( listGET_LIST_ITEM_VALUE( pxIterator ) == xWantedItemValue ) { @@ -1751,7 +1835,7 @@ FreeRTOS_Socket_t *pxSocket = NULL; if( pxListItem != NULL ) { /* The owner of the list item is the socket itself. */ - pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxListItem ); + pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxListItem ) ); configASSERT( pxSocket != NULL ); } return pxSocket; @@ -1759,100 +1843,240 @@ FreeRTOS_Socket_t *pxSocket = NULL; /*-----------------------------------------------------------*/ -#if ipconfigINCLUDE_FULL_INET_ADDR == 1 +const char *FreeRTOS_inet_ntoa( uint32_t ulIPAddress, char *pcBuffer ) +{ +socklen_t uxNibble; +socklen_t uxIndex = 0; +const uint8_t *pucAddress = ( const uint8_t * ) &( ulIPAddress ); +const char *pcResult = pcBuffer; +const socklen_t uxSize = 16; + +/* Each nibble is expressed in at most 3 digits, like e.g. "192". */ +#define sockDIGIT_COUNT ( 3U ) - uint32_t FreeRTOS_inet_addr( const char * pcIPAddress ) + for( uxNibble = 0; uxNibble < ipSIZE_OF_IPv4_ADDRESS; uxNibble++ ) { - const uint32_t ulDecimalBase = 10u; - uint8_t ucOctet[ socketMAX_IP_ADDRESS_OCTETS ]; - const char *pcPointerOnEntering; - uint32_t ulReturn = 0UL, ulValue; - UBaseType_t uxOctetNumber; - BaseType_t xResult = pdPASS; + uint8_t pucDigits[ sockDIGIT_COUNT ]; + uint8_t ucValue = pucAddress[ uxNibble ]; + socklen_t uxSource = sockDIGIT_COUNT - 1; + socklen_t uxNeeded; - for( uxOctetNumber = 0u; uxOctetNumber < socketMAX_IP_ADDRESS_OCTETS; uxOctetNumber++ ) + for( ;; ) { - ulValue = 0ul; - pcPointerOnEntering = pcIPAddress; - - while( ( *pcIPAddress >= '0' ) && ( *pcIPAddress <= '9' ) ) + pucDigits[ uxSource ] = ucValue % ( uint8_t ) 10U; + ucValue /= ( uint8_t ) 10U; + if( uxSource == 1U ) { - /* Move previous read characters into the next decimal - position. */ - ulValue *= ulDecimalBase; - - /* Add the binary value of the ascii character. */ - ulValue += ( ( uint32_t ) ( *pcIPAddress ) - ( uint32_t ) '0' ); - - /* Move to next character in the string. */ - pcIPAddress++; + break; } + uxSource--; + } + pucDigits[ 0 ] = ucValue; - /* Check characters were read. */ - if( pcIPAddress == pcPointerOnEntering ) + /* Skip leading zeros. */ + for( uxSource = 0; uxSource < ( socklen_t ) ( sockDIGIT_COUNT - 1 ); uxSource++ ) + { + if( pucDigits[ uxSource ] != 0U ) { - xResult = pdFAIL; + break; } + } + /* Write e.g. "192.", which is 3 digits and a dot. */ + uxNeeded = ( ( socklen_t ) sockDIGIT_COUNT - uxSource ) + 1U; + if( ( uxIndex + uxNeeded ) > uxSize ) + { + /* The result won't fit. */ + pcResult = NULL; + break; + } + + for( ; uxSource < ( socklen_t ) sockDIGIT_COUNT; uxSource++ ) + { + pcBuffer[ uxIndex ] = ( char ) ( pucDigits[ uxSource ] + ( char ) '0' ); + uxIndex++; + } + if( uxNibble < ( ipSIZE_OF_IPv4_ADDRESS - 1U ) ) + { + pcBuffer[ uxIndex ] = '.'; + } + else + { + pcBuffer[ uxIndex ] = '\0'; + } + uxIndex++; + } - /* Check the value fits in an 8-bit number. */ - if( ulValue > 0xffUL ) - { - xResult = pdFAIL; - } - else - { - ucOctet[ uxOctetNumber ] = ( uint8_t ) ulValue; + return pcResult; +} +/*-----------------------------------------------------------*/ - /* Check the next character is as expected. */ - if( uxOctetNumber < ( socketMAX_IP_ADDRESS_OCTETS - 1u ) ) - { - if( *pcIPAddress != '.' ) - { - xResult = pdFAIL; - } - else - { - /* Move past the dot. */ - pcIPAddress++; - } - } - } +BaseType_t FreeRTOS_inet_pton( BaseType_t xAddressFamily, const char *pcSource, void *pvDestination ) +{ +BaseType_t xResult; - if( xResult == pdFAIL ) - { - /* No point going on. */ - break; - } + /* Printable string to struct sockaddr. */ + switch( xAddressFamily ) + { + case FREERTOS_AF_INET: + xResult = FreeRTOS_inet_pton4( pcSource, pvDestination ); + break; + default: + xResult = -pdFREERTOS_ERRNO_EAFNOSUPPORT; + break; + } + return xResult; +} +/*-----------------------------------------------------------*/ + +const char *FreeRTOS_inet_ntop( BaseType_t xAddressFamily, const void *pvSource, char *pcDestination, socklen_t uxSize ) +{ +const char *pcResult; + + /* Printable struct sockaddr to string. */ + switch( xAddressFamily ) + { + case FREERTOS_AF_INET: + pcResult = FreeRTOS_inet_ntop4( pvSource, pcDestination, uxSize ); + break; + default: + /* errno should be set to pdFREERTOS_ERRNO_EAFNOSUPPORT. */ + pcResult = NULL; + break; + } + return pcResult; +} +/*-----------------------------------------------------------*/ + +const char *FreeRTOS_inet_ntop4( const void *pvSource, char *pcDestination, socklen_t uxSize ) +{ +uint32_t ulIPAddress; +const char *pcReturn; + + if( uxSize < 16U ) + { + /* There must be space for "255.255.255.255". */ + pcReturn = NULL; + } + else + { + ( void ) memcpy( &( ulIPAddress ), pvSource, sizeof( ulIPAddress ) ); + ( void ) FreeRTOS_inet_ntoa( ulIPAddress, pcDestination ); + pcReturn = pcDestination; + } + return pcReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t FreeRTOS_inet_pton4( const char *pcSource, void *pvDestination ) +{ +const uint32_t ulDecimalBase = 10U; +uint8_t ucOctet[ socketMAX_IP_ADDRESS_OCTETS ]; +uint32_t ulReturn = 0UL, ulValue; +UBaseType_t uxOctetNumber; +BaseType_t xResult = pdPASS; +const char *pcIPAddress = pcSource; + + /* Translate "192.168.2.100" to a 32-bit number, network-endian. */ + for( uxOctetNumber = 0U; uxOctetNumber < socketMAX_IP_ADDRESS_OCTETS; uxOctetNumber++ ) + { + ulValue = 0UL; + + while( ( *pcIPAddress >= '0' ) && ( *pcIPAddress <= '9' ) ) + { + BaseType_t xChar; + /* Move previous read characters into the next decimal + position. */ + ulValue *= ulDecimalBase; + + /* Add the binary value of the ascii character. */ + xChar = ( BaseType_t ) pcIPAddress[ 0 ]; + xChar = xChar - ( BaseType_t ) '0'; + ulValue += ( uint32_t ) xChar; + + /* Move to next character in the string. */ + pcIPAddress++; } - if( *pcIPAddress != ( char ) 0 ) + /* Check characters were read. */ + if( pcIPAddress == pcSource ) { - /* Expected the end of the string. */ xResult = pdFAIL; } - if( uxOctetNumber != socketMAX_IP_ADDRESS_OCTETS ) + /* Check the value fits in an 8-bit number. */ + if( ulValue > 0xffUL ) { - /* Didn't read enough octets. */ xResult = pdFAIL; } + else + { + ucOctet[ uxOctetNumber ] = ( uint8_t ) ulValue; + + /* Check the next character is as expected. */ + if( uxOctetNumber < ( socketMAX_IP_ADDRESS_OCTETS - 1U ) ) + { + if( *pcIPAddress != '.' ) + { + xResult = pdFAIL; + } + else + { + /* Move past the dot. */ + pcIPAddress++; + } + } + } - if( xResult == pdPASS ) + if( xResult == pdFAIL ) { - ulReturn = FreeRTOS_inet_addr_quick( ucOctet[ 0 ], ucOctet[ 1 ], ucOctet[ 2 ], ucOctet[ 3 ] ); + /* No point going on. */ + break; } + } + + if( *pcIPAddress != ( char ) 0 ) + { + /* Expected the end of the string. */ + xResult = pdFAIL; + } + + if( uxOctetNumber != socketMAX_IP_ADDRESS_OCTETS ) + { + /* Didn't read enough octets. */ + xResult = pdFAIL; + } - return ulReturn; + if( xResult == pdPASS ) + { + /* lint: ucOctet has been set because xResult == pdPASS. */ + ulReturn = FreeRTOS_inet_addr_quick( ucOctet[ 0 ], ucOctet[ 1 ], ucOctet[ 2 ], ucOctet[ 3 ] ); } + else + { + ulReturn = 0UL; + } + ( void ) memcpy( pvDestination, &( ulReturn ), sizeof( ulReturn ) ); -#endif /* ipconfigINCLUDE_FULL_INET_ADDR */ + return xResult; +} +/*-----------------------------------------------------------*/ + +uint32_t FreeRTOS_inet_addr( const char * pcIPAddress ) +{ +uint32_t ulReturn = 0UL; + /* inet_pton AF_INET target is a 4-byte 'struct in_addr'. */ + ( void ) FreeRTOS_inet_pton4( pcIPAddress, &( ulReturn ) ); + + return ulReturn; +} /*-----------------------------------------------------------*/ + /* Function to get the local address and IP port */ -size_t FreeRTOS_GetLocalAddress( Socket_t xSocket, struct freertos_sockaddr *pxAddress ) +size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket, struct freertos_sockaddr *pxAddress ) { -FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; +const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; /* IP address of local machine. */ pxAddress->sin_addr = *ipLOCAL_IP_ADDRESS_POINTER; @@ -1873,7 +2097,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { if( pxSocket->pxUserSemaphore != NULL ) { - xSemaphoreGive( pxSocket->pxUserSemaphore ); + ( void ) xSemaphoreGive( pxSocket->pxUserSemaphore ); } } #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */ @@ -1885,30 +2109,30 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) pxSocket->pxUserWakeCallback( pxSocket ); } } - #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */ + #endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */ #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) { if( pxSocket->pxSocketSet != NULL ) { - EventBits_t xSelectBits = ( pxSocket->xEventBits >> SOCKET_EVENT_BIT_COUNT ) & eSELECT_ALL; - if( xSelectBits != 0ul ) + EventBits_t xSelectBits = ( pxSocket->xEventBits >> SOCKET_EVENT_BIT_COUNT ) & ( ( EventBits_t ) eSELECT_ALL ); + if( xSelectBits != 0UL ) { pxSocket->xSocketBits |= xSelectBits; - xEventGroupSetBits( pxSocket->pxSocketSet->xSelectGroup, xSelectBits ); + ( void ) xEventGroupSetBits( pxSocket->pxSocketSet->xSelectGroup, xSelectBits ); } } - pxSocket->xEventBits &= eSOCKET_ALL; + pxSocket->xEventBits &= ( EventBits_t ) eSOCKET_ALL; } #endif /* ipconfigSUPPORT_SELECT_FUNCTION */ - if( ( pxSocket->xEventGroup != NULL ) && ( pxSocket->xEventBits != 0u ) ) + if( ( pxSocket->xEventGroup != NULL ) && ( pxSocket->xEventBits != 0U ) ) { - xEventGroupSetBits( pxSocket->xEventGroup, pxSocket->xEventBits ); + ( void ) xEventGroupSetBits( pxSocket->xEventGroup, pxSocket->xEventBits ); } - pxSocket->xEventBits = 0ul; + pxSocket->xEventBits = 0UL; } /*-----------------------------------------------------------*/ @@ -1918,7 +2142,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* This define makes it possible for network-card drivers to inspect * UDP message and see if there is any UDP socket bound to a given port * number. - * This is probably only usefull in systems with a minimum of RAM and + * This is probably only useful in systems with a minimum of RAM and * when lots of anonymous broadcast messages come in */ BaseType_t xPortHasUDPSocket( uint16_t usPortNr ) @@ -1932,7 +2156,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) xFound = pdTRUE; } } - xTaskResumeAll(); + ( void ) xTaskResumeAll(); return xFound; } @@ -1943,16 +2167,34 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) - static BaseType_t bMayConnect( FreeRTOS_Socket_t *pxSocket ); - static BaseType_t bMayConnect( FreeRTOS_Socket_t *pxSocket ) + static BaseType_t bMayConnect( FreeRTOS_Socket_t const * pxSocket ) { - switch( pxSocket->u.xTCP.ucTCPState ) + BaseType_t xResult; + eIPTCPState_t eState = ipNUMERIC_CAST( eIPTCPState_t, pxSocket->u.xTCP.ucTCPState ); + + switch( eState ) { case eCLOSED: - case eCLOSE_WAIT: return 0; - case eCONNECT_SYN: return -pdFREERTOS_ERRNO_EINPROGRESS; - default: return -pdFREERTOS_ERRNO_EAGAIN; + case eCLOSE_WAIT: + xResult = 0; + break; + case eCONNECT_SYN: + xResult = -pdFREERTOS_ERRNO_EINPROGRESS; + break; + case eTCP_LISTEN: + case eSYN_FIRST: + case eSYN_RECEIVED: + case eESTABLISHED: + case eFIN_WAIT_1: + case eFIN_WAIT_2: + case eCLOSING: + case eLAST_ACK: + case eTIME_WAIT: + default: + xResult = -pdFREERTOS_ERRNO_EAGAIN; + break; } + return xResult; } #endif /* ipconfigUSE_TCP */ @@ -1960,11 +2202,16 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) - static BaseType_t prvTCPConnectStart( FreeRTOS_Socket_t *pxSocket, struct freertos_sockaddr *pxAddress ) + static BaseType_t prvTCPConnectStart( FreeRTOS_Socket_t * pxSocket, struct freertos_sockaddr const * pxAddress ) { BaseType_t xResult = 0; - if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdFALSE ) == pdFALSE ) + if( pxAddress == NULL ) + { + /* NULL address passed to the function. Invalid value. */ + xResult = -pdFREERTOS_ERRNO_EINVAL; + } + else if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdFALSE ) == pdFALSE ) { /* Not a valid socket or wrong type */ xResult = -pdFREERTOS_ERRNO_EBADF; @@ -1974,11 +2221,15 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* The socket is already connected. */ xResult = -pdFREERTOS_ERRNO_EISCONN; } - else if( socketSOCKET_IS_BOUND( pxSocket ) == pdFALSE ) + else if( !socketSOCKET_IS_BOUND( pxSocket ) ) { /* Bind the socket to the port that the client task will send from. Non-standard, so the error returned is that returned by bind(). */ - xResult = FreeRTOS_bind( ( Socket_t ) pxSocket, NULL, 0u ); + xResult = FreeRTOS_bind( pxSocket, NULL, 0U ); + } + else + { + /* The socket is valid, not yet connected, and already bound to a port number. */ } if( xResult == 0 ) @@ -1990,8 +2241,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* Start the connect procedure, kernel will start working on it */ if( xResult == 0 ) { - pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE_UNSIGNED; - pxSocket->u.xTCP.ucRepCount = 0u; + pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; + pxSocket->u.xTCP.ucRepCount = 0U; FreeRTOS_debug_printf( ( "FreeRTOS_connect: %u to %lxip:%u\n", pxSocket->usLocalPort, FreeRTOS_ntohl( pxAddress->sin_addr ), FreeRTOS_ntohs( pxAddress->sin_port ) ) ); @@ -2006,7 +2257,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) vTCPStateChange( pxSocket, eCONNECT_SYN ); /* To start an active connect. */ - pxSocket->u.xTCP.usTimeout = 1u; + pxSocket->u.xTCP.usTimeout = 1U; if( xSendEventToIPTask( eTCPTimerEvent ) != pdPASS ) { @@ -2031,7 +2282,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t* ) xClientSocket; TickType_t xRemainingTime; BaseType_t xTimed = pdFALSE; - BaseType_t xResult; + BaseType_t xResult = -pdFREERTOS_ERRNO_EINVAL; TimeOut_t xTimeOut; ( void ) xAddressLength; @@ -2079,14 +2330,14 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } /* Is it allowed to sleep more? */ - if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) ) + if( xTaskCheckForTimeOut( &xTimeOut, &xRemainingTime ) != pdFALSE ) { xResult = -pdFREERTOS_ERRNO_ETIMEDOUT; break; } /* Go sleeping until we get any down-stream event */ - xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_CONNECT, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); + ( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_CONNECT, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); } } @@ -2115,13 +2366,13 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdTRUE ) == pdFALSE ) { /* Not a valid socket or wrong type */ - pxClientSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET; + pxClientSocket = FREERTOS_INVALID_SOCKET; } else if( ( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) && - ( pxSocket->u.xTCP.ucTCPState != eTCP_LISTEN ) ) + ( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eTCP_LISTEN ) ) { /* Parent socket is not in listening mode */ - pxClientSocket = ( FreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET; + pxClientSocket = FREERTOS_INVALID_SOCKET; } else { @@ -2146,7 +2397,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* Is it still not taken ? */ if( pxClientSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) { - pxClientSocket->u.xTCP.bits.bPassAccept = pdFALSE_UNSIGNED; + pxClientSocket->u.xTCP.bits.bPassAccept = pdFALSE; } else { @@ -2154,7 +2405,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } } } - xTaskResumeAll(); + ( void ) xTaskResumeAll(); if( pxClientSocket != NULL ) { @@ -2182,8 +2433,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* Ask to set an event in 'xEventGroup' as soon as a new client gets connected for this listening socket. */ xAskEvent.eEventType = eTCPAcceptEvent; - xAskEvent.pvData = ( void * ) pxSocket; - xSendEventStructToIPTask( &xAskEvent, portMAX_DELAY ); + xAskEvent.pvData = pxSocket; + ( void ) xSendEventStructToIPTask( &xAskEvent, portMAX_DELAY ); } if( pxClientSocket != NULL ) @@ -2214,11 +2465,11 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } /* Go sleeping until we get any down-stream event */ - xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_ACCEPT, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); + ( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_ACCEPT, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); } } - return ( Socket_t ) pxClientSocket; + return pxClientSocket; } #endif /* ipconfigUSE_TCP */ /*-----------------------------------------------------------*/ @@ -2229,7 +2480,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) * Read incoming data from a TCP socket * Only after the last byte has been read, a close error might be returned */ - BaseType_t FreeRTOS_recv( Socket_t xSocket, void *pvBuffer, size_t xBufferLength, BaseType_t xFlags ) + BaseType_t FreeRTOS_recv( Socket_t xSocket, void *pvBuffer, size_t uxBufferLength, BaseType_t xFlags ) { BaseType_t xByteCount; FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; @@ -2244,6 +2495,12 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { xByteCount = -pdFREERTOS_ERRNO_EINVAL; } + else if( ( ( ( uint32_t ) xFlags & ( uint32_t ) FREERTOS_ZERO_COPY ) != 0U ) && + ( pvBuffer == NULL ) ) + { + /* In zero-copy mode, pvBuffer is a pointer to a pointer ( not NULL ). */ + xByteCount = -pdFREERTOS_ERRNO_EINVAL; + } else { if( pxSocket->u.xTCP.rxStream != NULL ) @@ -2257,7 +2514,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) while( xByteCount == 0 ) { - switch( pxSocket->u.xTCP.ucTCPState ) + switch( ipNUMERIC_CAST( eIPTCPState_t, pxSocket->u.xTCP.ucTCPState ) ) { case eCLOSED: case eCLOSE_WAIT: /* (server + client) waiting for a connection termination request from the local user. */ @@ -2272,10 +2529,23 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { xByteCount = -pdFREERTOS_ERRNO_ENOTCONN; } - /* Call continue to break out of the switch and also the while - loop. */ - continue; + break; + + case eTCP_LISTEN: + case eCONNECT_SYN: + case eSYN_FIRST: + case eSYN_RECEIVED: + case eESTABLISHED: + case eFIN_WAIT_1: + case eFIN_WAIT_2: + case eLAST_ACK: + case eTIME_WAIT: default: + /* Nothing. */ + break; + } + if( xByteCount < 0 ) + { break; } @@ -2289,14 +2559,14 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigSUPPORT_SIGNALS != 0 ) { /* Just check for the interrupt flag. */ - xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_INTR, + xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_INTR, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, socketDONT_BLOCK ); } #endif /* ipconfigSUPPORT_SIGNALS */ break; } - if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 ) + if( ( ( uint32_t ) xFlags & ( uint32_t ) FREERTOS_MSG_DONTWAIT ) != 0U ) { break; } @@ -2316,11 +2586,11 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* Block until there is a down-stream event. */ xEventBits = xEventGroupWaitBits( pxSocket->xEventGroup, - eSOCKET_RECEIVE | eSOCKET_CLOSED | eSOCKET_INTR, + ( EventBits_t ) eSOCKET_RECEIVE | ( EventBits_t ) eSOCKET_CLOSED | ( EventBits_t ) eSOCKET_INTR, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); #if( ipconfigSUPPORT_SIGNALS != 0 ) { - if( ( xEventBits & eSOCKET_INTR ) != 0u ) + if( ( xEventBits & ( EventBits_t ) eSOCKET_INTR ) != 0U ) { break; } @@ -2342,13 +2612,13 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } #if( ipconfigSUPPORT_SIGNALS != 0 ) - if( ( xEventBits & eSOCKET_INTR ) != 0 ) + if( ( xEventBits & ( EventBits_t ) eSOCKET_INTR ) != 0U ) { - if( ( xEventBits & ( eSOCKET_RECEIVE | eSOCKET_CLOSED ) ) != 0 ) + if( ( xEventBits & ( ( EventBits_t ) eSOCKET_RECEIVE | ( EventBits_t ) eSOCKET_CLOSED ) ) != 0U ) { /* Shouldn't have cleared other flags. */ - xEventBits &= ~eSOCKET_INTR; - xEventGroupSetBits( pxSocket->xEventGroup, xEventBits ); + xEventBits &= ~( ( EventBits_t ) eSOCKET_INTR ); + ( void ) xEventGroupSetBits( pxSocket->xEventGroup, xEventBits ); } xByteCount = -pdFREERTOS_ERRNO_EINTR; } @@ -2356,9 +2626,16 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #endif /* ipconfigSUPPORT_SIGNALS */ if( xByteCount > 0 ) { - if( ( xFlags & FREERTOS_ZERO_COPY ) == 0 ) + if( ( ( uint32_t ) xFlags & ( uint32_t ) FREERTOS_ZERO_COPY ) == 0U ) { - xByteCount = ( BaseType_t ) uxStreamBufferGet( pxSocket->u.xTCP.rxStream, 0ul, ( uint8_t * ) pvBuffer, ( size_t ) xBufferLength, ( xFlags & FREERTOS_MSG_PEEK ) != 0 ); + BaseType_t xIsPeek = ( ( ( uint32_t ) xFlags & ( uint32_t ) FREERTOS_MSG_PEEK ) != 0U ) ? 1L : 0L; + + xByteCount = ( BaseType_t ) + uxStreamBufferGet( pxSocket->u.xTCP.rxStream, + 0UL, + ipPOINTER_CAST( uint8_t *, pvBuffer ), + ( size_t ) uxBufferLength, + xIsPeek ); if( pxSocket->u.xTCP.bits.bLowWater != pdFALSE_UNSIGNED ) { /* We had reached the low-water mark, now see if the flag @@ -2367,19 +2644,23 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) if( uxFrontSpace >= pxSocket->u.xTCP.uxEnoughSpace ) { - pxSocket->u.xTCP.bits.bLowWater = pdFALSE_UNSIGNED; - pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED; - pxSocket->u.xTCP.usTimeout = 1u; /* because bLowWater is cleared. */ - xSendEventToIPTask( eTCPTimerEvent ); + pxSocket->u.xTCP.bits.bLowWater = pdFALSE; + pxSocket->u.xTCP.bits.bWinChange = pdTRUE; + pxSocket->u.xTCP.usTimeout = 1U; /* because bLowWater is cleared. */ + ( void ) xSendEventToIPTask( eTCPTimerEvent ); } } } else { /* Zero-copy reception of data: pvBuffer is a pointer to a pointer. */ - xByteCount = ( BaseType_t ) uxStreamBufferGetPtr( pxSocket->u.xTCP.rxStream, (uint8_t **)pvBuffer ); + xByteCount = ( BaseType_t ) uxStreamBufferGetPtr( pxSocket->u.xTCP.rxStream, ipPOINTER_CAST( uint8_t **, pvBuffer ) ); } } + else + { + /* Nothing. */ + } } /* prvValidSocket() */ return xByteCount; @@ -2390,7 +2671,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) - static int32_t prvTCPSendCheck( FreeRTOS_Socket_t *pxSocket, size_t xDataLength ) + static int32_t prvTCPSendCheck( FreeRTOS_Socket_t *pxSocket, size_t uxDataLength ) { int32_t xResult = 1; @@ -2403,9 +2684,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { xResult = -pdFREERTOS_ERRNO_ENOMEM; } - else if( pxSocket->u.xTCP.ucTCPState == eCLOSED || - pxSocket->u.xTCP.ucTCPState == eCLOSE_WAIT || - pxSocket->u.xTCP.ucTCPState == eCLOSING ) + else if( ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCLOSED ) || + ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCLOSE_WAIT ) || + ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCLOSING ) ) { xResult = -pdFREERTOS_ERRNO_ENOTCONN; } @@ -2416,7 +2697,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) Return OK in order not to get closed/deleted too quickly */ xResult = 0; } - else if( xDataLength == 0ul ) + else if( uxDataLength == 0UL ) { /* send() is being called to send zero bytes */ xResult = 0; @@ -2424,13 +2705,17 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) else if( pxSocket->u.xTCP.txStream == NULL ) { /* Create the outgoing stream only when it is needed */ - prvTCPCreateStream( pxSocket, pdFALSE ); + ( void ) prvTCPCreateStream( pxSocket, pdFALSE ); if( pxSocket->u.xTCP.txStream == NULL ) { xResult = -pdFREERTOS_ERRNO_ENOMEM; } } + else + { + /* Nothing. */ + } return xResult; } @@ -2442,10 +2727,10 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* Get a direct pointer to the circular transmit buffer. '*pxLength' will contain the number of bytes that may be written. */ - uint8_t *FreeRTOS_get_tx_head( Socket_t xSocket, BaseType_t *pxLength ) + uint8_t *FreeRTOS_get_tx_head( ConstSocket_t xSocket, BaseType_t *pxLength ) { uint8_t *pucReturn = NULL; - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; StreamBuffer_t *pxBuffer = NULL; *pxLength = 0; @@ -2455,14 +2740,14 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) if( prvValidSocket( pxSocket, FREERTOS_IPPROTO_TCP, pdFALSE ) == pdTRUE ) { pxBuffer = pxSocket->u.xTCP.txStream; - if( pxBuffer != NULL ) - { - BaseType_t xSpace = ( BaseType_t )uxStreamBufferGetSpace( pxBuffer ); - BaseType_t xRemain = ( BaseType_t )( pxBuffer->LENGTH - pxBuffer->uxHead ); + if( pxBuffer != NULL ) + { + BaseType_t xSpace = ( BaseType_t ) uxStreamBufferGetSpace( pxBuffer ); + BaseType_t xRemain = ( BaseType_t ) pxBuffer->LENGTH - ( BaseType_t ) pxBuffer->uxHead; - *pxLength = FreeRTOS_min_BaseType( xSpace, xRemain ); - pucReturn = pxBuffer->ucArray + pxBuffer->uxHead; - } + *pxLength = FreeRTOS_min_BaseType( xSpace, xRemain ); + pucReturn = &( pxBuffer->ucArray[ pxBuffer->uxHead ] ); + } } return pucReturn; @@ -2478,19 +2763,23 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) */ BaseType_t FreeRTOS_send( Socket_t xSocket, const void *pvBuffer, size_t uxDataLength, BaseType_t xFlags ) { - BaseType_t xByteCount; + BaseType_t xByteCount = -pdFREERTOS_ERRNO_EINVAL; BaseType_t xBytesLeft; FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; TickType_t xRemainingTime; BaseType_t xTimed = pdFALSE; TimeOut_t xTimeOut; BaseType_t xCloseAfterSend; + const uint8_t *pucSource = ipPOINTER_CAST( const uint8_t *, pvBuffer ); /* Prevent compiler warnings about unused parameters. The parameter may be used in future versions. */ ( void ) xFlags; - - xByteCount = ( BaseType_t ) prvTCPSendCheck( pxSocket, uxDataLength ); + + if( pvBuffer != NULL ) + { + xByteCount = ( BaseType_t ) prvTCPSendCheck( pxSocket, uxDataLength ); + } if( xByteCount > 0 ) { @@ -2536,28 +2825,28 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* Now suspend the scheduler: sending the last data and setting bCloseRequested must be done together */ vTaskSuspendAll(); - pxSocket->u.xTCP.bits.bCloseRequested = pdTRUE_UNSIGNED; + pxSocket->u.xTCP.bits.bCloseRequested = pdTRUE; } - xByteCount = ( BaseType_t ) uxStreamBufferAdd( pxSocket->u.xTCP.txStream, 0ul, ( const uint8_t * ) pvBuffer, ( size_t ) xByteCount ); + xByteCount = ( BaseType_t ) uxStreamBufferAdd( pxSocket->u.xTCP.txStream, 0UL, pucSource, ( size_t ) xByteCount ); if( xCloseAfterSend != pdFALSE ) { /* Now when the IP-task transmits the data, it will also see that bCloseRequested is true and include the FIN flag to start closure of the connection. */ - xTaskResumeAll(); + ( void ) xTaskResumeAll(); } /* Send a message to the IP-task so it can work on this socket. Data is sent, let the IP-task work on it. */ - pxSocket->u.xTCP.usTimeout = 1u; + pxSocket->u.xTCP.usTimeout = 1U; if( xIsCallingFromIPTask() == pdFALSE ) { /* Only send a TCP timer event when not called from the IP-task. */ - xSendEventToIPTask( eTCPTimerEvent ); + ( void ) xSendEventToIPTask( eTCPTimerEvent ); } xBytesLeft -= xByteCount; @@ -2569,7 +2858,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* As there are still bytes left to be sent, increase the data pointer. */ - pvBuffer = ( void * ) ( ( ( const uint8_t * ) pvBuffer) + xByteCount ); + pucSource = &( pucSource [ xByteCount ] ); } /* Not all bytes have been sent. In case the socket is marked as @@ -2597,7 +2886,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) break; } - if( ( xFlags & FREERTOS_MSG_DONTWAIT ) != 0 ) + if( ( ( uint32_t ) xFlags & ( uint32_t ) FREERTOS_MSG_DONTWAIT ) != 0U ) { break; } @@ -2618,7 +2907,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } /* Go sleeping until down-stream events are received. */ - xEventGroupWaitBits( pxSocket->xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, + ( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_SEND | ( EventBits_t ) eSOCKET_CLOSED, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); xByteCount = ( BaseType_t ) uxStreamBufferGetSpace( pxSocket->u.xTCP.txStream ); @@ -2629,13 +2918,13 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) if( xByteCount == 0 ) { - if( pxSocket->u.xTCP.ucTCPState > eESTABLISHED ) + if( pxSocket->u.xTCP.ucTCPState > ( uint8_t ) eESTABLISHED ) { xByteCount = ( BaseType_t ) -pdFREERTOS_ERRNO_ENOTCONN; } else { - if( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) != pdFALSE ) + if( ipconfigTCP_MAY_LOG_PORT( pxSocket->usLocalPort ) ) { FreeRTOS_debug_printf( ( "FreeRTOS_send: %u -> %lxip:%d: no space\n", pxSocket->usLocalPort, @@ -2672,7 +2961,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP; } - else if( ( pxSocket->u.xTCP.ucTCPState != eCLOSED ) && ( pxSocket->u.xTCP.ucTCPState != eCLOSE_WAIT ) ) + else if( ( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eCLOSED ) && ( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eCLOSE_WAIT ) ) { /* Socket is in a wrong state. */ xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP; @@ -2685,7 +2974,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* This cleaning is necessary only if a listening socket is being reused as it might have had a previous connection. */ - if( pxSocket->u.xTCP.bits.bReuseSocket ) + if( pxSocket->u.xTCP.bits.bReuseSocket != pdFALSE_UNSIGNED ) { if( pxSocket->u.xTCP.rxStream != NULL ) { @@ -2697,13 +2986,13 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) vStreamBufferClear( pxSocket->u.xTCP.txStream ); } - memset( pxSocket->u.xTCP.xPacket.u.ucLastPacket, '\0', sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) ); - memset( &pxSocket->u.xTCP.xTCPWindow, '\0', sizeof( pxSocket->u.xTCP.xTCPWindow ) ); - memset( &pxSocket->u.xTCP.bits, '\0', sizeof( pxSocket->u.xTCP.bits ) ); + ( void ) memset( pxSocket->u.xTCP.xPacket.u.ucLastPacket, 0, sizeof( pxSocket->u.xTCP.xPacket.u.ucLastPacket ) ); + ( void ) memset( &pxSocket->u.xTCP.xTCPWindow, 0, sizeof( pxSocket->u.xTCP.xTCPWindow ) ); + ( void ) memset( &pxSocket->u.xTCP.bits, 0, sizeof( pxSocket->u.xTCP.bits ) ); /* Now set the bReuseSocket flag again, because the bits have just been cleared. */ - pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE_UNSIGNED; + pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE; } vTCPStateChange( pxSocket, eTCP_LISTEN ); @@ -2729,7 +3018,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) supports the listen() operation. */ xResult = -pdFREERTOS_ERRNO_EOPNOTSUPP; } - else if ( pxSocket->u.xTCP.ucTCPState != eESTABLISHED ) + else if ( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eESTABLISHED ) { /*_RB_ Is this comment correct? The socket is not of a type that supports the listen() operation. */ @@ -2740,8 +3029,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) pxSocket->u.xTCP.bits.bUserShutdown = pdTRUE_UNSIGNED; /* Let the IP-task perform the shutdown of the connection. */ - pxSocket->u.xTCP.usTimeout = 1u; - xSendEventToIPTask( eTCPTimerEvent ); + pxSocket->u.xTCP.usTimeout = 1U; + ( void ) xSendEventToIPTask( eTCPTimerEvent ); xResult = 0; } (void) xHow; @@ -2767,25 +3056,25 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) FreeRTOS_Socket_t *pxSocket; TickType_t xShortest = pdMS_TO_TICKS( ( TickType_t ) ipTCP_TIMER_PERIOD_MS ); TickType_t xNow = xTaskGetTickCount(); - static TickType_t xLastTime = 0u; + static TickType_t xLastTime = 0U; TickType_t xDelta = xNow - xLastTime; - ListItem_t* pxEnd = ( ListItem_t * ) listGET_END_MARKER( &xBoundTCPSocketsList ); - ListItem_t *pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); + const ListItem_t* pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); + const ListItem_t *pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); xLastTime = xNow; - if( xDelta == 0u ) + if( xDelta == 0U ) { - xDelta = 1u; + xDelta = 1U; } while( pxIterator != pxEnd ) { - pxSocket = ( FreeRTOS_Socket_t * )listGET_LIST_ITEM_OWNER( pxIterator ); + pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ); /* Sockets with 'tmout == 0' do not need any regular attention. */ - if( pxSocket->u.xTCP.usTimeout == 0u ) + if( pxSocket->u.xTCP.usTimeout == 0U ) { continue; } @@ -2796,13 +3085,14 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } else { - int rc ; - pxSocket->u.xTCP.usTimeout = 0u; - rc = xTCPSocketCheck( pxSocket ); + BaseType_t xRc; + + pxSocket->u.xTCP.usTimeout = 0U; + xRc = xTCPSocketCheck( pxSocket ); /* Within this function, the socket might want to send a delayed ack or send out data or whatever it needs to do. */ - if( rc < 0 ) + if( xRc < 0 ) { /* Continue because the socket was deleted. */ continue; @@ -2812,7 +3102,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* In xEventBits the driver may indicate that the socket has important events for the user. These are only done just before the IP-task goes to sleep. */ - if( pxSocket->xEventBits != 0u ) + if( pxSocket->xEventBits != 0U ) { if( xWillSleep != pdFALSE ) { @@ -2828,7 +3118,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } } - if( ( pxSocket->u.xTCP.usTimeout != 0u ) && ( xShortest > ( TickType_t ) pxSocket->u.xTCP.usTimeout ) ) + if( ( pxSocket->u.xTCP.usTimeout != 0U ) && ( xShortest > ( TickType_t ) pxSocket->u.xTCP.usTimeout ) ) { xShortest = ( TickType_t ) pxSocket->u.xTCP.usTimeout; } @@ -2850,22 +3140,22 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) */ FreeRTOS_Socket_t *pxTCPSocketLookup( uint32_t ulLocalIP, UBaseType_t uxLocalPort, uint32_t ulRemoteIP, UBaseType_t uxRemotePort ) { - ListItem_t *pxIterator; + const ListItem_t *pxIterator; FreeRTOS_Socket_t *pxResult = NULL, *pxListenSocket = NULL; - MiniListItem_t *pxEnd = ( MiniListItem_t* )listGET_END_MARKER( &xBoundTCPSocketsList ); + const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); /* Parameter not yet supported. */ ( void ) ulLocalIP; - for( pxIterator = ( ListItem_t * ) listGET_NEXT( pxEnd ); - pxIterator != ( ListItem_t * ) pxEnd; - pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) ) + for( pxIterator = listGET_NEXT( pxEnd ); + pxIterator != pxEnd; + pxIterator = listGET_NEXT( pxIterator ) ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator ); + FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); if( pxSocket->usLocalPort == ( uint16_t ) uxLocalPort ) { - if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN ) + if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eTCP_LISTEN ) { /* If this is a socket listening to uxLocalPort, remember it in case there is no perfect match. */ @@ -2878,6 +3168,10 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) pxResult = pxSocket; break; } + else + { + /* This 'pxSocket' doesn't match. */ + } } } if( pxResult == NULL ) @@ -2894,11 +3188,12 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /*-----------------------------------------------------------*/ #if( ipconfigUSE_TCP == 1 ) - - const struct xSTREAM_BUFFER *FreeRTOS_get_rx_buf( Socket_t xSocket ) - { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * )xSocket; - struct xSTREAM_BUFFER *pxReturn = NULL; + /* For the web server: borrow the circular Rx buffer for inspection + * HTML driver wants to see if a sequence of 13/10/13/10 is available. */ + const struct xSTREAM_BUFFER *FreeRTOS_get_rx_buf( ConstSocket_t xSocket ) + { + const FreeRTOS_Socket_t * pxSocket = ( const FreeRTOS_Socket_t * )xSocket; + const struct xSTREAM_BUFFER *pxReturn = NULL; /* Confirm that this is a TCP socket before dereferencing structure member pointers. */ @@ -2908,7 +3203,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } return pxReturn; - } + } #endif /* ipconfigUSE_TCP */ /*-----------------------------------------------------------*/ @@ -2927,12 +3222,12 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { uxLength = pxSocket->u.xTCP.uxRxStreamSize; - if( pxSocket->u.xTCP.uxLittleSpace == 0ul ) + if( pxSocket->u.xTCP.uxLittleSpace == 0UL ) { pxSocket->u.xTCP.uxLittleSpace = ( sock20_PERCENT * pxSocket->u.xTCP.uxRxStreamSize ) / sock100_PERCENT; } - if( pxSocket->u.xTCP.uxEnoughSpace == 0ul ) + if( pxSocket->u.xTCP.uxEnoughSpace == 0UL ) { pxSocket->u.xTCP.uxEnoughSpace = ( sock80_PERCENT * pxSocket->u.xTCP.uxRxStreamSize ) / sock100_PERCENT; } @@ -2946,35 +3241,37 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) uxLength += sizeof( size_t ); /* And make the length a multiple of sizeof( size_t ). */ - uxLength &= ~( sizeof( size_t ) - 1u ); + uxLength &= ~( sizeof( size_t ) - 1U ); - uxSize = sizeof( *pxBuffer ) - sizeof( pxBuffer->ucArray ) + uxLength; + uxSize = ( sizeof( *pxBuffer ) + uxLength ) - sizeof( pxBuffer->ucArray ); - pxBuffer = ( StreamBuffer_t * )pvPortMallocLarge( uxSize ); + pxBuffer = ipPOINTER_CAST( StreamBuffer_t *, pvPortMallocLarge( uxSize ) ); if( pxBuffer == NULL ) { FreeRTOS_debug_printf( ( "prvTCPCreateStream: malloc failed\n" ) ); - pxSocket->u.xTCP.bits.bMallocError = pdTRUE_UNSIGNED; + pxSocket->u.xTCP.bits.bMallocError = pdTRUE; vTCPStateChange( pxSocket, eCLOSE_WAIT ); } else { /* Clear the markers of the stream */ - memset( pxBuffer, '\0', sizeof( *pxBuffer ) - sizeof( pxBuffer->ucArray ) ); + ( void ) memset( pxBuffer, 0, sizeof( *pxBuffer ) - sizeof( pxBuffer->ucArray ) ); pxBuffer->LENGTH = ( size_t ) uxLength ; if( xTCPWindowLoggingLevel != 0 ) { - FreeRTOS_debug_printf( ( "prvTCPCreateStream: %cxStream created %lu bytes (total %lu)\n", xIsInputStream ? 'R' : 'T', uxLength, uxSize ) ); + FreeRTOS_debug_printf( ( "prvTCPCreateStream: %cxStream created %u bytes (total %u)\n", ( xIsInputStream != 0 ) ? 'R' : 'T', uxLength, uxSize ) ); } if( xIsInputStream != 0 ) { + iptraceMEM_STATS_CREATE( tcpRX_STREAM_BUFFER, pxBuffer, uxSize ); pxSocket->u.xTCP.rxStream = pxBuffer; } else { + iptraceMEM_STATS_CREATE( tcpTX_STREAM_BUFFER, pxBuffer, uxSize ); pxSocket->u.xTCP.txStream = pxBuffer; } } @@ -2994,9 +3291,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) int32_t lTCPAddRxdata( FreeRTOS_Socket_t *pxSocket, size_t uxOffset, const uint8_t *pcData, uint32_t ulByteCount ) { StreamBuffer_t *pxStream = pxSocket->u.xTCP.rxStream; - int32_t xResult; + int32_t xResult = 0; #if( ipconfigUSE_CALLBACKS == 1 ) - BaseType_t bHasHandler = ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleReceive ); + BaseType_t bHasHandler = ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleReceive ) ? pdTRUE : pdFALSE; const uint8_t *pucBuffer = NULL; #endif /* ipconfigUSE_CALLBACKS */ @@ -3010,44 +3307,46 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) pxStream = prvTCPCreateStream( pxSocket, pdTRUE ); if( pxStream == NULL ) { - return -1; + xResult = -1; } } - #if( ipconfigUSE_CALLBACKS == 1 ) + if( xResult >= 0 ) { - if( ( bHasHandler != pdFALSE ) && ( uxStreamBufferGetSize( pxStream ) == 0u ) && ( uxOffset == 0ul ) && ( pcData != NULL ) ) + #if( ipconfigUSE_CALLBACKS == 1 ) { - /* Data can be passed directly to the user */ - pucBuffer = pcData; + if( ( bHasHandler != pdFALSE ) && ( uxStreamBufferGetSize( pxStream ) == 0U ) && ( uxOffset == 0UL ) && ( pcData != NULL ) ) + { + /* Data can be passed directly to the user */ + pucBuffer = pcData; - /* Zero-copy for call-back: no need to add the bytes to the - stream, only the pointer will be advanced by uxStreamBufferAdd(). */ - pcData = NULL; + pcData = NULL; + } } - } - #endif /* ipconfigUSE_CALLBACKS */ + #endif /* ipconfigUSE_CALLBACKS */ - xResult = ( int32_t ) uxStreamBufferAdd( pxStream, uxOffset, pcData, ( size_t ) ulByteCount ); + xResult = ( int32_t ) uxStreamBufferAdd( pxStream, uxOffset, pcData, ( size_t ) ulByteCount ); - #if( ipconfigHAS_DEBUG_PRINTF != 0 ) - { - if( xResult != ( int32_t ) ulByteCount ) + #if( ipconfigHAS_DEBUG_PRINTF != 0 ) { - FreeRTOS_debug_printf( ( "lTCPAddRxdata: at %ld: %ld/%lu bytes (tail %lu head %lu space %lu front %lu)\n", - uxOffset, xResult, ulByteCount, - pxStream->uxTail, - pxStream->uxHead, - uxStreamBufferFrontSpace( pxStream ), - pxStream->uxFront ) ); + if( xResult != ( int32_t ) ulByteCount ) + { + FreeRTOS_debug_printf( ( "lTCPAddRxdata: at %u: %d/%u bytes (tail %u head %u space %u front %u)\n", + ( UBaseType_t ) uxOffset, + ( BaseType_t ) xResult, + ( UBaseType_t ) ulByteCount, + ( UBaseType_t ) pxStream->uxTail, + ( UBaseType_t ) pxStream->uxHead, + ( UBaseType_t ) uxStreamBufferFrontSpace( pxStream ), + ( UBaseType_t ) pxStream->uxFront ) ); + } } - } - #endif /* ipconfigHAS_DEBUG_PRINTF */ + #endif /* ipconfigHAS_DEBUG_PRINTF */ - if( uxOffset == 0u ) - { - /* Data is being added to rxStream at the head (offs = 0) */ - #if( ipconfigUSE_CALLBACKS == 1 ) + if( uxOffset == 0U ) + { + /* Data is being added to rxStream at the head (offs = 0) */ + #if( ipconfigUSE_CALLBACKS == 1 ) if( bHasHandler != pdFALSE ) { /* The socket owner has installed an OnReceive handler. Pass the @@ -3058,7 +3357,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) uint32_t ulCount; if( pucBuffer != NULL ) { - ucReadPtr = ( uint8_t * )pucBuffer; + ucReadPtr = ipPOINTER_CAST( uint8_t *, pucBuffer ); ulCount = ulByteCount; pucBuffer = NULL; } @@ -3067,44 +3366,45 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) ulCount = ( uint32_t ) uxStreamBufferGetPtr( pxStream, &( ucReadPtr ) ); } - if( ulCount == 0ul ) + if( ulCount == 0UL ) { break; } - pxSocket->u.xTCP.pxHandleReceive( ( Socket_t )pxSocket, ( void* )ucReadPtr, ( size_t ) ulCount ); - uxStreamBufferGet( pxStream, 0ul, NULL, ( size_t ) ulCount, pdFALSE ); + ( void ) pxSocket->u.xTCP.pxHandleReceive( pxSocket, ucReadPtr, ( size_t ) ulCount ); + ( void ) uxStreamBufferGet( pxStream, 0UL, NULL, ( size_t ) ulCount, pdFALSE ); } } else - #endif /* ipconfigUSE_CALLBACKS */ - { - /* See if running out of space. */ - if( pxSocket->u.xTCP.bits.bLowWater == pdFALSE_UNSIGNED ) + #endif /* ipconfigUSE_CALLBACKS */ { - size_t uxFrontSpace = uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream ); - if( uxFrontSpace <= pxSocket->u.xTCP.uxLittleSpace ) + /* See if running out of space. */ + if( pxSocket->u.xTCP.bits.bLowWater == pdFALSE_UNSIGNED ) { - pxSocket->u.xTCP.bits.bLowWater = pdTRUE_UNSIGNED; - pxSocket->u.xTCP.bits.bWinChange = pdTRUE_UNSIGNED; + size_t uxFrontSpace = uxStreamBufferFrontSpace( pxSocket->u.xTCP.rxStream ); + if( uxFrontSpace <= pxSocket->u.xTCP.uxLittleSpace ) + { + pxSocket->u.xTCP.bits.bLowWater = pdTRUE; + pxSocket->u.xTCP.bits.bWinChange = pdTRUE; - /* bLowWater was reached, send the changed window size. */ - pxSocket->u.xTCP.usTimeout = 1u; - xSendEventToIPTask( eTCPTimerEvent ); + /* bLowWater was reached, send the changed window size. */ + pxSocket->u.xTCP.usTimeout = 1U; + ( void ) xSendEventToIPTask( eTCPTimerEvent ); + } } - } - /* New incoming data is available, wake up the user. User's - semaphores will be set just before the IP-task goes asleep. */ - pxSocket->xEventBits |= eSOCKET_RECEIVE; + /* New incoming data is available, wake up the user. User's + semaphores will be set just before the IP-task goes asleep. */ + pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_RECEIVE; - #if ipconfigSUPPORT_SELECT_FUNCTION == 1 - { - if( ( pxSocket->xSelectBits & eSELECT_READ ) != 0 ) + #if ipconfigSUPPORT_SELECT_FUNCTION == 1 { - pxSocket->xEventBits |= ( eSELECT_READ << SOCKET_EVENT_BIT_COUNT ); + if( ( pxSocket->xSelectBits & ( EventBits_t ) eSELECT_READ ) != 0U ) + { + pxSocket->xEventBits |= ( ( ( EventBits_t ) eSELECT_READ ) << SOCKET_EVENT_BIT_COUNT ); + } } + #endif } - #endif } } @@ -3117,9 +3417,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) /* Function to get the remote address and IP port */ - BaseType_t FreeRTOS_GetRemoteAddress( Socket_t xSocket, struct freertos_sockaddr *pxAddress ) + BaseType_t FreeRTOS_GetRemoteAddress( ConstSocket_t xSocket, struct freertos_sockaddr *pxAddress ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xResult; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) @@ -3130,14 +3430,13 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) { /* BSD style sockets communicate IP and port addresses in network byte order. - IP address of remote machine. */ pxAddress->sin_addr = FreeRTOS_htonl ( pxSocket->u.xTCP.ulRemoteIP ); /* Port on remote machine. */ pxAddress->sin_port = FreeRTOS_htons ( pxSocket->u.xTCP.usRemotePort ); - xResult = ( BaseType_t ) sizeof( ( *pxAddress ) ); + xResult = ( BaseType_t ) sizeof( *pxAddress ); } return xResult; @@ -3150,18 +3449,18 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) /* Returns the number of bytes that may be added to txStream */ - BaseType_t FreeRTOS_maywrite( Socket_t xSocket ) + BaseType_t FreeRTOS_maywrite( ConstSocket_t xSocket ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xResult; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) { xResult = -pdFREERTOS_ERRNO_EINVAL; } - else if( pxSocket->u.xTCP.ucTCPState != eESTABLISHED ) + else if( pxSocket->u.xTCP.ucTCPState != ( uint8_t ) eESTABLISHED ) { - if( ( pxSocket->u.xTCP.ucTCPState < eCONNECT_SYN ) || ( pxSocket->u.xTCP.ucTCPState > eESTABLISHED ) ) + if( ( pxSocket->u.xTCP.ucTCPState < ( uint8_t ) eCONNECT_SYN ) || ( pxSocket->u.xTCP.ucTCPState > ( EventBits_t ) eESTABLISHED ) ) { xResult = -1; } @@ -3185,11 +3484,11 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #endif /* ipconfigUSE_TCP */ /*-----------------------------------------------------------*/ -#if( ipconfigUSE_TCP ==1 ) +#if( ipconfigUSE_TCP == 1 ) - BaseType_t FreeRTOS_tx_space( Socket_t xSocket ) + BaseType_t FreeRTOS_tx_space( ConstSocket_t xSocket ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xReturn; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) @@ -3216,9 +3515,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) - BaseType_t FreeRTOS_tx_size( Socket_t xSocket ) + BaseType_t FreeRTOS_tx_size( ConstSocket_t xSocket ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xReturn; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) @@ -3246,9 +3545,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) /* Returns pdTRUE if TCP socket is connected. */ - BaseType_t FreeRTOS_issocketconnected( Socket_t xSocket ) + BaseType_t FreeRTOS_issocketconnected( ConstSocket_t xSocket ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xReturn = pdFALSE; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) @@ -3257,9 +3556,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } else { - if( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) + if( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eESTABLISHED ) { - if( pxSocket->u.xTCP.ucTCPState < eCLOSE_WAIT ) + if( pxSocket->u.xTCP.ucTCPState < ( uint8_t ) eCLOSE_WAIT ) { xReturn = pdTRUE; } @@ -3274,10 +3573,10 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) - /* returns the actual size of MSS being used */ - BaseType_t FreeRTOS_mss( Socket_t xSocket ) + /* Returns the actual size of MSS being used. */ + BaseType_t FreeRTOS_mss( ConstSocket_t xSocket ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xReturn; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) @@ -3300,10 +3599,10 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigUSE_TCP == 1 ) - /* HT: for internal use only: return the connection status */ - BaseType_t FreeRTOS_connstatus( Socket_t xSocket ) + /* For internal use only: return the connection status. */ + BaseType_t FreeRTOS_connstatus( ConstSocket_t xSocket ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xReturn; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) @@ -3312,7 +3611,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } else { - /* Cast it to BaseType_t */ + /* Cast it to BaseType_t. */ xReturn = ( BaseType_t ) ( pxSocket->u.xTCP.ucTCPState ); } @@ -3327,9 +3626,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* * Returns the number of bytes which can be read. */ - BaseType_t FreeRTOS_rx_size( Socket_t xSocket ) + BaseType_t FreeRTOS_rx_size( ConstSocket_t xSocket ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; BaseType_t xReturn; if( pxSocket->ucProtocol != ( uint8_t ) FREERTOS_IPPROTO_TCP ) @@ -3351,6 +3650,24 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #endif /* ipconfigUSE_TCP */ /*-----------------------------------------------------------*/ +#if 0 +BaseType_t FreeRTOS_udp_rx_size( Socket_t xSocket ) +{ + BaseType_t xReturn = 0; + const FreeRTOS_Socket_t *pxSocket = ( const FreeRTOS_Socket_t * ) xSocket; + + if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_UDP ) + { + xReturn = ( BaseType_t ) listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ); + } + else + { + xReturn = -pdFREERTOS_ERRNO_EINVAL; + } + return xReturn; +} +#endif /* 0 */ + #if( ipconfigUSE_TCP == 1 ) void FreeRTOS_netstat( void ) @@ -3362,7 +3679,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) */ xAskEvent.eEventType = eTCPNetStat; xAskEvent.pvData = ( void * ) NULL; - xSendEventStructToIPTask( &xAskEvent, 1000u ); + ( void ) xSendEventStructToIPTask( &xAskEvent, pdMS_TO_TICKS( 1000U ) ); } #endif /* ipconfigUSE_TCP */ @@ -3373,59 +3690,59 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) void vTCPNetStat( void ) { /* Show a simple listing of all created sockets and their connections */ - ListItem_t *pxIterator; + const ListItem_t *pxIterator; BaseType_t count = 0; + size_t uxMinimum = uxGetMinimumFreeNetworkBuffers(); + size_t uxCurrent = uxGetNumberOfFreeNetworkBuffers(); - if( listLIST_IS_INITIALISED( &xBoundTCPSocketsList ) == pdFALSE ) + if( !listLIST_IS_INITIALISED( &xBoundTCPSocketsList ) ) { FreeRTOS_printf( ( "PLUS-TCP not initialized\n" ) ); } else { - FreeRTOS_printf( ( "Prot Port IP-Remote : Port R/T Status Alive tmout Child\n" ) ); - for( pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); - pxIterator != ( ListItem_t * ) listGET_END_MARKER( &xBoundTCPSocketsList ); - pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) ) + const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); + const ListItem_t *pxEndUDP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundUDPSocketsList ) ); + FreeRTOS_printf( ( "Prot Port IP-Remote : Port R/T Status Alive tmout Child\n" ) ); + for( pxIterator = listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); + pxIterator != pxEndTCP; + pxIterator = listGET_NEXT( pxIterator ) ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator ); + const FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( const FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); #if( ipconfigTCP_KEEP_ALIVE == 1 ) TickType_t age = xTaskGetTickCount() - pxSocket->u.xTCP.xLastAliveTime; #else - TickType_t age = 0u; - #endif - #if( ipconfigUSE_CALLBACKS == 1 ) - void *pxHandleReceive = (void*)pxSocket->u.xTCP.pxHandleReceive; - #else - void *pxHandleReceive = (void*)NULL; + TickType_t age = 0U; #endif + char ucChildText[16] = ""; - if (pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN) + if (pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eTCP_LISTEN) { + /* Using function "snprintf". */ const int32_t copied_len = snprintf( ucChildText, sizeof( ucChildText ), " %d/%d", - ( int ) pxSocket->u.xTCP.usChildCount, - ( int ) pxSocket->u.xTCP.usBacklog); + ( int32_t ) pxSocket->u.xTCP.usChildCount, + ( int32_t ) pxSocket->u.xTCP.usBacklog); + ( void )copied_len; /* These should never evaluate to false since the buffers are both shorter than 5-6 characters (<=65535) */ configASSERT( copied_len >= 0 ); - configASSERT( copied_len < sizeof( ucChildText ) ); + configASSERT( copied_len < ( int32_t ) sizeof( ucChildText ) ); } FreeRTOS_printf( ( "TCP %5d %-16lxip:%5d %d/%d %-13.13s %6lu %6u%s\n", pxSocket->usLocalPort, /* Local port on this machine */ pxSocket->u.xTCP.ulRemoteIP, /* IP address of remote machine */ pxSocket->u.xTCP.usRemotePort, /* Port on remote machine */ - pxSocket->u.xTCP.rxStream != NULL, - pxSocket->u.xTCP.txStream != NULL, + ( pxSocket->u.xTCP.rxStream != NULL ) ? 1 : 0, + ( pxSocket->u.xTCP.txStream != NULL ) ? 1 : 0, FreeRTOS_GetTCPStateName( pxSocket->u.xTCP.ucTCPState ), - (age > 999999 ? 999999 : age), /* Format 'age' for printing */ + ( age > 999999u ) ? 999999u : age, /* Format 'age' for printing */ pxSocket->u.xTCP.usTimeout, ucChildText ) ); - /* Remove compiler warnings if FreeRTOS_debug_printf() is not defined. */ - ( void ) pxHandleReceive; count++; } - for( pxIterator = ( ListItem_t * ) listGET_HEAD_ENTRY( &xBoundUDPSocketsList ); - pxIterator != ( ListItem_t * ) listGET_END_MARKER( &xBoundUDPSocketsList ); - pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ) ) + for( pxIterator = listGET_HEAD_ENTRY( &xBoundUDPSocketsList ); + pxIterator != pxEndUDP; + pxIterator = listGET_NEXT( pxIterator ) ) { /* Local port on this machine */ FreeRTOS_printf( ( "UDP Port %5u\n", @@ -3433,11 +3750,11 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) count++; } - FreeRTOS_printf( ( "FreeRTOS_netstat: %lu sockets %lu < %lu < %d buffers free\n", - count, - uxGetMinimumFreeNetworkBuffers( ), - uxGetNumberOfFreeNetworkBuffers( ), - ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ) ); + FreeRTOS_printf( ( "FreeRTOS_netstat: %lu sockets %lu < %lu < %ld buffers free\n", + ( UBaseType_t ) count, + ( UBaseType_t ) uxMinimum, + ( UBaseType_t ) uxCurrent, + ( BaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ) ); } } @@ -3458,27 +3775,26 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) /* These flags will be switched on after checking the socket status. */ EventBits_t xGroupBits = 0; - pxSocketSet->pxSocket = NULL; for( xRound = 0; xRound <= xLastRound; xRound++ ) { const ListItem_t *pxIterator; - const MiniListItem_t *pxEnd; + const ListItem_t *pxEnd; if( xRound == 0 ) { - pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xBoundUDPSocketsList ); + pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundUDPSocketsList ) ); } #if ipconfigUSE_TCP == 1 else { - pxEnd = ( const MiniListItem_t* )listGET_END_MARKER( &xBoundTCPSocketsList ); + pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) ); } #endif /* ipconfigUSE_TCP == 1 */ - for( pxIterator = ( const ListItem_t * ) ( listGET_NEXT( pxEnd ) ); - pxIterator != ( const ListItem_t * ) pxEnd; - pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator ) ) + for( pxIterator = listGET_NEXT( pxEnd ); + pxIterator != pxEnd; + pxIterator = listGET_NEXT( pxIterator ) ) { - FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator ); + FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) ); if( pxSocket->pxSocketSet != pxSocketSet ) { /* Socket does not belong to this select group. */ @@ -3486,90 +3802,94 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) } xSocketBits = 0; - #if( ipconfigUSE_TCP == 1 ) - if( pxSocket->ucProtocol == FREERTOS_IPPROTO_TCP ) - { - /* Check if the socket has already been accepted by the - owner. If not, it is useless to return it from a - select(). */ - BaseType_t bAccepted = pdFALSE; + #if( ipconfigUSE_TCP == 1 ) + if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ) + { + /* Check if the socket has already been accepted by the + owner. If not, it is useless to return it from a + select(). */ + BaseType_t bAccepted = pdFALSE; - if( pxSocket->u.xTCP.bits.bPassQueued == pdFALSE_UNSIGNED ) + if( pxSocket->u.xTCP.bits.bPassQueued == pdFALSE_UNSIGNED ) + { + if( pxSocket->u.xTCP.bits.bPassAccept == pdFALSE_UNSIGNED ) { - if( pxSocket->u.xTCP.bits.bPassAccept == pdFALSE_UNSIGNED ) - { - bAccepted = pdTRUE; - } + bAccepted = pdTRUE; } + } - /* Is the set owner interested in READ events? */ - if( ( pxSocket->xSelectBits & eSELECT_READ ) != 0 ) + /* Is the set owner interested in READ events? */ + if( ( pxSocket->xSelectBits & ( EventBits_t ) eSELECT_READ ) != ( EventBits_t ) 0U ) + { + if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eTCP_LISTEN ) { - if( pxSocket->u.xTCP.ucTCPState == eTCP_LISTEN ) - { - if( ( pxSocket->u.xTCP.pxPeerSocket != NULL ) && ( pxSocket->u.xTCP.pxPeerSocket->u.xTCP.bits.bPassAccept != 0 ) ) - { - xSocketBits |= eSELECT_READ; - } - } - else if( ( pxSocket->u.xTCP.bits.bReuseSocket != pdFALSE_UNSIGNED ) && ( pxSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) ) - { - /* This socket has the re-use flag. After connecting it turns into - aconnected socket. Set the READ event, so that accept() will be called. */ - xSocketBits |= eSELECT_READ; - } - else if( ( bAccepted != 0 ) && ( FreeRTOS_recvcount( pxSocket ) > 0 ) ) + if( ( pxSocket->u.xTCP.pxPeerSocket != NULL ) && ( pxSocket->u.xTCP.pxPeerSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) ) { - xSocketBits |= eSELECT_READ; + xSocketBits |= ( EventBits_t ) eSELECT_READ; } } - /* Is the set owner interested in EXCEPTION events? */ - if( ( pxSocket->xSelectBits & eSELECT_EXCEPT ) != 0 ) + else if( ( pxSocket->u.xTCP.bits.bReuseSocket != pdFALSE_UNSIGNED ) && ( pxSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) ) { - if( ( pxSocket->u.xTCP.ucTCPState == eCLOSE_WAIT ) || ( pxSocket->u.xTCP.ucTCPState == eCLOSED ) ) - { - xSocketBits |= eSELECT_EXCEPT; - } + /* This socket has the re-use flag. After connecting it turns into + aconnected socket. Set the READ event, so that accept() will be called. */ + xSocketBits |= ( EventBits_t ) eSELECT_READ; } - - /* Is the set owner interested in WRITE events? */ - if( ( pxSocket->xSelectBits & eSELECT_WRITE ) != 0 ) + else if( ( bAccepted != 0 ) && ( FreeRTOS_recvcount( pxSocket ) > 0 ) ) { - BaseType_t bMatch = pdFALSE; + xSocketBits |= ( EventBits_t ) eSELECT_READ; + } + else + { + /* Nothing. */ + } + } + /* Is the set owner interested in EXCEPTION events? */ + if( ( pxSocket->xSelectBits & ( EventBits_t ) eSELECT_EXCEPT ) != 0U ) + { + if( ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCLOSE_WAIT ) || ( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCLOSED ) ) + { + xSocketBits |= ( EventBits_t ) eSELECT_EXCEPT; + } + } - if( bAccepted != 0 ) - { - if( FreeRTOS_tx_space( pxSocket ) > 0 ) - { - bMatch = pdTRUE; - } - } + /* Is the set owner interested in WRITE events? */ + if( ( pxSocket->xSelectBits & ( EventBits_t ) eSELECT_WRITE ) != 0U ) + { + BaseType_t bMatch = pdFALSE; - if( bMatch == pdFALSE ) + if( bAccepted != 0 ) + { + if( FreeRTOS_tx_space( pxSocket ) > 0 ) { - if( ( pxSocket->u.xTCP.bits.bConnPrepared != pdFALSE_UNSIGNED ) && - ( pxSocket->u.xTCP.ucTCPState >= eESTABLISHED ) && - ( pxSocket->u.xTCP.bits.bConnPassed == pdFALSE_UNSIGNED ) ) - { - pxSocket->u.xTCP.bits.bConnPassed = pdTRUE_UNSIGNED; - bMatch = pdTRUE; - } + bMatch = pdTRUE; } + } - if( bMatch != pdFALSE ) + if( bMatch == pdFALSE ) + { + if( ( pxSocket->u.xTCP.bits.bConnPrepared != pdFALSE_UNSIGNED ) && + ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eESTABLISHED ) && + ( pxSocket->u.xTCP.bits.bConnPassed == pdFALSE_UNSIGNED ) ) { - xSocketBits |= eSELECT_WRITE; + pxSocket->u.xTCP.bits.bConnPassed = pdTRUE; + bMatch = pdTRUE; } } + + if( bMatch != pdFALSE ) + { + xSocketBits |= ( EventBits_t ) eSELECT_WRITE; + } } - else - #endif /* ipconfigUSE_TCP == 1 */ + } + else + #endif /* ipconfigUSE_TCP == 1 */ { /* Select events for UDP are simpler. */ - if( ( ( pxSocket->xSelectBits & eSELECT_READ ) != 0 ) && + if( ( ( pxSocket->xSelectBits & ( EventBits_t ) eSELECT_READ ) != 0U ) && ( listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) > 0U ) ) { - xSocketBits |= eSELECT_READ; + xSocketBits |= ( EventBits_t ) eSELECT_READ; } /* The WRITE and EXCEPT bits are not used for UDP */ } /* if( pxSocket->ucProtocol == FREERTOS_IPPROTO_TCP ) */ @@ -3588,24 +3908,24 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) xBitsToClear = xEventGroupGetBits( pxSocketSet->xSelectGroup ); /* Now set the necessary bits. */ - xBitsToClear = ( xBitsToClear & ~xGroupBits ) & eSELECT_ALL; + xBitsToClear = ( xBitsToClear & ~xGroupBits ) & ( ( EventBits_t ) eSELECT_ALL ); #if( ipconfigSUPPORT_SIGNALS != 0 ) { /* Maybe the socketset was signalled, but don't clear the 'eSELECT_INTR' bit here, as it will be used and cleared in FreeRTOS_select(). */ - xBitsToClear &= ( EventBits_t ) ~eSELECT_INTR; + xBitsToClear &= ~( ( EventBits_t ) eSELECT_INTR ); } #endif /* ipconfigSUPPORT_SIGNALS */ - if( xBitsToClear != 0 ) + if( xBitsToClear != 0U ) { - xEventGroupClearBits( pxSocketSet->xSelectGroup, xBitsToClear ); + ( void ) xEventGroupClearBits( pxSocketSet->xSelectGroup, xBitsToClear ); } /* Now include eSELECT_CALL_IP to wakeup the caller. */ - xEventGroupSetBits( pxSocketSet->xSelectGroup, xGroupBits | eSELECT_CALL_IP ); + ( void ) xEventGroupSetBits( pxSocketSet->xSelectGroup, xGroupBits | ( EventBits_t ) eSELECT_CALL_IP ); } #endif /* ipconfigSUPPORT_SELECT_FUNCTION == 1 */ @@ -3627,14 +3947,14 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #if( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) if( ( pxSocket->pxSocketSet != NULL ) && ( pxSocket->pxSocketSet->xSelectGroup != NULL ) ) { - xEventGroupSetBits( pxSocket->pxSocketSet->xSelectGroup, eSELECT_INTR ); + ( void ) xEventGroupSetBits( pxSocket->pxSocketSet->xSelectGroup, ( EventBits_t ) eSELECT_INTR ); xReturn = 0; } else #endif /* ipconfigSUPPORT_SELECT_FUNCTION */ if( pxSocket->xEventGroup != NULL ) { - xEventGroupSetBits( pxSocket->xEventGroup, eSOCKET_INTR ); + ( void ) xEventGroupSetBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_INTR ); xReturn = 0; } else @@ -3656,14 +3976,13 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * ) xSocket; BaseType_t xReturn; IPStackEvent_t xEvent; - extern QueueHandle_t xNetworkEventQueue; configASSERT( pxSocket != NULL ); - configASSERT( pxSocket->ucProtocol == FREERTOS_IPPROTO_TCP ); - configASSERT( pxSocket->xEventGroup ); + configASSERT( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ); + configASSERT( pxSocket->xEventGroup != NULL ); xEvent.eEventType = eSocketSignalEvent; - xEvent.pvData = ( void * )pxSocket; + xEvent.pvData = pxSocket; /* The IP-task will call FreeRTOS_SignalSocket for this socket. */ xReturn = xQueueSendToBackFromISR( xNetworkEventQueue, &xEvent, pxHigherPriorityTaskWoken ); @@ -3673,3 +3992,94 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket ) #endif /* ipconfigSUPPORT_SIGNALS */ /*-----------------------------------------------------------*/ + +#if 0 +#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) +struct pollfd { + Socket_t fd; /* file descriptor */ + EventBits_t events; /* requested events */ + EventBits_t revents; /* returned events */ +}; + +typedef BaseType_t nfds_t; + +BaseType_t poll(struct pollfd *fds, nfds_t nfds, BaseType_t timeout); +BaseType_t poll(struct pollfd *fds, nfds_t nfds, BaseType_t timeout) +{ +BaseType_t index; +SocketSelect_t *pxSocketSet = NULL; +BaseType_t xReturn = 0; + + /* See which socket-sets have been created and bound to the sockets involved. */ + for( index = 0; index < nfds; index++ ) + { + FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * )fds[ index ].fd; + + if( pxSocket->pxSocketSet != NULL ) + { + if( pxSocketSet == NULL ) + { + /* Use this socket-set. */ + pxSocketSet = pxSocket->pxSocketSet; + xReturn = 1; + } + else if( pxSocketSet == pxSocket->pxSocketSet ) + { + /* Good: associated with the same socket-set. */ + } + else + { + /* More than one socket-set is found: can not do a select on 2 sets. */ + xReturn = -1; + break; + } + } + } + if( xReturn == 0 ) + { + /* Create a new socket-set, and attach all sockets to it. */ + pxSocketSet = FreeRTOS_CreateSocketSet(); + if( pxSocketSet != NULL ) + { + xReturn = 1; + } + else + { + xReturn = -2; + } + /* Memory leak: when the last socket closes, there is no more reference to + this socket-set. It should be marked as an automatic or anonymous socket-set, + so when closing the last member, its memory will be freed. */ + } + if( xReturn > 0 ) + { + /* Only one socket-set is found. Connect all sockets to this socket-set. */ + for( index = 0; index < nfds; index++ ) + { + FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * )fds[ index ].fd; + EventBits_t xEventBits = fds[ index ].events; + + FreeRTOS_FD_SET( pxSocket, pxSocketSet, xEventBits ); + FreeRTOS_FD_CLR( pxSocket, pxSocketSet, ( EventBits_t ) ~xEventBits ); + } + /* And sleep until an event happens or a time-out. */ + xReturn = FreeRTOS_select( pxSocketSet, timeout ); + + /* Now set the return events, copying from the socked field 'xSocketBits'. */ + for( index = 0; index < nfds; index++ ) + { + FreeRTOS_Socket_t *pxSocket = ( FreeRTOS_Socket_t * )fds[ index ].fd; + + fds[ index ].revents = pxSocket->xSocketBits & ( ( EventBits_t ) eSELECT_ALL ); + } + } + else + { + /* -1: Sockets are connected to different socket sets. */ + /* -2: FreeRTOS_CreateSocketSet() failed. */ + } + return xReturn; +} + +#endif /* ipconfigSUPPORT_SELECT_FUNCTION */ +#endif /* 0 */ |