Currently the clockIdentity is generated from the mac address of the first interface/port in config file. This patch add the possibility to set it in config file. The reason is if the stack is restarted with a different set of ports, it may be circumstances when clockIdentity needs to be equal as before restart even if the port setup is different.
Signed-off-by: Anders Selhammer <anders.selham...@est.tech> --- clock.c | 16 +++++++++++++--- config.c | 1 + util.c | 15 +++++++++++++++ util.h | 9 +++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/clock.c b/clock.c index faf2dea..b87be5d 100644 --- a/clock.c +++ b/clock.c @@ -986,9 +986,19 @@ struct clock *clock_create(enum clock_type type, struct config *config, pr_info("selected /dev/ptp%d as PTP clock", phc_index); } - if (generate_clock_identity(&c->dds.clockIdentity, iface->name)) { - pr_err("failed to generate a clock identity"); - return NULL; + if (strcmp(config_get_string(config, NULL, "clockIdentity"), + "000000.0000.000000") == 0) { + if (generate_clock_identity(&c->dds.clockIdentity, + iface->name)) { + pr_err("failed to generate a clock identity"); + return NULL; + } + } else { + if (str2cid(config_get_string(config, NULL, "clockIdentity"), + &c->dds.clockIdentity)) { + pr_err("failed to set clock identity"); + return NULL; + } } /* Configure the UDS. */ diff --git a/config.c b/config.c index 7914ba4..242c7d1 100644 --- a/config.c +++ b/config.c @@ -195,6 +195,7 @@ struct config_item config_tab[] = { GLOB_ITEM_INT("check_fup_sync", 0, 0, 1), GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX), GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX), + GLOB_ITEM_STR("clockIdentity", "000000.0000.000000"), GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu), GLOB_ITEM_ENU("clock_type", CLOCK_TYPE_ORDINARY, clock_type_enu), GLOB_ITEM_ENU("dataset_comparison", DS_CMP_IEEE1588, dataset_comp_enu), diff --git a/util.c b/util.c index 73fb37e..c617510 100644 --- a/util.c +++ b/util.c @@ -218,6 +218,21 @@ int str2mac(const char *s, unsigned char mac[MAC_LEN]) return 0; } +int str2cid(const char *s, struct ClockIdentity *result) +{ + struct ClockIdentity cid; + unsigned char *ptr = cid.id; + int c; + c = sscanf(s, " %02hhx%02hhx%02hhx.%02hhx%02hhx.%02hhx%02hhx%02hhx", + &ptr[0], &ptr[1], &ptr[2], &ptr[3], + &ptr[4], &ptr[5], &ptr[6], &ptr[7]); + if (c == 8) { + *result = cid; + return 0; + } + return -1; +} + int str2pid(const char *s, struct PortIdentity *result) { struct PortIdentity pid; diff --git a/util.h b/util.h index 1ab1b3f..39d602e 100644 --- a/util.h +++ b/util.h @@ -134,6 +134,15 @@ int str2addr(enum transport_type type, const char *s, struct address *addr); int str2mac(const char *s, unsigned char mac[MAC_LEN]); /** + * Scan a string containing a clock identity and convert it into binary form. + * + * @param s String in human readable form. + * @param result Pointer to a buffer to hold the result. + * @return Zero on success, or -1 if the string is incorrectly formatted. + */ +int str2cid(const char *s, struct ClockIdentity *result); + +/** * Scan a string containing a port identity and convert it into binary form. * * @param s String in human readable form. -- 1.8.3.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel