aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2010-12-02 15:17:46 -0500
committerJohn W. Linville <linville@tuxdriver.com>2010-12-02 15:17:46 -0500
commitc30ae138aa0570665725166679bdf4207041c8df (patch)
tree06d887921a968298758e6b247a18b5f7cae449df
parent78b8595691c34478a51d1c2bcbbb0f6ec8a28247 (diff)
parentbe21871f24b0fcd8d0d09c8090385c9cec80efa3 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/padovan/bluetooth-next-2.6
-rw-r--r--drivers/bluetooth/ath3k.c4
-rw-r--r--drivers/bluetooth/btusb.c12
-rw-r--r--include/net/bluetooth/hci.h16
-rw-r--r--include/net/bluetooth/hci_core.h14
-rw-r--r--include/net/bluetooth/l2cap.h22
-rw-r--r--include/net/bluetooth/rfcomm.h18
-rw-r--r--include/net/bluetooth/sco.h20
-rw-r--r--net/bluetooth/bnep/core.c1
-rw-r--r--net/bluetooth/cmtp/core.c1
-rw-r--r--net/bluetooth/hci_conn.c23
-rw-r--r--net/bluetooth/hci_core.c66
-rw-r--r--net/bluetooth/hci_event.c177
-rw-r--r--net/bluetooth/hci_sock.c17
-rw-r--r--net/bluetooth/hidp/core.c2
-rw-r--r--net/bluetooth/l2cap.c94
-rw-r--r--net/bluetooth/rfcomm/core.c8
-rw-r--r--net/bluetooth/rfcomm/sock.c24
-rw-r--r--net/bluetooth/rfcomm/tty.c28
-rw-r--r--net/bluetooth/sco.c28
19 files changed, 363 insertions, 212 deletions
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 128cae4e8629..949ed09c6361 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -35,6 +35,10 @@
35static struct usb_device_id ath3k_table[] = { 35static struct usb_device_id ath3k_table[] = {
36 /* Atheros AR3011 */ 36 /* Atheros AR3011 */
37 { USB_DEVICE(0x0CF3, 0x3000) }, 37 { USB_DEVICE(0x0CF3, 0x3000) },
38
39 /* Atheros AR3011 with sflash firmware*/
40 { USB_DEVICE(0x0CF3, 0x3002) },
41
38 { } /* Terminating entry */ 42 { } /* Terminating entry */
39}; 43};
40 44
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index ab3894f742c3..1da773f899a2 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -99,6 +99,9 @@ static struct usb_device_id blacklist_table[] = {
99 /* Broadcom BCM2033 without firmware */ 99 /* Broadcom BCM2033 without firmware */
100 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE }, 100 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
101 101
102 /* Atheros 3011 with sflash firmware */
103 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
104
102 /* Broadcom BCM2035 */ 105 /* Broadcom BCM2035 */
103 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, 106 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
104 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, 107 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
@@ -239,7 +242,8 @@ static void btusb_intr_complete(struct urb *urb)
239 242
240 err = usb_submit_urb(urb, GFP_ATOMIC); 243 err = usb_submit_urb(urb, GFP_ATOMIC);
241 if (err < 0) { 244 if (err < 0) {
242 BT_ERR("%s urb %p failed to resubmit (%d)", 245 if (err != -EPERM)
246 BT_ERR("%s urb %p failed to resubmit (%d)",
243 hdev->name, urb, -err); 247 hdev->name, urb, -err);
244 usb_unanchor_urb(urb); 248 usb_unanchor_urb(urb);
245 } 249 }
@@ -323,7 +327,8 @@ static void btusb_bulk_complete(struct urb *urb)
323 327
324 err = usb_submit_urb(urb, GFP_ATOMIC); 328 err = usb_submit_urb(urb, GFP_ATOMIC);
325 if (err < 0) { 329 if (err < 0) {
326 BT_ERR("%s urb %p failed to resubmit (%d)", 330 if (err != -EPERM)
331 BT_ERR("%s urb %p failed to resubmit (%d)",
327 hdev->name, urb, -err); 332 hdev->name, urb, -err);
328 usb_unanchor_urb(urb); 333 usb_unanchor_urb(urb);
329 } 334 }
@@ -412,7 +417,8 @@ static void btusb_isoc_complete(struct urb *urb)
412 417
413 err = usb_submit_urb(urb, GFP_ATOMIC); 418 err = usb_submit_urb(urb, GFP_ATOMIC);
414 if (err < 0) { 419 if (err < 0) {
415 BT_ERR("%s urb %p failed to resubmit (%d)", 420 if (err != -EPERM)
421 BT_ERR("%s urb %p failed to resubmit (%d)",
416 hdev->name, urb, -err); 422 hdev->name, urb, -err);
417 usb_unanchor_urb(urb); 423 usb_unanchor_urb(urb);
418 } 424 }
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index e30e00834340..f3c5ed6d7bda 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1,4 +1,4 @@
1/* 1/*
2 BlueZ - Bluetooth protocol stack for Linux 2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated 3 Copyright (C) 2000-2001 Qualcomm Incorporated
4 4
@@ -12,13 +12,13 @@
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED. 22 SOFTWARE IS DISCLAIMED.
23*/ 23*/
24 24
@@ -489,7 +489,7 @@ struct hci_rp_read_local_name {
489 489
490#define HCI_OP_WRITE_PG_TIMEOUT 0x0c18 490#define HCI_OP_WRITE_PG_TIMEOUT 0x0c18
491 491
492#define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a 492#define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a
493 #define SCAN_DISABLED 0x00 493 #define SCAN_DISABLED 0x00
494 #define SCAN_INQUIRY 0x01 494 #define SCAN_INQUIRY 0x01
495 #define SCAN_PAGE 0x02 495 #define SCAN_PAGE 0x02
@@ -874,7 +874,7 @@ struct hci_ev_si_security {
874 874
875struct hci_command_hdr { 875struct hci_command_hdr {
876 __le16 opcode; /* OCF & OGF */ 876 __le16 opcode; /* OCF & OGF */
877 __u8 plen; 877 __u8 plen;
878} __packed; 878} __packed;
879 879
880struct hci_event_hdr { 880struct hci_event_hdr {
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index ebec8c9a929d..9c08625617a1 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -44,15 +44,15 @@ struct inquiry_data {
44}; 44};
45 45
46struct inquiry_entry { 46struct inquiry_entry {
47 struct inquiry_entry *next; 47 struct inquiry_entry *next;
48 __u32 timestamp; 48 __u32 timestamp;
49 struct inquiry_data data; 49 struct inquiry_data data;
50}; 50};
51 51
52struct inquiry_cache { 52struct inquiry_cache {
53 spinlock_t lock; 53 spinlock_t lock;
54 __u32 timestamp; 54 __u32 timestamp;
55 struct inquiry_entry *list; 55 struct inquiry_entry *list;
56}; 56};
57 57
58struct hci_conn_hash { 58struct hci_conn_hash {
@@ -141,7 +141,7 @@ struct hci_dev {
141 void *driver_data; 141 void *driver_data;
142 void *core_data; 142 void *core_data;
143 143
144 atomic_t promisc; 144 atomic_t promisc;
145 145
146 struct dentry *debugfs; 146 struct dentry *debugfs;
147 147
@@ -150,7 +150,7 @@ struct hci_dev {
150 150
151 struct rfkill *rfkill; 151 struct rfkill *rfkill;
152 152
153 struct module *owner; 153 struct module *owner;
154 154
155 int (*open)(struct hci_dev *hdev); 155 int (*open)(struct hci_dev *hdev);
156 int (*close)(struct hci_dev *hdev); 156 int (*close)(struct hci_dev *hdev);
@@ -215,8 +215,8 @@ extern rwlock_t hci_dev_list_lock;
215extern rwlock_t hci_cb_list_lock; 215extern rwlock_t hci_cb_list_lock;
216 216
217/* ----- Inquiry cache ----- */ 217/* ----- Inquiry cache ----- */
218#define INQUIRY_CACHE_AGE_MAX (HZ*30) // 30 seconds 218#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
219#define INQUIRY_ENTRY_AGE_MAX (HZ*60) // 60 seconds 219#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
220 220
221#define inquiry_cache_lock(c) spin_lock(&c->lock) 221#define inquiry_cache_lock(c) spin_lock(&c->lock)
222#define inquiry_cache_unlock(c) spin_unlock(&c->lock) 222#define inquiry_cache_unlock(c) spin_unlock(&c->lock)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index c819c8bf9b68..7ad25ca60ec0 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -1,4 +1,4 @@
1/* 1/*
2 BlueZ - Bluetooth protocol stack for Linux 2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated 3 Copyright (C) 2000-2001 Qualcomm Incorporated
4 Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org> 4 Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org>
@@ -14,13 +14,13 @@
14 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
16 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 16 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
17 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 17 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
18 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 21
22 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 22 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
23 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 23 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
24 SOFTWARE IS DISCLAIMED. 24 SOFTWARE IS DISCLAIMED.
25*/ 25*/
26 26
@@ -417,11 +417,11 @@ static inline int l2cap_tx_window_full(struct sock *sk)
417 return sub == pi->remote_tx_win; 417 return sub == pi->remote_tx_win;
418} 418}
419 419
420#define __get_txseq(ctrl) ((ctrl) & L2CAP_CTRL_TXSEQ) >> 1 420#define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1)
421#define __get_reqseq(ctrl) ((ctrl) & L2CAP_CTRL_REQSEQ) >> 8 421#define __get_reqseq(ctrl) (((ctrl) & L2CAP_CTRL_REQSEQ) >> 8)
422#define __is_iframe(ctrl) !((ctrl) & L2CAP_CTRL_FRAME_TYPE) 422#define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE))
423#define __is_sframe(ctrl) (ctrl) & L2CAP_CTRL_FRAME_TYPE 423#define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE)
424#define __is_sar_start(ctrl) ((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START 424#define __is_sar_start(ctrl) (((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START)
425 425
426void l2cap_load(void); 426void l2cap_load(void);
427 427
diff --git a/include/net/bluetooth/rfcomm.h b/include/net/bluetooth/rfcomm.h
index 71047bc0af84..6eac4a760c3b 100644
--- a/include/net/bluetooth/rfcomm.h
+++ b/include/net/bluetooth/rfcomm.h
@@ -1,5 +1,5 @@
1/* 1/*
2 RFCOMM implementation for Linux Bluetooth stack (BlueZ). 2 RFCOMM implementation for Linux Bluetooth stack (BlueZ)
3 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com> 3 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
4 Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org> 4 Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
5 5
@@ -11,13 +11,13 @@
11 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
13 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 13 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
14 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 14 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 18
19 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 19 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
20 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 20 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
21 SOFTWARE IS DISCLAIMED. 21 SOFTWARE IS DISCLAIMED.
22*/ 22*/
23 23
@@ -105,7 +105,7 @@
105struct rfcomm_hdr { 105struct rfcomm_hdr {
106 u8 addr; 106 u8 addr;
107 u8 ctrl; 107 u8 ctrl;
108 u8 len; // Actual size can be 2 bytes 108 u8 len; /* Actual size can be 2 bytes */
109} __packed; 109} __packed;
110 110
111struct rfcomm_cmd { 111struct rfcomm_cmd {
@@ -228,7 +228,7 @@ struct rfcomm_dlc {
228/* ---- RFCOMM SEND RPN ---- */ 228/* ---- RFCOMM SEND RPN ---- */
229int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci, 229int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci,
230 u8 bit_rate, u8 data_bits, u8 stop_bits, 230 u8 bit_rate, u8 data_bits, u8 stop_bits,
231 u8 parity, u8 flow_ctrl_settings, 231 u8 parity, u8 flow_ctrl_settings,
232 u8 xon_char, u8 xoff_char, u16 param_mask); 232 u8 xon_char, u8 xoff_char, u16 param_mask);
233 233
234/* ---- RFCOMM DLCs (channels) ---- */ 234/* ---- RFCOMM DLCs (channels) ---- */
diff --git a/include/net/bluetooth/sco.h b/include/net/bluetooth/sco.h
index e28a2a771471..1e35c43657c8 100644
--- a/include/net/bluetooth/sco.h
+++ b/include/net/bluetooth/sco.h
@@ -1,4 +1,4 @@
1/* 1/*
2 BlueZ - Bluetooth protocol stack for Linux 2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated 3 Copyright (C) 2000-2001 Qualcomm Incorporated
4 4
@@ -12,13 +12,13 @@
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED. 22 SOFTWARE IS DISCLAIMED.
23*/ 23*/
24 24
@@ -55,11 +55,11 @@ struct sco_conninfo {
55struct sco_conn { 55struct sco_conn {
56 struct hci_conn *hcon; 56 struct hci_conn *hcon;
57 57
58 bdaddr_t *dst; 58 bdaddr_t *dst;
59 bdaddr_t *src; 59 bdaddr_t *src;
60 60
61 spinlock_t lock; 61 spinlock_t lock;
62 struct sock *sk; 62 struct sock *sk;
63 63
64 unsigned int mtu; 64 unsigned int mtu;
65}; 65};
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index f10b41fb05a0..5868597534e5 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -648,6 +648,7 @@ int bnep_del_connection(struct bnep_conndel_req *req)
648 648
649static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s) 649static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s)
650{ 650{
651 memset(ci, 0, sizeof(*ci));
651 memcpy(ci->dst, s->eh.h_source, ETH_ALEN); 652 memcpy(ci->dst, s->eh.h_source, ETH_ALEN);
652 strcpy(ci->device, s->dev->name); 653 strcpy(ci->device, s->dev->name);
653 ci->flags = s->flags; 654 ci->flags = s->flags;
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index ec0a1347f933..8e5f292529ac 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -78,6 +78,7 @@ static void __cmtp_unlink_session(struct cmtp_session *session)
78 78
79static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci) 79static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci)
80{ 80{
81 memset(ci, 0, sizeof(*ci));
81 bacpy(&ci->bdaddr, &session->bdaddr); 82 bacpy(&ci->bdaddr, &session->bdaddr);
82 83
83 ci->flags = session->flags; 84 ci->flags = session->flags;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 0b1e460fe440..6b90a4191734 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -39,7 +39,7 @@
39#include <net/sock.h> 39#include <net/sock.h>
40 40
41#include <asm/system.h> 41#include <asm/system.h>
42#include <asm/uaccess.h> 42#include <linux/uaccess.h>
43#include <asm/unaligned.h> 43#include <asm/unaligned.h>
44 44
45#include <net/bluetooth/bluetooth.h> 45#include <net/bluetooth/bluetooth.h>
@@ -66,7 +66,8 @@ void hci_acl_connect(struct hci_conn *conn)
66 bacpy(&cp.bdaddr, &conn->dst); 66 bacpy(&cp.bdaddr, &conn->dst);
67 cp.pscan_rep_mode = 0x02; 67 cp.pscan_rep_mode = 0x02;
68 68
69 if ((ie = hci_inquiry_cache_lookup(hdev, &conn->dst))) { 69 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
70 if (ie) {
70 if (inquiry_entry_age(ie) <= INQUIRY_ENTRY_AGE_MAX) { 71 if (inquiry_entry_age(ie) <= INQUIRY_ENTRY_AGE_MAX) {
71 cp.pscan_rep_mode = ie->data.pscan_rep_mode; 72 cp.pscan_rep_mode = ie->data.pscan_rep_mode;
72 cp.pscan_mode = ie->data.pscan_mode; 73 cp.pscan_mode = ie->data.pscan_mode;
@@ -368,8 +369,10 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
368 369
369 BT_DBG("%s dst %s", hdev->name, batostr(dst)); 370 BT_DBG("%s dst %s", hdev->name, batostr(dst));
370 371
371 if (!(acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst))) { 372 acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
372 if (!(acl = hci_conn_add(hdev, ACL_LINK, dst))) 373 if (!acl) {
374 acl = hci_conn_add(hdev, ACL_LINK, dst);
375 if (!acl)
373 return NULL; 376 return NULL;
374 } 377 }
375 378
@@ -389,8 +392,10 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
389 if (type == ACL_LINK) 392 if (type == ACL_LINK)
390 return acl; 393 return acl;
391 394
392 if (!(sco = hci_conn_hash_lookup_ba(hdev, type, dst))) { 395 sco = hci_conn_hash_lookup_ba(hdev, type, dst);
393 if (!(sco = hci_conn_add(hdev, type, dst))) { 396 if (!sco) {
397 sco = hci_conn_add(hdev, type, dst);
398 if (!sco) {
394 hci_conn_put(acl); 399 hci_conn_put(acl);
395 return NULL; 400 return NULL;
396 } 401 }
@@ -647,10 +652,12 @@ int hci_get_conn_list(void __user *arg)
647 652
648 size = sizeof(req) + req.conn_num * sizeof(*ci); 653 size = sizeof(req) + req.conn_num * sizeof(*ci);
649 654
650 if (!(cl = kmalloc(size, GFP_KERNEL))) 655 cl = kmalloc(size, GFP_KERNEL);
656 if (!cl)
651 return -ENOMEM; 657 return -ENOMEM;
652 658
653 if (!(hdev = hci_dev_get(req.dev_id))) { 659 hdev = hci_dev_get(req.dev_id);
660 if (!hdev) {
654 kfree(cl); 661 kfree(cl);
655 return -ENODEV; 662 return -ENODEV;
656 } 663 }
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index bc2a052e518b..51c61f75a797 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -44,7 +44,7 @@
44#include <net/sock.h> 44#include <net/sock.h>
45 45
46#include <asm/system.h> 46#include <asm/system.h>
47#include <asm/uaccess.h> 47#include <linux/uaccess.h>
48#include <asm/unaligned.h> 48#include <asm/unaligned.h>
49 49
50#include <net/bluetooth/bluetooth.h> 50#include <net/bluetooth/bluetooth.h>
@@ -349,20 +349,23 @@ struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *b
349void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data) 349void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data)
350{ 350{
351 struct inquiry_cache *cache = &hdev->inq_cache; 351 struct inquiry_cache *cache = &hdev->inq_cache;
352 struct inquiry_entry *e; 352 struct inquiry_entry *ie;
353 353
354 BT_DBG("cache %p, %s", cache, batostr(&data->bdaddr)); 354 BT_DBG("cache %p, %s", cache, batostr(&data->bdaddr));
355 355
356 if (!(e = hci_inquiry_cache_lookup(hdev, &data->bdaddr))) { 356 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr);
357 if (!ie) {
357 /* Entry not in the cache. Add new one. */ 358 /* Entry not in the cache. Add new one. */
358 if (!(e = kzalloc(sizeof(struct inquiry_entry), GFP_ATOMIC))) 359 ie = kzalloc(sizeof(struct inquiry_entry), GFP_ATOMIC);
360 if (!ie)
359 return; 361 return;
360 e->next = cache->list; 362
361 cache->list = e; 363 ie->next = cache->list;
364 cache->list = ie;
362 } 365 }
363 366
364 memcpy(&e->data, data, sizeof(*data)); 367 memcpy(&ie->data, data, sizeof(*data));
365 e->timestamp = jiffies; 368 ie->timestamp = jiffies;
366 cache->timestamp = jiffies; 369 cache->timestamp = jiffies;
367} 370}
368 371
@@ -422,16 +425,20 @@ int hci_inquiry(void __user *arg)
422 425
423 hci_dev_lock_bh(hdev); 426 hci_dev_lock_bh(hdev);
424 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || 427 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX ||
425 inquiry_cache_empty(hdev) || 428 inquiry_cache_empty(hdev) ||
426 ir.flags & IREQ_CACHE_FLUSH) { 429 ir.flags & IREQ_CACHE_FLUSH) {
427 inquiry_cache_flush(hdev); 430 inquiry_cache_flush(hdev);
428 do_inquiry = 1; 431 do_inquiry = 1;
429 } 432 }
430 hci_dev_unlock_bh(hdev); 433 hci_dev_unlock_bh(hdev);
431 434
432 timeo = ir.length * msecs_to_jiffies(2000); 435 timeo = ir.length * msecs_to_jiffies(2000);
433 if (do_inquiry && (err = hci_request(hdev, hci_inq_req, (unsigned long)&ir, timeo)) < 0) 436
434 goto done; 437 if (do_inquiry) {
438 err = hci_request(hdev, hci_inq_req, (unsigned long)&ir, timeo);
439 if (err < 0)
440 goto done;
441 }
435 442
436 /* for unlimited number of responses we will use buffer with 255 entries */ 443 /* for unlimited number of responses we will use buffer with 255 entries */
437 max_rsp = (ir.num_rsp == 0) ? 255 : ir.num_rsp; 444 max_rsp = (ir.num_rsp == 0) ? 255 : ir.num_rsp;
@@ -439,7 +446,8 @@ int hci_inquiry(void __user *arg)
439 /* cache_dump can't sleep. Therefore we allocate temp buffer and then 446 /* cache_dump can't sleep. Therefore we allocate temp buffer and then
440 * copy it to the user space. 447 * copy it to the user space.
441 */ 448 */
442 if (!(buf = kmalloc(sizeof(struct inquiry_info) * max_rsp, GFP_KERNEL))) { 449 buf = kmalloc(sizeof(struct inquiry_info) *max_rsp, GFP_KERNEL);
450 if (!buf) {
443 err = -ENOMEM; 451 err = -ENOMEM;
444 goto done; 452 goto done;
445 } 453 }
@@ -611,7 +619,8 @@ int hci_dev_close(__u16 dev)
611 struct hci_dev *hdev; 619 struct hci_dev *hdev;
612 int err; 620 int err;
613 621
614 if (!(hdev = hci_dev_get(dev))) 622 hdev = hci_dev_get(dev);
623 if (!hdev)
615 return -ENODEV; 624 return -ENODEV;
616 err = hci_dev_do_close(hdev); 625 err = hci_dev_do_close(hdev);
617 hci_dev_put(hdev); 626 hci_dev_put(hdev);
@@ -623,7 +632,8 @@ int hci_dev_reset(__u16 dev)
623 struct hci_dev *hdev; 632 struct hci_dev *hdev;
624 int ret = 0; 633 int ret = 0;
625 634
626 if (!(hdev = hci_dev_get(dev))) 635 hdev = hci_dev_get(dev);
636 if (!hdev)
627 return -ENODEV; 637 return -ENODEV;
628 638
629 hci_req_lock(hdev); 639 hci_req_lock(hdev);
@@ -663,7 +673,8 @@ int hci_dev_reset_stat(__u16 dev)
663 struct hci_dev *hdev; 673 struct hci_dev *hdev;
664 int ret = 0; 674 int ret = 0;
665 675
666 if (!(hdev = hci_dev_get(dev))) 676 hdev = hci_dev_get(dev);
677 if (!hdev)
667 return -ENODEV; 678 return -ENODEV;
668 679
669 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); 680 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
@@ -682,7 +693,8 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
682 if (copy_from_user(&dr, arg, sizeof(dr))) 693 if (copy_from_user(&dr, arg, sizeof(dr)))
683 return -EFAULT; 694 return -EFAULT;
684 695
685 if (!(hdev = hci_dev_get(dr.dev_id))) 696 hdev = hci_dev_get(dr.dev_id);
697 if (!hdev)
686 return -ENODEV; 698 return -ENODEV;
687 699
688 switch (cmd) { 700 switch (cmd) {
@@ -763,7 +775,8 @@ int hci_get_dev_list(void __user *arg)
763 775
764 size = sizeof(*dl) + dev_num * sizeof(*dr); 776 size = sizeof(*dl) + dev_num * sizeof(*dr);
765 777
766 if (!(dl = kzalloc(size, GFP_KERNEL))) 778 dl = kzalloc(size, GFP_KERNEL);
779 if (!dl)
767 return -ENOMEM; 780 return -ENOMEM;
768 781
769 dr = dl->dev_req; 782 dr = dl->dev_req;
@@ -797,7 +810,8 @@ int hci_get_dev_info(void __user *arg)
797 if (copy_from_user(&di, arg, sizeof(di))) 810 if (copy_from_user(&di, arg, sizeof(di)))
798 return -EFAULT; 811 return -EFAULT;
799 812
800 if (!(hdev = hci_dev_get(di.dev_id))) 813 hdev = hci_dev_get(di.dev_id);
814 if (!hdev)
801 return -ENODEV; 815 return -ENODEV;
802 816
803 strcpy(di.name, hdev->name); 817 strcpy(di.name, hdev->name);
@@ -905,7 +919,7 @@ int hci_register_dev(struct hci_dev *hdev)
905 hdev->sniff_max_interval = 800; 919 hdev->sniff_max_interval = 800;
906 hdev->sniff_min_interval = 80; 920 hdev->sniff_min_interval = 80;
907 921
908 tasklet_init(&hdev->cmd_task, hci_cmd_task,(unsigned long) hdev); 922 tasklet_init(&hdev->cmd_task, hci_cmd_task, (unsigned long) hdev);
909 tasklet_init(&hdev->rx_task, hci_rx_task, (unsigned long) hdev); 923 tasklet_init(&hdev->rx_task, hci_rx_task, (unsigned long) hdev);
910 tasklet_init(&hdev->tx_task, hci_tx_task, (unsigned long) hdev); 924 tasklet_init(&hdev->tx_task, hci_tx_task, (unsigned long) hdev);
911 925
@@ -1368,7 +1382,8 @@ void hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags)
1368 bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT; 1382 bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT;
1369 hci_add_acl_hdr(skb, conn->handle, flags | ACL_START); 1383 hci_add_acl_hdr(skb, conn->handle, flags | ACL_START);
1370 1384
1371 if (!(list = skb_shinfo(skb)->frag_list)) { 1385 list = skb_shinfo(skb)->frag_list;
1386 if (!list) {
1372 /* Non fragmented */ 1387 /* Non fragmented */
1373 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); 1388 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
1374 1389
@@ -1609,7 +1624,8 @@ static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
1609 hci_conn_enter_active_mode(conn); 1624 hci_conn_enter_active_mode(conn);
1610 1625
1611 /* Send to upper protocol */ 1626 /* Send to upper protocol */
1612 if ((hp = hci_proto[HCI_PROTO_L2CAP]) && hp->recv_acldata) { 1627 hp = hci_proto[HCI_PROTO_L2CAP];
1628 if (hp && hp->recv_acldata) {
1613 hp->recv_acldata(conn, skb, flags); 1629 hp->recv_acldata(conn, skb, flags);
1614 return; 1630 return;
1615 } 1631 }
@@ -1644,7 +1660,8 @@ static inline void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
1644 register struct hci_proto *hp; 1660 register struct hci_proto *hp;
1645 1661
1646 /* Send to upper protocol */ 1662 /* Send to upper protocol */
1647 if ((hp = hci_proto[HCI_PROTO_SCO]) && hp->recv_scodata) { 1663 hp = hci_proto[HCI_PROTO_SCO];
1664 if (hp && hp->recv_scodata) {
1648 hp->recv_scodata(conn, skb); 1665 hp->recv_scodata(conn, skb);
1649 return; 1666 return;
1650 } 1667 }
@@ -1727,7 +1744,8 @@ static void hci_cmd_task(unsigned long arg)
1727 if (atomic_read(&hdev->cmd_cnt) && (skb = skb_dequeue(&hdev->cmd_q))) { 1744 if (atomic_read(&hdev->cmd_cnt) && (skb = skb_dequeue(&hdev->cmd_q))) {
1728 kfree_skb(hdev->sent_cmd); 1745 kfree_skb(hdev->sent_cmd);
1729 1746
1730 if ((hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC))) { 1747 hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC);
1748 if (hdev->sent_cmd) {
1731 atomic_dec(&hdev->cmd_cnt); 1749 atomic_dec(&hdev->cmd_cnt);
1732 hci_send_frame(skb); 1750 hci_send_frame(skb);
1733 hdev->cmd_last_tx = jiffies; 1751 hdev->cmd_last_tx = jiffies;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 84093b0000b9..8923b36a67a2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -39,7 +39,7 @@
39#include <net/sock.h> 39#include <net/sock.h>
40 40
41#include <asm/system.h> 41#include <asm/system.h>
42#include <asm/uaccess.h> 42#include <linux/uaccess.h>
43#include <asm/unaligned.h> 43#include <asm/unaligned.h>
44 44
45#include <net/bluetooth/bluetooth.h> 45#include <net/bluetooth/bluetooth.h>
@@ -677,9 +677,50 @@ static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
677 hci_dev_unlock(hdev); 677 hci_dev_unlock(hdev);
678} 678}
679 679
680static int hci_outgoing_auth_needed(struct hci_dev *hdev,
681 struct hci_conn *conn)
682{
683 if (conn->state != BT_CONFIG || !conn->out)
684 return 0;
685
686 if (conn->sec_level == BT_SECURITY_SDP)
687 return 0;
688
689 /* Only request authentication for SSP connections or non-SSP
690 * devices with sec_level HIGH */
691 if (!(hdev->ssp_mode > 0 && conn->ssp_mode > 0) &&
692 conn->sec_level != BT_SECURITY_HIGH)
693 return 0;
694
695 return 1;
696}
697
680static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) 698static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
681{ 699{
700 struct hci_cp_remote_name_req *cp;
701 struct hci_conn *conn;
702
682 BT_DBG("%s status 0x%x", hdev->name, status); 703 BT_DBG("%s status 0x%x", hdev->name, status);
704
705 /* If successful wait for the name req complete event before
706 * checking for the need to do authentication */
707 if (!status)
708 return;
709
710 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
711 if (!cp)
712 return;
713
714 hci_dev_lock(hdev);
715
716 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
717 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
718 struct hci_cp_auth_requested cp;
719 cp.handle = __cpu_to_le16(conn->handle);
720 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
721 }
722
723 hci_dev_unlock(hdev);
683} 724}
684 725
685static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) 726static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
@@ -955,12 +996,14 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
955 996
956 hci_dev_lock(hdev); 997 hci_dev_lock(hdev);
957 998
958 if ((ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr))) 999 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
1000 if (ie)
959 memcpy(ie->data.dev_class, ev->dev_class, 3); 1001 memcpy(ie->data.dev_class, ev->dev_class, 3);
960 1002
961 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); 1003 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
962 if (!conn) { 1004 if (!conn) {
963 if (!(conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr))) { 1005 conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr);
1006 if (!conn) {
964 BT_ERR("No memory for new connection"); 1007 BT_ERR("No memory for new connection");
965 hci_dev_unlock(hdev); 1008 hci_dev_unlock(hdev);
966 return; 1009 return;
@@ -1090,9 +1133,23 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1090 1133
1091static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) 1134static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
1092{ 1135{
1136 struct hci_ev_remote_name *ev = (void *) skb->data;
1137 struct hci_conn *conn;
1138
1093 BT_DBG("%s", hdev->name); 1139 BT_DBG("%s", hdev->name);
1094 1140
1095 hci_conn_check_pending(hdev); 1141 hci_conn_check_pending(hdev);
1142
1143 hci_dev_lock(hdev);
1144
1145 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
1146 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
1147 struct hci_cp_auth_requested cp;
1148 cp.handle = __cpu_to_le16(conn->handle);
1149 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1150 }
1151
1152 hci_dev_unlock(hdev);
1096} 1153}
1097 1154
1098static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) 1155static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
@@ -1162,33 +1219,39 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff
1162 hci_dev_lock(hdev); 1219 hci_dev_lock(hdev);
1163 1220
1164 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 1221 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1165 if (conn) { 1222 if (!conn)
1166 if (!ev->status) 1223 goto unlock;
1167 memcpy(conn->features, ev->features, 8);
1168 1224
1169 if (conn->state == BT_CONFIG) { 1225 if (!ev->status)
1170 if (!ev->status && lmp_ssp_capable(hdev) && 1226 memcpy(conn->features, ev->features, 8);
1171 lmp_ssp_capable(conn)) { 1227
1172 struct hci_cp_read_remote_ext_features cp; 1228 if (conn->state != BT_CONFIG)
1173 cp.handle = ev->handle; 1229 goto unlock;
1174 cp.page = 0x01; 1230
1175 hci_send_cmd(hdev, 1231 if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) {
1176 HCI_OP_READ_REMOTE_EXT_FEATURES, 1232 struct hci_cp_read_remote_ext_features cp;
1177 sizeof(cp), &cp); 1233 cp.handle = ev->handle;
1178 } else if (!ev->status && conn->out && 1234 cp.page = 0x01;
1179 conn->sec_level == BT_SECURITY_HIGH) { 1235 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
1180 struct hci_cp_auth_requested cp;
1181 cp.handle = ev->handle;
1182 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED,
1183 sizeof(cp), &cp); 1236 sizeof(cp), &cp);
1184 } else { 1237 goto unlock;
1185 conn->state = BT_CONNECTED; 1238 }
1186 hci_proto_connect_cfm(conn, ev->status); 1239
1187 hci_conn_put(conn); 1240 if (!ev->status) {
1188 } 1241 struct hci_cp_remote_name_req cp;
1189 } 1242 memset(&cp, 0, sizeof(cp));
1243 bacpy(&cp.bdaddr, &conn->dst);
1244 cp.pscan_rep_mode = 0x02;
1245 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
1190 } 1246 }
1191 1247
1248 if (!hci_outgoing_auth_needed(hdev, conn)) {
1249 conn->state = BT_CONNECTED;
1250 hci_proto_connect_cfm(conn, ev->status);
1251 hci_conn_put(conn);
1252 }
1253
1254unlock:
1192 hci_dev_unlock(hdev); 1255 hci_dev_unlock(hdev);
1193} 1256}
1194 1257
@@ -1449,10 +1512,12 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
1449 conn->sent -= count; 1512 conn->sent -= count;
1450 1513
1451 if (conn->type == ACL_LINK) { 1514 if (conn->type == ACL_LINK) {
1452 if ((hdev->acl_cnt += count) > hdev->acl_pkts) 1515 hdev->acl_cnt += count;
1516 if (hdev->acl_cnt > hdev->acl_pkts)
1453 hdev->acl_cnt = hdev->acl_pkts; 1517 hdev->acl_cnt = hdev->acl_pkts;
1454 } else { 1518 } else {
1455 if ((hdev->sco_cnt += count) > hdev->sco_pkts) 1519 hdev->sco_cnt += count;
1520 if (hdev->sco_cnt > hdev->sco_pkts)
1456 hdev->sco_cnt = hdev->sco_pkts; 1521 hdev->sco_cnt = hdev->sco_pkts;
1457 } 1522 }
1458 } 1523 }
@@ -1547,7 +1612,8 @@ static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *sk
1547 if (conn && !ev->status) { 1612 if (conn && !ev->status) {
1548 struct inquiry_entry *ie; 1613 struct inquiry_entry *ie;
1549 1614
1550 if ((ie = hci_inquiry_cache_lookup(hdev, &conn->dst))) { 1615 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
1616 if (ie) {
1551 ie->data.clock_offset = ev->clock_offset; 1617 ie->data.clock_offset = ev->clock_offset;
1552 ie->timestamp = jiffies; 1618 ie->timestamp = jiffies;
1553 } 1619 }
@@ -1581,7 +1647,8 @@ static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *
1581 1647
1582 hci_dev_lock(hdev); 1648 hci_dev_lock(hdev);
1583 1649
1584 if ((ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr))) { 1650 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
1651 if (ie) {
1585 ie->data.pscan_rep_mode = ev->pscan_rep_mode; 1652 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
1586 ie->timestamp = jiffies; 1653 ie->timestamp = jiffies;
1587 } 1654 }
@@ -1646,32 +1713,37 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_b
1646 hci_dev_lock(hdev); 1713 hci_dev_lock(hdev);
1647 1714
1648 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 1715 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1649 if (conn) { 1716 if (!conn)
1650 if (!ev->status && ev->page == 0x01) { 1717 goto unlock;
1651 struct inquiry_entry *ie;
1652 1718
1653 if ((ie = hci_inquiry_cache_lookup(hdev, &conn->dst))) 1719 if (!ev->status && ev->page == 0x01) {
1654 ie->data.ssp_mode = (ev->features[0] & 0x01); 1720 struct inquiry_entry *ie;
1655 1721
1656 conn->ssp_mode = (ev->features[0] & 0x01); 1722 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
1657 } 1723 if (ie)
1724 ie->data.ssp_mode = (ev->features[0] & 0x01);
1658 1725
1659 if (conn->state == BT_CONFIG) { 1726 conn->ssp_mode = (ev->features[0] & 0x01);
1660 if (!ev->status && hdev->ssp_mode > 0 &&
1661 conn->ssp_mode > 0 && conn->out &&
1662 conn->sec_level != BT_SECURITY_SDP) {
1663 struct hci_cp_auth_requested cp;
1664 cp.handle = ev->handle;
1665 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED,
1666 sizeof(cp), &cp);
1667 } else {
1668 conn->state = BT_CONNECTED;
1669 hci_proto_connect_cfm(conn, ev->status);
1670 hci_conn_put(conn);
1671 }
1672 }
1673 } 1727 }
1674 1728
1729 if (conn->state != BT_CONFIG)
1730 goto unlock;
1731
1732 if (!ev->status) {
1733 struct hci_cp_remote_name_req cp;
1734 memset(&cp, 0, sizeof(cp));
1735 bacpy(&cp.bdaddr, &conn->dst);
1736 cp.pscan_rep_mode = 0x02;
1737 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
1738 }
1739
1740 if (!hci_outgoing_auth_needed(hdev, conn)) {
1741 conn->state = BT_CONNECTED;
1742 hci_proto_connect_cfm(conn, ev->status);
1743 hci_conn_put(conn);
1744 }
1745
1746unlock:
1675 hci_dev_unlock(hdev); 1747 hci_dev_unlock(hdev);
1676} 1748}
1677 1749
@@ -1821,7 +1893,8 @@ static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_
1821 1893
1822 hci_dev_lock(hdev); 1894 hci_dev_lock(hdev);
1823 1895
1824 if ((ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr))) 1896 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
1897 if (ie)
1825 ie->data.ssp_mode = (ev->features[0] & 0x01); 1898 ie->data.ssp_mode = (ev->features[0] & 0x01);
1826 1899
1827 hci_dev_unlock(hdev); 1900 hci_dev_unlock(hdev);
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 83acd164d39e..b3753bad2a55 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -43,7 +43,7 @@
43#include <net/sock.h> 43#include <net/sock.h>
44 44
45#include <asm/system.h> 45#include <asm/system.h>
46#include <asm/uaccess.h> 46#include <linux/uaccess.h>
47#include <asm/unaligned.h> 47#include <asm/unaligned.h>
48 48
49#include <net/bluetooth/bluetooth.h> 49#include <net/bluetooth/bluetooth.h>
@@ -125,7 +125,8 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
125 continue; 125 continue;
126 } 126 }
127 127
128 if (!(nskb = skb_clone(skb, GFP_ATOMIC))) 128 nskb = skb_clone(skb, GFP_ATOMIC);
129 if (!nskb)
129 continue; 130 continue;
130 131
131 /* Put type byte before the data */ 132 /* Put type byte before the data */
@@ -370,7 +371,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
370 } 371 }
371 372
372 if (haddr->hci_dev != HCI_DEV_NONE) { 373 if (haddr->hci_dev != HCI_DEV_NONE) {
373 if (!(hdev = hci_dev_get(haddr->hci_dev))) { 374 hdev = hci_dev_get(haddr->hci_dev);
375 if (!hdev) {
374 err = -ENODEV; 376 err = -ENODEV;
375 goto done; 377 goto done;
376 } 378 }
@@ -457,7 +459,8 @@ static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
457 if (sk->sk_state == BT_CLOSED) 459 if (sk->sk_state == BT_CLOSED)
458 return 0; 460 return 0;
459 461
460 if (!(skb = skb_recv_datagram(sk, flags, noblock, &err))) 462 skb = skb_recv_datagram(sk, flags, noblock, &err);
463 if (!skb)
461 return err; 464 return err;
462 465
463 msg->msg_namelen = 0; 466 msg->msg_namelen = 0;
@@ -499,7 +502,8 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
499 502
500 lock_sock(sk); 503 lock_sock(sk);
501 504
502 if (!(hdev = hci_pi(sk)->hdev)) { 505 hdev = hci_pi(sk)->hdev;
506 if (!hdev) {
503 err = -EBADFD; 507 err = -EBADFD;
504 goto done; 508 goto done;
505 } 509 }
@@ -509,7 +513,8 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
509 goto done; 513 goto done;
510 } 514 }
511 515
512 if (!(skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err))) 516 skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err);
517 if (!skb)
513 goto done; 518 goto done;
514 519
515 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) { 520 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index c0ee8b3928ed..29544c21f4b5 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -107,6 +107,7 @@ static void __hidp_unlink_session(struct hidp_session *session)
107 107
108static void __hidp_copy_session(struct hidp_session *session, struct hidp_conninfo *ci) 108static void __hidp_copy_session(struct hidp_session *session, struct hidp_conninfo *ci)
109{ 109{
110 memset(ci, 0, sizeof(*ci));
110 bacpy(&ci->bdaddr, &session->bdaddr); 111 bacpy(&ci->bdaddr, &session->bdaddr);
111 112
112 ci->flags = session->flags; 113 ci->flags = session->flags;
@@ -115,7 +116,6 @@ static void __hidp_copy_session(struct hidp_session *session, struct hidp_connin
115 ci->vendor = 0x0000; 116 ci->vendor = 0x0000;
116 ci->product = 0x0000; 117 ci->product = 0x0000;
117 ci->version = 0x0000; 118 ci->version = 0x0000;
118 memset(ci->name, 0, 128);
119 119
120 if (session->input) { 120 if (session->input) {
121 ci->vendor = session->input->id.vendor; 121 ci->vendor = session->input->id.vendor;
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index cd8f6ea03841..c12eccfdfe01 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -57,7 +57,7 @@
57 57
58#define VERSION "2.15" 58#define VERSION "2.15"
59 59
60static int disable_ertm = 0; 60static int disable_ertm;
61 61
62static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN; 62static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN;
63static u8 l2cap_fixed_chan[8] = { 0x02, }; 63static u8 l2cap_fixed_chan[8] = { 0x02, };
@@ -83,6 +83,18 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
83static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb); 83static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb);
84 84
85/* ---- L2CAP timers ---- */ 85/* ---- L2CAP timers ---- */
86static void l2cap_sock_set_timer(struct sock *sk, long timeout)
87{
88 BT_DBG("sk %p state %d timeout %ld", sk, sk->sk_state, timeout);
89 sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout);
90}
91
92static void l2cap_sock_clear_timer(struct sock *sk)
93{
94 BT_DBG("sock %p state %d", sk, sk->sk_state);
95 sk_stop_timer(sk, &sk->sk_timer);
96}
97
86static void l2cap_sock_timeout(unsigned long arg) 98static void l2cap_sock_timeout(unsigned long arg)
87{ 99{
88 struct sock *sk = (struct sock *) arg; 100 struct sock *sk = (struct sock *) arg;
@@ -92,6 +104,14 @@ static void l2cap_sock_timeout(unsigned long arg)
92 104
93 bh_lock_sock(sk); 105 bh_lock_sock(sk);
94 106
107 if (sock_owned_by_user(sk)) {
108 /* sk is owned by user. Try again later */
109 l2cap_sock_set_timer(sk, HZ / 5);
110 bh_unlock_sock(sk);
111 sock_put(sk);
112 return;
113 }
114
95 if (sk->sk_state == BT_CONNECTED || sk->sk_state == BT_CONFIG) 115 if (sk->sk_state == BT_CONNECTED || sk->sk_state == BT_CONFIG)
96 reason = ECONNREFUSED; 116 reason = ECONNREFUSED;
97 else if (sk->sk_state == BT_CONNECT && 117 else if (sk->sk_state == BT_CONNECT &&
@@ -108,18 +128,6 @@ static void l2cap_sock_timeout(unsigned long arg)
108 sock_put(sk); 128 sock_put(sk);
109} 129}
110 130
111static void l2cap_sock_set_timer(struct sock *sk, long timeout)
112{
113 BT_DBG("sk %p state %d timeout %ld", sk, sk->sk_state, timeout);
114 sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout);
115}
116
117static void l2cap_sock_clear_timer(struct sock *sk)
118{
119 BT_DBG("sock %p state %d", sk, sk->sk_state);
120 sk_stop_timer(sk, &sk->sk_timer);
121}
122
123/* ---- L2CAP channels ---- */ 131/* ---- L2CAP channels ---- */
124static struct sock *__l2cap_get_chan_by_dcid(struct l2cap_chan_list *l, u16 cid) 132static struct sock *__l2cap_get_chan_by_dcid(struct l2cap_chan_list *l, u16 cid)
125{ 133{
@@ -743,11 +751,13 @@ found:
743/* Find socket with psm and source bdaddr. 751/* Find socket with psm and source bdaddr.
744 * Returns closest match. 752 * Returns closest match.
745 */ 753 */
746static struct sock *__l2cap_get_sock_by_psm(int state, __le16 psm, bdaddr_t *src) 754static struct sock *l2cap_get_sock_by_psm(int state, __le16 psm, bdaddr_t *src)
747{ 755{
748 struct sock *sk = NULL, *sk1 = NULL; 756 struct sock *sk = NULL, *sk1 = NULL;
749 struct hlist_node *node; 757 struct hlist_node *node;
750 758
759 read_lock(&l2cap_sk_list.lock);
760
751 sk_for_each(sk, node, &l2cap_sk_list.head) { 761 sk_for_each(sk, node, &l2cap_sk_list.head) {
752 if (state && sk->sk_state != state) 762 if (state && sk->sk_state != state)
753 continue; 763 continue;
@@ -762,20 +772,10 @@ static struct sock *__l2cap_get_sock_by_psm(int state, __le16 psm, bdaddr_t *src
762 sk1 = sk; 772 sk1 = sk;
763 } 773 }
764 } 774 }
765 return node ? sk : sk1;
766}
767 775
768/* Find socket with given address (psm, src).
769 * Returns locked socket */
770static inline struct sock *l2cap_get_sock_by_psm(int state, __le16 psm, bdaddr_t *src)
771{
772 struct sock *s;
773 read_lock(&l2cap_sk_list.lock);
774 s = __l2cap_get_sock_by_psm(state, psm, src);
775 if (s)
776 bh_lock_sock(s);
777 read_unlock(&l2cap_sk_list.lock); 776 read_unlock(&l2cap_sk_list.lock);
778 return s; 777
778 return node ? sk : sk1;
779} 779}
780 780
781static void l2cap_sock_destruct(struct sock *sk) 781static void l2cap_sock_destruct(struct sock *sk)
@@ -2926,6 +2926,8 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
2926 goto sendresp; 2926 goto sendresp;
2927 } 2927 }
2928 2928
2929 bh_lock_sock(parent);
2930
2929 /* Check if the ACL is secure enough (if not SDP) */ 2931 /* Check if the ACL is secure enough (if not SDP) */
2930 if (psm != cpu_to_le16(0x0001) && 2932 if (psm != cpu_to_le16(0x0001) &&
2931 !hci_conn_check_link_mode(conn->hcon)) { 2933 !hci_conn_check_link_mode(conn->hcon)) {
@@ -3078,6 +3080,14 @@ static inline int l2cap_connect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hd
3078 break; 3080 break;
3079 3081
3080 default: 3082 default:
3083 /* don't delete l2cap channel if sk is owned by user */
3084 if (sock_owned_by_user(sk)) {
3085 sk->sk_state = BT_DISCONN;
3086 l2cap_sock_clear_timer(sk);
3087 l2cap_sock_set_timer(sk, HZ / 5);
3088 break;
3089 }
3090
3081 l2cap_chan_del(sk, ECONNREFUSED); 3091 l2cap_chan_del(sk, ECONNREFUSED);
3082 break; 3092 break;
3083 } 3093 }
@@ -3283,6 +3293,15 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd
3283 3293
3284 sk->sk_shutdown = SHUTDOWN_MASK; 3294 sk->sk_shutdown = SHUTDOWN_MASK;
3285 3295
3296 /* don't delete l2cap channel if sk is owned by user */
3297 if (sock_owned_by_user(sk)) {
3298 sk->sk_state = BT_DISCONN;
3299 l2cap_sock_clear_timer(sk);
3300 l2cap_sock_set_timer(sk, HZ / 5);
3301 bh_unlock_sock(sk);
3302 return 0;
3303 }
3304
3286 l2cap_chan_del(sk, ECONNRESET); 3305 l2cap_chan_del(sk, ECONNRESET);
3287 bh_unlock_sock(sk); 3306 bh_unlock_sock(sk);
3288 3307
@@ -3305,6 +3324,15 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
3305 if (!sk) 3324 if (!sk)
3306 return 0; 3325 return 0;
3307 3326
3327 /* don't delete l2cap channel if sk is owned by user */
3328 if (sock_owned_by_user(sk)) {
3329 sk->sk_state = BT_DISCONN;
3330 l2cap_sock_clear_timer(sk);
3331 l2cap_sock_set_timer(sk, HZ / 5);
3332 bh_unlock_sock(sk);
3333 return 0;
3334 }
3335
3308 l2cap_chan_del(sk, 0); 3336 l2cap_chan_del(sk, 0);
3309 bh_unlock_sock(sk); 3337 bh_unlock_sock(sk);
3310 3338
@@ -4134,11 +4162,10 @@ static inline void l2cap_data_channel_rrframe(struct sock *sk, u16 rx_control)
4134 __mod_retrans_timer(); 4162 __mod_retrans_timer();
4135 4163
4136 pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 4164 pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY;
4137 if (pi->conn_state & L2CAP_CONN_SREJ_SENT) { 4165 if (pi->conn_state & L2CAP_CONN_SREJ_SENT)
4138 l2cap_send_ack(pi); 4166 l2cap_send_ack(pi);
4139 } else { 4167 else
4140 l2cap_ertm_send(sk); 4168 l2cap_ertm_send(sk);
4141 }
4142 } 4169 }
4143} 4170}
4144 4171
@@ -4430,6 +4457,8 @@ static inline int l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm, str
4430 if (!sk) 4457 if (!sk)
4431 goto drop; 4458 goto drop;
4432 4459
4460 bh_lock_sock(sk);
4461
4433 BT_DBG("sk %p, len %d", sk, skb->len); 4462 BT_DBG("sk %p, len %d", sk, skb->len);
4434 4463
4435 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_CONNECTED) 4464 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_CONNECTED)
@@ -4841,8 +4870,10 @@ static int __init l2cap_init(void)
4841 return err; 4870 return err;
4842 4871
4843 _busy_wq = create_singlethread_workqueue("l2cap"); 4872 _busy_wq = create_singlethread_workqueue("l2cap");
4844 if (!_busy_wq) 4873 if (!_busy_wq) {
4845 goto error; 4874 proto_unregister(&l2cap_proto);
4875 return -ENOMEM;
4876 }
4846 4877
4847 err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops); 4878 err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops);
4848 if (err < 0) { 4879 if (err < 0) {
@@ -4870,6 +4901,7 @@ static int __init l2cap_init(void)
4870 return 0; 4901 return 0;
4871 4902
4872error: 4903error:
4904 destroy_workqueue(_busy_wq);
4873 proto_unregister(&l2cap_proto); 4905 proto_unregister(&l2cap_proto);
4874 return err; 4906 return err;
4875} 4907}
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index fa642aa652bd..c1e2bbafb549 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -41,7 +41,7 @@
41#include <linux/slab.h> 41#include <linux/slab.h>
42 42
43#include <net/sock.h> 43#include <net/sock.h>
44#include <asm/uaccess.h> 44#include <linux/uaccess.h>
45#include <asm/unaligned.h> 45#include <asm/unaligned.h>
46 46
47#include <net/bluetooth/bluetooth.h> 47#include <net/bluetooth/bluetooth.h>
@@ -51,10 +51,10 @@
51 51
52#define VERSION "1.11" 52#define VERSION "1.11"
53 53
54static int disable_cfc = 0; 54static int disable_cfc;
55static int l2cap_ertm;
55static int channel_mtu = -1; 56static int channel_mtu = -1;
56static unsigned int l2cap_mtu = RFCOMM_MAX_L2CAP_MTU; 57static unsigned int l2cap_mtu = RFCOMM_MAX_L2CAP_MTU;
57static int l2cap_ertm = 0;
58 58
59static struct task_struct *rfcomm_thread; 59static struct task_struct *rfcomm_thread;
60 60
@@ -1901,7 +1901,7 @@ static inline void rfcomm_check_connection(struct rfcomm_session *s)
1901 1901
1902 BT_DBG("%p state %ld", s, s->state); 1902 BT_DBG("%p state %ld", s, s->state);
1903 1903
1904 switch(sk->sk_state) { 1904 switch (sk->sk_state) {
1905 case BT_CONNECTED: 1905 case BT_CONNECTED:
1906 s->state = BT_CONNECT; 1906 s->state = BT_CONNECT;
1907 1907
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index aec505f934df..66cc1f0c3df8 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -45,7 +45,7 @@
45#include <net/sock.h> 45#include <net/sock.h>
46 46
47#include <asm/system.h> 47#include <asm/system.h>
48#include <asm/uaccess.h> 48#include <linux/uaccess.h>
49 49
50#include <net/bluetooth/bluetooth.h> 50#include <net/bluetooth/bluetooth.h>
51#include <net/bluetooth/hci_core.h> 51#include <net/bluetooth/hci_core.h>
@@ -140,11 +140,13 @@ static struct sock *__rfcomm_get_sock_by_addr(u8 channel, bdaddr_t *src)
140/* Find socket with channel and source bdaddr. 140/* Find socket with channel and source bdaddr.
141 * Returns closest match. 141 * Returns closest match.
142 */ 142 */
143static struct sock *__rfcomm_get_sock_by_channel(int state, u8 channel, bdaddr_t *src) 143static struct sock *rfcomm_get_sock_by_channel(int state, u8 channel, bdaddr_t *src)
144{ 144{
145 struct sock *sk = NULL, *sk1 = NULL; 145 struct sock *sk = NULL, *sk1 = NULL;
146 struct hlist_node *node; 146 struct hlist_node *node;
147 147
148 read_lock(&rfcomm_sk_list.lock);
149
148 sk_for_each(sk, node, &rfcomm_sk_list.head) { 150 sk_for_each(sk, node, &rfcomm_sk_list.head) {
149 if (state && sk->sk_state != state) 151 if (state && sk->sk_state != state)
150 continue; 152 continue;
@@ -159,19 +161,10 @@ static struct sock *__rfcomm_get_sock_by_channel(int state, u8 channel, bdaddr_t
159 sk1 = sk; 161 sk1 = sk;
160 } 162 }
161 } 163 }
162 return node ? sk : sk1;
163}
164 164
165/* Find socket with given address (channel, src).
166 * Returns locked socket */
167static inline struct sock *rfcomm_get_sock_by_channel(int state, u8 channel, bdaddr_t *src)
168{
169 struct sock *s;
170 read_lock(&rfcomm_sk_list.lock);
171 s = __rfcomm_get_sock_by_channel(state, channel, src);
172 if (s) bh_lock_sock(s);
173 read_unlock(&rfcomm_sk_list.lock); 165 read_unlock(&rfcomm_sk_list.lock);
174 return s; 166
167 return node ? sk : sk1;
175} 168}
176 169
177static void rfcomm_sock_destruct(struct sock *sk) 170static void rfcomm_sock_destruct(struct sock *sk)
@@ -895,7 +888,8 @@ static int rfcomm_sock_shutdown(struct socket *sock, int how)
895 888
896 BT_DBG("sock %p, sk %p", sock, sk); 889 BT_DBG("sock %p, sk %p", sock, sk);
897 890
898 if (!sk) return 0; 891 if (!sk)
892 return 0;
899 893
900 lock_sock(sk); 894 lock_sock(sk);
901 if (!sk->sk_shutdown) { 895 if (!sk->sk_shutdown) {
@@ -945,6 +939,8 @@ int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc *
945 if (!parent) 939 if (!parent)
946 return 0; 940 return 0;
947 941
942 bh_lock_sock(parent);
943
948 /* Check for backlog size */ 944 /* Check for backlog size */
949 if (sk_acceptq_is_full(parent)) { 945 if (sk_acceptq_is_full(parent)) {
950 BT_DBG("backlog full %d", parent->sk_ack_backlog); 946 BT_DBG("backlog full %d", parent->sk_ack_backlog);
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index a9b81f5dacd1..2575c2db6404 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -58,9 +58,9 @@ struct rfcomm_dev {
58 58
59 bdaddr_t src; 59 bdaddr_t src;
60 bdaddr_t dst; 60 bdaddr_t dst;
61 u8 channel; 61 u8 channel;
62 62
63 uint modem_status; 63 uint modem_status;
64 64
65 struct rfcomm_dlc *dlc; 65 struct rfcomm_dlc *dlc;
66 struct tty_struct *tty; 66 struct tty_struct *tty;
@@ -69,7 +69,7 @@ struct rfcomm_dev {
69 69
70 struct device *tty_dev; 70 struct device *tty_dev;
71 71
72 atomic_t wmem_alloc; 72 atomic_t wmem_alloc;
73 73
74 struct sk_buff_head pending; 74 struct sk_buff_head pending;
75}; 75};
@@ -431,7 +431,8 @@ static int rfcomm_release_dev(void __user *arg)
431 431
432 BT_DBG("dev_id %d flags 0x%x", req.dev_id, req.flags); 432 BT_DBG("dev_id %d flags 0x%x", req.dev_id, req.flags);
433 433
434 if (!(dev = rfcomm_dev_get(req.dev_id))) 434 dev = rfcomm_dev_get(req.dev_id);
435 if (!dev)
435 return -ENODEV; 436 return -ENODEV;
436 437
437 if (dev->flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN)) { 438 if (dev->flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN)) {
@@ -470,7 +471,8 @@ static int rfcomm_get_dev_list(void __user *arg)
470 471
471 size = sizeof(*dl) + dev_num * sizeof(*di); 472 size = sizeof(*dl) + dev_num * sizeof(*di);
472 473
473 if (!(dl = kmalloc(size, GFP_KERNEL))) 474 dl = kmalloc(size, GFP_KERNEL);
475 if (!dl)
474 return -ENOMEM; 476 return -ENOMEM;
475 477
476 di = dl->dev_info; 478 di = dl->dev_info;
@@ -513,7 +515,8 @@ static int rfcomm_get_dev_info(void __user *arg)
513 if (copy_from_user(&di, arg, sizeof(di))) 515 if (copy_from_user(&di, arg, sizeof(di)))
514 return -EFAULT; 516 return -EFAULT;
515 517
516 if (!(dev = rfcomm_dev_get(di.id))) 518 dev = rfcomm_dev_get(di.id);
519 if (!dev)
517 return -ENODEV; 520 return -ENODEV;
518 521
519 di.flags = dev->flags; 522 di.flags = dev->flags;
@@ -561,7 +564,8 @@ static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb)
561 return; 564 return;
562 } 565 }
563 566
564 if (!(tty = dev->tty) || !skb_queue_empty(&dev->pending)) { 567 tty = dev->tty;
568 if (!tty || !skb_queue_empty(&dev->pending)) {
565 skb_queue_tail(&dev->pending, skb); 569 skb_queue_tail(&dev->pending, skb);
566 return; 570 return;
567 } 571 }
@@ -796,7 +800,8 @@ static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, in
796 800
797 memcpy(skb_put(skb, size), buf + sent, size); 801 memcpy(skb_put(skb, size), buf + sent, size);
798 802
799 if ((err = rfcomm_dlc_send(dlc, skb)) < 0) { 803 err = rfcomm_dlc_send(dlc, skb);
804 if (err < 0) {
800 kfree_skb(skb); 805 kfree_skb(skb);
801 break; 806 break;
802 } 807 }
@@ -892,7 +897,7 @@ static void rfcomm_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
892 897
893 /* Parity on/off and when on, odd/even */ 898 /* Parity on/off and when on, odd/even */
894 if (((old->c_cflag & PARENB) != (new->c_cflag & PARENB)) || 899 if (((old->c_cflag & PARENB) != (new->c_cflag & PARENB)) ||
895 ((old->c_cflag & PARODD) != (new->c_cflag & PARODD)) ) { 900 ((old->c_cflag & PARODD) != (new->c_cflag & PARODD))) {
896 changes |= RFCOMM_RPN_PM_PARITY; 901 changes |= RFCOMM_RPN_PM_PARITY;
897 BT_DBG("Parity change detected."); 902 BT_DBG("Parity change detected.");
898 } 903 }
@@ -937,11 +942,10 @@ static void rfcomm_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
937 /* POSIX does not support 1.5 stop bits and RFCOMM does not 942 /* POSIX does not support 1.5 stop bits and RFCOMM does not
938 * support 2 stop bits. So a request for 2 stop bits gets 943 * support 2 stop bits. So a request for 2 stop bits gets
939 * translated to 1.5 stop bits */ 944 * translated to 1.5 stop bits */
940 if (new->c_cflag & CSTOPB) { 945 if (new->c_cflag & CSTOPB)
941 stop_bits = RFCOMM_RPN_STOP_15; 946 stop_bits = RFCOMM_RPN_STOP_15;
942 } else { 947 else
943 stop_bits = RFCOMM_RPN_STOP_1; 948 stop_bits = RFCOMM_RPN_STOP_1;
944 }
945 949
946 /* Handle number of data bits [5-8] */ 950 /* Handle number of data bits [5-8] */
947 if ((old->c_cflag & CSIZE) != (new->c_cflag & CSIZE)) 951 if ((old->c_cflag & CSIZE) != (new->c_cflag & CSIZE))
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index d0927d1fdada..960c6d1637da 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -44,7 +44,7 @@
44#include <net/sock.h> 44#include <net/sock.h>
45 45
46#include <asm/system.h> 46#include <asm/system.h>
47#include <asm/uaccess.h> 47#include <linux/uaccess.h>
48 48
49#include <net/bluetooth/bluetooth.h> 49#include <net/bluetooth/bluetooth.h>
50#include <net/bluetooth/hci_core.h> 50#include <net/bluetooth/hci_core.h>
@@ -52,7 +52,7 @@
52 52
53#define VERSION "0.6" 53#define VERSION "0.6"
54 54
55static int disable_esco = 0; 55static int disable_esco;
56 56
57static const struct proto_ops sco_sock_ops; 57static const struct proto_ops sco_sock_ops;
58 58
@@ -138,16 +138,17 @@ static inline struct sock *sco_chan_get(struct sco_conn *conn)
138 138
139static int sco_conn_del(struct hci_conn *hcon, int err) 139static int sco_conn_del(struct hci_conn *hcon, int err)
140{ 140{
141 struct sco_conn *conn; 141 struct sco_conn *conn = hcon->sco_data;
142 struct sock *sk; 142 struct sock *sk;
143 143
144 if (!(conn = hcon->sco_data)) 144 if (!conn)
145 return 0; 145 return 0;
146 146
147 BT_DBG("hcon %p conn %p, err %d", hcon, conn, err); 147 BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
148 148
149 /* Kill socket */ 149 /* Kill socket */
150 if ((sk = sco_chan_get(conn))) { 150 sk = sco_chan_get(conn);
151 if (sk) {
151 bh_lock_sock(sk); 152 bh_lock_sock(sk);
152 sco_sock_clear_timer(sk); 153 sco_sock_clear_timer(sk);
153 sco_chan_del(sk, err); 154 sco_chan_del(sk, err);
@@ -185,7 +186,8 @@ static int sco_connect(struct sock *sk)
185 186
186 BT_DBG("%s -> %s", batostr(src), batostr(dst)); 187 BT_DBG("%s -> %s", batostr(src), batostr(dst));
187 188
188 if (!(hdev = hci_get_route(dst, src))) 189 hdev = hci_get_route(dst, src);
190 if (!hdev)
189 return -EHOSTUNREACH; 191 return -EHOSTUNREACH;
190 192
191 hci_dev_lock_bh(hdev); 193 hci_dev_lock_bh(hdev);
@@ -510,7 +512,8 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen
510 /* Set destination address and psm */ 512 /* Set destination address and psm */
511 bacpy(&bt_sk(sk)->dst, &sa->sco_bdaddr); 513 bacpy(&bt_sk(sk)->dst, &sa->sco_bdaddr);
512 514
513 if ((err = sco_connect(sk))) 515 err = sco_connect(sk);
516 if (err)
514 goto done; 517 goto done;
515 518
516 err = bt_sock_wait_state(sk, BT_CONNECTED, 519 err = bt_sock_wait_state(sk, BT_CONNECTED,
@@ -828,13 +831,14 @@ static void sco_chan_del(struct sock *sk, int err)
828 831
829static void sco_conn_ready(struct sco_conn *conn) 832static void sco_conn_ready(struct sco_conn *conn)
830{ 833{
831 struct sock *parent, *sk; 834 struct sock *parent;
835 struct sock *sk = conn->sk;
832 836
833 BT_DBG("conn %p", conn); 837 BT_DBG("conn %p", conn);
834 838
835 sco_conn_lock(conn); 839 sco_conn_lock(conn);
836 840
837 if ((sk = conn->sk)) { 841 if (sk) {
838 sco_sock_clear_timer(sk); 842 sco_sock_clear_timer(sk);
839 bh_lock_sock(sk); 843 bh_lock_sock(sk);
840 sk->sk_state = BT_CONNECTED; 844 sk->sk_state = BT_CONNECTED;
@@ -882,7 +886,7 @@ static int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type)
882 int lm = 0; 886 int lm = 0;
883 887
884 if (type != SCO_LINK && type != ESCO_LINK) 888 if (type != SCO_LINK && type != ESCO_LINK)
885 return 0; 889 return -EINVAL;
886 890
887 BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr)); 891 BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr));
888 892
@@ -908,7 +912,7 @@ static int sco_connect_cfm(struct hci_conn *hcon, __u8 status)
908 BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status); 912 BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status);
909 913
910 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK) 914 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
911 return 0; 915 return -EINVAL;
912 916
913 if (!status) { 917 if (!status) {
914 struct sco_conn *conn; 918 struct sco_conn *conn;
@@ -927,7 +931,7 @@ static int sco_disconn_cfm(struct hci_conn *hcon, __u8 reason)
927 BT_DBG("hcon %p reason %d", hcon, reason); 931 BT_DBG("hcon %p reason %d", hcon, reason);
928 932
929 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK) 933 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
930 return 0; 934 return -EINVAL;
931 935
932 sco_conn_del(hcon, bt_err(reason)); 936 sco_conn_del(hcon, bt_err(reason));
933 937