Commit 2200f98d authored by Adam Wujek's avatar Adam Wujek

use format_mac, format_hex and format_hex8 in printouts

To avoid storage of long formating strings

This saves ~600B on wrpc
Signed-off-by: 's avatarAdam Wujek <adam.wujek@creotech.pl>
parent de2b6db5
...@@ -133,3 +133,27 @@ void *create_map(unsigned long address, unsigned long size) ...@@ -133,3 +133,27 @@ void *create_map(unsigned long address, unsigned long size)
return NULL; return NULL;
return mapaddr + fragment; return mapaddr + fragment;
} }
char *format_hex(char *s, const unsigned char *mac, int cnt)
{
int i;
*s = '\0';
for (i = 0; i < cnt; i++) {
pp_sprintf(s, "%s%02x:", s, mac[i]);
}
/* remove last colon */
s[cnt * 3 - 1] = '\0'; /* cnt * strlen("FF:") - 1 */
return s;
}
char *format_hex8(char *s, const unsigned char *mac)
{
return format_hex(s, mac, 8);
}
char *format_mac(char *s, const unsigned char *mac)
{
format_hex(s, mac, 6);
return s;
}
...@@ -15,4 +15,7 @@ extern int atoi(const char *s); ...@@ -15,4 +15,7 @@ extern int atoi(const char *s);
extern uint32_t __div64_32(uint64_t *n, uint32_t base); extern uint32_t __div64_32(uint64_t *n, uint32_t base);
extern char *format_hex8(char *s, const unsigned char *mac);
extern char *format_mac(char *s, const unsigned char *mac);
#endif /* __PPSI_LIB_H__ */ #endif /* __PPSI_LIB_H__ */
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
#define FFB_TTRA 0x10 #define FFB_TTRA 0x10
#define FFB_FTRA 0x20 #define FFB_FTRA 0x20
/* String to save space in diag messages */
#define fmt_clock_identity_id_A_B "%sId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x.%04x,\n" \
"%sId B: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x.%04x\n"
#define fmt_clock_identity_id "%s: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x.%04x\n"
/* ppi->port_idx port is becoming Master. Table 13 (9.3.5) of the spec. */ /* ppi->port_idx port is becoming Master. Table 13 (9.3.5) of the spec. */
void bmc_m1(struct pp_instance *ppi) void bmc_m1(struct pp_instance *ppi)
{ {
...@@ -405,6 +400,7 @@ static int bmc_gm_cmp(struct pp_instance *ppi, ...@@ -405,6 +400,7 @@ static int bmc_gm_cmp(struct pp_instance *ppi,
int ret; int ret;
struct ClockQuality *qa = &a->grandmasterClockQuality; struct ClockQuality *qa = &a->grandmasterClockQuality;
struct ClockQuality *qb = &b->grandmasterClockQuality; struct ClockQuality *qb = &b->grandmasterClockQuality;
char clkid_str[26];
/* bmc_gm_cmp is called several times, so report only at level 2 */ /* bmc_gm_cmp is called several times, so report only at level 2 */
pp_diag(ppi, bmc, 2, "%s\n", __func__); pp_diag(ppi, bmc, 2, "%s\n", __func__);
...@@ -444,17 +440,12 @@ static int bmc_gm_cmp(struct pp_instance *ppi, ...@@ -444,17 +440,12 @@ static int bmc_gm_cmp(struct pp_instance *ppi,
return a->grandmasterPriority2 - b->grandmasterPriority2; return a->grandmasterPriority2 - b->grandmasterPriority2;
} }
pp_diag(ppi, bmc, 3, "GmId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", pp_diag(ppi, bmc, 3, "GmId A: %s\n",
a->grandmasterIdentity.id[0], a->grandmasterIdentity.id[1], format_hex8(clkid_str, a->grandmasterIdentity.id));
a->grandmasterIdentity.id[2], a->grandmasterIdentity.id[3],
a->grandmasterIdentity.id[4], a->grandmasterIdentity.id[5], pp_diag(ppi, bmc, 3, "GmId B: %s\n",
a->grandmasterIdentity.id[6], a->grandmasterIdentity.id[7]); format_hex8(clkid_str, b->grandmasterIdentity.id));
pp_diag(ppi, bmc, 3, "GmId B: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
b->grandmasterIdentity.id[0], b->grandmasterIdentity.id[1],
b->grandmasterIdentity.id[2], b->grandmasterIdentity.id[3],
b->grandmasterIdentity.id[4], b->grandmasterIdentity.id[5],
b->grandmasterIdentity.id[6], b->grandmasterIdentity.id[7]);
return bmc_idcmp(&a->grandmasterIdentity, &b->grandmasterIdentity); return bmc_idcmp(&a->grandmasterIdentity, &b->grandmasterIdentity);
} }
...@@ -469,6 +460,8 @@ static int bmc_topology_cmp(struct pp_instance *ppi, ...@@ -469,6 +460,8 @@ static int bmc_topology_cmp(struct pp_instance *ppi,
struct PortIdentity *pidrxa = &a->receivePortIdentity; struct PortIdentity *pidrxa = &a->receivePortIdentity;
struct PortIdentity *pidrxb = &b->receivePortIdentity; struct PortIdentity *pidrxb = &b->receivePortIdentity;
int diff; int diff;
char clkida_str[26];
char clkidb_str[26];
/* bmc_topology_cmp is called several times, so report only at level 2 /* bmc_topology_cmp is called several times, so report only at level 2
*/ */
...@@ -509,37 +502,25 @@ static int bmc_topology_cmp(struct pp_instance *ppi, ...@@ -509,37 +502,25 @@ static int bmc_topology_cmp(struct pp_instance *ppi,
/* stepsRemoved is equal, compare identities */ /* stepsRemoved is equal, compare identities */
diff = bmc_pidcmp(pidtxa, pidtxb); diff = bmc_pidcmp(pidtxa, pidtxb);
if (diff) { if (diff) {
pp_diag(ppi, bmc, 3, fmt_clock_identity_id_A_B, pp_diag(ppi, bmc, 3, "%sId A: %s.%04x,\n%sId B: %s.%04x\n",
"Tx", "Tx",
pidtxa->clockIdentity.id[0], pidtxa->clockIdentity.id[1], format_hex8(clkida_str, pidtxa->clockIdentity.id),
pidtxa->clockIdentity.id[2], pidtxa->clockIdentity.id[3],
pidtxa->clockIdentity.id[4], pidtxa->clockIdentity.id[5],
pidtxa->clockIdentity.id[6], pidtxa->clockIdentity.id[7],
pidtxa->portNumber, pidtxa->portNumber,
"Tx", "Tx",
pidtxb->clockIdentity.id[0], pidtxb->clockIdentity.id[1], format_hex8(clkidb_str, pidtxb->clockIdentity.id),
pidtxb->clockIdentity.id[2], pidtxb->clockIdentity.id[3],
pidtxb->clockIdentity.id[4], pidtxb->clockIdentity.id[5],
pidtxb->clockIdentity.id[6], pidtxb->clockIdentity.id[7],
pidtxb->portNumber); pidtxb->portNumber);
return diff; return diff;
} }
/* sourcePortIdentity is equal, compare receive port identites, which /* sourcePortIdentity is equal, compare receive port identites, which
* is the last decision maker, which has to be different */ * is the last decision maker, which has to be different */
pp_diag(ppi, bmc, 3, fmt_clock_identity_id_A_B, pp_diag(ppi, bmc, 3, "%sId A: %s.%04x,\n%sId B: %s.%04x\n",
"Rx", "Rx",
pidrxa->clockIdentity.id[0], pidrxa->clockIdentity.id[1], format_hex8(clkida_str, pidtxa->clockIdentity.id),
pidrxa->clockIdentity.id[2], pidrxa->clockIdentity.id[3], pidtxa->portNumber,
pidrxa->clockIdentity.id[4], pidrxa->clockIdentity.id[5],
pidrxa->clockIdentity.id[6], pidrxa->clockIdentity.id[7],
pidrxa->portNumber,
"Rx", "Rx",
pidrxb->clockIdentity.id[0], pidrxb->clockIdentity.id[1], format_hex8(clkidb_str, pidtxb->clockIdentity.id),
pidrxb->clockIdentity.id[2], pidrxb->clockIdentity.id[3], pidtxb->portNumber);
pidrxb->clockIdentity.id[4], pidrxb->clockIdentity.id[5],
pidrxb->clockIdentity.id[6], pidrxb->clockIdentity.id[7],
pidrxb->portNumber);
return bmc_pidcmp(pidrxa, pidrxb); return bmc_pidcmp(pidrxa, pidrxb);
} }
...@@ -553,19 +534,14 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -553,19 +534,14 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
struct pp_frgn_master *a, struct pp_frgn_master *a,
struct pp_frgn_master *b) struct pp_frgn_master *b)
{ {
char clkid_str[26];
/* dataset_cmp is called several times, so report only at level 2 */ /* dataset_cmp is called several times, so report only at level 2 */
pp_diag(ppi, bmc, 2, "%s\n", __func__); pp_diag(ppi, bmc, 2, "%s\n", __func__);
pp_diag(ppi, bmc, 3, "portId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", pp_diag(ppi, bmc, 3, "portId A: %s\n",
a->sourcePortIdentity.clockIdentity.id[0], a->sourcePortIdentity.clockIdentity.id[1], format_hex8(clkid_str, a->sourcePortIdentity.clockIdentity.id));
a->sourcePortIdentity.clockIdentity.id[2], a->sourcePortIdentity.clockIdentity.id[3],
a->sourcePortIdentity.clockIdentity.id[4], a->sourcePortIdentity.clockIdentity.id[5], pp_diag(ppi, bmc, 3, "portId B: %s\n",
a->sourcePortIdentity.clockIdentity.id[6], a->sourcePortIdentity.clockIdentity.id[7]); format_hex8(clkid_str, b->sourcePortIdentity.clockIdentity.id));
pp_diag(ppi, bmc, 3, "portId B: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
b->sourcePortIdentity.clockIdentity.id[0], b->sourcePortIdentity.clockIdentity.id[1],
b->sourcePortIdentity.clockIdentity.id[2], b->sourcePortIdentity.clockIdentity.id[3],
b->sourcePortIdentity.clockIdentity.id[4], b->sourcePortIdentity.clockIdentity.id[5],
b->sourcePortIdentity.clockIdentity.id[6], b->sourcePortIdentity.clockIdentity.id[7]);
if (!bmc_idcmp(&a->grandmasterIdentity, &b->grandmasterIdentity)) { if (!bmc_idcmp(&a->grandmasterIdentity, &b->grandmasterIdentity)) {
/* Check topology */ /* Check topology */
...@@ -870,6 +846,7 @@ struct pp_frgn_master * bmc_add_frgn_master(struct pp_instance *ppi, struct pp_ ...@@ -870,6 +846,7 @@ struct pp_frgn_master * bmc_add_frgn_master(struct pp_instance *ppi, struct pp_
int sel; int sel;
MsgHeader *hdr = &ppi->received_ptp_header; MsgHeader *hdr = &ppi->received_ptp_header;
struct PortIdentity *pid = &hdr->sourcePortIdentity; struct PortIdentity *pid = &hdr->sourcePortIdentity;
char clkid_str[26];
pp_diag(ppi, bmc, 2, "%s\n", __func__); pp_diag(ppi, bmc, 2, "%s\n", __func__);
...@@ -877,12 +854,9 @@ struct pp_frgn_master * bmc_add_frgn_master(struct pp_instance *ppi, struct pp_ ...@@ -877,12 +854,9 @@ struct pp_frgn_master * bmc_add_frgn_master(struct pp_instance *ppi, struct pp_
assert(ppi->state != PPS_FAULTY, "Should not be called when state is FAULTY\n"); assert(ppi->state != PPS_FAULTY, "Should not be called when state is FAULTY\n");
assert(ppi->state != PPS_INITIALIZING, "Should not be called when state is INITIALIZING\n"); assert(ppi->state != PPS_INITIALIZING, "Should not be called when state is INITIALIZING\n");
pp_diag(ppi, bmc, 3, fmt_clock_identity_id, pp_diag(ppi, bmc, 3, "%s: %s.%04x\n",
"Foreign Master Port Id", "Foreign Master Port Id",
pid->clockIdentity.id[0], pid->clockIdentity.id[1], format_hex8(clkid_str, pid->clockIdentity.id),
pid->clockIdentity.id[2], pid->clockIdentity.id[3],
pid->clockIdentity.id[4], pid->clockIdentity.id[5],
pid->clockIdentity.id[6], pid->clockIdentity.id[7],
pid->portNumber); pid->portNumber);
if (is_externalPortConfigurationEnabled(DSDEF(ppi)) ) { if (is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
...@@ -1133,6 +1107,7 @@ static int bmc_check_frgn_master(struct pp_instance *ppi) ...@@ -1133,6 +1107,7 @@ static int bmc_check_frgn_master(struct pp_instance *ppi)
{ {
int i; int i;
struct PortIdentity *pid; struct PortIdentity *pid;
char clkid_str[26];
if (ppi->frgn_rec_num > 0) { if (ppi->frgn_rec_num > 0) {
for (i =0; i < ppi->frgn_rec_num; i++) { for (i =0; i < ppi->frgn_rec_num; i++) {
...@@ -1143,12 +1118,9 @@ static int bmc_check_frgn_master(struct pp_instance *ppi) ...@@ -1143,12 +1118,9 @@ static int bmc_check_frgn_master(struct pp_instance *ppi)
if(0 > bmc_pidcmp(&ppi->frgn_master[i].sourcePortIdentity, if(0 > bmc_pidcmp(&ppi->frgn_master[i].sourcePortIdentity,
&DSPOR(ppi)->portIdentity)) { &DSPOR(ppi)->portIdentity)) {
pid = &ppi->frgn_master[i].sourcePortIdentity; pid = &ppi->frgn_master[i].sourcePortIdentity;
pp_diag(ppi, bmc, 3, fmt_clock_identity_id, pp_diag(ppi, bmc, 3, "%s: %s.%04x\n",
"Better Master on same Clock Port Id", "Better Master on same Clock Port Id",
pid->clockIdentity.id[0], pid->clockIdentity.id[1], format_hex8(clkid_str, pid->clockIdentity.id),
pid->clockIdentity.id[2], pid->clockIdentity.id[3],
pid->clockIdentity.id[4], pid->clockIdentity.id[5],
pid->clockIdentity.id[6], pid->clockIdentity.id[7],
pid->portNumber); pid->portNumber);
return 1; return 1;
} }
...@@ -1192,6 +1164,7 @@ static void bmc_update_erbest_inst(struct pp_instance *ppi) { ...@@ -1192,6 +1164,7 @@ static void bmc_update_erbest_inst(struct pp_instance *ppi) {
struct pp_frgn_master *frgn_master; struct pp_frgn_master *frgn_master;
PortIdentity *frgn_master_pid; PortIdentity *frgn_master_pid;
int j, best; int j, best;
char clkid_str[26];
/* if link is down clear foreign master table */ /* if link is down clear foreign master table */
if ((!ppi->link_up) && (ppi->frgn_rec_num > 0)) if ((!ppi->link_up) && (ppi->frgn_rec_num > 0))
...@@ -1220,12 +1193,9 @@ static void bmc_update_erbest_inst(struct pp_instance *ppi) { ...@@ -1220,12 +1193,9 @@ static void bmc_update_erbest_inst(struct pp_instance *ppi) {
ppi->frgn_rec_num); ppi->frgn_rec_num);
frgn_master_pid = &frgn_master[best].sourcePortIdentity; frgn_master_pid = &frgn_master[best].sourcePortIdentity;
pp_diag(ppi, bmc, 3, fmt_clock_identity_id, pp_diag(ppi, bmc, 3, "%s: %s.%04x\n",
"SourcePortId", "SourcePortId",
frgn_master_pid->clockIdentity.id[0], frgn_master_pid->clockIdentity.id[1], format_hex8(clkid_str, frgn_master_pid->clockIdentity.id),
frgn_master_pid->clockIdentity.id[2], frgn_master_pid->clockIdentity.id[3],
frgn_master_pid->clockIdentity.id[4], frgn_master_pid->clockIdentity.id[5],
frgn_master_pid->clockIdentity.id[6], frgn_master_pid->clockIdentity.id[7],
frgn_master_pid->portNumber); frgn_master_pid->portNumber);
} else } else
best=-1; best=-1;
...@@ -1257,6 +1227,7 @@ static void bmc_update_ebest(struct pp_globals *ppg) ...@@ -1257,6 +1227,7 @@ static void bmc_update_ebest(struct pp_globals *ppg)
int i, best=-1; int i, best=-1;
struct pp_instance *ppi_best; struct pp_instance *ppi_best;
PortIdentity *frgn_master_pid; PortIdentity *frgn_master_pid;
char clkid_str[26];
/* bmc_update_ebest is called several times, so report only at /* bmc_update_ebest is called several times, so report only at
* level 2 */ * level 2 */
...@@ -1288,12 +1259,9 @@ static void bmc_update_ebest(struct pp_globals *ppg) ...@@ -1288,12 +1259,9 @@ static void bmc_update_ebest(struct pp_globals *ppg)
pp_diag(ppi_best, bmc, 1, "Best foreign master is at port " pp_diag(ppi_best, bmc, 1, "Best foreign master is at port "
"%i\n", (best+1)); "%i\n", (best+1));
frgn_master_pid = &ppi_best->frgn_master[ppi_best->frgn_rec_best].sourcePortIdentity; frgn_master_pid = &ppi_best->frgn_master[ppi_best->frgn_rec_best].sourcePortIdentity;
pp_diag(ppi_best, bmc, 3, fmt_clock_identity_id, pp_diag(ppi_best, bmc, 3, "%s: %s.%04x\n",
"SourcePortId", "SourcePortId",
frgn_master_pid->clockIdentity.id[0], frgn_master_pid->clockIdentity.id[1], format_hex8(clkid_str, frgn_master_pid->clockIdentity.id),
frgn_master_pid->clockIdentity.id[2], frgn_master_pid->clockIdentity.id[3],
frgn_master_pid->clockIdentity.id[4], frgn_master_pid->clockIdentity.id[5],
frgn_master_pid->clockIdentity.id[6], frgn_master_pid->clockIdentity.id[7],
frgn_master_pid->portNumber); frgn_master_pid->portNumber);
} }
if (ppg->ebest_idx != best) { if (ppg->ebest_idx != best) {
......
...@@ -260,6 +260,7 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len) ...@@ -260,6 +260,7 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len)
/* Check if the foreign master has changed */ /* Check if the foreign master has changed */
if ( DSPAR(ppi)->newGrandmaster ) { if ( DSPAR(ppi)->newGrandmaster ) {
char gm_str[26];
// New grandmaster detected // New grandmaster detected
DSPAR(ppi)->newGrandmaster=FALSE; // Clear it DSPAR(ppi)->newGrandmaster=FALSE; // Clear it
...@@ -268,8 +269,7 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len) ...@@ -268,8 +269,7 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len)
ppi->next_state = PPS_UNCALIBRATED; ppi->next_state = PPS_UNCALIBRATED;
Octet *id=DSPAR(ppi)->parentPortIdentity.clockIdentity.id; Octet *id=DSPAR(ppi)->parentPortIdentity.clockIdentity.id;
pp_info("New grandmaster detected: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", pp_info("New grandmaster detected: %s\n", format_hex8(gm_str, id));
id[0],id[1],id[2],id[3],id[4],id[5],id[6],id[7]);
} }
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <ppsi/ieee1588_types.h> /* from ../include */ #include <ppsi/ieee1588_types.h> /* from ../include */
#include "decent_types.h" #include "decent_types.h"
#include "ptpdump.h" #include "ptpdump.h"
#include <ppsi/lib.h>
#define WR_MODE_ON_MASK 0x8 #define WR_MODE_ON_MASK 0x8
#define CALIBRATED_MASK 0x4 #define CALIBRATED_MASK 0x4
...@@ -65,6 +66,8 @@ static int dump_eth(char *prefix, struct ethhdr *eth) ...@@ -65,6 +66,8 @@ static int dump_eth(char *prefix, struct ethhdr *eth)
unsigned char *s = eth->h_source; unsigned char *s = eth->h_source;
int proto = ntohs(eth->h_proto); int proto = ntohs(eth->h_proto);
int ret; int ret;
char mac_s[20];
char mac_d[20];
/* Between eth header and payload may be a VLAN tag; /* Between eth header and payload may be a VLAN tag;
* NOTE: We cannot distinguish between both cases looking at * NOTE: We cannot distinguish between both cases looking at
...@@ -77,10 +80,9 @@ static int dump_eth(char *prefix, struct ethhdr *eth) ...@@ -77,10 +80,9 @@ static int dump_eth(char *prefix, struct ethhdr *eth)
} else } else
ret = sizeof(struct ethhdr); ret = sizeof(struct ethhdr);
printf("%sETH: %04x (%02x:%02x:%02x:%02x:%02x:%02x -> " printf("%sETH: %04x (%s -> %s)\n", prefix, proto,
"%02x:%02x:%02x:%02x:%02x:%02x)\n", prefix, proto, format_mac(mac_s, s),
s[0], s[1], s[2], s[3], s[4], s[5], format_mac(mac_d, d));
d[0], d[1], d[2], d[3], d[4], d[5]);
return ret; return ret;
} }
......
...@@ -222,3 +222,27 @@ int main(int argc, char **argv) ...@@ -222,3 +222,27 @@ int main(int argc, char **argv)
return 0; return 0;
} }
char *format_hex(char *s, const unsigned char *mac, int cnt)
{
int i;
*s = '\0';
for (i = 0; i < cnt; i++) {
sprintf(s, "%s%02x:", s, mac[i]);
}
/* remove last colon */
s[cnt * 3 - 1] = '\0'; /* cnt * strlen("FF:") - 1 */
return s;
}
char *format_hex8(char *s, const unsigned char *mac)
{
return format_hex(s, mac, 8);
}
char *format_mac(char *s, const unsigned char *mac)
{
format_hex(s, mac, 6);
return s;
}
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