diff --git a/config.c b/config.c index d583b02..bcb3121 100644 --- a/config.c +++ b/config.c @@ -20,6 +20,7 @@ #include #include "config.h" #include "ether.h" +#include "print.h" static void scan_line(char *s, struct config *cfg) { @@ -29,6 +30,7 @@ static void scan_line(char *s, struct config *cfg) UInteger16 u16; UInteger8 u8; unsigned char mac[MAC_LEN]; + char string[1024]; struct defaultDS *dds = &cfg->dds; struct port_defaults *pod = &cfg->pod; @@ -36,7 +38,7 @@ static void scan_line(char *s, struct config *cfg) if (1 == sscanf(s, " twoStepFlag %d", &val)) { if (val) /* TODO - implement one step */ - dds->twoStepFlag = val ? 1 : 0; + dds->twoStepFlag = val ? 1 : 0; } else if (1 == sscanf(s, " slaveOnly %d", &val)) { @@ -133,6 +135,61 @@ static void scan_line(char *s, struct config *cfg) for (i = 0; i < MAC_LEN; i++) cfg->p2p_dst_mac[i] = mac[i]; + + } else if (1 == sscanf(s, " logging_level %d", &val)) { + + if (val >= PRINT_LEVEL_MIN && val <= PRINT_LEVEL_MAX) + cfg->print_level = val; + + } else if (1 == sscanf(s, " verbose %d", &val)) { + + cfg->verbose = val ? 1 : 0; + + } else if (1 == sscanf(s, " use_syslog %d", &val)) { + + cfg->use_syslog = val ? 1 : 0; + + } else if (1 == sscanf(s, " time_stamping %1023s", string)) { + + if (0 == strcasecmp("hardware", string)) + + cfg->timestamping = TS_HARDWARE; + + else if (0 == strcasecmp("software", string)) + + cfg->timestamping = TS_SOFTWARE; + + else if (0 == strcasecmp("legacy", string)) + + cfg->timestamping = TS_LEGACY_HW; + + } else if (1 == sscanf(s, " delay_mechanism %1023s", string)) { + + if (0 == strcasecmp("E2E", string)) + + cfg->dm = DM_E2E; + + else if (0 == strcasecmp("P2P", string)) + + cfg->dm = DM_P2P; + + else if (0 == strcasecmp("Auto", string)) + + cfg->dm = DM_AUTO; + } else if (1 == sscanf(s, " network_transport %1023s", string)) { + + if (0 == strcasecmp("UDPv4", string)) + + cfg->transport = TRANS_UDP_IPV4; + + else if (0 == strcasecmp("UDPv6", string)) + + cfg->transport = TRANS_UDP_IPV6; + + else if (0 == strcasecmp("L2", string)) + + cfg->transport = TRANS_IEEE_802_3; + } } diff --git a/config.h b/config.h index 1a56ea1..d650ac2 100644 --- a/config.h +++ b/config.h @@ -53,6 +53,10 @@ struct config { double *pi_integral_const; unsigned char *ptp_dst_mac; unsigned char *p2p_dst_mac; + + int print_level; + int use_syslog; + int verbose; }; int config_read(char *name, struct config *cfg); diff --git a/print.h b/print.h index ad18105..d85b26f 100644 --- a/print.h +++ b/print.h @@ -22,6 +22,9 @@ #include +#define PRINT_LEVEL_MIN LOG_EMERG +#define PRINT_LEVEL_MAX LOG_DEBUG + void print(int level, char const *format, ...); void print_set_syslog(int value); diff --git a/ptp4l.c b/ptp4l.c index 0d4321a..1555812 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -68,6 +68,10 @@ static struct config cfg_settings = { .pi_integral_const = &configured_pi_ki, .ptp_dst_mac = ptp_dst_mac, .p2p_dst_mac = p2p_dst_mac, + + .print_level = LOG_INFO, + .use_syslog = 1, + .verbose = 0, }; static void usage(char *progname) @@ -162,13 +166,13 @@ int main(int argc, char *argv[]) slaveonly = 1; break; case 'l': - print_set_level(atoi(optarg)); + cfg_settings.print_level = atoi(optarg); break; case 'q': - print_set_syslog(1); + cfg_settings.use_syslog = 0; break; case 'v': - print_set_verbose(1); + cfg_settings.verbose = 1; break; case 'h': usage(progname); @@ -221,6 +225,10 @@ int main(int argc, char *argv[]) ds->clockQuality.clockClass = 255; } + print_set_verbose(cfg_settings.verbose); + print_set_syslog(cfg_settings.use_syslog); + print_set_level(cfg_settings.print_level); + clock = clock_create(phc_index, iface, *nports, *timestamping, ds); if (!clock) { fprintf(stderr, "failed to create a clock\n");