Module Name: src Committed By: snj Date: Sat Sep 26 18:47:47 UTC 2009
Modified Files: src/usr.bin/btpin [netbsd-5]: btpin.1 btpin.c Log Message: Pull up following revision(s) (requested by plunky in ticket #1013): usr.bin/btpin/btpin.c: revision 1.5 usr.bin/btpin/btpin.1: revision 1.9 add a -P flag to attempt immediate pairing To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.7.12.1 src/usr.bin/btpin/btpin.1 cvs rdiff -u -r1.4 -r1.4.4.1 src/usr.bin/btpin/btpin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/btpin/btpin.1 diff -u src/usr.bin/btpin/btpin.1:1.7 src/usr.bin/btpin/btpin.1:1.7.12.1 --- src/usr.bin/btpin/btpin.1:1.7 Fri Nov 9 21:18:24 2007 +++ src/usr.bin/btpin/btpin.1 Sat Sep 26 18:47:47 2009 @@ -1,4 +1,4 @@ -.\" $NetBSD: btpin.1,v 1.7 2007/11/09 21:18:24 plunky Exp $ +.\" $NetBSD: btpin.1,v 1.7.12.1 2009/09/26 18:47:47 snj Exp $ .\" .\" Copyright (c) 2006 Itronix Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 24, 2007 +.Dd May 16, 2009 .Dt BTPIN 1 .Os .Sh NAME @@ -35,6 +35,7 @@ .Nd Bluetooth PIN utility .Sh SYNOPSIS .Nm +.Op Fl P .Op Fl d Ar device .Op Fl s Ar path .Brq Fl p Ar pin | Fl r Op Fl l Ar len @@ -67,6 +68,11 @@ Specify length of PIN to generate, where 1 \*[Le] .Ar len \*[Le] 16. +.It Fl P +Pair with remote device. +.Nm +will attempt to open an authenticated L2CAP connection to the Service +Discovery Service on the remote device, to force immediate pairing. .It Fl p Ar pin The PIN to register. The PIN may be up to 16 bytes in length. Index: src/usr.bin/btpin/btpin.c diff -u src/usr.bin/btpin/btpin.c:1.4 src/usr.bin/btpin/btpin.c:1.4.4.1 --- src/usr.bin/btpin/btpin.c:1.4 Mon Jul 21 14:19:21 2008 +++ src/usr.bin/btpin/btpin.c Sat Sep 26 18:47:47 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: btpin.c,v 1.4 2008/07/21 14:19:21 lukem Exp $ */ +/* $NetBSD: btpin.c,v 1.4.4.1 2009/09/26 18:47:47 snj Exp $ */ /*- * Copyright (c) 2006 Itronix Inc. @@ -33,12 +33,13 @@ #include <sys/cdefs.h> __COPYRIGHT("@(#) Copyright (c) 2006 Itronix, Inc. All rights reserved."); -__RCSID("$NetBSD: btpin.c,v 1.4 2008/07/21 14:19:21 lukem Exp $"); +__RCSID("$NetBSD: btpin.c,v 1.4.4.1 2009/09/26 18:47:47 snj Exp $"); #include <sys/types.h> #include <sys/un.h> #include <bluetooth.h> #include <err.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -52,18 +53,20 @@ { bthcid_pin_response_t rp; struct sockaddr_un un; + struct sockaddr_bt bt; char *pin = NULL; - int ch, s, len; + int ch, s, len, pair; memset(&rp, 0, sizeof(rp)); len = -1; + pair = 0; memset(&un, 0, sizeof(un)); un.sun_len = sizeof(un); un.sun_family = AF_LOCAL; strlcpy(un.sun_path, BTHCID_SOCKET_NAME, sizeof(un.sun_path)); - while ((ch = getopt(ac, av, "a:d:l:p:rs:")) != EOF) { + while ((ch = getopt(ac, av, "a:d:l:Pp:rs:")) != -1) { switch (ch) { case 'a': if (!bt_aton(optarg, &rp.raddr)) { @@ -90,6 +93,10 @@ break; + case 'P': + pair++; + break; + case 'p': pin = optarg; break; @@ -141,6 +148,38 @@ err(EXIT_FAILURE, "send"); close(s); + + if (pair == 0) + exit(EXIT_SUCCESS); + + s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); + if (s < 0) + err(EXIT_FAILURE, "socket"); + + ch = L2CAP_LM_AUTH; + if (setsockopt(s, BTPROTO_L2CAP, SO_L2CAP_LM, &ch, sizeof(ch)) < 0) + err(EXIT_FAILURE, "SO_L2CAP_LM"); + + memset(&bt, 0, sizeof(bt)); + bt.bt_len = sizeof(bt); + bt.bt_family = AF_BLUETOOTH; + bdaddr_copy(&bt.bt_bdaddr, &rp.laddr); + if (bind(s, (struct sockaddr *)&bt, sizeof(bt)) < 0) + err(EXIT_FAILURE, "bind"); + + fprintf(stdout, "Pairing.. "); + fflush(stdout); + + bt.bt_psm = L2CAP_PSM_SDP; + bdaddr_copy(&bt.bt_bdaddr, &rp.raddr); + if (connect(s, (struct sockaddr *)&bt, sizeof(bt)) < 0) { + fprintf(stdout, "failed (%s)\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + close(s); + fprintf(stdout, "done\n"); + exit(EXIT_SUCCESS); } @@ -149,7 +188,7 @@ { fprintf(stderr, - "usage: %s [-d device] [-s socket] {-p pin | -r [-l len]} -a addr\n" + "usage: %s [-P] [-d device] [-s socket] {-p pin | -r [-l len]} -a addr\n" "", getprogname()); exit(EXIT_FAILURE);