summaryrefslogtreecommitdiff
path: root/android/hidhost.c
diff options
context:
space:
mode:
authorSzymon Janc <szymon.janc@tieto.com>2014-04-18 15:40:05 +0200
committerSzymon Janc <szymon.janc@tieto.com>2014-04-23 10:03:36 +0200
commitc803cf88ebb104c44485bc5a3f76f67c4c759f4f (patch)
treeffb212b82801763611eb8ada752439fbdfbf1419 /android/hidhost.c
parent35cd7eddbfa397dbd34986e50155320834d842a7 (diff)
downloadbluez-c803cf88ebb104c44485bc5a3f76f67c4c759f4f.tar.gz
android/hidhost: Don't use sscanf in hex2buf
Add cheaper version (based on similar code in oFono) that doesn't require sscanf.
Diffstat (limited to 'android/hidhost.c')
-rw-r--r--android/hidhost.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/android/hidhost.c b/android/hidhost.c
index ea8373302..ab7f7a870 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -30,6 +30,7 @@
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
+#include <ctype.h>
#include <glib.h>
@@ -162,12 +163,37 @@ static void hid_device_remove(struct hid_device *dev)
hid_device_free(dev);
}
-static void hex2buf(const uint8_t *hex, uint8_t *buf, int num)
+static bool hex2buf(const uint8_t *hex, uint8_t *buf, int buf_size)
{
- int i;
+ int i, j;
+ char c;
+ uint8_t b;
- for (i = 0; i < num; i++)
- sscanf((const char *)(hex + (i * 2)), "%02hhX", &buf[i]);
+ for (i = 0, j = 0; i < buf_size; i++, j++) {
+ c = toupper(hex[j]);
+
+ if (c >= '0' && c <= '9')
+ b = c - '0';
+ else if (c >= 'A' && c <= 'F')
+ b = 10 + c - 'A';
+ else
+ return false;
+
+ j++;
+
+ c = toupper(hex[j]);
+
+ if (c >= '0' && c <= '9')
+ b = b * 16 + c - '0';
+ else if (c >= 'A' && c <= 'F')
+ b = b * 16 + 10 + c - 'A';
+ else
+ return false;
+
+ buf[i] = b;
+ }
+
+ return true;
}
static void handle_uhid_output(struct hid_device *dev,