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/rfcomm_pppd | |
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/rfcomm_pppd')
-rw-r--r-- | usr.sbin/bluetooth/rfcomm_pppd/Makefile | 15 | ||||
-rw-r--r-- | usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 | 29 | ||||
-rw-r--r-- | usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c | 80 |
3 files changed, 79 insertions, 45 deletions
diff --git a/usr.sbin/bluetooth/rfcomm_pppd/Makefile b/usr.sbin/bluetooth/rfcomm_pppd/Makefile index 0269123..adac64e 100644 --- a/usr.sbin/bluetooth/rfcomm_pppd/Makefile +++ b/usr.sbin/bluetooth/rfcomm_pppd/Makefile @@ -1,13 +1,14 @@ -# $Id: Makefile,v 1.2 2003/03/15 03:07:50 max Exp $ +# $Id: Makefile,v 1.7 2003/09/07 18:32:11 max Exp $ # $FreeBSD$ -DESTDIR= /usr/sbin/ -MANDIR= ../share/man/man +.PATH: ${.CURDIR}/../../../usr.bin/bluetooth/rfcomm_sppd + PROG= rfcomm_pppd -MAN8= rfcomm_pppd.8 +MAN= rfcomm_pppd.8 +SRCS= rfcomm_pppd.c rfcomm_sdp.c WARNS?= 2 -CFLAGS+= -g -I${.CURDIR}/../../../sys/netgraph/bluetooth/include -SRCS= rfcomm_pppd.c -.include <bsd.prog.mk> +DPADD= ${LIBBLUETOOTH} ${LIBSDP} +LDADD= -lbluetooth -lsdp +.include <bsd.prog.mk> diff --git a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 b/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 index d6af46d..591a5ce 100644 --- a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 +++ b/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: rfcomm_pppd.8,v 1.5 2003/04/27 19:45:37 max Exp $ +.\" $Id: rfcomm_pppd.8,v 1.7 2003/09/07 18:32:11 max Exp $ .\" $FreeBSD$ .\" .Dd February 4, 2003 @@ -54,7 +54,7 @@ It can operate in two modes: client and server. .Pp In the client mode, .Nm -opens an RFCOMM connection to the specified server's +opens a RFCOMM connection to the specified server's .Ar BD_ADRR and .Ar channel . @@ -75,7 +75,7 @@ and connect to the Internet. .Pp In the server mode, .Nm -opens an RFCOMM socket and listens for incomming connections from remote clients. +opens a RFCOMM socket and listens for incomming connections from remote clients. Once the new incomming connection is accepted, .Nm forks and executes @@ -92,7 +92,7 @@ the standard serial port thus providing network connectivity to remote clients. The options are as follows: .Bl -tag -width indent .It Fl a Ar BD_ADDR -In the client mode, this required option specifies the remote BD_ADDR of the +In the client mode this required option specifies the remote BD_ADDR of the RFCOMM server. In the server mode, this option can be used to specify the local BD_ADDR to listen on. @@ -100,21 +100,32 @@ By default, server will listen on .Dv ANY address. .It Fl C Ar channel -In both client and server modes, this required option specifies RFCOMM channel +In both client and server modes this required option specifies RFCOMM channel to connect to or listen on. +In the server mode RFCOMM channel should be number between 1 and 30. +In the client mode RFCOMM channel could be either number between 1 and 30 or +service name. Supported service names are: +.Cm DUN +for DialUp Networking service and +.Cm LAN +for LAN Access Using PPP service. +If service name was specified instead of numeric RFCOMM channel then +.Nm +utility will try to obtain RFCOMM channel for the service via Service +Discovery Protocol. .It Fl c -Act as an RFCOMM client. +Act as a RFCOMM client. This is the default mode. .It Fl d Do not detach from the controlling terminal, i.e., run in foreground. .It Fl h Display usage message and exit. .It Fl l Ar label -In both client and server modes, this required option specifies which +In both client and server modes this required option specifies which .Xr ppp 8 label will be used. .It Fl s -Act as an RFCOMM server. +Act as a RFCOMM server. .El .Sh PPP CONFIGURATION .Ss Important Notes on PPP Configuration @@ -265,7 +276,7 @@ label. The .Nm utility -is not currently integrated with the SDP (Service Discovery Protocol). +does not register services with local SDP (Service Discovery Protocol) daemon. .Sh SEE ALSO .Xr rfcomm_sppd 1 , .Xr ng_btsocket 4 , diff --git a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c b/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c index 160988e..ec9f4ca4 100644 --- a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c +++ b/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c @@ -25,18 +25,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: rfcomm_pppd.c,v 1.3 2003/04/26 23:59:49 max Exp $ + * $Id: rfcomm_pppd.c,v 1.5 2003/09/07 18:32:11 max Exp $ * $FreeBSD$ */ -#include <sys/types.h> -#include <sys/socket.h> -#include <bitstring.h> +#include <bluetooth.h> +#include <ctype.h> +#include <err.h> #include <errno.h> #include <fcntl.h> -#include <ng_hci.h> -#include <ng_l2cap.h> -#include <ng_btsocket.h> +#include <sdp.h> #include <signal.h> #include <stdarg.h> #include <stdio.h> @@ -47,6 +45,10 @@ #define RFCOMM_PPPD "rfcomm_pppd" +int rfcomm_channel_lookup (bdaddr_t const *local, + bdaddr_t const *remote, + int service, int *channel, int *error); + static void exec_ppp (int s, char *label); static void sighandler (int s); static void usage (void); @@ -58,41 +60,49 @@ int main(int argc, char *argv[]) { struct sockaddr_rfcomm sock_addr; - char *label = NULL; + char *label = NULL, *ep = NULL; bdaddr_t addr; - int s, channel, detach, server; + int s, channel, detach, server, service; pid_t pid; memcpy(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)); channel = 0; detach = 1; server = 0; + service = 0; /* Parse command line arguments */ while ((s = getopt(argc, argv, "a:cC:dhl:s")) != -1) { switch (s) { - case 'a': { /* BDADDR */ - int a0, a1, a2, a3, a4, a5; - - if (sscanf(optarg, "%x:%x:%x:%x:%x:%x", - &a5, &a4, &a3, &a2, &a1, &a0) != 6) - usage(); - /* NOT REACHED */ - - addr.b[0] = a0 & 0xff; - addr.b[1] = a1 & 0xff; - addr.b[2] = a2 & 0xff; - addr.b[3] = a3 & 0xff; - addr.b[4] = a4 & 0xff; - addr.b[5] = a5 & 0xff; - } break; + case 'a': /* BDADDR */ + if (!bt_aton(optarg, &addr)) { + struct hostent *he = NULL; + + if ((he = bt_gethostbyname(optarg)) == NULL) + errx(1, "%s: %s", optarg, hstrerror(h_errno)); + + memcpy(&addr, he->h_addr, sizeof(addr)); + } + break; case 'c': /* client */ server = 0; break; case 'C': /* RFCOMM channel */ - channel = atoi(optarg); + channel = strtoul(optarg, &ep, 10); + if (*ep != 0) { + channel = 0; + switch (tolower(optarg[0])) { + case 'd': /* DialUp Networking */ + service = SDP_SERVICE_CLASS_DIALUP_NETWORKING; + break; + + case 'l': /* LAN Access Using PPP */ + service = SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP; + break; + } + } break; case 'd': /* do not detach */ @@ -115,10 +125,22 @@ main(int argc, char *argv[]) } /* Check if we got everything we wanted */ - if ((channel <= 0 || channel > 30) || label == NULL || - (!server && memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) == 0)) - usage(); - /* NOT REACHED */ + if (label == NULL) + errx(1, "Must specify PPP label"); + + if (!server) { + if (memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) == 0) + errx(1, "Must specify server BD_ADDR"); + + /* Check channel, if was not set then obtain it via SDP */ + if (channel == 0 && service != 0) + if (rfcomm_channel_lookup(NULL, &addr, service, + &channel, &s) != 0) + errc(1, s, "Could not obtain RFCOMM channel"); + } + + if (channel <= 0 || channel > 30) + errx(1, "Invalid RFCOMM channel number %d", channel); openlog(RFCOMM_PPPD, LOG_PID | LOG_PERROR | LOG_NDELAY, LOG_USER); |