1
0
Fork 0

net: cosmetic: Clean up CDP variables and functions

Make a thorough pass through all variables and function names contained
within cdp.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
utp
Joe Hershberger 2015-04-08 01:41:14 -05:00 committed by Simon Glass
parent 331db5a90f
commit 6aede5b750
5 changed files with 46 additions and 49 deletions

View File

@ -290,18 +290,19 @@ static void cdp_update_env(void)
{ {
char tmp[16]; char tmp[16];
if (CDPApplianceVLAN != htons(-1)) { if (cdp_appliance_vlan != htons(-1)) {
printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN)); printf("CDP offered appliance VLAN %d\n",
VLAN_to_string(CDPApplianceVLAN, tmp); ntohs(cdp_appliance_vlan));
VLAN_to_string(cdp_appliance_vlan, tmp);
setenv("vlan", tmp); setenv("vlan", tmp);
NetOurVLAN = CDPApplianceVLAN; NetOurVLAN = cdp_appliance_vlan;
} }
if (CDPNativeVLAN != htons(-1)) { if (cdp_native_vlan != htons(-1)) {
printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN)); printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan));
VLAN_to_string(CDPNativeVLAN, tmp); VLAN_to_string(cdp_native_vlan, tmp);
setenv("nvlan", tmp); setenv("nvlan", tmp);
NetOurNativeVLAN = CDPNativeVLAN; NetOurNativeVLAN = cdp_native_vlan;
} }
} }

View File

