#include <string.h> and/or #include <stdio.h> not needed.
[obnox/wireshark/wip.git] / epan / dissectors / packet-homeplug.c
1 /* packet-homeplug.c
2  * Routines for homeplug dissection
3  *
4  * Copyright 2006, Sebastien Tandel <sebastien[AT]tandel.be>
5  * Copyright 2009, Luca Ceresoli <luca[AT]lucaceresoli.net>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <glib.h>
33
34 #include <epan/packet.h>
35
36 #include <epan/etypes.h>
37
38 #include <epan/proto.h>
39 #include <epan/ptvcursor.h>
40
41 static int proto_homeplug               = -1;
42
43 static int hf_homeplug_mctrl            = -1;
44 static int hf_homeplug_mctrl_reserved = -1;
45 static int hf_homeplug_mctrl_ne = -1;
46 static int hf_homeplug_mehdr            = -1;
47 static int hf_homeplug_mehdr_mev        = -1;
48 static int hf_homeplug_mehdr_metype     = -1;
49 static int hf_homeplug_melen            = -1;
50 static int hf_homeplug_mme              = -1;
51   /* Request Channel Estimation */
52 static int hf_homeplug_rce              = -1;
53 static int hf_homeplug_rce_cev  = -1;
54 static int hf_homeplug_rce_rsvd = -1;
55   /* Channel Estimation Response */
56 static int hf_homeplug_cer              = -1;
57 static int hf_homeplug_cer_cerv = -1;
58 static int hf_homeplug_cer_rsvd1        = -1;
59 static int hf_homeplug_cer_rxtmi        = -1;
60 static int hf_homeplug_cer_vt   = -1;
61 static int hf_homeplug_cer_rate = -1;
62 static int hf_homeplug_cer_bp   = -1;
63 static int hf_homeplug_cer_mod  = -1;
64 static int hf_homeplug_cer_vt11 = -1;
65 static int hf_homeplug_cer_rsvd2        = -1;
66 static int hf_homeplug_cer_nbdas        = -1;
67 static int hf_homeplug_cer_bda  = -1;
68   /* Replace Bridge Address */
69 static int hf_homeplug_rba = -1;
70   /* Vendor Specific */
71 static int hf_homeplug_vs               = -1;
72 static int hf_homeplug_vs_oui   = -1;
73 static int hf_homeplug_vs_dir   = -1;
74 static int hf_homeplug_vs_mid   = -1;
75   /* Set Network Encryption Key */
76 static int hf_homeplug_snk              = -1;
77 static int hf_homeplug_snk_eks  = -1;
78 static int hf_homeplug_snk_nek  = -1;
79   /* Multicast With Response */
80 static int hf_homeplug_mwr = -1;
81   /* Confirm Network Encryption Key */
82 static int hf_homeplug_cnk = -1;
83   /* Host Tag */
84 static int hf_homeplug_htag = -1;
85   /* Request Parameters and Statistics */
86 static int hf_homeplug_rps              = -1;
87   /* Parameters and Statistics Response */
88 static int hf_homeplug_psr              = -1;
89 static int hf_homeplug_psr_txack        = -1;
90 static int hf_homeplug_psr_txnack       = -1;
91 static int hf_homeplug_psr_txfail       = -1;
92 static int hf_homeplug_psr_txcloss      = -1;
93 static int hf_homeplug_psr_txcoll       = -1;
94 static int hf_homeplug_psr_txca3lat     = -1;
95 static int hf_homeplug_psr_txca2lat = -1;
96 static int hf_homeplug_psr_txca1lat     = -1;
97 static int hf_homeplug_psr_txca0lat = -1;
98 static int hf_homeplug_psr_rxbp40       = -1;
99   /* Set Local Parameters */
100 static int hf_homeplug_slp              = -1;
101 static int hf_homeplug_slp_ma   = -1;
102   /* Loader */
103 static int hf_homeplug_loader           = -1;
104 static int hf_homeplug_loader_mid               = -1;
105 static int hf_homeplug_loader_length    = -1;
106 static int hf_homeplug_loader_status    = -1;
107 static int hf_homeplug_loader_version   = -1;
108 static int hf_homeplug_loader_gdfv      = -1;
109 static int hf_homeplug_loader_lsf               = -1;
110 static int hf_homeplug_loader_lwm               = -1;
111 static int hf_homeplug_loader_lrm               = -1;
112 static int hf_homeplug_loader_lrnvm     = -1;
113 static int hf_homeplug_loader_lwnvm     = -1;
114 static int hf_homeplug_loader_lreset    = -1;
115 static int hf_homeplug_loader_gmd       = -1;
116 static int hf_homeplug_loader_smd       = -1;
117 static int hf_homeplug_loader_module_id     = -1;
118 static int hf_homeplug_loader_module_offset = -1;
119 static int hf_homeplug_loader_module_size   = -1;
120 static int hf_homeplug_loader_data_length   = -1;
121 static int hf_homeplug_loader_data_address  = -1;
122 static int hf_homeplug_loader_data   = -1;
123 static int hf_homeplug_loader_cm                = -1;
124 static int hf_homeplug_loader_lemd      = -1;
125 static int hf_homeplug_loader_lenvms    = -1;
126 static int hf_homeplug_loader_gnvmp     = -1;
127 static int hf_homeplug_loader_snvmp     = -1;
128 static int hf_homeplug_loader_nvmp_type = -1;
129 static int hf_homeplug_loader_nvmp_pagesize     = -1;
130 static int hf_homeplug_loader_nvmp_blocksize    = -1;
131 static int hf_homeplug_loader_nvmp_memorysize   = -1;
132   /* Host Request */
133 static int hf_homeplug_hreq             = -1;
134 static int hf_homeplug_hreq_mid = -1;
135 static int hf_homeplug_hreq_gdv = -1;
136 static int hf_homeplug_hreq_gfv = -1;
137 static int hf_homeplug_hreq_gnek        = -1;
138 static int hf_homeplug_hreq_gclbpl      = -1;
139 static int hf_homeplug_hreq_nvds        = -1;
140 static int hf_homeplug_hreq_grbt        = -1;
141 static int hf_homeplug_hreq_gslnm       = -1;
142 static int hf_homeplug_hreq_gsss        = -1;
143 static int hf_homeplug_hreq_rsl = -1;
144 static int hf_homeplug_hreq_reset       = -1;
145 static int hf_homeplug_hreq_reset_type  = -1;
146 static int hf_homeplug_hreq_reset_delay = -1;
147   /* Host Response */
148 static int hf_homeplug_hrsp             = -1;
149 static int hf_homeplug_hrsp_mid = -1;
150 static int hf_homeplug_hrsp_gdvr        = -1;
151 static int hf_homeplug_hrsp_gfvr        = -1;
152 static int hf_homeplug_hrsp_gnekr       = -1;
153 static int hf_homeplug_hrsp_gnekr_select        = -1;
154 static int hf_homeplug_hrsp_gnekr_key   = -1;
155 static int hf_homeplug_hrsp_invalid     = -1;
156 static int hf_homeplug_hrsp_version = -1;
157   /* Network Statistics */
158 static int hf_homeplug_ns                     = -1;
159 static int hf_homeplug_ns_extended            = -1;
160     /* Basic */
161 static int hf_homeplug_ns_netw_ctrl_ac    = -1;
162 static int hf_homeplug_ns_netw_ctrl_icid  = -1;
163 static int hf_homeplug_ns_bytes40_robo    = -1;
164 static int hf_homeplug_ns_fails_robo      = -1;
165 static int hf_homeplug_ns_drops_robo      = -1;
166 static int hf_homeplug_ns_netw_da             = -1;
167 static int hf_homeplug_ns_bytes40             = -1;
168 static int hf_homeplug_ns_fails       = -1;
169 static int hf_homeplug_ns_drops       = -1;
170     /* Extended */
171 static int hf_homeplug_ns_tx_bfr_state  = -1;
172 static int hf_homeplug_ns_buf_in_use    = -1;
173 static int hf_homeplug_ns_prio          = -1;
174 static int hf_homeplug_ns_msdu_len              = -1;
175 static int hf_homeplug_ns_seqn          = -1;
176 static int hf_homeplug_ns_toneidx               = -1;
177   /* Bridging Characteristics Network */
178 static int hf_homeplug_bcn              = -1;
179 static int hf_homeplug_bcn_network      = -1;
180 static int hf_homeplug_bcn_return       = -1;
181 static int hf_homeplug_bcn_rsvd = -1;
182 static int hf_homeplug_bcn_fbn  = -1;
183 static int hf_homeplug_bcn_brda = -1;
184 static int hf_homeplug_bcn_bp_das       = -1;
185 static int hf_homeplug_bcn_bp_da        = -1;
186   /* Bridging Characteristics Local */
187 static int hf_homeplug_bcl              = -1;
188 static int hf_homeplug_bcl_network      = -1;
189 static int hf_homeplug_bcl_return       = -1;
190 static int hf_homeplug_bcl_rsvd = -1;
191 static int hf_homeplug_bcl_hprox_das= -1;
192 static int hf_homeplug_bcl_hpbda        = -1;
193   /* Set Transmit Characteristics */
194 static int hf_homeplug_stc              = -1;
195 static int hf_homeplug_stc_lco  = -1;
196 static int hf_homeplug_stc_encf = -1;
197 static int hf_homeplug_stc_txprio       = -1;
198 static int hf_homeplug_stc_rexp = -1;
199 static int hf_homeplug_stc_txcf = -1;
200 static int hf_homeplug_stc_cftop        = -1;
201 static int hf_homeplug_stc_rsvd1        = -1;
202 static int hf_homeplug_stc_retry        = -1;
203 static int hf_homeplug_stc_rsvd2        = -1;
204 static int hf_homeplug_stc_dder = -1;
205 static int hf_homeplug_stc_dur  = -1;
206 static int hf_homeplug_stc_ebp  = -1;
207 static int hf_homeplug_stc_dees = -1;
208 static int hf_homeplug_stc_txeks        = -1;
209 static int hf_homeplug_data      = -1;
210
211 static gint ett_homeplug                = -1;
212 static gint ett_homeplug_mctrl          = -1;
213 static gint ett_homeplug_mehdr          = -1;
214 static gint ett_homeplug_vs_mid         = -1;
215 static gint ett_homeplug_rce            = -1;
216 static gint ett_homeplug_cer            = -1;
217 static gint ett_homeplug_vs                     = -1;
218 static gint ett_homeplug_snk            = -1;
219 static gint ett_homeplug_rps            = -1;
220 static gint ett_homeplug_psr            = -1;
221 static gint ett_homeplug_slp            = -1;
222 static gint ett_homeplug_loader         = -1;
223 static gint ett_homeplug_hreq           = -1;
224 static gint ett_homeplug_hrsp           = -1;
225 static gint ett_homeplug_ns                     = -1;
226 static gint ett_homeplug_tone           = -1;
227 static gint ett_homeplug_tx_bfr_state   = -1;
228 static gint ett_homeplug_bridge         = -1;
229 static gint ett_homeplug_bcn            = -1;
230 static gint ett_homeplug_bcl            = -1;
231 static gint ett_homeplug_stc            = -1;
232
233
234 static guint8 homeplug_ne = 0;
235 static guint8 homeplug_melen = 0;
236 static guint8 homeplug_metype = 0;
237
238 static guint32  homeplug_offset = 0;
239
240
241 /* METYPE Values */
242 #define HOMEPLUG_MME_RCE      0x00
243 #define HOMEPLUG_MME_CER      0x01
244 #define HOMEPLUG_MME_VS       0x02
245 #define HOMEPLUG_MME_RBA      0x03
246 #define HOMEPLUG_MME_SNK      0x04
247 #define HOMEPLUG_MME_MWR      0x05
248 #define HOMEPLUG_MME_CNK      0x06
249 #define HOMEPLUG_MME_RPS      0x07
250 #define HOMEPLUG_MME_PSR      0x08
251 #define HOMEPLUG_MME_SLP      0x19
252 #define HOMEPLUG_MME_LOADER   0x10
253 #define HOMEPLUG_MME_HREQ     0x12
254 #define HOMEPLUG_MME_HRSP     0x13
255 #define HOMEPLUG_MME_HTAG     0x14
256 #define HOMEPLUG_MME_NS       0x1A
257 #define HOMEPLUG_MME_RES      0x1B
258 #define HOMEPLUG_MME_PS       0x1C
259 #define HOMEPLUG_MME_SLO      0x1D
260 #define HOMEPLUG_MME_BC       0x1E
261 #define HOMEPLUG_MME_STC      0x1F
262 static const value_string homeplug_metype_vals[] = {
263     { HOMEPLUG_MME_RCE, "Request Channel Estimation" },
264     { HOMEPLUG_MME_CER, "Channel Estimation Response" },
265     { HOMEPLUG_MME_VS , "Vendor Specific" },
266     { HOMEPLUG_MME_RBA, "Replace Bridge Address" },
267     { HOMEPLUG_MME_SNK, "Set Network Encryption Key" },
268     { HOMEPLUG_MME_MWR, "Multicast With Response" },
269     { HOMEPLUG_MME_CNK, "Confirm Network Encryption Key" },
270     { HOMEPLUG_MME_RPS, "Request Parameters and Statistics" },
271     { HOMEPLUG_MME_PSR, "Parameters and Statistics Response" },
272     { HOMEPLUG_MME_SLP, "Set Local Parameters" },
273     { HOMEPLUG_MME_NS , "Network Statistics" },
274     { HOMEPLUG_MME_RES, "Reserved" },
275     { HOMEPLUG_MME_PS , "Performance Statistics" },
276     { HOMEPLUG_MME_SLO, "Set Local Overrides" },
277     { HOMEPLUG_MME_BC , "Bridging Characteristics" },
278     { HOMEPLUG_MME_STC, "Set Transmit Characteristics" },
279     { 0, NULL }
280 };
281
282 /* MID Values, second field is METYPE they occur in */
283 #define HOMEPLUG_MID_GDD      16 /* 0x02 */
284 #define HOMEPLUG_MID_GCC      24 /* 0x02 */
285 #define HOMEPLUG_MID_GEC      25 /* 0x02 */
286 #define HOMEPLUG_MID_PRE      96 /* 0x02 */
287 #define HOMEPLUG_MID_PSI      97 /* 0x02 */
288
289 #define HOMEPLUG_MID_LGDFV     1 /* 0x10 */
290 #define HOMEPLUG_MID_LSF       2 /* 0x10 */
291 #define HOMEPLUG_MID_LWM       4 /* 0x10 */
292 #define HOMEPLUG_MID_LRM       9 /* 0x10 */
293 #define HOMEPLUG_MID_LRNVM    21 /* 0x10 */
294 #define HOMEPLUG_MID_LWNVM    22 /* 0x10 */
295 #define HOMEPLUG_MID_LRESET  127 /* 0x10 */
296 #define HOMEPLUG_MID_GMD     128 /* 0x10 */
297 #define HOMEPLUG_MID_SMD     129 /* 0x10 */
298 #define HOMEPLUG_MID_CM      130 /* 0x10 */
299 #define HOMEPLUG_MID_LEMD    132 /* 0x10 */
300 #define HOMEPLUG_MID_LENVMS  140 /* 0x10 */
301 #define HOMEPLUG_MID_GNVMP   141 /* 0x10 */
302 #define HOMEPLUG_MID_SNVMP   142 /* 0x10 */
303
304 #define HOMEPLUG_MID_GDV       1 /* 0x12 */
305 #define HOMEPLUG_MID_GFV      32 /* 0x12 */
306 #define HOMEPLUG_MID_GNEK     33 /* 0x12 */
307 #define HOMEPLUG_MID_GCLBPL   39 /* 0x12 */
308 #define HOMEPLUG_MID_NVDS     64 /* 0x12 */
309 #define HOMEPLUG_MID_GRBT     66 /* 0x12 */
310 #define HOMEPLUG_MID_GSLNM    68 /* 0x12 */
311 #define HOMEPLUG_MID_GSSS     72 /* 0x12 */
312 #define HOMEPLUG_MID_RSL     103 /* 0x12 */
313 #define HOMEPLUG_MID_RESET   127 /* 0x12 */
314
315 #define HOMEPLUG_MID_GDVR      1 /* 0x13 */
316 #define HOMEPLUG_MID_GFVR     32 /* 0x13 */
317 #define HOMEPLUG_MID_GNEKR    33 /* 0x13 */
318 #define HOMEPLUG_MID_INVALID 128 /* 0x13 */
319
320 #define HOMEPLUG_MID_EKT       1 /* 0x14 */
321
322
323
324 /* Bit mask Operation */
325 #define HOMEPLUG_MCTRL_RSVD   0x80
326 #define HOMEPLUG_MCTRL_NE     0x7F
327
328 #define HOMEPLUG_MEHDR_MEV    0xE0
329 #define HOMEPLUG_MEHDR_METYPE 0x1F
330
331 #define HOMEPLUG_VS_DIR       0x80
332 #define HOMEPLUG_VS_MID       0x3F
333
334 #define HOMEPLUG_NS_AC        0x80
335 #define HOMEPLUG_NS_ICID      0x7F
336 #define HOMEPLUG_NS_BUF_IN_USE 0x80
337 #define HOMEPLUG_NS_PRIO      0x60
338 #define HOMEPLUG_NS_MSDU_LEN  0x1F
339 #define HOMEPLUG_NS_SEQN      0xF0
340 #define HOMEPLUG_NS_TONEIDX   0x0F
341
342 /* string values in function of AC */
343 static const true_false_string homeplug_ns_ac_vals = {
344   "(from host) Return basic network statistics",
345   "(from host) Clear basic network statistics"
346 };
347
348 /* string values in function of BUF_IN_USE */
349 static const true_false_string homeplug_ns_buf_in_use_vals = {
350   "Buffer is in use",
351   "Buffer is available"
352 };
353
354 #define HOMEPLUG_RCE_CEV      0xF0
355 #define HOMEPLUG_RCE_RSVD     0x0F
356
357 #define HOMEPLUG_CER_CERV     0xF0
358 #define HOMEPLUG_CER_RSVD     0x0FE0
359 #define HOMEPLUG_CER_RXTMI    0x1F
360 #define HOMEPLUG_CER_RATE     0x80
361 #define HOMEPLUG_CER_BP       0x40
362 #define HOMEPLUG_CER_VT11     0x0F
363 #define HOMEPLUG_CER_RSVD2    0x80
364 #define HOMEPLUG_CER_NBDAS    0x7F
365
366 #define HOMEPLUG_BC_NETWORK   0x80
367 #define HOMEPLUG_BC_RETURN    0x40
368 #define HOMEPLUG_BCL_RSVD     0x3F
369 #define HOMEPLUG_BCN_RSVD     0x30
370 #define HOMEPLUG_BCN_FBN      0x0F
371
372 /* string values in function of BC_NETWORK */
373 static const true_false_string homeplug_bc_network_vals = {
374   "Network bridge information",
375   "Local bridge information"
376 };
377
378 /* string values in function of BC_RETURN */
379 static const true_false_string homeplug_bc_return_vals = {
380   "Return bridging characteristics",
381   "Set bridging characteristics"
382 };
383
384 #define HOMEPLUG_STC_LCO      0x80
385 #define HOMEPLUG_STC_ENCF     0x40
386 #define HOMEPLUG_STC_TXPRIO   0x30
387 #define HOMEPLUG_STC_REXP     0x08
388 #define HOMEPLUG_STC_TXCF     0x04
389 #define HOMEPLUG_STC_CFTOP    0x02
390 #define HOMEPLUG_STC_RSVD1    0x01
391 #define HOMEPLUG_STC_RETRY    0xC0
392 #define HOMEPLUG_STC_RSVD2    0x30
393 #define HOMEPLUG_STC_DDER     0x08
394 #define HOMEPLUG_STC_DUR      0x04
395 #define HOMEPLUG_STC_EBP      0x02
396 #define HOMEPLUG_STC_DEES     0x01
397
398 /* string values in function of CFTOP */
399 static const true_false_string homeplug_stc_cftop_vals = {
400   "CA2",
401   "CA3"
402 };
403
404 /* string values in function of RETRY */
405 static const value_string homeplug_stc_retry_vals[] = {
406   { 0, "No retries"},
407   { 1, "One retry only"},
408   { 2, "Normal retries based on specification"},
409   { 3, "Reserved"},
410   { 0, NULL}
411 };
412
413 /*  Length of Network Statistics Response defines whether it is the Basic or
414  *  the Extended Response */
415 #define HOMEPLUG_NS_BASIC_LEN 187
416 #define HOMEPLUG_NS_EXT_LEN   199
417
418 /* IC_ID Values */
419 #define HOMEPLUG_NS_ICID5130A1          0x00
420 #define HOMEPLUG_NS_ICID51X1USB         0x01
421 #define HOMEPLUG_NS_ICID51X1PHY         0x02
422 #define HOMEPLUG_NS_ICID51X1HOST        0x03
423 #define HOMEPLUG_NS_ICID5130A2          0x04
424 #define HOMEPLUG_NS_ICID_RSVD_MIN       0x05
425 #define HOMEPLUG_NS_ICID_RSVD_MAX       0x7F
426 /* string values in function of IC_ID values */
427 static const range_string homeplug_ns_icid_vals[] = {
428     { HOMEPLUG_NS_ICID5130A1,    HOMEPLUG_NS_ICID5130A1,    "INT5130A1" },
429     { HOMEPLUG_NS_ICID51X1USB,   HOMEPLUG_NS_ICID51X1USB,   "INT51X1 (USB Option)" },
430     { HOMEPLUG_NS_ICID51X1PHY,   HOMEPLUG_NS_ICID51X1PHY,   "INT51X1 (PHY Option)" },
431     { HOMEPLUG_NS_ICID51X1HOST,  HOMEPLUG_NS_ICID51X1HOST,  "INT51X1 (Host/DTE Option)" },
432     { HOMEPLUG_NS_ICID5130A2,    HOMEPLUG_NS_ICID5130A2,    "INT5130A2" },
433     { HOMEPLUG_NS_ICID_RSVD_MIN, HOMEPLUG_NS_ICID_RSVD_MAX, "Reserved"},
434     { 0, 0, NULL }
435 };
436
437 /* Modulation Method Bit Mask */
438 #define HOMEPLUG_CER_MOD_MASK           0x30
439 /* Modulation Method Values */
440 #define HOMEPLUG_CER_MOD_ROBO           0x00
441 #define HOMEPLUG_CER_MOD_DBPSK          0x01
442 #define HOMEPLUG_CER_MOD_DQPSK          0x02
443 #define HOMEPLUG_CER_MOD_RSVD           0x03
444 /* string values in function of Modulation Method Values */
445 static const value_string homeplug_cer_mod_vals[] = {
446   { HOMEPLUG_CER_MOD_ROBO,  "ROBO Modulation"},
447   { HOMEPLUG_CER_MOD_DBPSK, "DBPSK Modulation"},
448   { HOMEPLUG_CER_MOD_DQPSK, "DQPSK Modulation"},
449   { HOMEPLUG_CER_MOD_RSVD,  "Reserved"},
450   { 0, NULL}
451 };
452
453 /* Constants used by various MMEs */
454
455 #define HOMEPLUG_ADDR_INEXISTANT G_GINT64_CONSTANT(010000000000U)
456
457 /* string values in function of TXPRIO */
458 static const value_string homeplug_txprio_vals[] = {
459   { 0, "CA0"},
460   { 1, "CA1"},
461   { 2, "CA2"},
462   { 3, "CA3"},
463   { 0, NULL}
464 };
465
466 #define HOMEPLUG_MCTRL_LEN 1
467 #define HOMEPLUG_MEHDR_LEN 1
468 #define HOMEPLUG_MELEN_LEN 1
469
470
471 /* Dissection of MCTRL */
472 static void dissect_homeplug_mctrl(ptvcursor_t * cursor)
473 {
474   proto_item * it = NULL;
475
476   if (!ptvcursor_tree(cursor)) 
477     return;
478
479   it = ptvcursor_add_no_advance(cursor, hf_homeplug_mctrl, 1, FALSE);
480   /* Extract Number Of MAC Data Entries */
481   homeplug_ne = tvb_get_guint8(ptvcursor_tvbuff(cursor), 
482       ptvcursor_current_offset(cursor)) & HOMEPLUG_MCTRL_NE;
483
484   ptvcursor_push_subtree(cursor, it, ett_homeplug_mctrl);
485     ptvcursor_add_no_advance(cursor, hf_homeplug_mctrl_reserved, 1, FALSE);
486     ptvcursor_add(cursor, hf_homeplug_mctrl_ne, 1, FALSE);
487
488   ptvcursor_pop_subtree(cursor);
489 }
490
491 /* Dissection of MEHDR */
492 static void dissect_homeplug_mehdr(ptvcursor_t * cursor)
493 {
494   proto_item * it = NULL;
495
496   if (!ptvcursor_tree(cursor)) 
497     return;
498
499   it = ptvcursor_add_no_advance(cursor, hf_homeplug_mehdr, 1, FALSE);
500   homeplug_metype = tvb_get_guint8(ptvcursor_tvbuff(cursor), 
501       ptvcursor_current_offset(cursor)) & HOMEPLUG_MEHDR_METYPE;
502
503   ptvcursor_push_subtree(cursor, it, ett_homeplug_mehdr);
504     ptvcursor_add_no_advance(cursor, hf_homeplug_mehdr_mev, 1, FALSE);
505     ptvcursor_add(cursor, hf_homeplug_mehdr_metype, 1, FALSE);
506
507   ptvcursor_pop_subtree(cursor);
508 }
509
510 /* dissection of MELEN */
511 static void dissect_homeplug_melen(ptvcursor_t * cursor)
512 {
513   if (!ptvcursor_tree(cursor)) 
514     return;
515
516   homeplug_melen = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor)); 
517   ptvcursor_add(cursor, hf_homeplug_melen, 1, FALSE);
518
519 }
520
521 /* Dissection of Request Channel Estimation MME */
522 static void dissect_homeplug_rce(ptvcursor_t * cursor)
523 {
524   proto_item * it = NULL;
525
526   if (!ptvcursor_tree(cursor)) 
527     return;
528
529   it = ptvcursor_add_no_advance(cursor, hf_homeplug_rce, homeplug_melen, FALSE);
530
531   ptvcursor_push_subtree(cursor, it, ett_homeplug_rce);
532     ptvcursor_add_no_advance(cursor, hf_homeplug_rce_cev, 1, FALSE);
533     ptvcursor_add(cursor, hf_homeplug_rce_rsvd, 1, FALSE);
534
535   ptvcursor_pop_subtree(cursor);
536 }
537
538 /* Dissection of Channel Estimation Response MME */
539 static void dissect_homeplug_cer(ptvcursor_t * cursor)
540 {
541   proto_item * it = NULL;
542   guint8 iTone = 0;
543   guint8 BP = 0;
544   guint8 iNBDA = 0;
545
546   if (!ptvcursor_tree(cursor)) 
547     return;
548
549   it = ptvcursor_add_no_advance(cursor, hf_homeplug_cer, homeplug_melen, FALSE);
550
551   ptvcursor_push_subtree(cursor, it, ett_homeplug_cer);
552     ptvcursor_add_no_advance(cursor, hf_homeplug_cer_cerv, 1, FALSE);
553     ptvcursor_add(cursor, hf_homeplug_cer_rsvd1, 2, FALSE);
554     ptvcursor_add(cursor, hf_homeplug_cer_rxtmi, 1, FALSE);
555
556     for (;iTone < 10; iTone++) {
557       ptvcursor_add(cursor, hf_homeplug_cer_vt, 1, FALSE);
558     }
559
560     ptvcursor_add_no_advance(cursor, hf_homeplug_cer_rate, 1, FALSE);
561     ptvcursor_add_no_advance(cursor, hf_homeplug_cer_bp, 1, FALSE);
562     BP = tvb_get_guint8(ptvcursor_tvbuff(cursor), 
563         ptvcursor_current_offset(cursor)) & HOMEPLUG_CER_BP;
564     ptvcursor_add_no_advance(cursor, hf_homeplug_cer_mod, 1, FALSE);
565     ptvcursor_add(cursor, hf_homeplug_cer_vt11, 1, FALSE);
566     ptvcursor_add_no_advance(cursor, hf_homeplug_cer_rsvd2, 1, FALSE);
567
568     if (BP) {
569       iNBDA = tvb_get_guint8(ptvcursor_tvbuff(cursor), 
570           ptvcursor_current_offset(cursor)) & HOMEPLUG_CER_NBDAS;
571       ptvcursor_add(cursor, hf_homeplug_cer_nbdas, 1, FALSE);
572       /* TODO : Check on iNBDA! INT51X1 up to 16 dba. But up to 32 for INT51X1 (Host/DTE) */
573       for (;iNBDA > 0; iNBDA--) {
574         ptvcursor_add(cursor, hf_homeplug_cer_bda, 6, FALSE);
575       }
576     }
577   ptvcursor_pop_subtree(cursor);
578 }
579
580 /* Dissection of Vendor Specific MME */
581 static void dissect_homeplug_vs(ptvcursor_t * cursor)
582 {
583   int mid;
584   proto_item * it = NULL;
585
586   if (!ptvcursor_tree(cursor))
587     return;
588
589   it = ptvcursor_add_no_advance(cursor, hf_homeplug_vs, homeplug_melen, FALSE);
590
591   ptvcursor_push_subtree(cursor, it, ett_homeplug_vs);
592     ptvcursor_add(cursor, hf_homeplug_vs_oui, 3, FALSE);
593
594     it = ptvcursor_add_no_advance(cursor, hf_homeplug_vs_mid, 1, FALSE);
595     mid = tvb_get_guint8(ptvcursor_tvbuff(cursor),
596         ptvcursor_current_offset(cursor)) & HOMEPLUG_VS_MID;
597
598     ptvcursor_push_subtree(cursor, it, ett_homeplug_vs_mid);
599       ptvcursor_add_no_advance(cursor, hf_homeplug_vs_dir, 1, FALSE);
600       ptvcursor_add(cursor, hf_homeplug_vs_mid, 1, FALSE);
601
602     ptvcursor_pop_subtree(cursor);
603
604     switch(mid) {
605     };
606
607   ptvcursor_pop_subtree(cursor);
608 }
609
610 /* Dissection of Replace Bridge Address MME */
611 static void dissect_homeplug_rba(ptvcursor_t * cursor)
612 {
613   proto_item * it = NULL;
614
615   if (!ptvcursor_tree(cursor))
616     return;
617
618   it = ptvcursor_add_no_advance(cursor, hf_homeplug_rba, homeplug_melen, FALSE);
619 }
620
621 /* Dissection of Request Parameters and Statistics MME */
622 static void dissect_homeplug_rps(ptvcursor_t * cursor) 
623 {
624   if (!ptvcursor_tree(cursor)) 
625     return;
626
627   ptvcursor_add(cursor, hf_homeplug_rps, homeplug_melen, FALSE);
628 }
629
630 /* Dissection of Set Network Encryption Key MME */
631 static void dissect_homeplug_snk(ptvcursor_t * cursor)
632 {
633   proto_item * it = NULL;
634
635   if (!ptvcursor_tree(cursor)) 
636     return;
637
638   it = ptvcursor_add_no_advance(cursor, hf_homeplug_snk, homeplug_melen, FALSE);
639
640   ptvcursor_push_subtree(cursor, it, ett_homeplug_snk);
641     ptvcursor_add(cursor, hf_homeplug_snk_eks, 1, FALSE);
642     ptvcursor_add(cursor, hf_homeplug_snk_nek, 8, FALSE);
643
644   ptvcursor_pop_subtree(cursor);
645 }
646
647 /* Dissection of Multicast with Response MME */
648 static void dissect_homeplug_mwr(ptvcursor_t * cursor)
649 {
650   proto_item * it = NULL;
651
652   if (!ptvcursor_tree(cursor))
653     return;
654
655   it = ptvcursor_add_no_advance(cursor, hf_homeplug_mwr, homeplug_melen, FALSE);
656 }
657
658 /* Dissection of Confirm Network Encryption Key MME */
659 static void dissect_homeplug_cnk(ptvcursor_t * cursor)
660 {
661   proto_item * it = NULL;
662
663   if (!ptvcursor_tree(cursor))
664     return;
665
666   it = ptvcursor_add_no_advance(cursor, hf_homeplug_cnk, homeplug_melen, FALSE);
667 }
668
669 /* Dissection of Parameters and Statistics Response MME */
670 static void dissect_homeplug_psr(ptvcursor_t * cursor)
671 {
672   proto_item * it = NULL;
673
674   if (!ptvcursor_tree(cursor)) 
675     return;
676
677   it = ptvcursor_add_no_advance(cursor, hf_homeplug_psr, homeplug_melen, FALSE);
678
679   ptvcursor_push_subtree(cursor, it, ett_homeplug_psr);
680     ptvcursor_add(cursor, hf_homeplug_psr_txack, 2, FALSE);
681     ptvcursor_add(cursor, hf_homeplug_psr_txnack, 2, FALSE);
682     ptvcursor_add(cursor, hf_homeplug_psr_txfail, 2, FALSE);
683     ptvcursor_add(cursor, hf_homeplug_psr_txcloss, 2, FALSE);
684     ptvcursor_add(cursor, hf_homeplug_psr_txcoll, 2, FALSE);
685     ptvcursor_add(cursor, hf_homeplug_psr_txca3lat, 2, FALSE);
686     ptvcursor_add(cursor, hf_homeplug_psr_txca2lat, 2, FALSE);
687     ptvcursor_add(cursor, hf_homeplug_psr_txca1lat, 2, FALSE);
688     ptvcursor_add(cursor, hf_homeplug_psr_txca0lat, 2, FALSE);
689     ptvcursor_add(cursor, hf_homeplug_psr_rxbp40, 4, FALSE);
690
691   ptvcursor_pop_subtree(cursor);
692 }
693
694 /* Dissection of the Set Local Parameters MME */
695 static void dissect_homeplug_slp(ptvcursor_t * cursor)
696 {
697   proto_item * it = NULL;
698
699   if (!ptvcursor_tree(cursor)) 
700     return;
701
702   it = ptvcursor_add_no_advance(cursor, hf_homeplug_slp, homeplug_melen, FALSE);
703
704   ptvcursor_push_subtree(cursor, it, ett_homeplug_slp);
705     ptvcursor_add(cursor, hf_homeplug_slp_ma, 6, FALSE);
706   ptvcursor_pop_subtree(cursor);
707 }
708
709 /* Dissection of Load MME */
710 static void dissect_homeplug_loader(ptvcursor_t * cursor, packet_info * pinfo)
711 {
712         int mid, length, dlen;
713         proto_item * it = NULL;
714
715         if (!ptvcursor_tree(cursor))
716                 return;
717
718         it = ptvcursor_add_no_advance(cursor, hf_homeplug_loader, -1, FALSE);
719
720         ptvcursor_push_subtree(cursor, it, ett_homeplug_loader);
721
722         mid = tvb_get_guint8(ptvcursor_tvbuff(cursor),
723         ptvcursor_current_offset(cursor));
724
725         length = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
726         ptvcursor_current_offset(cursor) + 1);
727
728         switch(mid) {
729         case HOMEPLUG_MID_LGDFV:
730                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Get Firmware Version");
731                 ptvcursor_add(cursor, hf_homeplug_loader_gdfv, 1, FALSE);
732                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
733                 if (length != 0) {
734                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
735                         ptvcursor_add(cursor, hf_homeplug_loader_version, -1, FALSE);
736                 }
737                 break;
738         case HOMEPLUG_MID_LSF:
739                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Start Firmware");
740                 ptvcursor_add(cursor, hf_homeplug_loader_lsf, 1, FALSE);
741                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
742                 break;
743         case HOMEPLUG_MID_LWM:
744                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Write Memory");
745                 ptvcursor_add(cursor, hf_homeplug_loader_lwm, 1, FALSE);
746                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
747                 if (length == 7)
748                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
749                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
750
751                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
752                 ptvcursor_current_offset(cursor));
753                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
754                 if (length != 7)
755                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
756                 break;
757         case HOMEPLUG_MID_LRM:
758                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Read Memory");
759                 ptvcursor_add(cursor, hf_homeplug_loader_lrm, 1, FALSE);
760                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
761                 if (length != 6)
762                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
763                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
764                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
765                 ptvcursor_current_offset(cursor));
766                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
767                 if (length != 6)
768                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
769                 break;
770         case HOMEPLUG_MID_LRNVM:
771                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Read NVM");
772                 ptvcursor_add(cursor, hf_homeplug_loader_lrnvm, 1, FALSE);
773                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
774                 if (length != 7)
775                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
776                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
777                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
778                 ptvcursor_current_offset(cursor));
779                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
780                 if (length != 7)
781                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
782                 break;
783         case HOMEPLUG_MID_LWNVM:
784                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Write NVM");
785                 ptvcursor_add(cursor, hf_homeplug_loader_lwnvm, 1, FALSE);
786                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
787                 if (length == 7)
788                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
789                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
790                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
791                 ptvcursor_current_offset(cursor));
792                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
793                 if (length != 7)
794                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
795                 break;
796         case HOMEPLUG_MID_LRESET:
797                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Reset");
798                 ptvcursor_add(cursor, hf_homeplug_loader_lreset, 1, FALSE);
799                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
800                 break;
801         case HOMEPLUG_MID_GMD:
802                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Get Module Data");
803                 ptvcursor_add(cursor, hf_homeplug_loader_gmd, 1, FALSE);
804                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
805                 if (length != 10)
806                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
807                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
808                 ptvcursor_add(cursor, hf_homeplug_loader_module_offset, 4, FALSE);
809                 if (length == 10) {
810                         ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
811                 } else {
812                         ptvcursor_add(cursor, hf_homeplug_loader_module_size, 4, FALSE);
813                         ptvcursor_add(cursor, hf_homeplug_loader_data, length - 13, FALSE);
814                 }
815                 break;
816         case HOMEPLUG_MID_SMD:
817                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Set Module Data");
818                 ptvcursor_add(cursor, hf_homeplug_loader_smd, 1, FALSE);
819                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
820                 if (length == 13)
821                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
822                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
823                 ptvcursor_add(cursor, hf_homeplug_loader_module_offset, 4, FALSE);
824                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
825                 ptvcursor_current_offset(cursor));
826                 if (length != 13) {
827                         ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
828                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
829                 } else
830                         ptvcursor_add(cursor, hf_homeplug_loader_module_size, 4, FALSE);
831                 break;
832         case HOMEPLUG_MID_CM:
833                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Commit Module");
834                 ptvcursor_add(cursor, hf_homeplug_loader_cm, 1, FALSE);
835                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
836                 if (length == 5)
837                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
838                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
839                 break;
840         case HOMEPLUG_MID_LEMD:
841                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Erase Module Data");
842                 ptvcursor_add(cursor, hf_homeplug_loader_lemd, 1, FALSE);
843                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
844                 if (length == 9)
845                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
846                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
847                 break;
848         case HOMEPLUG_MID_LENVMS:
849                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Erase NVM Sectors");
850                 ptvcursor_add(cursor, hf_homeplug_loader_lenvms, 1, FALSE);
851                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
852                 if (length == 9)
853                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
854                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
855                 ptvcursor_add(cursor, hf_homeplug_loader_module_size, 4, FALSE);
856                 break;
857         case HOMEPLUG_MID_GNVMP:
858                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Get NVM Parametes");
859                 ptvcursor_add(cursor, hf_homeplug_loader_gnvmp, 1, FALSE);
860                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
861                 if (length == 17) {
862                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
863                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_type, 4, FALSE);
864                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_pagesize, 4, FALSE);
865                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_blocksize, 4, FALSE);
866                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_memorysize, 4, FALSE);
867                 }
868                 break;
869         case HOMEPLUG_MID_SNVMP:
870                 col_set_str(pinfo->cinfo, COL_INFO, "Loader Set NVM Parametes");
871                 ptvcursor_add(cursor, hf_homeplug_loader_snvmp, 1, FALSE);
872                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
873                 if (length == 17)
874                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
875                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_type, 4, FALSE);
876                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_pagesize, 4, FALSE);
877                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_blocksize, 4, FALSE);
878                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_memorysize, 4, FALSE);
879                 break;
880         default:
881                 ptvcursor_add(cursor, hf_homeplug_loader_mid, 1, FALSE);
882                 break;
883         };
884         ptvcursor_pop_subtree(cursor);
885 }
886
887 /* Dissection of Host Request MME */
888 static void dissect_homeplug_hreq(ptvcursor_t * cursor, packet_info * pinfo)
889 {
890   int mid, length;
891   proto_item * it = NULL;
892
893   if (!ptvcursor_tree(cursor))
894     return;
895
896   it = ptvcursor_add_no_advance(cursor, hf_homeplug_hreq, homeplug_melen, FALSE);
897
898   ptvcursor_push_subtree(cursor, it, ett_homeplug_hreq);
899
900   mid = tvb_get_guint8(ptvcursor_tvbuff(cursor),
901       ptvcursor_current_offset(cursor));
902   length = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
903       ptvcursor_current_offset(cursor) + 1);
904
905   switch(mid) {
906   case HOMEPLUG_MID_GDV:
907     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Device Version");
908     ptvcursor_add(cursor, hf_homeplug_hreq_gdv, 1, FALSE);
909     break;
910   case HOMEPLUG_MID_GFV:
911     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Firmware Version");
912     ptvcursor_add(cursor, hf_homeplug_hreq_gfv, 1, FALSE);
913     break;
914   case HOMEPLUG_MID_GNEK:
915     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Network Encryption Key Request");
916     ptvcursor_add(cursor, hf_homeplug_hreq_gnek, 1, FALSE);
917     break;
918   case HOMEPLUG_MID_GCLBPL:
919     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get/ Clear Local Bridge Proxy List");
920     ptvcursor_add(cursor, hf_homeplug_hreq_gclbpl, 1, FALSE);
921     break;
922   case HOMEPLUG_MID_NVDS:
923     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Non-volatile Database Status");
924     ptvcursor_add(cursor, hf_homeplug_hreq_nvds, 1, FALSE);
925     break;
926   case HOMEPLUG_MID_GRBT:
927     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Remote Bridge Table");
928     ptvcursor_add(cursor, hf_homeplug_hreq_grbt, 1, FALSE);
929     break;
930   case HOMEPLUG_MID_GSLNM:
931     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get/Set Logical Network Mappings");
932     ptvcursor_add(cursor, hf_homeplug_hreq_gslnm, 1, FALSE);
933     break;
934   case HOMEPLUG_MID_GSSS:
935     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get/Set Spectral Scaling");
936     ptvcursor_add(cursor, hf_homeplug_hreq_gsss, 1, FALSE);
937     break;
938   case HOMEPLUG_MID_RSL:
939     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: MAC Reset to Secondary Loader");
940     ptvcursor_add(cursor, hf_homeplug_hreq_rsl, 1, FALSE);
941     break;
942   case HOMEPLUG_MID_RESET:
943     col_set_str(pinfo->cinfo, COL_INFO, "Host Request: MAC Reset");
944     ptvcursor_add(cursor, hf_homeplug_hreq_reset, 1, FALSE);
945     ptvcursor_add(cursor, hf_homeplug_hreq_reset_type, 1, FALSE);
946     if (length == 4)
947       ptvcursor_add(cursor, hf_homeplug_hreq_reset_delay, 2, FALSE);
948     break;
949   default:
950     ptvcursor_add(cursor, hf_homeplug_hreq_mid, 1, FALSE);
951     break;
952   };
953   ptvcursor_pop_subtree(cursor);
954 }
955
956 /* Dissection of Host Response MME */
957 static void dissect_homeplug_hrsp(ptvcursor_t * cursor, packet_info * pinfo)
958 {
959   int mid;
960   proto_item * it = NULL;
961
962   if (!ptvcursor_tree(cursor))
963     return;
964
965   it = ptvcursor_add_no_advance(cursor, hf_homeplug_hrsp, homeplug_melen, FALSE);
966
967   ptvcursor_push_subtree(cursor, it, ett_homeplug_hrsp);
968
969   mid = tvb_get_guint8(ptvcursor_tvbuff(cursor),
970       ptvcursor_current_offset(cursor));
971   switch(mid) {
972   case HOMEPLUG_MID_GDVR:
973     col_set_str(pinfo->cinfo, COL_INFO, "Host Response: Get Device Version");
974     ptvcursor_add(cursor, hf_homeplug_hrsp_gdvr, 1, FALSE);
975     ptvcursor_add(cursor, hf_homeplug_hrsp_version, -1, FALSE);
976     break;
977   case HOMEPLUG_MID_GFVR:
978     col_set_str(pinfo->cinfo, COL_INFO, "Host Response: Get Firmware Version");
979     ptvcursor_add(cursor, hf_homeplug_hrsp_gfvr, 1, FALSE);
980     ptvcursor_add(cursor, hf_homeplug_hrsp_version, -1, FALSE);
981     break;
982   case HOMEPLUG_MID_GNEKR:
983     col_set_str(pinfo->cinfo, COL_INFO, "Get Network Encryption Key");
984     ptvcursor_add(cursor, hf_homeplug_hrsp_gnekr, 1, FALSE);
985     ptvcursor_add(cursor, hf_homeplug_hrsp_gnekr_select, 1, FALSE);
986     ptvcursor_add(cursor, hf_homeplug_hrsp_gnekr_key, 8, FALSE);
987     break;
988   case HOMEPLUG_MID_INVALID:
989     col_set_str(pinfo->cinfo, COL_INFO, "Host Response: Invalid MME");
990     ptvcursor_add(cursor, hf_homeplug_hrsp_invalid, 1, FALSE);
991     break;
992   default:
993     ptvcursor_add(cursor, hf_homeplug_hrsp_mid, 1, FALSE);
994     break;
995   };
996   ptvcursor_pop_subtree(cursor);
997 }
998
999 /* Dissection of Host Tag MME */
1000 static void dissect_homeplug_htag(ptvcursor_t * cursor)
1001 {
1002   proto_item * it = NULL;
1003
1004   if (!ptvcursor_tree(cursor))
1005     return;
1006
1007   it = ptvcursor_add_no_advance(cursor, hf_homeplug_htag, homeplug_melen, FALSE);
1008 }
1009
1010 /* Dissection of the Network Statistics MME */
1011 static void dissect_homeplug_ns(ptvcursor_t * cursor, packet_info * pinfo)
1012 {
1013   guint8 iTone = 0;
1014   guint8 i_buffer = 0;
1015
1016   guint16 ns_bytes40 = 0;
1017   guint64 newt_da = 0;
1018   gboolean extended = (homeplug_melen >= HOMEPLUG_NS_EXT_LEN);
1019   proto_item * ti;
1020
1021   /* Append Basic/Extender specifier to info column */
1022   if (check_col(pinfo->cinfo, COL_INFO))
1023     col_append_str(pinfo->cinfo, COL_INFO, extended ? " Extended" : " Basic");
1024
1025   if (!ptvcursor_tree(cursor)) 
1026     return;
1027
1028   ptvcursor_add_with_subtree(cursor, hf_homeplug_ns, homeplug_melen, FALSE,
1029       ett_homeplug_ns);
1030
1031     ti = proto_tree_add_boolean(ptvcursor_tree(cursor), hf_homeplug_ns_extended,
1032              ptvcursor_tvbuff(cursor), 0, 0, extended);
1033     PROTO_ITEM_SET_GENERATED(ti);
1034
1035     ptvcursor_add_no_advance(cursor, hf_homeplug_ns_netw_ctrl_ac, 1, FALSE);
1036     ptvcursor_add(cursor, hf_homeplug_ns_netw_ctrl_icid, 1, FALSE);
1037
1038     ptvcursor_add_no_advance(cursor, hf_homeplug_ns_bytes40_robo, 2, TRUE);
1039     ns_bytes40 = tvb_get_letohs(ptvcursor_tvbuff(cursor),
1040         ptvcursor_current_offset(cursor));
1041     proto_tree_add_text(ptvcursor_tree(cursor), ptvcursor_tvbuff(cursor), 
1042         ptvcursor_current_offset(cursor), 2, "MHz :  %.3f", (float)(ns_bytes40)/42);
1043     ptvcursor_advance(cursor, 2);
1044
1045     ptvcursor_add(cursor, hf_homeplug_ns_fails_robo, 2, TRUE);
1046     ptvcursor_add(cursor, hf_homeplug_ns_drops_robo, 2, TRUE);
1047
1048     while (iTone < 15) {
1049       newt_da = ((gint64)tvb_get_ntoh24(ptvcursor_tvbuff(cursor),
1050       ptvcursor_current_offset(cursor))) << 24;
1051       newt_da |= tvb_get_ntoh24(ptvcursor_tvbuff(cursor),
1052       ptvcursor_current_offset(cursor)+3);
1053
1054       if (newt_da != HOMEPLUG_ADDR_INEXISTANT) {
1055         ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH,
1056             ett_homeplug_tone, "Tone Map #%d", iTone+1);
1057
1058         ptvcursor_add(cursor, hf_homeplug_ns_netw_da, 6, FALSE);
1059
1060         ptvcursor_add_no_advance(cursor, hf_homeplug_ns_bytes40, 2, TRUE);
1061         ns_bytes40 = tvb_get_letohs(ptvcursor_tvbuff(cursor),
1062             ptvcursor_current_offset(cursor));
1063         proto_tree_add_text(ptvcursor_tree(cursor), ptvcursor_tvbuff(cursor),
1064             ptvcursor_current_offset(cursor), 2, "MHz :  %.3f", (float)(ns_bytes40)/42);
1065         ptvcursor_advance(cursor, 2);
1066
1067         ptvcursor_add(cursor, hf_homeplug_ns_fails, 2, TRUE);
1068         ptvcursor_add(cursor, hf_homeplug_ns_drops, 2, TRUE);
1069
1070         ptvcursor_pop_subtree(cursor);
1071       } else {
1072         proto_tree_add_text(ptvcursor_tree(cursor), ptvcursor_tvbuff(cursor),
1073             ptvcursor_current_offset(cursor), 12, "Tone Map #%d does not exist", iTone+1);
1074       }
1075
1076       iTone++;
1077     }
1078     if (extended) {
1079       while (i_buffer < 6) {
1080         ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH,
1081             ett_homeplug_tx_bfr_state, "TX_BFR_%d_STATE", i_buffer);
1082           ptvcursor_add_no_advance(cursor, hf_homeplug_ns_buf_in_use, 1, FALSE);
1083           ptvcursor_add_no_advance(cursor, hf_homeplug_ns_prio, 1, FALSE);
1084           ptvcursor_add(cursor, hf_homeplug_ns_msdu_len, 1, FALSE);
1085           ptvcursor_add_no_advance(cursor, hf_homeplug_ns_seqn, 1, FALSE);
1086           ptvcursor_add(cursor, hf_homeplug_ns_toneidx, 1, FALSE);
1087         ptvcursor_pop_subtree(cursor);
1088         i_buffer++;
1089       }
1090     }
1091   ptvcursor_pop_subtree(cursor);
1092 }
1093
1094 /* Dissection of the Bridging Characteristics Network MME */
1095 static void dissect_homeplug_bcn(ptvcursor_t * cursor)
1096 {
1097   proto_item * it = NULL;
1098   guint8 i_bridge = 0;
1099   guint8 num_das;
1100   guint8 i_da;
1101   guint8 fbn;
1102
1103   it = ptvcursor_add_no_advance(cursor, hf_homeplug_bcn, homeplug_melen, FALSE);
1104
1105   ptvcursor_push_subtree(cursor, it, ett_homeplug_bcn);
1106     ptvcursor_add_no_advance(cursor, hf_homeplug_bcn_network, 1, FALSE);
1107     ptvcursor_add_no_advance(cursor, hf_homeplug_bcn_return, 1, FALSE);
1108     ptvcursor_add_no_advance(cursor, hf_homeplug_bcn_rsvd, 1, FALSE);
1109     fbn = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor))
1110         & HOMEPLUG_BCN_FBN;
1111     ptvcursor_add(cursor, hf_homeplug_bcn_fbn, 1, FALSE);
1112     while (i_bridge < 2) {
1113       ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH,
1114           ett_homeplug_bridge, "Bridge #%d", fbn + i_bridge);
1115         ptvcursor_add(cursor, hf_homeplug_bcn_brda, 6, FALSE);
1116         num_das = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor));
1117         ptvcursor_add(cursor, hf_homeplug_bcn_bp_das, 1, FALSE);
1118         for (i_da = 0; i_da < num_das; i_da++) {
1119           ptvcursor_add(cursor, hf_homeplug_bcn_bp_da, 6, FALSE);
1120         }
1121       ptvcursor_pop_subtree(cursor);
1122       i_bridge++;
1123     }
1124   ptvcursor_pop_subtree(cursor);
1125 }
1126
1127 /* Dissection of the Bridging Characteristics Local MME */
1128 static void dissect_homeplug_bcl(ptvcursor_t * cursor)
1129 {
1130   proto_item * it = NULL;
1131   guint8 num_das;
1132   guint8 i_da = 0;
1133
1134   it = ptvcursor_add_no_advance(cursor, hf_homeplug_bcl, homeplug_melen, FALSE);
1135
1136   ptvcursor_push_subtree(cursor, it, ett_homeplug_bcl);
1137     ptvcursor_add_no_advance(cursor, hf_homeplug_bcl_network, 1, FALSE);
1138     ptvcursor_add_no_advance(cursor, hf_homeplug_bcl_return, 1, FALSE);
1139     ptvcursor_add(cursor, hf_homeplug_bcl_rsvd, 1, FALSE);
1140
1141     num_das = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor));
1142     ptvcursor_add(cursor, hf_homeplug_bcl_hprox_das, 1, FALSE);
1143
1144     while (i_da < num_das) {
1145       it = ptvcursor_add(cursor, hf_homeplug_bcl_hpbda, 6, FALSE);
1146       i_da++;
1147     }
1148   ptvcursor_pop_subtree(cursor);
1149 }
1150
1151 /* Dissection of the Bridging Characteristics MME */
1152 static void dissect_homeplug_bc(ptvcursor_t * cursor, packet_info * pinfo)
1153 {
1154   gboolean network;
1155
1156   if (!ptvcursor_tree(cursor)) 
1157     return;
1158
1159   network = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor))
1160           & HOMEPLUG_BC_NETWORK;
1161
1162   /* Append Network/Local specifier to info column */
1163   if (check_col(pinfo->cinfo, COL_INFO))
1164     col_append_str(pinfo->cinfo, COL_INFO, network ? " Network" : " Local");
1165
1166   /* Call specific dissector */
1167   if (network)
1168     dissect_homeplug_bcn(cursor);
1169   else
1170     dissect_homeplug_bcl(cursor);
1171 }
1172
1173 /* Dissection of the Set Transmit Characteristics MME */
1174 static void dissect_homeplug_stc(ptvcursor_t * cursor)
1175 {
1176   proto_item * it = NULL;
1177
1178   if (!ptvcursor_tree(cursor)) 
1179     return;
1180
1181   it = ptvcursor_add_no_advance(cursor, hf_homeplug_stc, homeplug_melen, FALSE);
1182
1183   ptvcursor_push_subtree(cursor, it, ett_homeplug_stc);
1184     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_lco, 1, FALSE);
1185     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_encf, 1, FALSE);
1186     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_txprio, 1, FALSE);
1187     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_rexp, 1, FALSE);
1188     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_txcf, 1, FALSE);
1189     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_cftop, 1, FALSE);
1190     ptvcursor_add(cursor, hf_homeplug_stc_rsvd1, 1, FALSE);
1191     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_retry, 1, FALSE);
1192     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_rsvd2, 1, FALSE);
1193     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_dder, 1, FALSE);
1194     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_dur, 1, FALSE);
1195     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_ebp, 1, FALSE);
1196     ptvcursor_add(cursor, hf_homeplug_stc_dees, 1, FALSE);
1197     ptvcursor_add(cursor, hf_homeplug_stc_txeks, 1, FALSE);
1198
1199   ptvcursor_pop_subtree(cursor);
1200
1201   return;
1202 }
1203
1204 /* Dissection of unknown tags */
1205 static void dissect_homeplug_unknown(ptvcursor_t * cursor)
1206 {
1207   ptvcursor_add(cursor, hf_homeplug_data, homeplug_melen, FALSE);
1208 }
1209
1210 static void dissect_homeplug_mme(ptvcursor_t * cursor, packet_info * pinfo)
1211 {
1212   if (check_col(pinfo->cinfo, COL_INFO)) {
1213     col_append_sep_str(pinfo->cinfo, COL_INFO, ", ",
1214         val_to_str(homeplug_metype, homeplug_metype_vals, "Unknown 0x%x"));
1215   }
1216
1217   switch(homeplug_metype) {
1218     case HOMEPLUG_MME_RCE:
1219       dissect_homeplug_rce(cursor);
1220       break;
1221     case HOMEPLUG_MME_CER:
1222       dissect_homeplug_cer(cursor);
1223       break;
1224     case HOMEPLUG_MME_VS:
1225       col_set_str(pinfo->cinfo, COL_INFO, "Vendor Specific");
1226       dissect_homeplug_vs(cursor);
1227       break;
1228     case HOMEPLUG_MME_RBA:
1229       col_set_str(pinfo->cinfo, COL_INFO, "Replace Bridge Address");
1230       dissect_homeplug_rba(cursor);
1231       break;
1232     case HOMEPLUG_MME_SNK:
1233       col_set_str(pinfo->cinfo, COL_INFO, "Set Network Encryption Key");
1234       dissect_homeplug_snk(cursor);
1235       break;
1236     case HOMEPLUG_MME_MWR:
1237       col_set_str(pinfo->cinfo, COL_INFO, "Multicast With Response");
1238       dissect_homeplug_mwr(cursor);
1239       break;
1240     case HOMEPLUG_MME_CNK:
1241       col_set_str(pinfo->cinfo, COL_INFO, "Confirm Network Encryption Key");
1242       dissect_homeplug_cnk(cursor);
1243       break;
1244     case HOMEPLUG_MME_RPS:
1245       dissect_homeplug_rps(cursor);
1246       break;
1247     case HOMEPLUG_MME_PSR:
1248       dissect_homeplug_psr(cursor);
1249       break;
1250     case HOMEPLUG_MME_SLP:
1251       dissect_homeplug_slp(cursor);
1252       break;
1253     case HOMEPLUG_MME_LOADER:
1254       col_set_str(pinfo->cinfo, COL_INFO, "Load Firmware");
1255       dissect_homeplug_loader(cursor, pinfo);
1256       break;
1257     case HOMEPLUG_MME_HREQ:
1258       col_set_str(pinfo->cinfo, COL_INFO, "Host Request");
1259       dissect_homeplug_hreq(cursor, pinfo);
1260       break;
1261     case HOMEPLUG_MME_HRSP:
1262       col_set_str(pinfo->cinfo, COL_INFO, "Host Response");
1263       dissect_homeplug_hrsp(cursor, pinfo);
1264       break;
1265     case HOMEPLUG_MME_HTAG:
1266       col_set_str(pinfo->cinfo, COL_INFO, "Host Tag");
1267       dissect_homeplug_htag(cursor);
1268       break;
1269     case HOMEPLUG_MME_NS:
1270       dissect_homeplug_ns(cursor, pinfo);
1271       break;
1272     case HOMEPLUG_MME_BC:
1273       dissect_homeplug_bc(cursor, pinfo);
1274       break;
1275     case HOMEPLUG_MME_STC:
1276       dissect_homeplug_stc(cursor);
1277       break;
1278     default:
1279       dissect_homeplug_unknown(cursor);
1280       break;
1281   }
1282 }
1283
1284 #define TVB_LEN_GREATEST  1
1285 #define TVB_LEN_UNDEF     0
1286 #define TVB_LEN_SHORTEST -1
1287 static int check_tvb_length(ptvcursor_t *cursor, const gint length)
1288 {
1289   if (!cursor)
1290     return TVB_LEN_UNDEF;
1291
1292   if (tvb_reported_length_remaining(ptvcursor_tvbuff(cursor),
1293                                     ptvcursor_current_offset(cursor)) < length)
1294     return TVB_LEN_SHORTEST;
1295
1296   return TVB_LEN_GREATEST;
1297 }
1298
1299 static void
1300 dissect_homeplug(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
1301 {
1302   proto_item * it= NULL;
1303   proto_tree * homeplug_tree= NULL;
1304   ptvcursor_t * cursor= NULL;
1305
1306   col_set_str(pinfo->cinfo, COL_PROTOCOL, "HomePlug");
1307   /* Clear out stuff in the info column */
1308   col_set_str(pinfo->cinfo, COL_INFO, "MAC Management");
1309
1310   homeplug_offset = 0;
1311
1312   if (tree) {
1313     it = proto_tree_add_item(tree, proto_homeplug, tvb, homeplug_offset, -1, FALSE);
1314     homeplug_tree = proto_item_add_subtree(it, ett_homeplug);
1315     cursor = ptvcursor_new(homeplug_tree, tvb, 0);
1316   }
1317
1318   /*  We do not have enough data to read mctrl field stop the dissection */
1319   if (check_tvb_length(cursor, HOMEPLUG_MCTRL_LEN) != TVB_LEN_SHORTEST) {
1320
1321     dissect_homeplug_mctrl(cursor);
1322
1323     /** homeplug_ne indicates the number of MME entries. This field is fetched
1324      *  from MCTRL. 
1325      */
1326     if ((homeplug_ne > 0)) {
1327       col_clear(pinfo->cinfo, COL_INFO);
1328     }
1329     for (; homeplug_ne > 0; homeplug_ne--) {
1330
1331       /* Check we have enough data in tvb to read MEHDR */
1332       if (check_tvb_length(cursor, HOMEPLUG_MEHDR_LEN) == TVB_LEN_SHORTEST)
1333         break;
1334       dissect_homeplug_mehdr(cursor);
1335
1336       /* Check we have enough data in tvb to read MELEN */
1337       if (check_tvb_length(cursor, HOMEPLUG_MELEN_LEN) == TVB_LEN_SHORTEST)
1338         break;
1339       dissect_homeplug_melen(cursor);
1340
1341       dissect_homeplug_mme(cursor, pinfo);
1342     }
1343   }
1344
1345   if (cursor) 
1346     ptvcursor_free(cursor);
1347 }
1348
1349
1350 void
1351 proto_reg_handoff_homeplug(void)
1352 {
1353   dissector_handle_t homeplug_handle;
1354
1355   homeplug_handle = create_dissector_handle(dissect_homeplug, proto_homeplug);
1356   dissector_add("ethertype", ETHERTYPE_HOMEPLUG, homeplug_handle);
1357 }
1358
1359 void
1360 proto_register_homeplug(void)
1361 {
1362
1363   static hf_register_info hf[] = {
1364     /* MAC Control Field */
1365     { &hf_homeplug_mctrl,
1366       { "MAC Control Field", "homeplug.mctrl",
1367       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1368     },
1369
1370     { &hf_homeplug_mctrl_reserved,
1371       { "Reserved", "homeplug.mctrl.rsvd",
1372       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_MCTRL_RSVD, NULL, HFILL }
1373     },
1374
1375     { &hf_homeplug_mctrl_ne,
1376       { "Number of MAC Data Entries", "homeplug.mctrl.ne",
1377       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_MCTRL_NE, NULL, HFILL }
1378     },
1379
1380     /* MAC Entry Header */
1381     { &hf_homeplug_mehdr,
1382       { "MAC Management Entry Header", "homeplug.mehdr",
1383       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1384     },
1385
1386     { &hf_homeplug_mehdr_mev,
1387       { "MAC Entry Version", "homeplug.mehdr.mev",
1388       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_MEHDR_MEV, NULL, HFILL }
1389     },
1390
1391     { &hf_homeplug_mehdr_metype,
1392       { "MAC Entry Type", "homeplug.mehdr.metype",
1393       FT_UINT8, BASE_HEX, VALS(homeplug_metype_vals), HOMEPLUG_MEHDR_METYPE, NULL, HFILL }
1394     },
1395
1396     /* MAC Entry Len */
1397     { &hf_homeplug_melen,
1398       { "MAC Management Entry Length", "homeplug.melen",
1399       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1400     },
1401
1402     /* MAC Management Entry */
1403     { &hf_homeplug_mme,
1404       { "MAC Management Entry Data", "homeplug.mmentry",
1405       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1406     },
1407
1408     /* Request Channel Estimation */
1409     { &hf_homeplug_rce,
1410       { "Request Channel Estimation", "homeplug.rce",
1411       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1412     },
1413
1414     { &hf_homeplug_rce_cev,
1415       { "Channel Estimation Version", "homeplug.rce.cev",
1416       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_RCE_CEV, NULL, HFILL }
1417     },
1418
1419     { &hf_homeplug_rce_rsvd,
1420       { "Reserved", "homeplug.rce.rsvd",
1421       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_RCE_RSVD, NULL, HFILL }
1422     },
1423
1424     /* Channel Estimation Response */
1425     { &hf_homeplug_cer,
1426       { "Channel Estimation Response", "homeplug.cer",
1427       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1428     },
1429
1430     { &hf_homeplug_cer_cerv,
1431       { "Channel Estimation Response Version", "homeplug.cer.cerv",
1432       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_CERV, NULL, HFILL }
1433     },
1434
1435     { &hf_homeplug_cer_rsvd1,
1436       { "Reserved", "homeplug.cer.rsvd1",
1437       FT_UINT16, BASE_DEC, NULL, HOMEPLUG_CER_RSVD, NULL, HFILL }
1438     },
1439
1440     { &hf_homeplug_cer_rxtmi,
1441       { "Receive Tone Map Index", "homeplug.cer.rxtmi",
1442       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_RXTMI, NULL, HFILL }
1443     },
1444
1445     /* TODO must append vt[79-0] */
1446
1447     { &hf_homeplug_cer_vt,
1448       {"Valid Tone Flags", "homeplug.cer.vt",
1449       FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
1450     },
1451
1452     { &hf_homeplug_cer_rate,
1453       { "FEC Rate", "homeplug.cer.rate",
1454       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_RATE, NULL, HFILL }
1455     },
1456
1457     { &hf_homeplug_cer_bp,
1458       { "Bridge Proxy", "homeplug.cer.bp",
1459       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_BP, NULL, HFILL }
1460     },
1461
1462     { &hf_homeplug_cer_mod,
1463       { "Modulation Method", "homeplug.cer.mod",
1464       FT_UINT8, BASE_DEC, VALS(homeplug_cer_mod_vals), HOMEPLUG_CER_MOD_MASK,
1465       NULL, HFILL }
1466     },
1467
1468     { &hf_homeplug_cer_vt11,
1469       { "Valid Tone Flags [83-80]", "homeplug.cer.vt11",
1470       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_VT11, NULL, HFILL }
1471     },
1472
1473     { &hf_homeplug_cer_rsvd2,
1474       { "Reserved", "homeplug.cer.rsvd2",
1475       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_RSVD2, NULL, HFILL }
1476     },
1477
1478     { &hf_homeplug_cer_nbdas,
1479       { "Number Bridged Destination Addresses", "homeplug.cer.nbdas",
1480       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_NBDAS, NULL, HFILL }
1481     },
1482
1483     { &hf_homeplug_cer_bda,
1484       { "Bridged Destination Address", "homeplug.cer.bda",
1485       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1486     },
1487
1488     /* Replace Bridge Address */
1489     { &hf_homeplug_rba,
1490       { "Replace Bridge Address", "homeplug.rba",
1491       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1492     },
1493
1494     /* Vendor Specific */
1495     { &hf_homeplug_vs,
1496       { "Vendor Specific", "homeplug.vs",
1497       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1498     },
1499
1500     { &hf_homeplug_vs_dir,
1501       { "Direction", "homeplug.vs.dir",
1502       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_VS_DIR, NULL, HFILL }
1503     },
1504
1505     { &hf_homeplug_vs_mid,
1506       { "Message ID", "homeplug.vs.mid",
1507       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_VS_MID, NULL, HFILL }
1508     },
1509
1510     { &hf_homeplug_vs_oui,
1511       { "OUI", "homeplug.vs.oui",
1512       FT_UINT24, BASE_HEX, NULL, 0x0, NULL, HFILL }
1513     },
1514
1515     /* Set Network Encryption Key */
1516     { &hf_homeplug_snk,
1517       { "Set Network Encryption Key", "homeplug.snk",
1518       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1519     },
1520
1521     { &hf_homeplug_snk_eks,
1522       { "Encryption Key Select", "homeplug.snk.eks",
1523       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1524     },
1525
1526     { &hf_homeplug_snk_nek,
1527       { "Network Encryption Key", "homeplug.snk.nek",
1528       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1529     },
1530
1531   /* Multicast With Response */
1532     { &hf_homeplug_mwr,
1533       { "Multicast With Response", "homeplug.mwr",
1534       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1535     },
1536
1537     /* Confirm Network Encryption Key */
1538     { &hf_homeplug_cnk,
1539       { "Confirm Network Encryption Key", "homeplug.cnk",
1540       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1541     },
1542
1543     /* Host Tag */
1544     { &hf_homeplug_htag,
1545       { "Host Tag", "homeplug.htag",
1546       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1547     },
1548
1549     /* Request Parameters and Statistics */
1550     { &hf_homeplug_rps,
1551       { "Request Parameters and Statistics", "homeplug.rps",
1552       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1553     },
1554
1555     /* Parameters and Statistics Response */
1556     { &hf_homeplug_psr,
1557       { "Parameters and Statistics Response", "homeplug.psr",
1558       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1559     },
1560
1561     { &hf_homeplug_psr_txack,
1562       { "Transmit ACK Counter", "homeplug.psr.txack",
1563       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1564     },
1565
1566     { &hf_homeplug_psr_txnack,
1567       { "Transmit NACK Counter", "homeplug.psr.txnack",
1568       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1569     },
1570
1571     { &hf_homeplug_psr_txfail,
1572       { "Transmit FAIL Counter", "homeplug.psr.txfail",
1573       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1574     },
1575
1576     { &hf_homeplug_psr_txcloss,
1577       { "Transmit Contention Loss Counter", "homeplug.psr.txcloss",
1578       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1579     },
1580
1581     { &hf_homeplug_psr_txcoll,
1582       { "Transmit Collision Counter", "homeplug.psr.txcoll",
1583       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1584     },
1585
1586     { &hf_homeplug_psr_txca3lat,
1587       { "Transmit CA3 Latency Counter", "homeplug.psr.txca3lat",
1588       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1589     },
1590
1591     { &hf_homeplug_psr_txca2lat,
1592       { "Transmit CA2 Latency Counter", "homeplug.psr.txca2lat",
1593       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1594     },
1595     { &hf_homeplug_psr_txca1lat,
1596       { "Transmit CA1 Latency Counter", "homeplug.psr.txca1lat",
1597       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1598     },
1599     { &hf_homeplug_psr_txca0lat,
1600       { "Transmit CA0 Latency Counter", "homeplug.psr.txca0lat",
1601       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1602     },
1603
1604     { &hf_homeplug_psr_rxbp40,
1605       { "Receive Cumulative Bytes per 40-symbol", "homeplug.psr.rxbp40",
1606       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1607     },
1608
1609     /* Set Local Parameters */
1610     { &hf_homeplug_slp,
1611       { "Set Local Parameters", "homeplug.slp",
1612       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1613     },
1614
1615     { &hf_homeplug_slp_ma,
1616       { "MAC Address", "homeplug.slp.ma",
1617       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1618     },
1619
1620     /* LOAD */
1621     { &hf_homeplug_loader,
1622       { "Loader", "homeplug.leader",
1623       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1624     },
1625
1626     { &hf_homeplug_loader_mid,
1627       { "Message ID", "homeplug.loader.mid",
1628       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1629     },
1630
1631     { &hf_homeplug_loader_length,
1632       { "Length", "homeplug.loader.length",
1633       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1634     },
1635
1636     { &hf_homeplug_loader_status,
1637       { "Status", "homeplug.loader.status",
1638       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1639     },
1640
1641     { &hf_homeplug_loader_version,
1642       { "Version", "homeplug.loader.version",
1643       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1644     },
1645
1646     { &hf_homeplug_loader_gdfv,
1647       { "Get Device/Firmware Version", "homeplug.loader.gdfv",
1648       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1649     },
1650
1651     { &hf_homeplug_loader_lsf,
1652       { "Start Firmware", "homeplug.loader.lsf",
1653       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1654     },
1655
1656     { &hf_homeplug_loader_lwm,
1657       { "Write Memory", "homeplug.loader.lwm",
1658       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1659     },
1660
1661     { &hf_homeplug_loader_lrm,
1662       { "Read Memory", "homeplug.loader.lrm",
1663       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1664     },
1665
1666     { &hf_homeplug_loader_lrnvm,
1667       { "Read NVM Data", "homeplug.loader.lrnvm",
1668       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1669     },
1670
1671     { &hf_homeplug_loader_lwnvm,
1672       { "Write NVM Data", "homeplug.loader.lrnvm",
1673       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1674     },
1675
1676     { &hf_homeplug_loader_lreset,
1677       { "Reset", "homeplug.loader.mid",
1678       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1679     },
1680
1681     { &hf_homeplug_loader_gmd,
1682       { "Get Module Data", "homeplug.loader.gmd",
1683       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1684     },
1685
1686     { &hf_homeplug_loader_smd,
1687       { "Set Module Data", "homeplug.loader.smd",
1688       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1689     },
1690
1691     { &hf_homeplug_loader_module_id,
1692       { "Module ID", "homeplug.loader.module.id",
1693       FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
1694     },
1695
1696     { &hf_homeplug_loader_module_offset,
1697       { "Offset", "homeplug.loader.module.offset",
1698       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1699     },
1700
1701     { &hf_homeplug_loader_module_size,
1702       { "Module size", "homeplug.loader.module.size",
1703       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1704     },
1705
1706     { &hf_homeplug_loader_data_length,
1707       { "Data length", "homeplug.loader.data.length",
1708       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1709     },
1710
1711     { &hf_homeplug_loader_data_address,
1712       { "Address", "homeplug.loader.data.address",
1713       FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
1714     },
1715
1716     { &hf_homeplug_loader_data,
1717       { "Data", "homeplug.loader.data",
1718       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1719     },
1720
1721     { &hf_homeplug_loader_cm,
1722       { "Commit Modules", "homeplug.loader.cm",
1723       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1724     },
1725
1726     { &hf_homeplug_loader_lemd,
1727       { "Erase Module Data", "homeplug.loader.emd",
1728       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1729     },
1730
1731     { &hf_homeplug_loader_lenvms,
1732       { "Erase NVM Sectors", "homeplug.loader.lenvms",
1733       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1734     },
1735
1736     { &hf_homeplug_loader_gnvmp,
1737       { "Get NVM Parameters", "homeplug.loader.nvmp",
1738       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1739     },
1740
1741     { &hf_homeplug_loader_nvmp_type,
1742       { "Type", "homeplug.loader.nvmp.type",
1743       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1744     },
1745
1746     { &hf_homeplug_loader_nvmp_pagesize,
1747       { "Page Size", "homeplug.loader.nvmp.pagesize",
1748       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1749     },
1750
1751     { &hf_homeplug_loader_nvmp_blocksize,
1752       { "Block Size", "homeplug.loader.nvmp.blocksize",
1753       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1754     },
1755
1756     { &hf_homeplug_loader_nvmp_memorysize,
1757       { "Memory Size", "homeplug.loader.nvmp.memorysize",
1758       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1759     },
1760
1761     { &hf_homeplug_loader_snvmp,
1762       { "Set NVM Parameters", "homeplug.loader.nvmp",
1763       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1764     },
1765
1766     /* Host Request */
1767     { &hf_homeplug_hreq,
1768       { "Host Request", "homeplug.hreq",
1769       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1770     },
1771
1772     { &hf_homeplug_hreq_mid,
1773       { "Message ID", "homeplug.hreq.mid",
1774       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1775     },
1776
1777     { &hf_homeplug_hreq_gdv,
1778       { "Get Device Version", "homeplug.hreq.gdv",
1779       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1780     },
1781
1782     { &hf_homeplug_hreq_gfv,
1783       { "Get Firmware Version", "homeplug.hreq.gfv",
1784       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1785     },
1786
1787     { &hf_homeplug_hreq_gnek,
1788       { "Get Network Encryption Key", "homeplug.hreq.gnek",
1789       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1790     },
1791
1792     { &hf_homeplug_hreq_gclbpl,
1793       { "Get/Clear Local Bridge Proxy List", "homeplug.hreq.gclbpl",
1794       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1795     },
1796
1797     { &hf_homeplug_hreq_nvds,
1798       { "Non-volatile Database Status", "homeplug.hreq.nvds",
1799       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1800     },
1801
1802     { &hf_homeplug_hreq_grbt,
1803       { "Get Remote Bridge Table", "homeplug.hreq.grbt",
1804       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1805     },
1806
1807     { &hf_homeplug_hreq_gslnm,
1808       { "Get/Set Logical Network Mapping", "homeplug.hreq.gslnm",
1809       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1810     },
1811
1812     { &hf_homeplug_hreq_gsss,
1813       { "Get/Set Spectral Scaling", "homeplug.hreq.gsss",
1814       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1815     },
1816
1817     { &hf_homeplug_hreq_rsl,
1818       { "Reset Secondary Loader", "homeplug.hreq.rsl",
1819       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1820     },
1821
1822     { &hf_homeplug_hreq_reset,
1823       { "Reset", "homeplug.hreq.reset",
1824       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1825     },
1826
1827     { &hf_homeplug_hreq_reset_type,
1828       { "Type", "homeplug.hreq.reset.type",
1829       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1830     },
1831
1832     { &hf_homeplug_hreq_reset_delay,
1833       { "Delay", "homeplug.hreq.reset.delay",
1834       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1835     },
1836
1837     /* Host Response */
1838     { &hf_homeplug_hrsp,
1839       { "Host Response", "homeplug.hrsp",
1840       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1841     },
1842
1843     { &hf_homeplug_hrsp_mid,
1844       { "Message ID", "homeplug.hrsp.mid",
1845       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1846     },
1847
1848     { &hf_homeplug_hrsp_gdvr,
1849       { "Get Device Version", "homeplug.hrsp.gdvr",
1850       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1851     },
1852
1853     { &hf_homeplug_hrsp_gfvr,
1854       { "Get Firmware Version", "homeplug.hrsp.gfvr",
1855       FT_UINT8, BASE_DEC, NULL, 0x0, "Get Firmwave Version", HFILL }
1856     },
1857
1858     { &hf_homeplug_hrsp_gnekr,
1859       { "Get Network Encryption Key", "homeplug.hrsp.gnekr",
1860       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1861     },
1862
1863     { &hf_homeplug_hrsp_gnekr_select,
1864       { "Key Select", "homeplug.hrsp.gnekr.select",
1865       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1866     },
1867
1868     { &hf_homeplug_hrsp_gnekr_key,
1869       { "Key", "homeplug.hrsp.gnekr.key",
1870       FT_UINT64, BASE_HEX, NULL, 0x0, NULL, HFILL }
1871     },
1872
1873     { &hf_homeplug_hrsp_invalid,
1874       { "Invalid", "homeplug.hrsp.invalid",
1875       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1876     },
1877
1878     { &hf_homeplug_hrsp_version,
1879       { "Version", "homeplug.hrsp.version",
1880       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1881     },
1882
1883     /* Network Statistics */
1884     { &hf_homeplug_ns,
1885       { "Network Statistics", "homeplug.ns",
1886       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1887     },
1888
1889     { &hf_homeplug_ns_extended,
1890       { "Network Statistics is Extended", "homeplug.ns.extended",
1891       FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Network Statistics is Extended (MELEN >= 199)", HFILL }
1892     },
1893
1894     { &hf_homeplug_ns_netw_ctrl_ac,
1895       { "Action Control", "homeplug.ns.ac",
1896       FT_BOOLEAN, 8, TFS(&homeplug_ns_ac_vals), HOMEPLUG_NS_AC, NULL, HFILL }
1897     },
1898
1899     { &hf_homeplug_ns_netw_ctrl_icid,
1900       { "IC_ID", "homeplug.ns.icid",
1901       FT_UINT8, BASE_HEX|BASE_RANGE_STRING, RVALS(homeplug_ns_icid_vals), HOMEPLUG_NS_ICID, NULL, HFILL }
1902     },
1903
1904     { &hf_homeplug_ns_bytes40_robo,
1905       { "Bytes in 40 symbols in ROBO", "homeplug.ns.bytes40_robo",
1906       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1907     },
1908
1909     { &hf_homeplug_ns_fails_robo,
1910       { "Fails Received in ROBO", "homeplug.ns.fails_robo",
1911       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1912     },
1913
1914     { &hf_homeplug_ns_drops_robo,
1915       { "Frame Drops in ROBO", "homeplug.ns.drops_robo",
1916       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1917     },
1918
1919     { &hf_homeplug_ns_netw_da,
1920       { "Address of Network DA", "homeplug.ns.netw_da",
1921       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1922     },
1923
1924     { &hf_homeplug_ns_bytes40,
1925       { "Bytes in 40 symbols", "homeplug.ns.bytes40",
1926       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1927     },
1928
1929     { &hf_homeplug_ns_fails,
1930       { "Fails Received", "homeplug.ns.fails",
1931       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1932     },
1933
1934     { &hf_homeplug_ns_drops,
1935       { "Frame Drops", "homeplug.ns.drops",
1936       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1937     },
1938
1939     /* ... Extended */
1940     { &hf_homeplug_ns_tx_bfr_state,
1941       { "Transmit Buffer State", "homeplug.ns.tx_bfr_state",
1942       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1943     },
1944
1945     { &hf_homeplug_ns_buf_in_use,
1946       { "Buffer in use", "homeplug.ns.buf_in_use",
1947       FT_BOOLEAN, 8, TFS(&homeplug_ns_buf_in_use_vals), HOMEPLUG_NS_BUF_IN_USE,
1948       "Buffer in use (1) or Available (0)", HFILL }
1949     },
1950
1951     { &hf_homeplug_ns_prio,
1952       { "Priority", "homeplug.ns.prio",
1953       FT_UINT8, BASE_DEC, VALS(homeplug_txprio_vals), HOMEPLUG_NS_PRIO,
1954       NULL, HFILL }
1955     },
1956
1957     { &hf_homeplug_ns_msdu_len,
1958       { "MSDU Length", "homeplug.ns.msdu_len",
1959       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_NS_MSDU_LEN, NULL, HFILL }
1960     },
1961
1962     { &hf_homeplug_ns_seqn,
1963       { "Sequence Number", "homeplug.ns.seqn",
1964       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_NS_SEQN, NULL, HFILL }
1965     },
1966
1967     { &hf_homeplug_ns_toneidx,
1968       { "Transmit tone map index", "homeplug.ns.toneidx",
1969       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_NS_TONEIDX,
1970       "Maps to the 16 statistics occurring earlier in this MME", HFILL }
1971     },
1972
1973     /* Bridging Characteristics Network */
1974     { &hf_homeplug_bcn,
1975       { "Bridging Characteristics Network", "homeplug.bcn",
1976       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1977     },
1978
1979     { &hf_homeplug_bcn_network,
1980       { "Network", "homeplug.bcn.network",
1981       FT_BOOLEAN, 8, TFS(&homeplug_bc_network_vals), HOMEPLUG_BC_NETWORK,
1982       "Local (0) or Network Bridge (1) Information", HFILL }
1983     },
1984
1985     { &hf_homeplug_bcn_return,
1986       { "Return/Set", "homeplug.bcn.return",
1987       FT_BOOLEAN, 8, TFS(&homeplug_bc_return_vals), HOMEPLUG_BC_RETURN,
1988       "From host: Return (1) or set bridging characteristics (0)", HFILL }
1989     },
1990
1991     { &hf_homeplug_bcn_rsvd,
1992       { "Reserved", "homeplug.bcn.rsvd",
1993       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_BCN_RSVD, NULL, HFILL }
1994     },
1995
1996     { &hf_homeplug_bcn_fbn,
1997       { "First Bridge Number", "homeplug.bcn.fbn",
1998       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_BCN_FBN, NULL, HFILL }
1999     },
2000
2001     { &hf_homeplug_bcn_brda,
2002       { "Address of Bridge", "homeplug.bcn.brda",
2003       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
2004     },
2005
2006     { &hf_homeplug_bcn_bp_das,
2007       { "Number of bridge proxied DAs", "homeplug.bcn.bp_das",
2008       FT_UINT8, BASE_DEC, NULL, 0x0,
2009       "Number of bridge proxied DAs supported", HFILL }
2010     },
2011
2012     { &hf_homeplug_bcn_bp_da,
2013       { "Bridged DA", "homeplug.bcn.bp_da",
2014       FT_ETHER, BASE_NONE, NULL, 0x0, "Bridged Destination Address", HFILL }
2015     },
2016
2017     /* Bridging Characteristics Local */
2018     { &hf_homeplug_bcl,
2019       { "Bridging Characteristics Local", "homeplug.bcl",
2020       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
2021     },
2022
2023     { &hf_homeplug_bcl_network,
2024       { "Network/Local", "homeplug.bcl.network",
2025       FT_BOOLEAN, 8, TFS(&homeplug_bc_network_vals), HOMEPLUG_BC_NETWORK,
2026       "Local (0) or Network Bridge (1) Information", HFILL }
2027     },
2028
2029     { &hf_homeplug_bcl_return,
2030       { "Return/Set", "homeplug.bcl.return",
2031       FT_BOOLEAN, 8, TFS(&homeplug_bc_return_vals), HOMEPLUG_BC_RETURN,
2032       "From host: Return (1) or set bridging characteristics (0)", HFILL }
2033     },
2034
2035     { &hf_homeplug_bcl_rsvd,
2036       { "Reserved", "homeplug.bcl.rsvd",
2037       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_BCL_RSVD, NULL, HFILL }
2038     },
2039
2040     { &hf_homeplug_bcl_hprox_das,
2041       { "Number of host proxied DAs", "homeplug.bcl.hprox_das",
2042       FT_UINT8, BASE_DEC, NULL, 0x0,
2043       "Number of host proxied DAs supported by the bridge application", HFILL }
2044     },
2045
2046     { &hf_homeplug_bcl_hpbda,
2047       { "Host Proxied DA", "homeplug.bcl.hpbda",
2048       FT_ETHER, BASE_NONE, NULL, 0x0, "Host Proxied Bridged Destination Address", HFILL }
2049     },
2050
2051     /* Set Transmit Characteristics */
2052     { &hf_homeplug_stc,
2053       { "Set Transmit Characteristics", "homeplug.stc",
2054       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
2055     },
2056
2057     { &hf_homeplug_stc_lco,
2058       { "Local Consumption Only", "homeplug.stc.lco",
2059       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_LCO,
2060       "Do not transmit subsequent frames to medium", HFILL }
2061     },
2062
2063     { &hf_homeplug_stc_encf,
2064       { "Encryption Flag", "homeplug.stc.encf",
2065       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_ENCF, "Encrypt subsequent frames", HFILL }
2066     },
2067
2068     { &hf_homeplug_stc_txprio,
2069       { "Transmit Priority", "homeplug.stc.txprio",
2070       FT_UINT8, BASE_DEC, VALS(homeplug_txprio_vals), HOMEPLUG_STC_TXPRIO,
2071       NULL, HFILL }
2072     },
2073
2074     { &hf_homeplug_stc_rexp,
2075       { "Response Expected", "homeplug.stc.rexp",
2076       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_REXP,
2077       "Mark subsequent frames to receive response", HFILL }
2078     },
2079
2080     { &hf_homeplug_stc_txcf,
2081       { "Transmit Contention Free", "homeplug.stc.txcf",
2082       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_TXCF,
2083       "Mark subsequently transmitted frames as contention free", HFILL }
2084     },
2085
2086     { &hf_homeplug_stc_cftop,
2087       { "Contention Free Transmit Override Priority", "homeplug.stc.cftop",
2088       FT_BOOLEAN, 8, TFS(&homeplug_stc_cftop_vals), HOMEPLUG_STC_CFTOP,
2089       "Transmit subsequent contention free frames with CA2/CA3 priority", HFILL }
2090     },
2091
2092     { &hf_homeplug_stc_rsvd1,
2093       { "Reserved", "homeplug.stc.rsvd1",
2094       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_STC_RSVD1, NULL, HFILL }
2095     },
2096
2097     { &hf_homeplug_stc_retry,
2098       { "Retry Control", "homeplug.stc.retry",
2099       FT_UINT8, BASE_DEC, VALS(homeplug_stc_retry_vals), HOMEPLUG_STC_RETRY,
2100       NULL, HFILL }
2101     },
2102
2103     { &hf_homeplug_stc_rsvd2,
2104       { "Reserved", "homeplug.stc.rsvd2",
2105       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_STC_RSVD2, NULL, HFILL }
2106     },
2107
2108     { &hf_homeplug_stc_dder,
2109       { "Disable Default Encryption Receive", "homeplug.stc.dder",
2110       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_DDER, NULL, HFILL }
2111     },
2112
2113     { &hf_homeplug_stc_dur,
2114       { "Disable Unencrypted Receive", "homeplug.stc.dur",
2115       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_DUR, NULL, HFILL }
2116     },
2117
2118     { &hf_homeplug_stc_ebp,
2119       { "INT51X1 (Host/DTE Option) Enable Backpressure", "homeplug.stc.ebp",
2120       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_EBP,
2121       NULL, HFILL }
2122     },
2123
2124     { &hf_homeplug_stc_dees,
2125       { "Disable EEPROM Save", "homeplug.stc.dees",
2126       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_DEES, NULL, HFILL }
2127     },
2128
2129     { &hf_homeplug_stc_txeks,
2130       { "EKS to be used for encryption", "homeplug.stc.txeks",
2131       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
2132     },
2133
2134     /* Undecoded data */
2135     { &hf_homeplug_data,
2136       { "Data", "homeplug.data",
2137       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
2138     }
2139   };
2140
2141   /* Setup protocol subtree array */
2142   static gint *ett[] = {
2143     &ett_homeplug,
2144     &ett_homeplug_mctrl,
2145     &ett_homeplug_mehdr,
2146     &ett_homeplug_rce,
2147     &ett_homeplug_cer,
2148     &ett_homeplug_vs,
2149     &ett_homeplug_vs_mid,
2150     &ett_homeplug_snk,
2151     &ett_homeplug_rps,
2152     &ett_homeplug_psr,
2153     &ett_homeplug_slp,
2154     &ett_homeplug_loader,
2155     &ett_homeplug_hreq,
2156     &ett_homeplug_hrsp,
2157     &ett_homeplug_ns,
2158     &ett_homeplug_tx_bfr_state,
2159     &ett_homeplug_tone,
2160     &ett_homeplug_bcn,
2161     &ett_homeplug_bridge,
2162     &ett_homeplug_bcl,
2163     &ett_homeplug_stc
2164   };
2165
2166   proto_homeplug = proto_register_protocol("HomePlug protocol", "HomePlug", "homeplug");
2167
2168   proto_register_field_array(proto_homeplug, hf, array_length(hf));
2169
2170   proto_register_subtree_array(ett, array_length(ett));
2171 }