Teach rfcomm_sppd(1) about service names, so it is possible to specify

service name instead of channel number with -c command option. Supported
service names are: DUN (Dial-Up Networking), FAX (Fax) and SP (Serial Port).

MFC after:	1 week
This commit is contained in:
Maksim Yevmenkin 2005-11-23 00:56:18 +00:00
parent f08e63dc4d
commit d47d4f47b0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=152704
2 changed files with 39 additions and 8 deletions

View File

@ -81,11 +81,18 @@ utility will attempt to resolve the name via
Detach from the controlling terminal, i.e., run in background.
.It Fl c Ar channel
This option specifies RFCOMM channel to connect to.
The channel must provide Serial Port service.
RFCOMM channel could either be a number between 1 and 30 or a service name.
Supported service names are:
.Cm DUN
(for DialUp Networking service),
.Cm FAX
(for Fax service) and
.Cm SP
(for Serial Port service).
If channel was not specified then
.Nm
utility will try to obtain RFCOMM channel via Service Discovery Protocol from
the server.
utility will try to obtain RFCOMM channel for Serial Port service via Service
Discovery Protocol from the server.
.It Fl h
Display usage message and exit.
.It Fl t Ar tty

View File

@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <bluetooth.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@ -70,12 +71,14 @@ main(int argc, char *argv[])
struct sigaction sa;
struct sockaddr_rfcomm ra;
bdaddr_t addr;
int n, background, channel, s, amaster, aslave, fd;
int n, background, channel, service,
s, amaster, aslave, fd;
fd_set rfd;
char *tty = NULL, buf[SPPD_BUFFER_SIZE];
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;
/* Parse command line options */
while ((n = getopt(argc, argv, "a:bc:t:h")) != -1) {
@ -92,7 +95,28 @@ main(int argc, char *argv[])
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 'f': /* Fax */
service = SDP_SERVICE_CLASS_FAX;
break;
case 's': /* Serial Port */
service = SDP_SERVICE_CLASS_SERIAL_PORT;
break;
default:
errx(1, "Unknown service name: %s",
optarg);
/* NOT REACHED */
}
}
break;
case 'b': /* Run in background */
@ -138,9 +162,9 @@ main(int argc, char *argv[])
err(1, "Could not sigaction(SIGCHLD)");
/* Check channel, if was not set then obtain it via SDP */
if (channel == 0)
if (channel == 0 && service != 0)
if (rfcomm_channel_lookup(NULL, &addr,
SDP_SERVICE_CLASS_SERIAL_PORT, &channel, &n) != 0)
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);