summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-02-24 18:12:08 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-02-24 18:12:08 +0000
commitd2bc437c04a2048856ba3edc54b9553bfdbd6e55 (patch)
tree1a36ade3bf7263246f7a43478c7056e8266f0a07
parentb0fc2dd356f7f5e1bceb3d901058bcd9e2bc5535 (diff)
Store the changed name of a local device
-rw-r--r--hcid/dbus-device.c5
-rw-r--r--hcid/hcid.h2
-rw-r--r--hcid/main.c13
-rw-r--r--hcid/storage.c42
4 files changed, 60 insertions, 2 deletions
diff --git a/hcid/dbus-device.c b/hcid/dbus-device.c
index ac592686..a9313505 100644
--- a/hcid/dbus-device.c
+++ b/hcid/dbus-device.c
@@ -296,6 +296,7 @@ static DBusMessage *handle_dev_set_name_req(DBusMessage *msg, void *data)
struct hci_dbus_data *dbus_data = data;
DBusMessageIter iter;
DBusMessage *reply;
+ bdaddr_t bdaddr;
char *str_ptr;
dbus_message_iter_init(msg, &iter);
@@ -306,6 +307,10 @@ static DBusMessage *handle_dev_set_name_req(DBusMessage *msg, void *data)
return bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
}
+ hci_devba(dbus_data->dev_id, &bdaddr);
+
+ write_local_name(&bdaddr, str_ptr);
+
set_device_name(dbus_data->dev_id, str_ptr);
reply = dbus_message_new_method_return(msg);
diff --git a/hcid/hcid.h b/hcid/hcid.h
index 6d71597c..ac1a33fc 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -158,6 +158,8 @@ int set_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, const char *alias)
int get_encryption_key_size(uint16_t dev_id, const bdaddr_t *baddr);
+int write_local_name(bdaddr_t *bdaddr, char *name);
+int read_local_name(bdaddr_t *bdaddr, char *name);
int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
int read_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver);
diff --git a/hcid/main.c b/hcid/main.c
index 30266ff7..c8ae1e34 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -219,10 +219,19 @@ static void configure_device(int hdev)
if ((device_opts->flags & (1 << HCID_SET_NAME)) && device_opts->name) {
change_local_name_cp cp;
write_ext_inquiry_response_cp ip;
+ bdaddr_t bdaddr;
+ char name[249];
uint8_t len;
- memset(cp.name, 0, sizeof(cp.name));
- expand_name((char *) cp.name, sizeof(cp.name), device_opts->name, hdev);
+ hci_devba(hdev, &bdaddr);
+
+ memset(name, 0, sizeof(name));
+ if (read_local_name(&bdaddr, name) < 0) {
+ memset(cp.name, 0, sizeof(cp.name));
+ expand_name((char *) cp.name, sizeof(cp.name),
+ device_opts->name, hdev);
+ } else
+ memcpy(cp.name, name, sizeof(cp.name));
ip.fec = 0x00;
memset(ip.data, 0, sizeof(ip.data));
diff --git a/hcid/storage.c b/hcid/storage.c
index 3040264d..48b040cf 100644
--- a/hcid/storage.c
+++ b/hcid/storage.c
@@ -43,6 +43,48 @@
#include "textfile.h"
#include "hcid.h"
+int write_local_name(bdaddr_t *bdaddr, char *name)
+{
+ char filename[PATH_MAX + 1], addr[18], str[249];
+ int i;
+
+ memset(str, 0, sizeof(str));
+ for (i = 0; i < 248 && name[i]; i++)
+ if (isprint(name[i]))
+ str[i] = name[i];
+ else
+ str[i] = '.';
+
+ ba2str(bdaddr, addr);
+ snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, addr);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ return textfile_put(filename, "name", str);
+}
+
+int read_local_name(bdaddr_t *bdaddr, char *name)
+{
+ char filename[PATH_MAX + 1], addr[18], *str;
+ int len;
+
+ ba2str(bdaddr, addr);
+ snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, addr);
+
+ str = textfile_get(filename, "name");
+ if (!str)
+ return -ENOENT;
+
+ len = strlen(str);
+ if (len > 248)
+ str[248] = '\0';
+ strcpy(name, str);
+
+ free(str);
+
+ return 0;
+}
+
int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name)
{
char filename[PATH_MAX + 1], addr[18], str[249];