print.c revision 1.1 1 1.1 plunky /* $NetBSD: print.c,v 1.1 2006/09/10 15:45:56 plunky Exp $ */
2 1.1 plunky
3 1.1 plunky /*-
4 1.1 plunky * Copyright (c) 2006 Itronix Inc.
5 1.1 plunky * All rights reserved.
6 1.1 plunky *
7 1.1 plunky * Written by Iain Hibbert for Itronix Inc.
8 1.1 plunky *
9 1.1 plunky * Redistribution and use in source and binary forms, with or without
10 1.1 plunky * modification, are permitted provided that the following conditions
11 1.1 plunky * are met:
12 1.1 plunky * 1. Redistributions of source code must retain the above copyright
13 1.1 plunky * notice, this list of conditions and the following disclaimer.
14 1.1 plunky * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 plunky * notice, this list of conditions and the following disclaimer in the
16 1.1 plunky * documentation and/or other materials provided with the distribution.
17 1.1 plunky * 3. The name of Itronix Inc. may not be used to endorse
18 1.1 plunky * or promote products derived from this software without specific
19 1.1 plunky * prior written permission.
20 1.1 plunky *
21 1.1 plunky * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22 1.1 plunky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1 plunky * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 plunky * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 1.1 plunky * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 1.1 plunky * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 1.1 plunky * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 1.1 plunky * ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 plunky * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 plunky * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 plunky * POSSIBILITY OF SUCH DAMAGE.
32 1.1 plunky */
33 1.1 plunky /*
34 1.1 plunky * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin (at) yahoo.com>
35 1.1 plunky * All rights reserved.
36 1.1 plunky *
37 1.1 plunky * Redistribution and use in source and binary forms, with or without
38 1.1 plunky * modification, are permitted provided that the following conditions
39 1.1 plunky * are met:
40 1.1 plunky * 1. Redistributions of source code must retain the above copyright
41 1.1 plunky * notice, this list of conditions and the following disclaimer.
42 1.1 plunky * 2. Redistributions in binary form must reproduce the above copyright
43 1.1 plunky * notice, this list of conditions and the following disclaimer in the
44 1.1 plunky * documentation and/or other materials provided with the distribution.
45 1.1 plunky *
46 1.1 plunky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
47 1.1 plunky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 1.1 plunky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 1.1 plunky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 1.1 plunky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 1.1 plunky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 1.1 plunky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 1.1 plunky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 1.1 plunky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 1.1 plunky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 1.1 plunky * SUCH DAMAGE.
57 1.1 plunky *
58 1.1 plunky */
59 1.1 plunky
60 1.1 plunky #include <sys/cdefs.h>
61 1.1 plunky __RCSID("$NetBSD: print.c,v 1.1 2006/09/10 15:45:56 plunky Exp $");
62 1.1 plunky
63 1.1 plunky #include <sys/types.h>
64 1.1 plunky
65 1.1 plunky #include <dev/bluetooth/btdev.h>
66 1.1 plunky #include <dev/bluetooth/bthidev.h>
67 1.1 plunky #include <dev/bluetooth/btsco.h>
68 1.1 plunky #include <dev/usb/usb.h>
69 1.1 plunky #include <dev/usb/usbhid.h>
70 1.1 plunky
71 1.1 plunky #include <prop/proplib.h>
72 1.1 plunky
73 1.1 plunky #include <bluetooth.h>
74 1.1 plunky #include <err.h>
75 1.1 plunky #include <usbhid.h>
76 1.1 plunky
77 1.1 plunky #include "btdevctl.h"
78 1.1 plunky
79 1.1 plunky static void cfg_bthidev(prop_dictionary_t dict);
80 1.1 plunky static void cfg_btsco(prop_dictionary_t dict);
81 1.1 plunky
82 1.1 plunky static void hid_dump_item(char const *, struct hid_item *);
83 1.1 plunky static void hid_parse(prop_data_t);
84 1.1 plunky
85 1.1 plunky void
86 1.1 plunky cfg_print(prop_dictionary_t dict)
87 1.1 plunky {
88 1.1 plunky prop_object_t obj;
89 1.1 plunky
90 1.1 plunky obj = prop_dictionary_get(dict, BTDEVladdr);
91 1.1 plunky if (prop_object_type(obj) != PROP_TYPE_DATA) {
92 1.1 plunky return;
93 1.1 plunky }
94 1.1 plunky printf("local bdaddr: %s\n", bt_ntoa(prop_data_data_nocopy(obj), NULL));
95 1.1 plunky
96 1.1 plunky obj = prop_dictionary_get(dict, BTDEVraddr);
97 1.1 plunky if (prop_object_type(obj) != PROP_TYPE_DATA) {
98 1.1 plunky return;
99 1.1 plunky }
100 1.1 plunky printf("remote bdaddr: %s\n", bt_ntoa(prop_data_data_nocopy(obj), NULL));
101 1.1 plunky
102 1.1 plunky obj = prop_dictionary_get(dict, BTDEVtype);
103 1.1 plunky if (prop_object_type(obj) != PROP_TYPE_STRING) {
104 1.1 plunky printf("No device type!\n");
105 1.1 plunky return;
106 1.1 plunky }
107 1.1 plunky printf("device type: %s\n", prop_string_cstring(obj));
108 1.1 plunky
109 1.1 plunky if (prop_string_equals_cstring(obj, "bthidev")) {
110 1.1 plunky cfg_bthidev(dict);
111 1.1 plunky return;
112 1.1 plunky }
113 1.1 plunky
114 1.1 plunky if (prop_string_equals_cstring(obj, "btsco")) {
115 1.1 plunky cfg_btsco(dict);
116 1.1 plunky return;
117 1.1 plunky }
118 1.1 plunky
119 1.1 plunky printf("Unknown device type!\n");
120 1.1 plunky }
121 1.1 plunky
122 1.1 plunky static void
123 1.1 plunky cfg_bthidev(prop_dictionary_t dict)
124 1.1 plunky {
125 1.1 plunky prop_object_t obj;
126 1.1 plunky
127 1.1 plunky obj = prop_dictionary_get(dict, BTHIDEVcontrolpsm);
128 1.1 plunky if (prop_object_type(obj) == PROP_TYPE_NUMBER)
129 1.1 plunky printf("control psm: 0x%4.4llx\n", prop_number_integer_value(obj));
130 1.1 plunky
131 1.1 plunky obj = prop_dictionary_get(dict, BTHIDEVinterruptpsm);
132 1.1 plunky if (prop_object_type(obj) == PROP_TYPE_NUMBER)
133 1.1 plunky printf("interrupt psm: 0x%4.4llx\n", prop_number_integer_value(obj));
134 1.1 plunky
135 1.1 plunky obj = prop_dictionary_get(dict, BTHIDEVreconnect);
136 1.1 plunky if (prop_bool_true(obj))
137 1.1 plunky printf("reconnect mode: TRUE\n");
138 1.1 plunky
139 1.1 plunky obj = prop_dictionary_get(dict, BTHIDEVdescriptor);
140 1.1 plunky if (prop_object_type(obj) == PROP_TYPE_DATA)
141 1.1 plunky hid_parse(obj);
142 1.1 plunky }
143 1.1 plunky
144 1.1 plunky static void
145 1.1 plunky cfg_btsco(prop_dictionary_t dict)
146 1.1 plunky {
147 1.1 plunky prop_object_t obj;
148 1.1 plunky
149 1.1 plunky obj = prop_dictionary_get(dict, BTSCOlisten);
150 1.1 plunky printf("mode: %s\n", prop_bool_true(obj) ? "listen" : "connect");
151 1.1 plunky
152 1.1 plunky obj = prop_dictionary_get(dict, BTSCOchannel);
153 1.1 plunky if (prop_object_type(obj) == PROP_TYPE_NUMBER)
154 1.1 plunky printf("channel: %lld\n", prop_number_integer_value(obj));
155 1.1 plunky }
156 1.1 plunky
157 1.1 plunky static void
158 1.1 plunky hid_parse(prop_data_t desc)
159 1.1 plunky {
160 1.1 plunky report_desc_t r;
161 1.1 plunky hid_data_t d;
162 1.1 plunky struct hid_item h;
163 1.1 plunky
164 1.1 plunky hid_init(NULL);
165 1.1 plunky
166 1.1 plunky r = hid_use_report_desc((unsigned char *)prop_data_data_nocopy(desc),
167 1.1 plunky prop_data_size(desc));
168 1.1 plunky if (r == NULL)
169 1.1 plunky return;
170 1.1 plunky
171 1.1 plunky d = hid_start_parse(r, ~0, -1);
172 1.1 plunky while (hid_get_item(d, &h)) {
173 1.1 plunky switch (h.kind) {
174 1.1 plunky case hid_collection:
175 1.1 plunky printf("Collection page=%s usage=%s\n",
176 1.1 plunky hid_usage_page(HID_PAGE(h.usage)),
177 1.1 plunky hid_usage_in_page(h.usage));
178 1.1 plunky break;
179 1.1 plunky
180 1.1 plunky case hid_endcollection:
181 1.1 plunky printf("End collection\n");
182 1.1 plunky break;
183 1.1 plunky
184 1.1 plunky case hid_input:
185 1.1 plunky hid_dump_item(" Input", &h);
186 1.1 plunky break;
187 1.1 plunky
188 1.1 plunky case hid_output:
189 1.1 plunky hid_dump_item(" Output", &h);
190 1.1 plunky break;
191 1.1 plunky
192 1.1 plunky case hid_feature:
193 1.1 plunky hid_dump_item("Feature", &h);
194 1.1 plunky break;
195 1.1 plunky }
196 1.1 plunky }
197 1.1 plunky
198 1.1 plunky hid_end_parse(d);
199 1.1 plunky hid_dispose_report_desc(r);
200 1.1 plunky }
201 1.1 plunky
202 1.1 plunky static void
203 1.1 plunky hid_dump_item(char const *label, struct hid_item *h)
204 1.1 plunky {
205 1.1 plunky
206 1.1 plunky printf("%s id=%u size=%u count=%u page=%s usage=%s%s%s%s%s%s%s%s%s%s",
207 1.1 plunky label, (uint8_t) h->report_ID, h->report_size, h->report_count,
208 1.1 plunky hid_usage_page(HID_PAGE(h->usage)),
209 1.1 plunky hid_usage_in_page(h->usage),
210 1.1 plunky (h->flags & HIO_CONST) ? " Const" : "",
211 1.1 plunky (h->flags & HIO_VARIABLE) ? " Variable" : "",
212 1.1 plunky (h->flags & HIO_RELATIVE) ? " Relative" : "",
213 1.1 plunky (h->flags & HIO_WRAP) ? " Wrap" : "",
214 1.1 plunky (h->flags & HIO_NONLINEAR) ? " NonLinear" : "",
215 1.1 plunky (h->flags & HIO_NOPREF) ? " NoPref" : "",
216 1.1 plunky (h->flags & HIO_NULLSTATE) ? " NullState" : "",
217 1.1 plunky (h->flags & HIO_VOLATILE) ? " Volatile" : "",
218 1.1 plunky (h->flags & HIO_BUFBYTES) ? " BufBytes" : "");
219 1.1 plunky
220 1.1 plunky printf(", logical range %d..%d",
221 1.1 plunky h->logical_minimum, h->logical_maximum);
222 1.1 plunky
223 1.1 plunky if (h->physical_minimum != h->physical_maximum)
224 1.1 plunky printf(", physical range %d..%d",
225 1.1 plunky h->physical_minimum, h->physical_maximum);
226 1.1 plunky
227 1.1 plunky if (h->unit)
228 1.1 plunky printf(", unit=0x%02x exp=%d", h->unit, h->unit_exponent);
229 1.1 plunky
230 1.1 plunky printf("\n");
231 1.1 plunky }
232