* [PATCH 1/4] Simplify ba2oui function
2011-03-04 18:34 [PATCH 0/4] Some small bluetooth.c cleanups and fixes Szymon Janc
@ 2011-03-04 18:34 ` Szymon Janc
2011-03-04 18:34 ` [PATCH 2/4] Simplify ba2str function Szymon Janc
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2011-03-04 18:34 UTC (permalink / raw)
To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
---
lib/bluetooth.c | 6 +-----
1 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index 875119b..d064f9e 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -109,11 +109,7 @@ int str2ba(const char *str, bdaddr_t *ba)
int ba2oui(const bdaddr_t *ba, char *str)
{
- uint8_t b[6];
-
- baswap((bdaddr_t *) b, ba);
-
- return sprintf(str, "%2.2X-%2.2X-%2.2X", b[0], b[1], b[2]);
+ return sprintf(str, "%2.2X-%2.2X-%2.2X", ba->b[5], ba->b[4], ba->b[3]);
}
int bachk(const char *str)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/4] Simplify ba2str function
2011-03-04 18:34 [PATCH 0/4] Some small bluetooth.c cleanups and fixes Szymon Janc
2011-03-04 18:34 ` [PATCH 1/4] Simplify ba2oui function Szymon Janc
@ 2011-03-04 18:34 ` Szymon Janc
2011-03-04 18:34 ` [PATCH 3/4] Fix str2ba behaviour on malformed bt address Szymon Janc
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2011-03-04 18:34 UTC (permalink / raw)
To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
---
lib/bluetooth.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index d064f9e..f51e310 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -82,11 +82,8 @@ bdaddr_t *strtoba(const char *str)
int ba2str(const bdaddr_t *ba, char *str)
{
- uint8_t b[6];
-
- baswap((bdaddr_t *) b, ba);
return sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
- b[0], b[1], b[2], b[3], b[4], b[5]);
+ ba->b[5], ba->b[4], ba->b[3], ba->b[2], ba->b[1], ba->b[0]);
}
int str2ba(const char *str, bdaddr_t *ba)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/4] Fix str2ba behaviour on malformed bt address
2011-03-04 18:34 [PATCH 0/4] Some small bluetooth.c cleanups and fixes Szymon Janc
2011-03-04 18:34 ` [PATCH 1/4] Simplify ba2oui function Szymon Janc
2011-03-04 18:34 ` [PATCH 2/4] Simplify ba2str function Szymon Janc
@ 2011-03-04 18:34 ` Szymon Janc
2011-03-04 18:34 ` [PATCH 4/4] Make strtoba use str2ba for string conversion Szymon Janc
2011-03-15 13:15 ` [PATCH 0/4] Some small bluetooth.c cleanups and fixes Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2011-03-04 18:34 UTC (permalink / raw)
To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
str2ba could create bogus bt address from malformed string. Return
all zeros bt address on malformed string.
---
lib/bluetooth.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index f51e310..d943fdc 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -88,19 +88,18 @@ int ba2str(const bdaddr_t *ba, char *str)
int str2ba(const char *str, bdaddr_t *ba)
{
- uint8_t b[6];
- const char *ptr = str;
+ bdaddr_t b;
int i;
- for (i = 0; i < 6; i++) {
- b[i] = (uint8_t) strtol(ptr, NULL, 16);
- if (i != 5 && !(ptr = strchr(ptr, ':')))
- ptr = ":00:00:00:00:00";
- ptr++;
+ if (bachk(str) < 0) {
+ memset(ba, 0, sizeof(*ba));
+ return -1;
}
- baswap(ba, (bdaddr_t *) b);
+ for (i = 0; i < 6; i++, str += 3)
+ b.b[i] = strtol(str, NULL, 16);
+ baswap(ba, &b);
return 0;
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 4/4] Make strtoba use str2ba for string conversion
2011-03-04 18:34 [PATCH 0/4] Some small bluetooth.c cleanups and fixes Szymon Janc
` (2 preceding siblings ...)
2011-03-04 18:34 ` [PATCH 3/4] Fix str2ba behaviour on malformed bt address Szymon Janc
@ 2011-03-04 18:34 ` Szymon Janc
2011-03-15 13:15 ` [PATCH 0/4] Some small bluetooth.c cleanups and fixes Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2011-03-04 18:34 UTC (permalink / raw)
To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
---
lib/bluetooth.c | 18 ++++++------------
1 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index d943fdc..aac9bdc 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -63,21 +63,15 @@ char *batostr(const bdaddr_t *ba)
bdaddr_t *strtoba(const char *str)
{
- const char *ptr = str;
- int i;
-
- uint8_t *ba = bt_malloc(sizeof(bdaddr_t));
- if (!ba)
- return NULL;
+ bdaddr_t b;
+ bdaddr_t *ba = bt_malloc(sizeof(*ba));
- for (i = 0; i < 6; i++) {
- ba[i] = (uint8_t) strtol(ptr, NULL, 16);
- if (i != 5 && !(ptr = strchr(ptr,':')))
- ptr = ":00:00:00:00:00";
- ptr++;
+ if (ba) {
+ str2ba(str, &b);
+ baswap(ba, &b);
}
- return (bdaddr_t *) ba;
+ return ba;
}
int ba2str(const bdaddr_t *ba, char *str)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/4] Some small bluetooth.c cleanups and fixes
2011-03-04 18:34 [PATCH 0/4] Some small bluetooth.c cleanups and fixes Szymon Janc
` (3 preceding siblings ...)
2011-03-04 18:34 ` [PATCH 4/4] Make strtoba use str2ba for string conversion Szymon Janc
@ 2011-03-15 13:15 ` Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2011-03-15 13:15 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth, par-gunnar.p.hjalmdahl, henrik.possung
Hi Szymon,
On Fri, Mar 04, 2011, Szymon Janc wrote:
> Along with "[PATCH] Simplify bachk function" these patches make bluetooth.c
> a little nicer.
All four patches have now been pushed upstream. Thanks.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread