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 secure_send_cmd(const void *data, uint8_t size)
207 uint8_t type = get_u8(data);
228 print_field("Type: %s fragment (0x%2.2x)", str, type);
230 packet_hexdump(data + 1, size - 1);
233 static void manufacturer_mode_cmd(const void *data, uint8_t size)
235 uint8_t mode = get_u8(data);
236 uint8_t reset = get_u8(data + 1);
251 print_field("Mode switch: %s (0x%2.2x)", str, mode);
258 str = "Reset and deactivate patches";
261 str = "Reset and activate patches";
268 print_field("Reset behavior: %s (0x%2.2x)", str, reset);
271 static void write_bd_data_cmd(const void *data, uint8_t size)
275 packet_print_addr("Address", data, false);
276 packet_hexdump(data + 6, 6);
278 memcpy(features, data + 12, 8);
279 packet_print_features_lmp(features, 0);
281 memcpy(features, data + 20, 1);
282 memset(features + 1, 0, 7);
283 packet_print_features_ll(features);
285 packet_hexdump(data + 21, size - 21);
288 static void read_bd_data_rsp(const void *data, uint8_t size)
290 uint8_t status = get_u8(data);
292 print_status(status);
293 packet_print_addr("Address", data + 1, false);
294 packet_hexdump(data + 7, size - 7);
297 static void write_bd_address_cmd(const void *data, uint8_t size)
299 packet_print_addr("Address", data, false);
302 static void act_deact_traces_cmd(const void *data, uint8_t size)
304 uint8_t tx = get_u8(data);
305 uint8_t tx_arq = get_u8(data + 1);
306 uint8_t rx = get_u8(data + 2);
308 print_field("Transmit traces: 0x%2.2x", tx);
309 print_field("Transmit ARQ: 0x%2.2x", tx_arq);
310 print_field("Receive traces: 0x%2.2x", rx);
313 static void stimulate_exception_cmd(const void *data, uint8_t size)
315 uint8_t type = get_u8(data);
320 str = "Fatal Exception";
323 str = "Debug Exception";
330 print_field("Type: %s (0x%2.2x)", str, type);
333 static const struct {
338 { 1, "SCO Rejected via LMP" },
339 { 2, "PTT Switch Notification" },
340 { 7, "Scan Status" },
341 { 9, "Debug Exception" },
342 { 10, "Fatal Exception" },
343 { 11, "System Exception" },
344 { 13, "LE Link Established" },
345 { 14, "FW Trace String" },
349 static void set_event_mask_cmd(const void *data, uint8_t size)
351 const uint8_t *events_array = data;
352 uint64_t mask, events = 0;
355 for (i = 0; i < 8; i++)
356 events |= ((uint64_t) events_array[i]) << (i * 8);
358 print_field("Mask: 0x%16.16" PRIx64, events);
362 for (i = 0; events_table[i].str; i++) {
363 if (events & (((uint64_t) 1) << events_table[i].bit)) {
364 print_field(" %s", events_table[i].str);
365 mask &= ~(((uint64_t) 1) << events_table[i].bit);
370 print_text(COLOR_UNKNOWN_EVENT_MASK, " Unknown mask "
371 "(0x%16.16" PRIx64 ")", mask);
374 static void ddc_config_write_cmd(const void *data, uint8_t size)
377 uint8_t param_len = get_u8(data);
378 uint16_t param_id = get_le16(data + 1);
380 print_field("Identifier: 0x%4.4x", param_id);
381 packet_hexdump(data + 2, param_len - 2);
383 data += param_len + 1;
384 size -= param_len + 1;
388 static void ddc_config_write_rsp(const void *data, uint8_t size)
390 uint8_t status = get_u8(data);
391 uint16_t param_id = get_le16(data + 1);
393 print_status(status);
394 print_field("Identifier: 0x%4.4x", param_id);
397 static void memory_write_cmd(const void *data, uint8_t size)
399 uint32_t addr = get_le32(data);
400 uint8_t mode = get_u8(data + 4);
401 uint8_t length = get_u8(data + 5);
404 print_field("Address: 0x%8.8x", addr);
411 str = "Half word access";
421 print_field("Mode: %s (0x%2.2x)", str, mode);
422 print_field("Length: %u", length);
424 packet_hexdump(data + 6, size - 6);
427 static const struct vendor_ocf vendor_ocf_table[] = {
430 status_rsp, 1, true },
431 { 0x002, "No Operation" },
432 { 0x005, "Read Version",
434 read_version_rsp, 10, true },
435 { 0x006, "Set UART Baudrate" },
436 { 0x007, "Enable LPM" },
437 { 0x008, "PCM Write Configuration" },
438 { 0x009, "Secure Send",
439 secure_send_cmd, 1, false,
440 status_rsp, 1, true },
441 { 0x00d, "Read Secure Boot Params",
443 { 0x00e, "Write Secure Boot Params" },
445 { 0x010, "Change UART Baudrate" },
446 { 0x011, "Manufacturer Mode",
447 manufacturer_mode_cmd, 2, true,
448 status_rsp, 1, true },
449 { 0x012, "Read Link RSSI" },
450 { 0x022, "Get Exception Info" },
451 { 0x024, "Clear Exception Info" },
452 { 0x02f, "Write BD Data",
453 write_bd_data_cmd, 6, false },
454 { 0x030, "Read BD Data",
456 read_bd_data_rsp, 7, false },
457 { 0x031, "Write BD Address",
458 write_bd_address_cmd, 6, true,
459 status_rsp, 1, true },
460 { 0x032, "Flow Specification" },
461 { 0x034, "Read Secure ID" },
462 { 0x038, "Set Synchronous USB Interface Type" },
463 { 0x039, "Config Synchronous Interface" },
464 { 0x03f, "SW RF Kill",
466 status_rsp, 1, true },
467 { 0x043, "Activate Deactivate Traces",
468 act_deact_traces_cmd, 3, true },
469 { 0x04d, "Stimulate Exception",
470 stimulate_exception_cmd, 1, true,
471 status_rsp, 1, true },
472 { 0x050, "Read HW Version" },
473 { 0x052, "Set Event Mask",
474 set_event_mask_cmd, 8, true,
475 status_rsp, 1, true },
476 { 0x053, "Config_Link_Controller" },
477 { 0x089, "DDC Write" },
478 { 0x08a, "DDC Read" },
479 { 0x08b, "DDC Config Write",
480 ddc_config_write_cmd, 3, false,
481 ddc_config_write_rsp, 3, true },
482 { 0x08c, "DDC Config Read" },
483 { 0x08d, "Memory Read" },
484 { 0x08e, "Memory Write",
485 memory_write_cmd, 6, false,
486 status_rsp, 1, true },
490 const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
494 for (i = 0; vendor_ocf_table[i].str; i++) {
495 if (vendor_ocf_table[i].ocf == ocf)
496 return &vendor_ocf_table[i];
502 static void startup_evt(const void *data, uint8_t size)
506 static void fatal_exception_evt(const void *data, uint8_t size)
508 uint16_t line = get_le16(data);
509 uint8_t module = get_u8(data + 2);
510 uint8_t reason = get_u8(data + 3);
512 print_field("Line: %u", line);
513 print_module(module);
514 print_field("Reason: 0x%2.2x", reason);
517 static void bootup_evt(const void *data, uint8_t size)
519 uint8_t zero = get_u8(data);
520 uint8_t num_packets = get_u8(data + 1);
521 uint8_t source = get_u8(data + 2);
522 uint8_t reset_type = get_u8(data + 3);
523 uint8_t reset_reason = get_u8(data + 4);
524 uint8_t ddc_status = get_u8(data + 5);
527 print_field("Zero: 0x%2.2x", zero);
528 print_field("Number of packets: %d", num_packets);
535 str = "Operational firmware";
538 str = "Self test firmware";
545 print_field("Source: %s (0x%2.2x)", str, source);
547 switch (reset_type) {
549 str = "Hardware reset";
552 str = "Soft watchdog reset";
555 str = "Soft software reset";
558 str = "Hard watchdog reset";
561 str = "Hard software reset";
568 print_field("Reset type: %s (0x%2.2x)", str, reset_type);
570 switch (reset_reason) {
575 str = "Reset command";
578 str = "Intel reset command";
584 str = "Fatal exception";
587 str = "System exception";
597 print_field("Reset reason: %s (0x%2.2x)", str, reset_reason);
599 switch (ddc_status) {
601 str = "Firmware default";
604 str = "Firmware default plus OTP";
607 str = "Persistent RAM";
617 print_field("DDC status: %s (0x%2.2x)", str, ddc_status);
620 static void default_bd_data_evt(const void *data, uint8_t size)
622 uint8_t mem_status = get_u8(data);
625 switch (mem_status) {
627 str = "Invalid manufacturing data";
634 print_field("Memory status: %s (0x%2.2x)", str, mem_status);
637 static void secure_send_commands_result_evt(const void *data, uint8_t size)
639 uint8_t result = get_u8(data);
640 uint16_t opcode = get_le16(data + 1);
641 uint16_t ogf = cmd_opcode_ogf(opcode);
642 uint16_t ocf = cmd_opcode_ocf(opcode);
643 uint8_t status = get_u8(data + 3);
651 str = "General failure";
654 str = "Hardware failure";
657 str = "Signature verification failed";
660 str = "Parsing error of command buffer";
663 str = "Command execution failure";
666 str = "Command parameters error";
669 str = "Command missing";
676 print_field("Result: %s (0x%2.2x)", str, result);
677 print_field("Opcode: 0x%4.4x (0x%2.2x|0x%4.4x)", opcode, ogf, ocf);
678 print_status(status);
681 static void debug_exception_evt(const void *data, uint8_t size)
683 uint16_t line = get_le16(data);
684 uint8_t module = get_u8(data + 2);
685 uint8_t reason = get_u8(data + 3);
687 print_field("Line: %u", line);
688 print_module(module);
689 print_field("Reason: 0x%2.2x", reason);
692 static void le_link_established_evt(const void *data, uint8_t size)
694 uint16_t handle = get_le16(data);
695 uint32_t access_addr = get_le32(data + 10);
697 print_field("Handle: %u", handle);
699 packet_hexdump(data + 2, 8);
701 print_field("Access address: 0x%8.8x", access_addr);
703 packet_hexdump(data + 14, size - 14);
706 static void scan_status_evt(const void *data, uint8_t size)
708 uint8_t enable = get_u8(data);
710 print_field("Inquiry scan: %s",
711 (enable & 0x01) ? "Enabled" : "Disabled");
712 print_field("Page scan: %s",
713 (enable & 0x02) ? "Enabled" : "Disabled");
716 print_text(COLOR_UNKNOWN_SCAN_STATUS,
717 " Unknown status (0x%2.2x)", enable & 0xfc);
721 static void act_deact_traces_complete_evt(const void *data, uint8_t size)
723 uint8_t status = get_u8(data);
725 print_status(status);
728 static void lmp_pdu_trace_evt(const void *data, uint8_t size)
730 uint8_t type, len, id;
731 uint16_t handle, count;
736 handle = get_le16(data + 1);
762 print_field("Type: %s (0x%2.2x)", str, type);
763 print_field("Handle: %u", handle);
768 clock = get_le32(data + 4 + len);
770 packet_hexdump(data + 3, 1);
771 lmp_packet(data + 4, len, false);
772 print_field("Clock: 0x%8.8x", clock);
776 clock = get_le32(data + 4 + len);
777 id = get_u8(data + 4 + len + 4);
779 packet_hexdump(data + 3, 1);
780 lmp_packet(data + 4, len, false);
781 print_field("Clock: 0x%8.8x", clock);
782 print_field("ID: 0x%2.2x", id);
785 clock = get_le32(data + 3);
786 id = get_u8(data + 3 + 4);
788 print_field("Clock: 0x%8.8x", clock);
789 print_field("ID: 0x%2.2x", id);
793 count = get_le16(data + 3);
795 print_field("Count: 0x%4.4x", count);
796 packet_hexdump(data + 3 + 2 + 1, 2);
797 llcp_packet(data + 8, len, false);
801 count = get_le16(data + 3);
802 id = get_u8(data + 3 + 2);
804 print_field("Count: 0x%4.4x", count);
805 print_field("ID: 0x%2.2x", id);
806 packet_hexdump(data + 3 + 2 + 1, 2);
807 llcp_packet(data + 8, len, false);
810 count = get_le16(data + 3);
811 id = get_u8(data + 3 + 2);
813 print_field("Count: 0x%4.4x", count);
814 print_field("ID: 0x%2.2x", id);
817 packet_hexdump(data + 3, size - 3);
822 static void write_bd_data_complete_evt(const void *data, uint8_t size)
824 uint8_t status = get_u8(data);
826 print_status(status);
829 static void sco_rejected_via_lmp_evt(const void *data, uint8_t size)
831 uint8_t reason = get_u8(data + 6);
833 packet_print_addr("Address", data, false);
834 packet_print_error("Reason", reason);
837 static void ptt_switch_notification_evt(const void *data, uint8_t size)
839 uint16_t handle = get_le16(data);
840 uint8_t table = get_u8(data + 2);
843 print_field("Handle: %u", handle);
850 str = "Enhanced data rate";
857 print_field("Packet type table: %s (0x%2.2x)", str, table);
860 static void system_exception_evt(const void *data, uint8_t size)
862 uint8_t type = get_u8(data);
867 str = "No Exception";
870 str = "Undefined Instruction";
873 str = "Prefetch abort";
883 print_field("Type: %s (0x%2.2x)", str, type);
885 packet_hexdump(data + 1, size - 1);
888 static const struct vendor_evt vendor_evt_table[] = {
890 startup_evt, 0, true },
891 { 0x01, "Fatal Exception",
892 fatal_exception_evt, 4, true },
894 bootup_evt, 6, true },
895 { 0x05, "Default BD Data",
896 default_bd_data_evt, 1, true },
897 { 0x06, "Secure Send Commands Result",
898 secure_send_commands_result_evt, 4, true },
899 { 0x08, "Debug Exception",
900 debug_exception_evt, 4, true },
901 { 0x0f, "LE Link Established",
902 le_link_established_evt, 26, true },
903 { 0x11, "Scan Status",
904 scan_status_evt, 1, true },
905 { 0x16, "Activate Deactivate Traces Complete",
906 act_deact_traces_complete_evt, 1, true },
907 { 0x17, "LMP PDU Trace",
908 lmp_pdu_trace_evt, 3, false },
909 { 0x19, "Write BD Data Complete",
910 write_bd_data_complete_evt, 1, true },
911 { 0x25, "SCO Rejected via LMP",
912 sco_rejected_via_lmp_evt, 7, true },
913 { 0x26, "PTT Switch Notification",
914 ptt_switch_notification_evt, 3, true },
915 { 0x29, "System Exception",
916 system_exception_evt, 133, true },
917 { 0x2c, "FW Trace String" },
918 { 0x2e, "FW Trace Binary" },
922 const struct vendor_evt *intel_vendor_evt(uint8_t evt)
926 for (i = 0; vendor_evt_table[i].str; i++) {
927 if (vendor_evt_table[i].evt == evt)
928 return &vendor_evt_table[i];