X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=bt-host.c;h=49205bf288cf2441b1a78486c1593c8c576c1967;hb=032ac6f8bfb68746cb0eea407b1cd2b22a78898f;hp=5d3e8405bd86350b1a06e936d3bb22d6bc60c9f4;hpb=fb599c9a030ac438755627f5919bfc40a57a0b9e;p=qemu.git diff --git a/bt-host.c b/bt-host.c index 5d3e8405b..49205bf28 100644 --- a/bt-host.c +++ b/bt-host.c @@ -13,28 +13,26 @@ * 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 + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . */ #include "qemu-common.h" -#include "qemu-char.h" -#include "sysemu.h" -#include "net.h" - -#include -#include -#include -#ifdef CONFIG_BLUEZ -# include -# include -# include -#else -# include "hw/bt.h" -# define HCI_MAX_FRAME_SIZE 1028 -#endif +#include "sysemu/bt.h" +#include "qemu/main-loop.h" + +#ifndef _WIN32 +# include +# include +# include +# ifdef CONFIG_BLUEZ +# include +# include +# include +# else +# include "hw/bt.h" +# define HCI_MAX_FRAME_SIZE 1028 +# endif struct bt_host_hci_s { struct HCIInfo hci; @@ -50,19 +48,19 @@ static void bt_host_send(struct HCIInfo *hci, struct bt_host_hci_s *s = (struct bt_host_hci_s *) hci; uint8_t pkt = type; struct iovec iv[2]; - int ret; - iv[0].iov_base = &pkt; + iv[0].iov_base = (void *)&pkt; iv[0].iov_len = 1; iv[1].iov_base = (void *) data; iv[1].iov_len = len; - while ((ret = writev(s->fd, iv, 2)) < 0) + while (writev(s->fd, iv, 2) < 0) { if (errno != EAGAIN && errno != EINTR) { fprintf(stderr, "qemu: error %i writing bluetooth packet.\n", errno); return; } + } } static void bt_host_cmd(struct HCIInfo *hci, const uint8_t *data, int len) @@ -80,13 +78,6 @@ static void bt_host_sco(struct HCIInfo *hci, const uint8_t *data, int len) bt_host_send(hci, HCI_SCODATA_PKT, data, len); } -static int bt_host_read_poll(void *opaque) -{ - struct bt_host_hci_s *s = (struct bt_host_hci_s *) opaque; - - return !!s->hci.evt_recv; -} - static void bt_host_read(void *opaque) { struct bt_host_hci_s *s = (struct bt_host_hci_s *) opaque; @@ -138,6 +129,7 @@ static void bt_host_read(void *opaque) pktlen = MIN(pkt[2] + 3, s->len); s->len -= pktlen; pkt += pktlen; + break; default: bad_pkt: @@ -154,7 +146,7 @@ struct HCIInfo *bt_host_hci(const char *id) { struct bt_host_hci_s *s; int fd = -1; -#ifdef CONFIG_BLUEZ +# ifdef CONFIG_BLUEZ int dev_id = hci_devid(id); struct hci_filter flt; @@ -166,33 +158,41 @@ struct HCIInfo *bt_host_hci(const char *id) fd = hci_open_dev(dev_id); /* XXX: can we ensure nobody else has the device opened? */ -#endif +# endif if (fd < 0) { fprintf(stderr, "qemu: Can't open `%s': %s (%i)\n", id, strerror(errno), errno); - return 0; + return NULL; } -#ifdef CONFIG_BLUEZ +# ifdef CONFIG_BLUEZ hci_filter_clear(&flt); hci_filter_all_ptypes(&flt); hci_filter_all_events(&flt); - if (setsockopt(fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { + if (qemu_setsockopt(fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { fprintf(stderr, "qemu: Can't set HCI filter on socket (%i)\n", errno); return 0; } -#endif +# endif - s = qemu_mallocz(sizeof(struct bt_host_hci_s)); + s = g_malloc0(sizeof(struct bt_host_hci_s)); s->fd = fd; s->hci.cmd_send = bt_host_cmd; s->hci.sco_send = bt_host_sco; s->hci.acl_send = bt_host_acl; s->hci.bdaddr_set = bt_host_bdaddr_set; - qemu_set_fd_handler2(s->fd, bt_host_read_poll, bt_host_read, 0, s); + qemu_set_fd_handler(s->fd, bt_host_read, NULL, s); return &s->hci; } +#else +struct HCIInfo *bt_host_hci(const char *id) +{ + fprintf(stderr, "qemu: bluetooth passthrough not supported (yet)\n"); + + return 0; +} +#endif