• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2003-2011  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include <stdio.h>
29 #include <errno.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #include <sys/types.h>
35 #include <netinet/in.h>
36 
37 #include "parser.h"
38 
type2str(uint8_t head)39 static char *type2str(uint8_t head)
40 {
41 	switch (head & 0xf0) {
42 	case 0x00:
43 		return "Handshake";
44 	case 0x10:
45 		return "Control";
46 	case 0x40:
47 		return "Get report";
48 	case 0x50:
49 		return "Set report";
50 	case 0x60:
51 		return "Get protocol";
52 	case 0x70:
53 		return "Set protocol";
54 	case 0x80:
55 		return "Get idle";
56 	case 0x90:
57 		return "Set idle";
58 	case 0xa0:
59 		return "Data";
60 	case 0xb0:
61 		return "Data continuation";
62 	default:
63 		return "Reserved";
64 	}
65 }
66 
result2str(uint8_t head)67 static char *result2str(uint8_t head)
68 {
69 	switch (head & 0x0f) {
70 	case 0x00:
71 		return "Successful";
72 	case 0x01:
73 		return "Not ready";
74 	case 0x02:
75 		return "Invalid report ID";
76 	case 0x03:
77 		return "Unsupported request";
78 	case 0x04:
79 		return "Invalid parameter";
80 	case 0x0e:
81 		return "Unknown";
82 	case 0x0f:
83 		return "Fatal";
84 	default:
85 		return "Reserved";
86 	}
87 }
88 
operation2str(uint8_t head)89 static char *operation2str(uint8_t head)
90 {
91 	switch (head & 0x0f) {
92 	case 0x00:
93 		return "No operation";
94 	case 0x01:
95 		return "Hard reset";
96 	case 0x02:
97 		return "Soft reset";
98 	case 0x03:
99 		return "Suspend";
100 	case 0x04:
101 		return "Exit suspend";
102 	case 0x05:
103 		return "Virtual cable unplug";
104 	default:
105 		return "Reserved";
106 	}
107 }
108 
report2str(uint8_t head)109 static char *report2str(uint8_t head)
110 {
111 	switch (head & 0x03) {
112 	case 0x00:
113 		return "Other report";
114 	case 0x01:
115 		return "Input report";
116 	case 0x02:
117 		return "Output report";
118 	case 0x03:
119 		return "Feature report";
120 	default:
121 		return "Reserved";
122 	}
123 }
124 
protocol2str(uint8_t head)125 static char *protocol2str(uint8_t head)
126 {
127 	switch (head & 0x01) {
128 	case 0x00:
129 		return "Boot protocol";
130 	case 0x01:
131 		return "Report protocol";
132 	default:
133 		return "Reserved";
134 	}
135 }
136 
hidp_dump(int level,struct frame * frm)137 void hidp_dump(int level, struct frame *frm)
138 {
139 	uint8_t hdr;
140 	char *param;
141 
142 	hdr = get_u8(frm);
143 
144 	switch (hdr & 0xf0) {
145 	case 0x00:
146 		param = result2str(hdr);
147 		break;
148 	case 0x10:
149 		param = operation2str(hdr);
150 		break;
151 	case 0x60:
152 	case 0x70:
153 		param = protocol2str(hdr);
154 		break;
155 	case 0x40:
156 	case 0x50:
157 	case 0xa0:
158 	case 0xb0:
159 		param = report2str(hdr);
160 		break;
161 	default:
162 		param = "";
163 		break;
164 	}
165 
166 	p_indent(level, frm);
167 
168 	printf("HIDP: %s: %s\n", type2str(hdr), param);
169 
170 	raw_dump(level, frm);
171 }
172