From: Michal Labedzki <michal.labedzki@tieto.com>
To: <linux-bluetooth@vger.kernel.org>
Cc: Michal Labedzki <michal.labedzki@tieto.com>
Subject: [PATCH 1/3] Filter device name in hciconfig.
Date: Mon, 20 Dec 2010 11:13:47 +0100 [thread overview]
Message-ID: <1292840029-27770-2-git-send-email-michal.labedzki@tieto.com> (raw)
In-Reply-To: <1292840029-27770-1-git-send-email-michal.labedzki@tieto.com>
No anymore work someting like "hciconfig tty1", "hciconfig qfg1" or
"hciconfig hci1hg" as "hci1".
---
lib/hci.c | 12 +++++++++++-
tools/hciconfig.c | 30 +++++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/lib/hci.c b/lib/hci.c
index 3304daa..64c7dad 100644
--- a/lib/hci.c
+++ b/lib/hci.c
@@ -54,6 +54,16 @@ typedef struct {
unsigned int val;
} hci_map;
+static int is_number(const char *c)
+{
+ while(*c) {
+ if (! isdigit(*c))
+ return 0;
+ ++c;
+ }
+ return 1;
+}
+
static char *hci_bit2str(hci_map *m, unsigned int val)
{
char *str = malloc(120);
@@ -889,7 +899,7 @@ int hci_devid(const char *str)
bdaddr_t ba;
int id = -1;
- if (!strncmp(str, "hci", 3) && strlen(str) >= 4) {
+ if (!strncmp(str, "hci", 3) && strlen(str) >= 4 && is_number(str+3)) {
id = atoi(str + 3);
if (hci_devba(id, &ba) < 0)
return -1;
diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 3627b7c..e8b0c69 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -1721,6 +1721,33 @@ static void print_dev_info(int ctl, struct hci_dev_info *di)
printf("\n");
}
+static int is_number(const char *c)
+{
+ while(*c) {
+ if (! isdigit(*c))
+ return 0;
+ ++c;
+ }
+ return 1;
+}
+
+static int dev_name_filter(char *dev_name)
+{
+ int ret;
+
+ if ( (strlen(dev_name) >= 4) && (!strncmp(dev_name, "hci", 3)) &&
+ (is_number(dev_name+3)) )
+ ret = atoi(dev_name+3);
+ else if (is_number(dev_name))
+ ret = atoi(dev_name);
+ else {
+ fprintf(stderr, "No valid device name\n");
+ exit(1);
+ }
+
+ return ret;
+}
+
static struct {
char *cmd;
void (*func)(int ctl, int hdev, char *opt);
@@ -1824,7 +1851,8 @@ int main(int argc, char *argv[])
exit(0);
}
- di.dev_id = atoi(argv[0] + 3);
+ di.dev_id = dev_name_filter(argv[0]);
+
argc--; argv++;
if (ioctl(ctl, HCIGETDEVINFO, (void *) &di)) {
--
1.7.0.4
next prev parent reply other threads:[~2010-12-20 10:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-20 10:13 [PATCH] Tools user interface improve Michal Labedzki
2010-12-20 10:13 ` Michal Labedzki [this message]
2010-12-21 8:30 ` [PATCH v2 1/3] Filter device name in hciconfig Michal Labedzki
2010-12-21 8:49 ` Johan Hedberg
2010-12-20 10:13 ` [PATCH 2/3] Fix tools UI to avoid program launch mistakes Michal Labedzki
2010-12-20 15:41 ` Johan Hedberg
2010-12-20 10:13 ` [PATCH 3/3] More CodingStyle in lib and tools Michal Labedzki
2010-12-20 15:38 ` Johan Hedberg
2010-12-21 8:34 ` [PATCH v2 " Michal Labedzki
2010-12-21 8:52 ` Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1292840029-27770-2-git-send-email-michal.labedzki@tieto.com \
--to=michal.labedzki@tieto.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox