Commit f9f487ff authored by Alessandro Rubini's avatar Alessandro Rubini

general (for bmc.c): turn ClockIdentity into a structure

This "type" was the only type represented as an array instead of
being a structure. This leads to inconsistent use: if you memcpy
the other ones you need "&", but not here.

So this commit uses an encompassing structure, to have ClockIdentity
behave like other composite fields.  The commit has no effect at all
on the generated binary files for wrpc but it unexpectedly reduces the
size of the output on the PC. Anyways, the commit is trivial, and all
changes can be easily verified to have no effect.

While this increases entropy, the reasoning is that I want to assign
structures instead of running zillions of memcpy functions, with the
hairy PP_CLOCK_IDENTITY_LENGTH.  So later commits, based on this one,
reduce entropy.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 6b7ec8be
......@@ -82,7 +82,9 @@ static inline void clear_TimeInternal(struct TimeInternal *t)
memset(t, 0, sizeof(*t));
}
typedef Octet ClockIdentity[8]; /* page 13 (33) */
typedef struct ClockIdentity { /* page 13 (33) */
Octet id[8];
} ClockIdentity;
#define PP_CLOCK_IDENTITY_LENGTH sizeof(ClockIdentity)
typedef struct PortIdentity { /* page 13 (33) */
......
......@@ -126,7 +126,7 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
*(UInteger8 *)(buf+32) = 0x05; //Table 23 -> all other
/* target portIdentity */
memcpy((buf+34), DSPAR(ppi)->parentPortIdentity.clockIdentity,
memcpy((buf+34), &DSPAR(ppi)->parentPortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
put_be16(buf + 42, DSPAR(ppi)->parentPortIdentity.portNumber);
......@@ -190,7 +190,7 @@ void msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
UInteger16 tlv_versionNumber;
Enumeration16 wr_msg_id;
memcpy(wrsig_msg->targetPortIdentity.clockIdentity, (buf + 34),
memcpy(&wrsig_msg->targetPortIdentity.clockIdentity, (buf + 34),
PP_CLOCK_IDENTITY_LENGTH);
wrsig_msg->targetPortIdentity.portNumber = (UInteger16)get_be16(buf+42);
......
......@@ -22,12 +22,12 @@ void m1(struct pp_instance *ppi)
clear_TimeInternal(&DSCUR(ppi)->meanPathDelay);
/* Parent data set */
memcpy(DSPAR(ppi)->parentPortIdentity.clockIdentity,
DSDEF(ppi)->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
memcpy(&DSPAR(ppi)->parentPortIdentity.clockIdentity,
&DSDEF(ppi)->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
DSPAR(ppi)->parentPortIdentity.portNumber = 0;
DSPAR(ppi)->observedParentClockPhaseChangeRate = 0;
DSPAR(ppi)->observedParentOffsetScaledLogVariance = 0;
memcpy(DSPAR(ppi)->grandmasterIdentity, DSDEF(ppi)->clockIdentity,
memcpy(&DSPAR(ppi)->grandmasterIdentity, &DSDEF(ppi)->clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
DSPAR(ppi)->grandmasterClockQuality.clockAccuracy =
DSDEF(ppi)->clockQuality.clockAccuracy;
......@@ -50,14 +50,14 @@ void s1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
DSCUR(ppi)->stepsRemoved = ann->stepsRemoved + 1;
/* Parent DS */
memcpy(DSPAR(ppi)->parentPortIdentity.clockIdentity,
hdr->sourcePortIdentity.clockIdentity,
memcpy(&DSPAR(ppi)->parentPortIdentity.clockIdentity,
&hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
DSPAR(ppi)->parentPortIdentity.portNumber =
hdr->sourcePortIdentity.portNumber;
memcpy(DSPAR(ppi)->grandmasterIdentity,
ann->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH);
memcpy(&DSPAR(ppi)->grandmasterIdentity,
&ann->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH);
DSPAR(ppi)->grandmasterClockQuality.clockAccuracy =
ann->grandmasterClockQuality.clockAccuracy;
......@@ -90,7 +90,7 @@ void s1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
void copy_d0( struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
{
ann->grandmasterPriority1 = DSDEF(ppi)->priority1;
memcpy(ann->grandmasterIdentity, DSDEF(ppi)->clockIdentity,
memcpy(&ann->grandmasterIdentity, &DSDEF(ppi)->clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
ann->grandmasterClockQuality.clockClass =
DSDEF(ppi)->clockQuality.clockClass;
......@@ -100,8 +100,8 @@ void copy_d0( struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
DSDEF(ppi)->clockQuality.offsetScaledLogVariance;
ann->grandmasterPriority2 = DSDEF(ppi)->priority2;
ann->stepsRemoved = 0;
memcpy(hdr->sourcePortIdentity.clockIdentity,
DSDEF(ppi)->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
memcpy(&hdr->sourcePortIdentity.clockIdentity,
&DSDEF(ppi)->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
}
......@@ -119,8 +119,8 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi,
PP_VPRINTF("BMC: in bmc_dataset_cmp\n");
/* Identity comparison */
if (!memcmp(ann_a->grandmasterIdentity,
ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH)) {
if (!memcmp(&ann_a->grandmasterIdentity,
&ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH)) {
/* Algorithm part2 Fig 28 */
if (ann_a->stepsRemoved > ann_b->stepsRemoved + 1)
......@@ -131,11 +131,11 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi,
else { /* A within 1 of B */
ppci = DSPAR(ppi)->parentPortIdentity.clockIdentity;
ppci = DSPAR(ppi)->parentPortIdentity.clockIdentity.id;
if (ann_a->stepsRemoved > ann_b->stepsRemoved) {
if (!memcmp(
hdr_a->sourcePortIdentity.clockIdentity,
&hdr_a->sourcePortIdentity.clockIdentity,
ppci,
PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -1");
......@@ -145,7 +145,7 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi,
} else if (ann_b->stepsRemoved > ann_a->stepsRemoved) {
if (!memcmp(
hdr_b->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity,
ppci,
PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -3");
......@@ -155,14 +155,14 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi,
}
} else { /* steps removed A == steps removed B */
if (!memcmp(
hdr_a->sourcePortIdentity.clockIdentity,
hdr_b->sourcePortIdentity.clockIdentity,
&hdr_a->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -2");
return 0;
} else if ((memcmp(
hdr_a->sourcePortIdentity.clockIdentity,
hdr_b->sourcePortIdentity.clockIdentity,
&hdr_a->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) < 0)
return -1;
else
......@@ -177,7 +177,7 @@ Integer8 bmc_dataset_cmp(struct pp_instance *ppi,
if (ann_a->grandmasterClockQuality.clockAccuracy == ann_b->grandmasterClockQuality.clockAccuracy) {
if (ann_a->grandmasterClockQuality.offsetScaledLogVariance == ann_b->grandmasterClockQuality.offsetScaledLogVariance) {
if (ann_a->grandmasterPriority2 == ann_b->grandmasterPriority2) {
comp = memcmp(ann_a->grandmasterIdentity, ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH);
comp = memcmp(&ann_a->grandmasterIdentity, &ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH);
if (comp < 0)
return -1;
else if (comp > 0)
......
......@@ -84,8 +84,8 @@ static void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
/* Check if foreign master is already known */
for (i = 0; i < ppi->number_foreign_records; i++) {
if (!memcmp(hdr->sourcePortIdentity.clockIdentity,
ppi->frgn_master[j].port_identity.
if (!memcmp(&hdr->sourcePortIdentity.clockIdentity,
&ppi->frgn_master[j].port_identity.
clockIdentity,
PP_CLOCK_IDENTITY_LENGTH) &&
(hdr->sourcePortIdentity.portNumber ==
......@@ -116,8 +116,8 @@ static void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
j = ppi->foreign_record_i;
/* Copy new foreign master data set from announce message */
memcpy(ppi->frgn_master[j].port_identity.clockIdentity,
hdr->sourcePortIdentity.clockIdentity,
memcpy(&ppi->frgn_master[j].port_identity.clockIdentity,
&hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
ppi->frgn_master[j].port_identity.portNumber =
hdr->sourcePortIdentity.portNumber;
......
......@@ -106,7 +106,7 @@ int msg_unpack_header(struct pp_instance *ppi, void *buf)
memcpy(&hdr->correctionfield.lsb, (buf + 12), 4);
hdr->correctionfield.msb = htonl(hdr->correctionfield.msb);
hdr->correctionfield.lsb = htonl(hdr->correctionfield.lsb);
memcpy(hdr->sourcePortIdentity.clockIdentity, (buf + 20),
memcpy(&hdr->sourcePortIdentity.clockIdentity, (buf + 20),
PP_CLOCK_IDENTITY_LENGTH);
hdr->sourcePortIdentity.portNumber =
htons(*(UInteger16 *) (buf + 28));
......@@ -121,13 +121,13 @@ int msg_unpack_header(struct pp_instance *ppi, void *buf)
* any port, not only the same port, as we can't sync with
* ourself even when we'll run in multi-port mode.
*/
if (!memcmp(ppi->received_ptp_header.sourcePortIdentity.clockIdentity,
DSPOR(ppi)->portIdentity.clockIdentity,
if (!memcmp(&ppi->received_ptp_header.sourcePortIdentity.clockIdentity,
&DSPOR(ppi)->portIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH))
return -1;
if (!memcmp(DSPAR(ppi)->parentPortIdentity.clockIdentity,
hdr->sourcePortIdentity.clockIdentity,
if (!memcmp(&DSPAR(ppi)->parentPortIdentity.clockIdentity,
&hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH) &&
(DSPAR(ppi)->parentPortIdentity.portNumber ==
hdr->sourcePortIdentity.portNumber))
......@@ -152,7 +152,7 @@ void msg_pack_header(struct pp_instance *ppi, void *buf)
*(UInteger8 *) (buf + 6) = PP_TWO_STEP_FLAG;
memset((buf + 8), 0, 8);
memcpy((buf + 20), DSPOR(ppi)->portIdentity.clockIdentity,
memcpy((buf + 20), &DSPOR(ppi)->portIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 28) =
htons(DSPOR(ppi)->portIdentity.portNumber);
......@@ -236,7 +236,7 @@ int msg_pack_announce(struct pp_instance *ppi)
*(UInteger16 *) (buf + 50) =
htons(DSDEF(ppi)->clockQuality.offsetScaledLogVariance);
*(UInteger8 *) (buf + 52) = DSPAR(ppi)->grandmasterPriority2;
memcpy((buf + 53), DSPAR(ppi)->grandmasterIdentity,
memcpy((buf + 53), &DSPAR(ppi)->grandmasterIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 61) = htons(DSCUR(ppi)->stepsRemoved);
*(Enumeration8 *) (buf + 63) = DSPRO(ppi)->timeSource;
......@@ -264,7 +264,7 @@ void msg_unpack_announce(void *buf, MsgAnnounce *ann)
ann->grandmasterClockQuality.offsetScaledLogVariance =
htons(*(UInteger16 *) (buf + 50));
ann->grandmasterPriority2 = *(UInteger8 *) (buf + 52);
memcpy(ann->grandmasterIdentity, (buf + 53),
memcpy(&ann->grandmasterIdentity, (buf + 53),
PP_CLOCK_IDENTITY_LENGTH);
ann->stepsRemoved = htons(*(UInteger16 *) (buf + 61));
ann->timeSource = *(Enumeration8 *) (buf + 63);
......@@ -388,7 +388,7 @@ void msg_pack_delay_resp(struct pp_instance *ppi,
htons(rcv_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = htonl(rcv_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = htonl(rcv_tstamp->nanosecondsField);
memcpy((buf + 44), hdr->sourcePortIdentity.clockIdentity,
memcpy((buf + 44), &hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) =
htons(hdr->sourcePortIdentity.portNumber);
......@@ -421,7 +421,7 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
htonl(*(UInteger32 *) (buf + 36));
resp->receiveTimestamp.nanosecondsField =
htonl(*(UInteger32 *) (buf + 40));
memcpy(resp->requestingPortIdentity.clockIdentity,
memcpy(&resp->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
resp->requestingPortIdentity.portNumber =
htons(*(UInteger16 *) (buf + 52));
......
......@@ -27,7 +27,7 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
*/
def->twoStepFlag = TRUE;
/* Clock identity comes from mac address with 0xff:0xfe intermixed */
id = def->clockIdentity;
id = (unsigned char *)&def->clockIdentity;
mac = NP(ppi)->ch[PP_NP_GEN].addr;
id[0] = mac[0];
id[1] = mac[1];
......@@ -50,8 +50,8 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
/*
* Initialize port data set
*/
memcpy(port->portIdentity.clockIdentity,
def->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
memcpy(&port->portIdentity.clockIdentity,
&def->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
port->portIdentity.portNumber = 1;
port->logMinDelayReqInterval = PP_DEFAULT_DELAYREQ_INTERVAL;
port->logAnnounceInterval = opt->announce_intvl;
......
......@@ -64,8 +64,8 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
msg_unpack_delay_resp(pkt, &ppi->msg_tmp.resp);
if ((memcmp(DSPOR(ppi)->portIdentity.clockIdentity,
ppi->msg_tmp.resp.requestingPortIdentity.clockIdentity,
if ((memcmp(&DSPOR(ppi)->portIdentity.clockIdentity,
&ppi->msg_tmp.resp.requestingPortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH) == 0) &&
((ppi->sent_seq[PPM_DELAY_REQ]) ==
hdr->sequenceId) &&
......
......@@ -42,7 +42,7 @@ void pp_timeout_rand(struct pp_instance *ppi, int index, int logval)
if (!seed) {
uint32_t *p;
/* use the least 32 bits of the mac address as seed */
p = (void *)(DSDEF(ppi)->clockIdentity)
p = (void *)(&DSDEF(ppi)->clockIdentity)
+ sizeof(ClockIdentity) - 4;
seed = *p;
}
......
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