How can I switch DHCP on/off in runtime

Hello

I use FreeRTOS + FAT with Renesas RA6M3.

I can change DHCP ON/OFF at build project.
#define ipconfigUSE_DHCP 0 or 1

I want to change DHCP ON/OFF in runtime.
Please tell me How to change DHCP ON/OFF.

@taki

You can use the bWantDHCP field inside the bits field of the network endpoint for which you want to turn DHCP on/off.

You can take a look at this example.

If you need even finer control over DHCP, you can take a look at the: xApplicationDHCPHook_Multi, this user implemented hook function is called by the DHCP state machine at multiple phases of the DHCP process. If you wish to stop the DHCP process in the middle for a particular endpoint - pxEndPoint you can make this hook function return - eDHCPUseDefaults, causing the TCP/IP stack to use the static IP settings.

Thank you for reply

I’ll try it.

Is this sample for IPV6?
Can you tell me for IPV4?

The example I linked is an IPv6 + IPv4 demo.
The usage is the same regardless of the IP version.

Here is another example that’s IPv4 only.

Thank you for reply

I will check the sample

Is ipconfigUSE_DHCP_HOOK = 1 correct?
When I changed ipconfigUSE_DHCP_HOOK to 1, many errors occurred.
If you know the cause of the error, please let me know.

If you are using ipconfigUSE_DHCP_HOOK, the application has to define: xApplicationDHCPHook or xApplicationDHCPHook_Multi depending on ipconfigIPv4_BACKWARD_COMPATIBLE.

Example

Thank you

I set ipconfigUSE_DHCP_HOOK to 0

Please tell me
What function is used to obtain an IP address from DHCP?

When DHCP is completed, the vApplicationIPNetworkEventHook is called, which has to be implemented in the application.
You can query the endpoint details using FreeRTOS_GetAddressConfiguration or FreeRTOS_GetEndPointConfiguration depending on ipconfigIPv4_BACKWARD_COMPATIBLE .

Example

Thanks for your reply
I’ll try it out using your example
If I have any questions I’ll ask.