Commit 0c74aa23 authored by Alessandro Rubini's avatar Alessandro Rubini

Merge branch 'ptpdump-within-ppsi'

This includes the functionality of tools/ptpdump inside the ppsi
executable. Each net_ops->send and net_ops->recv must call the
dumping functions (gnu-linux and bare-* already to in this branch;
arch-wrpc does not, and I'll all it later).
parents b31bb242 1c729a8c
# Alessandro Rubini for CERN, 2011 -- public domain # Alessandro Rubini for CERN, 2011 -- public domain
CFLAGS += -ffreestanding -Os -fno-stack-protector CFLAGS += -ffreestanding -Os -fno-stack-protector -Itools
ARCH_LDFLAGS = -nostdlib -static -T $(ARCH).lds ARCH_LDFLAGS = -nostdlib -static -T $(ARCH).lds
# All files are under A (short for ARCH) or L (short for lib): I'm lazy # All files are under A (short for ARCH) or L (short for lib): I'm lazy
...@@ -18,6 +18,7 @@ OBJ-libarch := $L/bare-startup.o \ ...@@ -18,6 +18,7 @@ OBJ-libarch := $L/bare-startup.o \
$L/bare-time.o \ $L/bare-time.o \
$A/syscalls.o \ $A/syscalls.o \
lib/libc-functions.o \ lib/libc-functions.o \
lib/dump-funcs.o \
lib/cmdline.o \ lib/cmdline.o \
lib/div64.o lib/div64.o
......
# Alessandro Rubini for CERN, 2011 -- public domain # Alessandro Rubini for CERN, 2011 -- public domain
CFLAGS += -ffreestanding -Os -fno-stack-protector CFLAGS += -ffreestanding -Os -fno-stack-protector -Itools
ARCH_LDFLAGS = -nostdlib -static -T $(ARCH).lds ARCH_LDFLAGS = -nostdlib -static -T $(ARCH).lds
# All files are under A (short for ARCH) or L (short for lib): I'm lazy # All files are under A (short for ARCH) or L (short for lib): I'm lazy
...@@ -19,6 +19,7 @@ OBJ-libarch := $L/bare-startup.o \ ...@@ -19,6 +19,7 @@ OBJ-libarch := $L/bare-startup.o \
$A/syscall.o \ $A/syscall.o \
$A/syscalls.o \ $A/syscalls.o \
lib/libc-functions.o \ lib/libc-functions.o \
lib/dump-funcs.o \
lib/cmdline.o \ lib/cmdline.o \
lib/div64.o lib/div64.o
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# All files are under A (short for ARCH): I'm lazy # All files are under A (short for ARCH): I'm lazy
A := arch-$(ARCH) A := arch-$(ARCH)
CFLAGS += -DCONFIG_PPSI_RUNTIME_VERBOSITY CFLAGS += -DCONFIG_PPSI_RUNTIME_VERBOSITY -Itools
LIBARCH := $A/libarch.a LIBARCH := $A/libarch.a
...@@ -15,6 +15,7 @@ OBJ-libarch := $A/posix-startup.o \ ...@@ -15,6 +15,7 @@ OBJ-libarch := $A/posix-startup.o \
$A/posix-time.o \ $A/posix-time.o \
lib/cmdline.o \ lib/cmdline.o \
lib/libc-functions.o \ lib/libc-functions.o \
lib/dump-funcs.o \
lib/div64.o lib/div64.o
$(LIBARCH): $(OBJ-libarch) $(LIBARCH): $(OBJ-libarch)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "ptpdump.h"
#include "posix.h" #include "posix.h"
/* posix_recv_msg uses recvmsg for timestamp query */ /* posix_recv_msg uses recvmsg for timestamp query */
...@@ -93,11 +94,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -93,11 +94,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t) TimeInternal *t)
{ {
struct pp_channel *ch1, *ch2; struct pp_channel *ch1, *ch2;
int ret;
if (OPTS(ppi)->ethernet_mode) { if (OPTS(ppi)->ethernet_mode) {
int fd = NP(ppi)->ch[PP_NP_GEN].fd; int fd = NP(ppi)->ch[PP_NP_GEN].fd;
return posix_recv_msg(ppi, fd, pkt, len, t); ret = posix_recv_msg(ppi, fd, pkt, len, t);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_1588pkt("recv: ", pkt, ret, t);
return ret;
} }
/* else: UDP, we can return one frame only, so swap priority */ /* else: UDP, we can return one frame only, so swap priority */
...@@ -111,13 +116,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -111,13 +116,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len,
POSIX_ARCH(ppi)->rcv_switch = !POSIX_ARCH(ppi)->rcv_switch; POSIX_ARCH(ppi)->rcv_switch = !POSIX_ARCH(ppi)->rcv_switch;
ret = -1;
if (ch1->pkt_present) if (ch1->pkt_present)
return posix_recv_msg(ppi, ch1->fd, pkt, len, t); ret = posix_recv_msg(ppi, ch1->fd, pkt, len, t);
else if (ch2->pkt_present)
if (ch2->pkt_present) ret = posix_recv_msg(ppi, ch2->fd, pkt, len, t);
return posix_recv_msg(ppi, ch2->fd, pkt, len, t);
return -1; if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_payloadpkt("recv: ", pkt, ret, t);
return ret;
} }
static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
...@@ -125,6 +132,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -125,6 +132,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
struct ethhdr *hdr = pkt; struct ethhdr *hdr = pkt;
int ret;
if (OPTS(ppi)->ethernet_mode) { if (OPTS(ppi)->ethernet_mode) {
hdr->h_proto = htons(ETH_P_1588); hdr->h_proto = htons(ETH_P_1588);
...@@ -136,7 +144,10 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -136,7 +144,10 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t) if (t)
ppi->t_ops->get(ppi, t); ppi->t_ops->get(ppi, t);
return send(NP(ppi)->ch[PP_NP_GEN].fd, hdr, len, 0); ret = send(NP(ppi)->ch[PP_NP_GEN].fd, hdr, len, 0);
if (pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", pkt, len, t);
return ret;
} }
/* else: UDP */ /* else: UDP */
...@@ -148,10 +159,11 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -148,10 +159,11 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t) if (t)
ppi->t_ops->get(ppi, t); ppi->t_ops->get(ppi, t);
return sendto(NP(ppi)->ch[chtype].fd, pkt, len, 0, ret = sendto(NP(ppi)->ch[chtype].fd, pkt, len, 0,
(struct sockaddr *)&addr, sizeof(struct sockaddr_in)); (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
if (pp_diag_allow(ppi, frames, 2))
return -1; dump_payloadpkt("send: ", pkt, len, t);
return ret;
} }
/* To open a channel we must bind to an interface and so on */ /* To open a channel we must bind to an interface and so on */
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
CFLAGS += -ffreestanding -Os \ CFLAGS += -ffreestanding -Os \
-ffunction-sections -fdata-sections \ -ffunction-sections -fdata-sections \
-mmultiply-enabled -mbarrel-shift-enabled \ -mmultiply-enabled -mbarrel-shift-enabled \
-Itools
ARCH_LDFLAGS = -nostdlib -static -T $(ARCH).lds ARCH_LDFLAGS = -nostdlib -static -T $(ARCH).lds
...@@ -31,6 +32,7 @@ OBJ-libarch := $A/wrpc-socket.o \ ...@@ -31,6 +32,7 @@ OBJ-libarch := $A/wrpc-socket.o \
$A/wrpc-io.o \ $A/wrpc-io.o \
$A/wrpc-spll.o \ $A/wrpc-spll.o \
$A/wrpc-calibration.o \ $A/wrpc-calibration.o \
lib/dump-funcs.o \
lib/div64.o lib/div64.o
$(LIBARCH): $(OBJ-libarch) $(LIBARCH): $(OBJ-libarch)
......
...@@ -16,7 +16,7 @@ static void pp_fsm_printf(struct pp_instance *ppi, char *fmt, ...) ...@@ -16,7 +16,7 @@ static void pp_fsm_printf(struct pp_instance *ppi, char *fmt, ...)
TimeInternal t; TimeInternal t;
unsigned long oflags = pp_global_flags; unsigned long oflags = pp_global_flags;
if (!__PP_DIAG_ALLOW(ppi, pp_dt_fsm, 1)) if (!pp_diag_allow(ppi, fsm, 1))
return; return;
/* temporarily set NOTIMELOG, as we'll print the time ourselves */ /* temporarily set NOTIMELOG, as we'll print the time ourselves */
...@@ -87,7 +87,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen) ...@@ -87,7 +87,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
*/ */
if (plen) { if (plen) {
if (plen >= PP_HEADER_LENGTH) if (plen >= PP_HEADER_LENGTH)
err = msg_unpack_header(ppi, packet); err = msg_unpack_header(ppi, packet, plen);
else else
err = 1; err = 1;
if (err) { if (err) {
......
...@@ -128,6 +128,9 @@ extern void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th, ...@@ -128,6 +128,9 @@ extern void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th,
PP_HAS_DIAG; /* return 1 if done, 0 if not done */ \ PP_HAS_DIAG; /* return 1 if done, 0 if not done */ \
}) })
#define pp_diag_allow(ppi_, th_, level_) \
(PP_HAS_DIAG && __PP_DIAG_ALLOW(ppi_, pp_dt_ ## th_, level_))
/* /*
* And this is the parser of the string. Internally it obeys VERB_LOG_MESGS * And this is the parser of the string. Internally it obeys VERB_LOG_MESGS
* to set the value to 0xfffffff0 to be compatible with previous usage. * to set the value to 0xfffffff0 to be compatible with previous usage.
......
...@@ -241,7 +241,7 @@ extern int bmc(struct pp_instance *ppi); ...@@ -241,7 +241,7 @@ extern int bmc(struct pp_instance *ppi);
/* msg.c */ /* msg.c */
extern void msg_pack_header(struct pp_instance *ppi, void *buf); extern void msg_pack_header(struct pp_instance *ppi, void *buf);
extern int __attribute__((warn_unused_result)) extern int __attribute__((warn_unused_result))
msg_unpack_header(struct pp_instance *ppi, void *buf); msg_unpack_header(struct pp_instance *ppi, void *buf, int plen);
void *msg_copy_header(MsgHeader *dest, MsgHeader *src); void *msg_copy_header(MsgHeader *dest, MsgHeader *src);
extern void msg_pack_sync(struct pp_instance *ppi, Timestamp *orig_tstamp); extern void msg_pack_sync(struct pp_instance *ppi, Timestamp *orig_tstamp);
extern void msg_unpack_sync(void *buf, MsgSync *sync); extern void msg_unpack_sync(void *buf, MsgSync *sync);
......
...@@ -4,22 +4,28 @@ ...@@ -4,22 +4,28 @@
/* Socket interface for bare Linux */ /* Socket interface for bare Linux */
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "ptpdump.h"
#include "bare-linux.h" #include "bare-linux.h"
/* FIXME: which socket we receive and send with? */ /* FIXME: which socket we receive and send with? */
static int bare_net_recv(struct pp_instance *ppi, void *pkt, int len, static int bare_net_recv(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t) TimeInternal *t)
{ {
int ret;
if (t) if (t)
ppi->t_ops->get(ppi, t); ppi->t_ops->get(ppi, t);
return sys_recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0); ret = sys_recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_1588pkt("recv: ", pkt, ret, t);
return ret;
} }
static int bare_net_send(struct pp_instance *ppi, void *pkt, int len, static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr) TimeInternal *t, int chtype, int use_pdelay_addr)
{ {
struct bare_ethhdr *hdr = pkt; struct bare_ethhdr *hdr = pkt;
int ret;
hdr->h_proto = htons(ETH_P_1588); hdr->h_proto = htons(ETH_P_1588);
...@@ -31,7 +37,10 @@ static int bare_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -31,7 +37,10 @@ static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t) if (t)
ppi->t_ops->get(ppi, t); ppi->t_ops->get(ppi, t);
return sys_send(NP(ppi)->ch[chtype].fd, pkt, len, 0); ret = sys_send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", pkt, len, t);
return ret;
} }
#define SHUT_RD 0 #define SHUT_RD 0
......
../tools/dump-funcs.c
\ No newline at end of file
/*
* This header is a hack, meant to provide data structures for
* tools/dump-funcs.c when it is built in a freestanding environment.
*/
#include <arch/arch.h> /* for ntohs and ntohl */
/* From: /usr/include/linux/if_ether.h with s/__be16/uint16_t/ */
#define ETH_ALEN 6 /* Octets in one ethernet addr */
#define ETH_HLEN 14 /* Total octets in header. */
struct ethhdr {
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
unsigned char h_source[ETH_ALEN]; /* source ether addr */
uint16_t h_proto; /* packet type ID field */
} __attribute__((packed));
/* From: /usr/include/netinet/ip.h, renaming the bitfield to avoid using them */
struct iphdr {
unsigned int ihl_unused:4;
unsigned int version_unused:4;
uint8_t tos;
uint16_t tot_len;
uint16_t id;
uint16_t frag_off;
uint8_t ttl;
uint8_t protocol;
uint16_t check;
uint32_t saddr;
uint32_t daddr;
/*The options start here. */
};
/* From: /usr/include/netinet/udp.h */
struct udphdr {
uint16_t source;
uint16_t dest;
uint16_t len;
uint16_t check;
};
...@@ -6,89 +6,8 @@ ...@@ -6,89 +6,8 @@
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "common-fun.h" #include "common-fun.h"
/*
* Temporarily, use the diagnostic level to set a fake pp_verbose_dump.
* We can't use ppi-specific flags at this point, but I plan to fix
* this msg.c overall -- ARub
*/
#define pp_verbose_dump \
__PP_DIAG_ALLOW_FLAGS(pp_global_flags, pp_dt_frames, 2)
static void Integer64_display(const char *label, Integer64 *bigint)
{
if (pp_verbose_dump) {
pp_Vprintf("%s:\n", label);
pp_Vprintf("LSB: %u\n", bigint->lsb);
pp_Vprintf("MSB: %d\n", bigint->msb);
}
}
static void UInteger48_display(const char *label, UInteger48 *bigint)
{
if (pp_verbose_dump) {
pp_Vprintf("%s:\n", label);
pp_Vprintf("LSB: %u\n", bigint->lsb);
pp_Vprintf("MSB: %u\n", bigint->msb);
}
}
static void timestamp_display(const char *label, Timestamp *timestamp)
{
if (pp_verbose_dump) {
pp_Vprintf("%s:\n", label);
UInteger48_display("seconds", &timestamp->secondsField);
pp_Vprintf("nanoseconds: %u\n", timestamp->nanosecondsField);
}
}
static void msg_display_header(MsgHeader *header)
{
if (pp_verbose_dump) {
pp_Vprintf("Message header:\n");
pp_Vprintf("\n");
pp_Vprintf("transportSpecific: %d\n",
header->transportSpecific);
pp_Vprintf("messageType: %d\n", header->messageType);
pp_Vprintf("versionPTP: %d\n", header->versionPTP);
pp_Vprintf("messageLength: %d\n", header->messageLength);
pp_Vprintf("domainNumber: %d\n", header->domainNumber);
pp_Vprintf("FlagField %02x:%02x\n", header->flagField[0],
header->flagField[1]);
Integer64_display("correctionfield", &header->correctionfield);
/* FIXME diag portIdentity_display(&h->sourcePortIdentity); */
pp_Vprintf("sequenceId: %d\n", header->sequenceId);
pp_Vprintf("controlField: %d\n", header->controlField);
pp_Vprintf("logMessageInterval: %d\n",
header->logMessageInterval);
pp_Vprintf("\n");
}
}
static void msg_display_announce(MsgAnnounce *announce)
{
if (pp_verbose_dump) {
pp_Vprintf("Message ANNOUNCE:\n");
timestamp_display("Origin Timestamp",
&announce->originTimestamp);
pp_Vprintf("currentUtcOffset: %d\n",
announce->currentUtcOffset);
pp_Vprintf("grandMasterPriority1: %d\n",
announce->grandmasterPriority1);
pp_Vprintf("grandMasterClockQuality:\n");
/* FIXME diag clockQuality_display(&ann->gmasterQuality); */
pp_Vprintf("grandMasterPriority2: %d\n",
announce->grandmasterPriority2);
pp_Vprintf("grandMasterIdentity:\n");
/* FIXME diag clockIdentity_display(ann->gmasterIdentity); */
pp_Vprintf("stepsRemoved: %d\n", announce->stepsRemoved);
pp_Vprintf("timeSource: %d\n", announce->timeSource);
pp_Vprintf("\n");
/* FIXME: diagnostic for extension */
}
}
/* Unpack header from in buffer to msg_tmp_header field */ /* Unpack header from in buffer to msg_tmp_header field */
int msg_unpack_header(struct pp_instance *ppi, void *buf) int msg_unpack_header(struct pp_instance *ppi, void *buf, int plen)
{ {
MsgHeader *hdr = &ppi->received_ptp_header; MsgHeader *hdr = &ppi->received_ptp_header;
...@@ -134,8 +53,6 @@ int msg_unpack_header(struct pp_instance *ppi, void *buf) ...@@ -134,8 +53,6 @@ int msg_unpack_header(struct pp_instance *ppi, void *buf)
ppi->is_from_cur_par = 1; ppi->is_from_cur_par = 1;
else else
ppi->is_from_cur_par = 0; ppi->is_from_cur_par = 0;
msg_display_header(hdr);
return 0; return 0;
} }
...@@ -202,12 +119,6 @@ void msg_unpack_sync(void *buf, MsgSync *sync) ...@@ -202,12 +119,6 @@ void msg_unpack_sync(void *buf, MsgSync *sync)
htonl(*(UInteger32 *) (buf + 36)); htonl(*(UInteger32 *) (buf + 36));
sync->originTimestamp.nanosecondsField = sync->originTimestamp.nanosecondsField =
htonl(*(UInteger32 *) (buf + 40)); htonl(*(UInteger32 *) (buf + 40));
if (pp_verbose_dump) {
PP_VPRINTF("Message SYNC\n");
timestamp_display("Origin Timestamp", &sync->originTimestamp);
PP_VPRINTF("\n");
}
} }
/* Pack Announce message into out buffer of ppi */ /* Pack Announce message into out buffer of ppi */
...@@ -271,7 +182,6 @@ void msg_unpack_announce(void *buf, MsgAnnounce *ann) ...@@ -271,7 +182,6 @@ void msg_unpack_announce(void *buf, MsgAnnounce *ann)
if (pp_hooks.unpack_announce) if (pp_hooks.unpack_announce)
pp_hooks.unpack_announce(buf, ann); pp_hooks.unpack_announce(buf, ann);
msg_display_announce(ann);
} }
/* Pack Follow Up message into out buffer of ppi*/ /* Pack Follow Up message into out buffer of ppi*/
...@@ -314,13 +224,6 @@ void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup) ...@@ -314,13 +224,6 @@ void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
htonl(*(UInteger32 *) (buf + 36)); htonl(*(UInteger32 *) (buf + 36));
flwup->preciseOriginTimestamp.nanosecondsField = flwup->preciseOriginTimestamp.nanosecondsField =
htonl(*(UInteger32 *) (buf + 40)); htonl(*(UInteger32 *) (buf + 40));
if (pp_verbose_dump) {
PP_VPRINTF("Message FOLLOW_UP\n");
timestamp_display("Precise Origin Timestamp",
&flwup->preciseOriginTimestamp);
PP_VPRINTF("\n");
}
} }
/* pack DelayReq message into out buffer of ppi */ /* pack DelayReq message into out buffer of ppi */
...@@ -403,13 +306,6 @@ void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req) ...@@ -403,13 +306,6 @@ void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req)
htonl(*(UInteger32 *) (buf + 36)); htonl(*(UInteger32 *) (buf + 36));
delay_req->originTimestamp.nanosecondsField = delay_req->originTimestamp.nanosecondsField =
htonl(*(UInteger32 *) (buf + 40)); htonl(*(UInteger32 *) (buf + 40));
if (pp_verbose_dump) {
PP_VPRINTF("Message DELAY_REQ\n");
timestamp_display("Origin Timestamp",
&delay_req->originTimestamp);
PP_VPRINTF("\n");
}
} }
/* Unpack delayResp message from IN buffer of ppi to msgtmp.presp */ /* Unpack delayResp message from IN buffer of ppi to msgtmp.presp */
...@@ -425,14 +321,6 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp) ...@@ -425,14 +321,6 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
(buf + 44), PP_CLOCK_IDENTITY_LENGTH); (buf + 44), PP_CLOCK_IDENTITY_LENGTH);
resp->requestingPortIdentity.portNumber = resp->requestingPortIdentity.portNumber =
htons(*(UInteger16 *) (buf + 52)); htons(*(UInteger16 *) (buf + 52));
if (pp_verbose_dump) {
PP_VPRINTF("Message DELAY_RESP\n");
timestamp_display("Receive Timestamp",
&resp->receiveTimestamp);
/* FIXME diag display requestingPortIdentity */
PP_VPRINTF("\n");
}
} }
const char const *pp_msg_names[] = { const char const *pp_msg_names[] = {
......
...@@ -9,7 +9,7 @@ STRIP = $(CROSS_COMPILE)strip ...@@ -9,7 +9,7 @@ STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -Wall -ggdb -I../include/ppsi CFLAGS = -Wall -ggdb -I../include
PROGS = ptpdump adjtime jmptime chktime PROGS = ptpdump adjtime jmptime chktime
LDFLAGS += -lrt LDFLAGS += -lrt
......
This diff is collapsed.
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <net/if_arp.h> #include <net/if_arp.h>
#include <netpacket/packet.h> #include <netpacket/packet.h>
#include <ieee1588_types.h> /* from ../include/ppsi */ #include <ppsi/ieee1588_types.h> /* from ../include */
#include "decent_types.h" #include "decent_types.h"
#include "ptpdump.h" #include "ptpdump.h"
...@@ -26,9 +26,28 @@ ...@@ -26,9 +26,28 @@
#define ETH_P_1588 0x88F7 #define ETH_P_1588 0x88F7
#endif #endif
void print_spaces(struct TimeInternal *ti)
{
static struct TimeInternal prev_ti;
int i, diffms;
if (prev_ti.seconds) {
diffms = (ti->seconds - prev_ti.seconds) * 1000
+ (ti->nanoseconds / 1000 / 1000)
- (prev_ti.nanoseconds / 1000 / 1000);
/* empty lines, one every .25 seconds, at most 10 of them */
for (i = 250; i < 2500 && i < diffms; i += 250)
printf("\n");
printf("TIMEDELTA: %i ms\n", diffms);
}
prev_ti = *ti;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int sock; int sock, ret;
struct packet_mreq req; struct packet_mreq req;
struct ifreq ifr; struct ifreq ifr;
char *ifname = "eth0"; char *ifname = "eth0";
...@@ -68,6 +87,8 @@ int main(int argc, char **argv) ...@@ -68,6 +87,8 @@ int main(int argc, char **argv)
static unsigned char prev[1500]; static unsigned char prev[1500];
static int prevlen; static int prevlen;
unsigned char buf[1500]; unsigned char buf[1500];
struct TimeInternal ti;
struct timeval tv;
struct sockaddr_in from; struct sockaddr_in from;
socklen_t fromlen = sizeof(from); socklen_t fromlen = sizeof(from);
...@@ -75,6 +96,12 @@ int main(int argc, char **argv) ...@@ -75,6 +96,12 @@ int main(int argc, char **argv)
len = recvfrom(sock, buf, sizeof(buf), MSG_TRUNC, len = recvfrom(sock, buf, sizeof(buf), MSG_TRUNC,
(struct sockaddr *) &from, &fromlen); (struct sockaddr *) &from, &fromlen);
/* Get the receive time, copy it to TimeInternal */
gettimeofday(&tv, NULL);
ti.seconds = tv.tv_sec;
ti.nanoseconds = tv.tv_usec * 1000;
if (len > sizeof(buf)) if (len > sizeof(buf))
len = sizeof(buf); len = sizeof(buf);
/* for some reasons, we receive it three times, check dups */ /* for some reasons, we receive it three times, check dups */
...@@ -89,18 +116,35 @@ int main(int argc, char **argv) ...@@ -89,18 +116,35 @@ int main(int argc, char **argv)
ip = (void *)(buf + ETH_HLEN); ip = (void *)(buf + ETH_HLEN);
switch(ntohs(eth->h_proto)) { switch(ntohs(eth->h_proto)) {
case ETH_P_IP: case ETH_P_IP:
if (len < ETH_HLEN + sizeof(*ip)) {
struct udphdr *udp = (void *)(ip + 1);
int udpdest = ntohs(udp->dest);
/*
* Filter before calling the dump function, otherwise
* we'll report TIMEDELAY for not-relevant frames
*/
if (len < ETH_HLEN + sizeof(*ip) + sizeof(*udp))
continue; continue;
if (ip->protocol != IPPROTO_UDP) if (ip->protocol != IPPROTO_UDP)
continue; continue;
dump_udppkt(buf, len); if (udpdest != 319 && udpdest != 320)
continue;
print_spaces(&ti);
ret = dump_udppkt("", buf, len, &ti);
break; break;
}
case ETH_P_1588: case ETH_P_1588:
dump_1588pkt(buf, len); print_spaces(&ti);
ret = dump_1588pkt("", buf, len, &ti);
break; break;
default: default:
ret = -1;
continue; continue;
} }
if (ret == 0)
putchar('\n');
fflush(stdout); fflush(stdout);
} }
......
#ifndef __PTPDUMP_H__
#define __PTPDUMP_H__
int dumpstruct(FILE *dest, char *prefix, char *name, void *ptr, int size); #if __STDC_HOSTED__
void dump_eth(struct ethhdr *eth); #include <time.h>
void dump_ip(struct iphdr *ip); #include <sys/time.h>
void dump_udp(struct udphdr *udp); #include <netinet/ip.h> /* struct iphdr */
void dump_1stamp(char *s, struct stamp *t); #include <netinet/udp.h> /* struct udphdr */
void dump_1quality(char *s, ClockQuality *q); #include <linux/if_ether.h> /* struct ethhdr */
void dump_1clockid(char *s, ClockIdentity i); #else
void dump_1port(char *s, unsigned char *p); #include <ppsi/ppsi.h>
void dump_msg_announce(struct ptp_announce *p); #include "../lib/network_types.h"
void dump_msg_sync_etc(char *s, struct ptp_sync_etc *p); #define printf pp_printf
void dump_msg_resp_etc(char *s, struct ptp_sync_etc *p); #endif
int dump_tlv(struct ptp_tlv *tlv, int totallen);
void dump_payload(void *pl, int len);
int dump_udppkt(void *buf, int len);
int dump_1588pkt(void *buf, int len);
int dump_udppkt(char *prefix, void *buf, int len, struct TimeInternal *ti);
int dump_payloadpkt(char *prefix, void *buf, int len, struct TimeInternal *ti);
int dump_1588pkt(char *prefix, void *buf, int len, struct TimeInternal *ti);
#endif /* __PTPDUMP_H__ */
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