3 * Routines for LWAPP encapsulated packet disassembly
4 * draft-ohara-capwap-lwapp-N (the current draft is 0)
8 * Copyright (c) 2003 by David Frascone <dave@frascone.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
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.
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.
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.
34 #include <epan/filesystem.h>
35 #include <epan/packet.h>
36 #include <epan/addr_resolv.h>
37 #include <epan/prefs.h>
40 #define LWAPP_FLAGS_T 0x04
41 #define LWAPP_FLAGS_F 0x02
42 #define LWAPP_FLAGS_FT 0x01
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;
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;
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;
72 /* Set by preferences */
73 static gboolean swap_frame_control;
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,
111 SUPPORTED_RATES_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,
125 DELETE_MOBILE_PAYLOAD
131 DISCOVERY_REQUEST = 1,
143 CONFIGURE_COMMAND_RES,
147 CHANGE_STATE_EVENT_RES,
162 PRIMARY_DISCOVERY_REQ,
163 PRIMARY_DISCOVERY_RES,
166 RESET_REQ_CLEAR_CONFIG
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"},
210 static const value_string control_tag_vals[] = {
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"},
246 static const true_false_string lwapp_flags_type = {
247 "LWAPP Control Packet" ,
251 static const true_false_string lwapp_set_truth = {
257 * dissect lwapp control packets. This is not fully implemented,
258 * but it's a good start.
260 static void dissect_control(tvbuff_t *tvb, packet_info *pinfo,
264 proto_tree *control_tree;
267 /* Set up structures needed to add the protocol subtree and manage it */
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,
276 /* Copy our header */
277 tvb_memcpy(tvb, (guint8*) &header, offset, sizeof(header));
280 * Fix the length (network byte ordering), and set our version &
283 header.length = g_ntohs(header.length);
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"));
290 /* In the interest of speed, if "tree" is NULL, don't do any work not
291 necessary to generate protocol tree items. */
293 /* create display subtree for the protocol */
294 ti = proto_tree_add_item(tree, proto_lwapp_control, tvb, offset,
296 control_tree = proto_item_add_subtree(ti, ett_lwapp_control);
298 proto_tree_add_uint(control_tree, hf_lwapp_control_type,
299 tvb, offset, 1, header.type);
302 proto_tree_add_uint(control_tree, hf_lwapp_control_seq_no,
303 tvb, offset, 1, header.seqNo);
306 proto_tree_add_uint(control_tree, hf_lwapp_control_length,
307 tvb, offset, 2, header.length);
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);
315 } /* dissect_control */
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.
322 static void dissect_lwapp_l3(tvbuff_t *tvb, packet_info *pinfo,
325 /* Set up structures needed to add the protocol subtree and manage it */
327 proto_tree *lwapp_tree;
329 tvbuff_t *next_client;
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");
336 /* create display subtree for the protocol */
337 ti = proto_tree_add_item(tree, proto_lwapp_l3, tvb, offset,
339 lwapp_tree = proto_item_add_subtree(ti, ett_lwapp_l3);
343 /* Dissect as Ethernet */
344 next_client = tvb_new_subset_remaining(tvb, 0);
345 call_dissector(eth_withoutfcs_handle, next_client, pinfo, lwapp_tree);
348 } /* dissect_lwapp_l3*/
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.
356 static void dissect_lwapp(tvbuff_t *tvb, packet_info *pinfo,
362 proto_tree *lwapp_tree;
363 proto_tree *flags_tree;
364 tvbuff_t *next_client;
366 guint8 have_destmac=0;
368 /* Set up structures needed to add the protocol subtree and manage it */
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");
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);
383 /* Copy our header */
384 tvb_memcpy(tvb, (guint8*) &header, offset + 6, sizeof(header));
387 /* Copy our header */
388 tvb_memcpy(tvb, (guint8*) &header, offset, sizeof(header));
393 * Fix the length (network byte ordering), and set our version &
396 header.length = g_ntohs(header.length);
397 version = (header.flags & 0xc0) >> 6;
398 slotId = (header.flags & 0x38) >> 3;
400 if (check_col(pinfo->cinfo, COL_INFO)) {
401 if ((header.flags & LWAPP_FLAGS_T) != 0)
402 col_append_str(pinfo->cinfo, COL_INFO,
405 col_append_str(pinfo->cinfo, COL_INFO,
409 /* In the interest of speed, if "tree" is NULL, don't do any work not
410 necessary to generate protocol tree items. */
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);
418 proto_tree_add_ether(lwapp_tree, hf_lwapp_control_mac, tvb, offset,
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);
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);
437 proto_tree_add_uint(lwapp_tree, hf_lwapp_fragment_id,
438 tvb, offset, 1, header.fragmentId);
441 proto_tree_add_uint(lwapp_tree, hf_lwapp_length,
442 tvb, offset, 2, header.length);
445 proto_tree_add_uint(lwapp_tree, hf_lwapp_rssi,
446 tvb, offset, 1, header.rssi);
448 proto_tree_add_uint(lwapp_tree, hf_lwapp_snr,
449 tvb, offset, 1, header.snr);
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);
460 dissect_control(next_client, pinfo, tree);
466 /* registration with the filtering engine */
468 proto_register_lwapp(void)
470 static hf_register_info hf[] = {
472 { "Version", "lwapp.version", FT_UINT8, BASE_DEC, NULL, 0x00,
475 { "slotId","lwapp.slotId", FT_UINT24, BASE_DEC, NULL, 0x0,
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,
484 { &hf_lwapp_flags_fragment_type,
485 { "Fragment Type", "lwapp.flags.fragmentType", FT_BOOLEAN, 8,
486 TFS(&lwapp_set_truth), LWAPP_FLAGS_FT,
488 { &hf_lwapp_fragment_id,
489 { "Fragment Id","lwapp.fragmentId", FT_UINT8, BASE_HEX,
490 NULL, 0x0, NULL, HFILL }},
492 { "Length","lwapp.Length", FT_UINT16, BASE_DEC,
493 NULL, 0x0, NULL, HFILL }},
495 { "RSSI","lwapp.rssi", FT_UINT8, BASE_HEX,
496 NULL, 0x0, NULL, HFILL }},
498 { "SNR","lwapp.snr", FT_UINT8, BASE_HEX,
499 NULL, 0x0, NULL, HFILL }},
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,
509 { &hf_lwapp_control_seq_no,
510 { "Control Sequence Number", "lwapp.control.seqno", FT_UINT8, BASE_DEC, NULL, 0x00,
512 { &hf_lwapp_control_length,
513 { "Control Length","lwapp.control.length", FT_UINT16, BASE_DEC,
514 NULL, 0x0, NULL, HFILL }},
516 static gint *ett[] = {
522 module_t *lwapp_module;
524 proto_lwapp = proto_register_protocol ("LWAPP Encapsulated Packet",
527 proto_lwapp_l3 = proto_register_protocol ("LWAPP Layer 3 Packet",
528 "LWAPP-L3", "lwapp-l3");
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));
535 lwapp_module = prefs_register_protocol(proto_lwapp, NULL);
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);
541 } /* proto_register_diameter */
544 proto_reg_handoff_lwapp(void)
546 dissector_handle_t lwapp_l3_handle;
547 dissector_handle_t lwapp_handle;
550 * Get handles for the Ethernet and wireless dissectors.
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");
557 /* This dissector assumes lwapp packets in an 802.3 frame */
558 lwapp_l3_handle = create_dissector_handle(dissect_lwapp_l3, proto_lwapp_l3);
560 /* This dissector assumes a lwapp packet */
561 lwapp_handle = create_dissector_handle(dissect_lwapp, proto_lwapp);
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.
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
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
578 * The last method is lwapp directly over layer 2. For this, we
579 * dissect two different ethertypes (until IANA gives us one)
583 /* Obsoleted LWAPP via encapsulated 802.3 over UDP */
585 dissector_add_uint("udp.port", 12220, lwapp_l3_handle);
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);
592 dissector_add_uint("ethertype", 0x88bb, lwapp_handle);
593 dissector_add_uint("ethertype", 0xbbbb, lwapp_handle);