3 * Routines for LWAPP encapsulated packet disassembly
4 * draft-calhoun-seamoby-lwapp-N (the current draft is 3)
6 * $Id: packet-lwapp.c,v 1.4 2003/09/24 23:35:39 guy Exp $
8 * Copyright (c) 2003 by David Frascone <dave@frascone.com>
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
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.
39 #include <epan/filesystem.h>
41 #include <epan/packet.h>
42 #include <epan/resolv.h>
46 #ifdef NEED_SNPRINTF_H
47 # include "snprintf.h"
50 #define LWAPP_FLAGS_T 0x04
51 #define LWAPP_FLAGS_F 0x02
52 #define LWAPP_FLAGS_FT 0x01
54 static gint proto_lwapp = -1;
55 static gint proto_lwapp_l3 = -1;
56 static gint proto_lwapp_control = -1;
57 static gint ett_lwapp = -1;
58 static gint ett_lwapp_l3 = -1;
59 static gint ett_lwapp_flags = -1;
60 static gint ett_lwapp_control = -1;
62 static gint hf_lwapp_version = -1;
63 static gint hf_lwapp_slotid = -1;
64 static gint hf_lwapp_flags_type = -1;
65 static gint hf_lwapp_flags_fragment = -1;
66 static gint hf_lwapp_flags_fragment_type = -1;
67 static gint hf_lwapp_fragment_id = -1;
68 static gint hf_lwapp_length = -1;
69 static gint hf_lwapp_rssi = -1;
70 static gint hf_lwapp_snr = -1;
71 static gint hf_lwapp_control = -1;
72 static gint hf_lwapp_control_type = -1;
73 static gint hf_lwapp_control_seq_no = -1;
74 static gint hf_lwapp_control_length = -1;
76 static dissector_handle_t eth_handle;
77 static dissector_handle_t wlan_handle;
78 static dissector_handle_t wlan_bsfc_handle;
79 static dissector_handle_t data_handle;
81 /* Set by preferences */
82 static gboolean swap_frame_control;
112 OPERATION_RATE_SET_PAYLOAD,
113 MULTI_DOMAIN_CAPABILITY_PAYLOAD,
114 MAC_OPERATION_PAYLOAD,
115 PHY_TX_POWER_PAYLOAD,
116 PHY_TX_POWER_LEVEL_PAYLOAD,
119 SUPPORTED_RATES_PAYLOAD,
122 RRM_NEIGHBOR_CTRL_PAYLOAD,
123 RRM_NOISE_CTRL_PAYLOAD,
124 RRM_NOISE_DATA_PAYLOAD,
125 RRM_INTERFERENCE_CTRL_PAYLOAD,
126 RRM_INTERFERENCE_DATA_PAYLOAD,
127 RRM_LOAD_CTRL_PAYLOAD,
128 RRM_LOAD_DATA_PAYLOAD,
129 CHANGE_STATE_EVENT_PAYLOAD,
133 DELETE_MOBILE_PAYLOAD
138 DISCOVERY_REQUEST = 1,
150 CONFIGURE_COMMAND_RES,
153 CHANGE_STATE_EVENT_RES,
164 const value_string control_msg_vals[] = {
165 {DISCOVERY_REQUEST, "DISCOVERY_REQUEST"},
166 {DISCOVERY_REPLY, "DISCOVERY_REPLY"},
167 {JOIN_REQUEST, "JOIN_REQUEST"},
168 {JOIN_REPLY, "JOIN_REPLY"},
169 {HANDOFF_REQUEST, "HANDOFF_REQUEST"},
170 {HANDOFF_REPLY, "HANDOFF_REPLY"},
171 {HANDOFF_COMMAND, "HANDOFF_COMMAND"},
172 {HANDOFF_RESPONSE, "HANDOFF_RESPONSE"},
173 {HANDOFF_CONFIRM, "HANDOFF_CONFIRM"},
174 {CONFIGURE_REQUEST, "CONFIGURE_REQUEST"},
175 {CONFIGURE_RESPONSE, "CONFIGURE_RESPONSE"},
176 {CONFIGURE_COMMAND, "CONFIGURE_COMMAND"},
177 {CONFIGURE_COMMAND_RES, "CONFIGURE_COMMAND_RES"},
178 {STATISTICS_INFO, "STATISTICS_INFO"},
179 {CHANGE_STATE_EVENT, "CHANGE_STATE_EVENT"},
180 {CHANGE_STATE_EVENT_RES, "CHANGE_STATE_EVENT_RES"},
181 {RRM_CONTROL_REQ, "RRM_CONTROL_REQ"},
182 {RRM_CONTROL_RES, "RRM_CONTROL_RES"},
183 {RRM_DATA_REQ, "RRM_DATA_REQ"},
184 {RRM_DATA_RES, "RRM_DATA_RES"},
185 {ECHO_REQUEST, "ECHO_REQUEST"},
186 {ECHO_RESPONSE, "ECHO_RESPONSE"},
187 {I_AM_UP_REQ, "I_AM_UP_REQ"},
188 {I_AM_UP_RES, "I_AM_UP_RES"},
192 const value_string control_tag_vals[] = {
194 {RESULT_CODE, "RESULT_CODE"},
195 {MWAR_ADDR_PAYLOAD, "MWAR_ADDR_PAYLOAD"},
196 {RAD_PAYLOAD, "RAD_PAYLOAD"},
197 {RAD_SLOT_PAYLOAD, "RAD_SLOT_PAYLOAD"},
198 {RAD_NAME_PAYLOAD, "RAD_NAME_PAYLOAD"},
199 {MWAR_PAYLOAD, "MWAR_PAYLOAD"},
200 {VAP_PAYLOAD, "VAP_PAYLOAD"},
201 {STATION_CFG_PAYLOAD, "STATION_CFG_PAYLOAD"},
202 {OPERATION_RATE_SET_PAYLOAD, "OPERATION_RATE_SET_PAYLOAD"},
203 {MULTI_DOMAIN_CAPABILITY_PAYLOAD, "MULTI_DOMAIN_CAPABILITY_PAYLOAD"},
204 {MAC_OPERATION_PAYLOAD, "MAC_OPERATION_PAYLOAD"},
205 {PHY_TX_POWER_PAYLOAD, "PHY_TX_POWER_PAYLOAD"},
206 {PHY_TX_POWER_LEVEL_PAYLOAD, "PHY_TX_POWER_LEVEL_PAYLOAD"},
207 {PHY_DSSS_PAYLOAD, "PHY_DSSS_PAYLOAD"},
208 {PHY_OFDM_PAYLOAD, "PHY_OFDM_PAYLOAD"},
209 {SUPPORTED_RATES_PAYLOAD, "SUPPORTED_RATES_PAYLOAD"},
210 {AUTH_PAYLOAD, "AUTH_PAYLOAD"},
211 {TEST_PAYLOAD, "TEST_PAYLOAD"},
212 {RRM_NEIGHBOR_CTRL_PAYLOAD, "RRM_NEIGHBOR_CTRL_PAYLOAD"},
213 {RRM_NOISE_CTRL_PAYLOAD, "RRM_NOISE_CTRL_PAYLOAD"},
214 {RRM_NOISE_DATA_PAYLOAD, "RRM_NOISE_DATA_PAYLOAD"},
215 {RRM_INTERFERENCE_CTRL_PAYLOAD, "RRM_INTERFERENCE_CTRL_PAYLOAD"},
216 {RRM_INTERFERENCE_DATA_PAYLOAD, "RRM_INTERFERENCE_DATA_PAYLOAD"},
217 {RRM_LOAD_CTRL_PAYLOAD, "RRM_LOAD_CTRL_PAYLOAD"},
218 {RRM_LOAD_DATA_PAYLOAD, "RRM_LOAD_DATA_PAYLOAD"},
219 {CHANGE_STATE_EVENT_PAYLOAD, "CHANGE_STATE_EVENT_PAYLOAD"},
220 {ADMIN_STATE_PAYLOAD, "ADMIN_STATE_PAYLOAD"},
221 {DELETE_VAP_PAYLOAD, "DELETE_VAP_PAYLOAD"},
222 {ADD_MOBILE_PAYLOAD, "ADD_MOBILE_PAYLOAD"},
223 {DELETE_MOBILE_PAYLOAD, "DELETE_MOBILE_PAYLOAD"},
227 static const true_false_string lwapp_flags_type = {
228 "LWAPP Control Packet" ,
232 static const true_false_string lwapp_set_truth = {
238 * dissect lwapp control packets. This is not fully implemented,
239 * but it's a good start.
241 static void dissect_control(tvbuff_t *tvb, packet_info *pinfo,
245 proto_tree *control_tree;
248 /* Set up structures needed to add the protocol subtree and manage it */
252 /* Make entries in Protocol column and Info column on summary display */
253 if (check_col(pinfo->cinfo, COL_PROTOCOL))
254 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LWAPP");
255 if (check_col(pinfo->cinfo, COL_INFO)) {
256 col_clear(pinfo->cinfo, COL_INFO);
257 col_add_str(pinfo->cinfo, COL_INFO,
261 /* Copy our header */
262 tvb_memcpy(tvb, (guint8*) &header, offset, sizeof(header));
265 * Fix the length (network byte ordering), and set our version &
268 header.length = g_ntohs(header.length);
270 if (check_col(pinfo->cinfo, COL_INFO)) {
271 col_append_str(pinfo->cinfo, COL_INFO,
272 val_to_str(header.type, control_msg_vals, "Bad Type: 0x%02x"));
275 /* In the interest of speed, if "tree" is NULL, don't do any work not
276 necessary to generate protocol tree items. */
278 /* create display subtree for the protocol */
279 ti = proto_tree_add_item(tree, proto_lwapp_control, tvb, offset,
281 control_tree = proto_item_add_subtree(ti, ett_lwapp_control);
283 proto_tree_add_uint(control_tree, hf_lwapp_control_type,
284 tvb, offset, 1, header.type);
287 proto_tree_add_uint(control_tree, hf_lwapp_control_seq_no,
288 tvb, offset, 1, header.seqNo);
291 proto_tree_add_uint(control_tree, hf_lwapp_control_length,
292 tvb, offset, 2, header.length);
295 /* Dissect rest of packet as data */
296 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
297 call_dissector(data_handle,next_tvb, pinfo, tree);
300 } /* dissect_control */
303 * This lwapp dissector assumes that there is an 802.3 header at
304 * the start of the packet, so it simply re-calls the ethernet
305 * dissector on the packet.
307 static void dissect_lwapp_l3(tvbuff_t *tvb, packet_info *pinfo,
310 /* Set up structures needed to add the protocol subtree and manage it */
312 proto_tree *lwapp_tree;
314 tvbuff_t *next_client;
316 /* Make entries in Protocol column and Info column on summary display */
317 if (check_col(pinfo->cinfo, COL_PROTOCOL))
318 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LWAPP-L3");
319 if (check_col(pinfo->cinfo, COL_INFO)) {
320 col_clear(pinfo->cinfo, COL_INFO);
321 col_add_str(pinfo->cinfo, COL_INFO, "802.3 Packets over Layer 3");
325 /* create display subtree for the protocol */
326 ti = proto_tree_add_item(tree, proto_lwapp_l3, tvb, offset,
328 lwapp_tree = proto_item_add_subtree(ti, ett_lwapp_l3);
331 /* Dissect as Ethernet */
332 next_client = tvb_new_subset(tvb, 0, -1, -1);
333 call_dissector(eth_handle, next_client, pinfo, tree);
336 } /* dissect_lwapp_l3*/
340 * This dissector dissects the lwapp protocol itself. It assumes an
341 * lwapp payload in the data, and doesn't care whether the data was
342 * from a UDP packet, or a Layer 2 one.
344 static void dissect_lwapp(tvbuff_t *tvb, packet_info *pinfo,
350 proto_tree *lwapp_tree;
351 proto_tree *flags_tree;
352 tvbuff_t *next_client;
354 /* Set up structures needed to add the protocol subtree and manage it */
358 /* Make entries in Protocol column and Info column on summary display */
359 if (check_col(pinfo->cinfo, COL_PROTOCOL))
360 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LWAPP");
361 if (check_col(pinfo->cinfo, COL_INFO)) {
362 col_clear(pinfo->cinfo, COL_INFO);
363 col_add_str(pinfo->cinfo, COL_INFO,
364 "LWAPP IP or Layer 2");
367 /* Copy our header */
368 tvb_memcpy(tvb, (guint8*) &header, offset, sizeof(header));
371 * Fix the length (network byte ordering), and set our version &
374 header.length = g_ntohs(header.length);
375 version = (header.flags & 0xc0) >> 6;
376 slotId = (header.flags & 0x38) >> 3;
378 if (check_col(pinfo->cinfo, COL_INFO)) {
379 if ((header.flags & LWAPP_FLAGS_T) != 0)
380 col_append_str(pinfo->cinfo, COL_INFO,
383 col_append_str(pinfo->cinfo, COL_INFO,
387 /* In the interest of speed, if "tree" is NULL, don't do any work not
388 necessary to generate protocol tree items. */
391 /* create display subtree for the protocol */
392 ti = proto_tree_add_item(tree, proto_lwapp, tvb, offset,
393 tvb_length(tvb), FALSE);
394 lwapp_tree = proto_item_add_subtree(ti, ett_lwapp);
396 proto_tree_add_uint(lwapp_tree, hf_lwapp_version,
397 tvb, offset, 1, version);
398 proto_tree_add_uint(lwapp_tree, hf_lwapp_slotid,
399 tvb, offset, 1, slotId);
401 flags_tree = proto_item_add_subtree(lwapp_tree, ett_lwapp_flags);
402 proto_tree_add_boolean(flags_tree, hf_lwapp_flags_type,
403 tvb, offset, 1, header.flags);
404 proto_tree_add_boolean(flags_tree, hf_lwapp_flags_fragment,
405 tvb, offset, 1, header.flags);
406 proto_tree_add_boolean(flags_tree, hf_lwapp_flags_fragment_type,
407 tvb, offset, 1, header.flags);
410 proto_tree_add_uint(lwapp_tree, hf_lwapp_fragment_id,
411 tvb, offset, 1, header.fragmentId);
414 proto_tree_add_uint(lwapp_tree, hf_lwapp_length,
415 tvb, offset, 2, header.length);
418 proto_tree_add_uint(lwapp_tree, hf_lwapp_rssi,
419 tvb, offset, 1, header.rssi);
421 proto_tree_add_uint(lwapp_tree, hf_lwapp_snr,
422 tvb, offset, 1, header.snr);
428 next_client = tvb_new_subset(tvb, sizeof(LWAPP_Header), -1, -1);
429 if ((header.flags & LWAPP_FLAGS_T) == 0) {
430 call_dissector(swap_frame_control ? wlan_bsfc_handle : wlan_handle,
431 next_client, pinfo, tree);
433 dissect_control(next_client, pinfo, tree);
439 /* registration with the filtering engine */
441 proto_register_lwapp(void)
443 static hf_register_info hf[] = {
445 { "Version", "lwapp.version", FT_UINT8, BASE_DEC, NULL, 0x00,
448 { "slotId","lwapp.slotId", FT_UINT24, BASE_DEC, NULL, 0x0,
450 { &hf_lwapp_flags_type,
451 { "Type", "lwapp.flags.type", FT_BOOLEAN, 8,
452 TFS(&lwapp_flags_type), LWAPP_FLAGS_T, "", HFILL }},
453 { &hf_lwapp_flags_fragment,
454 { "Fragment", "lwapp.flags.fragment", FT_BOOLEAN, 8,
455 TFS(&lwapp_set_truth), LWAPP_FLAGS_F,
457 { &hf_lwapp_flags_fragment_type,
458 { "Fragment Type", "lwapp.flags.fragmentType", FT_BOOLEAN, 8,
459 TFS(&lwapp_set_truth), LWAPP_FLAGS_FT,
461 { &hf_lwapp_fragment_id,
462 { "Fragment Id","lwapp.fragmentId", FT_UINT8, BASE_HEX,
463 NULL, 0x0, "", HFILL }},
465 { "Length","lwapp.Length", FT_UINT16, BASE_DEC,
466 NULL, 0x0, "", HFILL }},
468 { "RSSI","lwapp.rssi", FT_UINT8, BASE_HEX,
469 NULL, 0x0, "", HFILL }},
471 { "SNR","lwapp.snr", FT_UINT8, BASE_HEX,
472 NULL, 0x0, "", HFILL }},
474 { "Control Data (not dissected yet)","lwapp.control", FT_BYTES, BASE_NONE,
475 NULL, 0x0, "", HFILL }},
476 { &hf_lwapp_control_type,
477 { "Control Type", "lwapp.control.type", FT_UINT8, BASE_DEC, NULL, 0x00,
479 { &hf_lwapp_control_seq_no,
480 { "Control Sequence Number", "lwapp.control.seqno", FT_UINT8, BASE_DEC, NULL, 0x00,
482 { &hf_lwapp_control_length,
483 { "Control Length","lwapp.control.length", FT_UINT16, BASE_DEC,
484 NULL, 0x0, "", HFILL }},
486 static gint *ett[] = {
492 module_t *lwapp_module;
494 proto_lwapp = proto_register_protocol ("LWAPP Encapsulated Packet",
497 proto_lwapp_l3 = proto_register_protocol ("LWAPP Layer 3 Packet",
498 "LWAPP-L3", "lwapp-l3");
500 proto_lwapp_control = proto_register_protocol ("LWAP Control Message",
501 "LWAPP-CNTL", "lwapp-cntl");
502 proto_register_field_array(proto_lwapp, hf, array_length(hf));
503 proto_register_subtree_array(ett, array_length(ett));
505 lwapp_module = prefs_register_protocol(proto_lwapp, NULL);
507 prefs_register_bool_preference(lwapp_module,"swap_fc","Swap Frame Control",
508 "Swap frame control bytes (needed for some APs",
509 &swap_frame_control);
511 } /* proto_register_diameter */
514 proto_reg_handoff_lwapp(void)
516 dissector_handle_t lwapp_l3_handle;
517 dissector_handle_t lwapp_handle;
520 * Get handles for the Ethernet and wireless dissectors.
522 eth_handle = find_dissector("eth");
523 wlan_handle = find_dissector("wlan");
524 wlan_bsfc_handle = find_dissector("wlan_bsfc");
525 data_handle = find_dissector("data");
527 /* This dissector assumes lwapp packets in an 802.3 frame */
528 lwapp_l3_handle = create_dissector_handle(dissect_lwapp_l3, proto_lwapp_l3);
530 /* This dissector assumes a lwapp packet */
531 lwapp_handle = create_dissector_handle(dissect_lwapp, proto_lwapp);
534 * Ok, the following deserves some comments. We have four
535 * different ways lwapp can appear on the wire. Mostly, this is
536 * because lwapp is such a new protocol.
538 * First, lwapp can join on multiple udp ports, as encapsulated
539 * packets on top of UDP. In this case, there is a full raw
540 * ethernet frame inside of the UDP packet. This method is
541 * becoming obscelete, but we still wanted to dissect the
544 * Next, lwapp can be over UDP, but packged for L3 tunneling. This
545 * is the new-style. In this case, LWAP headers are just transmitted
548 * The last method is lwapp directly over layer 2. For this, we
549 * dissect two different ethertypes (until IANA gives us one)
553 /* Obsceleted LWAP via encapsulated 802.3 over UDP */
555 dissector_add("udp.port", 12220, lwapp_l3_handle);
557 /* new-style lwapp directly over UDP: L3-lwapp*/
558 dissector_add("udp.port", 12222, lwapp_handle);
561 dissector_add("ethertype", 0x88bb, lwapp_handle);
562 dissector_add("ethertype", 0xbbbb, lwapp_handle);