View | Details | Raw Unified | Return to bug 184597 | Differences between
and this patch

Collapse All | Expand All

(-)b/usr.bin/bluetooth/rfcomm_sppd/Makefile (-1 / +1 lines)
Lines 6-11 SRCS= rfcomm_sppd.c rfcomm_sdp.c Link Here
6
WARNS?=		2
6
WARNS?=		2
7
7
8
DPADD=		${LIBBLUETOOTH} ${LIBSDP}
8
DPADD=		${LIBBLUETOOTH} ${LIBSDP}
9
LDADD=		-lbluetooth -lsdp
9
LDADD=		-lbluetooth -lsdp -lutil
10
10
11
.include <bsd.prog.mk>
11
.include <bsd.prog.mk>
(-)b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1 (-15 / +15 lines)
Lines 33-42 Link Here
33
.Nd RFCOMM Serial Port Profile daemon
33
.Nd RFCOMM Serial Port Profile daemon
34
.Sh SYNOPSIS
34
.Sh SYNOPSIS
35
.Nm
35
.Nm
36
.Op Fl bhS
36
.Op Fl bhtS
37
.Fl a Ar address
37
.Fl a Ar address
38
.Fl c Ar channel
38
.Fl c Ar channel
39
.Op Fl t Ar tty
40
.Sh DESCRIPTION
39
.Sh DESCRIPTION
41
The
40
The
42
.Nm
41
.Nm
Lines 53-59 Once connection is established, the Link Here
53
.Nm
52
.Nm
54
utility provides access to the server's remote serial port via stdin/stdout
53
utility provides access to the server's remote serial port via stdin/stdout
55
or via
54
or via
56
.Xr pty 4
55
.Xr pts 4
57
interface if
56
interface if
58
.Fl t
57
.Fl t
59
option was specified.
58
option was specified.
Lines 72-79 daemon. Link Here
72
If
71
If
73
.Fl t
72
.Fl t
74
options was specified,
73
options was specified,
75
the server side of the virtual serial port is attached to the pseudo-terminal
74
the server side of the virtual serial port is attached to a pseudo-terminal.
76
.Ar tty .
77
Otherwise the virtual serial port is attached to the stdin/stdout.
75
Otherwise the virtual serial port is attached to the stdin/stdout.
78
.Nm
76
.Nm
79
should be run as root in order to communicate with
77
should be run as root in order to communicate with
Lines 146-169 Display usage message and exit. Link Here
146
.It Fl S
144
.It Fl S
147
Server mode; see
145
Server mode; see
148
.Sx DESCRIPTION .
146
.Sx DESCRIPTION .
149
.It Fl t Ar tty
147
.It Fl t
150
Slave pseudo tty name.
148
Use slave pseudo tty.
151
If not set stdin/stdout will be used.
149
If not set stdin/stdout will be used.
152
This option is required if
150
This option is required if
153
.Fl b
151
.Fl b
154
option was specified.
152
option was specified.
155
.El
153
.El
156
.Sh FILES
154
.Sh FILES
157
.Bl -tag -width ".Pa /dev/tty[p-sP-S][0-9a-v]" -compact
155
.Bl -tag -width ".Pa /dev/pts/[num]" -compact
158
.It Pa /dev/pty[p-sP-S][0-9a-v]
156
.It Pa /dev/pts/[num]
159
master pseudo terminals
160
.It Pa /dev/tty[p-sP-S][0-9a-v]
161
slave pseudo terminals
157
slave pseudo terminals
162
.El
158
.El
163
.Sh EXIT STATUS
159
.Sh EXIT STATUS
164
.Ex -std
160
.Ex -std
165
.Sh EXAMPLES
161
.Sh EXAMPLES
166
.Dl "rfcomm_sppd -a 00:01:02:03:04:05 -c 1 -t /dev/ttyp1"
162
.Dl "rfcomm_sppd -a 00:01:02:03:04:05 -c 1 -t"
167
.Pp
163
.Pp
168
Will start the
164
Will start the
169
.Nm
165
.Nm
Lines 171-183 utility and open RFCOMM connection to the server at Link Here
171
.Li 00:01:02:03:04:05
167
.Li 00:01:02:03:04:05
172
and channel
168
and channel
173
.Li 1 .
169
.Li 1 .
174
Once the connection has been established,
170
Once the connection has been established, a
175
.Pa /dev/ttyp1
171
.Xr pts 4
176
can be used to talk to the remote serial port on the server.
172
can be used to talk to the remote serial port on the server.
173
.Nm
174
prints the name of the
175
.Xr pts 4
176
to use.
177
.Sh SEE ALSO
177
.Sh SEE ALSO
178
.Xr bluetooth 3 ,
178
.Xr bluetooth 3 ,
179
.Xr ng_btsocket 4 ,
179
.Xr ng_btsocket 4 ,
180
.Xr pty 4 ,
180
.Xr pts 4 ,
181
.Xr rfcomm_pppd 8 ,
181
.Xr rfcomm_pppd 8 ,
182
.Xr sdpd 8
182
.Xr sdpd 8
183
.Sh AUTHORS
183
.Sh AUTHORS
(-)b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c (-75 / +24 lines)
Lines 32-37 Link Here
32
 */
