Used to enumerate all ports. With the future dynamic port adding/removal,
there may be holes in the port number sequence. For now, just fill it with
the sequence numbers.

Signed-off-by: Jiri Benc <jb...@redhat.com>
---
 clock.c |   16 ++++++++++++++++
 tlv.c   |   29 +++++++++++++++++++++++++++++
 tlv.h   |    6 ++++++
 3 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/clock.c b/clock.c
index 010262f522e3..2e7794cc07cd 100644
--- a/clock.c
+++ b/clock.c
@@ -381,6 +381,21 @@ static int clock_management_fill_response(struct clock *c,
                datalen = sizeof(*gsn);
                respond = 1;
                break;
+       case PORT_ENUMERATION_NP:
+               {
+                       struct port_enumeration_np *pen;
+                       int i;
+
+                       if (c->nports > 720)
+                               break;
+                       pen = (struct port_enumeration_np *)tlv->data;
+                       pen->numberPorts = c->nports;
+                       for (i = 0; i < c->nports; i++)
+                               pen->portNumber[i] = i + 1;
+                       datalen = sizeof(*pen) + pen->numberPorts * 
sizeof(UInteger16);
+                       respond = 1;
+               }
+               break;
        }
        if (respond) {
                if (datalen % 2) {
@@ -1030,6 +1045,7 @@ int clock_manage(struct clock *c, struct port *p, struct 
ptp_message *msg)
        case TIME_STATUS_NP:
        case GRANDMASTER_SETTINGS_NP:
        case SUBSCRIBE_EVENTS_NP:
+       case PORT_ENUMERATION_NP:
                clock_management_send_error(p, msg, NOT_SUPPORTED);
                break;
        default:
diff --git a/tlv.c b/tlv.c
index 352026ee5f7a..8d635c452905 100644
--- a/tlv.c
+++ b/tlv.c
@@ -252,6 +252,24 @@ static int mgt_post_recv(struct management_tlv *m, 
uint16_t data_len,
                        sen->bitmask = ntohl(sen->bitmask);
                }
                break;
+       case PORT_ENUMERATION_NP:
+               {
+                       struct port_enumeration_np *pen;
+                       size_t expected_len;
+                       int i;
+
+                       if (data_len < sizeof(struct port_enumeration_np))
+                               goto bad_length;
+                       pen = (struct port_enumeration_np *)m->data;
+                       pen->numberPorts = ntohs(pen->numberPorts);
+                       expected_len = sizeof(struct port_enumeration_np) +
+                                      pen->numberPorts * sizeof(UInteger16);
+                       if (data_len != expected_len)
+                               goto bad_length;
+                       for (i = 0; i < pen->numberPorts; i++)
+                               pen->portNumber[i] = ntohs(pen->portNumber[i]);
+               }
+               break;
        case SAVE_IN_NON_VOLATILE_STORAGE:
        case RESET_NON_VOLATILE_STORAGE:
        case INITIALIZE:
@@ -355,6 +373,17 @@ static void mgt_pre_send(struct management_tlv *m, struct 
tlv_extra *extra)
                        sen->bitmask = htonl(sen->bitmask);
                }
                break;
+       case PORT_ENUMERATION_NP:
+               {
+                       struct port_enumeration_np *pen;
+                       int i;
+
+                       pen = (struct port_enumeration_np *)m->data;
+                       for (i = 0; i < pen->numberPorts; i++)
+                               pen->portNumber[i] = htons(pen->portNumber[i]);
+                       pen->numberPorts = htons(pen->numberPorts);
+               }
+               break;
        }
 }
 
diff --git a/tlv.h b/tlv.h
index 8eb840685a81..dffdabda7d09 100644
--- a/tlv.h
+++ b/tlv.h
@@ -80,6 +80,7 @@ enum management_action {
 #define TIME_STATUS_NP                                 0xC000
 #define GRANDMASTER_SETTINGS_NP                                0xC001
 #define SUBSCRIBE_EVENTS_NP                            0xC003
+#define PORT_ENUMERATION_NP                            0xC004
 
 /* Port management ID values */
 #define NULL_MANAGEMENT                                        0x0000
@@ -201,6 +202,11 @@ struct subscribe_events_np {
        UInteger32    bitmask;
 } PACKED;
 
+struct port_enumeration_np {
+       UInteger16 numberPorts;
+       UInteger16 portNumber[0];
+} PACKED;
+
 enum clock_type {
        CLOCK_TYPE_ORDINARY   = 0x8000,
        CLOCK_TYPE_BOUNDARY   = 0x4000,
-- 
1.7.6.5


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to