qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	qemu-arm@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Miroslav Rezanina" <mrezanin@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [Qemu-devel] [PATCH-for-4.1? 6/7] vl: Extract bt_parse() into its own file
Date: Fri, 12 Jul 2019 15:39:27 +0200	[thread overview]
Message-ID: <20190712133928.21394-7-philmd@redhat.com> (raw)
In-Reply-To: <20190712133928.21394-1-philmd@redhat.com>

This is required to be able to compile vl.c with CONFIG_BLUETOOTH
disabled.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
2300 lines less for the C preprocessor :)
---
 Makefile.objs       |   2 +-
 bt-opts.c           | 140 ++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/bt.h |   3 +
 vl.c                | 128 ----------------------------------------
 4 files changed, 144 insertions(+), 129 deletions(-)
 create mode 100644 bt-opts.c

diff --git a/Makefile.objs b/Makefile.objs
index 6a143dcd57..c2845a0efc 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -65,7 +65,7 @@ common-obj-y += replay/
 
 common-obj-y += ui/
 common-obj-m += ui/
-common-obj-y += bt-host.o bt-vhci.o
+common-obj-y += bt-host.o bt-vhci.o bt-opts.o
 bt-host.o-cflags := $(BLUEZ_CFLAGS)
 
 common-obj-y += dma-helpers.o
diff --git a/bt-opts.c b/bt-opts.c
new file mode 100644
index 0000000000..d14ae4836f
--- /dev/null
+++ b/bt-opts.c
@@ -0,0 +1,140 @@
+/*
+ * Bluetooth command line options.
+ *
+ * Copyright (C) 2008 Andrzej Zaborowski
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qemu/cutils.h"
+#include "sysemu/bt.h"
+#include "net/net.h"
+#include "hw/bt.h"
+
+static int nb_hcis;
+static int cur_hci;
+static struct HCIInfo *hci_table[MAX_NICS];
+
+struct HCIInfo *qemu_next_hci(void)
+{
+    if (cur_hci == nb_hcis) {
+        return &null_hci;
+    }
+
+    return hci_table[cur_hci++];
+}
+
+static int bt_hci_parse(const char *str)
+{
+    struct HCIInfo *hci;
+    bdaddr_t bdaddr;
+
+    if (nb_hcis >= MAX_NICS) {
+        error_report("too many bluetooth HCIs (max %i)", MAX_NICS);
+        return -1;
+    }
+
+    hci = hci_init(str);
+    if (!hci) {
+        return -1;
+    }
+
+    bdaddr.b[0] = 0x52;
+    bdaddr.b[1] = 0x54;
+    bdaddr.b[2] = 0x00;
+    bdaddr.b[3] = 0x12;
+    bdaddr.b[4] = 0x34;
+    bdaddr.b[5] = 0x56 + nb_hcis;
+    hci->bdaddr_set(hci, bdaddr.b);
+
+    hci_table[nb_hcis++] = hci;
+
+    return 0;
+}
+
+static void bt_vhci_add(int vlan_id)
+{
+    struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
+
+    if (!vlan->slave) {
+        warn_report("adding a VHCI to an empty scatternet %i", vlan_id);
+    }
+
+    bt_vhci_init(bt_new_hci(vlan));
+}
+
+static struct bt_device_s *bt_device_add(const char *opt)
+{
+    struct bt_scatternet_s *vlan;
+    int vlan_id = 0;
+    char *endp = strstr(opt, ",vlan=");
+    int len = (endp ? endp - opt : strlen(opt)) + 1;
+    char devname[10];
+
+    pstrcpy(devname, MIN(sizeof(devname), len), opt);
+
+    if (endp) {
+        if (qemu_strtoi(endp + 6, (const char **)&endp, 0, &vlan_id) < 0) {
+            error_report("unrecognised bluetooth vlan Id");
+            return 0;
+        }
+    }
+
+    vlan = qemu_find_bt_vlan(vlan_id);
+
+    if (!vlan->slave) {
+        warn_report("adding a slave device to an empty scatternet %i",
+                    vlan_id);
+    }
+
+    if (!strcmp(devname, "keyboard")) {
+        return bt_keyboard_init(vlan);
+    }
+
+    error_report("unsupported bluetooth device '%s'", devname);
+    return 0;
+}
+
+int bt_parse(const char *opt)
+{
+    const char *endp, *p;
+    int vlan;
+
+    if (strstart(opt, "hci", &endp)) {
+        if (!*endp || *endp == ',') {
+            if (*endp) {
+                if (!strstart(endp, ",vlan=", 0)) {
+                    opt = endp + 1;
+                }
+            }
+
+            return bt_hci_parse(opt);
+       }
+    } else if (strstart(opt, "vhci", &endp)) {
+        if (!*endp || *endp == ',') {
+            if (*endp) {
+                if (strstart(endp, ",vlan=", &p)) {
+                    if (qemu_strtoi(p, &endp, 0, &vlan) < 0) {
+                        error_report("bad scatternet '%s'", p);
+                        return 1;
+                    }
+                } else {
+                    error_report("bad parameter '%s'", endp + 1);
+                    return 1;
+                }
+            } else {
+                vlan = 0;
+            }
+
+            bt_vhci_add(vlan);
+            return 0;
+        }
+    } else if (strstart(opt, "device:", &endp)) {
+        return !bt_device_add(endp);
+    }
+
+    error_report("bad bluetooth parameter '%s'", opt);
+    return 1;
+}
diff --git a/include/sysemu/bt.h b/include/sysemu/bt.h
index 2fd8c0f14b..5b73709c2d 100644
--- a/include/sysemu/bt.h
+++ b/include/sysemu/bt.h
@@ -17,4 +17,7 @@ typedef struct HCIInfo {
 struct HCIInfo *bt_host_hci(const char *id);
 struct HCIInfo *qemu_next_hci(void);
 
+/* TODO Convert bt-opts.c to opts_init() and remove from here. */
+int bt_parse(const char *opt);
+
 #endif
