Skip to content

Commit

Permalink
Remove deprecated ipconfigRAND32 (FreeRTOS#1108)
Browse files Browse the repository at this point in the history
* Remove deprecated ipconfigRAND32

* Uncrustify: triggered by comment.

* Update

* Check for return value

* Uncrustify: triggered by comment.

* Update

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
moninom1 and actions-user authored Nov 1, 2023
1 parent b1cadcc commit f60dd88
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 187 deletions.
32 changes: 12 additions & 20 deletions FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,37 @@ extern void vLoggingPrintf( const char * pcFormatString,

/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN

/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
* then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1

/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )

/* Include support for LLMNR: Link-local Multicast Name Resolution
* (non-Microsoft) */
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigUSE_LLMNR ( 1 )

/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_NBNS ( 1 )

/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket. */
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )

/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
Expand All @@ -115,22 +115,14 @@ extern void vLoggingPrintf( const char * pcFormatString,
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )

/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )

/* ipconfigRAND32() is called by the IP stack to generate random numbers for
* things such as a DHCP transaction number or initial sequence number. Random
* number generation is performed via this macro to allow applications to use their
* own random number generation method. For example, it might be possible to
* generate a random number by sampling noise on an analogue input. */
extern UBaseType_t uxRand();
#define ipconfigRAND32() uxRand()
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )

/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ static void prvMiscInitialisation( void )
( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 1 ] );
( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 2 ] );
( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 3 ] );

FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n",
ulRandomNumbers[ 0 ],
ulRandomNumbers[ 1 ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,37 @@ extern void vLoggingPrintf( const char * pcFormatString,

/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN

/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
* then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1

/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )

/* Include support for LLMNR: Link-local Multicast Name Resolution
* (non-Microsoft) */
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigUSE_LLMNR ( 1 )

/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_NBNS ( 1 )

/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket. */
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )

/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
Expand All @@ -120,22 +120,14 @@ extern void vLoggingPrintf( const char * pcFormatString,
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )

/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )

/* ipconfigRAND32() is called by the IP stack to generate random numbers for
* things such as a DHCP transaction number or initial sequence number. Random
* number generation is performed via this macro to allow applications to use their
* own random number generation method. For example, it might be possible to
* generate a random number by sampling noise on an analogue input. */
extern UBaseType_t uxRand();
#define ipconfigRAND32() uxRand()
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )

/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,40 @@ extern void vLoggingPrintf( const char * pcFormatString,

/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN

/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
* then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1

/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )

/* Include support for LLMNR: Link-local Multicast Name Resolution
* (non-Microsoft) */
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigUSE_LLMNR ( 1 )

/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_NBNS ( 1 )

/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket. */
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 33 )
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 33 )
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )

/* Let DNS wait for 3 seconds for an answer. */
#define ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS pdMS_TO_TICKS( 3000U )
#define ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS pdMS_TO_TICKS( 3000U )

/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
Expand All @@ -104,22 +104,14 @@ extern void vLoggingPrintf( const char * pcFormatString,
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )

/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )

/* ipconfigRAND32() is called by the IP stack to generate random numbers for
* things such as a DHCP transaction number or initial sequence number. Random
* number generation is performed via this macro to allow applications to use their
* own random number generation method. For example, it might be possible to
* generate a random number by sampling noise on an analogue input. */
extern UBaseType_t uxRand();
#define ipconfigRAND32() uxRand()
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )

/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,6 @@ UBaseType_t uxRand( void )
}
/*-----------------------------------------------------------*/

uint32_t uxRand32( void )
{
/* uxRand only returns 15 random bits. Call it 3 times. */
uint32_t ul[ 3 ] = { uxRand(), uxRand(), uxRand() };
uint32_t uxReturn = ul[ 0 ] | ( ul[ 1 ] << 15 ) | ( ul[ 2 ] << 30 );

return uxReturn;
}

