root / hw / bt.c @ 2d9401aa
History | View | Annotate | Download (3.5 kB)
1 | 1ae26a18 | balrog | /*
|
---|---|---|---|
2 | 1ae26a18 | balrog | * Convenience functions for bluetooth.
|
3 | 1ae26a18 | balrog | *
|
4 | 1ae26a18 | balrog | * Copyright (C) 2008 Andrzej Zaborowski <balrog@zabor.org>
|
5 | 1ae26a18 | balrog | *
|
6 | 1ae26a18 | balrog | * This program is free software; you can redistribute it and/or
|
7 | 1ae26a18 | balrog | * modify it under the terms of the GNU General Public License as
|
8 | 1ae26a18 | balrog | * published by the Free Software Foundation; either version 2 or
|
9 | 1ae26a18 | balrog | * (at your option) version 3 of the License.
|
10 | 1ae26a18 | balrog | *
|
11 | 1ae26a18 | balrog | * This program is distributed in the hope that it will be useful,
|
12 | 1ae26a18 | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 1ae26a18 | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 1ae26a18 | balrog | * GNU General Public License for more details.
|
15 | 1ae26a18 | balrog | *
|
16 | fad6cb1a | aurel32 | * You should have received a copy of the GNU General Public License along
|
17 | fad6cb1a | aurel32 | * with this program; if not, write to the Free Software Foundation, Inc.,
|
18 | fad6cb1a | aurel32 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
19 | 1ae26a18 | balrog | */
|
20 | 1ae26a18 | balrog | |
21 | 1ae26a18 | balrog | #include "qemu-common.h" |
22 | 1ae26a18 | balrog | #include "net.h" |
23 | 1ae26a18 | balrog | #include "bt.h" |
24 | 1ae26a18 | balrog | |
25 | 1ae26a18 | balrog | /* Slave implementations can ignore this */
|
26 | 1ae26a18 | balrog | static void bt_dummy_lmp_mode_change(struct bt_link_s *link) |
27 | 1ae26a18 | balrog | { |
28 | 1ae26a18 | balrog | } |
29 | 1ae26a18 | balrog | |
30 | 1ae26a18 | balrog | /* Slaves should never receive these PDUs */
|
31 | 1ae26a18 | balrog | static void bt_dummy_lmp_connection_complete(struct bt_link_s *link) |
32 | 1ae26a18 | balrog | { |
33 | 1ae26a18 | balrog | if (link->slave->reject_reason)
|
34 | 1ae26a18 | balrog | fprintf(stderr, "%s: stray LMP_not_accepted received, fixme\n",
|
35 | 1ae26a18 | balrog | __FUNCTION__); |
36 | 1ae26a18 | balrog | else
|
37 | 1ae26a18 | balrog | fprintf(stderr, "%s: stray LMP_accepted received, fixme\n",
|
38 | 1ae26a18 | balrog | __FUNCTION__); |
39 | 1ae26a18 | balrog | exit(-1);
|
40 | 1ae26a18 | balrog | } |
41 | 1ae26a18 | balrog | |
42 | 1ae26a18 | balrog | static void bt_dummy_lmp_disconnect_master(struct bt_link_s *link) |
43 | 1ae26a18 | balrog | { |
44 | 1ae26a18 | balrog | fprintf(stderr, "%s: stray LMP_detach received, fixme\n", __FUNCTION__);
|
45 | 1ae26a18 | balrog | exit(-1);
|
46 | 1ae26a18 | balrog | } |
47 | 1ae26a18 | balrog | |
48 | 1ae26a18 | balrog | static void bt_dummy_lmp_acl_resp(struct bt_link_s *link, |
49 | 1ae26a18 | balrog | const uint8_t *data, int start, int len) |
50 | 1ae26a18 | balrog | { |
51 | 1ae26a18 | balrog | fprintf(stderr, "%s: stray ACL response PDU, fixme\n", __FUNCTION__);
|
52 | 1ae26a18 | balrog | exit(-1);
|
53 | 1ae26a18 | balrog | } |
54 | 1ae26a18 | balrog | |
55 | 1ae26a18 | balrog | /* Slaves that don't hold any additional per link state can use these */
|
56 | 1ae26a18 | balrog | static void bt_dummy_lmp_connection_request(struct bt_link_s *req) |
57 | 1ae26a18 | balrog | { |
58 | 1ae26a18 | balrog | struct bt_link_s *link = qemu_mallocz(sizeof(struct bt_link_s)); |
59 | 1ae26a18 | balrog | |
60 | 1ae26a18 | balrog | link->slave = req->slave; |
61 | 1ae26a18 | balrog | link->host = req->host; |
62 | 1ae26a18 | balrog | |
63 | 1ae26a18 | balrog | req->host->reject_reason = 0;
|
64 | 1ae26a18 | balrog | req->host->lmp_connection_complete(link); |
65 | 1ae26a18 | balrog | } |
66 | 1ae26a18 | balrog | |
67 | 1ae26a18 | balrog | static void bt_dummy_lmp_disconnect_slave(struct bt_link_s *link) |
68 | 1ae26a18 | balrog | { |
69 | 1ae26a18 | balrog | qemu_free(link); |
70 | 1ae26a18 | balrog | } |
71 | 1ae26a18 | balrog | |
72 | 1ae26a18 | balrog | static void bt_dummy_destroy(struct bt_device_s *device) |
73 | 1ae26a18 | balrog | { |
74 | 1ae26a18 | balrog | bt_device_done(device); |
75 | 1ae26a18 | balrog | qemu_free(device); |
76 | 1ae26a18 | balrog | } |
77 | 1ae26a18 | balrog | |
78 | 1ae26a18 | balrog | static int bt_dev_idx = 0; |
79 | 1ae26a18 | balrog | |
80 | 1ae26a18 | balrog | void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net) |
81 | 1ae26a18 | balrog | { |
82 | 1ae26a18 | balrog | memset(dev, 0, sizeof(*dev)); |
83 | 1ae26a18 | balrog | dev->inquiry_scan = 1;
|
84 | 1ae26a18 | balrog | dev->page_scan = 1;
|
85 | 1ae26a18 | balrog | |
86 | 1ae26a18 | balrog | dev->bd_addr.b[0] = bt_dev_idx & 0xff; |
87 | 1ae26a18 | balrog | dev->bd_addr.b[1] = bt_dev_idx >> 8; |
88 | 1ae26a18 | balrog | dev->bd_addr.b[2] = 0xd0; |
89 | 1ae26a18 | balrog | dev->bd_addr.b[3] = 0xba; |
90 | 1ae26a18 | balrog | dev->bd_addr.b[4] = 0xbe; |
91 | 1ae26a18 | balrog | dev->bd_addr.b[5] = 0xba; |
92 | 1ae26a18 | balrog | bt_dev_idx ++; |
93 | 1ae26a18 | balrog | |
94 | 1ae26a18 | balrog | /* Simple slave-only devices need to implement only .lmp_acl_data */
|
95 | 1ae26a18 | balrog | dev->lmp_connection_complete = bt_dummy_lmp_connection_complete; |
96 | 1ae26a18 | balrog | dev->lmp_disconnect_master = bt_dummy_lmp_disconnect_master; |
97 | 1ae26a18 | balrog | dev->lmp_acl_resp = bt_dummy_lmp_acl_resp; |
98 | 1ae26a18 | balrog | dev->lmp_mode_change = bt_dummy_lmp_mode_change; |
99 | 1ae26a18 | balrog | dev->lmp_connection_request = bt_dummy_lmp_connection_request; |
100 | 1ae26a18 | balrog | dev->lmp_disconnect_slave = bt_dummy_lmp_disconnect_slave; |
101 | 1ae26a18 | balrog | |
102 | 1ae26a18 | balrog | dev->handle_destroy = bt_dummy_destroy; |
103 | 1ae26a18 | balrog | |
104 | 1ae26a18 | balrog | dev->net = net; |
105 | 1ae26a18 | balrog | dev->next = net->slave; |
106 | 1ae26a18 | balrog | net->slave = dev; |
107 | 1ae26a18 | balrog | } |
108 | 1ae26a18 | balrog | |
109 | 1ae26a18 | balrog | void bt_device_done(struct bt_device_s *dev) |
110 | 1ae26a18 | balrog | { |
111 | 1ae26a18 | balrog | struct bt_device_s **p = &dev->net->slave;
|
112 | 1ae26a18 | balrog | |
113 | 1ae26a18 | balrog | while (*p && *p != dev)
|
114 | 1ae26a18 | balrog | p = &(*p)->next; |
115 | 1ae26a18 | balrog | if (*p != dev) {
|
116 | 1ae26a18 | balrog | fprintf(stderr, "%s: bad bt device \"%s\"\n", __FUNCTION__,
|
117 | 1ae26a18 | balrog | dev->lmp_name ?: "(null)");
|
118 | 1ae26a18 | balrog | exit(-1);
|
119 | 1ae26a18 | balrog | } |
120 | 1ae26a18 | balrog | |
121 | 1ae26a18 | balrog | *p = dev->next; |
122 | 1ae26a18 | balrog | } |