diff options
-rw-r--r-- | hcid/main.c | 15 | ||||
-rw-r--r-- | hcid/storage.c | 9 |
2 files changed, 17 insertions, 7 deletions
diff --git a/hcid/main.c b/hcid/main.c index c8ae1e34a..0fabed406 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -219,14 +219,11 @@ 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; - hci_devba(hdev, &bdaddr); - memset(name, 0, sizeof(name)); - if (read_local_name(&bdaddr, name) < 0) { + if (read_local_name(&di.bdaddr, name) < 0) { memset(cp.name, 0, sizeof(cp.name)); expand_name((char *) cp.name, sizeof(cp.name), device_opts->name, hdev); @@ -254,10 +251,16 @@ static void configure_device(int hdev) /* Set device class */ if ((device_opts->flags & (1 << HCID_SET_CLASS))) { - uint32_t class = htobl(device_opts->class); write_class_of_dev_cp cp; + uint32_t class; + uint8_t cls[3]; + + if (read_local_class(&di.bdaddr, cls) < 0) { + class = htobl(device_opts->class); + memcpy(cp.dev_class, &class, 3); + } else + memcpy(cp.dev_class, cls, 3); - memcpy(cp.dev_class, &class, 3); hci_send_cmd(s, OGF_HOST_CTL, OCF_WRITE_CLASS_OF_DEV, WRITE_CLASS_OF_DEV_CP_SIZE, &cp); } diff --git a/hcid/storage.c b/hcid/storage.c index 0fae94475..17f0744aa 100644 --- a/hcid/storage.c +++ b/hcid/storage.c @@ -101,7 +101,8 @@ int write_local_class(bdaddr_t *bdaddr, uint8_t *class) int read_local_class(bdaddr_t *bdaddr, uint8_t *class) { - char filename[PATH_MAX + 1], addr[18], *str; + char filename[PATH_MAX + 1], addr[18], tmp[3], *str; + int i; ba2str(bdaddr, addr); snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, addr); @@ -110,6 +111,12 @@ int read_local_class(bdaddr_t *bdaddr, uint8_t *class) if (!str) return -ENOENT; + memset(tmp, 0, sizeof(tmp)); + for (i = 0; i < 3; i++) { + memcpy(tmp, str + (i * 2) + 2, 2); + class[2 - i] = (uint8_t) strtol(tmp, NULL, 16); + } + free(str); return 0; |