2 * Routines for Layer Two Tunnelling Protocol (L2TP) (RFC 2661) packet
4 * John Thomes <john@ensemblecom.com>
6 * Minor changes by: (2000-01-10)
7 * Laurent Cazalet <laurent.cazalet@mailclub.net>
8 * Thomas Parvais <thomas.parvais@advalvas.be>
10 * $Id: packet-l2tp.c,v 1.35 2002/08/28 21:00:19 jmayer Exp $
12 * Ethereal - Network traffic analyzer
13 * By Gerald Combs <gerald@ethereal.com>
14 * Copyright 1998 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 static int proto_l2tp = -1;
32 static int hf_l2tp_type = -1;
33 static int hf_l2tp_length_bit = -1;
34 static int hf_l2tp_seq_bit = -1;
35 static int hf_l2tp_offset_bit = -1;
36 static int hf_l2tp_priority = -1;
37 static int hf_l2tp_version = -1;
38 static int hf_l2tp_length = -1;
39 static int hf_l2tp_tunnel = -1;
40 static int hf_l2tp_session = -1;
41 static int hf_l2tp_Ns = -1;
42 static int hf_l2tp_Nr = -1;
43 static int hf_l2tp_offset = -1;
44 static int hf_l2tp_avp_mandatory = -1;
45 static int hf_l2tp_avp_hidden = -1;
46 static int hf_l2tp_avp_length = -1;
47 static int hf_l2tp_avp_vendor_id = -1;
48 static int hf_l2tp_avp_type = -1;
49 static int hf_l2tp_tie_breaker = -1;
60 #include <epan/packet.h>
61 #include <epan/resolv.h>
63 #define UDP_PORT_L2TP 1701
65 #define CONTROL_BIT(msg_info) (msg_info & 0x8000) /* Type bit control = 1 data = 0 */
66 #define LENGTH_BIT(msg_info) (msg_info & 0x4000) /* Length bit = 1 */
67 #define RESERVE_BITS(msg_info) (msg_info &0x37F8) /* Reserved bit - usused */
68 #define SEQUENCE_BIT(msg_info) (msg_info & 0x0800) /* SEQUENCE bit = 1 Ns and Nr fields */
69 #define OFFSET_BIT(msg_info) (msg_info & 0x0200) /* Offset */
70 #define PRIORITY_BIT(msg_info) (msg_info & 0x0100) /* Priority */
71 #define L2TP_VERSION(msg_info) (msg_info & 0x000f) /* Version of l2tp */
72 #define MANDATORY_BIT(msg_info) (msg_info & 0x8000) /* Mandatory = 1 */
73 #define HIDDEN_BIT(msg_info) (msg_info & 0x4000) /* Hidden = 1 */
74 #define AVP_LENGTH(msg_info) (msg_info & 0x03ff) /* AVP Length */
75 #define FRAMING_SYNC(msg_info) (msg_info & 0x0001) /* SYNC Framing Type */
76 #define FRAMING_ASYNC(msg_info) (msg_info & 0x0002) /* ASYNC Framing Type */
77 #define BEARER_DIGITAL(msg_info) (msg_info & 0x0001) /* Digital Bearer Type */
78 #define BEARER_ANALOG(msg_info) (msg_info & 0x0002) /* Analog Bearer Type */
80 static gint ett_l2tp = -1;
81 static gint ett_l2tp_ctrl = -1;
82 static gint ett_l2tp_avp = -1;
88 #define AVP_Reserved 5
96 #define AVP_Reserved1 13
100 #define NUM_CONTROL_CALL_TYPES 16
101 static const char *calltypestr[NUM_CONTROL_CALL_TYPES+1] = {
102 "Unknown Call Type ",
103 "Start_Control_Request ",
104 "Start_Control_Reply ",
105 "Start_Control_Connected ",
106 "Stop_Control_Notification ",
109 "Outgoing_Call_Request ",
110 "Outgoing_Call_Reply ",
111 "Outgoing_Call_Connected ",
112 "Incoming_Call_Request ",
113 "Incoming_Call_Reply ",
114 "Incoming_Call_Connected ",
116 "Call_Disconnect_Notification",
121 static const char *calltype_short_str[NUM_CONTROL_CALL_TYPES+1] = {
142 static const char *control_msg = "Control Message";
143 static const char *data_msg = "Data Message";
144 static const value_string l2tp_type_vals[] = {
145 { 0, "Data Message" },
146 { 1, "Control Message" },
150 static const value_string cause_code_direction_vals[] = {
151 { 0, "global error" },
157 static const true_false_string l2tp_length_bit_truth =
158 { "Length field is present", "Length field is not present" };
160 static const true_false_string l2tp_seq_bit_truth =
161 { "Ns and Nr fields are present", "Ns and Nr fields are not present" };
163 static const true_false_string l2tp_offset_bit_truth =
164 { "Offset Size field is present", "Offset size field is not present" };
166 static const true_false_string l2tp_priority_truth =
167 { "This data message has priority", "No priority" };
169 static const value_string authen_type_vals[] = {
171 { 1, "Textual username and password" },
174 { 4, "No Authentication" },
175 { 5, "Microsoft CHAP Version 1" },
179 #define CONTROL_MESSAGE 0
180 #define RESULT_ERROR_CODE 1
181 #define PROTOCOL_VERSION 2
182 #define FRAMING_CAPABILITIES 3
183 #define BEARER_CAPABILITIES 4
184 #define TIE_BREAKER 5
185 #define FIRMWARE_REVISION 6
187 #define VENDOR_NAME 8
188 #define ASSIGNED_TUNNEL_ID 9
189 #define RECEIVE_WINDOW_SIZE 10
191 #define CAUSE_CODE 12
192 #define CHALLENGE_RESPONSE 13
193 #define ASSIGNED_SESSION 14
194 #define CALL_SERIAL_NUMBER 15
195 #define MINIMUM_BPS 16
196 #define MAXIMUM_BPS 17
197 #define BEARER_TYPE 18
198 #define FRAMING_TYPE 19
199 #define CALLED_NUMBER 21
200 #define CALLING_NUMBER 22
201 #define SUB_ADDRESS 23
202 #define TX_CONNECT_SPEED 24
203 #define PHYSICAL_CHANNEL 25
204 #define INITIAL_RECEIVED_LCP 26
205 #define LAST_SEND_LCP_CONFREQ 27
206 #define LAST_RECEIVED_LCP_CONFREQ 28
207 #define PROXY_AUTHEN_TYPE 29
208 #define PROXY_AUTHEN_NAME 30
209 #define PROXY_AUTHEN_CHALLENGE 31
210 #define PROXY_AUTHEN_ID 32
211 #define PROXY_AUTHEN_RESPONSE 33
212 #define CALL_STATUS_AVPS 34
214 #define RANDOM_VECTOR 36
215 #define PRIVATE_GROUP_ID 37
216 #define RX_CONNECT_SPEED 38
217 #define SEQUENCING_REQUIRED 39
218 #define PPP_DISCONNECT_CAUSE_CODE 46 /* RFC 3145 */
220 #define NUM_AVP_TYPES 40
221 static const value_string avp_type_vals[] = {
222 { CONTROL_MESSAGE, "Control Message" },
223 { RESULT_ERROR_CODE, "Result-Error Code" },
224 { PROTOCOL_VERSION, "Protocol Version" },
225 { FRAMING_CAPABILITIES, "Framing Capabilities" },
226 { BEARER_CAPABILITIES, "Bearer Capabilities" },
227 { TIE_BREAKER, "Tie Breaker" },
228 { FIRMWARE_REVISION, "Firmware Revision" },
229 { HOST_NAME, "Host Name" },
230 { VENDOR_NAME, "Vendor Name" },
231 { ASSIGNED_TUNNEL_ID, "Assigned Tunnel ID" },
232 { RECEIVE_WINDOW_SIZE, "Receive Window Size" },
233 { CHALLENGE, "Challenge" },
234 { CAUSE_CODE, "Cause Code" },
235 { CHALLENGE_RESPONSE, "Challenge Response" },
236 { ASSIGNED_SESSION, "Assigned Session" },
237 { CALL_SERIAL_NUMBER, "Call Serial Number" },
238 { MINIMUM_BPS, "Minimum BPS" },
239 { MAXIMUM_BPS, "Maximum BPS" },
240 { BEARER_TYPE, "Bearer Type" },
241 { FRAMING_TYPE, "Framing Type" },
242 { CALLED_NUMBER, "Called Number" },
243 { CALLING_NUMBER, "Calling Number" },
244 { SUB_ADDRESS, "Sub-Address" },
245 { TX_CONNECT_SPEED, "Connect Speed" },
246 { PHYSICAL_CHANNEL, "Physical Channel" },
247 { INITIAL_RECEIVED_LCP, "Initial Received LCP" },
248 { LAST_SEND_LCP_CONFREQ, "Last Send LCP CONFREQ" },
249 { LAST_RECEIVED_LCP_CONFREQ, "Last Received LCP CONFREQ" },
250 { PROXY_AUTHEN_TYPE, "Proxy Authen Type" },
251 { PROXY_AUTHEN_NAME, "Proxy Authen Name" },
252 { PROXY_AUTHEN_CHALLENGE, "Proxy Authen Challenge" },
253 { PROXY_AUTHEN_ID, "Proxy Authen ID" },
254 { PROXY_AUTHEN_RESPONSE, "Proxy Authen Response" },
255 { CALL_STATUS_AVPS, "Call status AVPs" },
257 { RANDOM_VECTOR, "Random Vector" },
258 { PRIVATE_GROUP_ID, "Private group ID" },
259 { RX_CONNECT_SPEED, "RxConnect Speed" },
260 { SEQUENCING_REQUIRED, "Sequencing Required" },
261 { PPP_DISCONNECT_CAUSE_CODE, "PPP Disconnect Cause Code" },
266 * These are SMI Network Management Private Enterprise Codes for
269 * http://www.isi.edu/in-notes/iana/assignments/enterprise-numbers
273 #define VENDOR_IETF 0
275 #define VENDOR_CISCO 9
276 #define VENDOR_SHIVA 166
277 #define VENDOR_LIVINGSTON 307
278 #define VENDOR_3COM 429
279 #define VENDOR_ASCEND 529
280 #define VENDOR_BAY 1584
281 #define VENDOR_REDBACK 2352
282 #define VENDOR_JUNIPER 2636
283 #define VENDOR_COSINE 3085
284 #define VENDOR_UNISPHERE 4874
286 static const value_string avp_vendor_id_vals[] =
287 {{VENDOR_IETF,"IETF"},
289 {VENDOR_CISCO,"Cisco"},
290 {VENDOR_SHIVA,"Shiva"},
291 {VENDOR_LIVINGSTON,"Livingston"},
292 {VENDOR_3COM,"3Com"},
293 {VENDOR_ASCEND,"Ascend"},
294 {VENDOR_BAY,"Bay Networks"},
295 {VENDOR_REDBACK,"Redback"},
296 {VENDOR_JUNIPER,"Juniper Networks"},
297 {VENDOR_COSINE,"CoSine Communications"},
298 {VENDOR_UNISPHERE,"Unisphere Networks"},
301 static gchar textbuffer[200];
303 static dissector_handle_t ppp_hdlc_handle;
306 dissect_l2tp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
308 proto_tree *l2tp_tree=NULL, *l2tp_avp_tree, *ctrl_tree;
313 int proto_length = 0;
314 guint16 length = 0; /* Length field */
315 guint16 tid; /* Tunnel ID */
316 guint16 cid; /* Call ID */
317 guint16 offset_size; /* Offset size */
318 guint16 ver_len_hidden;
319 guint16 avp_vendor_id;
326 guint16 firmware_rev;
330 if (check_col(pinfo->cinfo, COL_PROTOCOL)) /* build output for closed L2tp frame displayed */
331 col_set_str(pinfo->cinfo, COL_PROTOCOL, "L2TP");
332 if (check_col(pinfo->cinfo, COL_INFO))
333 col_clear(pinfo->cinfo, COL_INFO);
335 control = tvb_get_ntohs(tvb, 0);
337 if (L2TP_VERSION(control) != 2) {
338 if (check_col(pinfo->cinfo, COL_INFO)) {
339 col_add_fstr(pinfo->cinfo, COL_INFO, "L2TP Version %u", L2TP_VERSION(control) );
346 if (LENGTH_BIT(control)) { /* length field included ? */
347 index += 2; /* skip ahead */
348 length = tvb_get_ntohs(tvb, index);
351 /* collect the tunnel id & call id */
353 tid = tvb_get_ntohs(tvb, index);
355 cid = tvb_get_ntohs(tvb, index);
357 if (check_col(pinfo->cinfo, COL_INFO)) {
358 if (CONTROL_BIT(control)) {
359 /* CONTROL MESSAGE */
362 if ((LENGTH_BIT(control))&&(length==12)) /* ZLB Message */
363 sprintf(textbuffer,"%s - ZLB (tunnel id=%d, session id=%d)",
364 control_msg , tid ,cid);
367 if (SEQUENCE_BIT(control)) {
373 avp_type = tvb_get_ntohs(tvb, (tmp_index+=2));
375 if (avp_type == CONTROL_MESSAGE)
377 /* We print message type */
378 msg_type = tvb_get_ntohs(tvb, (tmp_index+=2));
379 sprintf(textbuffer,"%s - %s (tunnel id=%d, session id=%d)",
381 ((NUM_CONTROL_CALL_TYPES + 1 ) > msg_type) ?
382 calltype_short_str[msg_type] : "Unknown",
388 * This is not a control message.
389 * We never pass here except in case of bad l2tp packet!
391 sprintf(textbuffer,"%s (tunnel id=%d, session id=%d)",
392 control_msg , tid ,cid);
399 sprintf(textbuffer,"%s (tunnel id=%d, session id=%d)",
402 col_add_fstr(pinfo->cinfo,COL_INFO,textbuffer);
405 if (LENGTH_BIT(control)) {
406 proto_length = length;
409 proto_length = tvb_length(tvb);
413 ti = proto_tree_add_item(tree,proto_l2tp, tvb, 0, proto_length, FALSE);
414 l2tp_tree = proto_item_add_subtree(ti, ett_l2tp);
416 ti = proto_tree_add_text(l2tp_tree, tvb, 0, 2,
417 "Packet Type: %s Tunnel Id=%d Session Id=%d",
418 (CONTROL_BIT(control) ? control_msg : data_msg), tid, cid);
420 ctrl_tree = proto_item_add_subtree(ti, ett_l2tp_ctrl);
421 proto_tree_add_uint(ctrl_tree, hf_l2tp_type, tvb, 0, 2, control);
422 proto_tree_add_boolean(ctrl_tree, hf_l2tp_length_bit, tvb, 0, 2, control);
423 proto_tree_add_boolean(ctrl_tree, hf_l2tp_seq_bit, tvb, 0, 2, control);
424 proto_tree_add_boolean(ctrl_tree, hf_l2tp_offset_bit, tvb, 0, 2, control);
425 proto_tree_add_boolean(ctrl_tree, hf_l2tp_priority, tvb, 0, 2, control);
426 proto_tree_add_uint(ctrl_tree, hf_l2tp_version, tvb, 0, 2, control);
429 if (LENGTH_BIT(control)) {
431 proto_tree_add_item(l2tp_tree, hf_l2tp_length, tvb, index, 2, FALSE);
437 proto_tree_add_item(l2tp_tree, hf_l2tp_tunnel, tvb, index, 2, FALSE);
441 proto_tree_add_item(l2tp_tree, hf_l2tp_session, tvb, index, 2, FALSE);
445 if (SEQUENCE_BIT(control)) {
447 proto_tree_add_item(l2tp_tree, hf_l2tp_Ns, tvb, index, 2, FALSE);
451 proto_tree_add_item(l2tp_tree, hf_l2tp_Nr, tvb, index, 2, FALSE);
455 if (OFFSET_BIT(control)) {
456 offset_size = tvb_get_ntohs(tvb, index);
458 proto_tree_add_uint(l2tp_tree, hf_l2tp_offset, tvb, index, 2,
463 proto_tree_add_text(l2tp_tree, tvb, index, offset_size, "Offset Padding");
465 index += offset_size;
467 if (tree && (LENGTH_BIT(control))&&(length==12)) {
468 proto_tree_add_text(l2tp_tree, tvb, 0, 0, "Zero Length Bit message");
471 if (!CONTROL_BIT(control)) { /* Data Messages so we are done */
472 /* If we have data, signified by having a length bit, dissect it */
473 if (tvb_offset_exists(tvb, index)) {
474 next_tvb = tvb_new_subset(tvb, index, -1, proto_length - index);
475 call_dissector(ppp_hdlc_handle, next_tvb, pinfo, tree);
481 if (!LENGTH_BIT(control)) {
484 while (index < length ) { /* Process AVP's */
485 ver_len_hidden = tvb_get_ntohs(tvb, index);
486 avp_len = AVP_LENGTH(ver_len_hidden);
487 avp_vendor_id = tvb_get_ntohs(tvb, index + 2);
488 avp_type = tvb_get_ntohs(tvb, index + 4);
490 if (avp_vendor_id == VENDOR_IETF) {
491 tf = proto_tree_add_text(l2tp_tree, tvb, index,
493 val_to_str(avp_type, avp_type_vals, "Unknown (%u)"));
494 } else { /* Vendor-Specific AVP */
495 tf = proto_tree_add_text(l2tp_tree, tvb, index,
496 avp_len, "Vendor %s AVP",
497 val_to_str(avp_vendor_id, avp_vendor_id_vals, "Unknown (%u)"));
500 l2tp_avp_tree = proto_item_add_subtree(tf, ett_l2tp_avp);
502 proto_tree_add_boolean_format(l2tp_avp_tree,hf_l2tp_avp_mandatory, tvb, index, 1,
503 rhcode, "Mandatory: %s",
504 (MANDATORY_BIT(ver_len_hidden)) ? "True" : "False" );
505 proto_tree_add_boolean_format(l2tp_avp_tree,hf_l2tp_avp_hidden, tvb, index, 1,
506 rhcode, "Hidden: %s",
507 (HIDDEN_BIT(ver_len_hidden)) ? "True" : "False" );
508 proto_tree_add_uint_format(l2tp_avp_tree,hf_l2tp_avp_length, tvb, index, 2,
509 rhcode, "Length: %u", avp_len);
510 if (HIDDEN_BIT(ver_len_hidden)) { /* don't try do display hidden */
516 proto_tree_add_text(l2tp_avp_tree, tvb, index, 0,
517 "AVP length must not be zero");
523 proto_tree_add_item(l2tp_avp_tree, hf_l2tp_avp_vendor_id,
524 tvb, index, 2, FALSE);
528 if (avp_vendor_id != VENDOR_IETF) {
529 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
530 "Type: %u", avp_type);
534 /* For the time being, we don't decode any Vendor-
536 proto_tree_add_text(l2tp_avp_tree, tvb, index,
537 avp_len, "Vendor-Specific AVP");
543 proto_tree_add_uint(l2tp_avp_tree, hf_l2tp_avp_type,
544 tvb, index, 2, avp_type);
550 case CONTROL_MESSAGE:
551 msg_type = tvb_get_ntohs(tvb, index);
552 proto_tree_add_text(l2tp_avp_tree,tvb, index, 2,
553 "Control Message Type: (%u) %s", msg_type,
554 ((NUM_CONTROL_CALL_TYPES + 1 ) > msg_type) ?
555 calltypestr[msg_type] : "Unknown");
558 case RESULT_ERROR_CODE:
561 result_code = tvb_get_ntohs(tvb, index);
562 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
563 "Result code: %u", result_code);
569 error_code = tvb_get_ntohs(tvb, index);
570 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
571 "Error code: %u", error_code);
577 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
578 "Error Message: %.*s", avp_len,
579 tvb_get_ptr(tvb, index, avp_len));
582 case PROTOCOL_VERSION:
585 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
586 "Version: %u", tvb_get_guint8(tvb, index));
590 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
591 "Revision: %u", tvb_get_guint8(tvb, index));
594 case FRAMING_CAPABILITIES:
595 bits = tvb_get_ntohl(tvb, index);
596 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
597 "Async Framing Supported: %s",
598 (FRAMING_ASYNC(bits)) ? "True" : "False");
599 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
600 "Sync Framing Supported: %s",
601 (FRAMING_SYNC(bits)) ? "True" : "False");
604 case BEARER_CAPABILITIES:
605 bits = tvb_get_ntohl(tvb, index);
606 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
607 "Analog Access Supported: %s",
608 (BEARER_ANALOG(bits)) ? "True" : "False");
609 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
610 "Digital Access Supported: %s",
611 (BEARER_DIGITAL(bits)) ? "True" : "False");
615 proto_tree_add_item(l2tp_avp_tree, hf_l2tp_tie_breaker, tvb, index, 8, FALSE);
618 case FIRMWARE_REVISION:
619 firmware_rev = tvb_get_ntohs(tvb, index);
620 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
621 "Firmware Revision: %d 0x%x", firmware_rev,firmware_rev );
625 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
626 "Host Name: %.*s", avp_len,
627 tvb_get_ptr(tvb, index, avp_len));
631 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
632 "Vendor Name: %.*s", avp_len,
633 tvb_get_ptr(tvb, index, avp_len));
636 case ASSIGNED_TUNNEL_ID:
637 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
638 "Tunnel ID: %u", tvb_get_ntohs(tvb, index));
641 case RECEIVE_WINDOW_SIZE:
642 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
643 "Receive Window Size: %u",
644 tvb_get_ntohs(tvb, index));
648 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
649 "CHAP Challenge: %s",
650 tvb_bytes_to_str(tvb, index, avp_len));
655 * XXX - export stuff from the Q.931 dissector
656 * to dissect the cause code and cause message,
661 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
663 tvb_get_ntohs(tvb, index));
669 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
671 tvb_get_guint8(tvb, index));
677 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
678 "Advisory Msg: %.*s", avp_len,
679 tvb_get_ptr(tvb, index, avp_len));
682 case CHALLENGE_RESPONSE:
683 proto_tree_add_text(l2tp_avp_tree, tvb, index, 16,
684 "CHAP Challenge Response: %s",
685 tvb_bytes_to_str(tvb, index, 16));
688 case ASSIGNED_SESSION:
689 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
690 "Assigned Session: %u",
691 tvb_get_ntohs(tvb, index));
694 case CALL_SERIAL_NUMBER:
695 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
696 "Call Serial Number: %u",
697 tvb_get_ntohl(tvb, index));
701 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
703 tvb_get_ntohl(tvb, index));
707 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
709 tvb_get_ntohl(tvb, index));
713 bits = tvb_get_ntohl(tvb, index);
714 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
715 "Analog Bearer Type: %s",
716 (BEARER_ANALOG(bits)) ? "True" : "False");
717 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
718 "Digital Bearer Type: %s",
719 (BEARER_DIGITAL(bits)) ? "True" : "False");
723 bits = tvb_get_ntohl(tvb, index);
724 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
725 "Async Framing Type: %s",
726 (FRAMING_ASYNC(bits)) ? "True" : "False");
727 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
728 "Sync Framing Type: %s",
729 (FRAMING_SYNC(bits)) ? "True" : "False");
735 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
736 "Called Number: %.*s", avp_len,
737 tvb_get_ptr(tvb, index, avp_len));
743 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
744 "Calling Number: %.*s", avp_len,
745 tvb_get_ptr(tvb, index, avp_len));
751 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
752 "Sub-Address: %.*s", avp_len,
753 tvb_get_ptr(tvb, index, avp_len));
756 case TX_CONNECT_SPEED:
757 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
759 tvb_get_ntohl(tvb, index));
762 case PHYSICAL_CHANNEL:
763 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
764 "Physical Channel: %u",
765 tvb_get_ntohl(tvb, index));
768 case INITIAL_RECEIVED_LCP:
770 * XXX - can this be dissected by stuff in the
773 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
774 "Initial LCP CONFREQ: %s",
775 tvb_bytes_to_str(tvb, index, avp_len));
778 case LAST_SEND_LCP_CONFREQ:
780 * XXX - can this be dissected by stuff in the
783 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
784 "Last Sent LCP CONFREQ: %s",
785 tvb_bytes_to_str(tvb, index, avp_len));
788 case LAST_RECEIVED_LCP_CONFREQ:
790 * XXX - can this be dissected by stuff in the
793 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
794 "Last Received LCP CONFREQ: %s",
795 tvb_bytes_to_str(tvb, index, avp_len));
798 case PROXY_AUTHEN_TYPE:
799 msg_type = tvb_get_ntohs(tvb, index);
800 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
801 "Proxy Authen Type: %s",
802 val_to_str(msg_type, authen_type_vals, "Unknown (%u)"));
805 case PROXY_AUTHEN_NAME:
808 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
809 "Proxy Authen Name: %.*s", avp_len,
810 tvb_get_ptr(tvb, index, avp_len));
813 case PROXY_AUTHEN_CHALLENGE:
814 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
815 "Proxy Authen Challenge: %s",
816 tvb_bytes_to_str(tvb, index, avp_len));
819 case PROXY_AUTHEN_ID:
820 proto_tree_add_text(l2tp_avp_tree, tvb, index + 1, 1,
821 "Proxy Authen ID: %u",
822 tvb_get_guint8(tvb, index + 1));
825 case PROXY_AUTHEN_RESPONSE:
826 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
827 "Proxy Authen Response: %s",
828 tvb_bytes_to_str(tvb, index, avp_len));
831 case CALL_STATUS_AVPS:
839 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
840 "CRC Errors: %u", tvb_get_ntohl(tvb, index));
846 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
847 "Framing Errors: %u", tvb_get_ntohl(tvb, index));
853 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
854 "Hardware Overruns: %u", tvb_get_ntohl(tvb, index));
860 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
861 "Buffer Overruns: %u", tvb_get_ntohl(tvb, index));
867 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
868 "Time-out Errors: %u", tvb_get_ntohl(tvb, index));
874 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
875 "Alignment Errors: %u", tvb_get_ntohl(tvb, index));
888 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
889 "Send ACCM: %u", tvb_get_ntohl(tvb, index));
895 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
896 "Receive ACCM: %u", tvb_get_ntohl(tvb, index));
902 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
904 tvb_bytes_to_str(tvb, index, avp_len));
907 case PRIVATE_GROUP_ID:
908 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
909 "Private Group ID: %s",
910 tvb_bytes_to_str(tvb, index, avp_len));
913 case RX_CONNECT_SPEED:
914 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
915 "Rx Connect Speed: %u",
916 tvb_get_ntohl(tvb, index));
919 case PPP_DISCONNECT_CAUSE_CODE:
922 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
923 "Disconnect Code: %u",
924 tvb_get_ntohs(tvb, index));
930 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
931 "Control Protocol Number: %u",
932 tvb_get_ntohs(tvb, index));
938 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
940 val_to_str(tvb_get_guint8(tvb, index),
941 cause_code_direction_vals,
948 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
949 "Message: %.*s", avp_len,
950 tvb_get_ptr(tvb, index, avp_len));
954 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
959 /* printf("Avp Decode avp_len= %d index= %d length= %d %x\n ",avp_len,
960 index,length,length); */
968 /* registration with the filtering engine */
970 proto_register_l2tp(void)
972 static hf_register_info hf[] = {
974 { "Type", "l2tp.type", FT_UINT16, BASE_DEC, VALS(l2tp_type_vals), 0x8000,
975 "Type bit", HFILL }},
977 { &hf_l2tp_length_bit,
978 { "Length Bit", "l2tp.length_bit", FT_BOOLEAN, 16, TFS(&l2tp_length_bit_truth), 0x4000,
979 "Length bit", HFILL }},
982 { "Sequence Bit", "l2tp.seq_bit", FT_BOOLEAN, 16, TFS(&l2tp_seq_bit_truth), 0x0800,
983 "Sequence bit", HFILL }},
985 { &hf_l2tp_offset_bit,
986 { "Offset bit", "l2tp.offset_bit", FT_BOOLEAN, 16, TFS(&l2tp_offset_bit_truth), 0x0200,
987 "Offset bit", HFILL }},
990 { "Priority", "l2tp.priority", FT_BOOLEAN, 16, TFS(&l2tp_priority_truth), 0x0100,
991 "Priority bit", HFILL }},
994 { "Version", "l2tp.version", FT_UINT16, BASE_DEC, NULL, 0x000f,
998 { "Length","l2tp.length", FT_UINT16, BASE_DEC, NULL, 0x0,
1002 { "Tunnel ID","l2tp.tunnel", FT_UINT16, BASE_DEC, NULL, 0x0, /* Probably should be FT_BYTES */
1003 "Tunnel ID", HFILL }},
1006 { "Session ID","l2tp.session", FT_UINT16, BASE_DEC, NULL, 0x0, /* Probably should be FT_BYTES */
1007 "Session ID", HFILL }},
1010 { "Ns","l2tp.Ns", FT_UINT16, BASE_DEC, NULL, 0x0,
1014 { "Nr","l2tp.Nr", FT_UINT16, BASE_DEC, NULL, 0x0,
1018 { "Offset","l2tp.offset", FT_UINT16, BASE_DEC, NULL, 0x0,
1019 "Number of octest past the L2TP header at which the"
1020 "payload data starts.", HFILL }},
1022 { &hf_l2tp_avp_mandatory,
1023 { "Mandatory", "l2tp.avp.mandatory", FT_BOOLEAN, BASE_NONE, NULL, 0,
1024 "Mandatory AVP", HFILL }},
1026 { &hf_l2tp_avp_hidden,
1027 { "Hidden", "l2tp.avp.hidden", FT_BOOLEAN, BASE_NONE, NULL, 0,
1028 "Hidden AVP", HFILL }},
1030 { &hf_l2tp_avp_length,
1031 { "Length", "l2tp.avp.length", FT_UINT16, BASE_DEC, NULL, 0,
1032 "AVP Length", HFILL }},
1034 { &hf_l2tp_avp_vendor_id,
1035 { "Vendor ID", "l2tp.avp.vendor_id", FT_UINT16, BASE_DEC, VALS(avp_vendor_id_vals), 0,
1036 "AVP Vendor ID", HFILL }},
1038 { &hf_l2tp_avp_type,
1039 { "Type", "l2tp.avp.type", FT_UINT16, BASE_DEC, VALS(avp_type_vals), 0,
1040 "AVP Type", HFILL }},
1042 { &hf_l2tp_tie_breaker,
1043 { "Tie Breaker", "l2tp.tie_breaker", FT_UINT64, BASE_HEX, NULL, 0,
1044 "Tie Breaker", HFILL }},
1048 static gint *ett[] = {
1054 proto_l2tp = proto_register_protocol(
1055 "Layer 2 Tunneling Protocol", "L2TP", "l2tp");
1056 proto_register_field_array(proto_l2tp, hf, array_length(hf));
1057 proto_register_subtree_array(ett, array_length(ett));
1061 proto_reg_handoff_l2tp(void)
1063 dissector_handle_t l2tp_handle;
1065 l2tp_handle = create_dissector_handle(dissect_l2tp, proto_l2tp);
1066 dissector_add("udp.port", UDP_PORT_L2TP, l2tp_handle);
1069 * Get a handle for the PPP-in-HDLC-like-framing dissector.
1071 ppp_hdlc_handle = find_dissector("ppp_hdlc");