X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=net%2Fcdp.c;h=f9ccf5323183d98cf10435192d17502c7a8cd069;hb=66669fcf809c1e3ff644b12e04e625d3737ffd8e;hp=9bec441497e51420701b357a4ab73743bd662809;hpb=0b4c5ff4ab7fb0a69030b9ddb8f9415076ab545b;p=people%2Fms%2Fu-boot.git diff --git a/net/cdp.c b/net/cdp.c index 9bec441497..f9ccf53231 100644 --- a/net/cdp.c +++ b/net/cdp.c @@ -6,6 +6,7 @@ * Copyright 2000 Roland Borde * Copyright 2000 Paolo Scaffardi * Copyright 2000-2002 Wolfgang Denk, wd@denx.de + * SPDX-License-Identifier: GPL-2.0 */ #include @@ -17,7 +18,7 @@ #include "cdp.h" /* Ethernet bcast address */ -const uchar NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }; +const u8 net_cdp_ethaddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }; #define CDP_DEVICE_ID_TLV 0x0001 #define CDP_ADDRESS_TLV 0x0002 @@ -35,17 +36,16 @@ const uchar NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }; #define CDP_TIMEOUT 250UL /* one packet every 250ms */ -static int CDPSeq; -static int CDPOK; +static int cdp_seq; +static int cdp_ok; -ushort CDPNativeVLAN; -ushort CDPApplianceVLAN; +ushort cdp_native_vlan; +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 }; -static ushort -CDP_compute_csum(const uchar *buff, ushort len) +static ushort cdp_compute_csum(const uchar *buff, ushort len) { ushort csum; int odd; @@ -103,8 +103,7 @@ CDP_compute_csum(const uchar *buff, ushort len) return csum; } -static int -CDPSendTrigger(void) +static int cdp_send_trigger(void) { uchar *pkt; ushort *s; @@ -117,20 +116,20 @@ CDPSendTrigger(void) char buf[32]; #endif - pkt = NetTxPacket; + pkt = net_tx_packet; et = (struct ethernet_hdr *)pkt; /* NOTE: trigger sent not on any VLAN */ /* form ethernet header */ - memcpy(et->et_dest, NetCDPAddr, 6); - memcpy(et->et_src, NetOurEther, 6); + memcpy(et->et_dest, net_cdp_ethaddr, 6); + memcpy(et->et_src, net_ethaddr, 6); pkt += ETHER_HDR_SIZE; /* SNAP header */ - memcpy((uchar *)pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr)); - pkt += sizeof(CDP_SNAP_hdr); + memcpy((uchar *)pkt, cdp_snap_hdr, sizeof(cdp_snap_hdr)); + pkt += sizeof(cdp_snap_hdr); /* CDP header */ *pkt++ = 0x02; /* CDP version 2 */ @@ -144,7 +143,7 @@ CDPSendTrigger(void) #ifdef CONFIG_CDP_DEVICE_ID *s++ = htons(CDP_DEVICE_ID_TLV); *s++ = htons(CONFIG_CDP_DEVICE_ID); - sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%pm", NetOurEther); + sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%pm", net_ethaddr); memcpy((uchar *)s, buf, 16); s += 16 / 2; #endif @@ -206,43 +205,35 @@ CDPSendTrigger(void) #endif /* length of ethernet packet */ - len = (uchar *)s - ((uchar *)NetTxPacket + ETHER_HDR_SIZE); + len = (uchar *)s - ((uchar *)net_tx_packet + 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)); + len = ETHER_HDR_SIZE + sizeof(cdp_snap_hdr); + chksum = cdp_compute_csum((uchar *)net_tx_packet + len, + (uchar *)s - (net_tx_packet + len)); if (chksum == 0) chksum = 0xFFFF; *cp = htons(chksum); - (void) eth_send(NetTxPacket, (uchar *)s - NetTxPacket); + net_send_packet(net_tx_packet, (uchar *)s - net_tx_packet); return 0; } -static void -CDPTimeout(void) +static void cdp_timeout_handler(void) { - CDPSeq++; + cdp_seq++; - if (CDPSeq < 3) { - NetSetTimeout(CDP_TIMEOUT, CDPTimeout); - CDPSendTrigger(); + if (cdp_seq < 3) { + net_set_timeout_handler(CDP_TIMEOUT, cdp_timeout_handler); + cdp_send_trigger(); return; } /* if not OK try again */ - if (!CDPOK) - NetStartAgain(); + if (!cdp_ok) + net_start_again(); else - NetState = NETLOOP_SUCCESS; -} - -static void -CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, - unsigned len) -{ - /* nothing */ + net_set_state(NETLOOP_SUCCESS); } void cdp_receive(const uchar *pkt, unsigned len) @@ -253,15 +244,15 @@ void cdp_receive(const uchar *pkt, unsigned len) ushort vlan, nvlan; /* minimum size? */ - if (len < sizeof(CDP_SNAP_hdr) + 4) + 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) + if (memcmp(pkt, cdp_snap_hdr, sizeof(cdp_snap_hdr)) != 0) return; - pkt += sizeof(CDP_SNAP_hdr); - len -= sizeof(CDP_SNAP_hdr); + 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) @@ -275,7 +266,7 @@ void cdp_receive(const uchar *pkt, unsigned len) printf("**WARNING: CDP packet received with a protocol version " "%d > 2\n", pkt[0] & 0xff); - if (CDP_compute_csum(pkt, len) != 0) + if (cdp_compute_csum(pkt, len) != 0) return; pkt += 4; @@ -346,29 +337,27 @@ void cdp_receive(const uchar *pkt, unsigned len) } } - CDPApplianceVLAN = vlan; - CDPNativeVLAN = nvlan; + cdp_appliance_vlan = vlan; + cdp_native_vlan = nvlan; - CDPOK = 1; + cdp_ok = 1; return; - pkt_short: +pkt_short: printf("** CDP packet is too short\n"); return; } -void -CDPStart(void) +void cdp_start(void) { printf("Using %s device\n", eth_get_name()); - CDPSeq = 0; - CDPOK = 0; + cdp_seq = 0; + cdp_ok = 0; - CDPNativeVLAN = htons(-1); - CDPApplianceVLAN = htons(-1); + cdp_native_vlan = htons(-1); + cdp_appliance_vlan = htons(-1); - NetSetTimeout(CDP_TIMEOUT, CDPTimeout); - NetSetHandler(CDPDummyHandler); + net_set_timeout_handler(CDP_TIMEOUT, cdp_timeout_handler); - CDPSendTrigger(); + cdp_send_trigger(); }