The DHCP protocol allows the client to continue using the IP address for the agreed-upon lease time, regardless of whether the server reboots. If there are any switches between the DHCP client and server, the client has no way of knowing what's going on with the server.
Marc VDH wrote:
The problem is that, when I shut down the router to which the coldfire ethernet link is connected, Coldfire Lite does not automatically request a new IP adress via DHCP after the link comes up again. Instead, it just keeps using it's originally assigned IP address.
What I would like to do is to detect when the link comes up, and then trigger the DHCP client to request a new IP address. I probably have to use dhc_setup() to do this. But I still have to detect when the link comes up somehow...
This appears to be caused by a hard-coded 30 second time-out in dhcsetup.c. I don't know why this strategy was chosen, but I suppose you could modify dhcsetup to do what is appropriate for your situation. For example, if there is no default address to fall back to, get rid of the 30 second limit and stay in dhcsetup indefinitely.
Marc VDH wrote:
For instance, when the coldfire device is not connected to a network at power up, it will not negotiate an IP address with the DHCP server when the physical connection is made.
TK_ENTRY(tk_updateDisplay){ uint16 mymrdata; int iface; linkDownDetect = FALSE; // Wait for TCP/IP stack to init while (!iniche_net_ready) TK_SLEEP(1); // Task's must not return, Infinite loops for (;;) { while(!(fec_mii_read(FEC_PHY0, PHY_REG_PSR, &mymrdata))) // read proprietary status register ; if (mymrdata & PHY_R17_LNK) { linkDownDetect = TRUE; // detect if link is down LCD_Clean (); LCD_String( (unsigned char *)"Link down!" , 1 ); } else { if (linkDownDetect == TRUE) { if( POWERUP_CONFIG_DHCP_ENABLED ) { LCD_Clean (); LCD_String( (unsigned char *)"Restarting DHCP..." , 1 ); for (iface = 0; iface < STATIC_NETS; iface++) dhc_state_init(iface, TRUE); } } linkDownDetect = FALSE; if (decoded) { displayUpdating = TRUE; displayTask(); displayUpdating = FALSE; } } tk_sleep( DISPLAY_REFRESH_TIME ); // Wait DISPLAY_REFRESH_TIME seconds....
: : #ifdef DHCP_CLIENT #include "dhcpclnt.h" #include "nvparms.h" /* For nvparms struct */ #include "netbuf.h" /* To remove warnings for net.h */ #include "net.h" /* For nets[] */ #include "in_utils.h" /* For netexit() */ extern void set_link_down_detect(char link_status); int dhc_main_ipset(int iface, int state); : : : void dhc_setup(void) { int iface; uint16 mymrdata; ulong dhcp_started; ip_addr dhcp_saveaddr[STATIC_NETS]; int e; int dhcnets = 0; /* number of nets doing DHCP */ while(!(fec_mii_read(FEC_PHY0, PHY_REG_PSR, &mymrdata))) // read proprietary status register ; if (mymrdata & PHY_R17_LNK) // detect if link is down set_link_down_detect(TRUE); else set_link_down_detect(FALSE); e = dhc_init(); : :
: : #ifdef TELNET_SVR extern void tel_check(void); #endif unsigned long nextppp = 0L; /* tick for next call to ppp timer */ #ifdef DHCP_CLIENT static char link_down_detect; void set_link_down_detect(char link_status) { link_down_detect = link_status; } char read_link_down_detect(void) { return link_down_detect; } #endif void (*port_1s_callout)(void) = NULL; : : : #ifdef USE_PPP ppp_timeisup(); #endif #ifdef DHCP_CLIENT while(!(fec_mii_read(FEC_PHY0, PHY_REG_PSR, &mymrdata))) // read proprietary status register ; if (mymrdata & PHY_R17_LNK) link_down_detect = TRUE; // detect if link is down else { if (link_down_detect == TRUE) { if( POWERUP_CONFIG_DHCP_ENABLED ) { for (iface = 0; iface < STATIC_NETS; iface++) dhc_state_init(iface, TRUE); } } link_down_detect = FALSE; } dhc_second(); #endif #ifdef DHCP_SERVER dhcp_timeisup(); #endif : :
#ifdef DHCP_CLIENT extern void set_link_down_detect(char link_status); #endif : : : watchdog_timer += UPDATE_TIME; if (watchdog_timer > WATCHDOG_TIMEOUT_TIME) // something wrong with network comm { #ifdef DHCP_CLIENT set_link_down_detect(TRUE); #endif watchdog_timer = 0; }