[En-Nut-Discussion] DHCP renewal

Joe Doubek jdoubek at control4.com
Sat Jun 19 19:02:57 CEST 2004


Alex, thanks for your reply! I still have been unable to get this to work. Here is my exact
code:

    NutNetLoadConfig("eth0");
    memcpy(confnet.cdn_mac, mac, 6);
    confnet.cdn_cip_addr = confnet.cdn_ip_addr = confnet.cdn_ip_mask = confnet.cdn_gateway = 0;
    NutNetSaveConfig();
    if (NutDhcpIfConfig("eth0", 0, DHCP_TIMEOUT)) 
    {
        debugPrint(("DHCP Server not found...\n"));
        return -1;
    }

I seem to hit the error state every time. It appears for me anyway the problem is in the 
dhcpc.c module. Calling NutDhcpIfConfig() more than once does not appear to provoke the 
currently running DHCP thread (still running from the initial bootup) to do anything. It 
looks like the only way for that thread to come out of the bound state is for the lease 
to expire. For me a quick fix was to add a new state to the DHCP state machine that forces 
the lease to expire on request and lets the state machine renew the lease. I have it so 
DHCP enters that state on any subsequent call to NutDhcpIfConfig() while the thread is 
running.  -Joe



________________________________________
From: en-nut-discussion-bounces at egnite.de [mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Zheng Anding
Sent: Tuesday, June 15, 2004 8:41 PM
To: Ethernut User Chat (English)
Subject: Re: [En-Nut-Discussion] DHCP renewal

Hi Joe,
 
I've almost same codes like yours but mine is working. The differences are:
 
1.Add in NutNetLoadConfig("eth0"); memcpy(confnet.cdn_mac, mac, 6); before your code;
 
2. I reset confnet.cdn_ip_addr = confnet.cdn_cip_addr = confnet.cdn_ip_mask = confnet.cdn_gateway = 0;
 
3. You cann't pass mac to NutDhcpIfConfig or it won't read EEPROM configuration. Check this out: http://www.ethernut.de/api/group__xgDHCPC.html#ga19. Use 0 instead.
 
4. Use long enough DHCP_TIMEOUT. 10sec is good for me.
 
Regards,
Alex



Joe Doubek <jdoubek at control4.com> wrote:
  Can anyone guide me on how I might go about renewing the DHCP address on demand. It appears the NutDhcpIfConfig 
Function looks for both a valid mac and an ip address/mask of zero in EEPROM before it will start the DHCP thread. 
Currently I am attempting something like this, where mac is a valid mac addr:

    confnet.cdn_cip_addr = 0;
    confnet.cdn_ip_mask = 0; 
    NutNetSaveConfig();   /* store an invalid ip addr and mask in EEPROM */
    if (NutDhcpIfConfig("eth0", mac, DHCP_TIMEOUT)) 
    {
        printf("DHCP server not found...\n");
        return -1;
    }

   I do this after I have successfully received a DHCP address and I am just sitting in an idle state. When I do this the DHCP 
thread never appears to attempt to obtain an address (watching ethereal I never see a DHCP discover), and eventually DHCP 
times out. Any ideas?

-Joe


_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion




More information about the En-Nut-Discussion mailing list