summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--input/manager.c38
-rw-r--r--input/storage.c42
-rw-r--r--input/storage.h1
3 files changed, 79 insertions, 2 deletions
diff --git a/input/manager.c b/input/manager.c
index 03c914ee..666c0e44 100644
--- a/input/manager.c
+++ b/input/manager.c
@@ -962,6 +962,34 @@ cleanup:
g_free(hidp.rd_data);
}
+/* hidd to input transition function */
+static void stored_hidd(char *key, char *value, void *data)
+{
+ struct hidp_connadd_req hidp;
+ char *str, filename[PATH_MAX + 1], addr[18];
+ bdaddr_t dst, *src = data;
+
+ ba2str(src, addr);
+ create_name(filename, PATH_MAX, STORAGEDIR, addr, "input");
+
+ str = textfile_get(filename, key);
+ if (str) {
+ /* Skip: entry found in input file */
+ free(str);
+ return;
+ }
+
+ memset(&hidp, 0, sizeof(struct hidp_connadd_req));
+
+ if (parse_stored_hidd(value, &hidp) < 0)
+ return;
+
+ str2ba(key, &dst);
+ store_device_info(src, &dst, &hidp);
+ if (hidp.rd_data)
+ g_free(hidp.rd_data);
+}
+
static void register_stored_inputs(void)
{
char dirname[PATH_MAX + 1];
@@ -980,10 +1008,16 @@ static void register_stored_inputs(void)
if (!isdigit(de->d_name[0]))
continue;
+ str2ba(de->d_name, &src);
+
+ /* move the hidd entries to the input storage */
create_name(filename, PATH_MAX, STORAGEDIR,
- de->d_name, "input");
+ de->d_name, "hidd");
+ textfile_foreach(filename, stored_hidd, &src);
- str2ba(de->d_name, &src);
+ /* load the input stored devices */
+ create_name(filename, PATH_MAX, STORAGEDIR,
+ de->d_name, "input");
textfile_foreach(filename, stored_input, &src);
}
diff --git a/input/storage.c b/input/storage.c
index 3793a275..7da536b3 100644
--- a/input/storage.c
+++ b/input/storage.c
@@ -59,6 +59,48 @@ static inline int create_filename(char *buf, size_t size,
return create_name(buf, size, STORAGEDIR, addr, name);
}
+int parse_stored_hidd(const char *str, struct hidp_connadd_req *req)
+{
+ char tmp[3];
+ char *desc;
+ unsigned int vendor, product, version, subclass, country, parser, pos;
+ int i;
+
+ desc = malloc(4096);
+ if (!desc)
+ return -ENOMEM;
+
+ memset(desc, 0, 4096);
+
+ sscanf(str, "%04X:%04X:%04X %02X %02X %04X %4095s %08X %n",
+ &vendor, &product, &version, &subclass, &country,
+ &parser, desc, &req->flags, &pos);
+
+ req->vendor = vendor;
+ req->product = product;
+ req->version = version;
+ req->subclass = subclass;
+ req->country = country;
+ req->parser = parser;
+
+ req->rd_size = strlen(desc) / 2;
+ req->rd_data = g_try_malloc0(req->rd_size);
+ if (!req->rd_data) {
+ g_free(desc);
+ return -ENOMEM;
+ }
+
+ memset(tmp, 0, sizeof(tmp));
+ for (i = 0; i < req->rd_size; i++) {
+ memcpy(tmp, desc + (i * 2), 2);
+ req->rd_data[i] = (uint8_t) strtol(tmp, NULL, 16);
+ }
+
+ g_free(desc);
+
+ return 0;
+}
+
int parse_stored_device_info(const char *str, struct hidp_connadd_req *req)
{
char tmp[3];
diff --git a/input/storage.h b/input/storage.h
index 81ad2599..a5462561 100644
--- a/input/storage.h
+++ b/input/storage.h
@@ -29,6 +29,7 @@ int del_stored_device_info(bdaddr_t *src, bdaddr_t *dst);
int store_device_info(bdaddr_t *src, bdaddr_t *dst,
struct hidp_connadd_req *req);
+int parse_stored_hidd(const char *str, struct hidp_connadd_req *req);
int parse_stored_device_info(const char *str,
struct hidp_connadd_req *req);