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