Re: [PATCH] Bluetooth: Report correct error codes on disconnect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Paulo Alcantara <paulo.alcantara@xxxxxxxxxxxxx>
Date: Fri,  8 Jun 2012 00:55:13 -0300

> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 47656be..2c7e4a7 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -1915,9 +1915,17 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
>  	}
>  
>  	if (ev->status == 0) {
> +		__u8 reason;
> +
>  		if (conn->type == ACL_LINK && conn->flush_key)
>  			hci_remove_link_key(hdev, &conn->dst);
> -		hci_proto_disconn_cfm(conn, ev->reason);
> +
> +		reason = hci_proto_disconn_ind(conn);
> +		if (reason)
> +			hci_proto_disconn_cfm(conn, reason);
> +		else
> +			hci_proto_disconn_cfm(conn, ev->reason);
> +

This is check is wrong since disc_reason is _always_ set to
HCI_ERROR_REMOTE_USER_TERM by default and it can be set to
HCI_ERROR_AUTH_FAILURE as well in l2cap_connect_req(), but it is _never_ set to
0 in anywhere else. I still do not know the reason why is always set to
HCI_ERROR_REMOTE_USER_TERM by default, but I've got two "solutions" for handling
this specific issue so far.

Primarily, it's worth to note that what I'm doing here is to avoid overwriting
error codes returned by LE encryption change event and exposing wrong error ones
to user space. BlueZ should handle specific error codes (e.g.: 0x06 "PIN or key
missing") that are returned by LE encrpytion change event, and not enabling auto
connection when there is "PIN or key missing" error code set in this event, for
example.

Well, the "solutions" that I've got are:

1) We can set the disconnect reason to 0 by default and set it accordingly.

2) Or change this check in hci_disconn_complete_evt() function to:

/* If reason was previously set in hci_encrypt_change_evt(), then we need to use
 * the reason set in disc_reason instead of the event one.
 */
if (reason != HCI_ERROR_REMOTE_USER_TERM && reason != HCI_ERROR_AUTH_FAILURE)
	hci_proto_disconn_cfm(conn, reason);
else
	hci_proto_disconn_cfm(conn, ev->reason);

(Although, the 2nd solution looks better and probably correct to me, IMO)

Do you guys have any other solution or comment that I could take into account,
or even any improvement in one of my solutions given above ?

       	    Paulo
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux