diff --git a/android/hidhost.c b/android/hidhost.c
index 81e7eb8..d45e1bd 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
hid_device_free(dev);
}
+static void hex2buf(const uint8_t *hex, uint8_t *buf, int num)
+{
+ int i;
+
+ for (i = 0; i < num; i++)
+ sscanf((const char *)(hex + (i * 2)), "%02hhX", &buf[i]);
+}
+
static void handle_uhid_output(struct hid_device *dev,
struct uhid_output_req *output)
{
- int fd, i;
+ int fd;
uint8_t *req = NULL;
uint8_t req_size = 0;
return;
req[0] = HID_MSG_SET_REPORT | output->rtype;
- for (i = 0; i < (req_size - 1); i++)
- sscanf((char *) &(output->data)[i * 2], "%hhx", &req[1 + i]);
+ hex2buf(output->data, req + 1, req_size - 1);
fd = g_io_channel_unix_get_fd(dev->ctrl_io);
struct hid_device *dev;
GSList *l;
bdaddr_t dst;
- int i, fd;
+ int fd;
uint8_t *req;
uint8_t req_size;
uint8_t status;
req[0] = HID_MSG_SET_REPORT | cmd->type;
/* Report data coming to HAL is in ascii format, HAL sends
* data in hex to daemon, so convert to binary. */
- for (i = 0; i < (req_size - 1); i++)
- sscanf((char *) &(cmd->data)[i * 2], "%hhx", &(req + 1)[i]);
+ hex2buf(cmd->data, req + 1, req_size - 1);
fd = g_io_channel_unix_get_fd(dev->ctrl_io);
struct hid_device *dev;
GSList *l;
bdaddr_t dst;
- int i, fd;
+ int fd;
uint8_t *req;
uint8_t req_size;
uint8_t status;
req[0] = HID_MSG_DATA | HID_DATA_TYPE_OUTPUT;
/* Report data coming to HAL is in ascii format, HAL sends
* data in hex to daemon, so convert to binary. */
- for (i = 0; i < (req_size - 1); i++)
- sscanf((char *) &(cmd->data)[i * 2], "%hhx", &(req + 1)[i]);
+ hex2buf(cmd->data, req + 1, req_size - 1);
fd = g_io_channel_unix_get_fd(dev->intr_io);