diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-06-21 21:18:00 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-06-21 21:18:00 +0000 |
commit | 3536636a5b1664499ee0ededd305b9bdc9ddeaa4 (patch) | |
tree | 6c2064ec0010546d771d62a0cea995740aa94241 | |
parent | 54d90a07ab77d86aeac4eed963071a07247eff18 (diff) |
Add common bachk() function
-rw-r--r-- | include/bluetooth.h | 1 | ||||
-rw-r--r-- | src/bluetooth.c | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/include/bluetooth.h b/include/bluetooth.h index 1362ed822..1d377781e 100644 --- a/include/bluetooth.h +++ b/include/bluetooth.h @@ -125,6 +125,7 @@ char *batostr(const bdaddr_t *ba); int ba2str(const bdaddr_t *ba, char *str); int str2ba(const char *str, bdaddr_t *ba); int ba2oui(const bdaddr_t *ba, char *oui); +int bachk(const char *str); int baprintf(const char *format, ...); int bafprintf(FILE *stream, const char *format, ...); diff --git a/src/bluetooth.c b/src/bluetooth.c index f0f800a51..676e468ed 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <errno.h> +#include <ctype.h> #include <stdarg.h> #include <stdlib.h> #include <malloc.h> @@ -110,6 +111,40 @@ int ba2oui(const bdaddr_t *ba, char *str) return sprintf(str, "%2.2X-%2.2X-%2.2X", b[0], b[1], b[2]); } +int bachk(const char *str) +{ + char tmp[18], *ptr = tmp; + + if (!str) + return -1; + + if (strlen(str) != 17) + return -1; + + memcpy(tmp, str, 18); + + while (*ptr) { + *ptr = toupper(*ptr); + if (*ptr < '0'|| (*ptr > '9' && *ptr < 'A') || *ptr > 'F') + return -1; + ptr++; + + *ptr = toupper(*ptr); + if (*ptr < '0'|| (*ptr > '9' && *ptr < 'A') || *ptr > 'F') + return -1; + ptr++; + + *ptr = toupper(*ptr); + if (*ptr == 0) + break; + if (*ptr != ':') + return -1; + ptr++; + } + + return 0; +} + int baprintf(const char *format, ...) { va_list ap; |