Skip to content

Commit

Permalink
Add the ALTERNATE_TIME_OFFSET_NAME management message.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Feb 25, 2023
1 parent a0bb005 commit d1b65c7
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
21 changes: 20 additions & 1 deletion clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ static int clock_management_fill_response(struct clock *c, struct port *p,
struct ptp_message *rsp, int id)
{
struct alternate_time_offset_properties *atop;
struct alternate_time_offset_name *aton;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
Expand Down Expand Up @@ -461,6 +462,16 @@ static int clock_management_fill_response(struct clock *c, struct port *p,
mtd->val = c->tds.flags & PTP_TIMESCALE;
datalen = sizeof(*mtd);
break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
key = clock_alttime_offset_get_key(req);
if (key >= MAX_TIME_ZONES) {
break;
}
aton = (struct alternate_time_offset_name *) tlv->data;
aton->keyField = key;
ptp_text_copy(&aton->displayName, &c->tz[key].display_name);
datalen = sizeof(*aton) + aton->displayName.length;
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
key = clock_alttime_offset_get_key(req);
if (key >= MAX_TIME_ZONES) {
Expand Down Expand Up @@ -558,6 +569,7 @@ static int clock_management_set(struct clock *c, struct port *p,
int id, struct ptp_message *req, int *changed)
{
struct alternate_time_offset_properties *atop;
struct alternate_time_offset_name *aton;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
Expand All @@ -579,6 +591,14 @@ static int clock_management_set(struct clock *c, struct port *p,
*changed = 1;
respond = 1;
break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
aton = (struct alternate_time_offset_name *) tlv->data;
key = aton->keyField;
if (key < MAX_TIME_ZONES &&
!static_ptp_text_copy(&c->tz[key].display_name, &aton->displayName)) {
respond = 1;
}
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) tlv->data;
key = atop->keyField;
Expand Down Expand Up @@ -1594,7 +1614,6 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
case MID_ACCEPTABLE_MASTER_TABLE:
case MID_ACCEPTABLE_MASTER_MAX_TABLE_SIZE:
case MID_ALTERNATE_TIME_OFFSET_ENABLE:
case MID_ALTERNATE_TIME_OFFSET_NAME:
case MID_ALTERNATE_TIME_OFFSET_MAX_KEY:
case MID_TRANSPARENT_CLOCK_DEFAULT_DATA_SET:
case MID_PRIMARY_DOMAIN:
Expand Down
9 changes: 9 additions & 0 deletions pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ static void pmc_show_signaling(struct ptp_message *msg, FILE *fp)
static void pmc_show(struct ptp_message *msg, FILE *fp)
{
struct alternate_time_offset_properties *atop;
struct alternate_time_offset_name *aton;
struct ieee_c37_238_settings_np *pwr;
struct unicast_master_table_np *umtn;
struct grandmaster_settings_np *gsn;
Expand Down Expand Up @@ -361,6 +362,14 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
fprintf(fp, "TIMESCALE_PROPERTIES "
IFMT "ptpTimescale %d", mtd->val & PTP_TIMESCALE ? 1 : 0);
break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
aton = (struct alternate_time_offset_name *) mgt->data;
fprintf(fp, "ALTERNATE_TIME_OFFSET_NAME "
IFMT "keyField %hhu"
IFMT "displayName %s",
aton->keyField,
text2str(&aton->displayName));
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) mgt->data;
next_jump = atop->timeOfNextJump.seconds_msb;
Expand Down
56 changes: 55 additions & 1 deletion pmc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static void do_get_action(struct pmc *pmc, int action, int index, char *str);
static void do_set_action(struct pmc *pmc, int action, int index, char *str);
static void not_supported(struct pmc *pmc, int action, int index, char *str);
static void null_management(struct pmc *pmc, int action, int index, char *str);
static int send_set_aton(struct pmc *pmc, int id, uint8_t key, const char *name);

static const char *action_string[] = {
"GET",
Expand Down Expand Up @@ -121,7 +122,7 @@ struct management_id idtab[] = {
{ "ACCEPTABLE_MASTER_TABLE", MID_ACCEPTABLE_MASTER_TABLE, not_supported },
{ "ACCEPTABLE_MASTER_MAX_TABLE_SIZE", MID_ACCEPTABLE_MASTER_MAX_TABLE_SIZE, not_supported },
{ "ALTERNATE_TIME_OFFSET_ENABLE", MID_ALTERNATE_TIME_OFFSET_ENABLE, not_supported },
{ "ALTERNATE_TIME_OFFSET_NAME", MID_ALTERNATE_TIME_OFFSET_NAME, not_supported },
{ "ALTERNATE_TIME_OFFSET_NAME", MID_ALTERNATE_TIME_OFFSET_NAME, do_set_action },
{ "ALTERNATE_TIME_OFFSET_MAX_KEY", MID_ALTERNATE_TIME_OFFSET_MAX_KEY, not_supported },
{ "ALTERNATE_TIME_OFFSET_PROPERTIES", MID_ALTERNATE_TIME_OFFSET_PROPERTIES, do_set_action },
{ "MASTER_ONLY", MID_MASTER_ONLY, do_get_action },
Expand Down Expand Up @@ -178,7 +179,9 @@ static void do_set_action(struct pmc *pmc, int action, int index, char *str)
struct port_ds_np pnp;
char onoff_port_state[4] = "off";
char onoff_time_status[4] = "off";
char display_name[11] = {0};
uint64_t jump;
uint8_t key;

mtd.reserved = 0;

Expand Down Expand Up @@ -207,6 +210,19 @@ static void do_set_action(struct pmc *pmc, int action, int index, char *str)
}
pmc_send_set_action(pmc, code, &mtd, sizeof(mtd));
break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
cnt = sscanf(str, " %*s %*s "
"keyField %hhu "
"displayName %10s ",
&key,
display_name);
if (cnt != 2) {
fprintf(stderr, "%s SET needs 2 values\n",
idtab[index].name);
break;
}
send_set_aton(pmc, code, key, display_name);
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
memset(&atop, 0, sizeof(atop));
cnt = sscanf(str, " %*s %*s "
Expand Down Expand Up @@ -597,6 +613,9 @@ static int pmc_tlv_datalen(struct pmc *pmc, int id)
case MID_TIME_STATUS_NP:
len += sizeof(struct time_status_np);
break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
len += sizeof(struct alternate_time_offset_name);
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
len += sizeof(struct alternate_time_offset_properties);
break;
Expand Down Expand Up @@ -728,6 +747,41 @@ int pmc_send_set_action(struct pmc *pmc, int id, void *data, int datasize)
return 0;
}

static int send_set_aton(struct pmc *pmc, int id, uint8_t key, const char *name)
{
struct alternate_time_offset_name *aton;
struct management_tlv *mgt;
struct ptp_message *msg;
struct tlv_extra *extra;
int datasize;

datasize = sizeof(*aton) + strlen(name);
if (datasize % 2) {
datasize++;
}
msg = pmc_message(pmc, SET);
if (!msg) {
return -1;
}
extra = msg_tlv_append(msg, sizeof(*mgt) + datasize);
if (!extra) {
msg_put(msg);
return -ENOMEM;
}
mgt = (struct management_tlv *) extra->tlv;
mgt->type = TLV_MANAGEMENT;
mgt->length = 2 + datasize;
mgt->id = id;
aton = (struct alternate_time_offset_name *) mgt->data;
aton->keyField = key;
ptp_text_set(&aton->displayName, name);

pmc_send(pmc, msg);
msg_put(msg);

return 0;
}

struct ptp_message *pmc_recv(struct pmc *pmc)
{
struct ptp_message *msg;
Expand Down
11 changes: 11 additions & 0 deletions tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t data_len,
struct tlv_extra *extra)
{
struct alternate_time_offset_properties *atop;
struct alternate_time_offset_name *aton;
struct ieee_c37_238_settings_np *pwr;
struct unicast_master_table_np *umtn;
struct grandmaster_settings_np *gsn;
Expand Down Expand Up @@ -335,6 +336,14 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t data_len,
p->portIdentity.portNumber = ntohs(p->portIdentity.portNumber);
p->peerMeanPathDelay = net2host64(p->peerMeanPathDelay);
break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
aton = (struct alternate_time_offset_name *) m->data;
if (data_len < sizeof(*aton)) {
goto bad_length;
}
extra_len = sizeof(*aton);
extra_len += aton->displayName.length;
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) m->data;
if (data_len != sizeof(*atop)) {
Expand Down Expand Up @@ -558,6 +567,8 @@ static void mgt_pre_send(struct management_tlv *m, struct tlv_extra *extra)
p->portIdentity.portNumber = htons(p->portIdentity.portNumber);
p->peerMeanPathDelay = host2net64(p->peerMeanPathDelay);
break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) m->data;
/* Message alignment broken by design. */
Expand Down
5 changes: 5 additions & 0 deletions tlv.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ struct alternate_time_offset_indicator_tlv {
struct PTPText displayName;
} PACKED;

struct alternate_time_offset_name {
UInteger8 keyField;
struct PTPText displayName;
} PACKED;

struct alternate_time_offset_properties {
UInteger8 keyField;
/* Message alignment broken by design. */
Expand Down

0 comments on commit d1b65c7

Please sign in to comment.