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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <epan/packet.h>
31 #include "packet-btl2cap.h"
33 /* Initialize the protocol and registered fields */
34 static int proto_btamp
= -1;
35 static int hf_btamp_command
= -1;
36 static int hf_btamp_cmd_code
= -1;
37 static int hf_btamp_cmd_ident
= -1;
38 static int hf_btamp_cmd_length
= -1;
39 static int hf_btamp_cmd_data
= -1;
40 static int hf_btamp_rej_reason
= -1;
41 static int hf_btamp_mtu
= -1;
42 static int hf_btamp_extfeatures
= -1;
43 static int hf_btamp_lcontroller_id
= -1;
44 static int hf_btamp_rcontroller_id
= -1;
45 static int hf_btamp_controller_list
= -1;
46 static int hf_btamp_controllers
= -1;
47 static int hf_btamp_controller_id
= -1;
48 static int hf_btamp_controller_type
= -1;
49 static int hf_btamp_controller_status
= -1;
50 static int hf_btamp_status
= -1;
51 /* static int hf_btamp_create_status = -1; */
52 /* static int hf_btamp_disc_status = -1; */
53 static int hf_btamp_total_bw
= -1;
54 static int hf_btamp_max_guaran_bw
= -1;
55 static int hf_btamp_min_latency
= -1;
56 static int hf_btamp_pal_caps_guaranteed
= -1;
57 static int hf_btamp_pal_caps_mask
= -1;
58 static int hf_btamp_amp_assoc_size
= -1;
59 static int hf_btamp_amp_assoc
= -1;
61 /* Initialize the subtree pointers */
62 static gint ett_btamp
= -1;
63 static gint ett_btamp_cmd
= -1;
64 static gint ett_btamp_caps
= -1;
65 static gint ett_btamp_controller_entry
= -1;
66 static gint ett_btamp_controller_list
= -1;
68 static const value_string command_code_vals
[] = {
69 { 0x01, "AMP Command Reject" },
70 { 0x02, "AMP Discover Request" },
71 { 0x03, "AMP Discover Response" },
72 { 0x04, "AMP Change Notify" },
73 { 0x05, "AMP Change Response" },
74 { 0x06, "AMP Get Info Request" },
75 { 0x07, "AMP Get Info Response" },
76 { 0x08, "AMP Get AMP Assoc Request" },
77 { 0x09, "AMP Get AMP Assoc Response" },
78 { 0x0A, "AMP Create Physical Link Request" },
79 { 0x0B, "AMP Create Physical Link Response" },
80 { 0x0C, "AMP Disconnect Physical Link Request" },
81 { 0x0D, "AMP Disconnect Physical Link Response" },
85 static const value_string reason_vals
[] = {
86 { 0x0000, "Command not understood" },
90 static const value_string controller_type_vals
[] = {
91 { 0x0000, "Bluetooth BR/EDR" },
93 { 0x0002, "ECMA-368" },
97 static const value_string controller_status_vals
[] = {
98 { 0x0000, "Controller available but currently physically powered down" },
99 { 0x0001, "Controller used exclusively by Bluetooth BR/EDR" },
100 { 0x0002, "Controller has no capacity available for Bluetooth operation" },
101 { 0x0003, "Controller has low capacity available for Bluetooth operation" },
102 { 0x0004, "Controller has medium capacity available for Bluetooth operation" },
103 { 0x0005, "Controller has high capacity available for Bluetooth operation" },
104 { 0x0006, "Controller has full capacity available for Bluetooth operation" },
108 static const value_string status_vals
[] = {
109 { 0x0000, "Success" },
110 { 0x0001, "Invalid Controller ID" },
115 static const value_string create_status_vals
[] = {
116 { 0x0000, "Success" },
117 { 0x0001, "Invalid Controller ID" },
118 { 0x0002, "Failed - Unable to start link creation" },
119 { 0x0003, "Failed - Collision Occurred" },
120 { 0x0004, "Failed - AMP Disconnected Physical Link Request packet received" },
121 { 0x0005, "Failed - Physical Link Already Exists" },
125 static const value_string disc_status_vals
[] = {
126 { 0x0000, "Success" },
127 { 0x0001, "Invalid Controller ID" },
128 { 0x0002, "Failed - No Physical Link exists and no Physical Link creation is in progress" },
133 void proto_register_btamp(void);
134 void proto_reg_handoff_btamp(void);
137 dissect_comrej(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
141 reason
= tvb_get_letohs(tvb
, offset
);
142 proto_tree_add_item(tree
, hf_btamp_rej_reason
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
146 case 0x0000: /* Command not understood */
157 dissect_discoverrequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
159 proto_tree_add_item(tree
, hf_btamp_mtu
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
162 proto_tree_add_item(tree
, hf_btamp_extfeatures
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
169 dissect_controller_entry(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
, guint16 idx
)
171 proto_item
*ti_controller_entry
;
172 proto_tree
*btamp_controller_entry_tree
;
174 ti_controller_entry
= proto_tree_add_none_format(tree
,
175 hf_btamp_controllers
, tvb
,
178 btamp_controller_entry_tree
= proto_item_add_subtree(ti_controller_entry
, ett_btamp_controller_entry
);
180 proto_tree_add_item(btamp_controller_entry_tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
183 proto_tree_add_item(btamp_controller_entry_tree
, hf_btamp_controller_type
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
186 proto_tree_add_item(btamp_controller_entry_tree
, hf_btamp_controller_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
193 dissect_discoverresponse(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
)
197 proto_item
*ti_controller_list
;
198 proto_tree
*btamp_controller_list_tree
;
200 proto_tree_add_item(tree
, hf_btamp_mtu
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
203 proto_tree_add_item(tree
, hf_btamp_extfeatures
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
206 length
= tvb_reported_length_remaining(tvb
, offset
);
207 ti_controller_list
= proto_tree_add_none_format(tree
,
208 hf_btamp_controller_list
, tvb
,
211 btamp_controller_list_tree
= proto_item_add_subtree(ti_controller_list
, ett_btamp_controller_list
);
213 while (tvb_reported_length_remaining(tvb
, offset
) >= 3) {
214 offset
= dissect_controller_entry(tvb
, offset
, pinfo
, btamp_controller_list_tree
, idx
);
222 dissect_changenotify(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
)
226 proto_item
*ti_controller_list
;
227 proto_tree
*btamp_controller_list_tree
;
229 length
= tvb_reported_length_remaining(tvb
, offset
);
230 ti_controller_list
= proto_tree_add_none_format(tree
,
231 hf_btamp_controller_list
, tvb
,
234 btamp_controller_list_tree
= proto_item_add_subtree(ti_controller_list
, ett_btamp_controller_list
);
236 while (tvb_reported_length_remaining(tvb
, offset
) >= 3) {
237 offset
= dissect_controller_entry(tvb
, offset
, pinfo
, btamp_controller_list_tree
, idx
);
245 dissect_changeresponse(tvbuff_t
*tvb _U_
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree _U_
)
251 dissect_getinforequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
253 proto_tree_add_item(tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
260 dissect_getinforesponse(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
262 proto_item
*ti_controller
;
263 proto_tree
*btamp_controller_tree
;
265 proto_tree_add_item(tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
268 proto_tree_add_item(tree
, hf_btamp_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
271 proto_tree_add_item(tree
, hf_btamp_total_bw
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
274 proto_tree_add_item(tree
, hf_btamp_max_guaran_bw
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
277 proto_tree_add_item(tree
, hf_btamp_min_latency
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
280 ti_controller
= proto_tree_add_none_format(tree
,
281 hf_btamp_pal_caps_mask
, tvb
,
284 btamp_controller_tree
= proto_item_add_subtree(ti_controller
, ett_btamp_caps
);
285 proto_tree_add_item(btamp_controller_tree
, hf_btamp_pal_caps_guaranteed
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
288 proto_tree_add_item(tree
, hf_btamp_amp_assoc_size
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
295 dissect_getampassocrequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
297 proto_tree_add_item(tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
304 dissect_ampassoc(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
306 proto_tree_add_item(tree
, hf_btamp_amp_assoc
, tvb
, offset
, tvb_reported_length_remaining(tvb
, offset
), ENC_NA
);
307 return tvb_reported_length(tvb
);
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, ENC_LITTLE_ENDIAN
);
316 proto_tree_add_item(tree
, hf_btamp_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
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, ENC_LITTLE_ENDIAN
);
330 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
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, ENC_LITTLE_ENDIAN
);
344 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
347 proto_tree_add_item(tree
, hf_btamp_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
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, ENC_LITTLE_ENDIAN
);
359 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
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, ENC_LITTLE_ENDIAN
);
371 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
374 proto_tree_add_item(tree
, hf_btamp_controller_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
381 dissect_btamp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
385 proto_tree
*btamp_tree
;
387 proto_item
*ti_command
;
388 proto_tree
*btamp_cmd_tree
;
392 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "AMP");
394 switch (pinfo
->p2p_dir
) {
396 col_set_str(pinfo
->cinfo
, COL_INFO
, "Sent ");
399 col_set_str(pinfo
->cinfo
, COL_INFO
, "Rcvd ");
402 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Unknown direction %d ",
407 ti
= proto_tree_add_item(tree
, proto_btamp
, tvb
, offset
, -1, ENC_NA
);
408 btamp_tree
= proto_item_add_subtree(ti
, ett_btamp
);
410 length
= tvb_reported_length_remaining(tvb
, offset
);
411 ti_command
= proto_tree_add_none_format(btamp_tree
,
412 hf_btamp_command
, tvb
,
415 btamp_cmd_tree
= proto_item_add_subtree(ti_command
, ett_btamp_cmd
);
417 cmd_code
= tvb_get_guint8(tvb
, offset
);
418 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_code
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
421 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_ident
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
424 cmd_length
= tvb_get_letohs(tvb
, offset
);
425 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_length
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
426 proto_item_set_len(ti_command
, cmd_length
+4);
430 case 0x01: /* Command Reject */
431 offset
= dissect_comrej(tvb
, offset
, pinfo
, btamp_cmd_tree
);
434 case 0x02: /* Discover Request */
435 offset
= dissect_discoverrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
438 case 0x03: /* Discover Response */
439 offset
= dissect_discoverresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
442 case 0x04: /* AMP Change Notify */
443 offset
= dissect_changenotify(tvb
, offset
, pinfo
, btamp_cmd_tree
);
446 case 0x05: /* AMP Change Response */
447 offset
= dissect_changeresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
450 case 0x06: /* AMP Get Info Request */
451 offset
= dissect_getinforequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
454 case 0x07: /* AMP Get Info Response */
455 offset
= dissect_getinforesponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
458 case 0x08: /* Get AMP Assoc Request */
459 offset
= dissect_getampassocrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
462 case 0x09: /* Get AMP Assoc Response */
463 offset
= dissect_getampassocresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
466 case 0x0A: /* Create Physical Link Request */
467 offset
= dissect_createphysicalrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
470 case 0x0B: /* Create Physical Link Response */
471 offset
= dissect_createphysicalresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
474 case 0x0c: /* Disconnect Physical Link Request */
475 offset
= dissect_discphysicalchanrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
478 case 0x0d: /* Disconnect Physical Link Response */
479 offset
= dissect_discphysicalchanresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
483 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_data
, tvb
, offset
, -1, ENC_NA
);
484 offset
= tvb_reported_length(tvb
);
488 proto_item_append_text(ti_command
, "%s", val_to_str(cmd_code
, command_code_vals
, "Unknown PDU (%u)"));
489 col_append_str(pinfo
->cinfo
, COL_INFO
, val_to_str(cmd_code
, command_code_vals
, "Unknown PDU (%u)"));
494 /* Register the protocol with Wireshark */
496 proto_register_btamp(void)
498 /* Setup list of header fields See Section 1.6.1 for details*/
499 static hf_register_info hf
[] = {
501 { "Command", "btamp.command",
502 FT_NONE
, BASE_NONE
, NULL
, 0x0,
503 "L2CAP Command", HFILL
}
505 { &hf_btamp_cmd_code
,
506 { "Command Code", "btamp.cmd_code",
507 FT_UINT8
, BASE_HEX
, VALS(command_code_vals
), 0x0,
508 "L2CAP Command Code", HFILL
}
510 { &hf_btamp_cmd_ident
,
511 { "Command Identifier", "btamp.cmd_ident",
512 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
513 "L2CAP Command Identifier", HFILL
}
515 { &hf_btamp_cmd_length
,
516 { "Command Length", "btamp.cmd_length",
517 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
518 "L2CAP Command Length", HFILL
}
520 { &hf_btamp_cmd_data
,
521 { "Command Data", "btamp.cmd_data",
522 FT_NONE
, BASE_NONE
, NULL
, 0x0,
523 "L2CAP Command Data", HFILL
}
525 { &hf_btamp_rej_reason
,
526 { "Reason", "btamp.rej_reason",
527 FT_UINT16
, BASE_HEX
, VALS(reason_vals
), 0x0,
531 { "MPS/MTU", "btamp.mps",
532 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
533 "MPS/MTU Size", HFILL
}
535 { &hf_btamp_extfeatures
,
536 { "Extended Features", "btamp.extfeatures",
537 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
538 "Extended Features Mask", HFILL
}
540 { &hf_btamp_controllers
,
541 { "Controller entry", "btamp.ctrl_entry",
542 FT_NONE
, BASE_NONE
, NULL
, 0x0,
545 { &hf_btamp_controller_list
,
546 { "Controller list", "btamp.ctrl_list",
547 FT_NONE
, BASE_NONE
, NULL
, 0x0,
550 { &hf_btamp_lcontroller_id
,
551 { "Local Controller ID", "btamp.lctrl_id",
552 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
555 { &hf_btamp_rcontroller_id
,
556 { "Remote Controller ID", "btamp.rctrl_id",
557 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
560 { &hf_btamp_controller_id
,
561 { "Controller ID", "btamp.ctrl_id",
562 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
565 { &hf_btamp_controller_type
,
566 { "Controller Type", "btamp.ctrl_type",
567 FT_UINT8
, BASE_DEC
, VALS(controller_type_vals
), 0x0,
570 { &hf_btamp_controller_status
,
571 { "Controller Status", "btamp.ctrl_status",
572 FT_UINT8
, BASE_DEC
, VALS(controller_status_vals
), 0x0,
576 { "Status", "btamp.status",
577 FT_UINT8
, BASE_DEC
, VALS(status_vals
), 0x0,
581 { &hf_btamp_create_status
,
582 { "Status", "btamp.create_status",
583 FT_UINT8
, BASE_DEC
, VALS(create_status_vals
), 0x0,
586 { &hf_btamp_disc_status
,
587 { "Status", "btamp.disc_status",
588 FT_UINT8
, BASE_DEC
, VALS(disc_status_vals
), 0x0,
592 { &hf_btamp_pal_caps_mask
,
593 { "PAL Capabilities Mask", "btamp.pal_caps_mask",
594 FT_NONE
, BASE_NONE
, NULL
, 0x0,
597 { &hf_btamp_pal_caps_guaranteed
,
598 { "Guaranteed Service type", "btamp.guaranteed_type",
599 FT_BOOLEAN
, 16, NULL
, 0x01,
602 { &hf_btamp_total_bw
,
603 { "Total Bandwidth", "btamp.total_bw",
604 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
607 { &hf_btamp_max_guaran_bw
,
608 { "Max Guaranteed Bandwidth", "btamp.max_guaran_bw",
609 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
612 { &hf_btamp_min_latency
,
613 { "Minimum latency", "btamp.min_latency",
614 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
617 { &hf_btamp_amp_assoc_size
,
618 { "Assoc Size", "btamp.assoc_size",
619 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
622 { &hf_btamp_amp_assoc
,
623 { "Assoc", "btamp.assoc",
624 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
629 /* Setup protocol subtree array */
630 static gint
*ett
[] = {
634 &ett_btamp_controller_entry
,
635 &ett_btamp_controller_list
,
638 /* Register the protocol name and description */
639 proto_btamp
= proto_register_protocol("Bluetooth AMP Packet", "BT AMP", "btamp");
641 new_register_dissector("btamp", dissect_btamp
, proto_btamp
);
643 /* Required function calls to register the header fields and subtrees used */
644 proto_register_field_array(proto_btamp
, hf
, array_length(hf
));
645 proto_register_subtree_array(ett
, array_length(ett
));
649 proto_reg_handoff_btamp(void)
651 dissector_handle_t btamp_handle
;
653 btamp_handle
= find_dissector("btamp");
654 dissector_add_uint("btl2cap.cid", BTL2CAP_FIXED_CID_AMP_MAN
, btamp_handle
);
658 * Editor modelines - http://www.wireshark.org/tools/modelines.html
663 * indent-tabs-mode: nil
666 * vi: set shiftwidth=4 tabstop=8 expandtab:
667 * :indentSize=4:tabSize=8:noTabs=true: