Skip to content

Commit ec6f3d7

Browse files
committed
Sync FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP with the version in GitHub at (23665258cabe49d5d68ba23968b6845a7c80eb34).
Notes: - header has version 2.2.0. - This sync did not bring in ./test directory, though we should. - New NetworkInterfaces are introduced by this merge. - Keil compiler support. - FreeRTOS_IP.h new API xApplicationGetRandomNumber(). - FreeRTOS_IP_Private.h new eIPEvent_t eNetworkTxEvent. - FreeRTOS_Stream_Buffer.h removing static xStreamBufferIsEmpty() and xStreamBufferIsFull(). - FreeRTOSConfigDefaults.h provides default ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS. - other type changes.
1 parent 0c1c85a commit ec6f3d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5661
-1674
lines changed

FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* FreeRTOS+TCP V2.0.11
2+
* FreeRTOS+TCP V2.2.0
33
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -580,15 +580,37 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
580580
}
581581
}
582582
#endif
583+
if( xIsCallingFromIPTask() != 0 )
584+
{
585+
/* Only the IP-task is allowed to call this function directly. */
586+
xNetworkInterfaceOutput( pxNetworkBuffer, pdTRUE );
587+
}
588+
else
589+
{
590+
IPStackEvent_t xSendEvent;
583591

584-
xNetworkInterfaceOutput( pxNetworkBuffer, pdTRUE );
592+
/* Send a message to the IP-task to send this ARP packet. */
593+
xSendEvent.eEventType = eNetworkTxEvent;
594+
xSendEvent.pvData = ( void * ) pxNetworkBuffer;
595+
if( xSendEventStructToIPTask( &xSendEvent, ( TickType_t ) portMAX_DELAY ) == pdFAIL )
596+
{
597+
/* Failed to send the message, so release the network buffer. */
598+
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
599+
}
600+
}
585601
}
586602
}
587603

