Home | History | Annotate | Download | only in parser
      1 /*
      2  *
      3  *  BlueZ - Bluetooth protocol stack for Linux
      4  *
      5  *  Copyright (C) 2000-2002  Maxim Krasnyansky <maxk (at) qualcomm.com>
      6  *  Copyright (C) 2003-2007  Marcel Holtmann <marcel (at) holtmann.org>
      7  *
      8  *
      9  *  This program is free software; you can redistribute it and/or modify
     10  *  it under the terms of the GNU General Public License as published by
     11  *  the Free Software Foundation; either version 2 of the License, or
     12  *  (at your option) any later version.
     13  *
     14  *  This program 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
     17  *  GNU General Public License for more details.
     18  *
     19  *  You should have received a copy of the GNU General Public License
     20  *  along with this program; if not, write to the Free Software
     21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     22  *
     23  */
     24 
     25 #ifdef HAVE_CONFIG_H
     26 #include <config.h>
     27 #endif
     28 
     29 #include <stdio.h>
     30 #include <errno.h>
     31 #include <ctype.h>
     32 #include <unistd.h>
     33 #include <stdlib.h>
     34 #include <string.h>
     35 
     36 #include <sys/types.h>
     37 #include <sys/socket.h>
     38 #include <netinet/in.h>
     39 
     40 #include <bluetooth/bluetooth.h>
     41 #include <bluetooth/hci.h>
     42 #include <bluetooth/hci_lib.h>
     43 
     44 #include "parser.h"
     45 
     46 static uint16_t manufacturer = DEFAULT_COMPID;
     47 
     48 static inline uint16_t get_manufacturer(void)
     49 {
     50 	return (manufacturer == DEFAULT_COMPID ? parser.defcompid : manufacturer);
     51 }
     52 
     53 #define EVENT_NUM 61
     54 static char *event_str[EVENT_NUM + 1] = {
     55 	"Unknown",
     56 	"Inquiry Complete",
     57 	"Inquiry Result",
     58 	"Connect Complete",
     59 	"Connect Request",
     60 	"Disconn Complete",
     61 	"Auth Complete",
     62 	"Remote Name Req Complete",
     63 	"Encrypt Change",
     64 	"Change Connection Link Key Complete",
     65 	"Master Link Key Complete",
     66 	"Read Remote Supported Features",
     67 	"Read Remote Ver Info Complete",
     68 	"QoS Setup Complete",
     69 	"Command Complete",
     70 	"Command Status",
     71 	"Hardware Error",
     72 	"Flush Occurred",
     73 	"Role Change",
     74 	"Number of Completed Packets",
     75 	"Mode Change",
     76 	"Return Link Keys",
     77 	"PIN Code Request",
     78 	"Link Key Request",
     79 	"Link Key Notification",
     80 	"Loopback Command",
     81 	"Data Buffer Overflow",
     82 	"Max Slots Change",
     83 	"Read Clock Offset Complete",
     84 	"Connection Packet Type Changed",
     85 	"QoS Violation",
     86 	"Page Scan Mode Change",
     87 	"Page Scan Repetition Mode Change",
     88 	"Flow Specification Complete",
     89 	"Inquiry Result with RSSI",
     90 	"Read Remote Extended Features",
     91 	"Unknown",
     92 	"Unknown",
     93 	"Unknown",
     94 	"Unknown",
     95 	"Unknown",
     96 	"Unknown",
     97 	"Unknown",
     98 	"Unknown",
     99 	"Synchronous Connect Complete",
    100 	"Synchronous Connect Changed",
    101 	"Sniff Subrate",
    102 	"Extended Inquiry Result",
    103 	"Encryption Key Refresh Complete",
    104 	"IO Capability Request",
    105 	"IO Capability Response",
    106 	"User Confirmation Request",
    107 	"User Passkey Request",
    108 	"Remote OOB Data Request",
    109 	"Simple Pairing Complete",
    110 	"Unknown",
    111 	"Link Supervision Timeout Change",
    112 	"Enhanced Flush Complete",
    113 	"Unknown",
    114 	"User Passkey Notification",
    115 	"Keypress Notification",
    116 	"Remote Host Supported Features Notification",
    117 };
    118 
    119 #define CMD_LINKCTL_NUM 52
    120 static char *cmd_linkctl_str[CMD_LINKCTL_NUM + 1] = {
    121 	"Unknown",
    122 	"Inquiry",
    123 	"Inquiry Cancel",
    124 	"Periodic Inquiry Mode",
    125 	"Exit Periodic Inquiry Mode",
    126 	"Create Connection",
    127 	"Disconnect",
    128 	"Add SCO Connection",
    129 	"Create Connection Cancel",
    130 	"Accept Connection Request",
    131 	"Reject Connection Request",
    132 	"Link Key Request Reply",
    133 	"Link Key Request Negative Reply",
    134 	"PIN Code Request Reply",
    135 	"PIN Code Request Negative Reply",
    136 	"Change Connection Packet Type",
    137 	"Unknown",
    138 	"Authentication Requested",
    139 	"Unknown",
    140 	"Set Connection Encryption",
    141 	"Unknown",
    142 	"Change Connection Link Key",
    143 	"Unknown",
    144 	"Master Link Key",
    145 	"Unknown",
    146 	"Remote Name Request",
    147 	"Remote Name Request Cancel",
    148 	"Read Remote Supported Features",
    149 	"Read Remote Extended Features",
    150 	"Read Remote Version Information",
    151 	"Unknown",
    152 	"Read Clock Offset",
    153 	"Read LMP Handle",
    154 	"Unknown",
    155 	"Unknown",
    156 	"Unknown",
    157 	"Unknown",
    158 	"Unknown",
    159 	"Unknown",
    160 	"Unknown",
    161 	"Setup Synchronous Connection",
    162 	"Accept Synchronous Connection",
    163 	"Reject Synchronous Connection",
    164 	"IO Capability Request Reply",
    165 	"User Confirmation Request Reply",
    166 	"User Confirmation Request Negative Reply",
    167 	"User Passkey Request Reply",
    168 	"User Passkey Request Negative Reply",
    169 	"Remote OOB Data Request Reply",
    170 	"Unknown",
    171 	"Unknown",
    172 	"Remote OOB Data Request Negative Reply",
    173 	"IO Capability Request Negative Reply",
    174 };
    175 
    176 #define CMD_LINKPOL_NUM 17
    177 static char *cmd_linkpol_str[CMD_LINKPOL_NUM + 1] = {
    178 	"Unknown",
    179 	"Hold Mode",
    180 	"Unknown",
    181 	"Sniff Mode",
    182 	"Exit Sniff Mode",
    183 	"Park State",
    184 	"Exit Park State",
    185 	"QoS Setup",
    186 	"Unknown",
    187 	"Role Discovery",
    188 	"Unknown",
    189 	"Switch Role",
    190 	"Read Link Policy Settings",
    191 	"Write Link Policy Settings",
    192 	"Read Default Link Policy Settings",
    193 	"Write Default Link Policy Settings",
    194 	"Flow Specification",
    195 	"Sniff Subrating",
    196 };
    197 
    198 #define CMD_HOSTCTL_NUM 95
    199 static char *cmd_hostctl_str[CMD_HOSTCTL_NUM + 1] = {
    200 	"Unknown",
    201 	"Set Event Mask",
    202 	"Unknown",
    203 	"Reset",
    204 	"Unknown",
    205 	"Set Event Filter",
    206 	"Unknown",
    207 	"Unknown",
    208 	"Flush",
    209 	"Read PIN Type ",
    210 	"Write PIN Type",
    211 	"Create New Unit Key",
    212 	"Unknown",
    213 	"Read Stored Link Key",
    214 	"Unknown",
    215 	"Unknown",
    216 	"Unknown",
    217 	"Write Stored Link Key",
    218 	"Delete Stored Link Key",
    219 	"Write Local Name",
    220 	"Read Local Name",
    221 	"Read Connection Accept Timeout",
    222 	"Write Connection Accept Timeout",
    223 	"Read Page Timeout",
    224 	"Write Page Timeout",
    225 	"Read Scan Enable",
    226 	"Write Scan Enable",
    227 	"Read Page Scan Activity",
    228 	"Write Page Scan Activity",
    229 	"Read Inquiry Scan Activity",
    230 	"Write Inquiry Scan Activity",
    231 	"Read Authentication Enable",
    232 	"Write Authentication Enable",
    233 	"Read Encryption Mode",
    234 	"Write Encryption Mode",
    235 	"Read Class of Device",
    236 	"Write Class of Device",
    237 	"Read Voice Setting",
    238 	"Write Voice Setting",
    239 	"Read Automatic Flush Timeout",
    240 	"Write Automatic Flush Timeout",
    241 	"Read Num Broadcast Retransmissions",
    242 	"Write Num Broadcast Retransmissions",
    243 	"Read Hold Mode Activity ",
    244 	"Write Hold Mode Activity",
    245 	"Read Transmit Power Level",
    246 	"Read Synchronous Flow Control Enable",
    247 	"Write Synchronous Flow Control Enable",
    248 	"Unknown",
    249 	"Set Host Controller To Host Flow Control",
    250 	"Unknown",
    251 	"Host Buffer Size",
    252 	"Unknown",
    253 	"Host Number of Completed Packets",
    254 	"Read Link Supervision Timeout",
    255 	"Write Link Supervision Timeout",
    256 	"Read Number of Supported IAC",
    257 	"Read Current IAC LAP",
    258 	"Write Current IAC LAP",
    259 	"Read Page Scan Period Mode",
    260 	"Write Page Scan Period Mode",
    261 	"Read Page Scan Mode",
    262 	"Write Page Scan Mode",
    263 	"Set AFH Host Channel Classification",
    264 	"Unknown",
    265 	"Unknown",
    266 	"Read Inquiry Scan Type",
    267 	"Write Inquiry Scan Type",
    268 	"Read Inquiry Mode",
    269 	"Write Inquiry Mode",
    270 	"Read Page Scan Type",
    271 	"Write Page Scan Type",
    272 	"Read AFH Channel Assessment Mode",
    273 	"Write AFH Channel Assessment Mode",
    274 	"Unknown",
    275 	"Unknown",
    276 	"Unknown",
    277 	"Unknown",
    278 	"Unknown",
    279 	"Unknown",
    280 	"Unknown",
    281 	"Read Extended Inquiry Response",
    282 	"Write Extended Inquiry Response",
    283 	"Refresh Encryption Key",
    284 	"Unknown",
    285 	"Read Simple Pairing Mode",
    286 	"Write Simple Pairing Mode",
    287 	"Read Local OOB Data",
    288 	"Read Inquiry Response Transmit Power Level",
    289 	"Write Inquiry Response Transmit Power Level",
    290 	"Read Default Erroneous Data Reporting",
    291 	"Write Default Erroneous Data Reporting",
    292 	"Unknown",
    293 	"Unknown",
    294 	"Unknown",
    295 	"Enhanced Flush"
    296 	"Unknown",
    297 };
    298 
    299 #define CMD_INFO_NUM 9
    300 static char *cmd_info_str[CMD_INFO_NUM + 1] = {
    301 	"Unknown",
    302 	"Read Local Version Information",
    303 	"Read Local Supported Commands",
    304 	"Read Local Supported Features",
    305 	"Read Local Extended Features",
    306 	"Read Buffer Size",
    307 	"Unknown",
    308 	"Read Country Code",
    309 	"Unknown",
    310 	"Read BD ADDR",
    311 };
    312 
    313 #define CMD_STATUS_NUM 7
    314 static char *cmd_status_str[CMD_STATUS_NUM + 1] = {
    315 	"Unknown",
    316 	"Read Failed Contact Counter",
    317 	"Reset Failed Contact Counter",
    318 	"Read Link Quality",
    319 	"Unknown",
    320 	"Read RSSI",
    321 	"Read AFH Channel Map",
    322 	"Read Clock",
    323 };
    324 
    325 #define CMD_TESTING_NUM 4
    326 static char *cmd_testing_str[CMD_TESTING_NUM + 1] = {
    327 	"Unknown",
    328 	"Read Loopback Mode",
    329 	"Write Loopback Mode",
    330 	"Enable Device Under Test mode",
    331 	"Unknown",
    332 };
    333 
    334 #define ERROR_CODE_NUM 56
    335 static char *error_code_str[ERROR_CODE_NUM + 1] = {
    336 	"Success",
    337 	"Unknown HCI Command",
    338 	"Unknown Connection Identifier",
    339 	"Hardware Failure",
    340 	"Page Timeout",
    341 	"Authentication Failure",
    342 	"PIN or Key Missing",
    343 	"Memory Capacity Exceeded",
    344 	"Connection Timeout",
    345 	"Connection Limit Exceeded",
    346 	"Synchronous Connection to a Device Exceeded",
    347 	"ACL Connection Already Exists",
    348 	"Command Disallowed",
    349 	"Connection Rejected due to Limited Resources",
    350 	"Connection Rejected due to Security Reasons",
    351 	"Connection Rejected due to Unacceptable BD_ADDR",
    352 	"Connection Accept Timeout Exceeded",
    353 	"Unsupported Feature or Parameter Value",
    354 	"Invalid HCI Command Parameters",
    355 	"Remote User Terminated Connection",
    356 	"Remote Device Terminated Connection due to Low Resources",
    357 	"Remote Device Terminated Connection due to Power Off",
    358 	"Connection Terminated by Local Host",
    359 	"Repeated Attempts",
    360 	"Pairing Not Allowed",
    361 	"Unknown LMP PDU",
    362 	"Unsupported Remote Feature / Unsupported LMP Feature",
    363 	"SCO Offset Rejected",
    364 	"SCO Interval Rejected",
    365 	"SCO Air Mode Rejected",
    366 	"Invalid LMP Parameters",
    367 	"Unspecified Error",
    368 	"Unsupported LMP Parameter Value",
    369 	"Role Change Not Allowed",
    370 	"LMP Response Timeout",
    371 	"LMP Error Transaction Collision",
    372 	"LMP PDU Not Allowed",
    373 	"Encryption Mode Not Acceptable",
    374 	"Link Key Can Not be Changed",
    375 	"Requested QoS Not Supported",
    376 	"Instant Passed",
    377 	"Pairing with Unit Key Not Supported",
    378 	"Different Transaction Collision",
    379 	"Reserved",
    380 	"QoS Unacceptable Parameter",
    381 	"QoS Rejected",
    382 	"Channel Classification Not Supported",
    383 	"Insufficient Security",
    384 	"Parameter out of Mandatory Range",
    385 	"Reserved",
    386 	"Role Switch Pending",
    387 	"Reserved",
    388 	"Reserved Slot Violation",
    389 	"Role Switch Failed",
    390 	"Extended Inquiry Response Too Large",
    391 	"Simple Pairing Not Supported by Host",
    392 	"Host Busy - Pairing",
    393 };
    394 
    395 static char *status2str(uint8_t status)
    396 {
    397 	char *str;
    398 
    399 	if (status <= ERROR_CODE_NUM)
    400 		str = error_code_str[status];
    401 	else
    402 		str = "Unknown";
    403 
    404 	return str;
    405 }
    406 
    407 static char *opcode2str(uint16_t opcode)
    408 {
    409 	uint16_t ogf = cmd_opcode_ogf(opcode);
    410 	uint16_t ocf = cmd_opcode_ocf(opcode);
    411 	char *cmd;
    412 
    413 	switch (ogf) {
    414 	case OGF_INFO_PARAM:
    415 		if (ocf <= CMD_INFO_NUM)
    416 			cmd = cmd_info_str[ocf];
    417 		else
    418 			cmd = "Unknown";
    419 		break;
    420 
    421 	case OGF_HOST_CTL:
    422 		if (ocf <= CMD_HOSTCTL_NUM)
    423 			cmd = cmd_hostctl_str[ocf];
    424 		else
    425 			cmd = "Unknown";
    426 		break;
    427 
    428 	case OGF_LINK_CTL:
    429 		if (ocf <= CMD_LINKCTL_NUM)
    430 			cmd = cmd_linkctl_str[ocf];
    431 		else
    432 			cmd = "Unknown";
    433 		break;
    434 
    435 	case OGF_LINK_POLICY:
    436 		if (ocf <= CMD_LINKPOL_NUM)
    437 			cmd = cmd_linkpol_str[ocf];
    438 		else
    439 			cmd = "Unknown";
    440 		break;
    441 
    442 	case OGF_STATUS_PARAM:
    443 		if (ocf <= CMD_STATUS_NUM)
    444 			cmd = cmd_status_str[ocf];
    445 		else
    446 			cmd = "Unknown";
    447 		break;
    448 
    449 	case OGF_TESTING_CMD:
    450 		if (ocf <= CMD_TESTING_NUM)
    451 			cmd = cmd_testing_str[ocf];
    452 		else
    453 			cmd = "Unknown";
    454 		break;
    455 
    456 	case OGF_VENDOR_CMD:
    457 		cmd = "Vendor";
    458 		break;
    459 
    460 	default:
    461 		cmd = "Unknown";
    462 		break;
    463 	}
    464 
    465 	return cmd;
    466 }
    467 
    468 static char *linktype2str(uint8_t type)
    469 {
    470 	switch (type) {
    471 	case 0x00:
    472 		return "SCO";
    473 	case 0x01:
    474 		return "ACL";
    475 	case 0x02:
    476 		return "eSCO";
    477 	default:
    478 		return "Unknown";
    479 	}
    480 }
    481 
    482 static char *role2str(uint8_t role)
    483 {
    484 	switch (role) {
    485 	case 0x00:
    486 		return "Master";
    487 	case 0x01:
    488 		return "Slave";
    489 	default:
    490 		return "Unknown";
    491 	}
    492 }
    493 
    494 static char *mode2str(uint8_t mode)
    495 {
    496 	switch (mode) {
    497 	case 0x00:
    498 		return "Active";
    499 	case 0x01:
    500 		return "Hold";
    501 	case 0x02:
    502 		return "Sniff";
    503 	case 0x03:
    504 		return "Park";
    505 	default:
    506 		return "Unknown";
    507 	}
    508 }
    509 
    510 static char *airmode2str(uint8_t mode)
    511 {
    512 	switch (mode) {
    513 	case 0x00:
    514 		return "u-law log";
    515 	case 0x01:
    516 		return "A-law log";
    517 	case 0x02:
    518 		return "CVSD";
    519 	case 0x04:
    520 		return "Transparent data";
    521 	default:
    522 		return "Reserved";
    523 	}
    524 }
    525 
    526 static char *keytype2str(uint8_t type)
    527 {
    528 	switch (type) {
    529 	case 0x00:
    530 		return "Combination Key";
    531 	case 0x01:
    532 		return "Local Unit Key";
    533 	case 0x02:
    534 		return "Remote Unit Key";
    535 	case 0x03:
    536 		return "Debug Combination Key";
    537 	case 0x04:
    538 		return "Unauthenticated Combination Key";
    539 	case 0x05:
    540 		return "Authenticated Combination Key";
    541 	case 0x06:
    542 		return "Changed Combination Key";
    543 	default:
    544 		return "Reserved";
    545 	}
    546 }
    547 
    548 static char *capability2str(uint8_t capability)
    549 {
    550 	switch (capability) {
    551 	case 0x00:
    552 		return "DisplayOnly";
    553 	case 0x01:
    554 		return "DisplayYesNo";
    555 	case 0x02:
    556 		return "KeyboardOnly";
    557 	case 0x03:
    558 		return "NoInputNoOutput";
    559 	default:
    560 		return "Reserved";
    561 	}
    562 }
    563 
    564 static char *authentication2str(uint8_t authentication)
    565 {
    566 	switch (authentication) {
    567 	case 0x00:
    568 		return "No Bonding (No MITM Protection)";
    569 	case 0x01:
    570 		return "No Bonding (MITM Protection)";
    571 	case 0x02:
    572 		return "Dedicated Bonding (No MITM Protection)";
    573 	case 0x03:
    574 		return "Dedicated Bonding (MITM Protection)";
    575 	case 0x04:
    576 		return "General Bonding (No MITM Protection)";
    577 	case 0x05:
    578 		return "General Bonding (MITM Protection)";
    579 	default:
    580 		return "Reserved";
    581 	}
    582 }
    583 
    584 static inline void ext_inquiry_response_dump(int level, struct frame *frm)
    585 {
    586 	void *ptr = frm->ptr;
    587 	uint32_t len = frm->len;
    588 	uint8_t type, length;
    589 	char *str;
    590 	int i;
    591 
    592 	length = get_u8(frm);
    593 
    594 	while (length > 0) {
    595 		type = get_u8(frm);
    596 		length--;
    597 
    598 		switch (type) {
    599 		case 0x01:
    600 			p_indent(level, frm);
    601 			printf("Flags:");
    602 			for (i = 0; i < length; i++)
    603 				printf(" 0x%2.2x", *((uint8_t *) (frm->ptr + i)));
    604 			printf("\n");
    605 			break;
    606 
    607 		case 0x02:
    608 		case 0x03:
    609 			p_indent(level, frm);
    610 			printf("%s service classes:",
    611 					type == 0x02 ? "Shortened" : "Complete");
    612 			for (i = 0; i < length / 2; i++) {
    613 				uint16_t val = btohs(bt_get_unaligned((uint16_t *) (frm->ptr + (i * 2))));
    614 				printf(" 0x%4.4x", val);
    615 			}
    616 			printf("\n");
    617 			break;
    618 
    619 		case 0x08:
    620 		case 0x09:
    621 			str = malloc(length + 1);
    622 			if (str) {
    623 				snprintf(str, length + 1, "%s", (char *) frm->ptr);
    624 				for (i = 0; i < length; i++)
    625 					if (!isprint(str[i]))
    626 						str[i] = '.';
    627 				p_indent(level, frm);
    628 				printf("%s local name: \'%s\'\n",
    629 					type == 0x08 ? "Shortened" : "Complete", str);
    630 				free(str);
    631 			}
    632 			break;
    633 
    634 		case 0x0a:
    635 			p_indent(level, frm);
    636 			printf("TX power level: %d\n", *((uint8_t *) frm->ptr));
    637 			break;
    638 
    639 		default:
    640 			p_indent(level, frm);
    641 			printf("Unknown type 0x%02x with %d bytes data\n",
    642 								type, length);
    643 			break;
    644 		}
    645 
    646 		frm->ptr += length;
    647 		frm->len -= length;
    648 
    649 		length = get_u8(frm);
    650 	}
    651 
    652 	frm->ptr = ptr + (EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
    653 	frm->len = len + (EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
    654 }
    655 
    656 static inline void bdaddr_command_dump(int level, struct frame *frm)
    657 {
    658 	bdaddr_t *bdaddr = frm->ptr;
    659 	char addr[18];
    660 
    661 	frm->ptr += sizeof(bdaddr_t);
    662 	frm->len -= sizeof(bdaddr_t);
    663 
    664 	p_indent(level, frm);
    665 	p_ba2str(bdaddr, addr);
    666 	printf("bdaddr %s\n", addr);
    667 
    668 	raw_dump(level, frm);
    669 }
    670 
    671 static inline void generic_command_dump(int level, struct frame *frm)
    672 {
    673 	uint16_t handle = btohs(htons(get_u16(frm)));
    674 
    675 	p_indent(level, frm);
    676 	printf("handle %d\n", handle);
    677 
    678 	raw_dump(level, frm);
    679 }
    680 
    681 static inline void generic_write_mode_dump(int level, struct frame *frm)
    682 {
    683 	uint8_t mode = get_u8(frm);
    684 
    685 	p_indent(level, frm);
    686 	printf("mode 0x%2.2x\n", mode);
    687 }
    688 
    689 static inline void inquiry_dump(int level, struct frame *frm)
    690 {
    691 	inquiry_cp *cp = frm->ptr;
    692 
    693 	p_indent(level, frm);
    694 	printf("lap 0x%2.2x%2.2x%2.2x len %d num %d\n",
    695 		cp->lap[2], cp->lap[1], cp->lap[0], cp->length, cp->num_rsp);
    696 }
    697 
    698 static inline void periodic_inquiry_dump(int level, struct frame *frm)
    699 {
    700 	periodic_inquiry_cp *cp = frm->ptr;
    701 
    702 	p_indent(level, frm);
    703 	printf("max %d min %d lap 0x%2.2x%2.2x%2.2x len %d num %d\n",
    704 		btohs(cp->max_period), btohs(cp->min_period),
    705 		cp->lap[2], cp->lap[1], cp->lap[0], cp->length, cp->num_rsp);
    706 }
    707 
    708 static inline void create_conn_dump(int level, struct frame *frm)
    709 {
    710 	create_conn_cp *cp = frm->ptr;
    711 	uint16_t ptype = btohs(cp->pkt_type);
    712 	uint16_t clkoffset = btohs(cp->clock_offset);
    713 	char addr[18], *str;
    714 
    715 	p_indent(level, frm);
    716 	p_ba2str(&cp->bdaddr, addr);
    717 	printf("bdaddr %s ptype 0x%4.4x rswitch 0x%2.2x clkoffset 0x%4.4x%s\n",
    718 		addr, ptype, cp->role_switch,
    719 		clkoffset & 0x7fff, clkoffset & 0x8000 ? " (valid)" : "");
    720 
    721 	str = hci_ptypetostr(ptype);
    722 	if (str) {
    723 		p_indent(level, frm);
    724 		printf("Packet type: %s\n", str);
    725 		free(str);
    726 	}
    727 }
    728 
    729 static inline void disconnect_dump(int level, struct frame *frm)
    730 {
    731 	disconnect_cp *cp = frm->ptr;
    732 
    733 	p_indent(level, frm);
    734 	printf("handle %d reason 0x%2.2x\n", btohs(cp->handle), cp->reason);
    735 
    736 	p_indent(level, frm);
    737 	printf("Reason: %s\n", status2str(cp->reason));
    738 }
    739 
    740 static inline void add_sco_dump(int level, struct frame *frm)
    741 {
    742 	add_sco_cp *cp = frm->ptr;
    743 	uint16_t ptype = btohs(cp->pkt_type);
    744 	char *str;
    745 
    746 	p_indent(level, frm);
    747 	printf("handle %d ptype 0x%4.4x\n", btohs(cp->handle), ptype);
    748 
    749 	str = hci_ptypetostr(ptype);
    750 	if (str) {
    751 		p_indent(level, frm);
    752 		printf("Packet type: %s\n", str);
    753 		free(str);
    754 	}
    755 }
    756 
    757 static inline void accept_conn_req_dump(int level, struct frame *frm)
    758 {
    759 	accept_conn_req_cp *cp = frm->ptr;
    760 	char addr[18];
    761 
    762 	p_indent(level, frm);
    763 	p_ba2str(&cp->bdaddr, addr);
    764 	printf("bdaddr %s role 0x%2.2x\n", addr, cp->role);
    765 
    766 	p_indent(level, frm);
    767 	printf("Role: %s\n", role2str(cp->role));
    768 }
    769 
    770 static inline void reject_conn_req_dump(int level, struct frame *frm)
    771 {
    772 	reject_conn_req_cp *cp = frm->ptr;
    773 	char addr[18];
    774 
    775 	p_indent(level, frm);
    776 	p_ba2str(&cp->bdaddr, addr);
    777 	printf("bdaddr %s reason 0x%2.2x\n", addr, cp->reason);
    778 
    779 	p_indent(level, frm);
    780 	printf("Reason: %s\n", status2str(cp->reason));
    781 }
    782 
    783 static inline void pin_code_reply_dump(int level, struct frame *frm)
    784 {
    785 	pin_code_reply_cp *cp = frm->ptr;
    786 	char addr[18], pin[17];
    787 
    788 	p_indent(level, frm);
    789 	p_ba2str(&cp->bdaddr, addr);
    790 	memset(pin, 0, sizeof(pin));
    791 	if (parser.flags & DUMP_NOVENDOR)
    792 		memset(pin, '*', cp->pin_len);
    793 	else
    794 		memcpy(pin, cp->pin_code, cp->pin_len);
    795 	printf("bdaddr %s len %d pin \'%s\'\n", addr, cp->pin_len, pin);
    796 }
    797 
    798 static inline void link_key_reply_dump(int level, struct frame *frm)
    799 {
    800 	link_key_reply_cp *cp = frm->ptr;
    801 	char addr[18];
    802 	int i;
    803 
    804 	p_indent(level, frm);
    805 	p_ba2str(&cp->bdaddr, addr);
    806 	printf("bdaddr %s key ", addr);
    807 	for (i = 0; i < 16; i++)
    808 		if (parser.flags & DUMP_NOVENDOR)
    809 			printf("**");
    810 		else
    811 			printf("%2.2X", cp->link_key[i]);
    812 	printf("\n");
    813 }
    814 
    815 static inline void pin_code_neg_reply_dump(int level, struct frame *frm)
    816 {
    817 	bdaddr_t *bdaddr = frm->ptr;
    818 	char addr[18];
    819 
    820 	p_indent(level, frm);
    821 	p_ba2str(bdaddr, addr);
    822 	printf("bdaddr %s\n", addr);
    823 }
    824 
    825 static inline void user_passkey_reply_dump(int level, struct frame *frm)
    826 {
    827 	user_passkey_reply_cp *cp = frm->ptr;
    828 	char addr[18];
    829 
    830 	p_indent(level, frm);
    831 	p_ba2str(&cp->bdaddr, addr);
    832 	printf("bdaddr %s passkey %d\n", addr, btohl(cp->passkey));
    833 }
    834 
    835 static inline void remote_oob_data_reply_dump(int level, struct frame *frm)
    836 {
    837 	remote_oob_data_reply_cp *cp = frm->ptr;
    838 	char addr[18];
    839 	int i;
    840 
    841 	p_indent(level, frm);
    842 	p_ba2str(&cp->bdaddr, addr);
    843 	printf("bdaddr %s\n", addr);
    844 
    845 	p_indent(level, frm);
    846 	printf("hash 0x");
    847 	for (i = 0; i < 16; i++)
    848 		printf("%02x", cp->hash[i]);
    849 	printf("\n");
    850 
    851 	p_indent(level, frm);
    852 	printf("randomizer 0x");
    853 	for (i = 0; i < 16; i++)
    854 			printf("%02x", cp->randomizer[i]);
    855 	printf("\n");
    856 }
    857 
    858 static inline void io_capability_reply_dump(int level, struct frame *frm)
    859 {
    860 	io_capability_reply_cp *cp = frm->ptr;
    861 	char addr[18];
    862 
    863 	p_indent(level, frm);
    864 	p_ba2str(&cp->bdaddr, addr);
    865 	printf("bdaddr %s capability 0x%2.2x oob 0x%2.2x auth 0x%2.2x\n",
    866 					addr, cp->capability, cp->oob_data,
    867 							cp->authentication);
    868 
    869 	p_indent(level, frm);
    870 	printf("Capability: %s (OOB data %s)\n",
    871 			capability2str(cp->capability),
    872 			cp->oob_data == 0x00 ? "not present" : "available");
    873 
    874 	p_indent(level, frm);
    875 	printf("Authentication: %s\n", authentication2str(cp->authentication));
    876 }
    877 
    878 static inline void set_conn_encrypt_dump(int level, struct frame *frm)
    879 {
    880 	set_conn_encrypt_cp *cp = frm->ptr;
    881 
    882 	p_indent(level, frm);
    883 	printf("handle %d encrypt 0x%2.2x\n", btohs(cp->handle), cp->encrypt);
    884 }
    885 
    886 static inline void remote_name_req_dump(int level, struct frame *frm)
    887 {
    888 	remote_name_req_cp *cp = frm->ptr;
    889 	uint16_t clkoffset = btohs(cp->clock_offset);
    890 	char addr[18];
    891 
    892 	p_indent(level, frm);
    893 	p_ba2str(&cp->bdaddr, addr);
    894 	printf("bdaddr %s mode %d clkoffset 0x%4.4x%s\n",
    895 		addr, cp->pscan_rep_mode,
    896 		clkoffset & 0x7fff, clkoffset & 0x8000 ? " (valid)" : "");
    897 }
    898 
    899 static inline void master_link_key_dump(int level, struct frame *frm)
    900 {
    901 	master_link_key_cp *cp = frm->ptr;
    902 
    903 	p_indent(level, frm);
    904 	printf("flag %d\n", cp->key_flag);
    905 }
    906 
    907 static inline void read_remote_ext_features_dump(int level, struct frame *frm)
    908 {
    909 	read_remote_ext_features_cp *cp = frm->ptr;
    910 
    911 	p_indent(level, frm);
    912 	printf("handle %d page %d\n", btohs(cp->handle), cp->page_num);
    913 }
    914 
    915 static inline void setup_sync_conn_dump(int level, struct frame *frm)
    916 {
    917 	setup_sync_conn_cp *cp = frm->ptr;
    918 
    919 	p_indent(level, frm);
    920 	printf("handle %d voice setting 0x%4.4x pkt_type 0x%4.4x\n",
    921 		btohs(cp->handle), btohs(cp->voice_setting),
    922 		btohs(cp->pkt_type));
    923 }
    924 
    925 static inline void accept_sync_conn_req_dump(int level, struct frame *frm)
    926 {
    927 	accept_sync_conn_req_cp *cp = frm->ptr;
    928 	char addr[18];
    929 
    930 	p_indent(level, frm);
    931 	p_ba2str(&cp->bdaddr, addr);
    932 	printf("bdaddr %s voice_setting 0x%4.4x pkt_type 0x%4.4x\n",
    933 		addr, btohs(cp->voice_setting), btohs(cp->pkt_type));
    934 }
    935 
    936 static inline void hold_mode_dump(int level, struct frame *frm)
    937 {
    938 	hold_mode_cp *cp = frm->ptr;
    939 
    940 	p_indent(level, frm);
    941 	printf("handle %d max %d min %d\n", btohs(cp->handle),
    942 			btohs(cp->max_interval), btohs(cp->min_interval));
    943 }
    944 
    945 static inline void sniff_mode_dump(int level, struct frame *frm)
    946 {
    947 	sniff_mode_cp *cp = frm->ptr;
    948 
    949 	p_indent(level, frm);
    950 	printf("handle %d max %d min %d attempt %d timeout %d\n",
    951 		btohs(cp->handle), btohs(cp->max_interval),
    952 		btohs(cp->min_interval), btohs(cp->attempt), btohs(cp->timeout));
    953 }
    954 
    955 static inline void qos_setup_dump(int level, struct frame *frm)
    956 {
    957 	qos_setup_cp *cp = frm->ptr;
    958 
    959 	p_indent(level, frm);
    960 	printf("handle %d flags 0x%2.2x\n", btohs(cp->handle), cp->flags);
    961 
    962 	p_indent(level, frm);
    963 	printf("Service type: %d\n", cp->qos.service_type);
    964 	p_indent(level, frm);
    965 	printf("Token rate: %d\n", btohl(cp->qos.token_rate));
    966 	p_indent(level, frm);
    967 	printf("Peak bandwith: %d\n", btohl(cp->qos.peak_bandwidth));
    968 	p_indent(level, frm);
    969 	printf("Latency: %d\n", btohl(cp->qos.latency));
    970 	p_indent(level, frm);
    971 	printf("Delay variation: %d\n", btohl(cp->qos.delay_variation));
    972 }
    973 
    974 static inline void write_link_policy_dump(int level, struct frame *frm)
    975 {
    976 	write_link_policy_cp *cp = frm->ptr;
    977 	uint16_t policy = btohs(cp->policy);
    978 	char *str;
    979 
    980 	p_indent(level, frm);
    981 	printf("handle %d policy 0x%2.2x\n", btohs(cp->handle), policy);
    982 
    983 	str = hci_lptostr(policy);
    984 	if (str) {
    985 		p_indent(level, frm);
    986 		printf("Link policy: %s\n", str);
    987 		free(str);
    988 	}
    989 }
    990 
    991 static inline void write_default_link_policy_dump(int level, struct frame *frm)
    992 {
    993 	uint16_t policy = btohs(htons(get_u16(frm)));
    994 	char *str;
    995 
    996 	p_indent(level, frm);
    997 	printf("policy 0x%2.2x\n", policy);
    998 
    999 	str = hci_lptostr(policy);
   1000 	if (str) {
   1001 		p_indent(level, frm);
   1002 		printf("Link policy: %s\n", str);
   1003 		free(str);
   1004 	}
   1005 }
   1006 
   1007 static inline void sniff_subrating_dump(int level, struct frame *frm)
   1008 {
   1009 	sniff_subrating_cp *cp = frm->ptr;
   1010 
   1011 	p_indent(level, frm);
   1012 	printf("handle %d\n", btohs(cp->handle));
   1013 
   1014 	p_indent(level, frm);
   1015 	printf("max latency %d\n", btohs(cp->max_latency));
   1016 
   1017 	p_indent(level, frm);
   1018 	printf("min timeout remote %d local %d\n",
   1019 		btohs(cp->min_remote_timeout), btohs(cp->min_local_timeout));
   1020 }
   1021 
   1022 static inline void set_event_mask_dump(int level, struct frame *frm)
   1023 {
   1024 	set_event_mask_cp *cp = frm->ptr;
   1025 	int i;
   1026 
   1027 	p_indent(level, frm);
   1028 	printf("Mask: 0x");
   1029 	for (i = 0; i < 8; i++)
   1030 		printf("%2.2x", cp->mask[i]);
   1031 	printf("\n");
   1032 }
   1033 
   1034 static inline void set_event_flt_dump(int level, struct frame *frm)
   1035 {
   1036 	set_event_flt_cp *cp = frm->ptr;
   1037 	uint8_t dev_class[3], dev_mask[3];
   1038 	char addr[18];
   1039 
   1040 	p_indent(level, frm);
   1041 	printf("type %d condition %d\n", cp->flt_type,
   1042 				(cp->flt_type == 0) ? 0 : cp->cond_type);
   1043 
   1044 	switch (cp->flt_type) {
   1045 	case FLT_CLEAR_ALL:
   1046 		p_indent(level, frm);
   1047 		printf("Clear all filters\n");
   1048 		break;
   1049 	case FLT_INQ_RESULT:
   1050 		p_indent(level, frm);
   1051 		printf("Inquiry result");
   1052 		switch (cp->cond_type) {
   1053 		case INQ_RESULT_RETURN_ALL:
   1054 			printf(" for all devices\n");
   1055 			break;
   1056 		case INQ_RESULT_RETURN_CLASS:
   1057 			memcpy(dev_class, cp->condition, 3);
   1058 			memcpy(dev_mask, cp->condition + 3, 3);
   1059 			printf(" with class 0x%2.2x%2.2x%2.2x mask 0x%2.2x%2.2x%2.2x\n",
   1060 				dev_class[2], dev_class[1], dev_class[0],
   1061 				dev_mask[2], dev_mask[1], dev_mask[0]);
   1062 			break;
   1063 		case INQ_RESULT_RETURN_BDADDR:
   1064 			p_ba2str((bdaddr_t *) cp->condition, addr);
   1065 			printf(" with bdaddr %s\n", addr);
   1066 			break;
   1067 		default:
   1068 			printf("\n");
   1069 			break;
   1070 		}
   1071 		break;
   1072 	case FLT_CONN_SETUP:
   1073 		p_indent(level, frm);
   1074 		printf("Connection setup");
   1075 		switch (cp->cond_type) {
   1076 		case CONN_SETUP_ALLOW_ALL:
   1077 		case CONN_SETUP_ALLOW_CLASS:
   1078 		case CONN_SETUP_ALLOW_BDADDR:
   1079 		default:
   1080 			printf("\n");
   1081 			break;
   1082 		}
   1083 		break;
   1084 	}
   1085 }
   1086 
   1087 static inline void write_pin_type_dump(int level, struct frame *frm)
   1088 {
   1089 	write_pin_type_cp *cp = frm->ptr;
   1090 
   1091 	p_indent(level, frm);
   1092 	printf("type %d\n", cp->pin_type);
   1093 }
   1094 
   1095 static inline void request_stored_link_key_dump(int level, struct frame *frm)
   1096 {
   1097 	read_stored_link_key_cp *cp = frm->ptr;
   1098 	char addr[18];
   1099 
   1100 	p_indent(level, frm);
   1101 	p_ba2str(&cp->bdaddr, addr);
   1102 	printf("bdaddr %s all %d\n", addr, cp->read_all);
   1103 }
   1104 
   1105 static inline void return_link_keys_dump(int level, struct frame *frm)
   1106 {
   1107 	uint8_t num = get_u8(frm);
   1108 	uint8_t key[16];
   1109 	char addr[18];
   1110 	int i, n;
   1111 
   1112 	for (n = 0; n < num; n++) {
   1113 		p_ba2str(frm->ptr, addr);
   1114 		memcpy(key, frm->ptr + 6, 16);
   1115 
   1116 		p_indent(level, frm);
   1117 		printf("bdaddr %s key ", addr);
   1118 		for (i = 0; i < 16; i++)
   1119 			if (parser.flags & DUMP_NOVENDOR)
   1120 				printf("**");
   1121 			else
   1122 				printf("%2.2X", key[i]);
   1123 		printf("\n");
   1124 
   1125 		frm->ptr += 2;
   1126 		frm->len -= 2;
   1127 	}
   1128 }
   1129 
   1130 static inline void change_local_name_dump(int level, struct frame *frm)
   1131 {
   1132 	change_local_name_cp *cp = frm->ptr;
   1133 	char name[249];
   1134 	int i;
   1135 
   1136 	memset(name, 0, sizeof(name));
   1137 	for (i = 0; i < 248 && cp->name[i]; i++)
   1138 		if (isprint(cp->name[i]))
   1139 			name[i] = cp->name[i];
   1140 		else
   1141 			name[i] = '.';
   1142 
   1143 	p_indent(level, frm);
   1144 	printf("name \'%s\'\n", name);
   1145 }
   1146 
   1147 static inline void write_class_of_dev_dump(int level, struct frame *frm)
   1148 {
   1149 	write_class_of_dev_cp *cp = frm->ptr;
   1150 
   1151 	p_indent(level, frm);
   1152 	printf("class 0x%2.2x%2.2x%2.2x\n",
   1153 			cp->dev_class[2], cp->dev_class[1], cp->dev_class[0]);
   1154 }
   1155 
   1156 static inline void write_voice_setting_dump(int level, struct frame *frm)
   1157 {
   1158 	write_voice_setting_cp *cp = frm->ptr;
   1159 
   1160 	p_indent(level, frm);
   1161 	printf("voice setting 0x%4.4x\n", btohs(cp->voice_setting));
   1162 }
   1163 
   1164 static inline void write_current_iac_lap_dump(int level, struct frame *frm)
   1165 {
   1166 	write_current_iac_lap_cp *cp = frm->ptr;
   1167 	int i;
   1168 
   1169 	for (i = 0; i < cp->num_current_iac; i++) {
   1170 		p_indent(level, frm);
   1171 		printf("IAC 0x%2.2x%2.2x%2.2x", cp->lap[i][2], cp->lap[i][1], cp->lap[i][0]);
   1172 		if (cp->lap[i][2] == 0x9e && cp->lap[i][1] == 0x8b) {
   1173 			switch (cp->lap[i][0]) {
   1174 			case 0x00:
   1175 				printf(" (Limited Inquiry Access Code)");
   1176 				break;
   1177 			case 0x33:
   1178 				printf(" (General Inquiry Access Code)");
   1179 				break;
   1180 			}
   1181 		}
   1182 		printf("\n");
   1183 	}
   1184 }
   1185 
   1186 static inline void write_scan_enable_dump(int level, struct frame *frm)
   1187 {
   1188 	uint8_t enable = get_u8(frm);
   1189 
   1190 	p_indent(level, frm);
   1191 	printf("enable %d\n", enable);
   1192 }
   1193 
   1194 static inline void write_page_timeout_dump(int level, struct frame *frm)
   1195 {
   1196 	write_page_timeout_cp *cp = frm->ptr;
   1197 
   1198 	p_indent(level, frm);
   1199 	printf("timeout %d\n", btohs(cp->timeout));
   1200 }
   1201 
   1202 static inline void write_page_activity_dump(int level, struct frame *frm)
   1203 {
   1204 	write_page_activity_cp *cp = frm->ptr;
   1205 
   1206 	p_indent(level, frm);
   1207 	printf("interval %d window %d\n", btohs(cp->interval), btohs(cp->window));
   1208 }
   1209 
   1210 static inline void write_inquiry_scan_type_dump(int level, struct frame *frm)
   1211 {
   1212 	write_inquiry_scan_type_cp *cp = frm->ptr;
   1213 
   1214 	p_indent(level, frm);
   1215 	printf("type %d\n", cp->type);
   1216 }
   1217 
   1218 static inline void write_inquiry_mode_dump(int level, struct frame *frm)
   1219 {
   1220 	write_inquiry_mode_cp *cp = frm->ptr;
   1221 
   1222 	p_indent(level, frm);
   1223 	printf("mode %d\n", cp->mode);
   1224 }
   1225 
   1226 static inline void set_afh_classification_dump(int level, struct frame *frm)
   1227 {
   1228 	set_afh_classification_cp *cp = frm->ptr;
   1229 	int i;
   1230 
   1231 	p_indent(level, frm);
   1232 	printf("map 0x");
   1233 	for (i = 0; i < 10; i++)
   1234 		printf("%02x", cp->map[i]);
   1235 	printf("\n");
   1236 }
   1237 
   1238 static inline void write_link_supervision_timeout_dump(int level, struct frame *frm)
   1239 {
   1240 	write_link_supervision_timeout_cp *cp = frm->ptr;
   1241 
   1242 	p_indent(level, frm);
   1243 	printf("handle %d timeout %d\n",
   1244 				btohs(cp->handle), btohs(cp->timeout));
   1245 }
   1246 
   1247 static inline void write_ext_inquiry_response_dump(int level, struct frame *frm)
   1248 {
   1249 	write_ext_inquiry_response_cp *cp = frm->ptr;
   1250 
   1251 	p_indent(level, frm);
   1252 	printf("fec 0x%2.2x\n", cp->fec);
   1253 
   1254 	frm->ptr++;
   1255 	frm->len--;
   1256 
   1257 	ext_inquiry_response_dump(level, frm);
   1258 }
   1259 
   1260 static inline void write_inquiry_transmit_power_level_dump(int level, struct frame *frm)
   1261 {
   1262 	write_inquiry_transmit_power_level_cp *cp = frm->ptr;
   1263 
   1264 	p_indent(level, frm);
   1265 	printf("level %d\n", cp->level);
   1266 }
   1267 
   1268 static inline void write_default_error_data_reporting_dump(int level, struct frame *frm)
   1269 {
   1270 	write_default_error_data_reporting_cp *cp = frm->ptr;
   1271 
   1272 	p_indent(level, frm);
   1273 	printf("reporting %d\n", cp->reporting);
   1274 }
   1275 
   1276 static inline void enhanced_flush_dump(int level, struct frame *frm)
   1277 {
   1278 	enhanced_flush_cp *cp = frm->ptr;
   1279 
   1280 	p_indent(level, frm);
   1281 	printf("handle %d type %d\n", btohs(cp->handle), cp->type);
   1282 }
   1283 
   1284 static inline void send_keypress_notify_dump(int level, struct frame *frm)
   1285 {
   1286 	send_keypress_notify_cp *cp = frm->ptr;
   1287 	char addr[18];
   1288 
   1289 	p_indent(level, frm);
   1290 	p_ba2str(&cp->bdaddr, addr);
   1291 	printf("bdaddr %s type %d\n", addr, cp->type);
   1292 }
   1293 
   1294 static inline void request_transmit_power_level_dump(int level, struct frame *frm)
   1295 {
   1296 	read_transmit_power_level_cp *cp = frm->ptr;
   1297 
   1298 	p_indent(level, frm);
   1299 	printf("handle %d type %d (%s)\n",
   1300 					btohs(cp->handle), cp->type,
   1301 					cp->type ? "maximum" : "current");
   1302 }
   1303 
   1304 static inline void request_local_ext_features_dump(int level, struct frame *frm)
   1305 {
   1306 	read_local_ext_features_cp *cp = frm->ptr;
   1307 
   1308 	p_indent(level, frm);
   1309 	printf("page %d\n", cp->page_num);
   1310 }
   1311 
   1312 static inline void request_clock_dump(int level, struct frame *frm)
   1313 {
   1314 	read_clock_cp *cp = frm->ptr;
   1315 
   1316 	p_indent(level, frm);
   1317 	printf("handle %d which %d (%s)\n",
   1318 					btohs(cp->handle), cp->which_clock,
   1319 					cp->which_clock ? "piconet" : "local");
   1320 }
   1321 
   1322 static inline void host_buffer_size_dump(int level, struct frame *frm)
   1323 {
   1324 	host_buffer_size_cp *cp = frm->ptr;
   1325 
   1326 	p_indent(level, frm);
   1327 	printf("ACL MTU %d:%d SCO MTU %d:%d\n",
   1328 				btohs(cp->acl_mtu), btohs(cp->acl_max_pkt),
   1329 				cp->sco_mtu, btohs(cp->sco_max_pkt));
   1330 }
   1331 
   1332 static inline void num_comp_pkts_dump(int level, struct frame *frm)
   1333 {
   1334 	uint8_t num = get_u8(frm);
   1335 	uint16_t handle, packets;
   1336 	int i;
   1337 
   1338 	for (i = 0; i < num; i++) {
   1339 		handle = btohs(htons(get_u16(frm)));
   1340 		packets = btohs(htons(get_u16(frm)));
   1341 
   1342 		p_indent(level, frm);
   1343 		printf("handle %d packets %d\n", handle, packets);
   1344 	}
   1345 }
   1346 
   1347 static inline void command_dump(int level, struct frame *frm)
   1348 {
   1349 	hci_command_hdr *hdr = frm->ptr;
   1350 	uint16_t opcode = btohs(hdr->opcode);
   1351 	uint16_t ogf = cmd_opcode_ogf(opcode);
   1352 	uint16_t ocf = cmd_opcode_ocf(opcode);
   1353 
   1354 	if (p_filter(FILT_HCI))
   1355 		return;
   1356 
   1357 	if (ogf == OGF_VENDOR_CMD && (parser.flags & DUMP_NOVENDOR))
   1358 		return;
   1359 
   1360 	p_indent(level, frm);
   1361 	printf("HCI Command: %s (0x%2.2x|0x%4.4x) plen %d\n",
   1362 				opcode2str(opcode), ogf, ocf, hdr->plen);
   1363 
   1364 	frm->ptr += HCI_COMMAND_HDR_SIZE;
   1365 	frm->len -= HCI_COMMAND_HDR_SIZE;
   1366 
   1367 	if (ogf == OGF_VENDOR_CMD) {
   1368 		if (ocf == 0 && get_manufacturer() == 10) {
   1369 			csr_dump(level + 1, frm);
   1370 			return;
   1371 		}
   1372 	}
   1373 
   1374 	if (!(parser.flags & DUMP_VERBOSE)) {
   1375 		raw_dump(level, frm);
   1376 		return;
   1377 	}
   1378 
   1379 	switch (ogf) {
   1380 	case OGF_LINK_CTL:
   1381 		switch (ocf) {
   1382 		case OCF_INQUIRY:
   1383 			inquiry_dump(level + 1, frm);
   1384 			return;
   1385 		case OCF_PERIODIC_INQUIRY:
   1386 			periodic_inquiry_dump(level + 1, frm);
   1387 			return;
   1388 		case OCF_INQUIRY_CANCEL:
   1389 		case OCF_EXIT_PERIODIC_INQUIRY:
   1390 			return;
   1391 		case OCF_CREATE_CONN:
   1392 			create_conn_dump(level + 1, frm);
   1393 			return;
   1394 		case OCF_DISCONNECT:
   1395 			disconnect_dump(level + 1, frm);
   1396 			return;
   1397 		case OCF_CREATE_CONN_CANCEL:
   1398 		case OCF_REMOTE_NAME_REQ_CANCEL:
   1399 			bdaddr_command_dump(level + 1, frm);
   1400 			return;
   1401 		case OCF_ACCEPT_SYNC_CONN_REQ:
   1402 			accept_sync_conn_req_dump(level + 1, frm);
   1403 			return;
   1404 		case OCF_ADD_SCO:
   1405 		case OCF_SET_CONN_PTYPE:
   1406 			add_sco_dump(level + 1, frm);
   1407 			return;
   1408 		case OCF_ACCEPT_CONN_REQ:
   1409 			accept_conn_req_dump(level + 1, frm);
   1410 			return;
   1411 		case OCF_REJECT_CONN_REQ:
   1412 		case OCF_REJECT_SYNC_CONN_REQ:
   1413 		case OCF_IO_CAPABILITY_NEG_REPLY:
   1414 			reject_conn_req_dump(level + 1, frm);
   1415 			return;
   1416 		case OCF_PIN_CODE_REPLY:
   1417 			pin_code_reply_dump(level + 1, frm);
   1418 			return;
   1419 		case OCF_LINK_KEY_REPLY:
   1420 			link_key_reply_dump(level + 1, frm);
   1421 			return;
   1422 		case OCF_PIN_CODE_NEG_REPLY:
   1423 		case OCF_LINK_KEY_NEG_REPLY:
   1424 		case OCF_USER_CONFIRM_REPLY:
   1425 		case OCF_USER_CONFIRM_NEG_REPLY:
   1426 		case OCF_USER_PASSKEY_NEG_REPLY:
   1427 		case OCF_REMOTE_OOB_DATA_NEG_REPLY:
   1428 			pin_code_neg_reply_dump(level + 1, frm);
   1429 			return;
   1430 		case OCF_USER_PASSKEY_REPLY:
   1431 			user_passkey_reply_dump(level + 1, frm);
   1432 			return;
   1433 		case OCF_REMOTE_OOB_DATA_REPLY:
   1434 			remote_oob_data_reply_dump(level + 1, frm);
   1435 			return;
   1436 		case OCF_IO_CAPABILITY_REPLY:
   1437 			io_capability_reply_dump(level + 1, frm);
   1438 			return;
   1439 		case OCF_SET_CONN_ENCRYPT:
   1440 			set_conn_encrypt_dump(level + 1, frm);
   1441 			return;
   1442 		case OCF_AUTH_REQUESTED:
   1443 		case OCF_CHANGE_CONN_LINK_KEY:
   1444 		case OCF_READ_REMOTE_FEATURES:
   1445 		case OCF_READ_REMOTE_VERSION:
   1446 		case OCF_READ_CLOCK_OFFSET:
   1447 		case OCF_READ_LMP_HANDLE:
   1448 			generic_command_dump(level + 1, frm);
   1449 			return;
   1450 		case OCF_MASTER_LINK_KEY:
   1451 			master_link_key_dump(level + 1, frm);
   1452 			return;
   1453 		case OCF_READ_REMOTE_EXT_FEATURES:
   1454 			read_remote_ext_features_dump(level + 1, frm);
   1455 			return;
   1456 		case OCF_REMOTE_NAME_REQ:
   1457 			remote_name_req_dump(level + 1, frm);
   1458 			return;
   1459 		case OCF_SETUP_SYNC_CONN:
   1460 			setup_sync_conn_dump(level + 1, frm);
   1461 			return;
   1462 		}
   1463 		break;
   1464 
   1465 	case OGF_LINK_POLICY:
   1466 		switch (ocf) {
   1467 		case OCF_HOLD_MODE:
   1468 		case OCF_PARK_MODE:
   1469 			hold_mode_dump(level + 1, frm);
   1470 			return;
   1471 		case OCF_SNIFF_MODE:
   1472 			sniff_mode_dump(level + 1, frm);
   1473 			return;
   1474 		case OCF_EXIT_SNIFF_MODE:
   1475 		case OCF_EXIT_PARK_MODE:
   1476 		case OCF_ROLE_DISCOVERY:
   1477 		case OCF_READ_LINK_POLICY:
   1478 			generic_command_dump(level + 1, frm);
   1479 			return;
   1480 		case OCF_READ_DEFAULT_LINK_POLICY:
   1481 			return;
   1482 		case OCF_SWITCH_ROLE:
   1483 			accept_conn_req_dump(level + 1, frm);
   1484 			return;
   1485 		case OCF_QOS_SETUP:
   1486 			qos_setup_dump(level + 1, frm);
   1487 			return;
   1488 		case OCF_WRITE_LINK_POLICY:
   1489 			write_link_policy_dump(level + 1, frm);
   1490 			return;
   1491 		case OCF_WRITE_DEFAULT_LINK_POLICY:
   1492 			write_default_link_policy_dump(level + 1, frm);
   1493 			return;
   1494 		case OCF_SNIFF_SUBRATING:
   1495 			sniff_subrating_dump(level + 1, frm);
   1496 			return;
   1497 		}
   1498 		break;
   1499 
   1500 	case OGF_HOST_CTL:
   1501 		switch (ocf) {
   1502 		case OCF_RESET:
   1503 		case OCF_CREATE_NEW_UNIT_KEY:
   1504 			return;
   1505 		case OCF_SET_EVENT_MASK:
   1506 			set_event_mask_dump(level + 1, frm);
   1507 			return;
   1508 		case OCF_SET_EVENT_FLT:
   1509 			set_event_flt_dump(level + 1, frm);
   1510 			return;
   1511 		case OCF_WRITE_PIN_TYPE:
   1512 			write_pin_type_dump(level + 1, frm);
   1513 			return;
   1514 		case OCF_READ_STORED_LINK_KEY:
   1515 		case OCF_DELETE_STORED_LINK_KEY:
   1516 			request_stored_link_key_dump(level + 1, frm);
   1517 			return;
   1518 		case OCF_WRITE_STORED_LINK_KEY:
   1519 			return_link_keys_dump(level + 1, frm);
   1520 			return;
   1521 		case OCF_CHANGE_LOCAL_NAME:
   1522 			change_local_name_dump(level + 1, frm);
   1523 			return;
   1524 		case OCF_WRITE_CLASS_OF_DEV:
   1525 			write_class_of_dev_dump(level + 1, frm);
   1526 			return;
   1527 		case OCF_WRITE_VOICE_SETTING:
   1528 			write_voice_setting_dump(level + 1, frm);
   1529 			return;
   1530 		case OCF_WRITE_CURRENT_IAC_LAP:
   1531 			write_current_iac_lap_dump(level + 1, frm);
   1532 			return;
   1533 		case OCF_WRITE_SCAN_ENABLE:
   1534 		case OCF_WRITE_AUTH_ENABLE:
   1535 		case OCF_SET_CONTROLLER_TO_HOST_FC:
   1536 			write_scan_enable_dump(level + 1, frm);
   1537 			return;
   1538 		case OCF_WRITE_CONN_ACCEPT_TIMEOUT:
   1539 		case OCF_WRITE_PAGE_TIMEOUT:
   1540 			write_page_timeout_dump(level + 1, frm);
   1541 			return;
   1542 		case OCF_WRITE_PAGE_ACTIVITY:
   1543 		case OCF_WRITE_INQ_ACTIVITY:
   1544 			write_page_activity_dump(level + 1, frm);
   1545 			return;
   1546 		case OCF_WRITE_INQUIRY_SCAN_TYPE:
   1547 			write_inquiry_scan_type_dump(level + 1, frm);
   1548 			return;
   1549 		case OCF_WRITE_ENCRYPT_MODE:
   1550 		case OCF_WRITE_INQUIRY_MODE:
   1551 		case OCF_WRITE_AFH_MODE:
   1552 			write_inquiry_mode_dump(level + 1, frm);
   1553 			return;
   1554 		case OCF_SET_AFH_CLASSIFICATION:
   1555 			set_afh_classification_dump(level + 1, frm);
   1556 			return;
   1557 		case OCF_READ_TRANSMIT_POWER_LEVEL:
   1558 			request_transmit_power_level_dump(level + 1, frm);
   1559 			return;
   1560 		case OCF_HOST_BUFFER_SIZE:
   1561 			host_buffer_size_dump(level + 1, frm);
   1562 			return;
   1563 		case OCF_HOST_NUM_COMP_PKTS:
   1564 			num_comp_pkts_dump(level + 1, frm);
   1565 			return;
   1566 		case OCF_FLUSH:
   1567 		case OCF_READ_LINK_SUPERVISION_TIMEOUT:
   1568 		case OCF_REFRESH_ENCRYPTION_KEY:
   1569 			generic_command_dump(level + 1, frm);
   1570 			return;
   1571 		case OCF_WRITE_LINK_SUPERVISION_TIMEOUT:
   1572 			write_link_supervision_timeout_dump(level + 1, frm);
   1573 			return;
   1574 		case OCF_WRITE_EXT_INQUIRY_RESPONSE:
   1575 			write_ext_inquiry_response_dump(level + 1, frm);
   1576 			return;
   1577 		case OCF_WRITE_SIMPLE_PAIRING_MODE:
   1578 			generic_write_mode_dump(level + 1, frm);
   1579 			return;
   1580 		case OCF_WRITE_INQUIRY_TRANSMIT_POWER_LEVEL:
   1581 			write_inquiry_transmit_power_level_dump(level + 1, frm);
   1582 			return;
   1583 		case OCF_WRITE_DEFAULT_ERROR_DATA_REPORTING:
   1584 			write_default_error_data_reporting_dump(level + 1, frm);
   1585 			return;
   1586 		case OCF_ENHANCED_FLUSH:
   1587 			enhanced_flush_dump(level + 1, frm);
   1588 			return;
   1589 		case OCF_SEND_KEYPRESS_NOTIFY:
   1590 			send_keypress_notify_dump(level + 1, frm);
   1591 			return;
   1592 		}
   1593 		break;
   1594 
   1595 	case OGF_INFO_PARAM:
   1596 		switch (ocf) {
   1597 		case OCF_READ_LOCAL_EXT_FEATURES:
   1598 			request_local_ext_features_dump(level + 1, frm);
   1599 			return;
   1600 		}
   1601 		break;
   1602 
   1603 	case OGF_STATUS_PARAM:
   1604 		switch (ocf) {
   1605 		case OCF_READ_LINK_QUALITY:
   1606 		case OCF_READ_RSSI:
   1607 		case OCF_READ_AFH_MAP:
   1608 			generic_command_dump(level + 1, frm);
   1609 			return;
   1610 		case OCF_READ_CLOCK:
   1611 			request_clock_dump(level + 1, frm);
   1612 			return;
   1613 		}
   1614 		break;
   1615 
   1616 	case OGF_TESTING_CMD:
   1617 		switch (ocf) {
   1618 		case OCF_WRITE_LOOPBACK_MODE:
   1619 		case OCF_WRITE_SIMPLE_PAIRING_DEBUG_MODE:
   1620 			generic_write_mode_dump(level + 1, frm);
   1621 			return;
   1622 		}
   1623 		break;
   1624 	}
   1625 
   1626 	raw_dump(level, frm);
   1627 }
   1628 
   1629 static inline void status_response_dump(int level, struct frame *frm)
   1630 {
   1631 	uint8_t status = get_u8(frm);
   1632 
   1633 	p_indent(level, frm);
   1634 	printf("status 0x%2.2x\n", status);
   1635 
   1636 	if (status > 0) {
   1637 		p_indent(level, frm);
   1638 		printf("Error: %s\n", status2str(status));
   1639 	}
   1640 
   1641 	raw_dump(level, frm);
   1642 }
   1643 
   1644 static inline void handle_response_dump(int level, struct frame *frm)
   1645 {
   1646 	uint16_t handle = btohs(htons(get_u16(frm)));
   1647 
   1648 	p_indent(level, frm);
   1649 	printf("handle %d\n", handle);
   1650 
   1651 	raw_dump(level, frm);
   1652 }
   1653 
   1654 static inline void bdaddr_response_dump(int level, struct frame *frm)
   1655 {
   1656 	uint8_t status = get_u8(frm);
   1657 	bdaddr_t *bdaddr = frm->ptr;
   1658 	char addr[18];
   1659 
   1660 	frm->ptr += sizeof(bdaddr_t);
   1661 	frm->len -= sizeof(bdaddr_t);
   1662 
   1663 	p_indent(level, frm);
   1664 	p_ba2str(bdaddr, addr);
   1665 	printf("status 0x%2.2x bdaddr %s\n", status, addr);
   1666 
   1667 	if (status > 0) {
   1668 		p_indent(level, frm);
   1669 		printf("Error: %s\n", status2str(status));
   1670 	}
   1671 
   1672 	raw_dump(level, frm);
   1673 }
   1674 
   1675 static inline void generic_response_dump(int level, struct frame *frm)
   1676 {
   1677 	uint8_t status = get_u8(frm);
   1678 	uint16_t handle = btohs(htons(get_u16(frm)));
   1679 
   1680 	p_indent(level, frm);
   1681 	printf("status 0x%2.2x handle %d\n", status, handle);
   1682 
   1683 	if (status > 0) {
   1684 		p_indent(level, frm);
   1685 		printf("Error: %s\n", status2str(status));
   1686 	}
   1687 
   1688 	raw_dump(level, frm);
   1689 }
   1690 
   1691 static inline void status_mode_dump(int level, struct frame *frm)
   1692 {
   1693 	uint8_t status = get_u8(frm);
   1694 	uint8_t mode = get_u8(frm);
   1695 
   1696 	p_indent(level, frm);
   1697 	printf("status 0x%2.2x mode 0x%2.2x\n", status, mode);
   1698 
   1699 	if (status > 0) {
   1700 		p_indent(level, frm);
   1701 		printf("Error: %s\n", status2str(status));
   1702 	}
   1703 }
   1704 
   1705 static inline void read_link_policy_dump(int level, struct frame *frm)
   1706 {
   1707 	read_link_policy_rp *rp = frm->ptr;
   1708 	uint16_t policy = btohs(rp->policy);
   1709 	char *str;
   1710 
   1711 	p_indent(level, frm);
   1712 	printf("status 0x%2.2x handle %d policy 0x%2.2x\n",
   1713 				rp->status, btohs(rp->handle), policy);
   1714 
   1715 	if (rp->status > 0) {
   1716 		p_indent(level, frm);
   1717 		printf("Error: %s\n", status2str(rp->status));
   1718 	} else {
   1719 		str = hci_lptostr(policy);
   1720 		if (str) {
   1721 			p_indent(level, frm);
   1722 			printf("Link policy: %s\n", str);
   1723 			free(str);
   1724 		}
   1725 	}
   1726 }
   1727 
   1728 static inline void read_default_link_policy_dump(int level, struct frame *frm)
   1729 {
   1730 	uint8_t status = get_u8(frm);
   1731 	uint16_t policy = btohs(htons(get_u16(frm)));
   1732 	char *str;
   1733 
   1734 	p_indent(level, frm);
   1735 	printf("status 0x%2.2x policy 0x%2.2x\n", status, policy);
   1736 
   1737 	if (status > 0) {
   1738 		p_indent(level, frm);
   1739 		printf("Error: %s\n", status2str(status));
   1740 	} else {
   1741 		str = hci_lptostr(policy);
   1742 		if (str) {
   1743 			p_indent(level, frm);
   1744 			printf("Link policy: %s\n", str);
   1745 			free(str);
   1746 		}
   1747 	}
   1748 }
   1749 
   1750 static inline void read_pin_type_dump(int level, struct frame *frm)
   1751 {
   1752 	read_pin_type_rp *rp = frm->ptr;
   1753 
   1754 	p_indent(level, frm);
   1755 	printf("status 0x%2.2x type %d\n", rp->status, rp->pin_type);
   1756 
   1757 	if (rp->status > 0) {
   1758 		p_indent(level, frm);
   1759 		printf("Error: %s\n", status2str(rp->status));
   1760 	}
   1761 }
   1762 
   1763 static inline void read_stored_link_key_dump(int level, struct frame *frm)
   1764 {
   1765 	read_stored_link_key_rp *rp = frm->ptr;
   1766 
   1767 	p_indent(level, frm);
   1768 	printf("status 0x%2.2x max %d num %d\n",
   1769 				rp->status, rp->max_keys, rp->num_keys);
   1770 
   1771 	if (rp->status > 0) {
   1772 		p_indent(level, frm);
   1773 		printf("Error: %s\n", status2str(rp->status));
   1774 	}
   1775 }
   1776 
   1777 static inline void write_stored_link_key_dump(int level, struct frame *frm)
   1778 {
   1779 	write_stored_link_key_rp *rp = frm->ptr;
   1780 
   1781 	p_indent(level, frm);
   1782 	printf("status 0x%2.2x written %d\n", rp->status, rp->num_keys);
   1783 
   1784 	if (rp->status > 0) {
   1785 		p_indent(level, frm);
   1786 		printf("Error: %s\n", status2str(rp->status));
   1787 	}
   1788 }
   1789 
   1790 static inline void delete_stored_link_key_dump(int level, struct frame *frm)
   1791 {
   1792 	delete_stored_link_key_rp *rp = frm->ptr;
   1793 
   1794 	p_indent(level, frm);
   1795 	printf("status 0x%2.2x deleted %d\n", rp->status, btohs(rp->num_keys));
   1796 
   1797 	if (rp->status > 0) {
   1798 		p_indent(level, frm);
   1799 		printf("Error: %s\n", status2str(rp->status));
   1800 	}
   1801 }
   1802 
   1803 static inline void read_local_name_dump(int level, struct frame *frm)
   1804 {
   1805 	read_local_name_rp *rp = frm->ptr;
   1806 	char name[249];
   1807 	int i;
   1808 
   1809 	memset(name, 0, sizeof(name));
   1810 	for (i = 0; i < 248 && rp->name[i]; i++)
   1811 		if (isprint(rp->name[i]))
   1812 			name[i] = rp->name[i];
   1813 		else
   1814 			name[i] = '.';
   1815 
   1816 	p_indent(level, frm);
   1817 	printf("status 0x%2.2x name \'%s\'\n", rp->status, name);
   1818 
   1819 	if (rp->status > 0) {
   1820 		p_indent(level, frm);
   1821 		printf("Error: %s\n", status2str(rp->status));
   1822 	}
   1823 }
   1824 
   1825 static inline void read_class_of_dev_dump(int level, struct frame *frm)
   1826 {
   1827 	read_class_of_dev_rp *rp = frm->ptr;
   1828 
   1829 	p_indent(level, frm);
   1830 	printf("status 0x%2.2x class 0x%2.2x%2.2x%2.2x\n", rp->status,
   1831 			rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
   1832 
   1833 	if (rp->status > 0) {
   1834 		p_indent(level, frm);
   1835 		printf("Error: %s\n", status2str(rp->status));
   1836 	}
   1837 }
   1838 
   1839 static inline void read_voice_setting_dump(int level, struct frame *frm)
   1840 {
   1841 	read_voice_setting_rp *rp = frm->ptr;
   1842 
   1843 	p_indent(level, frm);
   1844 	printf("status 0x%2.2x voice setting 0x%4.4x\n",
   1845 					rp->status, btohs(rp->voice_setting));
   1846 
   1847 	if (rp->status > 0) {
   1848 		p_indent(level, frm);
   1849 		printf("Error: %s\n", status2str(rp->status));
   1850 	}
   1851 }
   1852 
   1853 static inline void read_current_iac_lap_dump(int level, struct frame *frm)
   1854 {
   1855 	read_current_iac_lap_rp *rp = frm->ptr;
   1856 	int i;
   1857 
   1858 	for (i = 0; i < rp->num_current_iac; i++) {
   1859 		p_indent(level, frm);
   1860 		printf("IAC 0x%2.2x%2.2x%2.2x", rp->lap[i][2], rp->lap[i][1], rp->lap[i][0]);
   1861 		if (rp->lap[i][2] == 0x9e && rp->lap[i][1] == 0x8b) {
   1862 			switch (rp->lap[i][0]) {
   1863 			case 0x00:
   1864 				printf(" (Limited Inquiry Access Code)");
   1865 				break;
   1866 			case 0x33:
   1867 				printf(" (General Inquiry Access Code)");
   1868 				break;
   1869 			}
   1870 		}
   1871 		printf("\n");
   1872 	}
   1873 }
   1874 
   1875 static inline void read_scan_enable_dump(int level, struct frame *frm)
   1876 {
   1877 	uint8_t status = get_u8(frm);
   1878 	uint8_t enable = get_u8(frm);
   1879 
   1880 	p_indent(level, frm);
   1881 	printf("status 0x%2.2x enable %d\n", status, enable);
   1882 
   1883 	if (status > 0) {
   1884 		p_indent(level, frm);
   1885 		printf("Error: %s\n", status2str(status));
   1886 	}
   1887 }
   1888 
   1889 static inline void read_page_timeout_dump(int level, struct frame *frm)
   1890 {
   1891 	read_page_timeout_rp *rp = frm->ptr;
   1892 
   1893 	p_indent(level, frm);
   1894 	printf("status 0x%2.2x timeout %d\n", rp->status, btohs(rp->timeout));
   1895 
   1896 	if (rp->status > 0) {
   1897 		p_indent(level, frm);
   1898 		printf("Error: %s\n", status2str(rp->status));
   1899 	}
   1900 }
   1901 
   1902 static inline void read_page_activity_dump(int level, struct frame *frm)
   1903 {
   1904 	read_page_activity_rp *rp = frm->ptr;
   1905 
   1906 	p_indent(level, frm);
   1907 	printf("status 0x%2.2x interval %d window %d\n",
   1908 			rp->status, btohs(rp->interval), btohs(rp->window));
   1909 
   1910 	if (rp->status > 0) {
   1911 		p_indent(level, frm);
   1912 		printf("Error: %s\n", status2str(rp->status));
   1913 	}
   1914 }
   1915 
   1916 static inline void read_inquiry_scan_type_dump(int level, struct frame *frm)
   1917 {
   1918 	read_inquiry_scan_type_rp *rp = frm->ptr;
   1919 
   1920 	p_indent(level, frm);
   1921 	printf("status 0x%2.2x type %d\n", rp->status, rp->type);
   1922 
   1923 	if (rp->status > 0) {
   1924 		p_indent(level, frm);
   1925 		printf("Error: %s\n", status2str(rp->status));
   1926 	}
   1927 }
   1928 
   1929 static inline void read_inquiry_mode_dump(int level, struct frame *frm)
   1930 {
   1931 	read_inquiry_mode_rp *rp = frm->ptr;
   1932 
   1933 	p_indent(level, frm);
   1934 	printf("status 0x%2.2x mode %d\n", rp->status, rp->mode);
   1935 
   1936 	if (rp->status > 0) {
   1937 		p_indent(level, frm);
   1938 		printf("Error: %s\n", status2str(rp->status));
   1939 	}
   1940 }
   1941 
   1942 static inline void read_link_supervision_timeout_dump(int level, struct frame *frm)
   1943 {
   1944 	read_link_supervision_timeout_rp *rp = frm->ptr;
   1945 
   1946 	p_indent(level, frm);
   1947 	printf("status 0x%2.2x handle %d timeout %d\n",
   1948 			rp->status, btohs(rp->handle), btohs(rp->timeout));
   1949 
   1950 	if (rp->status > 0) {
   1951 		p_indent(level, frm);
   1952 		printf("Error: %s\n", status2str(rp->status));
   1953 	}
   1954 }
   1955 
   1956 static inline void read_transmit_power_level_dump(int level, struct frame *frm)
   1957 {
   1958 	read_transmit_power_level_rp *rp = frm->ptr;
   1959 
   1960 	p_indent(level, frm);
   1961 	printf("status 0x%2.2x handle %d level %d\n",
   1962 				rp->status, btohs(rp->handle), rp->level);
   1963 
   1964 	if (rp->status > 0) {
   1965 		p_indent(level, frm);
   1966 		printf("Error: %s\n", status2str(rp->status));
   1967 	}
   1968 }
   1969 
   1970 static inline void read_ext_inquiry_response_dump(int level, struct frame *frm)
   1971 {
   1972 	read_ext_inquiry_response_rp *rp = frm->ptr;
   1973 
   1974 	p_indent(level, frm);
   1975 	printf("status 0x%2.2x fec 0x%2.2x\n", rp->status, rp->fec);
   1976 
   1977 	if (rp->status > 0) {
   1978 		p_indent(level, frm);
   1979 		printf("Error: %s\n", status2str(rp->status));
   1980 	} else {
   1981 		frm->ptr += 2;
   1982 		frm->len -= 2;
   1983 
   1984 		ext_inquiry_response_dump(level, frm);
   1985 	}
   1986 }
   1987 
   1988 static inline void read_inquiry_transmit_power_level_dump(int level, struct frame *frm)
   1989 {
   1990 	read_inquiry_transmit_power_level_rp *rp = frm->ptr;
   1991 
   1992 	p_indent(level, frm);
   1993 	printf("status 0x%2.2x level %d\n", rp->status, rp->level);
   1994 
   1995 	if (rp->status > 0) {
   1996 		p_indent(level, frm);
   1997 		printf("Error: %s\n", status2str(rp->status));
   1998 	}
   1999 }
   2000 
   2001 static inline void read_default_error_data_reporting_dump(int level, struct frame *frm)
   2002 {
   2003 	read_default_error_data_reporting_rp *rp = frm->ptr;
   2004 
   2005 	p_indent(level, frm);
   2006 	printf("status 0x%2.2x reporting %d\n", rp->status, rp->reporting);
   2007 
   2008 	if (rp->status > 0) {
   2009 		p_indent(level, frm);
   2010 		printf("Error: %s\n", status2str(rp->status));
   2011 	}
   2012 }
   2013 
   2014 static inline void read_local_oob_data_dump(int level, struct frame *frm)
   2015 {
   2016 	read_local_oob_data_rp *rp = frm->ptr;
   2017 	int i;
   2018 
   2019 	p_indent(level, frm);
   2020 	printf("status 0x%2.2x\n", rp->status);
   2021 
   2022 	if (rp->status > 0) {
   2023 		p_indent(level, frm);
   2024 		printf("Error: %s\n", status2str(rp->status));
   2025 	} else {
   2026 		p_indent(level, frm);
   2027 		printf("hash 0x");
   2028 		for (i = 0; i < 16; i++)
   2029 			printf("%02x", rp->hash[i]);
   2030 		printf("\n");
   2031 
   2032 		p_indent(level, frm);
   2033 		printf("randomizer 0x");
   2034 		for (i = 0; i < 16; i++)
   2035 			printf("%02x", rp->randomizer[i]);
   2036 		printf("\n");
   2037 	}
   2038 }
   2039 
   2040 static inline void read_local_version_dump(int level, struct frame *frm)
   2041 {
   2042 	read_local_version_rp *rp = frm->ptr;
   2043 	uint16_t manufacturer = btohs(rp->manufacturer);
   2044 
   2045 	p_indent(level, frm);
   2046 	printf("status 0x%2.2x\n", rp->status);
   2047 
   2048 	if (rp->status > 0) {
   2049 		p_indent(level, frm);
   2050 		printf("Error: %s\n", status2str(rp->status));
   2051 	} else {
   2052 		p_indent(level, frm);
   2053 		printf("HCI Version: %s (0x%x) HCI Revision: 0x%x\n",
   2054 					hci_vertostr(rp->hci_ver),
   2055 					rp->hci_ver, btohs(rp->hci_rev));
   2056 		p_indent(level, frm);
   2057 		printf("LMP Version: %s (0x%x) LMP Subversion: 0x%x\n",
   2058 					lmp_vertostr(rp->lmp_ver),
   2059 					rp->lmp_ver, btohs(rp->lmp_subver));
   2060 		p_indent(level, frm);
   2061 		printf("Manufacturer: %s (%d)\n",
   2062 				bt_compidtostr(manufacturer), manufacturer);
   2063 	}
   2064 }
   2065 
   2066 static inline void read_local_commands_dump(int level, struct frame *frm)
   2067 {
   2068 	read_local_commands_rp *rp = frm->ptr;
   2069 	int i, max = 0;
   2070 
   2071 	p_indent(level, frm);
   2072 	printf("status 0x%2.2x\n", rp->status);
   2073 
   2074 	if (rp->status > 0) {
   2075 		p_indent(level, frm);
   2076 		printf("Error: %s\n", status2str(rp->status));
   2077 	} else {
   2078 		for (i = 0; i < 64; i++)
   2079 			if (rp->commands[i])
   2080 				max = i + 1;
   2081 		p_indent(level, frm);
   2082 		printf("Commands: ");
   2083 		for (i = 0; i < (max > 32 ? 32 : max); i++)
   2084 			printf("%2.2x", rp->commands[i]);
   2085 		printf("\n");
   2086 		if (max > 32) {
   2087 			p_indent(level, frm);
   2088 			printf("          ");
   2089 			for (i = 32; i < max; i++)
   2090 				printf("%2.2x", rp->commands[i]);
   2091 			printf("\n");
   2092 		}
   2093 	}
   2094 }
   2095 
   2096 static inline void read_local_features_dump(int level, struct frame *frm)
   2097 {
   2098 	read_local_features_rp *rp = frm->ptr;
   2099 	int i;
   2100 
   2101 	p_indent(level, frm);
   2102 	printf("status 0x%2.2x\n", rp->status);
   2103 
   2104 	if (rp->status > 0) {
   2105 		p_indent(level, frm);
   2106 		printf("Error: %s\n", status2str(rp->status));
   2107 	} else {
   2108 		p_indent(level, frm);
   2109 		printf("Features:");
   2110 		for (i = 0; i < 8; i++)
   2111 			printf(" 0x%2.2x", rp->features[i]);
   2112 		printf("\n");
   2113 	}
   2114 }
   2115 
   2116 static inline void read_local_ext_features_dump(int level, struct frame *frm)
   2117 {
   2118 	read_local_ext_features_rp *rp = frm->ptr;
   2119 	int i;
   2120 
   2121 	p_indent(level, frm);
   2122 	printf("status 0x%2.2x page %d max %d\n",
   2123 		rp->status, rp->page_num, rp->max_page_num);
   2124 
   2125 	if (rp->status > 0) {
   2126 		p_indent(level, frm);
   2127 		printf("Error: %s\n", status2str(rp->status));
   2128 	} else {
   2129 		p_indent(level, frm);
   2130 		printf("Features:");
   2131 		for (i = 0; i < 8; i++)
   2132 			 printf(" 0x%2.2x", rp->features[i]);
   2133 		printf("\n");
   2134 	}
   2135 }
   2136 
   2137 static inline void read_buffer_size_dump(int level, struct frame *frm)
   2138 {
   2139 	read_buffer_size_rp *rp = frm->ptr;
   2140 
   2141 	p_indent(level, frm);
   2142 	printf("status 0x%2.2x\n", rp->status);
   2143 
   2144 	if (rp->status > 0) {
   2145 		p_indent(level, frm);
   2146 		printf("Error: %s\n", status2str(rp->status));
   2147 	} else {
   2148 		p_indent(level, frm);
   2149 		printf("ACL MTU %d:%d SCO MTU %d:%d\n",
   2150 				btohs(rp->acl_mtu), btohs(rp->acl_max_pkt),
   2151 				rp->sco_mtu, btohs(rp->sco_max_pkt));
   2152 	}
   2153 }
   2154 
   2155 static inline void read_link_quality_dump(int level, struct frame *frm)
   2156 {
   2157 	read_link_quality_rp *rp = frm->ptr;
   2158 
   2159 	p_indent(level, frm);
   2160 	printf("status 0x%2.2x handle %d lq %d\n",
   2161 			rp->status, btohs(rp->handle), rp->link_quality);
   2162 
   2163 	if (rp->status > 0) {
   2164 		p_indent(level, frm);
   2165 		printf("Error: %s\n", status2str(rp->status));
   2166 	}
   2167 }
   2168 
   2169 static inline void read_rssi_dump(int level, struct frame *frm)
   2170 {
   2171 	read_rssi_rp *rp = frm->ptr;
   2172 
   2173 	p_indent(level, frm);
   2174 	printf("status 0x%2.2x handle %d rssi %d\n",
   2175 				rp->status, btohs(rp->handle), rp->rssi);
   2176 
   2177 	if (rp->status > 0) {
   2178 		p_indent(level, frm);
   2179 		printf("Error: %s\n", status2str(rp->status));
   2180 	}
   2181 }
   2182 
   2183 static inline void read_afh_map_dump(int level, struct frame *frm)
   2184 {
   2185 	read_afh_map_rp *rp = frm->ptr;
   2186 	int i;
   2187 
   2188 	p_indent(level, frm);
   2189 	printf("status 0x%2.2x handle %d mode %d\n",
   2190 				rp->status, btohs(rp->handle), rp->mode);
   2191 
   2192 	if (rp->status > 0) {
   2193 		p_indent(level, frm);
   2194 		printf("Error: %s\n", status2str(rp->status));
   2195 	} else {
   2196 		p_indent(level, frm);
   2197 		printf("AFH map: 0x");
   2198 		for (i = 0; i < 10; i++)
   2199 			printf("%2.2x", rp->map[i]);
   2200 		printf("\n");
   2201 	}
   2202 }
   2203 
   2204 static inline void read_clock_dump(int level, struct frame *frm)
   2205 {
   2206 	read_clock_rp *rp = frm->ptr;
   2207 
   2208 	p_indent(level, frm);
   2209 	printf("status 0x%2.2x handle %d clock 0x%4.4x accuracy %d\n",
   2210 					rp->status, btohs(rp->handle),
   2211 					btohl(rp->clock), btohs(rp->accuracy));
   2212 
   2213 	if (rp->status > 0) {
   2214 		p_indent(level, frm);
   2215 		printf("Error: %s\n", status2str(rp->status));
   2216 	}
   2217 }
   2218 
   2219 static inline void cmd_complete_dump(int level, struct frame *frm)
   2220 {
   2221 	evt_cmd_complete *evt = frm->ptr;
   2222 	uint16_t opcode = btohs(evt->opcode);
   2223 	uint16_t ogf = cmd_opcode_ogf(opcode);
   2224 	uint16_t ocf = cmd_opcode_ocf(opcode);
   2225 
   2226 	if (ogf == OGF_VENDOR_CMD && (parser.flags & DUMP_NOVENDOR))
   2227 		return;
   2228 
   2229 	p_indent(level, frm);
   2230 	printf("%s (0x%2.2x|0x%4.4x) ncmd %d\n",
   2231 				opcode2str(opcode), ogf, ocf, evt->ncmd);
   2232 
   2233 	frm->ptr += EVT_CMD_COMPLETE_SIZE;
   2234 	frm->len -= EVT_CMD_COMPLETE_SIZE;
   2235 
   2236 	if (!(parser.flags & DUMP_VERBOSE)) {
   2237 		raw_dump(level, frm);
   2238 		return;
   2239 	}
   2240 
   2241 	switch (ogf) {
   2242 	case OGF_LINK_CTL:
   2243 		switch (ocf) {
   2244 		case OCF_INQUIRY_CANCEL:
   2245 		case OCF_PERIODIC_INQUIRY:
   2246 		case OCF_EXIT_PERIODIC_INQUIRY:
   2247 		case OCF_READ_REMOTE_EXT_FEATURES:
   2248 			status_response_dump(level, frm);
   2249 			return;
   2250 		case OCF_CREATE_CONN_CANCEL:
   2251 		case OCF_REMOTE_NAME_REQ_CANCEL:
   2252 		case OCF_PIN_CODE_REPLY:
   2253 		case OCF_LINK_KEY_REPLY:
   2254 		case OCF_PIN_CODE_NEG_REPLY:
   2255 		case OCF_LINK_KEY_NEG_REPLY:
   2256 		case OCF_USER_CONFIRM_REPLY:
   2257 		case OCF_USER_CONFIRM_NEG_REPLY:
   2258 		case OCF_USER_PASSKEY_REPLY:
   2259 		case OCF_USER_PASSKEY_NEG_REPLY:
   2260 		case OCF_REMOTE_OOB_DATA_REPLY:
   2261 		case OCF_REMOTE_OOB_DATA_NEG_REPLY:
   2262 		case OCF_IO_CAPABILITY_REPLY:
   2263 		case OCF_IO_CAPABILITY_NEG_REPLY:
   2264 			bdaddr_response_dump(level, frm);
   2265 			return;
   2266 		}
   2267 		break;
   2268 
   2269 	case OGF_LINK_POLICY:
   2270 		switch (ocf) {
   2271 		case OCF_READ_LINK_POLICY:
   2272 			read_link_policy_dump(level, frm);
   2273 			return;
   2274 		case OCF_WRITE_LINK_POLICY:
   2275 		case OCF_SNIFF_SUBRATING:
   2276 			generic_response_dump(level, frm);
   2277 			return;
   2278 		case OCF_READ_DEFAULT_LINK_POLICY:
   2279 			read_default_link_policy_dump(level, frm);
   2280 			return;
   2281 		case OCF_WRITE_DEFAULT_LINK_POLICY:
   2282 			status_response_dump(level, frm);
   2283 			return;
   2284 		}
   2285 		break;
   2286 
   2287 	case OGF_HOST_CTL:
   2288 		switch (ocf) {
   2289 		case OCF_READ_PIN_TYPE:
   2290 			read_pin_type_dump(level, frm);
   2291 			return;
   2292 		case OCF_READ_STORED_LINK_KEY:
   2293 			read_stored_link_key_dump(level, frm);
   2294 			return;
   2295 		case OCF_WRITE_STORED_LINK_KEY:
   2296 			write_stored_link_key_dump(level, frm);
   2297 			return;
   2298 		case OCF_DELETE_STORED_LINK_KEY:
   2299 			delete_stored_link_key_dump(level, frm);
   2300 			return;
   2301 		case OCF_READ_LOCAL_NAME:
   2302 			read_local_name_dump(level, frm);
   2303 			return;
   2304 		case OCF_READ_CLASS_OF_DEV:
   2305 			read_class_of_dev_dump(level, frm);
   2306 			return;
   2307 		case OCF_READ_VOICE_SETTING:
   2308 			read_voice_setting_dump(level, frm);
   2309 			return;
   2310 		case OCF_READ_CURRENT_IAC_LAP:
   2311 			read_current_iac_lap_dump(level, frm);
   2312 			return;
   2313 		case OCF_READ_SCAN_ENABLE:
   2314 		case OCF_READ_AUTH_ENABLE:
   2315 			read_scan_enable_dump(level, frm);
   2316 			return;
   2317 		case OCF_READ_CONN_ACCEPT_TIMEOUT:
   2318 		case OCF_READ_PAGE_TIMEOUT:
   2319 			read_page_timeout_dump(level, frm);
   2320 			return;
   2321 		case OCF_READ_PAGE_ACTIVITY:
   2322 		case OCF_READ_INQ_ACTIVITY:
   2323 			read_page_activity_dump(level, frm);
   2324 			return;
   2325 		case OCF_READ_INQUIRY_SCAN_TYPE:
   2326 			read_inquiry_scan_type_dump(level, frm);
   2327 			return;
   2328 		case OCF_READ_ENCRYPT_MODE:
   2329 		case OCF_READ_INQUIRY_MODE:
   2330 		case OCF_READ_AFH_MODE:
   2331 			read_inquiry_mode_dump(level, frm);
   2332 			return;
   2333 		case OCF_READ_LINK_SUPERVISION_TIMEOUT:
   2334 			read_link_supervision_timeout_dump(level, frm);
   2335 			return;
   2336 		case OCF_READ_TRANSMIT_POWER_LEVEL:
   2337 			read_transmit_power_level_dump(level, frm);
   2338 			return;
   2339 		case OCF_READ_EXT_INQUIRY_RESPONSE:
   2340 			read_ext_inquiry_response_dump(level, frm);
   2341 			return;
   2342 		case OCF_READ_INQUIRY_TRANSMIT_POWER_LEVEL:
   2343 			read_inquiry_transmit_power_level_dump(level, frm);
   2344 			return;
   2345 		case OCF_READ_DEFAULT_ERROR_DATA_REPORTING:
   2346 			read_default_error_data_reporting_dump(level, frm);
   2347 			return;
   2348 		case OCF_READ_LOCAL_OOB_DATA:
   2349 			read_local_oob_data_dump(level, frm);
   2350 			return;
   2351 		case OCF_READ_SIMPLE_PAIRING_MODE:
   2352 			status_mode_dump(level, frm);
   2353 			return;
   2354 		case OCF_FLUSH:
   2355 		case OCF_WRITE_LINK_SUPERVISION_TIMEOUT:
   2356 			generic_response_dump(level, frm);
   2357 			return;
   2358 		case OCF_RESET:
   2359 		case OCF_SET_EVENT_MASK:
   2360 		case OCF_SET_EVENT_FLT:
   2361 		case OCF_WRITE_PIN_TYPE:
   2362 		case OCF_CREATE_NEW_UNIT_KEY:
   2363 		case OCF_CHANGE_LOCAL_NAME:
   2364 		case OCF_WRITE_CLASS_OF_DEV:
   2365 		case OCF_WRITE_VOICE_SETTING:
   2366 		case OCF_WRITE_CURRENT_IAC_LAP:
   2367 		case OCF_WRITE_SCAN_ENABLE:
   2368 		case OCF_WRITE_AUTH_ENABLE:
   2369 		case OCF_WRITE_ENCRYPT_MODE:
   2370 		case OCF_WRITE_CONN_ACCEPT_TIMEOUT:
   2371 		case OCF_WRITE_PAGE_TIMEOUT:
   2372 		case OCF_WRITE_PAGE_ACTIVITY:
   2373 		case OCF_WRITE_INQ_ACTIVITY:
   2374 		case OCF_WRITE_INQUIRY_SCAN_TYPE:
   2375 		case OCF_WRITE_INQUIRY_MODE:
   2376 		case OCF_WRITE_AFH_MODE:
   2377 		case OCF_SET_AFH_CLASSIFICATION:
   2378 		case OCF_WRITE_EXT_INQUIRY_RESPONSE:
   2379 		case OCF_WRITE_SIMPLE_PAIRING_MODE:
   2380 		case OCF_WRITE_INQUIRY_TRANSMIT_POWER_LEVEL:
   2381 		case OCF_WRITE_DEFAULT_ERROR_DATA_REPORTING:
   2382 		case OCF_SET_CONTROLLER_TO_HOST_FC:
   2383 		case OCF_HOST_BUFFER_SIZE:
   2384 		case OCF_REFRESH_ENCRYPTION_KEY:
   2385 		case OCF_SEND_KEYPRESS_NOTIFY:
   2386 			status_response_dump(level, frm);
   2387 			return;
   2388 		}
   2389 		break;
   2390 
   2391 	case OGF_INFO_PARAM:
   2392 		switch (ocf) {
   2393 		case OCF_READ_LOCAL_VERSION:
   2394 			read_local_version_dump(level, frm);
   2395 			return;
   2396 		case OCF_READ_LOCAL_COMMANDS:
   2397 			read_local_commands_dump(level, frm);
   2398 			return;
   2399 		case OCF_READ_LOCAL_FEATURES:
   2400 			read_local_features_dump(level, frm);
   2401 			return;
   2402 		case OCF_READ_LOCAL_EXT_FEATURES:
   2403 			read_local_ext_features_dump(level, frm);
   2404 			return;
   2405 		case OCF_READ_BUFFER_SIZE:
   2406 			read_buffer_size_dump(level, frm);
   2407 			return;
   2408 		case OCF_READ_BD_ADDR:
   2409 			bdaddr_response_dump(level, frm);
   2410 			return;
   2411 		}
   2412 		break;
   2413 
   2414 	case OGF_STATUS_PARAM:
   2415 		switch (ocf) {
   2416 		case OCF_READ_FAILED_CONTACT_COUNTER:
   2417 		case OCF_RESET_FAILED_CONTACT_COUNTER:
   2418 			status_response_dump(level, frm);
   2419 			return;
   2420 		case OCF_READ_LINK_QUALITY:
   2421 			read_link_quality_dump(level, frm);
   2422 			return;
   2423 		case OCF_READ_RSSI:
   2424 			read_rssi_dump(level, frm);
   2425 			return;
   2426 		case OCF_READ_AFH_MAP:
   2427 			read_afh_map_dump(level, frm);
   2428 			return;
   2429 		case OCF_READ_CLOCK:
   2430 			read_clock_dump(level, frm);
   2431 			return;
   2432 		}
   2433 		break;
   2434 
   2435 	case OGF_TESTING_CMD:
   2436 		switch (ocf) {
   2437 		case OCF_READ_LOOPBACK_MODE:
   2438 			status_mode_dump(level, frm);
   2439 			return;
   2440 		case OCF_WRITE_LOOPBACK_MODE:
   2441 		case OCF_ENABLE_DEVICE_UNDER_TEST_MODE:
   2442 		case OCF_WRITE_SIMPLE_PAIRING_DEBUG_MODE:
   2443 			status_response_dump(level, frm);
   2444 			return;
   2445 		}
   2446 		break;
   2447 	}
   2448 
   2449 	raw_dump(level, frm);
   2450 }
   2451 
   2452 static inline void cmd_status_dump(int level, struct frame *frm)
   2453 {
   2454 	evt_cmd_status *evt = frm->ptr;
   2455 	uint16_t opcode = btohs(evt->opcode);
   2456 	uint16_t ogf = cmd_opcode_ogf(opcode);
   2457 	uint16_t ocf = cmd_opcode_ocf(opcode);
   2458 
   2459 	if (ogf == OGF_VENDOR_CMD && (parser.flags & DUMP_NOVENDOR))
   2460 		return;
   2461 
   2462 	p_indent(level, frm);
   2463 	printf("%s (0x%2.2x|0x%4.4x) status 0x%2.2x ncmd %d\n",
   2464 			opcode2str(opcode), ogf, ocf, evt->status, evt->ncmd);
   2465 
   2466 	if (evt->status > 0) {
   2467 		p_indent(level, frm);
   2468 		printf("Error: %s\n", status2str(evt->status));
   2469 	}
   2470 }
   2471 
   2472 static inline void hardware_error_dump(int level, struct frame *frm)
   2473 {
   2474 	evt_hardware_error *evt = frm->ptr;
   2475 
   2476 	p_indent(level, frm);
   2477 	printf("code %d\n", evt->code);
   2478 }
   2479 
   2480 static inline void inq_result_dump(int level, struct frame *frm)
   2481 {
   2482 	uint8_t num = get_u8(frm);
   2483 	char addr[18];
   2484 	int i;
   2485 
   2486 	for (i = 0; i < num; i++) {
   2487 		inquiry_info *info = frm->ptr;
   2488 
   2489 		p_ba2str(&info->bdaddr, addr);
   2490 
   2491 		p_indent(level, frm);
   2492 		printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x\n",
   2493 			addr, info->pscan_rep_mode, btohs(info->clock_offset),
   2494 			info->dev_class[2], info->dev_class[1], info->dev_class[0]);
   2495 
   2496 		frm->ptr += INQUIRY_INFO_SIZE;
   2497 		frm->len -= INQUIRY_INFO_SIZE;
   2498 	}
   2499 }
   2500 
   2501 static inline void conn_complete_dump(int level, struct frame *frm)
   2502 {
   2503 	evt_conn_complete *evt = frm->ptr;
   2504 	char addr[18];
   2505 
   2506 	p_ba2str(&evt->bdaddr, addr);
   2507 
   2508 	p_indent(level, frm);
   2509 	printf("status 0x%2.2x handle %d bdaddr %s type %s encrypt 0x%2.2x\n",
   2510 			evt->status, btohs(evt->handle), addr,
   2511 			linktype2str(evt->link_type), evt->encr_mode);
   2512 
   2513 	if (evt->status > 0) {
   2514 		p_indent(level, frm);
   2515 		printf("Error: %s\n", status2str(evt->status));
   2516 	}
   2517 }
   2518 
   2519 static inline void conn_request_dump(int level, struct frame *frm)
   2520 {
   2521 	evt_conn_request *evt = frm->ptr;
   2522 	char addr[18];
   2523 
   2524 	p_ba2str(&evt->bdaddr, addr);
   2525 
   2526 	p_indent(level, frm);
   2527 	printf("bdaddr %s class 0x%2.2x%2.2x%2.2x type %s\n",
   2528 			addr, evt->dev_class[2], evt->dev_class[1],
   2529 			evt->dev_class[0], linktype2str(evt->link_type));
   2530 }
   2531 
   2532 static inline void disconn_complete_dump(int level, struct frame *frm)
   2533 {
   2534 	evt_disconn_complete *evt = frm->ptr;
   2535 
   2536 	p_indent(level, frm);
   2537 	printf("status 0x%2.2x handle %d reason 0x%2.2x\n",
   2538 				evt->status, btohs(evt->handle), evt->reason);
   2539 
   2540 	if (evt->status > 0) {
   2541 		p_indent(level, frm);
   2542 		printf("Error: %s\n", status2str(evt->status));
   2543 	} else if (evt->reason > 0) {
   2544 		p_indent(level, frm);
   2545 		printf("Reason: %s\n", status2str(evt->reason));
   2546 	}
   2547 }
   2548 
   2549 static inline void remote_name_req_complete_dump(int level, struct frame *frm)
   2550 {
   2551 	evt_remote_name_req_complete *evt = frm->ptr;
   2552 	char addr[18], name[249];
   2553 	int i;
   2554 
   2555 	p_ba2str(&evt->bdaddr, addr);
   2556 
   2557 	memset(name, 0, sizeof(name));
   2558 	for (i = 0; i < 248 && evt->name[i]; i++)
   2559 		if (isprint(evt->name[i]))
   2560 			name[i] = evt->name[i];
   2561 		else
   2562 			name[i] = '.';
   2563 
   2564 	p_indent(level, frm);
   2565 	printf("status 0x%2.2x bdaddr %s name '%s'\n", evt->status, addr, name);
   2566 
   2567 	if (evt->status > 0) {
   2568 		p_indent(level, frm);
   2569 		printf("Error: %s\n", status2str(evt->status));
   2570 	}
   2571 }
   2572 
   2573 static inline void master_link_key_complete_dump(int level, struct frame *frm)
   2574 {
   2575 	evt_master_link_key_complete *evt = frm->ptr;
   2576 
   2577 	p_indent(level, frm);
   2578 	printf("status 0x%2.2x handle %d flag %d\n",
   2579 				evt->status, btohs(evt->handle), evt->key_flag);
   2580 
   2581 	if (evt->status > 0) {
   2582 		p_indent(level, frm);
   2583 		printf("Error: %s\n", status2str(evt->status));
   2584 	}
   2585 }
   2586 
   2587 static inline void encrypt_change_dump(int level, struct frame *frm)
   2588 {
   2589 	evt_encrypt_change *evt = frm->ptr;
   2590 
   2591 	p_indent(level, frm);
   2592 	printf("status 0x%2.2x handle %d encrypt 0x%2.2x\n",
   2593 				evt->status, btohs(evt->handle), evt->encrypt);
   2594 
   2595 	if (evt->status > 0) {
   2596 		p_indent(level, frm);
   2597 		printf("Error: %s\n", status2str(evt->status));
   2598 	}
   2599 }
   2600 
   2601 static inline void read_remote_features_complete_dump(int level, struct frame *frm)
   2602 {
   2603 	evt_read_remote_features_complete *evt = frm->ptr;
   2604 	int i;
   2605 
   2606 	p_indent(level, frm);
   2607 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   2608 
   2609 	if (evt->status > 0) {
   2610 		p_indent(level, frm);
   2611 		printf("Error: %s\n", status2str(evt->status));
   2612 	} else {
   2613 		p_indent(level, frm);
   2614 		printf("Features:");
   2615 		for (i = 0; i < 8; i++)
   2616 			printf(" 0x%2.2x", evt->features[i]);
   2617 		printf("\n");
   2618 	}
   2619 }
   2620 
   2621 static inline void read_remote_version_complete_dump(int level, struct frame *frm)
   2622 {
   2623 	evt_read_remote_version_complete *evt = frm->ptr;
   2624 	uint16_t manufacturer = btohs(evt->manufacturer);
   2625 
   2626 	p_indent(level, frm);
   2627 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   2628 
   2629 	if (evt->status > 0) {
   2630 		p_indent(level, frm);
   2631 		printf("Error: %s\n", status2str(evt->status));
   2632 	} else {
   2633 		p_indent(level, frm);
   2634 		printf("LMP Version: %s (0x%x) LMP Subversion: 0x%x\n",
   2635 			lmp_vertostr(evt->lmp_ver), evt->lmp_ver,
   2636 			btohs(evt->lmp_subver));
   2637 		p_indent(level, frm);
   2638 		printf("Manufacturer: %s (%d)\n",
   2639 			bt_compidtostr(manufacturer), manufacturer);
   2640 	}
   2641 }
   2642 
   2643 static inline void qos_setup_complete_dump(int level, struct frame *frm)
   2644 {
   2645 	evt_qos_setup_complete *evt = frm->ptr;
   2646 
   2647 	p_indent(level, frm);
   2648 	printf("status 0x%2.2x handle %d flags %d\n",
   2649 				evt->status, btohs(evt->handle), evt->flags);
   2650 
   2651 	if (evt->status > 0) {
   2652 		p_indent(level, frm);
   2653 		printf("Error: %s\n", status2str(evt->status));
   2654 	} else {
   2655 		p_indent(level, frm);
   2656 		printf("Service type: %d\n", evt->qos.service_type);
   2657 		p_indent(level, frm);
   2658 		printf("Token rate: %d\n", btohl(evt->qos.token_rate));
   2659 		p_indent(level, frm);
   2660 		printf("Peak bandwith: %d\n", btohl(evt->qos.peak_bandwidth));
   2661 		p_indent(level, frm);
   2662 		printf("Latency: %d\n", btohl(evt->qos.latency));
   2663 		p_indent(level, frm);
   2664 		printf("Delay variation: %d\n", btohl(evt->qos.delay_variation));
   2665 	}
   2666 }
   2667 
   2668 static inline void role_change_dump(int level, struct frame *frm)
   2669 {
   2670 	evt_role_change *evt = frm->ptr;
   2671 	char addr[18];
   2672 
   2673 	p_indent(level, frm);
   2674 	p_ba2str(&evt->bdaddr, addr);
   2675 	printf("status 0x%2.2x bdaddr %s role 0x%2.2x\n",
   2676 						evt->status, addr, evt->role);
   2677 
   2678 	if (evt->status > 0) {
   2679 		p_indent(level, frm);
   2680 		printf("Error: %s\n", status2str(evt->status));
   2681 	} else {
   2682 		p_indent(level, frm);
   2683 		printf("Role: %s\n", role2str(evt->role));
   2684 	}
   2685 }
   2686 
   2687 static inline void mode_change_dump(int level, struct frame *frm)
   2688 {
   2689 	evt_mode_change *evt = frm->ptr;
   2690 
   2691 	p_indent(level, frm);
   2692 	printf("status 0x%2.2x handle %d mode 0x%2.2x interval %d\n",
   2693 		evt->status, btohs(evt->handle), evt->mode, btohs(evt->interval));
   2694 
   2695 	if (evt->status > 0) {
   2696 		p_indent(level, frm);
   2697 		printf("Error: %s\n", status2str(evt->status));
   2698 	} else {
   2699 		p_indent(level, frm);
   2700 		printf("Mode: %s\n", mode2str(evt->mode));
   2701 	}
   2702 }
   2703 
   2704 static inline void pin_code_req_dump(int level, struct frame *frm)
   2705 {
   2706 	evt_pin_code_req *evt = frm->ptr;
   2707 	char addr[18];
   2708 
   2709 	p_indent(level, frm);
   2710 	p_ba2str(&evt->bdaddr, addr);
   2711 	printf("bdaddr %s\n", addr);
   2712 }
   2713 
   2714 static inline void link_key_notify_dump(int level, struct frame *frm)
   2715 {
   2716 	evt_link_key_notify *evt = frm->ptr;
   2717 	char addr[18];
   2718 	int i;
   2719 
   2720 	p_indent(level, frm);
   2721 	p_ba2str(&evt->bdaddr, addr);
   2722 	printf("bdaddr %s key ", addr);
   2723 	for (i = 0; i < 16; i++)
   2724 		if (parser.flags & DUMP_NOVENDOR)
   2725 			printf("**");
   2726 		else
   2727 			printf("%2.2X", evt->link_key[i]);
   2728 	printf(" type %d\n", evt->key_type);
   2729 
   2730 	p_indent(level, frm);
   2731 	printf("Type: %s\n", keytype2str(evt->key_type));
   2732 }
   2733 
   2734 static inline void max_slots_change_dump(int level, struct frame *frm)
   2735 {
   2736 	evt_max_slots_change *evt = frm->ptr;
   2737 
   2738 	p_indent(level, frm);
   2739 	printf("handle %d slots %d\n", btohs(evt->handle), evt->max_slots);
   2740 }
   2741 
   2742 static inline void data_buffer_overflow_dump(int level, struct frame *frm)
   2743 {
   2744 	evt_data_buffer_overflow *evt = frm->ptr;
   2745 
   2746 	p_indent(level, frm);
   2747 	printf("type %s\n", linktype2str(evt->link_type));
   2748 }
   2749 
   2750 static inline void read_clock_offset_complete_dump(int level, struct frame *frm)
   2751 {
   2752 	evt_read_clock_offset_complete *evt = frm->ptr;
   2753 
   2754 	p_indent(level, frm);
   2755 	printf("status 0x%2.2x handle %d clkoffset 0x%4.4x\n",
   2756 		evt->status, btohs(evt->handle), btohs(evt->clock_offset));
   2757 
   2758 	if (evt->status > 0) {
   2759 		p_indent(level, frm);
   2760 		printf("Error: %s\n", status2str(evt->status));
   2761 	}
   2762 }
   2763 
   2764 static inline void conn_ptype_changed_dump(int level, struct frame *frm)
   2765 {
   2766 	evt_conn_ptype_changed *evt = frm->ptr;
   2767 	uint16_t ptype = btohs(evt->ptype);
   2768 	char *str;
   2769 
   2770 	p_indent(level, frm);
   2771 	printf("status 0x%2.2x handle %d ptype 0x%4.4x\n",
   2772 				evt->status, btohs(evt->handle), ptype);
   2773 
   2774 	if (evt->status > 0) {
   2775 		p_indent(level, frm);
   2776 		printf("Error: %s\n", status2str(evt->status));
   2777 	} else {
   2778 		str = hci_ptypetostr(ptype);
   2779 		if (str) {
   2780 			p_indent(level, frm);
   2781 			printf("Packet type: %s\n", str);
   2782 			free(str);
   2783 		}
   2784 	}
   2785 }
   2786 
   2787 static inline void pscan_rep_mode_change_dump(int level, struct frame *frm)
   2788 {
   2789 	evt_pscan_rep_mode_change *evt = frm->ptr;
   2790 	char addr[18];
   2791 
   2792 	p_indent(level, frm);
   2793 	p_ba2str(&evt->bdaddr, addr);
   2794 	printf("bdaddr %s mode %d\n", addr, evt->pscan_rep_mode);
   2795 }
   2796 
   2797 static inline void flow_spec_complete_dump(int level, struct frame *frm)
   2798 {
   2799 	evt_flow_spec_complete *evt = frm->ptr;
   2800 
   2801 	p_indent(level, frm);
   2802 	printf("status 0x%2.2x handle %d flags %d %s\n",
   2803 				evt->status, btohs(evt->handle), evt->flags,
   2804 				evt->direction == 0 ? "outgoing" : "incoming");
   2805 
   2806 	if (evt->status > 0) {
   2807 		p_indent(level, frm);
   2808 		printf("Error: %s\n", status2str(evt->status));
   2809 	} else {
   2810 		p_indent(level, frm);
   2811 		printf("Service type: %d\n", evt->qos.service_type);
   2812 		p_indent(level, frm);
   2813 		printf("Token rate: %d\n", btohl(evt->qos.token_rate));
   2814 		p_indent(level, frm);
   2815 		printf("Peak bandwith: %d\n", btohl(evt->qos.peak_bandwidth));
   2816 		p_indent(level, frm);
   2817 		printf("Latency: %d\n", btohl(evt->qos.latency));
   2818 		p_indent(level, frm);
   2819 		printf("Delay variation: %d\n", btohl(evt->qos.delay_variation));
   2820 	}
   2821 }
   2822 
   2823 static inline void inq_result_with_rssi_dump(int level, struct frame *frm)
   2824 {
   2825 	uint8_t num = get_u8(frm);
   2826 	char addr[18];
   2827 	int i;
   2828 
   2829 	if (!num)
   2830 		return;
   2831 
   2832 	if (frm->len / num == INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE) {
   2833 		for (i = 0; i < num; i++) {
   2834 			inquiry_info_with_rssi_and_pscan_mode *info = frm->ptr;
   2835 
   2836 			p_indent(level, frm);
   2837 
   2838 			p_ba2str(&info->bdaddr, addr);
   2839 			printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x rssi %d\n",
   2840 				addr, info->pscan_rep_mode, btohs(info->clock_offset),
   2841 				info->dev_class[2], info->dev_class[1], info->dev_class[0], info->rssi);
   2842 
   2843 			frm->ptr += INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE;
   2844 			frm->len -= INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE;
   2845 		}
   2846 	} else {
   2847 		for (i = 0; i < num; i++) {
   2848 			inquiry_info_with_rssi *info = frm->ptr;
   2849 
   2850 			p_indent(level, frm);
   2851 
   2852 			p_ba2str(&info->bdaddr, addr);
   2853 			printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x rssi %d\n",
   2854 				addr, info->pscan_rep_mode, btohs(info->clock_offset),
   2855 				info->dev_class[2], info->dev_class[1], info->dev_class[0], info->rssi);
   2856 
   2857 			frm->ptr += INQUIRY_INFO_WITH_RSSI_SIZE;
   2858 			frm->len -= INQUIRY_INFO_WITH_RSSI_SIZE;
   2859 		}
   2860 	}
   2861 }
   2862 
   2863 static inline void read_remote_ext_features_complete_dump(int level, struct frame *frm)
   2864 {
   2865 	evt_read_remote_ext_features_complete *evt = frm->ptr;
   2866 	int i;
   2867 
   2868 	p_indent(level, frm);
   2869 	printf("status 0x%2.2x handle %d page %d max %d\n",
   2870 					evt->status, btohs(evt->handle),
   2871 					evt->page_num, evt->max_page_num);
   2872 
   2873 	if (evt->status > 0) {
   2874 		p_indent(level, frm);
   2875 		printf("Error: %s\n", status2str(evt->status));
   2876 	} else {
   2877 		p_indent(level, frm);
   2878 		printf("Features:");
   2879 		for (i = 0; i < 8; i++)
   2880 			printf(" 0x%2.2x", evt->features[i]);
   2881 		printf("\n");
   2882 	}
   2883 }
   2884 
   2885 static inline void sync_conn_complete_dump(int level, struct frame *frm)
   2886 {
   2887 	evt_sync_conn_complete *evt = frm->ptr;
   2888 	char addr[18];
   2889 
   2890 	p_ba2str(&evt->bdaddr, addr);
   2891 
   2892 	p_indent(level, frm);
   2893 	printf("status 0x%2.2x handle %d bdaddr %s type %s\n",
   2894 					evt->status, btohs(evt->handle), addr,
   2895 					evt->link_type == 0 ? "SCO" : "eSCO");
   2896 
   2897 	if (evt->status > 0) {
   2898 		p_indent(level, frm);
   2899 		printf("Error: %s\n", status2str(evt->status));
   2900 	} else {
   2901 		p_indent(level, frm);
   2902 		printf("Air mode: %s\n", airmode2str(evt->air_mode));
   2903 	}
   2904 }
   2905 
   2906 static inline void sync_conn_changed_dump(int level, struct frame *frm)
   2907 {
   2908 	evt_sync_conn_changed *evt = frm->ptr;
   2909 
   2910 	p_indent(level, frm);
   2911 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   2912 
   2913 	if (evt->status > 0) {
   2914 		p_indent(level, frm);
   2915 		printf("Error: %s\n", status2str(evt->status));
   2916 	}
   2917 }
   2918 
   2919 static inline void sniff_subrating_event_dump(int level, struct frame *frm)
   2920 {
   2921 	evt_sniff_subrating *evt = frm->ptr;
   2922 
   2923 	p_indent(level, frm);
   2924 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   2925 
   2926 	if (evt->status > 0) {
   2927 		p_indent(level, frm);
   2928 		printf("Error: %s\n", status2str(evt->status));
   2929 	} else {
   2930 		p_indent(level, frm);
   2931 		printf("max latency transmit %d receive %d\n",
   2932 					btohs(evt->max_tx_latency),
   2933 					btohs(evt->max_rx_latency));
   2934 
   2935 		p_indent(level, frm);
   2936 		printf("min timeout remote %d local %d\n",
   2937 					btohs(evt->min_remote_timeout),
   2938 					btohs(evt->min_local_timeout));
   2939 	}
   2940 }
   2941 
   2942 static inline void extended_inq_result_dump(int level, struct frame *frm)
   2943 {
   2944 	uint8_t num = get_u8(frm);
   2945 	char addr[18];
   2946 	int i;
   2947 
   2948 	for (i = 0; i < num; i++) {
   2949 		extended_inquiry_info *info = frm->ptr;
   2950 
   2951 		p_ba2str(&info->bdaddr, addr);
   2952 
   2953 		p_indent(level, frm);
   2954 		printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x rssi %d\n",
   2955 			addr, info->pscan_rep_mode, btohs(info->clock_offset),
   2956 			info->dev_class[2], info->dev_class[1], info->dev_class[0], info->rssi);
   2957 
   2958 		frm->ptr += INQUIRY_INFO_WITH_RSSI_SIZE;
   2959 		frm->len -= INQUIRY_INFO_WITH_RSSI_SIZE;
   2960 
   2961 		ext_inquiry_response_dump(level, frm);
   2962 	}
   2963 }
   2964 
   2965 static inline void link_supervision_timeout_changed_dump(int level, struct frame *frm)
   2966 {
   2967 	evt_link_supervision_timeout_changed *evt = frm->ptr;
   2968 
   2969 	p_indent(level, frm);
   2970 	printf("handle %d timeout %d\n",
   2971 				btohs(evt->handle), btohs(evt->timeout));
   2972 }
   2973 
   2974 static inline void user_passkey_notify_dump(int level, struct frame *frm)
   2975 {
   2976 	evt_user_passkey_notify *evt = frm->ptr;
   2977 	char addr[18];
   2978 
   2979 	p_indent(level, frm);
   2980 	p_ba2str(&evt->bdaddr, addr);
   2981 	printf("bdaddr %s passkey %d\n", addr, btohl(evt->passkey));
   2982 }
   2983 
   2984 static inline void keypress_notify_dump(int level, struct frame *frm)
   2985 {
   2986 	evt_keypress_notify *evt = frm->ptr;
   2987 	char addr[18];
   2988 
   2989 	p_indent(level, frm);
   2990 	p_ba2str(&evt->bdaddr, addr);
   2991 	printf("bdaddr %s type %d\n", addr, evt->type);
   2992 }
   2993 
   2994 static inline void remote_host_features_notify_dump(int level, struct frame *frm)
   2995 {
   2996 	evt_remote_host_features_notify *evt = frm->ptr;
   2997 	char addr[18];
   2998 	int i;
   2999 
   3000 	p_indent(level, frm);
   3001 	p_ba2str(&evt->bdaddr, addr);
   3002 	printf("bdaddr %s\n", addr);
   3003 
   3004 	p_indent(level, frm);
   3005 	printf("Features:");
   3006 	for (i = 0; i < 8; i++)
   3007 		printf(" 0x%2.2x", evt->features[i]);
   3008 	printf("\n");
   3009 }
   3010 
   3011 static inline void event_dump(int level, struct frame *frm)
   3012 {
   3013 	hci_event_hdr *hdr = frm->ptr;
   3014 	uint8_t event = hdr->evt;
   3015 
   3016 	if (p_filter(FILT_HCI))
   3017 		return;
   3018 
   3019 	if (event <= EVENT_NUM) {
   3020 		p_indent(level, frm);
   3021 		printf("HCI Event: %s (0x%2.2x) plen %d\n",
   3022 					event_str[hdr->evt], hdr->evt, hdr->plen);
   3023 	} else if (hdr->evt == EVT_TESTING) {
   3024 		p_indent(level, frm);
   3025 		printf("HCI Event: Testing (0x%2.2x) plen %d\n", hdr->evt, hdr->plen);
   3026 	} else if (hdr->evt == EVT_VENDOR) {
   3027 		uint16_t manufacturer;
   3028 
   3029 		if (parser.flags & DUMP_NOVENDOR)
   3030 			return;
   3031 
   3032 		p_indent(level, frm);
   3033 		printf("HCI Event: Vendor (0x%2.2x) plen %d\n", hdr->evt, hdr->plen);
   3034 
   3035 		manufacturer = get_manufacturer();
   3036 
   3037 		switch (manufacturer) {
   3038 		case 0:
   3039 		case 37:
   3040 		case 48:
   3041 			frm->ptr += HCI_EVENT_HDR_SIZE;
   3042 			frm->len -= HCI_EVENT_HDR_SIZE;
   3043 			ericsson_dump(level + 1, frm);
   3044 			return;
   3045 		case 10:
   3046 			frm->ptr += HCI_EVENT_HDR_SIZE;
   3047 			frm->len -= HCI_EVENT_HDR_SIZE;
   3048 			csr_dump(level + 1, frm);
   3049 			return;
   3050 		}
   3051 	} else {
   3052 		p_indent(level, frm);
   3053 		printf("HCI Event: code 0x%2.2x plen %d\n", hdr->evt, hdr->plen);
   3054 	}
   3055 
   3056 	frm->ptr += HCI_EVENT_HDR_SIZE;
   3057 	frm->len -= HCI_EVENT_HDR_SIZE;
   3058 
   3059 	if (event == EVT_CMD_COMPLETE) {
   3060 		evt_cmd_complete *cc = frm->ptr;
   3061 		if (cc->opcode == cmd_opcode_pack(OGF_INFO_PARAM, OCF_READ_LOCAL_VERSION)) {
   3062 			read_local_version_rp *rp = frm->ptr + EVT_CMD_COMPLETE_SIZE;
   3063 			manufacturer = rp->manufacturer;
   3064 		}
   3065 	}
   3066 
   3067 	if (event == EVT_DISCONN_COMPLETE) {
   3068 		evt_disconn_complete *evt = frm->ptr;
   3069 		l2cap_clear(btohs(evt->handle));
   3070 	}
   3071 
   3072 	if (!(parser.flags & DUMP_VERBOSE)) {
   3073 		raw_dump(level, frm);
   3074 		return;
   3075 	}
   3076 
   3077 	switch (event) {
   3078 	case EVT_LOOPBACK_COMMAND:
   3079 		command_dump(level + 1, frm);
   3080 		break;
   3081 	case EVT_CMD_COMPLETE:
   3082 		cmd_complete_dump(level + 1, frm);
   3083 		break;
   3084 	case EVT_CMD_STATUS:
   3085 		cmd_status_dump(level + 1, frm);
   3086 		break;
   3087 	case EVT_HARDWARE_ERROR:
   3088 		hardware_error_dump(level + 1, frm);
   3089 		break;
   3090 	case EVT_FLUSH_OCCURRED:
   3091 	case EVT_QOS_VIOLATION:
   3092 		handle_response_dump(level + 1, frm);
   3093 		break;
   3094 	case EVT_INQUIRY_COMPLETE:
   3095 		status_response_dump(level + 1, frm);
   3096 		break;
   3097 	case EVT_INQUIRY_RESULT:
   3098 		inq_result_dump(level + 1, frm);
   3099 		break;
   3100 	case EVT_CONN_COMPLETE:
   3101 		conn_complete_dump(level + 1, frm);
   3102 		break;
   3103 	case EVT_CONN_REQUEST:
   3104 		conn_request_dump(level + 1, frm);
   3105 		break;
   3106 	case EVT_DISCONN_COMPLETE:
   3107 		disconn_complete_dump(level + 1, frm);
   3108 		break;
   3109 	case EVT_AUTH_COMPLETE:
   3110 	case EVT_CHANGE_CONN_LINK_KEY_COMPLETE:
   3111 		generic_response_dump(level + 1, frm);
   3112 		break;
   3113 	case EVT_MASTER_LINK_KEY_COMPLETE:
   3114 		master_link_key_complete_dump(level + 1, frm);
   3115 		break;
   3116 	case EVT_REMOTE_NAME_REQ_COMPLETE:
   3117 		remote_name_req_complete_dump(level + 1, frm);
   3118 		break;
   3119 	case EVT_ENCRYPT_CHANGE:
   3120 		encrypt_change_dump(level + 1, frm);
   3121 		break;
   3122 	case EVT_READ_REMOTE_FEATURES_COMPLETE:
   3123 		read_remote_features_complete_dump(level + 1, frm);
   3124 		break;
   3125 	case EVT_READ_REMOTE_VERSION_COMPLETE:
   3126 		read_remote_version_complete_dump(level + 1, frm);
   3127 		break;
   3128 	case EVT_QOS_SETUP_COMPLETE:
   3129 		qos_setup_complete_dump(level + 1, frm);
   3130 		break;
   3131 	case EVT_ROLE_CHANGE:
   3132 		role_change_dump(level + 1, frm);
   3133 		break;
   3134 	case EVT_NUM_COMP_PKTS:
   3135 		num_comp_pkts_dump(level + 1, frm);
   3136 		break;
   3137 	case EVT_MODE_CHANGE:
   3138 		mode_change_dump(level + 1, frm);
   3139 		break;
   3140 	case EVT_RETURN_LINK_KEYS:
   3141 		return_link_keys_dump(level + 1, frm);
   3142 		break;
   3143 	case EVT_PIN_CODE_REQ:
   3144 	case EVT_LINK_KEY_REQ:
   3145 	case EVT_IO_CAPABILITY_REQUEST:
   3146 	case EVT_USER_PASSKEY_REQUEST:
   3147 	case EVT_REMOTE_OOB_DATA_REQUEST:
   3148 		pin_code_req_dump(level + 1, frm);
   3149 		break;
   3150 	case EVT_LINK_KEY_NOTIFY:
   3151 		link_key_notify_dump(level + 1, frm);
   3152 		break;
   3153 	case EVT_DATA_BUFFER_OVERFLOW:
   3154 		data_buffer_overflow_dump(level + 1, frm);
   3155 		break;
   3156 	case EVT_MAX_SLOTS_CHANGE:
   3157 		max_slots_change_dump(level + 1, frm);
   3158 		break;
   3159 	case EVT_READ_CLOCK_OFFSET_COMPLETE:
   3160 		read_clock_offset_complete_dump(level + 1, frm);
   3161 		break;
   3162 	case EVT_CONN_PTYPE_CHANGED:
   3163 		conn_ptype_changed_dump(level + 1, frm);
   3164 		break;
   3165 	case EVT_PSCAN_REP_MODE_CHANGE:
   3166 		pscan_rep_mode_change_dump(level + 1, frm);
   3167 		break;
   3168 	case EVT_FLOW_SPEC_COMPLETE:
   3169 		flow_spec_complete_dump(level + 1, frm);
   3170 		break;
   3171 	case EVT_INQUIRY_RESULT_WITH_RSSI:
   3172 		inq_result_with_rssi_dump(level + 1, frm);
   3173 		break;
   3174 	case EVT_READ_REMOTE_EXT_FEATURES_COMPLETE:
   3175 		read_remote_ext_features_complete_dump(level + 1, frm);
   3176 		break;
   3177 	case EVT_SYNC_CONN_COMPLETE:
   3178 		sync_conn_complete_dump(level + 1, frm);
   3179 		break;
   3180 	case EVT_SYNC_CONN_CHANGED:
   3181 		sync_conn_changed_dump(level + 1, frm);
   3182 		break;
   3183 	case EVT_SNIFF_SUBRATING:
   3184 		sniff_subrating_event_dump(level + 1, frm);
   3185 		break;
   3186 	case EVT_EXTENDED_INQUIRY_RESULT:
   3187 		extended_inq_result_dump(level + 1, frm);
   3188 		break;
   3189 	case EVT_ENCRYPTION_KEY_REFRESH_COMPLETE:
   3190 		generic_response_dump(level + 1, frm);
   3191 		break;
   3192 	case EVT_SIMPLE_PAIRING_COMPLETE:
   3193 		bdaddr_response_dump(level + 1, frm);
   3194 		break;
   3195 	case EVT_LINK_SUPERVISION_TIMEOUT_CHANGED:
   3196 		link_supervision_timeout_changed_dump(level + 1, frm);
   3197 		break;
   3198 	case EVT_ENHANCED_FLUSH_COMPLETE:
   3199 		generic_command_dump(level + 1, frm);
   3200 		break;
   3201 	case EVT_IO_CAPABILITY_RESPONSE:
   3202 		io_capability_reply_dump(level + 1, frm);
   3203 		break;
   3204 	case EVT_USER_CONFIRM_REQUEST:
   3205 	case EVT_USER_PASSKEY_NOTIFY:
   3206 		user_passkey_notify_dump(level + 1, frm);
   3207 		break;
   3208 	case EVT_KEYPRESS_NOTIFY:
   3209 		keypress_notify_dump(level + 1, frm);
   3210 		break;
   3211 	case EVT_REMOTE_HOST_FEATURES_NOTIFY:
   3212 		remote_host_features_notify_dump(level + 1, frm);
   3213 		break;
   3214 	default:
   3215 		raw_dump(level, frm);
   3216 		break;
   3217 	}
   3218 }
   3219 
   3220 static inline void acl_dump(int level, struct frame *frm)
   3221 {
   3222 	hci_acl_hdr *hdr = (void *) frm->ptr;
   3223 	uint16_t handle = btohs(hdr->handle);
   3224 	uint16_t dlen = btohs(hdr->dlen);
   3225 	uint8_t flags = acl_flags(handle);
   3226 
   3227 	if (!p_filter(FILT_HCI)) {
   3228 		p_indent(level, frm);
   3229 		printf("ACL data: handle %d flags 0x%2.2x dlen %d\n",
   3230 			acl_handle(handle), flags, dlen);
   3231 		level++;
   3232 	}
   3233 
   3234 	frm->ptr += HCI_ACL_HDR_SIZE;
   3235 	frm->len -= HCI_ACL_HDR_SIZE;
   3236 	frm->flags  = flags;
   3237 	frm->handle = acl_handle(handle);
   3238 
   3239 	if (parser.filter & ~FILT_HCI)
   3240 		l2cap_dump(level, frm);
   3241 	else
   3242 		raw_dump(level, frm);
   3243 }
   3244 
   3245 static inline void sco_dump(int level, struct frame *frm)
   3246 {
   3247 	hci_sco_hdr *hdr = (void *) frm->ptr;
   3248 	uint16_t handle = btohs(hdr->handle);
   3249 	uint8_t flags = acl_flags(handle);
   3250 	int len;
   3251 
   3252 	if (frm->audio_fd > fileno(stderr))
   3253 		len = write(frm->audio_fd, frm->ptr + HCI_SCO_HDR_SIZE, hdr->dlen);
   3254 
   3255 	if (!p_filter(FILT_SCO)) {
   3256 		p_indent(level, frm);
   3257 		printf("SCO data: handle %d flags 0x%2.2x dlen %d\n",
   3258 				acl_handle(handle), flags, hdr->dlen);
   3259 		level++;
   3260 
   3261 		frm->ptr += HCI_SCO_HDR_SIZE;
   3262 		frm->len -= HCI_SCO_HDR_SIZE;
   3263 		raw_dump(level, frm);
   3264 	}
   3265 }
   3266 
   3267 static inline void vendor_dump(int level, struct frame *frm)
   3268 {
   3269 	if (p_filter(FILT_HCI))
   3270 		return;
   3271 
   3272 	if (frm->dev_id == HCI_DEV_NONE) {
   3273 		uint16_t device = btohs(htons(get_u16(frm)));
   3274 		uint16_t proto = btohs(htons(get_u16(frm)));
   3275 		uint16_t type = btohs(htons(get_u16(frm)));
   3276 		uint16_t plen = btohs(htons(get_u16(frm)));
   3277 
   3278 		p_indent(level, frm);
   3279 
   3280 		printf("System %s: device hci%d proto 0x%2.2x type 0x%2.2x plen %d\n",
   3281 			frm->in ? "event" : "command", device, proto, type, plen);
   3282 
   3283 		raw_dump(level, frm);
   3284 		return;
   3285 	}
   3286 
   3287 	if (parser.flags & DUMP_NOVENDOR)
   3288 		return;
   3289 
   3290 	if (get_manufacturer() == 12) {
   3291 		bpa_dump(level, frm);
   3292 		return;
   3293 	}
   3294 
   3295 	p_indent(level, frm);
   3296 	printf("Vendor data: len %d\n", frm->len);
   3297 	raw_dump(level, frm);
   3298 }
   3299 
   3300 void hci_dump(int level, struct frame *frm)
   3301 {
   3302 	uint8_t type = *(uint8_t *)frm->ptr;
   3303 
   3304 	frm->ptr++; frm->len--;
   3305 
   3306 	switch (type) {
   3307 	case HCI_COMMAND_PKT:
   3308 		command_dump(level, frm);
   3309 		break;
   3310 
   3311 	case HCI_EVENT_PKT:
   3312 		event_dump(level, frm);
   3313 		break;
   3314 
   3315 	case HCI_ACLDATA_PKT:
   3316 		acl_dump(level, frm);
   3317 		break;
   3318 
   3319 	case HCI_SCODATA_PKT:
   3320 		sco_dump(level, frm);
   3321 		break;
   3322 
   3323 	case HCI_VENDOR_PKT:
   3324 		vendor_dump(level, frm);
   3325 		break;
   3326 
   3327 	default:
   3328 		if (p_filter(FILT_HCI))
   3329 			break;
   3330 
   3331 		p_indent(level, frm);
   3332 		printf("Unknown: type 0x%2.2x len %d\n", type, frm->len);
   3333 		raw_dump(level, frm);
   3334 		break;
   3335 	}
   3336 }
   3337