* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- * MA 02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu-common.h"
* be continuously allocated. We do it though, to preserve similar
* behaviour between hosts. Some things, like the BD_ADDR cannot be
* preserved though (for example if a real hci is used). */
-#ifdef WORDS_BIGENDIAN
+#ifdef HOST_WORDS_BIGENDIAN
# define HNDL(raw) bswap16(raw)
#else
# define HNDL(raw) (raw)
switch (hci->lm.inquiry_mode) {
case 0x00:
- return bt_hci_inquiry_result_standard(hci, slave);
+ bt_hci_inquiry_result_standard(hci, slave);
+ return;
case 0x01:
- return bt_hci_inquiry_result_with_rssi(hci, slave);
+ bt_hci_inquiry_result_with_rssi(hci, slave);
+ return;
default:
fprintf(stderr, "%s: bad inquiry mode %02x\n", __FUNCTION__,
hci->lm.inquiry_mode);
static void bt_hci_mod_timer_1280ms(QEMUTimer *timer, int period)
{
- qemu_mod_timer(timer, qemu_get_clock(vm_clock) +
- muldiv64(period << 7, ticks_per_sec, 100));
+ qemu_mod_timer(timer, qemu_get_clock_ns(vm_clock) +
+ muldiv64(period << 7, get_ticks_per_sec(), 100));
}
static void bt_hci_inquiry_start(struct bt_hci_s *hci, int length)
if (master) {
link->acl_mode = acl_active;
hci->lm.handle[hci->lm.last_handle].acl_mode_timer =
- qemu_new_timer(vm_clock, bt_hci_mode_tick, link);
+ qemu_new_timer_ns(vm_clock, bt_hci_mode_tick, link);
}
}
static void bt_hci_connection_accept(struct bt_hci_s *hci,
struct bt_device_s *host)
{
- struct bt_hci_link_s *link = qemu_mallocz(sizeof(struct bt_hci_link_s));
+ struct bt_hci_link_s *link = g_malloc0(sizeof(struct bt_hci_link_s));
evt_conn_complete params;
uint16_t handle;
uint8_t status = HCI_SUCCESS;
tries);
if (!tries) {
- qemu_free(link);
+ g_free(link);
bt_hci_connection_reject(hci, host, HCI_REJECTED_LIMITED_RESOURCES);
status = HCI_NO_CONNECTION;
goto complete;
struct bt_hci_s *hci = hci_from_device(link->slave);
evt_conn_request params;
- if (hci->conn_req_host)
- return bt_hci_connection_reject(hci, link->host,
- HCI_REJECTED_LIMITED_RESOURCES);
+ if (hci->conn_req_host) {
+ bt_hci_connection_reject(hci, link->host,
+ HCI_REJECTED_LIMITED_RESOURCES);
+ return;
+ }
hci->conn_req_host = link->host;
/* TODO: if masked and auto-accept, then auto-accept,
* if masked and not auto-accept, then auto-reject */
/* We are the slave, we get to clean this burden */
link = (struct bt_hci_link_s *) btlink;
- qemu_free(link);
+ g_free(link);
complete:
bt_hci_lmp_link_teardown(hci, handle);
uint16_t handle = link->handle;
evt_disconn_complete params;
- qemu_free(link);
+ g_free(link);
bt_hci_lmp_link_teardown(hci, handle);
static int bt_hci_version_req(struct bt_hci_s *hci, uint16_t handle)
{
- struct bt_device_s *slave;
evt_read_remote_version_complete params;
if (bt_hci_handle_bad(hci, handle))
return -ENODEV;
- slave = bt_hci_remote_dev(hci, handle);
+ bt_hci_remote_dev(hci, handle);
bt_hci_event_status(hci, HCI_SUCCESS);
bt_hci_event_status(hci, HCI_SUCCESS);
- qemu_mod_timer(link->acl_mode_timer, qemu_get_clock(vm_clock) +
- muldiv64(interval * 625, ticks_per_sec, 1000000));
+ qemu_mod_timer(link->acl_mode_timer, qemu_get_clock_ns(vm_clock) +
+ muldiv64(interval * 625, get_ticks_per_sec(), 1000000));
bt_hci_lmp_mode_change_master(hci, link->link, mode, interval);
return 0;
hci->device.inquiry_scan = 0;
hci->device.page_scan = 0;
if (hci->device.lmp_name)
- qemu_free((void *) hci->device.lmp_name);
+ g_free((void *) hci->device.lmp_name);
hci->device.lmp_name = NULL;
hci->device.class[0] = 0x00;
hci->device.class[1] = 0x00;
LENGTH_CHECK(change_local_name);
if (hci->device.lmp_name)
- qemu_free((void *) hci->device.lmp_name);
- hci->device.lmp_name = qemu_strndup(PARAM(change_local_name, name),
+ g_free((void *) hci->device.lmp_name);
+ hci->device.lmp_name = g_strndup(PARAM(change_local_name, name),
sizeof(PARAM(change_local_name, name)));
bt_hci_event_complete_status(hci, HCI_SUCCESS);
break;
const uint8_t *data, int length)
{
struct bt_hci_s *hci = hci_from_info(info);
- struct bt_link_s *link;
uint16_t handle;
int datalen;
handle = acl_handle((data[1] << 8) | data[0]);
datalen = data[2];
- data += 3;
length -= 3;
if (bt_hci_handle_bad(hci, handle)) {
__FUNCTION__, handle);
return;
}
- handle &= ~HCI_HANDLE_OFFSET;
if (datalen > length) {
fprintf(stderr, "%s: SCO packet too short (%iB < %iB)\n",
return;
}
- link = hci->lm.handle[handle].link;
/* TODO */
/* TODO: increase counter and send EVT_NUM_COMP_PKTS if synchronous
/* TODO: notify upper layer */
struct bt_hci_s *s = opaque;
- return s->info.evt_recv(s->info.opaque, s->evt_buf, len);
+ s->info.evt_recv(s->info.opaque, s->evt_buf, len);
}
static int bt_hci_bdaddr_set(struct HCIInfo *info, const uint8_t *bd_addr)
{
struct bt_hci_s *hci = hci_from_device(dev);
- return bt_hci_done(&hci->info);
+ bt_hci_done(&hci->info);
}
struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net)
{
- struct bt_hci_s *s = qemu_mallocz(sizeof(struct bt_hci_s));
+ struct bt_hci_s *s = g_malloc0(sizeof(struct bt_hci_s));
- s->lm.inquiry_done = qemu_new_timer(vm_clock, bt_hci_inquiry_done, s);
- s->lm.inquiry_next = qemu_new_timer(vm_clock, bt_hci_inquiry_next, s);
+ s->lm.inquiry_done = qemu_new_timer_ns(vm_clock, bt_hci_inquiry_done, s);
+ s->lm.inquiry_next = qemu_new_timer_ns(vm_clock, bt_hci_inquiry_next, s);
s->conn_accept_timer =
- qemu_new_timer(vm_clock, bt_hci_conn_accept_timeout, s);
+ qemu_new_timer_ns(vm_clock, bt_hci_conn_accept_timeout, s);
s->evt_packet = bt_hci_evt_packet;
s->evt_submit = bt_hci_evt_submit;
bt_device_done(&hci->device);
if (hci->device.lmp_name)
- qemu_free((void *) hci->device.lmp_name);
+ g_free((void *) hci->device.lmp_name);
/* Be gentle and send DISCONNECT to all connected peers and those
* currently waiting for us to accept or reject a connection request.
* This frees the links. */
- if (hci->conn_req_host)
- return bt_hci_connection_reject(hci,
- hci->conn_req_host, HCI_OE_POWER_OFF);
+ if (hci->conn_req_host) {
+ bt_hci_connection_reject(hci,
+ hci->conn_req_host, HCI_OE_POWER_OFF);
+ return;
+ }
for (handle = HCI_HANDLE_OFFSET;
handle < (HCI_HANDLE_OFFSET | HCI_HANDLES_MAX); handle ++)
qemu_free_timer(hci->lm.inquiry_next);
qemu_free_timer(hci->conn_accept_timer);
- qemu_free(hci);
+ g_free(hci);
}