summaryrefslogtreecommitdiffstats
path: root/usr.bin/bluetooth/bthost
diff options
context:
space:
mode:
authoremax <emax@FreeBSD.org>2003-10-12 22:04:24 +0000
committeremax <emax@FreeBSD.org>2003-10-12 22:04:24 +0000
commit41bb0e8fd2568243020852e22a6d176bccfa60cd (patch)
tree0ae0c2be63f9f9161693789721b96beb9cabcc77 /usr.bin/bluetooth/bthost
parent66feac7937e372f502539e7d443aee80a25abe16 (diff)
downloadFreeBSD-src-41bb0e8fd2568243020852e22a6d176bccfa60cd.zip
FreeBSD-src-41bb0e8fd2568243020852e22a6d176bccfa60cd.tar.gz
Update Bluetooth code.
Reviewed by: M. Warner Losh <imp@bsdimp.com>; John Hay <jhay@freebsd.org> Approved by: M. Warner Losh <imp@bsdimp.com> (mentor)
Diffstat (limited to 'usr.bin/bluetooth/bthost')
-rw-r--r--usr.bin/bluetooth/bthost/Makefile12
-rw-r--r--usr.bin/bluetooth/bthost/bthost.1111
-rw-r--r--usr.bin/bluetooth/bthost/bthost.c142
3 files changed, 265 insertions, 0 deletions
diff --git a/usr.bin/bluetooth/bthost/Makefile b/usr.bin/bluetooth/bthost/Makefile
new file mode 100644
index 0000000..a761bbc
--- /dev/null
+++ b/usr.bin/bluetooth/bthost/Makefile
@@ -0,0 +1,12 @@
+# $Id: Makefile,v 1.4 2003/08/14 20:07:13 max Exp $
+# $FreeBSD$
+
+PROG= bthost
+MAN= bthost.1
+SRCS= bthost.c
+WARNS?= 2
+
+DPADD= ${LIBBLUETOOTH}
+LDADD= -lbluetooth
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/bluetooth/bthost/bthost.1 b/usr.bin/bluetooth/bthost/bthost.1
new file mode 100644
index 0000000..2fda952
--- /dev/null
+++ b/usr.bin/bluetooth/bthost/bthost.1
@@ -0,0 +1,111 @@
+.\" Copyright (c) 2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $Id: bthost.1,v 1.7 2003/05/21 22:19:00 max Exp $
+.\" $FreeBSD$
+.\"
+.Dd May 8, 2003
+.Dt BTHOST 1
+.Os
+.Sh NAME
+.Nm bthost
+.Nd look up Bluetooth host names and Protocol Service Multiplexor values
+.Sh SYNOPSIS
+.Nm bthost
+.Op Fl bhp
+.Ar host_or_protocol
+.Sh DESCRIPTION
+The
+.Nm
+utility looks for information about Bluetooth hosts and
+Protocol Service Multiplexor (PSM) values.
+It gets this information from the
+.Pa /etc/bluetooth/hosts
+and
+.Pa /etc/bluetooth/protocols
+files.
+.Pp
+In host mode it simply converts between host names and Bluetooth addresses.
+The argument can be either host name or Bluetooth address.
+The program first attempts to interpret it as Bluetooth address.
+If this fails, it will treat it as host name.
+A Bluetooth address consists of six hex bytes sparated by column,
+e.g. 01:02:03:04:05:06.
+A host name consists of names separated by dots, e.g. my.cell.phone.
+.Pp
+In protocol mode it simply converts between Protocol Service Multiplexor names
+and assigned numbers.
+The argument can be either Protocol Service Multiplexor name or assigned number.
+The program first attempts to interpret it as assigned number.
+.Pp
+The options are as follows:
+.Bl -tag -width indent
+.It Fl b
+Produce brief output.
+.It Fl h
+Display usage message and exit.
+.It Fl p
+Activate protocol mode.
+.El
+.Pp
+The
+.Nm
+utility will print results to the standard output and error messages to the
+standard error.
+You may see output of different kinds.
+Here is an example that shows all of them:
+.Pp
+.D1 Ic % bthost localhost
+.Dl Host localhost has address FF:FF:FF:00:00:00
+.D1 Ic % bthost ff:ff:ff:00:00:00
+.Dl Host FF:FF:FF:00:00:00 has name localhost
+.D1 Ic % bthost -b localhost
+.Dl FF:FF:FF:00:00:00
+.D1 Ic % bthost -b ff:ff:ff:00:00:00
+.Dl localhost
+.D1 Ic % bthost do.not.exists
+.Dl do.not.exists: Unknown host
+.D1 Ic % bthost 0:0:0:0:0:0
+.Dl 00:00:00:00:00:00: Unknown host
+.D1 Ic % bthost -p sdp
+.Dl Protocol/Service Multiplexor sdp has number 1
+.D1 Ic % bthost -p 3
+.Dl Protocol/Service Multiplexor rfcomm has number 3
+.D1 Ic % bthost -bp HID-Control
+.Dl 17
+.D1 Ic % bthost -p foo
+.Dl foo: Unknown Protocol/Service Multiplexor
+.Sh FILES
+.Bl -tag -width "/etc/bluetooth/hosts" -compact
+.It Pa /etc/bluetooth/hosts
+.It Pa /etc/bluetooth/protocols
+.El
+.Sh DIAGNOSTICS
+.Ex -std
+.Sh SEE ALSO
+.Xr bluetooth 3 ,
+.Xr bluetooth.hosts 5 ,
+.Xr bluetooth.protocols 5
+.Sh AUTHORS
+.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
diff --git a/usr.bin/bluetooth/bthost/bthost.c b/usr.bin/bluetooth/bthost/bthost.c
new file mode 100644
index 0000000..2dd5635
--- /dev/null
+++ b/usr.bin/bluetooth/bthost/bthost.c
@@ -0,0 +1,142 @@
+/*
+ * bthost.c
+ *
+ * Copyright (c) 2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: bthost.c,v 1.5 2003/05/21 20:30:01 max Exp $
+ * $FreeBSD$
+ */
+
+#include <bluetooth.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static int hostmode (char const *arg, int brief);
+static int protomode (char const *arg, int brief);
+static void usage (void);
+
+int
+main(int argc, char **argv)
+{
+ int opt, brief = 0, proto = 0;
+
+ while ((opt = getopt(argc, argv, "bhp")) != -1) {
+ switch (opt) {
+ case 'b':
+ brief = 1;
+ break;
+
+ case 'p':
+ proto = 1;
+ break;
+
+ case 'h':
+ default:
+ usage();
+ /* NOT REACHED */
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc < 1)
+ usage();
+
+ exit(proto? protomode(*argv, brief) : hostmode(*argv, brief));
+}
+
+static int
+hostmode(char const *arg, int brief)
+{
+ struct hostent *he = NULL;
+ bdaddr_t ba;
+ char bastr[32];
+ int reverse;
+
+ if (bt_aton(arg, &ba) == 1) {
+ reverse = 1;
+ he = bt_gethostbyaddr((char const *) &ba, sizeof(ba),
+ AF_BLUETOOTH);
+ } else {
+ reverse = 0;
+ he = bt_gethostbyname(arg);
+ }
+
+ if (he == NULL) {
+ herror(reverse? bt_ntoa(&ba, bastr) : arg);
+ return (1);
+ }
+
+ if (brief)
+ printf("%s", reverse? he->h_name :
+ bt_ntoa((bdaddr_t *)(he->h_addr), bastr));
+ else
+ printf("Host %s has %s %s\n",
+ reverse? bt_ntoa(&ba, bastr) : arg,
+ reverse? "name" : "address",
+ reverse? he->h_name :
+ bt_ntoa((bdaddr_t *)(he->h_addr), bastr));
+
+ return (0);
+}
+
+static int
+protomode(char const *arg, int brief)
+{
+ struct protoent *pe = NULL;
+ int proto;
+
+ if ((proto = atoi(arg)) != 0)
+ pe = bt_getprotobynumber(proto);
+ else
+ pe = bt_getprotobyname(arg);
+
+ if (pe == NULL) {
+ fprintf(stderr, "%s: Unknown Protocol/Service Multiplexor\n", arg);
+ return (1);
+ }
+
+ if (brief) {
+ if (proto)
+ printf("%s", pe->p_name);
+ else
+ printf("%d", pe->p_proto);
+ } else {
+ printf("Protocol/Service Multiplexor %s has number %d\n",
+ pe->p_name, pe->p_proto);
+ }
+
+ return (0);
+}
+
+static void
+usage(void)
+{
+ fprintf(stdout, "Usage: bthost [-b -h -p] host_or_protocol\n");
+ exit(255);
+}
+
OpenPOWER on IntegriCloud