a0049cdf35f8f06981fdde8c50a79eb9ef8ce331
[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                 if (check_col(pinfo->cinfo, COL_INFO)) {
731                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Get Firmware Version");
732                 }
733                 ptvcursor_add(cursor, hf_homeplug_loader_gdfv, 1, FALSE);
734                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
735                 if (length != 0) {
736                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
737                         ptvcursor_add(cursor, hf_homeplug_loader_version, -1, FALSE);
738                 }
739                 break;
740         case HOMEPLUG_MID_LSF:
741                 if (check_col(pinfo->cinfo, COL_INFO)) {
742                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Start Firmware");
743                 }
744                 ptvcursor_add(cursor, hf_homeplug_loader_lsf, 1, FALSE);
745                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
746                 break;
747         case HOMEPLUG_MID_LWM:
748                 if (check_col(pinfo->cinfo, COL_INFO)) {
749                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Write Memory");
750                 }
751                 ptvcursor_add(cursor, hf_homeplug_loader_lwm, 1, FALSE);
752                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
753                 if (length == 7)
754                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
755                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
756
757                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
758                 ptvcursor_current_offset(cursor));
759                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
760                 if (length != 7)
761                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
762                 break;
763         case HOMEPLUG_MID_LRM:
764                 if (check_col(pinfo->cinfo, COL_INFO)) {
765                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Read Memory");
766                 }
767                 ptvcursor_add(cursor, hf_homeplug_loader_lrm, 1, FALSE);
768                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
769                 if (length != 6)
770                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
771                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
772                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
773                 ptvcursor_current_offset(cursor));
774                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
775                 if (length != 6)
776                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
777                 break;
778         case HOMEPLUG_MID_LRNVM:
779                 if (check_col(pinfo->cinfo, COL_INFO)) {
780                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Read NVM");
781                 }
782                 ptvcursor_add(cursor, hf_homeplug_loader_lrnvm, 1, FALSE);
783                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
784                 if (length != 7)
785                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
786                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
787                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
788                 ptvcursor_current_offset(cursor));
789                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
790                 if (length != 7)
791                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
792                 break;
793         case HOMEPLUG_MID_LWNVM:
794                 if (check_col(pinfo->cinfo, COL_INFO)) {
795                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Write NVM");
796                 }
797                 ptvcursor_add(cursor, hf_homeplug_loader_lwnvm, 1, FALSE);
798                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
799                 if (length == 7)
800                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
801                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
802                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
803                 ptvcursor_current_offset(cursor));
804                 ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
805                 if (length != 7)
806                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
807                 break;
808         case HOMEPLUG_MID_LRESET:
809                 if (check_col(pinfo->cinfo, COL_INFO)) {
810                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Reset");
811                 }
812                 ptvcursor_add(cursor, hf_homeplug_loader_lreset, 1, FALSE);
813                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
814                 break;
815         case HOMEPLUG_MID_GMD:
816                 if (check_col(pinfo->cinfo, COL_INFO)) {
817                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Get Module Data");
818                 }
819                 ptvcursor_add(cursor, hf_homeplug_loader_gmd, 1, FALSE);
820                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
821                 if (length != 10)
822                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
823                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
824                 ptvcursor_add(cursor, hf_homeplug_loader_module_offset, 4, FALSE);
825                 if (length == 10) {
826                         ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
827                 } else {
828                         ptvcursor_add(cursor, hf_homeplug_loader_module_size, 4, FALSE);
829                         ptvcursor_add(cursor, hf_homeplug_loader_data, length - 13, FALSE);
830                 }
831                 break;
832         case HOMEPLUG_MID_SMD:
833                 if (check_col(pinfo->cinfo, COL_INFO)) {
834                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Set Module Data");
835                 }
836                 ptvcursor_add(cursor, hf_homeplug_loader_smd, 1, FALSE);
837                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
838                 if (length == 13)
839                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
840                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
841                 ptvcursor_add(cursor, hf_homeplug_loader_module_offset, 4, FALSE);
842                 dlen = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
843                 ptvcursor_current_offset(cursor));
844                 if (length != 13) {
845                         ptvcursor_add(cursor, hf_homeplug_loader_data_length, 2, FALSE);
846                         ptvcursor_add(cursor, hf_homeplug_loader_data, dlen, FALSE);
847                 } else
848                         ptvcursor_add(cursor, hf_homeplug_loader_module_size, 4, FALSE);
849                 break;
850         case HOMEPLUG_MID_CM:
851                 if (check_col(pinfo->cinfo, COL_INFO)) {
852                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Commit Module");
853                 }
854                 ptvcursor_add(cursor, hf_homeplug_loader_cm, 1, FALSE);
855                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
856                 if (length == 5)
857                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
858                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
859                 break;
860         case HOMEPLUG_MID_LEMD:
861                 if (check_col(pinfo->cinfo, COL_INFO)) {
862                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Erase Module Data");
863                 }
864                 ptvcursor_add(cursor, hf_homeplug_loader_lemd, 1, FALSE);
865                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
866                 if (length == 9)
867                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
868                 ptvcursor_add(cursor, hf_homeplug_loader_module_id, 4, FALSE);
869                 break;
870         case HOMEPLUG_MID_LENVMS:
871                 if (check_col(pinfo->cinfo, COL_INFO)) {
872                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Erase NVM Sectors");
873                 }
874                 ptvcursor_add(cursor, hf_homeplug_loader_lenvms, 1, FALSE);
875                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
876                 if (length == 9)
877                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
878                 ptvcursor_add(cursor, hf_homeplug_loader_data_address, 4, FALSE);
879                 ptvcursor_add(cursor, hf_homeplug_loader_module_size, 4, FALSE);
880                 break;
881         case HOMEPLUG_MID_GNVMP:
882                 if (check_col(pinfo->cinfo, COL_INFO)) {
883                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Get NVM Parametes");
884                 }
885                 ptvcursor_add(cursor, hf_homeplug_loader_gnvmp, 1, FALSE);
886                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
887                 if (length == 17) {
888                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
889                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_type, 4, FALSE);
890                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_pagesize, 4, FALSE);
891                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_blocksize, 4, FALSE);
892                         ptvcursor_add(cursor, hf_homeplug_loader_nvmp_memorysize, 4, FALSE);
893                 }
894                 break;
895         case HOMEPLUG_MID_SNVMP:
896                 if (check_col(pinfo->cinfo, COL_INFO)) {
897                         col_set_str(pinfo->cinfo, COL_INFO, "Loader Set NVM Parametes");
898                 }
899                 ptvcursor_add(cursor, hf_homeplug_loader_snvmp, 1, FALSE);
900                 ptvcursor_add(cursor, hf_homeplug_loader_length, 2, FALSE);
901                 if (length == 17)
902                         ptvcursor_add(cursor, hf_homeplug_loader_status, 1, FALSE);
903                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_type, 4, FALSE);
904                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_pagesize, 4, FALSE);
905                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_blocksize, 4, FALSE);
906                 ptvcursor_add(cursor, hf_homeplug_loader_nvmp_memorysize, 4, FALSE);
907                 break;
908         default:
909                 ptvcursor_add(cursor, hf_homeplug_loader_mid, 1, FALSE);
910                 break;
911         };
912         ptvcursor_pop_subtree(cursor);
913 }
914
915 /* Dissection of Host Request MME */
916 static void dissect_homeplug_hreq(ptvcursor_t * cursor, packet_info * pinfo)
917 {
918   int mid, length;
919   proto_item * it = NULL;
920
921   if (!ptvcursor_tree(cursor))
922     return;
923
924   it = ptvcursor_add_no_advance(cursor, hf_homeplug_hreq, homeplug_melen, FALSE);
925
926   ptvcursor_push_subtree(cursor, it, ett_homeplug_hreq);
927
928   mid = tvb_get_guint8(ptvcursor_tvbuff(cursor),
929       ptvcursor_current_offset(cursor));
930   length = tvb_get_ntohs(ptvcursor_tvbuff(cursor),
931       ptvcursor_current_offset(cursor) + 1);
932
933   switch(mid) {
934   case HOMEPLUG_MID_GDV:
935     if (check_col(pinfo->cinfo, COL_INFO)) {
936         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Device Version");
937     }
938     ptvcursor_add(cursor, hf_homeplug_hreq_gdv, 1, FALSE);
939     break;
940   case HOMEPLUG_MID_GFV:
941     if (check_col(pinfo->cinfo, COL_INFO)) {
942         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Firmware Version");
943     }
944     ptvcursor_add(cursor, hf_homeplug_hreq_gfv, 1, FALSE);
945     break;
946   case HOMEPLUG_MID_GNEK:
947     if (check_col(pinfo->cinfo, COL_INFO)) {
948         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Network Encryption Key Request");
949     }
950     ptvcursor_add(cursor, hf_homeplug_hreq_gnek, 1, FALSE);
951     break;
952   case HOMEPLUG_MID_GCLBPL:
953     if (check_col(pinfo->cinfo, COL_INFO)) {
954         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get/ Clear Local Bridge Proxy List");
955     }
956     ptvcursor_add(cursor, hf_homeplug_hreq_gclbpl, 1, FALSE);
957     break;
958   case HOMEPLUG_MID_NVDS:
959     if (check_col(pinfo->cinfo, COL_INFO)) {
960         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Non-volatile Database Status");
961     }
962     ptvcursor_add(cursor, hf_homeplug_hreq_nvds, 1, FALSE);
963     break;
964   case HOMEPLUG_MID_GRBT:
965     if (check_col(pinfo->cinfo, COL_INFO)) {
966         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get Remote Bridge Table");
967     }
968     ptvcursor_add(cursor, hf_homeplug_hreq_grbt, 1, FALSE);
969     break;
970   case HOMEPLUG_MID_GSLNM:
971     if (check_col(pinfo->cinfo, COL_INFO)) {
972         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get/Set Logical Network Mappings");
973     }
974     ptvcursor_add(cursor, hf_homeplug_hreq_gslnm, 1, FALSE);
975     break;
976   case HOMEPLUG_MID_GSSS:
977     if (check_col(pinfo->cinfo, COL_INFO)) {
978         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: Get/Set Spectral Scaling");
979     }
980     ptvcursor_add(cursor, hf_homeplug_hreq_gsss, 1, FALSE);
981     break;
982   case HOMEPLUG_MID_RSL:
983     if (check_col(pinfo->cinfo, COL_INFO)) {
984         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: MAC Reset to Secondary Loader");
985     }
986     ptvcursor_add(cursor, hf_homeplug_hreq_rsl, 1, FALSE);
987     break;
988   case HOMEPLUG_MID_RESET:
989     if (check_col(pinfo->cinfo, COL_INFO)) {
990         col_set_str(pinfo->cinfo, COL_INFO, "Host Request: MAC Reset");
991     }
992     ptvcursor_add(cursor, hf_homeplug_hreq_reset, 1, FALSE);
993     ptvcursor_add(cursor, hf_homeplug_hreq_reset_type, 1, FALSE);
994     if (length == 4)
995       ptvcursor_add(cursor, hf_homeplug_hreq_reset_delay, 2, FALSE);
996     break;
997   default:
998     ptvcursor_add(cursor, hf_homeplug_hreq_mid, 1, FALSE);
999     break;
1000   };
1001   ptvcursor_pop_subtree(cursor);
1002 }
1003
1004 /* Dissection of Host Response MME */
1005 static void dissect_homeplug_hrsp(ptvcursor_t * cursor, packet_info * pinfo)
1006 {
1007   int mid;
1008   proto_item * it = NULL;
1009
1010   if (!ptvcursor_tree(cursor))
1011     return;
1012
1013   it = ptvcursor_add_no_advance(cursor, hf_homeplug_hrsp, homeplug_melen, FALSE);
1014
1015   ptvcursor_push_subtree(cursor, it, ett_homeplug_hrsp);
1016
1017   mid = tvb_get_guint8(ptvcursor_tvbuff(cursor),
1018       ptvcursor_current_offset(cursor));
1019   switch(mid) {
1020   case HOMEPLUG_MID_GDVR:
1021     if (check_col(pinfo->cinfo, COL_INFO)) {
1022         col_set_str(pinfo->cinfo, COL_INFO, "Host Response: Get Device Version");
1023     }
1024     ptvcursor_add(cursor, hf_homeplug_hrsp_gdvr, 1, FALSE);
1025     ptvcursor_add(cursor, hf_homeplug_hrsp_version, -1, FALSE);
1026     break;
1027   case HOMEPLUG_MID_GFVR:
1028     if (check_col(pinfo->cinfo, COL_INFO)) {
1029         col_set_str(pinfo->cinfo, COL_INFO, "Host Response: Get Firmware Version");
1030     }
1031     ptvcursor_add(cursor, hf_homeplug_hrsp_gfvr, 1, FALSE);
1032     ptvcursor_add(cursor, hf_homeplug_hrsp_version, -1, FALSE);
1033     break;
1034   case HOMEPLUG_MID_GNEKR:
1035     if (check_col(pinfo->cinfo, COL_INFO)) {
1036         col_set_str(pinfo->cinfo, COL_INFO, "Get Network Encryption Key");
1037     }
1038     ptvcursor_add(cursor, hf_homeplug_hrsp_gnekr, 1, FALSE);
1039     ptvcursor_add(cursor, hf_homeplug_hrsp_gnekr_select, 1, FALSE);
1040     ptvcursor_add(cursor, hf_homeplug_hrsp_gnekr_key, 8, FALSE);
1041     break;
1042   case HOMEPLUG_MID_INVALID:
1043     if (check_col(pinfo->cinfo, COL_INFO)) {
1044         col_set_str(pinfo->cinfo, COL_INFO, "Host Response: Invalid MME");
1045     }
1046     ptvcursor_add(cursor, hf_homeplug_hrsp_invalid, 1, FALSE);
1047     break;
1048   default:
1049     ptvcursor_add(cursor, hf_homeplug_hrsp_mid, 1, FALSE);
1050     break;
1051   };
1052   ptvcursor_pop_subtree(cursor);
1053 }
1054
1055 /* Dissection of Host Tag MME */
1056 static void dissect_homeplug_htag(ptvcursor_t * cursor)
1057 {
1058   proto_item * it = NULL;
1059
1060   if (!ptvcursor_tree(cursor))
1061     return;
1062
1063   it = ptvcursor_add_no_advance(cursor, hf_homeplug_htag, homeplug_melen, FALSE);
1064 }
1065
1066 /* Dissection of the Network Statistics MME */
1067 static void dissect_homeplug_ns(ptvcursor_t * cursor, packet_info * pinfo)
1068 {
1069   guint8 iTone = 0;
1070   guint8 i_buffer = 0;
1071
1072   guint16 ns_bytes40 = 0;
1073   guint64 newt_da = 0;
1074   gboolean extended = (homeplug_melen >= HOMEPLUG_NS_EXT_LEN);
1075   proto_item * ti;
1076
1077   /* Append Basic/Extender specifier to info column */
1078   if (check_col(pinfo->cinfo, COL_INFO))
1079     col_append_str(pinfo->cinfo, COL_INFO, extended ? " Extended" : " Basic");
1080
1081   if (!ptvcursor_tree(cursor)) 
1082     return;
1083
1084   ptvcursor_add_with_subtree(cursor, hf_homeplug_ns, homeplug_melen, FALSE,
1085       ett_homeplug_ns);
1086
1087     ti = proto_tree_add_boolean(ptvcursor_tree(cursor), hf_homeplug_ns_extended,
1088              ptvcursor_tvbuff(cursor), 0, 0, extended);
1089     PROTO_ITEM_SET_GENERATED(ti);
1090
1091     ptvcursor_add_no_advance(cursor, hf_homeplug_ns_netw_ctrl_ac, 1, FALSE);
1092     ptvcursor_add(cursor, hf_homeplug_ns_netw_ctrl_icid, 1, FALSE);
1093
1094     ptvcursor_add_no_advance(cursor, hf_homeplug_ns_bytes40_robo, 2, TRUE);
1095     ns_bytes40 = tvb_get_letohs(ptvcursor_tvbuff(cursor),
1096         ptvcursor_current_offset(cursor));
1097     proto_tree_add_text(ptvcursor_tree(cursor), ptvcursor_tvbuff(cursor), 
1098         ptvcursor_current_offset(cursor), 2, "MHz :  %.3f", (float)(ns_bytes40)/42);
1099     ptvcursor_advance(cursor, 2);
1100
1101     ptvcursor_add(cursor, hf_homeplug_ns_fails_robo, 2, TRUE);
1102     ptvcursor_add(cursor, hf_homeplug_ns_drops_robo, 2, TRUE);
1103
1104     while (iTone < 15) {
1105       newt_da = ((gint64)tvb_get_ntoh24(ptvcursor_tvbuff(cursor),
1106       ptvcursor_current_offset(cursor))) << 24;
1107       newt_da |= tvb_get_ntoh24(ptvcursor_tvbuff(cursor),
1108       ptvcursor_current_offset(cursor)+3);
1109
1110       if (newt_da != HOMEPLUG_ADDR_INEXISTANT) {
1111         ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH,
1112             ett_homeplug_tone, "Tone Map #%d", iTone+1);
1113
1114         ptvcursor_add(cursor, hf_homeplug_ns_netw_da, 6, FALSE);
1115
1116         ptvcursor_add_no_advance(cursor, hf_homeplug_ns_bytes40, 2, TRUE);
1117         ns_bytes40 = tvb_get_letohs(ptvcursor_tvbuff(cursor),
1118             ptvcursor_current_offset(cursor));
1119         proto_tree_add_text(ptvcursor_tree(cursor), ptvcursor_tvbuff(cursor),
1120             ptvcursor_current_offset(cursor), 2, "MHz :  %.3f", (float)(ns_bytes40)/42);
1121         ptvcursor_advance(cursor, 2);
1122
1123         ptvcursor_add(cursor, hf_homeplug_ns_fails, 2, TRUE);
1124         ptvcursor_add(cursor, hf_homeplug_ns_drops, 2, TRUE);
1125
1126         ptvcursor_pop_subtree(cursor);
1127       } else {
1128         proto_tree_add_text(ptvcursor_tree(cursor), ptvcursor_tvbuff(cursor),
1129             ptvcursor_current_offset(cursor), 12, "Tone Map #%d does not exist", iTone+1);
1130       }
1131
1132       iTone++;
1133     }
1134     if (extended) {
1135       while (i_buffer < 6) {
1136         ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH,
1137             ett_homeplug_tx_bfr_state, "TX_BFR_%d_STATE", i_buffer);
1138           ptvcursor_add_no_advance(cursor, hf_homeplug_ns_buf_in_use, 1, FALSE);
1139           ptvcursor_add_no_advance(cursor, hf_homeplug_ns_prio, 1, FALSE);
1140           ptvcursor_add(cursor, hf_homeplug_ns_msdu_len, 1, FALSE);
1141           ptvcursor_add_no_advance(cursor, hf_homeplug_ns_seqn, 1, FALSE);
1142           ptvcursor_add(cursor, hf_homeplug_ns_toneidx, 1, FALSE);
1143         ptvcursor_pop_subtree(cursor);
1144         i_buffer++;
1145       }
1146     }
1147   ptvcursor_pop_subtree(cursor);
1148 }
1149
1150 /* Dissection of the Bridging Characteristics Network MME */
1151 static void dissect_homeplug_bcn(ptvcursor_t * cursor)
1152 {
1153   proto_item * it = NULL;
1154   guint8 i_bridge = 0;
1155   guint8 num_das;
1156   guint8 i_da;
1157   guint8 fbn;
1158
1159   it = ptvcursor_add_no_advance(cursor, hf_homeplug_bcn, homeplug_melen, FALSE);
1160
1161   ptvcursor_push_subtree(cursor, it, ett_homeplug_bcn);
1162     ptvcursor_add_no_advance(cursor, hf_homeplug_bcn_network, 1, FALSE);
1163     ptvcursor_add_no_advance(cursor, hf_homeplug_bcn_return, 1, FALSE);
1164     ptvcursor_add_no_advance(cursor, hf_homeplug_bcn_rsvd, 1, FALSE);
1165     fbn = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor))
1166         & HOMEPLUG_BCN_FBN;
1167     ptvcursor_add(cursor, hf_homeplug_bcn_fbn, 1, FALSE);
1168     while (i_bridge < 2) {
1169       ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH,
1170           ett_homeplug_bridge, "Bridge #%d", fbn + i_bridge);
1171         ptvcursor_add(cursor, hf_homeplug_bcn_brda, 6, FALSE);
1172         num_das = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor));
1173         ptvcursor_add(cursor, hf_homeplug_bcn_bp_das, 1, FALSE);
1174         for (i_da = 0; i_da < num_das; i_da++) {
1175           ptvcursor_add(cursor, hf_homeplug_bcn_bp_da, 6, FALSE);
1176         }
1177       ptvcursor_pop_subtree(cursor);
1178       i_bridge++;
1179     }
1180   ptvcursor_pop_subtree(cursor);
1181 }
1182
1183 /* Dissection of the Bridging Characteristics Local MME */
1184 static void dissect_homeplug_bcl(ptvcursor_t * cursor)
1185 {
1186   proto_item * it = NULL;
1187   guint8 num_das;
1188   guint8 i_da = 0;
1189
1190   it = ptvcursor_add_no_advance(cursor, hf_homeplug_bcl, homeplug_melen, FALSE);
1191
1192   ptvcursor_push_subtree(cursor, it, ett_homeplug_bcl);
1193     ptvcursor_add_no_advance(cursor, hf_homeplug_bcl_network, 1, FALSE);
1194     ptvcursor_add_no_advance(cursor, hf_homeplug_bcl_return, 1, FALSE);
1195     ptvcursor_add(cursor, hf_homeplug_bcl_rsvd, 1, FALSE);
1196
1197     num_das = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor));
1198     ptvcursor_add(cursor, hf_homeplug_bcl_hprox_das, 1, FALSE);
1199
1200     while (i_da < num_das) {
1201       it = ptvcursor_add(cursor, hf_homeplug_bcl_hpbda, 6, FALSE);
1202       i_da++;
1203     }
1204   ptvcursor_pop_subtree(cursor);
1205 }
1206
1207 /* Dissection of the Bridging Characteristics MME */
1208 static void dissect_homeplug_bc(ptvcursor_t * cursor, packet_info * pinfo)
1209 {
1210   gboolean network;
1211
1212   if (!ptvcursor_tree(cursor)) 
1213     return;
1214
1215   network = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor))
1216           & HOMEPLUG_BC_NETWORK;
1217
1218   /* Append Network/Local specifier to info column */
1219   if (check_col(pinfo->cinfo, COL_INFO))
1220     col_append_str(pinfo->cinfo, COL_INFO, network ? " Network" : " Local");
1221
1222   /* Call specific dissector */
1223   if (network)
1224     dissect_homeplug_bcn(cursor);
1225   else
1226     dissect_homeplug_bcl(cursor);
1227 }
1228
1229 /* Dissection of the Set Transmit Characteristics MME */
1230 static void dissect_homeplug_stc(ptvcursor_t * cursor)
1231 {
1232   proto_item * it = NULL;
1233
1234   if (!ptvcursor_tree(cursor)) 
1235     return;
1236
1237   it = ptvcursor_add_no_advance(cursor, hf_homeplug_stc, homeplug_melen, FALSE);
1238
1239   ptvcursor_push_subtree(cursor, it, ett_homeplug_stc);
1240     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_lco, 1, FALSE);
1241     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_encf, 1, FALSE);
1242     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_txprio, 1, FALSE);
1243     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_rexp, 1, FALSE);
1244     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_txcf, 1, FALSE);
1245     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_cftop, 1, FALSE);
1246     ptvcursor_add(cursor, hf_homeplug_stc_rsvd1, 1, FALSE);
1247     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_retry, 1, FALSE);
1248     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_rsvd2, 1, FALSE);
1249     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_dder, 1, FALSE);
1250     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_dur, 1, FALSE);
1251     ptvcursor_add_no_advance(cursor, hf_homeplug_stc_ebp, 1, FALSE);
1252     ptvcursor_add(cursor, hf_homeplug_stc_dees, 1, FALSE);
1253     ptvcursor_add(cursor, hf_homeplug_stc_txeks, 1, FALSE);
1254
1255   ptvcursor_pop_subtree(cursor);
1256
1257   return;
1258 }
1259
1260 /* Dissection of unknown tags */
1261 static void dissect_homeplug_unknown(ptvcursor_t * cursor)
1262 {
1263   ptvcursor_add(cursor, hf_homeplug_data, homeplug_melen, FALSE);
1264 }
1265
1266 static void dissect_homeplug_mme(ptvcursor_t * cursor, packet_info * pinfo)
1267 {
1268   if (check_col(pinfo->cinfo, COL_INFO)) {
1269     col_append_sep_str(pinfo->cinfo, COL_INFO, ", ",
1270         val_to_str(homeplug_metype, homeplug_metype_vals, "Unknown 0x%x"));
1271   }
1272
1273   switch(homeplug_metype) {
1274     case HOMEPLUG_MME_RCE:
1275       dissect_homeplug_rce(cursor);
1276       break;
1277     case HOMEPLUG_MME_CER:
1278       dissect_homeplug_cer(cursor);
1279       break;
1280     case HOMEPLUG_MME_VS:
1281       if (check_col(pinfo->cinfo, COL_INFO)) {
1282         col_set_str(pinfo->cinfo, COL_INFO, "Vendor Specific");
1283       }
1284       dissect_homeplug_vs(cursor);
1285       break;
1286     case HOMEPLUG_MME_RBA:
1287       if (check_col(pinfo->cinfo, COL_INFO)) {
1288         col_set_str(pinfo->cinfo, COL_INFO, "Replace Bridge Address");
1289       }
1290       dissect_homeplug_rba(cursor);
1291       break;
1292     case HOMEPLUG_MME_SNK:
1293       if (check_col(pinfo->cinfo, COL_INFO)) {
1294         col_set_str(pinfo->cinfo, COL_INFO, "Set Network Encryption Key");
1295       }
1296       dissect_homeplug_snk(cursor);
1297       break;
1298     case HOMEPLUG_MME_MWR:
1299       if (check_col(pinfo->cinfo, COL_INFO)) {
1300         col_set_str(pinfo->cinfo, COL_INFO, "Multicast With Response");
1301       }
1302       dissect_homeplug_mwr(cursor);
1303       break;
1304     case HOMEPLUG_MME_CNK:
1305       if (check_col(pinfo->cinfo, COL_INFO)) {
1306         col_set_str(pinfo->cinfo, COL_INFO, "Confirm Network Encryption Key");
1307       }
1308       dissect_homeplug_cnk(cursor);
1309       break;
1310     case HOMEPLUG_MME_RPS:
1311       dissect_homeplug_rps(cursor);
1312       break;
1313     case HOMEPLUG_MME_PSR:
1314       dissect_homeplug_psr(cursor);
1315       break;
1316     case HOMEPLUG_MME_SLP:
1317       dissect_homeplug_slp(cursor);
1318       break;
1319     case HOMEPLUG_MME_LOADER:
1320       if (check_col(pinfo->cinfo, COL_INFO)) {
1321         col_set_str(pinfo->cinfo, COL_INFO, "Load Firmware");
1322       }
1323       dissect_homeplug_loader(cursor, pinfo);
1324       break;
1325     case HOMEPLUG_MME_HREQ:
1326       if (check_col(pinfo->cinfo, COL_INFO)) {
1327         col_set_str(pinfo->cinfo, COL_INFO, "Host Request");
1328       }
1329       dissect_homeplug_hreq(cursor, pinfo);
1330       break;
1331     case HOMEPLUG_MME_HRSP:
1332       if (check_col(pinfo->cinfo, COL_INFO)) {
1333         col_set_str(pinfo->cinfo, COL_INFO, "Host Response");
1334       }
1335       dissect_homeplug_hrsp(cursor, pinfo);
1336       break;
1337     case HOMEPLUG_MME_HTAG:
1338       if (check_col(pinfo->cinfo, COL_INFO)) {
1339         col_set_str(pinfo->cinfo, COL_INFO, "Host Tag");
1340       }
1341       dissect_homeplug_htag(cursor);
1342       break;
1343     case HOMEPLUG_MME_NS:
1344       dissect_homeplug_ns(cursor, pinfo);
1345       break;
1346     case HOMEPLUG_MME_BC:
1347       dissect_homeplug_bc(cursor, pinfo);
1348       break;
1349     case HOMEPLUG_MME_STC:
1350       dissect_homeplug_stc(cursor);
1351       break;
1352     default:
1353       dissect_homeplug_unknown(cursor);
1354       break;
1355   }
1356 }
1357
1358 #define TVB_LEN_GREATEST  1
1359 #define TVB_LEN_UNDEF     0
1360 #define TVB_LEN_SHORTEST -1
1361 static int check_tvb_length(ptvcursor_t *cursor, const gint length)
1362 {
1363   if (!cursor)
1364     return TVB_LEN_UNDEF;
1365
1366   if (tvb_reported_length_remaining(ptvcursor_tvbuff(cursor),
1367                                     ptvcursor_current_offset(cursor)) < length)
1368     return TVB_LEN_SHORTEST;
1369
1370   return TVB_LEN_GREATEST;
1371 }
1372
1373 static void
1374 dissect_homeplug(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
1375 {
1376   proto_item * it= NULL;
1377   proto_tree * homeplug_tree= NULL;
1378   ptvcursor_t * cursor= NULL;
1379
1380   col_set_str(pinfo->cinfo, COL_PROTOCOL, "HomePlug");
1381   /* Clear out stuff in the info column */
1382   if (check_col(pinfo->cinfo, COL_INFO)) {
1383     col_set_str(pinfo->cinfo, COL_INFO, "MAC Management");
1384   }
1385
1386   homeplug_offset = 0;
1387
1388   if (tree) {
1389     it = proto_tree_add_item(tree, proto_homeplug, tvb, homeplug_offset, -1, FALSE);
1390     homeplug_tree = proto_item_add_subtree(it, ett_homeplug);
1391     cursor = ptvcursor_new(homeplug_tree, tvb, 0);
1392   }
1393
1394   /*  We do not have enough data to read mctrl field stop the dissection */
1395   if (check_tvb_length(cursor, HOMEPLUG_MCTRL_LEN) != TVB_LEN_SHORTEST) {
1396
1397     dissect_homeplug_mctrl(cursor);
1398
1399     /** homeplug_ne indicates the number of MME entries. This field is fetched
1400      *  from MCTRL. 
1401      */
1402     if ((homeplug_ne > 0) && check_col(pinfo->cinfo, COL_INFO)) {
1403       col_clear(pinfo->cinfo, COL_INFO);
1404     }
1405     for (; homeplug_ne > 0; homeplug_ne--) {
1406
1407       /* Check we have enough data in tvb to read MEHDR */
1408       if (check_tvb_length(cursor, HOMEPLUG_MEHDR_LEN) == TVB_LEN_SHORTEST)
1409         break;
1410       dissect_homeplug_mehdr(cursor);
1411
1412       /* Check we have enough data in tvb to read MELEN */
1413       if (check_tvb_length(cursor, HOMEPLUG_MELEN_LEN) == TVB_LEN_SHORTEST)
1414         break;
1415       dissect_homeplug_melen(cursor);
1416
1417       dissect_homeplug_mme(cursor, pinfo);
1418     }
1419   }
1420
1421   if (cursor) 
1422     ptvcursor_free(cursor);
1423 }
1424
1425
1426 void
1427 proto_reg_handoff_homeplug(void)
1428 {
1429   dissector_handle_t homeplug_handle;
1430
1431   homeplug_handle = create_dissector_handle(dissect_homeplug, proto_homeplug);
1432   dissector_add("ethertype", ETHERTYPE_HOMEPLUG, homeplug_handle);
1433 }
1434
1435 void
1436 proto_register_homeplug(void)
1437 {
1438
1439   static hf_register_info hf[] = {
1440     /* MAC Control Field */
1441     { &hf_homeplug_mctrl,
1442       { "MAC Control Field", "homeplug.mctrl",
1443       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1444     },
1445
1446     { &hf_homeplug_mctrl_reserved,
1447       { "Reserved", "homeplug.mctrl.rsvd",
1448       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_MCTRL_RSVD, NULL, HFILL }
1449     },
1450
1451     { &hf_homeplug_mctrl_ne,
1452       { "Number of MAC Data Entries", "homeplug.mctrl.ne",
1453       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_MCTRL_NE, NULL, HFILL }
1454     },
1455
1456     /* MAC Entry Header */
1457     { &hf_homeplug_mehdr,
1458       { "MAC Management Entry Header", "homeplug.mehdr",
1459       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1460     },
1461
1462     { &hf_homeplug_mehdr_mev,
1463       { "MAC Entry Version", "homeplug.mehdr.mev",
1464       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_MEHDR_MEV, NULL, HFILL }
1465     },
1466
1467     { &hf_homeplug_mehdr_metype,
1468       { "MAC Entry Type", "homeplug.mehdr.metype",
1469       FT_UINT8, BASE_HEX, VALS(homeplug_metype_vals), HOMEPLUG_MEHDR_METYPE, NULL, HFILL }
1470     },
1471
1472     /* MAC Entry Len */
1473     { &hf_homeplug_melen,
1474       { "MAC Management Entry Length", "homeplug.melen",
1475       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1476     },
1477
1478     /* MAC Management Entry */
1479     { &hf_homeplug_mme,
1480       { "MAC Management Entry Data", "homeplug.mmentry",
1481       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1482     },
1483
1484     /* Request Channel Estimation */
1485     { &hf_homeplug_rce,
1486       { "Request Channel Estimation", "homeplug.rce",
1487       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1488     },
1489
1490     { &hf_homeplug_rce_cev,
1491       { "Channel Estimation Version", "homeplug.rce.cev",
1492       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_RCE_CEV, NULL, HFILL }
1493     },
1494
1495     { &hf_homeplug_rce_rsvd,
1496       { "Reserved", "homeplug.rce.rsvd",
1497       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_RCE_RSVD, NULL, HFILL }
1498     },
1499
1500     /* Channel Estimation Response */
1501     { &hf_homeplug_cer,
1502       { "Channel Estimation Response", "homeplug.cer",
1503       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1504     },
1505
1506     { &hf_homeplug_cer_cerv,
1507       { "Channel Estimation Response Version", "homeplug.cer.cerv",
1508       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_CERV, NULL, HFILL }
1509     },
1510
1511     { &hf_homeplug_cer_rsvd1,
1512       { "Reserved", "homeplug.cer.rsvd1",
1513       FT_UINT16, BASE_DEC, NULL, HOMEPLUG_CER_RSVD, NULL, HFILL }
1514     },
1515
1516     { &hf_homeplug_cer_rxtmi,
1517       { "Receive Tone Map Index", "homeplug.cer.rxtmi",
1518       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_RXTMI, NULL, HFILL }
1519     },
1520
1521     /* TODO must append vt[79-0] */
1522
1523     { &hf_homeplug_cer_vt,
1524       {"Valid Tone Flags", "homeplug.cer.vt",
1525       FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
1526     },
1527
1528     { &hf_homeplug_cer_rate,
1529       { "FEC Rate", "homeplug.cer.rate",
1530       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_RATE, NULL, HFILL }
1531     },
1532
1533     { &hf_homeplug_cer_bp,
1534       { "Bridge Proxy", "homeplug.cer.bp",
1535       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_BP, NULL, HFILL }
1536     },
1537
1538     { &hf_homeplug_cer_mod,
1539       { "Modulation Method", "homeplug.cer.mod",
1540       FT_UINT8, BASE_DEC, VALS(homeplug_cer_mod_vals), HOMEPLUG_CER_MOD_MASK,
1541       NULL, HFILL }
1542     },
1543
1544     { &hf_homeplug_cer_vt11,
1545       { "Valid Tone Flags [83-80]", "homeplug.cer.vt11",
1546       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_VT11, NULL, HFILL }
1547     },
1548
1549     { &hf_homeplug_cer_rsvd2,
1550       { "Reserved", "homeplug.cer.rsvd2",
1551       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_RSVD2, NULL, HFILL }
1552     },
1553
1554     { &hf_homeplug_cer_nbdas,
1555       { "Number Bridged Destination Addresses", "homeplug.cer.nbdas",
1556       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_CER_NBDAS, NULL, HFILL }
1557     },
1558
1559     { &hf_homeplug_cer_bda,
1560       { "Bridged Destination Address", "homeplug.cer.bda",
1561       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1562     },
1563
1564     /* Replace Bridge Address */
1565     { &hf_homeplug_rba,
1566       { "Replace Bridge Address", "homeplug.rba",
1567       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1568     },
1569
1570     /* Vendor Specific */
1571     { &hf_homeplug_vs,
1572       { "Vendor Specific", "homeplug.vs",
1573       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1574     },
1575
1576     { &hf_homeplug_vs_dir,
1577       { "Direction", "homeplug.vs.dir",
1578       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_VS_DIR, NULL, HFILL }
1579     },
1580
1581     { &hf_homeplug_vs_mid,
1582       { "Message ID", "homeplug.vs.mid",
1583       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_VS_MID, NULL, HFILL }
1584     },
1585
1586     { &hf_homeplug_vs_oui,
1587       { "OUI", "homeplug.vs.oui",
1588       FT_UINT24, BASE_HEX, NULL, 0x0, NULL, HFILL }
1589     },
1590
1591     /* Set Network Encryption Key */
1592     { &hf_homeplug_snk,
1593       { "Set Network Encryption Key", "homeplug.snk",
1594       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1595     },
1596
1597     { &hf_homeplug_snk_eks,
1598       { "Encryption Key Select", "homeplug.snk.eks",
1599       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1600     },
1601
1602     { &hf_homeplug_snk_nek,
1603       { "Network Encryption Key", "homeplug.snk.nek",
1604       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1605     },
1606
1607   /* Multicast With Response */
1608     { &hf_homeplug_mwr,
1609       { "Multicast With Response", "homeplug.mwr",
1610       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1611     },
1612
1613     /* Confirm Network Encryption Key */
1614     { &hf_homeplug_cnk,
1615       { "Confirm Network Encryption Key", "homeplug.cnk",
1616       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1617     },
1618
1619     /* Host Tag */
1620     { &hf_homeplug_htag,
1621       { "Host Tag", "homeplug.htag",
1622       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1623     },
1624
1625     /* Request Parameters and Statistics */
1626     { &hf_homeplug_rps,
1627       { "Request Parameters and Statistics", "homeplug.rps",
1628       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1629     },
1630
1631     /* Parameters and Statistics Response */
1632     { &hf_homeplug_psr,
1633       { "Parameters and Statistics Response", "homeplug.psr",
1634       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1635     },
1636
1637     { &hf_homeplug_psr_txack,
1638       { "Transmit ACK Counter", "homeplug.psr.txack",
1639       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1640     },
1641
1642     { &hf_homeplug_psr_txnack,
1643       { "Transmit NACK Counter", "homeplug.psr.txnack",
1644       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1645     },
1646
1647     { &hf_homeplug_psr_txfail,
1648       { "Transmit FAIL Counter", "homeplug.psr.txfail",
1649       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1650     },
1651
1652     { &hf_homeplug_psr_txcloss,
1653       { "Transmit Contention Loss Counter", "homeplug.psr.txcloss",
1654       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1655     },
1656
1657     { &hf_homeplug_psr_txcoll,
1658       { "Transmit Collision Counter", "homeplug.psr.txcoll",
1659       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1660     },
1661
1662     { &hf_homeplug_psr_txca3lat,
1663       { "Transmit CA3 Latency Counter", "homeplug.psr.txca3lat",
1664       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1665     },
1666
1667     { &hf_homeplug_psr_txca2lat,
1668       { "Transmit CA2 Latency Counter", "homeplug.psr.txca2lat",
1669       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1670     },
1671     { &hf_homeplug_psr_txca1lat,
1672       { "Transmit CA1 Latency Counter", "homeplug.psr.txca1lat",
1673       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1674     },
1675     { &hf_homeplug_psr_txca0lat,
1676       { "Transmit CA0 Latency Counter", "homeplug.psr.txca0lat",
1677       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1678     },
1679
1680     { &hf_homeplug_psr_rxbp40,
1681       { "Receive Cumulative Bytes per 40-symbol", "homeplug.psr.rxbp40",
1682       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1683     },
1684
1685     /* Set Local Parameters */
1686     { &hf_homeplug_slp,
1687       { "Set Local Parameters", "homeplug.slp",
1688       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1689     },
1690
1691     { &hf_homeplug_slp_ma,
1692       { "MAC Address", "homeplug.slp.ma",
1693       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1694     },
1695
1696     /* LOAD */
1697     { &hf_homeplug_loader,
1698       { "Loader", "homeplug.leader",
1699       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1700     },
1701
1702     { &hf_homeplug_loader_mid,
1703       { "Message ID", "homeplug.loader.mid",
1704       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1705     },
1706
1707     { &hf_homeplug_loader_length,
1708       { "Length", "homeplug.loader.length",
1709       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1710     },
1711
1712     { &hf_homeplug_loader_status,
1713       { "Status", "homeplug.loader.status",
1714       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1715     },
1716
1717     { &hf_homeplug_loader_version,
1718       { "Version", "homeplug.loader.version",
1719       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1720     },
1721
1722     { &hf_homeplug_loader_gdfv,
1723       { "Get Device/Firmware Version", "homeplug.loader.gdfv",
1724       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1725     },
1726
1727     { &hf_homeplug_loader_lsf,
1728       { "Start Firmware", "homeplug.loader.lsf",
1729       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1730     },
1731
1732     { &hf_homeplug_loader_lwm,
1733       { "Write Memory", "homeplug.loader.lwm",
1734       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1735     },
1736
1737     { &hf_homeplug_loader_lrm,
1738       { "Read Memory", "homeplug.loader.lrm",
1739       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1740     },
1741
1742     { &hf_homeplug_loader_lrnvm,
1743       { "Read NVM Data", "homeplug.loader.lrnvm",
1744       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1745     },
1746
1747     { &hf_homeplug_loader_lwnvm,
1748       { "Write NVM Data", "homeplug.loader.lrnvm",
1749       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1750     },
1751
1752     { &hf_homeplug_loader_lreset,
1753       { "Reset", "homeplug.loader.mid",
1754       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1755     },
1756
1757     { &hf_homeplug_loader_gmd,
1758       { "Get Module Data", "homeplug.loader.gmd",
1759       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1760     },
1761
1762     { &hf_homeplug_loader_smd,
1763       { "Set Module Data", "homeplug.loader.smd",
1764       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1765     },
1766
1767     { &hf_homeplug_loader_module_id,
1768       { "Module ID", "homeplug.loader.module.id",
1769       FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
1770     },
1771
1772     { &hf_homeplug_loader_module_offset,
1773       { "Offset", "homeplug.loader.module.offset",
1774       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1775     },
1776
1777     { &hf_homeplug_loader_module_size,
1778       { "Module size", "homeplug.loader.module.size",
1779       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1780     },
1781
1782     { &hf_homeplug_loader_data_length,
1783       { "Data length", "homeplug.loader.data.length",
1784       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1785     },
1786
1787     { &hf_homeplug_loader_data_address,
1788       { "Address", "homeplug.loader.data.address",
1789       FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
1790     },
1791
1792     { &hf_homeplug_loader_data,
1793       { "Data", "homeplug.loader.data",
1794       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1795     },
1796
1797     { &hf_homeplug_loader_cm,
1798       { "Commit Modules", "homeplug.loader.cm",
1799       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1800     },
1801
1802     { &hf_homeplug_loader_lemd,
1803       { "Erase Module Data", "homeplug.loader.emd",
1804       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1805     },
1806
1807     { &hf_homeplug_loader_lenvms,
1808       { "Erase NVM Sectors", "homeplug.loader.lenvms",
1809       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1810     },
1811
1812     { &hf_homeplug_loader_gnvmp,
1813       { "Get NVM Parameters", "homeplug.loader.nvmp",
1814       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1815     },
1816
1817     { &hf_homeplug_loader_nvmp_type,
1818       { "Type", "homeplug.loader.nvmp.type",
1819       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1820     },
1821
1822     { &hf_homeplug_loader_nvmp_pagesize,
1823       { "Page Size", "homeplug.loader.nvmp.pagesize",
1824       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1825     },
1826
1827     { &hf_homeplug_loader_nvmp_blocksize,
1828       { "Block Size", "homeplug.loader.nvmp.blocksize",
1829       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1830     },
1831
1832     { &hf_homeplug_loader_nvmp_memorysize,
1833       { "Memory Size", "homeplug.loader.nvmp.memorysize",
1834       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1835     },
1836
1837     { &hf_homeplug_loader_snvmp,
1838       { "Set NVM Parameters", "homeplug.loader.nvmp",
1839       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1840     },
1841
1842     /* Host Request */
1843     { &hf_homeplug_hreq,
1844       { "Host Request", "homeplug.hreq",
1845       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1846     },
1847
1848     { &hf_homeplug_hreq_mid,
1849       { "Message ID", "homeplug.hreq.mid",
1850       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1851     },
1852
1853     { &hf_homeplug_hreq_gdv,
1854       { "Get Device Version", "homeplug.hreq.gdv",
1855       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1856     },
1857
1858     { &hf_homeplug_hreq_gfv,
1859       { "Get Firmware Version", "homeplug.hreq.gfv",
1860       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1861     },
1862
1863     { &hf_homeplug_hreq_gnek,
1864       { "Get Network Encryption Key", "homeplug.hreq.gnek",
1865       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1866     },
1867
1868     { &hf_homeplug_hreq_gclbpl,
1869       { "Get/Clear Local Bridge Proxy List", "homeplug.hreq.gclbpl",
1870       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1871     },
1872
1873     { &hf_homeplug_hreq_nvds,
1874       { "Non-volatile Database Status", "homeplug.hreq.nvds",
1875       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1876     },
1877
1878     { &hf_homeplug_hreq_grbt,
1879       { "Get Remote Bridge Table", "homeplug.hreq.grbt",
1880       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1881     },
1882
1883     { &hf_homeplug_hreq_gslnm,
1884       { "Get/Set Logical Network Mapping", "homeplug.hreq.gslnm",
1885       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1886     },
1887
1888     { &hf_homeplug_hreq_gsss,
1889       { "Get/Set Spectral Scaling", "homeplug.hreq.gsss",
1890       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1891     },
1892
1893     { &hf_homeplug_hreq_rsl,
1894       { "Reset Secondary Loader", "homeplug.hreq.rsl",
1895       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1896     },
1897
1898     { &hf_homeplug_hreq_reset,
1899       { "Reset", "homeplug.hreq.reset",
1900       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1901     },
1902
1903     { &hf_homeplug_hreq_reset_type,
1904       { "Type", "homeplug.hreq.reset.type",
1905       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1906     },
1907
1908     { &hf_homeplug_hreq_reset_delay,
1909       { "Delay", "homeplug.hreq.reset.delay",
1910       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1911     },
1912
1913     /* Host Response */
1914     { &hf_homeplug_hrsp,
1915       { "Host Response", "homeplug.hrsp",
1916       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1917     },
1918
1919     { &hf_homeplug_hrsp_mid,
1920       { "Message ID", "homeplug.hrsp.mid",
1921       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1922     },
1923
1924     { &hf_homeplug_hrsp_gdvr,
1925       { "Get Device Version", "homeplug.hrsp.gdvr",
1926       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1927     },
1928
1929     { &hf_homeplug_hrsp_gfvr,
1930       { "Get Firmware Version", "homeplug.hrsp.gfvr",
1931       FT_UINT8, BASE_DEC, NULL, 0x0, "Get Firmwave Version", HFILL }
1932     },
1933
1934     { &hf_homeplug_hrsp_gnekr,
1935       { "Get Network Encryption Key", "homeplug.hrsp.gnekr",
1936       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1937     },
1938
1939     { &hf_homeplug_hrsp_gnekr_select,
1940       { "Key Select", "homeplug.hrsp.gnekr.select",
1941       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1942     },
1943
1944     { &hf_homeplug_hrsp_gnekr_key,
1945       { "Key", "homeplug.hrsp.gnekr.key",
1946       FT_UINT64, BASE_HEX, NULL, 0x0, NULL, HFILL }
1947     },
1948
1949     { &hf_homeplug_hrsp_invalid,
1950       { "Invalid", "homeplug.hrsp.invalid",
1951       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1952     },
1953
1954     { &hf_homeplug_hrsp_version,
1955       { "Version", "homeplug.hrsp.version",
1956       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1957     },
1958
1959     /* Network Statistics */
1960     { &hf_homeplug_ns,
1961       { "Network Statistics", "homeplug.ns",
1962       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1963     },
1964
1965     { &hf_homeplug_ns_extended,
1966       { "Network Statistics is Extended", "homeplug.ns.extended",
1967       FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Network Statistics is Extended (MELEN >= 199)", HFILL }
1968     },
1969
1970     { &hf_homeplug_ns_netw_ctrl_ac,
1971       { "Action Control", "homeplug.ns.ac",
1972       FT_BOOLEAN, 8, TFS(&homeplug_ns_ac_vals), HOMEPLUG_NS_AC, NULL, HFILL }
1973     },
1974
1975     { &hf_homeplug_ns_netw_ctrl_icid,
1976       { "IC_ID", "homeplug.ns.icid",
1977       FT_UINT8, BASE_HEX|BASE_RANGE_STRING, RVALS(homeplug_ns_icid_vals), HOMEPLUG_NS_ICID, NULL, HFILL }
1978     },
1979
1980     { &hf_homeplug_ns_bytes40_robo,
1981       { "Bytes in 40 symbols in ROBO", "homeplug.ns.bytes40_robo",
1982       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1983     },
1984
1985     { &hf_homeplug_ns_fails_robo,
1986       { "Fails Received in ROBO", "homeplug.ns.fails_robo",
1987       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1988     },
1989
1990     { &hf_homeplug_ns_drops_robo,
1991       { "Frame Drops in ROBO", "homeplug.ns.drops_robo",
1992       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1993     },
1994
1995     { &hf_homeplug_ns_netw_da,
1996       { "Address of Network DA", "homeplug.ns.netw_da",
1997       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1998     },
1999
2000     { &hf_homeplug_ns_bytes40,
2001       { "Bytes in 40 symbols", "homeplug.ns.bytes40",
2002       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
2003     },
2004
2005     { &hf_homeplug_ns_fails,
2006       { "Fails Received", "homeplug.ns.fails",
2007       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
2008     },
2009
2010     { &hf_homeplug_ns_drops,
2011       { "Frame Drops", "homeplug.ns.drops",
2012       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
2013     },
2014
2015     /* ... Extended */
2016     { &hf_homeplug_ns_tx_bfr_state,
2017       { "Transmit Buffer State", "homeplug.ns.tx_bfr_state",
2018       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
2019     },
2020
2021     { &hf_homeplug_ns_buf_in_use,
2022       { "Buffer in use", "homeplug.ns.buf_in_use",
2023       FT_BOOLEAN, 8, TFS(&homeplug_ns_buf_in_use_vals), HOMEPLUG_NS_BUF_IN_USE,
2024       "Buffer in use (1) or Available (0)", HFILL }
2025     },
2026
2027     { &hf_homeplug_ns_prio,
2028       { "Priority", "homeplug.ns.prio",
2029       FT_UINT8, BASE_DEC, VALS(homeplug_txprio_vals), HOMEPLUG_NS_PRIO,
2030       NULL, HFILL }
2031     },
2032
2033     { &hf_homeplug_ns_msdu_len,
2034       { "MSDU Length", "homeplug.ns.msdu_len",
2035       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_NS_MSDU_LEN, NULL, HFILL }
2036     },
2037
2038     { &hf_homeplug_ns_seqn,
2039       { "Sequence Number", "homeplug.ns.seqn",
2040       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_NS_SEQN, NULL, HFILL }
2041     },
2042
2043     { &hf_homeplug_ns_toneidx,
2044       { "Transmit tone map index", "homeplug.ns.toneidx",
2045       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_NS_TONEIDX,
2046       "Maps to the 16 statistics occurring earlier in this MME", HFILL }
2047     },
2048
2049     /* Bridging Characteristics Network */
2050     { &hf_homeplug_bcn,
2051       { "Bridging Characteristics Network", "homeplug.bcn",
2052       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
2053     },
2054
2055     { &hf_homeplug_bcn_network,
2056       { "Network", "homeplug.bcn.network",
2057       FT_BOOLEAN, 8, TFS(&homeplug_bc_network_vals), HOMEPLUG_BC_NETWORK,
2058       "Local (0) or Network Bridge (1) Information", HFILL }
2059     },
2060
2061     { &hf_homeplug_bcn_return,
2062       { "Return/Set", "homeplug.bcn.return",
2063       FT_BOOLEAN, 8, TFS(&homeplug_bc_return_vals), HOMEPLUG_BC_RETURN,
2064       "From host: Return (1) or set bridging characteristics (0)", HFILL }
2065     },
2066
2067     { &hf_homeplug_bcn_rsvd,
2068       { "Reserved", "homeplug.bcn.rsvd",
2069       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_BCN_RSVD, NULL, HFILL }
2070     },
2071
2072     { &hf_homeplug_bcn_fbn,
2073       { "First Bridge Number", "homeplug.bcn.fbn",
2074       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_BCN_FBN, NULL, HFILL }
2075     },
2076
2077     { &hf_homeplug_bcn_brda,
2078       { "Address of Bridge", "homeplug.bcn.brda",
2079       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
2080     },
2081
2082     { &hf_homeplug_bcn_bp_das,
2083       { "Number of bridge proxied DAs", "homeplug.bcn.bp_das",
2084       FT_UINT8, BASE_DEC, NULL, 0x0,
2085       "Number of bridge proxied DAs supported", HFILL }
2086     },
2087
2088     { &hf_homeplug_bcn_bp_da,
2089       { "Bridged DA", "homeplug.bcn.bp_da",
2090       FT_ETHER, BASE_NONE, NULL, 0x0, "Bridged Destination Address", HFILL }
2091     },
2092
2093     /* Bridging Characteristics Local */
2094     { &hf_homeplug_bcl,
2095       { "Bridging Characteristics Local", "homeplug.bcl",
2096       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
2097     },
2098
2099     { &hf_homeplug_bcl_network,
2100       { "Network/Local", "homeplug.bcl.network",
2101       FT_BOOLEAN, 8, TFS(&homeplug_bc_network_vals), HOMEPLUG_BC_NETWORK,
2102       "Local (0) or Network Bridge (1) Information", HFILL }
2103     },
2104
2105     { &hf_homeplug_bcl_return,
2106       { "Return/Set", "homeplug.bcl.return",
2107       FT_BOOLEAN, 8, TFS(&homeplug_bc_return_vals), HOMEPLUG_BC_RETURN,
2108       "From host: Return (1) or set bridging characteristics (0)", HFILL }
2109     },
2110
2111     { &hf_homeplug_bcl_rsvd,
2112       { "Reserved", "homeplug.bcl.rsvd",
2113       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_BCL_RSVD, NULL, HFILL }
2114     },
2115
2116     { &hf_homeplug_bcl_hprox_das,
2117       { "Number of host proxied DAs", "homeplug.bcl.hprox_das",
2118       FT_UINT8, BASE_DEC, NULL, 0x0,
2119       "Number of host proxied DAs supported by the bridge application", HFILL }
2120     },
2121
2122     { &hf_homeplug_bcl_hpbda,
2123       { "Host Proxied DA", "homeplug.bcl.hpbda",
2124       FT_ETHER, BASE_NONE, NULL, 0x0, "Host Proxied Bridged Destination Address", HFILL }
2125     },
2126
2127     /* Set Transmit Characteristics */
2128     { &hf_homeplug_stc,
2129       { "Set Transmit Characteristics", "homeplug.stc",
2130       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
2131     },
2132
2133     { &hf_homeplug_stc_lco,
2134       { "Local Consumption Only", "homeplug.stc.lco",
2135       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_LCO,
2136       "Do not transmit subsequent frames to medium", HFILL }
2137     },
2138
2139     { &hf_homeplug_stc_encf,
2140       { "Encryption Flag", "homeplug.stc.encf",
2141       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_ENCF, "Encrypt subsequent frames", HFILL }
2142     },
2143
2144     { &hf_homeplug_stc_txprio,
2145       { "Transmit Priority", "homeplug.stc.txprio",
2146       FT_UINT8, BASE_DEC, VALS(homeplug_txprio_vals), HOMEPLUG_STC_TXPRIO,
2147       NULL, HFILL }
2148     },
2149
2150     { &hf_homeplug_stc_rexp,
2151       { "Response Expected", "homeplug.stc.rexp",
2152       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_REXP,
2153       "Mark subsequent frames to receive response", HFILL }
2154     },
2155
2156     { &hf_homeplug_stc_txcf,
2157       { "Transmit Contention Free", "homeplug.stc.txcf",
2158       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_TXCF,
2159       "Mark subsequently transmitted frames as contention free", HFILL }
2160     },
2161
2162     { &hf_homeplug_stc_cftop,
2163       { "Contention Free Transmit Override Priority", "homeplug.stc.cftop",
2164       FT_BOOLEAN, 8, TFS(&homeplug_stc_cftop_vals), HOMEPLUG_STC_CFTOP,
2165       "Transmit subsequent contention free frames with CA2/CA3 priority", HFILL }
2166     },
2167
2168     { &hf_homeplug_stc_rsvd1,
2169       { "Reserved", "homeplug.stc.rsvd1",
2170       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_STC_RSVD1, NULL, HFILL }
2171     },
2172
2173     { &hf_homeplug_stc_retry,
2174       { "Retry Control", "homeplug.stc.retry",
2175       FT_UINT8, BASE_DEC, VALS(homeplug_stc_retry_vals), HOMEPLUG_STC_RETRY,
2176       NULL, HFILL }
2177     },
2178
2179     { &hf_homeplug_stc_rsvd2,
2180       { "Reserved", "homeplug.stc.rsvd2",
2181       FT_UINT8, BASE_DEC, NULL, HOMEPLUG_STC_RSVD2, NULL, HFILL }
2182     },
2183
2184     { &hf_homeplug_stc_dder,
2185       { "Disable Default Encryption Receive", "homeplug.stc.dder",
2186       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_DDER, NULL, HFILL }
2187     },
2188
2189     { &hf_homeplug_stc_dur,
2190       { "Disable Unencrypted Receive", "homeplug.stc.dur",
2191       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_DUR, NULL, HFILL }
2192     },
2193
2194     { &hf_homeplug_stc_ebp,
2195       { "INT51X1 (Host/DTE Option) Enable Backpressure", "homeplug.stc.ebp",
2196       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_EBP,
2197       NULL, HFILL }
2198     },
2199
2200     { &hf_homeplug_stc_dees,
2201       { "Disable EEPROM Save", "homeplug.stc.dees",
2202       FT_BOOLEAN, 8, NULL, HOMEPLUG_STC_DEES, NULL, HFILL }
2203     },
2204
2205     { &hf_homeplug_stc_txeks,
2206       { "EKS to be used for encryption", "homeplug.stc.txeks",
2207       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
2208     },
2209
2210     /* Undecoded data */
2211     { &hf_homeplug_data,
2212       { "Data", "homeplug.data",
2213       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
2214     }
2215   };
2216
2217   /* Setup protocol subtree array */
2218   static gint *ett[] = {
2219     &ett_homeplug,
2220     &ett_homeplug_mctrl,
2221     &ett_homeplug_mehdr,
2222     &ett_homeplug_rce,
2223     &ett_homeplug_cer,
2224     &ett_homeplug_vs,
2225     &ett_homeplug_vs_mid,
2226     &ett_homeplug_snk,
2227     &ett_homeplug_rps,
2228     &ett_homeplug_psr,
2229     &ett_homeplug_slp,
2230     &ett_homeplug_loader,
2231     &ett_homeplug_hreq,
2232     &ett_homeplug_hrsp,
2233     &ett_homeplug_ns,
2234     &ett_homeplug_tx_bfr_state,
2235     &ett_homeplug_tone,
2236     &ett_homeplug_bcn,
2237     &ett_homeplug_bridge,
2238     &ett_homeplug_bcl,
2239     &ett_homeplug_stc
2240   };
2241
2242   proto_homeplug = proto_register_protocol("HomePlug protocol", "HomePlug", "homeplug");
2243
2244   proto_register_field_array(proto_homeplug, hf, array_length(hf));
2245
2246   proto_register_subtree_array(ett, array_length(ett));
2247 }