Richard Tenney

Adding DHCP to ColdFire_Lite demo

Discussion created by Richard Tenney on May 27, 2006
Latest reply on Jul 8, 2006 by Eric Gregori
At the recent ColdFire Ethernet Seminar, a ColdFire_Lite program that provided a web server was used as a demo of the M52233DEMO board. It had a fixed IP address of 192.168.1.99. However, there are bits and pieces in the code that almost allow the program to use DHCP to obtain its IP address. Just a few changes are necessary.

The ones below have worked for me, but I have not stress tested them and don't know, for example, what would happen if the DHCP server didn't serve up an IP address.

I'd appreciate any feedback.

In main.c, replace the code used to set the address to 192.168.1.99 to read as follows:

#ifdef DHCP_CLIENT // 24 May 06 -- rlt
// zero out info to be provided by DHCP
netstatic[0].n_ipaddr = (0x00000000);
netstatic[0].n_defgw = (0x00000000);
netstatic[0].snmask = (0x00000000);

/* hardcode FEC IP address for now. We set it in netstatic, and
* Ip startup code will initialize net[] from it.
*/
#elif 1 // EMG 192.168.1.99
// added gateway as 192.168.1.1 to allow pinging beyond LAN
netstatic[0].n_ipaddr = (0xC0A80163);
netstatic[0].n_defgw = (0xC0A80101); // 24 May 06 -- rlt
netstatic[0].snmask = (0xffffff00);
#else //jpw 192.168.2.3
netstatic[0].n_ipaddr = (0xC0A80203);
netstatic[0].n_defgw = (0xC0A80201);
netstatic[0].snmask = (0xffffff00);
#endif // DHCP_CLIENT


In dhcsetup.c, in the dhc_setup() function, just before the test

if (!(nets[iface]->n_flags & NF_DHCPC))
continue;

add

#ifdef DHCP_CLIENT
nets[iface]->n_flags |= NF_DHCPC ; /* use DHCP Client on each iface */ // rlt 26 May 06
#endif

To make this work, you have to uncomment the definition of DHCP_CLIENT in ipport.h to read

#define DHCP_CLIENT 1 /* include DHCP client code */

To restore the project to its original (except for my added 192.168.1.1 gateway) just comment out the #define of DHCP_CLIENT. If you don't want the gateway, change 0xC0A80101 to 0x00000000.

Cheers,
- Richard

P.S. Sorry about the lack of indenting in the code, but that's the way the forum's software formats it.

Outcomes