FreeRTOS+TCP: How can I switch DHCP on/off at runtime

heinbali01 wrote on Wednesday, February 10, 2016:

The first time this hook gets called it is with eDHCPOffer, which in the
code you suggested did result in the DHCP discover packet to be send at
least once. Does this make sense?

That makes sense.
The library will do at most two call-backs:

    eDHCPOffer:   Driver is about to ask for a DHCP offer
    eDHCPRequest: Driver is about to request DHCP an IP address

If you do not reply eDHCPContinue in the state eDHCPOffer, you will never see the second question eDHCPRequest.

In my applications I’d always return eDHCPContinue to eDHCPOffer because I want to know the values of the other fields (GW, DNS).
Then if the user has indicated to use a fixed IP-address, I’d answer eDHCPStopNoChanges to the second question eDHCPRequest.

Within my vApplicationIPNetworkEventHook(), the code will set the final parameters to work with:

if( ( DHCPIsEnabled == pdFALSE ) || ( DHCPFailed == pdTRUE ) )
{
    FreeRTOS_SetAddressConfiguration(
        &ulIPAddress,
        &ulNetMask,
        &ulGateway,
        &ulDNSAddress);
}

Regards, Hein