Line 51... |
Line 51... |
|
|
/* For Debug */
|
/* For Debug */
|
char *dhcpmsg2str(int type)
|
char *dhcpmsg2str(int type)
|
{
|
{
|
switch (type) {
|
switch (type) {
|
case 1: return "DHCPDISCOVER"; break;
|
case 1:
|
case 2: return "DHCPOFFER"; break;
|
return "DHCPDISCOVER";
|
case 3: return "DHCPREQUEST"; break;
|
break;
|
case 4: return "DHCPDECLINE"; break;
|
case 2:
|
case 5: return "DHCPACK"; break;
|
return "DHCPOFFER";
|
case 6: return "DHCPNACK"; break;
|
break;
|
case 7: return "DHCPRELEASE"; break;
|
case 3:
|
default: return "UNKNOWN/INVALID MSG TYPE"; break;
|
return "DHCPREQUEST";
|
|
break;
|
|
case 4:
|
|
return "DHCPDECLINE";
|
|
break;
|
|
case 5:
|
|
return "DHCPACK";
|
|
break;
|
|
case 6:
|
|
return "DHCPNACK";
|
|
break;
|
|
case 7:
|
|
return "DHCPRELEASE";
|
|
break;
|
|
default:
|
|
return "UNKNOWN/INVALID MSG TYPE";
|
|
break;
|
}
|
}
|
}
|
}
|
|
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */
|
extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */
|
Line 81... |
Line 97... |
if (len < sizeof (Bootp_t) - OPT_SIZE)
|
if (len < sizeof (Bootp_t) - OPT_SIZE)
|
retval = -2;
|
retval = -2;
|
if (bp->bp_op != OP_BOOTREQUEST &&
|
if (bp->bp_op != OP_BOOTREQUEST &&
|
bp->bp_op != OP_BOOTREPLY &&
|
bp->bp_op != OP_BOOTREPLY &&
|
bp->bp_op != DHCP_OFFER &&
|
bp->bp_op != DHCP_OFFER &&
|
bp->bp_op != DHCP_ACK &&
|
bp->bp_op != DHCP_ACK && bp->bp_op != DHCP_NAK) {
|
bp->bp_op != DHCP_NAK ) {
|
|
retval = -3;
|
retval = -3;
|
}
|
}
|
if (bp->bp_htype != HWT_ETHER)
|
if (bp->bp_htype != HWT_ETHER)
|
retval = -4;
|
retval = -4;
|
if (bp->bp_hlen != HWL_ETHER)
|
if (bp->bp_hlen != HWL_ETHER)
|
Line 121... |
Line 136... |
}
|
}
|
|
|
static int truncate_sz (const char *name, int maxlen, int curlen)
|
static int truncate_sz (const char *name, int maxlen, int curlen)
|
{
|
{
|
if (curlen >= maxlen) {
|
if (curlen >= maxlen) {
|
printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
|
printf
|
|
("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
|
name, curlen, maxlen);
|
name, curlen, maxlen);
|
curlen = maxlen - 1;
|
curlen = maxlen - 1;
|
}
|
}
|
return (curlen);
|
return (curlen);
|
}
|
}
|
Line 134... |
Line 150... |
|
|
static void BootpVendorFieldProcess(u8 *ext)
|
static void BootpVendorFieldProcess(u8 *ext)
|
{
|
{
|
int size = *(ext+1) ;
|
int size = *(ext+1) ;
|
|
|
debug_ext ("[BOOTP] Processing extension %d... (%d bytes)\n", *ext, *(ext+1));
|
debug_ext("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
|
|
*(ext + 1));
|
|
|
NetBootFileSize = 0;
|
NetBootFileSize = 0;
|
|
|
switch (*ext) {
|
switch (*ext) {
|
/* Fixed length fields */
|
/* Fixed length fields */
|
Line 173... |
Line 190... |
break;
|
break;
|
case 11: /* RPL server - Not yet supported */
|
case 11: /* RPL server - Not yet supported */
|
break;
|
break;
|
case 12: /* Host name */
|
case 12: /* Host name */
|
if (NetOurHostName[0] == 0) {
|
if (NetOurHostName[0] == 0) {
|
size = truncate_sz("Host Name", sizeof(NetOurHostName), size);
|
size =
|
|
truncate_sz("Host Name", sizeof(NetOurHostName),
|
|
size);
|
memcpy(&NetOurHostName, ext+2, size);
|
memcpy(&NetOurHostName, ext+2, size);
|
NetOurHostName[size] = 0 ;
|
NetOurHostName[size] = 0 ;
|
}
|
}
|
break;
|
break;
|
case 13: /* Boot file size */
|
case 13: /* Boot file size */
|
Line 189... |
Line 208... |
break;
|
break;
|
case 16: /* Swap server - Not yet supported */
|
case 16: /* Swap server - Not yet supported */
|
break;
|
break;
|
case 17: /* Root path */
|
case 17: /* Root path */
|
if (NetOurRootPath[0] == 0) {
|
if (NetOurRootPath[0] == 0) {
|
size = truncate_sz("Root Path", sizeof(NetOurRootPath), size);
|
size =
|
|
truncate_sz("Root Path", sizeof(NetOurRootPath),
|
|
size);
|
memcpy(&NetOurRootPath, ext+2, size);
|
memcpy(&NetOurRootPath, ext+2, size);
|
NetOurRootPath[size] = 0 ;
|
NetOurRootPath[size] = 0 ;
|
}
|
}
|
break;
|
break;
|
case 18: /* Extension path - Not yet supported */
|
case 18: /* Extension path - Not yet supported */
|
Line 205... |
Line 226... |
break;
|
break;
|
/* IP host layer fields */
|
/* IP host layer fields */
|
case 40: /* NIS Domain name */
|
case 40: /* NIS Domain name */
|
if (NetOurNISDomain[0] == 0) {
|
if (NetOurNISDomain[0] == 0) {
|
size = truncate_sz ("NIS Domain Name",
|
size = truncate_sz ("NIS Domain Name",
|
sizeof(NetOurNISDomain),
|
sizeof(NetOurNISDomain), size);
|
size);
|
|
memcpy(&NetOurNISDomain, ext+2, size);
|
memcpy(&NetOurNISDomain, ext+2, size);
|
NetOurNISDomain[size] = 0 ;
|
NetOurNISDomain[size] = 0 ;
|
}
|
}
|
break;
|
break;
|
/* Application layer fields */
|
/* Application layer fields */
|
Line 230... |
Line 250... |
|
|
debug_ext ("[BOOTP] Checking extension (%d bytes)...\n", size);
|
debug_ext ("[BOOTP] Checking extension (%d bytes)...\n", size);
|
|
|
while ((ext < end) && (*ext != 0xff)) {
|
while ((ext < end) && (*ext != 0xff)) {
|
if (*ext == 0) {
|
if (*ext == 0) {
|
ext ++ ;
|
ext++;
|
} else {
|
} else {
|
u8 *opt = ext ;
|
u8 *opt = ext ;
|
ext += ext[1] + 2 ;
|
ext += ext[1] + 2 ;
|
if (ext <= end)
|
if (ext <= end)
|
BootpVendorFieldProcess (opt) ;
|
BootpVendorFieldProcess (opt) ;
|
Line 274... |
Line 294... |
}
|
}
|
|
|
/*
|
/*
|
* Handle a BOOTP received packet.
|
* Handle a BOOTP received packet.
|
*/
|
*/
|
static void
|
static void BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
|
BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
|
|
{
|
{
|
Bootp_t *bp;
|
Bootp_t *bp;
|
char *s;
|
char *s;
|
|
|
debug ("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%d)\n",
|
debug ("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%d)\n",
|
Line 324... |
Line 343... |
#endif /* !CFG_CMD_DHCP */
|
#endif /* !CFG_CMD_DHCP */
|
|
|
/*
|
/*
|
* Timeout on BOOTP/DHCP request.
|
* Timeout on BOOTP/DHCP request.
|
*/
|
*/
|
static void
|
static void BootpTimeout(void)
|
BootpTimeout(void)
|
|
{
|
{
|
if (BootpTry >= TIMEOUT_COUNT) {
|
if (BootpTry >= TIMEOUT_COUNT) {
|
puts ("\nRetry count exceeded; starting again\n");
|
puts ("\nRetry count exceeded; starting again\n");
|
NetStartAgain ();
|
NetStartAgain ();
|
} else {
|
} else {
|
Line 340... |
Line 358... |
|
|
/*
|
/*
|
* Initialize BOOTP extension fields in the request.
|
* Initialize BOOTP extension fields in the request.
|
*/
|
*/
|
#if (CONFIG_COMMANDS & CFG_CMD_DHCP)
|
#if (CONFIG_COMMANDS & CFG_CMD_DHCP)
|
static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
|
static int DhcpExtended(u8 * e, int message_type, IPaddr_t ServerID,
|
|
IPaddr_t RequestedIP)
|
{
|
{
|
u8 *start = e ;
|
u8 *start = e ;
|
u8 *cnt;
|
u8 *cnt;
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
u8 *x;
|
u8 *x;
|
Line 379... |
Line 398... |
*e++ = RequestedIP >> 24;
|
*e++ = RequestedIP >> 24;
|
*e++ = RequestedIP >> 16;
|
*e++ = RequestedIP >> 16;
|
*e++ = RequestedIP >> 8;
|
*e++ = RequestedIP >> 8;
|
*e++ = RequestedIP & 0xff;
|
*e++ = RequestedIP & 0xff;
|
}
|
}
|
|
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
if ((x = dhcp_vendorex_prep (e)))
|
if ((x = dhcp_vendorex_prep (e)))
|
return x - start ;
|
return x - start ;
|
#endif
|
#endif
|
|
|
Line 499... |
Line 517... |
|
|
return e - start ;
|
return e - start ;
|
}
|
}
|
#endif /* CFG_CMD_DHCP */
|
#endif /* CFG_CMD_DHCP */
|
|
|
void
|
void BootpRequest(void)
|
BootpRequest (void)
|
|
{
|
{
|
volatile uchar *pkt, *iphdr;
|
volatile uchar *pkt, *iphdr;
|
Bootp_t *bp;
|
Bootp_t *bp;
|
int ext_len, pktlen, iplen;
|
int ext_len, pktlen, iplen;
|
|
|
Line 513... |
Line 530... |
#endif
|
#endif
|
|
|
#ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
|
#ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
|
unsigned char bi_enetaddr[6];
|
unsigned char bi_enetaddr[6];
|
int reg;
|
int reg;
|
char *e,*s;
|
char *e, *s;
|
uchar tmp[64];
|
uchar tmp[64];
|
ulong tst1, tst2, sum, m_mask, m_value = 0;
|
ulong tst1, tst2, sum, m_mask, m_value = 0;
|
|
|
if (BootpTry ==0) {
|
if (BootpTry ==0) {
|
/* get our mac */
|
/* get our mac */
|
Line 531... |
Line 548... |
}
|
}
|
}
|
}
|
#ifdef DEBUG
|
#ifdef DEBUG
|
printf("BootpRequest => Our Mac: ");
|
printf("BootpRequest => Our Mac: ");
|
for (reg=0; reg<6; reg++) {
|
for (reg=0; reg<6; reg++) {
|
printf ("%x%c",
|
printf("%x%c", bi_enetaddr[reg], reg == 5 ? '\n' : ':');
|
bi_enetaddr[reg],
|
|
reg==5 ? '\n' : ':');
|
|
}
|
}
|
#endif /* DEBUG */
|
#endif /* DEBUG */
|
|
|
/* Mac-Manipulation 2 get seed1 */
|
/* Mac-Manipulation 2 get seed1 */
|
tst1=0;
|
tst1=0;
|
Line 670... |
Line 685... |
case 6:
|
case 6:
|
NetOurDNSIP = *(IPaddr_t *)(popt +2);
|
NetOurDNSIP = *(IPaddr_t *)(popt +2);
|
break;
|
break;
|
case 12:
|
case 12:
|
size = truncate_sz ("Host Name",
|
size = truncate_sz ("Host Name",
|
sizeof(NetOurHostName),
|
sizeof(NetOurHostName), oplen);
|
oplen);
|
|
memcpy(&NetOurHostName, popt+2, size);
|
memcpy(&NetOurHostName, popt+2, size);
|
NetOurHostName[size] = 0 ;
|
NetOurHostName[size] = 0 ;
|
break;
|
break;
|
case 15: /* Ignore Domain Name Option */
|
case 15: /* Ignore Domain Name Option */
|
break;
|
break;
|
case 17:
|
case 17:
|
size = truncate_sz ("Root Path",
|
size = truncate_sz ("Root Path",
|
sizeof(NetOurRootPath),
|
sizeof(NetOurRootPath), oplen);
|
oplen);
|
|
memcpy(&NetOurRootPath, popt+2, size);
|
memcpy(&NetOurRootPath, popt+2, size);
|
NetOurRootPath[size] = 0 ;
|
NetOurRootPath[size] = 0 ;
|
break;
|
break;
|
case 51:
|
case 51:
|
dhcp_leasetime = *(unsigned int *)(popt + 2);
|
dhcp_leasetime = *(unsigned int *)(popt + 2);
|
Line 760... |
Line 773... |
bp->bp_id = bp_offer->bp_id;
|
bp->bp_id = bp_offer->bp_id;
|
|
|
/*
|
/*
|
* Copy options from OFFER packet if present
|
* Copy options from OFFER packet if present
|
*/
|
*/
|
extlen = DhcpExtended(bp->bp_vend, DHCP_REQUEST, NetServerIP, bp->bp_yiaddr);
|
extlen =
|
|
DhcpExtended(bp->bp_vend, DHCP_REQUEST, NetServerIP, bp->bp_yiaddr);
|
|
|
pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + extlen;
|
pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + extlen;
|
iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
|
iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
|
NetSetIP(iphdr, 0xffffffffL, PORT_BOOTPS, PORT_BOOTPC, iplen);
|
NetSetIP(iphdr, 0xffffffffL, PORT_BOOTPS, PORT_BOOTPC, iplen);
|
|
|
Line 773... |
Line 787... |
}
|
}
|
|
|
/*
|
/*
|
* Handle DHCP received packets.
|
* Handle DHCP received packets.
|
*/
|
*/
|
static void
|
static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
|
DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
|
|
{
|
{
|
Bootp_t *bp = (Bootp_t *)pkt;
|
Bootp_t *bp = (Bootp_t *)pkt;
|
|
|
debug ("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
|
debug ("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
|
src, dest, len, dhcp_state);
|
src, dest, len, dhcp_state);
|
|
|
if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
|
if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
|
return;
|
return;
|
|
|
debug ("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
|
debug
|
|
("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
|
src, dest, len, dhcp_state);
|
src, dest, len, dhcp_state);
|
|
|
switch (dhcp_state) {
|
switch (dhcp_state) {
|
case SELECTING:
|
case SELECTING:
|
/*
|
/*
|