Bluetooth: Add framework for device found filtering based on UUID
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 38 lines · Linux Kernel Mailing List
Gitweb: http://git.kernel.org/linus/;a=commit;h=b487b9ce9340a6e98d7f8277399304b23b7be456 Commit: b487b9ce9340a6e98d7f8277399304b23b7be456 Parent: bda157a40077447b25a1172a17b8ef81a2905cb7 Refname: refs/heads/master Author: Marcel Holtmann <[email protected]> AuthorDate: Fri Dec 5 10:55:57 2014 +0100 Committer: Johan Hedberg <[email protected]> CommitDate: Fri Dec 5 12:37:35 2014 +0200Bluetooth: Add framework for device found filtering based on UUID
Using Start Service Discovery provides the option to specifiy a list of UUID that are used to filter out device found events. This patch provides the framework for hooking up the UUID filter.
Signed-off-by Marcel Holtmann <[email protected]>Signed-off-by Johan Hedberg <[email protected]>--- net/bluetooth/mgmt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-)net/bluetooth/mgmt.c +5
-0@@ -6802,6 +6802,11 @@ void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,mgmt_pending_remove (cmd); } +static bool eir_has_uuids (u8 *eir,u16 eir_len,u16 uuid_count,u8 (*uuids)[16 ]) +{ +return false; +} +void mgmt_device_found (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 *dev_class,s8 rssi,u32 flags,u8 *eir,u16 eir_len,u8 *scan_rsp,u8 scan_rsp_len)
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6817
Quoted 4 lines
net/bluetooth/mgmt.c +1
-0@@ -6809,6 +6814,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,char buf[512 ];struct mgmt_ev_device_found *ev = (void *) buf;size_t ev_size; +bool match;
net/bluetooth/mgmt.c: In function ‘mgmt_device_found’:net/bluetooth/mgmt.c:6993: warning: ‘match’ may be used uninitialized in this function
All tests for "match" are protected by "if (hdev->discovery.uuid_count > 0)", so we only have to care about that case.
Quoted 11 lines
net/bluetooth/mgmt.c +4
-1/* Don't send events for a non-kernel initiated discovery. With * LE one exception is if we have pend_le_reports > 0 in which @@ -6843,15 +6849,59 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, ev->rssi = rssi; ev->flags =cpu_to_le32 (flags); -if (eir_len >0 ) +if (eir_len >0 ) { +/* When using service discovery and a list of UUID is +* provided, results with no matching UUID should be +* dropped. In case there is a match the result is
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6865
Quoted 10 lines
net/bluetooth/mgmt.c +10
-0+* kept and checking possible scan response data +* will be skipped. +*/ +if (hdev->discovery.uuid_count >0 ) { + match =eir_has_uuids (eir, eir_len, + hdev->discovery.uuid_count, + hdev->discovery.uuids); +if (!match) +return ; + }
If we get here and if (hdev->discovery.uuid_count > 0), "match" must be true.
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6875
Quoted 10 lines
net/bluetooth/mgmt.c +9
-0+ +/* Copy EIR or advertising data into event */ memcpy (ev->eir, eir, eir_len); + }else { +/* When using service discovery and a list of UUID is +* provided, results with empty EIR or advertising data +* should be dropped since they do not match any UUID. +*/ +if (hdev->discovery.uuid_count >0 ) +return ;
We will never get here if (hdev->discovery.uuid_count > 0).
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6876
Quoted 1 line
net/bluetooth/mgmt.c +1
-0+ }
Hence if we get here and if (hdev->discovery.uuid_count > 0), "match" is always true.
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6888
Quoted 13 lines
net/bluetooth/mgmt.c +8
-1if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV)) eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, dev_class, 3); -if (scan_rsp_len >0 ) + if (scan_rsp_len > 0) { + /* When using service discovery and a list of UUID is + * provided, results with no matching UUID should be + * dropped if there is no previous match from the + * advertising data. + */ + if (hdev->discovery.uuid_count > 0) { + if (!match && !eir_has_uuids(scan_rsp, scan_rsp_len,
"match" is true, so this whole block is useless.
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6901
Quoted 13 lines
net/bluetooth/mgmt.c +12
-0+ hdev->discovery.uuid_count, + hdev->discovery.uuids)) + return; + } + +/* Append scan response data to event */ memcpy (ev->eir + eir_len, scan_rsp, scan_rsp_len); + }else { +/* When using service discovery and a list of UUID is +* provided, results with empty scan response and no +* previous matched advertising data should be dropped. +*/ +if (hdev->discovery.uuid_count >0 && !match)
"match" is true, so this whole block is useless.
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6906
Quoted 5 lines
net/bluetooth/mgmt.c +2
-0+return ; + } ev->eir_len =cpu_to_le16 (eir_len + scan_rsp_len); ev_size =sizeof (*ev) + eir_len + scan_rsp_len;
Is my analysis correct?
Am I missing something?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hi Geert,
Quoted 38 lines
Quoted 38 lines
Gitweb: http://git.kernel.org/linus/;a=commit;h=b487b9ce9340a6e98d7f8277399304b23b7be456 Commit: b487b9ce9340a6e98d7f8277399304b23b7be456 Parent: bda157a40077447b25a1172a17b8ef81a2905cb7 Refname: refs/heads/master Author: Marcel Holtmann <[email protected]> AuthorDate: Fri Dec 5 10:55:57 2014 +0100 Committer: Johan Hedberg <[email protected]> CommitDate: Fri Dec 5 12:37:35 2014 +0200Bluetooth: Add framework for device found filtering based on UUID
Using Start Service Discovery provides the option to specifiy a list of UUID that are used to filter out device found events. This patch provides the framework for hooking up the UUID filter.
Signed-off-by Marcel Holtmann <[email protected]>Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/mgmt.c| 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--1 file changed, 52 insertions(+), 2 deletions(-)net/bluetooth/mgmt.c +5
-0@@ -6802,6 +6802,11 @@ void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,mgmt_pending_remove (cmd); } +static bool eir_has_uuids (u8 *eir,u16 eir_len,u16 uuid_count,u8 (*uuids)[16 ]) +{ +return false; +} +void mgmt_device_found (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 *dev_class,s8 rssi,u32 flags,u8 *eir,u16 eir_len,u8 *scan_rsp,u8 scan_rsp_len)@@ -6809,6 +6814,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
Quoted 8 lines
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6817
Quoted 4 lines
net/bluetooth/mgmt.c +1
-0char buf[512 ];struct mgmt_ev_device_found *ev = (void *) buf;size_t ev_size; +bool match;
net/bluetooth/mgmt.c: In function ‘mgmt_device_found’:net/bluetooth/mgmt.c:6993: warning: ‘match’ may be used uninitialized in this function
I did not get this warning, but I did consider it happening and my conclusion was that it will not and thus no need for initializing this to false.
Quoted 18 lines
All tests for "match" are protected by "if (
hdev->discovery.uuid_count> 0)", so we only have to care about that case.Quoted 15 lines
net/bluetooth/mgmt.c +8
-1/* Don't send events for a non-kernel initiated discovery. With * LE one exception is if we have pend_le_reports > 0 in which @@ -6843,15 +6849,59 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, ev->rssi = rssi; ev->flags =cpu_to_le32 (flags); -if (eir_len >0 ) +if (eir_len >0 ) { +/* When using service discovery and a list of UUID is +* provided, results with no matching UUID should be +* dropped. In case there is a match the result is +* kept and checking possible scan response data +* will be skipped. +*/ +if (hdev->discovery.uuid_count >0 ) {
Quoted 8 lines
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6865
Quoted 6 lines
net/bluetooth/mgmt.c +6
-0+ match =eir_has_uuids (eir, eir_len, + hdev->discovery.uuid_count, + hdev->discovery.uuids); +if (!match) +return ; + }If we get here and if (
hdev->discovery.uuid_count> 0), "match" must be true.
We need to keep the match state to optimize the later branch. There is no point in running through the second list if the first one already has a match.
Actually this is the bogus one here. The only valid reason to leave here is when also !scan_rsp_len.
Quoted 34 lines
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6875
Quoted 10 lines
net/bluetooth/mgmt.c +9
-0+ +/* Copy EIR or advertising data into event */ memcpy (ev->eir, eir, eir_len); + }else { +/* When using service discovery and a list of UUID is +* provided, results with empty EIR or advertising data +* should be dropped since they do not match any UUID. +*/ +if (hdev->discovery.uuid_count >0 ) +return ;We will never get here if (
hdev->discovery.uuid_count> 0).net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6876
Quoted 1 line
net/bluetooth/mgmt.c +1
-0+ }Hence if we get here and if (
hdev->discovery.uuid_count> 0), "match" is always true.net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6888
Quoted 13 lines
net/bluetooth/mgmt.c +8
-1if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV)) eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, dev_class, 3); -if (scan_rsp_len >0 ) + if (scan_rsp_len > 0) { + /* When using service discovery and a list of UUID is + * provided, results with no matching UUID should be + * dropped if there is no previous match from the + * advertising data. + */ + if (hdev->discovery.uuid_count > 0) { + if (!match && !eir_has_uuids(scan_rsp, scan_rsp_len,
Quoted 1 line
"match" is true, so this whole block is useless.
This was meant to not bother checking the second data block since we already had a match in the first one. However we need to append the second data block to the first one before sending out the event.
Quoted 15 lines
Quoted 4 lines
net/bluetooth/mgmt.c +3
-0+ hdev->discovery.uuid_count, + hdev->discovery.uuids)) + return;net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6901
Quoted 10 lines
net/bluetooth/mgmt.c +9
-0+ } + +/* Append scan response data to event */ memcpy (ev->eir + eir_len, scan_rsp, scan_rsp_len); + }else { +/* When using service discovery and a list of UUID is +* provided, results with empty scan response and no +* previous matched advertising data should be dropped. +*/ +if (hdev->discovery.uuid_count >0 && !match)
Quoted 1 line
"match" is true, so this whole block is useless.
This was suppose to do what the comment says, but we never get here :(
Quoted 9 lines
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6906
Quoted 6 lines
net/bluetooth/mgmt.c +2
-0+return ; + } ev->eir_len =cpu_to_le16 (eir_len + scan_rsp_len); ev_size =sizeof (*ev) + eir_len + scan_rsp_len;Is my analysis correct?
Am I missing something?
Your analysis seems correct and even while putting in tons of comments, my brain still messed it up.
I looked at the whole code again and this is would should make all statements work correctly.
@@ -7085,7 +7085,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
match = eir_has_uuids(eir, eir_len,
hdev->discovery.uuid_count,
hdev->discovery.uuids);
- if (!match)
+ if (!match && !scan_rsp_len)
return;
}Regards
Marcel
Hi Marcel,
Quoted 12 lines · Marcel Holtmann
Quoted 11 lines
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6817
Quoted 7 lines
net/bluetooth/mgmt.c +1
-0@@ -6809,6 +6814,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,char buf[512 ];struct mgmt_ev_device_found *ev = (void *) buf;size_t ev_size; +bool match;
net/bluetooth/mgmt.c: In function ‘mgmt_device_found’:net/bluetooth/mgmt.c:6993: warning: ‘match’ may be used uninitialized in this function
Quoted 1 line
I did not get this warning, but I did consider it happening and my conclusion was that it will not and thus no need for initializing this to false.
It's highly compiler-dependent, and it's the reason I'll stick to gcc 4.1.2 as long it
helps me finding several real issues during each merge window.
Quoted 27 lines
Quoted 18 lines
All tests for "match" are protected by "if (
hdev->discovery.uuid_count> 0)", so we only have to care about that case.Quoted 15 lines
net/bluetooth/mgmt.c +8
-1/* Don't send events for a non-kernel initiated discovery. With * LE one exception is if we have pend_le_reports > 0 in which @@ -6843,15 +6849,59 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, ev->rssi = rssi; ev->flags =cpu_to_le32 (flags); -if (eir_len >0 ) +if (eir_len >0 ) { +/* When using service discovery and a list of UUID is +* provided, results with no matching UUID should be +* dropped. In case there is a match the result is +* kept and checking possible scan response data +* will be skipped. +*/ +if (hdev->discovery.uuid_count >0 ) {Quoted 8 lines
net/bluetooth/mgmt.c void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 6865
Quoted 6 lines
net/bluetooth/mgmt.c +6
-0+ match =eir_has_uuids (eir, eir_len, + hdev->discovery.uuid_count, + hdev->discovery.uuids); +if (!match) +return ; + }If we get here and if (
hdev->discovery.uuid_count> 0), "match" must be true.
Quoted 3 lines
We need to keep the match state to optimize the later branch. There is no point in running through the second list if the first one already has a match.
Actually this is the bogus one here. The only valid reason to leave here is when also !scan_rsp_len.
OK.
Quoted 8 lines
Quoted 2 lines
Is my analysis correct?
Am I missing something?Your analysis seems correct and even while putting in tons of comments, my brain still messed it up.
I looked at the whole code again and this is would should make all statements work correctly.
Review void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · line 7090
Quoted 7 lines
(quoted diff) +1
-1@@ -7085,7 +7085,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, match = eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, hdev->discovery.uuids); - if (!match) + if (!match && !scan_rsp_len) return; }
Thanks, that indeed changes all further checks for match to make sense.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds