3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011-2014 Intel Corporation
6 * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include "lib/bluetooth.h"
35 #include "src/shared/util.h"
43 #define COLOR_UNKNOWN_EVENT_MASK COLOR_WHITE_BG
44 #define COLOR_UNKNOWN_SCAN_STATUS COLOR_WHITE_BG
46 static void print_status(uint8_t status)
48 packet_print_error("Status", status);
51 static void print_module(uint8_t module)
97 print_field("Module: %s (0x%2.2x)", str, module);
100 static void null_cmd(const void *data, uint8_t size)
104 static void status_rsp(const void *data, uint8_t size)
106 uint8_t status = get_u8(data);
108 print_status(status);
111 static void reset_cmd(const void *data, uint8_t size)
113 uint8_t reset_type = get_u8(data);
114 uint8_t patch_enable = get_u8(data + 1);
115 uint8_t ddc_reload = get_u8(data + 2);
116 uint8_t boot_option = get_u8(data + 3);
117 uint32_t boot_addr = get_le32(data + 4);
120 switch (reset_type) {
122 str = "Soft software reset";
125 str = "Hard software reset";
132 print_field("Reset type: %s (0x%2.2x)", str, reset_type);
134 switch (patch_enable) {
136 str = "Do not enable";
146 print_field("Patch vectors: %s (0x%2.2x)", str, patch_enable);
148 switch (ddc_reload) {
150 str = "Do not reload";
153 str = "Reload from OTP";
160 print_field("DDC parameters: %s (0x%2.2x)", str, ddc_reload);
162 switch (boot_option) {
164 str = "Current image";
167 str = "Specified address";
174 print_field("Boot option: %s (0x%2.2x)", str, boot_option);
175 print_field("Boot address: 0x%8.8x", boot_addr);
178 static void read_version_rsp(const void *data, uint8_t size)
180 uint8_t status = get_u8(data);
181 uint8_t hw_platform = get_u8(data + 1);
182 uint8_t hw_variant = get_u8(data + 2);
183 uint8_t hw_revision = get_u8(data + 3);
184 uint8_t fw_variant = get_u8(data + 4);
185 uint8_t fw_revision = get_u8(data + 5);
186 uint8_t fw_build_nn = get_u8(data + 6);
187 uint8_t fw_build_cw = get_u8(data + 7);
188 uint8_t fw_build_yy = get_u8(data + 8);
189 uint8_t fw_patch = get_u8(data + 9);
191 print_status(status);
192 print_field("Hardware platform: 0x%2.2x", hw_platform);
193 print_field("Hardware variant: 0x%2.2x", hw_variant);
194 print_field("Hardware revision: %u.%u", hw_revision >> 4,
196 print_field("Firmware variant: 0x%2.2x", fw_variant);
197 print_field("Firmware revision: %u.%u", fw_revision >> 4,
200 print_field("Firmware build: %u-%u.%u", fw_build_nn,
201 fw_build_cw, 2000 + fw_build_yy);
202 print_field("Firmware patch: %u", fw_patch);
205 static void set_uart_baudrate_cmd(const void *data, uint8_t size)
207 uint8_t baudrate = get_u8(data);
236 str = "1843200 Baud";
239 str = "3250000 baud";
242 str = "2000000 baud";
245 str = "3000000 baud";
248 str = "3714286 baud";
251 str = "4333333 baud";
254 str = "6500000 baud";
261 print_field("Baudrate: %s (0x%2.2x)", str, baudrate);
264 static void secure_send_cmd(const void *data, uint8_t size)
266 uint8_t type = get_u8(data);
287 print_field("Type: %s fragment (0x%2.2x)", str, type);
289 packet_hexdump(data + 1, size - 1);
292 static void manufacturer_mode_cmd(const void *data, uint8_t size)
294 uint8_t mode = get_u8(data);
295 uint8_t reset = get_u8(data + 1);
310 print_field("Mode switch: %s (0x%2.2x)", str, mode);
317 str = "Reset and deactivate patches";
320 str = "Reset and activate patches";
327 print_field("Reset behavior: %s (0x%2.2x)", str, reset);
330 static void write_bd_data_cmd(const void *data, uint8_t size)
334 packet_print_addr("Address", data, false);
335 packet_hexdump(data + 6, 6);
337 memcpy(features, data + 12, 8);
338 packet_print_features_lmp(features, 0);
340 memcpy(features, data + 20, 1);
341 memset(features + 1, 0, 7);
342 packet_print_features_ll(features);
344 packet_hexdump(data + 21, size - 21);
347 static void read_bd_data_rsp(const void *data, uint8_t size)
349 uint8_t status = get_u8(data);
351 print_status(status);
352 packet_print_addr("Address", data + 1, false);
353 packet_hexdump(data + 7, size - 7);
356 static void write_bd_address_cmd(const void *data, uint8_t size)
358 packet_print_addr("Address", data, false);
361 static void act_deact_traces_cmd(const void *data, uint8_t size)
363 uint8_t tx = get_u8(data);
364 uint8_t tx_arq = get_u8(data + 1);
365 uint8_t rx = get_u8(data + 2);
367 print_field("Transmit traces: 0x%2.2x", tx);
368 print_field("Transmit ARQ: 0x%2.2x", tx_arq);
369 print_field("Receive traces: 0x%2.2x", rx);
372 static void stimulate_exception_cmd(const void *data, uint8_t size)
374 uint8_t type = get_u8(data);
379 str = "Fatal Exception";
382 str = "Debug Exception";
389 print_field("Type: %s (0x%2.2x)", str, type);
392 static const struct {
397 { 1, "SCO Rejected via LMP" },
398 { 2, "PTT Switch Notification" },
399 { 7, "Scan Status" },
400 { 9, "Debug Exception" },
401 { 10, "Fatal Exception" },
402 { 11, "System Exception" },
403 { 13, "LE Link Established" },
404 { 14, "FW Trace String" },
408 static void set_event_mask_cmd(const void *data, uint8_t size)
410 const uint8_t *events_array = data;
411 uint64_t mask, events = 0;
414 for (i = 0; i < 8; i++)
415 events |= ((uint64_t) events_array[i]) << (i * 8);
417 print_field("Mask: 0x%16.16" PRIx64, events);
421 for (i = 0; events_table[i].str; i++) {
422 if (events & (((uint64_t) 1) << events_table[i].bit)) {
423 print_field(" %s", events_table[i].str);
424 mask &= ~(((uint64_t) 1) << events_table[i].bit);
429 print_text(COLOR_UNKNOWN_EVENT_MASK, " Unknown mask "
430 "(0x%16.16" PRIx64 ")", mask);
433 static void ddc_config_write_cmd(const void *data, uint8_t size)
436 uint8_t param_len = get_u8(data);
437 uint16_t param_id = get_le16(data + 1);
439 print_field("Identifier: 0x%4.4x", param_id);
440 packet_hexdump(data + 3, param_len - 2);
442 data += param_len + 1;
443 size -= param_len + 1;
447 static void ddc_config_write_rsp(const void *data, uint8_t size)
449 uint8_t status = get_u8(data);
450 uint16_t param_id = get_le16(data + 1);
452 print_status(status);
453 print_field("Identifier: 0x%4.4x", param_id);
456 static void memory_write_cmd(const void *data, uint8_t size)
458 uint32_t addr = get_le32(data);
459 uint8_t mode = get_u8(data + 4);
460 uint8_t length = get_u8(data + 5);
463 print_field("Address: 0x%8.8x", addr);
470 str = "Half word access";
480 print_field("Mode: %s (0x%2.2x)", str, mode);
481 print_field("Length: %u", length);
483 packet_hexdump(data + 6, size - 6);
486 static const struct vendor_ocf vendor_ocf_table[] = {
489 status_rsp, 1, true },
490 { 0x002, "No Operation" },
491 { 0x005, "Read Version",
493 read_version_rsp, 10, true },
494 { 0x006, "Set UART Baudrate",
495 set_uart_baudrate_cmd, 1, true,
496 status_rsp, 1, true },
497 { 0x007, "Enable LPM" },
498 { 0x008, "PCM Write Configuration" },
499 { 0x009, "Secure Send",
500 secure_send_cmd, 1, false,
501 status_rsp, 1, true },
502 { 0x00d, "Read Secure Boot Params",
504 { 0x00e, "Write Secure Boot Params" },
506 { 0x010, "Change UART Baudrate" },
507 { 0x011, "Manufacturer Mode",
508 manufacturer_mode_cmd, 2, true,
509 status_rsp, 1, true },
510 { 0x012, "Read Link RSSI" },
511 { 0x022, "Get Exception Info" },
512 { 0x024, "Clear Exception Info" },
513 { 0x02f, "Write BD Data",
514 write_bd_data_cmd, 6, false },
515 { 0x030, "Read BD Data",
517 read_bd_data_rsp, 7, false },
518 { 0x031, "Write BD Address",
519 write_bd_address_cmd, 6, true,
520 status_rsp, 1, true },
521 { 0x032, "Flow Specification" },
522 { 0x034, "Read Secure ID" },
523 { 0x038, "Set Synchronous USB Interface Type" },
524 { 0x039, "Config Synchronous Interface" },
525 { 0x03f, "SW RF Kill",
527 status_rsp, 1, true },
528 { 0x043, "Activate Deactivate Traces",
529 act_deact_traces_cmd, 3, true },
530 { 0x04d, "Stimulate Exception",
531 stimulate_exception_cmd, 1, true,
532 status_rsp, 1, true },
533 { 0x050, "Read HW Version" },
534 { 0x052, "Set Event Mask",
535 set_event_mask_cmd, 8, true,
536 status_rsp, 1, true },
537 { 0x053, "Config_Link_Controller" },
538 { 0x089, "DDC Write" },
539 { 0x08a, "DDC Read" },
540 { 0x08b, "DDC Config Write",
541 ddc_config_write_cmd, 3, false,
542 ddc_config_write_rsp, 3, true },
543 { 0x08c, "DDC Config Read" },
544 { 0x08d, "Memory Read" },
545 { 0x08e, "Memory Write",
546 memory_write_cmd, 6, false,
547 status_rsp, 1, true },
551 const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
555 for (i = 0; vendor_ocf_table[i].str; i++) {
556 if (vendor_ocf_table[i].ocf == ocf)
557 return &vendor_ocf_table[i];
563 static void startup_evt(const void *data, uint8_t size)
567 static void fatal_exception_evt(const void *data, uint8_t size)
569 uint16_t line = get_le16(data);
570 uint8_t module = get_u8(data + 2);
571 uint8_t reason = get_u8(data + 3);
573 print_field("Line: %u", line);
574 print_module(module);
575 print_field("Reason: 0x%2.2x", reason);
578 static void bootup_evt(const void *data, uint8_t size)
580 uint8_t zero = get_u8(data);
581 uint8_t num_packets = get_u8(data + 1);
582 uint8_t source = get_u8(data + 2);
583 uint8_t reset_type = get_u8(data + 3);
584 uint8_t reset_reason = get_u8(data + 4);
585 uint8_t ddc_status = get_u8(data + 5);
588 print_field("Zero: 0x%2.2x", zero);
589 print_field("Number of packets: %d", num_packets);
596 str = "Operational firmware";
599 str = "Self test firmware";
606 print_field("Source: %s (0x%2.2x)", str, source);
608 switch (reset_type) {
610 str = "Hardware reset";
613 str = "Soft watchdog reset";
616 str = "Soft software reset";
619 str = "Hard watchdog reset";
622 str = "Hard software reset";
629 print_field("Reset type: %s (0x%2.2x)", str, reset_type);
631 switch (reset_reason) {
636 str = "Reset command";
639 str = "Intel reset command";
645 str = "Fatal exception";
648 str = "System exception";
658 print_field("Reset reason: %s (0x%2.2x)", str, reset_reason);
660 switch (ddc_status) {
662 str = "Firmware default";
665 str = "Firmware default plus OTP";
668 str = "Persistent RAM";
678 print_field("DDC status: %s (0x%2.2x)", str, ddc_status);
681 static void default_bd_data_evt(const void *data, uint8_t size)
683 uint8_t mem_status = get_u8(data);
686 switch (mem_status) {
688 str = "Invalid manufacturing data";
695 print_field("Memory status: %s (0x%2.2x)", str, mem_status);
698 static void secure_send_commands_result_evt(const void *data, uint8_t size)
700 uint8_t result = get_u8(data);
701 uint16_t opcode = get_le16(data + 1);
702 uint16_t ogf = cmd_opcode_ogf(opcode);
703 uint16_t ocf = cmd_opcode_ocf(opcode);
704 uint8_t status = get_u8(data + 3);
712 str = "General failure";
715 str = "Hardware failure";
718 str = "Signature verification failed";
721 str = "Parsing error of command buffer";
724 str = "Command execution failure";
727 str = "Command parameters error";
730 str = "Command missing";
737 print_field("Result: %s (0x%2.2x)", str, result);
738 print_field("Opcode: 0x%4.4x (0x%2.2x|0x%4.4x)", opcode, ogf, ocf);
739 print_status(status);
742 static void debug_exception_evt(const void *data, uint8_t size)
744 uint16_t line = get_le16(data);
745 uint8_t module = get_u8(data + 2);
746 uint8_t reason = get_u8(data + 3);
748 print_field("Line: %u", line);
749 print_module(module);
750 print_field("Reason: 0x%2.2x", reason);
753 static void le_link_established_evt(const void *data, uint8_t size)
755 uint16_t handle = get_le16(data);
756 uint32_t access_addr = get_le32(data + 10);
758 print_field("Handle: %u", handle);
760 packet_hexdump(data + 2, 8);
762 print_field("Access address: 0x%8.8x", access_addr);
764 packet_hexdump(data + 14, size - 14);
767 static void scan_status_evt(const void *data, uint8_t size)
769 uint8_t enable = get_u8(data);
771 print_field("Inquiry scan: %s",
772 (enable & 0x01) ? "Enabled" : "Disabled");
773 print_field("Page scan: %s",
774 (enable & 0x02) ? "Enabled" : "Disabled");
777 print_text(COLOR_UNKNOWN_SCAN_STATUS,
778 " Unknown status (0x%2.2x)", enable & 0xfc);
782 static void act_deact_traces_complete_evt(const void *data, uint8_t size)
784 uint8_t status = get_u8(data);
786 print_status(status);
789 static void lmp_pdu_trace_evt(const void *data, uint8_t size)
791 uint8_t type, len, id;
792 uint16_t handle, count;
797 handle = get_le16(data + 1);
823 print_field("Type: %s (0x%2.2x)", str, type);
824 print_field("Handle: %u", handle);
829 clock = get_le32(data + 4 + len);
831 packet_hexdump(data + 3, 1);
832 lmp_packet(data + 4, len, false);
833 print_field("Clock: 0x%8.8x", clock);
837 clock = get_le32(data + 4 + len);
838 id = get_u8(data + 4 + len + 4);
840 packet_hexdump(data + 3, 1);
841 lmp_packet(data + 4, len, false);
842 print_field("Clock: 0x%8.8x", clock);
843 print_field("ID: 0x%2.2x", id);
846 clock = get_le32(data + 3);
847 id = get_u8(data + 3 + 4);
849 print_field("Clock: 0x%8.8x", clock);
850 print_field("ID: 0x%2.2x", id);
854 count = get_le16(data + 3);
856 print_field("Count: 0x%4.4x", count);
857 packet_hexdump(data + 3 + 2 + 1, 2);
858 llcp_packet(data + 8, len, false);
862 count = get_le16(data + 3);
863 id = get_u8(data + 3 + 2);
865 print_field("Count: 0x%4.4x", count);
866 print_field("ID: 0x%2.2x", id);
867 packet_hexdump(data + 3 + 2 + 1, 2);
868 llcp_packet(data + 8, len, false);
871 count = get_le16(data + 3);
872 id = get_u8(data + 3 + 2);
874 print_field("Count: 0x%4.4x", count);
875 print_field("ID: 0x%2.2x", id);
878 packet_hexdump(data + 3, size - 3);
883 static void write_bd_data_complete_evt(const void *data, uint8_t size)
885 uint8_t status = get_u8(data);
887 print_status(status);
890 static void sco_rejected_via_lmp_evt(const void *data, uint8_t size)
892 uint8_t reason = get_u8(data + 6);
894 packet_print_addr("Address", data, false);
895 packet_print_error("Reason", reason);
898 static void ptt_switch_notification_evt(const void *data, uint8_t size)
900 uint16_t handle = get_le16(data);
901 uint8_t table = get_u8(data + 2);
904 print_field("Handle: %u", handle);
911 str = "Enhanced data rate";
918 print_field("Packet type table: %s (0x%2.2x)", str, table);
921 static void system_exception_evt(const void *data, uint8_t size)
923 uint8_t type = get_u8(data);
928 str = "No Exception";
931 str = "Undefined Instruction";
934 str = "Prefetch abort";
944 print_field("Type: %s (0x%2.2x)", str, type);
946 packet_hexdump(data + 1, size - 1);
949 static const struct vendor_evt vendor_evt_table[] = {
951 startup_evt, 0, true },
952 { 0x01, "Fatal Exception",
953 fatal_exception_evt, 4, true },
955 bootup_evt, 6, true },
956 { 0x05, "Default BD Data",
957 default_bd_data_evt, 1, true },
958 { 0x06, "Secure Send Commands Result",
959 secure_send_commands_result_evt, 4, true },
960 { 0x08, "Debug Exception",
961 debug_exception_evt, 4, true },
962 { 0x0f, "LE Link Established",
963 le_link_established_evt, 26, true },
964 { 0x11, "Scan Status",
965 scan_status_evt, 1, true },
966 { 0x16, "Activate Deactivate Traces Complete",
967 act_deact_traces_complete_evt, 1, true },
968 { 0x17, "LMP PDU Trace",
969 lmp_pdu_trace_evt, 3, false },
970 { 0x19, "Write BD Data Complete",
971 write_bd_data_complete_evt, 1, true },
972 { 0x25, "SCO Rejected via LMP",
973 sco_rejected_via_lmp_evt, 7, true },
974 { 0x26, "PTT Switch Notification",
975 ptt_switch_notification_evt, 3, true },
976 { 0x29, "System Exception",
977 system_exception_evt, 133, true },
978 { 0x2c, "FW Trace String" },
979 { 0x2e, "FW Trace Binary" },
983 const struct vendor_evt *intel_vendor_evt(uint8_t evt)
987 for (i = 0; vendor_evt_table[i].str; i++) {
988 if (vendor_evt_table[i].evt == evt)
989 return &vendor_evt_table[i];