Commit cd2a1001 authored by Alessandro Rubini's avatar Alessandro Rubini

msg (and common-fun.h): merge extension into std, using hooks

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent f62f7bc6
...@@ -320,6 +320,8 @@ struct pp_ext_hooks { ...@@ -320,6 +320,8 @@ struct pp_ext_hooks {
void (*handle_announce)(struct pp_instance *ppi); void (*handle_announce)(struct pp_instance *ppi);
int (*handle_followup)(struct pp_instance *ppi, TimeInternal *orig, int (*handle_followup)(struct pp_instance *ppi, TimeInternal *orig,
TimeInternal *correction_field); TimeInternal *correction_field);
int (*pack_announce)(struct pp_instance *ppi);
void (*unpack_announce)(void *buf, MsgAnnounce *ann);
}; };
extern struct pp_ext_hooks pp_hooks; /* The one for the extension we build */ extern struct pp_ext_hooks pp_hooks; /* The one for the extension we build */
......
...@@ -7,7 +7,6 @@ LIBWRO := $D/libwr.o ...@@ -7,7 +7,6 @@ LIBWRO := $D/libwr.o
LIBS += $(LIBWRO) LIBS += $(LIBWRO)
OBJ-libwr := $D/fsm-table.o \ OBJ-libwr := $D/fsm-table.o \
$D/msg.o \
$D/hooks.o \ $D/hooks.o \
$D/state-wr-present.o \ $D/state-wr-present.o \
$D/state-wr-m-lock.o \ $D/state-wr-m-lock.o \
......
/*
* Aurelio Colosimo for CERN, 2011 -- GNU LGPL v2.1 or later
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*/
#ifndef __WREXT_COMMON_FUN_H__
#define __WREXT_COMMON_FUN_H__
#include <ppsi/ppsi.h>
/* Contains all functions common to more than one state */
/* The following macros are used both by msg.c and by wr-msg.c */
#ifdef VERB_LOG_MSGS
#define MSG_SEND_AND_RET_VARLEN(x,y,z,w)\
if (pp_send_packet(ppi, ppi->buf_out, w,\
&ppi->last_snt_time, PP_NP_##y , z) < w) {\
PP_PRINTF("%s(%d) Message can't be sent -> FAULTY state!\n",\
pp_msg_names[PPM_##x], PPM_##x);\
return -1;\
}\
PP_VPRINTF("SENT %02d %d.%d %s \n", w,\
ppi->last_snt_time.seconds,\
ppi->last_snt_time.nanoseconds,pp_msg_names[PPM_##x]);\
ppi->sent_seq_id[PPM_## x]++;\
return 0;
#else
#define MSG_SEND_AND_RET_VARLEN(x,y,z,w)\
if (pp_send_packet(ppi, ppi->buf_out, w,\
&ppi->last_snt_time, PP_NP_##y , z) < w) {\
return -1;\
}\
ppi->sent_seq_id[PPM_## x]++;\
return 0;
#endif
#define MSG_SEND_AND_RET(x,y,z)\
MSG_SEND_AND_RET_VARLEN(x,y,z,PP_## x ##_LENGTH)
/* returns -1 in case of error, see below */
int st_com_execute_slave(struct pp_instance *ppi, int check_delayreq);
void st_com_restart_annrec_timer(struct pp_instance *ppi);
int st_com_check_record_update(struct pp_instance *ppi);
/* Each of the following "handle" functions" return 0 in case of correct
* message, -1 in case the message contained in buf is not proper (e.g. size
* is not the expected one
*/
int st_com_slave_handle_announce(struct pp_instance *ppi, unsigned char *buf,
int len);
int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf,
int len);
int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int len);
int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int len);
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int len);
int st_com_handle_pdelay_req(struct pp_instance *ppi, unsigned char *buf,
int len);
#endif /* __WREXT_COMMON_FUN_H__ */
...@@ -142,6 +142,25 @@ static int wr_handle_followup(struct pp_instance *ppi, ...@@ -142,6 +142,25 @@ static int wr_handle_followup(struct pp_instance *ppi,
return 1; /* the caller returns too */ return 1; /* the caller returns too */
} }
int wr_pack_announce(struct pp_instance *ppi)
{
if (WR_DSPOR(ppi)->wrConfig != NON_WR &&
WR_DSPOR(ppi)->wrConfig != WR_S_ONLY) {
msg_pack_announce_wr_tlv(ppi);
return WR_ANNOUNCE_LENGTH;
}
return PP_ANNOUNCE_LENGTH;
}
void wr_unpack_announce(void *buf, MsgAnnounce *ann)
{
int msg_len = htons(*(UInteger16 *) (buf + 2));
if (msg_len > PP_ANNOUNCE_LENGTH) {
msg_unpack_announce_wr_tlv(buf, ann);
}
}
struct pp_ext_hooks pp_hooks = { struct pp_ext_hooks pp_hooks = {
.init = wr_init, .init = wr_init,
...@@ -154,4 +173,6 @@ struct pp_ext_hooks pp_hooks = { ...@@ -154,4 +173,6 @@ struct pp_ext_hooks pp_hooks = {
.execute_slave = wr_execute_slave, .execute_slave = wr_execute_slave,
.handle_announce = wr_handle_announce, .handle_announce = wr_handle_announce,
.handle_followup = wr_handle_followup, .handle_followup = wr_handle_followup,
.pack_announce = wr_pack_announce,
.unpack_announce = wr_unpack_announce,
}; };
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "wr-api.h" #include "wr-api.h"
#include "common-fun.h" #include "../proto-standard/common-fun.h"
int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen) int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include <ppsi/diag.h> #include <ppsi/diag.h>
#include "wr-api.h" #include "wr-api.h"
#include "common-fun.h" #include "../proto-standard/common-fun.h"
/* /*
* WR way to handle little/big endianess * WR way to handle little/big endianess
......
...@@ -39,4 +39,30 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf, ...@@ -39,4 +39,30 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int st_com_handle_pdelay_req(struct pp_instance *ppi, unsigned char *buf, int st_com_handle_pdelay_req(struct pp_instance *ppi, unsigned char *buf,
int len); int len);
#ifdef VERB_LOG_MSGS
#define MSG_SEND_AND_RET_VARLEN(x,y,z,w)\
if (pp_send_packet(ppi, ppi->buf_out, w,\
&ppi->last_snt_time, PP_NP_##y , z) < w) {\
PP_PRINTF("%s(%d) Message can't be sent -> FAULTY state!\n",\
pp_msg_names[PPM_##x], PPM_##x);\
return -1;\
}\
PP_VPRINTF("SENT %02d %d.%d %s \n", w,\
ppi->last_snt_time.seconds,\
ppi->last_snt_time.nanoseconds,pp_msg_names[PPM_##x]);\
ppi->sent_seq_id[PPM_## x]++;\
return 0;
#else
#define MSG_SEND_AND_RET_VARLEN(x,y,z,w)\
if (pp_send_packet(ppi, ppi->buf_out, w,\
&ppi->last_snt_time, PP_NP_##y , z) < w) {\
return -1;\
}\
ppi->sent_seq_id[PPM_## x]++;\
return 0;
#endif
#define MSG_SEND_AND_RET(x,y,z)\
MSG_SEND_AND_RET_VARLEN(x,y,z,PP_## x ##_LENGTH)
#endif /* __COMMON_FUN_H */ #endif /* __COMMON_FUN_H */
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include <ppsi/diag.h> #include <ppsi/diag.h>
#include "common-fun.h"
static inline void Integer64_display(const char *label, Integer64 *bigint) static inline void Integer64_display(const char *label, Integer64 *bigint)
{ {
...@@ -71,6 +72,7 @@ static inline void msg_display_announce(MsgAnnounce *announce) ...@@ -71,6 +72,7 @@ static inline void msg_display_announce(MsgAnnounce *announce)
PP_VPRINTF("stepsRemoved: %d\n", announce->stepsRemoved); PP_VPRINTF("stepsRemoved: %d\n", announce->stepsRemoved);
PP_VPRINTF("timeSource: %d\n", announce->timeSource); PP_VPRINTF("timeSource: %d\n", announce->timeSource);
PP_VPRINTF("\n"); PP_VPRINTF("\n");
/* FIXME: diagnostic for extension */
#endif #endif
} }
...@@ -226,6 +228,8 @@ int msg_pack_announce(struct pp_instance *ppi) ...@@ -226,6 +228,8 @@ int msg_pack_announce(struct pp_instance *ppi)
*(UInteger16 *) (buf + 61) = htons(DSCUR(ppi)->stepsRemoved); *(UInteger16 *) (buf + 61) = htons(DSCUR(ppi)->stepsRemoved);
*(Enumeration8 *) (buf + 63) = DSPRO(ppi)->timeSource; *(Enumeration8 *) (buf + 63) = DSPRO(ppi)->timeSource;
if (pp_hooks.pack_announce)
return pp_hooks.pack_announce(ppi);
return PP_ANNOUNCE_LENGTH; return PP_ANNOUNCE_LENGTH;
} }
...@@ -252,6 +256,8 @@ void msg_unpack_announce(void *buf, MsgAnnounce *ann) ...@@ -252,6 +256,8 @@ void msg_unpack_announce(void *buf, MsgAnnounce *ann)
ann->stepsRemoved = htons(*(UInteger16 *) (buf + 61)); ann->stepsRemoved = htons(*(UInteger16 *) (buf + 61));
ann->timeSource = *(Enumeration8 *) (buf + 63); ann->timeSource = *(Enumeration8 *) (buf + 63);
if (pp_hooks.unpack_announce)
pp_hooks.unpack_announce(buf, ann);
msg_display_announce(ann); msg_display_announce(ann);
} }
...@@ -592,25 +598,12 @@ const char const * pp_msg_names[] = { ...@@ -592,25 +598,12 @@ const char const * pp_msg_names[] = {
"management" "management"
}; };
#define MSG_SEND_AND_RET(x,y,z)\
if (pp_send_packet(ppi, ppi->buf_out, PP_## x ##_LENGTH,\
&ppi->last_snt_time, PP_NP_##y , z) < PP_## x ##_LENGTH) {\
PP_PRINTF("%s(%d) Message can't be sent -> FAULTY state!\n",\
pp_msg_names[PPM_##x], PPM_##x);\
return -1;\
}\
ppi->sent_seq_id[PPM_## x]++;\
PP_VPRINTF("SENT %02d %d.%d %s \n", PP_## x ##_LENGTH,\
ppi->last_snt_time.seconds,\
ppi->last_snt_time.nanoseconds,pp_msg_names[PPM_##x]);\
return 0;
/* Pack and send on general multicast ip adress an Announce message */ /* Pack and send on general multicast ip adress an Announce message */
int msg_issue_announce(struct pp_instance *ppi) int msg_issue_announce(struct pp_instance *ppi)
{ {
msg_pack_announce(ppi); int len;
len = msg_pack_announce(ppi);
MSG_SEND_AND_RET(ANNOUNCE, GEN, 0); MSG_SEND_AND_RET_VARLEN(ANNOUNCE, GEN, 0, len);
} }
/* Pack and send on event multicast ip adress a Sync message */ /* Pack and send on event multicast ip adress a Sync message */
......
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