summaryrefslogtreecommitdiffstats
path: root/rfcomm
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2003-01-18 20:15:45 +0000
committerMarcel Holtmann <marcel@holtmann.org>2003-01-18 20:15:45 +0000
commit0c19759d355a83b63158c66d5f601be816f90424 (patch)
treee84c28bb812d538e476670be6d2550aaee1766ac /rfcomm
parent9d2bce555fcd594df420b39d67f0d4bec313e46f (diff)
Update of the listen command
Diffstat (limited to 'rfcomm')
-rw-r--r--rfcomm/main.c77
-rw-r--r--rfcomm/rfcomm.17
2 files changed, 47 insertions, 37 deletions
diff --git a/rfcomm/main.c b/rfcomm/main.c
index c03f6127..b0df9c72 100644
--- a/rfcomm/main.c
+++ b/rfcomm/main.c
@@ -44,6 +44,7 @@
#include "kword.h"
static char *rfcomm_config_file = NULL;
+static int rfcomm_raw_tty = 0;
extern int optind, opterr, optopt;
extern char *optarg;
@@ -325,10 +326,12 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg
}
}
- tcflush(fd, TCIOFLUSH);
+ if (rfcomm_raw_tty) {
+ tcflush(fd, TCIOFLUSH);
- cfmakeraw(&ti);
- tcsetattr(fd, TCSANOW, &ti);
+ cfmakeraw(&ti);
+ tcsetattr(fd, TCSANOW, &ti);
+ }
close(sk);
@@ -368,32 +371,14 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv
struct sockaddr_rc laddr, raddr;
struct rfcomm_dev_req req;
struct termios ti;
+ struct sigaction sa;
+ struct pollfd p;
char dst[18], devname[MAXPATHLEN];
int sk, nsk, fd, alen;
- int i;
-
- if (argc < 3) {
- fprintf(stderr, "No command specified\n");
- return;
- }
laddr.rc_family = AF_BLUETOOTH;
bacpy(&laddr.rc_bdaddr, bdaddr);
-
- if (strncmp(argv[1], "exec", 4) == 0) {
- laddr.rc_channel = 1;
- argc -= 2;
- argv += 2;
- } else if (strncmp(argv[2], "exec", 4) == 0) {
- laddr.rc_channel = atoi(argv[1]);
- argc -= 3;
- argv += 3;
- } else {
- fprintf(stderr, "Unknown syntax\n");
- return;
- }
-
- argv[argc] = NULL;
+ laddr.rc_channel = (argc < 2) ? 1 : atoi(argv[1]);
if ((sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
perror("Can't create RFCOMM socket");
@@ -444,27 +429,43 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv
}
}
- tcflush(fd, TCIOFLUSH);
+ if (rfcomm_raw_tty) {
+ tcflush(fd, TCIOFLUSH);
- cfmakeraw(&ti);
- tcsetattr(fd, TCSANOW, &ti);
+ cfmakeraw(&ti);
+ tcsetattr(fd, TCSANOW, &ti);
+ }
close(sk);
close(nsk);
ba2str(&req.dst, dst);
printf("Connection from %s to %s\n", dst, devname);
+ printf("Press CTRL-C for hangup\n");
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_flags = SA_NOCLDSTOP;
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGCHLD, &sa, NULL);
+ sigaction(SIGPIPE, &sa, NULL);
+
+ sa.sa_handler = sig_term;
+ sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGINT, &sa, NULL);
+
+ sa.sa_handler = sig_hup;
+ sigaction(SIGHUP, &sa, NULL);
- for (i = 1; i < argc; i++)
- if (strcmp(argv[i], "%d") == 0)
- argv[i] = devname;
+ p.fd = fd;
+ p.events = POLLERR | POLLHUP;
- printf("Executing ");
- for (i = 0; i < argc; i++)
- printf("%s%s", (i == 0) ? "\"" : " ", argv[i]);
- printf("\"\n");
+ while (!__io_canceled) {
+ p.revents = 0;
+ if (poll(&p, 1, 100))
+ break;
+ }
- execvp(argv[0], argv);
+ printf("Disconnected\n");
close(fd);
}
@@ -545,6 +546,7 @@ static struct option main_options[] = {
{ "help", 0, 0, 'h' },
{ "device", 1, 0, 'i' },
{ "config", 1, 0, 'f' },
+ { "raw", 0, 0, 'r' },
{ 0, 0, 0, 0 }
};
@@ -556,7 +558,7 @@ int main(int argc, char *argv[])
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt = getopt_long(argc, argv, "+i:f:ah", main_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "+i:f:rah", main_options, NULL)) != -1) {
switch(opt) {
case 'i':
if (strncmp(optarg, "hci", 3) == 0)
@@ -568,6 +570,9 @@ int main(int argc, char *argv[])
case 'f':
rfcomm_config_file = strdup(optarg);
break;
+ case 'r':
+ rfcomm_raw_tty = 1;
+ break;
case 'a':
show_all = 1;
diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1
index 2164febe..0a0f48a0 100644
--- a/rfcomm/rfcomm.1
+++ b/rfcomm/rfcomm.1
@@ -57,12 +57,17 @@ available Bluetooth device.
.BI show " <dev>"
Display the information about the specified device.
.TP
-.BI conn " <dev> [bdaddr] [channel]"
+.BI connect " <dev> [bdaddr] [channel]"
Connect the RFCOMM device to the remote Bluetooth device on the
specified channel. If no channel is specified, it will use the
channel number 1. If also the Bluetooth address is left out, it
tries to read the data from the config file. This command can
be terminated with the key sequence CTRL-C.
+.TP
+.BI listen " <dev> [channel]"
+Listen on a specified RFCOMM channel for incoming connections.
+If no channel is specified, it will use the channel number 1.
+This command can be terminated with the key sequence CTRL-C.
.TP
.BI bind " <dev> [bdaddr] [channel]"
This binds the RFCOMM device to a remote Bluetooth device. The