Commit b5cdb8a3 authored by Sven Meier's avatar Sven Meier Committed by Adam Wujek

audit porting: ported the patches of the audit chapter 2.4.1

The patches from the audit chapter 2.4.1 were ported, some of the
changes were not ported due to previous changes or different
foreign master handling, eg.g announce unpacking is still done since
this seems more streamline with other message handling and is actually
still used for field extraction for the foreign master data set
parent ab3d3253
......@@ -64,16 +64,23 @@ struct pp_channel {
* it is called foreignMasterDS, see 9.3.2.4
*/
struct pp_frgn_master {
PortIdentity port_id; /* used to identify old/new masters */
PortIdentity source_id; /* used for the dataset comparisment */
/* how many announce messages from this port where received in the
* interval */
int ann_cnt[PP_FOREIGN_MASTER_TIME_WINDOW];
/* We don't need all fields of the following ones */
MsgAnnounce ann;
MsgHeader hdr;
/* on which port we received the frame */
PortIdentity receivePortIdentity;
/* BMC related information */
UInteger16 sequenceId;
PortIdentity sourcePortIdentity;
Octet flagField[2];
Integer16 currentUtcOffset;
UInteger8 grandmasterPriority1;
ClockQuality grandmasterClockQuality;
UInteger8 grandmasterPriority2;
ClockIdentity grandmasterIdentity;
UInteger16 stepsRemoved;
Enumeration8 timeSource;
unsigned long ext_specific; /* used by extension */
};
/*
......
......@@ -70,8 +70,6 @@ extern struct pp_msgtype_info pp_msgtype_info[16];
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_request(struct pp_instance *ppi);
extern int pp_lib_handle_announce(struct pp_instance *ppi,
unsigned char *buf, int len);
/* We use data sets a lot, so have these helpers */
static inline struct pp_globals *GLBS(struct pp_instance *ppi)
......@@ -158,7 +156,7 @@ struct pp_ext_hooks {
int plen, int msgtype);
int (*new_slave)(struct pp_instance *ppi, unsigned char *pkt, int plen);
int (*handle_resp)(struct pp_instance *ppi);
void (*s1)(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann);
void (*s1)(struct pp_instance *ppi, struct pp_frgn_master *frgn_master);
int (*execute_slave)(struct pp_instance *ppi);
int (*handle_announce)(struct pp_instance *ppi);
int (*handle_followup)(struct pp_instance *ppi, struct pp_time *orig);
......@@ -166,7 +164,7 @@ struct pp_ext_hooks {
int (*handle_presp) (struct pp_instance * ppi);
int (*pack_announce)(struct pp_instance *ppi);
void (*unpack_announce)(void *buf, MsgAnnounce *ann);
int (*bmc_state_decision)(struct pp_instance *ppi, int next_state);
int (*state_decision)(struct pp_instance *ppi, int next_state);
};
extern struct pp_ext_hooks pp_hooks; /* The one for the extension we build */
......@@ -363,10 +361,12 @@ extern void pp_servo_got_presp(struct pp_instance *ppi); /* got all t3..t6 */
extern void bmc_m1(struct pp_instance *ppi);
extern void bmc_m2(struct pp_instance *ppi);
extern void bmc_m3(struct pp_instance *ppi);
extern void bmc_s1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann);
extern void bmc_s1(struct pp_instance *ppi,
struct pp_frgn_master *frgn_master);
extern void bmc_p1(struct pp_instance *ppi);
extern void bmc_p2(struct pp_instance *ppi);
extern void bmc_copy_d0(struct pp_instance *ppi, struct pp_frgn_master *m);
extern void bmc_setup_local_frgn_master(struct pp_instance *ppi,
struct pp_frgn_master *frgn_master);
extern int bmc_idcmp(struct ClockIdentity *a, struct ClockIdentity *b);
extern int bmc_pidcmp(struct PortIdentity *a, struct PortIdentity *b);
extern int bmc(struct pp_instance *ppi);
......@@ -379,6 +379,10 @@ extern int bmc_topology_cmp(struct pp_instance *ppi,
extern int bmc_dataset_cmp(struct pp_instance *ppi,
struct pp_frgn_master *a,
struct pp_frgn_master *b);
extern void bmc_store_frgn_master(struct pp_instance *ppi,
struct pp_frgn_master *frgn_master, unsigned char *buf, int len);
extern void bmc_add_frgn_master(struct pp_instance *ppi, unsigned char *buf,
int len);
/* msg.c */
extern void msg_init_header(struct pp_instance *ppi, void *buf);
extern int __attribute__((warn_unused_result))
......
......@@ -149,16 +149,16 @@ static int wr_handle_resp(struct pp_instance *ppi)
return 0;
}
static void wr_s1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
static void wr_s1(struct pp_instance *ppi, struct pp_frgn_master *frgn_master)
{
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
WR_DSPOR(ppi)->parentIsWRnode =
((ann->ext_specific & WR_NODE_MODE) != NON_WR);
((frgn_master->ext_specific & WR_NODE_MODE) != NON_WR);
WR_DSPOR(ppi)->parentWrModeOn =
(ann->ext_specific & WR_IS_WR_MODE) ? TRUE : FALSE;
(frgn_master->ext_specific & WR_IS_WR_MODE) ? TRUE : FALSE;
WR_DSPOR(ppi)->parentCalibrated =
((ann->ext_specific & WR_IS_CALIBRATED) ? 1 : 0);
WR_DSPOR(ppi)->parentWrConfig = ann->ext_specific & WR_NODE_MODE;
((frgn_master->ext_specific & WR_IS_CALIBRATED) ? 1 : 0);
WR_DSPOR(ppi)->parentWrConfig = frgn_master->ext_specific & WR_NODE_MODE;
DSCUR(ppi)->primarySlavePortNumber =
DSPOR(ppi)->portIdentity.portNumber;
}
......@@ -275,7 +275,7 @@ static void wr_unpack_announce(void *buf, MsgAnnounce *ann)
}
/* State decision algorithm 9.3.3 Fig 26 with extension for wr */
static int wr_bmc_state_decision(struct pp_instance *ppi, int next_state)
static int wr_state_decision(struct pp_instance *ppi, int next_state)
{
struct wr_dsport *wrp = WR_DSPOR(ppi);
struct pp_globals *ppg = GLBS(ppi);
......@@ -332,5 +332,5 @@ struct pp_ext_hooks pp_hooks = {
#endif
.pack_announce = wr_pack_announce,
.unpack_announce = wr_unpack_announce,
.bmc_state_decision = wr_bmc_state_decision,
.state_decision = wr_state_decision,
};
......@@ -11,8 +11,7 @@
/* Please increment WRS_PPSI_SHMEM_VERSION if you change any exported data
* structure */
#define WRS_PPSI_SHMEM_VERSION 21 /* Added source_id and ann_cnt to struct
* pp_frgn_master */
#define WRS_PPSI_SHMEM_VERSION 22 /* Changed struct pp_frgn_master */
/* Don't include the Following when this file is included in assembler. */
#ifndef __ASSEMBLY__
......
This diff is collapsed.
......@@ -220,6 +220,15 @@ int st_com_peer_handle_preq(struct pp_instance *ppi, unsigned char *buf,
return 0;
}
int st_com_handle_announce(struct pp_instance *ppi, unsigned char *buf, int len)
{
bmc_add_frgn_master(ppi, buf, len);
if (pp_hooks.handle_announce)
return pp_hooks.handle_announce(ppi);
return 0;
}
int __send_and_log(struct pp_instance *ppi, int msglen, int chtype)
{
int msgtype = ((char *)ppi->tx_ptp)[0] & 0xf;
......
......@@ -24,6 +24,10 @@ int st_com_peer_handle_pres(struct pp_instance *ppi, unsigned char *buf,
int st_com_peer_handle_pres_followup(struct pp_instance *ppi,
unsigned char *buf, int len);
int st_com_handle_announce(struct pp_instance *ppi, unsigned char *buf,
int len);
int __send_and_log(struct pp_instance *ppi, int msglen, int chtype);
/* Count successfully received PTP packets */
......
......@@ -108,144 +108,4 @@ int pp_lib_may_issue_request(struct pp_instance *ppi)
return 0;
}
/* Called by this file, basically when an announce is got, all states */
static void __lib_add_foreign(struct pp_instance *ppi, unsigned char *buf)
{
int i, worst, sel;
struct pp_frgn_master frgn_master;
MsgHeader *hdr = &ppi->received_ptp_header;
pp_diag(ppi, bmc, 2, "%s\n", __func__);
/* if we are a configured master don't add*/
if (ppi->role == PPSI_ROLE_MASTER)
return;
/* if in DISABLED, INITIALIZING or FAULTY ignore announce */
if ((ppi->state == PPS_DISABLED) ||
(ppi->state == PPS_FAULTY) ||
(ppi->state == PPS_INITIALIZING))
return;
/*
* header and announce field of each Foreign Master are
* useful to run Best Master Clock Algorithm
*/
msg_copy_header(&frgn_master.hdr, hdr);
msg_unpack_announce(buf, &frgn_master.ann);
/* Copy new foreign master data set from announce message */
memcpy(&frgn_master.port_id,
&hdr->sourcePortIdentity, sizeof(hdr->sourcePortIdentity));
/* Copy the source port identity */
memcpy(&frgn_master.source_id,
&DSPOR(ppi)->portIdentity, sizeof(DSPOR(ppi)->portIdentity));
if (DSDEF(ppi)->numberPorts > 1) {
/* Check if announce from the same port from this clock 9.3.2.5 a)
* from another port of this clock we still handle even though it
* states something different in IEEE1588 because in 9.5.2.3
* there is a special handling described for boundary clocks
* which is done in the BMC
*/
if (!memcmp(&hdr->sourcePortIdentity,
&DSPOR(ppi)->portIdentity,
sizeof(PortIdentity))) {
pp_diag(ppi, bmc, 2, "Announce frame from this port\n");
return;
}
} else {
/* Check if announce from a port from this clock 9.3.2.5 a) */
if (!memcmp(&hdr->sourcePortIdentity.clockIdentity,
&DSDEF(ppi)->clockIdentity,
sizeof(ClockIdentity))) {
pp_diag(ppi, bmc, 2, "Announce frame from this clock\n");
return;
}
}
/* Check if announce has steps removed larger than 255 9.3.2.5 d) */
if (frgn_master.ann.stepsRemoved >= 255) {
pp_diag(ppi, bmc, 2, "Announce frame steps removed"
"larger or equal 255: %i\n",
frgn_master.ann.stepsRemoved);
return;
}
/* Check if foreign master is already known */
for (i = 0; i < ppi->frgn_rec_num; i++) {
if (!memcmp(&hdr->sourcePortIdentity,
&ppi->frgn_master[i].port_id,
sizeof(PortIdentity))) {
pp_diag(ppi, bmc, 2, "Foreign Master %i updated\n", i);
/* update the number of announce received if correct
* sequence number 9.3.2.5 b) */
if (hdr->sequenceId
== (ppi->frgn_master[i].hdr.sequenceId + 1))
ppi->frgn_master[i].ann_cnt[0]++;
/* already in Foreign master data set, update info */
msg_copy_header(&ppi->frgn_master[i].hdr, hdr);
msg_unpack_announce(buf, &ppi->frgn_master[i].ann);
return;
}
}
/* set qualification timeouts as valid to compare against worst*/
for (i = 0; i < PP_FOREIGN_MASTER_TIME_WINDOW; i++)
frgn_master.ann_cnt[i] = 1;
/* New foreign master */
if (ppi->frgn_rec_num < PP_NR_FOREIGN_RECORDS) {
/* there is space for a new one */
sel = ppi->frgn_rec_num;
ppi->frgn_rec_num++;
} else {
/* find the worst to replace */
for (i = 1, worst = 0; i < ppi->frgn_rec_num; i++)
if (bmc_dataset_cmp(ppi, &ppi->frgn_master[i],
&ppi->frgn_master[worst]) > 0)
worst = i;
/* check if worst is better than the new one, and skip the new
* one if so */
if (bmc_dataset_cmp(ppi, &ppi->frgn_master[worst], &frgn_master)
< 0) {
pp_diag(ppi, bmc, 1, "%s:%i: New foreign "
"master worse than worst in the full "
"table, skipping\n",
__func__, __LINE__);
return;
}
sel = worst;
}
/* clear qualification timeouts */
for (i = 0; i < PP_FOREIGN_MASTER_TIME_WINDOW; i++)
frgn_master.ann_cnt[i] = 0;
/* This is the first one qualified 9.3.2.5 e)*/
frgn_master.ann_cnt[0] = 1;
/* Copy the temporary foreign master entry */
memcpy(&ppi->frgn_master[sel],
&frgn_master, sizeof(frgn_master));
pp_diag(ppi, bmc, 1, "New foreign Master %i added\n", sel);
}
int pp_lib_handle_announce(struct pp_instance *ppi, unsigned char *buf, int len)
{
__lib_add_foreign(ppi, buf);
//TODO pp_timeout_set(ppi, PP_TO_ANN_RECEIPT);
if (pp_hooks.handle_announce)
return pp_hooks.handle_announce(ppi);
return 0;
}
......@@ -219,8 +219,11 @@ void msg_unpack_announce(void *buf, MsgAnnounce *ann)
ann->stepsRemoved = (ann->stepsRemoved << 8) + *(UInteger8 *)(buf + 62);
ann->timeSource = *(Enumeration8 *) (buf + 63);
/* this can fill in extention specific flags otherwise just zero them*/
if (pp_hooks.unpack_announce)
pp_hooks.unpack_announce(buf, ann);
else
ann->ext_specific = 0;
}
/* Pack Follow Up message into out buffer of ppi*/
......
......@@ -19,7 +19,7 @@ static pp_action *actions[] = {
#endif
[PPM_FOLLOW_UP] = 0,
[PPM_DELAY_RESP] = 0,
[PPM_ANNOUNCE] = pp_lib_handle_announce,
[PPM_ANNOUNCE] = st_com_handle_announce,
/* skip signaling and management, for binary size */
};
......
......@@ -22,7 +22,7 @@ static pp_action *actions[] = {
#endif
[PPM_FOLLOW_UP] = 0,
[PPM_DELAY_RESP] = 0,
[PPM_ANNOUNCE] = pp_lib_handle_announce,
[PPM_ANNOUNCE] = st_com_handle_announce,
/* skip signaling and management, for binary size */
};
......
......@@ -31,12 +31,12 @@ static int passive_handle_announce(struct pp_instance *ppi, unsigned char *buf,
MsgHeader *hdr = &ppi->received_ptp_header;
struct pp_frgn_master *erbest = &ppi->frgn_master[ppi->frgn_rec_best];
ret = pp_lib_handle_announce(ppi, buf, len);
ret = st_com_handle_announce(ppi, buf, len);
if (ret)
return ret;
if (!memcmp(&hdr->sourcePortIdentity,
&erbest->port_id,
&erbest->sourcePortIdentity,
sizeof(PortIdentity))) {
/*
* 9.2.6.11 d) reset timeout when an announce
......
......@@ -19,7 +19,7 @@ static int slave_handle_response(struct pp_instance *ppi, unsigned char *buf,
static int slave_handle_announce(struct pp_instance *ppi, unsigned char *buf, int len);
static pp_action *actions[] = {
[PPM_SYNC] = slave_handle_sync,
[PPM_SYNC] = slave_handle_sync,
[PPM_DELAY_REQ] = 0,
#if CONFIG_HAS_P2P
[PPM_PDELAY_REQ] = st_com_peer_handle_preq,
......@@ -162,10 +162,9 @@ static int slave_handle_response(struct pp_instance *ppi, unsigned char *buf,
static int slave_handle_announce(struct pp_instance *ppi, unsigned char *buf, int len)
{
int ret = 0;
MsgHeader *hdr = &ppi->received_ptp_header;
MsgAnnounce ann;
ret = pp_lib_handle_announce(ppi, buf, len);
struct pp_frgn_master frgn_master;
ret = st_com_handle_announce(ppi, buf, len);
if (ret)
return ret;
......@@ -173,8 +172,8 @@ static int slave_handle_announce(struct pp_instance *ppi, unsigned char *buf, in
/* 9.2.6.11 a) reset timeout */
pp_timeout_set(ppi, PP_TO_ANN_RECEIPT);
/* 9.5.3 Figure 29 update data set if announce from current master */
msg_unpack_announce(buf, &ann);
bmc_s1(ppi, hdr, &ann);
bmc_store_frgn_master(ppi, &frgn_master, buf, len);
bmc_s1(ppi, &frgn_master);
}
return 0;
......
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