[net] cleanups:
- remove cdp support - replace CONFIG_BOOTP_MASK with #ifdef CONFIG_...
This commit is contained in:
parent
5b671e9611
commit
9bf7a4f97f
52
net/bootp.c
52
net/bootp.c
|
@ -58,7 +58,7 @@ static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len);
|
|||
|
||||
/* For Debug */
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
||||
#ifdef CONFIG_BOOTP_VENDOREX
|
||||
extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */
|
||||
extern u8 *dhcp_vendorex_proc (u8 *e); /*rtn next e if mine,else NULL */
|
||||
#endif
|
||||
|
@ -163,7 +163,7 @@ static void BootpVendorFieldProcess (u8 * ext)
|
|||
if (NetOurDNSIP == 0) {
|
||||
NetCopyIP (&NetOurDNSIP, (IPaddr_t *) (ext + 2));
|
||||
}
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
|
||||
#ifdef CONFIG_BOOTP_DNS2
|
||||
if ((NetOurDNS2IP == 0) && (size > 4)) {
|
||||
NetCopyIP (&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
|
||||
}
|
||||
|
@ -347,10 +347,10 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
|
|||
u8 *start = e;
|
||||
u8 *cnt;
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
||||
#ifdef CONFIG_BOOTP_VENDOREX
|
||||
u8 *x;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME)
|
||||
#ifdef CONFIG_BOOTP_SEND_HOSTNAME
|
||||
char *hostname;
|
||||
#endif
|
||||
|
||||
|
@ -389,7 +389,7 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
|
|||
*e++ = tmp >> 8;
|
||||
*e++ = tmp & 0xff;
|
||||
}
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME)
|
||||
#ifdef CONFIG_BOOTP_SEND_HOSTNAME
|
||||
if ((hostname = getenv ("hostname"))) {
|
||||
int hostnamelen = strlen (hostname);
|
||||
|
||||
|
@ -400,7 +400,7 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
|
|||
}
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
||||
#ifdef CONFIG_BOOTP_VENDOREX
|
||||
if ((x = dhcp_vendorex_prep (e)))
|
||||
return x - start;
|
||||
#endif
|
||||
|
@ -408,39 +408,39 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
|
|||
*e++ = 55; /* Parameter Request List */
|
||||
cnt = e++; /* Pointer to count of requested items */
|
||||
*cnt = 0;
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK)
|
||||
#ifdef CONFIG_BOOTP_SUBNETMASK
|
||||
*e++ = 1; /* Subnet Mask */
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
|
||||
#ifdef CONFIG_BOOTP_TIMEOFFSET
|
||||
*e++ = 2;
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY)
|
||||
#ifdef CONFIG_BOOTP_GATEWAY
|
||||
*e++ = 3; /* Router Option */
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS)
|
||||
#ifdef CONFIG_BOOTP_DNS
|
||||
*e++ = 6; /* DNS Server(s) */
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME)
|
||||
#ifdef CONFIG_BOOTP_HOSTNAME
|
||||
*e++ = 12; /* Hostname */
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE)
|
||||
#ifdef CONFIG_BOOTP_BOOTFILESIZE
|
||||
*e++ = 13; /* Boot File Size */
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH)
|
||||
#ifdef CONFIG_BOOTP_BOOTPATH
|
||||
*e++ = 17; /* Boot path */
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN)
|
||||
#ifdef CONFIG_BOOTP_NISDOMAIN
|
||||
*e++ = 40; /* NIS Domain name request */
|
||||
*cnt += 1;
|
||||
#endif
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
|
||||
#ifdef CONFIG_BOOTP_NTPSERVER
|
||||
*e++ = 42;
|
||||
*cnt += 1;
|
||||
#endif
|
||||
|
@ -479,43 +479,43 @@ static int BootpExtended (u8 * e)
|
|||
*e++ = (576 - 312 + OPT_SIZE) & 0xff;
|
||||
#endif /* CFG_CMD_DHCP */
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK)
|
||||
#ifdef CONFIG_BOOTP_SUBNETMASK
|
||||
*e++ = 1; /* Subnet mask request */
|
||||
*e++ = 4;
|
||||
e += 4;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY)
|
||||
#ifdef CONFIG_BOOTP_GATEWAY
|
||||
*e++ = 3; /* Default gateway request */
|
||||
*e++ = 4;
|
||||
e += 4;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS)
|
||||
#ifdef CONFIG_BOOTP_DNS
|
||||
*e++ = 6; /* Domain Name Server */
|
||||
*e++ = 4;
|
||||
e += 4;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME)
|
||||
#ifdef CONFIG_BOOTP_HOSTNAME
|
||||
*e++ = 12; /* Host name request */
|
||||
*e++ = 32;
|
||||
e += 32;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE)
|
||||
#ifdef CONFIG_BOOTP_BOOTFILESIZE
|
||||
*e++ = 13; /* Boot file size */
|
||||
*e++ = 2;
|
||||
e += 2;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH)
|
||||
#ifdef CONFIG_BOOTP_BOOTPATH
|
||||
*e++ = 17; /* Boot path */
|
||||
*e++ = 32;
|
||||
e += 32;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN)
|
||||
#ifdef CONFIG_BOOTP_NISDOMAIN
|
||||
*e++ = 40; /* NIS Domain name request */
|
||||
*e++ = 32;
|
||||
e += 32;
|
||||
|
@ -616,7 +616,7 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
|
|||
case 1:
|
||||
NetCopyIP (&NetOurSubnetMask, (popt + 2));
|
||||
break;
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
|
||||
#if defined CONFIG_NET_SNTP && defined CONFIG_BOOTP_TIMEOFFSET
|
||||
case 2: /* Time offset */
|
||||
NetCopyLong (&NetTimeOffset, (ulong *) (popt + 2));
|
||||
NetTimeOffset = ntohl (NetTimeOffset);
|
||||
|
@ -627,7 +627,7 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
|
|||
break;
|
||||
case 6:
|
||||
NetCopyIP (&NetOurDNSIP, (popt + 2));
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
|
||||
#ifdef CONFIG_BOOTP_DNS2
|
||||
if (*(popt + 1) > 4) {
|
||||
NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
|
|||
memcpy (&NetOurRootPath, popt + 2, size);
|
||||
NetOurRootPath[size] = 0;
|
||||
break;
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
|
||||
#if defined CONFIG_NET_SNTP && defined CONFIG_BOOTP_NTPSERVER
|
||||
case 42: /* NTP server IP */
|
||||
NetCopyIP (&NetNtpServerIP, (popt + 2));
|
||||
break;
|
||||
|
@ -691,7 +691,7 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
|
|||
}
|
||||
break;
|
||||
default:
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
|
||||
#ifdef CONFIG_BOOTP_VENDOREX
|
||||
if (dhcp_vendorex_proc (popt))
|
||||
break;
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
/*
|
||||
* BOOTP header.
|
||||
*/
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_DHCP)
|
||||
#ifdef CONFIG_NET_DHCP
|
||||
#define OPT_SIZE 312 /* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */
|
||||
#else
|
||||
#define OPT_SIZE 64
|
||||
|
|
417
net/net.c
417
net/net.c
|
@ -107,7 +107,7 @@
|
|||
IPaddr_t NetOurSubnetMask=0; /* Our subnet mask (0=unknown) */
|
||||
IPaddr_t NetOurGatewayIP=0; /* Our gateways IP address */
|
||||
IPaddr_t NetOurDNSIP=0; /* Our DNS IP address */
|
||||
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
|
||||
#ifdef CONFIG_BOOTP_DNS2
|
||||
IPaddr_t NetOurDNS2IP=0; /* Our 2nd DNS IP address */
|
||||
#endif
|
||||
char NetOurNISDomain[32]={0,}; /* Our NIS domain */
|
||||
|
@ -130,10 +130,6 @@ uchar NetBcastAddr[6] = /* Ethernet bcast address */
|
|||
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
uchar NetEtherNullAddr[6] =
|
||||
{ 0, 0, 0, 0, 0, 0 };
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
uchar NetCDPAddr[6] = /* Ethernet bcast address */
|
||||
{ 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
|
||||
#endif
|
||||
int NetState; /* Network loop state */
|
||||
|
||||
/* XXX in both little & big endian machines 0xFFFF == ntohs(-1) */
|
||||
|
@ -148,10 +144,6 @@ IPaddr_t NetPingIP; /* the ip address to ping */
|
|||
extern void PingStart(void);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
static void CDPStart(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_SNTP
|
||||
IPaddr_t NetNtpServerIP; /* NTP server IP address */
|
||||
int NetTimeOffset=0; /* offset time from UTC */
|
||||
|
@ -358,10 +350,6 @@ restart:
|
|||
NetServerIP = dev_get_param_ip(eth_current->dev, "serverip");
|
||||
NetOurVLAN = getenv_VLAN("vlan"); /* VLANs must be read */
|
||||
NetOurNativeVLAN = getenv_VLAN("nvlan");
|
||||
case CDP:
|
||||
NetOurVLAN = getenv_VLAN("vlan"); /* VLANs must be read */
|
||||
NetOurNativeVLAN = getenv_VLAN("nvlan");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -410,11 +398,6 @@ restart:
|
|||
NfsStart();
|
||||
break;
|
||||
#endif
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
case CDP:
|
||||
CDPStart();
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_NETCONSOLE
|
||||
case NETCONS:
|
||||
NcStart();
|
||||
|
@ -433,19 +416,6 @@ restart:
|
|||
break;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
|
||||
#if defined(CFG_FAULT_ECHO_LINK_DOWN) && defined(CONFIG_STATUS_LED) && defined(STATUS_LED_RED)
|
||||
/*
|
||||
* Echo the inverted link state to the fault LED.
|
||||
*/
|
||||
if(miiphy_link(eth_get_dev()->name, CFG_FAULT_MII_ADDR)) {
|
||||
status_led_set (STATUS_LED_RED, STATUS_LED_OFF);
|
||||
} else {
|
||||
status_led_set (STATUS_LED_RED, STATUS_LED_ON);
|
||||
}
|
||||
#endif /* CFG_FAULT_ECHO_LINK_DOWN, ... */
|
||||
#endif /* CONFIG_MII, ... */
|
||||
|
||||
/*
|
||||
* Main packet reception loop. Loop receiving packets until
|
||||
* someone sets `NetState' to a state that terminates.
|
||||
|
@ -481,21 +451,6 @@ restart:
|
|||
*/
|
||||
if (timeHandler && is_timeout(timeStart, timeDelta)) {
|
||||
thand_f *x;
|
||||
|
||||
#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
|
||||
# if defined(CFG_FAULT_ECHO_LINK_DOWN) && \
|
||||
defined(CONFIG_STATUS_LED) && \
|
||||
defined(STATUS_LED_RED)
|
||||
/*
|
||||
* Echo the inverted link state to the fault LED.
|
||||
*/
|
||||
if(miiphy_link(eth_get_dev()->name, CFG_FAULT_MII_ADDR)) {
|
||||
status_led_set (STATUS_LED_RED, STATUS_LED_OFF);
|
||||
} else {
|
||||
status_led_set (STATUS_LED_RED, STATUS_LED_ON);
|
||||
}
|
||||
# endif /* CFG_FAULT_ECHO_LINK_DOWN, ... */
|
||||
#endif /* CONFIG_MII, ... */
|
||||
x = timeHandler;
|
||||
timeHandler = (thand_f *)0;
|
||||
(*x)();
|
||||
|
@ -639,357 +594,6 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
|
|||
return 0; /* transmitted */
|
||||
}
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
|
||||
#define CDP_DEVICE_ID_TLV 0x0001
|
||||
#define CDP_ADDRESS_TLV 0x0002
|
||||
#define CDP_PORT_ID_TLV 0x0003
|
||||
#define CDP_CAPABILITIES_TLV 0x0004
|
||||
#define CDP_VERSION_TLV 0x0005
|
||||
#define CDP_PLATFORM_TLV 0x0006
|
||||
#define CDP_NATIVE_VLAN_TLV 0x000a
|
||||
#define CDP_APPLIANCE_VLAN_TLV 0x000e
|
||||
#define CDP_TRIGGER_TLV 0x000f
|
||||
#define CDP_POWER_CONSUMPTION_TLV 0x0010
|
||||
#define CDP_SYSNAME_TLV 0x0014
|
||||
#define CDP_SYSOBJECT_TLV 0x0015
|
||||
#define CDP_MANAGEMENT_ADDRESS_TLV 0x0016
|
||||
|
||||
#define CDP_TIMEOUT (250 * MSECOND) /* one packet every 250ms */
|
||||
|
||||
static int CDPSeq;
|
||||
static int CDPOK;
|
||||
|
||||
ushort CDPNativeVLAN;
|
||||
ushort CDPApplianceVLAN;
|
||||
|
||||
static const uchar CDP_SNAP_hdr[8] = { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x0C, 0x20, 0x00 };
|
||||
|
||||
static ushort CDP_compute_csum(const uchar *buff, ushort len)
|
||||
{
|
||||
ushort csum;
|
||||
int odd;
|
||||
ulong result = 0;
|
||||
ushort leftover;
|
||||
ushort *p;
|
||||
|
||||
if (len > 0) {
|
||||
odd = 1 & (ulong)buff;
|
||||
if (odd) {
|
||||
result = *buff << 8;
|
||||
len--;
|
||||
buff++;
|
||||
}
|
||||
while (len > 1) {
|
||||
p = (ushort *)buff;
|
||||
result += *p++;
|
||||
buff = (uchar *)p;
|
||||
if (result & 0x80000000)
|
||||
result = (result & 0xFFFF) + (result >> 16);
|
||||
len -= 2;
|
||||
}
|
||||
if (len) {
|
||||
leftover = (signed short)(*(const signed char *)buff);
|
||||
/* CISCO SUCKS big time! (and blows too):
|
||||
* CDP uses the IP checksum algorithm with a twist;
|
||||
* for the last byte it *sign* extends and sums.
|
||||
*/
|
||||
result = (result & 0xffff0000) | ((result + leftover) & 0x0000ffff);
|
||||
}
|
||||
while (result >> 16)
|
||||
result = (result & 0xFFFF) + (result >> 16);
|
||||
|
||||
if (odd)
|
||||
result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
|
||||
}
|
||||
|
||||
/* add up 16-bit and 17-bit words for 17+c bits */
|
||||
result = (result & 0xffff) + (result >> 16);
|
||||
/* add up 16-bit and 2-bit for 16+c bit */
|
||||
result = (result & 0xffff) + (result >> 16);
|
||||
/* add up carry.. */
|
||||
result = (result & 0xffff) + (result >> 16);
|
||||
|
||||
/* negate */
|
||||
csum = ~(ushort)result;
|
||||
|
||||
/* run time endian detection */
|
||||
if (csum != htons(csum)) /* little endian */
|
||||
csum = htons(csum);
|
||||
|
||||
return csum;
|
||||
}
|
||||
|
||||
int CDPSendTrigger(void)
|
||||
{
|
||||
uchar *pkt;
|
||||
ushort *s;
|
||||
ushort *cp;
|
||||
Ethernet_t *et;
|
||||
int len;
|
||||
ushort chksum;
|
||||
#if defined(CONFIG_CDP_DEVICE_ID) || defined(CONFIG_CDP_PORT_ID) || \
|
||||
defined(CONFIG_CDP_VERSION) || defined(CONFIG_CDP_PLATFORM)
|
||||
char buf[32];
|
||||
#endif
|
||||
|
||||
pkt = NetTxPacket;
|
||||
et = (Ethernet_t *)pkt;
|
||||
|
||||
/* NOTE: trigger sent not on any VLAN */
|
||||
|
||||
/* form ethernet header */
|
||||
memcpy(et->et_dest, NetCDPAddr, 6);
|
||||
memcpy(et->et_src, NetOurEther, 6);
|
||||
|
||||
pkt += ETHER_HDR_SIZE;
|
||||
|
||||
/* SNAP header */
|
||||
memcpy((uchar *)pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr));
|
||||
pkt += sizeof(CDP_SNAP_hdr);
|
||||
|
||||
/* CDP header */
|
||||
*pkt++ = 0x02; /* CDP version 2 */
|
||||
*pkt++ = 180; /* TTL */
|
||||
s = (ushort *)pkt;
|
||||
cp = s;
|
||||
*s++ = htons(0); /* checksum (0 for later calculation) */
|
||||
|
||||
/* CDP fields */
|
||||
#ifdef CONFIG_CDP_DEVICE_ID
|
||||
*s++ = htons(CDP_DEVICE_ID_TLV);
|
||||
*s++ = htons(CONFIG_CDP_DEVICE_ID);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%02X%02X%02X%02X%02X%02X",
|
||||
NetOurEther[0] & 0xff, NetOurEther[1] & 0xff,
|
||||
NetOurEther[2] & 0xff, NetOurEther[3] & 0xff,
|
||||
NetOurEther[4] & 0xff, NetOurEther[5] & 0xff);
|
||||
memcpy((uchar *)s, buf, 16);
|
||||
s += 16 / 2;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CDP_PORT_ID
|
||||
*s++ = htons(CDP_PORT_ID_TLV);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sprintf(buf, CONFIG_CDP_PORT_ID, eth_get_dev_index());
|
||||
len = strlen(buf);
|
||||
if (len & 1) /* make it even */
|
||||
len++;
|
||||
*s++ = htons(len + 4);
|
||||
memcpy((uchar *)s, buf, len);
|
||||
s += len / 2;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CDP_CAPABILITIES
|
||||
*s++ = htons(CDP_CAPABILITIES_TLV);
|
||||
*s++ = htons(8);
|
||||
*(ulong *)s = htonl(CONFIG_CDP_CAPABILITIES);
|
||||
s += 2;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CDP_VERSION
|
||||
*s++ = htons(CDP_VERSION_TLV);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strcpy(buf, CONFIG_CDP_VERSION);
|
||||
len = strlen(buf);
|
||||
if (len & 1) /* make it even */
|
||||
len++;
|
||||
*s++ = htons(len + 4);
|
||||
memcpy((uchar *)s, buf, len);
|
||||
s += len / 2;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CDP_PLATFORM
|
||||
*s++ = htons(CDP_PLATFORM_TLV);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strcpy(buf, CONFIG_CDP_PLATFORM);
|
||||
len = strlen(buf);
|
||||
if (len & 1) /* make it even */
|
||||
len++;
|
||||
*s++ = htons(len + 4);
|
||||
memcpy((uchar *)s, buf, len);
|
||||
s += len / 2;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CDP_TRIGGER
|
||||
*s++ = htons(CDP_TRIGGER_TLV);
|
||||
*s++ = htons(8);
|
||||
*(ulong *)s = htonl(CONFIG_CDP_TRIGGER);
|
||||
s += 2;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CDP_POWER_CONSUMPTION
|
||||
*s++ = htons(CDP_POWER_CONSUMPTION_TLV);
|
||||
*s++ = htons(6);
|
||||
*s++ = htons(CONFIG_CDP_POWER_CONSUMPTION);
|
||||
#endif
|
||||
|
||||
/* length of ethernet packet */
|
||||
len = (uchar *)s - ((uchar *)NetTxPacket + ETHER_HDR_SIZE);
|
||||
et->et_protlen = htons(len);
|
||||
|
||||
len = ETHER_HDR_SIZE + sizeof(CDP_SNAP_hdr);
|
||||
chksum = CDP_compute_csum((uchar *)NetTxPacket + len, (uchar *)s - (NetTxPacket + len));
|
||||
if (chksum == 0)
|
||||
chksum = 0xFFFF;
|
||||
*cp = htons(chksum);
|
||||
|
||||
(void) eth_send(NetTxPacket, (uchar *)s - NetTxPacket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
CDPTimeout (void)
|
||||
{
|
||||
CDPSeq++;
|
||||
|
||||
if (CDPSeq < 3) {
|
||||
NetSetTimeout (CDP_TIMEOUT, CDPTimeout);
|
||||
CDPSendTrigger();
|
||||
return;
|
||||
}
|
||||
|
||||
/* if not OK try again */
|
||||
if (!CDPOK)
|
||||
NetStartAgain();
|
||||
else
|
||||
NetState = NETLOOP_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
CDPDummyHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
static void
|
||||
CDPHandler(const uchar * pkt, unsigned len)
|
||||
{
|
||||
const uchar *t;
|
||||
const ushort *ss;
|
||||
ushort type, tlen;
|
||||
uchar applid;
|
||||
ushort vlan, nvlan;
|
||||
|
||||
/* minimum size? */
|
||||
if (len < sizeof(CDP_SNAP_hdr) + 4)
|
||||
goto pkt_short;
|
||||
|
||||
/* check for valid CDP SNAP header */
|
||||
if (memcmp(pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr)) != 0)
|
||||
return;
|
||||
|
||||
pkt += sizeof(CDP_SNAP_hdr);
|
||||
len -= sizeof(CDP_SNAP_hdr);
|
||||
|
||||
/* Version of CDP protocol must be >= 2 and TTL != 0 */
|
||||
if (pkt[0] < 0x02 || pkt[1] == 0)
|
||||
return;
|
||||
|
||||
/* if version is greater than 0x02 maybe we'll have a problem; output a warning */
|
||||
if (pkt[0] != 0x02)
|
||||
printf("** WARNING: CDP packet received with a protocol version %d > 2\n",
|
||||
pkt[0] & 0xff);
|
||||
|
||||
if (CDP_compute_csum(pkt, len) != 0)
|
||||
return;
|
||||
|
||||
pkt += 4;
|
||||
len -= 4;
|
||||
|
||||
vlan = htons(-1);
|
||||
nvlan = htons(-1);
|
||||
while (len > 0) {
|
||||
if (len < 4)
|
||||
goto pkt_short;
|
||||
|
||||
ss = (const ushort *)pkt;
|
||||
type = ntohs(ss[0]);
|
||||
tlen = ntohs(ss[1]);
|
||||
if (tlen > len) {
|
||||
goto pkt_short;
|
||||
}
|
||||
|
||||
pkt += tlen;
|
||||
len -= tlen;
|
||||
|
||||
ss += 2; /* point ss to the data of the TLV */
|
||||
tlen -= 4;
|
||||
|
||||
switch (type) {
|
||||
case CDP_DEVICE_ID_TLV:
|
||||
break;
|
||||
case CDP_ADDRESS_TLV:
|
||||
break;
|
||||
case CDP_PORT_ID_TLV:
|
||||
break;
|
||||
case CDP_CAPABILITIES_TLV:
|
||||
break;
|
||||
case CDP_VERSION_TLV:
|
||||
break;
|
||||
case CDP_PLATFORM_TLV:
|
||||
break;
|
||||
case CDP_NATIVE_VLAN_TLV:
|
||||
nvlan = *ss;
|
||||
break;
|
||||
case CDP_APPLIANCE_VLAN_TLV:
|
||||
t = (const uchar *)ss;
|
||||
while (tlen > 0) {
|
||||
if (tlen < 3)
|
||||
goto pkt_short;
|
||||
|
||||
applid = t[0];
|
||||
ss = (const ushort *)(t + 1);
|
||||
|
||||
#ifdef CONFIG_CDP_APPLIANCE_VLAN_TYPE
|
||||
if (applid == CONFIG_CDP_APPLIANCE_VLAN_TYPE)
|
||||
vlan = *ss;
|
||||
#else
|
||||
vlan = ntohs(*ss); /* XXX will this work; dunno */
|
||||
#endif
|
||||
t += 3; tlen -= 3;
|
||||
}
|
||||
break;
|
||||
case CDP_TRIGGER_TLV:
|
||||
break;
|
||||
case CDP_POWER_CONSUMPTION_TLV:
|
||||
break;
|
||||
case CDP_SYSNAME_TLV:
|
||||
break;
|
||||
case CDP_SYSOBJECT_TLV:
|
||||
break;
|
||||
case CDP_MANAGEMENT_ADDRESS_TLV:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CDPApplianceVLAN = vlan;
|
||||
CDPNativeVLAN = nvlan;
|
||||
|
||||
CDPOK = 1;
|
||||
return;
|
||||
|
||||
pkt_short:
|
||||
printf("** CDP packet is too short\n");
|
||||
return;
|
||||
}
|
||||
|
||||
static void CDPStart(void)
|
||||
{
|
||||
CDPSeq = 0;
|
||||
CDPOK = 0;
|
||||
|
||||
CDPNativeVLAN = htons(-1);
|
||||
CDPApplianceVLAN = htons(-1);
|
||||
|
||||
NetSetTimeout (CDP_TIMEOUT, CDPTimeout);
|
||||
NetSetHandler (CDPDummyHandler);
|
||||
|
||||
CDPSendTrigger();
|
||||
}
|
||||
#endif /* CFG_CMD_CDP */
|
||||
|
||||
|
||||
void
|
||||
NetReceive(uchar * inpkt, int len)
|
||||
{
|
||||
|
@ -999,9 +603,6 @@ NetReceive(uchar * inpkt, int len)
|
|||
IPaddr_t tmp;
|
||||
int x;
|
||||
uchar *pkt;
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
int iscdp;
|
||||
#endif
|
||||
ushort cti = 0, vlanid = VLAN_NONE, myvlanid, mynvlanid;
|
||||
|
||||
#ifdef ET_DEBUG
|
||||
|
@ -1016,11 +617,6 @@ NetReceive(uchar * inpkt, int len)
|
|||
if (len < ETHER_HDR_SIZE)
|
||||
return;
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
/* keep track if packet is CDP */
|
||||
iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0;
|
||||
#endif
|
||||
|
||||
myvlanid = ntohs(NetOurVLAN);
|
||||
if (myvlanid == (ushort)-1)
|
||||
myvlanid = VLAN_NONE;
|
||||
|
@ -1059,9 +655,6 @@ NetReceive(uchar * inpkt, int len)
|
|||
|
||||
/* if no VLAN active */
|
||||
if ((ntohs(NetOurVLAN) & VLAN_IDMASK) == VLAN_NONE
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
&& iscdp == 0
|
||||
#endif
|
||||
)
|
||||
return;
|
||||
|
||||
|
@ -1077,13 +670,6 @@ NetReceive(uchar * inpkt, int len)
|
|||
printf("Receive from protocol 0x%x\n", x);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_CDP)
|
||||
if (iscdp) {
|
||||
CDPHandler((uchar *)ip, len);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((myvlanid & VLAN_IDMASK) != VLAN_NONE) {
|
||||
if (vlanid == VLAN_NONE)
|
||||
vlanid = (mynvlanid & VLAN_IDMASK);
|
||||
|
@ -1393,7 +979,6 @@ static int net_check_prereq (proto_t protocol)
|
|||
case DHCP:
|
||||
case RARP:
|
||||
case BOOTP:
|
||||
case CDP:
|
||||
if (memcmp (NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
|
||||
printf("*** ERROR: `%s.ethaddr' not set\n", ethid);
|
||||
return (1);
|
||||
|
|
Loading…
Reference in New Issue