}
static int mgmt_discovering(int mgmt_sk, uint16_t index,
- struct mgmt_mode *ev, uint16_t len)
+ struct mgmt_ev_discovering *ev, uint16_t len)
{
if (len < sizeof(*ev)) {
fprintf(stderr, "Too short (%u bytes) discovering event\n",
return -EINVAL;
}
- if (ev->val == 0 && discovery)
+ if (ev->discovering == 0 && discovery)
exit(EXIT_SUCCESS);
if (monitor)
- printf("hci%u discovering %s\n", index,
- ev->val ? "on" : "off");
+ printf("hci%u type %u discovering %s\n", index,
+ ev->type, ev->discovering ? "on" : "off");
return 0;
}
uint32_t current_settings;
uint8_t dev_class[3];
GSList *connections;
+ uint8_t discov_type;
} *controllers = NULL;
static int mgmt_sock = -1;
static void add_controller(uint16_t index)
{
+ struct controller_info *info;
+
if (index > max_index) {
size_t size = sizeof(struct controller_info) * (index + 1);
max_index = index;
controllers = g_realloc(controllers, size);
}
- memset(&controllers[index], 0, sizeof(struct controller_info));
+ info = &controllers[index];
+
+ memset(info, 0, sizeof(*info));
- controllers[index].valid = TRUE;
+ info->valid = TRUE;
+
+ hci_set_bit(MGMT_ADDR_BREDR, &info->discov_type);
+ hci_set_bit(MGMT_ADDR_LE_PUBLIC, &info->discov_type);
+ hci_set_bit(MGMT_ADDR_LE_RANDOM, &info->discov_type);
DBG("Added controller %u", index);
}
static void mgmt_discovering(int sk, uint16_t index, void *buf, size_t len)
{
- struct mgmt_mode *ev = buf;
+ struct mgmt_ev_discovering *ev = buf;
struct controller_info *info;
struct btd_adapter *adapter;
return;
}
- DBG("Controller %u discovering %u", index, ev->val);
+ DBG("Controller %u type %u discovering %u", index,
+ ev->type, ev->discovering);
if (index > max_index) {
error("Unexpected index %u in discovering event", index);
if (!adapter)
return;
- adapter_set_discovering(adapter, ev->val);
+ adapter_set_discovering(adapter, ev->discovering);
}
static void mgmt_device_blocked(int sk, uint16_t index, void *buf, size_t len)
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);
- hci_set_bit(MGMT_ADDR_BREDR, &cp->type);
- hci_set_bit(MGMT_ADDR_LE_PUBLIC, &cp->type);
- hci_set_bit(MGMT_ADDR_LE_RANDOM, &cp->type);
+ cp->type = info->discov_type;
if (write(mgmt_sock, buf, sizeof(buf)) < 0)
return -errno;
static int mgmt_stop_discovery(int index)
{
- struct mgmt_hdr hdr;
+ 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);
- memset(&hdr, 0, sizeof(hdr));
- hdr.opcode = htobs(MGMT_OP_STOP_DISCOVERY);
- hdr.index = htobs(index);
+ memset(buf, 0, sizeof(buf));
+ hdr->opcode = htobs(MGMT_OP_STOP_DISCOVERY);
+ hdr->len = htobs(sizeof(*cp));
+ hdr->index = htobs(index);
- if (write(mgmt_sock, &hdr, sizeof(hdr)) < 0)
+ cp->type = info->discov_type;
+
+ if (write(mgmt_sock, buf, sizeof(buf)) < 0)
return -errno;
return 0;