monitor: Add Intel read supported features command
[platform/upstream/bluez.git] / monitor / intel.c
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3  *
4  *  BlueZ - Bluetooth protocol stack for Linux
5  *
6  *  Copyright (C) 2011-2014  Intel Corporation
7  *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
8  *
9  *
10  */
11
12 #ifdef HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15
16 #include <stdio.h>
17 #include <inttypes.h>
18
19 #include "lib/bluetooth.h"
20 #include "lib/hci.h"
21
22 #include "src/shared/util.h"
23 #include "display.h"
24 #include "packet.h"
25 #include "lmp.h"
26 #include "ll.h"
27 #include "vendor.h"
28 #include "intel.h"
29
30 #define COLOR_UNKNOWN_EVENT_MASK        COLOR_WHITE_BG
31 #define COLOR_UNKNOWN_SCAN_STATUS       COLOR_WHITE_BG
32
33 static void print_status(uint8_t status)
34 {
35         packet_print_error("Status", status);
36 }
37
38 static void print_module(uint8_t module)
39 {
40         const char *str;
41
42         switch (module) {
43         case 0x01:
44                 str = "BC";
45                 break;
46         case 0x02:
47                 str = "HCI";
48                 break;
49         case 0x03:
50                 str = "LLC";
51                 break;
52         case 0x04:
53                 str = "OS";
54                 break;
55         case 0x05:
56                 str = "LM";
57                 break;
58         case 0x06:
59                 str = "SC";
60                 break;
61         case 0x07:
62                 str = "SP";
63                 break;
64         case 0x08:
65                 str = "OSAL";
66                 break;
67         case 0x09:
68                 str = "LC";
69                 break;
70         case 0x0a:
71                 str = "APP";
72                 break;
73         case 0x0b:
74                 str = "TLD";
75                 break;
76         case 0xf0:
77                 str = "Debug";
78                 break;
79         default:
80                 str = "Reserved";
81                 break;
82         }
83
84         print_field("Module: %s (0x%2.2x)", str, module);
85 }
86
87 static void null_cmd(const void *data, uint8_t size)
88 {
89 }
90
91 static void status_rsp(const void *data, uint8_t size)
92 {
93         uint8_t status = get_u8(data);
94
95         print_status(status);
96 }
97
98 static void reset_cmd(const void *data, uint8_t size)
99 {
100         uint8_t reset_type = get_u8(data);
101         uint8_t patch_enable = get_u8(data + 1);
102         uint8_t ddc_reload = get_u8(data + 2);
103         uint8_t boot_option = get_u8(data + 3);
104         uint32_t boot_addr = get_le32(data + 4);
105         const char *str;
106
107         switch (reset_type) {
108         case 0x00:
109                 str = "Soft software reset";
110                 break;
111         case 0x01:
112                 str = "Hard software reset";
113                 break;
114         default:
115                 str = "Reserved";
116                 break;
117         }
118
119         print_field("Reset type: %s (0x%2.2x)", str, reset_type);
120
121         switch (patch_enable) {
122         case 0x00:
123                 str = "Do not enable";
124                 break;
125         case 0x01:
126                 str = "Enable";
127                 break;
128         default:
129                 str = "Reserved";
130                 break;
131         }
132
133         print_field("Patch vectors: %s (0x%2.2x)", str, patch_enable);
134
135         switch (ddc_reload) {
136         case 0x00:
137                 str = "Do not reload";
138                 break;
139         case 0x01:
140                 str = "Reload from OTP";
141                 break;
142         default:
143                 str = "Reserved";
144                 break;
145         }
146
147         print_field("DDC parameters: %s (0x%2.2x)", str, ddc_reload);
148
149         switch (boot_option) {
150         case 0x00:
151                 str = "Current image";
152                 break;
153         case 0x01:
154                 str = "Specified address";
155                 break;
156         default:
157                 str = "Reserved";
158                 break;
159         }
160
161         print_field("Boot option: %s (0x%2.2x)", str, boot_option);
162         print_field("Boot address: 0x%8.8x", boot_addr);
163 }
164
165 static void read_version_rsp(const void *data, uint8_t size)
166 {
167         uint8_t status = get_u8(data);
168         uint8_t hw_platform = get_u8(data + 1);
169         uint8_t hw_variant = get_u8(data + 2);
170         uint8_t hw_revision = get_u8(data + 3);
171         uint8_t fw_variant = get_u8(data + 4);
172         uint8_t fw_revision = get_u8(data + 5);
173         uint8_t fw_build_nn = get_u8(data + 6);
174         uint8_t fw_build_cw = get_u8(data + 7);
175         uint8_t fw_build_yy = get_u8(data + 8);
176         uint8_t fw_patch = get_u8(data + 9);
177
178         print_status(status);
179         print_field("Hardware platform: 0x%2.2x", hw_platform);
180         print_field("Hardware variant: 0x%2.2x", hw_variant);
181         print_field("Hardware revision: %u.%u", hw_revision >> 4,
182                                                 hw_revision & 0x0f);
183         print_field("Firmware variant: 0x%2.2x", fw_variant);
184         print_field("Firmware revision: %u.%u", fw_revision >> 4,
185                                                 fw_revision & 0x0f);
186
187         print_field("Firmware build: %u-%u.%u", fw_build_nn,
188                                         fw_build_cw, 2000 + fw_build_yy);
189         print_field("Firmware patch: %u", fw_patch);
190 }
191
192 static void set_uart_baudrate_cmd(const void *data, uint8_t size)
193 {
194         uint8_t baudrate = get_u8(data);
195         const char *str;
196
197         switch (baudrate) {
198         case 0x00:
199                 str = "9600 Baud";
200                 break;
201         case 0x01:
202                 str = "19200 Baud";
203                 break;
204         case 0x02:
205                 str = "38400 Baud";
206                 break;
207         case 0x03:
208                 str = "57600 Baud";
209                 break;
210         case 0x04:
211                 str = "115200 Baud";
212                 break;
213         case 0x05:
214                 str = "230400 Baud";
215                 break;
216         case 0x06:
217                 str = "460800 Baud";
218                 break;
219         case 0x07:
220                 str = "921600 Baud";
221                 break;
222         case 0x08:
223                 str = "1843200 Baud";
224                 break;
225         case 0x09:
226                 str = "3250000 baud";
227                 break;
228         case 0x0a:
229                 str = "2000000 baud";
230                 break;
231         case 0x0b:
232                 str = "3000000 baud";
233                 break;
234         case 0x0c:
235                 str = "3714286 baud";
236                 break;
237         case 0x0d:
238                 str = "4333333 baud";
239                 break;
240         case 0x0e:
241                 str = "6500000 baud";
242                 break;
243         default:
244                 str = "Reserved";
245                 break;
246         }
247
248         print_field("Baudrate: %s (0x%2.2x)", str, baudrate);
249 }
250
251 static void secure_send_cmd(const void *data, uint8_t size)
252 {
253         uint8_t type = get_u8(data);
254         const char *str;
255
256         switch (type) {
257         case 0x00:
258                 str = "Init";
259                 break;
260         case 0x01:
261                 str = "Data";
262                 break;
263         case 0x02:
264                 str = "Sign";
265                 break;
266         case 0x03:
267                 str = "PKey";
268                 break;
269         default:
270                 str = "Reserved";
271                 break;
272         }
273
274         print_field("Type: %s fragment (0x%2.2x)", str, type);
275
276         packet_hexdump(data + 1, size - 1);
277 }
278
279 static void manufacturer_mode_cmd(const void *data, uint8_t size)
280 {
281         uint8_t mode = get_u8(data);
282         uint8_t reset = get_u8(data + 1);
283         const char *str;
284
285         switch (mode) {
286         case 0x00:
287                 str = "Disabled";
288                 break;
289         case 0x01:
290                 str = "Enabled";
291                 break;
292         default:
293                 str = "Reserved";
294                 break;
295         }
296
297         print_field("Mode switch: %s (0x%2.2x)", str, mode);
298
299         switch (reset) {
300         case 0x00:
301                 str = "No reset";
302                 break;
303         case 0x01:
304                 str = "Reset and deactivate patches";
305                 break;
306         case 0x02:
307                 str = "Reset and activate patches";
308                 break;
309         default:
310                 str = "Reserved";
311                 break;
312         }
313
314         print_field("Reset behavior: %s (0x%2.2x)", str, reset);
315 }
316
317 static void write_bd_data_cmd(const void *data, uint8_t size)
318 {
319         uint8_t features[8];
320
321         packet_print_addr("Address", data, false);
322         packet_hexdump(data + 6, 6);
323
324         memcpy(features, data + 12, 8);
325         packet_print_features_lmp(features, 0);
326
327         memcpy(features, data + 20, 1);
328         memset(features + 1, 0, 7);
329         packet_print_features_ll(features);
330
331         packet_hexdump(data + 21, size - 21);
332 }
333
334 static void read_bd_data_rsp(const void *data, uint8_t size)
335 {
336         uint8_t status = get_u8(data);
337
338         print_status(status);
339         packet_print_addr("Address", data + 1, false);
340         packet_hexdump(data + 7, size - 7);
341 }
342
343 static void write_bd_address_cmd(const void *data, uint8_t size)
344 {
345         packet_print_addr("Address", data, false);
346 }
347
348 static void act_deact_traces_cmd(const void *data, uint8_t size)
349 {
350         uint8_t tx = get_u8(data);
351         uint8_t tx_arq = get_u8(data + 1);
352         uint8_t rx = get_u8(data + 2);
353
354         print_field("Transmit traces: 0x%2.2x", tx);
355         print_field("Transmit ARQ: 0x%2.2x", tx_arq);
356         print_field("Receive traces: 0x%2.2x", rx);
357 }
358
359 static void stimulate_exception_cmd(const void *data, uint8_t size)
360 {
361         uint8_t type = get_u8(data);
362         const char *str;
363
364         switch (type) {
365         case 0x00:
366                 str = "Fatal Exception";
367                 break;
368         case 0x01:
369                 str = "Debug Exception";
370                 break;
371         default:
372                 str = "Reserved";
373                 break;
374         }
375
376         print_field("Type: %s (0x%2.2x)", str, type);
377 }
378
379 static const struct {
380         uint8_t bit;
381         const char *str;
382 } events_table[] = {
383         {  0, "Bootup"                  },
384         {  1, "SCO Rejected via LMP"    },
385         {  2, "PTT Switch Notification" },
386         {  7, "Scan Status"             },
387         {  9, "Debug Exception"         },
388         { 10, "Fatal Exception"         },
389         { 11, "System Exception"        },
390         { 13, "LE Link Established"     },
391         { 14, "FW Trace String"         },
392         { }
393 };
394
395 static void set_event_mask_cmd(const void *data, uint8_t size)
396 {
397         const uint8_t *events_array = data;
398         uint64_t mask, events = 0;
399         int i;
400
401         for (i = 0; i < 8; i++)
402                 events |= ((uint64_t) events_array[i]) << (i * 8);
403
404         print_field("Mask: 0x%16.16" PRIx64, events);
405
406         mask = events;
407
408         for (i = 0; events_table[i].str; i++) {
409                 if (events & (((uint64_t) 1) << events_table[i].bit)) {
410                         print_field("  %s", events_table[i].str);
411                         mask &= ~(((uint64_t) 1) << events_table[i].bit);
412                 }
413         }
414
415         if (mask)
416                 print_text(COLOR_UNKNOWN_EVENT_MASK, "  Unknown mask "
417                                                 "(0x%16.16" PRIx64 ")", mask);
418 }
419
420 static void ddc_config_write_cmd(const void *data, uint8_t size)
421 {
422         while (size > 0) {
423                 uint8_t param_len = get_u8(data);
424                 uint16_t param_id = get_le16(data + 1);
425
426                 print_field("Identifier: 0x%4.4x", param_id);
427                 packet_hexdump(data + 3, param_len - 2);
428
429                 data += param_len + 1;
430                 size -= param_len + 1;
431         }
432 }
433
434 static void ddc_config_write_rsp(const void *data, uint8_t size)
435 {
436         uint8_t status = get_u8(data);
437         uint16_t param_id = get_le16(data + 1);
438
439         print_status(status);
440         print_field("Identifier: 0x%4.4x", param_id);
441 }
442
443 static void memory_write_cmd(const void *data, uint8_t size)
444 {
445         uint32_t addr = get_le32(data);
446         uint8_t mode = get_u8(data + 4);
447         uint8_t length = get_u8(data + 5);
448         const char *str;
449
450         print_field("Address: 0x%8.8x", addr);
451
452         switch (mode) {
453         case 0x00:
454                 str = "Byte access";
455                 break;
456         case 0x01:
457                 str = "Half word access";
458                 break;
459         case 0x02:
460                 str = "Word access";
461                 break;
462         default:
463                 str = "Reserved";
464                 break;
465         }
466
467         print_field("Mode: %s (0x%2.2x)", str, mode);
468         print_field("Length: %u", length);
469
470         packet_hexdump(data + 6, size - 6);
471 }
472
473 static void read_supported_features_cmd(const void *data, uint8_t size)
474 {
475         uint8_t page = get_u8(data);
476
477         print_field("Page: 0x%2.2x", page);
478 }
479
480 static void read_supported_features_rsp(const void *data, uint8_t size)
481 {
482         uint8_t status = get_u8(data);
483         uint8_t page = get_u8(data + 1);
484         uint8_t max_pages = get_u8(data + 2);
485
486         print_status(status);
487         print_field("Page: 0x%2.2x", page);
488         print_field("Max Pages: 0x%2.2x", max_pages);
489         print_field("Supported Features:");
490         packet_hexdump(data + 3, size - 3);
491 }
492
493 static const struct vendor_ocf vendor_ocf_table[] = {
494         { 0x001, "Reset",
495                         reset_cmd, 8, true,
496                         status_rsp, 1, true },
497         { 0x002, "No Operation" },
498         { 0x005, "Read Version",
499                         null_cmd, 0, true,
500                         read_version_rsp, 10, true },
501         { 0x006, "Set UART Baudrate",
502                         set_uart_baudrate_cmd, 1, true,
503                         status_rsp, 1, true },
504         { 0x007, "Enable LPM" },
505         { 0x008, "PCM Write Configuration" },
506         { 0x009, "Secure Send",
507                         secure_send_cmd, 1, false,
508                         status_rsp, 1, true },
509         { 0x00d, "Read Secure Boot Params",
510                         null_cmd, 0, true },
511         { 0x00e, "Write Secure Boot Params" },
512         { 0x00f, "Unlock" },
513         { 0x010, "Change UART Baudrate" },
514         { 0x011, "Manufacturer Mode",
515                         manufacturer_mode_cmd, 2, true,
516                         status_rsp, 1, true },
517         { 0x012, "Read Link RSSI" },
518         { 0x022, "Get Exception Info" },
519         { 0x024, "Clear Exception Info" },
520         { 0x02f, "Write BD Data",
521                         write_bd_data_cmd, 6, false },
522         { 0x030, "Read BD Data",
523                         null_cmd, 0, true,
524                         read_bd_data_rsp, 7, false },
525         { 0x031, "Write BD Address",
526                         write_bd_address_cmd, 6, true,
527                         status_rsp, 1, true },
528         { 0x032, "Flow Specification" },
529         { 0x034, "Read Secure ID" },
530         { 0x038, "Set Synchronous USB Interface Type" },
531         { 0x039, "Config Synchronous Interface" },
532         { 0x03f, "SW RF Kill",
533                         null_cmd, 0, true,
534                         status_rsp, 1, true },
535         { 0x043, "Activate Deactivate Traces",
536                         act_deact_traces_cmd, 3, true },
537         { 0x04d, "Stimulate Exception",
538                         stimulate_exception_cmd, 1, true,
539                         status_rsp, 1, true },
540         { 0x050, "Read HW Version" },
541         { 0x052, "Set Event Mask",
542                         set_event_mask_cmd, 8, true,
543                         status_rsp, 1, true },
544         { 0x053, "Config_Link_Controller" },
545         { 0x089, "DDC Write" },
546         { 0x08a, "DDC Read" },
547         { 0x08b, "DDC Config Write",
548                         ddc_config_write_cmd, 3, false,
549                         ddc_config_write_rsp, 3, true },
550         { 0x08c, "DDC Config Read" },
551         { 0x08d, "Memory Read" },
552         { 0x08e, "Memory Write",
553                         memory_write_cmd, 6, false,
554                         status_rsp, 1, true },
555         { 0x0a6, "Read Supported Features",
556                         read_supported_features_cmd, 1, true,
557                         read_supported_features_rsp, 19, true },
558
559         { }
560 };
561
562 const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
563 {
564         int i;
565
566         for (i = 0; vendor_ocf_table[i].str; i++) {
567                 if (vendor_ocf_table[i].ocf == ocf)
568                         return &vendor_ocf_table[i];
569         }
570
571         return NULL;
572 }
573
574 static void startup_evt(const void *data, uint8_t size)
575 {
576 }
577
578 static void fatal_exception_evt(const void *data, uint8_t size)
579 {
580         uint16_t line = get_le16(data);
581         uint8_t module = get_u8(data + 2);
582         uint8_t reason = get_u8(data + 3);
583
584         print_field("Line: %u", line);
585         print_module(module);
586         print_field("Reason: 0x%2.2x", reason);
587 }
588
589 static void bootup_evt(const void *data, uint8_t size)
590 {
591         uint8_t zero = get_u8(data);
592         uint8_t num_packets = get_u8(data + 1);
593         uint8_t source = get_u8(data + 2);
594         uint8_t reset_type = get_u8(data + 3);
595         uint8_t reset_reason = get_u8(data + 4);
596         uint8_t ddc_status = get_u8(data + 5);
597         const char *str;
598
599         print_field("Zero: 0x%2.2x", zero);
600         print_field("Number of packets: %d", num_packets);
601
602         switch (source) {
603         case 0x00:
604                 str = "Bootloader";
605                 break;
606         case 0x01:
607                 str = "Operational firmware";
608                 break;
609         case 0x02:
610                 str = "Self test firmware";
611                 break;
612         default:
613                 str = "Reserved";
614                 break;
615         }
616
617         print_field("Source: %s (0x%2.2x)", str, source);
618
619         switch (reset_type) {
620         case 0x00:
621                 str = "Hardware reset";
622                 break;
623         case 0x01:
624                 str = "Soft watchdog reset";
625                 break;
626         case 0x02:
627                 str = "Soft software reset";
628                 break;
629         case 0x03:
630                 str = "Hard watchdog reset";
631                 break;
632         case 0x04:
633                 str = "Hard software reset";
634                 break;
635         default:
636                 str = "Reserved";
637                 break;
638         }
639
640         print_field("Reset type: %s (0x%2.2x)", str, reset_type);
641
642         switch (reset_reason) {
643         case 0x00:
644                 str = "Power on";
645                 break;
646         case 0x01:
647                 str = "Reset command";
648                 break;
649         case 0x02:
650                 str = "Intel reset command";
651                 break;
652         case 0x03:
653                 str = "Watchdog";
654                 break;
655         case 0x04:
656                 str = "Fatal exception";
657                 break;
658         case 0x05:
659                 str = "System exception";
660                 break;
661         case 0xff:
662                 str = "Unknown";
663                 break;
664         default:
665                 str = "Reserved";
666                 break;
667         }
668
669         print_field("Reset reason: %s (0x%2.2x)", str, reset_reason);
670
671         switch (ddc_status) {
672         case 0x00:
673                 str = "Firmware default";
674                 break;
675         case 0x01:
676                 str = "Firmware default plus OTP";
677                 break;
678         case 0x02:
679                 str = "Persistent RAM";
680                 break;
681         case 0x03:
682                 str = "Not used";
683                 break;
684         default:
685                 str = "Reserved";
686                 break;
687         }
688
689         print_field("DDC status: %s (0x%2.2x)", str, ddc_status);
690 }
691
692 static void default_bd_data_evt(const void *data, uint8_t size)
693 {
694         uint8_t mem_status = get_u8(data);
695         const char *str;
696
697         switch (mem_status) {
698         case 0x02:
699                 str = "Invalid manufacturing data";
700                 break;
701         default:
702                 str = "Reserved";
703                 break;
704         }
705
706         print_field("Memory status: %s (0x%2.2x)", str, mem_status);
707 }
708
709 static void secure_send_commands_result_evt(const void *data, uint8_t size)
710 {
711         uint8_t result = get_u8(data);
712         uint16_t opcode = get_le16(data + 1);
713         uint16_t ogf = cmd_opcode_ogf(opcode);
714         uint16_t ocf = cmd_opcode_ocf(opcode);
715         uint8_t status = get_u8(data + 3);
716         const char *str;
717
718         switch (result) {
719         case 0x00:
720                 str = "Success";
721                 break;
722         case 0x01:
723                 str = "General failure";
724                 break;
725         case 0x02:
726                 str = "Hardware failure";
727                 break;
728         case 0x03:
729                 str = "Signature verification failed";
730                 break;
731         case 0x04:
732                 str = "Parsing error of command buffer";
733                 break;
734         case 0x05:
735                 str = "Command execution failure";
736                 break;
737         case 0x06:
738                 str = "Command parameters error";
739                 break;
740         case 0x07:
741                 str = "Command missing";
742                 break;
743         default:
744                 str = "Reserved";
745                 break;
746         }
747
748         print_field("Result: %s (0x%2.2x)", str, result);
749         print_field("Opcode: 0x%4.4x (0x%2.2x|0x%4.4x)", opcode, ogf, ocf);
750         print_status(status);
751 }
752
753 static void debug_exception_evt(const void *data, uint8_t size)
754 {
755         uint16_t line = get_le16(data);
756         uint8_t module = get_u8(data + 2);
757         uint8_t reason = get_u8(data + 3);
758
759         print_field("Line: %u", line);
760         print_module(module);
761         print_field("Reason: 0x%2.2x", reason);
762 }
763
764 static void le_link_established_evt(const void *data, uint8_t size)
765 {
766         uint16_t handle = get_le16(data);
767         uint32_t access_addr = get_le32(data + 10);
768
769         print_field("Handle: %u", handle);
770
771         packet_hexdump(data + 2, 8);
772
773         print_field("Access address: 0x%8.8x", access_addr);
774
775         packet_hexdump(data + 14, size - 14);
776 }
777
778 static void scan_status_evt(const void *data, uint8_t size)
779 {
780         uint8_t enable = get_u8(data);
781
782         print_field("Inquiry scan: %s",
783                                 (enable & 0x01) ? "Enabled" : "Disabled");
784         print_field("Page scan: %s",
785                                 (enable & 0x02) ? "Enabled" : "Disabled");
786
787         if (enable & 0xfc)
788                 print_text(COLOR_UNKNOWN_SCAN_STATUS,
789                                 "  Unknown status (0x%2.2x)", enable & 0xfc);
790
791 }
792
793 static void act_deact_traces_complete_evt(const void *data, uint8_t size)
794 {
795         uint8_t status = get_u8(data);
796
797         print_status(status);
798 }
799
800 static void lmp_pdu_trace_evt(const void *data, uint8_t size)
801 {
802         uint8_t type, len, id;
803         uint16_t handle, count;
804         uint32_t clock;
805         const char *str;
806
807         type = get_u8(data);
808         handle = get_le16(data + 1);
809
810         switch (type) {
811         case 0x00:
812                 str = "RX LMP";
813                 break;
814         case 0x01:
815                 str = "TX LMP";
816                 break;
817         case 0x02:
818                 str = "ACK LMP";
819                 break;
820         case 0x03:
821                 str = "RX LL";
822                 break;
823         case 0x04:
824                 str = "TX LL";
825                 break;
826         case 0x05:
827                 str = "ACK LL";
828                 break;
829         default:
830                 str = "Unknown";
831                 break;
832         }
833
834         print_field("Type: %s (0x%2.2x)", str, type);
835         print_field("Handle: %u", handle);
836
837         switch (type) {
838         case 0x00:
839                 len = size - 8;
840                 clock = get_le32(data + 4 + len);
841
842                 packet_hexdump(data + 3, 1);
843                 lmp_packet(data + 4, len, false);
844                 print_field("Clock: 0x%8.8x", clock);
845                 break;
846         case 0x01:
847                 len = size - 9;
848                 clock = get_le32(data + 4 + len);
849                 id = get_u8(data + 4 + len + 4);
850
851                 packet_hexdump(data + 3, 1);
852                 lmp_packet(data + 4, len, false);
853                 print_field("Clock: 0x%8.8x", clock);
854                 print_field("ID: 0x%2.2x", id);
855                 break;
856         case 0x02:
857                 clock = get_le32(data + 3);
858                 id = get_u8(data + 3 + 4);
859
860                 print_field("Clock: 0x%8.8x", clock);
861                 print_field("ID: 0x%2.2x", id);
862                 break;
863         case 0x03:
864                 len = size - 8;
865                 count = get_le16(data + 3);
866
867                 print_field("Count: 0x%4.4x", count);
868                 packet_hexdump(data + 3 + 2 + 1, 2);
869                 llcp_packet(data + 8, len, false);
870                 break;
871         case 0x04:
872                 len = size - 8;
873                 count = get_le16(data + 3);
874                 id = get_u8(data + 3 + 2);
875
876                 print_field("Count: 0x%4.4x", count);
877                 print_field("ID: 0x%2.2x", id);
878                 packet_hexdump(data + 3 + 2 + 1, 2);
879                 llcp_packet(data + 8, len, false);
880                 break;
881         case 0x05:
882                 count = get_le16(data + 3);
883                 id = get_u8(data + 3 + 2);
884
885                 print_field("Count: 0x%4.4x", count);
886                 print_field("ID: 0x%2.2x", id);
887                 break;
888         default:
889                 packet_hexdump(data + 3, size - 3);
890                 break;
891         }
892 }
893
894 static void write_bd_data_complete_evt(const void *data, uint8_t size)
895 {
896         uint8_t status = get_u8(data);
897
898         print_status(status);
899 }
900
901 static void sco_rejected_via_lmp_evt(const void *data, uint8_t size)
902 {
903         uint8_t reason = get_u8(data + 6);
904
905         packet_print_addr("Address", data, false);
906         packet_print_error("Reason", reason);
907 }
908
909 static void ptt_switch_notification_evt(const void *data, uint8_t size)
910 {
911         uint16_t handle = get_le16(data);
912         uint8_t table = get_u8(data + 2);
913         const char *str;
914
915         print_field("Handle: %u", handle);
916
917         switch (table) {
918         case 0x00:
919                 str = "Basic rate";
920                 break;
921         case 0x01:
922                 str = "Enhanced data rate";
923                 break;
924         default:
925                 str = "Reserved";
926                 break;
927         }
928
929         print_field("Packet type table: %s (0x%2.2x)", str, table);
930 }
931
932 static void system_exception_evt(const void *data, uint8_t size)
933 {
934         uint8_t type = get_u8(data);
935         const char *str;
936
937         switch (type) {
938         case 0x00:
939                 str = "No Exception";
940                 break;
941         case 0x01:
942                 str = "Undefined Instruction";
943                 break;
944         case 0x02:
945                 str = "Prefetch abort";
946                 break;
947         case 0x03:
948                 str = "Data abort";
949                 break;
950         default:
951                 str = "Reserved";
952                 break;
953         }
954
955         print_field("Type: %s (0x%2.2x)", str, type);
956
957         packet_hexdump(data + 1, size - 1);
958 }
959
960 static const struct vendor_evt vendor_evt_table[] = {
961         { 0x00, "Startup",
962                         startup_evt, 0, true },
963         { 0x01, "Fatal Exception",
964                         fatal_exception_evt, 4, true },
965         { 0x02, "Bootup",
966                         bootup_evt, 6, true },
967         { 0x05, "Default BD Data",
968                         default_bd_data_evt, 1, true },
969         { 0x06, "Secure Send Commands Result",
970                         secure_send_commands_result_evt, 4, true },
971         { 0x08, "Debug Exception",
972                         debug_exception_evt, 4, true },
973         { 0x0f, "LE Link Established",
974                         le_link_established_evt, 26, true },
975         { 0x11, "Scan Status",
976                         scan_status_evt, 1, true },
977         { 0x16, "Activate Deactivate Traces Complete",
978                         act_deact_traces_complete_evt, 1, true },
979         { 0x17, "LMP PDU Trace",
980                         lmp_pdu_trace_evt, 3, false },
981         { 0x19, "Write BD Data Complete",
982                         write_bd_data_complete_evt, 1, true },
983         { 0x25, "SCO Rejected via LMP",
984                         sco_rejected_via_lmp_evt, 7, true },
985         { 0x26, "PTT Switch Notification",
986                         ptt_switch_notification_evt, 3, true },
987         { 0x29, "System Exception",
988                         system_exception_evt, 133, true },
989         { 0x2c, "FW Trace String" },
990         { 0x2e, "FW Trace Binary" },
991         { }
992 };
993
994 const struct vendor_evt *intel_vendor_evt(uint8_t evt)
995 {
996         int i;
997
998         for (i = 0; vendor_evt_table[i].str; i++) {
999                 if (vendor_evt_table[i].evt == evt)
1000                         return &vendor_evt_table[i];
1001         }
1002
1003         return NULL;
1004 }