Bluetooth: Add support for entering limited discoverable mode
Subsystems (2)
Marcel Holtmann
maintainerPATCH 1/1 Bluetooth: Add support for entering limited discoverable mode
The limited discoverable mode should be used when a device is only discoverable for a certain amount of time and after that it returns back into being non-discoverable.
The management interface allows to specify a timeout parameter when makeing a device discoverable. If such a timeout is specified or changed, enter limited discoverable mode. Otherwise enter general discoverable mode.
Devices in limited discoverable mode can still be found by the general discovery procedure. It is mandatory that a device sets both GIAC and LIAC when entering limited discoverable mode.
--- include/net/bluetooth/hci.h | 6 ++++++ net/bluetooth/mgmt.c | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-)
include/net/bluetooth/hci.h +6 -0
@@ -823,6 +823,12 @@ struct hci_rp_read_num_supported_iac {#define HCI_OP_READ_CURRENT_IAC_LAP 0x0c39 +#define HCI_OP_WRITE_CURRENT_IAC_LAP 0x0c3a +struct hci_cp_write_current_iac_lap { +__u8 num_iac; +__u8 iac_lap[6 ]; +} __packed; +#define HCI_OP_WRITE_INQUIRY_MODE 0x0c45#define HCI_MAX_EIR_LENGTH 240
net/bluetooth/mgmt.c +37 -4
61 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Hi Marcel,
net/bluetooth/mgmt.c static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, · line 1083
Quoted 5 lines · Marcel Holtmann
net/bluetooth/mgmt.c +5
-0+if (cp->val) { +struct hci_cp_write_current_iac_lap cp; + +if (timeout >0 ) { +/* Limited discoverable mode */
Wouldn't we want to follow the recommendation from the Core spec here, volume 3, part C, section 4.1.2.1:
"A Bluetooth device should not be in limited discoverable mode for more than TGAP(104)"
TGAP(104) in turn is defined as 1 minute (vol 3, part C, Appendix A).
Johan
Hi,
Quoted 10 lines · Johan Hedberg
net/bluetooth/mgmt.c static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, · line 1083
Quoted 5 lines · Marcel Holtmann
net/bluetooth/mgmt.c +5
-0+if (cp->val) { +struct hci_cp_write_current_iac_lap cp; + +if (timeout >0 ) { +/* Limited discoverable mode */ Wouldn't we want to follow the recommendation from the Core spec here, volume 3, part C, section 4.1.2.1:
Quoted 4 lines
"A Bluetooth device should not be in limited discoverable mode for more than TGAP(104)"
TGAP(104) in turn is defined as 1 minute (vol 3, part C, Appendix A).
We might even want to limit this to 30 seconds so the same can be used for LE once this is hooked up to advertising:
TGAP(lim_adv_timeout) 30.72s Maximum time to remain Required value
advertising when in the limited discoverable mode
Johan
Marcel Holtmann
maintainerHi Johan,
Quoted 9 lines
net/bluetooth/mgmt.c static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, · line 1083
Quoted 5 lines
net/bluetooth/mgmt.c +5
-0+if (cp->val) { +struct hci_cp_write_current_iac_lap cp; + +if (timeout >0 ) { +/* Limited discoverable mode */ Wouldn't we want to follow the recommendation from the Core spec here, volume 3, part C, section 4.1.2.1:
Quoted 4 lines
"A Bluetooth device should not be in limited discoverable mode for more than TGAP(104)"
TGAP(104) in turn is defined as 1 minute (vol 3, part C, Appendix A).
I was not going to be this strict. So yes, userspace can violate the GAP part here, but it might be a good idea to ensure that when a too large value is entered we stick with general discoverable mode. However is this really worth it.
Another option is to just reject too large timeout values as invalid parameters and force userspace to implement large timeouts with general discoverable mode in userspace.
Regards
Marcel
Hi Marcel,
Quoted 12 lines · Marcel Holtmann
Quoted 12 lines
net/bluetooth/mgmt.c static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, · line 1083
Quoted 5 lines
net/bluetooth/mgmt.c +5
-0+if (cp->val) { +struct hci_cp_write_current_iac_lap cp; + +if (timeout >0 ) { +/* Limited discoverable mode */ Wouldn't we want to follow the recommendation from the Core spec here, volume 3, part C, section 4.1.2.1:
"A Bluetooth device should not be in limited discoverable mode for more than TGAP(104)"
Quoted 6 lines
Quoted 1 line
TGAP(104) in turn is defined as 1 minute (vol 3, part C, Appendix A).
I was not going to be this strict. So yes, userspace can violate the GAP part here, but it might be a good idea to ensure that when a too large value is entered we stick with general discoverable mode. However is this really worth it.
For Advertising the max value is actually not just a recommendation but a requirement (check my other mail), so at least there we should probably enforce it. And if we have to enforce it for LE we might as well do it for BR/EDR too. It's anyway a rather simple change to the if-statement.
Quoted 3 lines
Another option is to just reject too large timeout values as invalid parameters and force userspace to implement large timeouts with general discoverable mode in userspace.
I don't think it's a good idea to force this kind of special handling to user space (not just the requirement to know where the limits go but also the need to implement a separate timer).
Johan
Marcel Holtmann
maintainerHi Johan,
Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
net/bluetooth/mgmt.c static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, · line 1083
Quoted 5 lines
net/bluetooth/mgmt.c +5
-0+if (cp->val) { +struct hci_cp_write_current_iac_lap cp; + +if (timeout >0 ) { +/* Limited discoverable mode */ Wouldn't we want to follow the recommendation from the Core spec here, volume 3, part C, section 4.1.2.1:
"A Bluetooth device should not be in limited discoverable mode for more than TGAP(104)"
Quoted 6 lines
Quoted 1 line
TGAP(104) in turn is defined as 1 minute (vol 3, part C, Appendix A).
I was not going to be this strict. So yes, userspace can violate the GAP part here, but it might be a good idea to ensure that when a too large value is entered we stick with general discoverable mode. However is this really worth it.
For Advertising the max value is actually not just a recommendation but a requirement (check my other mail), so at least there we should probably enforce it. And if we have to enforce it for LE we might as well do it for BR/EDR too. It's anyway a rather simple change to the if-statement.
Quoted 7 lines
Quoted 3 lines
Another option is to just reject too large timeout values as invalid parameters and force userspace to implement large timeouts with general discoverable mode in userspace.
I don't think it's a good idea to force this kind of special handling to user space (not just the requirement to know where the limits go but also the need to implement a separate timer).
This sounds also a bit like black magic. Userspace needs to know that a small value enters limited discoverable mode and a large one sticks with general discoverable mode. We might should have added a flag to the command in the first place. However I think our general intention was that with a timeout we do limited discoverable mode and without a timeout we do general discoverable mode.
I was complaining on why we bothered with a timeout for this parameter when building src/share/mgmt.[ch] and cleaning up some of the core adapter handling. Mainly because for PairableTimeout D-Bus property we have to run our own timer and for DiscoverableTimeout property we rely on the kernel. And in the end just running your own timeout was a lot simpler, then integrating with the kernel.
So I would be actually fine just saying with timeout that is limited discoverable mode. If you want general discoverable mode with a timeout, then you have to run this by yourself.
Then again, nothing stops us from introducing mode 0x02 for limited discoverable if you feel that we should keep the general discoverable mode with a timeout.
Regards
Marcel
Hi Marcel,
Quoted 47 lines · Marcel Holtmann
Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
net/bluetooth/mgmt.c static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, · line 1083
Quoted 5 lines
net/bluetooth/mgmt.c +5
-0+if (cp->val) { +struct hci_cp_write_current_iac_lap cp; + +if (timeout >0 ) { +/* Limited discoverable mode */ Wouldn't we want to follow the recommendation from the Core spec here, volume 3, part C, section 4.1.2.1:
"A Bluetooth device should not be in limited discoverable mode for more than TGAP(104)"
Quoted 6 lines
Quoted 1 line
TGAP(104) in turn is defined as 1 minute (vol 3, part C, Appendix A).
I was not going to be this strict. So yes, userspace can violate the GAP part here, but it might be a good idea to ensure that when a too large value is entered we stick with general discoverable mode. However is this really worth it.
For Advertising the max value is actually not just a recommendation but a requirement (check my other mail), so at least there we should probably enforce it. And if we have to enforce it for LE we might as well do it for BR/EDR too. It's anyway a rather simple change to the if-statement.
Quoted 7 lines
Quoted 3 lines
Another option is to just reject too large timeout values as invalid parameters and force userspace to implement large timeouts with general discoverable mode in userspace.
I don't think it's a good idea to force this kind of special handling to user space (not just the requirement to know where the limits go but also the need to implement a separate timer).
This sounds also a bit like black magic. Userspace needs to know that a small value enters limited discoverable mode and a large one sticks with general discoverable mode. We might should have added a flag to the command in the first place. However I think our general intention was that with a timeout we do limited discoverable mode and without a timeout we do general discoverable mode.
I was complaining on why we bothered with a timeout for this parameter when building src/share/mgmt.[ch] and cleaning up some of the core adapter handling. Mainly because for PairableTimeout D-Bus property we have to run our own timer and for DiscoverableTimeout property we rely on the kernel. And in the end just running your own timeout was a lot simpler, then integrating with the kernel.
Quoted 3 lines
So I would be actually fine just saying with timeout that is limited discoverable mode. If you want general discoverable mode with a timeout, then you have to run this by yourself.
Fair enough, and I really don't want to complicate this more by adding a new 0x02 value either. The patch has now been pushed to bluetooth-next.
Johan
Marcel Holtmann
maintainerHi Johan,
Quoted 47 lines
Quoted 47 lines
Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
net/bluetooth/mgmt.c static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, · line 1083
Quoted 5 lines
net/bluetooth/mgmt.c +5
-0+if (cp->val) { +struct hci_cp_write_current_iac_lap cp; + +if (timeout >0 ) { +/* Limited discoverable mode */ Wouldn't we want to follow the recommendation from the Core spec here, volume 3, part C, section 4.1.2.1:
"A Bluetooth device should not be in limited discoverable mode for more than TGAP(104)"
Quoted 6 lines
Quoted 1 line
TGAP(104) in turn is defined as 1 minute (vol 3, part C, Appendix A).
I was not going to be this strict. So yes, userspace can violate the GAP part here, but it might be a good idea to ensure that when a too large value is entered we stick with general discoverable mode. However is this really worth it.
For Advertising the max value is actually not just a recommendation but a requirement (check my other mail), so at least there we should probably enforce it. And if we have to enforce it for LE we might as well do it for BR/EDR too. It's anyway a rather simple change to the if-statement.
Quoted 7 lines
Quoted 3 lines
Another option is to just reject too large timeout values as invalid parameters and force userspace to implement large timeouts with general discoverable mode in userspace.
I don't think it's a good idea to force this kind of special handling to user space (not just the requirement to know where the limits go but also the need to implement a separate timer).
This sounds also a bit like black magic. Userspace needs to know that a small value enters limited discoverable mode and a large one sticks with general discoverable mode. We might should have added a flag to the command in the first place. However I think our general intention was that with a timeout we do limited discoverable mode and without a timeout we do general discoverable mode.
I was complaining on why we bothered with a timeout for this parameter when building src/share/mgmt.[ch] and cleaning up some of the core adapter handling. Mainly because for PairableTimeout D-Bus property we have to run our own timer and for DiscoverableTimeout property we rely on the kernel. And in the end just running your own timeout was a lot simpler, then integrating with the kernel.
Quoted 6 lines
Quoted 3 lines
So I would be actually fine just saying with timeout that is limited discoverable mode. If you want general discoverable mode with a timeout, then you have to run this by yourself.
Fair enough, and I really don't want to complicate this more by adding a new
0x02value either. The patch has now been pushed to bluetooth-next.
and I was tending towards reworking the patch to add a new 0x02 mode. In that mode we enforce the correct timeout values ahead of time.
I am no longer convinced that we are doing the right thing here. I was 100% sure yesterday and today, I would start exploring other options.
Regards
Marcel