Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/rfcomm_sppd In server mode, relax the requirement to...



details:   https://anonhg.NetBSD.org/src/rev/6f92d5c4a9f3
branches:  trunk
changeset: 758359:6f92d5c4a9f3
user:      plunky <plunky%NetBSD.org@localhost>
date:      Wed Nov 03 08:27:27 2010 +0000

description:
In server mode, relax the requirement to specify a channel number. If
one is not given, attempt to allocate the first unused one.

diffstat:

 usr.bin/rfcomm_sppd/rfcomm_sppd.1 |  10 +++++-----
 usr.bin/rfcomm_sppd/rfcomm_sppd.c |  27 +++++++++++++++++----------
 2 files changed, 22 insertions(+), 15 deletions(-)

diffs (129 lines):

diff -r 7a73919f9460 -r 6f92d5c4a9f3 usr.bin/rfcomm_sppd/rfcomm_sppd.1
--- a/usr.bin/rfcomm_sppd/rfcomm_sppd.1 Wed Nov 03 05:23:11 2010 +0000
+++ b/usr.bin/rfcomm_sppd/rfcomm_sppd.1 Wed Nov 03 08:27:27 2010 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: rfcomm_sppd.1,v 1.8 2010/11/02 19:44:09 plunky Exp $
+.\" $NetBSD: rfcomm_sppd.1,v 1.9 2010/11/03 08:27:27 plunky Exp $
 .\"
 .\" Copyright (c) 2006 Itronix Inc.
 .\" All rights reserved.
@@ -65,7 +65,7 @@
 .Op Fl p Ar psm
 .Op Fl s Ar service
 .Op Fl t Ar tty
-.Brq Fl a Ar address | Fl c Ar channel
+.Brq Fl a Ar address | Op Fl c Ar channel
 .Sh DESCRIPTION
 The
 .Nm
@@ -87,7 +87,8 @@
 .Ar service
 with the local SDP server and listens on the specified RFCOMM
 .Ar channel
-for an incoming connection.
+for an incoming connection, or the first unused channel if none
+was given.
 .Pp
 The options are as follows:
 .Bl -tag -width ".Fl c Ar channel"
@@ -100,8 +101,7 @@
 utility will attempt to resolve the name via
 .Xr bt_gethostbyname 3 .
 .It Fl c Ar channel
-Server mode.
-Specify the RFCOMM channel number to listen on.
+In server mode, specify the RFCOMM channel number to listen on.
 .Nm
 will register the service with the local
 .Xr sdpd 8
diff -r 7a73919f9460 -r 6f92d5c4a9f3 usr.bin/rfcomm_sppd/rfcomm_sppd.c
--- a/usr.bin/rfcomm_sppd/rfcomm_sppd.c Wed Nov 03 05:23:11 2010 +0000
+++ b/usr.bin/rfcomm_sppd/rfcomm_sppd.c Wed Nov 03 08:27:27 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rfcomm_sppd.c,v 1.12 2009/09/24 18:30:37 plunky Exp $  */
+/*     $NetBSD: rfcomm_sppd.c,v 1.13 2010/11/03 08:27:27 plunky Exp $  */
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -62,7 +62,7 @@
   Copyright (c) 2006 Itronix, Inc.\
   Copyright (c) 2003 Maksim Yevmenkin m_evmenkin%yahoo.com@localhost.\
   All rights reserved.");
-__RCSID("$NetBSD: rfcomm_sppd.c,v 1.12 2009/09/24 18:30:37 plunky Exp $");
+__RCSID("$NetBSD: rfcomm_sppd.c,v 1.13 2010/11/03 08:27:27 plunky Exp $");
 
 #include <sys/param.h>
 
@@ -128,7 +128,7 @@
        bdaddr_copy(&raddr, BDADDR_ANY);
        service = "SP";
        tty = NULL;
-       channel = 0;
+       channel = RFCOMM_CHANNEL_ANY;
        psm = L2CAP_PSM_RFCOMM;
        lm = 0;
 
@@ -149,7 +149,9 @@
 
                case 'c': /* RFCOMM channel */
                        channel = strtoul(optarg, &ep, 10);
-                       if (*ep != '\0' || channel < 1 || channel > 30)
+                       if (*ep != '\0'
+                           || channel < RFCOMM_CHANNEL_MIN
+                           || channel > RFCOMM_CHANNEL_MAX)
                                errx(EXIT_FAILURE, "Invalid channel: %s", optarg);
 
                        break;
@@ -200,10 +202,9 @@
 
        /*
         * validate options:
-        *      must have channel or remote address but not both
+        *      cannot have remote address if channel was given
         */
-       if ((channel == 0 && bdaddr_any(&raddr))
-           || (channel != 0 && !bdaddr_any(&raddr)))
+       if (channel != RFCOMM_CHANNEL_ANY && !bdaddr_any(&raddr))
                usage();
 
        /*
@@ -218,7 +219,7 @@
        }
 
        /* open RFCOMM */
-       if (channel == 0)
+       if (!bdaddr_any(&raddr))
                rfcomm = open_client(&laddr, &raddr, lm, psm, service);
        else
                rfcomm = open_server(&laddr, psm, channel, lm, service);
@@ -433,6 +434,12 @@
        if (listen(sv, 1) < 0)
                err(EXIT_FAILURE, "listen()");
 
+       len = sizeof(sa);
+       if (getsockname(sv, (struct sockaddr *)&sa, &len) < 0)
+               err(EXIT_FAILURE, "getsockname()");
+       if (len != sizeof(sa))
+               errx(EXIT_FAILURE, "getsockname()");
+
        /* Build SDP record */
        rec.next = buffer;
        rec.end = buffer + sizeof(buffer);
@@ -454,7 +461,7 @@
                sdp_put_uint16(&rec, psm);
        sdp_put_seq(&rec, 5);
        sdp_put_uuid16(&rec, SDP_UUID_PROTOCOL_RFCOMM);
-       sdp_put_uint8(&rec, channel);
+       sdp_put_uint8(&rec, sa.bt_channel);
 
        sdp_put_uint16(&rec, SDP_ATTR_BROWSE_GROUP_LIST);
        sdp_put_seq(&rec, 3);
@@ -671,7 +678,7 @@
        struct service *s;
 
        fprintf(stderr, "Usage: %s [-d device] [-m mode] [-p psm] [-s service] [-t tty]\n"
-                       "       %*s {-a bdaddr | -c channel}\n"
+                       "       %*s {-a bdaddr | [-c channel]}\n"
                        "\n"
                        "Where:\n"
                        "\t-a bdaddr    remote device address\n"



Home | Main Index | Thread Index | Old Index