From nobody@FreeBSD.org  Fri Aug 25 22:56:16 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id DA53D16A4E7
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 Aug 2006 22:56:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A253243D53
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 Aug 2006 22:56:16 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k7PMuGd1021402
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 Aug 2006 22:56:16 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k7PMuGfo021401;
	Fri, 25 Aug 2006 22:56:16 GMT
	(envelope-from nobody)
Message-Id: <200608252256.k7PMuGfo021401@www.freebsd.org>
Date: Fri, 25 Aug 2006 22:56:16 GMT
From: Dave Eckhardt <davide+freebsd-pr@cs.cmu.edu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] Virtual serial port server code for bluetooth/rfcomm_sppd
X-Send-Pr-Version: www-2.3

>Number:         102523
>Category:       bin
>Synopsis:       [bluetooth] [patch] Virtual serial port server code for bluetooth/rfcomm_sppd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    emax
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 25 23:00:42 GMT 2006
>Closed-Date:    Tue Mar 04 17:42:47 UTC 2008
>Last-Modified:  Tue Mar  4 17:50:03 UTC 2008
>Originator:     Dave Eckhardt
>Release:        FreeBSD 6.1-RELEASE i386
>Organization:
Carnegie Mellon University
>Environment:
FreeBSD memex 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Sun May  7 04:32:43 UTC 2006    root@opus.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
While there is already code which enables synchronization
of a PalmOS device over Bluetooth using DUN (dial-up
networking), that seems unnecessarily heavyweight and
harder to secure than the other approach, synchronizing
over an RFCOMM "virtual serial port".

Enclosed please find a patch to rfcomm_sppd which adds
"server mode" code.  I have gone back and forth on whether
server mode should contain a loop around the existing
single-transaction code, but figured I'd send in what I
have now and let the maintainer make the policy decision.

I don't have an obvious way to test the (original) client-side
RFCOMM behavior, so it would probably be a good idea to make
sure I haven't broken that, though I tried not to.  Also, feel
free to let me know if this approach seems wrong in some way.
>How-To-Repeat:
See directions at http://howto.pilot-link.org/bluesync/ and
ask yourself if it wouldn't be better to skip all the dialup
networking setup on both the Palm device and the host--and
also close that worrisome "-p net:any" door.
>Fix:
http://www.cs.cmu.edu/~davide/howto/hotsync_bluetooth_serial.html  
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->emax 
Responsible-Changed-By: emax 
Responsible-Changed-When: Mon Sep 11 20:49:32 UTC 2006 
Responsible-Changed-Why:  
over to me 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102523 

From: Eric Anderson <anderson@centtech.com>
To: bug-followup@FreeBSD.org, davide+freebsd-pr@cs.cmu.edu
Cc:  
Subject: Re: bin/102523: [bluetooth] [patch] Virtual serial port server code
 for bluetooth/rfcomm_sppd
Date: Mon, 20 Nov 2006 15:47:43 -0600

 Just FYI - this works great for me!  (Palm TREO 700p)
 
 
 Eric
 
 
 -- 
 ------------------------------------------------------------------------
 Eric Anderson        Sr. Systems Administrator        Centaur Technology
 Anything that works is better than anything that doesn't.
 ------------------------------------------------------------------------

From: Bruce M Simpson <bms@incunabulum.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/102523: [bluetooth] [patch] Virtual serial port server code
 for bluetooth/rfcomm_sppd
