Bluetooth: Cleanups and LE advertising support
Subsystems (2)
cover Bluetooth: Cleanups and LE advertising support
Hi,
This patch set is a combination of cleanups that I had in my tree (patches 1-3) a fix for set_powered (patch 4) and a new mgmt setting to allow enabling LE advertising (patches 5-8). What's still open is whether we want to rename the internal HCI_LE_PERIPHERAL flag to match the "advertising" name used for the mgmt setting, however that can be done as an independent patch on top of this set if necessary.
I've tested this through my own additions to user space btmgmt and mgmt-tester tools. Once the general API is acked I'll push those additions to bluez.git.
Johan
----------------------------------------------------------------
Johan Hedberg (8):
Bluetooth: Add clarifying comment to bt_sock_wait_state()
Bluetooth: Clean up socket locking in l2cap_sock_recvmsg
Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
Bluetooth: Fix busy return for mgmt_set_powered in some cases
Bluetooth: Move mgmt response convenience functions to a better location
Bluetooth: Use async request for LE enable/disable
Bluetooth: Add new mgmt setting for LE advertising
Bluetooth: Add new mgmt_set_advertising command
include/net/bluetooth/hci_core.h | 1 - include/net/bluetooth/mgmt.h | 3 + net/bluetooth/af_bluetooth.c | 1 + net/bluetooth/hci_core.c | 4 +- net/bluetooth/hci_event.c | 11 -- net/bluetooth/l2cap_sock.c | 5 +- net/bluetooth/mgmt.c | 276 ++++++++++++++++++++++++++------------ 7 files changed, 199 insertions(+), 102 deletions(-)
PATCH 1/8 Bluetooth: Add clarifying comment to bt_sock_wait_state()
From: Johan Hedberg <[email protected]>
The bt_sock_wait_state requires the sk lock to be held (through lock_sock) so document it clearly in the code.
--- net/bluetooth/af_bluetooth.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/af_bluetooth.c +1 -0
@@ -490,6 +490,7 @@ int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) }EXPORT_SYMBOL (bt_sock_ioctl); +/* This function expects the sk lock to be held when called */ int bt_sock_wait_state (struct sock *sk,int state,unsigned long timeo) {DECLARE_WAITQUEUE (wait, current);
Signature · 1 line
1.8.4.rc3
Re: [PATCH 1/8] Bluetooth: Add clarifying comment to bt_sock_wait_state()
Hi Johan,
Quoted 7 lines
The
bt_sock_wait_staterequires the sk lock to be held (throughlock_sock) so document it clearly in the code.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/af_bluetooth.c| 1 +1 file changed, 1 insertion(+)
Regards
Marcel
PATCH 2/8 Bluetooth: Clean up socket locking in l2cap_sock_recvmsg
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch cleans up the locking login in l2cap_sock_recvmsg by pairing up each lock_sock call with a release_sock call. The function already has a "done" label that handles releasing the socket and returning from the function so the fix is rather simple.
--- net/bluetooth/l2cap_sock.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/bluetooth/l2cap_sock.c +2 -3
@@ -795,7 +795,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, {struct sock *sk = sock->sk;struct l2cap_pinfo *pi =l2cap_pi (sk); -int err; +int err =0 ;lock_sock (sk);
@@ -805,8 +805,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, pi->chan->state =BT_CONFIG ;__l2cap_connect_rsp_defer (pi->chan); -release_sock (sk); -return 0 ; + goto done; }release_sock (sk);
Signature · 1 line
1.8.4.rc3
Marcel Holtmann
maintainerRe: [PATCH 2/8] Bluetooth: Clean up socket locking in l2cap_sock_recvmsg
Hi Johan,
Quoted 24 lines
This patch cleans up the locking login in
l2cap_sock_recvmsgby pairing up eachlock_sockcall with arelease_sockcall. The function already has a "done" label that handles releasing the socket and returning from the function so the fix is rather simple.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/l2cap_sock.c| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)net/bluetooth/l2cap_sock.c +1
-1@@ -795,7 +795,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, {struct sock *sk = sock->sk;struct l2cap_pinfo *pi =l2cap_pi (sk); -int err; +int err =0 ;lock_sock (sk);
net/bluetooth/l2cap_sock.c static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, · line 809
Quoted 5 lines
net/bluetooth/l2cap_sock.c +0
-2@@ -805,8 +805,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, pi->chan->state =BT_CONFIG ;__l2cap_connect_rsp_defer (pi->chan); -release_sock (sk); -return 0 ;
can we just do
err = 0;
here instead of declaring it global.
net/bluetooth/l2cap_sock.c static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, · line 811
Quoted 4 lines
net/bluetooth/l2cap_sock.c +1
-0+ goto done; }release_sock (sk);
Regards
Marcel
PATCH 3/8 Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
In reply to [email protected]From: Johan Hedberg <[email protected]>
If either one of the HCI_SETUP or HCI_USER_CHANNEL flags is set the device is not considered valid for mgmt. By having these checks inside the mgmt_valid_hdev function the a couple of places using it can be simplified.
--- net/bluetooth/hci_core.c | 4 +--- net/bluetooth/mgmt.c | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-)
net/bluetooth/hci_core.c +1 -3
@@ -1238,9 +1238,7 @@ int hci_dev_open(__u16 dev)hci_dev_hold (hdev);set_bit (HCI_UP , &hdev->flags);hci_notify (hdev,HCI_DEV_UP ); -if (!test_bit (HCI_SETUP , &hdev->dev_flags) && - !test_bit (HCI_USER_CHANNEL , &hdev->dev_flags) && -mgmt_valid_hdev (hdev)) { +if (mgmt_valid_hdev (hdev)) {hci_dev_lock (hdev);mgmt_powered (hdev,1 );hci_dev_unlock (hdev);
net/bluetooth/mgmt.c +6 -6
@@ -183,6 +183,12 @@ static u8 mgmt_status_table[] = {bool mgmt_valid_hdev (struct hci_dev *hdev) { +if (test_bit (HCI_SETUP , &hdev->dev_flags)) +return false; + +if (test_bit (HCI_USER_CHANNEL , &hdev->dev_flags)) +return false; +return hdev->dev_type ==HCI_BREDR ; }
@@ -336,12 +342,6 @@ static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data, count =0 ;list_for_each_entry (d, &hci_dev_list, list) { -if (test_bit (HCI_SETUP , &d->dev_flags)) -continue ; - -if (test_bit (HCI_USER_CHANNEL , &d->dev_flags)) -continue ; -if (!mgmt_valid_hdev (d))continue ;
Signature · 1 line
1.8.4.rc3
Marcel Holtmann
maintainerRe: [PATCH 3/8] Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
Hi Johan,
Quoted 4 lines
If either one of the
HCI_SETUPorHCI_USER_CHANNELflags is set the device is not considered valid for mgmt. By having these checks inside themgmt_valid_hdevfunction the a couple of places using it can be simplified.
I looked at doing this and decided not to. Reason was that the device gets removed from mgmt anyway.
So I need a bit more detail why we better do it this way.
Regards
Marcel
Re: [PATCH 3/8] Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
Hi Marcel,
Quoted 7 lines · Marcel Holtmann
Quoted 4 lines
If either one of the
HCI_SETUPorHCI_USER_CHANNELflags is set the device is not considered valid for mgmt. By having these checks inside themgmt_valid_hdevfunction the a couple of places using it can be simplified.I looked at doing this and decided not to. Reason was that the device gets removed from mgmt anyway.
I'm not sure what significance you think "device gets removed from mgmt" has. All that is is a mgmt event saying that index has been removed. In addition to that we need to ensure that we don't send any more mgmt events for such devices and that we don't include such devices in the response to mgmt_read_index list.
These are the two places of the code that my patch simplifies, one is the check for whether to send a "power on" mgmt event and the other the response handling of read_index_list.
Johan
Marcel Holtmann
maintainerRe: [PATCH 3/8] Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
Hi Johan,
Quoted 14 lines
Quoted 7 lines
Quoted 4 lines
If either one of the
HCI_SETUPorHCI_USER_CHANNELflags is set the device is not considered valid for mgmt. By having these checks inside themgmt_valid_hdevfunction the a couple of places using it can be simplified.I looked at doing this and decided not to. Reason was that the device gets removed from mgmt anyway.
I'm not sure what significance you think "device gets removed from mgmt" has. All that is is a mgmt event saying that index has been removed. In addition to that we need to ensure that we don't send any more mgmt events for such devices and that we don't include such devices in the response to
mgmt_read_indexlist.
Quoted 3 lines
These are the two places of the code that my patch simplifies, one is the check for whether to send a "power on" mgmt event and the other the response handling of
read_index_list.
I have taken care of that part. It is done inside mgmt_control() and in case of a controller in user channel mode it returns invalid index.
For the events, I have no idea on how we would generate events if we are not going through hci_event.c when the user channel is active.
Regards
Marcel
Re: [PATCH 3/8] Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
Hi Marcel,
Quoted 14 lines · Marcel Holtmann
Quoted 14 lines
Quoted 7 lines
Quoted 4 lines
If either one of the
HCI_SETUPorHCI_USER_CHANNELflags is set the device is not considered valid for mgmt. By having these checks inside themgmt_valid_hdevfunction the a couple of places using it can be simplified.I looked at doing this and decided not to. Reason was that the device gets removed from mgmt anyway.
I'm not sure what significance you think "device gets removed from mgmt" has. All that is is a mgmt event saying that index has been removed. In addition to that we need to ensure that we don't send any more mgmt events for such devices and that we don't include such devices in the response to
mgmt_read_indexlist.
Quoted 6 lines
Quoted 3 lines
These are the two places of the code that my patch simplifies, one is the check for whether to send a "power on" mgmt event and the other the response handling of
read_index_list.I have taken care of that part. It is done inside
mgmt_control()and in case of a controller in user channel mode it returns invalid index.
That's great, but it doesn't cover the read_index_list command which we were talking about here since the command doesn't target any specific controller (as per our mgmt-api.txt it has the value <non-controller> as the controller index). The command handler will in this case be invoked that that's where it'd be convenient to rely on mgmt_valid_hdev() for constructing the response.
Quoted 2 lines
For the events, I have no idea on how we would generate events if we are not going through
hci_event.cwhen the user channel is active.
The "powered on" event in question doesn't come from hci_event.c but from the hci_dev_open() function, so again this is not covered by the existing user channel checks.
Johan
Marcel Holtmann
maintainerRe: [PATCH 3/8] Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
Hi Johan,
Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 7 lines
Quoted 4 lines
If either one of the
HCI_SETUPorHCI_USER_CHANNELflags is set the device is not considered valid for mgmt. By having these checks inside themgmt_valid_hdevfunction the a couple of places using it can be simplified.I looked at doing this and decided not to. Reason was that the device gets removed from mgmt anyway.
I'm not sure what significance you think "device gets removed from mgmt" has. All that is is a mgmt event saying that index has been removed. In addition to that we need to ensure that we don't send any more mgmt events for such devices and that we don't include such devices in the response to
mgmt_read_indexlist.Quoted 6 lines
Quoted 3 lines
These are the two places of the code that my patch simplifies, one is the check for whether to send a "power on" mgmt event and the other the response handling of
read_index_list.I have taken care of that part. It is done inside
mgmt_control()and in case of a controller in user channel mode it returns invalid index.
Quoted 6 lines
That's great, but it doesn't cover the
read_index_listcommand which we were talking about here since the command doesn't target any specific controller (as per our mgmt-api.txt it has the value <non-controller> as the controller index). The command handler will in this case be invoked that that's where it'd be convenient to rely onmgmt_valid_hdev()for constructing the response.
the read index list command has a special check for user channel. As I said, I looked into this and opted against extending valid hdev macro since we only need it in a few specific cases. Adding it there resulted in simpler code then some magic macro that is used in more places.
When I wrote the patches for user channel this felt cleaner. I had patches for both ways, but decided to go this route.
Quoted 6 lines
Quoted 2 lines
For the events, I have no idea on how we would generate events if we are not going through
hci_event.cwhen the user channel is active.The "powered on" event in question doesn't come from
hci_event.cbut from thehci_dev_open()function, so again this is not covered by the existing user channel checks.
How would you trigger a power on event. When user channel is active everything else is blocked. So every other operation will fail. That is taken care of.
In addition you can only activate user channel on a controller that is powered off. That was a conscious design decision. Keep it really simple. User channel mode is exclusive and exclusive to one user at a time.
Regards
Marcel
Re: [PATCH 3/8] Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
Hi Marcel,
Quoted 28 lines · Marcel Holtmann
Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 7 lines
Quoted 4 lines
If either one of the
HCI_SETUPorHCI_USER_CHANNELflags is set the device is not considered valid for mgmt. By having these checks inside themgmt_valid_hdevfunction the a couple of places using it can be simplified.I looked at doing this and decided not to. Reason was that the device gets removed from mgmt anyway.
I'm not sure what significance you think "device gets removed from mgmt" has. All that is is a mgmt event saying that index has been removed. In addition to that we need to ensure that we don't send any more mgmt events for such devices and that we don't include such devices in the response to
mgmt_read_indexlist.Quoted 6 lines
Quoted 3 lines
These are the two places of the code that my patch simplifies, one is the check for whether to send a "power on" mgmt event and the other the response handling of
read_index_list.I have taken care of that part. It is done inside
mgmt_control()and in case of a controller in user channel mode it returns invalid index.Quoted 6 lines
That's great, but it doesn't cover the
read_index_listcommand which we were talking about here since the command doesn't target any specific controller (as per our mgmt-api.txt it has the value <non-controller> as the controller index). The command handler will in this case be invoked that that's where it'd be convenient to rely onmgmt_valid_hdev()for constructing the response.
Quoted 8 lines
the read index list command has a special check for user channel. As I said, I looked into this and opted against extending valid hdev macro since we only need it in a few specific cases. Adding it there resulted in simpler code then some magic macro that is used in more places.
When I wrote the patches for user channel this felt cleaner. I had patches for both ways, but decided to go this route.
Fair enough.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
For the events, I have no idea on how we would generate events if we are not going through
hci_event.cwhen the user channel is active.The "powered on" event in question doesn't come from
hci_event.cbut from thehci_dev_open()function, so again this is not covered by the existing user channel checks.
Quoted 8 lines
How would you trigger a power on event. When user channel is active everything else is blocked. So every other operation will fail. That is taken care of.
In addition you can only activate user channel on a controller that is powered off. That was a conscious design decision. Keep it really simple. User channel mode is exclusive and exclusive to one user at a time.
Good point. The only hci_dev_open() call that comes to mind is the one automatically triggered by the setup stage, but user space doesn't yet know about the controller at that point.
Johan
PATCH 4/8 Bluetooth: Fix busy return for mgmt_set_powered in some cases
In reply to [email protected]From: Johan Hedberg <[email protected]>
We should return a "busy" error always when there is another mgmt_set_powered operation in progress. Previously when powering on while the auto off timer was still set the code could have let two or more pending power on commands to be queued. This patch fixes the issue by moving the check for duplicate commands to an earlier point in the set_powered handler.
--- net/bluetooth/mgmt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/bluetooth/mgmt.c +6 -6
@@ -807,6 +807,12 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,hci_dev_lock (hdev); +if (mgmt_pending_find (MGMT_OP_SET_POWERED , hdev)) { + err =cmd_status (sk, hdev->id,MGMT_OP_SET_POWERED , +MGMT_STATUS_BUSY ); + goto failed; + } +if (test_and_clear_bit (HCI_AUTO_OFF , &hdev->dev_flags)) {cancel_delayed_work (&hdev->power_off);
@@ -823,12 +829,6 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, goto failed; } -if (mgmt_pending_find (MGMT_OP_SET_POWERED , hdev)) { - err =cmd_status (sk, hdev->id,MGMT_OP_SET_POWERED , -MGMT_STATUS_BUSY ); - goto failed; - } - cmd =mgmt_pending_add (sk,MGMT_OP_SET_POWERED , hdev, data, len);if (!cmd) { err = -ENOMEM ;
Signature · 1 line
1.8.4.rc3
Re: [PATCH 4/8] Bluetooth: Fix busy return for mgmt_set_powered in some cases
Hi Johan,
Quoted 11 lines
We should return a "busy" error always when there is another
mgmt_set_poweredoperation in progress. Previously when powering on while the auto off timer was still set the code could have let two or more pending power on commands to be queued. This patch fixes the issue by moving the check for duplicate commands to an earlier point in theset_poweredhandler.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/mgmt.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)
Regards
Marcel
PATCH 5/8 Bluetooth: Move mgmt response convenience functions to a better location
In reply to [email protected]From: Johan Hedberg <[email protected]>
The settings_rsp and cmd_status_rsp functions can be useful for all mgmt command handlers when asynchronous request callbacks are used. They will e.g. be used by subsequent patches to change set_le to use an async request as well as a new set_advertising command. Therefore, move them higher up in the mgmt.c file to avoid unnecessary forward declarations or mixing this trivial change with other patches.
--- net/bluetooth/mgmt.c | 60 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 30 deletions(-)
net/bluetooth/mgmt.c +30 -30
@@ -886,6 +886,36 @@ static int new_settings(struct hci_dev *hdev, struct sock *skip)return mgmt_event (MGMT_EV_NEW_SETTINGS , hdev, &ev,sizeof (ev), skip); } +struct cmd_lookup { +struct sock *sk; +struct hci_dev *hdev; +u8 mgmt_status; +}; + +static void settings_rsp (struct pending_cmd *cmd,void *data) +{ +struct cmd_lookup *match = data; + +send_settings_rsp (cmd->sk, cmd->opcode, match->hdev); + +list_del (&cmd->list); + +if (match->sk ==NULL ) { + match->sk = cmd->sk; +sock_hold (match->sk); + } + +mgmt_pending_free (cmd); +} + +static void cmd_status_rsp (struct pending_cmd *cmd,void *data) +{ +u8 *status = data; + +cmd_status (cmd->sk, cmd->index, cmd->opcode, *status); +mgmt_pending_remove (cmd); +} +static int set_discoverable (struct sock *sk,struct hci_dev *hdev,void *data,u16 len) {
@@ -3374,14 +3404,6 @@ done:return err; } -static void cmd_status_rsp (struct pending_cmd *cmd,void *data) -{ -u8 *status = data; - -cmd_status (cmd->sk, cmd->index, cmd->opcode, *status); -mgmt_pending_remove (cmd); -} -int mgmt_index_added (struct hci_dev *hdev) {if (!mgmt_valid_hdev (hdev))
@@ -3402,28 +3424,6 @@ int mgmt_index_removed(struct hci_dev *hdev)return mgmt_event (MGMT_EV_INDEX_REMOVED , hdev,NULL ,0 ,NULL ); } -struct cmd_lookup { -struct sock *sk; -struct hci_dev *hdev; -u8 mgmt_status; -}; - -static void settings_rsp (struct pending_cmd *cmd,void *data) -{ -struct cmd_lookup *match = data; - -send_settings_rsp (cmd->sk, cmd->opcode, match->hdev); - -list_del (&cmd->list); - -if (match->sk ==NULL ) { - match->sk = cmd->sk; -sock_hold (match->sk); - } - -mgmt_pending_free (cmd); -} -static void set_bredr_scan (struct hci_request *req) {struct hci_dev *hdev = req->hdev;
Signature · 1 line
1.8.4.rc3
Re: [PATCH 5/8] Bluetooth: Move mgmt response convenience functions to a better location
Hi Johan,
Quoted 11 lines
The
settings_rspandcmd_status_rspfunctions can be useful for all mgmt command handlers when asynchronous request callbacks are used. They will e.g. be used by subsequent patches to changeset_leto use an async request as well as a newset_advertisingcommand. Therefore, move them higher up in themgmt.cfile to avoid unnecessary forward declarations or mixing this trivial change with other patches.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/mgmt.c| 60 ++++++++++++++++++++++++++--------------------------1 file changed, 30 insertions(+), 30 deletions(-)
Regards
Marcel
PATCH 6/8 Bluetooth: Use async request for LE enable/disable
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch updates the code to use an asynchronous request for handling the enabling and disabling of LE support. This refactoring is necessary as a preparation for adding advertising support, since when LE is disabled we should also disable advertising, and the cleanest way to do this is to perform the two respective HCI commands in the same asynchronous request.
--- include/net/bluetooth/hci_core.h | 1 - net/bluetooth/hci_event.c | 11 ------- net/bluetooth/mgmt.c | 69 +++++++++++++++++----------------------- 3 files changed, 29 insertions(+), 52 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
@@ -1168,7 +1168,6 @@ int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,int mgmt_set_local_name_complete (struct hci_dev *hdev,u8 *name,u8 status);int mgmt_read_local_oob_data_reply_complete (struct hci_dev *hdev,u8 *hash,u8 *randomizer,u8 status); -int mgmt_le_enable_complete (struct hci_dev *hdev,u8 enable,u8 status);int mgmt_device_found (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 *dev_class,s8 rssi,u8 cfm_name,u8 ssp,u8 *eir,u16 eir_len);
net/bluetooth/hci_event.c +0 -11
@@ -911,13 +911,6 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)hci_dev_lock (hdev); -if (!status) { -if (*sent) -set_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags); -else -clear_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags); - } -if (!test_bit (HCI_INIT , &hdev->flags)) {struct hci_request req;
@@ -1004,10 +997,6 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev,else hdev->features[1 ][0 ] &= ~LMP_HOST_LE_BREDR ; } - -if (test_bit (HCI_MGMT , &hdev->dev_flags) && - !test_bit (HCI_INIT , &hdev->flags)) -mgmt_le_enable_complete (hdev, sent->le, status); } static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
net/bluetooth/mgmt.c +29 -40
92 lines not on this page · raw message
Signature · 1 line
1.8.4.rc3
Re: [PATCH 6/8] Bluetooth: Use async request for LE enable/disable
Hi Johan,
Quoted 7 lines
This patch updates the code to use an asynchronous request for handling the enabling and disabling of LE support. This refactoring is necessary as a preparation for adding advertising support, since when LE is disabled we should also disable advertising, and the cleanest way to do this is to perform the two respective HCI commands in the same asynchronous request.
Quoted 6 lines
Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci_core.h | 1 - net/bluetooth/hci_event.c | 11 ------- net/bluetooth/mgmt.c | 69 +++++++++++++++++----------------------- 3 files changed, 29 insertions(+), 52 deletions(-)
Regards
Marcel
PATCH 7/8 Bluetooth: Add new mgmt setting for LE advertising
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch adds a new mgmt setting for LE advertising and hooks up the necessary places in the mgmt code to operate on the HCI_LE_PERIPHERAL flag (which corresponds to this setting). This patch does not yet add any new command for enabling the setting - that is left for a subsequent patch.
--- include/net/bluetooth/mgmt.h | 1 + net/bluetooth/mgmt.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)
include/net/bluetooth/mgmt.h +1 -0
@@ -93,6 +93,7 @@ struct mgmt_rp_read_index_list {#define MGMT_SETTING_BREDR 0x00000080#define MGMT_SETTING_HS 0x00000100#define MGMT_SETTING_LE 0x00000200 +#define MGMT_SETTING_ADVERTISING 0x00000400#define MGMT_OP_READ_INFO 0x0004#define MGMT_READ_INFO_SIZE 0
net/bluetooth/mgmt.c +23 -1
@@ -384,8 +384,10 @@ static u32 get_supported_settings(struct hci_dev *hdev)if (enable_hs) settings |=MGMT_SETTING_HS ; -if (lmp_le_capable (hdev)) +if (lmp_le_capable (hdev)) { settings |=MGMT_SETTING_LE ; + settings |=MGMT_SETTING_ADVERTISING ; + }return settings; }
@@ -424,6 +426,9 @@ static u32 get_current_settings(struct hci_dev *hdev)if (test_bit (HCI_HS_ENABLED , &hdev->dev_flags)) settings |=MGMT_SETTING_HS ; +if (test_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags)) + settings |=MGMT_SETTING_ADVERTISING ; +return settings; }
@@ -1368,6 +1373,9 @@ static void le_enable_complete(struct hci_dev *hdev, u8 status)change_bit (HCI_LE_ENABLED , &hdev->dev_flags); +if (!test_bit (HCI_LE_ENABLED , &hdev->dev_flags)) +clear_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags); +mgmt_pending_foreach (MGMT_OP_SET_LE , hdev, settings_rsp, &match);new_settings (hdev, match.sk);
@@ -1413,6 +1421,11 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) changed = true; } +if (!val &&test_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags)) { +clear_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags); + changed = true; + } + err =send_settings_rsp (sk,MGMT_OP_SET_LE , hdev);if (err <0 ) goto unlock;
@@ -1444,6 +1457,9 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)hci_req_init (&req, hdev); +if (test_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags) && !val) +hci_req_add (&req,HCI_OP_LE_SET_ADV_ENABLE ,sizeof (val), &val); +hci_req_add (&req,HCI_OP_WRITE_LE_HOST_SUPPORTED ,sizeof (hci_cp), &hci_cp);
@@ -3519,6 +3535,12 @@ static int powered_update_hci(struct hci_dev *hdev) sizeof(cp), &cp); } +if (test_bit (HCI_LE_PERIPHERAL , &hdev->dev_flags)) { +u8 adv =0x01 ; + +hci_req_add (&req,HCI_OP_LE_SET_ADV_ENABLE ,sizeof (adv), &adv); + } + link_sec =test_bit (HCI_LINK_SECURITY , &hdev->dev_flags);if (link_sec !=test_bit (HCI_AUTH , &hdev->flags)) hci_req_add(&req, HCI_OP_WRITE_AUTH_ENABLE,
Signature · 1 line
1.8.4.rc3
Re: [PATCH 7/8] Bluetooth: Add new mgmt setting for LE advertising
Hi Johan,
Quoted 7 lines · On Tue, Sep 24, 2013 at 10:02 AM, <[email protected]> wrote:
From: Johan Hedberg <[email protected]>
This patch adds a new mgmt setting for LE advertising and hooks up the necessary places in the mgmt code to operate on the
HCI_LE_PERIPHERALflag (which corresponds to this setting). This patch does not yet add any new command for enabling the setting - that is left for a subsequent patch.
How this code behaves if we enable/disable LE advertising using hciconfig hci0 leadv/noleadv? IIRC the LE_SET_ADV_ENABLE command will fail if advertising is already set on the controller.
Best Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Re: [PATCH 7/8] Bluetooth: Add new mgmt setting for LE advertising
Hi Lizardo,
Quoted 10 lines · Anderson Lizardo
Quoted 5 lines · On Tue, Sep 24, 2013 at 10:02 AM, <[email protected]> wrote:
This patch adds a new mgmt setting for LE advertising and hooks up the necessary places in the mgmt code to operate on the
HCI_LE_PERIPHERALflag (which corresponds to this setting). This patch does not yet add any new command for enabling the setting - that is left for a subsequent patch.How this code behaves if we enable/disable LE advertising using hciconfig hci0 leadv/noleadv? IIRC the
LE_SET_ADV_ENABLEcommand will fail if advertising is already set on the controller.
You're right that a mix of mgmt and hciconfig will mix things up on the kernel side. This is something I was aware of but didn't investigate much further since I was assuming it would add too much complexity to the code. The principle has always been that we keep compatibility/good behavior with mixed mgmg/raw HCI access only as long as it doesn't needlessly complicate the code.
That said, I'll take a another look if the flag setting could be moved to a hci_event.c handler from the request callback without requiring the addition of a second flag or state variable. This issue is not unique to this new setting but actually exists for many of them. What we probably need is a generic mgmt_send_new_settings function that hci_event.c handlers can call when they know that new_settings should be emitted. I suspect that might solve the issue.
Johan
Re: [PATCH 7/8] Bluetooth: Add new mgmt setting for LE advertising
Hi,
Quoted 19 lines · Johan Hedberg
Quoted 10 lines · Anderson Lizardo
Quoted 5 lines · On Tue, Sep 24, 2013 at 10:02 AM, <[email protected]> wrote:
This patch adds a new mgmt setting for LE advertising and hooks up the necessary places in the mgmt code to operate on the
HCI_LE_PERIPHERALflag (which corresponds to this setting). This patch does not yet add any new command for enabling the setting - that is left for a subsequent patch.How this code behaves if we enable/disable LE advertising using hciconfig hci0 leadv/noleadv? IIRC the
LE_SET_ADV_ENABLEcommand will fail if advertising is already set on the controller.You're right that a mix of mgmt and hciconfig will mix things up on the kernel side. This is something I was aware of but didn't investigate much further since I was assuming it would add too much complexity to the code. The principle has always been that we keep compatibility/good behavior with mixed mgmg/raw HCI access only as long as it doesn't needlessly complicate the code.
Quoted 7 lines
That said, I'll take a another look if the flag setting could be moved to a
hci_event.chandler from the request callback without requiring the addition of a second flag or state variable. This issue is not unique to this new setting but actually exists for many of them. What we probably need is a genericmgmt_send_new_settingsfunction thathci_event.chandlers can call when they know thatnew_settingsshould be emitted. I suspect that might solve the issue.
So I did take another look and this gets tricky since we don't just need to emit a new_settings, but also ensure that it does not get emitted on the mgmt socket that may have caused the command to be sent. Therefore, I decided against trying to have "full" support of mixing mgmt with raw HCI. What I did do is ensure that our dev_flags remain correct by using the hci_event.c handler to set them. This ensures that subsequent mgmt commands still work even though bluetoothd may not always be completely up to date with these settings.
Johan
Re: [PATCH 7/8] Bluetooth: Add new mgmt setting for LE advertising
In reply to [email protected]Hi Johan,
Quoted 11 lines
This patch adds a new mgmt setting for LE advertising and hooks up the necessary places in the mgmt code to operate on the
HCI_LE_PERIPHERALflag (which corresponds to this setting). This patch does not yet add any new command for enabling the setting - that is left for a subsequent patch.Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/mgmt.h| 1 +net/bluetooth/mgmt.c| 24 +++++++++++++++++++++++-2 files changed, 24 insertions(+), 1 deletion(-)
Regards
Marcel
PATCH 8/8 Bluetooth: Add new mgmt_set_advertising command
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch adds a new mgmt command for enabling and disabling LE advertising.
--- include/net/bluetooth/mgmt.h | 2 + net/bluetooth/mgmt.c | 99 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-)
include/net/bluetooth/mgmt.h +2 -0
@@ -352,6 +352,8 @@ struct mgmt_cp_set_device_id { } __packed;#define MGMT_SET_DEVICE_ID_SIZE 8 +#define MGMT_OP_SET_ADVERTISING 0x0029 +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {__le16 opcode;
net/bluetooth/mgmt.c +98 -1
123 lines not on this page · raw message
Signature · 1 line
1.8.4.rc3
Re: [PATCH 8/8] Bluetooth: Add new mgmt_set_advertising command
Hi,
Quoted 8 lines · On Tue, Sep 24, 2013, [email protected] wrote:
This patch adds a new mgmt command for enabling and disabling LE advertising.
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/mgmt.h | 2 + net/bluetooth/mgmt.c | 99 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-)
Apologies for this really short commit message. I was going to fill this in before sending but seems I forgot. I'll fix this for the next revision but I'll first wait at least for some feedback before that.
Johan