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