Split management message creation to more fine-grained functions to allow notification messages to be created.
Signed-off-by: Jiri Benc <jb...@redhat.com> --- clock.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---------- clock.h | 8 ++++++++ port.c | 8 +++++++- port.h | 14 ++++++++++++++ 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/clock.c b/clock.c index 29d58b0c2461..e585074daea3 100644 --- a/clock.c +++ b/clock.c @@ -290,22 +290,16 @@ static void clock_management_send_error(struct port *p, pr_err("failed to send management error status"); } -static int clock_management_get_response(struct clock *c, struct port *p, - int id, struct ptp_message *req) +static int clock_management_fill_response(struct clock *c, + struct ptp_message *rsp, int id) { int datalen = 0, respond = 0; struct management_tlv *tlv; struct management_tlv_datum *mtd; - struct ptp_message *rsp; struct time_status_np *tsn; struct grandmaster_settings_np *gsn; - struct PortIdentity pid = port_identity(p); struct PTPText *text; - 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; @@ -416,10 +410,26 @@ static int clock_management_get_response(struct clock *c, struct port *p, tlv->length = sizeof(tlv->id) + datalen; rsp->header.messageLength += sizeof(*tlv) + datalen; rsp->tlv_count = 1; - port_prepare_and_send(p, rsp, 0); } + return respond; +} + +static int clock_management_get_response(struct clock *c, struct port *p, + int id, struct ptp_message *req) +{ + struct PortIdentity pid = port_identity(p); + struct ptp_message *rsp; + int respond; + + rsp = port_management_reply(pid, p, req); + if (!rsp) { + return 0; + } + respond = clock_management_fill_response(c, rsp, id); + if (respond) + port_prepare_and_send(p, rsp, 0); msg_put(rsp); - return respond ? 1 : 0; + return respond; } static int clock_management_set(struct clock *c, struct port *p, @@ -1062,6 +1072,34 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg) return changed; } +void clock_notify_event(struct clock *c, enum notification event) +{ + struct port *uds = c->port[c->nports]; + struct PortIdentity pid = port_identity(uds); + struct ptp_message *msg; + UInteger16 msg_len; + int id; + + switch (event) { + /* set id */ + default: + return; + } + /* targetPortIdentity and sequenceId will be filled by + * clock_send_notification */ + msg = port_management_notify(pid, uds); + if (!msg) + return; + if (!clock_management_fill_response(c, msg, id)) + goto err; + msg_len = msg->header.messageLength; + if (msg_pre_send(msg)) + goto err; + clock_send_notification(c, msg, msg_len, event); +err: + msg_put(msg); +} + struct parent_ds *clock_parent_ds(struct clock *c) { return &c->dad; diff --git a/clock.h b/clock.h index 8718f2db715b..92ec163d962f 100644 --- a/clock.h +++ b/clock.h @@ -145,6 +145,14 @@ void clock_send_notification(struct clock *c, struct ptp_message *msg, int msglen, enum notification event); /** + * Construct and send notification to subscribers about an event that + * occured on the clock. + * @param c The clock instance. + * @param event The identification of the event. + */ +void clock_notify_event(struct clock *c, enum notification event); + +/** * Obtain a clock's parent data set. * @param c The clock instance. * @return A pointer to the parent data set of the clock. diff --git a/port.c b/port.c index d48d275ba1a3..29e98ceb66ce 100644 --- a/port.c +++ b/port.c @@ -2336,6 +2336,12 @@ struct ptp_message *port_management_reply(struct PortIdentity pid, management_action(req)); } +struct ptp_message *port_management_notify(struct PortIdentity pid, + struct port *port) +{ + return port_management_construct(pid, port, 0, NULL, 1, GET); +} + void port_notify_event(struct port *p, enum notification event) { struct PortIdentity pid = port_identity(p); @@ -2350,7 +2356,7 @@ void port_notify_event(struct port *p, enum notification event) } /* targetPortIdentity and sequenceId will be filled by * clock_send_notification */ - msg = port_management_construct(pid, p, 0, NULL, 1, GET); + msg = port_management_notify(pid, p); if (!msg) return; if (!port_management_fill_response(p, msg, id)) diff --git a/port.h b/port.h index 34c18a3e2d0c..a1b8ad795040 100644 --- a/port.h +++ b/port.h @@ -157,6 +157,20 @@ struct ptp_message *port_management_reply(struct PortIdentity pid, struct ptp_message *req); /** + * Allocate a standalone reply management message. + * + * See note in @ref port_management_reply description about freeing the + * message. Also note that the constructed message does not have + * targetPortIdentity and sequenceId filled. + * + * @param pid The id of the responding port. + * @param port The port to which the message will be sent. + * @return Pointer to a message on success, NULL otherwise. + */ +struct ptp_message *port_management_notify(struct PortIdentity pid, + struct port *port); + +/** * Construct and send notification to subscribers about an event that * occured on the port. * @param p The port. -- 1.7.6.5 ------------------------------------------------------------------------------ "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available. Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel