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)
return NULL;
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);
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__ */
......@@ -16,11 +16,6 @@
#define FFB_TTRA 0x10
#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. */
void bmc_m1(struct pp_instance *ppi)
{
......@@ -405,6 +400,7 @@ static int bmc_gm_cmp(struct pp_instance *ppi,
int ret;
struct ClockQuality *qa = &a->grandmasterClockQuality;
struct ClockQuality *qb = &b->grandmasterClockQuality;
char clkid_str[26];
/* bmc_gm_cmp is called several times, so report only at level 2 */
pp_diag(ppi, bmc, 2, "%s\n", __func__);
......@@ -444,17 +440,12 @@ static int bmc_gm_cmp(struct pp_instance *ppi,
return a->grandmasterPriority2 - b->grandmasterPriority2;
}
pp_diag(ppi, bmc, 3, "GmId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
a->grandmasterIdentity.id[0], a->grandmasterIdentity.id[1],
a->grandmasterIdentity.id[2], a->grandmasterIdentity.id[3],
a->grandmasterIdentity.id[4], a->grandmasterIdentity.id[5],
a->grandmasterIdentity.id[6], a->grandmasterIdentity.id[7]);
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]);
pp_diag(ppi, bmc, 3, "GmId A: %s\n",
format_hex8(clkid_str, a->grandmasterIdentity.id));
pp_diag(ppi, bmc, 3, "GmId B: %s\n",
format_hex8(clkid_str, b->grandmasterIdentity.id));
return bmc_idcmp(&a->grandmasterIdentity, &b->grandmasterIdentity);
}
......@@ -469,6 +460,8 @@ static int bmc_topology_cmp(struct pp_instance *ppi,
struct PortIdentity *pidrxa = &a->receivePortIdentity;
struct PortIdentity *pidrxb = &b->receivePortIdentity;
int diff;
char clkida_str[26];
char clkidb_str[26];
/* 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,
/* stepsRemoved is equal, compare identities */
diff = bmc_pidcmp(pidtxa, pidtxb);
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",
pidtxa->clockIdentity.id[0], pidtxa->clockIdentity.id[1],
pidtxa->clockIdentity.id[2], pidtxa->clockIdentity.id[3],
pidtxa->clockIdentity.id[4], pidtxa->clockIdentity.id[5],
pidtxa->clockIdentity.id[6], pidtxa->clockIdentity.id[7],
format_hex8(clkida_str, pidtxa->clockIdentity.id),
pidtxa->portNumber,
"Tx",
pidtxb->clockIdentity.id[0], pidtxb->clockIdentity.id[1],
pidtxb->clockIdentity.id[2], pidtxb->clockIdentity.id[3],
pidtxb->clockIdentity.id[4], pidtxb->clockIdentity.id[5],
pidtxb->clockIdentity.id[6], pidtxb->clockIdentity.id[7],
format_hex8(clkidb_str, pidtxb->clockIdentity.id),
pidtxb->portNumber);
return diff;
}
/* sourcePortIdentity is equal, compare receive port identites, which
* 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",
pidrxa->clockIdentity.id[0], pidrxa->clockIdentity.id[1],
pidrxa->clockIdentity.id[2], pidrxa->clockIdentity.id[3],
pidrxa->clockIdentity.id[4], pidrxa->clockIdentity.id[5],
pidrxa->clockIdentity.id[6], pidrxa->clockIdentity.id[7],
pidrxa->portNumber,
format_hex8(clkida_str, pidtxa->clockIdentity.id),
pidtxa->portNumber,
"Rx",
pidrxb->clockIdentity.id[0], pidrxb->clockIdentity.id[1],
pidrxb->clockIdentity.id[2], pidrxb->clockIdentity.id[3],
pidrxb->clockIdentity.id[4], pidrxb->clockIdentity.id[5],
pidrxb->clockIdentity.id[6], pidrxb->clockIdentity.id[7],
pidrxb->portNumber);
format_hex8(clkidb_str, pidtxb->clockIdentity.id),
pidtxb->portNumber);
return bmc_pidcmp(pidrxa, pidrxb);
}
......@@ -553,19 +534,14 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
struct pp_frgn_master *a,
struct pp_frgn_master *b)
{
char clkid_str[26];
/* dataset_cmp is called several times, so report only at level 2 */
pp_diag(ppi, bmc, 2, "%s\n", __func__);
pp_diag(ppi, bmc, 3, "portId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
a->sourcePortIdentity.clockIdentity.id[0], a->sourcePortIdentity.clockIdentity.id[1],
a->sourcePortIdentity.clockIdentity.id[2], a->sourcePortIdentity.clockIdentity.id[3],
a->sourcePortIdentity.clockIdentity.id[4], a->sourcePortIdentity.clockIdentity.id[5],
a->sourcePortIdentity.clockIdentity.id[6], a->sourcePortIdentity.clockIdentity.id[7]);
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]);
pp_diag(ppi, bmc, 3, "portId A: %s\n",
format_hex8(clkid_str, a->sourcePortIdentity.clockIdentity.id));
pp_diag(ppi, bmc, 3, "portId B: %s\n",
format_hex8(clkid_str, b->sourcePortIdentity.clockIdentity.id));
if (!bmc_idcmp(&a->grandmasterIdentity, &b->grandmasterIdentity)) {
/* Check topology */
......@@ -870,6 +846,7 @@ struct pp_frgn_master * bmc_add_frgn_master(struct pp_instance *ppi, struct pp_
int sel;
MsgHeader *hdr = &ppi->received_ptp_header;
struct PortIdentity *pid = &hdr->sourcePortIdentity;
char clkid_str[26];
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_
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");
pp_diag(ppi, bmc, 3, fmt_clock_identity_id,
pp_diag(ppi, bmc, 3, "%s: %s.%04x\n",
"Foreign Master Port Id",
pid->clockIdentity.id[0], pid->clockIdentity.id[1],
pid->clockIdentity.id[2], pid->clockIdentity.id[3],
pid->clockIdentity.id[4], pid->clockIdentity.id[5],
pid->clockIdentity.id[6], pid->clockIdentity.id[7],
format_hex8(clkid_str, pid->clockIdentity.id),
pid->portNumber);
if (is_externalPortConfigurationEnabled(DSDEF(ppi)) ) {
......@@ -1133,6 +1107,7 @@ static int bmc_check_frgn_master(struct pp_instance *ppi)
{
int i;
struct PortIdentity *pid;
char clkid_str[26];
if (ppi->frgn_rec_num > 0) {
for (i =0; i < ppi->frgn_rec_num; i++) {
......@@ -1143,12 +1118,9 @@ static int bmc_check_frgn_master(struct pp_instance *ppi)
if(0 > bmc_pidcmp(&ppi->frgn_master[i].sourcePortIdentity,
&DSPOR(ppi)->portIdentity)) {
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",
pid->clockIdentity.id[0], pid->clockIdentity.id[1],
pid->clockIdentity.id[2], pid->clockIdentity.id[3],
pid->clockIdentity.id[4], pid->clockIdentity.id[5],
pid->clockIdentity.id[6], pid->clockIdentity.id[7],
format_hex8(clkid_str, pid->clockIdentity.id),
pid->portNumber);
return 1;
}
......@@ -1192,6 +1164,7 @@ static void bmc_update_erbest_inst(struct pp_instance *ppi) {
struct pp_frgn_master *frgn_master;
PortIdentity *frgn_master_pid;
int j, best;
char clkid_str[26];
/* if link is down clear foreign master table */
if ((!ppi->link_up) && (ppi->frgn_rec_num > 0))
......@@ -1220,12 +1193,9 @@ static void bmc_update_erbest_inst(struct pp_instance *ppi) {
ppi->frgn_rec_num);
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",
frgn_master_pid->clockIdentity.id[0], frgn_master_pid->clockIdentity.id[1],
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],
format_hex8(clkid_str, frgn_master_pid->clockIdentity.id),
frgn_master_pid->portNumber);
} else
best=-1;
......@@ -1257,6 +1227,7 @@ static void bmc_update_ebest(struct pp_globals *ppg)
int i, best=-1;
struct pp_instance *ppi_best;
PortIdentity *frgn_master_pid;
char clkid_str[26];
/* bmc_update_ebest is called several times, so report only at
* level 2 */
......@@ -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 "
"%i\n", (best+1));
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",
frgn_master_pid->clockIdentity.id[0], frgn_master_pid->clockIdentity.id[1],
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],
format_hex8(clkid_str, frgn_master_pid->clockIdentity.id),
frgn_master_pid->portNumber);
}
if (ppg->ebest_idx != best) {
......
......@@ -260,6 +260,7 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len)
/* Check if the foreign master has changed */
if ( DSPAR(ppi)->newGrandmaster ) {
char gm_str[26];
// New grandmaster detected
DSPAR(ppi)->newGrandmaster=FALSE; // Clear it
......@@ -268,8 +269,7 @@ int pp_slave(struct pp_instance *ppi, void *buf, int len)
ppi->next_state = PPS_UNCALIBRATED;
Octet *id=DSPAR(ppi)->parentPortIdentity.clockIdentity.id;
pp_info("New grandmaster detected: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
id[0],id[1],id[2],id[3],id[4],id[5],id[6],id[7]);
pp_info("New grandmaster detected: %s\n", format_hex8(gm_str, id));
}
}
......
......@@ -9,6 +9,7 @@
#include <ppsi/ieee1588_types.h> /* from ../include */
#include "decent_types.h"
#include "ptpdump.h"
#include <ppsi/lib.h>
#define WR_MODE_ON_MASK 0x8
#define CALIBRATED_MASK 0x4
......@@ -65,6 +66,8 @@ static int dump_eth(char *prefix, struct ethhdr *eth)
unsigned char *s = eth->h_source;
int proto = ntohs(eth->h_proto);
int ret;
char mac_s[20];
char mac_d[20];
/* Between eth header and payload may be a VLAN tag;
* NOTE: We cannot distinguish between both cases looking at
......@@ -77,10 +80,9 @@ static int dump_eth(char *prefix, struct ethhdr *eth)
} else
ret = sizeof(struct ethhdr);
printf("%sETH: %04x (%02x:%02x:%02x:%02x:%02x:%02x -> "
"%02x:%02x:%02x:%02x:%02x:%02x)\n", prefix, proto,
s[0], s[1], s[2], s[3], s[4], s[5],
d[0], d[1], d[2], d[3], d[4], d[5]);
printf("%sETH: %04x (%s -> %s)\n", prefix, proto,
format_mac(mac_s, s),
format_mac(mac_d, d));
return ret;
}
......
......@@ -222,3 +222,27 @@ int main(int argc, char **argv)
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