Date: Thu, 25 Jan 2007 00:29:38 +0000

 This is a multi-part message in MIME format.
 --------------080207040503020809030900
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 FYI: updated diff attached against RELENG_6_2
 
 --------------080207040503020809030900
 Content-Type: text/x-patch;
  name="rfcomm_sppd.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="rfcomm_sppd.diff"
 
 ? .swp
 ? rfcomm_sppd
 ? rfcomm_sppd.1.gz
 ? rfcomm_sppd.c.diff
 Index: rfcomm_sppd.1
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1,v
 retrieving revision 1.7.2.2
 diff -u -p -r1.7.2.2 rfcomm_sppd.1
 --- rfcomm_sppd.1	12 Dec 2005 17:58:13 -0000	1.7.2.2
 +++ rfcomm_sppd.1	25 Jan 2007 00:24:07 -0000
 @@ -25,7 +25,7 @@
  .\" $Id: rfcomm_sppd.1,v 1.3 2003/09/07 18:15:55 max Exp $
  .\" $FreeBSD: src/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1,v 1.7.2.2 2005/12/12 17:58:13 emax Exp $
  .\"
 -.Dd April 26, 2003
 +.Dd January 24, 2007
  .Dt RFCOMM_SPPD 1
  .Os
  .Sh NAME
 @@ -33,7 +33,7 @@
  .Nd RFCOMM Serial Port Profile daemon
  .Sh SYNOPSIS
  .Nm
 -.Op Fl bh
 +.Op Fl bhS
  .Fl a Ar address
  .Fl c Ar channel
  .Op Fl t Ar tty
 @@ -54,6 +54,32 @@ interface if
  .Fl t
  option was specified.
  .Pp
 +If the
 +.Fl S
 +option is specified,
 +.Nm
 +will act as an RFCOMM server, advertising a virtual serial port
 +via the
 +.Xr sdpd 8
 +daemon.
 +The
 +.Fl t
 +option must be specified;
 +the server side of the virtual serial port is attached to the pseudo-terminal
 +.Ar tty .
 +.Nm
 +should be run as root in order to communicate with
 +.Xr sdp 8
 +in this case.
 +If the
 +.Fl a
 +option is also specified,
 +.Nm
 +will only allow connections from the
 +.Tn Bluetooth
 +device with address
 +.Ar address .
 +.Pp
  The
  .Nm
  utility opens both master and slave pseudo terminals.
 @@ -97,6 +123,9 @@ utility will try to obtain RFCOMM channe
  Discovery Protocol from the server.
  .It Fl h
  Display usage message and exit.
 +.It Fl S
 +Server mode; see
 +.Sx DESCRIPTION .
  .It Fl t Ar tty
  Slave pseudo tty name.
  If not set stdin/stdout will be used.
 @@ -129,7 +158,8 @@ can be used to talk to the remote serial
  .Xr bluetooth 3 ,
  .Xr ng_btsocket 4 ,
  .Xr pty 4 ,
 -.Xr rfcomm_pppd 8
 +.Xr rfcomm_pppd 8 ,
 +.Xr sdpd 8
  .Sh AUTHORS
  .An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
  .Sh BUGS
 Index: rfcomm_sppd.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c,v
 retrieving revision 1.6.2.2
 diff -u -p -r1.6.2.2 rfcomm_sppd.c
 --- rfcomm_sppd.c	12 Dec 2005 17:58:13 -0000	1.6.2.2
 +++ rfcomm_sppd.c	25 Jan 2007 00:24:07 -0000
 @@ -72,16 +72,17 @@ main(int argc, char *argv[]) 
  	struct sockaddr_rfcomm	 ra;
  	bdaddr_t		 addr;
  	int			 n, background, channel, service,
 -				 s, amaster, aslave, fd;
 +				 s, amaster, aslave, fd, doserver;
  	fd_set			 rfd;
  	char			*tty = NULL, *ep = NULL, buf[SPPD_BUFFER_SIZE];
  
  	memcpy(&addr, NG_HCI_BDADDR_ANY, sizeof(addr));
  	background = channel = 0;
  	service = SDP_SERVICE_CLASS_SERIAL_PORT;
 +	doserver = 0;
  
  	/* Parse command line options */
 -	while ((n = getopt(argc, argv, "a:bc:t:h")) != -1) {
 +	while ((n = getopt(argc, argv, "a:bc:t:hS")) != -1) {
  		switch (n) { 
  		case 'a': /* BDADDR */
  			if (!bt_aton(optarg, &addr)) {
 @@ -134,6 +135,10 @@ main(int argc, char *argv[]) 
  				tty = optarg;
  			break;
  
 +		case 'S':
 +			doserver = 1;
 +			break;
 +
  		case 'h':
  		default:
  			usage();
 @@ -142,7 +147,7 @@ main(int argc, char *argv[]) 
  	}
  
  	/* Check if we have everything we need */
 -	if (memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) == 0)
 +	if (!doserver && memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) == 0)
  		usage();
  		/* NOT REACHED */
  
 @@ -165,14 +170,6 @@ main(int argc, char *argv[]) 
  	if (sigaction(SIGCHLD, &sa, NULL) < 0)
  		err(1, "Could not sigaction(SIGCHLD)");
  
 -	/* Check channel, if was not set then obtain it via SDP */
 -	if (channel == 0 && service != 0)
 -		if (rfcomm_channel_lookup(NULL, &addr,
 -			    service, &channel, &n) != 0)
 -			errc(1, n, "Could not obtain RFCOMM channel");
 -	if (channel <= 0 || channel > 30)
 -		errx(1, "Invalid RFCOMM channel number %d", channel);
 -
  	/* Open TTYs */
  	if (tty == NULL) {
  		if (background)
 @@ -187,24 +184,95 @@ main(int argc, char *argv[]) 
  		fd = amaster;
  	}		
  
 -
  	/* Open RFCOMM connection */
 -	memset(&ra, 0, sizeof(ra));
 -	ra.rfcomm_len = sizeof(ra);
 -	ra.rfcomm_family = AF_BLUETOOTH;
 -
 -	s = socket(PF_BLUETOOTH, SOCK_STREAM, BLUETOOTH_PROTO_RFCOMM);
 -	if (s < 0)
 -		err(1, "Could not create socket");
  
 -	if (bind(s, (struct sockaddr *) &ra, sizeof(ra)) < 0)
 -		err(1, "Could not bind socket");
 +	if (doserver) {
 +		struct sockaddr_rfcomm	 ma;
 +		bdaddr_t		 bt_addr_any;
 +		sdp_lan_profile_t	 lan;
 +		void			*ss;
 +		uint32_t		 sdp_handle;
 +		int			 acceptsock, aaddrlen;
 +
 +		if (channel == 0) {
 +			/* XXX: should check if selected channel is unused */
 +			channel = (getpid() % 30) + 1;
 +		}
 +		acceptsock = socket(PF_BLUETOOTH, SOCK_STREAM,
 +		    BLUETOOTH_PROTO_RFCOMM);
 +		if (acceptsock < 0)
 +			err(1, "Could not create socket");
 +
 +		memset(&ma, 0, sizeof(ma));
 +		ma.rfcomm_len = sizeof(ma);
 +		ma.rfcomm_family = AF_BLUETOOTH;
 +		ma.rfcomm_channel = channel;
 +
 +		if (bind(acceptsock, (struct sockaddr *)&ma, sizeof(ma)) < 0)
 +			err(1, "Could not bind socket -- channel %d in use?",
 +			    channel);
 +		listen(acceptsock, 10);
 +
 +		ss = sdp_open_local(NULL);
 +		if (ss == NULL)
 +			errx(1, "Unable to create local SDP session");
 +		if (sdp_error(ss) != 0)
 +			errx(1, "Unable to open local SDP session. %s (%d)",
 +			    strerror(sdp_error(ss)), sdp_error(ss));
 +		memset(&lan, 0, sizeof(lan));
 +		lan.server_channel = channel;
 +
 +		memcpy(&bt_addr_any, NG_HCI_BDADDR_ANY, sizeof(bt_addr_any));
 +		if (sdp_register_service(ss, service, &bt_addr_any,
 +		    (void *)&lan, sizeof(lan), &sdp_handle) != 0) {
 +			errx(1, "Unable to register LAN service with "
 +			    "local SDP daemon. %s (%d)",
 +			    strerror(sdp_error(ss)), sdp_error(ss));
 +		}
 +
 +		s = -1;
 +		while (s < 0) {
 +			aaddrlen = sizeof(ra);
 +			s = accept(acceptsock, (struct sockaddr *)&ra,
 +			    &aaddrlen);
 +			if (s < 0)
 +				err(1, "Unable to accept()");
 +			if (memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) &&
 +			    memcmp(&addr, &ra.rfcomm_bdaddr, sizeof(addr))) {
 +				warnx("Connect from wrong client");
 +				close(s);
 +				s = -1;
 +			}
 +		}
 +		sdp_unregister_service(ss, sdp_handle);
 +		sdp_close(ss);
 +		close(acceptsock);
 +	} else {
 +		/* Check channel, if was not set then obtain it via SDP */
 +		if (channel == 0 && service != 0)
 +			if (rfcomm_channel_lookup(NULL, &addr,
 +				    service, &channel, &n) != 0)
 +				errc(1, n, "Could not obtain RFCOMM channel");
 +		if (channel <= 0 || channel > 30)
 +			errx(1, "Invalid RFCOMM channel number %d", channel);
 +
 +		s = socket(PF_BLUETOOTH, SOCK_STREAM, BLUETOOTH_PROTO_RFCOMM);
 +		if (s < 0)
 +			err(1, "Could not create socket");
 +
 +		if (bind(s, (struct sockaddr *) &ra, sizeof(ra)) < 0)
 +			err(1, "Could not bind socket");
 +
 +		memset(&ra, 0, sizeof(ra));
 +		ra.rfcomm_len = sizeof(ra);
 +		ra.rfcomm_family = AF_BLUETOOTH;
  
 -	memcpy(&ra.rfcomm_bdaddr, &addr, sizeof(ra.rfcomm_bdaddr));
 -	ra.rfcomm_channel = channel;
 +		memcpy(&ra.rfcomm_bdaddr, &addr, sizeof(ra.rfcomm_bdaddr));
 +		ra.rfcomm_channel = channel;
  
 -	if (connect(s, (struct sockaddr *) &ra, sizeof(ra)) < 0)
 -		err(1, "Could not connect socket");
 +		if (connect(s, (struct sockaddr *) &ra, sizeof(ra)) < 0)
 +			err(1, "Could not connect socket");
 +	}
  
  	/* Became daemon if required */
  	if (background) {
 @@ -346,7 +414,7 @@ sppd_ttys_open(char const *tty, int *ama
  		ttygid = -1;
  
  	(void) chown(tty, getuid(), ttygid);
 -	(void) chmod(tty, S_IRUSR|S_IWUSR|S_IWGRP);
 +	(void) chmod(tty, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
  	(void) revoke(tty);
  
  	if ((*aslave = open(tty, O_RDWR, 0)) < 0) {
 @@ -433,12 +501,12 @@ usage(void)
  	fprintf(stdout,
  "Usage: %s options\n" \
  "Where options are:\n" \
 -"\t-a address Address to connect to (required)\n" \
 +"\t-a address Peer address (required in client mode)\n" \
  "\t-b         Run in background\n" \
  "\t-c channel RFCOMM channel to connect to\n" \
  "\t-t tty     TTY name (required in background mode)\n" \
 +"\t-S         Serve an RFCOMM connection to one client\n" \
  "\t-h         Display this message\n", SPPD_IDENT);
 -
  	exit(255);
  } /* usage */
  
 
 --------------080207040503020809030900--
State-Changed-From-To: open->feedback 
State-Changed-By: emax 
State-Changed-When: Thu Jan 25 20:55:52 UTC 2007 
State-Changed-Why:  
patch committed to -current 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102523 
State-Changed-From-To: feedback->patched 
State-Changed-By: linimon 
State-Changed-When: Sun Mar 2 05:58:47 UTC 2008 
State-Changed-Why:  
Patch was committed to -current, awaiting MFC. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=102523 
State-Changed-From-To: patched->closed 
State-Changed-By: emax 
State-Changed-When: Tue Mar 4 17:42:20 UTC 2008 
State-Changed-Why:  
patch was MFC'ed 


http://www.freebsd.org/cgi/query-pr.cgi?pr=102523 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/102523: commit references a PR
Date: Tue,  4 Mar 2008 17:42:10 +0000 (UTC)

 emax        2008-03-04 17:41:58 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.bin/bluetooth/rfcomm_sppd rfcomm_sppd.1 rfcomm_sppd.c 
   Log:
   MFC: add "server mode" to rfcomm_sppd(1)
   
   MFC: Check return value of listen()
   
   PR:             bin/102523
   Submitted by:   Dave Eckhardt, bms, kevlo
   Tested by:      Dave Eckhardt, Eric Anderson, bms
   
   Revision  Changes    Path
   1.7.2.3   +53 -8     src/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1
   1.6.2.3   +100 -31   src/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:

patch was MFC'ed
