Bluetooth: Device Scan and connection collision fix
Subsystems (2)
PATCH 1/1 Bluetooth: Device Scan and connection collision fix
From: Ram Malovany <[email protected]>
During search of devices, HCI Remote Name Request Command is sent for every device which name was not included in inquiry result. But the same command is also sent during incoming connection establishing procedure. Function hci_check_pending_name() was fixed in order to handle this situation which led to a kernel crash when initiating an incoming connection from a device that was not found in the inquiry while doing a search. There is no need to continue resolving the next name if we get the request from the incoming connection procedure as it will be done upon receiving another remote name request complete event
--- net/bluetooth/hci_event.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
net/bluetooth/hci_event.c +12 -4
@@ -1365,7 +1365,7 @@ static bool hci_resolve_next_name(struct hci_dev *hdev)return false; e =hci_inquiry_cache_lookup_resolve (hdev,BDADDR_ANY ,NAME_NEEDED ); -if (hci_resolve_name (hdev, e) ==0 ) { +if (e &&hci_resolve_name (hdev, e) ==0 ) { e->name_state =NAME_PENDING ;return true; }
@@ -1379,6 +1379,9 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,struct discovery_state *discov = &hdev->discovery;struct inquiry_entry *e; +BT_DBG ("name %p, name_len %d, discov->state %d" , + name, name_len, discov->state); +if (conn && !test_and_set_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags))mgmt_device_connected (hdev, bdaddr,ACL_LINK ,0x00 ,0 , name, name_len, conn->dev_class);
@@ -1394,11 +1397,16 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, e =hci_inquiry_cache_lookup_resolve (hdev, bdaddr,NAME_PENDING );if (e) { - e->name_state =NAME_KNOWN ;list_del (&e->list); -if (name) +if (name) { + e->name_state =NAME_KNOWN ;mgmt_remote_name (hdev, bdaddr,ACL_LINK ,0x00 , e->data.rssi, name, name_len); + }else { + e->name_state =NAME_NOT_KNOWN ; + } + }else { +return ; }if (hci_resolve_next_name (hdev))
@@ -1996,7 +2004,7 @@ static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)struct hci_ev_remote_name *ev = (void *) skb->data;struct hci_conn *conn; -BT_DBG ("%s" , hdev->name); +BT_DBG ("%s, status %d" , hdev->name, ev->status);hci_conn_check_pending (hdev);
Signature · 1 line
1.7.4.1
Hi Ram,
Quoted 23 lines · On Tue, Jul 17, 2012 at 04:52:06PM +0300, [email protected] wrote:
From: Ram Malovany <[email protected]>
During search of devices, HCI Remote Name Request Command is sent for every device which name was not included in inquiry result. But the same command is also sent during incoming connection establishing procedure. Function
hci_check_pending_name()was fixed in order to handle this situation which led to a kernel crash when initiating an incoming connection from a device that was not found in the inquiry while doing a search. There is no need to continue resolving the next name if we get the request from the incoming connection procedure as it will be done upon receiving another remote name request complete eventSigned-off-by Ram Malovany <[email protected]>--- net/bluetooth/hci_event.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)net/bluetooth/hci_event.c +0
-0
net/bluetooth/hci_event.c static bool hci_resolve_next_name(struct hci_dev *hdev) · line 1368
Quoted 5 lines
net/bluetooth/hci_event.c +1
-1@@ -1365,7 +1365,7 @@ static bool hci_resolve_next_name(struct hci_dev *hdev)return false; e =hci_inquiry_cache_lookup_resolve (hdev,BDADDR_ANY ,NAME_NEEDED ); -if (hci_resolve_name (hdev, e) ==0 ) { +if (e &&hci_resolve_name (hdev, e) ==0 ) {
good catch
net/bluetooth/hci_event.c static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, · line 1383
Quoted 9 lines
net/bluetooth/hci_event.c +2
-0e->name_state =NAME_PENDING ;return true; }@@ -1379,6 +1379,9 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,struct discovery_state *discov = &hdev->discovery;struct inquiry_entry *e; +BT_DBG ("name %p, name_len %d, discov->state %d" , + name, name_len, discov->state);
wrong indentation
Quoted 24 lines
net/bluetooth/hci_event.c +8
-2+if (conn && !test_and_set_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags))mgmt_device_connected (hdev, bdaddr,ACL_LINK ,0x00 ,0 , name, name_len, conn->dev_class);@@ -1394,11 +1397,16 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, e =hci_inquiry_cache_lookup_resolve (hdev, bdaddr,NAME_PENDING );if (e) { - e->name_state =NAME_KNOWN ;list_del (&e->list); -if (name) +if (name) { + e->name_state =NAME_KNOWN ;mgmt_remote_name (hdev, bdaddr,ACL_LINK ,0x00 , e->data.rssi, name, name_len); + }else { + e->name_state =NAME_NOT_KNOWN ; + } + }else { +return ; }if (hci_resolve_next_name (hdev))
net/bluetooth/hci_event.c static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) · line 2007
Quoted 5 lines
net/bluetooth/hci_event.c +1
-1@@ -1996,7 +2004,7 @@ static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)struct hci_ev_remote_name *ev = (void *) skb->data;struct hci_conn *conn; -BT_DBG ("%s" , hdev->name); +BT_DBG ("%s, status %d" , hdev->name, ev->status);
please use 0x%2.2x for status
Best regards
Andrei Emeltchenko
Hi Andrei,
Quoted 84 lines
-----Original Message-----
From: Andrei Emeltchenko [mailto:[email protected]]
Sent: Tuesday, July 17, 2012 5:18 PM
To: Malovany, Ram
Cc: [email protected]
Subject: Re: [PATCH] Bluetooth: Device Scan and connection collision fixHi Ram,
net/bluetooth/hci_event.c static bool hci_resolve_next_name(struct hci_dev
Quoted 23 lines · On Tue, Jul 17, 2012 at 04:52:06PM +0300, [email protected] wrote:
From: Ram Malovany <[email protected]>
During search of devices, HCI Remote Name Request Command is sent for every device which name was not included in inquiry result. But the same command is also sent during incoming connection establishing procedure. Function
hci_check_pending_name()was fixed in order to handle this situation which led to a kernel crash when initiating an incoming connection from a device that was not found in the inquiry while doing a search. There is no need to continue resolving the next name if we get the request from the incoming connection procedure as it will be done upon receiving another remote name request complete eventSigned-off-by Ram Malovany <[email protected]>--- net/bluetooth/hci_event.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)net/bluetooth/hci_event.c +0
-0@@ -1365,7 +1365,7 @@ static bool hci_resolve_next_name(struct hci_dev*hdev)
net/bluetooth/hci_event.c static bool hci_resolve_next_name(struct hci_dev *hdev) · line 1368
Quoted 5 lines
net/bluetooth/hci_event.c +1
-1return false; e =hci_inquiry_cache_lookup_resolve (hdev,BDADDR_ANY ,NAME_NEEDED ); -if (hci_resolve_name (hdev, e) ==0 ) { +if (e &&hci_resolve_name (hdev, e) ==0 ) {good catch
net/bluetooth/hci_event.c static void hci_check_pending_name(struct hci_dev
Quoted 4 lines
net/bluetooth/hci_event.c +0
-0e->name_state =NAME_PENDING ;return true; }@@ -1379,6 +1379,9 @@ static void hci_check_pending_name(struct hci_dev*hdev, struct
hci_conn*conn,net/bluetooth/hci_event.c static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, · line 1383
Quoted 5 lines
net/bluetooth/hci_event.c +2
-0struct discovery_state *discov = &hdev->discovery;struct inquiry_entry *e; +BT_DBG ("name %p, name_len %d, discov->state %d" , + name, name_len, discov->state);wrong indentation
net/bluetooth/hci_event.c static void hci_check_pending_name(struct hci_dev
Quoted 5 lines
net/bluetooth/hci_event.c +1
-0+if (conn && !test_and_set_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags))mgmt_device_connected (hdev, bdaddr,ACL_LINK ,0x00 ,0 , name, name_len, conn->dev_class);@@ -1394,11 +1397,16 @@ static void hci_check_pending_name(struct hci_dev*hdev, struct
hci_conn*conn,net/bluetooth/hci_event.c static void hci_remote_name_evt(struct hci_dev *hdev,
Quoted 19 lines
net/bluetooth/hci_event.c +7
-2e =hci_inquiry_cache_lookup_resolve (hdev, bdaddr,NAME_PENDING );if (e) { - e->name_state =NAME_KNOWN ;list_del (&e->list); -if (name) +if (name) { + e->name_state =NAME_KNOWN ;mgmt_remote_name (hdev, bdaddr,ACL_LINK ,0x00 , e->data.rssi, name, name_len); + }else { + e->name_state =NAME_NOT_KNOWN ; + } + }else { +return ; }if (hci_resolve_next_name (hdev))@@ -1996,7 +2004,7 @@ static void hci_remote_name_evt(struct hci_dev *hdev,struct
sk_buff*skb)Quoted 3 lines
net/bluetooth/hci_event.c +0
-0struct hci_ev_remote_name *ev = (void *) skb->data;struct hci_conn *conn;
Quoted 7 lines
net/bluetooth/hci_event.c static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) · line 2007
Quoted 2 lines
net/bluetooth/hci_event.c +1
-1-BT_DBG ("%s" , hdev->name); +BT_DBG ("%s, status %d" , hdev->name, ev->status);please use 0x%2.2x for status
Best regards
Andrei Emeltchenko
Will fix it.
Thanks,
Ram