818718373124d032fa1d9d392aebb8d3393e2f18
[obnox/wireshark/wip.git] / epan / dissectors / packet-lwapp.c
1 /* packet-lwapp.c
2  *
3  * Routines for LWAPP encapsulated packet disassembly
4  * draft-ohara-capwap-lwapp-N (the current draft is 0)
5  *
6  * $Id$
7  *
8  * Copyright (c) 2003 by David Frascone <dave@frascone.com>
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <glib.h>
34 #include <epan/filesystem.h>
35 #include <epan/packet.h>
36 #include <epan/addr_resolv.h>
37 #include <epan/prefs.h>
38
39
40 #define LWAPP_FLAGS_T 0x04
41 #define LWAPP_FLAGS_F 0x02
42 #define LWAPP_FLAGS_FT 0x01
43
44 static gint proto_lwapp = -1;
45 static gint proto_lwapp_l3 = -1;
46 static gint proto_lwapp_control = -1;
47 static gint ett_lwapp = -1;
48 static gint ett_lwapp_l3 = -1;
49 static gint ett_lwapp_flags = -1;
50 static gint ett_lwapp_control = -1;
51
52 static gint hf_lwapp_version = -1;
53 static gint hf_lwapp_slotid = -1;
54 static gint hf_lwapp_flags_type = -1;
55 static gint hf_lwapp_flags_fragment = -1;
56 static gint hf_lwapp_flags_fragment_type = -1;
57 static gint hf_lwapp_fragment_id = -1;
58 static gint hf_lwapp_length = -1;
59 static gint hf_lwapp_rssi = -1;
60 static gint hf_lwapp_snr = -1;
61 static gint hf_lwapp_control = -1;
62 static gint hf_lwapp_control_mac = -1;
63 static gint hf_lwapp_control_type = -1;
64 static gint hf_lwapp_control_seq_no = -1;
65 static gint hf_lwapp_control_length = -1;
66
67 static dissector_handle_t eth_withoutfcs_handle;
68 static dissector_handle_t wlan_handle;
69 static dissector_handle_t wlan_bsfc_handle;
70 static dissector_handle_t data_handle;
71
72 /* Set by preferences */
73 static gboolean swap_frame_control;
74
75 typedef struct {
76     guint8 flags;
77     guint8 fragmentId;
78     guint16 length;
79     guint8 rssi;
80     guint8 snr;
81 } LWAPP_Header;
82
83 typedef struct {
84     guint8   tag;
85     guint16  length;
86 } CNTL_Data_Header;
87
88 typedef struct {
89     guint8    type;
90     guint8    seqNo;
91     guint16   length;
92 } CNTL_Header;
93
94 #if 0
95 typedef enum {
96     RESULT_CODE = 1,
97     MWAR_ADDR_PAYLOAD,
98     RAD_PAYLOAD,
99     RAD_SLOT_PAYLOAD,
100     RAD_NAME_PAYLOAD,
101     MWAR_PAYLOAD,
102     VAP_PAYLOAD,
103     STATION_CFG_PAYLOAD,
104     OPERATION_RATE_SET_PAYLOAD,
105     MULTI_DOMAIN_CAPABILITY_PAYLOAD,
106     MAC_OPERATION_PAYLOAD,
107     PHY_TX_POWER_PAYLOAD,
108     PHY_TX_POWER_LEVEL_PAYLOAD,
109     PHY_DSSS_PAYLOAD,
110     PHY_OFDM_PAYLOAD,
111     SUPPORTED_RATES_PAYLOAD,
112     AUTH_PAYLOAD,
113     TEST_PAYLOAD,
114     RRM_NEIGHBOR_CTRL_PAYLOAD,
115     RRM_NOISE_CTRL_PAYLOAD,
116     RRM_NOISE_DATA_PAYLOAD,
117     RRM_INTERFERENCE_CTRL_PAYLOAD,
118     RRM_INTERFERENCE_DATA_PAYLOAD,
119     RRM_LOAD_CTRL_PAYLOAD,
120     RRM_LOAD_DATA_PAYLOAD,
121     CHANGE_STATE_EVENT_PAYLOAD,
122     ADMIN_STATE_PAYLOAD,
123     DELETE_VAP_PAYLOAD,
124     ADD_MOBILE_PAYLOAD,
125     DELETE_MOBILE_PAYLOAD
126 } control_tags;
127 #endif
128
129 typedef enum
130   {
131     DISCOVERY_REQUEST = 1,
132     DISCOVERY_REPLY,
133     JOIN_REQUEST,
134     JOIN_REPLY,
135     HANDOFF_REQUEST,
136     HANDOFF_REPLY,
137     HANDOFF_COMMAND,
138     HANDOFF_RESPONSE,
139     HANDOFF_CONFIRM,
140     CONFIGURE_REQUEST,
141     CONFIGURE_RESPONSE,
142     CONFIGURE_COMMAND,
143     CONFIGURE_COMMAND_RES,
144     STATISTICS_INFO,
145     STATISTICS_INFO_RES,
146     CHANGE_STATE_EVENT,
147     CHANGE_STATE_EVENT_RES,
148     RRM_CONTROL_REQ,
149     RRM_CONTROL_RES,
150     RRM_DATA_REQ,
151     RRM_DATA_RES,
152     ECHO_REQUEST,
153     ECHO_RESPONSE,
154     IMAGE_DATA,
155     IMAGE_DATA_RES,
156     RESET_REQ,
157     RESET_RES,
158     I_AM_UP_REQ,
159     I_AM_UP_RES,
160     KEY_UPDATE_REQ,
161     KEY_UPDATE_RES,
162     PRIMARY_DISCOVERY_REQ,
163     PRIMARY_DISCOVERY_RES,
164     DATA_TRANSFER,
165     DATA_TRANSFER_RES,
166     RESET_REQ_CLEAR_CONFIG
167   }CNTLMsgType;
168
169 static const value_string control_msg_vals[] = {
170     {DISCOVERY_REQUEST, "DISCOVERY_REQUEST"},
171     {DISCOVERY_REPLY, "DISCOVERY_REPLY"},
172     {JOIN_REQUEST, "JOIN_REQUEST"},
173     {JOIN_REPLY, "JOIN_REPLY"},
174     {HANDOFF_REQUEST, "HANDOFF_REQUEST"},
175     {HANDOFF_REPLY, "HANDOFF_REPLY"},
176     {HANDOFF_COMMAND, "HANDOFF_COMMAND"},
177     {HANDOFF_RESPONSE, "HANDOFF_RESPONSE"},
178     {HANDOFF_CONFIRM, "HANDOFF_CONFIRM"},
179     {CONFIGURE_REQUEST, "CONFIGURE_REQUEST"},
180     {CONFIGURE_RESPONSE, "CONFIGURE_RESPONSE"},
181     {CONFIGURE_COMMAND, "CONFIGURE_COMMAND"},
182     {CONFIGURE_COMMAND_RES, "CONFIGURE_COMMAND_RES"},
183     {STATISTICS_INFO, "STATISTICS_INFO"},
184     {STATISTICS_INFO_RES, "STATISTICS_INFO_RES"},
185     {CHANGE_STATE_EVENT, "CHANGE_STATE_EVENT"},
186     {CHANGE_STATE_EVENT_RES, "CHANGE_STATE_EVENT_RES"},
187     {RRM_CONTROL_REQ, "RRM_CONTROL_REQ"},
188     {RRM_CONTROL_RES, "RRM_CONTROL_RES"},
189     {RRM_DATA_REQ, "RRM_DATA_REQ"},
190     {RRM_DATA_RES, "RRM_DATA_RES"},
191     {ECHO_REQUEST, "ECHO_REQUEST"},
192     {ECHO_RESPONSE, "ECHO_RESPONSE"},
193     {IMAGE_DATA, "IMAGE_DATA"},
194     {IMAGE_DATA_RES, "IMAGE_DATA_RES"},
195     {RESET_REQ, "RESET_REQ"},
196     {RESET_RES, "RESET_RES"},
197     {I_AM_UP_RES, "I_AM_UP_RES"},
198     {I_AM_UP_RES, "I_AM_UP_RES"},
199     {KEY_UPDATE_REQ, "KEY_UPDATE_REQ"},
200     {KEY_UPDATE_RES, "KEY_UPDATE_RES"},
201     {PRIMARY_DISCOVERY_REQ, "PRIMARY_DISCOVERY_REQ"},
202     {PRIMARY_DISCOVERY_RES, "PRIMARY_DISCOVERY_RES"},
203     {DATA_TRANSFER, "DATA_TRANSFER"},
204     {DATA_TRANSFER_RES, "DATA_TRANSFER_RES"},
205     {RESET_REQ_CLEAR_CONFIG, "RESET_REQ_CLEAR_CONFIG"},
206
207     { 0, NULL}
208 };
209 #if 0
210 static const value_string control_tag_vals[] = {
211
212     {RESULT_CODE, "RESULT_CODE"},
213     {MWAR_ADDR_PAYLOAD, "MWAR_ADDR_PAYLOAD"},
214     {RAD_PAYLOAD, "RAD_PAYLOAD"},
215     {RAD_SLOT_PAYLOAD, "RAD_SLOT_PAYLOAD"},
216     {RAD_NAME_PAYLOAD, "RAD_NAME_PAYLOAD"},
217     {MWAR_PAYLOAD, "MWAR_PAYLOAD"},
218     {VAP_PAYLOAD, "VAP_PAYLOAD"},
219     {STATION_CFG_PAYLOAD, "STATION_CFG_PAYLOAD"},
220     {OPERATION_RATE_SET_PAYLOAD, "OPERATION_RATE_SET_PAYLOAD"},
221     {MULTI_DOMAIN_CAPABILITY_PAYLOAD, "MULTI_DOMAIN_CAPABILITY_PAYLOAD"},
222     {MAC_OPERATION_PAYLOAD, "MAC_OPERATION_PAYLOAD"},
223     {PHY_TX_POWER_PAYLOAD, "PHY_TX_POWER_PAYLOAD"},
224     {PHY_TX_POWER_LEVEL_PAYLOAD, "PHY_TX_POWER_LEVEL_PAYLOAD"},
225     {PHY_DSSS_PAYLOAD, "PHY_DSSS_PAYLOAD"},
226     {PHY_OFDM_PAYLOAD, "PHY_OFDM_PAYLOAD"},
227     {SUPPORTED_RATES_PAYLOAD, "SUPPORTED_RATES_PAYLOAD"},
228     {AUTH_PAYLOAD, "AUTH_PAYLOAD"},
229     {TEST_PAYLOAD, "TEST_PAYLOAD"},
230     {RRM_NEIGHBOR_CTRL_PAYLOAD, "RRM_NEIGHBOR_CTRL_PAYLOAD"},
231     {RRM_NOISE_CTRL_PAYLOAD, "RRM_NOISE_CTRL_PAYLOAD"},
232     {RRM_NOISE_DATA_PAYLOAD, "RRM_NOISE_DATA_PAYLOAD"},
233     {RRM_INTERFERENCE_CTRL_PAYLOAD, "RRM_INTERFERENCE_CTRL_PAYLOAD"},
234     {RRM_INTERFERENCE_DATA_PAYLOAD, "RRM_INTERFERENCE_DATA_PAYLOAD"},
235     {RRM_LOAD_CTRL_PAYLOAD, "RRM_LOAD_CTRL_PAYLOAD"},
236     {RRM_LOAD_DATA_PAYLOAD, "RRM_LOAD_DATA_PAYLOAD"},
237     {CHANGE_STATE_EVENT_PAYLOAD, "CHANGE_STATE_EVENT_PAYLOAD"},
238     {ADMIN_STATE_PAYLOAD, "ADMIN_STATE_PAYLOAD"},
239     {DELETE_VAP_PAYLOAD, "DELETE_VAP_PAYLOAD"},
240     {ADD_MOBILE_PAYLOAD, "ADD_MOBILE_PAYLOAD"},
241     {DELETE_MOBILE_PAYLOAD, "DELETE_MOBILE_PAYLOAD"},
242     {0, NULL}
243 };
244 #endif
245
246 static const true_false_string lwapp_flags_type = {
247     "LWAPP Control Packet" ,
248     "Encapsulated 80211"
249 };
250
251 static const true_false_string lwapp_set_truth = {
252     "Not Set",
253     "Set"
254 };
255
256 /*
257  * dissect lwapp control packets.  This is not fully implemented,
258  * but it's a good start.
259  */
260 static void dissect_control(tvbuff_t *tvb, packet_info *pinfo,
261                          proto_tree *tree)
262 {
263     CNTL_Header header;
264     proto_tree      *control_tree;
265     tvbuff_t        *next_tvb;
266
267     /* Set up structures needed to add the protocol subtree and manage it */
268     proto_item      *ti;
269     gint             offset=0;
270
271     /* Make entries in Protocol column and Info column on summary display */
272     col_set_str(pinfo->cinfo, COL_PROTOCOL, "LWAPP");
273     col_set_str(pinfo->cinfo, COL_INFO,
274                     "CNTL ");
275
276     /* Copy our header */
277     tvb_memcpy(tvb, (guint8*) &header, offset, sizeof(header));
278
279     /*
280      * Fix the length (network byte ordering), and set our version &
281      * slot id
282      */
283     header.length = g_ntohs(header.length);
284
285     if (check_col(pinfo->cinfo, COL_INFO)) {
286         col_append_str(pinfo->cinfo, COL_INFO,
287             val_to_str(header.type, control_msg_vals, "Bad Type: 0x%02x"));
288     }
289
290     /* In the interest of speed, if "tree" is NULL, don't do any work not
291        necessary to generate protocol tree items. */
292     if (tree) {
293         /* create display subtree for the protocol */
294         ti = proto_tree_add_item(tree, proto_lwapp_control, tvb, offset,
295                                  -1, FALSE);
296         control_tree = proto_item_add_subtree(ti, ett_lwapp_control);
297
298         proto_tree_add_uint(control_tree, hf_lwapp_control_type,
299                                tvb, offset, 1, header.type);
300         offset++;
301
302         proto_tree_add_uint(control_tree, hf_lwapp_control_seq_no,
303                                tvb, offset, 1, header.seqNo);
304         offset++;
305
306         proto_tree_add_uint(control_tree, hf_lwapp_control_length,
307                                tvb, offset, 2, header.length);
308         offset += 2;
309
310         /* Dissect rest of packet as data */
311         next_tvb = tvb_new_subset_remaining(tvb, offset);
312         call_dissector(data_handle,next_tvb, pinfo, tree);
313     }
314
315 } /* dissect_control */
316
317 /*
318  * This lwapp dissector assumes that there is an 802.3 header at
319  * the start of the packet, so it simply re-calls the ethernet
320  * dissector on the packet.
321  */
322 static void dissect_lwapp_l3(tvbuff_t *tvb, packet_info *pinfo,
323                             proto_tree *tree)
324 {
325     /* Set up structures needed to add the protocol subtree and manage it */
326     proto_item      *ti;
327     proto_tree      *lwapp_tree;
328     gint             offset=0;
329     tvbuff_t        *next_client;
330
331     /* Make entries in Protocol column and Info column on summary display */
332     col_set_str(pinfo->cinfo, COL_PROTOCOL, "LWAPP-L3");
333     col_set_str(pinfo->cinfo, COL_INFO, "802.3 Packets over Layer 3");
334
335     if (tree) {
336         /* create display subtree for the protocol */
337         ti = proto_tree_add_item(tree, proto_lwapp_l3, tvb, offset,
338                                  -1, FALSE);
339         lwapp_tree = proto_item_add_subtree(ti, ett_lwapp_l3);
340     } else {
341         lwapp_tree = NULL;
342     }
343     /* Dissect as Ethernet */
344     next_client = tvb_new_subset_remaining(tvb, 0);
345     call_dissector(eth_withoutfcs_handle, next_client, pinfo, lwapp_tree);
346     return;
347
348 } /* dissect_lwapp_l3*/
349
350
351 /*
352  * This dissector dissects the lwapp protocol itself.  It assumes an
353  * lwapp payload in the data, and doesn't care whether the data was
354  * from a UDP packet, or a Layer 2 one.
355  */
356 static void dissect_lwapp(tvbuff_t *tvb, packet_info *pinfo,
357                         proto_tree *tree)
358 {
359     LWAPP_Header header;
360     guint8       slotId;
361     guint8       version;
362     proto_tree  *lwapp_tree;
363     proto_tree  *flags_tree;
364     tvbuff_t    *next_client;
365     guint8       dest_mac[6];
366     guint8       have_destmac=0;
367
368     /* Set up structures needed to add the protocol subtree and manage it */
369     proto_item      *ti;
370     gint             offset=0;
371
372     /* Make entries in Protocol column and Info column on summary display */
373     col_set_str(pinfo->cinfo, COL_PROTOCOL, "LWAPP");
374     col_set_str(pinfo->cinfo, COL_INFO,
375                     "LWAPP IP or Layer 2");
376
377     /* First, set up our dest mac, if we're a control packet with a
378      * dest of port 12223 */
379     if (pinfo->destport == 12223 ) {
380         tvb_memcpy(tvb, dest_mac, offset, 6);
381         have_destmac = 1;
382
383         /* Copy our header */
384         tvb_memcpy(tvb, (guint8*) &header, offset + 6, sizeof(header));
385     } else {
386
387         /* Copy our header */
388         tvb_memcpy(tvb, (guint8*) &header, offset, sizeof(header));
389     }
390
391
392     /*
393      * Fix the length (network byte ordering), and set our version &
394      * slot id
395      */
396     header.length = g_ntohs(header.length);
397     version = (header.flags & 0xc0) >> 6;
398     slotId = (header.flags & 0x38) >> 3;
399
400     if (check_col(pinfo->cinfo, COL_INFO)) {
401         if ((header.flags & LWAPP_FLAGS_T) != 0)
402             col_append_str(pinfo->cinfo, COL_INFO,
403                            " Control Packet");
404         else
405             col_append_str(pinfo->cinfo, COL_INFO,
406                            " 802.11 Packet");
407     }
408
409     /* In the interest of speed, if "tree" is NULL, don't do any work not
410        necessary to generate protocol tree items. */
411     if (tree) {
412
413         /* create display subtree for the protocol */
414         ti = proto_tree_add_item(tree, proto_lwapp, tvb, offset, -1, FALSE);
415         lwapp_tree = proto_item_add_subtree(ti, ett_lwapp);
416
417         if (have_destmac) {
418             proto_tree_add_ether(lwapp_tree, hf_lwapp_control_mac, tvb, offset,
419                          6, dest_mac);
420             offset += 6;
421         }
422
423         proto_tree_add_uint(lwapp_tree, hf_lwapp_version,
424                                tvb, offset, 1, version);
425         proto_tree_add_uint(lwapp_tree, hf_lwapp_slotid,
426                                tvb, offset, 1, slotId);
427
428         flags_tree = proto_item_add_subtree(lwapp_tree, ett_lwapp_flags);
429         proto_tree_add_boolean(flags_tree, hf_lwapp_flags_type,
430                                tvb, offset, 1, header.flags);
431         proto_tree_add_boolean(flags_tree, hf_lwapp_flags_fragment,
432                                tvb, offset, 1, header.flags);
433         proto_tree_add_boolean(flags_tree, hf_lwapp_flags_fragment_type,
434                                tvb, offset, 1, header.flags);
435         offset++;
436
437         proto_tree_add_uint(lwapp_tree, hf_lwapp_fragment_id,
438                                tvb, offset, 1, header.fragmentId);
439         offset++;
440
441         proto_tree_add_uint(lwapp_tree, hf_lwapp_length,
442                                tvb, offset, 2, header.length);
443         offset += 2;
444
445         proto_tree_add_uint(lwapp_tree, hf_lwapp_rssi,
446                                tvb, offset, 1, header.rssi);
447         offset++;
448         proto_tree_add_uint(lwapp_tree, hf_lwapp_snr,
449                                tvb, offset, 1, header.snr);
450         offset++;
451
452
453     }  /* tree */
454
455     next_client = tvb_new_subset(tvb, (have_destmac?6:0) + sizeof(LWAPP_Header), -1, -1);
456     if ((header.flags & LWAPP_FLAGS_T) == 0) {
457         call_dissector(swap_frame_control ? wlan_bsfc_handle : wlan_handle,
458                         next_client, pinfo, tree);
459     } else {
460         dissect_control(next_client, pinfo, tree);
461     }
462     return;
463
464 } /* dissect_lwapp*/
465
466 /* registration with the filtering engine */
467 void
468 proto_register_lwapp(void)
469 {
470     static hf_register_info hf[] = {
471         { &hf_lwapp_version,
472           { "Version", "lwapp.version", FT_UINT8, BASE_DEC, NULL, 0x00,
473             NULL, HFILL }},
474         { &hf_lwapp_slotid,
475           { "slotId","lwapp.slotId", FT_UINT24, BASE_DEC, NULL, 0x0,
476             NULL, HFILL }},
477         { &hf_lwapp_flags_type,
478           { "Type", "lwapp.flags.type", FT_BOOLEAN, 8,
479             TFS(&lwapp_flags_type), LWAPP_FLAGS_T, NULL, HFILL }},
480         { &hf_lwapp_flags_fragment,
481           { "Fragment", "lwapp.flags.fragment", FT_BOOLEAN, 8,
482             TFS(&lwapp_set_truth), LWAPP_FLAGS_F,
483             NULL, HFILL }},
484         { &hf_lwapp_flags_fragment_type,
485           { "Fragment Type", "lwapp.flags.fragmentType", FT_BOOLEAN, 8,
486             TFS(&lwapp_set_truth), LWAPP_FLAGS_FT,
487             NULL, HFILL }},
488         { &hf_lwapp_fragment_id,
489           { "Fragment Id","lwapp.fragmentId", FT_UINT8, BASE_HEX,
490             NULL, 0x0, NULL, HFILL }},
491         { &hf_lwapp_length,
492           { "Length","lwapp.Length", FT_UINT16, BASE_DEC,
493             NULL, 0x0, NULL, HFILL }},
494         { &hf_lwapp_rssi,
495           { "RSSI","lwapp.rssi", FT_UINT8, BASE_HEX,
496             NULL, 0x0, NULL, HFILL }},
497         { &hf_lwapp_snr,
498           { "SNR","lwapp.snr", FT_UINT8, BASE_HEX,
499             NULL, 0x0, NULL, HFILL }},
500         { &hf_lwapp_control,
501           { "Control Data (not dissected yet)","lwapp.control", FT_BYTES, BASE_NONE,
502             NULL, 0x0, NULL, HFILL }},
503         { &hf_lwapp_control_mac,
504           { "AP Identity", "lwapp.apid", FT_ETHER, BASE_NONE, NULL, 0x0,
505               "Access Point Identity", HFILL }},
506         { &hf_lwapp_control_type,
507           { "Control Type", "lwapp.control.type", FT_UINT8, BASE_DEC, NULL, 0x00,
508             NULL, HFILL }},
509         { &hf_lwapp_control_seq_no,
510           { "Control Sequence Number", "lwapp.control.seqno", FT_UINT8, BASE_DEC, NULL, 0x00,
511             NULL, HFILL }},
512         { &hf_lwapp_control_length,
513           { "Control Length","lwapp.control.length", FT_UINT16, BASE_DEC,
514             NULL, 0x0, NULL, HFILL }},
515     };
516     static gint *ett[] = {
517         &ett_lwapp_l3,
518         &ett_lwapp,
519         &ett_lwapp_control,
520         &ett_lwapp_flags
521     };
522     module_t *lwapp_module;
523
524     proto_lwapp = proto_register_protocol ("LWAPP Encapsulated Packet",
525                                          "LWAPP", "lwapp");
526
527     proto_lwapp_l3 = proto_register_protocol ("LWAPP Layer 3 Packet",
528                                          "LWAPP-L3", "lwapp-l3");
529
530     proto_lwapp_control = proto_register_protocol ("LWAPP Control Message",
531                                          "LWAPP-CNTL", "lwapp-cntl");
532     proto_register_field_array(proto_lwapp, hf, array_length(hf));
533     proto_register_subtree_array(ett, array_length(ett));
534
535     lwapp_module = prefs_register_protocol(proto_lwapp, NULL);
536
537     prefs_register_bool_preference(lwapp_module,"swap_fc","Swap Frame Control",
538                                    "Swap frame control bytes (needed for some APs",
539                                     &swap_frame_control);
540
541 } /* proto_register_diameter */
542
543 void
544 proto_reg_handoff_lwapp(void)
545 {
546     dissector_handle_t lwapp_l3_handle;
547     dissector_handle_t lwapp_handle;
548
549     /*
550      * Get handles for the Ethernet and wireless dissectors.
551      */
552     eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
553     wlan_handle = find_dissector("wlan");
554     wlan_bsfc_handle = find_dissector("wlan_bsfc");
555     data_handle = find_dissector("data");
556
557     /* This dissector assumes lwapp packets in an 802.3 frame */
558     lwapp_l3_handle = create_dissector_handle(dissect_lwapp_l3, proto_lwapp_l3);
559
560     /* This dissector assumes a lwapp packet */
561     lwapp_handle = create_dissector_handle(dissect_lwapp, proto_lwapp);
562
563     /*
564      * Ok, the following deserves some comments.  We have four
565      * different ways lwapp can appear on the wire.  Mostly, this is
566      * because lwapp is such a new protocol.
567      *
568      * First, lwapp can join on multiple udp ports, as encapsulated
569      * packets on top of UDP.  In this case, there is a full raw
570      * ethernet frame inside of the UDP packet.  This method is
571      * becoming obscelete, but we still wanted to dissect the
572      * packets.
573      *
574      * Next, lwapp can be over UDP, but packged for L3 tunneling.  This
575      * is the new-style.  In this case, LWAP headers are just transmitted
576      * via UDP.
577      *
578      * The last method is lwapp directly over layer 2.  For this, we
579      * dissect two different ethertypes (until IANA gives us one)
580      *
581      */
582
583     /* Obsoleted LWAPP via encapsulated 802.3 over UDP */
584
585     dissector_add_uint("udp.port", 12220, lwapp_l3_handle);
586
587     /* new-style lwapp directly over UDP: L3-lwapp*/
588     dissector_add_uint("udp.port", 12222, lwapp_handle);
589     dissector_add_uint("udp.port", 12223, lwapp_handle);
590
591     /* Lwapp over L2 */
592     dissector_add_uint("ethertype", 0x88bb, lwapp_handle);
593     dissector_add_uint("ethertype", 0xbbbb, lwapp_handle);
594
595 }