2 * Routines for the Bluetooth AMP dissection
4 * Copyright 2009, Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
17 #include "packet-btl2cap.h"
19 /* Initialize the protocol and registered fields */
20 static int proto_btamp
;
21 static int hf_btamp_command
;
22 static int hf_btamp_cmd_code
;
23 static int hf_btamp_cmd_ident
;
24 static int hf_btamp_cmd_length
;
25 static int hf_btamp_cmd_data
;
26 static int hf_btamp_rej_reason
;
27 static int hf_btamp_mtu
;
28 static int hf_btamp_extfeatures
;
29 static int hf_btamp_lcontroller_id
;
30 static int hf_btamp_rcontroller_id
;
31 static int hf_btamp_controller_list
;
32 static int hf_btamp_controllers
;
33 static int hf_btamp_controller_id
;
34 static int hf_btamp_controller_type
;
35 static int hf_btamp_controller_status
;
36 static int hf_btamp_status
;
37 /* static int hf_btamp_create_status; */
38 /* static int hf_btamp_disc_status; */
39 static int hf_btamp_total_bw
;
40 static int hf_btamp_max_guaran_bw
;
41 static int hf_btamp_min_latency
;
42 static int hf_btamp_pal_caps_guaranteed
;
43 static int hf_btamp_pal_caps_mask
;
44 static int hf_btamp_amp_assoc_size
;
45 static int hf_btamp_amp_assoc
;
47 /* Initialize the subtree pointers */
49 static int ett_btamp_cmd
;
50 static int ett_btamp_caps
;
51 static int ett_btamp_controller_entry
;
52 static int ett_btamp_controller_list
;
54 static dissector_handle_t btamp_handle
;
57 static const value_string command_code_vals
[] = {
58 { 0x01, "AMP Command Reject" },
59 { 0x02, "AMP Discover Request" },
60 { 0x03, "AMP Discover Response" },
61 { 0x04, "AMP Change Notify" },
62 { 0x05, "AMP Change Response" },
63 { 0x06, "AMP Get Info Request" },
64 { 0x07, "AMP Get Info Response" },
65 { 0x08, "AMP Get AMP Assoc Request" },
66 { 0x09, "AMP Get AMP Assoc Response" },
67 { 0x0A, "AMP Create Physical Link Request" },
68 { 0x0B, "AMP Create Physical Link Response" },
69 { 0x0C, "AMP Disconnect Physical Link Request" },
70 { 0x0D, "AMP Disconnect Physical Link Response" },
74 static const value_string reason_vals
[] = {
75 { 0x0000, "Command not understood" },
79 static const value_string controller_type_vals
[] = {
80 { 0x0000, "Bluetooth BR/EDR" },
82 { 0x0002, "ECMA-368" },
86 static const value_string controller_status_vals
[] = {
87 { 0x0000, "Controller available but currently physically powered down" },
88 { 0x0001, "Controller used exclusively by Bluetooth BR/EDR" },
89 { 0x0002, "Controller has no capacity available for Bluetooth operation" },
90 { 0x0003, "Controller has low capacity available for Bluetooth operation" },
91 { 0x0004, "Controller has medium capacity available for Bluetooth operation" },
92 { 0x0005, "Controller has high capacity available for Bluetooth operation" },
93 { 0x0006, "Controller has full capacity available for Bluetooth operation" },
97 static const value_string status_vals
[] = {
98 { 0x0000, "Success" },
99 { 0x0001, "Invalid Controller ID" },
104 static const value_string create_status_vals
[] = {
105 { 0x0000, "Success" },
106 { 0x0001, "Invalid Controller ID" },
107 { 0x0002, "Failed - Unable to start link creation" },
108 { 0x0003, "Failed - Collision Occurred" },
109 { 0x0004, "Failed - AMP Disconnected Physical Link Request packet received" },
110 { 0x0005, "Failed - Physical Link Already Exists" },
114 static const value_string disc_status_vals
[] = {
115 { 0x0000, "Success" },
116 { 0x0001, "Invalid Controller ID" },
117 { 0x0002, "Failed - No Physical Link exists and no Physical Link creation is in progress" },
122 void proto_register_btamp(void);
123 void proto_reg_handoff_btamp(void);
126 dissect_comrej(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
130 reason
= tvb_get_letohs(tvb
, offset
);
131 proto_tree_add_item(tree
, hf_btamp_rej_reason
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
135 case 0x0000: /* Command not understood */
146 dissect_discoverrequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
148 proto_tree_add_item(tree
, hf_btamp_mtu
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
151 proto_tree_add_item(tree
, hf_btamp_extfeatures
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
158 dissect_controller_entry(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
, uint16_t idx
)
160 proto_item
*ti_controller_entry
;
161 proto_tree
*btamp_controller_entry_tree
;
163 ti_controller_entry
= proto_tree_add_none_format(tree
,
164 hf_btamp_controllers
, tvb
,
167 btamp_controller_entry_tree
= proto_item_add_subtree(ti_controller_entry
, ett_btamp_controller_entry
);
169 proto_tree_add_item(btamp_controller_entry_tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
172 proto_tree_add_item(btamp_controller_entry_tree
, hf_btamp_controller_type
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
175 proto_tree_add_item(btamp_controller_entry_tree
, hf_btamp_controller_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
182 dissect_discoverresponse(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
)
186 proto_item
*ti_controller_list
;
187 proto_tree
*btamp_controller_list_tree
;
189 proto_tree_add_item(tree
, hf_btamp_mtu
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
192 proto_tree_add_item(tree
, hf_btamp_extfeatures
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
195 length
= tvb_reported_length_remaining(tvb
, offset
);
196 ti_controller_list
= proto_tree_add_none_format(tree
,
197 hf_btamp_controller_list
, tvb
,
200 btamp_controller_list_tree
= proto_item_add_subtree(ti_controller_list
, ett_btamp_controller_list
);
202 while (tvb_reported_length_remaining(tvb
, offset
) >= 3) {
203 offset
= dissect_controller_entry(tvb
, offset
, pinfo
, btamp_controller_list_tree
, idx
);
211 dissect_changenotify(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
)
215 proto_item
*ti_controller_list
;
216 proto_tree
*btamp_controller_list_tree
;
218 length
= tvb_reported_length_remaining(tvb
, offset
);
219 ti_controller_list
= proto_tree_add_none_format(tree
,
220 hf_btamp_controller_list
, tvb
,
223 btamp_controller_list_tree
= proto_item_add_subtree(ti_controller_list
, ett_btamp_controller_list
);
225 while (tvb_reported_length_remaining(tvb
, offset
) >= 3) {
226 offset
= dissect_controller_entry(tvb
, offset
, pinfo
, btamp_controller_list_tree
, idx
);
234 dissect_changeresponse(tvbuff_t
*tvb _U_
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree _U_
)
240 dissect_getinforequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
242 proto_tree_add_item(tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
249 dissect_getinforesponse(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
251 proto_item
*ti_controller
;
252 proto_tree
*btamp_controller_tree
;
254 proto_tree_add_item(tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
257 proto_tree_add_item(tree
, hf_btamp_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
260 proto_tree_add_item(tree
, hf_btamp_total_bw
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
263 proto_tree_add_item(tree
, hf_btamp_max_guaran_bw
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
266 proto_tree_add_item(tree
, hf_btamp_min_latency
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
269 ti_controller
= proto_tree_add_none_format(tree
,
270 hf_btamp_pal_caps_mask
, tvb
,
273 btamp_controller_tree
= proto_item_add_subtree(ti_controller
, ett_btamp_caps
);
274 proto_tree_add_item(btamp_controller_tree
, hf_btamp_pal_caps_guaranteed
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
277 proto_tree_add_item(tree
, hf_btamp_amp_assoc_size
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
284 dissect_getampassocrequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
286 proto_tree_add_item(tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
293 dissect_ampassoc(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
295 proto_tree_add_item(tree
, hf_btamp_amp_assoc
, tvb
, offset
, tvb_reported_length_remaining(tvb
, offset
), ENC_NA
);
296 return tvb_reported_length(tvb
);
300 dissect_getampassocresponse(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
)
302 proto_tree_add_item(tree
, hf_btamp_controller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
305 proto_tree_add_item(tree
, hf_btamp_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
308 offset
= dissect_ampassoc(tvb
, offset
, pinfo
, tree
);
314 dissect_createphysicalrequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
)
316 proto_tree_add_item(tree
, hf_btamp_lcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
319 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
322 offset
= dissect_ampassoc(tvb
, offset
, pinfo
, tree
);
328 dissect_createphysicalresponse(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
330 proto_tree_add_item(tree
, hf_btamp_lcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
333 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
336 proto_tree_add_item(tree
, hf_btamp_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
343 dissect_discphysicalchanrequest(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
345 proto_tree_add_item(tree
, hf_btamp_lcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
348 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
355 dissect_discphysicalchanresponse(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
357 proto_tree_add_item(tree
, hf_btamp_lcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
360 proto_tree_add_item(tree
, hf_btamp_rcontroller_id
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
363 proto_tree_add_item(tree
, hf_btamp_controller_status
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
370 dissect_btamp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
374 proto_tree
*btamp_tree
;
376 proto_item
*ti_command
;
377 proto_tree
*btamp_cmd_tree
;
381 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "AMP");
383 switch (pinfo
->p2p_dir
) {
385 col_set_str(pinfo
->cinfo
, COL_INFO
, "Sent ");
388 col_set_str(pinfo
->cinfo
, COL_INFO
, "Rcvd ");
391 col_set_str(pinfo
->cinfo
, COL_INFO
, "UnknownDirection ");
395 ti
= proto_tree_add_item(tree
, proto_btamp
, tvb
, offset
, -1, ENC_NA
);
396 btamp_tree
= proto_item_add_subtree(ti
, ett_btamp
);
398 length
= tvb_reported_length_remaining(tvb
, offset
);
399 ti_command
= proto_tree_add_none_format(btamp_tree
,
400 hf_btamp_command
, tvb
,
403 btamp_cmd_tree
= proto_item_add_subtree(ti_command
, ett_btamp_cmd
);
405 cmd_code
= tvb_get_uint8(tvb
, offset
);
406 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_code
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
409 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_ident
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
412 cmd_length
= tvb_get_letohs(tvb
, offset
);
413 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_length
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
414 proto_item_set_len(ti_command
, cmd_length
+4);
418 case 0x01: /* Command Reject */
419 offset
= dissect_comrej(tvb
, offset
, pinfo
, btamp_cmd_tree
);
422 case 0x02: /* Discover Request */
423 offset
= dissect_discoverrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
426 case 0x03: /* Discover Response */
427 offset
= dissect_discoverresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
430 case 0x04: /* AMP Change Notify */
431 offset
= dissect_changenotify(tvb
, offset
, pinfo
, btamp_cmd_tree
);
434 case 0x05: /* AMP Change Response */
435 offset
= dissect_changeresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
438 case 0x06: /* AMP Get Info Request */
439 offset
= dissect_getinforequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
442 case 0x07: /* AMP Get Info Response */
443 offset
= dissect_getinforesponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
446 case 0x08: /* Get AMP Assoc Request */
447 offset
= dissect_getampassocrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
450 case 0x09: /* Get AMP Assoc Response */
451 offset
= dissect_getampassocresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
454 case 0x0A: /* Create Physical Link Request */
455 offset
= dissect_createphysicalrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
458 case 0x0B: /* Create Physical Link Response */
459 offset
= dissect_createphysicalresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
462 case 0x0c: /* Disconnect Physical Link Request */
463 offset
= dissect_discphysicalchanrequest(tvb
, offset
, pinfo
, btamp_cmd_tree
);
466 case 0x0d: /* Disconnect Physical Link Response */
467 offset
= dissect_discphysicalchanresponse(tvb
, offset
, pinfo
, btamp_cmd_tree
);
471 proto_tree_add_item(btamp_cmd_tree
, hf_btamp_cmd_data
, tvb
, offset
, -1, ENC_NA
);
472 offset
= tvb_reported_length(tvb
);
476 proto_item_append_text(ti_command
, "%s", val_to_str(cmd_code
, command_code_vals
, "Unknown PDU (%u)"));
477 col_append_str(pinfo
->cinfo
, COL_INFO
, val_to_str(cmd_code
, command_code_vals
, "Unknown PDU (%u)"));
482 /* Register the protocol with Wireshark */
484 proto_register_btamp(void)
486 /* Setup list of header fields See Section 1.6.1 for details*/
487 static hf_register_info hf
[] = {
489 { "Command", "btamp.command",
490 FT_NONE
, BASE_NONE
, NULL
, 0x0,
491 "L2CAP Command", HFILL
}
493 { &hf_btamp_cmd_code
,
494 { "Command Code", "btamp.cmd_code",
495 FT_UINT8
, BASE_HEX
, VALS(command_code_vals
), 0x0,
496 "L2CAP Command Code", HFILL
}
498 { &hf_btamp_cmd_ident
,
499 { "Command Identifier", "btamp.cmd_ident",
500 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
501 "L2CAP Command Identifier", HFILL
}
503 { &hf_btamp_cmd_length
,
504 { "Command Length", "btamp.cmd_length",
505 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
506 "L2CAP Command Length", HFILL
}
508 { &hf_btamp_cmd_data
,
509 { "Command Data", "btamp.cmd_data",
510 FT_NONE
, BASE_NONE
, NULL
, 0x0,
511 "L2CAP Command Data", HFILL
}
513 { &hf_btamp_rej_reason
,
514 { "Reason", "btamp.rej_reason",
515 FT_UINT16
, BASE_HEX
, VALS(reason_vals
), 0x0,
519 { "MPS/MTU", "btamp.mps",
520 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
521 "MPS/MTU Size", HFILL
}
523 { &hf_btamp_extfeatures
,
524 { "Extended Features", "btamp.extfeatures",
525 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
526 "Extended Features Mask", HFILL
}
528 { &hf_btamp_controllers
,
529 { "Controller entry", "btamp.ctrl_entry",
530 FT_NONE
, BASE_NONE
, NULL
, 0x0,
533 { &hf_btamp_controller_list
,
534 { "Controller list", "btamp.ctrl_list",
535 FT_NONE
, BASE_NONE
, NULL
, 0x0,
538 { &hf_btamp_lcontroller_id
,
539 { "Local Controller ID", "btamp.lctrl_id",
540 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
543 { &hf_btamp_rcontroller_id
,
544 { "Remote Controller ID", "btamp.rctrl_id",
545 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
548 { &hf_btamp_controller_id
,
549 { "Controller ID", "btamp.ctrl_id",
550 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
553 { &hf_btamp_controller_type
,
554 { "Controller Type", "btamp.ctrl_type",
555 FT_UINT8
, BASE_DEC
, VALS(controller_type_vals
), 0x0,
558 { &hf_btamp_controller_status
,
559 { "Controller Status", "btamp.ctrl_status",
560 FT_UINT8
, BASE_DEC
, VALS(controller_status_vals
), 0x0,
564 { "Status", "btamp.status",
565 FT_UINT8
, BASE_DEC
, VALS(status_vals
), 0x0,
569 { &hf_btamp_create_status
,
570 { "Status", "btamp.create_status",
571 FT_UINT8
, BASE_DEC
, VALS(create_status_vals
), 0x0,
574 { &hf_btamp_disc_status
,
575 { "Status", "btamp.disc_status",
576 FT_UINT8
, BASE_DEC
, VALS(disc_status_vals
), 0x0,
580 { &hf_btamp_pal_caps_mask
,
581 { "PAL Capabilities Mask", "btamp.pal_caps_mask",
582 FT_NONE
, BASE_NONE
, NULL
, 0x0,
585 { &hf_btamp_pal_caps_guaranteed
,
586 { "Guaranteed Service type", "btamp.guaranteed_type",
587 FT_BOOLEAN
, 16, NULL
, 0x0001,
590 { &hf_btamp_total_bw
,
591 { "Total Bandwidth", "btamp.total_bw",
592 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
595 { &hf_btamp_max_guaran_bw
,
596 { "Max Guaranteed Bandwidth", "btamp.max_guaran_bw",
597 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
600 { &hf_btamp_min_latency
,
601 { "Minimum latency", "btamp.min_latency",
602 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
605 { &hf_btamp_amp_assoc_size
,
606 { "Assoc Size", "btamp.assoc_size",
607 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
610 { &hf_btamp_amp_assoc
,
611 { "Assoc", "btamp.assoc",
612 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
617 /* Setup protocol subtree array */
618 static int *ett
[] = {
622 &ett_btamp_controller_entry
,
623 &ett_btamp_controller_list
,
626 /* Register the protocol name and description */
627 proto_btamp
= proto_register_protocol("Bluetooth AMP Packet", "BT AMP", "btamp");
629 btamp_handle
= register_dissector("btamp", dissect_btamp
, proto_btamp
);
631 /* Required function calls to register the header fields and subtrees used */
632 proto_register_field_array(proto_btamp
, hf
, array_length(hf
));
633 proto_register_subtree_array(ett
, array_length(ett
));
637 proto_reg_handoff_btamp(void)
639 dissector_add_uint("btl2cap.cid", BTL2CAP_FIXED_CID_AMP_MAN
, btamp_handle
);
643 * Editor modelines - https://www.wireshark.org/tools/modelines.html
648 * indent-tabs-mode: nil
651 * vi: set shiftwidth=4 tabstop=8 expandtab:
652 * :indentSize=4:tabSize=8:noTabs=true: