diff options
author | emax <emax@FreeBSD.org> | 2003-10-12 22:04:24 +0000 |
---|---|---|
committer | emax <emax@FreeBSD.org> | 2003-10-12 22:04:24 +0000 |
commit | 41bb0e8fd2568243020852e22a6d176bccfa60cd (patch) | |
tree | 0ae0c2be63f9f9161693789721b96beb9cabcc77 /usr.sbin/bluetooth/l2control | |
parent | 66feac7937e372f502539e7d443aee80a25abe16 (diff) | |
download | FreeBSD-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.sbin/bluetooth/l2control')
-rw-r--r-- | usr.sbin/bluetooth/l2control/Makefile | 12 | ||||
-rw-r--r-- | usr.sbin/bluetooth/l2control/l2cap.c | 50 | ||||
-rw-r--r-- | usr.sbin/bluetooth/l2control/l2control.8 | 9 | ||||
-rw-r--r-- | usr.sbin/bluetooth/l2control/l2control.c | 47 |
4 files changed, 66 insertions, 52 deletions
diff --git a/usr.sbin/bluetooth/l2control/Makefile b/usr.sbin/bluetooth/l2control/Makefile index f6fb501..847ff4b 100644 --- a/usr.sbin/bluetooth/l2control/Makefile +++ b/usr.sbin/bluetooth/l2control/Makefile @@ -1,12 +1,12 @@ -# $Id: Makefile,v 1.2 2003/03/15 03:07:47 max Exp $ +# $Id: Makefile,v 1.7 2003/08/14 20:06:22 max Exp $ # $FreeBSD$ -DESTDIR= /usr/sbin/ -MANDIR= ../share/man/man PROG= l2control -MAN8= l2control.8 -WARNS?= 2 -CFLAGS+= -g -I${.CURDIR}/../../../sys/netgraph/bluetooth/include +MAN= l2control.8 SRCS= l2cap.c l2control.c +WARNS?= 2 + +DPADD= ${LIBBLUETOOTH} +LDADD= -lbluetooth .include <bsd.prog.mk> diff --git a/usr.sbin/bluetooth/l2control/l2cap.c b/usr.sbin/bluetooth/l2control/l2cap.c index ca4111d..c23106c 100644 --- a/usr.sbin/bluetooth/l2control/l2cap.c +++ b/usr.sbin/bluetooth/l2control/l2cap.c @@ -25,17 +25,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: l2cap.c,v 1.4 2003/04/26 23:11:25 max Exp $ + * $Id: l2cap.c,v 1.5 2003/05/16 19:52:37 max Exp $ * $FreeBSD$ */ -#include <sys/types.h> #include <sys/ioctl.h> -#include <bitstring.h> +#include <bluetooth.h> #include <errno.h> -#include <ng_hci.h> -#include <ng_l2cap.h> -#include <ng_btsocket.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -43,6 +39,33 @@ #define SIZE(x) (sizeof((x))/sizeof((x)[0])) +/* Print BDADDR */ +static char * +bdaddrpr(bdaddr_t const *ba) +{ + extern int numeric_bdaddr; + static char str[24]; + struct hostent *he = NULL; + + if (memcmp(ba, NG_HCI_BDADDR_ANY, sizeof(*ba)) == 0) { + str[0] = '*'; + str[1] = 0; + + return (str); + } + + if (!numeric_bdaddr && + (he = bt_gethostbyaddr((char *)ba, sizeof(*ba), AF_BLUETOOTH)) != NULL) { + strlcpy(str, he->h_name, sizeof(str)); + + return (str); + } + + bt_ntoa(ba, str); + + return (str); +} /* bdaddrpr */ + /* Send read_node_flags command to the node */ static int l2cap_read_node_flags(int s, int argc, char **argv) @@ -134,17 +157,12 @@ l2cap_read_connection_list(int s, int argc, char **argv) "Remote BD_ADDR Handle Flags Pending State\n"); for (n = 0; n < r.num_connections; n++) { fprintf(stdout, - "%02x:%02x:%02x:%02x:%02x:%02x " \ + "%-17.17s " \ "%6d " \ "%c%c%c%c%c " \ "%7d " \ "%s\n", - r.connections[n].remote.b[5], - r.connections[n].remote.b[4], - r.connections[n].remote.b[3], - r.connections[n].remote.b[2], - r.connections[n].remote.b[1], - r.connections[n].remote.b[0], + bdaddrpr(&r.connections[n].remote), r.connections[n].con_handle, ((r.connections[n].flags & NG_L2CAP_CON_OUTGOING)? 'O' : 'I'), ((r.connections[n].flags & NG_L2CAP_CON_LP_TIMO)? 'L' : ' '), @@ -197,13 +215,11 @@ l2cap_read_channel_list(int s, int argc, char **argv) "Remote BD_ADDR SCID/ DCID PSM IMTU/ OMTU State\n"); for (n = 0; n < r.num_channels; n++) { fprintf(stdout, - "%02x:%02x:%02x:%02x:%02x:%02x " \ + "%-17.17s " \ "%5d/%5d %5d " \ "%5d/%5d " \ "%s\n", - r.channels[n].remote.b[5], r.channels[n].remote.b[4], - r.channels[n].remote.b[3], r.channels[n].remote.b[2], - r.channels[n].remote.b[1], r.channels[n].remote.b[0], + bdaddrpr(&r.channels[n].remote), r.channels[n].scid, r.channels[n].dcid, r.channels[n].psm, r.channels[n].imtu, r.channels[n].omtu, diff --git a/usr.sbin/bluetooth/l2control/l2control.8 b/usr.sbin/bluetooth/l2control/l2control.8 index dcd05fe..e98f301 100644 --- a/usr.sbin/bluetooth/l2control/l2control.8 +++ b/usr.sbin/bluetooth/l2control/l2control.8 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: l2control.8,v 1.3 2003/04/27 19:45:34 max Exp $ +.\" $Id: l2control.8,v 1.5 2003/05/21 00:53:00 max Exp $ .\" $FreeBSD$ .\" .Dd June 14, 2002 @@ -33,7 +33,7 @@ .Nd L2CAP configuration utility .Sh SYNOPSIS .Nm -.Op Fl h +.Op Fl hn .Fl a Ar BD_ADDR .Ar command .Op Ar parameters ... @@ -55,6 +55,11 @@ Example: .Fl a Li 00:01:02:03:04:05 . .It Fl h Display usage message and exit. +.It Fl n +Show Bluetooth addresses as numbers. +Normally +.Nm +attempts to resolve Bluetooth addresses, and display them symbolically. .It Ar command One of the supported commands (see below). Special command diff --git a/usr.sbin/bluetooth/l2control/l2control.c b/usr.sbin/bluetooth/l2control/l2control.c index a259657..585021c 100644 --- a/usr.sbin/bluetooth/l2control/l2control.c +++ b/usr.sbin/bluetooth/l2control/l2control.c @@ -25,19 +25,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: l2control.c,v 1.3 2003/04/27 19:45:34 max Exp $ + * $Id: l2control.c,v 1.6 2003/09/05 00:38:25 max Exp $ * $FreeBSD$ */ -#include <sys/types.h> -#include <sys/socket.h> -#include <bitstring.h> #include <assert.h> +#include <bluetooth.h> #include <err.h> #include <errno.h> -#include <ng_hci.h> -#include <ng_l2cap.h> -#include <ng_btsocket.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -52,6 +47,9 @@ static void print_l2cap_command (struct l2cap_command *); static void usage (void); /* Main */ + +int numeric_bdaddr = 0; + int main(int argc, char *argv[]) { @@ -61,24 +59,22 @@ main(int argc, char *argv[]) memset(&bdaddr, 0, sizeof(bdaddr)); /* Process command line arguments */ - while ((n = getopt(argc, argv, "a:h")) != -1) { + while ((n = getopt(argc, argv, "a:nh")) != -1) { switch (n) { - case 'a': { - int a0, a1, a2, a3, a4, a5; + case 'a': + if (!bt_aton(optarg, &bdaddr)) { + struct hostent *he = NULL; + + if ((he = bt_gethostbyname(optarg)) == NULL) + errx(1, "%s: %s", optarg, hstrerror(h_errno)); - if (sscanf(optarg, "%x:%x:%x:%x:%x:%x", - &a5, &a4, &a3, &a2, &a1, &a0) != 6) { - usage(); - break; + memcpy(&bdaddr, he->h_addr, sizeof(bdaddr)); } + break; - bdaddr.b[0] = (a0 & 0xff); - bdaddr.b[1] = (a1 & 0xff); - bdaddr.b[2] = (a2 & 0xff); - bdaddr.b[3] = (a3 & 0xff); - bdaddr.b[4] = (a4 & 0xff); - bdaddr.b[5] = (a5 & 0xff); - } break; + case 'n': + numeric_bdaddr = 1; + break; case 'h': default: @@ -144,10 +140,7 @@ do_l2cap_command(bdaddr_p bdaddr, int argc, char **argv) if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) err(2, -"Could not bind socket, bdaddr=%x:%x:%x:%x:%x:%x", - sa.l2cap_bdaddr.b[5], sa.l2cap_bdaddr.b[4], - sa.l2cap_bdaddr.b[3], sa.l2cap_bdaddr.b[2], - sa.l2cap_bdaddr.b[1], sa.l2cap_bdaddr.b[0]); +"Could not bind socket, bdaddr=%s", bt_ntoa(&sa.l2cap_bdaddr, NULL)); e = 0x0ffff; if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &e, sizeof(e)) < 0) @@ -200,7 +193,7 @@ find_l2cap_command(char const *command, struct l2cap_command *category) return (NULL); } /* find_l2cap_command */ -/* Try to find command in specified category */ +/* Print commands in specified category */ static void print_l2cap_command(struct l2cap_command *category) { @@ -214,7 +207,7 @@ print_l2cap_command(struct l2cap_command *category) static void usage(void) { - fprintf(stdout, "Usage: l2control -a BD_ADDR [-h] cmd [p1] [..]]\n"); + fprintf(stdout, "Usage: l2control -a BD_ADDR [-n] [-h] cmd [p1] [..]]\n"); exit(255); } /* usage */ |