From 6728b0dbbfba17d6d41c46aa4cadb52945070771 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Mon, 7 Oct 2002 05:58:18 +0000 Subject: Add RFCOMM TTY configuration tool. --- rfcomm/Makefile.am | 13 ++ rfcomm/kword.c | 60 ++++++++ rfcomm/kword.h | 48 ++++++ rfcomm/lexer.l | 107 +++++++++++++ rfcomm/main.c | 433 +++++++++++++++++++++++++++++++++++++++++++++++++++++ rfcomm/parser.y | 164 ++++++++++++++++++++ rfcomm/rfcomm.8 | 36 +++++ rfcomm/rfcomm.conf | 19 +++ 8 files changed, 880 insertions(+) create mode 100644 rfcomm/Makefile.am create mode 100644 rfcomm/kword.c create mode 100644 rfcomm/kword.h create mode 100644 rfcomm/lexer.l create mode 100644 rfcomm/main.c create mode 100644 rfcomm/parser.y create mode 100644 rfcomm/rfcomm.8 create mode 100644 rfcomm/rfcomm.conf (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am new file mode 100644 index 00000000..6b7a9eee --- /dev/null +++ b/rfcomm/Makefile.am @@ -0,0 +1,13 @@ +# +# $Id$ +# + +sbin_PROGRAMS = rfcomm + +rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c + +man_MANS = rfcomm.8 + +YFLAGS = -d + +CLEANFILES = lexer.c parser.c parser.h diff --git a/rfcomm/kword.c b/rfcomm/kword.c new file mode 100644 index 00000000..c83dcc4b --- /dev/null +++ b/rfcomm/kword.c @@ -0,0 +1,60 @@ +/* + * + * RFCOMM configuration file + * + * Copyright (C) 2001-2002 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include + +#include +#include + +#include "kword.h" +#include "parser.h" + +int lineno; + +struct keyword_t rfcomm_keyword[] = { + { "bind", K_BIND }, + { "device", K_DEVICE }, + { "channel", K_CHANNEL }, + { "comment", K_COMMENT }, + + { "yes", K_YES }, + { "no", K_NO }, + { "enable", K_YES }, + { "disable", K_NO }, + + { NULL , 0 } +}; + +int rfcomm_find_keyword(struct keyword_t *keyword, char *string) +{ + while (keyword->string) { + if (!strcmp(string, keyword->string)) + return keyword->type; + keyword++; + } + + return -1; +} + +struct rfcomm_opts rfcomm_opts[RFCOMM_MAX_DEV]; diff --git a/rfcomm/kword.h b/rfcomm/kword.h new file mode 100644 index 00000000..cdee0c8c --- /dev/null +++ b/rfcomm/kword.h @@ -0,0 +1,48 @@ +/* + * + * RFCOMM configuration file + * + * Copyright (C) 2001-2002 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +extern int lineno; + + +struct keyword_t { + char *string; + int type; +}; + +extern struct keyword_t rfcomm_keyword[]; + +int rfcomm_find_keyword(struct keyword_t *keyword, char *string); + + +#define MAXCOMMENTLEN 100 + +struct rfcomm_opts { + int bind; + bdaddr_t bdaddr; + int channel; + char comment[MAXCOMMENTLEN + 1]; +}; + +extern struct rfcomm_opts rfcomm_opts[RFCOMM_MAX_DEV]; + +int rfcomm_read_config(char *filename); diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l new file mode 100644 index 00000000..c044391f --- /dev/null +++ b/rfcomm/lexer.l @@ -0,0 +1,107 @@ +%{ +/* + * + * RFCOMM configuration file + * + * Copyright (C) 2001-2002 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include + +#include +#include + +#include "kword.h" +#include "parser.h" + + +#define ECHO {;} +#define YY_DECL int yylex(void) + +int yyerror(char *str); + +%} + +space [ \t] +linebreak \n +comment \#.*\n +keyword [A-Za-z0-9\_\-]+ + +number [0-9]+ +string \".*\" +bdaddr [A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2}:[A-Za-z0-9]{2} + +%% + +{space} { + /* Skip spaces and tabs */ + ; + } + +{comment} { + /* Skip comments */ + lineno++; + } + +{number} { + yylval.number = atoi(yytext); + return NUMBER; + } + +{string} { + yylval.string = yytext; + return STRING; + } + +{bdaddr} { + bdaddr_t *ba = malloc(sizeof(bdaddr_t)); + str2ba(yytext, ba); + yylval.bdaddr = ba; + return BDADDR; + } + +{keyword} { + int keyword = rfcomm_find_keyword(rfcomm_keyword, yytext); + if (keyword != -1) + return keyword; + + if (strncmp(yytext, "rfcomm", 6) == 0) { + yylval.number = atoi(yytext + 6); + return RFCOMM; + } + + yylval.string = yytext; + return WORD; + } + +{linebreak} { + lineno++; + } + +. { + return *yytext; + } + +%% + +int yywrap(void) +{ + return 1; +} diff --git a/rfcomm/main.c b/rfcomm/main.c new file mode 100644 index 00000000..2f793faa --- /dev/null +++ b/rfcomm/main.c @@ -0,0 +1,433 @@ +/* + * + * RFCOMM configuration utility + * + * Copyright (C) 2002 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kword.h" + +static char *rfcomm_config_file = NULL; + +extern int optind, opterr, optopt; +extern char *optarg; + +static char *rfcomm_state[] = { + "unknown", + "connected", + "open", + "bound", + "listening", + "connecting", + "connecting", + "config", + "disconnecting", + "closed" +}; + +static volatile sig_atomic_t __io_canceled = 0; + +static void sig_hup(int sig) +{ + return; +} + +static void sig_term(int sig) +{ + __io_canceled = 1; +} + +static char *rfcomm_flagstostr(uint32_t flags) +{ + static char str[100]; + str[0] = 0; + + strcat(str, "["); + + if (flags & (1 << RFCOMM_REUSE_DLC)) + strcat(str, "reuse-dlc "); + + if (flags & (1 << RFCOMM_RELEASE_ONHUP)) + strcat(str, "release-on-hup "); + + if (flags & (1 << RFCOMM_TTY_ATTACHED)) + strcat(str, "tty-attached"); + + strcat(str, "]"); + return str; +} + +static void print_dev_info(struct rfcomm_dev_info *di) +{ + char src[18], dst[18], addr[100]; + + ba2str(&di->src, src); ba2str(&di->dst, dst); + + if (bacmp(&di->src, BDADDR_ANY) == 0) + sprintf(addr, "%s", dst); + else + sprintf(addr, "%s -> %s", src, dst); + + printf("rfcomm%d: %s channel %d %s %s\n", + di->id, addr, di->channel, + rfcomm_state[di->state], + di->flags ? rfcomm_flagstostr(di->flags) : ""); +} + +static void print_dev_list(int ctl, int flags) +{ + struct rfcomm_dev_list_req *dl; + struct rfcomm_dev_info *di; + int i; + + dl = malloc(sizeof(*dl) + RFCOMM_MAX_DEV * sizeof(*di)); + if (!dl) { + perror("Can't allocate memory"); + exit(1); + } + + dl->dev_num = RFCOMM_MAX_DEV; + di = dl->dev_info; + + if (ioctl(ctl, RFCOMMGETDEVLIST, (void *) dl) < 0) { + perror("Can't get device list"); + exit(1); + } + + for (i = 0; i < dl->dev_num; i++) + print_dev_info(di + i); +} + +static int create_dev(int ctl, int dev, int flags, bdaddr_t *bdaddr, int argc, char **argv) +{ + struct rfcomm_dev_req req; + int err; + + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = flags; + bacpy(&req.src, bdaddr); + + if (argc < 2) { + if ((err = rfcomm_read_config(rfcomm_config_file)) < 0) { + perror("Can't open RFCOMM config file"); + return err; + } + + bacpy(&req.dst, &rfcomm_opts[dev].bdaddr); + req.channel = rfcomm_opts[dev].channel; + + if (bacmp(&req.dst, BDADDR_ANY) == 0) { + fprintf(stderr, "Can't find a config entry for rfcomm%d\n", dev); + return -EFAULT; + } + + } else { + str2ba(argv[1], &req.dst); + + if (argc > 2) + req.channel = atoi(argv[2]); + else + req.channel = 1; + } + + if ((err = ioctl(ctl, RFCOMMCREATEDEV, &req)) < 0 ) + perror("Can't create device"); + + return err; +} + +static int create_all(int ctl) +{ + struct rfcomm_dev_req req; + int i, err; + + if ((err = rfcomm_read_config(rfcomm_config_file)) < 0) { + perror("Can't open RFCOMM config file"); + return err; + } + + for (i = 0; i < RFCOMM_MAX_DEV; i++) { + memset(&req, 0, sizeof(req)); + req.dev_id = i; + req.flags = 0; + bacpy(&req.src, BDADDR_ANY); + bacpy(&req.dst, &rfcomm_opts[i].bdaddr); + req.channel = rfcomm_opts[i].channel; + + if (bacmp(&req.dst, BDADDR_ANY) != 0) + ioctl(ctl, RFCOMMCREATEDEV, &req); + } + + return 0; +} + +static int release_dev(int ctl, int dev, int flags) +{ + struct rfcomm_dev_req req; + int err; + + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + + if ((err = ioctl(ctl, RFCOMMRELEASEDEV, &req)) < 0 ) + perror("Can't release device"); + + return err; +} + +static int release_all(int ctl) +{ + struct rfcomm_dev_list_req *dl; + struct rfcomm_dev_info *di; + int i; + + dl = malloc(sizeof(*dl) + RFCOMM_MAX_DEV * sizeof(*di)); + if (!dl) { + perror("Can't allocate memory"); + exit(1); + } + + dl->dev_num = RFCOMM_MAX_DEV; + di = dl->dev_info; + + if (ioctl(ctl, RFCOMMGETDEVLIST, (void *) dl) < 0) { + perror("Can't get device list"); + exit(1); + } + + for (i = 0; i < dl->dev_num; i++) + release_dev(ctl, (di + i)->id, 0); + + return 0; +} + +static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) +{ + struct sigaction sa; + struct pollfd p; + char devname[MAXPATHLEN]; + int fd; + + if (create_dev(ctl, dev, 0, bdaddr, argc, argv) < 0) + return; + + snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); + if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + perror("Can't open RFCOMM device"); + goto release; + } + + 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); + + p.fd = fd; + p.events = POLLHUP; + + while (!__io_canceled) { + p.revents = 0; + poll(&p, 1, 100); + } + + close(fd); + +release: + release_dev(ctl, dev, 0); +} + +static void cmd_create(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) +{ + if (strcmp(argv[0], "all") == 0) + create_all(ctl); + else + create_dev(ctl, dev, 0, bdaddr, argc, argv); +} + +static void cmd_release(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) +{ + if (strcmp(argv[0], "all") == 0) + release_all(ctl); + else + release_dev(ctl, dev, 0); +} + +static void cmd_show(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) +{ + if (strcmp(argv[0], "all") == 0) + print_dev_list(ctl, 0); + else { + struct rfcomm_dev_info di = { id: atoi(argv[0]) }; + if (ioctl(ctl, RFCOMMGETDEVINFO, &di) < 0) { + perror("Get info failed"); + exit(1); + } + + print_dev_info(&di); + } +} + +struct { + char *cmd; + char *alt; + void (*func)(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv); + char *opt; + char *doc; +} command[] = { + { "bind", "create", cmd_create, " [channel]", "Bind device" }, + { "release", "unbind", cmd_release, "", "Release device" }, + { "connect", "conn", cmd_connect, " [channel]", "Connect device" }, + { "show", "info", cmd_show, 0, "Show device" }, + { NULL, NULL, NULL, 0, 0 } +}; + +static void usage(void) +{ + int i; + + printf("RFCOMM configuration utility ver %s\n", VERSION); + + printf("Usage:\n" + "\trfcomm [options] \n" + "\n"); + + printf("Options:\n" + "\t-i [hciX|bdaddr] Local HCI device or BD Address\n" + "\t-h, --help Display help\n" + "\t-a Show all devices (default)\n" + "\n"); + + printf("Commands:\n"); + for (i = 0; command[i].cmd; i++) + printf("\t%-8s %-24s\t%s\n", + command[i].cmd, + command[i].opt ? command[i].opt : " ", + command[i].doc); + printf("\n"); +} + + +static struct option main_options[] = { + { "help", 0, 0, 'h' }, + { "device", 1, 0, 'i' }, + { "config", 1, 0, 'f' }, + { 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:ah", main_options, NULL)) != -1) { + switch(opt) { + case 'i': + if (strncmp(optarg, "hci", 3) == 0) + hci_devba(atoi(optarg + 3), &bdaddr); + else + str2ba(optarg, &bdaddr); + break; + + case 'f': + rfcomm_config_file = strdup(optarg); + break; + + case 'a': + show_all = 1; + break; + + case 'h': + usage(); + exit(0); + + default: + exit(0); + } + } + + argc -= optind; + argv += optind; + optind = 0; + + if (argc < 2) + show_all = 1; + + if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM)) < 0 ) { + perror("Can't open RFCOMM control socket"); + exit(1); + } + + if (show_all) { + print_dev_list(ctl, 0); + close(ctl); + exit(0); + } + + if (strncmp(argv[1], "rfcomm", 6) == 0) + dev_id = atoi(argv[1] + 6); + else + dev_id = atoi(argv[1]); + + for (i = 0; command[i].cmd; i++) { + if (strncmp(command[i].cmd, argv[0], 4) && strncmp(command[i].alt, argv[0], 4)) + continue; + argc--; + argv++; + command[i].func(ctl, dev_id, &bdaddr, argc, argv); + close(ctl); + exit(0); + } + + usage(); + + close(ctl); + + return 0; +} diff --git a/rfcomm/parser.y b/rfcomm/parser.y new file mode 100644 index 00000000..9f05f044 --- /dev/null +++ b/rfcomm/parser.y @@ -0,0 +1,164 @@ +%{ +/* + * + * RFCOMM configuration file + * + * Copyright (C) 2001-2002 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "kword.h" + +int yyparse(void); +int yylex(void); +int yyerror(char *s); + +struct rfcomm_opts *opts; + +%} + +%union { + int number; + char *string; + bdaddr_t *bdaddr; +} + +%token K_BIND K_DEVICE K_CHANNEL K_COMMENT +%token K_YES K_NO + +%token NUMBER RFCOMM +%token STRING WORD +%token BDADDR + +%type bool + +%% + +config : statement | config statement + ; + +statement : section '{' rfcomm_options '}' + | rfcomm '{' rfcomm_options '}' + | WORD + { + } + | error + { + yyclearin; + yyerrok; + } + ; + +section : WORD + { + opts = NULL; + } + +rfcomm : RFCOMM + { + if (($1 >= 0) && ($1 < RFCOMM_MAX_DEV)) + opts = &rfcomm_opts[$1]; + else + opts = NULL; + } + ; + +rfcomm_options : rfcomm_option ';' + | error ';' + | rfcomm_options rfcomm_option ';' + ; + +rfcomm_option : K_BIND bool + { + if (opts) + opts->bind = $2; + } + | K_DEVICE BDADDR + { + if (opts) + bacpy(&opts->bdaddr, $2); + } + | K_CHANNEL NUMBER + { + if (opts) + opts->channel = $2; + } + | K_COMMENT STRING + { + if (opts) + snprintf(opts->comment, MAXCOMMENTLEN, "%s", $2); + } + | WORD + { + // Unknown option + } + ; + +bool : K_YES { $$ = 1; } + | K_NO { $$ = 0; } + ; + +%% + +int yyerror(char *s) +{ + fprintf(stderr, "%s line %d\n", s, lineno); + return 0; +} + +int rfcomm_read_config(char *filename) +{ + extern FILE *yyin; + char file[MAXPATHLEN + 1]; + int i; + + for (i = 0; i < RFCOMM_MAX_DEV; i++) { + rfcomm_opts[i].bind = 0; + bacpy(&rfcomm_opts[i].bdaddr, BDADDR_ANY); + rfcomm_opts[i].channel = 1; + } + + if (filename) { + snprintf(file, MAXPATHLEN, "%s", filename); + } else { + snprintf(file, MAXPATHLEN, "%s/.bluetooth/rfcomm.conf", getenv("HOME")); + + if ((getuid() == 0) || (access(file, R_OK) < 0)) + snprintf(file, MAXPATHLEN, "/etc/bluetooth/rfcomm.conf"); + } + + if (!(yyin = fopen(file, "r"))) + return -1; + + lineno = 1; + yyparse(); + + fclose(yyin); + + return 0; +} diff --git a/rfcomm/rfcomm.8 b/rfcomm/rfcomm.8 new file mode 100644 index 00000000..d60af804 --- /dev/null +++ b/rfcomm/rfcomm.8 @@ -0,0 +1,36 @@ +.\" +.\" This program is free software; you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation; either version 2 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License +.\" along with this program; if not, write to the Free Software +.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +.\" +.\" +.TH RFCOMM 8 "APRIL 28, 2002" "" "" + +.SH NAME +rfcomm \- RFCOMM configuration utility +.SH SYNOPSIS +.BR "rfcomm +[-i +.I hciX | bdaddr +] < +.I command +> < +.I dev +> +.SH DESCRIPTION +.B rfcomm +is used to set up, maintain, and inspect the RFCOMM configuration +of the Bluetooth subsystem in the Linux kernel. +.SH AUTHOR +Written by Marcel Holtmann . +.br diff --git a/rfcomm/rfcomm.conf b/rfcomm/rfcomm.conf new file mode 100644 index 00000000..c1b10cd5 --- /dev/null +++ b/rfcomm/rfcomm.conf @@ -0,0 +1,19 @@ +# +# RFCOMM configuration file. +# +# $Id$ +# + +rfcomm0 { + # Automatically bind the device at startup + bind no; + + # Bluetooth address of the device + device 11:22:33:44:55:66; + + # RFCOMM channel for the connection + channel 1; + + # Description of the connection + comment "Example Bluetooth device"; +} -- cgit From c450127ad7b9705add1c299ec5340e59ff71fbe3 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 7 Oct 2002 07:30:04 +0000 Subject: Correct year in the copyright line --- rfcomm/kword.c | 2 +- rfcomm/kword.h | 2 +- rfcomm/lexer.l | 2 +- rfcomm/parser.y | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/kword.c b/rfcomm/kword.c index c83dcc4b..26943c09 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -2,7 +2,7 @@ * * RFCOMM configuration file * - * Copyright (C) 2001-2002 Marcel Holtmann + * Copyright (C) 2002 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/kword.h b/rfcomm/kword.h index cdee0c8c..9016a5b4 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -2,7 +2,7 @@ * * RFCOMM configuration file * - * Copyright (C) 2001-2002 Marcel Holtmann + * Copyright (C) 2002 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index c044391f..4585f5c9 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -3,7 +3,7 @@ * * RFCOMM configuration file * - * Copyright (C) 2001-2002 Marcel Holtmann + * Copyright (C) 2002 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/parser.y b/rfcomm/parser.y index 9f05f044..d8747c93 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -3,7 +3,7 @@ * * RFCOMM configuration file * - * Copyright (C) 2001-2002 Marcel Holtmann + * Copyright (C) 2002 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 78c812d9f44075238c2f3f8d46a51d574f383cd1 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 7 Oct 2002 07:44:31 +0000 Subject: Install the default rfcomm.conf file --- rfcomm/Makefile.am | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 6b7a9eee..83b1f3f2 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -2,12 +2,23 @@ # $Id$ # -sbin_PROGRAMS = rfcomm +mandir = $(prefix)/share/man +confdir = /etc/bluetooth + +bin_PROGRAMS = rfcomm rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c +rfcomm_CONFIG = rfcomm.conf -man_MANS = rfcomm.8 +man_MANS = rfcomm.8 YFLAGS = -d CLEANFILES = lexer.c parser.c parser.h + +EXTRA_DIST = $(man_MANS) $(rfcomm_CONFIG) + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(confdir) + [ -f $(DESTDIR)$(confdir)/$(rfcomm_CONFIG) ] || \ + $(INSTALL_DATA) $(srcdir)/$(rfcomm_CONFIG) $(DESTDIR)$(confdir)/$(rfcomm_CONFIG) -- cgit From cd0f1ea91c4ffa3ecb6a9b3c6c179fa389d85ac6 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 7 Oct 2002 08:14:34 +0000 Subject: Cleanup --- rfcomm/kword.c | 2 +- rfcomm/kword.h | 2 +- rfcomm/lexer.l | 2 +- rfcomm/parser.y | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/kword.c b/rfcomm/kword.c index 26943c09..3cb9f2c6 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -1,6 +1,6 @@ /* * - * RFCOMM configuration file + * RFCOMM configuration utility * * Copyright (C) 2002 Marcel Holtmann * diff --git a/rfcomm/kword.h b/rfcomm/kword.h index 9016a5b4..dddd2a83 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -1,6 +1,6 @@ /* * - * RFCOMM configuration file + * RFCOMM configuration utility * * Copyright (C) 2002 Marcel Holtmann * diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index 4585f5c9..0f64cb43 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -1,7 +1,7 @@ %{ /* * - * RFCOMM configuration file + * RFCOMM configuration utility * * Copyright (C) 2002 Marcel Holtmann * diff --git a/rfcomm/parser.y b/rfcomm/parser.y index d8747c93..f45f367c 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -1,7 +1,7 @@ %{ /* * - * RFCOMM configuration file + * RFCOMM configuration utility * * Copyright (C) 2002 Marcel Holtmann * -- cgit From 3f1417ff2d1e3fc91ae02c63cfb10eb1f50167cd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 9 Oct 2002 21:58:09 +0000 Subject: Move the man page of rfcomm to section 1 --- rfcomm/Makefile.am | 2 +- rfcomm/rfcomm.1 | 36 ++++++++++++++++++++++++++++++++++++ rfcomm/rfcomm.8 | 36 ------------------------------------ 3 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 rfcomm/rfcomm.1 delete mode 100644 rfcomm/rfcomm.8 (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 83b1f3f2..8ba03314 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -10,7 +10,7 @@ bin_PROGRAMS = rfcomm rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c rfcomm_CONFIG = rfcomm.conf -man_MANS = rfcomm.8 +man_MANS = rfcomm.1 YFLAGS = -d diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1 new file mode 100644 index 00000000..51a258dc --- /dev/null +++ b/rfcomm/rfcomm.1 @@ -0,0 +1,36 @@ +.\" +.\" This program is free software; you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation; either version 2 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License +.\" along with this program; if not, write to the Free Software +.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +.\" +.\" +.TH RFCOMM 1 "APRIL 28, 2002" "" "" + +.SH NAME +rfcomm \- RFCOMM configuration utility +.SH SYNOPSIS +.BR "rfcomm +[-i +.I hciX | bdaddr +] < +.I command +> < +.I dev +> +.SH DESCRIPTION +.B rfcomm +is used to set up, maintain, and inspect the RFCOMM configuration +of the Bluetooth subsystem in the Linux kernel. +.SH AUTHOR +Written by Marcel Holtmann . +.br diff --git a/rfcomm/rfcomm.8 b/rfcomm/rfcomm.8 deleted file mode 100644 index d60af804..00000000 --- a/rfcomm/rfcomm.8 +++ /dev/null @@ -1,36 +0,0 @@ -.\" -.\" This program is free software; you can redistribute it and/or modify -.\" it under the terms of the GNU General Public License as published by -.\" the Free Software Foundation; either version 2 of the License, or -.\" (at your option) any later version. -.\" -.\" This program is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.\" GNU General Public License for more details. -.\" -.\" You should have received a copy of the GNU General Public License -.\" along with this program; if not, write to the Free Software -.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -.\" -.\" -.TH RFCOMM 8 "APRIL 28, 2002" "" "" - -.SH NAME -rfcomm \- RFCOMM configuration utility -.SH SYNOPSIS -.BR "rfcomm -[-i -.I hciX | bdaddr -] < -.I command -> < -.I dev -> -.SH DESCRIPTION -.B rfcomm -is used to set up, maintain, and inspect the RFCOMM configuration -of the Bluetooth subsystem in the Linux kernel. -.SH AUTHOR -Written by Marcel Holtmann . -.br -- cgit From ca71f93f6b66c424e8e76237b98bc293b2f5674c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 17 Oct 2002 22:15:48 +0000 Subject: Correct the man path for rfcomm.1 --- rfcomm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 8ba03314..72635ff2 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -2,7 +2,7 @@ # $Id$ # -mandir = $(prefix)/share/man +mandir = $(prefix)/usr/share/man confdir = /etc/bluetooth bin_PROGRAMS = rfcomm -- cgit From 9295987f15f7b96ac07a19da7d1e0a6f6f51ee6c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 18 Oct 2002 21:59:04 +0000 Subject: Let "rfcomm connect ..." also work with DevFS --- rfcomm/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 2f793faa..f0275f74 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -249,8 +249,11 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { - perror("Can't open RFCOMM device"); - goto release; + snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); + if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + perror("Can't open RFCOMM device"); + goto release; + } } memset(&sa, 0, sizeof(sa)); -- cgit From b172c800ea6c3375be9ded04480038a4ee3044b9 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 27 Oct 2002 16:08:42 +0000 Subject: New RFCOMM connect command which can be called by normal users --- rfcomm/main.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 12 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index f0275f74..a98c584e 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -94,7 +94,7 @@ static char *rfcomm_flagstostr(uint32_t flags) static void print_dev_info(struct rfcomm_dev_info *di) { - char src[18], dst[18], addr[100]; + char src[18], dst[18], addr[40]; ba2str(&di->src, src); ba2str(&di->dst, dst); @@ -133,7 +133,7 @@ static void print_dev_list(int ctl, int flags) print_dev_info(di + i); } -static int create_dev(int ctl, int dev, int flags, bdaddr_t *bdaddr, int argc, char **argv) +static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int argc, char **argv) { struct rfcomm_dev_req req; int err; @@ -197,7 +197,7 @@ static int create_all(int ctl) return 0; } -static int release_dev(int ctl, int dev, int flags) +static int release_dev(int ctl, int dev, uint32_t flags) { struct rfcomm_dev_req req; int err; @@ -239,23 +239,93 @@ static int release_all(int ctl) static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) { + struct sockaddr_rc laddr, raddr; + struct rfcomm_dev_req req; struct sigaction sa; struct pollfd p; - char devname[MAXPATHLEN]; - int fd; + char dst[18], devname[MAXPATHLEN]; + int sk, fd, alen; + + laddr.rc_family = AF_BLUETOOTH; + bacpy(&laddr.rc_bdaddr, bdaddr); + laddr.rc_channel = 0; + + if (argc < 2) { + if (rfcomm_read_config(rfcomm_config_file) < 0) { + perror("Can't open RFCOMM config file"); + return; + } + + raddr.rc_family = AF_BLUETOOTH; + bacpy(&raddr.rc_bdaddr, &rfcomm_opts[dev].bdaddr); + raddr.rc_channel = rfcomm_opts[dev].channel; - if (create_dev(ctl, dev, 0, bdaddr, argc, argv) < 0) + if (bacmp(&req.dst, BDADDR_ANY) == 0) { + fprintf(stderr, "Can't find a config entry for rfcomm%d\n", dev); + return; + } + + } else { + raddr.rc_family = AF_BLUETOOTH; + str2ba(argv[1], &raddr.rc_bdaddr); + + if (argc > 2) + raddr.rc_channel = atoi(argv[2]); + else + raddr.rc_channel = 1; + } + + if ((sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { + perror("Can't create RFCOMM socket"); return; + } + + if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { + perror("Can't bind RFCOMM socket"); + close(sk); + return; + } + + if (connect(sk, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) { + perror("Can't connect RFCOMM socket"); + close(sk); + return; + } + + alen = sizeof(laddr); + if (getsockname(sk, (struct sockaddr *)&laddr, &alen) < 0) { + perror("Can't get RFCOMM socket name"); + close(sk); + return; + } + + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = (1 << RFCOMM_REUSE_DLC) | (1 << RFCOMM_RELEASE_ONHUP); + + bacpy(&req.src, &laddr.rc_bdaddr); + bacpy(&req.dst, &raddr.rc_bdaddr); + req.channel = raddr.rc_channel; + + if ((dev = ioctl(sk, RFCOMMCREATEDEV, &req)) < 0) { + perror("Can't create RFCOMM TTY"); + close(sk); + return; + } snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { perror("Can't open RFCOMM device"); - goto release; + return; } } + ba2str(&req.dst, dst); + printf("Connected %s to %s on channel %d\n", devname, dst, req.channel); + printf("Press CTRL-C for hangup\n"); + memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = SIG_IGN; @@ -270,17 +340,17 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg sigaction(SIGHUP, &sa, NULL); p.fd = fd; - p.events = POLLHUP; + p.events = POLLERR | POLLHUP; while (!__io_canceled) { p.revents = 0; - poll(&p, 1, 100); + if (poll(&p, 1, 100)) + break; } - close(fd); + printf("Disconnected\n"); -release: - release_dev(ctl, dev, 0); + close(fd); } static void cmd_create(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) -- cgit From c9f0375c2a2c9f2488354b83972af955c44daef8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 31 Oct 2002 10:09:48 +0000 Subject: Syntax fix --- rfcomm/parser.y | 1 + 1 file changed, 1 insertion(+) (limited to 'rfcomm') diff --git a/rfcomm/parser.y b/rfcomm/parser.y index f45f367c..5a42b2f1 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -78,6 +78,7 @@ section : WORD { opts = NULL; } + ; rfcomm : RFCOMM { -- cgit From 0137a3922771558d22189839ce78449397651ca8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 1 Nov 2002 19:29:26 +0000 Subject: Display "clean" instead of "open" --- rfcomm/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index a98c584e..0dae70e6 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -50,7 +50,7 @@ extern char *optarg; static char *rfcomm_state[] = { "unknown", "connected", - "open", + "clean", "bound", "listening", "connecting", -- cgit From 1c57015e3e0a917d3b3df7fa61017aed6abf7d0d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 16 Nov 2002 02:33:57 +0000 Subject: Update of the manpage for rfcomm --- rfcomm/rfcomm.1 | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1 index 51a258dc..2164febe 100644 --- a/rfcomm/rfcomm.1 +++ b/rfcomm/rfcomm.1 @@ -20,8 +20,8 @@ rfcomm \- RFCOMM configuration utility .SH SYNOPSIS .BR "rfcomm -[-i -.I hciX | bdaddr +[ +.I options ] < .I command > < @@ -30,7 +30,48 @@ rfcomm \- RFCOMM configuration utility .SH DESCRIPTION .B rfcomm is used to set up, maintain, and inspect the RFCOMM configuration -of the Bluetooth subsystem in the Linux kernel. +of the Bluetooth subsystem in the Linux kernel. If no +.B command +is given, or if the option +.B -a +is used, +.B rfcomm +prints information about the configured RFCOMM devices. +.SH OPTIONS +.TP +.BI -h +Gives a list of possible commands. +.TP +.BI -a +Prints information about all configured RFCOMM devices. +.TP +.BI -i " | " +The command is applied to device +.I +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. +.SH COMMANDS +.TP +.BI show " " +Display the information about the specified device. +.TP +.BI conn " [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 bind " [bdaddr] [channel]" +This binds the RFCOMM device to a remote Bluetooth device. The +command did not establish a connection to the remote device, it +only creates the binding. The connection will be establish right +after an application tries to open the RFCOMM device. +.TP +.BI release " " +This command releases a defined RFCOMM binding. .SH AUTHOR Written by Marcel Holtmann . .br -- cgit From c9271603f6ae622ee61f4514d97adf8e38f3eef1 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 2 Jan 2003 01:50:47 +0000 Subject: Basic support for listen command --- rfcomm/main.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 134 insertions(+), 15 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 0dae70e6..c03f6127 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -2,7 +2,7 @@ * * RFCOMM configuration utility * - * Copyright (C) 2002 Marcel Holtmann + * Copyright (C) 2002-2003 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -50,14 +51,14 @@ extern char *optarg; static char *rfcomm_state[] = { "unknown", "connected", - "clean", - "bound", - "listening", - "connecting", - "connecting", - "config", - "disconnecting", - "closed" + "clean", + "bound", + "listening", + "connecting", + "connecting", + "config", + "disconnecting", + "closed" }; static volatile sig_atomic_t __io_canceled = 0; @@ -241,6 +242,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg { struct sockaddr_rc laddr, raddr; struct rfcomm_dev_req req; + struct termios ti; struct sigaction sa; struct pollfd p; char dst[18], devname[MAXPATHLEN]; @@ -264,7 +266,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg fprintf(stderr, "Can't find a config entry for rfcomm%d\n", dev); return; } - + } else { raddr.rc_family = AF_BLUETOOTH; str2ba(argv[1], &raddr.rc_bdaddr); @@ -296,7 +298,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg if (getsockname(sk, (struct sockaddr *)&laddr, &alen) < 0) { perror("Can't get RFCOMM socket name"); close(sk); - return; + return; } memset(&req, 0, sizeof(req)); @@ -305,7 +307,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg bacpy(&req.src, &laddr.rc_bdaddr); bacpy(&req.dst, &raddr.rc_bdaddr); - req.channel = raddr.rc_channel; + req.channel = raddr.rc_channel; if ((dev = ioctl(sk, RFCOMMCREATEDEV, &req)) < 0) { perror("Can't create RFCOMM TTY"); @@ -318,10 +320,18 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { perror("Can't open RFCOMM device"); + close(sk); return; } } + tcflush(fd, TCIOFLUSH); + + cfmakeraw(&ti); + tcsetattr(fd, TCSANOW, &ti); + + close(sk); + ba2str(&req.dst, dst); printf("Connected %s to %s on channel %d\n", devname, dst, req.channel); printf("Press CTRL-C for hangup\n"); @@ -353,6 +363,112 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg close(fd); } +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; + 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; + + if ((sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { + perror("Can't create RFCOMM socket"); + return; + } + + if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { + perror("Can't bind RFCOMM socket"); + close(sk); + return; + } + + printf("Waiting for connection on channel %d\n", laddr.rc_channel); + + listen(sk, 10); + + alen = sizeof(raddr); + nsk = accept(sk, (struct sockaddr *) &raddr, &alen); + + alen = sizeof(laddr); + if (getsockname(nsk, (struct sockaddr *)&laddr, &alen) < 0) { + perror("Can't get RFCOMM socket name"); + close(nsk); + return; + } + + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = (1 << RFCOMM_REUSE_DLC) | (1 << RFCOMM_RELEASE_ONHUP); + + bacpy(&req.src, &laddr.rc_bdaddr); + bacpy(&req.dst, &raddr.rc_bdaddr); + req.channel = raddr.rc_channel; + + if ((dev = ioctl(nsk, RFCOMMCREATEDEV, &req)) < 0) { + perror("Can't create RFCOMM TTY"); + close(sk); + return; + } + + snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); + if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); + if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + perror("Can't open RFCOMM device"); + close(sk); + return; + } + } + + tcflush(fd, TCIOFLUSH); + + cfmakeraw(&ti); + tcsetattr(fd, TCSANOW, &ti); + + close(sk); + close(nsk); + + ba2str(&req.dst, dst); + printf("Connection from %s to %s\n", dst, devname); + + for (i = 1; i < argc; i++) + if (strcmp(argv[i], "%d") == 0) + argv[i] = devname; + + printf("Executing "); + for (i = 0; i < argc; i++) + printf("%s%s", (i == 0) ? "\"" : " ", argv[i]); + printf("\"\n"); + + execvp(argv[0], argv); + + close(fd); +} + static void cmd_create(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) { if (strcmp(argv[0], "all") == 0) @@ -393,8 +509,9 @@ struct { } command[] = { { "bind", "create", cmd_create, " [channel]", "Bind device" }, { "release", "unbind", cmd_release, "", "Release device" }, + { "show", "info", cmd_show, "", "Show device" }, { "connect", "conn", cmd_connect, " [channel]", "Connect device" }, - { "show", "info", cmd_show, 0, "Show device" }, + { "listen", "server", cmd_listen, " [channel]", "Listen" }, { NULL, NULL, NULL, 0, 0 } }; @@ -447,7 +564,7 @@ int main(int argc, char *argv[]) else str2ba(optarg, &bdaddr); break; - + case 'f': rfcomm_config_file = strdup(optarg); break; @@ -483,7 +600,9 @@ int main(int argc, char *argv[]) exit(0); } - if (strncmp(argv[1], "rfcomm", 6) == 0) + if (strncmp(argv[1], "/dev/rfcomm", 11) == 0) + dev_id = atoi(argv[1] + 11); + else if (strncmp(argv[1], "rfcomm", 6) == 0) dev_id = atoi(argv[1] + 6); else dev_id = atoi(argv[1]); -- cgit From 9d2bce555fcd594df420b39d67f0d4bec313e46f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 18 Jan 2003 15:52:33 +0000 Subject: Update of the copyright statement --- rfcomm/kword.c | 2 +- rfcomm/kword.h | 2 +- rfcomm/lexer.l | 2 +- rfcomm/parser.y | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/kword.c b/rfcomm/kword.c index 3cb9f2c6..f0aaed4f 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -2,7 +2,7 @@ * * RFCOMM configuration utility * - * Copyright (C) 2002 Marcel Holtmann + * Copyright (C) 2002-2003 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/kword.h b/rfcomm/kword.h index dddd2a83..f8e4210e 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -2,7 +2,7 @@ * * RFCOMM configuration utility * - * Copyright (C) 2002 Marcel Holtmann + * Copyright (C) 2002-2003 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index 0f64cb43..46b76d13 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -3,7 +3,7 @@ * * RFCOMM configuration utility * - * Copyright (C) 2002 Marcel Holtmann + * Copyright (C) 2002-2003 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/parser.y b/rfcomm/parser.y index 5a42b2f1..3775de95 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -3,7 +3,7 @@ * * RFCOMM configuration utility * - * Copyright (C) 2002 Marcel Holtmann + * Copyright (C) 2002-2003 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 0c19759d355a83b63158c66d5f601be816f90424 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 18 Jan 2003 20:15:45 +0000 Subject: Update of the listen command --- rfcomm/main.c | 77 ++++++++++++++++++++++++++++++--------------------------- rfcomm/rfcomm.1 | 7 +++++- 2 files changed, 47 insertions(+), 37 deletions(-) (limited to 'rfcomm') 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 " " Display the information about the specified device. .TP -.BI conn " [bdaddr] [channel]" +.BI connect " [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 " [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 " [bdaddr] [channel]" This binds the RFCOMM device to a remote Bluetooth device. The -- cgit From a9ea91fd12bfac8dfb529911c56e062cd2abc34b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 18 Feb 2003 06:04:55 +0000 Subject: Allow rfcomm.conf without entries --- rfcomm/parser.y | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/parser.y b/rfcomm/parser.y index 3775de95..f7ee3d70 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -59,7 +59,9 @@ struct rfcomm_opts *opts; %% -config : statement | config statement +config : + | statement + | config statement ; statement : section '{' rfcomm_options '}' -- cgit From e9c06d166a352ee2e9b037397f4fb4ba1c8c43f2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 15 Apr 2003 19:20:58 +0000 Subject: Use the bind option in the config file --- rfcomm/main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index b0df9c72..17cb14b6 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -185,6 +185,9 @@ static int create_all(int ctl) } for (i = 0; i < RFCOMM_MAX_DEV; i++) { + if (!rfcomm_opts[i].bind) + continue; + memset(&req, 0, sizeof(req)); req.dev_id = i; req.flags = 0; -- cgit From 9d6d2bae4f2598f97863568b327e4b57ae8db0bd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 15 Apr 2003 19:30:47 +0000 Subject: Update of the man page --- rfcomm/rfcomm.1 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1 index 0a0f48a0..4085e5ec 100644 --- a/rfcomm/rfcomm.1 +++ b/rfcomm/rfcomm.1 @@ -72,11 +72,25 @@ This command can be terminated with the key sequence CTRL-C. .BI bind " [bdaddr] [channel]" This binds the RFCOMM device to a remote Bluetooth device. The command did not establish a connection to the remote device, it -only creates the binding. The connection will be establish right -after an application tries to open the RFCOMM device. +only creates the binding. The connection will be established right +after an application tries to open the RFCOMM device. If no channel +number is specified, it uses the channel number 1. If the Bluetooth +address is also left out, it tries to read the data from the config +file. + +If +.B all +is specified for the RFCOMM device, then all devices that have +.B "bind yes" +set in the config will be bound. .TP .BI release " " This command releases a defined RFCOMM binding. + +If +.B all +is specified for the RFCOMM device, then all bindings will be removed. +This command didn't care about the settings in the config file. .SH AUTHOR Written by Marcel Holtmann . .br -- cgit From 1854d87540f35ec18ed8adc5464c6e55aa906978 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 18 Jul 2003 09:25:50 +0000 Subject: Honor the setting of --sysconfdir --- rfcomm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 72635ff2..aa0c5462 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -3,7 +3,7 @@ # mandir = $(prefix)/usr/share/man -confdir = /etc/bluetooth +confdir = $(sysconfdir)/bluetooth bin_PROGRAMS = rfcomm -- cgit From a3607755c836532a6a6e3cb8acc911b8cf2b61da Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 13 Mar 2004 12:31:29 +0000 Subject: Give udev some time to create the RFCOMM device nodes --- rfcomm/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 17cb14b6..68396b5e 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -250,7 +250,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg struct sigaction sa; struct pollfd p; char dst[18], devname[MAXPATHLEN]; - int sk, fd, alen; + int sk, fd, alen, try = 3; laddr.rc_family = AF_BLUETOOTH; bacpy(&laddr.rc_bdaddr, bdaddr); @@ -270,7 +270,6 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg fprintf(stderr, "Can't find a config entry for rfcomm%d\n", dev); return; } - } else { raddr.rc_family = AF_BLUETOOTH; str2ba(argv[1], &raddr.rc_bdaddr); @@ -322,7 +321,11 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); - if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + if (try--) { + sleep(1); + continue; + } perror("Can't open RFCOMM device"); close(sk); return; @@ -377,7 +380,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv struct sigaction sa; struct pollfd p; char dst[18], devname[MAXPATHLEN]; - int sk, nsk, fd, alen; + int sk, nsk, fd, alen, try = 3; laddr.rc_family = AF_BLUETOOTH; bacpy(&laddr.rc_bdaddr, bdaddr); @@ -425,7 +428,11 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); - if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + if (try--) { + sleep(1); + continue; + } perror("Can't open RFCOMM device"); close(sk); return; -- cgit From b4e62d0942cc975be9f427d444231d5f104c87d0 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 1 Apr 2004 21:19:18 +0000 Subject: Change default prefix to /usr --- rfcomm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index aa0c5462..262dbc4c 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -2,7 +2,7 @@ # $Id$ # -mandir = $(prefix)/usr/share/man +mandir = $(prefix)/share/man confdir = $(sysconfdir)/bluetooth bin_PROGRAMS = rfcomm -- cgit From 719873a6b8d26c78b0a9a2380647e83c8e4bc05c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 2 Apr 2004 00:08:19 +0000 Subject: Modifying $mandir is no longer needed --- rfcomm/Makefile.am | 1 - 1 file changed, 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 262dbc4c..f525fc4f 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -2,7 +2,6 @@ # $Id$ # -mandir = $(prefix)/share/man confdir = $(sysconfdir)/bluetooth bin_PROGRAMS = rfcomm -- cgit From 1d3715db11f573060cb02a2b7b7c44f06607d337 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 3 Apr 2004 06:04:35 +0000 Subject: Update BlueZ library configuration --- rfcomm/Makefile.am | 4 ++++ rfcomm/main.c | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index f525fc4f..980b0900 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -9,6 +9,10 @@ bin_PROGRAMS = rfcomm rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c rfcomm_CONFIG = rfcomm.conf +LDFLAGS = @BLUEZ_LIBS@ + +INCLUDES = @BLUEZ_INCLUDES@ + man_MANS = rfcomm.1 YFLAGS = -d diff --git a/rfcomm/main.c b/rfcomm/main.c index 68396b5e..52701d40 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -21,6 +21,10 @@ * */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include -- cgit From fb022821661f5cc051061fe01818d58bad4cfd06 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 9 Apr 2004 15:37:46 +0000 Subject: Try to release the TTY if no device node is found --- rfcomm/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 52701d40..5d061fb7 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -323,14 +323,21 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg } snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); - if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); - while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (try--) { + snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); sleep(1); continue; } perror("Can't open RFCOMM device"); + + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = (1 << RFCOMM_HANGUP_NOW); + ioctl(ctl, RFCOMMRELEASEDEV, &req); + close(sk); return; } -- cgit From b66d3f9b2cb8934a0eb7ac07f347001984488ac6 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 28 Apr 2004 10:39:47 +0000 Subject: Unify copyright and license information --- rfcomm/kword.c | 33 +++++++++++++++++++++------------ rfcomm/kword.h | 31 +++++++++++++++++-------------- rfcomm/lexer.l | 33 +++++++++++++++++++++------------ rfcomm/main.c | 31 ++++++++++++++++++------------- rfcomm/parser.y | 37 +++++++++++++++++++++++-------------- 5 files changed, 100 insertions(+), 65 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/kword.c b/rfcomm/kword.c index f0aaed4f..0747eef3 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -1,26 +1,35 @@ /* * - * RFCOMM configuration utility + * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2003 Marcel Holtmann + * Copyright (C) 2002-2004 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. * + * + * $Id$ */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include diff --git a/rfcomm/kword.h b/rfcomm/kword.h index f8e4210e..c0acd946 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -1,29 +1,33 @@ /* * - * RFCOMM configuration utility + * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2003 Marcel Holtmann + * Copyright (C) 2002-2004 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. * + * + * $Id$ */ extern int lineno; - struct keyword_t { char *string; int type; @@ -33,7 +37,6 @@ extern struct keyword_t rfcomm_keyword[]; int rfcomm_find_keyword(struct keyword_t *keyword, char *string); - #define MAXCOMMENTLEN 100 struct rfcomm_opts { diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index 46b76d13..89c41828 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -1,27 +1,36 @@ %{ /* * - * RFCOMM configuration utility + * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2003 Marcel Holtmann + * Copyright (C) 2002-2004 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. * + * + * $Id$ */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include diff --git a/rfcomm/main.c b/rfcomm/main.c index 5d061fb7..dbb74869 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -1,24 +1,29 @@ /* * - * RFCOMM configuration utility + * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2003 Marcel Holtmann + * Copyright (C) 2002-2004 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. * + * + * $Id$ */ #ifdef HAVE_CONFIG_H @@ -554,7 +559,7 @@ static void usage(void) "\n"); printf("Commands:\n"); - for (i = 0; command[i].cmd; i++) + for (i = 0; command[i].cmd; i++) printf("\t%-8s %-24s\t%s\n", command[i].cmd, command[i].opt ? command[i].opt : " ", diff --git a/rfcomm/parser.y b/rfcomm/parser.y index f7ee3d70..58bc74c0 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -1,27 +1,36 @@ %{ /* * - * RFCOMM configuration utility + * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2003 Marcel Holtmann + * Copyright (C) 2002-2004 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY + * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, + * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS + * SOFTWARE IS DISCLAIMED. * + * + * $Id$ */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -162,6 +171,6 @@ int rfcomm_read_config(char *filename) yyparse(); fclose(yyin); - - return 0; + + return 0; } -- cgit From c337593d343e7320332557ba9137561eefabf22e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 9 May 2004 09:35:52 +0000 Subject: Fix TTY creation problem for listen command --- rfcomm/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index dbb74869..3a7fe0a5 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -442,14 +442,21 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv } snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); - if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); - while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (try--) { + snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); sleep(1); continue; } perror("Can't open RFCOMM device"); + + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = (1 << RFCOMM_HANGUP_NOW); + ioctl(ctl, RFCOMMRELEASEDEV, &req); + close(sk); return; } -- cgit From 7ac6ede99ac309c7e28f3c2993fbc9bbbe28a68b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 23 May 2004 10:39:50 +0000 Subject: Use LIBS instead of LDFLAGS --- rfcomm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 980b0900..b1386b02 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -9,7 +9,7 @@ bin_PROGRAMS = rfcomm rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c rfcomm_CONFIG = rfcomm.conf -LDFLAGS = @BLUEZ_LIBS@ +LIBS = @BLUEZ_LIBS@ INCLUDES = @BLUEZ_INCLUDES@ -- cgit From 495521cf00684b398eaf69a9bb542d85404a108e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 7 Jul 2004 16:34:47 +0000 Subject: Make use of AM_YFLAGS --- rfcomm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index b1386b02..a300fcbd 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -15,7 +15,7 @@ INCLUDES = @BLUEZ_INCLUDES@ man_MANS = rfcomm.1 -YFLAGS = -d +AM_YFLAGS = -d CLEANFILES = lexer.c parser.c parser.h -- cgit From 43f017c9527dd4f64670831114f3c85f5defebbd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 21 Jul 2004 15:05:27 +0000 Subject: Use AM_CFLAGS instead of INCLUDES --- rfcomm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index a300fcbd..ddccca30 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -11,7 +11,7 @@ rfcomm_CONFIG = rfcomm.conf LIBS = @BLUEZ_LIBS@ -INCLUDES = @BLUEZ_INCLUDES@ +AM_CFLAGS = @BLUEZ_CFLAGS@ man_MANS = rfcomm.1 -- cgit From 15c1cf1ca0d2fc45dff471d71339db49deecd1cd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 21 Jul 2004 15:20:28 +0000 Subject: Make use of MAINTAINERCLEANFILES --- rfcomm/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index ddccca30..dd7f4082 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -21,6 +21,8 @@ CLEANFILES = lexer.c parser.c parser.h EXTRA_DIST = $(man_MANS) $(rfcomm_CONFIG) +MAINTAINERCLEANFILES = Makefile.in + install-data-local: $(mkinstalldirs) $(DESTDIR)$(confdir) [ -f $(DESTDIR)$(confdir)/$(rfcomm_CONFIG) ] || \ -- cgit From c37be1ab2480c43fdaec098f75ec5e25a65ceb59 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 27 Jul 2004 13:01:42 +0000 Subject: Make more parts optional --- rfcomm/Makefile.am | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index dd7f4082..bedb07f6 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -4,10 +4,11 @@ confdir = $(sysconfdir)/bluetooth +conf_DATA = rfcomm.conf + bin_PROGRAMS = rfcomm rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c -rfcomm_CONFIG = rfcomm.conf LIBS = @BLUEZ_LIBS@ @@ -19,11 +20,6 @@ AM_YFLAGS = -d CLEANFILES = lexer.c parser.c parser.h -EXTRA_DIST = $(man_MANS) $(rfcomm_CONFIG) +EXTRA_DIST = $(man_MANS) $(conf_DATA) MAINTAINERCLEANFILES = Makefile.in - -install-data-local: - $(mkinstalldirs) $(DESTDIR)$(confdir) - [ -f $(DESTDIR)$(confdir)/$(rfcomm_CONFIG) ] || \ - $(INSTALL_DATA) $(srcdir)/$(rfcomm_CONFIG) $(DESTDIR)$(confdir)/$(rfcomm_CONFIG) -- cgit From 71e6fca1e290bee72853bea6ea3768879d4510a7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 9 Aug 2004 08:01:36 +0000 Subject: Make use of CONFIGDIR --- rfcomm/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/parser.y b/rfcomm/parser.y index 58bc74c0..1d5f9024 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -161,7 +161,7 @@ int rfcomm_read_config(char *filename) snprintf(file, MAXPATHLEN, "%s/.bluetooth/rfcomm.conf", getenv("HOME")); if ((getuid() == 0) || (access(file, R_OK) < 0)) - snprintf(file, MAXPATHLEN, "/etc/bluetooth/rfcomm.conf"); + snprintf(file, MAXPATHLEN, "%s/rfcomm.conf", CONFIGDIR); } if (!(yyin = fopen(file, "r"))) -- cgit From 338653545090b72df3e97610ce8dc9b6f1a4e6d4 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 21 Nov 2004 16:56:03 +0000 Subject: Fix a bug when connected to a device from the config file --- rfcomm/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 3a7fe0a5..86331b9d 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -275,7 +275,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg bacpy(&raddr.rc_bdaddr, &rfcomm_opts[dev].bdaddr); raddr.rc_channel = rfcomm_opts[dev].channel; - if (bacmp(&req.dst, BDADDR_ANY) == 0) { + if (bacmp(&raddr.rc_bdaddr, BDADDR_ANY) == 0) { fprintf(stderr, "Can't find a config entry for rfcomm%d\n", dev); return; } -- cgit From adbb22a47c9356e0c191a75daec0439e8d941bd1 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 21 Apr 2005 21:34:08 +0000 Subject: Use LDADD instead of LIBS --- rfcomm/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index bedb07f6..65a5af53 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -9,8 +9,7 @@ conf_DATA = rfcomm.conf bin_PROGRAMS = rfcomm rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c - -LIBS = @BLUEZ_LIBS@ +rfcomm_LDADD = @BLUEZ_LIBS@ AM_CFLAGS = @BLUEZ_CFLAGS@ -- cgit From 1f422e5f2b343d35a8c77ce4be16f74b2819b2bf Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 5 Jul 2005 21:15:41 +0000 Subject: Fix some GCC 4.0 warnings --- rfcomm/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 86331b9d..decabcc6 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -258,8 +258,9 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg struct termios ti; struct sigaction sa; struct pollfd p; + socklen_t alen; char dst[18], devname[MAXPATHLEN]; - int sk, fd, alen, try = 3; + int sk, fd, try = 3; laddr.rc_family = AF_BLUETOOTH; bacpy(&laddr.rc_bdaddr, bdaddr); @@ -395,8 +396,9 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv struct termios ti; struct sigaction sa; struct pollfd p; + socklen_t alen; char dst[18], devname[MAXPATHLEN]; - int sk, nsk, fd, alen, try = 3; + int sk, nsk, fd, try = 3; laddr.rc_family = AF_BLUETOOTH; bacpy(&laddr.rc_bdaddr, bdaddr); -- cgit From 632a9432774ff3a0c6e556e8f32a565b38890767 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 29 Oct 2005 22:36:31 +0000 Subject: Big cleanup of CVS relics --- rfcomm/Makefile.am | 3 --- rfcomm/kword.c | 28 ++++++++++++---------------- rfcomm/kword.h | 27 +++++++++++---------------- rfcomm/lexer.l | 28 ++++++++++++---------------- rfcomm/main.c | 33 ++++++++++++++------------------- rfcomm/parser.y | 30 +++++++++++++----------------- rfcomm/rfcomm.conf | 2 -- 7 files changed, 62 insertions(+), 89 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 65a5af53..bda4a13f 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -1,6 +1,3 @@ -# -# $Id$ -# confdir = $(sysconfdir)/bluetooth diff --git a/rfcomm/kword.c b/rfcomm/kword.c index 0747eef3..578a8435 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -2,28 +2,23 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2004 Marcel Holtmann + * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY - * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, - * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS - * SOFTWARE IS DISCLAIMED. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * - * $Id$ */ #ifdef HAVE_CONFIG_H @@ -31,6 +26,7 @@ #endif #include +#include #include #include diff --git a/rfcomm/kword.h b/rfcomm/kword.h index c0acd946..9247e1aa 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -2,28 +2,23 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2004 Marcel Holtmann + * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY - * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, - * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS - * SOFTWARE IS DISCLAIMED. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * - * $Id$ */ extern int lineno; diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index 89c41828..fb0b5e04 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -3,28 +3,23 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2004 Marcel Holtmann + * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY - * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, - * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS - * SOFTWARE IS DISCLAIMED. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * - * $Id$ */ #ifdef HAVE_CONFIG_H @@ -32,6 +27,7 @@ #endif #include +#include #include #include diff --git a/rfcomm/main.c b/rfcomm/main.c index decabcc6..48c09682 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -2,28 +2,23 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2004 Marcel Holtmann + * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY - * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, - * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS - * SOFTWARE IS DISCLAIMED. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * - * $Id$ */ #ifdef HAVE_CONFIG_H @@ -31,14 +26,14 @@ #endif #include -#include +#include +#include #include +#include #include #include #include #include -#include -#include #include #include #include diff --git a/rfcomm/parser.y b/rfcomm/parser.y index 1d5f9024..c0e3eda7 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -3,28 +3,23 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2004 Marcel Holtmann + * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY - * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, - * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS - * SOFTWARE IS DISCLAIMED. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * - * $Id$ */ #ifdef HAVE_CONFIG_H @@ -32,8 +27,9 @@ #endif #include -#include +#include #include +#include #include #include #include diff --git a/rfcomm/rfcomm.conf b/rfcomm/rfcomm.conf index c1b10cd5..d5e81ed1 100644 --- a/rfcomm/rfcomm.conf +++ b/rfcomm/rfcomm.conf @@ -1,8 +1,6 @@ # # RFCOMM configuration file. # -# $Id$ -# rfcomm0 { # Automatically bind the device at startup -- cgit From f2e48c44a7e4c9ee31b8ce2e302186f6047cfeab Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 3 Jan 2006 13:28:56 +0000 Subject: Update copyright information --- rfcomm/kword.c | 2 +- rfcomm/kword.h | 2 +- rfcomm/lexer.l | 2 +- rfcomm/main.c | 2 +- rfcomm/parser.y | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/kword.c b/rfcomm/kword.c index 578a8435..c0d3583d 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2005 Marcel Holtmann + * Copyright (C) 2002-2006 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/kword.h b/rfcomm/kword.h index 9247e1aa..013b9c86 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2005 Marcel Holtmann + * Copyright (C) 2002-2006 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index fb0b5e04..1a95e1b2 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -3,7 +3,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2005 Marcel Holtmann + * Copyright (C) 2002-2006 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/main.c b/rfcomm/main.c index 48c09682..d4ed9a48 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2005 Marcel Holtmann + * Copyright (C) 2002-2006 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/parser.y b/rfcomm/parser.y index c0e3eda7..e22e3ef1 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -3,7 +3,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2005 Marcel Holtmann + * Copyright (C) 2002-2006 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 044d91ae4967861fbbd7b5f0b25860ee8c58f2ae Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 4 Jun 2006 13:17:37 +0000 Subject: Fix any command issue --- rfcomm/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index d4ed9a48..7294a363 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -621,8 +621,13 @@ int main(int argc, char *argv[]) argv += optind; optind = 0; - if (argc < 2) - show_all = 1; + if (argc < 2) { + if (argc != 0) { + usage(); + exit(1); + } else + show_all = 1; + } if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM)) < 0 ) { perror("Can't open RFCOMM control socket"); -- cgit From f6c34df1c7a053440af9816bf61904d8aca24ea2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 4 Jun 2006 15:45:42 +0000 Subject: Handle EOPNOTSUPP errors --- rfcomm/main.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 7294a363..db30dd66 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -150,7 +150,8 @@ static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int ar bacpy(&req.src, bdaddr); if (argc < 2) { - if ((err = rfcomm_read_config(rfcomm_config_file)) < 0) { + err = rfcomm_read_config(rfcomm_config_file); + if (err < 0) { perror("Can't open RFCOMM config file"); return err; } @@ -172,7 +173,10 @@ static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int ar req.channel = 1; } - if ((err = ioctl(ctl, RFCOMMCREATEDEV, &req)) < 0 ) + err = ioctl(ctl, RFCOMMCREATEDEV, &req); + if (err == EOPNOTSUPP) + fprintf(stderr, "RFCOMM TTY support not available\n"); + else if (err < 0) perror("Can't create device"); return err; @@ -183,7 +187,8 @@ static int create_all(int ctl) struct rfcomm_dev_req req; int i, err; - if ((err = rfcomm_read_config(rfcomm_config_file)) < 0) { + err = rfcomm_read_config(rfcomm_config_file); + if (err < 0) { perror("Can't open RFCOMM config file"); return err; } @@ -214,7 +219,8 @@ static int release_dev(int ctl, int dev, uint32_t flags) memset(&req, 0, sizeof(req)); req.dev_id = dev; - if ((err = ioctl(ctl, RFCOMMRELEASEDEV, &req)) < 0 ) + err = ioctl(ctl, RFCOMMRELEASEDEV, &req); + if (err < 0) perror("Can't release device"); return err; @@ -285,7 +291,8 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg raddr.rc_channel = 1; } - if ((sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { + sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + if (sk < 0) { perror("Can't create RFCOMM socket"); return; } @@ -317,7 +324,8 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg bacpy(&req.dst, &raddr.rc_bdaddr); req.channel = raddr.rc_channel; - if ((dev = ioctl(sk, RFCOMMCREATEDEV, &req)) < 0) { + dev = ioctl(sk, RFCOMMCREATEDEV, &req); + if (dev < 0) { perror("Can't create RFCOMM TTY"); close(sk); return; @@ -399,7 +407,8 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv bacpy(&laddr.rc_bdaddr, bdaddr); laddr.rc_channel = (argc < 2) ? 1 : atoi(argv[1]); - if ((sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { + sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + if (sk < 0) { perror("Can't create RFCOMM socket"); return; } @@ -432,7 +441,8 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv bacpy(&req.dst, &raddr.rc_bdaddr); req.channel = raddr.rc_channel; - if ((dev = ioctl(nsk, RFCOMMCREATEDEV, &req)) < 0) { + dev = ioctl(nsk, RFCOMMCREATEDEV, &req); + if (dev < 0) { perror("Can't create RFCOMM TTY"); close(sk); return; @@ -629,7 +639,8 @@ int main(int argc, char *argv[]) show_all = 1; } - if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM)) < 0 ) { + ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM); + if (ctl < 0) { perror("Can't open RFCOMM control socket"); exit(1); } -- cgit From be06891a834058b45fdc89c8a939c07fe4c23527 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 6 Jul 2006 09:31:03 +0000 Subject: Sleep only 100 msecs for device detection --- rfcomm/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index db30dd66..1d302a98 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -261,7 +261,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg struct pollfd p; socklen_t alen; char dst[18], devname[MAXPATHLEN]; - int sk, fd, try = 3; + int sk, fd, try = 30; laddr.rc_family = AF_BLUETOOTH; bacpy(&laddr.rc_bdaddr, bdaddr); @@ -337,7 +337,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (try--) { snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); - sleep(1); + usleep(100); continue; } perror("Can't open RFCOMM device"); @@ -401,7 +401,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv struct pollfd p; socklen_t alen; char dst[18], devname[MAXPATHLEN]; - int sk, nsk, fd, try = 3; + int sk, nsk, fd, try = 30; laddr.rc_family = AF_BLUETOOTH; bacpy(&laddr.rc_bdaddr, bdaddr); @@ -454,7 +454,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (try--) { snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); - sleep(1); + usleep(100); continue; } perror("Can't open RFCOMM device"); -- cgit From 49ddeb81d3609370ccc66397efc81bb9f590e2ed Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 10 Aug 2006 09:48:13 +0000 Subject: List all available options --- rfcomm/main.c | 8 +++++--- rfcomm/rfcomm.1 | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 1d302a98..e7a381fc 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -567,9 +567,11 @@ static void usage(void) "\n"); printf("Options:\n" - "\t-i [hciX|bdaddr] Local HCI device or BD Address\n" - "\t-h, --help Display help\n" - "\t-a Show all devices (default)\n" + "\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-f, --config [file] Specify alternate config file\n" + "\t-a Show all devices (default)\n" "\n"); printf("Commands:\n"); diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1 index 4085e5ec..d1e11cf9 100644 --- a/rfcomm/rfcomm.1 +++ b/rfcomm/rfcomm.1 @@ -45,6 +45,12 @@ Gives a list of possible commands. .BI -a Prints information about all configured RFCOMM devices. .TP +.BI -r +Switch TTY into raw mode (doesn't work with "bind"). +.TP +.BI -f " [file]" +Specify alternate config file. +.TP .BI -i " | " The command is applied to device .I -- cgit From b3c1c09bb8e8e3d6ed84908f9831ac30d59ef4d2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 10 Aug 2006 10:03:56 +0000 Subject: Comment out example config entry --- rfcomm/rfcomm.conf | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/rfcomm.conf b/rfcomm/rfcomm.conf index d5e81ed1..6179ef7b 100644 --- a/rfcomm/rfcomm.conf +++ b/rfcomm/rfcomm.conf @@ -2,16 +2,16 @@ # RFCOMM configuration file. # -rfcomm0 { - # Automatically bind the device at startup - bind no; - - # Bluetooth address of the device - device 11:22:33:44:55:66; - - # RFCOMM channel for the connection - channel 1; - - # Description of the connection - comment "Example Bluetooth device"; -} +#rfcomm0 { +# # Automatically bind the device at startup +# bind no; +# +# # Bluetooth address of the device +# device 11:22:33:44:55:66; +# +# # RFCOMM channel for the connection +# channel 1; +# +# # Description of the connection +# comment "Example Bluetooth device"; +#} -- cgit From 35e9349ffc53950c4b78fba9537a50cdb6e5fd7a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 10 Aug 2006 10:20:59 +0000 Subject: Change default poll() timeout --- rfcomm/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index e7a381fc..43d52e61 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -383,7 +383,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg while (!__io_canceled) { p.revents = 0; - if (poll(&p, 1, 100)) + if (poll(&p, 1, 500)) break; } @@ -501,7 +501,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv while (!__io_canceled) { p.revents = 0; - if (poll(&p, 1, 100)) + if (poll(&p, 1, 500)) break; } -- cgit From a1bc48d15a5d6e78efe744eb7b27b6421cb7222f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 16 Aug 2006 10:54:06 +0000 Subject: Convert to using ppoll() and pselect() --- rfcomm/Makefile.am | 2 ++ rfcomm/main.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index bda4a13f..8e883540 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -10,6 +10,8 @@ rfcomm_LDADD = @BLUEZ_LIBS@ AM_CFLAGS = @BLUEZ_CFLAGS@ +INCLUDES = -I$(top_srcdir)/common + man_MANS = rfcomm.1 AM_YFLAGS = -d diff --git a/rfcomm/main.c b/rfcomm/main.c index 43d52e61..5167d497 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -25,6 +25,7 @@ #include #endif +#define _GNU_SOURCE #include #include #include @@ -47,6 +48,10 @@ #include "kword.h" +#ifdef NEED_PPOLL +#include "ppoll.h" +#endif + static char *rfcomm_config_file = NULL; static int rfcomm_raw_tty = 0; @@ -259,6 +264,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg struct termios ti; struct sigaction sa; struct pollfd p; + sigset_t sigs; socklen_t alen; char dst[18], devname[MAXPATHLEN]; int sk, fd, try = 30; @@ -378,12 +384,14 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); + sigfillset(&sigs); + p.fd = fd; p.events = POLLERR | POLLHUP; while (!__io_canceled) { p.revents = 0; - if (poll(&p, 1, 500)) + if (ppoll(&p, 1, NULL, &sigs) > 0) break; } @@ -399,6 +407,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv struct termios ti; struct sigaction sa; struct pollfd p; + sigset_t sigs; socklen_t alen; char dst[18], devname[MAXPATHLEN]; int sk, nsk, fd, try = 30; @@ -496,12 +505,14 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); + sigfillset(&sigs); + p.fd = fd; p.events = POLLERR | POLLHUP; while (!__io_canceled) { p.revents = 0; - if (poll(&p, 1, 500)) + if (ppoll(&p, 1, NULL, &sigs) > 0) break; } -- cgit From 73b9315e56f5f635eaf82a08271e8f462b731972 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 16 Aug 2006 11:44:52 +0000 Subject: Don't forget to unblock signals for ppoll() --- rfcomm/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 5167d497..9baf8533 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -385,6 +385,11 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg sigaction(SIGHUP, &sa, NULL); sigfillset(&sigs); + sigdelset(&sigs, SIGCHLD); + sigdelset(&sigs, SIGPIPE); + sigdelset(&sigs, SIGTERM); + sigdelset(&sigs, SIGINT); + sigdelset(&sigs, SIGHUP); p.fd = fd; p.events = POLLERR | POLLHUP; @@ -506,6 +511,11 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv sigaction(SIGHUP, &sa, NULL); sigfillset(&sigs); + sigdelset(&sigs, SIGCHLD); + sigdelset(&sigs, SIGPIPE); + sigdelset(&sigs, SIGTERM); + sigdelset(&sigs, SIGINT); + sigdelset(&sigs, SIGHUP); p.fd = fd; p.events = POLLERR | POLLHUP; -- cgit From 3d6f08cb24a31bf76cb3e934dddbc1f8d52d4c94 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 1 Sep 2006 00:20:45 +0000 Subject: Add option to disable installation of config files --- rfcomm/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 8e883540..a1a97b8a 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -1,7 +1,9 @@ +if CONFIGFILES confdir = $(sysconfdir)/bluetooth conf_DATA = rfcomm.conf +endif bin_PROGRAMS = rfcomm @@ -18,6 +20,6 @@ AM_YFLAGS = -d CLEANFILES = lexer.c parser.c parser.h -EXTRA_DIST = $(man_MANS) $(conf_DATA) +EXTRA_DIST = $(man_MANS) rfcomm.conf MAINTAINERCLEANFILES = Makefile.in -- cgit From f64cc95873c872ad5a34abe6418a2e26570d5d02 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 10 Nov 2006 23:09:02 +0000 Subject: Allow running a command after successful connection creation --- rfcomm/main.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 6 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 9baf8533..efffcc9a 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -257,6 +258,56 @@ static int release_all(int ctl) return 0; } +static void run_cmdline(struct pollfd *p, sigset_t* sigs, char *devname, + int argc, char **argv) +{ + int i = 0; + pid_t pid, child; + struct timespec ts; + int status = 0; + char **cmdargv; + + cmdargv = malloc((argc + 1) * sizeof(char*)); + if (!cmdargv) + return; + + for (i = 0; i < argc; i++) + cmdargv[i] = (strcmp(argv[i], "{}") == 0) ? devname : argv[i]; + cmdargv[i] = NULL; + + pid = fork(); + + switch (pid) { + case 0: + i = execvp(cmdargv[0], cmdargv); + fprintf(stderr, "Couldn't execute command %s (errno=%d:%s)\n", + cmdargv[0], errno, strerror(errno)); + break; + case -1: + fprintf(stderr, "Couldn't fork to execute command %s\n", + cmdargv[0]); + break; + default: + while (1) { + child = waitpid(-1, &status, WNOHANG); + if (child == pid || (child < 0 && errno != EAGAIN)) + break; + + p->revents = 0; + ts.tv_sec = 0; + ts.tv_nsec = 200; + if (ppoll(p, 1, &ts, sigs) || __io_canceled) { + kill(pid, SIGTERM); + waitpid(pid, &status, 0); + break; + } + } + break; + } + + free(cmdargv); +} + static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) { struct sockaddr_rc laddr, raddr; @@ -520,17 +571,32 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv p.fd = fd; p.events = POLLERR | POLLHUP; - while (!__io_canceled) { - p.revents = 0; - if (ppoll(&p, 1, NULL, &sigs) > 0) - break; - } + if (argc <= 2) { + while (!__io_canceled) { + p.revents = 0; + if (ppoll(&p, 1, NULL, &sigs) > 0) + break; + } + } else + run_cmdline(&p, &sigs, devname, argc - 2, argv + 2); + + sa.sa_handler = NULL; + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, NULL); printf("Disconnected\n"); close(fd); } +static void cmd_watch(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) +{ + while (!__io_canceled) { + cmd_listen(ctl, dev, bdaddr, argc, argv); + usleep(10000); + } +} + static void cmd_create(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) { if (strcmp(argv[0], "all") == 0) @@ -573,7 +639,8 @@ struct { { "release", "unbind", cmd_release, "", "Release device" }, { "show", "info", cmd_show, "", "Show device" }, { "connect", "conn", cmd_connect, " [channel]", "Connect device" }, - { "listen", "server", cmd_listen, " [channel]", "Listen" }, + { "listen", "server", cmd_listen, " [channel [cmd]]", "Listen" }, + { "watch", "watch", cmd_watch, " [channel [cmd]]", "Watch" }, { NULL, NULL, NULL, 0, 0 } }; -- cgit From cd3839f1d911767db77d1383e2ac1b1df405bed2 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 10 Nov 2006 23:18:53 +0000 Subject: Cleanup of rfcomm exec command patch --- rfcomm/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index efffcc9a..7e42b910 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -261,10 +261,8 @@ static int release_all(int ctl) static void run_cmdline(struct pollfd *p, sigset_t* sigs, char *devname, int argc, char **argv) { - int i = 0; - pid_t pid, child; - struct timespec ts; - int status = 0; + int i; + pid_t pid; char **cmdargv; cmdargv = malloc((argc + 1) * sizeof(char*)); @@ -289,6 +287,10 @@ static void run_cmdline(struct pollfd *p, sigset_t* sigs, char *devname, break; default: while (1) { + int status; + pid_t child; + struct timespec ts; + child = waitpid(-1, &status, WNOHANG); if (child == pid || (child < 0 && errno != EAGAIN)) break; -- cgit From 489d06626b3c3497ae13281713b7ee4fb06524b8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 20 Nov 2006 11:21:21 +0000 Subject: Fix dependency for concurrent builds --- rfcomm/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index a1a97b8a..7fe2d743 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -14,6 +14,8 @@ AM_CFLAGS = @BLUEZ_CFLAGS@ INCLUDES = -I$(top_srcdir)/common +BUILT_SOURCES = parser.h + man_MANS = rfcomm.1 AM_YFLAGS = -d -- cgit From ef7fc3ba8e140d4b05a158e90d57b673f8b82199 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 24 Dec 2006 13:49:04 +0000 Subject: Add authentication, encryption and role switch options --- rfcomm/main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ rfcomm/rfcomm.1 | 30 +++++++++++++++++++++++++++--- 2 files changed, 73 insertions(+), 9 deletions(-) (limited to 'rfcomm') 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 " " @@ -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 " [channel]" +.BI listen " [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 " [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 " [bdaddr] [channel]" This binds the RFCOMM device to a remote Bluetooth device. The -- cgit From 607695ed109340f4b7a5628420e0a8e8aee34f4e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 13 Jan 2007 17:48:12 +0000 Subject: Update copyright information --- rfcomm/kword.c | 2 +- rfcomm/kword.h | 2 +- rfcomm/lexer.l | 2 +- rfcomm/main.c | 2 +- rfcomm/parser.y | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/kword.c b/rfcomm/kword.c index c0d3583d..2108fe4e 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2006 Marcel Holtmann + * Copyright (C) 2002-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/kword.h b/rfcomm/kword.h index 013b9c86..dfcc60f0 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2006 Marcel Holtmann + * Copyright (C) 2002-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index 1a95e1b2..70e1be81 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -3,7 +3,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2006 Marcel Holtmann + * Copyright (C) 2002-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/main.c b/rfcomm/main.c index f1897dd8..304c7134 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2006 Marcel Holtmann + * Copyright (C) 2002-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/parser.y b/rfcomm/parser.y index e22e3ef1..fe2cbe60 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -3,7 +3,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2006 Marcel Holtmann + * Copyright (C) 2002-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 4539df01941b46f707bd8ccf9d54ff6f288cae70 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 13 Feb 2007 20:41:55 +0000 Subject: Wait 30 * 100ms for udev to create the device node --- rfcomm/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 304c7134..b66bcdce 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -397,7 +397,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (try--) { snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); - usleep(100); + usleep(100 * 1000); continue; } perror("Can't open RFCOMM device"); -- cgit From b1b5f09d40dee0469e9fcbc79296838dbd487d55 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 21 Feb 2007 19:43:44 +0000 Subject: Include security parameters --- rfcomm/rfcomm.1 | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1 index f3744f12..47c98857 100644 --- a/rfcomm/rfcomm.1 +++ b/rfcomm/rfcomm.1 @@ -53,6 +53,14 @@ Specify alternate config file. .TP .BI -i " | " The command is applied to device +.BI -A +Enable authentication. +.BI -E +Enable encryption. +.BI -S +Secure connection. +.BI -M +Become the master of a piconet. .I hciX , which must be the name or the address of an installed Bluetooth -- cgit From 24795de83b9f2b24bd128707770387bcddad4367 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 27 Apr 2007 05:21:13 +0000 Subject: Fix the yyunput warning message --- rfcomm/lexer.l | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index 70e1be81..9988243f 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -44,6 +44,8 @@ int yyerror(char *str); %} +%option nounput + space [ \t] linebreak \n comment \#.*\n -- cgit From 68dc1b1a461792897e7be1cafb97b1f80e6aa304 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 14 May 2007 10:47:49 +0000 Subject: Make it possible to disable installation of manual pages --- rfcomm/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 7fe2d743..5eec05e8 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -16,12 +16,14 @@ INCLUDES = -I$(top_srcdir)/common BUILT_SOURCES = parser.h +if MANPAGES man_MANS = rfcomm.1 +endif AM_YFLAGS = -d CLEANFILES = lexer.c parser.c parser.h -EXTRA_DIST = $(man_MANS) rfcomm.conf +EXTRA_DIST = rfcomm.1 rfcomm.conf MAINTAINERCLEANFILES = Makefile.in -- cgit From 20c6b4ab406b9b3b2bf27098273b6175b910305c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 17 May 2007 13:39:30 +0000 Subject: Error out on access denied --- rfcomm/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index b66bcdce..8835967a 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -393,6 +393,18 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + if (errno == EACCES) { + perror("Can't open RFCOMM device"); + + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = (1 << RFCOMM_HANGUP_NOW); + ioctl(ctl, RFCOMMRELEASEDEV, &req); + + close(sk); + return; + } + snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (try--) { -- cgit From faee4dba3bef596dbc8735964b6577f9858ad7ef Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 17 May 2007 16:05:24 +0000 Subject: Make the EACCES path look nicer --- rfcomm/main.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 8835967a..80eaab56 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -395,14 +395,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (errno == EACCES) { perror("Can't open RFCOMM device"); - - memset(&req, 0, sizeof(req)); - req.dev_id = dev; - req.flags = (1 << RFCOMM_HANGUP_NOW); - ioctl(ctl, RFCOMMRELEASEDEV, &req); - - close(sk); - return; + goto release; } snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); @@ -413,14 +406,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg continue; } perror("Can't open RFCOMM device"); - - memset(&req, 0, sizeof(req)); - req.dev_id = dev; - req.flags = (1 << RFCOMM_HANGUP_NOW); - ioctl(ctl, RFCOMMRELEASEDEV, &req); - - close(sk); - return; + goto release; } } @@ -469,6 +455,15 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg printf("Disconnected\n"); close(fd); + return; + +release: + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = (1 << RFCOMM_HANGUP_NOW); + ioctl(ctl, RFCOMMRELEASEDEV, &req); + + close(sk); } static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) @@ -546,6 +541,11 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv snprintf(devname, MAXPATHLEN - 1, "/dev/rfcomm%d", dev); while ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { + if (errno == EACCES) { + perror("Can't open RFCOMM device"); + goto release; + } + snprintf(devname, MAXPATHLEN - 1, "/dev/bluetooth/rfcomm/%d", dev); if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) { if (try--) { @@ -554,14 +554,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv continue; } perror("Can't open RFCOMM device"); - - memset(&req, 0, sizeof(req)); - req.dev_id = dev; - req.flags = (1 << RFCOMM_HANGUP_NOW); - ioctl(ctl, RFCOMMRELEASEDEV, &req); - - close(sk); - return; + goto release; } } @@ -618,6 +611,15 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv printf("Disconnected\n"); close(fd); + return; + +release: + memset(&req, 0, sizeof(req)); + req.dev_id = dev; + req.flags = (1 << RFCOMM_HANGUP_NOW); + ioctl(ctl, RFCOMMRELEASEDEV, &req); + + close(sk); } static void cmd_watch(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) -- cgit From b9192f4232bd24394a0d22180d6a9e5900d2ea98 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 5 Jun 2007 09:38:05 +0000 Subject: Add support for linger timeout --- rfcomm/main.c | 38 +++++++++++++++++++++++++++++++------- rfcomm/rfcomm.1 | 5 ++++- 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index 80eaab56..e648c2d1 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -59,6 +59,7 @@ static int auth = 0; static int encryption = 0; static int secure = 0; static int master = 0; +static int linger = 0; static char *rfcomm_state[] = { "unknown", @@ -100,7 +101,7 @@ static char *rfcomm_flagstostr(uint32_t flags) if (flags & (1 << RFCOMM_TTY_ATTACHED)) strcat(str, "tty-attached"); - + strcat(str, "]"); return str; } @@ -170,7 +171,6 @@ static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int ar fprintf(stderr, "Can't find a config entry for rfcomm%d\n", dev); return -EFAULT; } - } else { str2ba(argv[1], &req.dst); @@ -265,7 +265,7 @@ static void run_cmdline(struct pollfd *p, sigset_t* sigs, char *devname, int i; pid_t pid; char **cmdargv; - + cmdargv = malloc((argc + 1) * sizeof(char*)); if (!cmdargv) return; @@ -357,13 +357,22 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg return; } - if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { + if (linger) { + struct linger l = { .l_onoff = 1, .l_linger = linger }; + + if (setsockopt(sk, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) { + perror("Can't set linger option"); + return; + } + } + + if (bind(sk, (struct sockaddr *) &laddr, sizeof(laddr)) < 0) { perror("Can't bind RFCOMM socket"); close(sk); return; } - if (connect(sk, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) { + if (connect(sk, (struct sockaddr *) &raddr, sizeof(raddr)) < 0) { perror("Can't connect RFCOMM socket"); close(sk); return; @@ -524,6 +533,16 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv return; } + if (linger) { + struct linger l = { .l_onoff = 1, .l_linger = linger }; + + if (setsockopt(nsk, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) { + perror("Can't set linger option"); + close(nsk); + return; + } + } + memset(&req, 0, sizeof(req)); req.dev_id = dev; req.flags = (1 << RFCOMM_REUSE_DLC) | (1 << RFCOMM_RELEASE_ONHUP); @@ -708,7 +727,6 @@ static void usage(void) printf("\n"); } - static struct option main_options[] = { { "help", 0, 0, 'h' }, { "device", 1, 0, 'i' }, @@ -718,6 +736,7 @@ static struct option main_options[] = { { "encrypt", 0, 0, 'E' }, { "secure", 0, 0, 'S' }, { "master", 0, 0, 'M' }, + { "linger", 1, 0, 'L' }, { 0, 0, 0, 0 } }; @@ -728,7 +747,7 @@ int main(int argc, char *argv[]) bacpy(&bdaddr, BDADDR_ANY); - while ((opt = getopt_long(argc, argv, "+i:f:rahAESM", main_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "+i:f:rahAESML:", main_options, NULL)) != -1) { switch(opt) { case 'i': if (strncmp(optarg, "hci", 3) == 0) @@ -740,6 +759,7 @@ int main(int argc, char *argv[]) case 'f': rfcomm_config_file = strdup(optarg); break; + case 'r': rfcomm_raw_tty = 1; break; @@ -768,6 +788,10 @@ int main(int argc, char *argv[]) master = 1; break; + case 'L': + linger = atoi(optarg); + break; + default: exit(0); } diff --git a/rfcomm/rfcomm.1 b/rfcomm/rfcomm.1 index 47c98857..eaec05df 100644 --- a/rfcomm/rfcomm.1 +++ b/rfcomm/rfcomm.1 @@ -48,7 +48,7 @@ Prints information about all configured RFCOMM devices. .BI -r Switch TTY into raw mode (doesn't work with "bind"). .TP -.BI -f " [file]" +.BI -f " " Specify alternate config file. .TP .BI -i " | " @@ -78,6 +78,9 @@ Secure connection .TP .BI -M Become the master of a piconet +.TP +.BI -L " " +Set linger timeout .SH COMMANDS .TP .BI show " " -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- rfcomm/kword.c | 2 +- rfcomm/kword.h | 2 +- rfcomm/lexer.l | 2 +- rfcomm/main.c | 2 +- rfcomm/parser.y | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'rfcomm') diff --git a/rfcomm/kword.c b/rfcomm/kword.c index 2108fe4e..020f790f 100644 --- a/rfcomm/kword.c +++ b/rfcomm/kword.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2007 Marcel Holtmann + * Copyright (C) 2002-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/kword.h b/rfcomm/kword.h index dfcc60f0..557441cb 100644 --- a/rfcomm/kword.h +++ b/rfcomm/kword.h @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2007 Marcel Holtmann + * Copyright (C) 2002-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/lexer.l b/rfcomm/lexer.l index 9988243f..0c4dfee5 100644 --- a/rfcomm/lexer.l +++ b/rfcomm/lexer.l @@ -3,7 +3,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2007 Marcel Holtmann + * Copyright (C) 2002-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/main.c b/rfcomm/main.c index e648c2d1..f831f6a4 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2007 Marcel Holtmann + * Copyright (C) 2002-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify diff --git a/rfcomm/parser.y b/rfcomm/parser.y index fe2cbe60..3afec076 100644 --- a/rfcomm/parser.y +++ b/rfcomm/parser.y @@ -3,7 +3,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2002-2007 Marcel Holtmann + * Copyright (C) 2002-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From d842176ec218c4417321b22a87fa33d037c84795 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 10 Feb 2008 05:27:22 +0000 Subject: Add option for installing generic tools --- rfcomm/Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'rfcomm') diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am index 5eec05e8..9baa8e67 100644 --- a/rfcomm/Makefile.am +++ b/rfcomm/Makefile.am @@ -1,4 +1,5 @@ +if TOOLS if CONFIGFILES confdir = $(sysconfdir)/bluetooth @@ -8,7 +9,9 @@ endif bin_PROGRAMS = rfcomm rfcomm_SOURCES = main.c parser.h parser.y lexer.l kword.h kword.c + rfcomm_LDADD = @BLUEZ_LIBS@ +endif AM_CFLAGS = @BLUEZ_CFLAGS@ @@ -16,9 +19,11 @@ INCLUDES = -I$(top_srcdir)/common BUILT_SOURCES = parser.h +if TOOLS if MANPAGES man_MANS = rfcomm.1 endif +endif AM_YFLAGS = -d -- cgit From 45c36dbd276501aa76d9798a8fafe6c202db7276 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 11 Jun 2008 13:20:50 +0000 Subject: Avoid direct inclusion of malloc.h --- rfcomm/main.c | 1 - 1 file changed, 1 deletion(-) (limited to 'rfcomm') diff --git a/rfcomm/main.c b/rfcomm/main.c index f831f6a4..f21e989c 100644 --- a/rfcomm/main.c +++ b/rfcomm/main.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include -- cgit