[U-Boot] [PATCH v2 04/21] net: Move CDP out of net.c

Simon Glass sjg at chromium.org
Sat Apr 21 04:59:57 CEST 2012


Hi Joe,

On Tue, Mar 27, 2012 at 4:42 PM, Joe Hershberger <joe.hershberger at ni.com> wrote:

This needs a commit message.

> Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
> Cc: Joe Hershberger <joe.hershberger at gmail.com>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Mike Frysinger <vapier at gentoo.org>
> ---
> Changes for v2:
>   - Moved is_cdp_packet to a separate patch
>   - Fixed blank newline at the end of cdp.h
>   - Pushed #ifdef CONFIG_CMD_CDP into header
>
>  include/net.h |    8 +-
>  net/Makefile  |    1 +
>  net/cdp.c     |  374 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  net/cdp.h     |   20 +++
>  net/net.c     |  366 +-------------------------------------------------------
>  5 files changed, 399 insertions(+), 370 deletions(-)
>  create mode 100644 net/cdp.c
>  create mode 100644 net/cdp.h
>
> diff --git a/include/net.h b/include/net.h
> index e39d88b..54f05bb 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -355,9 +355,7 @@ extern uchar                NetEtherNullAddr[6];
>  extern ushort          NetOurVLAN;             /* Our VLAN */
>  extern ushort          NetOurNativeVLAN;       /* Our Native VLAN */
>
> -extern uchar   NetCDPAddr[6];          /* Ethernet CDP address */
> -extern ushort  CDPNativeVLAN;          /* CDP returned native VLAN */
> -extern ushort  CDPApplianceVLAN;       /* CDP returned appliance VLAN */
> +extern const uchar     NetCDPAddr[6];          /* Ethernet CDP address */
>
>  extern int             NetState;               /* Network loop state */
>  #define NETLOOP_CONTINUE       1
> @@ -386,8 +384,8 @@ extern IPaddr_t     NetPingIP;                      /* the ip address to ping */
>
>  #if defined(CONFIG_CMD_CDP)
>  /* when CDP completes these hold the return values */
> -extern ushort CDPNativeVLAN;
> -extern ushort CDPApplianceVLAN;
> +extern ushort CDPNativeVLAN;           /* CDP returned native VLAN */
> +extern ushort CDPApplianceVLAN;                /* CDP returned appliance VLAN */
>  #endif
>
>  #if defined(CONFIG_CMD_SNTP)
> diff --git a/net/Makefile b/net/Makefile
> index 5901046..b350bfc 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -28,6 +28,7 @@ include $(TOPDIR)/config.mk
>  LIB    = $(obj)libnet.o
>
>  COBJS-$(CONFIG_CMD_NET)  += bootp.o
> +COBJS-$(CONFIG_CMD_CDP)  += cdp.o
>  COBJS-$(CONFIG_CMD_DNS)  += dns.o
>  COBJS-$(CONFIG_CMD_NET)  += eth.o
>  COBJS-$(CONFIG_CMD_NET)  += net.o
> diff --git a/net/cdp.c b/net/cdp.c
> new file mode 100644
> index 0000000..028be82
> --- /dev/null
> +++ b/net/cdp.c
> @@ -0,0 +1,374 @@
> +/*
> + *     Copied from Linux Monitor (LiMon) - Networking.
> + *
> + *     Copyright 1994 - 2000 Neil Russell.
> + *     (See License)
> + *     Copyright 2000 Roland Borde
> + *     Copyright 2000 Paolo Scaffardi
> + *     Copyright 2000-2002 Wolfgang Denk, wd at denx.de
> + */
> +
> +#include <common.h>
> +#include <net.h>
> +#if defined(CONFIG_CDP_VERSION)
> +#include <timestamp.h>
> +#endif
> +
> +#include "cdp.h"
> +
> +/* Ethernet bcast address */
> +const uchar NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
> +
> +#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                    250UL   /* 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 };

Can we put the values on the next line?

> +
> +static ushort
> +CDP_compute_csum(const uchar *buff, ushort len)

Would be nice to add a function comment if you know what it does, and returns

> +{
> +       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):

Comment style. But it is existing code, so perhaps you can leave it
along? Poor Cisco.

> +                        * 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);
> +       }
> +


Regards,
Simon


More information about the U-Boot mailing list