hci_conn.c (a3ec4a603faf4244e275bf11b467aad092dfbd8a) hci_conn.c (fcd89c09a59a054fb986861e0862aa2fff7d7c40)
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as

--- 31 unchanged lines hidden (view full) ---

40
41#include <asm/system.h>
42#include <linux/uaccess.h>
43#include <asm/unaligned.h>
44
45#include <net/bluetooth/bluetooth.h>
46#include <net/bluetooth/hci_core.h>
47
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as

--- 31 unchanged lines hidden (view full) ---

40
41#include <asm/system.h>
42#include <linux/uaccess.h>
43#include <asm/unaligned.h>
44
45#include <net/bluetooth/bluetooth.h>
46#include <net/bluetooth/hci_core.h>
47
48static void hci_le_connect(struct hci_conn *conn)
49{
50 struct hci_dev *hdev = conn->hdev;
51 struct hci_cp_le_create_conn cp;
52
53 conn->state = BT_CONNECT;
54 conn->out = 1;
55
56 memset(&cp, 0, sizeof(cp));
57 cp.scan_interval = cpu_to_le16(0x0004);
58 cp.scan_window = cpu_to_le16(0x0004);
59 bacpy(&cp.peer_addr, &conn->dst);
60 cp.conn_interval_min = cpu_to_le16(0x0008);
61 cp.conn_interval_max = cpu_to_le16(0x0100);
62 cp.supervision_timeout = cpu_to_le16(0x0064);
63 cp.min_ce_len = cpu_to_le16(0x0001);
64 cp.max_ce_len = cpu_to_le16(0x0001);
65
66 hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(cp), &cp);
67}
68
69static void hci_le_connect_cancel(struct hci_conn *conn)
70{
71 hci_send_cmd(conn->hdev, HCI_OP_LE_CREATE_CONN_CANCEL, 0, NULL);
72}
73
48void hci_acl_connect(struct hci_conn *conn)
49{
50 struct hci_dev *hdev = conn->hdev;
51 struct inquiry_entry *ie;
52 struct hci_cp_create_conn cp;
53
54 BT_DBG("%p", conn);
55

--- 132 unchanged lines hidden (view full) ---

188 if (atomic_read(&conn->refcnt))
189 return;
190
191 hci_dev_lock(hdev);
192
193 switch (conn->state) {
194 case BT_CONNECT:
195 case BT_CONNECT2:
74void hci_acl_connect(struct hci_conn *conn)
75{
76 struct hci_dev *hdev = conn->hdev;
77 struct inquiry_entry *ie;
78 struct hci_cp_create_conn cp;
79
80 BT_DBG("%p", conn);
81

--- 132 unchanged lines hidden (view full) ---

214 if (atomic_read(&conn->refcnt))
215 return;
216
217 hci_dev_lock(hdev);
218
219 switch (conn->state) {
220 case BT_CONNECT:
221 case BT_CONNECT2:
196 if (conn->type == ACL_LINK && conn->out)
197 hci_acl_connect_cancel(conn);
222 if (conn->out) {
223 if (conn->type == ACL_LINK)
224 hci_acl_connect_cancel(conn);
225 else if (conn->type == LE_LINK)
226 hci_le_connect_cancel(conn);
227 }
198 break;
199 case BT_CONFIG:
200 case BT_CONNECTED:
201 reason = hci_proto_disconn_ind(conn);
202 hci_acl_disconn(conn, reason);
203 break;
204 default:
205 conn->state = BT_CLOSED;

--- 23 unchanged lines hidden (view full) ---

229 return NULL;
230
231 bacpy(&conn->dst, dst);
232 conn->hdev = hdev;
233 conn->type = type;
234 conn->mode = HCI_CM_ACTIVE;
235 conn->state = BT_OPEN;
236 conn->auth_type = HCI_AT_GENERAL_BONDING;
228 break;
229 case BT_CONFIG:
230 case BT_CONNECTED:
231 reason = hci_proto_disconn_ind(conn);
232 hci_acl_disconn(conn, reason);
233 break;
234 default:
235 conn->state = BT_CLOSED;

--- 23 unchanged lines hidden (view full) ---

259 return NULL;
260
261 bacpy(&conn->dst, dst);
262 conn->hdev = hdev;
263 conn->type = type;
264 conn->mode = HCI_CM_ACTIVE;
265 conn->state = BT_OPEN;
266 conn->auth_type = HCI_AT_GENERAL_BONDING;
267 conn->io_capability = hdev->io_capability;
237
238 conn->power_save = 1;
239 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
240
241 switch (type) {
242 case ACL_LINK:
243 conn->pkt_type = hdev->pkt_type & ACL_PTYPE_MASK;
244 break;

--- 110 unchanged lines hidden (view full) ---

355 if (hdev)
356 hdev = hci_dev_hold(hdev);
357
358 read_unlock_bh(&hci_dev_list_lock);
359 return hdev;
360}
361EXPORT_SYMBOL(hci_get_route);
362
268
269 conn->power_save = 1;
270 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
271
272 switch (type) {
273 case ACL_LINK:
274 conn->pkt_type = hdev->pkt_type & ACL_PTYPE_MASK;
275 break;

--- 110 unchanged lines hidden (view full) ---

386 if (hdev)
387 hdev = hci_dev_hold(hdev);
388
389 read_unlock_bh(&hci_dev_list_lock);
390 return hdev;
391}
392EXPORT_SYMBOL(hci_get_route);
393
363/* Create SCO or ACL connection.
394/* Create SCO, ACL or LE connection.
364 * Device _must_ be locked */
365struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type)
366{
367 struct hci_conn *acl;
368 struct hci_conn *sco;
395 * Device _must_ be locked */
396struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type)
397{
398 struct hci_conn *acl;
399 struct hci_conn *sco;
400 struct hci_conn *le;
369
370 BT_DBG("%s dst %s", hdev->name, batostr(dst));
371
401
402 BT_DBG("%s dst %s", hdev->name, batostr(dst));
403
404 if (type == LE_LINK) {
405 le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
406 if (!le)
407 le = hci_conn_add(hdev, LE_LINK, dst);
408 if (!le)
409 return NULL;
410 if (le->state == BT_OPEN)
411 hci_le_connect(le);
412
413 hci_conn_hold(le);
414
415 return le;
416 }
417
372 acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
373 if (!acl) {
374 acl = hci_conn_add(hdev, ACL_LINK, dst);
375 if (!acl)
376 return NULL;
377 }
378
379 hci_conn_hold(acl);

--- 364 unchanged lines hidden ---
418 acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
419 if (!acl) {
420 acl = hci_conn_add(hdev, ACL_LINK, dst);
421 if (!acl)
422 return NULL;
423 }
424
425 hci_conn_hold(acl);

--- 364 unchanged lines hidden ---