static void prvSRand( UBaseType_t ulSeed )
{
/* Utility function to seed the pseudo random number generator. */
Expand All @@ -483,6 +474,7 @@ static void prvSRand( UBaseType_t ulSeed )
static void prvMiscInitialisation( void )
{
time_t xTimeNow;
uint32_t ulRandomNumbers[ 4 ];
uint32_t ulLoggingIPAddress;

ulLoggingIPAddress = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0, configECHO_SERVER_ADDR1, configECHO_SERVER_ADDR2, configECHO_SERVER_ADDR3 );
Expand All @@ -492,7 +484,16 @@ static void prvMiscInitialisation( void )
time( &xTimeNow );
FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\r\n", xTimeNow ) );
prvSRand( ( uint32_t ) xTimeNow );
FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\r\n", ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32() ) );

( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 0 ] );
( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 1 ] );
( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 2 ] );
( void ) xApplicationGetRandomNumber( &ulRandomNumbers[ 3 ] );
FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n",
ulRandomNumbers[ 0 ],
ulRandomNumbers[ 1 ],
ulRandomNumbers[ 2 ],
ulRandomNumbers[ 3 ] ) );
}
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -637,12 +638,16 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
uint32_t ulRandomNumber;

( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;

return uxRand32();
( void ) xApplicationGetRandomNumber( &ulRandomNumber );

return ulRandomNumber;
}
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -930,34 +935,41 @@ static void vDNSEvent( const char * pcName,

static void dns_test( const char * pcHostName )
{
uint32_t ulID = uxRand32();
uint32_t ulID;
BaseType_t rc;

FreeRTOS_dnsclear();

struct freertos_addrinfo xHints;
struct freertos_addrinfo * pxResult = NULL;

memset( &xHints, 0, sizeof xHints );
xHints.ai_family = FREERTOS_AF_INET6;

rc = FreeRTOS_getaddrinfo( pcHostName, NULL, &xHints, &pxResult );

FreeRTOS_printf( ( "Lookup '%s': %d\n", pcHostName, rc ) );

FreeRTOS_dnsclear();
xDNSResult = -2;
rc = FreeRTOS_getaddrinfo_a( pcHostName,
NULL,
&xHints,
&pxResult, /* An allocated struct, containing the results. */
vDNSEvent,
( void * ) ulID,
pdMS_TO_TICKS( 1000U ) );
vTaskDelay( pdMS_TO_TICKS( 1000U ) );
rc = xDNSResult;
FreeRTOS_printf( ( "Lookup '%s': %d\n", pcHostName, rc ) );
/* FreeRTOS_gethostbyname( pcHostName ); */
if( xApplicationGetRandomNumber( &( ulID ) ) != pdFALSE )
{
FreeRTOS_dnsclear();

struct freertos_addrinfo xHints;
struct freertos_addrinfo * pxResult = NULL;

memset( &xHints, 0, sizeof xHints );
xHints.ai_family = FREERTOS_AF_INET6;

rc = FreeRTOS_getaddrinfo( pcHostName, NULL, &xHints, &pxResult );

FreeRTOS_printf( ( "Lookup '%s': %d\n", pcHostName, rc ) );

FreeRTOS_dnsclear();
xDNSResult = -2;
rc = FreeRTOS_getaddrinfo_a( pcHostName,
NULL,
&xHints,
&pxResult, /* An allocated struct, containing the results. */
vDNSEvent,
( void * ) ulID,
pdMS_TO_TICKS( 1000U ) );
vTaskDelay( pdMS_TO_TICKS( 1000U ) );
rc = xDNSResult;
FreeRTOS_printf( ( "Lookup '%s': %d\n", pcHostName, rc ) );
/* FreeRTOS_gethostbyname( pcHostName ); */
}
else
{
FreeRTOS_printf( ( "dns_test: Failed to generate a random SearchID\n" ) );
}
}

void showAddressInfo( struct freertos_addrinfo * pxAddrInfo )
Expand Down
Loading

0 comments on commit f60dd88

Please sign in to comment.