diff options
author | Vladimir Kondratyev <wulf@FreeBSD.org> | 2018-04-30 10:49:29 +0000 |
---|---|---|
committer | Vladimir Kondratyev <wulf@FreeBSD.org> | 2018-04-30 10:49:29 +0000 |
commit | e65080696611e52ddc84103f4314122d0a336fa5 (patch) | |
tree | 107fad098fe8461111419943f00d182333882049 /usr.sbin/bluetooth | |
parent | 4b58fa12407d078957b2d335216ba54a13cf4233 (diff) | |
download | src-e65080696611e52ddc84103f4314122d0a336fa5.tar.gz src-e65080696611e52ddc84103f4314122d0a336fa5.zip |
bthidd(8): Add internal support for user-friendly name of remote devices.
Extend bthidd.conf format to store name of remote Bluetooth HID devices and
implement querying of this information with bthidcontrol(8) "Query" command.
Reviewed by: emax
Differential Revision: https://reviews.freebsd.org/D13456
Notes
Notes:
svn path=/head/; revision=333112
Diffstat (limited to 'usr.sbin/bluetooth')
-rw-r--r-- | usr.sbin/bluetooth/bthidcontrol/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/bluetooth/bthidcontrol/sdp.c | 24 | ||||
-rw-r--r-- | usr.sbin/bluetooth/bthidd/bthid_config.h | 1 | ||||
-rw-r--r-- | usr.sbin/bluetooth/bthidd/bthidd.conf.sample | 2 | ||||
-rw-r--r-- | usr.sbin/bluetooth/bthidd/lexer.l | 9 | ||||
-rw-r--r-- | usr.sbin/bluetooth/bthidd/parser.y | 27 |
6 files changed, 58 insertions, 8 deletions
diff --git a/usr.sbin/bluetooth/bthidcontrol/Makefile b/usr.sbin/bluetooth/bthidcontrol/Makefile index 61988aed562e..b830fced3c99 100644 --- a/usr.sbin/bluetooth/bthidcontrol/Makefile +++ b/usr.sbin/bluetooth/bthidcontrol/Makefile @@ -7,7 +7,8 @@ PROG= bthidcontrol MAN= bthidcontrol.8 SRCS= bthidcontrol.c hid.c lexer.l parser.y sdp.c WARNS?= 1 -CFLAGS+= -DBTHIDCONTROL=1 -I${.CURDIR:H}/bthidd +CFLAGS+= -DBTHIDCONTROL=1 -I${.CURDIR:H}/bthidd -I${SRCTOP}/lib/libsdp \ + -I${SRCTOP}/lib/libbluetooth LIBADD+= bluetooth sdp usbhid diff --git a/usr.sbin/bluetooth/bthidcontrol/sdp.c b/usr.sbin/bluetooth/bthidcontrol/sdp.c index 0728eff874c5..c63ddd5efa0a 100644 --- a/usr.sbin/bluetooth/bthidcontrol/sdp.c +++ b/usr.sbin/bluetooth/bthidcontrol/sdp.c @@ -31,7 +31,9 @@ * $FreeBSD$ */ +#include <sys/types.h> #include <sys/queue.h> +#include <sys/sysctl.h> #define L2CAP_SOCKET_CHECKED #include <bluetooth.h> #include <dev/usb/usb.h> @@ -114,13 +116,15 @@ hid_init_return_values() { static int32_t hid_sdp_query(bdaddr_t const *local, struct hid_device *hd, int32_t *error) { - void *ss = NULL; - uint8_t *hid_descriptor = NULL, *v; - int32_t i, control_psm = -1, interrupt_psm = -1, - reconnect_initiate = -1, - normally_connectable = 0, battery_power = 0, - hid_descriptor_length = -1, type; - int16_t vendor_id = 0, product_id = 0, version = 0; + void *ss = NULL; + uint8_t *hid_descriptor = NULL, *v; + int32_t i, control_psm = -1, interrupt_psm = -1, + reconnect_initiate = -1, + normally_connectable = 0, battery_power = 0, + hid_descriptor_length = -1, type; + int16_t vendor_id = 0, product_id = 0, version = 0; + bdaddr_t sdp_local; + char devname[HCI_DEVNAME_SIZE]; if (local == NULL) local = NG_HCI_BDADDR_ANY; @@ -175,6 +179,11 @@ hid_sdp_query(bdaddr_t const *local, struct hid_device *hd, int32_t *error) if (sdp_search(ss, 1, &service_devid, 1, &attrs_devid, nvalues, values) != 0) hid_sdp_query_exit(sdp_error(ss)); + /* Try extract HCI bdaddr from opened SDP session */ + if (sdp_get_lcaddr(ss, &sdp_local) != 0 || + bt_devname(devname, &sdp_local) == 0) + hid_sdp_query_exit(ENOATTR); + sdp_close(ss); ss = NULL; @@ -212,6 +221,7 @@ hid_sdp_query(bdaddr_t const *local, struct hid_device *hd, int32_t *error) reconnect_initiate == -1 || hid_descriptor == NULL || hid_descriptor_length == -1) hid_sdp_query_exit(ENOATTR); + hd->name = bt_devremote_name_gen(devname, &hd->bdaddr); hd->vendor_id = vendor_id; hd->product_id = product_id; hd->version = version; diff --git a/usr.sbin/bluetooth/bthidd/bthid_config.h b/usr.sbin/bluetooth/bthidd/bthid_config.h index 4a1c1a26b69a..5cce48a39dcf 100644 --- a/usr.sbin/bluetooth/bthidd/bthid_config.h +++ b/usr.sbin/bluetooth/bthidd/bthid_config.h @@ -42,6 +42,7 @@ struct hid_device { bdaddr_t bdaddr; /* HID device BDADDR */ + char * name; /* HID device name */ uint16_t control_psm; /* control PSM */ uint16_t interrupt_psm; /* interrupt PSM */ uint16_t vendor_id; /* primary vendor id */ diff --git a/usr.sbin/bluetooth/bthidd/bthidd.conf.sample b/usr.sbin/bluetooth/bthidd/bthidd.conf.sample index 1750a4c26dce..deb414870da0 100644 --- a/usr.sbin/bluetooth/bthidd/bthidd.conf.sample +++ b/usr.sbin/bluetooth/bthidd/bthidd.conf.sample @@ -2,6 +2,7 @@ device { bdaddr 00:50:f2:e5:68:84; + name "Bluetooth Mouse"; vendor_id 0x0000; product_id 0x0000; version 0x0000; @@ -27,6 +28,7 @@ device { device { bdaddr 00:50:f2:e3:fb:e1; + name "Bluetooth Keyboard"; vendor_id 0x0000; product_id 0x0000; version 0x0000; diff --git a/usr.sbin/bluetooth/bthidd/lexer.l b/usr.sbin/bluetooth/bthidd/lexer.l index ac875e04fae8..22b5d2d18651 100644 --- a/usr.sbin/bluetooth/bthidd/lexer.l +++ b/usr.sbin/bluetooth/bthidd/lexer.l @@ -56,6 +56,7 @@ hexword {hexdigit}{hexdigit}?{hexdigit}?{hexdigit}? device_word device bdaddr_word bdaddr +name_word name vendor_id_word vendor_id product_id_word product_id version_word version @@ -71,6 +72,7 @@ false_word false bdaddrstring {hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte} hexbytestring 0x{hexbyte} hexwordstring 0x{hexword} +string \".+\" %% @@ -85,6 +87,7 @@ hexwordstring 0x{hexword} {device_word} return (T_DEVICE); {bdaddr_word} return (T_BDADDR); +{name_word} return (T_NAME); {vendor_id_word} return (T_VENDOR_ID); {product_id_word} return (T_PRODUCT_ID); {version_word} return (T_VERSION); @@ -118,6 +121,12 @@ hexwordstring 0x{hexword} return (*ep == '\0'? T_HEXWORD : T_ERROR); } +{string} { + yytext[strlen(yytext) - 1] = 0; + yylval.string = &yytext[1]; + return (T_STRING); + } + . return (T_ERROR); %% diff --git a/usr.sbin/bluetooth/bthidd/parser.y b/usr.sbin/bluetooth/bthidd/parser.y index 824f617de276..317101a4b9bd 100644 --- a/usr.sbin/bluetooth/bthidd/parser.y +++ b/usr.sbin/bluetooth/bthidd/parser.y @@ -63,6 +63,8 @@ #define EOL "\n" #endif /* ndef BTHIDCONTROL */ +#define NAMELESS_DEVICE "No Name" + #include "bthid_config.h" int yylex (void); @@ -85,11 +87,14 @@ static LIST_HEAD(, hid_device) hid_devices; %union { bdaddr_t bdaddr; int32_t num; + char *string; } %token <bdaddr> T_BDADDRSTRING %token <num> T_HEXBYTE %token <num> T_HEXWORD +%token <string> T_STRING +%token T_NAME %token T_DEVICE T_BDADDR T_VENDOR_ID T_PRODUCT_ID T_VERSION T_CONTROL_PSM %token T_INTERRUPT_PSM T_RECONNECT_INITIATE T_BATTERY_POWER %token T_NORMALLY_CONNECTABLE T_HID_DESCRIPTOR @@ -128,6 +133,7 @@ options: option ';' ; option: bdaddr + | name | vendor_id | product_id | version @@ -146,6 +152,24 @@ bdaddr: T_BDADDR T_BDADDRSTRING } ; +name: T_NAME T_STRING + { + if (hid_device->name != NULL) { + free(hid_device->name); + hid_device->name = NULL; + } + + if (strcmp($2, NAMELESS_DEVICE)) { + hid_device->name = strdup($2); + if (hid_device->name == NULL) { + SYSLOG(LOGCRIT, "Could not allocate new " \ + "device name" EOL); + YYABORT; + } + } + } + ; + vendor_id: T_VENDOR_ID T_HEXWORD { hid_device->vendor_id = $2; @@ -332,6 +356,7 @@ print_hid_device(hid_device_p d, FILE *f) fprintf(f, "device {\n" \ " bdaddr %s;\n" \ +" name \"%s\";\n" \ " vendor_id 0x%04x;\n" \ " product_id 0x%04x;\n" \ " version 0x%04x;\n" \ @@ -342,6 +367,7 @@ print_hid_device(hid_device_p d, FILE *f) " normally_connectable %s;\n" \ " hid_descriptor {", bt_ntoa(&d->bdaddr, NULL), + (d->name != NULL)? d->name : NAMELESS_DEVICE, d->vendor_id, d->product_id, d->version, d->control_psm, d->interrupt_psm, d->reconnect_initiate? "true" : "false", @@ -419,6 +445,7 @@ free_hid_device(hid_device_p d) if (d->desc != NULL) hid_dispose_report_desc(d->desc); + free(d->name); memset(d, 0, sizeof(*d)); free(d); } |