4 * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $Id: hid.c,v 1.3 2004/02/17 22:14:57 max Exp $
32 #include <sys/queue.h>
33 #include <bluetooth.h>
34 #include <dev/usb/usb.h>
35 #include <dev/usb/usbhid.h>
39 #include "bthid_config.h"
40 #include "bthidcontrol.h"
42 static void hid_dump_descriptor (report_desc_t r);
43 static void hid_dump_item (char const *label, struct hid_item *h);
46 hid_dump(bdaddr_t *bdaddr, int argc, char **argv)
48 struct hid_device *hd = NULL;
51 if (read_config_file() == 0) {
52 if ((hd = get_hid_device(bdaddr)) != NULL) {
53 hid_dump_descriptor(hd->desc);
64 hid_forget(bdaddr_t *bdaddr, int argc, char **argv)
66 struct hid_device *hd = NULL;
69 if (read_config_file() == 0) {
70 if (read_hids_file() == 0) {
71 if ((hd = get_hid_device(bdaddr)) != NULL) {
73 if (write_hids_file() == 0)
85 hid_known(bdaddr_t *bdaddr, int argc, char **argv)
87 struct hid_device *hd = NULL;
88 struct hostent *he = NULL;
91 if (read_config_file() == 0) {
92 if (read_hids_file() == 0) {
95 for (hd = get_next_hid_device(hd);
97 hd = get_next_hid_device(hd)) {
101 he = bt_gethostbyaddr((char *) &hd->bdaddr,
106 "%s %s\n", bt_ntoa(&hd->bdaddr, NULL),
107 (he != NULL && he->h_name != NULL)?
119 hid_dump_descriptor(report_desc_t r)
121 struct hid_data *d = NULL;
124 for (d = hid_start_parse(r, ~0, -1); hid_get_item(d, &h); ) {
128 "Collection page=%s usage=%s\n", hid_usage_page(HID_PAGE(h.usage)),
129 hid_usage_in_page(h.usage));
132 case hid_endcollection:
133 fprintf(stdout, "End collection\n");
137 hid_dump_item("Input ", &h);
141 hid_dump_item("Output ", &h);
145 hid_dump_item("Feature", &h);
154 hid_dump_item(char const *label, struct hid_item *h)
157 "%s id=%u size=%u count=%u page=%s usage=%s%s%s%s%s%s%s%s%s%s",
158 label, (uint8_t) h->report_ID, h->report_size, h->report_count,
159 hid_usage_page(HID_PAGE(h->usage)),
160 hid_usage_in_page(h->usage),
161 h->flags & HIO_CONST ? " Const" : "",
162 h->flags & HIO_VARIABLE ? " Variable" : "",
163 h->flags & HIO_RELATIVE ? " Relative" : "",
164 h->flags & HIO_WRAP ? " Wrap" : "",
165 h->flags & HIO_NONLINEAR ? " NonLinear" : "",
166 h->flags & HIO_NOPREF ? " NoPref" : "",
167 h->flags & HIO_NULLSTATE ? " NullState" : "",
168 h->flags & HIO_VOLATILE ? " Volatile" : "",
169 h->flags & HIO_BUFBYTES ? " BufBytes" : "");
172 ", logical range %d..%d",
173 h->logical_minimum, h->logical_maximum);
175 if (h->physical_minimum != h->physical_maximum)
177 ", physical range %d..%d",
178 h->physical_minimum, h->physical_maximum);
182 ", unit=0x%02x exp=%d", h->unit, h->unit_exponent);
184 fprintf(stdout, "\n");
187 struct bthid_command hid_commands[] = {
190 "Dump HID descriptor for the specified device in human readable form. The\n" \
191 "device must have an entry in the Bluetooth HID daemon configuration file.\n",
196 "List all known to the Bluetooth HID daemon devices.\n",
201 "Forget (mark as new) specified HID device. This command is useful when it\n" \
202 "is required to remove device from the known HIDs file. This should be done\n" \
203 "when reset button was pressed on the device or the battery was changed. The\n"\
204 "Bluetooth HID daemon should be restarted.\n",