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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <epan/filesystem.h>
33 #include <epan/packet.h>
34 #include <epan/addr_resolv.h>
35 #include <epan/prefs.h>
38 #define LWAPP_FLAGS_T 0x04
39 #define LWAPP_FLAGS_F 0x02
40 #define LWAPP_FLAGS_FT 0x01
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;
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;
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
;
70 /* Set by preferences */
71 static gboolean swap_frame_control
;
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
,
109 SUPPORTED_RATES_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
,
123 DELETE_MOBILE_PAYLOAD
129 DISCOVERY_REQUEST
= 1,
141 CONFIGURE_COMMAND_RES
,
145 CHANGE_STATE_EVENT_RES
,
160 PRIMARY_DISCOVERY_REQ
,
161 PRIMARY_DISCOVERY_RES
,
164 RESET_REQ_CLEAR_CONFIG
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"},
207 static value_string_ext control_msg_vals_ext
= VALUE_STRING_EXT_INIT(control_msg_vals
);
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"},
244 static value_string_ext control_tag_vals_ext
= VALUE_STRING_EXT_INIT(control_tag_vals
);
247 static const true_false_string lwapp_flags_type
= {
248 "LWAPP Control Packet" ,
253 * dissect lwapp control packets. This is not fully implemented,
254 * but it's a good start.
257 dissect_control(tvbuff_t
*tvb
, packet_info
*pinfo
,
261 proto_tree
*control_tree
;
264 /* Set up structures needed to add the protocol subtree and manage it */
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
,
273 /* Copy our header */
274 tvb_memcpy(tvb
, (guint8
*) &header
, offset
, sizeof(header
));
277 * Fix the length (network byte ordering), and set our version &
280 header
.length
= g_ntohs(header
.length
);
282 col_append_str(pinfo
->cinfo
, COL_INFO
,
283 val_to_str_ext(header
.type
, &control_msg_vals_ext
, "Bad Type: 0x%02x"));
285 /* In the interest of speed, if "tree" is NULL, don't do any work not
286 necessary to generate protocol tree items. */
288 /* create display subtree for the protocol */
289 ti
= proto_tree_add_item(tree
, proto_lwapp_control
, tvb
, offset
,
291 control_tree
= proto_item_add_subtree(ti
, ett_lwapp_control
);
293 proto_tree_add_uint(control_tree
, hf_lwapp_control_type
,
294 tvb
, offset
, 1, header
.type
);
297 proto_tree_add_uint(control_tree
, hf_lwapp_control_seq_no
,
298 tvb
, offset
, 1, header
.seqNo
);
301 proto_tree_add_uint(control_tree
, hf_lwapp_control_length
,
302 tvb
, offset
, 2, header
.length
);
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
);
310 } /* dissect_control */
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.
318 dissect_lwapp_l3(tvbuff_t
*tvb
, packet_info
*pinfo
,
321 /* Set up structures needed to add the protocol subtree and manage it */
323 proto_tree
*lwapp_tree
;
325 tvbuff_t
*next_client
;
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");
332 /* create display subtree for the protocol */
333 ti
= proto_tree_add_item(tree
, proto_lwapp_l3
, tvb
, offset
,
335 lwapp_tree
= proto_item_add_subtree(ti
, ett_lwapp_l3
);
339 /* Dissect as Ethernet */
340 next_client
= tvb_new_subset_remaining(tvb
, 0);
341 call_dissector(eth_withoutfcs_handle
, next_client
, pinfo
, lwapp_tree
);
344 } /* dissect_lwapp_l3*/
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.
353 dissect_lwapp(tvbuff_t
*tvb
, packet_info
*pinfo
,
359 proto_tree
*lwapp_tree
;
360 proto_tree
*flags_tree
;
361 tvbuff_t
*next_client
;
363 guint8 have_destmac
=0;
365 /* Set up structures needed to add the protocol subtree and manage it */
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");
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);
380 /* Copy our header */
381 tvb_memcpy(tvb
, (guint8
*) &header
, offset
+ 6, sizeof(header
));
384 /* Copy our header */
385 tvb_memcpy(tvb
, (guint8
*) &header
, offset
, sizeof(header
));
390 * Fix the length (network byte ordering), and set our version &
393 header
.length
= g_ntohs(header
.length
);
394 version
= (header
.flags
& 0xc0) >> 6;
395 slotId
= (header
.flags
& 0x38) >> 3;
397 if ((header
.flags
& LWAPP_FLAGS_T
) != 0)
398 col_append_str(pinfo
->cinfo
, COL_INFO
,
401 col_append_str(pinfo
->cinfo
, COL_INFO
,
404 /* In the interest of speed, if "tree" is NULL, don't do any work not
405 necessary to generate protocol tree items. */
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
);
413 proto_tree_add_ether(lwapp_tree
, hf_lwapp_control_mac
, tvb
, offset
,
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
);
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
);
432 proto_tree_add_uint(lwapp_tree
, hf_lwapp_fragment_id
,
433 tvb
, offset
, 1, header
.fragmentId
);
436 proto_tree_add_uint(lwapp_tree
, hf_lwapp_length
,
437 tvb
, offset
, 2, header
.length
);
440 proto_tree_add_uint(lwapp_tree
, hf_lwapp_rssi
,
441 tvb
, offset
, 1, header
.rssi
);
443 proto_tree_add_uint(lwapp_tree
, hf_lwapp_snr
,
444 tvb
, offset
, 1, header
.snr
);
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
);
455 dissect_control(next_client
, pinfo
, tree
);
461 /* registration with the filtering engine */
463 proto_register_lwapp(void)
465 static hf_register_info hf
[] = {
467 { "Version", "lwapp.version", FT_UINT8
, BASE_DEC
, NULL
, 0x00,
470 { "slotId","lwapp.slotId", FT_UINT24
, BASE_DEC
, NULL
, 0x0,
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
,
479 { &hf_lwapp_flags_fragment_type
,
480 { "Fragment Type", "lwapp.flags.fragmentType", FT_BOOLEAN
, 8,
481 TFS(&tfs_set_notset
), LWAPP_FLAGS_FT
,
483 { &hf_lwapp_fragment_id
,
484 { "Fragment Id","lwapp.fragmentId", FT_UINT8
, BASE_HEX
,
485 NULL
, 0x0, NULL
, HFILL
}},
487 { "Length","lwapp.Length", FT_UINT16
, BASE_DEC
,
488 NULL
, 0x0, NULL
, HFILL
}},
490 { "RSSI","lwapp.rssi", FT_UINT8
, BASE_HEX
,
491 NULL
, 0x0, NULL
, HFILL
}},
493 { "SNR","lwapp.snr", FT_UINT8
, BASE_HEX
,
494 NULL
, 0x0, NULL
, HFILL
}},
497 { "Control Data (not dissected yet)","lwapp.control", FT_BYTES
, BASE_NONE
,
498 NULL
, 0x0, NULL
, HFILL
}},
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,
506 { &hf_lwapp_control_seq_no
,
507 { "Control Sequence Number", "lwapp.control.seqno", FT_UINT8
, BASE_DEC
, NULL
, 0x00,
509 { &hf_lwapp_control_length
,
510 { "Control Length","lwapp.control.length", FT_UINT16
, BASE_DEC
,
511 NULL
, 0x0, NULL
, HFILL
}},
513 static gint
*ett
[] = {
519 module_t
*lwapp_module
;
521 proto_lwapp
= proto_register_protocol ("LWAPP Encapsulated Packet",
524 proto_lwapp_l3
= proto_register_protocol ("LWAPP Layer 3 Packet",
525 "LWAPP-L3", "lwapp-l3");
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
));
532 lwapp_module
= prefs_register_protocol(proto_lwapp
, NULL
);
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
);
538 } /* proto_register_diameter */
541 proto_reg_handoff_lwapp(void)
543 dissector_handle_t lwapp_l3_handle
;
544 dissector_handle_t lwapp_handle
;
547 * Get handles for the Ethernet and wireless dissectors.
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");
554 /* This dissector assumes lwapp packets in an 802.3 frame */
555 lwapp_l3_handle
= create_dissector_handle(dissect_lwapp_l3
, proto_lwapp_l3
);
557 /* This dissector assumes a lwapp packet */
558 lwapp_handle
= create_dissector_handle(dissect_lwapp
, proto_lwapp
);
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.
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
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
575 * The last method is lwapp directly over layer 2. For this, we
576 * dissect two different ethertypes (until IANA gives us one)
580 /* Obsoleted LWAPP via encapsulated 802.3 over UDP */
582 dissector_add_uint("udp.port", 12220, lwapp_l3_handle
);
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
);
589 dissector_add_uint("ethertype", 0x88bb, lwapp_handle
);
590 dissector_add_uint("ethertype", 0xbbbb, lwapp_handle
);