588604
void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer )
589605
{
590606
ARPPacket_t *pxARPPacket;
591607

608+
/* Buffer allocation ensures that buffers always have space
609+
for an ARP packet. See buffer allocation implementations 1
610+
and 2 under portable/BufferManagement. */
611+
configASSERT( pxNetworkBuffer );
612+
configASSERT( pxNetworkBuffer->xDataLength >= sizeof(ARPPacket_t) );
613+
592614
pxARPPacket = ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
593615

594616
/* memcpy the const part of the header information into the correct

FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* FreeRTOS+TCP V2.0.11
2+
* FreeRTOS+TCP V2.2.0
33
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -84,9 +84,9 @@
8484

8585
/* Offsets into the transmitted DHCP options fields at which various parameters
8686
are located. */
87-
#define dhcpCLIENT_IDENTIFIER_OFFSET ( 5 )
88-
#define dhcpREQUESTED_IP_ADDRESS_OFFSET ( 13 )
89-
#define dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ( 19 )
87+
#define dhcpCLIENT_IDENTIFIER_OFFSET ( 6 )
88+
#define dhcpREQUESTED_IP_ADDRESS_OFFSET ( 14 )
89+
#define dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ( 20 )
9090

9191
/* Values used in the DHCP packets. */
9292
#define dhcpREQUEST_OPCODE ( 1 )
@@ -354,9 +354,7 @@ BaseType_t xGivingUp = pdFALSE;
354354

355355
if( xDHCPData.xDHCPTxPeriod <= ipconfigMAXIMUM_DISCOVER_TX_PERIOD )
356356
{
357-
xDHCPData.ulTransactionId = ipconfigRAND32( );
358-
359-
if( 0 != xDHCPData.ulTransactionId )
357+
if( xApplicationGetRandomNumber( &( xDHCPData.ulTransactionId ) ) != pdFALSE )
360358
{
361359
xDHCPData.xDHCPTxTime = xTaskGetTickCount( );
362360
xDHCPData.xUseBroadcast = !xDHCPData.xUseBroadcast;
@@ -589,10 +587,9 @@ static void prvInitialiseDHCP( void )
589587
/* Initialise the parameters that will be set by the DHCP process. Per
590588
https://www.ietf.org/rfc/rfc2131.txt, Transaction ID should be a random
591589
value chosen by the client. */
592-
xDHCPData.ulTransactionId = ipconfigRAND32();
593590

594591
/* Check for random number generator API failure. */
595-
if( 0 != xDHCPData.ulTransactionId )
592+
if( xApplicationGetRandomNumber( &( xDHCPData.ulTransactionId ) ) != pdFALSE )
596593
{
597594
xDHCPData.xUseBroadcast = 0;
598595
xDHCPData.ulOfferedIPAddress = 0UL;
@@ -604,6 +601,10 @@ static void prvInitialiseDHCP( void )
604601
FreeRTOS_debug_printf( ( "prvInitialiseDHCP: start after %lu ticks\n", dhcpINITIAL_TIMER_PERIOD ) );
605602
vIPReloadDHCPTimer( dhcpINITIAL_TIMER_PERIOD );
606603
}
604+
else
605+
{
606+
/* There was a problem with the randomiser. */
607+
}
607608
}
608609
/*-----------------------------------------------------------*/
609610

@@ -642,8 +643,8 @@ const uint32_t ulMandatoryOptions = 2ul; /* DHCP server address, and the correct
642643
/* Walk through the options until the dhcpOPTION_END_BYTE byte
643644
is found, taking care not to walk off the end of the options. */
644645
pucByte = &( pxDHCPMessage->ucFirstOptionByte );
645-
/* Maintain a pointer to the last valid byte (i.e. not the first
646-
invalid byte). */
646+
/* Maintain a pointer to the last valid byte (i.e. not the first
647+
invalid byte). */
647648
pucLastByte = pucUDPPayload + lBytes - 1;
648649

649650
while( pucByte <= pucLastByte )
@@ -665,7 +666,7 @@ const uint32_t ulMandatoryOptions = 2ul; /* DHCP server address, and the correct
665666
/* Stop if the response is malformed. */
666667
if( pucByte < pucLastByte )
667668
{
668-
/* There are at least two bytes left. */
669+
/* There are at least two bytes left. */
669670
ucLength = pucByte[ 1 ];
670671
pucByte += 2;
671672

@@ -904,7 +905,7 @@ static const uint8_t ucDHCPRequestOptions[] =
904905
dhcpCLIENT_IDENTIFIER_OFFSET, dhcpREQUESTED_IP_ADDRESS_OFFSET and
905906
dhcpDHCP_SERVER_IP_ADDRESS_OFFSET. */
906907
dhcpMESSAGE_TYPE_OPTION_CODE, 1, dhcpMESSAGE_TYPE_REQUEST, /* Message type option. */
907-
dhcpCLIENT_IDENTIFIER_OPTION_CODE, 6, 0, 0, 0, 0, 0, 0, /* Client identifier. */
908+
dhcpCLIENT_IDENTIFIER_OPTION_CODE, 7, 1, 0, 0, 0, 0, 0, 0, /* Client identifier. */
908909
dhcpREQUEST_IP_ADDRESS_OPTION_CODE, 4, 0, 0, 0, 0, /* The IP address being requested. */
909910
dhcpSERVER_IP_ADDRESS_OPTION_CODE, 4, 0, 0, 0, 0, /* The IP address of the DHCP server. */
910911
dhcpOPTION_END_BYTE
@@ -942,7 +943,7 @@ static const uint8_t ucDHCPDiscoverOptions[] =
942943
{
943944
/* Do not change the ordering without also changing dhcpCLIENT_IDENTIFIER_OFFSET. */
944945
dhcpMESSAGE_TYPE_OPTION_CODE, 1, dhcpMESSAGE_TYPE_DISCOVER, /* Message type option. */
945-
dhcpCLIENT_IDENTIFIER_OPTION_CODE, 6, 0, 0, 0, 0, 0, 0, /* Client identifier. */
946+
dhcpCLIENT_IDENTIFIER_OPTION_CODE, 7, 1, 0, 0, 0, 0, 0, 0, /* Client identifier. */
946947
dhcpPARAMETER_REQUEST_OPTION_CODE, 3, dhcpSUBNET_MASK_OPTION_CODE, dhcpGATEWAY_OPTION_CODE, dhcpDNS_SERVER_OPTIONS_CODE, /* Parameter request option. */
947948
dhcpOPTION_END_BYTE
948949
};
@@ -968,13 +969,16 @@ size_t xOptionsLength = sizeof( ucDHCPDiscoverOptions );
968969
static void prvPrepareLinkLayerIPLookUp( void )
969970
{
970971
uint8_t ucLinkLayerIPAddress[ 2 ];
972+
uint32_t ulNumbers[ 2 ];
971973

972974
/* After DHCP has failed to answer, prepare everything to start
973975
trying-out LinkLayer IP-addresses, using the random method. */
974976
xDHCPData.xDHCPTxTime = xTaskGetTickCount();
975977

976-
ucLinkLayerIPAddress[ 0 ] = ( uint8_t )1 + ( uint8_t )( ipconfigRAND32() % 0xFDu ); /* get value 1..254 for IP-address 3rd byte of IP address to try. */
977-
ucLinkLayerIPAddress[ 1 ] = ( uint8_t )1 + ( uint8_t )( ipconfigRAND32() % 0xFDu ); /* get value 1..254 for IP-address 4th byte of IP address to try. */
978+
xApplicationGetRandomNumber( &( ulNumbers[ 0 ] ) );
979+
xApplicationGetRandomNumber( &( ulNumbers[ 1 ] ) );
980+
ucLinkLayerIPAddress[ 0 ] = ( uint8_t )1 + ( uint8_t )( ulNumbers[ 0 ] % 0xFDu ); /* get value 1..254 for IP-address 3rd byte of IP address to try. */
981+
ucLinkLayerIPAddress[ 1 ] = ( uint8_t )1 + ( uint8_t )( ulNumbers[ 1 ] % 0xFDu ); /* get value 1..254 for IP-address 4th byte of IP address to try. */
978982

979983
xNetworkAddressing.ulGatewayAddress = FreeRTOS_htonl( 0xA9FE0203 );
980984

@@ -995,9 +999,15 @@ size_t xOptionsLength = sizeof( ucDHCPDiscoverOptions );
995999
xNetworkAddressing.ulBroadcastAddress = ( xDHCPData.ulOfferedIPAddress & xNetworkAddressing.ulNetMask ) | ~xNetworkAddressing.ulNetMask;
9961000

9971001
/* Close socket to ensure packets don't queue on it. not needed anymore as DHCP failed. but still need timer for ARP testing. */
998-
vSocketClose( xDHCPData.xDHCPSocket );
999-
xDHCPData.xDHCPSocket = NULL;
1000-
xDHCPData.xDHCPTxPeriod = pdMS_TO_TICKS( 3000ul + ( ipconfigRAND32() & 0x3fful ) ); /* do ARP test every (3 + 0-1024mS) seconds. */
1002+
if( xDHCPData.xDHCPSocket != NULL )
1003+
{
1004+
/* Close socket to ensure packets don't queue on it. */
1005+
vSocketClose( xDHCPData.xDHCPSocket );
1006+
xDHCPData.xDHCPSocket = NULL;
1007+
}
1008+
1009+
xApplicationGetRandomNumber( &( ulNumbers[ 0 ] ) );
1010+
xDHCPData.xDHCPTxPeriod = pdMS_TO_TICKS( 3000ul + ( ulNumbers[ 0 ] & 0x3ffuL ) ); /* do ARP test every (3 + 0-1024mS) seconds. */
10011011

10021012
xARPHadIPClash = pdFALSE; /* reset flag that shows if have ARP clash. */
10031013
vARPSendGratuitous();

0 commit comments

Comments
 (0)