Skip to content

Commit

Permalink
Provide a port method to allocate a management message reply.
Browse files Browse the repository at this point in the history
This function will be needed for both positive replies and error status
messages.

Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Aug 5, 2012
1 parent 2d2e38b commit f233528
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
10 changes: 10 additions & 0 deletions msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ struct ptp_message {
int tlv_count;
};

/**
* Obtain the action field from a management message.
* @param m A management message.
* @return The value of the action field.
*/
static inline uint8_t management_action(struct ptp_message *m)
{
return m->management.flags & 0x0f;
}

/**
* Test a given bit in a message's flag field.
* @param m Message to test.
Expand Down
39 changes: 39 additions & 0 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,45 @@ int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg)
return 0;
}

struct ptp_message *port_management_reply(struct PortIdentity pid,
struct port *ingress,
struct ptp_message *req)
{
struct ptp_message *msg;
int pdulen;

msg = msg_allocate();
if (!msg)
return NULL;

pdulen = sizeof(struct management_msg);
msg->hwts.type = ingress->timestamping;

msg->header.tsmt = MANAGEMENT | ingress->transportSpecific;
msg->header.ver = PTP_VERSION;
msg->header.messageLength = pdulen;
msg->header.domainNumber = clock_domain_number(ingress->clock);
msg->header.sourcePortIdentity = pid;
msg->header.sequenceId = req->header.sequenceId;
msg->header.control = CTL_MANAGEMENT;
msg->header.logMessageInterval = 0x7f;

msg->management.targetPortIdentity = req->header.sourcePortIdentity;
msg->management.startingBoundaryHops =
req->management.startingBoundaryHops - req->management.boundaryHops;
msg->management.boundaryHops = msg->management.startingBoundaryHops;

switch (management_action(req)) {
case GET: case SET:
msg->management.flags = RESPONSE;
break;
case COMMAND:
msg->management.flags = ACKNOWLEDGE;
break;
}
return msg;
}

struct port *port_open(struct port_defaults *pod,
int phc_index,
char *name,
Expand Down
16 changes: 16 additions & 0 deletions port.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ int port_forward(struct port *p, struct ptp_message *msg, int msglen);
*/
int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg);

/**
* Allocate a reply to a management message.
*
* Messages are reference counted, and newly allocated messages have a
* reference count of one. Allocated messages are freed using the
* function @ref msg_put().
*
* @param pid The id of the responding port.
* @param ingress The port on which 'req' was received.
* @param req A management message.
* @return Pointer to a message on success, NULL otherwise.
*/
struct ptp_message *port_management_reply(struct PortIdentity pid,
struct port *ingress,
struct ptp_message *req);

/**
* Open a network port.
* @param pod A pointer to a default port data set for this port.
Expand Down

0 comments on commit f233528

Please sign in to comment.