diff --git a/vl.c b/vl.c
index c7f4d01c99..3a6dd3ba2b 100644
--- a/vl.c
+++ b/vl.c
@@ -60,7 +60,6 @@ int main(int argc, char **argv)
 #include "hw/isa/isa.h"
 #include "hw/scsi/scsi.h"
 #include "hw/display/vga.h"
-#include "hw/bt.h"
 #include "sysemu/watchdog.h"
 #include "hw/firmware/smbios.h"
 #include "hw/acpi/acpi.h"
@@ -913,133 +912,6 @@ static void configure_rtc(QemuOpts *opts)
 }
 
 /***********************************************************/
-/* Bluetooth support */
-static int nb_hcis;
-static int cur_hci;
-static struct HCIInfo *hci_table[MAX_NICS];
-
-struct HCIInfo *qemu_next_hci(void)
-{
-    if (cur_hci == nb_hcis) {
-        return &null_hci;
-    }
-
-    return hci_table[cur_hci++];
-}
-
-static int bt_hci_parse(const char *str)
-{
-    struct HCIInfo *hci;
-    bdaddr_t bdaddr;
-
-    if (nb_hcis >= MAX_NICS) {
-        error_report("too many bluetooth HCIs (max %i)", MAX_NICS);
-        return -1;
-    }
-
-    hci = hci_init(str);
-    if (!hci) {
-        return -1;
-    }
-
-    bdaddr.b[0] = 0x52;
-    bdaddr.b[1] = 0x54;
-    bdaddr.b[2] = 0x00;
-    bdaddr.b[3] = 0x12;
-    bdaddr.b[4] = 0x34;
-    bdaddr.b[5] = 0x56 + nb_hcis;
-    hci->bdaddr_set(hci, bdaddr.b);
-
-    hci_table[nb_hcis++] = hci;
-
-    return 0;
-}
-
-static void bt_vhci_add(int vlan_id)
-{
-    struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
-
-    if (!vlan->slave) {
-        warn_report("adding a VHCI to an empty scatternet %i",
-                    vlan_id);
-    }
-
-    bt_vhci_init(bt_new_hci(vlan));
-}
-
-static struct bt_device_s *bt_device_add(const char *opt)
-{
-    struct bt_scatternet_s *vlan;
-    int vlan_id = 0;
-    char *endp = strstr(opt, ",vlan=");
-    int len = (endp ? endp - opt : strlen(opt)) + 1;
-    char devname[10];
-
-    pstrcpy(devname, MIN(sizeof(devname), len), opt);
-
-    if (endp) {
-        if (qemu_strtoi(endp + 6, (const char **)&endp, 0, &vlan_id) < 0) {
-            error_report("unrecognised bluetooth vlan Id");
-            return 0;
-        }
-    }
-
-    vlan = qemu_find_bt_vlan(vlan_id);
-
-    if (!vlan->slave) {
-        warn_report("adding a slave device to an empty scatternet %i",
-                    vlan_id);
-    }
-
-    if (!strcmp(devname, "keyboard")) {
-        return bt_keyboard_init(vlan);
-    }
-
-    error_report("unsupported bluetooth device '%s'", devname);
-    return 0;
-}
-
-static int bt_parse(const char *opt)
-{
-    const char *endp, *p;
-    int vlan;
-
-    if (strstart(opt, "hci", &endp)) {
-        if (!*endp || *endp == ',') {
-            if (*endp) {
-                if (!strstart(endp, ",vlan=", 0)) {
-                    opt = endp + 1;
-                }
-            }
-
-            return bt_hci_parse(opt);
-       }
-    } else if (strstart(opt, "vhci", &endp)) {
-        if (!*endp || *endp == ',') {
-            if (*endp) {
-                if (strstart(endp, ",vlan=", &p)) {
-                    if (qemu_strtoi(p, &endp, 0, &vlan) < 0) {
-                        error_report("bad scatternet '%s'", p);
-                        return 1;
-                    }
-                } else {
-                    error_report("bad parameter '%s'", endp + 1);
-                    return 1;
-                }
-            } else {
-                vlan = 0;
-            }
-
-            bt_vhci_add(vlan);
-            return 0;
-        }
-    } else if (strstart(opt, "device:", &endp)) {
-        return !bt_device_add(endp);
-    }
-
-    error_report("bad bluetooth parameter '%s'", opt);
-    return 1;
-}
 
 static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
 {
-- 
2.20.1



  parent reply	other threads:[~2019-07-12 13:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-12 13:39 [Qemu-devel] [PATCH-for-4.1? 0/7] vl: Allow building with CONFIG_BLUETOOTH disabled Philippe Mathieu-Daudé
2019-07-12 13:39 ` [Qemu-devel] [PATCH-for-4.1? 1/7] hw/arm: Nokia N-series tablet requires Bluetooth Philippe Mathieu-Daudé
2019-07-15 13:05   ` Thomas Huth
2019-07-12 13:39 ` [Qemu-devel] [PATCH-for-4.1 2/7] hw/usb: Bluetooth HCI USB depends on USB & BLUETOOTH Philippe Mathieu-Daudé
2019-07-12 13:58   ` Paolo Bonzini
2019-07-12 14:16     ` Philippe Mathieu-Daudé
2019-07-12 14:58       ` Paolo Bonzini
2019-07-12 16:45         ` Philippe Mathieu-Daudé
2019-07-12 17:31           ` Paolo Bonzini
2019-07-14 16:01             ` Philippe Mathieu-Daudé
2019-07-12 13:39 ` [Qemu-devel] [PATCH-for-4.1? 3/7] MAINTAINERS: Add an entry for the Bluetooth devices Philippe Mathieu-Daudé
2019-08-14 12:47   ` Philippe Mathieu-Daudé
2019-07-12 13:39 ` [Qemu-devel] [PATCH-for-4.1? 4/7] vl: Fix 'braces' coding style issues Philippe Mathieu-Daudé
2019-07-12 13:39 ` [Qemu-devel] [PATCH-for-4.1? 5/7] vl: Use qemu_strtoi() instead of strtol() Philippe Mathieu-Daudé
2019-07-12 13:39 ` Philippe Mathieu-Daudé [this message]
2019-07-12 13:39 ` [Qemu-devel] [PATCH-for-4.1? 7/7] hw/bt: Allow building with CONFIG_BLUETOOTH disabled Philippe Mathieu-Daudé
2019-07-15 13:08   ` Thomas Huth
2019-07-14 11:04 ` [Qemu-devel] [PATCH-for-4.1? 0/7] vl: " Richard Henderson
2019-07-15 13:13 ` Thomas Huth
2019-08-13 14:00   ` Philippe Mathieu-Daudé
2019-08-13 14:04     ` Peter Maydell
2019-08-14 12:45       ` Philippe Mathieu-Daudé
2019-11-07 19:09         ` Philippe Mathieu-Daudé
2019-11-07 19:31           ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190712133928.21394-7-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=mrezanin@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).