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-2011  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 76
     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 	"LE Meta Event",
    118 	"Physical Link Complete",
    119 	"Channel Selected",
    120 	"Disconnection Physical Link Complete",
    121 	"Physical Link Loss Early Warning",
    122 	"Physical Link Recovery",
    123 	"Logical Link Complete",
    124 	"Disconnection Logical Link Complete",
    125 	"Flow Spec Modify Complete",
    126 	"Number Of Completed Data Blocks",
    127 	"AMP Start Test",
    128 	"AMP Test End",
    129 	"AMP Receiver Report",
    130 	"Short Range Mode Change Complete",
    131 	"AMP Status Change",
    132 };
    133 
    134 #define LE_EV_NUM 5
    135 static char *ev_le_meta_str[LE_EV_NUM + 1] = {
    136 	"Unknown",
    137 	"LE Connection Complete",
    138 	"LE Advertising Report",
    139 	"LE Connection Update Complete",
    140 	"LE Read Remote Used Features Complete",
    141 	"LE Long Term Key Request",
    142 };
    143 
    144 #define CMD_LINKCTL_NUM 60
    145 static char *cmd_linkctl_str[CMD_LINKCTL_NUM + 1] = {
    146 	"Unknown",
    147 	"Inquiry",
    148 	"Inquiry Cancel",
    149 	"Periodic Inquiry Mode",
    150 	"Exit Periodic Inquiry Mode",
    151 	"Create Connection",
    152 	"Disconnect",
    153 	"Add SCO Connection",
    154 	"Create Connection Cancel",
    155 	"Accept Connection Request",
    156 	"Reject Connection Request",
    157 	"Link Key Request Reply",
    158 	"Link Key Request Negative Reply",
    159 	"PIN Code Request Reply",
    160 	"PIN Code Request Negative Reply",
    161 	"Change Connection Packet Type",
    162 	"Unknown",
    163 	"Authentication Requested",
    164 	"Unknown",
    165 	"Set Connection Encryption",
    166 	"Unknown",
    167 	"Change Connection Link Key",
    168 	"Unknown",
    169 	"Master Link Key",
    170 	"Unknown",
    171 	"Remote Name Request",
    172 	"Remote Name Request Cancel",
    173 	"Read Remote Supported Features",
    174 	"Read Remote Extended Features",
    175 	"Read Remote Version Information",
    176 	"Unknown",
    177 	"Read Clock Offset",
    178 	"Read LMP Handle",
    179 	"Unknown",
    180 	"Unknown",
    181 	"Unknown",
    182 	"Unknown",
    183 	"Unknown",
    184 	"Unknown",
    185 	"Unknown",
    186 	"Setup Synchronous Connection",
    187 	"Accept Synchronous Connection",
    188 	"Reject Synchronous Connection",
    189 	"IO Capability Request Reply",
    190 	"User Confirmation Request Reply",
    191 	"User Confirmation Request Negative Reply",
    192 	"User Passkey Request Reply",
    193 	"User Passkey Request Negative Reply",
    194 	"Remote OOB Data Request Reply",
    195 	"Unknown",
    196 	"Unknown",
    197 	"Remote OOB Data Request Negative Reply",
    198 	"IO Capability Request Negative Reply",
    199 	"Create Physical Link",
    200 	"Accept Physical Link",
    201 	"Disconnect Physical Link",
    202 	"Create Logical Link",
    203 	"Accept Logical Link",
    204 	"Disconnect Logical Link",
    205 	"Logical Link Cancel",
    206 	"Flow Spec Modify",
    207 };
    208 
    209 #define CMD_LINKPOL_NUM 17
    210 static char *cmd_linkpol_str[CMD_LINKPOL_NUM + 1] = {
    211 	"Unknown",
    212 	"Hold Mode",
    213 	"Unknown",
    214 	"Sniff Mode",
    215 	"Exit Sniff Mode",
    216 	"Park State",
    217 	"Exit Park State",
    218 	"QoS Setup",
    219 	"Unknown",
    220 	"Role Discovery",
    221 	"Unknown",
    222 	"Switch Role",
    223 	"Read Link Policy Settings",
    224 	"Write Link Policy Settings",
    225 	"Read Default Link Policy Settings",
    226 	"Write Default Link Policy Settings",
    227 	"Flow Specification",
    228 	"Sniff Subrating",
    229 };
    230 
    231 #define CMD_HOSTCTL_NUM 109
    232 static char *cmd_hostctl_str[CMD_HOSTCTL_NUM + 1] = {
    233 	"Unknown",
    234 	"Set Event Mask",
    235 	"Unknown",
    236 	"Reset",
    237 	"Unknown",
    238 	"Set Event Filter",
    239 	"Unknown",
    240 	"Unknown",
    241 	"Flush",
    242 	"Read PIN Type ",
    243 	"Write PIN Type",
    244 	"Create New Unit Key",
    245 	"Unknown",
    246 	"Read Stored Link Key",
    247 	"Unknown",
    248 	"Unknown",
    249 	"Unknown",
    250 	"Write Stored Link Key",
    251 	"Delete Stored Link Key",
    252 	"Write Local Name",
    253 	"Read Local Name",
    254 	"Read Connection Accept Timeout",
    255 	"Write Connection Accept Timeout",
    256 	"Read Page Timeout",
    257 	"Write Page Timeout",
    258 	"Read Scan Enable",
    259 	"Write Scan Enable",
    260 	"Read Page Scan Activity",
    261 	"Write Page Scan Activity",
    262 	"Read Inquiry Scan Activity",
    263 	"Write Inquiry Scan Activity",
    264 	"Read Authentication Enable",
    265 	"Write Authentication Enable",
    266 	"Read Encryption Mode",
    267 	"Write Encryption Mode",
    268 	"Read Class of Device",
    269 	"Write Class of Device",
    270 	"Read Voice Setting",
    271 	"Write Voice Setting",
    272 	"Read Automatic Flush Timeout",
    273 	"Write Automatic Flush Timeout",
    274 	"Read Num Broadcast Retransmissions",
    275 	"Write Num Broadcast Retransmissions",
    276 	"Read Hold Mode Activity ",
    277 	"Write Hold Mode Activity",
    278 	"Read Transmit Power Level",
    279 	"Read Synchronous Flow Control Enable",
    280 	"Write Synchronous Flow Control Enable",
    281 	"Unknown",
    282 	"Set Host Controller To Host Flow Control",
    283 	"Unknown",
    284 	"Host Buffer Size",
    285 	"Unknown",
    286 	"Host Number of Completed Packets",
    287 	"Read Link Supervision Timeout",
    288 	"Write Link Supervision Timeout",
    289 	"Read Number of Supported IAC",
    290 	"Read Current IAC LAP",
    291 	"Write Current IAC LAP",
    292 	"Read Page Scan Period Mode",
    293 	"Write Page Scan Period Mode",
    294 	"Read Page Scan Mode",
    295 	"Write Page Scan Mode",
    296 	"Set AFH Host Channel Classification",
    297 	"Unknown",
    298 	"Unknown",
    299 	"Read Inquiry Scan Type",
    300 	"Write Inquiry Scan Type",
    301 	"Read Inquiry Mode",
    302 	"Write Inquiry Mode",
    303 	"Read Page Scan Type",
    304 	"Write Page Scan Type",
    305 	"Read AFH Channel Assessment Mode",
    306 	"Write AFH Channel Assessment Mode",
    307 	"Unknown",
    308 	"Unknown",
    309 	"Unknown",
    310 	"Unknown",
    311 	"Unknown",
    312 	"Unknown",
    313 	"Unknown",
    314 	"Read Extended Inquiry Response",
    315 	"Write Extended Inquiry Response",
    316 	"Refresh Encryption Key",
    317 	"Unknown",
    318 	"Read Simple Pairing Mode",
    319 	"Write Simple Pairing Mode",
    320 	"Read Local OOB Data",
    321 	"Read Inquiry Response Transmit Power Level",
    322 	"Write Inquiry Transmit Power Level",
    323 	"Read Default Erroneous Data Reporting",
    324 	"Write Default Erroneous Data Reporting",
    325 	"Unknown",
    326 	"Unknown",
    327 	"Unknown",
    328 	"Enhanced Flush",
    329 	"Unknown",
    330 	"Read Logical Link Accept Timeout",
    331 	"Write Logical Link Accept Timeout",
    332 	"Set Event Mask Page 2",
    333 	"Read Location Data",
    334 	"Write Location Data",
    335 	"Read Flow Control Mode",
    336 	"Write Flow Control Mode",
    337 	"Read Enhanced Transmit Power Level",
    338 	"Read Best Effort Flush Timeout",
    339 	"Write Best Effort Flush Timeout",
    340 	"Short Range Mode",
    341 	"Read LE Host Supported",
    342 	"Write LE Host Supported",
    343 };
    344 
    345 #define CMD_INFO_NUM 9
    346 static char *cmd_info_str[CMD_INFO_NUM + 1] = {
    347 	"Unknown",
    348 	"Read Local Version Information",
    349 	"Read Local Supported Commands",
    350 	"Read Local Supported Features",
    351 	"Read Local Extended Features",
    352 	"Read Buffer Size",
    353 	"Unknown",
    354 	"Read Country Code",
    355 	"Unknown",
    356 	"Read BD ADDR",
    357 };
    358 
    359 #define CMD_STATUS_NUM 11
    360 static char *cmd_status_str[CMD_STATUS_NUM + 1] = {
    361 	"Unknown",
    362 	"Read Failed Contact Counter",
    363 	"Reset Failed Contact Counter",
    364 	"Read Link Quality",
    365 	"Unknown",
    366 	"Read RSSI",
    367 	"Read AFH Channel Map",
    368 	"Read Clock",
    369 	"Read Encryption Key Size",
    370 	"Read Local AMP Info",
    371 	"Read Local AMP ASSOC",
    372 	"Write Remote AMP ASSOC"
    373 };
    374 
    375 #define CMD_TESTING_NUM 4
    376 static char *cmd_testing_str[CMD_TESTING_NUM + 1] = {
    377 	"Unknown",
    378 	"Read Loopback Mode",
    379 	"Write Loopback Mode",
    380 	"Enable Device Under Test mode",
    381 	"Unknown",
    382 };
    383 
    384 #define CMD_LE_NUM 31
    385 static char *cmd_le_str[CMD_LE_NUM + 1] = {
    386 	"Unknown",
    387 	"LE Set Event Mask",
    388 	"LE Read Buffer Size",
    389 	"LE Read Local Supported Features",
    390 	"Unknown",
    391 	"LE Set Random Address",
    392 	"LE Set Advertising Parameters",
    393 	"LE Read Advertising Channel Tx Power",
    394 	"LE Set Advertising Data",
    395 	"LE Set Scan Response Data",
    396 	"LE Set Advertise Enable",
    397 	"LE Set Scan Parameters",
    398 	"LE Set Scan Enable",
    399 	"LE Create Connection",
    400 	"LE Create Connection Cancel",
    401 	"LE Read White List Size",
    402 	"LE Clear White List",
    403 	"LE Add Device To White List",
    404 	"LE Remove Device From White List",
    405 	"LE Connection Update",
    406 	"LE Set Host Channel Classification",
    407 	"LE Read Channel Map",
    408 	"LE Read Remote Used Features",
    409 	"LE Encrypt",
    410 	"LE Rand",
    411 	"LE Start Encryption",
    412 	"LE Long Term Key Request Reply",
    413 	"LE Long Term Key Request Negative Reply",
    414 	"LE Read Supported States",
    415 	"LE Receiver Test",
    416 	"LE Transmitter Test",
    417 	"LE Test End",
    418 };
    419 
    420 #define ERROR_CODE_NUM 56
    421 static char *error_code_str[ERROR_CODE_NUM + 1] = {
    422 	"Success",
    423 	"Unknown HCI Command",
    424 	"Unknown Connection Identifier",
    425 	"Hardware Failure",
    426 	"Page Timeout",
    427 	"Authentication Failure",
    428 	"PIN or Key Missing",
    429 	"Memory Capacity Exceeded",
    430 	"Connection Timeout",
    431 	"Connection Limit Exceeded",
    432 	"Synchronous Connection to a Device Exceeded",
    433 	"ACL Connection Already Exists",
    434 	"Command Disallowed",
    435 	"Connection Rejected due to Limited Resources",
    436 	"Connection Rejected due to Security Reasons",
    437 	"Connection Rejected due to Unacceptable BD_ADDR",
    438 	"Connection Accept Timeout Exceeded",
    439 	"Unsupported Feature or Parameter Value",
    440 	"Invalid HCI Command Parameters",
    441 	"Remote User Terminated Connection",
    442 	"Remote Device Terminated Connection due to Low Resources",
    443 	"Remote Device Terminated Connection due to Power Off",
    444 	"Connection Terminated by Local Host",
    445 	"Repeated Attempts",
    446 	"Pairing Not Allowed",
    447 	"Unknown LMP PDU",
    448 	"Unsupported Remote Feature / Unsupported LMP Feature",
    449 	"SCO Offset Rejected",
    450 	"SCO Interval Rejected",
    451 	"SCO Air Mode Rejected",
    452 	"Invalid LMP Parameters",
    453 	"Unspecified Error",
    454 	"Unsupported LMP Parameter Value",
    455 	"Role Change Not Allowed",
    456 	"LMP Response Timeout",
    457 	"LMP Error Transaction Collision",
    458 	"LMP PDU Not Allowed",
    459 	"Encryption Mode Not Acceptable",
    460 	"Link Key Can Not be Changed",
    461 	"Requested QoS Not Supported",
    462 	"Instant Passed",
    463 	"Pairing with Unit Key Not Supported",
    464 	"Different Transaction Collision",
    465 	"Reserved",
    466 	"QoS Unacceptable Parameter",
    467 	"QoS Rejected",
    468 	"Channel Classification Not Supported",
    469 	"Insufficient Security",
    470 	"Parameter out of Mandatory Range",
    471 	"Reserved",
    472 	"Role Switch Pending",
    473 	"Reserved",
    474 	"Reserved Slot Violation",
    475 	"Role Switch Failed",
    476 	"Extended Inquiry Response Too Large",
    477 	"Simple Pairing Not Supported by Host",
    478 	"Host Busy - Pairing",
    479 };
    480 
    481 static char *status2str(uint8_t status)
    482 {
    483 	char *str;
    484 
    485 	if (status <= ERROR_CODE_NUM)
    486 		str = error_code_str[status];
    487 	else
    488 		str = "Unknown";
    489 
    490 	return str;
    491 }
    492 
    493 static char *opcode2str(uint16_t opcode)
    494 {
    495 	uint16_t ogf = cmd_opcode_ogf(opcode);
    496 	uint16_t ocf = cmd_opcode_ocf(opcode);
    497 	char *cmd;
    498 
    499 	switch (ogf) {
    500 	case OGF_INFO_PARAM:
    501 		if (ocf <= CMD_INFO_NUM)
    502 			cmd = cmd_info_str[ocf];
    503 		else
    504 			cmd = "Unknown";
    505 		break;
    506 
    507 	case OGF_HOST_CTL:
    508 		if (ocf <= CMD_HOSTCTL_NUM)
    509 			cmd = cmd_hostctl_str[ocf];
    510 		else
    511 			cmd = "Unknown";
    512 		break;
    513 
    514 	case OGF_LINK_CTL:
    515 		if (ocf <= CMD_LINKCTL_NUM)
    516 			cmd = cmd_linkctl_str[ocf];
    517 		else
    518 			cmd = "Unknown";
    519 		break;
    520 
    521 	case OGF_LINK_POLICY:
    522 		if (ocf <= CMD_LINKPOL_NUM)
    523 			cmd = cmd_linkpol_str[ocf];
    524 		else
    525 			cmd = "Unknown";
    526 		break;
    527 
    528 	case OGF_STATUS_PARAM:
    529 		if (ocf <= CMD_STATUS_NUM)
    530 			cmd = cmd_status_str[ocf];
    531 		else
    532 			cmd = "Unknown";
    533 		break;
    534 
    535 	case OGF_TESTING_CMD:
    536 		if (ocf <= CMD_TESTING_NUM)
    537 			cmd = cmd_testing_str[ocf];
    538 		else
    539 			cmd = "Unknown";
    540 		break;
    541 
    542 	case OGF_LE_CTL:
    543 		if (ocf <= CMD_LE_NUM)
    544 			cmd = cmd_le_str[ocf];
    545 		else
    546 			cmd = "Unknown";
    547 		break;
    548 
    549 	case OGF_VENDOR_CMD:
    550 		cmd = "Vendor";
    551 		break;
    552 
    553 	default:
    554 		cmd = "Unknown";
    555 		break;
    556 	}
    557 
    558 	return cmd;
    559 }
    560 
    561 static char *linktype2str(uint8_t type)
    562 {
    563 	switch (type) {
    564 	case 0x00:
    565 		return "SCO";
    566 	case 0x01:
    567 		return "ACL";
    568 	case 0x02:
    569 		return "eSCO";
    570 	default:
    571 		return "Unknown";
    572 	}
    573 }
    574 
    575 static char *role2str(uint8_t role)
    576 {
    577 	switch (role) {
    578 	case 0x00:
    579 		return "Master";
    580 	case 0x01:
    581 		return "Slave";
    582 	default:
    583 		return "Unknown";
    584 	}
    585 }
    586 
    587 static char *mode2str(uint8_t mode)
    588 {
    589 	switch (mode) {
    590 	case 0x00:
    591 		return "Active";
    592 	case 0x01:
    593 		return "Hold";
    594 	case 0x02:
    595 		return "Sniff";
    596 	case 0x03:
    597 		return "Park";
    598 	default:
    599 		return "Unknown";
    600 	}
    601 }
    602 
    603 static char *airmode2str(uint8_t mode)
    604 {
    605 	switch (mode) {
    606 	case 0x00:
    607 		return "u-law log";
    608 	case 0x01:
    609 		return "A-law log";
    610 	case 0x02:
    611 		return "CVSD";
    612 	case 0x04:
    613 		return "Transparent data";
    614 	default:
    615 		return "Reserved";
    616 	}
    617 }
    618 
    619 static const char *bdaddrtype2str(uint8_t type)
    620 {
    621 	switch (type) {
    622 	case 0x00:
    623 		return "Public";
    624 	case 0x01:
    625 		return "Random";
    626 	default:
    627 		return "Reserved";
    628 	}
    629 }
    630 
    631 static const char *evttype2str(uint8_t type)
    632 {
    633 	switch (type) {
    634 	case 0x00:
    635 		return "ADV_IND - Connectable undirected advertising";
    636 	case 0x01:
    637 		return "ADV_DIRECT_IND - Connectable directed advertising";
    638 	case 0x02:
    639 		return "ADV_SCAN_IND - Scannable undirected advertising";
    640 	case 0x03:
    641 		return "ADV_NONCONN_IND - Non connectable undirected advertising";
    642 	case 0x04:
    643 		return "SCAN_RSP - Scan Response";
    644 	default:
    645 		return "Reserved";
    646 	}
    647 }
    648 
    649 static char *keytype2str(uint8_t type)
    650 {
    651 	switch (type) {
    652 	case 0x00:
    653 		return "Combination Key";
    654 	case 0x01:
    655 		return "Local Unit Key";
    656 	case 0x02:
    657 		return "Remote Unit Key";
    658 	case 0x03:
    659 		return "Debug Combination Key";
    660 	case 0x04:
    661 		return "Unauthenticated Combination Key";
    662 	case 0x05:
    663 		return "Authenticated Combination Key";
    664 	case 0x06:
    665 		return "Changed Combination Key";
    666 	default:
    667 		return "Reserved";
    668 	}
    669 }
    670 
    671 static char *capability2str(uint8_t capability)
    672 {
    673 	switch (capability) {
    674 	case 0x00:
    675 		return "DisplayOnly";
    676 	case 0x01:
    677 		return "DisplayYesNo";
    678 	case 0x02:
    679 		return "KeyboardOnly";
    680 	case 0x03:
    681 		return "NoInputNoOutput";
    682 	default:
    683 		return "Reserved";
    684 	}
    685 }
    686 
    687 static char *authentication2str(uint8_t authentication)
    688 {
    689 	switch (authentication) {
    690 	case 0x00:
    691 		return "No Bonding (No MITM Protection)";
    692 	case 0x01:
    693 		return "No Bonding (MITM Protection)";
    694 	case 0x02:
    695 		return "Dedicated Bonding (No MITM Protection)";
    696 	case 0x03:
    697 		return "Dedicated Bonding (MITM Protection)";
    698 	case 0x04:
    699 		return "General Bonding (No MITM Protection)";
    700 	case 0x05:
    701 		return "General Bonding (MITM Protection)";
    702 	default:
    703 		return "Reserved";
    704 	}
    705 }
    706 
    707 static char *eventmask2str(const uint8_t mask[8])
    708 {
    709 	int i;
    710 
    711 	for (i = 0; i < 7; i++) {
    712 		if (mask[i] != 0x00)
    713 			return "Reserved";
    714 	}
    715 
    716 	switch (mask[7]) {
    717 	case 0x00:
    718 		return "No LE events specified";
    719 	case 0x01:
    720 		return "LE Connection Complete Event";
    721 	case 0x02:
    722 		return "LE Advertising Report Event";
    723 	case 0x04:
    724 		return "LE Connection Update Complete Event";
    725 	case 0x08:
    726 		return "LE Read Remote Used Features Complete Event";
    727 	case 0x10:
    728 		return "LE Long Term Key Request Event";
    729 	case 0x1F:
    730 		return "Default";
    731 	default:
    732 		return "Reserved";
    733 	}
    734 }
    735 
    736 static char *lefeatures2str(const uint8_t features[8])
    737 {
    738 	if (features[0] & 0x01)
    739 		return "Link Layer supports LE Encryption";
    740 
    741 	return "RFU";
    742 }
    743 
    744 static char *filterpolicy2str(uint8_t policy)
    745 {
    746 	switch (policy) {
    747 	case 0x00:
    748 		return "Allow scan from any, connection from any";
    749 	case 0x01:
    750 		return "Allow scan from white list, connection from any";
    751 	case 0x02:
    752 		return "Allow scan from any, connection from white list";
    753 	case 0x03:
    754 		return "Allow scan and connection from white list";
    755 	default:
    756 		return "Reserved";
    757 	}
    758 }
    759 
    760 static inline void ext_inquiry_data_dump(int level, struct frame *frm,
    761 						uint8_t *data)
    762 {
    763 	uint8_t len = data[0];
    764 	uint8_t type;
    765 	char *str;
    766 	int i;
    767 
    768 	if (len == 0)
    769 		return;
    770 
    771 	type = data[1];
    772 	data += 2;
    773 	len -= 1;
    774 
    775 	switch (type) {
    776 	case 0x01:
    777 		p_indent(level, frm);
    778 		printf("Flags:");
    779 		for (i = 0; i < len; i++)
    780 			printf(" 0x%2.2x", data[i]);
    781 		printf("\n");
    782 		break;
    783 
    784 	case 0x02:
    785 	case 0x03:
    786 		p_indent(level, frm);
    787 		printf("%s service classes:",
    788 				type == 0x02 ? "Shortened" : "Complete");
    789 
    790 		for (i = 0; i < len / 2; i++) {
    791 			uint16_t val;
    792 
    793 			val = btohs(bt_get_unaligned(((uint16_t *) (data + i * 2))));
    794 			printf(" 0x%4.4x", val);
    795 		}
    796 		printf("\n");
    797 		break;
    798 
    799 	case 0x08:
    800 	case 0x09:
    801 		str = malloc(len + 1);
    802 		if (str) {
    803 			snprintf(str, len + 1, "%s", (char *) data);
    804 			for (i = 0; i < len; i++)
    805 				if (!isprint(str[i]))
    806 					str[i] = '.';
    807 			p_indent(level, frm);
    808 			printf("%s local name: \'%s\'\n",
    809 				type == 0x08 ? "Shortened" : "Complete", str);
    810 			free(str);
    811 		}
    812 		break;
    813 
    814 	case 0x0a:
    815 		p_indent(level, frm);
    816 		printf("TX power level: %d\n", *((uint8_t *) data));
    817 		break;
    818 
    819 	default:
    820 		p_indent(level, frm);
    821 		printf("Unknown type 0x%02x with %d bytes data\n",
    822 							type, len);
    823 		break;
    824 	}
    825 }
    826 
    827 static inline void ext_inquiry_response_dump(int level, struct frame *frm)
    828 {
    829 	void *ptr = frm->ptr;
    830 	uint32_t len = frm->len;
    831 	uint8_t length;
    832 
    833 	length = get_u8(frm);
    834 
    835 	while (length > 0) {
    836 		ext_inquiry_data_dump(level, frm, frm->ptr);
    837 
    838 		frm->ptr += length;
    839 		frm->len -= length;
    840 
    841 		length = get_u8(frm);
    842 	}
    843 
    844 	frm->ptr = ptr +
    845 		(EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
    846 	frm->len = len +
    847 		(EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
    848 }
    849 
    850 static inline void bdaddr_command_dump(int level, struct frame *frm)
    851 {
    852 	bdaddr_t *bdaddr = frm->ptr;
    853 	char addr[18];
    854 
    855 	frm->ptr += sizeof(bdaddr_t);
    856 	frm->len -= sizeof(bdaddr_t);
    857 
    858 	p_indent(level, frm);
    859 	p_ba2str(bdaddr, addr);
    860 	printf("bdaddr %s\n", addr);
    861 
    862 	raw_dump(level, frm);
    863 }
    864 
    865 static inline void generic_command_dump(int level, struct frame *frm)
    866 {
    867 	uint16_t handle = btohs(htons(get_u16(frm)));
    868 
    869 	p_indent(level, frm);
    870 	printf("handle %d\n", handle);
    871 
    872 	raw_dump(level, frm);
    873 }
    874 
    875 static inline void generic_write_mode_dump(int level, struct frame *frm)
    876 {
    877 	uint8_t mode = get_u8(frm);
    878 
    879 	p_indent(level, frm);
    880 	printf("mode 0x%2.2x\n", mode);
    881 }
    882 
    883 static inline void inquiry_dump(int level, struct frame *frm)
    884 {
    885 	inquiry_cp *cp = frm->ptr;
    886 
    887 	p_indent(level, frm);
    888 	printf("lap 0x%2.2x%2.2x%2.2x len %d num %d\n",
    889 		cp->lap[2], cp->lap[1], cp->lap[0], cp->length, cp->num_rsp);
    890 }
    891 
    892 static inline void periodic_inquiry_dump(int level, struct frame *frm)
    893 {
    894 	periodic_inquiry_cp *cp = frm->ptr;
    895 
    896 	p_indent(level, frm);
    897 	printf("max %d min %d lap 0x%2.2x%2.2x%2.2x len %d num %d\n",
    898 		btohs(cp->max_period), btohs(cp->min_period),
    899 		cp->lap[2], cp->lap[1], cp->lap[0], cp->length, cp->num_rsp);
    900 }
    901 
    902 static inline void create_conn_dump(int level, struct frame *frm)
    903 {
    904 	create_conn_cp *cp = frm->ptr;
    905 	uint16_t ptype = btohs(cp->pkt_type);
    906 	uint16_t clkoffset = btohs(cp->clock_offset);
    907 	char addr[18], *str;
    908 
    909 	p_indent(level, frm);
    910 	p_ba2str(&cp->bdaddr, addr);
    911 	printf("bdaddr %s ptype 0x%4.4x rswitch 0x%2.2x clkoffset 0x%4.4x%s\n",
    912 		addr, ptype, cp->role_switch,
    913 		clkoffset & 0x7fff, clkoffset & 0x8000 ? " (valid)" : "");
    914 
    915 	str = hci_ptypetostr(ptype);
    916 	if (str) {
    917 		p_indent(level, frm);
    918 		printf("Packet type: %s\n", str);
    919 		free(str);
    920 	}
    921 }
    922 
    923 static inline void disconnect_dump(int level, struct frame *frm)
    924 {
    925 	disconnect_cp *cp = frm->ptr;
    926 
    927 	p_indent(level, frm);
    928 	printf("handle %d reason 0x%2.2x\n", btohs(cp->handle), cp->reason);
    929 
    930 	p_indent(level, frm);
    931 	printf("Reason: %s\n", status2str(cp->reason));
    932 }
    933 
    934 static inline void add_sco_dump(int level, struct frame *frm)
    935 {
    936 	add_sco_cp *cp = frm->ptr;
    937 	uint16_t ptype = btohs(cp->pkt_type);
    938 	char *str;
    939 
    940 	p_indent(level, frm);
    941 	printf("handle %d ptype 0x%4.4x\n", btohs(cp->handle), ptype);
    942 
    943 	str = hci_ptypetostr(ptype);
    944 	if (str) {
    945 		p_indent(level, frm);
    946 		printf("Packet type: %s\n", str);
    947 		free(str);
    948 	}
    949 }
    950 
    951 static inline void accept_conn_req_dump(int level, struct frame *frm)
    952 {
    953 	accept_conn_req_cp *cp = frm->ptr;
    954 	char addr[18];
    955 
    956 	p_indent(level, frm);
    957 	p_ba2str(&cp->bdaddr, addr);
    958 	printf("bdaddr %s role 0x%2.2x\n", addr, cp->role);
    959 
    960 	p_indent(level, frm);
    961 	printf("Role: %s\n", role2str(cp->role));
    962 }
    963 
    964 static inline void reject_conn_req_dump(int level, struct frame *frm)
    965 {
    966 	reject_conn_req_cp *cp = frm->ptr;
    967 	char addr[18];
    968 
    969 	p_indent(level, frm);
    970 	p_ba2str(&cp->bdaddr, addr);
    971 	printf("bdaddr %s reason 0x%2.2x\n", addr, cp->reason);
    972 
    973 	p_indent(level, frm);
    974 	printf("Reason: %s\n", status2str(cp->reason));
    975 }
    976 
    977 static inline void pin_code_reply_dump(int level, struct frame *frm)
    978 {
    979 	pin_code_reply_cp *cp = frm->ptr;
    980 	char addr[18], pin[17];
    981 
    982 	p_indent(level, frm);
    983 	p_ba2str(&cp->bdaddr, addr);
    984 	memset(pin, 0, sizeof(pin));
    985 	if (parser.flags & DUMP_NOVENDOR)
    986 		memset(pin, '*', cp->pin_len);
    987 	else
    988 		memcpy(pin, cp->pin_code, cp->pin_len);
    989 	printf("bdaddr %s len %d pin \'%s\'\n", addr, cp->pin_len, pin);
    990 }
    991 
    992 static inline void link_key_reply_dump(int level, struct frame *frm)
    993 {
    994 	link_key_reply_cp *cp = frm->ptr;
    995 	char addr[18];
    996 	int i;
    997 
    998 	p_indent(level, frm);
    999 	p_ba2str(&cp->bdaddr, addr);
   1000 	printf("bdaddr %s key ", addr);
   1001 	for (i = 0; i < 16; i++)
   1002 		if (parser.flags & DUMP_NOVENDOR)
   1003 			printf("**");
   1004 		else
   1005 			printf("%2.2X", cp->link_key[i]);
   1006 	printf("\n");
   1007 }
   1008 
   1009 static inline void pin_code_neg_reply_dump(int level, struct frame *frm)
   1010 {
   1011 	bdaddr_t *bdaddr = frm->ptr;
   1012 	char addr[18];
   1013 
   1014 	p_indent(level, frm);
   1015 	p_ba2str(bdaddr, addr);
   1016 	printf("bdaddr %s\n", addr);
   1017 }
   1018 
   1019 static inline void user_passkey_reply_dump(int level, struct frame *frm)
   1020 {
   1021 	user_passkey_reply_cp *cp = frm->ptr;
   1022 	char addr[18];
   1023 
   1024 	p_indent(level, frm);
   1025 	p_ba2str(&cp->bdaddr, addr);
   1026 	printf("bdaddr %s passkey %d\n", addr, btohl(cp->passkey));
   1027 }
   1028 
   1029 static inline void remote_oob_data_reply_dump(int level, struct frame *frm)
   1030 {
   1031 	remote_oob_data_reply_cp *cp = frm->ptr;
   1032 	char addr[18];
   1033 	int i;
   1034 
   1035 	p_indent(level, frm);
   1036 	p_ba2str(&cp->bdaddr, addr);
   1037 	printf("bdaddr %s\n", addr);
   1038 
   1039 	p_indent(level, frm);
   1040 	printf("hash 0x");
   1041 	for (i = 0; i < 16; i++)
   1042 		printf("%02x", cp->hash[i]);
   1043 	printf("\n");
   1044 
   1045 	p_indent(level, frm);
   1046 	printf("randomizer 0x");
   1047 	for (i = 0; i < 16; i++)
   1048 			printf("%02x", cp->randomizer[i]);
   1049 	printf("\n");
   1050 }
   1051 
   1052 static inline void io_capability_reply_dump(int level, struct frame *frm)
   1053 {
   1054 	io_capability_reply_cp *cp = frm->ptr;
   1055 	char addr[18];
   1056 
   1057 	p_indent(level, frm);
   1058 	p_ba2str(&cp->bdaddr, addr);
   1059 	printf("bdaddr %s capability 0x%2.2x oob 0x%2.2x auth 0x%2.2x\n",
   1060 					addr, cp->capability, cp->oob_data,
   1061 							cp->authentication);
   1062 
   1063 	p_indent(level, frm);
   1064 	printf("Capability: %s (OOB data %s)\n",
   1065 			capability2str(cp->capability),
   1066 			cp->oob_data == 0x00 ? "not present" : "available");
   1067 
   1068 	p_indent(level, frm);
   1069 	printf("Authentication: %s\n", authentication2str(cp->authentication));
   1070 }
   1071 
   1072 static inline void set_conn_encrypt_dump(int level, struct frame *frm)
   1073 {
   1074 	set_conn_encrypt_cp *cp = frm->ptr;
   1075 
   1076 	p_indent(level, frm);
   1077 	printf("handle %d encrypt 0x%2.2x\n", btohs(cp->handle), cp->encrypt);
   1078 }
   1079 
   1080 static inline void remote_name_req_dump(int level, struct frame *frm)
   1081 {
   1082 	remote_name_req_cp *cp = frm->ptr;
   1083 	uint16_t clkoffset = btohs(cp->clock_offset);
   1084 	char addr[18];
   1085 
   1086 	p_indent(level, frm);
   1087 	p_ba2str(&cp->bdaddr, addr);
   1088 	printf("bdaddr %s mode %d clkoffset 0x%4.4x%s\n",
   1089 		addr, cp->pscan_rep_mode,
   1090 		clkoffset & 0x7fff, clkoffset & 0x8000 ? " (valid)" : "");
   1091 }
   1092 
   1093 static inline void master_link_key_dump(int level, struct frame *frm)
   1094 {
   1095 	master_link_key_cp *cp = frm->ptr;
   1096 
   1097 	p_indent(level, frm);
   1098 	printf("flag %d\n", cp->key_flag);
   1099 }
   1100 
   1101 static inline void read_remote_ext_features_dump(int level, struct frame *frm)
   1102 {
   1103 	read_remote_ext_features_cp *cp = frm->ptr;
   1104 
   1105 	p_indent(level, frm);
   1106 	printf("handle %d page %d\n", btohs(cp->handle), cp->page_num);
   1107 }
   1108 
   1109 static inline void setup_sync_conn_dump(int level, struct frame *frm)
   1110 {
   1111 	setup_sync_conn_cp *cp = frm->ptr;
   1112 
   1113 	p_indent(level, frm);
   1114 	printf("handle %d voice setting 0x%4.4x ptype 0x%4.4x\n",
   1115 		btohs(cp->handle), btohs(cp->voice_setting),
   1116 		btohs(cp->pkt_type));
   1117 }
   1118 
   1119 static inline void create_physical_link_dump(int level, struct frame *frm)
   1120 {
   1121 	create_physical_link_cp *cp = frm->ptr;
   1122 	int i;
   1123 
   1124 	p_indent(level, frm);
   1125 
   1126 	printf("handle %d key length %d key type %d\n",
   1127 		cp->handle, cp->key_length, cp->key_type);
   1128 	printf("key ");
   1129 
   1130 	for (i = 0; i < cp->key_length && cp->key_length < 32; i++)
   1131 		printf("%2.2x", cp->key[i]);
   1132 	printf("\n");
   1133 }
   1134 
   1135 static inline void create_logical_link_dump(int level, struct frame *frm)
   1136 {
   1137 	create_logical_link_cp *cp = frm->ptr;
   1138 	int i;
   1139 
   1140 	p_indent(level, frm);
   1141 
   1142 	printf("handle %d\n", cp->handle);
   1143 	printf("tx_flow ");
   1144 	for (i = 0; i < 16; i++)
   1145 		printf("%2.2x", cp->tx_flow[i]);
   1146 	printf("\nrx_flow ");
   1147 	for (i = 0; i < 16; i++)
   1148 		printf("%2.2x", cp->rx_flow[i]);
   1149 	printf("\n");
   1150 }
   1151 
   1152 static inline void accept_sync_conn_req_dump(int level, struct frame *frm)
   1153 {
   1154 	accept_sync_conn_req_cp *cp = frm->ptr;
   1155 	char addr[18];
   1156 
   1157 	p_indent(level, frm);
   1158 	p_ba2str(&cp->bdaddr, addr);
   1159 	printf("bdaddr %s voice_setting 0x%4.4x pkt_type 0x%4.4x\n",
   1160 		addr, btohs(cp->voice_setting), btohs(cp->pkt_type));
   1161 }
   1162 
   1163 static inline void hold_mode_dump(int level, struct frame *frm)
   1164 {
   1165 	hold_mode_cp *cp = frm->ptr;
   1166 
   1167 	p_indent(level, frm);
   1168 	printf("handle %d max %d min %d\n", btohs(cp->handle),
   1169 			btohs(cp->max_interval), btohs(cp->min_interval));
   1170 }
   1171 
   1172 static inline void sniff_mode_dump(int level, struct frame *frm)
   1173 {
   1174 	sniff_mode_cp *cp = frm->ptr;
   1175 
   1176 	p_indent(level, frm);
   1177 	printf("handle %d max %d min %d attempt %d timeout %d\n",
   1178 		btohs(cp->handle), btohs(cp->max_interval),
   1179 		btohs(cp->min_interval), btohs(cp->attempt), btohs(cp->timeout));
   1180 }
   1181 
   1182 static inline void qos_setup_dump(int level, struct frame *frm)
   1183 {
   1184 	qos_setup_cp *cp = frm->ptr;
   1185 
   1186 	p_indent(level, frm);
   1187 	printf("handle %d flags 0x%2.2x\n", btohs(cp->handle), cp->flags);
   1188 
   1189 	p_indent(level, frm);
   1190 	printf("Service type: %d\n", cp->qos.service_type);
   1191 	p_indent(level, frm);
   1192 	printf("Token rate: %d\n", btohl(cp->qos.token_rate));
   1193 	p_indent(level, frm);
   1194 	printf("Peak bandwith: %d\n", btohl(cp->qos.peak_bandwidth));
   1195 	p_indent(level, frm);
   1196 	printf("Latency: %d\n", btohl(cp->qos.latency));
   1197 	p_indent(level, frm);
   1198 	printf("Delay variation: %d\n", btohl(cp->qos.delay_variation));
   1199 }
   1200 
   1201 static inline void write_link_policy_dump(int level, struct frame *frm)
   1202 {
   1203 	write_link_policy_cp *cp = frm->ptr;
   1204 	uint16_t policy = btohs(cp->policy);
   1205 	char *str;
   1206 
   1207 	p_indent(level, frm);
   1208 	printf("handle %d policy 0x%2.2x\n", btohs(cp->handle), policy);
   1209 
   1210 	str = hci_lptostr(policy);
   1211 	if (str) {
   1212 		p_indent(level, frm);
   1213 		printf("Link policy: %s\n", str);
   1214 		free(str);
   1215 	}
   1216 }
   1217 
   1218 static inline void write_default_link_policy_dump(int level, struct frame *frm)
   1219 {
   1220 	uint16_t policy = btohs(htons(get_u16(frm)));
   1221 	char *str;
   1222 
   1223 	p_indent(level, frm);
   1224 	printf("policy 0x%2.2x\n", policy);
   1225 
   1226 	str = hci_lptostr(policy);
   1227 	if (str) {
   1228 		p_indent(level, frm);
   1229 		printf("Link policy: %s\n", str);
   1230 		free(str);
   1231 	}
   1232 }
   1233 
   1234 static inline void sniff_subrating_dump(int level, struct frame *frm)
   1235 {
   1236 	sniff_subrating_cp *cp = frm->ptr;
   1237 
   1238 	p_indent(level, frm);
   1239 	printf("handle %d\n", btohs(cp->handle));
   1240 
   1241 	p_indent(level, frm);
   1242 	printf("max latency %d\n", btohs(cp->max_latency));
   1243 
   1244 	p_indent(level, frm);
   1245 	printf("min timeout remote %d local %d\n",
   1246 		btohs(cp->min_remote_timeout), btohs(cp->min_local_timeout));
   1247 }
   1248 
   1249 static inline void set_event_mask_dump(int level, struct frame *frm)
   1250 {
   1251 	set_event_mask_cp *cp = frm->ptr;
   1252 	int i;
   1253 
   1254 	p_indent(level, frm);
   1255 	printf("Mask: 0x");
   1256 	for (i = 0; i < 8; i++)
   1257 		printf("%2.2x", cp->mask[i]);
   1258 	printf("\n");
   1259 }
   1260 
   1261 static inline void set_event_flt_dump(int level, struct frame *frm)
   1262 {
   1263 	set_event_flt_cp *cp = frm->ptr;
   1264 	uint8_t dev_class[3], dev_mask[3];
   1265 	char addr[18];
   1266 
   1267 	p_indent(level, frm);
   1268 	printf("type %d condition %d\n", cp->flt_type,
   1269 				(cp->flt_type == 0) ? 0 : cp->cond_type);
   1270 
   1271 	switch (cp->flt_type) {
   1272 	case FLT_CLEAR_ALL:
   1273 		p_indent(level, frm);
   1274 		printf("Clear all filters\n");
   1275 		break;
   1276 	case FLT_INQ_RESULT:
   1277 		p_indent(level, frm);
   1278 		printf("Inquiry result");
   1279 		switch (cp->cond_type) {
   1280 		case INQ_RESULT_RETURN_ALL:
   1281 			printf(" for all devices\n");
   1282 			break;
   1283 		case INQ_RESULT_RETURN_CLASS:
   1284 			memcpy(dev_class, cp->condition, 3);
   1285 			memcpy(dev_mask, cp->condition + 3, 3);
   1286 			printf(" with class 0x%2.2x%2.2x%2.2x mask 0x%2.2x%2.2x%2.2x\n",
   1287 				dev_class[2], dev_class[1], dev_class[0],
   1288 				dev_mask[2], dev_mask[1], dev_mask[0]);
   1289 			break;
   1290 		case INQ_RESULT_RETURN_BDADDR:
   1291 			p_ba2str((bdaddr_t *) cp->condition, addr);
   1292 			printf(" with bdaddr %s\n", addr);
   1293 			break;
   1294 		default:
   1295 			printf("\n");
   1296 			break;
   1297 		}
   1298 		break;
   1299 	case FLT_CONN_SETUP:
   1300 		p_indent(level, frm);
   1301 		printf("Connection setup");
   1302 		switch (cp->cond_type) {
   1303 		case CONN_SETUP_ALLOW_ALL:
   1304 		case CONN_SETUP_ALLOW_CLASS:
   1305 		case CONN_SETUP_ALLOW_BDADDR:
   1306 		default:
   1307 			printf("\n");
   1308 			break;
   1309 		}
   1310 		break;
   1311 	}
   1312 }
   1313 
   1314 static inline void write_pin_type_dump(int level, struct frame *frm)
   1315 {
   1316 	write_pin_type_cp *cp = frm->ptr;
   1317 
   1318 	p_indent(level, frm);
   1319 	printf("type %d\n", cp->pin_type);
   1320 }
   1321 
   1322 static inline void request_stored_link_key_dump(int level, struct frame *frm)
   1323 {
   1324 	read_stored_link_key_cp *cp = frm->ptr;
   1325 	char addr[18];
   1326 
   1327 	p_indent(level, frm);
   1328 	p_ba2str(&cp->bdaddr, addr);
   1329 	printf("bdaddr %s all %d\n", addr, cp->read_all);
   1330 }
   1331 
   1332 static inline void return_link_keys_dump(int level, struct frame *frm)
   1333 {
   1334 	uint8_t num = get_u8(frm);
   1335 	uint8_t key[16];
   1336 	char addr[18];
   1337 	int i, n;
   1338 
   1339 	for (n = 0; n < num; n++) {
   1340 		p_ba2str(frm->ptr, addr);
   1341 		memcpy(key, frm->ptr + 6, 16);
   1342 
   1343 		p_indent(level, frm);
   1344 		printf("bdaddr %s key ", addr);
   1345 		for (i = 0; i < 16; i++)
   1346 			if (parser.flags & DUMP_NOVENDOR)
   1347 				printf("**");
   1348 			else
   1349 				printf("%2.2X", key[i]);
   1350 		printf("\n");
   1351 
   1352 		frm->ptr += 2;
   1353 		frm->len -= 2;
   1354 	}
   1355 }
   1356 
   1357 static inline void change_local_name_dump(int level, struct frame *frm)
   1358 {
   1359 	change_local_name_cp *cp = frm->ptr;
   1360 	char name[249];
   1361 	int i;
   1362 
   1363 	memset(name, 0, sizeof(name));
   1364 	for (i = 0; i < 248 && cp->name[i]; i++)
   1365 		if (isprint(cp->name[i]))
   1366 			name[i] = cp->name[i];
   1367 		else
   1368 			name[i] = '.';
   1369 
   1370 	p_indent(level, frm);
   1371 	printf("name \'%s\'\n", name);
   1372 }
   1373 
   1374 static inline void write_class_of_dev_dump(int level, struct frame *frm)
   1375 {
   1376 	write_class_of_dev_cp *cp = frm->ptr;
   1377 
   1378 	p_indent(level, frm);
   1379 	printf("class 0x%2.2x%2.2x%2.2x\n",
   1380 			cp->dev_class[2], cp->dev_class[1], cp->dev_class[0]);
   1381 }
   1382 
   1383 static inline void write_voice_setting_dump(int level, struct frame *frm)
   1384 {
   1385 	write_voice_setting_cp *cp = frm->ptr;
   1386 
   1387 	p_indent(level, frm);
   1388 	printf("voice setting 0x%4.4x\n", btohs(cp->voice_setting));
   1389 }
   1390 
   1391 static inline void write_current_iac_lap_dump(int level, struct frame *frm)
   1392 {
   1393 	write_current_iac_lap_cp *cp = frm->ptr;
   1394 	int i;
   1395 
   1396 	for (i = 0; i < cp->num_current_iac; i++) {
   1397 		p_indent(level, frm);
   1398 		printf("IAC 0x%2.2x%2.2x%2.2x", cp->lap[i][2], cp->lap[i][1], cp->lap[i][0]);
   1399 		if (cp->lap[i][2] == 0x9e && cp->lap[i][1] == 0x8b) {
   1400 			switch (cp->lap[i][0]) {
   1401 			case 0x00:
   1402 				printf(" (Limited Inquiry Access Code)");
   1403 				break;
   1404 			case 0x33:
   1405 				printf(" (General Inquiry Access Code)");
   1406 				break;
   1407 			}
   1408 		}
   1409 		printf("\n");
   1410 	}
   1411 }
   1412 
   1413 static inline void write_scan_enable_dump(int level, struct frame *frm)
   1414 {
   1415 	uint8_t enable = get_u8(frm);
   1416 
   1417 	p_indent(level, frm);
   1418 	printf("enable %d\n", enable);
   1419 }
   1420 
   1421 static inline void write_page_timeout_dump(int level, struct frame *frm)
   1422 {
   1423 	write_page_timeout_cp *cp = frm->ptr;
   1424 
   1425 	p_indent(level, frm);
   1426 	printf("timeout %d\n", btohs(cp->timeout));
   1427 }
   1428 
   1429 static inline void write_page_activity_dump(int level, struct frame *frm)
   1430 {
   1431 	write_page_activity_cp *cp = frm->ptr;
   1432 
   1433 	p_indent(level, frm);
   1434 	printf("interval %d window %d\n", btohs(cp->interval), btohs(cp->window));
   1435 }
   1436 
   1437 static inline void write_inquiry_scan_type_dump(int level, struct frame *frm)
   1438 {
   1439 	write_inquiry_scan_type_cp *cp = frm->ptr;
   1440 
   1441 	p_indent(level, frm);
   1442 	printf("type %d\n", cp->type);
   1443 }
   1444 
   1445 static inline void write_inquiry_mode_dump(int level, struct frame *frm)
   1446 {
   1447 	write_inquiry_mode_cp *cp = frm->ptr;
   1448 
   1449 	p_indent(level, frm);
   1450 	printf("mode %d\n", cp->mode);
   1451 }
   1452 
   1453 static inline void set_afh_classification_dump(int level, struct frame *frm)
   1454 {
   1455 	set_afh_classification_cp *cp = frm->ptr;
   1456 	int i;
   1457 
   1458 	p_indent(level, frm);
   1459 	printf("map 0x");
   1460 	for (i = 0; i < 10; i++)
   1461 		printf("%02x", cp->map[i]);
   1462 	printf("\n");
   1463 }
   1464 
   1465 static inline void write_link_supervision_timeout_dump(int level, struct frame *frm)
   1466 {
   1467 	write_link_supervision_timeout_cp *cp = frm->ptr;
   1468 
   1469 	p_indent(level, frm);
   1470 	printf("handle %d timeout %d\n",
   1471 				btohs(cp->handle), btohs(cp->timeout));
   1472 }
   1473 
   1474 static inline void write_ext_inquiry_response_dump(int level, struct frame *frm)
   1475 {
   1476 	write_ext_inquiry_response_cp *cp = frm->ptr;
   1477 
   1478 	p_indent(level, frm);
   1479 	printf("fec 0x%2.2x\n", cp->fec);
   1480 
   1481 	frm->ptr++;
   1482 	frm->len--;
   1483 
   1484 	ext_inquiry_response_dump(level, frm);
   1485 }
   1486 
   1487 static inline void write_inquiry_transmit_power_level_dump(int level, struct frame *frm)
   1488 {
   1489 	write_inquiry_transmit_power_level_cp *cp = frm->ptr;
   1490 
   1491 	p_indent(level, frm);
   1492 	printf("level %d\n", cp->level);
   1493 }
   1494 
   1495 static inline void write_default_error_data_reporting_dump(int level, struct frame *frm)
   1496 {
   1497 	write_default_error_data_reporting_cp *cp = frm->ptr;
   1498 
   1499 	p_indent(level, frm);
   1500 	printf("reporting %d\n", cp->reporting);
   1501 }
   1502 
   1503 static inline void enhanced_flush_dump(int level, struct frame *frm)
   1504 {
   1505 	enhanced_flush_cp *cp = frm->ptr;
   1506 
   1507 	p_indent(level, frm);
   1508 	printf("handle %d type %d\n", btohs(cp->handle), cp->type);
   1509 }
   1510 
   1511 static inline void send_keypress_notify_dump(int level, struct frame *frm)
   1512 {
   1513 	send_keypress_notify_cp *cp = frm->ptr;
   1514 	char addr[18];
   1515 
   1516 	p_indent(level, frm);
   1517 	p_ba2str(&cp->bdaddr, addr);
   1518 	printf("bdaddr %s type %d\n", addr, cp->type);
   1519 }
   1520 
   1521 static inline void request_transmit_power_level_dump(int level, struct frame *frm)
   1522 {
   1523 	read_transmit_power_level_cp *cp = frm->ptr;
   1524 
   1525 	p_indent(level, frm);
   1526 	printf("handle %d type %d (%s)\n",
   1527 					btohs(cp->handle), cp->type,
   1528 					cp->type ? "maximum" : "current");
   1529 }
   1530 
   1531 static inline void request_local_ext_features_dump(int level, struct frame *frm)
   1532 {
   1533 	read_local_ext_features_cp *cp = frm->ptr;
   1534 
   1535 	p_indent(level, frm);
   1536 	printf("page %d\n", cp->page_num);
   1537 }
   1538 
   1539 static inline void request_clock_dump(int level, struct frame *frm)
   1540 {
   1541 	read_clock_cp *cp = frm->ptr;
   1542 
   1543 	p_indent(level, frm);
   1544 	printf("handle %d which %d (%s)\n",
   1545 					btohs(cp->handle), cp->which_clock,
   1546 					cp->which_clock ? "piconet" : "local");
   1547 }
   1548 
   1549 static inline void host_buffer_size_dump(int level, struct frame *frm)
   1550 {
   1551 	host_buffer_size_cp *cp = frm->ptr;
   1552 
   1553 	p_indent(level, frm);
   1554 	printf("ACL MTU %d:%d SCO MTU %d:%d\n",
   1555 				btohs(cp->acl_mtu), btohs(cp->acl_max_pkt),
   1556 				cp->sco_mtu, btohs(cp->sco_max_pkt));
   1557 }
   1558 
   1559 static inline void num_comp_pkts_dump(int level, struct frame *frm)
   1560 {
   1561 	uint8_t num = get_u8(frm);
   1562 	uint16_t handle, packets;
   1563 	int i;
   1564 
   1565 	for (i = 0; i < num; i++) {
   1566 		handle = btohs(htons(get_u16(frm)));
   1567 		packets = btohs(htons(get_u16(frm)));
   1568 
   1569 		p_indent(level, frm);
   1570 		printf("handle %d packets %d\n", handle, packets);
   1571 	}
   1572 }
   1573 
   1574 static inline void le_create_connection_dump(int level, struct frame *frm)
   1575 {
   1576 	char addr[18];
   1577 	le_create_connection_cp *cp = frm->ptr;
   1578 
   1579 	p_indent(level, frm);
   1580 	p_ba2str(&cp->peer_bdaddr, addr);
   1581 	printf("bdaddr %s type %d\n", addr, cp->peer_bdaddr_type);
   1582 }
   1583 
   1584 static inline void le_set_event_mask_dump(int level, struct frame *frm)
   1585 {
   1586 	int i;
   1587 	le_set_event_mask_cp *cp = frm->ptr;
   1588 
   1589 	p_indent(level, frm);
   1590 	printf("mask 0x");
   1591 	for (i = 0; i < 8; i++)
   1592 		printf("%.2x", cp->mask[i]);
   1593 
   1594 	printf(" (%s)\n", eventmask2str(cp->mask));
   1595 }
   1596 
   1597 static inline void le_set_random_address_dump(int level, struct frame *frm)
   1598 {
   1599 	char addr[18];
   1600 	le_set_random_address_cp *cp = frm->ptr;
   1601 
   1602 	p_indent(level, frm);
   1603 	p_ba2str(&cp->bdaddr, addr);
   1604 	printf("bdaddr %s\n", addr);
   1605 }
   1606 
   1607 
   1608 static inline void le_set_advertising_parameters_dump(int level, struct frame *frm)
   1609 {
   1610 	char addr[18];
   1611 	le_set_advertising_parameters_cp *cp = frm->ptr;
   1612 
   1613 	p_indent(level, frm);
   1614 	printf("min %.3fms, max %.3fms\n", btohs(cp->min_interval) * 0.625,
   1615 			btohs(cp->max_interval) * 0.625);
   1616 
   1617 	p_indent(level, frm);
   1618 	printf("type 0x%02x (%s) ownbdaddr 0x%02x (%s)\n", cp->advtype,
   1619 			evttype2str(cp->advtype), cp->own_bdaddr_type,
   1620 			bdaddrtype2str(cp->own_bdaddr_type));
   1621 
   1622 	p_indent(level, frm);
   1623 	p_ba2str(&cp->direct_bdaddr, addr);
   1624 	printf("directbdaddr 0x%02x (%s) %s\n", cp->direct_bdaddr_type,
   1625 			bdaddrtype2str(cp->direct_bdaddr_type), addr);
   1626 
   1627 	p_indent(level, frm);
   1628 	printf("channelmap 0x%02x filterpolicy 0x%02x (%s)\n",
   1629 			cp->chan_map, cp->filter, filterpolicy2str(cp->filter));
   1630 }
   1631 
   1632 static inline void le_set_scan_parameters_dump(int level, struct frame *frm)
   1633 {
   1634 	le_set_scan_parameters_cp *cp = frm->ptr;
   1635 
   1636 	p_indent(level, frm);
   1637 	printf("type 0x%02x (%s)\n", cp->type,
   1638 		cp->type == 0x00 ? "passive" : "active");
   1639 
   1640 	p_indent(level, frm);
   1641 	printf("interval %.3fms window %.3fms\n", btohs(cp->interval) * 0.625,
   1642 		btohs(cp->window) * 0.625);
   1643 
   1644 	p_indent(level, frm);
   1645 	printf("own address: 0x%02x (%s) policy: %s\n", cp->own_bdaddr_type,
   1646 			bdaddrtype2str(cp->own_bdaddr_type),
   1647 		(cp->filter == 0x00 ? "All" :
   1648 			(cp->filter == 0x01 ? "white list only" : "reserved")));
   1649 }
   1650 
   1651 static inline void le_set_scan_enable_dump(int level, struct frame *frm)
   1652 {
   1653 	le_set_scan_enable_cp *cp = frm->ptr;
   1654 
   1655 	p_indent(level, frm);
   1656 	printf("value 0x%02x (%s)\n", cp->enable,
   1657 		(cp->enable == 0x00 ? "scanning disabled" :
   1658 		"scanning enabled"));
   1659 
   1660 	p_indent(level, frm);
   1661 	printf("filter duplicates 0x%02x (%s)\n", cp->filter_dup,
   1662 		(cp->filter_dup == 0x00 ? "disabled" : "enabled"));
   1663 }
   1664 
   1665 static inline void command_dump(int level, struct frame *frm)
   1666 {
   1667 	hci_command_hdr *hdr = frm->ptr;
   1668 	uint16_t opcode = btohs(hdr->opcode);
   1669 	uint16_t ogf = cmd_opcode_ogf(opcode);
   1670 	uint16_t ocf = cmd_opcode_ocf(opcode);
   1671 
   1672 	if (p_filter(FILT_HCI))
   1673 		return;
   1674 
   1675 	if (ogf == OGF_VENDOR_CMD && (parser.flags & DUMP_NOVENDOR))
   1676 		return;
   1677 
   1678 	p_indent(level, frm);
   1679 	printf("HCI Command: %s (0x%2.2x|0x%4.4x) plen %d\n",
   1680 				opcode2str(opcode), ogf, ocf, hdr->plen);
   1681 
   1682 	frm->ptr += HCI_COMMAND_HDR_SIZE;
   1683 	frm->len -= HCI_COMMAND_HDR_SIZE;
   1684 
   1685 	if (ogf == OGF_VENDOR_CMD) {
   1686 		if (ocf == 0 && get_manufacturer() == 10) {
   1687 			csr_dump(level + 1, frm);
   1688 			return;
   1689 		}
   1690 	}
   1691 
   1692 	if (!(parser.flags & DUMP_VERBOSE)) {
   1693 		raw_dump(level, frm);
   1694 		return;
   1695 	}
   1696 
   1697 	switch (ogf) {
   1698 	case OGF_LINK_CTL:
   1699 		switch (ocf) {
   1700 		case OCF_INQUIRY:
   1701 			inquiry_dump(level + 1, frm);
   1702 			return;
   1703 		case OCF_PERIODIC_INQUIRY:
   1704 			periodic_inquiry_dump(level + 1, frm);
   1705 			return;
   1706 		case OCF_INQUIRY_CANCEL:
   1707 		case OCF_EXIT_PERIODIC_INQUIRY:
   1708 			return;
   1709 		case OCF_CREATE_CONN:
   1710 			create_conn_dump(level + 1, frm);
   1711 			return;
   1712 		case OCF_DISCONNECT:
   1713 			disconnect_dump(level + 1, frm);
   1714 			return;
   1715 		case OCF_CREATE_CONN_CANCEL:
   1716 		case OCF_REMOTE_NAME_REQ_CANCEL:
   1717 			bdaddr_command_dump(level + 1, frm);
   1718 			return;
   1719 		case OCF_ACCEPT_SYNC_CONN_REQ:
   1720 			accept_sync_conn_req_dump(level + 1, frm);
   1721 			return;
   1722 		case OCF_ADD_SCO:
   1723 		case OCF_SET_CONN_PTYPE:
   1724 			add_sco_dump(level + 1, frm);
   1725 			return;
   1726 		case OCF_ACCEPT_CONN_REQ:
   1727 			accept_conn_req_dump(level + 1, frm);
   1728 			return;
   1729 		case OCF_REJECT_CONN_REQ:
   1730 		case OCF_REJECT_SYNC_CONN_REQ:
   1731 		case OCF_IO_CAPABILITY_NEG_REPLY:
   1732 			reject_conn_req_dump(level + 1, frm);
   1733 			return;
   1734 		case OCF_PIN_CODE_REPLY:
   1735 			pin_code_reply_dump(level + 1, frm);
   1736 			return;
   1737 		case OCF_LINK_KEY_REPLY:
   1738 			link_key_reply_dump(level + 1, frm);
   1739 			return;
   1740 		case OCF_PIN_CODE_NEG_REPLY:
   1741 		case OCF_LINK_KEY_NEG_REPLY:
   1742 		case OCF_USER_CONFIRM_REPLY:
   1743 		case OCF_USER_CONFIRM_NEG_REPLY:
   1744 		case OCF_USER_PASSKEY_NEG_REPLY:
   1745 		case OCF_REMOTE_OOB_DATA_NEG_REPLY:
   1746 			pin_code_neg_reply_dump(level + 1, frm);
   1747 			return;
   1748 		case OCF_USER_PASSKEY_REPLY:
   1749 			user_passkey_reply_dump(level + 1, frm);
   1750 			return;
   1751 		case OCF_REMOTE_OOB_DATA_REPLY:
   1752 			remote_oob_data_reply_dump(level + 1, frm);
   1753 			return;
   1754 		case OCF_IO_CAPABILITY_REPLY:
   1755 			io_capability_reply_dump(level + 1, frm);
   1756 			return;
   1757 		case OCF_SET_CONN_ENCRYPT:
   1758 			set_conn_encrypt_dump(level + 1, frm);
   1759 			return;
   1760 		case OCF_AUTH_REQUESTED:
   1761 		case OCF_CHANGE_CONN_LINK_KEY:
   1762 		case OCF_READ_REMOTE_FEATURES:
   1763 		case OCF_READ_REMOTE_VERSION:
   1764 		case OCF_READ_CLOCK_OFFSET:
   1765 		case OCF_READ_LMP_HANDLE:
   1766 		case OCF_DISCONNECT_LOGICAL_LINK:
   1767 			generic_command_dump(level + 1, frm);
   1768 			return;
   1769 		case OCF_MASTER_LINK_KEY:
   1770 			master_link_key_dump(level + 1, frm);
   1771 			return;
   1772 		case OCF_READ_REMOTE_EXT_FEATURES:
   1773 			read_remote_ext_features_dump(level + 1, frm);
   1774 			return;
   1775 		case OCF_REMOTE_NAME_REQ:
   1776 			remote_name_req_dump(level + 1, frm);
   1777 			return;
   1778 		case OCF_SETUP_SYNC_CONN:
   1779 			setup_sync_conn_dump(level + 1, frm);
   1780 			return;
   1781 		case OCF_CREATE_PHYSICAL_LINK:
   1782 		case OCF_ACCEPT_PHYSICAL_LINK:
   1783 			create_physical_link_dump(level + 1, frm);
   1784 			return;
   1785 		case OCF_CREATE_LOGICAL_LINK:
   1786 		case OCF_ACCEPT_LOGICAL_LINK:
   1787 			create_logical_link_dump(level + 1, frm);
   1788 			return;
   1789 		}
   1790 		break;
   1791 
   1792 	case OGF_LINK_POLICY:
   1793 		switch (ocf) {
   1794 		case OCF_HOLD_MODE:
   1795 		case OCF_PARK_MODE:
   1796 			hold_mode_dump(level + 1, frm);
   1797 			return;
   1798 		case OCF_SNIFF_MODE:
   1799 			sniff_mode_dump(level + 1, frm);
   1800 			return;
   1801 		case OCF_EXIT_SNIFF_MODE:
   1802 		case OCF_EXIT_PARK_MODE:
   1803 		case OCF_ROLE_DISCOVERY:
   1804 		case OCF_READ_LINK_POLICY:
   1805 			generic_command_dump(level + 1, frm);
   1806 			return;
   1807 		case OCF_READ_DEFAULT_LINK_POLICY:
   1808 			return;
   1809 		case OCF_SWITCH_ROLE:
   1810 			accept_conn_req_dump(level + 1, frm);
   1811 			return;
   1812 		case OCF_QOS_SETUP:
   1813 			qos_setup_dump(level + 1, frm);
   1814 			return;
   1815 		case OCF_WRITE_LINK_POLICY:
   1816 			write_link_policy_dump(level + 1, frm);
   1817 			return;
   1818 		case OCF_WRITE_DEFAULT_LINK_POLICY:
   1819 			write_default_link_policy_dump(level + 1, frm);
   1820 			return;
   1821 		case OCF_SNIFF_SUBRATING:
   1822 			sniff_subrating_dump(level + 1, frm);
   1823 			return;
   1824 		}
   1825 		break;
   1826 
   1827 	case OGF_HOST_CTL:
   1828 		switch (ocf) {
   1829 		case OCF_RESET:
   1830 		case OCF_CREATE_NEW_UNIT_KEY:
   1831 			return;
   1832 		case OCF_SET_EVENT_MASK:
   1833 		case OCF_SET_EVENT_MASK_PAGE_2:
   1834 			set_event_mask_dump(level + 1, frm);
   1835 			return;
   1836 		case OCF_SET_EVENT_FLT:
   1837 			set_event_flt_dump(level + 1, frm);
   1838 			return;
   1839 		case OCF_WRITE_PIN_TYPE:
   1840 			write_pin_type_dump(level + 1, frm);
   1841 			return;
   1842 		case OCF_READ_STORED_LINK_KEY:
   1843 		case OCF_DELETE_STORED_LINK_KEY:
   1844 			request_stored_link_key_dump(level + 1, frm);
   1845 			return;
   1846 		case OCF_WRITE_STORED_LINK_KEY:
   1847 			return_link_keys_dump(level + 1, frm);
   1848 			return;
   1849 		case OCF_CHANGE_LOCAL_NAME:
   1850 			change_local_name_dump(level + 1, frm);
   1851 			return;
   1852 		case OCF_WRITE_CLASS_OF_DEV:
   1853 			write_class_of_dev_dump(level + 1, frm);
   1854 			return;
   1855 		case OCF_WRITE_VOICE_SETTING:
   1856 			write_voice_setting_dump(level + 1, frm);
   1857 			return;
   1858 		case OCF_WRITE_CURRENT_IAC_LAP:
   1859 			write_current_iac_lap_dump(level + 1, frm);
   1860 			return;
   1861 		case OCF_WRITE_SCAN_ENABLE:
   1862 		case OCF_WRITE_AUTH_ENABLE:
   1863 		case OCF_SET_CONTROLLER_TO_HOST_FC:
   1864 			write_scan_enable_dump(level + 1, frm);
   1865 			return;
   1866 		case OCF_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
   1867 		case OCF_WRITE_CONN_ACCEPT_TIMEOUT:
   1868 		case OCF_WRITE_PAGE_TIMEOUT:
   1869 			write_page_timeout_dump(level + 1, frm);
   1870 			return;
   1871 		case OCF_WRITE_PAGE_ACTIVITY:
   1872 		case OCF_WRITE_INQ_ACTIVITY:
   1873 			write_page_activity_dump(level + 1, frm);
   1874 			return;
   1875 		case OCF_WRITE_INQUIRY_SCAN_TYPE:
   1876 			write_inquiry_scan_type_dump(level + 1, frm);
   1877 			return;
   1878 		case OCF_WRITE_ENCRYPT_MODE:
   1879 		case OCF_WRITE_INQUIRY_MODE:
   1880 		case OCF_WRITE_AFH_MODE:
   1881 			write_inquiry_mode_dump(level + 1, frm);
   1882 			return;
   1883 		case OCF_SET_AFH_CLASSIFICATION:
   1884 			set_afh_classification_dump(level + 1, frm);
   1885 			return;
   1886 		case OCF_READ_TRANSMIT_POWER_LEVEL:
   1887 			request_transmit_power_level_dump(level + 1, frm);
   1888 			return;
   1889 		case OCF_HOST_BUFFER_SIZE:
   1890 			host_buffer_size_dump(level + 1, frm);
   1891 			return;
   1892 		case OCF_HOST_NUM_COMP_PKTS:
   1893 			num_comp_pkts_dump(level + 1, frm);
   1894 			return;
   1895 		case OCF_FLUSH:
   1896 		case OCF_READ_LINK_SUPERVISION_TIMEOUT:
   1897 		case OCF_REFRESH_ENCRYPTION_KEY:
   1898 		case OCF_READ_BEST_EFFORT_FLUSH_TIMEOUT:
   1899 			generic_command_dump(level + 1, frm);
   1900 			return;
   1901 		case OCF_WRITE_LINK_SUPERVISION_TIMEOUT:
   1902 			write_link_supervision_timeout_dump(level + 1, frm);
   1903 			return;
   1904 		case OCF_WRITE_EXT_INQUIRY_RESPONSE:
   1905 			write_ext_inquiry_response_dump(level + 1, frm);
   1906 			return;
   1907 		case OCF_WRITE_SIMPLE_PAIRING_MODE:
   1908 		case OCF_WRITE_FLOW_CONTROL_MODE:
   1909 			generic_write_mode_dump(level + 1, frm);
   1910 			return;
   1911 		case OCF_WRITE_INQUIRY_TRANSMIT_POWER_LEVEL:
   1912 			write_inquiry_transmit_power_level_dump(level + 1, frm);
   1913 			return;
   1914 		case OCF_WRITE_DEFAULT_ERROR_DATA_REPORTING:
   1915 			write_default_error_data_reporting_dump(level + 1, frm);
   1916 			return;
   1917 		case OCF_ENHANCED_FLUSH:
   1918 			enhanced_flush_dump(level + 1, frm);
   1919 			return;
   1920 		case OCF_SEND_KEYPRESS_NOTIFY:
   1921 			send_keypress_notify_dump(level + 1, frm);
   1922 			return;
   1923 		}
   1924 		break;
   1925 
   1926 	case OGF_INFO_PARAM:
   1927 		switch (ocf) {
   1928 		case OCF_READ_LOCAL_EXT_FEATURES:
   1929 			request_local_ext_features_dump(level + 1, frm);
   1930 			return;
   1931 		}
   1932 		break;
   1933 
   1934 	case OGF_STATUS_PARAM:
   1935 		switch (ocf) {
   1936 		case OCF_READ_LINK_QUALITY:
   1937 		case OCF_READ_RSSI:
   1938 		case OCF_READ_AFH_MAP:
   1939 			generic_command_dump(level + 1, frm);
   1940 			return;
   1941 		case OCF_READ_CLOCK:
   1942 			request_clock_dump(level + 1, frm);
   1943 			return;
   1944 		}
   1945 		break;
   1946 
   1947 	case OGF_TESTING_CMD:
   1948 		switch (ocf) {
   1949 		case OCF_WRITE_LOOPBACK_MODE:
   1950 		case OCF_WRITE_SIMPLE_PAIRING_DEBUG_MODE:
   1951 			generic_write_mode_dump(level + 1, frm);
   1952 			return;
   1953 		}
   1954 		break;
   1955 
   1956 	case OGF_LE_CTL:
   1957 		switch (ocf) {
   1958 		case OCF_LE_SET_EVENT_MASK:
   1959 			le_set_event_mask_dump(level + 1, frm);
   1960 			return;
   1961 		case OCF_LE_READ_BUFFER_SIZE:
   1962 		case OCF_LE_READ_LOCAL_SUPPORTED_FEATURES:
   1963 		case OCF_LE_READ_ADVERTISING_CHANNEL_TX_POWER:
   1964 			return;
   1965 		case OCF_LE_SET_RANDOM_ADDRESS:
   1966 			le_set_random_address_dump(level + 1, frm);
   1967 			return;
   1968 		case OCF_LE_SET_ADVERTISING_PARAMETERS:
   1969 			le_set_advertising_parameters_dump(level + 1, frm);
   1970 			return;
   1971 		case OCF_LE_SET_SCAN_PARAMETERS:
   1972 			le_set_scan_parameters_dump(level + 1, frm);
   1973 			return;
   1974 		case OCF_LE_SET_SCAN_ENABLE:
   1975 			le_set_scan_enable_dump(level + 1, frm);
   1976 			return;
   1977 		case OCF_LE_CREATE_CONN:
   1978 			le_create_connection_dump(level + 1, frm);
   1979 			return;
   1980 		}
   1981 		break;
   1982 	}
   1983 
   1984 	raw_dump(level, frm);
   1985 }
   1986 
   1987 static inline void status_response_dump(int level, struct frame *frm)
   1988 {
   1989 	uint8_t status = get_u8(frm);
   1990 
   1991 	p_indent(level, frm);
   1992 	printf("status 0x%2.2x\n", status);
   1993 
   1994 	if (status > 0) {
   1995 		p_indent(level, frm);
   1996 		printf("Error: %s\n", status2str(status));
   1997 	}
   1998 
   1999 	raw_dump(level, frm);
   2000 }
   2001 
   2002 static inline void handle_response_dump(int level, struct frame *frm)
   2003 {
   2004 	uint16_t handle = btohs(htons(get_u16(frm)));
   2005 
   2006 	p_indent(level, frm);
   2007 	printf("handle %d\n", handle);
   2008 
   2009 	raw_dump(level, frm);
   2010 }
   2011 
   2012 static inline void bdaddr_response_dump(int level, struct frame *frm)
   2013 {
   2014 	uint8_t status = get_u8(frm);
   2015 	bdaddr_t *bdaddr = frm->ptr;
   2016 	char addr[18];
   2017 
   2018 	frm->ptr += sizeof(bdaddr_t);
   2019 	frm->len -= sizeof(bdaddr_t);
   2020 
   2021 	p_indent(level, frm);
   2022 	p_ba2str(bdaddr, addr);
   2023 	printf("status 0x%2.2x bdaddr %s\n", status, addr);
   2024 
   2025 	if (status > 0) {
   2026 		p_indent(level, frm);
   2027 		printf("Error: %s\n", status2str(status));
   2028 	}
   2029 
   2030 	raw_dump(level, frm);
   2031 }
   2032 
   2033 static inline void generic_response_dump(int level, struct frame *frm)
   2034 {
   2035 	uint8_t status = get_u8(frm);
   2036 	uint16_t handle = btohs(htons(get_u16(frm)));
   2037 
   2038 	p_indent(level, frm);
   2039 	printf("status 0x%2.2x handle %d\n", status, handle);
   2040 
   2041 	if (status > 0) {
   2042 		p_indent(level, frm);
   2043 		printf("Error: %s\n", status2str(status));
   2044 	}
   2045 
   2046 	raw_dump(level, frm);
   2047 }
   2048 
   2049 static inline void status_mode_dump(int level, struct frame *frm)
   2050 {
   2051 	uint8_t status = get_u8(frm);
   2052 	uint8_t mode = get_u8(frm);
   2053 
   2054 	p_indent(level, frm);
   2055 	printf("status 0x%2.2x mode 0x%2.2x\n", status, mode);
   2056 
   2057 	if (status > 0) {
   2058 		p_indent(level, frm);
   2059 		printf("Error: %s\n", status2str(status));
   2060 	}
   2061 }
   2062 
   2063 static inline void read_link_policy_dump(int level, struct frame *frm)
   2064 {
   2065 	read_link_policy_rp *rp = frm->ptr;
   2066 	uint16_t policy = btohs(rp->policy);
   2067 	char *str;
   2068 
   2069 	p_indent(level, frm);
   2070 	printf("status 0x%2.2x handle %d policy 0x%2.2x\n",
   2071 				rp->status, btohs(rp->handle), policy);
   2072 
   2073 	if (rp->status > 0) {
   2074 		p_indent(level, frm);
   2075 		printf("Error: %s\n", status2str(rp->status));
   2076 	} else {
   2077 		str = hci_lptostr(policy);
   2078 		if (str) {
   2079 			p_indent(level, frm);
   2080 			printf("Link policy: %s\n", str);
   2081 			free(str);
   2082 		}
   2083 	}
   2084 }
   2085 
   2086 static inline void read_default_link_policy_dump(int level, struct frame *frm)
   2087 {
   2088 	uint8_t status = get_u8(frm);
   2089 	uint16_t policy = btohs(htons(get_u16(frm)));
   2090 	char *str;
   2091 
   2092 	p_indent(level, frm);
   2093 	printf("status 0x%2.2x policy 0x%2.2x\n", status, policy);
   2094 
   2095 	if (status > 0) {
   2096 		p_indent(level, frm);
   2097 		printf("Error: %s\n", status2str(status));
   2098 	} else {
   2099 		str = hci_lptostr(policy);
   2100 		if (str) {
   2101 			p_indent(level, frm);
   2102 			printf("Link policy: %s\n", str);
   2103 			free(str);
   2104 		}
   2105 	}
   2106 }
   2107 
   2108 static inline void read_pin_type_dump(int level, struct frame *frm)
   2109 {
   2110 	read_pin_type_rp *rp = frm->ptr;
   2111 
   2112 	p_indent(level, frm);
   2113 	printf("status 0x%2.2x type %d\n", rp->status, rp->pin_type);
   2114 
   2115 	if (rp->status > 0) {
   2116 		p_indent(level, frm);
   2117 		printf("Error: %s\n", status2str(rp->status));
   2118 	}
   2119 }
   2120 
   2121 static inline void read_stored_link_key_dump(int level, struct frame *frm)
   2122 {
   2123 	read_stored_link_key_rp *rp = frm->ptr;
   2124 
   2125 	p_indent(level, frm);
   2126 	printf("status 0x%2.2x max %d num %d\n",
   2127 				rp->status, rp->max_keys, rp->num_keys);
   2128 
   2129 	if (rp->status > 0) {
   2130 		p_indent(level, frm);
   2131 		printf("Error: %s\n", status2str(rp->status));
   2132 	}
   2133 }
   2134 
   2135 static inline void write_stored_link_key_dump(int level, struct frame *frm)
   2136 {
   2137 	write_stored_link_key_rp *rp = frm->ptr;
   2138 
   2139 	p_indent(level, frm);
   2140 	printf("status 0x%2.2x written %d\n", rp->status, rp->num_keys);
   2141 
   2142 	if (rp->status > 0) {
   2143 		p_indent(level, frm);
   2144 		printf("Error: %s\n", status2str(rp->status));
   2145 	}
   2146 }
   2147 
   2148 static inline void delete_stored_link_key_dump(int level, struct frame *frm)
   2149 {
   2150 	delete_stored_link_key_rp *rp = frm->ptr;
   2151 
   2152 	p_indent(level, frm);
   2153 	printf("status 0x%2.2x deleted %d\n", rp->status, btohs(rp->num_keys));
   2154 
   2155 	if (rp->status > 0) {
   2156 		p_indent(level, frm);
   2157 		printf("Error: %s\n", status2str(rp->status));
   2158 	}
   2159 }
   2160 
   2161 static inline void read_local_name_dump(int level, struct frame *frm)
   2162 {
   2163 	read_local_name_rp *rp = frm->ptr;
   2164 	char name[249];
   2165 	int i;
   2166 
   2167 	memset(name, 0, sizeof(name));
   2168 	for (i = 0; i < 248 && rp->name[i]; i++)
   2169 		if (isprint(rp->name[i]))
   2170 			name[i] = rp->name[i];
   2171 		else
   2172 			name[i] = '.';
   2173 
   2174 	p_indent(level, frm);
   2175 	printf("status 0x%2.2x name \'%s\'\n", rp->status, name);
   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_class_of_dev_dump(int level, struct frame *frm)
   2184 {
   2185 	read_class_of_dev_rp *rp = frm->ptr;
   2186 
   2187 	p_indent(level, frm);
   2188 	printf("status 0x%2.2x class 0x%2.2x%2.2x%2.2x\n", rp->status,
   2189 			rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
   2190 
   2191 	if (rp->status > 0) {
   2192 		p_indent(level, frm);
   2193 		printf("Error: %s\n", status2str(rp->status));
   2194 	}
   2195 }
   2196 
   2197 static inline void read_voice_setting_dump(int level, struct frame *frm)
   2198 {
   2199 	read_voice_setting_rp *rp = frm->ptr;
   2200 
   2201 	p_indent(level, frm);
   2202 	printf("status 0x%2.2x voice setting 0x%4.4x\n",
   2203 					rp->status, btohs(rp->voice_setting));
   2204 
   2205 	if (rp->status > 0) {
   2206 		p_indent(level, frm);
   2207 		printf("Error: %s\n", status2str(rp->status));
   2208 	}
   2209 }
   2210 
   2211 static inline void read_current_iac_lap_dump(int level, struct frame *frm)
   2212 {
   2213 	read_current_iac_lap_rp *rp = frm->ptr;
   2214 	int i;
   2215 
   2216 	for (i = 0; i < rp->num_current_iac; i++) {
   2217 		p_indent(level, frm);
   2218 		printf("IAC 0x%2.2x%2.2x%2.2x", rp->lap[i][2], rp->lap[i][1], rp->lap[i][0]);
   2219 		if (rp->lap[i][2] == 0x9e && rp->lap[i][1] == 0x8b) {
   2220 			switch (rp->lap[i][0]) {
   2221 			case 0x00:
   2222 				printf(" (Limited Inquiry Access Code)");
   2223 				break;
   2224 			case 0x33:
   2225 				printf(" (General Inquiry Access Code)");
   2226 				break;
   2227 			}
   2228 		}
   2229 		printf("\n");
   2230 	}
   2231 }
   2232 
   2233 static inline void read_scan_enable_dump(int level, struct frame *frm)
   2234 {
   2235 	uint8_t status = get_u8(frm);
   2236 	uint8_t enable = get_u8(frm);
   2237 
   2238 	p_indent(level, frm);
   2239 	printf("status 0x%2.2x enable %d\n", status, enable);
   2240 
   2241 	if (status > 0) {
   2242 		p_indent(level, frm);
   2243 		printf("Error: %s\n", status2str(status));
   2244 	}
   2245 }
   2246 
   2247 static inline void read_page_timeout_dump(int level, struct frame *frm)
   2248 {
   2249 	read_page_timeout_rp *rp = frm->ptr;
   2250 
   2251 	p_indent(level, frm);
   2252 	printf("status 0x%2.2x timeout %d\n", rp->status, btohs(rp->timeout));
   2253 
   2254 	if (rp->status > 0) {
   2255 		p_indent(level, frm);
   2256 		printf("Error: %s\n", status2str(rp->status));
   2257 	}
   2258 }
   2259 
   2260 static inline void read_page_activity_dump(int level, struct frame *frm)
   2261 {
   2262 	read_page_activity_rp *rp = frm->ptr;
   2263 
   2264 	p_indent(level, frm);
   2265 	printf("status 0x%2.2x interval %d window %d\n",
   2266 			rp->status, btohs(rp->interval), btohs(rp->window));
   2267 
   2268 	if (rp->status > 0) {
   2269 		p_indent(level, frm);
   2270 		printf("Error: %s\n", status2str(rp->status));
   2271 	}
   2272 }
   2273 
   2274 static inline void read_inquiry_scan_type_dump(int level, struct frame *frm)
   2275 {
   2276 	read_inquiry_scan_type_rp *rp = frm->ptr;
   2277 
   2278 	p_indent(level, frm);
   2279 	printf("status 0x%2.2x type %d\n", rp->status, rp->type);
   2280 
   2281 	if (rp->status > 0) {
   2282 		p_indent(level, frm);
   2283 		printf("Error: %s\n", status2str(rp->status));
   2284 	}
   2285 }
   2286 
   2287 static inline void read_inquiry_mode_dump(int level, struct frame *frm)
   2288 {
   2289 	read_inquiry_mode_rp *rp = frm->ptr;
   2290 
   2291 	p_indent(level, frm);
   2292 	printf("status 0x%2.2x mode %d\n", rp->status, rp->mode);
   2293 
   2294 	if (rp->status > 0) {
   2295 		p_indent(level, frm);
   2296 		printf("Error: %s\n", status2str(rp->status));
   2297 	}
   2298 }
   2299 
   2300 static inline void read_link_supervision_timeout_dump(int level, struct frame *frm)
   2301 {
   2302 	read_link_supervision_timeout_rp *rp = frm->ptr;
   2303 
   2304 	p_indent(level, frm);
   2305 	printf("status 0x%2.2x handle %d timeout %d\n",
   2306 			rp->status, btohs(rp->handle), btohs(rp->timeout));
   2307 
   2308 	if (rp->status > 0) {
   2309 		p_indent(level, frm);
   2310 		printf("Error: %s\n", status2str(rp->status));
   2311 	}
   2312 }
   2313 
   2314 static inline void read_transmit_power_level_dump(int level, struct frame *frm)
   2315 {
   2316 	read_transmit_power_level_rp *rp = frm->ptr;
   2317 
   2318 	p_indent(level, frm);
   2319 	printf("status 0x%2.2x handle %d level %d\n",
   2320 				rp->status, btohs(rp->handle), rp->level);
   2321 
   2322 	if (rp->status > 0) {
   2323 		p_indent(level, frm);
   2324 		printf("Error: %s\n", status2str(rp->status));
   2325 	}
   2326 }
   2327 
   2328 static inline void read_ext_inquiry_response_dump(int level, struct frame *frm)
   2329 {
   2330 	read_ext_inquiry_response_rp *rp = frm->ptr;
   2331 
   2332 	p_indent(level, frm);
   2333 	printf("status 0x%2.2x fec 0x%2.2x\n", rp->status, rp->fec);
   2334 
   2335 	if (rp->status > 0) {
   2336 		p_indent(level, frm);
   2337 		printf("Error: %s\n", status2str(rp->status));
   2338 	} else {
   2339 		frm->ptr += 2;
   2340 		frm->len -= 2;
   2341 
   2342 		ext_inquiry_response_dump(level, frm);
   2343 	}
   2344 }
   2345 
   2346 static inline void read_inquiry_transmit_power_level_dump(int level, struct frame *frm)
   2347 {
   2348 	read_inquiry_transmit_power_level_rp *rp = frm->ptr;
   2349 
   2350 	p_indent(level, frm);
   2351 	printf("status 0x%2.2x level %d\n", rp->status, rp->level);
   2352 
   2353 	if (rp->status > 0) {
   2354 		p_indent(level, frm);
   2355 		printf("Error: %s\n", status2str(rp->status));
   2356 	}
   2357 }
   2358 
   2359 static inline void read_default_error_data_reporting_dump(int level, struct frame *frm)
   2360 {
   2361 	read_default_error_data_reporting_rp *rp = frm->ptr;
   2362 
   2363 	p_indent(level, frm);
   2364 	printf("status 0x%2.2x reporting %d\n", rp->status, rp->reporting);
   2365 
   2366 	if (rp->status > 0) {
   2367 		p_indent(level, frm);
   2368 		printf("Error: %s\n", status2str(rp->status));
   2369 	}
   2370 }
   2371 
   2372 static inline void read_local_oob_data_dump(int level, struct frame *frm)
   2373 {
   2374 	read_local_oob_data_rp *rp = frm->ptr;
   2375 	int i;
   2376 
   2377 	p_indent(level, frm);
   2378 	printf("status 0x%2.2x\n", rp->status);
   2379 
   2380 	if (rp->status > 0) {
   2381 		p_indent(level, frm);
   2382 		printf("Error: %s\n", status2str(rp->status));
   2383 	} else {
   2384 		p_indent(level, frm);
   2385 		printf("hash 0x");
   2386 		for (i = 0; i < 16; i++)
   2387 			printf("%02x", rp->hash[i]);
   2388 		printf("\n");
   2389 
   2390 		p_indent(level, frm);
   2391 		printf("randomizer 0x");
   2392 		for (i = 0; i < 16; i++)
   2393 			printf("%02x", rp->randomizer[i]);
   2394 		printf("\n");
   2395 	}
   2396 }
   2397 
   2398 static inline void read_local_version_dump(int level, struct frame *frm)
   2399 {
   2400 	read_local_version_rp *rp = frm->ptr;
   2401 	uint16_t manufacturer = btohs(rp->manufacturer);
   2402 
   2403 	p_indent(level, frm);
   2404 	printf("status 0x%2.2x\n", rp->status);
   2405 
   2406 	if (rp->status > 0) {
   2407 		p_indent(level, frm);
   2408 		printf("Error: %s\n", status2str(rp->status));
   2409 	} else {
   2410 		p_indent(level, frm);
   2411 		printf("HCI Version: %s (0x%x) HCI Revision: 0x%x\n",
   2412 					hci_vertostr(rp->hci_ver),
   2413 					rp->hci_ver, btohs(rp->hci_rev));
   2414 		p_indent(level, frm);
   2415 		printf("LMP Version: %s (0x%x) LMP Subversion: 0x%x\n",
   2416 					lmp_vertostr(rp->lmp_ver),
   2417 					rp->lmp_ver, btohs(rp->lmp_subver));
   2418 		p_indent(level, frm);
   2419 		printf("Manufacturer: %s (%d)\n",
   2420 				bt_compidtostr(manufacturer), manufacturer);
   2421 	}
   2422 }
   2423 
   2424 static inline void read_local_commands_dump(int level, struct frame *frm)
   2425 {
   2426 	read_local_commands_rp *rp = frm->ptr;
   2427 	int i, max = 0;
   2428 
   2429 	p_indent(level, frm);
   2430 	printf("status 0x%2.2x\n", rp->status);
   2431 
   2432 	if (rp->status > 0) {
   2433 		p_indent(level, frm);
   2434 		printf("Error: %s\n", status2str(rp->status));
   2435 	} else {
   2436 		for (i = 0; i < 64; i++)
   2437 			if (rp->commands[i])
   2438 				max = i + 1;
   2439 		p_indent(level, frm);
   2440 		printf("Commands: ");
   2441 		for (i = 0; i < (max > 32 ? 32 : max); i++)
   2442 			printf("%2.2x", rp->commands[i]);
   2443 		printf("\n");
   2444 		if (max > 32) {
   2445 			p_indent(level, frm);
   2446 			printf("          ");
   2447 			for (i = 32; i < max; i++)
   2448 				printf("%2.2x", rp->commands[i]);
   2449 			printf("\n");
   2450 		}
   2451 	}
   2452 }
   2453 
   2454 static inline void read_local_features_dump(int level, struct frame *frm)
   2455 {
   2456 	read_local_features_rp *rp = frm->ptr;
   2457 	int i;
   2458 
   2459 	p_indent(level, frm);
   2460 	printf("status 0x%2.2x\n", rp->status);
   2461 
   2462 	if (rp->status > 0) {
   2463 		p_indent(level, frm);
   2464 		printf("Error: %s\n", status2str(rp->status));
   2465 	} else {
   2466 		p_indent(level, frm);
   2467 		printf("Features:");
   2468 		for (i = 0; i < 8; i++)
   2469 			printf(" 0x%2.2x", rp->features[i]);
   2470 		printf("\n");
   2471 	}
   2472 }
   2473 
   2474 static inline void read_local_ext_features_dump(int level, struct frame *frm)
   2475 {
   2476 	read_local_ext_features_rp *rp = frm->ptr;
   2477 	int i;
   2478 
   2479 	p_indent(level, frm);
   2480 	printf("status 0x%2.2x page %d max %d\n",
   2481 		rp->status, rp->page_num, rp->max_page_num);
   2482 
   2483 	if (rp->status > 0) {
   2484 		p_indent(level, frm);
   2485 		printf("Error: %s\n", status2str(rp->status));
   2486 	} else {
   2487 		p_indent(level, frm);
   2488 		printf("Features:");
   2489 		for (i = 0; i < 8; i++)
   2490 			 printf(" 0x%2.2x", rp->features[i]);
   2491 		printf("\n");
   2492 	}
   2493 }
   2494 
   2495 static inline void read_buffer_size_dump(int level, struct frame *frm)
   2496 {
   2497 	read_buffer_size_rp *rp = frm->ptr;
   2498 
   2499 	p_indent(level, frm);
   2500 	printf("status 0x%2.2x\n", rp->status);
   2501 
   2502 	if (rp->status > 0) {
   2503 		p_indent(level, frm);
   2504 		printf("Error: %s\n", status2str(rp->status));
   2505 	} else {
   2506 		p_indent(level, frm);
   2507 		printf("ACL MTU %d:%d SCO MTU %d:%d\n",
   2508 				btohs(rp->acl_mtu), btohs(rp->acl_max_pkt),
   2509 				rp->sco_mtu, btohs(rp->sco_max_pkt));
   2510 	}
   2511 }
   2512 
   2513 static inline void read_link_quality_dump(int level, struct frame *frm)
   2514 {
   2515 	read_link_quality_rp *rp = frm->ptr;
   2516 
   2517 	p_indent(level, frm);
   2518 	printf("status 0x%2.2x handle %d lq %d\n",
   2519 			rp->status, btohs(rp->handle), rp->link_quality);
   2520 
   2521 	if (rp->status > 0) {
   2522 		p_indent(level, frm);
   2523 		printf("Error: %s\n", status2str(rp->status));
   2524 	}
   2525 }
   2526 
   2527 static inline void read_rssi_dump(int level, struct frame *frm)
   2528 {
   2529 	read_rssi_rp *rp = frm->ptr;
   2530 
   2531 	p_indent(level, frm);
   2532 	printf("status 0x%2.2x handle %d rssi %d\n",
   2533 				rp->status, btohs(rp->handle), rp->rssi);
   2534 
   2535 	if (rp->status > 0) {
   2536 		p_indent(level, frm);
   2537 		printf("Error: %s\n", status2str(rp->status));
   2538 	}
   2539 }
   2540 
   2541 static inline void read_afh_map_dump(int level, struct frame *frm)
   2542 {
   2543 	read_afh_map_rp *rp = frm->ptr;
   2544 	int i;
   2545 
   2546 	p_indent(level, frm);
   2547 	printf("status 0x%2.2x handle %d mode %d\n",
   2548 				rp->status, btohs(rp->handle), rp->mode);
   2549 
   2550 	if (rp->status > 0) {
   2551 		p_indent(level, frm);
   2552 		printf("Error: %s\n", status2str(rp->status));
   2553 	} else {
   2554 		p_indent(level, frm);
   2555 		printf("AFH map: 0x");
   2556 		for (i = 0; i < 10; i++)
   2557 			printf("%2.2x", rp->map[i]);
   2558 		printf("\n");
   2559 	}
   2560 }
   2561 
   2562 static inline void read_clock_dump(int level, struct frame *frm)
   2563 {
   2564 	read_clock_rp *rp = frm->ptr;
   2565 
   2566 	p_indent(level, frm);
   2567 	printf("status 0x%2.2x handle %d clock 0x%4.4x accuracy %d\n",
   2568 					rp->status, btohs(rp->handle),
   2569 					btohl(rp->clock), btohs(rp->accuracy));
   2570 
   2571 	if (rp->status > 0) {
   2572 		p_indent(level, frm);
   2573 		printf("Error: %s\n", status2str(rp->status));
   2574 	}
   2575 }
   2576 
   2577 static inline void read_local_amp_info_dump(int level, struct frame *frm)
   2578 {
   2579 	read_local_amp_info_rp *rp = frm->ptr;
   2580 
   2581 	p_indent(level, frm);
   2582 	printf("status 0x%2.2x amp status 0x%2.2x\n",
   2583 			rp->status, rp->amp_status);
   2584 	if (rp->status > 0) {
   2585 		p_indent(level, frm);
   2586 		printf("Error: %s\n", status2str(rp->status));
   2587 	} else {
   2588 		p_indent(level, frm);
   2589 		printf("total bandwidth %d, max guaranteed bandwidth %d\n",
   2590 			btohl(rp->total_bandwidth),
   2591 			btohl(rp->max_guaranteed_bandwidth));
   2592 		p_indent(level, frm);
   2593 		printf("min latency %d, max PDU %d, controller type 0x%2.2x\n",
   2594 			btohl(rp->min_latency), btohl(rp->max_pdu_size),
   2595 			rp->controller_type);
   2596 		p_indent(level, frm);
   2597 		printf("pal caps 0x%4.4x, max assoc len %d\n",
   2598 			btohs(rp->pal_caps), btohs(rp->max_amp_assoc_length));
   2599 		p_indent(level, frm);
   2600 		printf("max flush timeout %d, best effort flush timeout %d\n",
   2601 			btohl(rp->max_flush_timeout),
   2602 			btohl(rp->best_effort_flush_timeout));
   2603 	}
   2604 }
   2605 
   2606 static inline void read_local_amp_assoc_dump(int level, struct frame *frm)
   2607 {
   2608 	read_local_amp_assoc_rp *rp = frm->ptr;
   2609 	uint16_t len = btohs(rp->length);
   2610 	int i;
   2611 
   2612 	p_indent(level, frm);
   2613 	printf("status 0x%2.2x handle 0x%2.2x length %d\n",
   2614 			rp->status, rp->handle, len);
   2615 	if (rp->status > 0) {
   2616 		p_indent(level, frm);
   2617 		printf("Error: %s\n", status2str(rp->status));
   2618 	} else {
   2619 		for (i = 0; i < len; i++) {
   2620 			if (!(i % 16)) {
   2621 				printf("\n");
   2622 				p_indent(level, frm);
   2623 			}
   2624 			printf("%2.2x ", rp->fragment[i]);
   2625 		}
   2626 		printf("\n");
   2627 	}
   2628 }
   2629 
   2630 static inline void write_remote_amp_assoc_dump(int level, struct frame *frm)
   2631 {
   2632 	write_remote_amp_assoc_rp *rp = frm->ptr;
   2633 
   2634 	p_indent(level, frm);
   2635 	printf("status 0x%2.2x handle 0x%2.2x\n", rp->status, rp->handle);
   2636 	if (rp->status > 0) {
   2637 		p_indent(level, frm);
   2638 		printf("Error: %s\n", status2str(rp->status));
   2639 	}
   2640 }
   2641 
   2642 static inline void le_read_buffer_size_response_dump(int level, struct frame *frm)
   2643 {
   2644 	le_read_buffer_size_rp *rp = frm->ptr;
   2645 
   2646 	p_indent(level, frm);
   2647 	printf("status 0x%2.2x pktlen 0x%4.4x maxpkt 0x%2.2x\n", rp->status,
   2648 			rp->pkt_len, rp->max_pkt);
   2649 
   2650 	if (rp->status > 0) {
   2651 		p_indent(level, frm);
   2652 		printf("Error: %s\n", status2str(rp->status));
   2653 	}
   2654 }
   2655 
   2656 static inline void le_read_local_supported_features_dump(int level, struct frame *frm)
   2657 {
   2658 	int i;
   2659 	le_read_local_supported_features_rp *rp = frm->ptr;
   2660 
   2661 	p_indent(level, frm);
   2662 	printf("status 0x%2.2x features 0x", rp->status);
   2663 	for (i = 0; i < 8; i++)
   2664 		printf("%2.2x", rp->features[i]);
   2665 	printf(" (%s)\n", lefeatures2str(rp->features));
   2666 
   2667 	if (rp->status > 0) {
   2668 		p_indent(level, frm);
   2669 		printf("Error: %s\n", status2str(rp->status));
   2670 	}
   2671 }
   2672 
   2673 static inline void le_read_advertising_channel_tx_power_dump(int level, struct frame *frm)
   2674 {
   2675 	le_read_advertising_channel_tx_power_rp *rp = frm->ptr;
   2676 
   2677 	p_indent(level, frm);
   2678 	printf("status 0x%2.2x level 0x%x (dBm)\n", rp->status, rp->level);
   2679 
   2680 	if (rp->status > 0) {
   2681 		p_indent(level, frm);
   2682 		printf("Error: %s\n", status2str(rp->status));
   2683 	}
   2684 }
   2685 
   2686 static inline void cmd_complete_dump(int level, struct frame *frm)
   2687 {
   2688 	evt_cmd_complete *evt = frm->ptr;
   2689 	uint16_t opcode = btohs(evt->opcode);
   2690 	uint16_t ogf = cmd_opcode_ogf(opcode);
   2691 	uint16_t ocf = cmd_opcode_ocf(opcode);
   2692 
   2693 	if (ogf == OGF_VENDOR_CMD && (parser.flags & DUMP_NOVENDOR))
   2694 		return;
   2695 
   2696 	p_indent(level, frm);
   2697 	printf("%s (0x%2.2x|0x%4.4x) ncmd %d\n",
   2698 				opcode2str(opcode), ogf, ocf, evt->ncmd);
   2699 
   2700 	frm->ptr += EVT_CMD_COMPLETE_SIZE;
   2701 	frm->len -= EVT_CMD_COMPLETE_SIZE;
   2702 
   2703 	if (!(parser.flags & DUMP_VERBOSE)) {
   2704 		raw_dump(level, frm);
   2705 		return;
   2706 	}
   2707 
   2708 	switch (ogf) {
   2709 	case OGF_LINK_CTL:
   2710 		switch (ocf) {
   2711 		case OCF_INQUIRY_CANCEL:
   2712 		case OCF_PERIODIC_INQUIRY:
   2713 		case OCF_EXIT_PERIODIC_INQUIRY:
   2714 		case OCF_READ_REMOTE_EXT_FEATURES:
   2715 			status_response_dump(level, frm);
   2716 			return;
   2717 		case OCF_CREATE_CONN_CANCEL:
   2718 		case OCF_REMOTE_NAME_REQ_CANCEL:
   2719 		case OCF_PIN_CODE_REPLY:
   2720 		case OCF_LINK_KEY_REPLY:
   2721 		case OCF_PIN_CODE_NEG_REPLY:
   2722 		case OCF_LINK_KEY_NEG_REPLY:
   2723 		case OCF_USER_CONFIRM_REPLY:
   2724 		case OCF_USER_CONFIRM_NEG_REPLY:
   2725 		case OCF_USER_PASSKEY_REPLY:
   2726 		case OCF_USER_PASSKEY_NEG_REPLY:
   2727 		case OCF_REMOTE_OOB_DATA_REPLY:
   2728 		case OCF_REMOTE_OOB_DATA_NEG_REPLY:
   2729 		case OCF_IO_CAPABILITY_REPLY:
   2730 		case OCF_IO_CAPABILITY_NEG_REPLY:
   2731 			bdaddr_response_dump(level, frm);
   2732 			return;
   2733 		}
   2734 		break;
   2735 
   2736 	case OGF_LINK_POLICY:
   2737 		switch (ocf) {
   2738 		case OCF_READ_LINK_POLICY:
   2739 			read_link_policy_dump(level, frm);
   2740 			return;
   2741 		case OCF_WRITE_LINK_POLICY:
   2742 		case OCF_SNIFF_SUBRATING:
   2743 			generic_response_dump(level, frm);
   2744 			return;
   2745 		case OCF_READ_DEFAULT_LINK_POLICY:
   2746 			read_default_link_policy_dump(level, frm);
   2747 			return;
   2748 		case OCF_WRITE_DEFAULT_LINK_POLICY:
   2749 			status_response_dump(level, frm);
   2750 			return;
   2751 		}
   2752 		break;
   2753 
   2754 	case OGF_HOST_CTL:
   2755 		switch (ocf) {
   2756 		case OCF_READ_PIN_TYPE:
   2757 			read_pin_type_dump(level, frm);
   2758 			return;
   2759 		case OCF_READ_STORED_LINK_KEY:
   2760 			read_stored_link_key_dump(level, frm);
   2761 			return;
   2762 		case OCF_WRITE_STORED_LINK_KEY:
   2763 			write_stored_link_key_dump(level, frm);
   2764 			return;
   2765 		case OCF_DELETE_STORED_LINK_KEY:
   2766 			delete_stored_link_key_dump(level, frm);
   2767 			return;
   2768 		case OCF_READ_LOCAL_NAME:
   2769 			read_local_name_dump(level, frm);
   2770 			return;
   2771 		case OCF_READ_CLASS_OF_DEV:
   2772 			read_class_of_dev_dump(level, frm);
   2773 			return;
   2774 		case OCF_READ_VOICE_SETTING:
   2775 			read_voice_setting_dump(level, frm);
   2776 			return;
   2777 		case OCF_READ_CURRENT_IAC_LAP:
   2778 			read_current_iac_lap_dump(level, frm);
   2779 			return;
   2780 		case OCF_READ_SCAN_ENABLE:
   2781 		case OCF_READ_AUTH_ENABLE:
   2782 			read_scan_enable_dump(level, frm);
   2783 			return;
   2784 		case OCF_READ_CONN_ACCEPT_TIMEOUT:
   2785 		case OCF_READ_PAGE_TIMEOUT:
   2786 		case OCF_READ_LOGICAL_LINK_ACCEPT_TIMEOUT:
   2787 			read_page_timeout_dump(level, frm);
   2788 			return;
   2789 		case OCF_READ_PAGE_ACTIVITY:
   2790 		case OCF_READ_INQ_ACTIVITY:
   2791 			read_page_activity_dump(level, frm);
   2792 			return;
   2793 		case OCF_READ_INQUIRY_SCAN_TYPE:
   2794 			read_inquiry_scan_type_dump(level, frm);
   2795 			return;
   2796 		case OCF_READ_ENCRYPT_MODE:
   2797 		case OCF_READ_INQUIRY_MODE:
   2798 		case OCF_READ_AFH_MODE:
   2799 			read_inquiry_mode_dump(level, frm);
   2800 			return;
   2801 		case OCF_READ_LINK_SUPERVISION_TIMEOUT:
   2802 			read_link_supervision_timeout_dump(level, frm);
   2803 			return;
   2804 		case OCF_READ_TRANSMIT_POWER_LEVEL:
   2805 			read_transmit_power_level_dump(level, frm);
   2806 			return;
   2807 		case OCF_READ_EXT_INQUIRY_RESPONSE:
   2808 			read_ext_inquiry_response_dump(level, frm);
   2809 			return;
   2810 		case OCF_READ_INQUIRY_TRANSMIT_POWER_LEVEL:
   2811 			read_inquiry_transmit_power_level_dump(level, frm);
   2812 			return;
   2813 		case OCF_READ_DEFAULT_ERROR_DATA_REPORTING:
   2814 			read_default_error_data_reporting_dump(level, frm);
   2815 			return;
   2816 		case OCF_READ_LOCAL_OOB_DATA:
   2817 			read_local_oob_data_dump(level, frm);
   2818 			return;
   2819 		case OCF_READ_SIMPLE_PAIRING_MODE:
   2820 		case OCF_READ_FLOW_CONTROL_MODE:
   2821 			status_mode_dump(level, frm);
   2822 			return;
   2823 		case OCF_FLUSH:
   2824 		case OCF_WRITE_LINK_SUPERVISION_TIMEOUT:
   2825 			generic_response_dump(level, frm);
   2826 			return;
   2827 		case OCF_RESET:
   2828 		case OCF_SET_EVENT_MASK:
   2829 		case OCF_SET_EVENT_FLT:
   2830 		case OCF_WRITE_PIN_TYPE:
   2831 		case OCF_CREATE_NEW_UNIT_KEY:
   2832 		case OCF_CHANGE_LOCAL_NAME:
   2833 		case OCF_WRITE_CLASS_OF_DEV:
   2834 		case OCF_WRITE_VOICE_SETTING:
   2835 		case OCF_WRITE_CURRENT_IAC_LAP:
   2836 		case OCF_WRITE_SCAN_ENABLE:
   2837 		case OCF_WRITE_AUTH_ENABLE:
   2838 		case OCF_WRITE_ENCRYPT_MODE:
   2839 		case OCF_WRITE_CONN_ACCEPT_TIMEOUT:
   2840 		case OCF_WRITE_PAGE_TIMEOUT:
   2841 		case OCF_WRITE_PAGE_ACTIVITY:
   2842 		case OCF_WRITE_INQ_ACTIVITY:
   2843 		case OCF_WRITE_INQUIRY_SCAN_TYPE:
   2844 		case OCF_WRITE_INQUIRY_MODE:
   2845 		case OCF_WRITE_AFH_MODE:
   2846 		case OCF_SET_AFH_CLASSIFICATION:
   2847 		case OCF_WRITE_EXT_INQUIRY_RESPONSE:
   2848 		case OCF_WRITE_SIMPLE_PAIRING_MODE:
   2849 		case OCF_WRITE_INQUIRY_TRANSMIT_POWER_LEVEL:
   2850 		case OCF_WRITE_DEFAULT_ERROR_DATA_REPORTING:
   2851 		case OCF_SET_CONTROLLER_TO_HOST_FC:
   2852 		case OCF_HOST_BUFFER_SIZE:
   2853 		case OCF_REFRESH_ENCRYPTION_KEY:
   2854 		case OCF_SEND_KEYPRESS_NOTIFY:
   2855 		case OCF_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
   2856 		case OCF_SET_EVENT_MASK_PAGE_2:
   2857 		case OCF_WRITE_LOCATION_DATA:
   2858 		case OCF_WRITE_FLOW_CONTROL_MODE:
   2859 		case OCF_READ_BEST_EFFORT_FLUSH_TIMEOUT:
   2860 		case OCF_WRITE_BEST_EFFORT_FLUSH_TIMEOUT:
   2861 			status_response_dump(level, frm);
   2862 			return;
   2863 		}
   2864 		break;
   2865 
   2866 	case OGF_INFO_PARAM:
   2867 		switch (ocf) {
   2868 		case OCF_READ_LOCAL_VERSION:
   2869 			read_local_version_dump(level, frm);
   2870 			return;
   2871 		case OCF_READ_LOCAL_COMMANDS:
   2872 			read_local_commands_dump(level, frm);
   2873 			return;
   2874 		case OCF_READ_LOCAL_FEATURES:
   2875 			read_local_features_dump(level, frm);
   2876 			return;
   2877 		case OCF_READ_LOCAL_EXT_FEATURES:
   2878 			read_local_ext_features_dump(level, frm);
   2879 			return;
   2880 		case OCF_READ_BUFFER_SIZE:
   2881 			read_buffer_size_dump(level, frm);
   2882 			return;
   2883 		case OCF_READ_BD_ADDR:
   2884 			bdaddr_response_dump(level, frm);
   2885 			return;
   2886 		}
   2887 		break;
   2888 
   2889 	case OGF_STATUS_PARAM:
   2890 		switch (ocf) {
   2891 		case OCF_READ_FAILED_CONTACT_COUNTER:
   2892 		case OCF_RESET_FAILED_CONTACT_COUNTER:
   2893 			status_response_dump(level, frm);
   2894 			return;
   2895 		case OCF_READ_LINK_QUALITY:
   2896 			read_link_quality_dump(level, frm);
   2897 			return;
   2898 		case OCF_READ_RSSI:
   2899 			read_rssi_dump(level, frm);
   2900 			return;
   2901 		case OCF_READ_AFH_MAP:
   2902 			read_afh_map_dump(level, frm);
   2903 			return;
   2904 		case OCF_READ_CLOCK:
   2905 			read_clock_dump(level, frm);
   2906 			return;
   2907 		case OCF_READ_LOCAL_AMP_INFO:
   2908 			read_local_amp_info_dump(level, frm);
   2909 			return;
   2910 		case OCF_READ_LOCAL_AMP_ASSOC:
   2911 			read_local_amp_assoc_dump(level, frm);
   2912 			return;
   2913 		case OCF_WRITE_REMOTE_AMP_ASSOC:
   2914 			write_remote_amp_assoc_dump(level, frm);
   2915 			return;
   2916 		}
   2917 		break;
   2918 
   2919 	case OGF_TESTING_CMD:
   2920 		switch (ocf) {
   2921 		case OCF_READ_LOOPBACK_MODE:
   2922 			status_mode_dump(level, frm);
   2923 			return;
   2924 		case OCF_WRITE_LOOPBACK_MODE:
   2925 		case OCF_ENABLE_DEVICE_UNDER_TEST_MODE:
   2926 		case OCF_WRITE_SIMPLE_PAIRING_DEBUG_MODE:
   2927 			status_response_dump(level, frm);
   2928 			return;
   2929 		}
   2930 		break;
   2931 
   2932 	case OGF_LE_CTL:
   2933 		switch (ocf) {
   2934 		case OCF_LE_SET_EVENT_MASK:
   2935 		case OCF_LE_SET_RANDOM_ADDRESS:
   2936 		case OCF_LE_SET_ADVERTISING_PARAMETERS:
   2937 		case OCF_LE_SET_ADVERTISING_DATA:
   2938 		case OCF_LE_SET_SCAN_RESPONSE_DATA:
   2939 		case OCF_LE_SET_ADVERTISE_ENABLE:
   2940 		case OCF_LE_SET_SCAN_PARAMETERS:
   2941 		case OCF_LE_SET_SCAN_ENABLE:
   2942 		case OCF_LE_CREATE_CONN:
   2943 		case OCF_LE_CLEAR_WHITE_LIST:
   2944 		case OCF_LE_ADD_DEVICE_TO_WHITE_LIST:
   2945 		case OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST:
   2946 		case OCF_LE_SET_HOST_CHANNEL_CLASSIFICATION:
   2947 		case OCF_LE_RECEIVER_TEST:
   2948 		case OCF_LE_TRANSMITTER_TEST:
   2949 			status_response_dump(level, frm);
   2950 			return;
   2951 		case OCF_LE_READ_BUFFER_SIZE:
   2952 			le_read_buffer_size_response_dump(level, frm);
   2953 			return;
   2954 		case OCF_LE_READ_LOCAL_SUPPORTED_FEATURES:
   2955 			le_read_local_supported_features_dump(level, frm);
   2956 			return;
   2957 		case OCF_LE_READ_ADVERTISING_CHANNEL_TX_POWER:
   2958 			le_read_advertising_channel_tx_power_dump(level, frm);
   2959 			return;
   2960 		}
   2961 		break;
   2962 	}
   2963 
   2964 	raw_dump(level, frm);
   2965 }
   2966 
   2967 static inline void cmd_status_dump(int level, struct frame *frm)
   2968 {
   2969 	evt_cmd_status *evt = frm->ptr;
   2970 	uint16_t opcode = btohs(evt->opcode);
   2971 	uint16_t ogf = cmd_opcode_ogf(opcode);
   2972 	uint16_t ocf = cmd_opcode_ocf(opcode);
   2973 
   2974 	if (ogf == OGF_VENDOR_CMD && (parser.flags & DUMP_NOVENDOR))
   2975 		return;
   2976 
   2977 	p_indent(level, frm);
   2978 	printf("%s (0x%2.2x|0x%4.4x) status 0x%2.2x ncmd %d\n",
   2979 			opcode2str(opcode), ogf, ocf, evt->status, evt->ncmd);
   2980 
   2981 	if (evt->status > 0) {
   2982 		p_indent(level, frm);
   2983 		printf("Error: %s\n", status2str(evt->status));
   2984 	}
   2985 }
   2986 
   2987 static inline void hardware_error_dump(int level, struct frame *frm)
   2988 {
   2989 	evt_hardware_error *evt = frm->ptr;
   2990 
   2991 	p_indent(level, frm);
   2992 	printf("code %d\n", evt->code);
   2993 }
   2994 
   2995 static inline void inq_result_dump(int level, struct frame *frm)
   2996 {
   2997 	uint8_t num = get_u8(frm);
   2998 	char addr[18];
   2999 	int i;
   3000 
   3001 	for (i = 0; i < num; i++) {
   3002 		inquiry_info *info = frm->ptr;
   3003 
   3004 		p_ba2str(&info->bdaddr, addr);
   3005 
   3006 		p_indent(level, frm);
   3007 		printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x\n",
   3008 			addr, info->pscan_rep_mode, btohs(info->clock_offset),
   3009 			info->dev_class[2], info->dev_class[1], info->dev_class[0]);
   3010 
   3011 		frm->ptr += INQUIRY_INFO_SIZE;
   3012 		frm->len -= INQUIRY_INFO_SIZE;
   3013 	}
   3014 }
   3015 
   3016 static inline void conn_complete_dump(int level, struct frame *frm)
   3017 {
   3018 	evt_conn_complete *evt = frm->ptr;
   3019 	char addr[18];
   3020 
   3021 	p_ba2str(&evt->bdaddr, addr);
   3022 
   3023 	p_indent(level, frm);
   3024 	printf("status 0x%2.2x handle %d bdaddr %s type %s encrypt 0x%2.2x\n",
   3025 			evt->status, btohs(evt->handle), addr,
   3026 			linktype2str(evt->link_type), evt->encr_mode);
   3027 
   3028 	if (evt->status > 0) {
   3029 		p_indent(level, frm);
   3030 		printf("Error: %s\n", status2str(evt->status));
   3031 	}
   3032 }
   3033 
   3034 static inline void conn_request_dump(int level, struct frame *frm)
   3035 {
   3036 	evt_conn_request *evt = frm->ptr;
   3037 	char addr[18];
   3038 
   3039 	p_ba2str(&evt->bdaddr, addr);
   3040 
   3041 	p_indent(level, frm);
   3042 	printf("bdaddr %s class 0x%2.2x%2.2x%2.2x type %s\n",
   3043 			addr, evt->dev_class[2], evt->dev_class[1],
   3044 			evt->dev_class[0], linktype2str(evt->link_type));
   3045 }
   3046 
   3047 static inline void disconn_complete_dump(int level, struct frame *frm)
   3048 {
   3049 	evt_disconn_complete *evt = frm->ptr;
   3050 
   3051 	p_indent(level, frm);
   3052 	printf("status 0x%2.2x handle %d reason 0x%2.2x\n",
   3053 				evt->status, btohs(evt->handle), evt->reason);
   3054 
   3055 	if (evt->status > 0) {
   3056 		p_indent(level, frm);
   3057 		printf("Error: %s\n", status2str(evt->status));
   3058 	} else if (evt->reason > 0) {
   3059 		p_indent(level, frm);
   3060 		printf("Reason: %s\n", status2str(evt->reason));
   3061 	}
   3062 }
   3063 
   3064 static inline void remote_name_req_complete_dump(int level, struct frame *frm)
   3065 {
   3066 	evt_remote_name_req_complete *evt = frm->ptr;
   3067 	char addr[18], name[249];
   3068 	int i;
   3069 
   3070 	p_ba2str(&evt->bdaddr, addr);
   3071 
   3072 	memset(name, 0, sizeof(name));
   3073 	for (i = 0; i < 248 && evt->name[i]; i++)
   3074 		if (isprint(evt->name[i]))
   3075 			name[i] = evt->name[i];
   3076 		else
   3077 			name[i] = '.';
   3078 
   3079 	p_indent(level, frm);
   3080 	printf("status 0x%2.2x bdaddr %s name '%s'\n", evt->status, addr, name);
   3081 
   3082 	if (evt->status > 0) {
   3083 		p_indent(level, frm);
   3084 		printf("Error: %s\n", status2str(evt->status));
   3085 	}
   3086 }
   3087 
   3088 static inline void master_link_key_complete_dump(int level, struct frame *frm)
   3089 {
   3090 	evt_master_link_key_complete *evt = frm->ptr;
   3091 
   3092 	p_indent(level, frm);
   3093 	printf("status 0x%2.2x handle %d flag %d\n",
   3094 				evt->status, btohs(evt->handle), evt->key_flag);
   3095 
   3096 	if (evt->status > 0) {
   3097 		p_indent(level, frm);
   3098 		printf("Error: %s\n", status2str(evt->status));
   3099 	}
   3100 }
   3101 
   3102 static inline void encrypt_change_dump(int level, struct frame *frm)
   3103 {
   3104 	evt_encrypt_change *evt = frm->ptr;
   3105 
   3106 	p_indent(level, frm);
   3107 	printf("status 0x%2.2x handle %d encrypt 0x%2.2x\n",
   3108 				evt->status, btohs(evt->handle), evt->encrypt);
   3109 
   3110 	if (evt->status > 0) {
   3111 		p_indent(level, frm);
   3112 		printf("Error: %s\n", status2str(evt->status));
   3113 	}
   3114 }
   3115 
   3116 static inline void read_remote_features_complete_dump(int level, struct frame *frm)
   3117 {
   3118 	evt_read_remote_features_complete *evt = frm->ptr;
   3119 	int i;
   3120 
   3121 	p_indent(level, frm);
   3122 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   3123 
   3124 	if (evt->status > 0) {
   3125 		p_indent(level, frm);
   3126 		printf("Error: %s\n", status2str(evt->status));
   3127 	} else {
   3128 		p_indent(level, frm);
   3129 		printf("Features:");
   3130 		for (i = 0; i < 8; i++)
   3131 			printf(" 0x%2.2x", evt->features[i]);
   3132 		printf("\n");
   3133 	}
   3134 }
   3135 
   3136 static inline void read_remote_version_complete_dump(int level, struct frame *frm)
   3137 {
   3138 	evt_read_remote_version_complete *evt = frm->ptr;
   3139 	uint16_t manufacturer = btohs(evt->manufacturer);
   3140 
   3141 	p_indent(level, frm);
   3142 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   3143 
   3144 	if (evt->status > 0) {
   3145 		p_indent(level, frm);
   3146 		printf("Error: %s\n", status2str(evt->status));
   3147 	} else {
   3148 		p_indent(level, frm);
   3149 		printf("LMP Version: %s (0x%x) LMP Subversion: 0x%x\n",
   3150 			lmp_vertostr(evt->lmp_ver), evt->lmp_ver,
   3151 			btohs(evt->lmp_subver));
   3152 		p_indent(level, frm);
   3153 		printf("Manufacturer: %s (%d)\n",
   3154 			bt_compidtostr(manufacturer), manufacturer);
   3155 	}
   3156 }
   3157 
   3158 static inline void qos_setup_complete_dump(int level, struct frame *frm)
   3159 {
   3160 	evt_qos_setup_complete *evt = frm->ptr;
   3161 
   3162 	p_indent(level, frm);
   3163 	printf("status 0x%2.2x handle %d flags %d\n",
   3164 				evt->status, btohs(evt->handle), evt->flags);
   3165 
   3166 	if (evt->status > 0) {
   3167 		p_indent(level, frm);
   3168 		printf("Error: %s\n", status2str(evt->status));
   3169 	} else {
   3170 		p_indent(level, frm);
   3171 		printf("Service type: %d\n", evt->qos.service_type);
   3172 		p_indent(level, frm);
   3173 		printf("Token rate: %d\n", btohl(evt->qos.token_rate));
   3174 		p_indent(level, frm);
   3175 		printf("Peak bandwith: %d\n", btohl(evt->qos.peak_bandwidth));
   3176 		p_indent(level, frm);
   3177 		printf("Latency: %d\n", btohl(evt->qos.latency));
   3178 		p_indent(level, frm);
   3179 		printf("Delay variation: %d\n", btohl(evt->qos.delay_variation));
   3180 	}
   3181 }
   3182 
   3183 static inline void role_change_dump(int level, struct frame *frm)
   3184 {
   3185 	evt_role_change *evt = frm->ptr;
   3186 	char addr[18];
   3187 
   3188 	p_indent(level, frm);
   3189 	p_ba2str(&evt->bdaddr, addr);
   3190 	printf("status 0x%2.2x bdaddr %s role 0x%2.2x\n",
   3191 						evt->status, addr, evt->role);
   3192 
   3193 	if (evt->status > 0) {
   3194 		p_indent(level, frm);
   3195 		printf("Error: %s\n", status2str(evt->status));
   3196 	} else {
   3197 		p_indent(level, frm);
   3198 		printf("Role: %s\n", role2str(evt->role));
   3199 	}
   3200 }
   3201 
   3202 static inline void mode_change_dump(int level, struct frame *frm)
   3203 {
   3204 	evt_mode_change *evt = frm->ptr;
   3205 
   3206 	p_indent(level, frm);
   3207 	printf("status 0x%2.2x handle %d mode 0x%2.2x interval %d\n",
   3208 		evt->status, btohs(evt->handle), evt->mode, btohs(evt->interval));
   3209 
   3210 	if (evt->status > 0) {
   3211 		p_indent(level, frm);
   3212 		printf("Error: %s\n", status2str(evt->status));
   3213 	} else {
   3214 		p_indent(level, frm);
   3215 		printf("Mode: %s\n", mode2str(evt->mode));
   3216 	}
   3217 }
   3218 
   3219 static inline void pin_code_req_dump(int level, struct frame *frm)
   3220 {
   3221 	evt_pin_code_req *evt = frm->ptr;
   3222 	char addr[18];
   3223 
   3224 	p_indent(level, frm);
   3225 	p_ba2str(&evt->bdaddr, addr);
   3226 	printf("bdaddr %s\n", addr);
   3227 }
   3228 
   3229 static inline void link_key_notify_dump(int level, struct frame *frm)
   3230 {
   3231 	evt_link_key_notify *evt = frm->ptr;
   3232 	char addr[18];
   3233 	int i;
   3234 
   3235 	p_indent(level, frm);
   3236 	p_ba2str(&evt->bdaddr, addr);
   3237 	printf("bdaddr %s key ", addr);
   3238 	for (i = 0; i < 16; i++)
   3239 		if (parser.flags & DUMP_NOVENDOR)
   3240 			printf("**");
   3241 		else
   3242 			printf("%2.2X", evt->link_key[i]);
   3243 	printf(" type %d\n", evt->key_type);
   3244 
   3245 	p_indent(level, frm);
   3246 	printf("Type: %s\n", keytype2str(evt->key_type));
   3247 }
   3248 
   3249 static inline void max_slots_change_dump(int level, struct frame *frm)
   3250 {
   3251 	evt_max_slots_change *evt = frm->ptr;
   3252 
   3253 	p_indent(level, frm);
   3254 	printf("handle %d slots %d\n", btohs(evt->handle), evt->max_slots);
   3255 }
   3256 
   3257 static inline void data_buffer_overflow_dump(int level, struct frame *frm)
   3258 {
   3259 	evt_data_buffer_overflow *evt = frm->ptr;
   3260 
   3261 	p_indent(level, frm);
   3262 	printf("type %s\n", linktype2str(evt->link_type));
   3263 }
   3264 
   3265 static inline void read_clock_offset_complete_dump(int level, struct frame *frm)
   3266 {
   3267 	evt_read_clock_offset_complete *evt = frm->ptr;
   3268 
   3269 	p_indent(level, frm);
   3270 	printf("status 0x%2.2x handle %d clkoffset 0x%4.4x\n",
   3271 		evt->status, btohs(evt->handle), btohs(evt->clock_offset));
   3272 
   3273 	if (evt->status > 0) {
   3274 		p_indent(level, frm);
   3275 		printf("Error: %s\n", status2str(evt->status));
   3276 	}
   3277 }
   3278 
   3279 static inline void conn_ptype_changed_dump(int level, struct frame *frm)
   3280 {
   3281 	evt_conn_ptype_changed *evt = frm->ptr;
   3282 	uint16_t ptype = btohs(evt->ptype);
   3283 	char *str;
   3284 
   3285 	p_indent(level, frm);
   3286 	printf("status 0x%2.2x handle %d ptype 0x%4.4x\n",
   3287 				evt->status, btohs(evt->handle), ptype);
   3288 
   3289 	if (evt->status > 0) {
   3290 		p_indent(level, frm);
   3291 		printf("Error: %s\n", status2str(evt->status));
   3292 	} else {
   3293 		str = hci_ptypetostr(ptype);
   3294 		if (str) {
   3295 			p_indent(level, frm);
   3296 			printf("Packet type: %s\n", str);
   3297 			free(str);
   3298 		}
   3299 	}
   3300 }
   3301 
   3302 static inline void pscan_rep_mode_change_dump(int level, struct frame *frm)
   3303 {
   3304 	evt_pscan_rep_mode_change *evt = frm->ptr;
   3305 	char addr[18];
   3306 
   3307 	p_indent(level, frm);
   3308 	p_ba2str(&evt->bdaddr, addr);
   3309 	printf("bdaddr %s mode %d\n", addr, evt->pscan_rep_mode);
   3310 }
   3311 
   3312 static inline void flow_spec_complete_dump(int level, struct frame *frm)
   3313 {
   3314 	evt_flow_spec_complete *evt = frm->ptr;
   3315 
   3316 	p_indent(level, frm);
   3317 	printf("status 0x%2.2x handle %d flags %d %s\n",
   3318 				evt->status, btohs(evt->handle), evt->flags,
   3319 				evt->direction == 0 ? "outgoing" : "incoming");
   3320 
   3321 	if (evt->status > 0) {
   3322 		p_indent(level, frm);
   3323 		printf("Error: %s\n", status2str(evt->status));
   3324 	} else {
   3325 		p_indent(level, frm);
   3326 		printf("Service type: %d\n", evt->qos.service_type);
   3327 		p_indent(level, frm);
   3328 		printf("Token rate: %d\n", btohl(evt->qos.token_rate));
   3329 		p_indent(level, frm);
   3330 		printf("Peak bandwith: %d\n", btohl(evt->qos.peak_bandwidth));
   3331 		p_indent(level, frm);
   3332 		printf("Latency: %d\n", btohl(evt->qos.latency));
   3333 		p_indent(level, frm);
   3334 		printf("Delay variation: %d\n", btohl(evt->qos.delay_variation));
   3335 	}
   3336 }
   3337 
   3338 static inline void inq_result_with_rssi_dump(int level, struct frame *frm)
   3339 {
   3340 	uint8_t num = get_u8(frm);
   3341 	char addr[18];
   3342 	int i;
   3343 
   3344 	if (!num)
   3345 		return;
   3346 
   3347 	if (frm->len / num == INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE) {
   3348 		for (i = 0; i < num; i++) {
   3349 			inquiry_info_with_rssi_and_pscan_mode *info = frm->ptr;
   3350 
   3351 			p_indent(level, frm);
   3352 
   3353 			p_ba2str(&info->bdaddr, addr);
   3354 			printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x rssi %d\n",
   3355 				addr, info->pscan_rep_mode, btohs(info->clock_offset),
   3356 				info->dev_class[2], info->dev_class[1], info->dev_class[0], info->rssi);
   3357 
   3358 			frm->ptr += INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE;
   3359 			frm->len -= INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE;
   3360 		}
   3361 	} else {
   3362 		for (i = 0; i < num; i++) {
   3363 			inquiry_info_with_rssi *info = frm->ptr;
   3364 
   3365 			p_indent(level, frm);
   3366 
   3367 			p_ba2str(&info->bdaddr, addr);
   3368 			printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x rssi %d\n",
   3369 				addr, info->pscan_rep_mode, btohs(info->clock_offset),
   3370 				info->dev_class[2], info->dev_class[1], info->dev_class[0], info->rssi);
   3371 
   3372 			frm->ptr += INQUIRY_INFO_WITH_RSSI_SIZE;
   3373 			frm->len -= INQUIRY_INFO_WITH_RSSI_SIZE;
   3374 		}
   3375 	}
   3376 }
   3377 
   3378 static inline void read_remote_ext_features_complete_dump(int level, struct frame *frm)
   3379 {
   3380 	evt_read_remote_ext_features_complete *evt = frm->ptr;
   3381 	int i;
   3382 
   3383 	p_indent(level, frm);
   3384 	printf("status 0x%2.2x handle %d page %d max %d\n",
   3385 					evt->status, btohs(evt->handle),
   3386 					evt->page_num, evt->max_page_num);
   3387 
   3388 	if (evt->status > 0) {
   3389 		p_indent(level, frm);
   3390 		printf("Error: %s\n", status2str(evt->status));
   3391 	} else {
   3392 		p_indent(level, frm);
   3393 		printf("Features:");
   3394 		for (i = 0; i < 8; i++)
   3395 			printf(" 0x%2.2x", evt->features[i]);
   3396 		printf("\n");
   3397 	}
   3398 }
   3399 
   3400 static inline void sync_conn_complete_dump(int level, struct frame *frm)
   3401 {
   3402 	evt_sync_conn_complete *evt = frm->ptr;
   3403 	char addr[18];
   3404 
   3405 	p_ba2str(&evt->bdaddr, addr);
   3406 
   3407 	p_indent(level, frm);
   3408 	printf("status 0x%2.2x handle %d bdaddr %s type %s\n",
   3409 					evt->status, btohs(evt->handle), addr,
   3410 					evt->link_type == 0 ? "SCO" : "eSCO");
   3411 
   3412 	if (evt->status > 0) {
   3413 		p_indent(level, frm);
   3414 		printf("Error: %s\n", status2str(evt->status));
   3415 	} else {
   3416 		p_indent(level, frm);
   3417 		printf("Air mode: %s\n", airmode2str(evt->air_mode));
   3418 	}
   3419 }
   3420 
   3421 static inline void sync_conn_changed_dump(int level, struct frame *frm)
   3422 {
   3423 	evt_sync_conn_changed *evt = frm->ptr;
   3424 
   3425 	p_indent(level, frm);
   3426 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   3427 
   3428 	if (evt->status > 0) {
   3429 		p_indent(level, frm);
   3430 		printf("Error: %s\n", status2str(evt->status));
   3431 	}
   3432 }
   3433 
   3434 static inline void sniff_subrating_event_dump(int level, struct frame *frm)
   3435 {
   3436 	evt_sniff_subrating *evt = frm->ptr;
   3437 
   3438 	p_indent(level, frm);
   3439 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   3440 
   3441 	if (evt->status > 0) {
   3442 		p_indent(level, frm);
   3443 		printf("Error: %s\n", status2str(evt->status));
   3444 	} else {
   3445 		p_indent(level, frm);
   3446 		printf("max latency transmit %d receive %d\n",
   3447 					btohs(evt->max_tx_latency),
   3448 					btohs(evt->max_rx_latency));
   3449 
   3450 		p_indent(level, frm);
   3451 		printf("min timeout remote %d local %d\n",
   3452 					btohs(evt->min_remote_timeout),
   3453 					btohs(evt->min_local_timeout));
   3454 	}
   3455 }
   3456 
   3457 static inline void extended_inq_result_dump(int level, struct frame *frm)
   3458 {
   3459 	uint8_t num = get_u8(frm);
   3460 	char addr[18];
   3461 	int i;
   3462 
   3463 	for (i = 0; i < num; i++) {
   3464 		extended_inquiry_info *info = frm->ptr;
   3465 
   3466 		p_ba2str(&info->bdaddr, addr);
   3467 
   3468 		p_indent(level, frm);
   3469 		printf("bdaddr %s mode %d clkoffset 0x%4.4x class 0x%2.2x%2.2x%2.2x rssi %d\n",
   3470 			addr, info->pscan_rep_mode, btohs(info->clock_offset),
   3471 			info->dev_class[2], info->dev_class[1], info->dev_class[0], info->rssi);
   3472 
   3473 		frm->ptr += INQUIRY_INFO_WITH_RSSI_SIZE;
   3474 		frm->len -= INQUIRY_INFO_WITH_RSSI_SIZE;
   3475 
   3476 		ext_inquiry_response_dump(level, frm);
   3477 	}
   3478 }
   3479 
   3480 static inline void link_supervision_timeout_changed_dump(int level, struct frame *frm)
   3481 {
   3482 	evt_link_supervision_timeout_changed *evt = frm->ptr;
   3483 
   3484 	p_indent(level, frm);
   3485 	printf("handle %d timeout %d\n",
   3486 				btohs(evt->handle), btohs(evt->timeout));
   3487 }
   3488 
   3489 static inline void user_passkey_notify_dump(int level, struct frame *frm)
   3490 {
   3491 	evt_user_passkey_notify *evt = frm->ptr;
   3492 	char addr[18];
   3493 
   3494 	p_indent(level, frm);
   3495 	p_ba2str(&evt->bdaddr, addr);
   3496 	printf("bdaddr %s passkey %d\n", addr, btohl(evt->passkey));
   3497 }
   3498 
   3499 static inline void keypress_notify_dump(int level, struct frame *frm)
   3500 {
   3501 	evt_keypress_notify *evt = frm->ptr;
   3502 	char addr[18];
   3503 
   3504 	p_indent(level, frm);
   3505 	p_ba2str(&evt->bdaddr, addr);
   3506 	printf("bdaddr %s type %d\n", addr, evt->type);
   3507 }
   3508 
   3509 static inline void remote_host_features_notify_dump(int level, struct frame *frm)
   3510 {
   3511 	evt_remote_host_features_notify *evt = frm->ptr;
   3512 	char addr[18];
   3513 	int i;
   3514 
   3515 	p_indent(level, frm);
   3516 	p_ba2str(&evt->bdaddr, addr);
   3517 	printf("bdaddr %s\n", addr);
   3518 
   3519 	p_indent(level, frm);
   3520 	printf("Features:");
   3521 	for (i = 0; i < 8; i++)
   3522 		printf(" 0x%2.2x", evt->features[i]);
   3523 	printf("\n");
   3524 }
   3525 
   3526 static inline void evt_le_conn_complete_dump(int level, struct frame *frm)
   3527 {
   3528 	evt_le_connection_complete *evt = frm->ptr;
   3529 
   3530 	p_indent(level, frm);
   3531 	printf("status 0x%2.2x handle %d, role %s\n",
   3532 					evt->status, btohs(evt->handle),
   3533 					evt->role ? "slave" : "master");
   3534 }
   3535 
   3536 static inline void evt_le_advertising_report_dump(int level, struct frame *frm)
   3537 {
   3538 	uint8_t num_reports = get_u8(frm);
   3539 	const uint8_t RSSI_SIZE = 1;
   3540 
   3541 	while (num_reports--) {
   3542 		char addr[18];
   3543 		le_advertising_info *info = frm->ptr;
   3544 
   3545 		p_ba2str(&info->bdaddr, addr);
   3546 
   3547 		p_indent(level, frm);
   3548 		printf("%s (%d)\n", evttype2str(info->evt_type), info->evt_type);
   3549 
   3550 		p_indent(level, frm);
   3551 		printf("bdaddr %s (%s)\n", addr,
   3552 					bdaddrtype2str(info->bdaddr_type));
   3553 
   3554 		if (info->length > 0) {
   3555 			ext_inquiry_data_dump(level, frm,
   3556 					((uint8_t *) &info->length) + 1);
   3557 		}
   3558 
   3559 		frm->ptr += LE_ADVERTISING_INFO_SIZE + info->length;
   3560 		frm->len -= LE_ADVERTISING_INFO_SIZE + info->length;
   3561 
   3562 		p_indent(level, frm);
   3563 		printf("RSSI: %d\n", ((int8_t *) frm->ptr)[frm->len - 1]);
   3564 
   3565 		frm->ptr += RSSI_SIZE;
   3566 		frm->len -= RSSI_SIZE;
   3567 	}
   3568 }
   3569 
   3570 static inline void evt_le_conn_update_complete_dump(int level,
   3571 							struct frame *frm)
   3572 {
   3573 	evt_le_connection_update_complete *uevt = frm->ptr;
   3574 
   3575 	p_indent(level, frm);
   3576 	printf("status 0x%2.2x handle %d\n", uevt->status, btohs(uevt->handle));
   3577 
   3578 	p_indent(level, frm);
   3579 	printf("interval %.2fms, latency %.2fms, superv. timeout %.2fms\n",
   3580 			btohs(uevt->interval) * 1.25, btohs(uevt->latency) * 1.25,
   3581 			btohs(uevt->supervision_timeout) * 10.0);
   3582 }
   3583 
   3584 static inline void evt_le_read_remote_used_features_complete_dump(int level, struct frame *frm)
   3585 {
   3586 	int i;
   3587 	evt_le_read_remote_used_features_complete *revt = frm->ptr;
   3588 
   3589 	p_indent(level, frm);
   3590 	printf("status 0x%2.2x handle %d\n", revt->status, btohs(revt->handle));
   3591 
   3592 	if (revt->status > 0) {
   3593 		p_indent(level, frm);
   3594 		printf("Error: %s\n", status2str(revt->status));
   3595 	} else {
   3596 		p_indent(level, frm);
   3597 		printf("Features:");
   3598 		for (i = 0; i < 8; i++)
   3599 			printf(" 0x%2.2x", revt->features[i]);
   3600 		printf("\n");
   3601 	}
   3602 }
   3603 
   3604 static inline void le_meta_ev_dump(int level, struct frame *frm)
   3605 {
   3606 	evt_le_meta_event *mevt = frm->ptr;
   3607 	uint8_t subevent;
   3608 
   3609 	subevent = mevt->subevent;
   3610 
   3611 	frm->ptr += EVT_LE_META_EVENT_SIZE;
   3612 	frm->len -= EVT_LE_META_EVENT_SIZE;
   3613 
   3614 	p_indent(level, frm);
   3615 	printf("%s\n", ev_le_meta_str[subevent]);
   3616 
   3617 	switch (mevt->subevent) {
   3618 	case EVT_LE_CONN_COMPLETE:
   3619 		evt_le_conn_complete_dump(level + 1, frm);
   3620 		break;
   3621 	case EVT_LE_ADVERTISING_REPORT:
   3622 		evt_le_advertising_report_dump(level + 1, frm);
   3623 		break;
   3624 	case EVT_LE_CONN_UPDATE_COMPLETE:
   3625 		evt_le_conn_update_complete_dump(level + 1, frm);
   3626 		break;
   3627 	case EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE:
   3628 		evt_le_read_remote_used_features_complete_dump(level + 1, frm);
   3629 		break;
   3630 	default:
   3631 		raw_dump(level, frm);
   3632 		break;
   3633 	}
   3634 }
   3635 
   3636 static inline void phys_link_complete_dump(int level, struct frame *frm)
   3637 {
   3638 	evt_physical_link_complete *evt = frm->ptr;
   3639 
   3640 	p_indent(level, frm);
   3641 	printf("status 0x%2.2x handle %d\n", evt->status, evt->handle);
   3642 
   3643 	if (evt->status > 0) {
   3644 		p_indent(level, frm);
   3645 		printf("Error: %s\n", status2str(evt->status));
   3646 	}
   3647 }
   3648 
   3649 static inline void disconn_phys_link_complete_dump(int level, struct frame *frm)
   3650 {
   3651 	evt_disconn_physical_link_complete *evt = frm->ptr;
   3652 
   3653 	p_indent(level, frm);
   3654 	printf("status 0x%2.2x handle %d reason 0x%2.2x\n",
   3655 				evt->status, evt->handle, evt->reason);
   3656 
   3657 	if (evt->status > 0) {
   3658 		p_indent(level, frm);
   3659 		printf("Error: %s\n", status2str(evt->status));
   3660 	} else if (evt->reason > 0) {
   3661 		p_indent(level, frm);
   3662 		printf("Reason: %s\n", status2str(evt->reason));
   3663 	}
   3664 }
   3665 
   3666 static inline void phys_link_loss_warning_dump(int level, struct frame *frm)
   3667 {
   3668 	evt_physical_link_loss_warning *evt = frm->ptr;
   3669 
   3670 	p_indent(level, frm);
   3671 	printf("handle %d reason 0x%2.2x\n", evt->handle, evt->reason);
   3672 }
   3673 
   3674 static inline void phys_link_handle_dump(int level, struct frame *frm)
   3675 {
   3676 	evt_physical_link_recovery *evt = frm->ptr;
   3677 
   3678 	p_indent(level, frm);
   3679 	printf("handle %d\n", evt->handle);
   3680 }
   3681 
   3682 static inline void logical_link_complete_dump(int level, struct frame *frm)
   3683 {
   3684 	evt_logical_link_complete *evt = frm->ptr;
   3685 
   3686 	p_indent(level, frm);
   3687 	printf("status 0x%2.2x log_handle %d handle %d tx_flow_id %d\n",
   3688 			evt->status, btohs(evt->log_handle), evt->handle,
   3689 			evt->tx_flow_id);
   3690 
   3691 	if (evt->status > 0) {
   3692 		p_indent(level, frm);
   3693 		printf("Error: %s\n", status2str(evt->status));
   3694 	}
   3695 }
   3696 
   3697 static inline void flow_spec_modify_dump(int level, struct frame *frm)
   3698 {
   3699 	evt_flow_spec_modify_complete *evt = frm->ptr;
   3700 
   3701 	p_indent(level, frm);
   3702 	printf("status 0x%2.2x handle %d\n", evt->status, btohs(evt->handle));
   3703 
   3704 	if (evt->status > 0) {
   3705 		p_indent(level, frm);
   3706 		printf("Error: %s\n", status2str(evt->status));
   3707 	}
   3708 }
   3709 
   3710 static inline void event_dump(int level, struct frame *frm)
   3711 {
   3712 	hci_event_hdr *hdr = frm->ptr;
   3713 	uint8_t event = hdr->evt;
   3714 
   3715 	if (p_filter(FILT_HCI))
   3716 		return;
   3717 
   3718 	if (event <= EVENT_NUM) {
   3719 		p_indent(level, frm);
   3720 		printf("HCI Event: %s (0x%2.2x) plen %d\n",
   3721 					event_str[hdr->evt], hdr->evt, hdr->plen);
   3722 	} else if (hdr->evt == EVT_TESTING) {
   3723 		p_indent(level, frm);
   3724 		printf("HCI Event: Testing (0x%2.2x) plen %d\n", hdr->evt, hdr->plen);
   3725 	} else if (hdr->evt == EVT_VENDOR) {
   3726 		uint16_t manufacturer;
   3727 
   3728 		if (parser.flags & DUMP_NOVENDOR)
   3729 			return;
   3730 
   3731 		p_indent(level, frm);
   3732 		printf("HCI Event: Vendor (0x%2.2x) plen %d\n", hdr->evt, hdr->plen);
   3733 
   3734 		manufacturer = get_manufacturer();
   3735 
   3736 		switch (manufacturer) {
   3737 		case 0:
   3738 		case 37:
   3739 		case 48:
   3740 			frm->ptr += HCI_EVENT_HDR_SIZE;
   3741 			frm->len -= HCI_EVENT_HDR_SIZE;
   3742 			ericsson_dump(level + 1, frm);
   3743 			return;
   3744 		case 10:
   3745 			frm->ptr += HCI_EVENT_HDR_SIZE;
   3746 			frm->len -= HCI_EVENT_HDR_SIZE;
   3747 			csr_dump(level + 1, frm);
   3748 			return;
   3749 		}
   3750 	} else {
   3751 		p_indent(level, frm);
   3752 		printf("HCI Event: code 0x%2.2x plen %d\n", hdr->evt, hdr->plen);
   3753 	}
   3754 
   3755 	frm->ptr += HCI_EVENT_HDR_SIZE;
   3756 	frm->len -= HCI_EVENT_HDR_SIZE;
   3757 
   3758 	if (event == EVT_CMD_COMPLETE) {
   3759 		evt_cmd_complete *cc = frm->ptr;
   3760 		if (cc->opcode == cmd_opcode_pack(OGF_INFO_PARAM, OCF_READ_LOCAL_VERSION)) {
   3761 			read_local_version_rp *rp = frm->ptr + EVT_CMD_COMPLETE_SIZE;
   3762 			manufacturer = rp->manufacturer;
   3763 		}
   3764 	}
   3765 
   3766 	if (event == EVT_DISCONN_COMPLETE) {
   3767 		evt_disconn_complete *evt = frm->ptr;
   3768 		l2cap_clear(btohs(evt->handle));
   3769 	}
   3770 
   3771 	if (!(parser.flags & DUMP_VERBOSE)) {
   3772 		raw_dump(level, frm);
   3773 		return;
   3774 	}
   3775 
   3776 	switch (event) {
   3777 	case EVT_LOOPBACK_COMMAND:
   3778 		command_dump(level + 1, frm);
   3779 		break;
   3780 	case EVT_CMD_COMPLETE:
   3781 		cmd_complete_dump(level + 1, frm);
   3782 		break;
   3783 	case EVT_CMD_STATUS:
   3784 		cmd_status_dump(level + 1, frm);
   3785 		break;
   3786 	case EVT_HARDWARE_ERROR:
   3787 		hardware_error_dump(level + 1, frm);
   3788 		break;
   3789 	case EVT_FLUSH_OCCURRED:
   3790 	case EVT_QOS_VIOLATION:
   3791 		handle_response_dump(level + 1, frm);
   3792 		break;
   3793 	case EVT_INQUIRY_COMPLETE:
   3794 		status_response_dump(level + 1, frm);
   3795 		break;
   3796 	case EVT_INQUIRY_RESULT:
   3797 		inq_result_dump(level + 1, frm);
   3798 		break;
   3799 	case EVT_CONN_COMPLETE:
   3800 		conn_complete_dump(level + 1, frm);
   3801 		break;
   3802 	case EVT_CONN_REQUEST:
   3803 		conn_request_dump(level + 1, frm);
   3804 		break;
   3805 	case EVT_DISCONN_COMPLETE:
   3806 	case EVT_DISCONNECT_LOGICAL_LINK_COMPLETE:
   3807 		disconn_complete_dump(level + 1, frm);
   3808 		break;
   3809 	case EVT_AUTH_COMPLETE:
   3810 	case EVT_CHANGE_CONN_LINK_KEY_COMPLETE:
   3811 		generic_response_dump(level + 1, frm);
   3812 		break;
   3813 	case EVT_MASTER_LINK_KEY_COMPLETE:
   3814 		master_link_key_complete_dump(level + 1, frm);
   3815 		break;
   3816 	case EVT_REMOTE_NAME_REQ_COMPLETE:
   3817 		remote_name_req_complete_dump(level + 1, frm);
   3818 		break;
   3819 	case EVT_ENCRYPT_CHANGE:
   3820 		encrypt_change_dump(level + 1, frm);
   3821 		break;
   3822 	case EVT_READ_REMOTE_FEATURES_COMPLETE:
   3823 		read_remote_features_complete_dump(level + 1, frm);
   3824 		break;
   3825 	case EVT_READ_REMOTE_VERSION_COMPLETE:
   3826 		read_remote_version_complete_dump(level + 1, frm);
   3827 		break;
   3828 	case EVT_QOS_SETUP_COMPLETE:
   3829 		qos_setup_complete_dump(level + 1, frm);
   3830 		break;
   3831 	case EVT_ROLE_CHANGE:
   3832 		role_change_dump(level + 1, frm);
   3833 		break;
   3834 	case EVT_NUM_COMP_PKTS:
   3835 		num_comp_pkts_dump(level + 1, frm);
   3836 		break;
   3837 	case EVT_MODE_CHANGE:
   3838 		mode_change_dump(level + 1, frm);
   3839 		break;
   3840 	case EVT_RETURN_LINK_KEYS:
   3841 		return_link_keys_dump(level + 1, frm);
   3842 		break;
   3843 	case EVT_PIN_CODE_REQ:
   3844 	case EVT_LINK_KEY_REQ:
   3845 	case EVT_IO_CAPABILITY_REQUEST:
   3846 	case EVT_USER_PASSKEY_REQUEST:
   3847 	case EVT_REMOTE_OOB_DATA_REQUEST:
   3848 		pin_code_req_dump(level + 1, frm);
   3849 		break;
   3850 	case EVT_LINK_KEY_NOTIFY:
   3851 		link_key_notify_dump(level + 1, frm);
   3852 		break;
   3853 	case EVT_DATA_BUFFER_OVERFLOW:
   3854 		data_buffer_overflow_dump(level + 1, frm);
   3855 		break;
   3856 	case EVT_MAX_SLOTS_CHANGE:
   3857 		max_slots_change_dump(level + 1, frm);
   3858 		break;
   3859 	case EVT_READ_CLOCK_OFFSET_COMPLETE:
   3860 		read_clock_offset_complete_dump(level + 1, frm);
   3861 		break;
   3862 	case EVT_CONN_PTYPE_CHANGED:
   3863 		conn_ptype_changed_dump(level + 1, frm);
   3864 		break;
   3865 	case EVT_PSCAN_REP_MODE_CHANGE:
   3866 		pscan_rep_mode_change_dump(level + 1, frm);
   3867 		break;
   3868 	case EVT_FLOW_SPEC_COMPLETE:
   3869 		flow_spec_complete_dump(level + 1, frm);
   3870 		break;
   3871 	case EVT_INQUIRY_RESULT_WITH_RSSI:
   3872 		inq_result_with_rssi_dump(level + 1, frm);
   3873 		break;
   3874 	case EVT_READ_REMOTE_EXT_FEATURES_COMPLETE:
   3875 		read_remote_ext_features_complete_dump(level + 1, frm);
   3876 		break;
   3877 	case EVT_SYNC_CONN_COMPLETE:
   3878 		sync_conn_complete_dump(level + 1, frm);
   3879 		break;
   3880 	case EVT_SYNC_CONN_CHANGED:
   3881 		sync_conn_changed_dump(level + 1, frm);
   3882 		break;
   3883 	case EVT_SNIFF_SUBRATING:
   3884 		sniff_subrating_event_dump(level + 1, frm);
   3885 		break;
   3886 	case EVT_EXTENDED_INQUIRY_RESULT:
   3887 		extended_inq_result_dump(level + 1, frm);
   3888 		break;
   3889 	case EVT_ENCRYPTION_KEY_REFRESH_COMPLETE:
   3890 		generic_response_dump(level + 1, frm);
   3891 		break;
   3892 	case EVT_SIMPLE_PAIRING_COMPLETE:
   3893 		bdaddr_response_dump(level + 1, frm);
   3894 		break;
   3895 	case EVT_LINK_SUPERVISION_TIMEOUT_CHANGED:
   3896 		link_supervision_timeout_changed_dump(level + 1, frm);
   3897 		break;
   3898 	case EVT_ENHANCED_FLUSH_COMPLETE:
   3899 		generic_command_dump(level + 1, frm);
   3900 		break;
   3901 	case EVT_IO_CAPABILITY_RESPONSE:
   3902 		io_capability_reply_dump(level + 1, frm);
   3903 		break;
   3904 	case EVT_USER_CONFIRM_REQUEST:
   3905 	case EVT_USER_PASSKEY_NOTIFY:
   3906 		user_passkey_notify_dump(level + 1, frm);
   3907 		break;
   3908 	case EVT_KEYPRESS_NOTIFY:
   3909 		keypress_notify_dump(level + 1, frm);
   3910 		break;
   3911 	case EVT_REMOTE_HOST_FEATURES_NOTIFY:
   3912 		remote_host_features_notify_dump(level + 1, frm);
   3913 		break;
   3914 	case EVT_LE_META_EVENT:
   3915 		le_meta_ev_dump(level + 1, frm);
   3916 		break;
   3917 	case EVT_PHYSICAL_LINK_COMPLETE:
   3918 		phys_link_complete_dump(level + 1, frm);
   3919 		break;
   3920 	case EVT_DISCONNECT_PHYSICAL_LINK_COMPLETE:
   3921 		disconn_phys_link_complete_dump(level + 1, frm);
   3922 		break;
   3923 	case EVT_PHYSICAL_LINK_LOSS_EARLY_WARNING:
   3924 		phys_link_loss_warning_dump(level + 1, frm);
   3925 		break;
   3926 	case EVT_PHYSICAL_LINK_RECOVERY:
   3927 	case EVT_CHANNEL_SELECTED:
   3928 		phys_link_handle_dump(level + 1, frm);
   3929 		break;
   3930 	case EVT_LOGICAL_LINK_COMPLETE:
   3931 		logical_link_complete_dump(level + 1, frm);
   3932 		break;
   3933 	case EVT_FLOW_SPEC_MODIFY_COMPLETE:
   3934 		flow_spec_modify_dump(level + 1, frm);
   3935 		break;
   3936 	default:
   3937 		raw_dump(level, frm);
   3938 		break;
   3939 	}
   3940 }
   3941 
   3942 static inline void acl_dump(int level, struct frame *frm)
   3943 {
   3944 	hci_acl_hdr *hdr = (void *) frm->ptr;
   3945 	uint16_t handle = btohs(hdr->handle);
   3946 	uint16_t dlen = btohs(hdr->dlen);
   3947 	uint8_t flags = acl_flags(handle);
   3948 
   3949 	if (!p_filter(FILT_HCI)) {
   3950 		p_indent(level, frm);
   3951 		printf("ACL data: handle %d flags 0x%2.2x dlen %d\n",
   3952 			acl_handle(handle), flags, dlen);
   3953 		level++;
   3954 	}
   3955 
   3956 	frm->ptr += HCI_ACL_HDR_SIZE;
   3957 	frm->len -= HCI_ACL_HDR_SIZE;
   3958 	frm->flags  = flags;
   3959 	frm->handle = acl_handle(handle);
   3960 
   3961 	if (parser.filter & ~FILT_HCI)
   3962 		l2cap_dump(level, frm);
   3963 	else
   3964 		raw_dump(level, frm);
   3965 }
   3966 
   3967 static inline void sco_dump(int level, struct frame *frm)
   3968 {
   3969 	hci_sco_hdr *hdr = (void *) frm->ptr;
   3970 	uint16_t handle = btohs(hdr->handle);
   3971 	uint8_t flags = acl_flags(handle);
   3972 	int len;
   3973 
   3974 	if (frm->audio_fd > fileno(stderr))
   3975 		len = write(frm->audio_fd, frm->ptr + HCI_SCO_HDR_SIZE, hdr->dlen);
   3976 
   3977 	if (!p_filter(FILT_SCO)) {
   3978 		p_indent(level, frm);
   3979 		printf("SCO data: handle %d flags 0x%2.2x dlen %d\n",
   3980 				acl_handle(handle), flags, hdr->dlen);
   3981 		level++;
   3982 
   3983 		frm->ptr += HCI_SCO_HDR_SIZE;
   3984 		frm->len -= HCI_SCO_HDR_SIZE;
   3985 		raw_dump(level, frm);
   3986 	}
   3987 }
   3988 
   3989 static inline void vendor_dump(int level, struct frame *frm)
   3990 {
   3991 	if (p_filter(FILT_HCI))
   3992 		return;
   3993 
   3994 	if (frm->dev_id == HCI_DEV_NONE) {
   3995 		uint16_t device = btohs(htons(get_u16(frm)));
   3996 		uint16_t proto = btohs(htons(get_u16(frm)));
   3997 		uint16_t type = btohs(htons(get_u16(frm)));
   3998 		uint16_t plen = btohs(htons(get_u16(frm)));
   3999 
   4000 		p_indent(level, frm);
   4001 
   4002 		printf("System %s: device hci%d proto 0x%2.2x type 0x%2.2x plen %d\n",
   4003 			frm->in ? "event" : "command", device, proto, type, plen);
   4004 
   4005 		raw_dump(level, frm);
   4006 		return;
   4007 	}
   4008 
   4009 	if (parser.flags & DUMP_NOVENDOR)
   4010 		return;
   4011 
   4012 	if (get_manufacturer() == 12) {
   4013 		bpa_dump(level, frm);
   4014 		return;
   4015 	}
   4016 
   4017 	p_indent(level, frm);
   4018 	printf("Vendor data: len %d\n", frm->len);
   4019 	raw_dump(level, frm);
   4020 }
   4021 
   4022 void hci_dump(int level, struct frame *frm)
   4023 {
   4024 	uint8_t type = *(uint8_t *)frm->ptr;
   4025 
   4026 	frm->ptr++; frm->len--;
   4027 
   4028 	switch (type) {
   4029 	case HCI_COMMAND_PKT:
   4030 		command_dump(level, frm);
   4031 		break;
   4032 
   4033 	case HCI_EVENT_PKT:
   4034 		event_dump(level, frm);
   4035 		break;
   4036 
   4037 	case HCI_ACLDATA_PKT:
   4038 		acl_dump(level, frm);
   4039 		break;
   4040 
   4041 	case HCI_SCODATA_PKT:
   4042 		sco_dump(level, frm);
   4043 		break;
   4044 
   4045 	case HCI_VENDOR_PKT:
   4046 		vendor_dump(level, frm);
   4047 		break;
   4048 
   4049 	default:
   4050 		if (p_filter(FILT_HCI))
   4051 			break;
   4052 
   4053 		p_indent(level, frm);
   4054 		printf("Unknown: type 0x%2.2x len %d\n", type, frm->len);
   4055 		raw_dump(level, frm);
   4056 		break;
   4057 	}
   4058 }
   4059