summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/hciconfig.c38
-rw-r--r--tools/hcitool.c2
2 files changed, 26 insertions, 14 deletions
diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 21f7bc1c..4b4844ff 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -32,6 +32,7 @@
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
+#include <getopt.h>
#include <termios.h>
#include <fcntl.h>
@@ -580,55 +581,66 @@ void usage(void)
command[i].doc);
}
-int main(int argc, char *argv[], char *env[])
+static struct option main_options[] = {
+ {"help", 0,0, 'h'},
+ {"all", 0,0, 'a'},
+ {0, 0, 0, 0}
+};
+
+int main(int argc, char **argv, char **env)
{
int opt, ctl, i, cmd=0;
- char *dev;
- while ((opt=getopt(argc, argv,"ha")) != EOF) {
+ while ((opt=getopt_long(argc, argv, "ah", main_options, NULL)) != -1) {
switch(opt) {
case 'a':
all = 1;
break;
+
case 'h':
+ default:
usage();
exit(0);
}
}
+ argc -= optind;
+ argv += optind;
+ optind = 0;
+
/* Open HCI socket */
if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
perror("Can't open HCI socket.");
exit(1);
}
- if (argc - optind < 1) {
+ if (argc < 1) {
print_dev_list(ctl, 0);
exit(0);
}
- dev = strdup(argv[optind]);
- di.dev_id = atoi(argv[optind]+3);
- optind++;
+ di.dev_id = atoi(argv[0] + 3);
+ argc--; argv++;
if (ioctl(ctl, HCIGETDEVINFO, (void*)&di)) {
perror("Can't get device info");
exit(1);
}
- while (optind < argc) {
+ while (argc > 0) {
for (i=0; command[i].cmd; i++) {
- if (strncmp(command[i].cmd, argv[optind],4))
+ if (strncmp(command[i].cmd, *argv, 4))
continue;
- if (command[i].opt)
- optind++;
+ if (command[i].opt) {
+ argc--; argv++;
+ }
- command[i].func(ctl, di.dev_id, argv[optind]);
+ command[i].func(ctl, di.dev_id, *argv);
cmd = 1;
break;
}
- optind++;
+ argc--; argv++;
}
if (!cmd)
diff --git a/tools/hcitool.c b/tools/hcitool.c
index 06c426ca..8ec564d7 100644
--- a/tools/hcitool.c
+++ b/tools/hcitool.c
@@ -783,7 +783,7 @@ static void usage(void)
{
int i;
- printf("hcitool - HCI Tool\n");
+ printf("hcitool - HCI Tool ver %s\n", VERSION);
printf("Usage:\n"
"\thcitool [options] <command> [command parameters]\n");
printf("Options:\n"