Commit 962f8a25 authored by Benoit Rat's avatar Benoit Rat

wrs-iftool: adding iftool from wr-switch-sw:ce_test to check interfaces connectivity

parent bb92b0d9
# Checking variable (you should define these as global)
ifeq ($(strip $(WRS_BASE_DIR)),)
$(error You first need to define WRS_BASE_DIR variable)
#WRS_BASE_DIR=/home/neub/Work/7S/WR/wr-switch-sw/build
endif
ifeq ($(strip $(CROSS_COMPILE)),)
$(warning You might define CROSS_COMPILE variable)
endif
ifeq ($(strip $(WR_INSTALL_ROOT)),)
WR_INSTALL_ROOT=/tftpboot/rootfs-test/wr/
endif
# Standard stanza for cross-compilation (courtesy of the linux makefile)
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
TARGETS := wrs-iftool
# Calculate endianness before everything, for my ptpd-wrappers.h to have it
CFLAGS += $(shell ./check-endian $(CC))
# Flags for standalone compilation
TOPDIR=$(shell /bin/pwd)
CFLAGS = -Wall -ggdb -O2 -DDEBUG \
-I$(LINUX)/include \
-I$(LINUX)/arch/arm/mach-at91/include \
-I${WRS_BASE_DIR}/../userspace/ptp-noposix/libptpnetif \
-I${WRS_BASE_DIR}/../userspace/wrsw_hal \
-I${WRS_BASE_DIR}/../userspace/wrsw_rtud \
-I${WRS_BASE_DIR}/../userspace/mini-rpc \
-I${WRS_BASE_DIR}/../userspace/ptp-noposix/PTPWRd \
-I${WRS_BASE_DIR}/../userspace/ptp-noposix/libposix \
-I${WRS_BASE_DIR}/../userspace/include
LDFLAGS = -L$(WR_INSTALL_ROOT)/lib \
-L${WRS_BASE_DIR}/../userspace/mini-rpc \
-L${WRS_BASE_DIR}/../userspace/ptp-noposix \
-L${WRS_BASE_DIR}/../userspace/libswitchhw \
-lminipc -lptpnetif -lswitchhw
CFLAGSII= -g3 -O0 -lm -w -Wall
# The main objects are all from the ptp directory
all: $(TARGETS)
# the binary is just a collection of object files.
# However, we need a freestanding version, so we build two binaries:
# one is gnu/linux-based (well, "posix") and the other is freestanding.
# The "ptpd.o" object is used to run "nm" on it and drive patches
$(TARGETS) : $(TARGETS).o $(CORELIBS)
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
install: $(TARGETS)
cp $(TARGETS) $(WR_INSTALL_ROOT)/bin
# This is a target for me: print all headers included by this tree
printh:
grep -h '^#include' $(OBJS:.o=.c) $$(find . -name \*.h) | \
sort | uniq -c
printhf:
grep '^#include' $(OBJS:.o=.c) $$(find . -name \*.h) | \
sort -k 2
# clean and so on.
clean:
rm -f $(TARGETS) *.o *.a */*.o */dep/*.o *~ */*~ */dep/*~
# even if there are files with these names, ignore them
.PHONY: all check libs clean distclean printh printhf
/* Light version of trace.h in atmel SAMBA tools.
*
* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \unit
///
/// !Purpose
///
/// Standard output methods for reporting debug information, warnings and
/// errors, which can be easily be turned on/off.
///
/// !Usage
/// -# Initialize the DBGU using TRACE_CONFIGURE() if you intend to eventually
/// disable ALL traces; otherwise use DBGU_Configure().
/// -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR()
/// TRACE_FATAL() macros to output traces throughout the program.
/// -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2
/// and Fatal 1. Disable a group of traces by changing the value of
/// TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL
/// are not generated. To generate no trace, use the reserved value 0.
/// -# Trace disabling can be static or dynamic. If dynamic disabling is selected
/// the trace level can be modified in runtime. If static disabling is selected
/// the disabled traces are not compiled.
///
/// !Trace level description
/// -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program,
/// and which do not produce meaningful information otherwise.
/// -# TRACE_INFO (4): Informational trace about the program execution. Should
/// enable the user to see the execution flow.
/// -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case
/// it can be discarded safely; it may even be expected.
/// -# TRACE_ERROR (2): Indicates an error which may not stop the program execution,
/// but which indicates there is a problem with the code.
/// -# TRACE_FATAL (1): Indicates a major error which prevents the program from going
/// any further.
//------------------------------------------------------------------------------
#ifndef TRACE_H
#define TRACE_H
#include <stdio.h>
//------------------------------------------------------------------------------
// Global Definitions
//------------------------------------------------------------------------------
#define TRACE_LEVEL_DEBUG 5
#define TRACE_LEVEL_INFO 4
#define TRACE_LEVEL_WARNING 3
#define TRACE_LEVEL_ERROR 2
#define TRACE_LEVEL_FATAL 1
#define TRACE_LEVEL_NO_TRACE 0
// By default, all traces are output except the debug one.
#if !defined(TRACE_LEVEL)
#define TRACE_LEVEL TRACE_LEVEL_INFO
#endif
// By default, trace level is static (not dynamic)
#if !defined(DYN_TRACES)
#define DYN_TRACES 0
#endif
#if defined(NOTRACE)
#error "Error: NOTRACE has to be not defined !"
#endif
#undef NOTRACE
#if (DYN_TRACES==0)
#if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
#define NOTRACE
#endif
#endif
//------------------------------------------------------------------------------
// Global Macros
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Outputs a formatted string using <printf> if the log level is high
/// enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
/// \param format Formatted string to output.
/// \param ... Additional parameters depending on formatted string.
//------------------------------------------------------------------------------
#if defined(NOTRACE)
// Empty macro
#define TRACE_DEBUG(...) { }
#define TRACE_INFO(...) { }
#define TRACE_WARNING(...) { }
#define TRACE_ERROR(...) { }
#define TRACE_FATAL(...) { while(1); }
#define TRACE_DEBUG_WP(...) { }
#define TRACE_INFO_WP(...) { }
#define TRACE_WARNING_WP(...) { }
#define TRACE_ERROR_WP(...) { }
#define TRACE_FATAL_WP(...) { while(1); }
#elif (DYN_TRACES == 1)
#define TRACE_FILE stderr
// Trace output depends on traceLevel value
#define TRACE_DEBUG(...) { if (traceLevel >= TRACE_LEVEL_DEBUG) { fprintf(TRACE_FILE,"-D- " __VA_ARGS__); } }
#define TRACE_INFO(...) { if (traceLevel >= TRACE_LEVEL_INFO) { fprintf(TRACE_FILE,"-I- " __VA_ARGS__); } }
#define TRACE_WARNING(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { fprintf(TRACE_FILE,"-W- " __VA_ARGS__); } }
#define TRACE_ERROR(...) { if (traceLevel >= TRACE_LEVEL_ERROR) { fprintf(TRACE_FILE,"-E- " __VA_ARGS__); } }
#define TRACE_FATAL(...) { if (traceLevel >= TRACE_LEVEL_FATAL) { fprintf(TRACE_FILE,"-F- " __VA_ARGS__); while(1); } }
#define TRACE_DEBUG_WP(...) { if (traceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } }
#define TRACE_INFO_WP(...) { if (traceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } }
#define TRACE_WARNING_WP(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
#define TRACE_ERROR_WP(...) { if (traceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } }
#define TRACE_FATAL_WP(...) { if (traceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while(1); } }
#else
// Trace compilation depends on TRACE_LEVEL value
#if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
#define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); }
#define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_DEBUG(...) { }
#define TRACE_DEBUG_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
#define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); }
#define TRACE_INFO_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_INFO(...) { }
#define TRACE_INFO_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
#define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); }
#define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_WARNING(...) { }
#define TRACE_WARNING_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
#define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); }
#define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); }
#else
#define TRACE_ERROR(...) { }
#define TRACE_ERROR_WP(...) { }
#endif
#if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
#define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while(1); }
#define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while(1); }
#else
#define TRACE_FATAL(...) { while(1); }
#define TRACE_FATAL_WP(...) { while(1); }
#endif
#endif
#define DUMP_REG(structname, periph, reg) \
TRACE_INFO("%s%s = 0x%08x\r\n", #periph,#reg, \
((AT91PS_##structname )(AT91C_BASE_##periph)) -> structname##_##reg);
//------------------------------------------------------------------------------
// Exported variables
//------------------------------------------------------------------------------
// Depending on DYN_TRACES, traceLevel is a modifable runtime variable
// or a define
#if !defined(NOTRACE) && (DYN_TRACES == 1)
extern unsigned int traceLevel;
#endif
#endif //#ifndef TRACE_H
This diff is collapsed.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#include <linux/net_tstamp.h>
#include <linux/errqueue.h>
#include <linux/sockios.h>
#include <sys/time.h>
#include <asm/types.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <asm/socket.h>
#include <signal.h>
#include "ptpd_netif.h"
#include "hal_client.h"
#define NUMBER_PORTS 18
#define IFACE_NAME_LENGTH 16
#define UUID_LENGTH 6
#define ETHER_MTU 1518
typedef struct
{
int repeat;
uint64_t start_tics;
uint64_t timeout;
} timeout_t; //
typedef struct timeval timeval_t;
PACKED struct etherframe {
struct ethhdr ether;
char data[ETHER_MTU];
};
const mac_addr_t MULTICAST_ADDR = {0x01, 0x1b, 0x19, 0 , 0, 0};
const mac_addr_t UNICAST_ADDR = {0x01, 0x1b, 0x19 , 0 , 0, 0};
const mac_addr_t BCAST_ADDR = {0xFF, 0xFF, 0xFF , 0xFF , 0xFF, 0xFF};
const mac_addr_t CPU_ADDR = {0, 0, 0 , 0 , 0, 0};
typedef struct {
int family;
mac_addr_t mac;
mac_addr_t mac_dest;
ipv4_addr_t ip;
uint16_t ethertype;
uint16_t physical_port;
char if_name[IFACE_NAME_LEN];
} sockaddr_t;
typedef struct{
int fd;
sockaddr_t bind_addr;
mac_addr_t local_mac;
int if_index;
uint32_t clock_period;
uint32_t phase_transition;
uint32_t dmtd_phase;
int dmtd_phase_valid;
timeout_t dmtd_update_tmo;
} socket_t;
typedef struct {
socket_t *sock;
sockaddr_t multicastAddr;
sockaddr_t unicastAddr;
sockaddr_t selfAddr;
char port_uuid_field[UUID_LENGTH];
char ifaceName[IFACE_NAME_LEN];
uint16_t portNumber;
uint8_t linkUP;
} net_t;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment