From b06d17086118549cc228d6062a3594203474e26e Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Mon, 6 Mar 2023 05:35:32 -0800 Subject: [PATCH] Make static IP address configurable (#947) --- .../FreeRTOS+TCP/plus_tcp_hooks_winsim.c | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c b/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c index 941b051de57..876b656605b 100644 --- a/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c +++ b/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c @@ -160,29 +160,34 @@ void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) void vPlatformInitIpStack( void ) { - UBaseType_t uxRandomNumber; BaseType_t xResult; uint8_t ucIPAddress[ 4 ]; - uint8_t ucNetMask[ 4 ] = { 255, 255, 0, 0 }; - uint8_t ucNullAddress[ 4 ] = { 0, 0, 0, 0 }; + uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 }; uint8_t ucMACAddress[ 6 ]; - - /* Generate a random number */ - uxRandomNumber = uxRand(); - - /* Generate a random MAC address in the reserved range */ - ucMACAddress[ 0 ] = 0x00; - ucMACAddress[ 1 ] = 0x11; - ucMACAddress[ 2 ] = ( uxRandomNumber & 0xFF ); - ucMACAddress[ 3 ] = ( ( uxRandomNumber >> 8 ) & 0xFF ); - ucMACAddress[ 4 ] = ( ( uxRandomNumber >> 16 ) & 0xFF ); - ucMACAddress[ 5 ] = ( ( uxRandomNumber >> 24 ) & 0xFF ); - - /* Assign a link-local address in the 169.254.0.0/16 range */ - ucIPAddress[ 0 ] = 169U; - ucIPAddress[ 1 ] = 254U; - ucIPAddress[ 2 ] = ( ( uxRandomNumber >> 16 ) & 0xFF ); - ucIPAddress[ 3 ] = ( ( uxRandomNumber >> 24 ) & 0xFF ); + uint8_t ucDNSServerAddress[ 4 ]; + uint8_t ucGatewayAddress[ 4 ]; + + ucMACAddress[ 0 ] = configMAC_ADDR0; + ucMACAddress[ 1 ] = configMAC_ADDR1; + ucMACAddress[ 2 ] = configMAC_ADDR2; + ucMACAddress[ 3 ] = configMAC_ADDR3; + ucMACAddress[ 4 ] = configMAC_ADDR4; + ucMACAddress[ 5 ] = configMAC_ADDR5; + + ucIPAddress[ 0 ] = configIP_ADDR0; + ucIPAddress[ 1 ] = configIP_ADDR1; + ucIPAddress[ 2 ] = configIP_ADDR2; + ucIPAddress[ 3 ] = configIP_ADDR3; + + ucDNSServerAddress[ 0 ] = configDNS_SERVER_ADDR0; + ucDNSServerAddress[ 1 ] = configDNS_SERVER_ADDR1; + ucDNSServerAddress[ 2 ] = configDNS_SERVER_ADDR2; + ucDNSServerAddress[ 3 ] = configDNS_SERVER_ADDR3; + + ucGatewayAddress[ 0 ] = configGATEWAY_ADDR0; + ucGatewayAddress[ 1 ] = configGATEWAY_ADDR1; + ucGatewayAddress[ 2 ] = configGATEWAY_ADDR2; + ucGatewayAddress[ 3 ] = configGATEWAY_ADDR3; /* Initialise the network interface.*/ FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\r\n" ) ); @@ -192,7 +197,7 @@ void vPlatformInitIpStack( void ) pxWinPcap_FillInterfaceDescriptor( 0, &( xInterfaces[ 0 ] ) ); /* === End-point 0 === */ - FreeRTOS_FillEndPoint( &( xInterfaces[ 0 ] ), &( xEndPoints[ 0 ] ), ucIPAddress, ucNetMask, ucNullAddress, ucNullAddress, ucMACAddress ); + FreeRTOS_FillEndPoint( &( xInterfaces[ 0 ] ), &( xEndPoints[ 0 ] ), ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress ); #if ( ipconfigUSE_DHCP != 0 ) { /* End-point 0 wants to use DHCPv4. */ @@ -203,7 +208,7 @@ void vPlatformInitIpStack( void ) xResult = FreeRTOS_IPStart(); #else /* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */ - xResult = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucNullAddress, ucNullAddress, ucMACAddress ); + xResult = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress ); #endif /* if defined( FREERTOS_PLUS_TCP_VERSION ) && ( FREERTOS_PLUS_TCP_VERSION >= 10 ) */ configASSERT( xResult == pdTRUE ); @@ -228,4 +233,4 @@ eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase, } #endif -/*-----------------------------------------------------------*/ \ No newline at end of file +/*-----------------------------------------------------------*/