From Didier Gautheron:
[obnox/wireshark/wip.git] / epan / dissectors / packet-l2tp.c
1 /* packet-l2tp.c
2  * Routines for Layer Two Tunnelling Protocol (L2TP) packet disassembly
3  * John Thomes <john@ensemblecom.com>
4  *
5  * Minor changes by: (2000-01-10)
6  * Laurent Cazalet <laurent.cazalet@mailclub.net>
7  * Thomas Parvais <thomas.parvais@advalvas.be>
8  *
9  * $Id$
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 /*
31  * RFC 2661 for L2TPv2
32  * http://tools.ietf.org/html/rfc2661
33  *
34  * RFC 3931 for L2TPv3
35  * http://tools.ietf.org/html/rfc3931
36  *
37  * Layer Two Tunneling Protocol "L2TP" number assignments:
38  *      http://www.iana.org/assignments/l2tp-parameters
39  *
40  * Pseudowire types:
41  *
42  * RFC 4591 for Frame Relay
43  * http://tools.ietf.org/html/rfc4591
44  *
45  * RFC 4454 for ATM
46  * http://tools.ietf.org/html/rfc4454
47  *
48  * RFC 4719 for Ethernet
49  * http://tools.ietf.org/html/rfc4719
50  *
51  * RFC 4349 for HDLC
52  * http://tools.ietf.org/html/rfc4349
53  *
54  * XXX - what about LAPD?
55  */
56
57 static int proto_l2tp = -1;
58 static int hf_l2tp_type = -1;
59 static int hf_l2tp_length_bit = -1;
60 static int hf_l2tp_seq_bit = -1;
61 static int hf_l2tp_offset_bit = -1;
62 static int hf_l2tp_priority = -1;
63 static int hf_l2tp_version = -1;
64 static int hf_l2tp_length = -1;
65 static int hf_l2tp_tunnel = -1;
66 static int hf_l2tp_session = -1;
67 static int hf_l2tp_Ns = -1;
68 static int hf_l2tp_Nr = -1;
69 static int hf_l2tp_offset = -1;
70 static int hf_l2tp_avp_mandatory = -1;
71 static int hf_l2tp_avp_hidden = -1;
72 static int hf_l2tp_avp_length = -1;
73 static int hf_l2tp_avp_vendor_id = -1;
74 static int hf_l2tp_avp_type = -1;
75 static int hf_l2tp_tie_breaker = -1;
76 static int hf_l2tp_sid = -1;
77 static int hf_l2tp_res = -1;
78 static int hf_l2tp_ccid = -1;
79 static int hf_l2tp_cookie = -1;
80 static int hf_l2tp_l2_spec_def = -1;
81 static int hf_l2tp_l2_spec_atm = -1;
82 static int hf_l2tp_l2_spec_s = -1;
83 static int hf_l2tp_l2_spec_sequence = -1;
84 static int hf_l2tp_l2_spec_t = -1;
85 static int hf_l2tp_l2_spec_g = -1;
86 static int hf_l2tp_l2_spec_c = -1;
87 static int hf_l2tp_l2_spec_u = -1;
88 static int hf_l2tp_cisco_avp_type = -1;
89
90 #ifdef HAVE_CONFIG_H
91 #include "config.h"
92 #endif
93
94 #include <stdio.h>
95 #include <stdlib.h>
96 #include <string.h>
97 #include <ctype.h>
98 #include <glib.h>
99 #include <epan/packet.h>
100 #include <epan/addr_resolv.h>
101 #include <epan/ipproto.h>
102 #include <epan/sminmpec.h>
103 #include <epan/prefs.h>
104
105 #define UDP_PORT_L2TP   1701
106
107 #define CONTROL_BIT(msg_info) (msg_info & 0x8000)   /* Type bit control = 1 data = 0 */
108 #define LENGTH_BIT(msg_info) (msg_info & 0x4000)    /* Length bit = 1  */
109 #define RESERVE_BITS(msg_info) (msg_info &0x37F8)   /* Reserved bit - usused */
110 #define SEQUENCE_BIT(msg_info) (msg_info & 0x0800)  /* SEQUENCE bit = 1 Ns and Nr fields */
111 #define OFFSET_BIT(msg_info) (msg_info & 0x0200)    /* Offset */
112 #define PRIORITY_BIT(msg_info) (msg_info & 0x0100)  /* Priority */
113 #define L2TP_VERSION(msg_info) (msg_info & 0x000f)  /* Version of l2tp */
114 #define MANDATORY_BIT(msg_info) (msg_info & 0x8000) /* Mandatory = 1 */
115 #define HIDDEN_BIT(msg_info) (msg_info & 0x4000)    /* Hidden = 1 */
116 #define AVP_LENGTH(msg_info) (msg_info & 0x03ff)    /* AVP Length */
117 #define FRAMING_SYNC(msg_info)  (msg_info & 0x0001) /* SYNC Framing Type */
118 #define FRAMING_ASYNC(msg_info) (msg_info & 0x0002) /* ASYNC Framing Type */
119 #define BEARER_DIGITAL(msg_info) (msg_info & 0x0001) /* Digital Bearer Type */
120 #define BEARER_ANALOG(msg_info) (msg_info & 0x0002) /* Analog Bearer Type */
121 #define CIRCUIT_STATUS_BIT(msg_info) (msg_info & 0x0001)        /* Circuit Status */
122 #define CIRCUIT_TYPE_BIT(msg_info) (msg_info & 0x0001)          /* Circuit Condition */
123
124 static gint ett_l2tp = -1;
125 static gint ett_l2tp_ctrl = -1;
126 static gint ett_l2tp_avp = -1;
127 static gint ett_l2tp_avp_sub = -1;
128 static gint ett_l2tp_lcp = -1;
129 static gint ett_l2tp_l2_spec = -1;
130
131 static enum_val_t l2tpv3_cookies[] = {
132     {"cookie0", "None",                 0},
133     {"cookie4", "4 Byte Cookie",        4},
134     {"cookie8", "8 Byte Cookie",        8},
135     {NULL, NULL, 0}
136 };
137
138 #define L2TPv3_PROTOCOL_ETH     0
139 #define L2TPv3_PROTOCOL_CHDLC   1
140 #define L2TPv3_PROTOCOL_FR      2
141 #define L2TPv3_PROTOCOL_PPP     3
142 #define L2TPv3_PROTOCOL_IP      4
143 #define L2TPv3_PROTOCOL_MPLS    5
144 #define L2TPv3_PROTOCOL_AAL5    6
145 #define L2TPv3_PROTOCOL_LAPD    7
146
147 static enum_val_t l2tpv3_protocols[] = {
148     {"eth",     "Ethernet",     L2TPv3_PROTOCOL_ETH},
149     {"chdlc",   "Cisco HDLC",   L2TPv3_PROTOCOL_CHDLC},
150     {"fr",      "Frame Relay",  L2TPv3_PROTOCOL_FR},
151     {"ppp",     "PPP",          L2TPv3_PROTOCOL_PPP},
152     {"ip",      "IP",           L2TPv3_PROTOCOL_IP},
153     {"mpls",    "MPLS",         L2TPv3_PROTOCOL_MPLS},
154     {"aal5",    "AAL5",         L2TPv3_PROTOCOL_AAL5},
155     {"lapd",    "LAPD",         L2TPv3_PROTOCOL_LAPD},
156     {NULL, NULL, 0}
157 };
158
159 #define L2TPv3_L2_SPECIFIC_NONE         0
160 #define L2TPv3_L2_SPECIFIC_DEFAULT      1
161 #define L2TPv3_L2_SPECIFIC_ATM          2
162 #define L2TPv3_L2_SPECIFIC_LAPD         3
163
164 static enum_val_t l2tpv3_l2_specifics[] = {
165     {"none",    "None",                 L2TPv3_L2_SPECIFIC_NONE},
166     {"default", "Default L2-Specific",  L2TPv3_L2_SPECIFIC_DEFAULT},
167     {"atm",     "ATM-Specific",         L2TPv3_L2_SPECIFIC_ATM},
168     {"lapd",    "LAPD-Specific",        L2TPv3_L2_SPECIFIC_LAPD},
169     {NULL, NULL, 0}
170 };
171
172 static gint l2tpv3_cookie = 4;
173 static gint l2tpv3_protocol = L2TPv3_PROTOCOL_CHDLC;
174 static gint l2tpv3_l2_specific = L2TPv3_L2_SPECIFIC_DEFAULT;
175
176 #define AVP_SCCRQ      1
177 #define AVP_SCCRP      2
178 #define AVP_SCCCN      3
179 #define AVP_StopCCN    4
180 #define AVP_Reserved   5
181 #define AVP_HELLO      6
182 #define AVP_OCRQ       7
183 #define AVP_OCRP       8
184 #define AVP_ORCRP      9
185 #define AVP_ICRQ      10
186 #define AVP_ICRP      11
187 #define AVP_ICCN      12
188 #define AVP_Reserved1 13
189 #define AVP_CDN       14
190
191 #define NUM_CONTROL_CALL_TYPES  27
192 static const char *calltypestr[NUM_CONTROL_CALL_TYPES+1] = {
193   "Unknown Call Type",
194   "Start_Control_Request",
195   "Start_Control_Reply",
196   "Start_Control_Connected",
197   "Stop_Control_Notification",
198   "Reserved",                                                   /* 5*/
199   "Hello",
200   "Outgoing_Call_Request",
201   "Outgoing_Call_Reply",
202   "Outgoing_Call_Connected",
203   "Incoming_Call_Request",                              /* 10 */
204   "Incoming_Call_Reply",
205   "Incoming_Call_Connected",
206   "Reserved",                                                   /* 13 */
207   "Call_Disconnect_Notification",
208   "WAN_Error_Notify",                                   /* 15 */
209   "Set_Link_Info",
210   "Modem_Status",
211   "Service_Relay_Request_Msg",
212   "Service_Relay_Reply_Message",
213   "Explicit_Acknowledgement",                   /* 20 */
214   "Failover_Session_Query_Message",             /* 21 [RFC4951] */
215   "Failover_Session_Response_Message",  /* 22 [RFC4951] */
216   /* Multicast Management */
217   "Multicast-Session-Request",                  /* 23 [RFC4045]*/
218   "Multicast-Session-Response ",                /* 24 [RFC4045]*/
219   "Multicast-Session-Establishment",    /* 25 [RFC4045]*/
220   "Multicast-Session-Information",              /* 26 [RFC4045]*/
221   "Multicast-Session-End-Notify",               /* 27 [RFC4045]*/
222
223 };
224
225 static const char *calltype_short_str[NUM_CONTROL_CALL_TYPES+1] = {
226   "Unknown ",
227   "SCCRQ   ",
228   "SCCRP   ",
229   "SCCCN   ",
230   "StopCCN ",
231   "Reserved", /* 5 */
232   "Hello   ",
233   "OCRQ    ",
234   "OCRP    ",
235   "OCCN    ",
236   "ICRQ    ", /* 10 */
237   "ICRP    ",
238   "ICCN    ",
239   "Reserved",
240   "CDN     ",
241   "WEN     ", /* 15 */
242   "SLI     ",
243   "MDMST   ",
244   "SRRQ    ",
245   "SRRP    ",
246   "ACK     ", /* 20 */
247   "FSQ     ", 
248   "FSR     ", 
249   "MSRQ    ", 
250   "MSRP    ", 
251   "MSE     ", /* 25 */
252   "MSI     ", 
253   "MSEN    ", 
254
255 };
256
257
258 static const char *control_msg  = "Control Message";
259 static const char *data_msg     = "Data    Message";
260 static const value_string l2tp_type_vals[] = {
261         { 0, "Data Message" },
262         { 1, "Control Message" },
263         { 0, NULL },
264 };
265
266 static const value_string cause_code_direction_vals[] = {
267         { 0, "global error" },
268         { 1, "at peer" },
269         { 2, "at local" },
270         { 0, NULL },
271 };
272
273 static const true_false_string l2tp_length_bit_truth =
274         { "Length field is present", "Length field is not present" };
275
276 static const true_false_string l2tp_seq_bit_truth =
277         { "Ns and Nr fields are present", "Ns and Nr fields are not present" };
278
279 static const true_false_string l2tp_offset_bit_truth =
280         { "Offset Size field is present", "Offset size field is not present" };
281
282 static const true_false_string l2tp_priority_truth =
283         { "This data message has priority", "No priority" };
284
285 static const value_string authen_type_vals[] = {
286   { 0, "Reserved" },
287   { 1, "Textual username/password exchange" },
288   { 2, "PPP CHAP" },
289   { 3, "PPP PAP" },
290   { 4, "No Authentication" },
291   { 5, "Microsoft CHAP Version 1" },
292   { 6, "Reserved" },
293   { 7, "EAP" },
294   { 0, NULL }
295 };
296
297 static const value_string data_sequencing_vals[] = {
298   { 0, "No incoming data packets require sequencing" },
299   { 1, "Only non-IP data packets require sequencing" },
300   { 2, "All incoming data packets require sequencing" },
301   { 0, NULL }
302 };
303
304 static const value_string l2_sublayer_vals[] = {
305   { 0, "No L2-Specific Sublayer" },
306   { 1, "Default L2-Specific Sublayer present" },
307   { 2, "ATM-Specific Sublayer present" },
308   { 3, "MPT-Specific Sublayer" },
309   { 4, "PSP-Specific Sublayer" },
310   { 0, NULL }
311 };
312
313 static const value_string result_code_stopccn_vals[] = {
314   { 0, "Reserved", },
315   { 1, "General request to clear control connection", },
316   { 2, "General error, Error Code indicates the problem", },
317   { 3, "Control connection already exists", },
318   { 4, "Requester is not authorized to establish a control connection", },
319   { 5, "The protocol version of the requester is not supported", },
320   { 6, "Requester is being shut down", },
321   { 7, "Finite state machine error or timeout", },
322   { 8, "Control connection due to mismatching CCDS value", }, /* [RFC3308] */
323   { 0, NULL }
324 };
325
326 static const value_string result_code_cdn_vals[] = {
327   { 0, "Reserved", },
328   { 1, "Session disconnected due to loss of carrier or circuit disconnect", },
329   { 2, "Session disconnected for the reason indicated in Error Code", },
330   { 3, "Session disconnected for administrative reasons", },
331   { 4, "Appropriate facilities unavailable (temporary condition)", },
332   { 5, "Appropriate facilities unavailable (permanent condition)", },
333   { 6, "Invalid destination", },
334   { 7, "Call failed due to no carrier detected", },
335   { 8, "Call failed due to detection of a busy signal", },
336   { 9, "Call failed due to lack of a dial tone", },
337   { 10, "Call was not established within time allotted by LAC", },
338   { 11, "Call was connected but no appropriate framing was detected", },
339   { 12, "Disconnecting call due to mismatching SDS value", },
340   { 13, "Session not established due to losing tie breaker", },
341   { 14, "Session not established due to unsupported PW type", },
342   { 15, "Session not established, sequencing required without valid L2-Specific Sublayer", },
343   { 16, "Finite state machine error or timeout", },
344   { 17, "FR PVC was deleted permanently (no longer provisioned) ", },      /* [RFC4591] */
345   { 18, "FR PVC has been INACTIVE for an extended period of time", },      /* [RFC4591] */
346   { 19, "Mismatched FR Header Length", },                                  /* [RFC4591] */
347   { 20, "HDLC Link was deleted permanently (no longer provisioned)", },    /* [RFC4349] */
348   { 21, "HDLC Link has been INACTIVE for an extended period of time", },   /* [RFC4349] */
349   { 22, "Session not established due to other LCCE can not support the OAM Cell Emulation", },    /* [RFC4454] */
350   { 23, "Mismatching interface MTU", },                                    /* [RFC4667] */
351   { 24, "Attempt to connect to non-existent forwarder", },                 /* [RFC4667] */
352   { 25, "Attempt to connect to unauthorized forwarder", },                 /* [RFC4667] */
353   { 26, "Loop Detected", },                                                /* [draft-ietf-l2tpext-tunnel-switching-06.txt] */
354
355
356   { 0, NULL }
357 };
358
359 static const value_string error_code_vals[] = {
360   { 0, "No General Error", },
361   { 1, "No control connection exists yet for this pair of LCCEs", },
362   { 2, "Length is wrong", },
363   { 3, "One of the field values was out of range", },
364   { 4, "Insufficient resources to handle this operation now", },
365   { 5, "Invalid Session ID", },
366   { 6, "A generic vendor-specific error occurred", },
367   { 7, "Try another", },
368   { 8, "Receipt of an unknown AVP with the M bit set", },
369   { 9, "Try another directed", },
370   { 10, "Next hop unreachable", },
371   { 11, "Next hop busy", },
372   { 12, "TSA busy", },
373   { 0, NULL }
374 };
375
376 #define  CONTROL_MESSAGE  0
377 #define  RESULT_ERROR_CODE 1
378 #define  PROTOCOL_VERSION  2
379 #define  FRAMING_CAPABILITIES 3
380 #define  BEARER_CAPABILITIES 4
381 #define  TIE_BREAKER 5
382 #define  FIRMWARE_REVISION 6
383 #define  HOST_NAME 7
384 #define  VENDOR_NAME 8
385 #define  ASSIGNED_TUNNEL_ID 9
386 #define  RECEIVE_WINDOW_SIZE 10
387 #define  CHALLENGE 11
388 #define  CAUSE_CODE 12
389 #define  CHALLENGE_RESPONSE 13
390 #define  ASSIGNED_SESSION 14
391 #define  CALL_SERIAL_NUMBER 15
392 #define  MINIMUM_BPS 16
393 #define  MAXIMUM_BPS 17
394 #define  BEARER_TYPE 18
395 #define  FRAMING_TYPE 19
396 #define  CALLED_NUMBER 21
397 #define  CALLING_NUMBER 22
398 #define  SUB_ADDRESS 23
399 #define  TX_CONNECT_SPEED 24
400 #define  PHYSICAL_CHANNEL 25
401 #define  INITIAL_RECEIVED_LCP_CONFREQ 26
402 #define  LAST_SENT_LCP_CONFREQ 27
403 #define  LAST_RECEIVED_LCP_CONFREQ 28
404 #define  PROXY_AUTHEN_TYPE 29
405 #define  PROXY_AUTHEN_NAME 30
406 #define  PROXY_AUTHEN_CHALLENGE 31
407 #define  PROXY_AUTHEN_ID 32
408 #define  PROXY_AUTHEN_RESPONSE 33
409 #define  CALL_STATUS_AVPS 34
410 #define  ACCM 35
411 #define  RANDOM_VECTOR 36
412 #define  PRIVATE_GROUP_ID 37
413 #define  RX_CONNECT_SPEED 38
414 #define  SEQUENCING_REQUIRED 39
415 #define  PPP_DISCONNECT_CAUSE_CODE 46   /* RFC 3145 */
416 #define  EXTENDED_VENDOR_ID                     58
417 #define  MESSAGE_DIGEST                         59
418 #define  ROUTER_ID                                      60
419 #define  ASSIGNED_CONTROL_CONN_ID       61
420 #define  PW_CAPABILITY_LIST                     62
421 #define  LOCAL_SESSION_ID                       63
422 #define  REMOTE_SESSION_ID                      64
423 #define  ASSIGNED_COOKIE                        65
424 #define  REMOTE_END_ID                          66
425 #define  PW_TYPE                                        68
426 #define  L2_SPECIFIC_SUBLAYER           69
427 #define  DATA_SEQUENCING                        70
428 #define  CIRCUIT_STATUS                         71
429 #define  PREFERRED_LANGUAGE                     72
430 #define  CTL_MSG_AUTH_NONCE                     73
431 #define  TX_CONNECT_SPEED_V3            74
432 #define  RX_CONNECT_SPEED_V3            75
433
434 #define NUM_AVP_TYPES  96
435 static const value_string avp_type_vals[] = {
436   { CONTROL_MESSAGE,           "Control Message" },
437   { RESULT_ERROR_CODE,         "Result-Error Code" },
438   { PROTOCOL_VERSION,          "Protocol Version" },
439   { FRAMING_CAPABILITIES,      "Framing Capabilities" },
440   { BEARER_CAPABILITIES,       "Bearer Capabilities" },
441   { TIE_BREAKER,               "Tie Breaker" },
442   { FIRMWARE_REVISION,         "Firmware Revision" },
443   { HOST_NAME,                 "Host Name" },
444   { VENDOR_NAME,               "Vendor Name" },
445   { ASSIGNED_TUNNEL_ID,        "Assigned Tunnel ID" },
446   { RECEIVE_WINDOW_SIZE,       "Receive Window Size" },
447   { CHALLENGE,                 "Challenge" },
448   { CAUSE_CODE,                "Cause Code" },
449   { CHALLENGE_RESPONSE,        "Challenge Response" },
450   { ASSIGNED_SESSION,          "Assigned Session" },
451   { CALL_SERIAL_NUMBER,        "Call Serial Number" },
452   { MINIMUM_BPS,               "Minimum BPS" },
453   { MAXIMUM_BPS,               "Maximum BPS" },
454   { BEARER_TYPE,               "Bearer Type" },
455   { FRAMING_TYPE,              "Framing Type" },
456   { CALLED_NUMBER,             "Called Number" },
457   { CALLING_NUMBER,            "Calling Number" },
458   { SUB_ADDRESS,               "Sub-Address" },
459   { TX_CONNECT_SPEED,          "Connect Speed" },
460   { PHYSICAL_CHANNEL,          "Physical Channel" },
461   { INITIAL_RECEIVED_LCP_CONFREQ, "Initial Received LCP CONFREQ" },
462   { LAST_SENT_LCP_CONFREQ,     "Last Sent LCP CONFREQ" },
463   { LAST_RECEIVED_LCP_CONFREQ, "Last Received LCP CONFREQ" },
464   { PROXY_AUTHEN_TYPE,         "Proxy Authen Type" },
465   { PROXY_AUTHEN_NAME,         "Proxy Authen Name" },
466   { PROXY_AUTHEN_CHALLENGE,    "Proxy Authen Challenge" },
467   { PROXY_AUTHEN_ID,           "Proxy Authen ID" },
468   { PROXY_AUTHEN_RESPONSE,     "Proxy Authen Response" },
469   { CALL_STATUS_AVPS,          "Call status AVPs" },
470   { ACCM,                      "ACCM" },
471   { RANDOM_VECTOR,             "Random Vector" },
472   { PRIVATE_GROUP_ID,          "Private group ID" },
473   { RX_CONNECT_SPEED,          "RxConnect Speed" },
474   { SEQUENCING_REQUIRED,       "Sequencing Required" },
475   { PPP_DISCONNECT_CAUSE_CODE, "PPP Disconnect Cause Code" },
476   { EXTENDED_VENDOR_ID,        "Extended Vendor ID" },
477   { MESSAGE_DIGEST,            "Message Digest" },
478   { ROUTER_ID,                 "Router ID" },
479   { ASSIGNED_CONTROL_CONN_ID,  "Assigned Control Connection ID" },
480   { PW_CAPABILITY_LIST,        "Pseudowire Capability List" },
481   { LOCAL_SESSION_ID,          "Local Session ID" },
482   { REMOTE_SESSION_ID,         "Remote Session ID" },
483   { ASSIGNED_COOKIE,           "Assigned Cookie" },
484   { REMOTE_END_ID,             "Remote End ID" },
485   { PW_TYPE,                   "Pseudowire Type" },
486   { L2_SPECIFIC_SUBLAYER,      "Layer2 Specific Sublayer" },
487   { DATA_SEQUENCING,           "Data Sequencing" },
488   { CIRCUIT_STATUS,            "Circuit Status" },
489   { PREFERRED_LANGUAGE,        "Preferred Language" },
490   { CTL_MSG_AUTH_NONCE,        "Control Message Authentication Nonce" },
491   { TX_CONNECT_SPEED_V3,       "Tx Connect Speed Version 3" },
492   { RX_CONNECT_SPEED_V3,       "Rx Connect Speed Version 3" },
493   { 76,                                                 "Failover Capability" },                                                        /*[RFC4951] */
494   { 77,                                                 "Tunnel Recovery" },                                                            /*[RFC4951] */
495   { 78,                                                 "Suggested Control Sequence" },                                         /*[RFC4951] */
496   { 79,                                                 "Failover Session State" },                                                     /*[RFC4951] */
497   { 80,                                                 "Multicast Capability" },                                                       /*[RFC4045] */
498   { 81,                                                 "New Outgoing Sessions" },                                                      /*[RFC4045] */
499   { 82,                                                 "New Outgoing Sessions Acknowledgement" },                      /*[RFC4045] */
500   { 83,                                                 "Withdraw Outgoing Sessions" },                                         /*[RFC4045] */
501   { 84,                                                 "Multicast Packets Priority" },                                         /*[RFC4045] */
502   { 85,                                                 "Frame-Relay Header Length" },                                          /*[RFC4591] */
503   { 86,                                                 "ATM Maximum Concatenated Cells AVP" },                         /*[RFC4454] */
504   { 87,                                                 "OAM Emulation Required AVP" },                                         /*[RFC4454] */
505   { 88,                                                 "ATM Alarm Status AVP" },                                                       /*[RFC4454] */
506     /*        Also, see ATM Alarm Status AVP Values below */
507   { 89,                                                 "Attachment Group Identifier" },                                        /*[RFC4667] */
508   { 90,                                                 "Local End Identifier" },                                                       /*[RFC4667] */
509   { 91,                                                 "Interface Maximum Transmission Unit" },                        /*[RFC4667] */
510   { 92,                                                 "FCS Retention" },                                                                      /*[RFC4720] */
511   { 93,                                                 "Tunnel Switching Aggregator ID AVP" },                         /*[draft-ietf-l2tpext-tunnel-switching-06.txt] */
512   { 94,                                                 "Maximum Receive Unit (MRU) AVP" },                                     /*[RFC4623] */
513   { 95,                                                 "Maximum Reassembled Receive Unit (MRRU) AVP" },        /*[RFC4623] */
514
515
516   { 0,                         NULL }
517 };
518
519 #define CISCO_ASSIGNED_CONNECTION_ID    1
520 #define CISCO_PW_CAPABILITY_LIST                2
521 #define CISCO_LOCAL_SESSION_ID                  3
522 #define CISCO_REMOTE_SESSION_ID                 4
523 #define CISCO_ASSIGNED_COOKIE                   5
524 #define CISCO_REMOTE_END_ID                             6
525 #define CISCO_PW_TYPE                                   7
526 #define CISCO_CIRCUIT_STATUS                    8
527 #define CISCO_SESSION_TIE_BREAKER               9
528 #define CISCO_DRAFT_AVP_VERSION                 10
529 #define CISCO_MESSAGE_DIGEST                    12
530 #define CISCO_AUTH_NONCE                                13
531 #define CISCO_INTERFACE_MTU                             14
532
533 static const value_string cisco_avp_type_vals[] = {
534   { CISCO_ASSIGNED_CONNECTION_ID,       "Assigned Connection ID" },
535   { CISCO_PW_CAPABILITY_LIST,           "Pseudowire Capabilities List" },
536   { CISCO_LOCAL_SESSION_ID,                     "Local Session ID" },
537   { CISCO_REMOTE_SESSION_ID,            "Remote Session ID" },
538   { CISCO_ASSIGNED_COOKIE,                      "Assigned Cookie" },
539   { CISCO_REMOTE_END_ID,                        "Remote End ID" },
540   { CISCO_PW_TYPE,                                      "Pseudowire Type" },
541   { CISCO_CIRCUIT_STATUS,                       "Circuit Status" },
542   { CISCO_SESSION_TIE_BREAKER,          "Session Tie Breaker" },
543   { CISCO_DRAFT_AVP_VERSION,            "Draft AVP Version" },
544   { CISCO_MESSAGE_DIGEST,               "Message Digest" },
545   { CISCO_AUTH_NONCE,                   "Control Message Authentication Nonce" },
546   { CISCO_INTERFACE_MTU,                        "Interface MTU" },
547   { 0,                                  NULL }
548 };
549
550 static const value_string pw_types_vals[] = {
551         { 0x0001,  "Frame Relay DLCI" },
552         { 0x0002,  "ATM AAL5 SDU VCC transport" },
553         { 0x0003,  "ATM Cell transparent Port Mode" },
554         { 0x0004,  "Ethernet VLAN" },
555         { 0x0005,  "Ethernet" },
556         { 0x0006,  "HDLC" },
557         { 0x0007,  "PPP" },
558         { 0x0009,  "ATM Cell transport VCC Mode" },
559         { 0x000A,  "ATM Cell transport VPC Mode" },
560         { 0x000B,  "IP Transport" },
561         { 0x000C,  "MPEG-TS Payload Type (MPTPW)" },
562         { 0x000D,  "Packet Streaming Protocol (PSPPW)" },
563         { 0,  NULL },
564 };
565
566 static dissector_handle_t ppp_hdlc_handle;
567 static dissector_handle_t ppp_lcp_options_handle;
568
569 static dissector_handle_t eth_withoutfcs_handle; 
570 static dissector_handle_t chdlc_handle; 
571 static dissector_handle_t fr_handle;
572 static dissector_handle_t ip_handle;
573 static dissector_handle_t mpls_handle;
574 static dissector_handle_t atm_oam_handle;
575 static dissector_handle_t llc_handle;
576 static dissector_handle_t lapd_handle;
577 static dissector_handle_t data_handle;
578
579 /*
580  * Processes AVPs for Control Messages all versions and transports
581  */
582 static void process_control_avps(tvbuff_t *tvb,
583                                  packet_info *pinfo,
584                                  proto_tree *l2tp_tree,
585                                  int index,
586                                  int length)
587 {
588         proto_tree *l2tp_lcp_avp_tree, *l2tp_avp_tree, *l2tp_avp_tree_sub;
589         proto_item *tf, *te;
590
591         int             msg_type;
592         gboolean        isStopCcn = FALSE;
593         int             avp_type;
594         guint32         avp_vendor_id;
595         guint16         avp_len;
596         guint16         ver_len_hidden;
597         int             rhcode = 10;
598         tvbuff_t        *next_tvb;
599         guint16         result_code;
600         guint16         error_code;
601         guint32         bits;
602         guint16         firmware_rev;
603         
604                 while (index < length) {    /* Process AVP's */
605                         ver_len_hidden  = tvb_get_ntohs(tvb, index);
606                         avp_len         = AVP_LENGTH(ver_len_hidden);
607                         avp_vendor_id   = tvb_get_ntohs(tvb, index + 2);
608                         avp_type        = tvb_get_ntohs(tvb, index + 4);
609
610                         if (avp_len < 1) {
611                                 proto_tree_add_text(l2tp_tree, tvb, index, 0,
612                                                     "AVP length must be >= 1");
613                                 return;
614                         }
615
616                         if (avp_vendor_id == VENDOR_IETF) {
617                                 tf =  proto_tree_add_text(l2tp_tree, tvb, index,
618                                                           avp_len, "%s AVP",
619                                                           val_to_str(avp_type, avp_type_vals, "Unknown (%u)"));
620                         } else if (avp_vendor_id == VENDOR_CISCO) {      /* Vendor-Specific AVP */
621                                 tf =  proto_tree_add_text(l2tp_tree, tvb, index,
622                                                           avp_len, "Vendor %s: %s AVP",
623                                                           val_to_str(avp_vendor_id, sminmpec_values, "Unknown (%u)"),
624                                                           val_to_str(avp_type, cisco_avp_type_vals, "Unknown (%u)"));
625                         } else {        /* Vendor-Specific AVP */
626                                 tf =  proto_tree_add_text(l2tp_tree, tvb, index,
627                                                           avp_len, "Vendor %s AVP Type %u",
628                                                           val_to_str(avp_vendor_id, sminmpec_values, "Unknown (%u)"),
629                                                           avp_type);
630                         }
631                                                                                 
632
633                         l2tp_avp_tree = proto_item_add_subtree(tf,  ett_l2tp_avp);
634
635                         proto_tree_add_boolean_format(l2tp_avp_tree,hf_l2tp_avp_mandatory, tvb, index, 1,
636                                                       rhcode, "Mandatory: %s",
637                                                       (MANDATORY_BIT(ver_len_hidden)) ? "True" : "False" );
638                         proto_tree_add_boolean_format(l2tp_avp_tree,hf_l2tp_avp_hidden, tvb, index, 1,
639                                                       rhcode, "Hidden: %s",
640                                                       (HIDDEN_BIT(ver_len_hidden)) ? "True" : "False" );
641                         proto_tree_add_uint_format(l2tp_avp_tree,hf_l2tp_avp_length, tvb, index, 2,
642                                                    rhcode, "Length: %u", avp_len);
643                         if (HIDDEN_BIT(ver_len_hidden)) { /* don't try do display hidden */
644                                 index += avp_len;
645                                 continue;
646                         }
647
648                         if (avp_len < 6) {
649                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 0,
650                                                     "AVP length must be >= 6");
651                                 return;
652                         }
653                         index += 2;
654                         avp_len -= 2;
655
656                         /* Special Case for handling Extended Vendor Id */
657                         if (avp_type == EXTENDED_VENDOR_ID) {
658                                 index += 2;
659                                 avp_len -= 2;
660                                 proto_tree_add_item(l2tp_avp_tree, hf_l2tp_avp_vendor_id,
661                                                                         tvb, index, 4, FALSE);
662
663                                 avp_vendor_id  = tvb_get_ntohl(tvb, index);
664                                 
665                                 index += 4;
666                                 avp_len -= 4;
667                                 continue;
668                         }
669                         else {
670                                 proto_tree_add_item(l2tp_avp_tree, hf_l2tp_avp_vendor_id,
671                                                     tvb, index, 2, FALSE);
672                                 index += 2;
673                                 avp_len -= 2;
674                         }
675
676                         if (avp_vendor_id == VENDOR_CISCO) {
677                                 proto_tree_add_uint(l2tp_avp_tree, hf_l2tp_cisco_avp_type,
678                                                     tvb, index, 2, avp_type);
679                                 index += 2;
680                                 avp_len -= 2;
681
682                                 /* For the time being, we don't decode any Vendor-
683                                    specific AVP. */
684                                 switch (avp_type) {
685                                 case CISCO_ASSIGNED_CONNECTION_ID:
686                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
687                                                             "Assigned Control Connection ID: %u",
688                                                             tvb_get_ntohl(tvb, index));
689                                         break;
690
691                                 case CISCO_PW_CAPABILITY_LIST:
692                                         te = proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
693                                                 "Pseudowire Capabilities List");
694                                         l2tp_avp_tree_sub = proto_item_add_subtree(te, ett_l2tp_avp_sub);
695                                         while (avp_len >= 2) {
696                                                 int pw_type = tvb_get_ntohs(tvb, index);
697
698                                                 proto_tree_add_text(l2tp_avp_tree_sub, tvb, index,
699                                                                     2, "PW Type: (%u) %s",
700                                                                     pw_type,
701                                                                     val_to_str(pw_type, pw_types_vals,
702                                                                                "Unknown (0x%04x)"));
703                                                 index += 2;
704                                                 avp_len -= 2;
705                                         }
706                                         break;
707                                         
708                                 case CISCO_LOCAL_SESSION_ID:
709                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
710                                                             "Local Session ID: %u",
711                                                             tvb_get_ntohl(tvb, index));
712                                         break;
713                                 case CISCO_REMOTE_SESSION_ID:
714                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
715                                                             "Remote Session ID: %u",
716                                                             tvb_get_ntohl(tvb, index));
717                                         break;
718                                 case CISCO_ASSIGNED_COOKIE:
719                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
720                                                             "Assigned Cookie: %s",
721                                                             tvb_bytes_to_str(tvb, index, avp_len));
722                                         break;
723                                 case CISCO_REMOTE_END_ID:
724                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
725                                                             "Remote End ID: %s",
726                                                             tvb_format_text(tvb, index, avp_len));
727                                         break;
728                                 case CISCO_PW_TYPE:
729                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
730                                                             "Pseudowire Type: %u - %s",
731                                                             tvb_get_ntohs(tvb, index),
732                                                             val_to_str(tvb_get_ntohs(tvb, index),
733                                                                        pw_types_vals, "Unknown (0x%04x)"));
734                                         break;
735                                 case CISCO_CIRCUIT_STATUS:
736                                         bits = tvb_get_ntohs(tvb, index);
737                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
738                                                             "Circuit Status: %s",
739                                                             (CIRCUIT_STATUS_BIT(bits)) ? "Up" : "Down");
740                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
741                                                             "Circuit Type: %s",
742                                                             (CIRCUIT_TYPE_BIT(bits)) ? "New" : "Existing");
743                                         break;
744                                 case CISCO_SESSION_TIE_BREAKER:
745                                         proto_tree_add_item(l2tp_avp_tree, hf_l2tp_tie_breaker,
746                                                             tvb, index, 8, FALSE);
747                                         break;
748                                 case CISCO_DRAFT_AVP_VERSION:
749                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
750                                                             "Draft AVP Version: %u",
751                                                             tvb_get_ntohs(tvb, index));
752                                         break;
753                                 case CISCO_MESSAGE_DIGEST:
754                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
755                                                             "Message Digest: %s",
756                                                             tvb_bytes_to_str(tvb, index, avp_len));
757                                         break;
758                                 case CISCO_AUTH_NONCE:
759                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
760                                                             "Nonce: %s",
761                                                             tvb_bytes_to_str(tvb, index, avp_len));
762                                         break;
763                                 case CISCO_INTERFACE_MTU:
764                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
765                                                             "Interface MTU: %u",
766                                                             tvb_get_ntohs(tvb, index));
767                                         break;
768                                         
769                                 default:
770                                         proto_tree_add_text(l2tp_avp_tree, tvb, index,
771                                                             avp_len, "Vendor-Specific AVP");
772                                         break;
773                                 }
774                                 index += avp_len;
775                                 continue;
776                         } else if (avp_vendor_id != VENDOR_IETF) {
777                                 if (avp_len >= 2) {
778                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
779                                                 "Type: %u", avp_type);
780                                         index += 2;
781                                         avp_len -= 2;
782                                         if (avp_len > 0) {
783                                                 proto_tree_add_text(l2tp_avp_tree, tvb, index,
784                                                         avp_len, "Vendor-Specific AVP");
785                                         }
786                                 }
787                                 index += avp_len;
788                                 continue;
789                         }
790
791                         proto_tree_add_uint(l2tp_avp_tree, hf_l2tp_avp_type,
792                                             tvb, index, 2, avp_type);
793                         index += 2;
794                         avp_len -= 2;
795
796                         switch (avp_type) {
797
798                         case CONTROL_MESSAGE:
799                                 msg_type = tvb_get_ntohs(tvb, index);
800                                 proto_tree_add_text(l2tp_avp_tree,tvb, index, 2,
801                                                     "Control Message Type: (%u) %s", msg_type,
802                                                     ((NUM_CONTROL_CALL_TYPES + 1 ) > msg_type) ?
803                                                     calltypestr[msg_type] : "Unknown");
804
805                                 if (msg_type == AVP_StopCCN) {
806                                         isStopCcn = TRUE;
807                                 }
808                                 break;
809
810                         case RESULT_ERROR_CODE:
811                                 if (avp_len < 2)
812                                         break;
813                                 result_code = tvb_get_ntohs(tvb, index);
814                                 if (isStopCcn) {
815                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
816                                                             "Result code: %u - %s", result_code,
817                                                             val_to_str(result_code, result_code_stopccn_vals, "Unknown (%u)"));
818                                 }
819                                 else {
820                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
821                                                             "Result code: %u - %s", result_code,
822                                                             val_to_str(result_code, result_code_cdn_vals, "Unknown (%u)"));
823                                 }
824                                 index += 2;
825                                 avp_len -= 2;
826
827                                 if (avp_len < 2)
828                                         break;
829                                 error_code = tvb_get_ntohs(tvb, index);
830                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
831                                                     "Error code: %u - %s", error_code, 
832                                                     val_to_str(error_code, error_code_vals, "Unknown (%u)"));
833                                 index += 2;
834                                 avp_len -= 2;
835
836                                 if (avp_len == 0)
837                                         break;
838                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
839                                                     "Error Message: %s",
840                                                     tvb_format_text(tvb, index, avp_len));
841                                 break;
842
843                         case PROTOCOL_VERSION:
844                                 if (avp_len < 1)
845                                         break;
846                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
847                                                     "Version: %u", tvb_get_guint8(tvb, index));
848                                 index += 1;
849                                 avp_len -= 1;
850
851                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
852                                                     "Revision: %u", tvb_get_guint8(tvb, index));
853                                 break;
854
855                         case FRAMING_CAPABILITIES:
856                                 bits = tvb_get_ntohl(tvb, index);
857                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
858                                                     "Async Framing Supported: %s",
859                                                     (FRAMING_ASYNC(bits)) ? "True" : "False");
860                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
861                                                     "Sync Framing Supported: %s",
862                                                     (FRAMING_SYNC(bits)) ? "True" : "False");
863                                 break;
864
865                         case BEARER_CAPABILITIES:
866                                 bits = tvb_get_ntohl(tvb, index);
867                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
868                                                     "Analog Access Supported: %s",
869                                                     (BEARER_ANALOG(bits)) ? "True" : "False");
870                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
871                                                     "Digital Access Supported: %s",
872                                                     (BEARER_DIGITAL(bits)) ? "True" : "False");
873                                 break;
874
875                         case TIE_BREAKER:
876                                 proto_tree_add_item(l2tp_avp_tree, hf_l2tp_tie_breaker, tvb, index, 8, FALSE);
877                                 break;
878
879                         case FIRMWARE_REVISION:
880                                 firmware_rev = tvb_get_ntohs(tvb, index);
881                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
882                                                     "Firmware Revision: %d 0x%x", firmware_rev,firmware_rev );
883                                 break;
884
885                         case HOST_NAME:
886                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
887                                                     "Host Name: %s",
888                                                     tvb_format_text(tvb, index, avp_len));
889                                 break;
890
891                         case VENDOR_NAME:
892                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
893                                                     "Vendor Name: %s",
894                                                     tvb_format_text(tvb, index, avp_len));
895                                 break;
896
897                         case ASSIGNED_TUNNEL_ID:
898                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
899                                                     "Tunnel ID: %u", tvb_get_ntohs(tvb, index));
900                                 break;
901
902                         case RECEIVE_WINDOW_SIZE:
903                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
904                                                     "Receive Window Size: %u",
905                                                     tvb_get_ntohs(tvb, index));
906                                 break;
907
908                         case CHALLENGE:
909                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
910                                                     "CHAP Challenge: %s",
911                                                     tvb_bytes_to_str(tvb, index, avp_len));
912                                 break;
913
914                         case CAUSE_CODE:
915                                 /*
916                                  * XXX - export stuff from the Q.931 dissector
917                                  * to dissect the cause code and cause message,
918                                  * and use it.
919                                  */
920                                 if (avp_len < 2)
921                                         break;
922                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
923                                                     "Cause Code: %u",
924                                                     tvb_get_ntohs(tvb, index));
925                                 index += 2;
926                                 avp_len -= 2;
927
928                                 if (avp_len < 1)
929                                         break;
930                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
931                                                     "Cause Msg: %u",
932                                                     tvb_get_guint8(tvb, index));
933                                 index += 1;
934                                 avp_len -= 1;
935
936                                 if (avp_len == 0)
937                                         break;
938                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
939                                                     "Advisory Msg: %s",
940                                                     tvb_format_text(tvb, index, avp_len));
941                                 break;
942
943                         case CHALLENGE_RESPONSE:
944                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 16,
945                                                     "CHAP Challenge Response: %s",
946                                                     tvb_bytes_to_str(tvb, index, 16));
947                                 break;
948
949                         case ASSIGNED_SESSION:
950                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
951                                                     "Assigned Session: %u",
952                                                     tvb_get_ntohs(tvb, index));
953                                 break;
954
955                         case CALL_SERIAL_NUMBER:
956                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
957                                                     "Call Serial Number: %u",
958                                                     tvb_get_ntohl(tvb, index));
959                                 break;
960
961                         case MINIMUM_BPS:
962                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
963                                                     "Minimum BPS: %u",
964                                                     tvb_get_ntohl(tvb, index));
965                                 break;
966
967                         case MAXIMUM_BPS:
968                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
969                                                     "Maximum BPS: %u",
970                                                     tvb_get_ntohl(tvb, index));
971                                 break;
972
973                         case BEARER_TYPE:
974                                 bits = tvb_get_ntohl(tvb, index);
975                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
976                                                     "Analog Bearer Type: %s",
977                                                     (BEARER_ANALOG(bits)) ? "True" : "False");
978                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
979                                                     "Digital Bearer Type: %s",
980                                                     (BEARER_DIGITAL(bits)) ? "True" : "False");
981                                 break;
982
983                         case FRAMING_TYPE:
984                                 bits = tvb_get_ntohl(tvb, index);
985                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
986                                                     "Async Framing Type: %s",
987                                                     (FRAMING_ASYNC(bits)) ? "True" : "False");
988                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
989                                                     "Sync Framing Type: %s",
990                                                      (FRAMING_SYNC(bits)) ? "True" : "False");
991                                 break;
992
993                         case CALLED_NUMBER:
994                                 if (avp_len == 0)
995                                         break;
996                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
997                                                     "Called Number: %s",
998                                                     tvb_format_text(tvb, index, avp_len));
999                                 break;
1000
1001                         case CALLING_NUMBER:
1002                                 if (avp_len == 0)
1003                                         break;
1004                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1005                                                     "Calling Number: %s",
1006                                                     tvb_format_text(tvb, index, avp_len));
1007                                 break;
1008
1009                         case SUB_ADDRESS:
1010                                 if (avp_len == 0)
1011                                         break;
1012                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1013                                                     "Sub-Address: %s",
1014                                                     tvb_format_text(tvb, index, avp_len));
1015                                 break;
1016
1017                         case TX_CONNECT_SPEED:
1018                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1019                                                     "Connect Speed: %u",
1020                                                     tvb_get_ntohl(tvb, index));
1021                                 break;
1022
1023                         case PHYSICAL_CHANNEL:
1024                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1025                                                     "Physical Channel: %u",
1026                                                     tvb_get_ntohl(tvb, index));
1027                                 break;
1028
1029                         case INITIAL_RECEIVED_LCP_CONFREQ:
1030                                 te = proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1031                                                          "Initial Received LCP CONFREQ: %s",
1032                                                          tvb_bytes_to_str(tvb, index, avp_len));
1033                                 l2tp_lcp_avp_tree = proto_item_add_subtree(te, ett_l2tp_lcp);
1034                                 next_tvb = tvb_new_subset(tvb, index, avp_len, avp_len);
1035                                 call_dissector(ppp_lcp_options_handle, next_tvb, pinfo, l2tp_lcp_avp_tree );
1036                                 break;
1037
1038                         case LAST_SENT_LCP_CONFREQ:
1039                                 te = proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1040                                                          "Last Sent LCP CONFREQ: %s",
1041                                                          tvb_bytes_to_str(tvb, index, avp_len));
1042                                 l2tp_lcp_avp_tree = proto_item_add_subtree(te, ett_l2tp_lcp);
1043                                 next_tvb = tvb_new_subset(tvb, index, avp_len, avp_len);
1044                                 call_dissector(ppp_lcp_options_handle, next_tvb, pinfo, l2tp_lcp_avp_tree );
1045                                 break;
1046
1047                         case LAST_RECEIVED_LCP_CONFREQ:
1048                                 te = proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1049                                                          "Last Received LCP CONFREQ: %s",
1050                                                          tvb_bytes_to_str(tvb, index, avp_len));
1051                                 l2tp_lcp_avp_tree = proto_item_add_subtree(te, ett_l2tp_lcp);
1052                                 next_tvb = tvb_new_subset(tvb, index, avp_len, avp_len);
1053                                 call_dissector(ppp_lcp_options_handle, next_tvb, pinfo, l2tp_lcp_avp_tree );
1054                                 break;
1055
1056                         case PROXY_AUTHEN_TYPE:
1057                                 msg_type = tvb_get_ntohs(tvb, index);
1058                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1059                                                     "Proxy Authen Type: %s",
1060                                                     val_to_str(msg_type, authen_type_vals, "Unknown (%u)"));
1061                                 break;
1062
1063                         case PROXY_AUTHEN_NAME:
1064                                 if (avp_len == 0)
1065                                         break;
1066                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1067                                                     "Proxy Authen Name: %s",
1068                                                     tvb_format_text(tvb, index, avp_len));
1069                                 break;
1070
1071                         case PROXY_AUTHEN_CHALLENGE:
1072                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1073                                                     "Proxy Authen Challenge: %s",
1074                                                     tvb_bytes_to_str(tvb, index, avp_len));
1075                                 break;
1076
1077                         case PROXY_AUTHEN_ID:
1078                                 proto_tree_add_text(l2tp_avp_tree, tvb, index + 1, 1,
1079                                                     "Proxy Authen ID: %u",
1080                                                     tvb_get_guint8(tvb, index + 1));
1081                                 break;
1082
1083                         case PROXY_AUTHEN_RESPONSE:
1084                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1085                                                     "Proxy Authen Response: %s",
1086                                                     tvb_bytes_to_str(tvb, index, avp_len));
1087                                 break;
1088
1089                         case CALL_STATUS_AVPS:
1090                                 if (avp_len < 2)
1091                                         break;
1092                                 index += 2;
1093                                 avp_len -= 2;
1094
1095                                 if (avp_len < 4)
1096                                         break;
1097                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1098                                                     "CRC Errors: %u", tvb_get_ntohl(tvb, index));
1099                                 index += 4;
1100                                 avp_len -= 4;
1101
1102                                 if (avp_len < 4)
1103                                         break;
1104                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1105                                                     "Framing Errors: %u", tvb_get_ntohl(tvb, index));
1106                                 index += 4;
1107                                 avp_len -= 4;
1108
1109                                 if (avp_len < 4)
1110                                         break;
1111                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1112                                                     "Hardware Overruns: %u", tvb_get_ntohl(tvb, index));
1113                                 index += 4;
1114                                 avp_len -= 4;
1115
1116                                 if (avp_len < 4)
1117                                         break;
1118                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1119                                                     "Buffer Overruns: %u", tvb_get_ntohl(tvb, index));
1120                                 index += 4;
1121                                 avp_len -= 4;
1122
1123                                 if (avp_len < 4)
1124                                         break;
1125                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1126                                                     "Time-out Errors: %u", tvb_get_ntohl(tvb, index));
1127                                 index += 4;
1128                                 avp_len -= 4;
1129
1130                                 if (avp_len < 4)
1131                                         break;
1132                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1133                                                     "Alignment Errors: %u", tvb_get_ntohl(tvb, index));
1134                                 index += 4;
1135                                 avp_len -= 4;
1136                                 break;
1137
1138                         case ACCM:
1139                                 if (avp_len < 2)
1140                                         break;
1141                                 index += 2;
1142                                 avp_len -= 2;
1143
1144                                 if (avp_len < 4)
1145                                         break;
1146                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1147                                                     "Send ACCM: %u", tvb_get_ntohl(tvb, index));
1148                                 index += 4;
1149                                 avp_len -= 4;
1150
1151                                 if (avp_len < 4)
1152                                         break;
1153                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1154                                                     "Receive ACCM: %u", tvb_get_ntohl(tvb, index));
1155                                 index += 4;
1156                                 avp_len -= 4;
1157                                 break;
1158
1159                         case RANDOM_VECTOR:
1160                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1161                                                     "Random Vector: %s",
1162                                                     tvb_bytes_to_str(tvb, index, avp_len));
1163                                 break;
1164
1165                         case PRIVATE_GROUP_ID:
1166                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1167                                                     "Private Group ID: %s",
1168                                                     tvb_bytes_to_str(tvb, index, avp_len));
1169                                 break;
1170
1171                         case RX_CONNECT_SPEED:
1172                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1173                                                     "Rx Connect Speed: %u",
1174                                                     tvb_get_ntohl(tvb, index));
1175                                 break;
1176
1177                         case PPP_DISCONNECT_CAUSE_CODE:
1178                                 if (avp_len < 2)
1179                                         break;
1180                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1181                                                     "Disconnect Code: %u",
1182                                                     tvb_get_ntohs(tvb, index));
1183                                 index += 2;
1184                                 avp_len -= 2;
1185
1186                                 if (avp_len < 2)
1187                                         break;
1188                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1189                                                     "Control Protocol Number: %u",
1190                                                     tvb_get_ntohs(tvb, index));
1191                                 index += 2;
1192                                 avp_len -= 2;
1193
1194                                 if (avp_len < 1)
1195                                         break;
1196                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 1,
1197                                                     "Direction: %s",
1198                                                     val_to_str(tvb_get_guint8(tvb, index),
1199                                                     cause_code_direction_vals,
1200                                                     "Reserved (%u)"));
1201                                 index += 1;
1202                                 avp_len -= 1;
1203
1204                                 if (avp_len == 0)
1205                                         break;
1206                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1207                                                     "Message: %s",
1208                                                     tvb_format_text(tvb, index, avp_len));
1209                                 break;
1210
1211                         case MESSAGE_DIGEST:
1212                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1213                                                     "Message Digest: %s",
1214                                                     tvb_bytes_to_str(tvb, index, avp_len));
1215                                 break;
1216                         case ROUTER_ID:
1217                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1218                                                     "Router ID: %u",
1219                                                     tvb_get_ntohl(tvb, index));
1220                                 break;
1221                         case ASSIGNED_CONTROL_CONN_ID:
1222                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1223                                                     "Assigned Control Connection ID: %u",
1224                                                     tvb_get_ntohl(tvb, index));
1225                                 break;
1226                         case PW_CAPABILITY_LIST:
1227                                 te = proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1228                                         "Pseudowire Capabilities List");
1229                                 l2tp_avp_tree_sub = proto_item_add_subtree(te, ett_l2tp_avp_sub);
1230
1231                                 while (avp_len >= 2) {
1232                                         int pw_type = tvb_get_ntohs(tvb, index);
1233                                         proto_tree_add_text(l2tp_avp_tree_sub, tvb, index,
1234                                                             2, "PW Type: (%u) %s",
1235                                                             pw_type,
1236                                                             val_to_str(pw_type, pw_types_vals,
1237                                                                        "Unknown (0x%04x)"));
1238                                         index += 2;
1239                                         avp_len -= 2;
1240                                 }
1241                                 break;
1242                         case LOCAL_SESSION_ID:
1243                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1244                                                     "Local Session ID: %u",
1245                                                     tvb_get_ntohl(tvb, index));
1246                                 break;
1247                         case REMOTE_SESSION_ID:
1248                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 4,
1249                                                     "Remote Session ID: %u",
1250                                                     tvb_get_ntohl(tvb, index));
1251                                 break;
1252                         case ASSIGNED_COOKIE:
1253                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1254                                                     "Assigned Cookie: %s",
1255                                                     tvb_bytes_to_str(tvb, index, avp_len));
1256                                 break;
1257                         case REMOTE_END_ID:
1258                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1259                                                     "Remote End ID: %s",
1260                                                     tvb_format_text(tvb, index, avp_len));
1261                                 break;
1262                         case PW_TYPE:
1263                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1264                                                     "Pseudowire Type: %u - %s",
1265                                                     tvb_get_ntohs(tvb, index),
1266                                                     val_to_str(tvb_get_ntohs(tvb, index),
1267                                                                pw_types_vals, "Unknown (0x%04x)"));
1268                                 break;
1269                         case L2_SPECIFIC_SUBLAYER:
1270                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1271                                                     "Layer2 Specific Sublayer: %s",
1272                                                     val_to_str(tvb_get_ntohs(tvb, index),
1273                                                                l2_sublayer_vals, "Invalid (%u)"));
1274                                 break;
1275                         case DATA_SEQUENCING:
1276                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1277                                                     "Data Sequencing: %s",
1278                                                     val_to_str(tvb_get_ntohs(tvb, index),
1279                                                                data_sequencing_vals, "Invalid (%u)"));
1280                                 break;
1281                         case CIRCUIT_STATUS:
1282                                 bits = tvb_get_ntohs(tvb, index);
1283                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1284                                                     "Circuit Status: %s",
1285                                                     (CIRCUIT_STATUS_BIT(bits)) ? "Up" : "Down");
1286                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, 2,
1287                                                     "Circuit Type: %s",
1288                                                     (CIRCUIT_TYPE_BIT(bits)) ? "New" : "Existing");
1289                                 break;
1290                         case PREFERRED_LANGUAGE:
1291                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1292                                                    "Preferred Language: %s",
1293                                                    tvb_format_text(tvb, index, avp_len));
1294                                 break;
1295                         case CTL_MSG_AUTH_NONCE:
1296                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1297                                                     "Nonce: %s",
1298                                                     tvb_bytes_to_str(tvb, index, avp_len));
1299                                 break;
1300                         case TX_CONNECT_SPEED_V3:
1301                         {
1302                                 guint32 l_int, h_int;
1303                                 if (avp_len < 8)
1304                                         break;
1305                                 
1306                                 h_int = tvb_get_ntohl(tvb, index);
1307                                 l_int = tvb_get_ntohl(tvb, index+4);
1308                                 if (!h_int && !l_int) {
1309                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 8,
1310                                                             "Tx Connect Speed v3: indeterminable or no physical p2p link");
1311                                 }
1312                                 else {
1313                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 8,
1314                                                             "Tx Connect Speed v3: %#x%04x",
1315                                                             h_int, l_int);
1316                                 }
1317                                 break;
1318                         }
1319                         case RX_CONNECT_SPEED_V3:
1320                         {
1321                                 guint32 l_int, h_int;
1322                                 if (avp_len < 8)
1323                                         break;
1324                                 
1325                                 h_int = tvb_get_ntohl(tvb, index);
1326                                 l_int = tvb_get_ntohl(tvb, index+4);
1327                                 if (!h_int && !l_int) {
1328                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 8,
1329                                                             "Rx Connect Speed v3: indeterminable or no physical p2p link");
1330                                 }
1331                                 else {
1332                                         proto_tree_add_text(l2tp_avp_tree, tvb, index, 8,
1333                                                             "Rx Connect Speed v3: %#x%04x",
1334                                                             h_int, l_int);
1335                                 }
1336                                 break;
1337                         }
1338                         default:
1339                                 proto_tree_add_text(l2tp_avp_tree, tvb, index, avp_len,
1340                                                     "Unknown AVP");
1341                                 break;
1342                         }
1343
1344                         index += avp_len;
1345                 }
1346
1347 }
1348
1349 /*
1350  * Processes Data Messages for v3 IP and UDP, starting from the  Session ID
1351  * (common to IP and UDP). Dissects the L2TPv3 Session header, the (optional)
1352  * L2-Specific sublayer and calls the appropriate dissector for the payload.
1353  */
1354 static void
1355 process_l2tpv3_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1356                     proto_tree *l2tp_tree, proto_item *l2tp_item, int *pIndex)
1357 {
1358         int             index = *pIndex;
1359         int             sid;
1360         guint8          oam_cell = 0;
1361         proto_tree      *l2_specific = NULL;
1362         proto_item      *ti = NULL;
1363         tvbuff_t        *next_tvb;
1364         
1365         /* Get Session ID */
1366         sid = tvb_get_ntohl(tvb, index);
1367         index += 4;
1368
1369         if (check_col(pinfo->cinfo, COL_INFO)) {
1370                 col_add_fstr(pinfo->cinfo,COL_INFO,
1371                              "%s            (session id=%u)",
1372                              data_msg, sid);
1373         }
1374
1375         if (tree) {
1376                 proto_tree_add_item(l2tp_tree, hf_l2tp_sid, tvb, index-4, 4, FALSE);
1377                 proto_item_set_len(l2tp_item, index);
1378                 if (!(tvb_offset_exists(tvb, index)))
1379                         return;
1380                 if (l2tpv3_cookie != 0)
1381                         proto_tree_add_item(l2tp_tree, hf_l2tp_cookie, tvb, index, l2tpv3_cookie, FALSE);
1382         }
1383
1384         switch(l2tpv3_l2_specific){
1385         case L2TPv3_L2_SPECIFIC_DEFAULT:
1386                 if (tree) {
1387                         ti = proto_tree_add_item(tree, hf_l2tp_l2_spec_def,
1388                                         tvb, index + l2tpv3_cookie, 4, FALSE);
1389                         l2_specific = proto_item_add_subtree(ti, ett_l2tp_l2_spec);
1390
1391                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_s, tvb, index + l2tpv3_cookie,
1392                                                 1, FALSE);
1393                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_sequence, tvb,
1394                                                 index + l2tpv3_cookie + 1, 3, FALSE);
1395                 }
1396                 next_tvb = tvb_new_subset_remaining(tvb, index + l2tpv3_cookie + 4);
1397                 break;
1398         case L2TPv3_L2_SPECIFIC_ATM:
1399                 if (tree) {
1400                         ti = proto_tree_add_item(tree, hf_l2tp_l2_spec_atm,
1401                                         tvb, index + l2tpv3_cookie, 4, FALSE);
1402                         l2_specific = proto_item_add_subtree(ti, ett_l2tp_l2_spec);
1403
1404                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_s, tvb, index + l2tpv3_cookie,
1405                                                 1, FALSE);
1406                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_t, tvb, index + l2tpv3_cookie,
1407                                                 1, FALSE);
1408                         /*
1409                          * As per RFC 4454, the T bit specifies whether
1410                          * we're transporting an OAM cell or an AAL5 frame.
1411                          */
1412                         oam_cell = tvb_get_guint8(tvb, index + l2tpv3_cookie) & 0x08;
1413                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_g, tvb, index + l2tpv3_cookie,
1414                                                 1, FALSE);
1415                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_c, tvb, index + l2tpv3_cookie,
1416                                                 1, FALSE);
1417                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_u, tvb, index + l2tpv3_cookie,
1418                                                 1, FALSE);
1419                         proto_tree_add_item(l2_specific, hf_l2tp_l2_spec_sequence, tvb,
1420                                                 index + l2tpv3_cookie + 1, 3, FALSE);
1421                 }
1422                 next_tvb = tvb_new_subset_remaining(tvb, index + l2tpv3_cookie + 4);
1423                 break;
1424         case L2TPv3_L2_SPECIFIC_LAPD:
1425                 if (tree)
1426                         proto_tree_add_text(tree, tvb, index + l2tpv3_cookie + 4, 3,"LAPD info");
1427                 next_tvb = tvb_new_subset_remaining(tvb, index + l2tpv3_cookie+4+3);
1428                 break;
1429         case L2TPv3_L2_SPECIFIC_NONE:
1430         default:
1431                 next_tvb = tvb_new_subset_remaining(tvb, index + l2tpv3_cookie);
1432                 break;
1433         }
1434
1435         switch(l2tpv3_protocol){
1436         case L2TPv3_PROTOCOL_ETH:
1437                 call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree);
1438                 break;
1439         case L2TPv3_PROTOCOL_CHDLC:
1440                 call_dissector(chdlc_handle, next_tvb, pinfo, tree);
1441                 break;
1442         case L2TPv3_PROTOCOL_FR:
1443                 call_dissector(fr_handle, next_tvb, pinfo, tree);
1444                 break;
1445         case L2TPv3_PROTOCOL_PPP:
1446                 /*
1447                  * PPP is transported without Address and Control
1448                  * fields, ppp_hdlc_handle can handle that as if if
1449                  * was ACFC (NULL Address and Control)
1450                  */
1451                 call_dissector(ppp_hdlc_handle, next_tvb, pinfo, tree);
1452                 break;
1453         case L2TPv3_PROTOCOL_IP:
1454                 call_dissector(ip_handle, next_tvb, pinfo, tree);
1455                 break;
1456         case L2TPv3_PROTOCOL_MPLS:
1457                 call_dissector(mpls_handle, next_tvb, pinfo, tree);
1458                 break;
1459         case L2TPv3_PROTOCOL_AAL5:
1460                 if (oam_cell) {
1461                         call_dissector(atm_oam_handle, next_tvb, pinfo, tree);
1462                 } else {
1463                         call_dissector(llc_handle, next_tvb, pinfo, tree);
1464                 }
1465                 break;
1466         case L2TPv3_PROTOCOL_LAPD:
1467                 call_dissector(lapd_handle, next_tvb, pinfo, tree);
1468                 break;
1469         default:
1470                 call_dissector(data_handle, next_tvb, pinfo, tree);
1471                 break;
1472         }
1473 }
1474
1475 /*
1476  * Processes v3 data message over UDP, to then call process_l2tpv3_data
1477  * from the common part (Session ID)
1478  */
1479 static void
1480 process_l2tpv3_data_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1481 {
1482         proto_tree *l2tp_tree = NULL, *ctrl_tree;
1483         proto_item *l2tp_item = NULL, *ti;
1484         
1485         int index = 0;
1486         int control;
1487         int sid;
1488         
1489         control = tvb_get_ntohs(tvb, index);
1490         index += 2;                     /* skip ahead */
1491         index += 2;                     /* Skip the reserved */
1492         sid = tvb_get_ntohl(tvb, index);
1493
1494         if (tree) {
1495                 l2tp_item = proto_tree_add_item(tree, proto_l2tp, tvb, 0, -1, FALSE);
1496                 l2tp_tree = proto_item_add_subtree(l2tp_item, ett_l2tp);
1497                 proto_item_append_text(l2tp_item, " version 3");
1498
1499                 ti = proto_tree_add_text(l2tp_tree, tvb, 0, 2,
1500                                          "Packet Type: %s Session Id=%u",
1501                                          data_msg, sid);
1502
1503                 ctrl_tree = proto_item_add_subtree(ti, ett_l2tp_ctrl);
1504                 proto_tree_add_uint(ctrl_tree, hf_l2tp_type, tvb, 0, 2, control);
1505                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_length_bit, tvb, 0, 2, control);
1506                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_seq_bit, tvb, 0, 2, control);
1507                 proto_tree_add_uint(ctrl_tree, hf_l2tp_version, tvb, 0, 2, control);
1508                 /* Data in v3 over UDP has this reserved */
1509                 proto_tree_add_item(l2tp_tree, hf_l2tp_res, tvb, 2, 2, FALSE);
1510         }
1511
1512         /* Call process_l2tpv3_data from Session ID (offset in index of 4) */
1513         process_l2tpv3_data(tvb, pinfo, tree, l2tp_tree, l2tp_item, &index);
1514 }
1515
1516 /*
1517  * Processes v3 data message over IP, to then call process_l2tpv3_data
1518  * from the common part (Session ID)
1519  */
1520 static void
1521 process_l2tpv3_data_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1522 {
1523         proto_tree *l2tp_tree = NULL;
1524         proto_item *l2tp_item = NULL, *ti;
1525         
1526         int index = 0;
1527         int sid;
1528
1529         sid = tvb_get_ntohl(tvb, index);
1530         
1531         if (tree) {
1532                 l2tp_item = proto_tree_add_item(tree, proto_l2tp, tvb, 0, -1, FALSE);
1533                 l2tp_tree = proto_item_add_subtree(l2tp_item, ett_l2tp);
1534                 proto_item_append_text(l2tp_item, " version 3");
1535
1536                 ti = proto_tree_add_text(l2tp_tree, tvb, 0, 4,
1537                                          "Packet Type: %s Session Id=%u",
1538                                          data_msg, sid);
1539         }
1540
1541         /* Call process_l2tpv3_data from Session ID (offset in index of 0) */
1542         process_l2tpv3_data(tvb, pinfo, tree, l2tp_tree, l2tp_item, &index);
1543 }
1544
1545 /*
1546  * Processes v3 Control Message over IP, that carries NULL Session ID
1547  * to then call process_control_avps after dissecting the control.
1548  */
1549 static void
1550 process_l2tpv3_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int baseIndex)
1551 {
1552         proto_tree *l2tp_tree=NULL, *ctrl_tree;
1553         proto_item *l2tp_item = NULL, *ti;
1554         
1555         int index = baseIndex;
1556         int tmp_index;
1557         guint16 length = 0;             /* Length field */
1558         guint32 ccid = 0;               /* Control Connection ID */
1559         guint16 avp_type;
1560         guint16 msg_type;
1561         guint16 control = 0;
1562         
1563         control = tvb_get_ntohs(tvb, index);
1564         index += 2;                     /* skip ahead */
1565         if (LENGTH_BIT(control)) {      /* length field included ? */
1566                 length = tvb_get_ntohs(tvb, index);
1567                 index += 2;
1568         }
1569
1570         /* Get Control Channel ID */
1571         ccid = tvb_get_ntohl(tvb, index);
1572         index += 4;
1573
1574         if (check_col(pinfo->cinfo, COL_INFO)) {
1575                 tmp_index = index;
1576
1577                 if ((LENGTH_BIT(control))&&(length==12))                /* ZLB Message */
1578                         col_add_fstr(pinfo->cinfo, COL_INFO,
1579                                      "%s - ZLB      (tunnel id=%u)",
1580                                      control_msg , ccid);
1581                 else
1582                 {
1583                         if (SEQUENCE_BIT(control)) {
1584                                 tmp_index += 4;
1585                         }
1586
1587                         tmp_index+=4;
1588
1589                         avp_type = tvb_get_ntohs(tvb, tmp_index);
1590                         tmp_index += 2;
1591                                 
1592                         if (avp_type == CONTROL_MESSAGE) {
1593                                 /* We print message type */
1594                                 msg_type = tvb_get_ntohs(tvb, tmp_index);
1595                                 tmp_index += 2;
1596                                 col_add_fstr(pinfo->cinfo, COL_INFO,
1597                                              "%s - %s (tunnel id=%u)",
1598                                              control_msg ,
1599                                              ((NUM_CONTROL_CALL_TYPES + 1 ) > msg_type) ?
1600                                              calltype_short_str[msg_type] : "Unknown",
1601                                              ccid);
1602                         }
1603                         else {
1604                                 /*
1605                                  * This is not a control message.
1606                                  * We never pass here except in case of bad l2tp packet!
1607                                  */
1608                                 col_add_fstr(pinfo->cinfo, COL_INFO,
1609                                              "%s (tunnel id=%u)",
1610                                              control_msg,  ccid);
1611                         }
1612                 }
1613         }
1614
1615         if (LENGTH_BIT(control)) {
1616                 /*
1617                  * Set the length of this tvbuff to be no longer than the length
1618                  * in the header.
1619                  *
1620                  * XXX - complain if that length is longer than the length of
1621                  * the tvbuff?  Have "set_actual_length()" return a Boolean
1622                  * and have its callers check the result?
1623                  */
1624                 set_actual_length(tvb, length+baseIndex);
1625         }
1626
1627         if (tree) {
1628                 l2tp_item = proto_tree_add_item(tree, proto_l2tp, tvb, 0, -1, FALSE);
1629                 l2tp_tree = proto_item_add_subtree(l2tp_item, ett_l2tp);
1630                 proto_item_append_text(l2tp_item, " version 3");
1631
1632                 if (baseIndex) {
1633                         proto_tree_add_item(l2tp_tree, hf_l2tp_sid, tvb, 0, 4, FALSE);
1634                 }
1635                 ti = proto_tree_add_text(l2tp_tree, tvb, baseIndex, 2,
1636                                                                  "Packet Type: %s Control Connection Id=%d",
1637                                                                  (CONTROL_BIT(control) ? control_msg : data_msg), ccid);
1638
1639                 ctrl_tree = proto_item_add_subtree(ti, ett_l2tp_ctrl);
1640                 proto_tree_add_uint(ctrl_tree, hf_l2tp_type, tvb, baseIndex, 2, control);
1641                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_length_bit, tvb, baseIndex, 2, control);
1642                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_seq_bit, tvb, baseIndex, 2, control);
1643                 proto_tree_add_uint(ctrl_tree, hf_l2tp_version, tvb, baseIndex, 2, control);
1644         }
1645         index = baseIndex + 2;
1646         if (LENGTH_BIT(control)) {
1647                 if (tree) {
1648                         proto_tree_add_item(l2tp_tree, hf_l2tp_length, tvb, index, 2, FALSE);
1649                 }
1650                 index += 2;
1651         }
1652
1653         if (tree) {
1654                 proto_tree_add_item(l2tp_tree, hf_l2tp_ccid, tvb, index, 4, FALSE);
1655         }
1656         index += 4;
1657
1658         if (SEQUENCE_BIT(control)) {
1659                 if (tree) {
1660                         proto_tree_add_item(l2tp_tree, hf_l2tp_Ns, tvb, index, 2, FALSE);
1661                 }
1662                 index += 2;
1663                 if (tree) {
1664                         proto_tree_add_item(l2tp_tree, hf_l2tp_Nr, tvb, index, 2, FALSE);
1665                 }
1666                 index += 2;
1667         }
1668         
1669         if (tree && (LENGTH_BIT(control))&&(length==12)) {
1670                 proto_tree_add_text(l2tp_tree, tvb, 0, 0, "Zero Length Bit message");
1671         }
1672
1673         if (!LENGTH_BIT(control)) {
1674                 return;
1675         }
1676
1677         process_control_avps(tvb, pinfo, l2tp_tree, index, length+baseIndex);
1678 }
1679
1680 /*
1681  * Dissector for L2TP over UDP. For v2, calls process_control_avps for
1682  * control messages, or the ppp dissector based on the control bit.
1683  * For v3, calls either process_l2tpv3_control or process_l2tpv3_data_udp
1684  * based on the control bit.
1685  */
1686 static int
1687 dissect_l2tp_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1688 {
1689         proto_tree *l2tp_tree=NULL, *ctrl_tree;
1690         proto_item *l2tp_item = NULL, *ti;
1691         int index = 0;
1692         int tmp_index;
1693         guint16 length = 0;             /* Length field */
1694         guint16 tid;                    /* Tunnel ID */
1695         guint16 cid;                    /* Call ID */
1696         guint16 offset_size;            /* Offset size */
1697         guint16 avp_type;
1698         guint16 msg_type;
1699         guint16 control;
1700         tvbuff_t        *next_tvb;
1701
1702         /*
1703          * Don't accept packets that aren't for an L2TP version we know,
1704          * as they might not be L2TP packets even though they happen
1705          * to be coming from or going to the L2TP port.
1706          */
1707         if (tvb_length(tvb) < 2)
1708                 return 0;       /* not enough information to check */
1709         control = tvb_get_ntohs(tvb, 0);
1710         switch (L2TP_VERSION(control)) {
1711
1712         case 2:
1713         case 3:
1714                 break;
1715
1716         default:
1717                 return 0;
1718         }
1719
1720         if (check_col(pinfo->cinfo, COL_PROTOCOL))      /* build output for closed L2tp frame displayed  */
1721                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "L2TP");
1722         col_clear(pinfo->cinfo, COL_INFO);
1723
1724         switch (L2TP_VERSION(control)) {
1725
1726         case 2:
1727                 break;
1728
1729         case 3:
1730                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "L2TPv3");
1731                 if (CONTROL_BIT(control)) {
1732                         /* Call to process l2tp v3 control message */
1733                         process_l2tpv3_control(tvb, pinfo, tree, 0);
1734                 }
1735                 else {
1736                         /* Call to process l2tp v3 data message */
1737                         process_l2tpv3_data_udp(tvb, pinfo, tree);
1738                 }
1739                 return tvb_length(tvb);
1740         }
1741
1742         if (LENGTH_BIT(control)) {              /* length field included ? */
1743                 index += 2;                     /* skip ahead */
1744                 length = tvb_get_ntohs(tvb, index);
1745         }
1746
1747         /* collect the tunnel id & call id */
1748         index += 2;
1749         tid = tvb_get_ntohs(tvb, index);
1750         index += 2;
1751         cid = tvb_get_ntohs(tvb, index);
1752
1753         if (check_col(pinfo->cinfo, COL_INFO)) {
1754                 if (CONTROL_BIT(control)) {
1755                         /* CONTROL MESSAGE */
1756                         tmp_index = index;
1757
1758                         if ((LENGTH_BIT(control))&&(length==12))        /* ZLB Message */
1759                                 col_add_fstr(pinfo->cinfo, COL_INFO,
1760                                              "%s - ZLB      (tunnel id=%d, session id=%u)",
1761                                              control_msg, tid, cid);
1762                         else
1763                         {
1764                                 if (SEQUENCE_BIT(control)) {
1765                                         tmp_index += 4;
1766                                 }
1767
1768                                 tmp_index+=4;
1769
1770                                 avp_type = tvb_get_ntohs(tvb, (tmp_index+=2));
1771
1772                                 if (avp_type == CONTROL_MESSAGE) {
1773                                         /* We print message type */
1774                                         msg_type = tvb_get_ntohs(tvb, (tmp_index+=2));
1775                                         col_add_fstr(pinfo->cinfo, COL_INFO,
1776                                                      "%s - %s (tunnel id=%u, session id=%u)",
1777                                                      control_msg,
1778                                                      ((NUM_CONTROL_CALL_TYPES + 1 ) > msg_type) ?
1779                                                      calltype_short_str[msg_type] : "Unknown",
1780                                                      tid, cid);
1781                                 }
1782                                 else
1783                                 {
1784                                         /*
1785                                          * This is not a control message.
1786                                          * We never pass here except in case of bad l2tp packet!
1787                                          */
1788                                         col_add_fstr(pinfo->cinfo, COL_INFO,
1789                                                      "%s (tunnel id=%u, session id=%u)",
1790                                                      control_msg, tid, cid);
1791
1792                                 }
1793                         }
1794                 }
1795                 else {
1796                         /* DATA Message */
1797                         col_add_fstr(pinfo->cinfo, COL_INFO,
1798                                      "%s            (tunnel id=%u, session id=%u)",
1799                                      data_msg, tid, cid);
1800                 }
1801         }
1802
1803         if (LENGTH_BIT(control)) {
1804                 /*
1805                  * Set the length of this tvbuff to be no longer than the length
1806                  * in the header.
1807                  *
1808                  * XXX - complain if that length is longer than the length of
1809                  * the tvbuff?  Have "set_actual_length()" return a Boolean
1810                  * and have its callers check the result?
1811                  */
1812                 set_actual_length(tvb, length);
1813         }
1814
1815         if (tree) {
1816                 l2tp_item = proto_tree_add_item(tree,proto_l2tp, tvb, 0, -1, FALSE);
1817                 l2tp_tree = proto_item_add_subtree(l2tp_item, ett_l2tp);
1818
1819                 ti = proto_tree_add_text(l2tp_tree, tvb, 0, 2,
1820                                          "Packet Type: %s Tunnel Id=%d Session Id=%d",
1821                                          (CONTROL_BIT(control) ? control_msg : data_msg), tid, cid);
1822
1823                 ctrl_tree = proto_item_add_subtree(ti, ett_l2tp_ctrl);
1824                 proto_tree_add_uint(ctrl_tree, hf_l2tp_type, tvb, 0, 2, control);
1825                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_length_bit, tvb, 0, 2, control);
1826                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_seq_bit, tvb, 0, 2, control);
1827                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_offset_bit, tvb, 0, 2, control);
1828                 proto_tree_add_boolean(ctrl_tree, hf_l2tp_priority, tvb, 0, 2, control);
1829                 proto_tree_add_uint(ctrl_tree, hf_l2tp_version, tvb, 0, 2, control);
1830         }
1831         index = 2;
1832         if (LENGTH_BIT(control)) {
1833                 if (tree) {
1834                         proto_tree_add_item(l2tp_tree, hf_l2tp_length, tvb, index, 2, FALSE);
1835                 }
1836                 index += 2;
1837         }
1838
1839         if (tree) {
1840                 proto_tree_add_item(l2tp_tree, hf_l2tp_tunnel, tvb, index, 2, FALSE);
1841         }
1842         index += 2;
1843         if (tree) {
1844                 proto_tree_add_item(l2tp_tree, hf_l2tp_session, tvb, index, 2, FALSE);
1845         }
1846         index += 2;
1847
1848         if (SEQUENCE_BIT(control)) {
1849                 if (tree) {
1850                         proto_tree_add_item(l2tp_tree, hf_l2tp_Ns, tvb, index, 2, FALSE);
1851                 }
1852                 index += 2;
1853                 if (tree) {
1854                         proto_tree_add_item(l2tp_tree, hf_l2tp_Nr, tvb, index, 2, FALSE);
1855                 }
1856                 index += 2;
1857         }
1858         if (OFFSET_BIT(control)) {
1859                 offset_size = tvb_get_ntohs(tvb, index);
1860                 if (tree) {
1861                         proto_tree_add_uint(l2tp_tree, hf_l2tp_offset, tvb, index, 2,
1862                                                                 offset_size);
1863                 }
1864                 index += 2;
1865                 if (offset_size != 0) {
1866                         if (tree) {
1867                                 proto_tree_add_text(l2tp_tree, tvb, index, offset_size, "Offset Padding");
1868                         }
1869                         index += offset_size;
1870                 }
1871         }
1872         
1873         if (tree && (LENGTH_BIT(control))&&(length==12)) {
1874                 proto_tree_add_text(l2tp_tree, tvb, 0, 0, "Zero Length Bit message");
1875         }
1876
1877         if (!CONTROL_BIT(control)) {  /* Data Messages so we are done */
1878                 if (tree)
1879                         proto_item_set_len(l2tp_item, index);
1880                 /* If we have data, signified by having a length bit, dissect it */
1881                 if (tvb_offset_exists(tvb, index)) {
1882                         next_tvb = tvb_new_subset_remaining(tvb, index);
1883                         call_dissector(ppp_hdlc_handle, next_tvb, pinfo, tree);
1884                 }
1885                 return tvb_length(tvb);
1886         }
1887
1888         if (LENGTH_BIT(control))
1889                 process_control_avps(tvb, pinfo, l2tp_tree, index, length);
1890
1891         return tvb_length(tvb);
1892 }
1893
1894
1895 /*
1896  * Only L2TPv3 runs directly over IP, and dissect_l2tp_ip starts dissecting
1897  * those packets to call either process_l2tpv3_control for Control Messages
1898  * or process_l2tpv3_data_ip for Data Messages over IP, based on the
1899  * Session ID
1900  */
1901 static void
1902 dissect_l2tp_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1903 {
1904         int index = 0;
1905         guint32 sid;                    /* Session ID */
1906
1907         if (check_col(pinfo->cinfo, COL_PROTOCOL))      /* Only L2TPv3 runs directly over IP */
1908                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "L2TPv3");
1909
1910         col_clear(pinfo->cinfo, COL_INFO);
1911
1912         sid = tvb_get_ntohl(tvb, index);
1913         if (sid == 0) {
1914                 /* This is control message */
1915                 /* Call to process l2tp v3 control message */
1916                 process_l2tpv3_control(tvb, pinfo, tree, 4);
1917         }
1918         else {
1919                 /* Call to process l2tp v3 data message */
1920                 process_l2tpv3_data_ip(tvb, pinfo, tree);
1921         }
1922         
1923         return; 
1924 }
1925
1926 /* registration with the filtering engine */
1927 void
1928 proto_register_l2tp(void)
1929 {
1930         static hf_register_info hf[] = {
1931                 { &hf_l2tp_type,
1932                 { "Type", "l2tp.type", FT_UINT16, BASE_DEC, VALS(l2tp_type_vals), 0x8000,
1933                         "Type bit", HFILL }},
1934
1935                 { &hf_l2tp_length_bit,
1936                 { "Length Bit", "l2tp.length_bit", FT_BOOLEAN, 16, TFS(&l2tp_length_bit_truth), 0x4000,
1937                         "Length bit", HFILL }},
1938
1939                 { &hf_l2tp_seq_bit,
1940                 { "Sequence Bit", "l2tp.seq_bit", FT_BOOLEAN, 16, TFS(&l2tp_seq_bit_truth), 0x0800,
1941                         "Sequence bit", HFILL }},
1942
1943                 { &hf_l2tp_offset_bit,
1944                 { "Offset bit", "l2tp.offset_bit", FT_BOOLEAN, 16, TFS(&l2tp_offset_bit_truth), 0x0200,
1945                         NULL, HFILL }},
1946
1947                 { &hf_l2tp_priority,
1948                 { "Priority", "l2tp.priority", FT_BOOLEAN, 16, TFS(&l2tp_priority_truth), 0x0100,
1949                         "Priority bit", HFILL }},
1950
1951                 { &hf_l2tp_version,
1952                 { "Version", "l2tp.version", FT_UINT16, BASE_DEC, NULL, 0x000f,
1953                         NULL, HFILL }},
1954
1955                 { &hf_l2tp_length,
1956                 { "Length","l2tp.length", FT_UINT16, BASE_DEC, NULL, 0x0,
1957                         NULL, HFILL }},
1958
1959                 { &hf_l2tp_tunnel,
1960                 { "Tunnel ID","l2tp.tunnel", FT_UINT16, BASE_DEC, NULL, 0x0, /* Probably should be FT_BYTES */
1961                         NULL, HFILL }},
1962
1963                 { &hf_l2tp_session,
1964                 { "Session ID","l2tp.session", FT_UINT16, BASE_DEC, NULL, 0x0, /* Probably should be FT_BYTES */
1965                         NULL, HFILL }},
1966
1967                 { &hf_l2tp_Ns,
1968                 { "Ns","l2tp.Ns", FT_UINT16, BASE_DEC, NULL, 0x0,
1969                         NULL, HFILL }},
1970
1971                 { &hf_l2tp_Nr,
1972                 { "Nr","l2tp.Nr", FT_UINT16, BASE_DEC, NULL, 0x0,
1973                         NULL, HFILL }},
1974
1975                 { &hf_l2tp_offset,
1976                 { "Offset","l2tp.offset", FT_UINT16, BASE_DEC, NULL, 0x0,
1977                         "Number of octest past the L2TP header at which thepayload data starts.", HFILL }},
1978
1979                 { &hf_l2tp_avp_mandatory,
1980                 { "Mandatory", "l2tp.avp.mandatory", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1981                         "Mandatory AVP", HFILL }},
1982
1983                 { &hf_l2tp_avp_hidden,
1984                 { "Hidden", "l2tp.avp.hidden", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1985                         "Hidden AVP", HFILL }},
1986
1987                 { &hf_l2tp_avp_length,
1988                 { "Length", "l2tp.avp.length", FT_UINT16, BASE_DEC, NULL, 0,
1989                         "AVP Length", HFILL }},
1990
1991                 { &hf_l2tp_avp_vendor_id,
1992                 { "Vendor ID", "l2tp.avp.vendor_id", FT_UINT16, BASE_DEC, VALS(sminmpec_values), 0,
1993                         "AVP Vendor ID", HFILL }},
1994
1995                 { &hf_l2tp_avp_type,
1996                 { "Type", "l2tp.avp.type", FT_UINT16, BASE_DEC, VALS(avp_type_vals), 0,
1997                         "AVP Type", HFILL }},
1998
1999                 { &hf_l2tp_tie_breaker,
2000                 { "Tie Breaker", "l2tp.tie_breaker", FT_UINT64, BASE_HEX, NULL, 0,
2001                         NULL, HFILL }},
2002
2003                 { &hf_l2tp_sid,
2004                 { "Session ID","l2tp.sid", FT_UINT32, BASE_DEC, NULL, 0x0,
2005                         NULL, HFILL }},
2006
2007                 { &hf_l2tp_ccid,
2008                 { "Control Connection ID","l2tp.ccid", FT_UINT32, BASE_DEC, NULL, 0x0,
2009                         NULL, HFILL }},
2010
2011                 { &hf_l2tp_res,
2012                 { "Reserved","l2tp.res", FT_UINT16, BASE_HEX, NULL, 0x0,
2013                         NULL, HFILL }},
2014
2015                 { &hf_l2tp_cookie,
2016                 { "Cookie","lt2p.cookie", FT_BYTES, BASE_NONE, NULL, 0x0,
2017                         NULL, HFILL }},
2018
2019                 { &hf_l2tp_l2_spec_def,
2020                 { "Default L2-Specific Sublayer","lt2p.l2_spec_def", FT_NONE, BASE_NONE, NULL, 0x0,
2021                         NULL, HFILL }},
2022
2023                 { &hf_l2tp_l2_spec_atm,
2024                 { "ATM-Specific Sublayer","lt2p.l2_spec_atm", FT_NONE, BASE_NONE, NULL, 0x0,
2025                         NULL, HFILL }},
2026
2027                 { &hf_l2tp_l2_spec_s,
2028                 { "S-bit","lt2p.l2_spec_s", FT_BOOLEAN, 8, NULL, 0x40,
2029                         "Sequence Bit", HFILL }},
2030
2031                 { &hf_l2tp_l2_spec_t,
2032                 { "T-bit","lt2p.l2_spec_t", FT_BOOLEAN, 8, NULL, 0x08,
2033                         "Transport Type Bit", HFILL }},
2034
2035                 { &hf_l2tp_l2_spec_g, 
2036                 { "G-bit","lt2p.l2_spec_g", FT_BOOLEAN, 8, NULL, 0x04,
2037                         "EFCI Bit", HFILL }},
2038
2039                 { &hf_l2tp_l2_spec_c,
2040                 { "C-bit","lt2p.l2_spec_c", FT_BOOLEAN, 8, NULL, 0x02,
2041                         "CLP Bit", HFILL }},
2042
2043                 { &hf_l2tp_l2_spec_u,
2044                 { "U-bit","lt2p.l2_spec_u", FT_BOOLEAN, 8, NULL, 0x01,
2045                         "C/R Bit", HFILL }},
2046
2047                 { &hf_l2tp_l2_spec_sequence,
2048                 { "Sequence Number","lt2p.l2_spec_sequence", FT_UINT24, BASE_DEC, NULL, 0x0,
2049                         NULL, HFILL }},
2050
2051                 { &hf_l2tp_cisco_avp_type,
2052                 { "Type", "l2tp.avp.ciscotype", FT_UINT16, BASE_DEC, VALS(cisco_avp_type_vals), 0,
2053                         "AVP Type", HFILL }},
2054
2055         };
2056
2057         static gint *ett[] = {
2058                 &ett_l2tp,
2059                 &ett_l2tp_ctrl,
2060                 &ett_l2tp_avp,
2061                 &ett_l2tp_avp_sub,
2062                 &ett_l2tp_l2_spec,
2063                 &ett_l2tp_lcp,
2064         };
2065
2066         module_t *l2tp_module;
2067
2068         proto_l2tp = proto_register_protocol(
2069                 "Layer 2 Tunneling Protocol", "L2TP", "l2tp");
2070         proto_register_field_array(proto_l2tp, hf, array_length(hf));
2071         proto_register_subtree_array(ett, array_length(ett));
2072
2073         l2tp_module = prefs_register_protocol(proto_l2tp, NULL);
2074
2075         prefs_register_enum_preference(l2tp_module,
2076                                         "cookie_size",
2077                                         "L2TPv3 Cookie Size",
2078                                         "L2TPv3 Cookie Size",
2079                                         &l2tpv3_cookie,
2080                                         l2tpv3_cookies,
2081                                         FALSE);
2082
2083         prefs_register_enum_preference(l2tp_module,
2084                                         "l2_specific",
2085                                         "L2TPv3 L2-Specific Sublayer",
2086                                         "L2TPv3 L2-Specific Sublayer",
2087                                         &l2tpv3_l2_specific,
2088                                         l2tpv3_l2_specifics,
2089                                         FALSE);
2090
2091         prefs_register_enum_preference(l2tp_module,
2092                                         "protocol",
2093                                         "Decode L2TPv3 packet contents as this protocol",
2094                                         "Decode L2TPv3 packet contents as this protocol",
2095                                         &l2tpv3_protocol,
2096                                         l2tpv3_protocols,
2097                                         FALSE);
2098
2099 }
2100
2101 void
2102 proto_reg_handoff_l2tp(void)
2103 {
2104         dissector_handle_t l2tp_udp_handle;
2105         dissector_handle_t l2tp_ip_handle;
2106
2107         l2tp_udp_handle = new_create_dissector_handle(dissect_l2tp_udp, proto_l2tp);
2108         dissector_add("udp.port", UDP_PORT_L2TP, l2tp_udp_handle);
2109
2110         l2tp_ip_handle = create_dissector_handle(dissect_l2tp_ip, proto_l2tp);
2111         dissector_add("ip.proto", IP_PROTO_L2TP, l2tp_ip_handle);
2112
2113         /*
2114          * Get a handle for the PPP-in-HDLC-like-framing dissector.
2115          */
2116         ppp_hdlc_handle = find_dissector("ppp_hdlc");
2117         ppp_lcp_options_handle = find_dissector("ppp_lcp_options");
2118
2119         /*
2120          * Get a handle for the dissectors used in v3.
2121          */
2122         eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
2123         chdlc_handle = find_dissector("chdlc");
2124         fr_handle = find_dissector("fr");
2125         ip_handle = find_dissector("ip");
2126         mpls_handle = find_dissector("mpls");
2127         atm_oam_handle = find_dissector("atm_oam_cell");
2128         llc_handle = find_dissector("llc");
2129         lapd_handle = find_dissector("lapd");
2130
2131         data_handle = find_dissector("data");
2132 }