Now that all the pieces are in place, hook the port logic into the
unicast service code.

Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 config.c            |  1 +
 configs/default.cfg |  1 +
 port.c              |  7 ++++++-
 port_signaling.c    | 19 ++++++++++++++++++-
 unicast_service.c   |  4 +++-
 5 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/config.c b/config.c
index cc3055c..15cf5c5 100644
--- a/config.c
+++ b/config.c
@@ -265,6 +265,7 @@ struct config_item config_tab[] = {
        PORT_ITEM_INT("udp_ttl", 1, 1, 255),
        PORT_ITEM_INT("udp6_scope", 0x0E, 0x00, 0x0F),
        GLOB_ITEM_STR("uds_address", "/var/run/ptp4l"),
+       PORT_ITEM_INT("unicast_listen", 0, 0, 1),
        PORT_ITEM_INT("unicast_master_table", 0, 0, INT_MAX),
        PORT_ITEM_INT("unicast_req_duration", 3600, 10, INT_MAX),
        GLOB_ITEM_INT("use_syslog", 1, 0, 1),
diff --git a/configs/default.cfg b/configs/default.cfg
index 33c808e..00ec61f 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -42,6 +42,7 @@ hybrid_e2e            0
 net_sync_monitor       0
 tc_spanning_tree       0
 tx_timestamp_timeout   1
+unicast_listen         0
 unicast_master_table   0
 unicast_req_duration   3600
 use_syslog             1
diff --git a/port.c b/port.c
index cc1ea78..8cc1641 100644
--- a/port.c
+++ b/port.c
@@ -41,6 +41,7 @@
 #include "tmv.h"
 #include "tsproc.h"
 #include "unicast_client.h"
+#include "unicast_service.h"
 #include "util.h"
 
 #define ALLOWED_LOST_RESPONSES 3
@@ -2216,6 +2217,7 @@ void port_close(struct port *p)
                rtnl_close(p->fda.fd[FD_RTNL]);
        }
 
+       unicast_service_cleanup(p);
        transport_destroy(p->trp);
        tsproc_destroy(p->tsproc);
        if (p->fault_fd >= 0) {
@@ -2480,7 +2482,7 @@ static enum fsm_event bc_event(struct port *p, int 
fd_index)
 
        case FD_UNICAST_SRV_TIMER:
                pr_debug("port %hu: unicast service timeout", portnum(p));
-               return EV_NONE;
+               return unicast_service_timer(p) ? EV_FAULT_DETECTED : EV_NONE;
 
        case FD_UNICAST_REQ_TIMER:
                pr_debug("port %hu: unicast request timeout", portnum(p));
@@ -2898,6 +2900,9 @@ struct port *port_open(int phc_index,
            config_set_section_int(cfg, p->name, "hybrid_e2e", 1)) {
                goto err_port;
        }
+       if (number && unicast_service_initialize(p)) {
+               goto err_port;
+       }
        p->hybrid_e2e = config_get_int(cfg, p->name, "hybrid_e2e");
 
        if (number && type == CLOCK_TYPE_P2P && p->delayMechanism != DM_P2P) {
diff --git a/port_signaling.c b/port_signaling.c
index c26e062..f845d36 100644
--- a/port_signaling.c
+++ b/port_signaling.c
@@ -19,6 +19,7 @@
  */
 #include "port_private.h"
 #include "unicast_client.h"
+#include "unicast_service.h"
 
 struct ptp_message *port_signaling_construct(struct port *p,
                                             struct address *address,
@@ -49,7 +50,7 @@ struct ptp_message *port_signaling_construct(struct port *p,
 int process_signaling(struct port *p, struct ptp_message *m)
 {
        struct tlv_extra *extra;
-       int err = 0;
+       int err = 0, result;
 
        switch (p->state) {
        case PS_INITIALIZING:
@@ -69,13 +70,29 @@ int process_signaling(struct port *p, struct ptp_message *m)
        TAILQ_FOREACH(extra, &m->tlv_list, list) {
                switch (extra->tlv->type) {
                case TLV_REQUEST_UNICAST_TRANSMISSION:
+                       result = unicast_service_add(p, m, extra);
+                       switch (result) {
+                       case SERVICE_GRANTED:
+                               err = unicast_service_grant(p, m, extra);
+                               break;
+                       case SERVICE_DENIED:
+                               err = unicast_service_deny(p, m, extra);
+                               break;
+                       case SERVICE_DISABLED:
+                       default:
+                               break;
+                       }
                        break;
+
                case TLV_GRANT_UNICAST_TRANSMISSION:
                        unicast_client_grant(p, m, extra);
                        break;
+
                case TLV_CANCEL_UNICAST_TRANSMISSION:
                        err = unicast_client_cancel(p, m, extra);
+                       unicast_service_remove(p, m, extra);
                        break;
+
                case TLV_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION:
                        break;
                }
diff --git a/unicast_service.c b/unicast_service.c
index 6318a24..09e0eac 100644
--- a/unicast_service.c
+++ b/unicast_service.c
@@ -404,7 +404,9 @@ int unicast_service_initialize(struct port *p)
        if (!config_get_int(cfg, p->name, "unicast_listen")) {
                return 0;
        }
-
+       if (config_set_section_int(cfg, p->name, "hybrid_e2e", 1)) {
+               return -1;
+       }
        p->unicast_service = calloc(1, sizeof(*p->unicast_service));
        if (!p->unicast_service) {
                return -1;
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to