Home | History | Annotate | Line # | Download | only in btdevctl
print.c revision 1.7.4.2
      1  1.7.4.2  wrstuden /*	$NetBSD: print.c,v 1.7.4.2 2007/09/30 03:39:20 wrstuden 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.7.4.2  wrstuden __RCSID("$NetBSD: print.c,v 1.7.4.2 2007/09/30 03:39:20 wrstuden 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.7.4.1  wrstuden 	obj = prop_dictionary_get(dict, BTDEVmode);
    103  1.7.4.1  wrstuden 	if (prop_object_type(obj) == PROP_TYPE_STRING)
    104  1.7.4.1  wrstuden 		printf("link mode: %s\n", prop_string_cstring_nocopy(obj));
    105  1.7.4.1  wrstuden 
    106      1.1    plunky 	obj = prop_dictionary_get(dict, BTDEVtype);
    107      1.1    plunky 	if (prop_object_type(obj) != PROP_TYPE_STRING) {
    108      1.1    plunky 		printf("No device type!\n");
    109      1.1    plunky 		return;
    110      1.1    plunky 	}
    111      1.7    plunky 	printf("device type: %s\n", prop_string_cstring_nocopy(obj));
    112      1.1    plunky 
    113      1.1    plunky 	if (prop_string_equals_cstring(obj, "bthidev")) {
    114      1.1    plunky 		cfg_bthidev(dict);
    115      1.1    plunky 		return;
    116      1.1    plunky 	}
    117      1.1    plunky 
    118      1.1    plunky 	if (prop_string_equals_cstring(obj, "btsco")) {
    119      1.1    plunky 		cfg_btsco(dict);
    120      1.1    plunky 		return;
    121      1.1    plunky 	}
    122      1.1    plunky 
    123      1.1    plunky 	printf("Unknown device type!\n");
    124      1.1    plunky }
    125      1.1    plunky 
    126      1.1    plunky static void
    127      1.1    plunky cfg_bthidev(prop_dictionary_t dict)
    128      1.1    plunky {
    129      1.1    plunky 	prop_object_t obj;
    130      1.1    plunky 
    131      1.1    plunky 	obj = prop_dictionary_get(dict, BTHIDEVcontrolpsm);
    132      1.1    plunky 	if (prop_object_type(obj) == PROP_TYPE_NUMBER)
    133      1.2        he 		printf("control psm: 0x%4.4" PRIx64 "\n",
    134      1.2        he 			prop_number_integer_value(obj));
    135      1.1    plunky 
    136      1.1    plunky 	obj = prop_dictionary_get(dict, BTHIDEVinterruptpsm);
    137      1.1    plunky 	if (prop_object_type(obj) == PROP_TYPE_NUMBER)
    138      1.2        he 		printf("interrupt psm: 0x%4.4" PRIx64 "\n",
    139      1.2        he 			prop_number_integer_value(obj));
    140      1.1    plunky 
    141      1.1    plunky 	obj = prop_dictionary_get(dict, BTHIDEVreconnect);
    142      1.1    plunky 	if (prop_bool_true(obj))
    143  1.7.4.2  wrstuden 		printf("reconnect mode: true\n");
    144      1.1    plunky 
    145      1.1    plunky 	obj = prop_dictionary_get(dict, BTHIDEVdescriptor);
    146      1.1    plunky 	if (prop_object_type(obj) == PROP_TYPE_DATA)
    147      1.1    plunky 		hid_parse(obj);
    148      1.1    plunky }
    149      1.1    plunky 
    150      1.1    plunky static void
    151      1.1    plunky cfg_btsco(prop_dictionary_t dict)
    152      1.1    plunky {
    153      1.1    plunky 	prop_object_t obj;
    154      1.1    plunky 
    155      1.1    plunky 	obj = prop_dictionary_get(dict, BTSCOlisten);
    156      1.1    plunky 	printf("mode: %s\n", prop_bool_true(obj) ? "listen" : "connect");
    157      1.1    plunky 
    158      1.1    plunky 	obj = prop_dictionary_get(dict, BTSCOchannel);
    159      1.1    plunky 	if (prop_object_type(obj) == PROP_TYPE_NUMBER)
    160      1.2        he 		printf("channel: %" PRId64 "\n",
    161      1.2        he 			prop_number_integer_value(obj));
    162      1.1    plunky }
    163      1.1    plunky 
    164      1.1    plunky static void
    165      1.1    plunky hid_parse(prop_data_t desc)
    166      1.1    plunky {
    167      1.1    plunky 	report_desc_t		 r;
    168      1.1    plunky 	hid_data_t		 d;
    169      1.1    plunky 	struct hid_item		 h;
    170      1.1    plunky 
    171      1.1    plunky 	hid_init(NULL);
    172      1.1    plunky 
    173  1.7.4.1  wrstuden 	r = hid_use_report_desc(prop_data_data_nocopy(desc),
    174      1.1    plunky 				prop_data_size(desc));
    175      1.1    plunky 	if (r == NULL)
    176      1.1    plunky 		return;
    177      1.1    plunky 
    178      1.1    plunky 	d = hid_start_parse(r, ~0, -1);
    179      1.1    plunky 	while (hid_get_item(d, &h)) {
    180      1.1    plunky 		switch (h.kind) {
    181      1.1    plunky 		case hid_collection:
    182      1.1    plunky 			printf("Collection page=%s usage=%s\n",
    183      1.1    plunky 				hid_usage_page(HID_PAGE(h.usage)),
    184      1.1    plunky 				hid_usage_in_page(h.usage));
    185      1.1    plunky 			break;
    186      1.1    plunky 
    187      1.1    plunky 		case hid_endcollection:
    188      1.1    plunky 			printf("End collection\n");
    189      1.1    plunky 			break;
    190      1.1    plunky 
    191      1.1    plunky 		case hid_input:
    192      1.1    plunky 			hid_dump_item("  Input", &h);
    193      1.1    plunky 			break;
    194      1.1    plunky 
    195      1.1    plunky 		case hid_output:
    196      1.1    plunky 			hid_dump_item(" Output", &h);
    197      1.1    plunky 			break;
    198      1.1    plunky 
    199      1.1    plunky 		case hid_feature:
    200      1.1    plunky 			hid_dump_item("Feature", &h);
    201      1.1    plunky 			break;
    202      1.1    plunky 		}
    203      1.1    plunky 	}
    204      1.1    plunky 
    205      1.1    plunky 	hid_end_parse(d);
    206      1.1    plunky 	hid_dispose_report_desc(r);
    207      1.1    plunky }
    208      1.1    plunky 
    209      1.1    plunky static void
    210      1.1    plunky hid_dump_item(char const *label, struct hid_item *h)
    211      1.1    plunky {
    212      1.1    plunky 
    213      1.1    plunky 	printf("%s id=%u size=%u count=%u page=%s usage=%s%s%s%s%s%s%s%s%s%s",
    214      1.1    plunky 		label, (uint8_t) h->report_ID, h->report_size, h->report_count,
    215      1.1    plunky 		hid_usage_page(HID_PAGE(h->usage)),
    216      1.1    plunky 		hid_usage_in_page(h->usage),
    217      1.1    plunky 		(h->flags & HIO_CONST) ? " Const" : "",
    218      1.1    plunky 		(h->flags & HIO_VARIABLE) ? " Variable" : "",
    219      1.1    plunky 		(h->flags & HIO_RELATIVE) ? " Relative" : "",
    220      1.1    plunky 		(h->flags & HIO_WRAP) ? " Wrap" : "",
    221      1.1    plunky 		(h->flags & HIO_NONLINEAR) ? " NonLinear" : "",
    222      1.1    plunky 		(h->flags & HIO_NOPREF) ? " NoPref" : "",
    223      1.1    plunky 		(h->flags & HIO_NULLSTATE) ? " NullState" : "",
    224      1.1    plunky 		(h->flags & HIO_VOLATILE) ? " Volatile" : "",
    225      1.1    plunky 		(h->flags & HIO_BUFBYTES) ? " BufBytes" : "");
    226      1.1    plunky 
    227      1.1    plunky 	printf(", logical range %d..%d",
    228      1.1    plunky 		h->logical_minimum, h->logical_maximum);
    229      1.1    plunky 
    230      1.1    plunky 	if (h->physical_minimum != h->physical_maximum)
    231      1.1    plunky 		printf(", physical range %d..%d",
    232      1.1    plunky 			h->physical_minimum, h->physical_maximum);
    233      1.1    plunky 
    234      1.1    plunky 	if (h->unit)
    235      1.1    plunky 		printf(", unit=0x%02x exp=%d", h->unit, h->unit_exponent);
    236      1.1    plunky 
    237      1.1    plunky 	printf("\n");
    238      1.1    plunky }
    239