Respond to the current data set management query.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-08-22 07:31:21 +02:00
parent 7da00ec089
commit 8c0393321e
1 changed files with 45 additions and 1 deletions

46
clock.c
View File

@ -112,6 +112,47 @@ static int clock_fault_timeout(struct clock *c, int index, int set)
return timerfd_settime(c->fault_fd[index], 0, &tmo, NULL); return timerfd_settime(c->fault_fd[index], 0, &tmo, NULL);
} }
static int clock_management_response(struct clock *c, struct port *p, int id,
struct ptp_message *req)
{
int datalen = 0, err, pdulen, respond = 0;
struct management_tlv *tlv;
struct ptp_message *rsp;
struct PortIdentity pid;
pid.clockIdentity = clock_identity(c);
pid.portNumber = 0;
rsp = port_management_reply(pid, p, req);
if (!rsp) {
return 0;
}
tlv = (struct management_tlv *) rsp->management.suffix;
tlv->type = TLV_MANAGEMENT;
tlv->id = id;
switch (id) {
case CURRENT_DATA_SET:
memcpy(tlv->data, &c->cur, sizeof(c->cur));
datalen = sizeof(c->cur);
respond = 1;
break;
}
if (respond) {
tlv->length = sizeof(tlv->id) + datalen;
pdulen = rsp->header.messageLength + sizeof(*tlv) + datalen;
rsp->header.messageLength = pdulen;
rsp->tlv_count = 1;
err = msg_pre_send(rsp);
if (err) {
goto out;
}
err = port_forward(p, rsp, pdulen);
}
out:
msg_put(rsp);
return respond ? 1 : 0;
}
static int clock_master_lost(struct clock *c) static int clock_master_lost(struct clock *c)
{ {
int i; int i;
@ -425,6 +466,10 @@ void clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
return; return;
} }
mgt = (struct management_tlv *) msg->management.suffix; mgt = (struct management_tlv *) msg->management.suffix;
if (clock_management_response(c, p, mgt->id, msg))
return;
switch (mgt->id) { switch (mgt->id) {
case USER_DESCRIPTION: case USER_DESCRIPTION:
case SAVE_IN_NON_VOLATILE_STORAGE: case SAVE_IN_NON_VOLATILE_STORAGE:
@ -433,7 +478,6 @@ void clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
case FAULT_LOG: case FAULT_LOG:
case FAULT_LOG_RESET: case FAULT_LOG_RESET:
case DEFAULT_DATA_SET: case DEFAULT_DATA_SET:
case CURRENT_DATA_SET:
case PARENT_DATA_SET: case PARENT_DATA_SET:
case TIME_PROPERTIES_DATA_SET: case TIME_PROPERTIES_DATA_SET:
case PRIORITY1: case PRIORITY1: