Index: include/bluetooth.h =================================================================== RCS file: /cvsroot/bluez/libs/include/bluetooth.h,v retrieving revision 1.27 diff -u -r1.27 bluetooth.h --- include/bluetooth.h 13 Jan 2007 17:50:06 -0000 1.27 +++ include/bluetooth.h 21 Jun 2007 17:45:10 -0000 @@ -125,6 +125,7 @@ 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, ...); Index: src/bluetooth.c =================================================================== RCS file: /cvsroot/bluez/libs/src/bluetooth.c,v retrieving revision 1.41 diff -u -r1.41 bluetooth.c --- src/bluetooth.c 20 Jun 2007 15:34:46 -0000 1.41 +++ src/bluetooth.c 21 Jun 2007 17:45:11 -0000 @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -110,6 +111,38 @@ return sprintf(str, "%2.2X-%2.2X-%2.2X", b[0], b[1], b[2]); } +int bachk(const char *str) +{ + char tmp[18]; + char *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;