diff options
author | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2012-08-09 17:29:02 -0300 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-08-09 22:52:38 -0700 |
commit | 5bec57420bd57f86d61b2919450d182f3407facf (patch) | |
tree | 6d41764b79314d1f96177b407c03841bab87ea98 /tools | |
parent | dde5b23665ba3b29ccfa8c9fd640c5995de3b4a3 (diff) |
rfcomm: Remove support for configuration file
Diffstat (limited to 'tools')
-rw-r--r-- | tools/kword.c | 65 | ||||
-rw-r--r-- | tools/kword.h | 46 | ||||
-rw-r--r-- | tools/lexer.l | 120 | ||||
-rw-r--r-- | tools/parser.y | 171 | ||||
-rw-r--r-- | tools/rfcomm.1 | 19 | ||||
-rw-r--r-- | tools/rfcomm.c | 99 | ||||
-rw-r--r-- | tools/rfcomm.conf | 17 |
7 files changed, 22 insertions, 515 deletions
diff --git a/tools/kword.c b/tools/kword.c deleted file mode 100644 index 62e24fee..00000000 --- a/tools/kword.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org> - * - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <errno.h> -#include <sys/socket.h> - -#include <bluetooth/bluetooth.h> -#include <bluetooth/rfcomm.h> - -#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/tools/kword.h b/tools/kword.h deleted file mode 100644 index 81a2a88f..00000000 --- a/tools/kword.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org> - * - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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/tools/lexer.l b/tools/lexer.l deleted file mode 100644 index ff9ce812..00000000 --- a/tools/lexer.l +++ /dev/null @@ -1,120 +0,0 @@ -%{ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org> - * - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -/* Nasty workaround, but flex defines isatty() twice */ -#define _UNISTD_H - -#include <stdio.h> -#include <errno.h> -#include <sys/socket.h> - -#include <bluetooth/bluetooth.h> -#include <bluetooth/rfcomm.h> - -#include "kword.h" -#include "parser.h" - -int yylex(void); - -#define YY_NO_INPUT - -#define ECHO {;} -#define YY_DECL int yylex(void) - -int yyerror(char *str); - -%} - -%option nounput - -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/tools/parser.y b/tools/parser.y deleted file mode 100644 index 96e6a569..00000000 --- a/tools/parser.y +++ /dev/null @@ -1,171 +0,0 @@ -%{ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org> - * - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <errno.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <sys/param.h> -#include <sys/socket.h> - -#include <bluetooth/bluetooth.h> -#include <bluetooth/rfcomm.h> - -#include "kword.h" - -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> NUMBER RFCOMM -%token <string> STRING WORD -%token <bdaddr> BDADDR - -%type <number> 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, "%s/rfcomm.conf", CONFIGDIR); - } - - if (!(yyin = fopen(file, "r"))) - return -1; - - lineno = 1; - yyparse(); - - fclose(yyin); - - return 0; -} diff --git a/tools/rfcomm.1 b/tools/rfcomm.1 index 06303cd8..f880f524 100644 --- a/tools/rfcomm.1 +++ b/tools/rfcomm.1 @@ -48,9 +48,6 @@ Prints information about all configured RFCOMM devices. .BI -r Switch TTY into raw mode (doesn't work with "bind"). .TP -.BI -f " <file>" -Specify alternate config file. -.TP .BI -i " <hciX> | <bdaddr>" The command is applied to device .BI -A @@ -89,9 +86,8 @@ Display the information about the specified device. .BI connect " <dev> [bdaddr] [channel]" Connect the RFCOMM device to the remote Bluetooth device on the specified channel. If no channel is specified, it will use the -channel number 1. If also the Bluetooth address is left out, it -tries to read the data from the config file. This command can -be terminated with the key sequence CTRL-C. +channel number 1. This command can be terminated with the key +sequence CTRL-C. .TP .BI listen " <dev> [channel] [cmd]" Listen on a specified RFCOMM channel for incoming connections. @@ -115,15 +111,7 @@ 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 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. +number is specified, it uses the channel number 1. .TP .BI release " <dev>" This command releases a defined RFCOMM binding. @@ -131,7 +119,6 @@ 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 <marcel@holtmann.org>. .br diff --git a/tools/rfcomm.c b/tools/rfcomm.c index 0a806702..add9f3b6 100644 --- a/tools/rfcomm.c +++ b/tools/rfcomm.c @@ -46,13 +46,10 @@ #include <bluetooth/hci_lib.h> #include <bluetooth/rfcomm.h> -#include "kword.h" - #ifdef NEED_PPOLL #include "ppoll.h" #endif -static char *rfcomm_config_file = NULL; static int rfcomm_raw_tty = 0; static int auth = 0; static int encryption = 0; @@ -159,27 +156,16 @@ static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int ar bacpy(&req.src, bdaddr); if (argc < 2) { - err = rfcomm_read_config(rfcomm_config_file); - if (err < 0) { - perror("Can't open RFCOMM config file"); - return err; - } - - bacpy(&req.dst, &rfcomm_opts[dev].bdaddr); - req.channel = rfcomm_opts[dev].channel; + fprintf(stderr, "Missing dev parameter"); + return -EINVAL; + } - 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); + str2ba(argv[1], &req.dst); - if (argc > 2) - req.channel = atoi(argv[2]); - else - req.channel = 1; - } + if (argc > 2) + req.channel = atoi(argv[2]); + else + req.channel = 1; err = ioctl(ctl, RFCOMMCREATEDEV, &req); if (err == -1) { @@ -194,35 +180,6 @@ static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int ar return err; } -static int create_all(int ctl) -{ - struct rfcomm_dev_req req; - int i, err; - - err = rfcomm_read_config(rfcomm_config_file); - if (err < 0) { - perror("Can't open RFCOMM config file"); - return err; - } - - 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; - 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, uint32_t flags) { struct rfcomm_dev_req req; @@ -335,28 +292,17 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg laddr.rc_channel = 0; if (argc < 2) { - if (rfcomm_read_config(rfcomm_config_file) < 0) { - perror("Can't open RFCOMM config file"); - return; - } + fprintf(stderr, "Missing dev parameter"); + return; + } - raddr.rc_family = AF_BLUETOOTH; - bacpy(&raddr.rc_bdaddr, &rfcomm_opts[dev].bdaddr); - raddr.rc_channel = rfcomm_opts[dev].channel; + raddr.rc_family = AF_BLUETOOTH; + str2ba(argv[1], &raddr.rc_bdaddr); - if (bacmp(&raddr.rc_bdaddr, 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 (argc > 2) + raddr.rc_channel = atoi(argv[2]); + else + raddr.rc_channel = 1; sk = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); if (sk < 0) { @@ -658,10 +604,7 @@ static void cmd_watch(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) 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); + create_dev(ctl, dev, 0, bdaddr, argc, argv); } static void cmd_release(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv) @@ -754,7 +697,7 @@ int main(int argc, char *argv[]) bacpy(&bdaddr, BDADDR_ANY); - while ((opt = getopt_long(argc, argv, "+i:f:rahAESML:", main_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "+i:rahAESML:", main_options, NULL)) != -1) { switch(opt) { case 'i': if (strncmp(optarg, "hci", 3) == 0) @@ -763,10 +706,6 @@ int main(int argc, char *argv[]) str2ba(optarg, &bdaddr); break; - case 'f': - rfcomm_config_file = strdup(optarg); - break; - case 'r': rfcomm_raw_tty = 1; break; diff --git a/tools/rfcomm.conf b/tools/rfcomm.conf deleted file mode 100644 index 6179ef7b..00000000 --- a/tools/rfcomm.conf +++ /dev/null @@ -1,17 +0,0 @@ -# -# 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"; -#} |