Fix various typos and spelling errors (mostly in text strings)
[obnox/wireshark/wip.git] / epan / dissectors / packet-btl2cap.c
1 /* packet-btl2cap.c
2  * Routines for the Bluetooth L2CAP dissection
3  * Copyright 2002, Christoph Scholz <scholz@cs.uni-bonn.de>
4  *  From: http://affix.sourceforge.net/archive/ethereal_affix-3.patch
5  *
6  * Refactored for wireshark checkin
7  *   Ronnie Sahlberg 2006
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 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <glib.h>
35
36 #include <epan/packet.h>
37 #include <etypes.h>
38 #include <epan/emem.h>
39 #include "packet-bthci_acl.h"
40 #include "packet-btl2cap.h"
41
42 /* Initialize the protocol and registered fields */
43 static int proto_btl2cap = -1;
44 static int hf_btl2cap_length = -1;
45 static int hf_btl2cap_cid = -1;
46 static int hf_btl2cap_payload = -1;
47 static int hf_btl2cap_command = -1;
48 static int hf_btl2cap_cmd_code = -1;
49 static int hf_btl2cap_cmd_ident = -1;
50 static int hf_btl2cap_cmd_length = -1;
51 static int hf_btl2cap_cmd_data = -1;
52 static int hf_btl2cap_psm = -1;
53 static int hf_btl2cap_scid = -1;
54 static int hf_btl2cap_dcid = -1;
55 static int hf_btl2cap_result = -1;
56 static int hf_btl2cap_status = -1;
57 static int hf_btl2cap_rej_reason = -1;
58 static int hf_btl2cap_sig_mtu = -1;
59 static int hf_btl2cap_info_mtu = -1;
60 static int hf_btl2cap_info_flowcontrol = -1;
61 static int hf_btl2cap_info_retransmission = -1;
62 static int hf_btl2cap_info_bidirqos = -1;
63 static int hf_btl2cap_info_type = -1;
64 static int hf_btl2cap_info_result = -1;
65 static int hf_btl2cap_continuation_flag = -1;
66 static int hf_btl2cap_configuration_result = -1;
67 static int hf_btl2cap_info_extfeatures = -1;
68 static int hf_btl2cap_option = -1;
69 static int hf_btl2cap_option_type = -1;
70 static int hf_btl2cap_option_length = -1;
71 static int hf_btl2cap_option_mtu = -1;
72 static int hf_btl2cap_option_flushTO = -1;
73 static int hf_btl2cap_option_flags = -1;
74 static int hf_btl2cap_option_service_type = -1;
75 static int hf_btl2cap_option_tokenrate = -1;
76 static int hf_btl2cap_option_tokenbucketsize = -1;
77 static int hf_btl2cap_option_peakbandwidth = -1;
78 static int hf_btl2cap_option_latency = -1;
79 static int hf_btl2cap_option_delayvariation = -1;
80 static int hf_btl2cap_option_retransmissionmode = -1;
81 static int hf_btl2cap_option_txwindow = -1;
82 static int hf_btl2cap_option_maxtransmit = -1;
83 static int hf_btl2cap_option_retransmittimeout = -1;
84 static int hf_btl2cap_option_monitortimeout = -1;
85 static int hf_btl2cap_option_mps = -1;
86 static int hf_btl2cap_control = -1;
87 static int hf_btl2cap_control_sar = -1;
88 static int hf_btl2cap_control_reqseq = -1;
89 static int hf_btl2cap_control_txseq = -1;
90 static int hf_btl2cap_control_retransmissiondisable = -1;
91 static int hf_btl2cap_control_supervisory = -1;
92 static int hf_btl2cap_control_type = -1;
93 static int hf_btl2cap_fcs = -1;
94 static int hf_btl2cap_sdulength = -1;
95 static int hf_btl2cap_continuation_to = -1;
96 static int hf_btl2cap_reassembled_in = -1;
97
98 /* Initialize the subtree pointers */
99 static gint ett_btl2cap = -1;
100 static gint ett_btl2cap_cmd = -1;
101 static gint ett_btl2cap_option = -1;
102 static gint ett_btl2cap_extfeatures = -1;
103 static gint ett_btl2cap_control = -1;
104
105
106 /* Initialize dissector table */
107 dissector_table_t l2cap_psm_dissector_table;
108
109 /* This table maps cid values to psm values.
110  * The same table is used both for SCID and DCID.
111  * For received CIDs we mask the cid with 0x8000 in this table
112  */
113 static emem_tree_t *cid_to_psm_table = NULL;
114 typedef struct _config_data_t {
115         guint8          mode;
116         guint8          txwindow;
117         emem_tree_t *start_fragments;  /* indexed by pinfo->fd->num */
118 } config_data_t;
119 typedef struct _psm_data_t {
120         guint16                 psm;
121         config_data_t   in;
122         config_data_t   out;
123 } psm_data_t;
124
125 static const value_string command_code_vals[] = {
126         { 0x01, "Command Reject" },
127         { 0x02, "Connection Request" },
128         { 0x03, "Connection Response" },
129         { 0x04, "Configure Request" },
130         { 0x05, "Configure Response" },
131         { 0x06, "Disconnect Request" },
132         { 0x07, "Disconnect Response" },
133         { 0x08, "Echo Request" },
134         { 0x09, "Echo Response" },
135         { 0x0A, "Information Request" },
136         { 0x0B, "Information Response" },
137         { 0, NULL }
138 };
139
140
141 static const value_string psm_vals[] = {
142         { 0x0001,       "SDP" },
143         { 0x0003,       "RFCOMM" },
144         { 0x0005,       "TCS-BIN" },
145         { 0x0007,       "TCS-BIN-CORDLESS" },
146         { 0x000F,       "BNEP" },
147         { 0x0011,       "HID_CONTROL" },
148         { 0x0013,       "HID_INTERRUPT" },
149         { 0x0015,       "UPnP" },
150         { 0x0017,       "AVCTP" },
151         { 0x0019,       "AVDTP" },
152         { 0x001D,       "UDI_C-Plane" },
153         { 0, NULL }
154 };
155
156
157 static const value_string result_vals[] = {
158         { 0x0000,       "Connection successful" },
159         { 0x0001,       "Connection pending" },
160         { 0x0002,       "Connection Refused - PSM not supported" },
161         { 0x0003,       "Connection refused - security block" },
162         { 0x0004,       "Connection refused - no resources available" },
163         { 0, NULL }
164 };
165
166 static const value_string configuration_result_vals[] = {
167         { 0x0000, "Success"},
168         { 0x0001, "Failure - unacceptable parameters" },
169         { 0x0002, "Failure - reject (no reason provided)" },
170         { 0x0003, "Failure - unknown options" },
171         { 0, NULL }
172 };
173
174 static const value_string status_vals[] = {
175         { 0x0000,       "No further information available" },
176         { 0x0001,       "Authentication pending" },
177         { 0x0002,       "Authorization pending" },
178         { 0, NULL }
179 };
180
181 static const value_string reason_vals[] = {
182         { 0x0000,       "Command not understood" },
183         { 0x0001,       "Signaling MTU exceeded" },
184         { 0x0002,       "Invalid CID in request" },
185         { 0, NULL }
186 };
187
188 static const value_string info_type_vals[] = {
189         { 0x0001, "Connectionless MTU" },
190         { 0x0002, "Extended Features Mask" },
191         { 0, NULL }
192 };
193
194 static const value_string info_result_vals[] = {
195         { 0x0000, "Success" },
196         { 0x0001, "Not Supported" },
197         { 0, NULL }
198 };
199
200 static const value_string option_servicetype_vals[] = {
201         { 0x00, "No traffic" },
202         { 0x01, "Best effort (Default)" },
203         { 0x02, "Guaranteed" },
204         { 0, NULL }
205 };
206
207 static const value_string option_type_vals[] = {
208         { 0x01, "Maximum Transmission Unit" },
209         { 0x02, "Flush Timeout" },
210         { 0x03, "Quality of Service" },
211         { 0x04, "Retransmission and Flow Control" },
212         { 0, NULL }
213 };
214
215 static const value_string option_retransmissionmode_vals[] = {
216         { 0x00, "Basic Mode" },
217         { 0x01, "Retransmission Mode" },
218         { 0x02, "Flow Control Mode" },
219         { 0, NULL }
220 };
221
222 static const value_string control_sar_vals[] = {
223         { 0x00, "Unsegmented" },
224         { 0x01, "Start" },
225         { 0x02, "End" },
226         { 0x03, "Continuation" },
227         { 0, NULL }
228 };
229
230 static const value_string control_supervisory_vals[] = {
231         { 0x00, "RR" },
232         { 0x01, "REJ" },
233         { 0, NULL }
234 };
235
236 static const value_string control_type_vals[] = {
237         { 0x00, "I-Frame" },
238         { 0x01, "S-Frame" },
239         { 0, NULL }
240 };
241
242 static int 
243 dissect_comrej(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
244 {
245         guint16 reason;
246
247         reason = tvb_get_letohs(tvb, offset);
248         proto_tree_add_item(tree, hf_btl2cap_rej_reason, tvb, offset, 2, TRUE);
249         offset+=2;
250
251         switch(reason){
252         case 0x0000: /* Command not understood */
253                 break;
254
255         case 0x0001: /* Signaling MTU exceeded */
256                 proto_tree_add_item(tree, hf_btl2cap_sig_mtu, tvb, offset, 2, TRUE);
257                 offset+=2;
258                 break;
259
260         case 0x0002: /* Invalid CID in requets */
261                 proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, TRUE);
262                 offset+=2;
263
264                 proto_tree_add_item(tree, hf_btl2cap_dcid, tvb, offset, 2, TRUE);
265                 offset+=2;
266
267                 break;
268
269         default:
270                 break;
271         }
272
273         return offset;
274 }
275
276 static int
277 dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
278 {
279         guint16 scid, psm;
280         psm_data_t *psm_data;
281
282         psm=tvb_get_letohs(tvb, offset);
283         proto_tree_add_item(tree, hf_btl2cap_psm, tvb, offset, 2, TRUE);
284         offset+=2;
285
286         scid=tvb_get_letohs(tvb, offset);
287         proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, TRUE);
288         offset+=2;
289
290         if (pinfo->fd->flags.visited == 0) {
291                 psm_data=se_alloc(sizeof(psm_data_t));
292                 psm_data->psm=psm;
293                 psm_data->in.mode=0;
294                 psm_data->in.txwindow=0;
295                 psm_data->in.start_fragments=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "bthci_l2cap fragment starts");
296                 psm_data->out.mode=0;
297                 psm_data->out.txwindow=0;
298                 psm_data->out.start_fragments=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "bthci_l2cap fragment starts");
299                 se_tree_insert32(cid_to_psm_table, scid|((pinfo->p2p_dir == P2P_DIR_RECV)?0x8000:0x0000), psm_data);
300
301         }
302         return offset;
303 }
304
305
306 static int
307 dissect_options(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int length, config_data_t *config_data)
308 {
309         proto_item *ti_option=NULL;
310         proto_tree *ti_option_subtree=NULL;
311         guint8 option_type, option_length;
312
313         while(length>0){
314                 option_type   = tvb_get_guint8(tvb, offset);
315                 option_length = tvb_get_guint8(tvb, offset+1);
316
317                 ti_option = proto_tree_add_none_format(tree, 
318                                 hf_btl2cap_option, tvb,
319                                 offset, option_length + 2,
320                                 "Option: ");
321                 ti_option_subtree = proto_item_add_subtree(ti_option, ett_btl2cap_option);
322                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_type, tvb, offset, 1, TRUE);
323                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_length, tvb, offset+1, 1, TRUE);
324                 offset+=2;
325
326                 if(option_length>0){
327                         switch(option_type){
328                         case 0x01: /* MTU */
329                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_mtu, tvb, offset, 2, TRUE);
330                                 offset+=2;
331
332                                 proto_item_append_text(ti_option, "MTU");
333                                 break;
334
335                         case 0x02: /* Flush timeout */
336                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_flushTO, tvb, offset, 2, TRUE);
337                                 offset+=2;
338
339                                 proto_item_append_text(ti_option, "Flush Timeout");
340                                 break;
341
342                         case 0x03: /* QOS */
343                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_flags, tvb, offset, 1, TRUE);
344                                 offset++;
345
346                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_service_type, tvb, offset, 1, TRUE);
347                                 offset++;
348
349                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_tokenrate, tvb, offset, 4, TRUE);
350                                 offset+=4;
351
352                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_tokenbucketsize, tvb, offset, 4, TRUE);
353                                 offset+=4;
354
355                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_peakbandwidth, tvb, offset, 4, TRUE);
356                                 offset+=4;
357
358                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_latency, tvb, offset, 4, TRUE);
359                                 offset+=4;
360
361                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_delayvariation, tvb, offset, 4, TRUE);
362                                 offset+=4;
363
364                                 proto_item_append_text(ti_option, "QOS");
365                                 break;
366
367                         case 0x04: /* Retransmission and Flow Control*/
368                                 if(config_data) 
369                                 {
370                                         config_data->mode = tvb_get_guint8(tvb, offset);
371                                         config_data->txwindow = tvb_get_guint8(tvb, offset+1);
372                                 }
373                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_retransmissionmode, tvb, offset, 1, TRUE);
374                                 offset++;
375
376                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_txwindow, tvb, offset, 1, TRUE);
377                                 offset++;
378
379                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_maxtransmit, tvb, offset, 1, TRUE);
380                                 offset++;
381
382                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_retransmittimeout, tvb, offset, 2, TRUE);
383                                 offset+= 2;
384
385                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_monitortimeout, tvb, offset, 2, TRUE);
386                                 offset+= 2;
387
388                                 proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_mps, tvb, offset, 2, TRUE);
389                                 offset+= 2;
390
391                                 proto_item_append_text(ti_option, "Retransmission and Flow Control");
392                                 break;
393
394                         default:
395                                 proto_item_append_text(ti_option, "unknown");
396                                 offset+=option_length;
397                                 break;
398                         }
399                 }
400                 length -= (option_length + 2);
401         }
402         return offset;
403 }
404
405
406
407 static int
408 dissect_configrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, guint16 length)
409 {
410         psm_data_t *psm_data;
411         config_data_t *config_data;
412         guint16 dcid;
413
414         dcid = tvb_get_letohs(tvb, offset);
415         psm_data=se_tree_lookup32(cid_to_psm_table, dcid|((pinfo->p2p_dir==P2P_DIR_RECV)?0x0000:0x8000));
416         proto_tree_add_item(tree, hf_btl2cap_dcid, tvb, offset, 2, TRUE);
417         offset+=2;
418
419         proto_tree_add_item(tree, hf_btl2cap_continuation_flag, tvb, offset, 2, TRUE);
420         offset+=2;
421
422         if(tvb_length_remaining(tvb, offset)){
423                 if (psm_data)
424                         if(pinfo->p2p_dir==P2P_DIR_RECV)
425                                 config_data = &(psm_data->out);
426                         else
427                                 config_data = &(psm_data->in);
428                 else
429                         config_data = NULL;
430                 offset=dissect_options(tvb, offset, pinfo, tree, length - 4, config_data);
431         }
432
433         return offset;
434 }
435
436
437 static int
438 dissect_inforequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
439 {
440         proto_tree_add_item(tree, hf_btl2cap_info_type, tvb, offset, 2, TRUE);
441         offset+=2;
442
443         return offset;
444 }
445
446 static int
447 dissect_inforesponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
448 {
449         guint16 info_type;
450         proto_item *ti_features=NULL;
451         proto_tree *ti_features_subtree=NULL;
452         guint32 features;
453
454         info_type=tvb_get_letohs(tvb, offset);
455         proto_tree_add_item(tree, hf_btl2cap_info_type, tvb, offset, 2, TRUE);
456         offset+=2;
457
458         proto_tree_add_item(tree, hf_btl2cap_info_result, tvb, offset, 2, TRUE);
459         offset+=2;
460
461         if(tvb_length_remaining(tvb, offset)) {
462                 switch(info_type){
463                 case 0x0001: /* Connectionless MTU */
464                         proto_tree_add_item(tree, hf_btl2cap_info_mtu, tvb, offset, 2, TRUE);
465                         offset+=2;
466
467                         break;
468                 case 0x0002: /* Extended Features */
469                         ti_features = proto_tree_add_none_format(tree, 
470                                         hf_btl2cap_info_extfeatures, tvb,
471                                         offset, 4,
472                                         "Features: ");
473                         ti_features_subtree = proto_item_add_subtree(ti_features, ett_btl2cap_extfeatures);
474                         features = tvb_get_letohl(tvb, offset);
475                         if(features & 0x1)
476                                 proto_item_append_text(ti_features, "FlowControl ");
477                         if(features & 0x2)
478                                 proto_item_append_text(ti_features, "Retransmission ");
479                         if(features & 0x4)
480                                 proto_item_append_text(ti_features, "BiDirQOS ");
481                         proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_flowcontrol, tvb, offset, 1, TRUE);
482                         proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_retransmission, tvb, offset, 1, TRUE);
483                         proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_bidirqos, tvb, offset, 1, TRUE);
484                         offset+=4;
485
486                         break;
487                 default:
488                         proto_tree_add_item(tree, hf_btl2cap_cmd_data, tvb, offset, -1, TRUE);
489                         offset+=tvb_length_remaining(tvb, offset);
490
491                         break;
492                 }
493         }
494
495         return offset;
496 }
497
498 static int
499 dissect_configresponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, guint16 length)
500 {
501         psm_data_t *psm_data;
502         config_data_t *config_data;
503         guint16 scid;
504
505         scid = tvb_get_letohs(tvb, offset);
506         psm_data=se_tree_lookup32(cid_to_psm_table, scid|((pinfo->p2p_dir==P2P_DIR_RECV)?0x0000:0x8000));
507         proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, TRUE);
508         offset+=2;
509
510         proto_tree_add_item(tree, hf_btl2cap_continuation_flag, tvb, offset, 2, TRUE);
511         offset+=2;
512
513         proto_tree_add_item(tree, hf_btl2cap_configuration_result, tvb, offset, 2, TRUE);
514         offset+=2;
515
516         if(tvb_length_remaining(tvb, offset)){
517                 if (psm_data)
518                         if(pinfo->p2p_dir==P2P_DIR_RECV)
519                                 config_data = &(psm_data->out);
520                         else
521                                 config_data = &(psm_data->in);
522                 else
523                         config_data = NULL;
524                 offset=dissect_options(tvb, offset, pinfo, tree, length - 6, config_data);
525         }
526
527         return offset;
528 }
529
530 static int 
531 dissect_connresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
532 {
533         guint16 scid, dcid;
534         psm_data_t *psm_data;
535
536         dcid = tvb_get_letohs(tvb, offset);
537         proto_tree_add_item(tree, hf_btl2cap_dcid, tvb, offset, 2, TRUE);
538         offset+=2;
539
540         scid = tvb_get_letohs(tvb, offset);
541         proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, TRUE);
542         offset+=2;
543
544         proto_tree_add_item(tree, hf_btl2cap_result, tvb, offset, 2, TRUE);
545         offset+=2;
546
547         proto_tree_add_item(tree, hf_btl2cap_status, tvb, offset, 2, TRUE);
548         offset+=2;
549
550         if (pinfo->fd->flags.visited == 0) {
551                 if((psm_data=se_tree_lookup32(cid_to_psm_table, scid|((pinfo->p2p_dir==P2P_DIR_RECV)?0x0000:0x8000)))){
552                         se_tree_insert32(cid_to_psm_table, dcid|((pinfo->p2p_dir == P2P_DIR_RECV)?0x8000:0x0000), psm_data);
553                 }
554         }
555
556         return offset;
557 }
558
559
560 static int
561 dissect_disconnrequestresponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
562 {
563         guint16 scid, dcid;
564
565         dcid = tvb_get_letohs(tvb, offset);
566         proto_tree_add_item(tree, hf_btl2cap_dcid, tvb, offset, 2, TRUE);
567         offset+=2;
568
569         scid = tvb_get_letohs(tvb, offset);
570         proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, TRUE);
571         offset+=2;
572
573         return offset;
574 }
575
576 static void dissect_b_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *btl2cap_tree, guint16 psm, guint16 length, int offset)
577 {
578         tvbuff_t *next_tvb;
579         next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), length);
580
581         if(check_col(pinfo->cinfo, COL_INFO)){
582                 col_append_str(pinfo->cinfo, COL_INFO, "Connection oriented channel");
583         }
584
585         if(psm){
586                 proto_item *psm_item;
587
588                 psm_item=proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm);
589                 PROTO_ITEM_SET_GENERATED(psm_item);
590
591                 /* call next dissector */
592                 if (!dissector_try_port(l2cap_psm_dissector_table, (guint32) psm,
593                                         next_tvb, pinfo, tree)) {
594                         /* unknown protocol. declare as data */
595                         proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, TRUE);
596                 }
597                 offset+=tvb_length_remaining(tvb, offset);
598         } else {
599                 proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, TRUE);
600                 offset+=tvb_length_remaining(tvb, offset);
601         }
602 }
603
604 typedef struct _sdu_reassembly_t
605 {
606         guint8* reassembled;
607         guint8 seq;
608         guint32 first_frame;
609         guint32 last_frame;
610         guint16 tot_len;
611         int cur_off;    /* counter used by reassembly */
612 } sdu_reassembly_t;
613
614 static void dissect_i_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *btl2cap_tree, psm_data_t *psm_data, guint16 length, int offset, config_data_t *config_data)
615 {
616         tvbuff_t *next_tvb = NULL;
617         guint16 control, segment;
618         guint16 sdulen;
619         proto_item* ti_control;
620         proto_tree* ti_control_subtree;
621         sdu_reassembly_t* mfp = NULL;
622         guint16 psm = (psm_data?psm_data->psm:0);
623
624         control = tvb_get_letohs(tvb, offset);
625         segment = (control & 0xC000) >> 14;
626         if(check_col(pinfo->cinfo, COL_INFO)){
627                 switch(segment)
628                 {
629                 case 0:
630                         col_append_str(pinfo->cinfo, COL_INFO, "[I] Unsegmented SDU");
631                         break;
632                 case 1:
633                         col_append_str(pinfo->cinfo, COL_INFO, "[I] Start SDU");
634                         break;
635                 case 2:
636                         col_append_str(pinfo->cinfo, COL_INFO, "[I] End SDU");
637                         break;
638                 case 3:
639                         col_append_str(pinfo->cinfo, COL_INFO, "[I] Continuation SDU");
640                         break;
641                 }
642         }
643         ti_control = proto_tree_add_none_format(btl2cap_tree, hf_btl2cap_control, tvb,
644                 offset, 2, "Control: %s reqseq:%d r:%d txseq:%d",
645                 val_to_str((control & 0xC000) >> 14, control_sar_vals, "unknown"),
646                 (control & 0x3F00) >> 8,
647                 (control & 0x0080) >> 7,
648                 (control & 0x007E) >> 1);
649         ti_control_subtree = proto_item_add_subtree(ti_control, ett_btl2cap_control);
650         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_sar, tvb, offset, 2, TRUE);
651         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_reqseq, tvb, offset, 2, TRUE);
652         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_retransmissiondisable, tvb, offset, 2, TRUE);
653         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_txseq, tvb, offset, 2, TRUE);
654         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_type, tvb, offset, 2, TRUE);
655         offset += 2;
656
657         /*Segmented frames with SAR = start have an extra SDU length header field*/
658         if(segment == 0x01) {
659                 sdulen = tvb_get_letohs(tvb, offset);
660                 proto_tree_add_item(btl2cap_tree, hf_btl2cap_sdulength, tvb, offset, 2, TRUE);
661                 offset += 2;
662                 length -= 6; /*Control, SDUlength, FCS*/
663                 if(!pinfo->fd->flags.visited){
664                         mfp=se_alloc(sizeof(sdu_reassembly_t));
665                         mfp->first_frame=pinfo->fd->num;
666                         mfp->last_frame=0;
667                         mfp->tot_len=sdulen;
668                         mfp->reassembled=se_alloc(sdulen);
669                         tvb_memcpy(tvb, mfp->reassembled, offset, length);
670                         mfp->cur_off=length;
671                         se_tree_insert32(config_data->start_fragments, pinfo->fd->num, mfp);
672                 } else {
673                         mfp=se_tree_lookup32(config_data->start_fragments, pinfo->fd->num);
674                 }
675                 if(mfp && mfp->last_frame){
676                         proto_item *item;
677                         item=proto_tree_add_uint(btl2cap_tree, hf_btl2cap_reassembled_in, tvb, 0, 0, mfp->last_frame);
678                         PROTO_ITEM_SET_GENERATED(item);
679                         if (check_col(pinfo->cinfo, COL_INFO)){
680                                 col_append_fstr(pinfo->cinfo, COL_INFO, "[Reassembled in #%u] ", mfp->last_frame);
681                         }
682                 }
683         } else {
684                 length -= 4; /*Control, FCS*/
685         }
686         if(segment == 0x02 || segment == 0x03) {
687                 mfp=se_tree_lookup32_le(config_data->start_fragments, pinfo->fd->num);
688                 if(!pinfo->fd->flags.visited){
689                         if(mfp && !mfp->last_frame && (mfp->tot_len>=mfp->cur_off+length)){
690                                 tvb_memcpy(tvb, mfp->reassembled+mfp->cur_off, offset, length);
691                                 mfp->cur_off+=length;
692                                 if(segment == 0x02){
693                                         mfp->last_frame=pinfo->fd->num;
694                                 }
695                         }
696                 }
697                 if(mfp){
698                         proto_item *item;
699                         item=proto_tree_add_uint(btl2cap_tree, hf_btl2cap_continuation_to, tvb, 0, 0, mfp->first_frame);
700                         PROTO_ITEM_SET_GENERATED(item);
701                         if (check_col(pinfo->cinfo, COL_INFO)){
702                                 col_append_fstr(pinfo->cinfo, COL_INFO, "[Continuation to #%u] ", mfp->first_frame);
703                         }
704                 }
705         }
706         if(segment == 0x02 && mfp && mfp->last_frame==pinfo->fd->num){
707                 next_tvb = tvb_new_real_data((guint8*)mfp->reassembled, mfp->tot_len, mfp->tot_len);
708                 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
709                 add_new_data_source(pinfo, next_tvb, "Reassembled L2CAP");
710         }
711         /*pass up to higher layer if we have a complete packet*/
712         if(segment == 0x00) {
713                 next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset) - 2, length);
714         }
715         if(next_tvb) {
716                 if(psm){
717                         proto_item *psm_item;
718
719                         psm_item=proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm);
720                         PROTO_ITEM_SET_GENERATED(psm_item);
721
722                         /* call next dissector */
723                         if (!dissector_try_port(l2cap_psm_dissector_table, (guint32) psm,
724                                                 next_tvb, pinfo, tree)) {
725                                 /* unknown protocol. declare as data */
726                                 proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, next_tvb, 0, tvb_length(next_tvb), TRUE);
727                         }
728                 } else {
729                         proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, next_tvb, 0, tvb_length(next_tvb), TRUE);
730                 }
731         }
732         offset+=(tvb_length_remaining(tvb, offset) - 2);
733         proto_tree_add_item(btl2cap_tree, hf_btl2cap_fcs, tvb, offset, 2, TRUE);
734         offset += 2;
735 }
736
737 static void dissect_s_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, proto_tree *btl2cap_tree, guint16 psm _U_, guint16 length _U_, int offset, config_data_t *config_data _U_)
738 {
739         proto_item* ti_control;
740         proto_tree* ti_control_subtree;
741         guint16 control;
742
743         control = tvb_get_letohs(tvb, offset);
744         if(check_col(pinfo->cinfo, COL_INFO)){
745                 switch((control & 0x000C) >> 2)
746                 {
747                 case 0:
748                         col_append_str(pinfo->cinfo, COL_INFO, "[S] Receiver Ready");
749                         break;
750                 case 1:
751                         col_append_str(pinfo->cinfo, COL_INFO, "[S] Reject");
752                         break;
753                 default:
754                         col_append_str(pinfo->cinfo, COL_INFO, "[S] Unknown supervisory frame");
755                         break;
756                 }
757         }
758         ti_control = proto_tree_add_none_format(btl2cap_tree, hf_btl2cap_control, tvb,
759                 offset, 2, "Control: %s reqseq:%d r:%d",
760                 val_to_str((control & 0x000C) >> 2, control_supervisory_vals, "unknown"),
761                 (control & 0x3F00) >> 8,
762                 (control & 0x0080) >> 7);
763         ti_control_subtree = proto_item_add_subtree(ti_control, ett_btl2cap_control);
764         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_reqseq, tvb, offset, 2, TRUE);
765         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_retransmissiondisable, tvb, offset, 2, TRUE);
766         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_supervisory, tvb, offset, 2, TRUE);
767         proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_type, tvb, offset, 2, TRUE);
768         offset += 2;
769         proto_tree_add_item(ti_control_subtree, hf_btl2cap_fcs, tvb, offset, 2, TRUE);
770         offset += 2;
771 }
772
773 /* Code to actually dissect the packets
774  * This dissector will only be called ontop of BTHCI ACL
775  * and this dissector _REQUIRES_ that 
776  * pinfo->private_data points to a valid bthci_acl_data_t structure
777  */
778 static void dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
779 {
780         int offset=0;
781         proto_item *ti=NULL;
782         proto_tree *btl2cap_tree=NULL;
783         guint16 length, cid;
784         guint16 psm;
785         guint16 control;
786         tvbuff_t *next_tvb;
787         psm_data_t *psm_data;
788         bthci_acl_data_t *acl_data;
789         btl2cap_data_t *l2cap_data;
790         config_data_t *config_data;
791
792         if(check_col(pinfo->cinfo, COL_PROTOCOL)){
793                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "L2CAP");
794         }
795         if(check_col(pinfo->cinfo, COL_INFO)){
796                 col_clear(pinfo->cinfo, COL_INFO);
797                 col_set_str(pinfo->cinfo, COL_INFO, pinfo->p2p_dir == P2P_DIR_SENT ? "Sent " : "Rcvd ");
798         }
799
800         if(tree){
801                 ti=proto_tree_add_item(tree, proto_btl2cap, tvb, offset, -1, FALSE);
802                 btl2cap_tree=proto_item_add_subtree(ti, ett_btl2cap);
803         }
804
805         length = tvb_get_letohs(tvb, offset);
806         proto_tree_add_item(btl2cap_tree, hf_btl2cap_length, tvb, offset, 2, TRUE);
807         offset+=2;
808
809         cid = tvb_get_letohs(tvb, offset);
810         proto_tree_add_item(btl2cap_tree, hf_btl2cap_cid, tvb, offset, 2, TRUE);
811         offset+=2;
812
813         acl_data=(bthci_acl_data_t *)pinfo->private_data;
814         l2cap_data=ep_alloc(sizeof(btl2cap_data_t));
815         l2cap_data->chandle=acl_data->chandle;
816         l2cap_data->cid=cid;
817         pinfo->private_data=l2cap_data;
818
819         if(cid==0x0001){ /* This is a command packet*/
820                 while(offset<(length+4)) {
821                         proto_tree *btl2cap_cmd_tree=NULL;
822                         proto_item *ti_command=NULL;
823                         guint8 cmd_code;
824                         guint16 cmd_length;
825
826                         ti_command=proto_tree_add_none_format(btl2cap_tree, 
827                                         hf_btl2cap_command, tvb,
828                                         offset, length,
829                                         "Command: ");      
830                         btl2cap_cmd_tree=proto_item_add_subtree(ti_command, ett_btl2cap_cmd);
831
832                         cmd_code=tvb_get_guint8(tvb, offset);
833                         proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cmd_code, tvb, offset, 1, TRUE);
834                         offset++;
835
836                         proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cmd_ident, tvb, offset, 1, TRUE);
837                         offset++;
838
839                         cmd_length=tvb_get_letohs(tvb, offset);
840                         proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cmd_length, tvb, offset, 2, TRUE);
841                         proto_item_set_len(ti_command, cmd_length+4);
842                         offset+=2;
843
844                         switch(cmd_code) {
845                         case 0x01: /* Command Reject */
846                                 offset=dissect_comrej(tvb, offset, pinfo, btl2cap_cmd_tree);
847                                 proto_item_append_text(ti_command, "Command Reject");
848                                 if ((check_col(pinfo->cinfo, COL_INFO))){
849                                         col_append_str(pinfo->cinfo, COL_INFO, "Command Reject");
850                                 }
851                                 break;
852
853                         case 0x02: /* Connection Request */
854                                 offset=dissect_connrequest(tvb, offset, pinfo, btl2cap_cmd_tree);
855                                 proto_item_append_text(ti_command, "Connection Request");
856                                 if ((check_col(pinfo->cinfo, COL_INFO))){
857                                         col_append_str(pinfo->cinfo, COL_INFO, "Connection Request");
858                                 }
859                                 break;
860
861                         case 0x03: /* Connection Response */
862                                 offset=dissect_connresponse(tvb, offset, pinfo, btl2cap_cmd_tree);
863                                 proto_item_append_text(ti_command, "Connection Response");
864                                 if ((check_col(pinfo->cinfo, COL_INFO))){
865                                         col_append_str(pinfo->cinfo, COL_INFO, "Connection Response");
866                                 }
867                                 break;
868                         case 0x04: /* Configure Request */
869                                 offset=dissect_configrequest(tvb, offset, pinfo, btl2cap_cmd_tree, cmd_length);
870                                 proto_item_append_text(ti_command, "Configure Request");
871                                 if ((check_col(pinfo->cinfo, COL_INFO))){
872                                         col_append_str(pinfo->cinfo, COL_INFO, "Configure Request");
873                                 }
874                                 break;
875
876                         case 0x05: /* Configure Response */
877                                 offset=dissect_configresponse(tvb, offset, pinfo, btl2cap_cmd_tree, cmd_length);
878                                 proto_item_append_text(ti_command, "Configure Response");
879                                 if ((check_col(pinfo->cinfo, COL_INFO))){
880                                         col_append_str(pinfo->cinfo, COL_INFO, "Configure Response");
881                                 }
882                                 break;
883
884                         case 0x06: /* Disconnect Request */
885                                 offset=dissect_disconnrequestresponse(tvb, offset, pinfo, btl2cap_cmd_tree);
886                                 proto_item_append_text(ti_command, "Disconnect Request");
887                                 if ((check_col(pinfo->cinfo, COL_INFO))){
888                                         col_append_str(pinfo->cinfo, COL_INFO, "Disconnect Request");
889                                 }
890                                 break;
891
892                         case 0x07: /* Disconnect Response */
893                                 offset=dissect_disconnrequestresponse(tvb, offset, pinfo, btl2cap_cmd_tree);   
894                                 proto_item_append_text(ti_command, "Disconnect Response");
895                                 if ((check_col(pinfo->cinfo, COL_INFO))){
896                                         col_append_str(pinfo->cinfo, COL_INFO, "Disconnect Response");
897                                 }
898                                 break;    
899
900                         case 0x08: /* Echo Request */
901                                 proto_item_append_text(ti_command, "Echo Request");
902                                 offset+=tvb_length_remaining(tvb, offset);
903                                 if ((check_col(pinfo->cinfo, COL_INFO))){
904                                         col_append_str(pinfo->cinfo, COL_INFO, "Echo Request");
905                                 }
906                                 break;
907
908                         case 0x09: /* Echo Response */
909                                 proto_item_append_text(ti_command, "Echo Response");
910                                 offset+=tvb_length_remaining(tvb, offset);
911                                 if ((check_col(pinfo->cinfo, COL_INFO))){
912                                         col_append_str(pinfo->cinfo, COL_INFO, "Echo Response");
913                                 }
914                                 break;
915
916                         case 0x0a: /* Information Request */
917                                 offset=dissect_inforequest(tvb, offset, pinfo, btl2cap_cmd_tree);
918
919                                 proto_item_append_text(ti_command, "Information Request");
920                                 if ((check_col(pinfo->cinfo, COL_INFO))){
921                                         col_append_str(pinfo->cinfo, COL_INFO, "Information Request");
922                                 }
923                                 break;
924
925                         case 0x0b: /* Information Response */
926                                 offset=dissect_inforesponse(tvb, offset, pinfo, btl2cap_cmd_tree);
927                                 proto_item_append_text(ti_command, "Information Response");
928                                 if ((check_col(pinfo->cinfo, COL_INFO))){
929                                         col_append_str(pinfo->cinfo, COL_INFO, "Information Response");
930                                 }
931                                 break;
932
933                                 default:
934                                         proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cmd_data, tvb, offset, -1, TRUE);
935                                         offset+=tvb_length_remaining(tvb, offset);
936                                         break;
937                         }
938                 }
939         } else if (cid == 0x0002) { /* Connectionless reception channel */
940                 if(check_col(pinfo->cinfo, COL_INFO)){
941                         col_append_str(pinfo->cinfo, COL_INFO, "Connectionless reception channel");
942                 }
943
944                 psm = tvb_get_letohs(tvb, offset);
945                 proto_tree_add_item(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 2, TRUE);
946                 offset+=2;
947
948
949                 next_tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), length);
950
951                 /* call next dissector */
952                 if(!dissector_try_port(l2cap_psm_dissector_table, (guint32) psm, 
953                                         next_tvb, pinfo, tree)){
954                         /* unknown protocol. declare as data */
955                         proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, TRUE);
956                 }
957                 offset+=tvb_length_remaining(tvb, offset);
958         } else if(cid >= 0x0040) { /* Connection oriented channel */
959                 if((psm_data=se_tree_lookup32(cid_to_psm_table, cid|((pinfo->p2p_dir==P2P_DIR_RECV)?0x0000:0x8000)))){
960                         psm=psm_data->psm;
961                         if(pinfo->p2p_dir==P2P_DIR_RECV)
962                                 config_data = &(psm_data->in);
963                         else
964                                 config_data = &(psm_data->out);
965                         if(config_data->mode == 0) {
966                                 dissect_b_frame(tvb, pinfo, tree, btl2cap_tree, psm, length, offset);
967                         } else {
968                                 control = tvb_get_letohs(tvb, offset);
969                                 if(control & 0x1) {
970                                         dissect_s_frame(tvb, pinfo, tree, btl2cap_tree, psm, length, offset, config_data);
971                                 } else {
972                                         dissect_i_frame(tvb, pinfo, tree, btl2cap_tree, psm_data, length, offset, config_data);
973                                 }
974                         }
975                 } else {
976                         psm=0;
977                         dissect_b_frame(tvb, pinfo, tree, btl2cap_tree, psm, length, offset);
978                 }
979
980         } else { /* Something else */
981                 if(check_col(pinfo->cinfo, COL_INFO)){
982                         col_clear(pinfo->cinfo, COL_INFO);
983                 }
984
985                 proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, TRUE);
986                 offset+=length;
987         }
988 }
989
990
991 /* Register the protocol with Wireshark */
992 void
993 proto_register_btl2cap(void)
994 {                 
995
996         /* Setup list of header fields  See Section 1.6.1 for details*/
997         static hf_register_info hf[] = {
998                 { &hf_btl2cap_length,
999                         { "Length",           "btl2cap.length",
1000                                 FT_UINT16, BASE_DEC, NULL, 0x0,          
1001                                 "L2CAP Payload Length", HFILL }
1002                 },
1003                 { &hf_btl2cap_cid,
1004                         { "CID",           "btl2cap.cid",
1005                                 FT_UINT16, BASE_HEX, NULL, 0x0,          
1006                                 "L2CAP Channel Identifier", HFILL }
1007                 },
1008                 { &hf_btl2cap_payload,
1009                         { "Payload",           "btl2cap.payload",
1010                                 FT_BYTES, BASE_HEX, NULL, 0x0,          
1011                                 "L2CAP Payload", HFILL }
1012                 },
1013                 { &hf_btl2cap_command,
1014                         { "Command",           "btl2cap.command",
1015                                 FT_NONE, BASE_NONE, NULL, 0x0,          
1016                                 "L2CAP Command", HFILL }
1017                 },
1018                 { &hf_btl2cap_cmd_code,
1019                         { "Command Code",           "btl2cap.cmd_code",
1020                                 FT_UINT8, BASE_HEX, VALS(command_code_vals), 0x0,          
1021                                 "L2CAP Command Code", HFILL }
1022                 },
1023                 { &hf_btl2cap_cmd_ident,
1024                         { "Command Identifier",           "btl2cap.cmd_ident",
1025                                 FT_UINT8, BASE_HEX, NULL, 0x0,          
1026                                 "L2CAP Command Identifier", HFILL }
1027                 },
1028                 { &hf_btl2cap_cmd_length,
1029                         { "Command Length",           "btl2cap.cmd_length",
1030                                 FT_UINT8, BASE_DEC, NULL, 0x0,          
1031                                 "L2CAP Command Length", HFILL }
1032                 },
1033                 { &hf_btl2cap_cmd_data,
1034                         { "Command Data",           "btl2cap.cmd_data",
1035                                 FT_NONE, BASE_NONE, NULL, 0x0,          
1036                                 "L2CAP Command Data", HFILL }
1037                 },
1038                 { &hf_btl2cap_psm,
1039                         { "PSM",           "btl2cap.psm",
1040                                 FT_UINT16, BASE_HEX, VALS(psm_vals), 0x0,          
1041                                 "Protocol/Service Multiplexer", HFILL }
1042                 },
1043                 { &hf_btl2cap_scid,
1044                         { "Source CID",           "btl2cap.scid",
1045                                 FT_UINT16, BASE_HEX, NULL, 0x0,          
1046                                 "Source Channel Identifier", HFILL }
1047                 },
1048                 { &hf_btl2cap_dcid,
1049                         { "Destination CID",           "btl2cap.dcid",
1050                                 FT_UINT16, BASE_HEX, NULL, 0x0,          
1051                                 "Destination Channel Identifier", HFILL }
1052                 },
1053                 { &hf_btl2cap_result,
1054                         { "Result",           "btl2cap.result",
1055                                 FT_UINT16, BASE_HEX, VALS(result_vals), 0x0,          
1056                                 "Result", HFILL }
1057                 },
1058                 { &hf_btl2cap_status,
1059                         { "Status",           "btl2cap.status",
1060                                 FT_UINT16, BASE_HEX, VALS(status_vals), 0x0,          
1061                                 "Status", HFILL }
1062                 },
1063                 { &hf_btl2cap_rej_reason,
1064                         { "Reason",           "btl2cap.rej_reason",
1065                                 FT_UINT16, BASE_HEX, VALS(reason_vals), 0x0,          
1066                                 "Reason", HFILL }
1067                 },
1068                 { &hf_btl2cap_sig_mtu,
1069                         { "Maximum Signalling MTU",           "btl2cap.sig_mtu",
1070                                 FT_UINT16, BASE_DEC, NULL, 0x0,          
1071                                 "Maximum Signalling MTU", HFILL }
1072                 },
1073                 { &hf_btl2cap_info_mtu,
1074                         { "Remote Entity MTU",           "btl2cap.info_mtu",
1075                                 FT_UINT16, BASE_DEC, NULL, 0x0,          
1076                                 "Remote entity acceptable connectionless MTU", HFILL }
1077                 },
1078                 { &hf_btl2cap_info_flowcontrol,
1079                         { "Flow Control Mode",           "btl2cap.info_flowcontrol",
1080                                 FT_UINT8, BASE_DEC, NULL, 0x01,
1081                                 "Flow Control mode support", HFILL }
1082                 },
1083                 { &hf_btl2cap_info_retransmission,
1084                         { "Retransmission Mode",         "btl2cap.info_retransmission",
1085                                 FT_UINT8, BASE_DEC, NULL, 0x02,
1086                                 "Retransmission mode support", HFILL }
1087                 },
1088                 { &hf_btl2cap_info_bidirqos,
1089                         { "Bi-Directional QOS",          "btl2cap.info_bidirqos",
1090                                 FT_UINT8, BASE_DEC, NULL, 0x04,
1091                                 "Bi-Directional QOS support", HFILL }
1092                 },
1093                 { &hf_btl2cap_info_type,
1094                         { "Information Type",           "btl2cap.info_type",
1095                                 FT_UINT16, BASE_HEX, VALS(info_type_vals), 0x0,          
1096                                 "Type of implementation-specific information", HFILL }
1097                 },
1098                 { &hf_btl2cap_info_result,
1099                         { "Result",           "btl2cap.info_result",
1100                                 FT_UINT16, BASE_HEX, VALS(info_result_vals), 0x0,          
1101                                 "Information about the success of the request", HFILL }
1102                 },
1103                 { &hf_btl2cap_info_extfeatures,
1104                         { "Extended Features",           "btl2cap.info_extfeatures",
1105                                 FT_NONE, BASE_NONE, NULL, 0x0,
1106                                 "Extended Features Mask", HFILL }
1107                 },
1108                 { &hf_btl2cap_continuation_flag,
1109                         { "Continuation Flag",           "btl2cap.continuation",
1110                                 FT_BOOLEAN, BASE_DEC, NULL, 0x0001,          
1111                                 "Continuation Flag", HFILL }
1112                 },
1113                 { &hf_btl2cap_configuration_result,
1114                         { "Result",           "btl2cap.conf_result",
1115                                 FT_UINT16, BASE_HEX, VALS(configuration_result_vals), 0x0,
1116                                 "Configuration Result", HFILL }
1117                 },
1118                 { &hf_btl2cap_option_type,
1119                         { "Type",           "btl2cap.option_type",
1120                                 FT_UINT8, BASE_HEX, VALS(option_type_vals), 0x0,          
1121                                 "Type of option", HFILL }
1122                 },
1123                 { &hf_btl2cap_option_length,
1124                         { "Length",           "btl2cap.option_length",
1125                                 FT_UINT8, BASE_DEC, NULL, 0x0,          
1126                                 "Number of octets in option payload ", HFILL }
1127                 },
1128                 { &hf_btl2cap_option_mtu,
1129                         { "MTU",           "btl2cap.option_mtu",
1130                                 FT_UINT16, BASE_DEC, NULL, 0x0,          
1131                                 "Maximum Transmission Unit", HFILL }
1132                 },
1133                 { &hf_btl2cap_option_flushTO,
1134                         { "Flush Timeout (ms)",           "btl2cap.option_flushto",
1135                                 FT_UINT16, BASE_DEC, NULL, 0x0,          
1136                                 "Flush Timeout in milliseconds", HFILL }
1137                 },
1138                 { &hf_btl2cap_option_flags,
1139                         { "Flags",           "btl2cap.option_flags",
1140                                 FT_UINT8, BASE_HEX, NULL, 0x0,          
1141                                 "Flags - must be set to 0 (Reserved for future use)", HFILL }
1142                 },
1143                 { &hf_btl2cap_option_service_type,
1144                         { "Service Type",           "btl2cap.option_servicetype",
1145                                 FT_UINT8, BASE_HEX, VALS(option_servicetype_vals), 0x0,     
1146                                 "Level of service required", HFILL }
1147                 },
1148                 { &hf_btl2cap_option_tokenrate,
1149                         { "Token Rate (bytes/s)",           "btl2cap.option_tokenrate",
1150                                 FT_UINT32, BASE_DEC, NULL, 0x0,          
1151                                 "Rate at which traffic credits are granted (bytes/s)", HFILL }
1152                 },
1153                 { &hf_btl2cap_option_tokenbucketsize,
1154                         { "Token Bucket Size (bytes)",           "btl2cap.option_tokenbsize",
1155                                 FT_UINT32, BASE_DEC, NULL, 0x0,          
1156                                 "Size of the token bucket (bytes)", HFILL }
1157                 },
1158                 { &hf_btl2cap_option_peakbandwidth,
1159                         { "Peak Bandwidth (bytes/s)",           "btl2cap.option_peakbandwidth",
1160                                 FT_UINT32, BASE_DEC, NULL, 0x0,          
1161                                 "Limit how fast packets may be sent (bytes/s)", HFILL }
1162                 },
1163                 { &hf_btl2cap_option_latency,
1164                         { "Latency (microseconds)",           "btl2cap.option_latency",
1165                                 FT_UINT32, BASE_DEC, NULL, 0x0,          
1166                                 "Maximal acceptable delay (microseconds)", HFILL }
1167                 },
1168                 { &hf_btl2cap_option_delayvariation,
1169                         { "Delay Variation (microseconds)",           "btl2cap.option_delayvar",
1170                                 FT_UINT32, BASE_DEC, NULL, 0x0,          
1171                                 "Difference between maximum and minimum delay (microseconds)", HFILL }
1172                 },
1173                 { &hf_btl2cap_option_retransmissionmode,
1174                         { "Mode",                                                               "btl2cap.retransmissionmode",
1175                                 FT_UINT8, BASE_HEX, VALS(option_retransmissionmode_vals), 0x0,
1176                                 "Retransmission/Flow Control mode", HFILL }
1177                 },
1178                 { &hf_btl2cap_option_txwindow,
1179                         { "TxWindow",                                                   "btl2cap.txwindow",
1180                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1181                                 "Retransmission window size", HFILL }
1182                 },
1183                 { &hf_btl2cap_option_maxtransmit,
1184                         { "MaxTransmit",                                                "btl2cap.maxtransmit",
1185                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1186                                 "Maximum I-frame retransmissions", HFILL }
1187                 },
1188                 { &hf_btl2cap_option_retransmittimeout,
1189                         { "Retransmit timeout (ms)",                    "btl2cap.retransmittimeout",
1190                                 FT_UINT16, BASE_DEC, NULL, 0x0,
1191                                 "Retransmission timeout (milliseconds)", HFILL }
1192                 },
1193                 { &hf_btl2cap_option_monitortimeout,
1194                         { "Monitor Timeout (ms)",                               "btl2cap.monitortimeout",
1195                                 FT_UINT16, BASE_DEC, NULL, 0x0,
1196                                 "S-frame transmission interval (milliseconds)", HFILL }
1197                 },
1198                 { &hf_btl2cap_option_mps,
1199                         { "MPS",                                                                "btl2cap.mps",
1200                                 FT_UINT16, BASE_DEC, NULL, 0x0,
1201                                 "Maximum PDU Payload Size", HFILL }
1202                 },
1203                 { &hf_btl2cap_option,
1204                         { "Configuration Parameter Option",           "btl2cap.conf_param_option",
1205                                 FT_NONE, BASE_NONE, NULL, 0x0,          
1206                                 "Configuration Parameter Option", HFILL }
1207                 },
1208                 { &hf_btl2cap_control_sar,
1209                         { "Segmentation and reassembly",           "btl2cap.control_sar",
1210                                 FT_UINT16, BASE_HEX, VALS(control_sar_vals), 0xC000,
1211                                 "Segmentation and reassembly", HFILL }
1212                 },
1213                 { &hf_btl2cap_control_reqseq,
1214                         { "ReqSeq",           "btl2cap.control_reqseq",
1215                                 FT_UINT16, BASE_DEC, NULL, 0x3F00,
1216                                 "Request Sequence Number", HFILL }
1217                 },
1218                 { &hf_btl2cap_control_txseq,
1219                         { "TxSeq",           "btl2cap.control_txseq",
1220                                 FT_UINT16, BASE_DEC, NULL, 0x007E,
1221                                 "Transmitted Sequence Number", HFILL }
1222                 },
1223                 { &hf_btl2cap_control_retransmissiondisable,
1224                         { "R",           "btl2cap.control_retransmissiondisable",
1225                                 FT_UINT16, BASE_HEX, NULL, 0x0080,
1226                                 "Retransmission Disable", HFILL }
1227                 },
1228                 { &hf_btl2cap_control_supervisory,
1229                         { "S",           "btl2cap.control_supervisory",
1230                                 FT_UINT16, BASE_HEX, VALS(control_supervisory_vals), 0x000C,
1231                                 "Supervisory Function", HFILL }
1232                 },
1233                 { &hf_btl2cap_control_type,
1234                         { "Frame Type",           "btl2cap.control_type",
1235                                 FT_UINT16, BASE_HEX, VALS(control_type_vals), 0x0001,
1236                                 "Frame Type", HFILL }
1237                 },
1238                 { &hf_btl2cap_control,
1239                         { "Control field",           "btl2cap.control",
1240                                 FT_NONE, BASE_NONE, NULL, 0x0,
1241                                 "Control field", HFILL }
1242                 },
1243                 { &hf_btl2cap_fcs,
1244                         { "FCS",           "btl2cap.fcs",
1245                                 FT_UINT16, BASE_HEX, NULL, 0,
1246                                 "Frame Check Sequence", HFILL }
1247                 },
1248                 { &hf_btl2cap_sdulength,
1249                         { "SDU Length",           "btl2cap.sdulength",
1250                                 FT_UINT16, BASE_DEC, NULL, 0,
1251                                 "SDU Length", HFILL }
1252                 },
1253                 { &hf_btl2cap_reassembled_in,
1254                         { "This SDU is reassembled in frame",           "btl2cap.reassembled_in",
1255                                 FT_FRAMENUM, BASE_NONE, NULL, 0,
1256                                 "This SDU is reassembled in frame #", HFILL }
1257                 },
1258                 { &hf_btl2cap_continuation_to,
1259                         { "This is a continuation to the SDU in frame",           "btl2cap.continuation_to",
1260                                 FT_FRAMENUM, BASE_NONE, NULL, 0,
1261                                 "This is a continuation to the SDU in frame #", HFILL }
1262                 }
1263         };
1264
1265         /* Setup protocol subtree array */
1266         static gint *ett[] = {
1267                 &ett_btl2cap,
1268                 &ett_btl2cap_cmd,
1269                 &ett_btl2cap_option,
1270                 &ett_btl2cap_extfeatures,
1271                 &ett_btl2cap_control
1272         };
1273
1274         /* Register the protocol name and description */
1275         proto_btl2cap = proto_register_protocol("Bluetooth L2CAP Packet", "L2CAP", "btl2cap");
1276
1277         register_dissector("btl2cap", dissect_btl2cap, proto_btl2cap);
1278
1279         /* subdissector code */
1280         l2cap_psm_dissector_table = register_dissector_table("btl2cap.psm", "L2CAP PSM", FT_UINT16, BASE_HEX);
1281
1282         /* Required function calls to register the header fields and subtrees used */
1283         proto_register_field_array(proto_btl2cap, hf, array_length(hf));
1284         proto_register_subtree_array(ett, array_length(ett));
1285
1286         cid_to_psm_table=se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "btl2cap scid to psm");
1287
1288 }
1289
1290
1291 void 
1292 proto_reg_handoff_btl2cap(void)
1293 {
1294
1295 }
1296
1297