Commit 5874cdfe authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

general: add a msgtype array for type-specific information

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent d2a57023
...@@ -52,7 +52,7 @@ CFLAGS += -ggdb -Iinclude -fno-common ...@@ -52,7 +52,7 @@ CFLAGS += -ggdb -Iinclude -fno-common
CFLAGS += -DPPSI_VERSION=\"$(VERSION)\" CFLAGS += -DPPSI_VERSION=\"$(VERSION)\"
# to avoid ifdef as much as possible, I use the kernel trick for OBJ variables # to avoid ifdef as much as possible, I use the kernel trick for OBJ variables
OBJ-y := fsm.o diag.o timeout.o OBJ-y := fsm.o diag.o timeout.o msgtype.o
# Include arch code. Each arch chooses its own time directory.. # Include arch code. Each arch chooses its own time directory..
include arch-$(ARCH)/Makefile include arch-$(ARCH)/Makefile
......
...@@ -171,13 +171,16 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen) ...@@ -171,13 +171,16 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
{ {
struct pp_state_table_item *ip; struct pp_state_table_item *ip;
int state, err = 0; int state, err = 0;
int msgtype;
if (plen) if (plen) {
msgtype = packet[0] & 0xf;
pp_diag(ppi, frames, 1, pp_diag(ppi, frames, 1,
"RECV %02d bytes at %d.%09d (type %x, %s)\n", plen, "RECV %02d bytes at %d.%09d (type %x, %s)\n", plen,
(int)ppi->last_rcv_time.seconds, (int)ppi->last_rcv_time.seconds,
(int)ppi->last_rcv_time.nanoseconds, (int)ppi->last_rcv_time.nanoseconds, msgtype,
packet[0] & 0xf, pp_msg_names[packet[0] & 0xf]); pp_msgtype_info[msgtype].name);
}
/* /*
* Discard too short packets * Discard too short packets
......
...@@ -310,8 +310,6 @@ enum pp_std_messages { ...@@ -310,8 +310,6 @@ enum pp_std_messages {
PPM_NOTHING_TO_DO = 0x100, /* for hooks.master_msg() */ PPM_NOTHING_TO_DO = 0x100, /* for hooks.master_msg() */
}; };
extern const char const * pp_msg_names[];
/* Enumeration Domain Number (table 2, page 41) */ /* Enumeration Domain Number (table 2, page 41) */
enum ENDomainNumber { enum ENDomainNumber {
DFLT_DOMAIN_NUMBER = 0, DFLT_DOMAIN_NUMBER = 0,
......
...@@ -45,6 +45,20 @@ struct pp_vlanhdr { ...@@ -45,6 +45,20 @@ struct pp_vlanhdr {
uint16_t h_proto; uint16_t h_proto;
}; };
/* Factorize some random information in this table */
struct pp_msgtype_info {
char *name; /* For diagnostics */
uint16_t msglen;
unsigned char chtype;
unsigned char is_pdelay;
unsigned char controlField; /* Table 23 */
unsigned char logMessageInterval; /* Table 24, see defines */
#define PP_LOG_ANNOUNCE 0
#define PP_LOG_SYNC 1
#define PP_LOG_REQUEST 2
};
extern struct pp_msgtype_info pp_msgtype_info[16];
/* Helpers for the fsm (fsm-lib.c) */ /* Helpers for the fsm (fsm-lib.c) */
extern int pp_lib_may_issue_sync(struct pp_instance *ppi); extern int pp_lib_may_issue_sync(struct pp_instance *ppi);
extern int pp_lib_may_issue_announce(struct pp_instance *ppi); extern int pp_lib_may_issue_announce(struct pp_instance *ppi);
......
#include <ppsi/ppsi.h>
/*
* PP_NP_GEN/EVT is the event or general message. It selects the socket etc
* PP_P2P_MECH is used to select a destination address for pdelay frames.
* the numeric 0..5 is the "controlField" (magic ptpV1 numbers in byte 32).
* PP_LOG is the kind of logInterval to put in byte 33.
*/
struct pp_msgtype_info pp_msgtype_info[16] = {
[PPM_SYNC] = {
"sync", PP_SYNC_LENGTH,
PP_NP_EVT, PP_E2E_MECH, 0, PP_LOG_SYNC },
[PPM_DELAY_REQ] = {
"delay_req", PP_DELAY_REQ_LENGTH,
PP_NP_EVT, PP_E2E_MECH, 1, 0x7f },
[PPM_PDELAY_REQ] = {
"pdelay_req", PP_PDELAY_REQ_LENGTH,
PP_NP_EVT, PP_P2P_MECH, 5, 0x7f },
[PPM_PDELAY_RESP] = {
"pdelay_resp", PP_PDELAY_RESP_LENGTH,
PP_NP_EVT, PP_P2P_MECH, 5, 0x7f },
[PPM_FOLLOW_UP] = {
"follow_up", PP_FOLLOW_UP_LENGTH,
PP_NP_GEN, PP_E2E_MECH, 2, PP_LOG_SYNC },
[PPM_DELAY_RESP] = {
"delay_resp", PP_DELAY_RESP_LENGTH,
PP_NP_GEN, PP_E2E_MECH, 3, PP_LOG_REQUEST },
[PPM_PDELAY_R_FUP] = {
"pdelay_resp_follow_up", PP_PDELAY_R_FUP_LENGTH,
PP_NP_GEN, PP_P2P_MECH, 5, 0x7f },
[PPM_ANNOUNCE] = {
"announce", PP_ANNOUNCE_LENGTH,
PP_NP_GEN, PP_E2E_MECH, 5, PP_LOG_ANNOUNCE},
/* We don't use signaling and management, or not in the table-driven code */
[PPM_SIGNALING] = { "signaling", -1, PP_NP_GEN, PP_E2E_MECH, 5, 0x7f},
[PPM_MANAGEMENT] = { "management", -1, PP_NP_GEN, PP_E2E_MECH, 4, 0x7f},
};
...@@ -410,14 +410,14 @@ int __send_and_log(struct pp_instance *ppi, int msglen, ...@@ -410,14 +410,14 @@ int __send_and_log(struct pp_instance *ppi, int msglen,
&ppi->last_snt_time, chtype, &ppi->last_snt_time, chtype,
pdelay_addr) < msglen) { pdelay_addr) < msglen) {
pp_diag(ppi, frames, 1, "%s(%d) Message can't be sent\n", pp_diag(ppi, frames, 1, "%s(%d) Message can't be sent\n",
pp_msg_names[msgtype], msgtype); pp_msgtype_info[msgtype].name, msgtype);
return PP_SEND_ERROR; return PP_SEND_ERROR;
} }
/* FIXME: diagnosticst should be looped back in the send method */ /* FIXME: diagnosticst should be looped back in the send method */
pp_diag(ppi, frames, 1, "SENT %02d bytes at %d.%09d (%s)\n", msglen, pp_diag(ppi, frames, 1, "SENT %02d bytes at %d.%09d (%s)\n", msglen,
(int)(ppi->last_snt_time.seconds), (int)(ppi->last_snt_time.seconds),
(int)(ppi->last_snt_time.nanoseconds), (int)(ppi->last_snt_time.nanoseconds),
pp_msg_names[msgtype]); pp_msgtype_info[msgtype].name);
if (chtype == PP_NP_EVT && ppi->last_snt_time.correct == 0) if (chtype == PP_NP_EVT && ppi->last_snt_time.correct == 0)
return PP_SEND_NO_STAMP; return PP_SEND_NO_STAMP;
......
...@@ -442,20 +442,6 @@ void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp * presp) ...@@ -442,20 +442,6 @@ void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp * presp)
htons(*(UInteger16 *) (buf + 52)); htons(*(UInteger16 *) (buf + 52));
} }
const char const *pp_msg_names[16] = {
[PPM_SYNC] = "sync",
[PPM_DELAY_REQ] = "delay_req",
[PPM_PDELAY_REQ] = "pdelay_req",
[PPM_PDELAY_RESP] = "pdelay_resp",
[PPM_FOLLOW_UP] = "follow_up",
[PPM_DELAY_RESP] = "delay_resp",
[PPM_PDELAY_R_FUP] = "pdelay_resp_follow_up",
[PPM_ANNOUNCE] = "announce",
[PPM_SIGNALING] = "signaling",
[PPM_MANAGEMENT] = "management",
};
/* 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)
{ {
......
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