All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: Clear role switch pending flag
@ 2014-11-05 12:56 Kuba Pawlak
  2014-11-05 19:27 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Kuba Pawlak @ 2014-11-05 12:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Kuba Pawlak

If role switch was rejected by the controller and HCI Event: Command Status
returned with status "Command Disallowed" (0x0C) the flag
HCI_CONN_RSWITCH_PEND remains set. No further role switches are
possible as this flag prevents us from sending any new HCI Switch Role
requests and the only way to clear it is to receive a valid
HCI Event Switch Role.

This patch clears the flag if command was rejected.

2013-01-01 00:03:44.209913 < HCI Command: Switch Role (0x02|0x000b) plen 7
    bdaddr BC:C6:DB:C4:6F:79 role 0x00
    Role: Master
2013-01-01 00:03:44.210867 > HCI Event: Command Status (0x0f) plen 4
    Switch Role (0x02|0x000b) status 0x0c ncmd 1
    Error: Command Disallowed

Signed-off-by: Kuba Pawlak <kubax.t.pawlak@intel.com>
---
 net/bluetooth/hci_event.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 2f02ff0..be38684 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1947,6 +1947,29 @@ unlock:
 	hci_dev_unlock(hdev);
 }
 
+static void hci_cs_switch_role(struct hci_dev *hdev, u8 status)
+{
+	struct hci_cp_switch_role *cp;
+	struct hci_conn *conn;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, status);
+
+	if (!status)
+		return;
+
+	cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE);
+	if (!cp)
+		return;
+
+	hci_dev_lock(hdev);
+
+	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
+	if (conn)
+		clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
+
+	hci_dev_unlock(hdev);
+}
+
 static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	__u8 status = *((__u8 *) skb->data);
@@ -2906,6 +2929,10 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_cs_le_start_enc(hdev, ev->status);
 		break;
 
+	case HCI_OP_SWITCH_ROLE:
+		hci_cs_switch_role(hdev, ev->status);
+		break;
+
 	default:
 		BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
 		break;
-- 
1.7.11.7

Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Bluetooth: Clear role switch pending flag
  2014-11-05 12:56 [PATCH] Bluetooth: Clear role switch pending flag Kuba Pawlak
@ 2014-11-05 19:27 ` Marcel Holtmann
  2014-11-06  9:39   ` Pawlak, KubaX T
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2014-11-05 19:27 UTC (permalink / raw)
  To: Kuba Pawlak; +Cc: linux-bluetooth

Hi Kuba,

> If role switch was rejected by the controller and HCI Event: Command Status
> returned with status "Command Disallowed" (0x0C) the flag
> HCI_CONN_RSWITCH_PEND remains set. No further role switches are
> possible as this flag prevents us from sending any new HCI Switch Role
> requests and the only way to clear it is to receive a valid
> HCI Event Switch Role.
> 
> This patch clears the flag if command was rejected.
> 
> 2013-01-01 00:03:44.209913 < HCI Command: Switch Role (0x02|0x000b) plen 7
>    bdaddr BC:C6:DB:C4:6F:79 role 0x00
>    Role: Master
> 2013-01-01 00:03:44.210867 > HCI Event: Command Status (0x0f) plen 4
>    Switch Role (0x02|0x000b) status 0x0c ncmd 1
>    Error: Command Disallowed
> 
> Signed-off-by: Kuba Pawlak <kubax.t.pawlak@intel.com>
> ---
> net/bluetooth/hci_event.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
> 
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 2f02ff0..be38684 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -1947,6 +1947,29 @@ unlock:
> 	hci_dev_unlock(hdev);
> }
> 
> +static void hci_cs_switch_role(struct hci_dev *hdev, u8 status)
> +{
> +	struct hci_cp_switch_role *cp;
> +	struct hci_conn *conn;
> +
> +	BT_DBG("%s status 0x%2.2x", hdev->name, status);
> +
> +	if (!status)
> +		return;
> +
> +	cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE);
> +	if (!cp)
> +		return;
> +
> +	hci_dev_lock(hdev);
> +
> +	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
> +	if (conn)
> +		clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
> +
> +	hci_dev_unlock(hdev);
> +}
> +
> static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
> {
> 	__u8 status = *((__u8 *) skb->data);
> @@ -2906,6 +2929,10 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
> 		hci_cs_le_start_enc(hdev, ev->status);
> 		break;
> 
> +	case HCI_OP_SWITCH_ROLE:
> +		hci_cs_switch_role(hdev, ev->status);
> +		break;
> +

please sort these by opcode. I think we at least tried to have them in order of opcode.

Regards

Marcel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] Bluetooth: Clear role switch pending flag
  2014-11-05 19:27 ` Marcel Holtmann
@ 2014-11-06  9:39   ` Pawlak, KubaX T
  2014-11-06 16:50     ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Pawlak, KubaX T @ 2014-11-06  9:39 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel

> please sort these by opcode. I think we at least tried to have them in order of
> opcode.
> 

Actually opcodes sorting in this function looks like this:
0x0401
0x0405
0x0407
0x0411
0x0413
0x0419
0x041b
0x041c
0x0428
0x0803 <-  sniff mode
0x0804  <- exit sniff mode
0x0406 <-disconnect
0x0435
0x0436
0x200d <- LE related
0x0219 

Mine is 0x080b so it goes at the end and the list needs resorting or in the middle after 0x0803 and 0x0804. 

Kuba
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Bluetooth: Clear role switch pending flag
  2014-11-06  9:39   ` Pawlak, KubaX T
@ 2014-11-06 16:50     ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2014-11-06 16:50 UTC (permalink / raw)
  To: Pawlak, KubaX T; +Cc: linux-bluetooth

Hi Kuba,

>> please sort these by opcode. I think we at least tried to have them in order of
>> opcode.
>> 
> 
> Actually opcodes sorting in this function looks like this:
> 0x0401
> 0x0405
> 0x0407
> 0x0411
> 0x0413
> 0x0419
> 0x041b
> 0x041c
> 0x0428
> 0x0803 <-  sniff mode
> 0x0804  <- exit sniff mode

please insert it here.

> 0x0406 <-disconnect
> 0x0435
> 0x0436
> 0x200d <- LE related
> 0x0219 
> 
> Mine is 0x080b so it goes at the end and the list needs resorting or in the middle after 0x0803 and 0x0804. 

And then please send a second patch that actually sorts these correctly. We try to do our best, but sometimes things slip through.

Regards

Marcel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-06 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-05 12:56 [PATCH] Bluetooth: Clear role switch pending flag Kuba Pawlak
2014-11-05 19:27 ` Marcel Holtmann
2014-11-06  9:39   ` Pawlak, KubaX T
2014-11-06 16:50     ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.