32
 */
33
33
34
#include <sys/stat.h>
34
#include <sys/stat.h>
35
#include <sys/types.h>
35
#include <bluetooth.h>
36
#include <bluetooth.h>
36
#include <ctype.h>
37
#include <ctype.h>
37
#include <err.h>
38
#include <err.h>
Lines 49-54 Link Here
49
#include <syslog.h>
50
#include <syslog.h>
50
#include <termios.h>
51
#include <termios.h>
51
#include <unistd.h>
52
#include <unistd.h>
53
#include <libutil.h>
52
54
53
#define SPPD_IDENT		"rfcomm_sppd"
55
#define SPPD_IDENT		"rfcomm_sppd"
54
#define SPPD_BUFFER_SIZE	1024
56
#define SPPD_BUFFER_SIZE	1024
Lines 58-64 int rfcomm_channel_lookup (bdaddr_t const *local, Link Here
58
					 bdaddr_t const *remote, 
60
					 bdaddr_t const *remote, 
59
					 int service, int *channel, int *error);
61
					 int service, int *channel, int *error);
60
62
61
static int	sppd_ttys_open	(char const *tty, int *amaster, int *aslave);
63
static int	sppd_ttys_open	(char **tty, int *amaster, int *aslave);
62
static int	sppd_read	(int fd, char *buffer, int size);
64
static int	sppd_read	(int fd, char *buffer, int size);
63
static int	sppd_write	(int fd, char *buffer, int size);
65
static int	sppd_write	(int fd, char *buffer, int size);
64
static void	sppd_sighandler	(int s);
66
static void	sppd_sighandler	(int s);
Lines 74-80 main(int argc, char *argv[]) Link Here
74
	struct sockaddr_rfcomm	 ra;
76
	struct sockaddr_rfcomm	 ra;
75
	bdaddr_t		 addr;
77
	bdaddr_t		 addr;
76
	int			 n, background, channel, service,
78
	int			 n, background, channel, service,
77
				 s, amaster, aslave, fd, doserver;
79
				 s, amaster, aslave, fd, doserver,
80
				 dopty;
78
	fd_set			 rfd;
81
	fd_set			 rfd;
79
	char			*tty = NULL, *ep = NULL, buf[SPPD_BUFFER_SIZE];
82
	char			*tty = NULL, *ep = NULL, buf[SPPD_BUFFER_SIZE];
80
83
Lines 82-90 main(int argc, char *argv[]) Link Here
82
	background = channel = 0;
85
	background = channel = 0;
83
	service = SDP_SERVICE_CLASS_SERIAL_PORT;
86
	service = SDP_SERVICE_CLASS_SERIAL_PORT;
84
	doserver = 0;
87
	doserver = 0;
88
	dopty = 0;
85
89
86
	/* Parse command line options */
90
	/* Parse command line options */
