Do not rely on BSD style echo (which accepts -n option)
[qemu/mini2440.git] / hw / bt.c
bloba6fcba8b579b5df88a55a5e55d30327d692fd58a
1 /*
2 * Convenience functions for bluetooth.
4 * Copyright (C) 2008 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 or
9 * (at your option) version 3 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * MA 02111-1307 USA
22 #include "qemu-common.h"
23 #include "net.h"
24 #include "bt.h"
26 /* Slave implementations can ignore this */
27 static void bt_dummy_lmp_mode_change(struct bt_link_s *link)
31 /* Slaves should never receive these PDUs */
32 static void bt_dummy_lmp_connection_complete(struct bt_link_s *link)
34 if (link->slave->reject_reason)
35 fprintf(stderr, "%s: stray LMP_not_accepted received, fixme\n",
36 __FUNCTION__);
37 else
38 fprintf(stderr, "%s: stray LMP_accepted received, fixme\n",
39 __FUNCTION__);
40 exit(-1);
43 static void bt_dummy_lmp_disconnect_master(struct bt_link_s *link)
45 fprintf(stderr, "%s: stray LMP_detach received, fixme\n", __FUNCTION__);
46 exit(-1);
49 static void bt_dummy_lmp_acl_resp(struct bt_link_s *link,
50 const uint8_t *data, int start, int len)
52 fprintf(stderr, "%s: stray ACL response PDU, fixme\n", __FUNCTION__);
53 exit(-1);
56 /* Slaves that don't hold any additional per link state can use these */
57 static void bt_dummy_lmp_connection_request(struct bt_link_s *req)
59 struct bt_link_s *link = qemu_mallocz(sizeof(struct bt_link_s));
61 link->slave = req->slave;
62 link->host = req->host;
64 req->host->reject_reason = 0;
65 req->host->lmp_connection_complete(link);
68 static void bt_dummy_lmp_disconnect_slave(struct bt_link_s *link)
70 qemu_free(link);
73 static void bt_dummy_destroy(struct bt_device_s *device)
75 bt_device_done(device);
76 qemu_free(device);
79 static int bt_dev_idx = 0;
81 void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net)
83 memset(dev, 0, sizeof(*dev));
84 dev->inquiry_scan = 1;
85 dev->page_scan = 1;
87 dev->bd_addr.b[0] = bt_dev_idx & 0xff;
88 dev->bd_addr.b[1] = bt_dev_idx >> 8;
89 dev->bd_addr.b[2] = 0xd0;
90 dev->bd_addr.b[3] = 0xba;
91 dev->bd_addr.b[4] = 0xbe;
92 dev->bd_addr.b[5] = 0xba;
93 bt_dev_idx ++;
95 /* Simple slave-only devices need to implement only .lmp_acl_data */
96 dev->lmp_connection_complete = bt_dummy_lmp_connection_complete;
97 dev->lmp_disconnect_master = bt_dummy_lmp_disconnect_master;
98 dev->lmp_acl_resp = bt_dummy_lmp_acl_resp;
99 dev->lmp_mode_change = bt_dummy_lmp_mode_change;
100 dev->lmp_connection_request = bt_dummy_lmp_connection_request;
101 dev->lmp_disconnect_slave = bt_dummy_lmp_disconnect_slave;
103 dev->handle_destroy = bt_dummy_destroy;
105 dev->net = net;
106 dev->next = net->slave;
107 net->slave = dev;
110 void bt_device_done(struct bt_device_s *dev)
112 struct bt_device_s **p = &dev->net->slave;
114 while (*p && *p != dev)
115 p = &(*p)->next;
116 if (*p != dev) {
117 fprintf(stderr, "%s: bad bt device \"%s\"\n", __FUNCTION__,
118 dev->lmp_name ?: "(null)");
119 exit(-1);
122 *p = dev->next;