--- bluez-4.64.orig/plugins/hciops.c +++ bluez-4.64/plugins/hciops.c @@ -119,6 +119,7 @@ static void init_device(int index) struct hci_dev_info di; pid_t pid; int dd, err; + char name[249]; /* Do initialization in the separate process */ pid = fork(); @@ -143,6 +144,30 @@ static void init_device(int index) exit(1); } + if (hci_read_local_name(dd, sizeof(name), name, 1000) < 0) { + error("Can't read local name on hci%d: %s (%d)\n", + index, strerror(errno), errno); + exit(1); + } + + name[248] = '\0'; + + if (!g_utf8_validate(name, -1, NULL)) { + char *utf8_name; + + utf8_name = g_convert(name, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); + if (utf8_name) { + debug("Fix invalid non-UTF-8 device name \"%s\" on hci%d to \"%s\"", + name, index, utf8_name); + if (hci_write_local_name(dd, utf8_name, 2000) < 0) { + error("Can't change local name on hci%d: %s (%d)\n", + index, strerror(errno), errno); + exit(1); + } + g_free(utf8_name); + } + } + memset(&dr, 0, sizeof(dr)); dr.dev_id = index;