@ -518,8 +518,8 @@ extern struct in_addr net_ping_ip; /* the ip address to ping */
#if defined(CONFIG_CMD_CDP) #if defined(CONFIG_CMD_CDP)
/* when CDP completes these hold the return values */ /* when CDP completes these hold the return values */
extern ushort CDPNativeVLAN; /* CDP returned native VLAN */ extern ushort cdp_native_vlan; /* CDP returned native VLAN */
extern ushort CDPApplianceVLAN; /* CDP returned appliance VLAN */ extern ushort cdp_appliance_vlan; /* CDP returned appliance VLAN */
/* /*
* Check for a CDP packet by examining the received MAC address field * Check for a CDP packet by examining the received MAC address field

View File

@ -36,17 +36,16 @@ const u8 net_cdp_ethaddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
#define CDP_TIMEOUT 250UL /* one packet every 250ms */ #define CDP_TIMEOUT 250UL /* one packet every 250ms */
static int CDPSeq; static int cdp_seq;
static int CDPOK; static int cdp_ok;
ushort CDPNativeVLAN; ushort cdp_native_vlan;
ushort CDPApplianceVLAN; ushort cdp_appliance_vlan;
static const uchar CDP_SNAP_hdr[8] = { static const uchar cdp_snap_hdr[8] = {
0xAA, 0xAA, 0x03, 0x00, 0x00, 0x0C, 0x20, 0x00 }; 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x0C, 0x20, 0x00 };
static ushort static ushort cdp_compute_csum(const uchar *buff, ushort len)
CDP_compute_csum(const uchar *buff, ushort len)
{ {
ushort csum; ushort csum;
int odd; int odd;
@ -104,8 +103,7 @@ CDP_compute_csum(const uchar *buff, ushort len)
return csum; return csum;
} }
static int static int cdp_send_trigger(void)
CDPSendTrigger(void)
{ {
uchar *pkt; uchar *pkt;
ushort *s; ushort *s;
@ -130,8 +128,8 @@ CDPSendTrigger(void)
pkt += ETHER_HDR_SIZE; pkt += ETHER_HDR_SIZE;
/* SNAP header */ /* SNAP header */
memcpy((uchar *)pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr)); memcpy((uchar *)pkt, cdp_snap_hdr, sizeof(cdp_snap_hdr));
pkt += sizeof(CDP_SNAP_hdr); pkt += sizeof(cdp_snap_hdr);
/* CDP header */ /* CDP header */
*pkt++ = 0x02; /* CDP version 2 */ *pkt++ = 0x02; /* CDP version 2 */
@ -210,8 +208,8 @@ CDPSendTrigger(void)
len = (uchar *)s - ((uchar *)net_tx_packet + ETHER_HDR_SIZE); len = (uchar *)s - ((uchar *)net_tx_packet + ETHER_HDR_SIZE);
et->et_protlen = htons(len); et->et_protlen = htons(len);
len = ETHER_HDR_SIZE + sizeof(CDP_SNAP_hdr); len = ETHER_HDR_SIZE + sizeof(cdp_snap_hdr);
chksum = CDP_compute_csum((uchar *)net_tx_packet + len, chksum = cdp_compute_csum((uchar *)net_tx_packet + len,
(uchar *)s - (net_tx_packet + len)); (uchar *)s - (net_tx_packet + len));
if (chksum == 0) if (chksum == 0)
chksum = 0xFFFF; chksum = 0xFFFF;
@ -221,19 +219,18 @@ CDPSendTrigger(void)
return 0; return 0;
} }
static void static void cdp_timeout_handler(void)
CDPTimeout(void)
{ {
CDPSeq++; cdp_seq++;
if (CDPSeq < 3) { if (cdp_seq < 3) {
NetSetTimeout(CDP_TIMEOUT, CDPTimeout); NetSetTimeout(CDP_TIMEOUT, cdp_timeout_handler);
CDPSendTrigger(); cdp_send_trigger();
return; return;
} }
/* if not OK try again */ /* if not OK try again */
if (!CDPOK) if (!cdp_ok)
NetStartAgain(); NetStartAgain();
else else
net_set_state(NETLOOP_SUCCESS); net_set_state(NETLOOP_SUCCESS);
@ -247,15 +244,15 @@ void cdp_receive(const uchar *pkt, unsigned len)
ushort vlan, nvlan; ushort vlan, nvlan;
/* minimum size? */ /* minimum size? */
if (len < sizeof(CDP_SNAP_hdr) + 4) if (len < sizeof(cdp_snap_hdr) + 4)
goto pkt_short; goto pkt_short;
/* check for valid CDP SNAP header */ /* check for valid CDP SNAP header */
if (memcmp(pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr)) != 0) if (memcmp(pkt, cdp_snap_hdr, sizeof(cdp_snap_hdr)) != 0)
return; return;
pkt += sizeof(CDP_SNAP_hdr); pkt += sizeof(cdp_snap_hdr);
len -= sizeof(CDP_SNAP_hdr); len -= sizeof(cdp_snap_hdr);
/* Version of CDP protocol must be >= 2 and TTL != 0 */ /* Version of CDP protocol must be >= 2 and TTL != 0 */
if (pkt[0] < 0x02 || pkt[1] == 0) if (pkt[0] < 0x02 || pkt[1] == 0)
@ -269,7 +266,7 @@ void cdp_receive(const uchar *pkt, unsigned len)
printf("**WARNING: CDP packet received with a protocol version " printf("**WARNING: CDP packet received with a protocol version "
"%d > 2\n", pkt[0] & 0xff); "%d > 2\n", pkt[0] & 0xff);
if (CDP_compute_csum(pkt, len) != 0) if (cdp_compute_csum(pkt, len) != 0)
return; return;
pkt += 4; pkt += 4;
@ -340,28 +337,27 @@ void cdp_receive(const uchar *pkt, unsigned len)
} }
} }
CDPApplianceVLAN = vlan; cdp_appliance_vlan = vlan;
CDPNativeVLAN = nvlan; cdp_native_vlan = nvlan;
CDPOK = 1; cdp_ok = 1;
return; return;
pkt_short: pkt_short:
printf("** CDP packet is too short\n"); printf("** CDP packet is too short\n");
return; return;
} }
void void cdp_start(void)
CDPStart(void)
{ {
printf("Using %s device\n", eth_get_name()); printf("Using %s device\n", eth_get_name());
CDPSeq = 0; cdp_seq = 0;
CDPOK = 0; cdp_ok = 0;
CDPNativeVLAN = htons(-1); cdp_native_vlan = htons(-1);
CDPApplianceVLAN = htons(-1); cdp_appliance_vlan = htons(-1);
NetSetTimeout(CDP_TIMEOUT, CDPTimeout); NetSetTimeout(CDP_TIMEOUT, cdp_timeout_handler);
CDPSendTrigger(); cdp_send_trigger();
} }

View File

@ -14,7 +14,7 @@
#ifndef __CDP_H__ #ifndef __CDP_H__
#define __CDP_H__ #define __CDP_H__
void CDPStart(void); void cdp_start(void);
/* Process a received CDP packet */ /* Process a received CDP packet */
void cdp_receive(const uchar *pkt, unsigned len); void cdp_receive(const uchar *pkt, unsigned len);

View File

@ -412,7 +412,7 @@ restart:
#endif #endif
#if defined(CONFIG_CMD_CDP) #if defined(CONFIG_CMD_CDP)
case CDP: case CDP:
CDPStart(); cdp_start();
break; break;
#endif #endif
#if defined (CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD) #if defined (CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD)