[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [5348] Use VHCI to allow the host os to participate in a qe
From: |
Andrzej Zaborowski |
Subject: |
[Qemu-devel] [5348] Use VHCI to allow the host os to participate in a qemu bluetooth " vlan". |
Date: |
Mon, 29 Sep 2008 00:31:42 +0000 |
Revision: 5348
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5348
Author: balrog
Date: 2008-09-29 00:31:41 +0000 (Mon, 29 Sep 2008)
Log Message:
-----------
Use VHCI to allow the host os to participate in a qemu bluetooth "vlan".
This does the reverse of bt-host.c, proxying from guest to host.
Appears to be more reliable.
Modified Paths:
--------------
trunk/Makefile
trunk/hw/bt.h
Added Paths:
-----------
trunk/bt-vhci.c
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2008-09-29 00:25:17 UTC (rev 5347)
+++ trunk/Makefile 2008-09-29 00:31:41 UTC (rev 5348)
@@ -81,7 +81,7 @@
OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o
OBJS+=usb-serial.o usb-net.o
OBJS+=sd.o ssi-sd.o
-OBJS+=bt.o bt-host.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
+OBJS+=bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
ifdef CONFIG_BRLAPI
OBJS+= baum.o
Added: trunk/bt-vhci.c
===================================================================
--- trunk/bt-vhci.c (rev 0)
+++ trunk/bt-vhci.c 2008-09-29 00:31:41 UTC (rev 5348)
@@ -0,0 +1,172 @@
+/*
+ * Support for host VHCIs inside qemu scatternets.
+ *
+ * Copyright (C) 2008 Andrzej Zaborowski <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include "qemu-common.h"
+#include "qemu-char.h"
+#include "sysemu.h"
+#include "net.h"
+#include "hw/bt.h"
+
+#include <sys/uio.h>
+
+#define VHCI_DEV "/dev/vhci"
+#define VHCI_UDEV "/dev/hci_vhci"
+
+struct bt_vhci_s {
+ int fd;
+ struct HCIInfo *info;
+
+ uint8_t hdr[4096];
+ int len;
+};
+
+static void vhci_read(void *opaque)
+{
+ struct bt_vhci_s *s = (struct bt_vhci_s *) opaque;
+ uint8_t *pkt;
+ int pktlen;
+
+ /* Seems that we can't read only the header first and then the amount
+ * of data indicated in the header because Linux will discard everything
+ * that's not been read in one go. */
+ s->len = read(s->fd, s->hdr, sizeof(s->hdr));
+
+ if (s->len < 0) {
+ fprintf(stderr, "qemu: error %i reading the PDU\n", errno);
+ return;
+ }
+
+ pkt = s->hdr;
+ while (s->len --)
+ switch (*pkt ++) {
+ case HCI_COMMAND_PKT:
+ if (s->len < 3)
+ goto bad_pkt;
+
+ pktlen = MIN(pkt[2] + 3, s->len);
+ s->info->cmd_send(s->info, pkt, pktlen);
+ s->len -= pktlen;
+ pkt += pktlen;
+ break;
+
+ case HCI_ACLDATA_PKT:
+ if (s->len < 4)
+ goto bad_pkt;
+
+ pktlen = MIN(((pkt[3] << 8) | pkt[2]) + 4, s->len);
+ s->info->acl_send(s->info, pkt, pktlen);
+ s->len -= pktlen;
+ pkt += pktlen;
+ break;
+
+ case HCI_SCODATA_PKT:
+ if (s->len < 3)
+ goto bad_pkt;
+
+ pktlen = MIN(pkt[2] + 3, s->len);
+ s->info->sco_send(s->info, pkt, pktlen);
+ s->len -= pktlen;
+ pkt += pktlen;
+ break;
+
+ default:
+ bad_pkt:
+ fprintf(stderr, "qemu: bad HCI packet type %02x\n", pkt[-1]);
+ }
+}
+
+static void vhci_host_send(void *opaque,
+ int type, const uint8_t *data, int len)
+{
+ struct bt_vhci_s *s = (struct bt_vhci_s *) opaque;
+#if 0
+ uint8_t pkt = type;
+ struct iovec iv[2];
+
+ iv[0].iov_base = &pkt;
+ iv[0].iov_len = 1;
+ iv[1].iov_base = (void *) data;
+ iv[1].iov_len = len;
+
+ while (writev(s->fd, iv, 2) < 0)
+ if (errno != EAGAIN && errno != EINTR) {
+ fprintf(stderr, "qemu: error %i writing bluetooth packet.\n",
+ errno);
+ return;
+ }
+#else
+ /* Apparently VHCI wants us to write everything in one chunk :-( */
+ static uint8_t buf[4096];
+
+ buf[0] = type;
+ memcpy(buf + 1, data, len);
+
+ while (write(s->fd, buf, len + 1) < 0)
+ if (errno != EAGAIN && errno != EINTR) {
+ fprintf(stderr, "qemu: error %i writing bluetooth packet.\n",
+ errno);
+ return;
+ }
+#endif
+}
+
+static void vhci_out_hci_packet_event(void *opaque,
+ const uint8_t *data, int len)
+{
+ vhci_host_send(opaque, HCI_EVENT_PKT, data, len);
+}
+
+static void vhci_out_hci_packet_acl(void *opaque,
+ const uint8_t *data, int len)
+{
+ vhci_host_send(opaque, HCI_ACLDATA_PKT, data, len);
+}
+
+void bt_vhci_init(struct HCIInfo *info)
+{
+ struct bt_vhci_s *s;
+ int err[2];
+ int fd;
+
+ fd = open(VHCI_DEV, O_RDWR);
+ err[0] = errno;
+ if (fd < 0) {
+ fd = open(VHCI_UDEV, O_RDWR);
+ err[1] = errno;
+ }
+
+ if (fd < 0) {
+ fprintf(stderr, "qemu: Can't open `%s': %s (%i)\n",
+ VHCI_DEV, strerror(err[0]), err[0]);
+ fprintf(stderr, "qemu: Can't open `%s': %s (%i)\n",
+ VHCI_UDEV, strerror(err[1]), err[1]);
+ exit(-1);
+ }
+
+ s = qemu_mallocz(sizeof(struct bt_vhci_s));
+ s->fd = fd;
+ s->info = info ?: qemu_next_hci();
+ s->info->opaque = s;
+ s->info->evt_recv = vhci_out_hci_packet_event;
+ s->info->acl_recv = vhci_out_hci_packet_acl;
+
+ qemu_set_fd_handler(s->fd, vhci_read, 0, s);
+}
Modified: trunk/hw/bt.h
===================================================================
--- trunk/hw/bt.h 2008-09-29 00:25:17 UTC (rev 5347)
+++ trunk/hw/bt.h 2008-09-29 00:31:41 UTC (rev 5348)
@@ -115,6 +115,9 @@
/* bt-host.c */
struct HCIInfo *bt_host_hci(const char *id);
+/* bt-vhci.c */
+void bt_vhci_init(struct HCIInfo *info);
+
/* bt-hci-csr.c */
enum {
csrhci_pin_reset,
@@ -167,6 +170,11 @@
/* bt-sdp.c */
void bt_l2cap_sdp_init(struct bt_l2cap_device_s *dev);
+/* bt-hid.c */
+struct bt_device_s *bt_mouse_init(struct bt_scatternet_s *net);
+struct bt_device_s *bt_tablet_init(struct bt_scatternet_s *net);
+struct bt_device_s *bt_keyboard_init(struct bt_scatternet_s *net);
+
/* Link Management Protocol layer defines */
#define LLID_ACLU_CONT 0x1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [5348] Use VHCI to allow the host os to participate in a qemu bluetooth " vlan".,
Andrzej Zaborowski <=