* Copyright 2000 Paolo Scaffardi
*/
-/* #define DEBUG_BOOTP_EXT 1 / * Debug received vendor fields */
+#if 0
+#define DEBUG 1 /* general debug */
+#define DEBUG_BOOTP_EXT 1 /* Debug received vendor fields */
+#endif
#include <ppcboot.h>
#include <command.h>
retval = -1;
if (len < sizeof (Bootp_t) - OPT_SIZE)
retval = -2;
- if (bp->bp_op != OP_BOOTREQUEST &&
- bp->bp_op != OP_BOOTREPLY &&
- bp->bp_op != DHCP_OFFER &&
+ if (bp->bp_op != OP_BOOTREQUEST &&
+ bp->bp_op != OP_BOOTREPLY &&
+ bp->bp_op != DHCP_OFFER &&
bp->bp_op != DHCP_ACK &&
bp->bp_op != DHCP_NAK ) {
retval = -3;
if (bp->bp_id != BootpID)
retval = -6;
- // printf("Filtering pkt = %d\n", retval);
+#ifdef DEBUG
+ printf("Filtering pkt = %d\n", retval);
+#endif
return retval;
}
-/*
+/*
* Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
*/
void BootpCopyNetParams(Bootp_t *bp)
while ( popt < end && *popt != 0xff ) {
oplen = *(popt + 1);
switch(*popt) {
- case 1: NetOurSubnetMask = *(IPaddr_t *)(popt + 2); break;
- case 3: NetOurGatewayIP = *(IPaddr_t *)(popt + 2); break;
- case 53: break; /* Ignore Message Type Option */
- case 54: NetServerIP = *(IPaddr_t *)(popt+2); break;
- case 51: dhcp_leasetime = *(unsigned int *)(popt + 2); break;
+ case 1:
+ NetOurSubnetMask = *(IPaddr_t *)(popt + 2);
+ break;
+ case 3:
+ NetOurGatewayIP = *(IPaddr_t *)(popt + 2);
+ break;
+ case 53:
+ break; /* Ignore Message Type Option */
+ case 54:
+ NetServerIP = *(IPaddr_t *)(popt+2);
+ break;
+ case 51:
+ dhcp_leasetime = *(unsigned int *)(popt + 2);
+ break;
default:
- printf("******* Unhandled DHCP Option present in OFFER/ACK: %d\n", *popt);
+ printf("*** Unhandled DHCP Option in OFFER/ACK: %d\n",
+ *popt);
break;
}
popt += oplen + 2; /* Process next option */
return -1;
}
-/*
- * Scan string for filename str within fname
- */
-static int strfind(char *fname, char *str)
-{
- int lf = strlen(fname);
- int ls = strlen(str);
- char *p = fname;
- if ( ls > lf )
- return -1;
-
- while ( p - fname < lf ) {
- if ( strncmp(p, str, ls) == 0 )
- return 0;
- p++;
- }
- return -1;
-}
-
void DhcpSendRequestPkt(Bootp_t *bp_offer)
{
volatile uchar *pkt, *iphdr;
Bootp_t *bp;
int pktlen, iplen, extlen;
+#ifdef DEBUG
printf("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
+#endif
pkt = NetTxPacket;
memset ((void*)pkt, 0, PKTSIZE);
DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
{
Bootp_t *bp = (Bootp_t *)pkt;
- 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;
#ifdef DEBUG
- printf("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d)\n",
- src, dest, len);
+ printf("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
+ src, dest, len, dhcp_state);
#endif /* DEBUG */
switch (dhcp_state) {
* If filename is in format we recognize, assume it is a valid
* OFFER from a server we want.
*/
- if ( strfind(bp->bp_file, BOOT_FILE_PREFIX) == 0 ) {
+#ifdef DEBUG
+ printf("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
+#endif
+#ifdef CFG_BOOTFILE_PREFIX
+ if (strncmp(bp->bp_file,
+ CFG_BOOTFILE_PREFIX,
+ strlen(CFG_BOOTFILE_PREFIX)) == 0 ) {
+#endif /* CFG_BOOTFILE_PREFIX */
+
+#ifdef DEBUG
printf("TRANSITIONING TO REQUESTING STATE\n");
+#endif
dhcp_state = REQUESTING;
if ((*(uint *)bp->bp_vend) == BOOTP_VENDOR_MAGIC)
DhcpOptionsProcess(&bp->bp_vend[4]);
-
- BootpCopyNetParams(bp); /* Store net params from reply */
-
+
+ BootpCopyNetParams(bp); /* Store net params from reply */
+
NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout);
DhcpSendRequestPkt(bp);
+#ifdef CFG_BOOTFILE_PREFIX
}
+#endif /* CFG_BOOTFILE_PREFIX */
+
return;
break;
case REQUESTING:
+#ifdef DEBUG
printf("DHCP State: REQUESTING\n");
+#endif
if ( DhcpMessageType(bp->bp_vend) == DHCP_ACK ) {
dhcp_state = BOUND;
printf("DhcpHandler: Client BOUND to address ");