static struct device_opts *get_device_opts(int hdev) { struct device_opts *device_opts = NULL; struct hci_dev_info di; /* First try to get BD_ADDR based settings ... */ if (hci_devinfo(hdev, &di) == 0) { char addr[18]; ba2str(&di.bdaddr, addr); device_opts = find_device_opts(addr); } /* ... then try HCI based settings ... */ if (!device_opts) { char ref[8]; snprintf(ref, sizeof(ref) - 1, "hci%d", hdev); device_opts = find_device_opts(ref); } /* ... and last use the default settings. */ if (!device_opts) device_opts = &default_device; return device_opts; }
static struct device_opts *get_device_opts(int sock, int hdev) { struct device_opts *device_opts = NULL; struct hci_dev_info di; /* First try to get BD_ADDR based settings ... */ di.dev_id = hdev; if (!ioctl(sock, HCIGETDEVINFO, (void *) &di)) { char addr[18]; ba2str(&di.bdaddr, addr); device_opts = find_device_opts(addr); } /* ... then try HCI based settings ... */ if (!device_opts) { char ref[8]; snprintf(ref, sizeof(ref) - 1, "hci%d", hdev); device_opts = find_device_opts(ref); } /* ... and last use the default settings. */ if (!device_opts) device_opts = &default_device; return device_opts; }
int get_discoverable_timeout(int hdev) { struct device_opts *device_opts = NULL; struct hci_dev_info di; char addr[18]; int sock, timeout; if (hdev < 0) return HCID_DEFAULT_DISCOVERABLE_TIMEOUT; sock = hci_open_dev(hdev); if (sock < 0) goto no_address; if (hci_devinfo(hdev, &di) < 0) { close(sock); goto no_address; } close(sock); if (read_discoverable_timeout(&di.bdaddr, &timeout) == 0) return timeout; ba2str(&di.bdaddr, addr); device_opts = find_device_opts(addr); no_address: if (!device_opts) { char ref[8]; snprintf(ref, sizeof(ref) - 1, "hci%d", hdev); device_opts = find_device_opts(ref); } if (!device_opts) device_opts = &default_device; return device_opts->discovto; }
static struct device_opts *get_opts(int hdev) { struct device_opts *device_opts = NULL; struct hci_dev_info di; char addr[18]; int sock; if (hdev < 0) return NULL; sock = hci_open_dev(hdev); if (sock < 0) goto no_address; if (hci_devinfo(hdev, &di) < 0) { close(sock); goto no_address; } close(sock); ba2str(&di.bdaddr, addr); device_opts = find_device_opts(addr); no_address: if (!device_opts) { char ref[8]; snprintf(ref, sizeof(ref) - 1, "hci%d", hdev); device_opts = find_device_opts(ref); } if (!device_opts) device_opts = &default_device; return device_opts; }