summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
Diffstat (limited to 'input')
-rw-r--r--input/device.c14
-rw-r--r--input/storage.c34
-rw-r--r--input/storage.h2
3 files changed, 44 insertions, 6 deletions
diff --git a/input/device.c b/input/device.c
index 6e701862..2d05d264 100644
--- a/input/device.c
+++ b/input/device.c
@@ -85,8 +85,9 @@ struct pending_connect {
};
struct input_device {
- bdaddr_t src;
- bdaddr_t dst;
+ bdaddr_t src;
+ bdaddr_t dst;
+ char *name;
uint8_t major;
uint8_t minor;
struct hidp_connadd_req hidp; /* FIXME: Use dynamic alloc? */
@@ -121,6 +122,11 @@ static struct input_device *input_device_new(bdaddr_t *src, bdaddr_t *dst, uint3
idev->major = (cls >> 8) & 0x1f;
idev->minor = (cls >> 2) & 0x3f;
+ read_device_name(src, dst, &idev->name);
+
+ /* FIXME: hidp could be alloc dynamically */
+ snprintf(idev->hidp.name, 128, "%s", idev->name);
+
return idev;
}
@@ -139,6 +145,8 @@ static void input_device_free(struct input_device *idev)
{
if (!idev)
return;
+ if (idev->name)
+ g_free(idev->name);
if (idev->hidp.rd_data)
g_free(idev->hidp.rd_data);
if (idev->fake)
@@ -594,7 +602,7 @@ static gboolean rfcomm_connect_cb(GIOChannel *chan, GIOCondition cond,
* first to report volume gain key events
*/
- fake->uinput = uinput_create("Fake input");
+ fake->uinput = uinput_create(idev->name);
if (fake->uinput < 0) {
err = errno;
goto failed;
diff --git a/input/storage.c b/input/storage.c
index be5ab3e3..fd8d4bcb 100644
--- a/input/storage.c
+++ b/input/storage.c
@@ -71,7 +71,6 @@ int parse_stored_device_info(const char *str, struct hidp_connadd_req *req)
&vendor, &product, &version, &subclass, &country,
&parser, &req->flags, &pos);
-
desc = &str[pos];
len = strlen(desc);
if (len <= 0)
@@ -84,8 +83,6 @@ int parse_stored_device_info(const char *str, struct hidp_connadd_req *req)
req->country = country;
req->parser = parser;
- /* FIXME: Retrieve the name from the filesystem file "names" */
-
req->rd_size = len / 2;
req->rd_data = g_try_malloc0(req->rd_size);
if (!req->rd_data) {
@@ -174,6 +171,37 @@ int store_device_info(bdaddr_t *src, bdaddr_t *dst, struct hidp_connadd_req *req
return err;
}
+int read_device_name(bdaddr_t *local, bdaddr_t *peer, char **name)
+{
+ char filename[PATH_MAX + 1], addr[18], *str;
+ int len;
+
+ create_filename(filename, PATH_MAX, local, "names");
+
+ ba2str(peer, addr);
+ str = textfile_get(filename, addr);
+ if (!str)
+ return -ENOENT;
+
+ len = strlen(str);
+
+ /* HID max name size is 128 chars */
+ if (len < 128) {
+ *name = str;
+ return 0;
+ }
+
+ *name = g_try_malloc0(128);
+ if (!*name)
+ return -ENOMEM;
+
+ snprintf(*name, 128, "%s", str);
+
+ free(str);
+
+ return 0;
+}
+
int encrypt_link(bdaddr_t *src, bdaddr_t *dst)
{
char filename[PATH_MAX + 1];
diff --git a/input/storage.h b/input/storage.h
index 09a696cf..60df915d 100644
--- a/input/storage.h
+++ b/input/storage.h
@@ -32,4 +32,6 @@ int store_device_info(bdaddr_t *src, bdaddr_t *dst,
int parse_stored_device_info(const char *str,
struct hidp_connadd_req *req);
+int read_device_name(bdaddr_t *local, bdaddr_t *peer, char **name);
+
int encrypt_link(bdaddr_t *src, bdaddr_t *dst);