GSList *devices; /* Devices structure pointers */
guint remove_temp; /* Remove devices timer */
GSList *disc_sessions; /* Discovery sessions */
+ uint8_t discov_type;
struct session_req *scanning_session;
GSList *connect_list; /* Devices to connect when found */
guint discov_id; /* Discovery timer */
}
if (mgmt_powered(adapter->current_settings))
- mgmt_stop_discovery(adapter->dev_id);
+ mgmt_stop_discovery(adapter->dev_id, adapter->discov_type);
else
discovery_cleanup(adapter);
}
struct btd_adapter *adapter = user_data;
adapter->discov_id = 0;
+ adapter->discov_type = 0;
- if (adapter->scanning_session &&
- g_slist_length(adapter->disc_sessions) == 1)
- mgmt_start_le_scanning(adapter->dev_id);
- else
- mgmt_start_discovery(adapter->dev_id);
+ if (adapter->current_settings & MGMT_SETTING_LE) {
+ hci_set_bit(BDADDR_LE_PUBLIC, &adapter->discov_type);
+ hci_set_bit(BDADDR_LE_RANDOM, &adapter->discov_type);
+ }
+
+ if (!adapter->scanning_session ||
+ g_slist_length(adapter->disc_sessions) != 1)
+ hci_set_bit(BDADDR_BREDR, &adapter->discov_type);
+
+ mgmt_start_discovery(adapter->dev_id, adapter->discov_type);
return FALSE;
}
if (adapter->discov_suspended)
goto done;
- err = mgmt_start_discovery(adapter->dev_id);
+ adapter->discov_type = 0;
+
+ if (adapter->current_settings & MGMT_SETTING_BREDR)
+ hci_set_bit(BDADDR_BREDR, &adapter->discov_type);
+
+ if (adapter->current_settings & MGMT_SETTING_LE) {
+ hci_set_bit(BDADDR_LE_PUBLIC, &adapter->discov_type);
+ hci_set_bit(BDADDR_LE_RANDOM, &adapter->discov_type);
+ }
+
+ err = mgmt_start_discovery(adapter->dev_id, adapter->discov_type);
if (err < 0)
return btd_error_failed(msg, strerror(-err));
g_source_remove(adapter->discov_id);
adapter->discov_id = 0;
} else
- mgmt_stop_discovery(adapter->dev_id);
+ mgmt_stop_discovery(adapter->dev_id, adapter->discov_type);
}
static gboolean clean_connecting_state(GIOChannel *io, GIOCondition cond,
if (adapter->discov_suspended) {
adapter->discov_suspended = FALSE;
- mgmt_start_discovery(adapter->dev_id);
+ mgmt_start_discovery(adapter->dev_id, adapter->discov_type);
}
check_oob_bonding_complete(adapter, bdaddr, status);
static struct controller_info {
gboolean valid;
uint32_t current_settings;
- uint8_t discov_type;
} *controllers = NULL;
static int mgmt_sock = -1;
}
}
-int mgmt_start_discovery(int index)
+int mgmt_start_discovery(int index, uint8_t type)
{
char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_start_discovery)];
struct mgmt_hdr *hdr = (void *) buf;
struct mgmt_cp_start_discovery *cp = (void *) &buf[sizeof(*hdr)];
- struct controller_info *info = &controllers[index];
DBG("index %d", index);
- info->discov_type = 0;
-
- if (mgmt_bredr(info->current_settings))
- hci_set_bit(BDADDR_BREDR, &info->discov_type);
-
- if (mgmt_low_energy(info->current_settings)) {
- hci_set_bit(BDADDR_LE_PUBLIC, &info->discov_type);
- hci_set_bit(BDADDR_LE_RANDOM, &info->discov_type);
- }
-
- memset(buf, 0, sizeof(buf));
- hdr->opcode = htobs(MGMT_OP_START_DISCOVERY);
- hdr->len = htobs(sizeof(*cp));
- hdr->index = htobs(index);
-
- cp->type = info->discov_type;
-
- if (write(mgmt_sock, buf, sizeof(buf)) < 0) {
- int err = -errno;
- error("failed to write to MGMT socket: %s", strerror(-err));
- return err;
- }
-
- return 0;
-}
-
-int mgmt_start_le_scanning(int index)
-{
- char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_start_discovery)];
- struct mgmt_hdr *hdr = (void *) buf;
- struct mgmt_cp_start_discovery *cp = (void *) &buf[sizeof(*hdr)];
- struct controller_info *info = &controllers[index];
-
- DBG("index %d", index);
-
- if (!mgmt_low_energy(info->current_settings)) {
- error("scanning failed: Low Energy not enabled/supported");
- return -ENOTSUP;
- }
-
- info->discov_type = 0;
- hci_set_bit(BDADDR_LE_PUBLIC, &info->discov_type);
- hci_set_bit(BDADDR_LE_RANDOM, &info->discov_type);
-
memset(buf, 0, sizeof(buf));
hdr->opcode = htobs(MGMT_OP_START_DISCOVERY);
hdr->len = htobs(sizeof(*cp));
hdr->index = htobs(index);
- cp->type = info->discov_type;
+ cp->type = type;
if (write(mgmt_sock, buf, sizeof(buf)) < 0) {
int err = -errno;
return 0;
}
-int mgmt_stop_discovery(int index)
+int mgmt_stop_discovery(int index, uint8_t type)
{
char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_start_discovery)];
struct mgmt_hdr *hdr = (void *) buf;
struct mgmt_cp_start_discovery *cp = (void *) &buf[sizeof(*hdr)];
- struct controller_info *info = &controllers[index];
DBG("index %d", index);
hdr->len = htobs(sizeof(*cp));
hdr->index = htobs(index);
- cp->type = info->discov_type;
+ cp->type = type;
if (write(mgmt_sock, buf, sizeof(buf)) < 0)
return -errno;
int mgmt_setup(void);
void mgmt_cleanup(void);
-int mgmt_start_discovery(int index);
-int mgmt_start_le_scanning(int index);
-int mgmt_stop_discovery(int index);
+int mgmt_start_discovery(int index, uint8_t type);
+int mgmt_stop_discovery(int index, uint8_t type);
int mgmt_block_device(int index, const bdaddr_t *bdaddr, uint8_t bdaddr_type);
int mgmt_unblock_device(int index, const bdaddr_t *bdaddr, uint8_t bdaddr_type);