]> git.sur5r.net Git - ngadmin/blob - raw/include/nsdp/protocol.h
Raw: refactor attribute encoding and decoding
[ngadmin] / raw / include / nsdp / protocol.h
1
2 #ifndef DEF_PROTOCOL
3 #define DEF_PROTOCOL
4
5
6 #include <netinet/ether.h>
7
8
9 #define CLIENT_PORT             63321
10 #define SWITCH_PORT             63322
11
12 #define NSDP_VERSION            1
13 #define NSDP_PROTOID            "NSDP"
14
15 #define CODE_READ_REQ           1
16 #define CODE_READ_REP           2
17 #define CODE_WRITE_REQ          3
18 #define CODE_WRITE_REP          4
19
20 #define ERROR_READONLY          3
21 #define ERROR_INVALID_VALUE     5
22 #define ERROR_DENIED            7
23
24
25 #define ATTR_PRODUCT            0x0001
26 #define ATTR_UNK_0002           0x0002
27 #define ATTR_NAME               0x0003
28 #define ATTR_MAC                0x0004
29 #define ATTR_UNK_0005           0x0005
30 #define ATTR_IP                 0x0006
31 #define ATTR_NETMASK            0x0007
32 #define ATTR_GATEWAY            0x0008
33 #define ATTR_NEW_PASSWORD       0x0009
34 #define ATTR_PASSWORD           0x000A
35 #define ATTR_DHCP               0x000B
36 #define ATTR_UNK_000C           0x000C
37 #define ATTR_FIRM_VER           0x000D
38 #define ATTR_UNK_000E           0x000E
39 #define ATTR_UNK_000F           0x000F
40 #define ATTR_FIRM_UPGRADE       0x0010
41 #define ATTR_RESTART            0x0013
42 #define ATTR_ENCPASS            0x0014
43 #define ATTR_DEFAULTS           0x0400
44 #define ATTR_PORT_STATUS        0x0C00
45 #define ATTR_PORT_STATISTICS    0x1000
46 #define ATTR_STATS_RESET        0x1400
47 #define ATTR_CABLETEST_DO       0x1800
48 #define ATTR_CABLETEST_RESULT   0x1C00
49 #define ATTR_VLAN_TYPE          0x2000
50 #define ATTR_VLAN_PORT_CONF     0x2400
51 #define ATTR_VLAN_DOT_CONF      0x2800
52 #define ATTR_VLAN_DESTROY       0x2C00
53 #define ATTR_VLAN_PVID          0x3000
54 #define ATTR_QOS_TYPE           0x3400
55 #define ATTR_QOS_CONFIG         0x3800
56 #define ATTR_BITRATE_INPUT      0x4C00
57 #define ATTR_BITRATE_OUTPUT     0x5000
58 #define ATTR_STORM_ENABLE       0x5400
59 #define ATTR_STORM_BITRATE      0x5800
60 #define ATTR_MIRROR             0x5C00
61 #define ATTR_PORTS_COUNT        0x6000
62 #define ATTR_MAX_VLAN           0x6400
63 #define ATTR_IGMP_ENABLE_VLAN   0x6800
64 #define ATTR_IGMP_BLOCK_UNK     0x6C00
65 #define ATTR_IGMP_VALID_V3      0x7000
66 #define ATTR_TLV_BITMAP         0x7400
67 #define ATTR_END                0xFFFF
68
69
70
71 struct nsdp_header {
72         unsigned char version;                  /* always 1, maybe version */
73         unsigned char code;                     /* request code: read request, read reply, write request, write reply */
74         unsigned char error;                    /* error code, 0 when no error */
75         unsigned char unk1;                     /* always 0, unknown */
76         unsigned short attr;                    /* attribute code which caused error, 0 when no error */
77         unsigned char unk2[2];                  /* always 0, unknown */
78         unsigned char client_mac[ETH_ALEN];     /* client MAC address */
79         unsigned char switch_mac[ETH_ALEN];     /* switch MAC address */
80         unsigned int seqnum;                    /* sequence number */
81         unsigned char proto_id[4];              /* always "NSDP", maybe short for "Netgear Switch Description Protocol" */
82         unsigned char unk3[4];                  /* always 0, unknown */
83         unsigned char data[0];                  /* attributes data */
84 } __attribute__((packed));
85
86
87 struct attr_header {
88         unsigned short attr;            /* attribute code */
89         unsigned short size;            /* attribute data size */
90         unsigned char data[0];                  /* attribute data */
91 } __attribute__((packed));
92
93
94
95 struct attr_port_status {
96         unsigned char port;             /* port number */
97         unsigned char status;           /* port status (speed index) */
98         unsigned char unk;              /* unknown */
99 } __attribute__((packed));
100
101
102 struct attr_port_stat {
103         unsigned char port;             /* port number */
104         unsigned long long recv;        /* received bytes */
105         unsigned long long sent;        /* sent bytes */
106         unsigned long long unk1;        /* unknown */
107         unsigned long long unk2;        /* unknown */
108         unsigned long long unk3;        /* unknown */
109         unsigned long long crc;         /* CRC errors */
110 } __attribute__((packed));
111
112
113 struct attr_bitrate {
114         unsigned char port;             /* port number */
115         int bitrate;                    /* bitrate index */
116 } __attribute__((packed));
117
118
119 struct attr_qos {
120         unsigned char port;             /* port number */
121         unsigned char prio;             /* prio index */
122 } __attribute__((packed));
123
124
125 struct attr_pvid {
126         unsigned char port;             /* port number */
127         unsigned short vlan;            /* VLAN */
128 } __attribute__((packed));
129
130
131 struct attr_igmp_vlan {
132         unsigned short enable;          /* IGMP filtering enabled */
133         unsigned short vlan;            /* VLAN where IGMP packets are filtered */
134 } __attribute__((packed));
135
136
137 struct attr_cabletest_do {
138         unsigned char port;             /* port number */
139         unsigned char action;           /* action index */
140 } __attribute__((packed));
141
142
143 struct attr_cabletest_result {
144         unsigned char port;             /* port number */
145         unsigned int v1;                /* raw value 1 (values unknown yet) */
146         unsigned int v2;                /* raw value 2 (values unknown yet) */
147 } __attribute__((packed));
148
149
150 /* Note: this structure is not sent "as-is" on the wire.
151  * A translation is done between the wire format (which uses somewhat not
152  * trivial bitmap) and this simpler format. See attr.c for more details.
153  */
154 struct attr_vlan_conf {
155         unsigned short vlan;            /* VLAN number */
156         unsigned char ports[0];         /* array, maps each port association with the VLAN */
157 };
158
159
160 /* Note: this structure is not sent "as-is" on the wire.
161  * A translation is done between the wire format (which uses somewhat not
162  * trivial bitmap) and this simpler format. See attr.c for more details.
163  */
164 struct attr_mirror {
165         unsigned char outport;          /* port number on which traffic is sent */
166         unsigned char ports[0];         /* array, maps each port source mirror traffic */
167 };
168
169
170 #endif
171