87
	while ((n = getopt(argc, argv, "a:bc:t:hS")) != -1) {
91
	while ((n = getopt(argc, argv, "a:bc:thS")) != -1) {
88
		switch (n) { 
92
		switch (n) { 
89
		case 'a': /* BDADDR */
93
		case 'a': /* BDADDR */
90
			if (!bt_aton(optarg, &addr)) {
94
			if (!bt_aton(optarg, &addr)) {
Lines 130-140 main(int argc, char *argv[]) Link Here
130
			background = 1;
134
			background = 1;
131
			break;
135
			break;
132
136
133
		case 't': /* Slave TTY name */
137
		case 't': /* Open pseudo TTY */
134
			if (optarg[0] != '/')
138
			dopty = 1;
135
				asprintf(&tty, "%s%s", _PATH_DEV, optarg);
136
			else
137
				tty = optarg;
138
			break;
139
			break;
139
140
140
		case 'S':
141
		case 'S':
Lines 173-190 main(int argc, char *argv[]) Link Here
173
		err(1, "Could not sigaction(SIGCHLD)");
174
		err(1, "Could not sigaction(SIGCHLD)");
174
175
175
	/* Open TTYs */
176
	/* Open TTYs */
176
	if (tty == NULL) {
177
	if (dopty) {
178
		if (sppd_ttys_open(&tty, &amaster, &aslave) < 0)
179
			exit(1);
180
181
		fd = amaster;
182
	} else {
177
		if (background)
183
		if (background)
178
			usage();
184
			usage();
179
185
180
		amaster = STDIN_FILENO;
186
		amaster = STDIN_FILENO;
181
		fd = STDOUT_FILENO;
187
		fd = STDOUT_FILENO;
182
	} else {
188
	}
183
		if (sppd_ttys_open(tty, &amaster, &aslave) < 0)
184
			exit(1);
185
		
186
		fd = amaster;
187
	}		
188
189
189
	/* Open RFCOMM connection */
190
	/* Open RFCOMM connection */
190
191
Lines 359-430 main(int argc, char *argv[]) Link Here
359
360
360
/* Open TTYs */
361
/* Open TTYs */
361
static int
362
static int
362
sppd_ttys_open(char const *tty, int *amaster, int *aslave)
363
sppd_ttys_open(char **tty, int *amaster, int *aslave)
363
{
364
{
364
	char		 pty[PATH_MAX], *slash;
365
	char		 pty[PATH_MAX];
365
	struct group	*gr = NULL;
366
	gid_t		 ttygid;
367
	struct termios	 tio;
366
	struct termios	 tio;
368
367
369
	/*
368
	cfmakeraw(&tio);
370
	 * Construct master PTY name. The slave tty name must be less then
371
	 * PATH_MAX characters in length, must contain '/' character and 
372
	 * must not end with '/'.
373
	 */
374
375
	if (strlen(tty) >= sizeof(pty)) {
376
		syslog(LOG_ERR, "Slave tty name is too long");
377
		return (-1);
378
	}
379
380
	strlcpy(pty, tty, sizeof(pty));
381
	slash = strrchr(pty, '/');
382
	if (slash == NULL || slash[1] == '\0') {
383
		syslog(LOG_ERR, "Invalid slave tty name (%s)", tty);
384
		return (-1);
385
	}
386
387
	slash[1] = 'p';
388
	
389
	if (strcmp(pty, tty) == 0) {
390
		syslog(LOG_ERR, "Master and slave tty are the same (%s)", tty);
391
		return (-1);
392
	}
393
394
	if ((*amaster = open(pty, O_RDWR, 0)) < 0) {
395
		syslog(LOG_ERR, "Could not open(%s). %s", pty, strerror(errno));
396
		return (-1);
397
	}
398
399
	/*
400
	 * Slave TTY
401
	 */
402
403
	if ((gr = getgrnam("tty")) != NULL)
404
		ttygid = gr->gr_gid;
405
	else
406
		ttygid = -1;
407
408
	(void) chown(tty, getuid(), ttygid);
409
	(void) chmod(tty, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
410
	(void) revoke(tty);
411
369
412
	if ((*aslave = open(tty, O_RDWR, 0)) < 0) {
370
	if (openpty(amaster, aslave, pty, &tio, NULL) == -1) {
413
		syslog(LOG_ERR, "Could not open(%s). %s", tty, strerror(errno));
371
		syslog(LOG_ERR, "Could not openpty(). %s", strerror(errno));
414
		close(*amaster);
415
		return (-1);
372
		return (-1);
416
	}
373
	}
417
374
418
	/*
375
	if ((*tty = strdup(pty)) == NULL) {
419
	 * Make slave TTY raw
376
		syslog(LOG_ERR, "Could not strdup(). %s", strerror(errno));
420
	 */
421
422
	cfmakeraw(&tio);
423
424
	if (tcsetattr(*aslave, TCSANOW, &tio) < 0) {
425
		syslog(LOG_ERR, "Could not tcsetattr(). %s", strerror(errno));
426
		close(*aslave);
427
		close(*amaster);
428
		return (-1);
377
		return (-1);
429
	}
378
	}
430
379
Lines 496-502 usage(void) Link Here
496
"\t-a address Peer address (required in client mode)\n" \
445
"\t-a address Peer address (required in client mode)\n" \
497
"\t-b         Run in background\n" \
446
"\t-b         Run in background\n" \
498
"\t-c channel RFCOMM channel to connect to or listen on\n" \
447
"\t-c channel RFCOMM channel to connect to or listen on\n" \
499
"\t-t tty     TTY name (required in background mode)\n" \
448
"\t-t         use slave pseudo tty (required in background mode)\n" \
500
"\t-S         Server mode\n" \
449
"\t-S         Server mode\n" \
501
"\t-h         Display this message\n", SPPD_IDENT);
450
"\t-h         Display this message\n", SPPD_IDENT);
502
	exit(255);
451
	exit(255);

Return to bug 184597