From c19756d3729d0770bf1e266ad9817d6e86bce667 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 22 Mar 2014 19:30:18 +0200 Subject: [PATCH] core: Update btd_adapter_find_device to also match the address type This is necessary to do accurate matching for LE devices. --- plugins/sixaxis.c | 3 ++- profiles/audio/avctp.c | 3 ++- profiles/audio/avdtp.c | 3 ++- profiles/input/device.c | 2 +- profiles/input/server.c | 4 ++-- src/adapter.c | 38 +++++++++++++++++++++++--------------- src/adapter.h | 3 ++- src/attrib-server.c | 2 +- src/profile.c | 2 +- 9 files changed, 36 insertions(+), 24 deletions(-) diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c index 4fdeff350..8045448f1 100644 --- a/plugins/sixaxis.c +++ b/plugins/sixaxis.c @@ -197,7 +197,8 @@ static bool setup_device(int fd, int index, struct btd_adapter *adapter) /* This can happen if controller was plugged while already connected * eg. to charge up battery. * Don't set LEDs in that case, hence return false */ - device = btd_adapter_find_device(adapter, &device_bdaddr); + device = btd_adapter_find_device(adapter, &device_bdaddr, + BDADDR_BREDR); if (device && btd_device_is_connected(device)) return false; diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c index f88e6346c..74d351263 100644 --- a/profiles/audio/avctp.c +++ b/profiles/audio/avctp.c @@ -1399,7 +1399,8 @@ static void avctp_confirm_cb(GIOChannel *chan, gpointer data) DBG("AVCTP: incoming connect from %s", address); - device = btd_adapter_find_device(adapter_find(&src), &dst); + device = btd_adapter_find_device(adapter_find(&src), &dst, + BDADDR_BREDR); if (!device) return; diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c index fbf61f09b..8a7d1c0e7 100644 --- a/profiles/audio/avdtp.c +++ b/profiles/audio/avdtp.c @@ -2467,7 +2467,8 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data) DBG("AVDTP: incoming connect from %s", address); - device = btd_adapter_find_device(adapter_find(&src), &dst); + device = btd_adapter_find_device(adapter_find(&src), &dst, + BDADDR_BREDR); if (!device) goto drop; diff --git a/profiles/input/device.c b/profiles/input/device.c index 5235dfd08..a2329c614 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -875,7 +875,7 @@ static struct input_device *find_device(const bdaddr_t *src, struct btd_device *device; struct btd_service *service; - device = btd_adapter_find_device(adapter_find(src), dst); + device = btd_adapter_find_device(adapter_find(src), dst, BDADDR_BREDR); if (device == NULL) return NULL; diff --git a/profiles/input/server.c b/profiles/input/server.c index 650ece163..772a605fb 100644 --- a/profiles/input/server.c +++ b/profiles/input/server.c @@ -101,7 +101,7 @@ static void sixaxis_browse_sdp(const bdaddr_t *src, const bdaddr_t *dst, struct btd_device *device; struct sixaxis_data *data; - device = btd_adapter_find_device(adapter_find(src), dst); + device = btd_adapter_find_device(adapter_find(src), dst, BDADDR_BREDR); if (!device) return; @@ -120,7 +120,7 @@ static bool dev_is_sixaxis(const bdaddr_t *src, const bdaddr_t *dst) struct btd_device *device; uint16_t vid, pid; - device = btd_adapter_find_device(adapter_find(src), dst); + device = btd_adapter_find_device(adapter_find(src), dst, BDADDR_BREDR); if (!device) return false; diff --git a/src/adapter.c b/src/adapter.c index e3de8cf7d..61fae2a55 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -725,18 +725,21 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name) } struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter, - const bdaddr_t *dst) + const bdaddr_t *dst, + uint8_t bdaddr_type) { + struct device_addr_type addr; struct btd_device *device; - char addr[18]; GSList *list; if (!adapter) return NULL; - ba2str(dst, addr); + bacpy(&addr.bdaddr, dst); + addr.bdaddr_type = bdaddr_type; - list = g_slist_find_custom(adapter->devices, addr, device_address_cmp); + list = g_slist_find_custom(adapter->devices, &addr, + device_addr_type_cmp); if (!list) return NULL; @@ -1119,7 +1122,7 @@ struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter, if (!adapter) return NULL; - device = btd_adapter_find_device(adapter, addr); + device = btd_adapter_find_device(adapter, addr, addr_type); if (device) return device; @@ -4676,7 +4679,7 @@ static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst, struct btd_device *device; static guint id = 0; - device = btd_adapter_find_device(adapter, dst); + device = btd_adapter_find_device(adapter, dst, BDADDR_BREDR); if (!device) return 0; @@ -4877,7 +4880,7 @@ int btd_adapter_pincode_reply(struct btd_adapter *adapter, /* Since a pincode was requested, update the starting time to * the point where the pincode is provided. */ - device = btd_adapter_find_device(adapter, bdaddr); + device = btd_adapter_find_device(adapter, bdaddr, BDADDR_BREDR); device_bonding_restart_timer(device); id = mgmt_reply(adapter->mgmt, MGMT_OP_PIN_CODE_REPLY, @@ -5211,7 +5214,7 @@ static void bonding_complete(struct btd_adapter *adapter, if (status == 0) device = btd_adapter_get_device(adapter, bdaddr, addr_type); else - device = btd_adapter_find_device(adapter, bdaddr); + device = btd_adapter_find_device(adapter, bdaddr, addr_type); if (device != NULL) device_bonding_complete(device, addr_type, status); @@ -5238,7 +5241,7 @@ static void bonding_attempt_complete(struct btd_adapter *adapter, if (status == 0) device = btd_adapter_get_device(adapter, bdaddr, addr_type); else - device = btd_adapter_find_device(adapter, bdaddr); + device = btd_adapter_find_device(adapter, bdaddr, addr_type); if (status == MGMT_STATUS_AUTH_FAILED && adapter->pincode_requested) { /* On faliure, issue a bonding_retry if possible. */ @@ -5397,7 +5400,7 @@ static void dev_disconnected(struct btd_adapter *adapter, DBG("Device %s disconnected, reason %u", dst, reason); - device = btd_adapter_find_device(adapter, &addr->bdaddr); + device = btd_adapter_find_device(adapter, &addr->bdaddr, addr->type); if (device) adapter_remove_connection(adapter, device, addr->type); @@ -5810,7 +5813,8 @@ static void new_irk_callback(uint16_t index, uint16_t length, if (bacmp(&ev->rpa, BDADDR_ANY)) { device = btd_adapter_get_device(adapter, &ev->rpa, BDADDR_LE_RANDOM); - duplicate = btd_adapter_find_device(adapter, &addr->bdaddr); + duplicate = btd_adapter_find_device(adapter, &addr->bdaddr, + addr->type); if (duplicate == device) duplicate = NULL; } else { @@ -6205,7 +6209,8 @@ static void device_blocked_callback(uint16_t index, uint16_t length, ba2str(&ev->addr.bdaddr, addr); DBG("hci%u %s blocked", index, addr); - device = btd_adapter_find_device(adapter, &ev->addr.bdaddr); + device = btd_adapter_find_device(adapter, &ev->addr.bdaddr, + ev->addr.type); if (device) device_block(device, TRUE); } @@ -6226,7 +6231,8 @@ static void device_unblocked_callback(uint16_t index, uint16_t length, ba2str(&ev->addr.bdaddr, addr); DBG("hci%u %s unblocked", index, addr); - device = btd_adapter_find_device(adapter, &ev->addr.bdaddr); + device = btd_adapter_find_device(adapter, &ev->addr.bdaddr, + ev->addr.type); if (device) device_unblock(device, FALSE, TRUE); } @@ -6248,7 +6254,8 @@ static void connect_failed_callback(uint16_t index, uint16_t length, DBG("hci%u %s status %u", index, addr, ev->status); - device = btd_adapter_find_device(adapter, &ev->addr.bdaddr); + device = btd_adapter_find_device(adapter, &ev->addr.bdaddr, + ev->addr.type); if (device) { /* If the device is in a bonding process cancel any auth request * sent to the agent before proceeding, but keep the bonding @@ -6294,7 +6301,8 @@ static void unpaired_callback(uint16_t index, uint16_t length, DBG("hci%u addr %s", index, addr); - device = btd_adapter_find_device(adapter, &ev->addr.bdaddr); + device = btd_adapter_find_device(adapter, &ev->addr.bdaddr, + ev->addr.type); if (!device) { warn("No device object for unpaired device %s", addr); return; diff --git a/src/adapter.h b/src/adapter.h index e497d1bde..49eca11e1 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -81,7 +81,8 @@ struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter, sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter); struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter, - const bdaddr_t *dst); + const bdaddr_t *dst, + uint8_t dst_type); const char *adapter_get_path(struct btd_adapter *adapter); const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter); diff --git a/src/attrib-server.c b/src/attrib-server.c index 3f579bbbe..889ef204a 100644 --- a/src/attrib-server.c +++ b/src/attrib-server.c @@ -1162,7 +1162,7 @@ guint attrib_channel_attach(GAttrib *attrib) channel = g_new0(struct gatt_channel, 1); channel->server = server; - device = btd_adapter_find_device(server->adapter, &dst); + device = btd_adapter_find_device(server->adapter, &dst, bdaddr_type); if (device == NULL) { error("Device object not found for attrib server"); g_free(channel); diff --git a/src/profile.c b/src/profile.c index 4b9d8e559..f6aa97018 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1039,7 +1039,7 @@ static struct ext_io *create_conn(struct ext_io *server, GIOChannel *io, GIOCondition cond; char addr[18]; - device = btd_adapter_find_device(server->adapter, dst); + device = btd_adapter_find_device(server->adapter, dst, BDADDR_BREDR); if (device == NULL) { ba2str(dst, addr); error("%s device %s not found", server->ext->name, addr);