summaryrefslogtreecommitdiffstats
path: root/rfcomm
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-12-24 13:49:04 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-12-24 13:49:04 +0000
commitef7fc3ba8e140d4b05a158e90d57b673f8b82199 (patch)
tree82747adf4cbd381492eee4ef3e1f2db84ce81897 /rfcomm
parentf1e35f0b9edc15eebfd9b2b0b01ffa4bf0f85cdb (diff)
Add authentication, encryption and role switch options
Diffstat (limited to 'rfcomm')
-rw-r--r--rfcomm/main.c52
-rw-r--r--rfcomm/rfcomm.130
2 files changed, 73 insertions, 9 deletions
diff --git a/rfcomm/main.c b/rfcomm/main.c
index 7e42b910..f1897dd8 100644
--- a/rfcomm/main.c
+++ b/rfcomm/main.c
@@ -55,9 +55,10 @@
static char *rfcomm_config_file = NULL;
static int rfcomm_raw_tty = 0;
-
-extern int optind, opterr, optopt;
-extern char *optarg;
+static int auth = 0;
+static int encryption = 0;
+static int secure = 0;
+static int master = 0;
static char *rfcomm_state[] = {
"unknown",
@@ -468,7 +469,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv
sigset_t sigs;
socklen_t alen;
char dst[18], devname[MAXPATHLEN];
- int sk, nsk, fd, try = 30;
+ int sk, nsk, fd, lm, try = 30;
laddr.rc_family = AF_BLUETOOTH;
bacpy(&laddr.rc_bdaddr, bdaddr);
@@ -480,6 +481,22 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv
return;
}
+ lm = 0;
+ if (master)
+ lm |= RFCOMM_LM_MASTER;
+ if (auth)
+ lm |= RFCOMM_LM_AUTH;
+ if (encryption)
+ lm |= RFCOMM_LM_ENCRYPT;
+ if (secure)
+ lm |= RFCOMM_LM_SECURE;
+
+ if (lm && setsockopt(sk, SOL_RFCOMM, RFCOMM_LM, &lm, sizeof(lm)) < 0) {
+ perror("Can't set RFCOMM link mode");
+ close(sk);
+ return;
+ }
+
if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
perror("Can't bind RFCOMM socket");
close(sk);
@@ -660,6 +677,10 @@ static void usage(void)
"\t-i [hciX|bdaddr] Local HCI device or BD Address\n"
"\t-h, --help Display help\n"
"\t-r, --raw Switch TTY into raw mode\n"
+ "\t-A, --auth Enable authentication\n"
+ "\t-E, --encrypt Enable encryption\n"
+ "\t-S, --secure Secure connection\n"
+ "\t-M, --master Become the master of a piconet\n"
"\t-f, --config [file] Specify alternate config file\n"
"\t-a Show all devices (default)\n"
"\n");
@@ -679,18 +700,21 @@ static struct option main_options[] = {
{ "device", 1, 0, 'i' },
{ "config", 1, 0, 'f' },
{ "raw", 0, 0, 'r' },
+ { "auth", 0, 0, 'A' },
+ { "encrypt", 0, 0, 'E' },
+ { "secure", 0, 0, 'S' },
+ { "master", 0, 0, 'M' },
{ 0, 0, 0, 0 }
};
int main(int argc, char *argv[])
{
-
bdaddr_t bdaddr;
int i, opt, ctl, dev_id, show_all = 0;
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt = getopt_long(argc, argv, "+i:f:rah", main_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "+i:f:rahAESM", main_options, NULL)) != -1) {
switch(opt) {
case 'i':
if (strncmp(optarg, "hci", 3) == 0)
@@ -714,6 +738,22 @@ int main(int argc, char *argv[])
usage();
exit(0);
+ case 'A':
+ auth = 1;
+ break;
+
+ case 'E':
+ encryption = 1;
+ break;
+
+ case 'S':
+ secure = 1;
+ break;
+
+ case 'M':
+ master = 1;
+ break;
+
default:
exit(0);
}
diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1
index d1e11cf9..f3744f12 100644
--- a/rfcomm/rfcomm.1
+++ b/rfcomm/rfcomm.1
@@ -58,6 +58,18 @@ hciX
, which must be the name or the address of an installed Bluetooth
device. If not specified, the command will be use the first
available Bluetooth device.
+.TP
+.BI -A
+Enable authentification
+.TP
+.BI -E
+Enable encryption
+.TP
+.BI -S
+Secure connection
+.TP
+.BI -M
+Become the master of a piconet
.SH COMMANDS
.TP
.BI show " <dev>"
@@ -70,10 +82,22 @@ 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]"
+.BI listen " <dev> [channel] [cmd]"
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.
+If no channel is specified, it will use the channel number 1, but
+a channel must be specified before cmd. If cmd is given, it will be
+executed as soon as a client connects. When the child process
+terminates or the client disconnect, the command will terminate.
+Occurences of {} in cmd will be replaced by the name of the device
+used by the connection. This command can be terminated with the key
+sequence CTRL-C.
+.TP
+.BI watch " <dev> [channel] [cmd]"
+Watch is identical to
+.B listen
+except that when the child process terminates or the client
+disconnect, the command will restart listening with the same
+parameters.
.TP
.BI bind " <dev> [bdaddr] [channel]"
This binds the RFCOMM device to a remote Bluetooth device. The