2 * Routines for the Bluetooth AMP dissection
4 * Copyright 2009, Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
34 #include "packet-btl2cap.h"
36 /* Initialize the protocol and registered fields */
37 static int proto_btamp = -1;
38 static int hf_btamp_command = -1;
39 static int hf_btamp_cmd_code = -1;
40 static int hf_btamp_cmd_ident = -1;
41 static int hf_btamp_cmd_length = -1;
42 static int hf_btamp_cmd_data = -1;
43 static int hf_btamp_rej_reason = -1;
44 static int hf_btamp_mtu = -1;
45 static int hf_btamp_extfeatures = -1;
46 static int hf_btamp_lcontroller_id = -1;
47 static int hf_btamp_rcontroller_id = -1;
48 static int hf_btamp_controller_list = -1;
49 static int hf_btamp_controllers = -1;
50 static int hf_btamp_controller_id = -1;
51 static int hf_btamp_controller_type = -1;
52 static int hf_btamp_controller_status = -1;
53 static int hf_btamp_status = -1;
54 static int hf_btamp_create_status = -1;
55 static int hf_btamp_disc_status = -1;
56 static int hf_btamp_total_bw = -1;
57 static int hf_btamp_max_guaran_bw = -1;
58 static int hf_btamp_min_latency = -1;
59 static int hf_btamp_pal_caps_guaranteed = -1;
60 static int hf_btamp_pal_caps_mask = -1;
61 static int hf_btamp_amp_assoc_size = -1;
62 static int hf_btamp_amp_assoc = -1;
64 /* Initialize the subtree pointers */
65 static gint ett_btamp = -1;
66 static gint ett_btamp_cmd = -1;
67 static gint ett_btamp_caps = -1;
68 static gint ett_btamp_controller_entry = -1;
69 static gint ett_btamp_controller_list = -1;
71 static const value_string command_code_vals[] = {
72 { 0x01, "AMP Command Reject" },
73 { 0x02, "AMP Discover Request" },
74 { 0x03, "AMP Discover Response" },
75 { 0x04, "AMP Change Notify" },
76 { 0x05, "AMP Change Response" },
77 { 0x06, "AMP Get Info Request" },
78 { 0x07, "AMP Get Info Response" },
79 { 0x08, "AMP Get AMP Assoc Request" },
80 { 0x09, "AMP Get AMP Assoc Response" },
81 { 0x0A, "AMP Create Physical Link Request" },
82 { 0x0B, "AMP Create Physical Link Response" },
83 { 0x0C, "AMP Disconnect Physical Link Request" },
84 { 0x0D, "AMP Disconnect Physical Link Response" },
88 static const value_string reason_vals[] = {
89 { 0x0000, "Command not understood" },
93 static const value_string controller_type_vals[] = {
94 { 0x0000, "Bluetooth BR/EDR" },
96 { 0x0002, "ECMA-368" },
100 static const value_string controller_status_vals[] = {
101 { 0x0000, "Controller available but currently physically powered down" },
102 { 0x0001, "Controller used exclusively by Bluetooth BR/EDR" },
103 { 0x0002, "Controller has no capacity available for Bluetooth operation" },
104 { 0x0003, "Controller has low capacity available for Bluetooth operation" },
105 { 0x0004, "Controller has medium capacity available for Bluetooth operation" },
106 { 0x0005, "Controller has high capacity available for Bluetooth operation" },
107 { 0x0006, "Controller has full capacity available for Bluetooth operation" },
111 static const value_string status_vals[] = {
112 { 0x0000, "Success" },
113 { 0x0001, "Invalid Controller ID" },
117 static const value_string create_status_vals[] = {
118 { 0x0000, "Success" },
119 { 0x0001, "Invalid Controller ID" },
120 { 0x0002, "Failed - Unable to start link creation" },
121 { 0x0003, "Failed - Collision Occurred" },
122 { 0x0004, "Failed - AMP Disconnected Physical Link Request packet received" },
123 { 0x0005, "Failed - Physical Link Already Exists" },
127 static const value_string disc_status_vals[] = {
128 { 0x0000, "Success" },
129 { 0x0001, "Invalid Controller ID" },
130 { 0x0002, "Failed - No Physical Link exists and no Physical Link creation is in progress" },
135 dissect_comrej(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
139 reason = tvb_get_letohs(tvb, offset);
140 proto_tree_add_item(tree, hf_btamp_rej_reason, tvb, offset, 2, TRUE);
144 case 0x0000: /* Command not understood */
155 dissect_discoverrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
157 proto_tree_add_item(tree, hf_btamp_mtu, tvb, offset, 2, TRUE);
160 proto_tree_add_item(tree, hf_btamp_extfeatures, tvb, offset, 2, TRUE);
167 dissect_controller_entry(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, guint16 idx)
169 proto_tree *btamp_controller_entry_tree=NULL;
170 proto_item *ti_controller_entry=NULL;
172 ti_controller_entry=proto_tree_add_none_format(tree,
173 hf_btamp_controllers, tvb,
176 btamp_controller_entry_tree=proto_item_add_subtree(ti_controller_entry, ett_btamp_controller_entry);
178 proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
181 proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_type, tvb, offset, 1, TRUE);
184 proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_status, tvb, offset, 1, TRUE);
191 dissect_discoverresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
195 proto_tree *btamp_controller_list_tree=NULL;
196 proto_item *ti_controller_list=NULL;
198 proto_tree_add_item(tree, hf_btamp_mtu, tvb, offset, 2, TRUE);
201 proto_tree_add_item(tree, hf_btamp_extfeatures, tvb, offset, 2, TRUE);
204 length = tvb_length_remaining(tvb, offset);
205 ti_controller_list=proto_tree_add_none_format(tree,
206 hf_btamp_controller_list, tvb,
209 btamp_controller_list_tree=proto_item_add_subtree(ti_controller_list, ett_btamp_controller_list);
211 while ((length = tvb_length_remaining(tvb, offset)) >= 3) {
212 offset = dissect_controller_entry(tvb, offset, pinfo, btamp_controller_list_tree, idx);
220 dissect_changenotify(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
224 proto_tree *btamp_controller_list_tree=NULL;
225 proto_item *ti_controller_list=NULL;
227 length = tvb_length_remaining(tvb, offset);
228 ti_controller_list=proto_tree_add_none_format(tree,
229 hf_btamp_controller_list, tvb,
232 btamp_controller_list_tree=proto_item_add_subtree(ti_controller_list, ett_btamp_controller_list);
234 while ((length = tvb_length_remaining(tvb, offset)) >= 3) {
235 offset = dissect_controller_entry(tvb, offset, pinfo, btamp_controller_list_tree, idx);
243 dissect_changeresponse(tvbuff_t *tvb _U_, int offset, packet_info *pinfo _U_, proto_tree *tree _U_)
249 dissect_getinforequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
251 proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
258 dissect_getinforesponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
260 proto_tree *btamp_controller_tree=NULL;
261 proto_item *ti_controller=NULL;
263 proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
266 proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, TRUE);
269 proto_tree_add_item(tree, hf_btamp_total_bw, tvb, offset, 4, TRUE);
272 proto_tree_add_item(tree, hf_btamp_max_guaran_bw, tvb, offset, 4, TRUE);
275 proto_tree_add_item(tree, hf_btamp_min_latency, tvb, offset, 4, TRUE);
278 ti_controller=proto_tree_add_none_format(tree,
279 hf_btamp_pal_caps_mask, tvb,
282 btamp_controller_tree=proto_item_add_subtree(ti_controller, ett_btamp_caps);
283 proto_tree_add_item(btamp_controller_tree, hf_btamp_pal_caps_guaranteed, tvb, offset, 2, TRUE);
286 proto_tree_add_item(tree, hf_btamp_amp_assoc_size, tvb, offset, 2, TRUE);
293 dissect_getampassocrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
295 proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
302 dissect_ampassoc(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
304 proto_tree_add_item(tree, hf_btamp_amp_assoc, tvb, offset, tvb_length_remaining(tvb, offset), TRUE);
305 offset+=tvb_length_remaining(tvb, offset);
311 dissect_getampassocresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
313 proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
316 proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, TRUE);
319 offset=dissect_ampassoc(tvb, offset, pinfo, tree);
325 dissect_createphysicalrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
327 proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
330 proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
333 offset=dissect_ampassoc(tvb, offset, pinfo, tree);
339 dissect_createphysicalresponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
341 proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
344 proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
347 proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, TRUE);
354 dissect_discphysicalchanrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
356 proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
359 proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
366 dissect_discphysicalchanresponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
368 proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
371 proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
374 proto_tree_add_item(tree, hf_btamp_controller_status, tvb, offset, 1, TRUE);
380 static void dissect_btamp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
384 proto_tree *btamp_tree=NULL;
386 proto_tree *btamp_cmd_tree=NULL;
387 proto_item *ti_command=NULL;
391 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AMP");
392 col_set_str(pinfo->cinfo, COL_INFO, pinfo->p2p_dir == P2P_DIR_SENT ? "Sent " : "Rcvd ");
395 ti=proto_tree_add_item(tree, proto_btamp, tvb, offset, -1, FALSE);
396 btamp_tree=proto_item_add_subtree(ti, ett_btamp);
399 length = tvb_length_remaining(tvb, offset);
400 ti_command=proto_tree_add_none_format(btamp_tree,
401 hf_btamp_command, tvb,
404 btamp_cmd_tree=proto_item_add_subtree(ti_command, ett_btamp_cmd);
406 cmd_code=tvb_get_guint8(tvb, offset);
407 proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_code, tvb, offset, 1, TRUE);
410 proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_ident, tvb, offset, 1, TRUE);
413 cmd_length=tvb_get_letohs(tvb, offset);
414 proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_length, tvb, offset, 2, TRUE);
415 proto_item_set_len(ti_command, cmd_length+4);
419 case 0x01: /* Command Reject */
420 offset=dissect_comrej(tvb, offset, pinfo, btamp_cmd_tree);
423 case 0x02: /* Discover Request */
424 offset=dissect_discoverrequest(tvb, offset, pinfo, btamp_cmd_tree);
427 case 0x03: /* Discover Response */
428 offset=dissect_discoverresponse(tvb, offset, pinfo, btamp_cmd_tree);
431 case 0x04: /* AMP Change Notify */
432 offset=dissect_changenotify(tvb, offset, pinfo, btamp_cmd_tree);
435 case 0x05: /* AMP Change Response */
436 offset=dissect_changeresponse(tvb, offset, pinfo, btamp_cmd_tree);
439 case 0x06: /* AMP Get Info Request */
440 offset=dissect_getinforequest(tvb, offset, pinfo, btamp_cmd_tree);
443 case 0x07: /* AMP Get Info Response */
444 offset=dissect_getinforesponse(tvb, offset, pinfo, btamp_cmd_tree);
447 case 0x08: /* Get AMP Assoc Request */
448 offset=dissect_getampassocrequest(tvb, offset, pinfo, btamp_cmd_tree);
451 case 0x09: /* Get AMP Assoc Response */
452 offset=dissect_getampassocresponse(tvb, offset, pinfo, btamp_cmd_tree);
455 case 0x0A: /* Create Physical Link Request */
456 offset=dissect_createphysicalrequest(tvb, offset, pinfo, btamp_cmd_tree);
459 case 0x0B: /* Create Physical Link Response */
460 offset=dissect_createphysicalresponse(tvb, offset, pinfo, btamp_cmd_tree);
463 case 0x0c: /* Disconnect Physical Link Request */
464 offset=dissect_discphysicalchanrequest(tvb, offset, pinfo, btamp_cmd_tree);
467 case 0x0d: /* Disconnect Physical Link Response */
468 offset=dissect_discphysicalchanresponse(tvb, offset, pinfo, btamp_cmd_tree);
472 proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_data, tvb, offset, -1, TRUE);
473 offset+=tvb_length_remaining(tvb, offset);
477 proto_item_append_text(ti_command, "%s", val_to_str(cmd_code, command_code_vals, "Unknown PDU (%u)"));
478 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(cmd_code, command_code_vals, "Unknown PDU (%u)"));
481 /* Register the protocol with Wireshark */
483 proto_register_btamp(void)
485 /* Setup list of header fields See Section 1.6.1 for details*/
486 static hf_register_info hf[] = {
488 { "Command", "btamp.command",
489 FT_NONE, BASE_NONE, NULL, 0x0,
490 "L2CAP Command", HFILL }
492 { &hf_btamp_cmd_code,
493 { "Command Code", "btamp.cmd_code",
494 FT_UINT8, BASE_HEX, VALS(command_code_vals), 0x0,
495 "L2CAP Command Code", HFILL }
497 { &hf_btamp_cmd_ident,
498 { "Command Identifier", "btamp.cmd_ident",
499 FT_UINT8, BASE_HEX, NULL, 0x0,
500 "L2CAP Command Identifier", HFILL }
502 { &hf_btamp_cmd_length,
503 { "Command Length", "btamp.cmd_length",
504 FT_UINT8, BASE_DEC, NULL, 0x0,
505 "L2CAP Command Length", HFILL }
507 { &hf_btamp_cmd_data,
508 { "Command Data", "btamp.cmd_data",
509 FT_NONE, BASE_NONE, NULL, 0x0,
510 "L2CAP Command Data", HFILL }
512 { &hf_btamp_rej_reason,
513 { "Reason", "btl2cap.rej_reason",
514 FT_UINT16, BASE_HEX, VALS(reason_vals), 0x0,
518 { "MPS/MTU", "btamp.mps",
519 FT_UINT16, BASE_HEX, NULL, 0x0,
520 "MPS/MTU Size", HFILL }
522 { &hf_btamp_extfeatures,
523 { "Extended Features", "btamp.extfeatures",
524 FT_UINT16, BASE_HEX, NULL, 0x0,
525 "Extended Features Mask", HFILL }
527 { &hf_btamp_controllers,
528 { "Controller entry", "btamp.ctrl_entry",
529 FT_NONE, BASE_NONE, NULL, 0x0,
532 { &hf_btamp_controller_list,
533 { "Controller list", "btamp.ctrl_list",
534 FT_NONE, BASE_NONE, NULL, 0x0,
537 { &hf_btamp_lcontroller_id,
538 { "Local Controller ID", "btamp.lctrl_id",
539 FT_UINT8, BASE_DEC, NULL, 0x0,
542 { &hf_btamp_rcontroller_id,
543 { "Remote Controller ID", "btamp.rctrl_id",
544 FT_UINT8, BASE_DEC, NULL, 0x0,
547 { &hf_btamp_controller_id,
548 { "Controller ID", "btamp.ctrl_id",
549 FT_UINT8, BASE_DEC, NULL, 0x0,
552 { &hf_btamp_controller_type,
553 { "Controller Type", "btamp.ctrl_type",
554 FT_UINT8, BASE_DEC, VALS(controller_type_vals), 0x0,
557 { &hf_btamp_controller_status,
558 { "Controller Status", "btamp.ctrl_status",
559 FT_UINT8, BASE_DEC, VALS(controller_status_vals), 0x0,
563 { "Status", "btamp.status",
564 FT_UINT8, BASE_DEC, VALS(status_vals), 0x0,
567 { &hf_btamp_create_status,
568 { "Status", "btamp.create_status",
569 FT_UINT8, BASE_DEC, VALS(create_status_vals), 0x0,
572 { &hf_btamp_disc_status,
573 { "Status", "btamp.disc_status",
574 FT_UINT8, BASE_DEC, VALS(disc_status_vals), 0x0,
577 { &hf_btamp_pal_caps_mask,
578 { "PAL Capabilities Mask", "btamp.pal_caps_mask",
579 FT_NONE, BASE_NONE, NULL, 0x0,
582 { &hf_btamp_pal_caps_guaranteed,
583 { "Guaranteed Service type", "btamp.guaranteed_type",
584 FT_BOOLEAN, 16, NULL, 0x01,
587 { &hf_btamp_total_bw,
588 { "Total Bandwidth", "btamp.total_bw",
589 FT_UINT32, BASE_HEX, NULL, 0x0,
592 { &hf_btamp_max_guaran_bw,
593 { "Max Guaranteed Bandwidth", "btamp.max_guaran_bw",
594 FT_UINT32, BASE_HEX, NULL, 0x0,
597 { &hf_btamp_min_latency,
598 { "Minimum latency", "btamp.min_latency",
599 FT_UINT32, BASE_HEX, NULL, 0x0,
602 { &hf_btamp_amp_assoc_size,
603 { "Assoc Size", "btamp.assoc_size",
604 FT_UINT16, BASE_HEX, NULL, 0x0,
607 { &hf_btamp_amp_assoc,
608 { "Assoc", "btamp.assoc",
609 FT_BYTES, BASE_NONE, NULL, 0x0,
614 /* Setup protocol subtree array */
615 static gint *ett[] = {
619 &ett_btamp_controller_entry,
620 &ett_btamp_controller_list,
623 /* Register the protocol name and description */
624 proto_btamp = proto_register_protocol("Bluetooth AMP Packet", "AMP", "btamp");
626 register_dissector("btamp", dissect_btamp, proto_btamp);
628 /* Required function calls to register the header fields and subtrees used */
629 proto_register_field_array(proto_btamp, hf, array_length(hf));
630 proto_register_subtree_array(ett, array_length(ett));
634 proto_reg_handoff_btamp(void)
636 dissector_handle_t btamp_handle;
638 btamp_handle = find_dissector("btamp");
639 dissector_add("btl2cap.cid", BTL2CAP_FIXED_CID_AMP_MAN, btamp_handle);