/*\r
- * FreeRTOS+TCP 191100 experimental\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ * FreeRTOS+TCP V2.2.0\r
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
*\r
* Permission is hereby granted, free of charge, to any person obtaining a copy of\r
* this software and associated documentation files (the "Software"), to deal in\r
\r
/* Offsets into the transmitted DHCP options fields at which various parameters\r
are located. */\r
-#define dhcpCLIENT_IDENTIFIER_OFFSET ( 5 )\r
-#define dhcpREQUESTED_IP_ADDRESS_OFFSET ( 13 )\r
-#define dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ( 19 )\r
+#define dhcpCLIENT_IDENTIFIER_OFFSET ( 6 )\r
+#define dhcpREQUESTED_IP_ADDRESS_OFFSET ( 14 )\r
+#define dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ( 20 )\r
\r
/* Values used in the DHCP packets. */\r
#define dhcpREQUEST_OPCODE ( 1 )\r
\r
if( xDHCPData.xDHCPTxPeriod <= ipconfigMAXIMUM_DISCOVER_TX_PERIOD )\r
{\r
- xDHCPData.ulTransactionId = ipconfigRAND32( );\r
-\r
- if( 0 != xDHCPData.ulTransactionId )\r
+ if( xApplicationGetRandomNumber( &( xDHCPData.ulTransactionId ) ) != pdFALSE )\r
{\r
xDHCPData.xDHCPTxTime = xTaskGetTickCount( );\r
xDHCPData.xUseBroadcast = !xDHCPData.xUseBroadcast;\r
/* Initialise the parameters that will be set by the DHCP process. Per\r
https://www.ietf.org/rfc/rfc2131.txt, Transaction ID should be a random\r
value chosen by the client. */\r
- xDHCPData.ulTransactionId = ipconfigRAND32();\r
\r
/* Check for random number generator API failure. */\r
- if( 0 != xDHCPData.ulTransactionId )\r
+ if( xApplicationGetRandomNumber( &( xDHCPData.ulTransactionId ) ) != pdFALSE )\r
{\r
xDHCPData.xUseBroadcast = 0;\r
xDHCPData.ulOfferedIPAddress = 0UL;\r
FreeRTOS_debug_printf( ( "prvInitialiseDHCP: start after %lu ticks\n", dhcpINITIAL_TIMER_PERIOD ) );\r
vIPReloadDHCPTimer( dhcpINITIAL_TIMER_PERIOD );\r
}\r
+ else\r
+ {\r
+ /* There was a problem with the randomiser. */\r
+ }\r
}\r
/*-----------------------------------------------------------*/\r
\r
/* Walk through the options until the dhcpOPTION_END_BYTE byte\r
is found, taking care not to walk off the end of the options. */\r
pucByte = &( pxDHCPMessage->ucFirstOptionByte );\r
- /* Maintain a pointer to the last valid byte (i.e. not the first\r
- invalid byte). */\r
+ /* Maintain a pointer to the last valid byte (i.e. not the first\r
+ invalid byte). */\r
pucLastByte = pucUDPPayload + lBytes - 1;\r
\r
while( pucByte <= pucLastByte )\r
/* Stop if the response is malformed. */\r
if( pucByte < pucLastByte )\r
{\r
- /* There are at least two bytes left. */\r
+ /* There are at least two bytes left. */\r
ucLength = pucByte[ 1 ];\r
pucByte += 2;\r
\r
dhcpCLIENT_IDENTIFIER_OFFSET, dhcpREQUESTED_IP_ADDRESS_OFFSET and\r
dhcpDHCP_SERVER_IP_ADDRESS_OFFSET. */\r
dhcpMESSAGE_TYPE_OPTION_CODE, 1, dhcpMESSAGE_TYPE_REQUEST, /* Message type option. */\r
- dhcpCLIENT_IDENTIFIER_OPTION_CODE, 6, 0, 0, 0, 0, 0, 0, /* Client identifier. */\r
+ dhcpCLIENT_IDENTIFIER_OPTION_CODE, 7, 1, 0, 0, 0, 0, 0, 0, /* Client identifier. */\r
dhcpREQUEST_IP_ADDRESS_OPTION_CODE, 4, 0, 0, 0, 0, /* The IP address being requested. */\r
dhcpSERVER_IP_ADDRESS_OPTION_CODE, 4, 0, 0, 0, 0, /* The IP address of the DHCP server. */\r
dhcpOPTION_END_BYTE\r
{\r
/* Do not change the ordering without also changing dhcpCLIENT_IDENTIFIER_OFFSET. */\r
dhcpMESSAGE_TYPE_OPTION_CODE, 1, dhcpMESSAGE_TYPE_DISCOVER, /* Message type option. */\r
- dhcpCLIENT_IDENTIFIER_OPTION_CODE, 6, 0, 0, 0, 0, 0, 0, /* Client identifier. */\r
+ dhcpCLIENT_IDENTIFIER_OPTION_CODE, 7, 1, 0, 0, 0, 0, 0, 0, /* Client identifier. */\r
dhcpPARAMETER_REQUEST_OPTION_CODE, 3, dhcpSUBNET_MASK_OPTION_CODE, dhcpGATEWAY_OPTION_CODE, dhcpDNS_SERVER_OPTIONS_CODE, /* Parameter request option. */\r
dhcpOPTION_END_BYTE\r
};\r
static void prvPrepareLinkLayerIPLookUp( void )\r
{\r
uint8_t ucLinkLayerIPAddress[ 2 ];\r
+ uint32_t ulNumbers[ 2 ];\r
\r
/* After DHCP has failed to answer, prepare everything to start\r
trying-out LinkLayer IP-addresses, using the random method. */\r
xDHCPData.xDHCPTxTime = xTaskGetTickCount();\r
\r
- ucLinkLayerIPAddress[ 0 ] = ( uint8_t )1 + ( uint8_t )( ipconfigRAND32() % 0xFDu ); /* get value 1..254 for IP-address 3rd byte of IP address to try. */\r
- ucLinkLayerIPAddress[ 1 ] = ( uint8_t )1 + ( uint8_t )( ipconfigRAND32() % 0xFDu ); /* get value 1..254 for IP-address 4th byte of IP address to try. */\r
+ xApplicationGetRandomNumber( &( ulNumbers[ 0 ] ) );\r
+ xApplicationGetRandomNumber( &( ulNumbers[ 1 ] ) );\r
+ ucLinkLayerIPAddress[ 0 ] = ( uint8_t )1 + ( uint8_t )( ulNumbers[ 0 ] % 0xFDu ); /* get value 1..254 for IP-address 3rd byte of IP address to try. */\r
+ ucLinkLayerIPAddress[ 1 ] = ( uint8_t )1 + ( uint8_t )( ulNumbers[ 1 ] % 0xFDu ); /* get value 1..254 for IP-address 4th byte of IP address to try. */\r
\r
xNetworkAddressing.ulGatewayAddress = FreeRTOS_htonl( 0xA9FE0203 );\r
\r
xNetworkAddressing.ulBroadcastAddress = ( xDHCPData.ulOfferedIPAddress & xNetworkAddressing.ulNetMask ) | ~xNetworkAddressing.ulNetMask;\r
\r
/* Close socket to ensure packets don't queue on it. not needed anymore as DHCP failed. but still need timer for ARP testing. */\r
- vSocketClose( xDHCPData.xDHCPSocket );\r
- xDHCPData.xDHCPSocket = NULL;\r
- xDHCPData.xDHCPTxPeriod = pdMS_TO_TICKS( 3000ul + ( ipconfigRAND32() & 0x3fful ) ); /* do ARP test every (3 + 0-1024mS) seconds. */\r
+ if( xDHCPData.xDHCPSocket != NULL )\r
+ {\r
+ /* Close socket to ensure packets don't queue on it. */\r
+ vSocketClose( xDHCPData.xDHCPSocket );\r
+ xDHCPData.xDHCPSocket = NULL;\r
+ }\r
+\r
+ xApplicationGetRandomNumber( &( ulNumbers[ 0 ] ) );\r
+ xDHCPData.xDHCPTxPeriod = pdMS_TO_TICKS( 3000ul + ( ulNumbers[ 0 ] & 0x3ffuL ) ); /* do ARP test every (3 + 0-1024mS) seconds. */\r
\r
xARPHadIPClash = pdFALSE; /* reset flag that shows if have ARP clash. */\r
vARPSendGratuitous();\r