Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/kraxel/tags/usb-20180126-v3-pul…
Browse files Browse the repository at this point in the history
…l-request' into staging

usb: -usbdevice cleanups, storage fix, QOMify ccid.

# gpg: Signature made Fri 26 Jan 2018 08:04:49 GMT
# gpg:                using RSA key 0x4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <[email protected]>"
# gpg:                 aka "Gerd Hoffmann <[email protected]>"
# gpg:                 aka "Gerd Hoffmann (private) <[email protected]>"
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/usb-20180126-v3-pull-request:
  usb-ccid: convert CCIDCardClass::exitfn() -> unrealize()
  usb-ccid: inline ccid_card_initfn() in ccid_card_realize()
  hw/usb/ccid: Make ccid_card_init() take an error parameter
  usb-storage: Fix share-rw option parsing
  usb: Remove legacy -usbdevice options (host, serial, disk and net)

Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
pm215 committed Jan 26, 2018
2 parents 1867d97 + 80ae865 commit d45091e
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 370 deletions.
9 changes: 8 additions & 1 deletion hw/scsi/scsi-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ static void scsi_qdev_unrealize(DeviceState *qdev, Error **errp)
/* handle legacy '-drive if=scsi,...' cmd line args */
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk,
int unit, bool removable, int bootindex,
bool share_rw,
const char *serial, Error **errp)
{
const char *driver;
Expand Down Expand Up @@ -254,6 +255,12 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk,
object_unparent(OBJECT(dev));
return NULL;
}
object_property_set_bool(OBJECT(dev), share_rw, "share-rw", &err);
if (err != NULL) {
error_propagate(errp, err);
object_unparent(OBJECT(dev));
return NULL;
}
object_property_set_bool(OBJECT(dev), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
Expand Down Expand Up @@ -288,7 +295,7 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, bool deprecated)
}
}
scsi_bus_legacy_add_drive(bus, blk_by_legacy_dinfo(dinfo),
unit, false, -1, NULL, &error_fatal);
unit, false, -1, false, NULL, &error_fatal);
}
loc_pop(&loc);
}
Expand Down
2 changes: 1 addition & 1 deletion hw/usb/Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ redirect.o-libs = $(USB_REDIR_LIBS)

# usb pass-through
ifeq ($(CONFIG_USB_LIBUSB)$(CONFIG_USB),yy)
common-obj-y += host-libusb.o host-legacy.o
common-obj-y += host-libusb.o
else
common-obj-y += host-stub.o
endif
Expand Down
48 changes: 24 additions & 24 deletions hw/usb/ccid-card-emulated.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "qemu/thread.h"
#include "qemu/main-loop.h"
#include "ccid.h"
#include "qapi/error.h"

#define DPRINTF(card, lvl, fmt, ...) \
do {\
Expand Down Expand Up @@ -401,10 +402,10 @@ static void card_event_handler(EventNotifier *notifier)
qemu_mutex_unlock(&card->event_list_mutex);
}

static int init_event_notifier(EmulatedState *card)
static int init_event_notifier(EmulatedState *card, Error **errp)
{
if (event_notifier_init(&card->notifier, false) < 0) {
DPRINTF(card, 2, "event notifier creation failed\n");
error_setg(errp, "ccid-card-emul: event notifier creation failed");
return -1;
}
event_notifier_set_handler(&card->notifier, card_event_handler);
Expand Down Expand Up @@ -480,7 +481,7 @@ static uint32_t parse_enumeration(char *str,
return ret;
}

static int emulated_initfn(CCIDCardState *base)
static void emulated_realize(CCIDCardState *base, Error **errp)
{
EmulatedState *card = EMULATED_CCID_CARD(base);
VCardEmulError ret;
Expand All @@ -494,8 +495,8 @@ static int emulated_initfn(CCIDCardState *base)
qemu_cond_init(&card->handle_apdu_cond);
card->reader = NULL;
card->quit_apdu_thread = 0;
if (init_event_notifier(card) < 0) {
return -1;
if (init_event_notifier(card, errp) < 0) {
return;
}

card->backend = 0;
Expand All @@ -505,49 +506,48 @@ static int emulated_initfn(CCIDCardState *base)
}

if (card->backend == 0) {
printf("backend must be one of:\n");
error_setg(errp, "backend must be one of:");
for (ptable = backend_enum_table; ptable->name != NULL; ++ptable) {
printf("%s\n", ptable->name);
error_append_hint(errp, "%s\n", ptable->name);
}
return -1;
return;
}

/* TODO: a passthru backened that works on local machine. third card type?*/
if (card->backend == BACKEND_CERTIFICATES) {
if (card->cert1 != NULL && card->cert2 != NULL && card->cert3 != NULL) {
ret = emulated_initialize_vcard_from_certificates(card);
} else {
printf("%s: you must provide all three certs for"
" certificates backend\n", TYPE_EMULATED_CCID);
return -1;
error_setg(errp, "%s: you must provide all three certs for"
" certificates backend", TYPE_EMULATED_CCID);
return;
}
} else {
if (card->backend != BACKEND_NSS_EMULATED) {
printf("%s: bad backend specified. The options are:\n%s (default),"
" %s.\n", TYPE_EMULATED_CCID, BACKEND_NSS_EMULATED_NAME,
BACKEND_CERTIFICATES_NAME);
return -1;
error_setg(errp, "%s: bad backend specified. The options are:%s"
" (default), %s.", TYPE_EMULATED_CCID,
BACKEND_NSS_EMULATED_NAME, BACKEND_CERTIFICATES_NAME);
return;
}
if (card->cert1 != NULL || card->cert2 != NULL || card->cert3 != NULL) {
printf("%s: unexpected cert parameters to nss emulated backend\n",
TYPE_EMULATED_CCID);
return -1;
error_setg(errp, "%s: unexpected cert parameters to nss emulated "
"backend", TYPE_EMULATED_CCID);
return;
}
/* default to mirroring the local hardware readers */
ret = wrap_vcard_emul_init(NULL);
}
if (ret != VCARD_EMUL_OK) {
printf("%s: failed to initialize vcard\n", TYPE_EMULATED_CCID);
return -1;
error_setg(errp, "%s: failed to initialize vcard", TYPE_EMULATED_CCID);
return;
}
qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread,
card, QEMU_THREAD_JOINABLE);
qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thread,
card, QEMU_THREAD_JOINABLE);
return 0;
}

static void emulated_exitfn(CCIDCardState *base)
static void emulated_unrealize(CCIDCardState *base, Error **errp)
{
EmulatedState *card = EMULATED_CCID_CARD(base);
VEvent *vevent = vevent_new(VEVENT_LAST, NULL, NULL);
Expand Down Expand Up @@ -581,8 +581,8 @@ static void emulated_class_initfn(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
CCIDCardClass *cc = CCID_CARD_CLASS(klass);

cc->initfn = emulated_initfn;
cc->exitfn = emulated_exitfn;
cc->realize = emulated_realize;
cc->unrealize = emulated_unrealize;
cc->get_atr = emulated_get_atr;
cc->apdu_from_guest = emulated_apdu_from_guest;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
Expand Down
13 changes: 7 additions & 6 deletions hw/usb/ccid-card-passthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*/

#include "qemu/osdep.h"
#include "qapi/error.h"
#include <cacard/vscard_common.h>
#include "chardev/char-fe.h"
#include "qemu/error-report.h"
#include "qemu/sockets.h"
#include "ccid.h"
#include "qapi/error.h"

#define DPRINTF(card, lvl, fmt, ...) \
do { \
Expand Down Expand Up @@ -337,29 +339,28 @@ static const uint8_t *passthru_get_atr(CCIDCardState *base, uint32_t *len)
return card->atr;
}

static int passthru_initfn(CCIDCardState *base)
static void passthru_realize(CCIDCardState *base, Error **errp)
{
PassthruState *card = PASSTHRU_CCID_CARD(base);

card->vscard_in_pos = 0;
card->vscard_in_hdr = 0;
if (qemu_chr_fe_backend_connected(&card->cs)) {
DPRINTF(card, D_INFO, "initing chardev\n");
error_setg(errp, "ccid-card-passthru: initing chardev");
qemu_chr_fe_set_handlers(&card->cs,
ccid_card_vscard_can_read,
ccid_card_vscard_read,
ccid_card_vscard_event, NULL, card, NULL, true);
ccid_card_vscard_send_init(card);
} else {
error_report("missing chardev");
return -1;
error_setg(errp, "missing chardev");
return;
}
card->debug = parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE,
card->debug);
assert(sizeof(DEFAULT_ATR) <= MAX_ATR_SIZE);
memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR));
card->atr_length = sizeof(DEFAULT_ATR);
return 0;
}

static VMStateDescription passthru_vmstate = {
Expand Down Expand Up @@ -387,7 +388,7 @@ static void passthru_class_initfn(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
CCIDCardClass *cc = CCID_CARD_CLASS(klass);

cc->initfn = passthru_initfn;
cc->realize = passthru_realize;
cc->get_atr = passthru_get_atr;
cc->apdu_from_guest = passthru_apdu_from_guest;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
Expand Down
6 changes: 4 additions & 2 deletions hw/usb/ccid.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ typedef struct CCIDCardInfo CCIDCardInfo;
* into the smartcard device (hw/ccid-card-*.c)
*/
typedef struct CCIDCardClass {
/*< private >*/
DeviceClass parent_class;
/*< public >*/
const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len);
void (*apdu_from_guest)(CCIDCardState *card,
const uint8_t *apdu,
uint32_t len);
void (*exitfn)(CCIDCardState *card);
int (*initfn)(CCIDCardState *card);
void (*realize)(CCIDCardState *card, Error **errp);
void (*unrealize)(CCIDCardState *card, Error **errp);
} CCIDCardClass;

/*
Expand Down
26 changes: 0 additions & 26 deletions hw/usb/dev-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,31 +1382,6 @@ static void usb_net_instance_init(Object *obj)
&dev->qdev, NULL);
}

static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
{
Error *local_err = NULL;
USBDevice *dev;
QemuOpts *opts;
int idx;

opts = qemu_opts_parse_noisily(qemu_find_opts("net"), cmdline, false);
if (!opts) {
return NULL;
}
qemu_opt_set(opts, "type", "nic", &error_abort);
qemu_opt_set(opts, "model", "usb", &error_abort);

idx = net_client_init(opts, false, &local_err);
if (local_err) {
error_report_err(local_err);
return NULL;
}

dev = usb_create(bus, "usb-net");
qdev_set_nic_properties(&dev->qdev, &nd_table[idx]);
return dev;
}

static const VMStateDescription vmstate_usb_net = {
.name = "usb-net",
.unmigratable = 1,
Expand Down Expand Up @@ -1446,7 +1421,6 @@ static const TypeInfo net_info = {
static void usb_net_register_types(void)
{
type_register_static(&net_info);
usb_legacy_register(TYPE_USB_NET, "net", usb_net_init);
}

type_init(usb_net_register_types)
30 changes: 0 additions & 30 deletions hw/usb/dev-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,35 +509,6 @@ static void usb_serial_realize(USBDevice *dev, Error **errp)
}
}

static USBDevice *usb_serial_init(USBBus *bus, const char *filename)
{
USBDevice *dev;
Chardev *cdrv;
char label[32];
static int index;

if (*filename == ':') {
filename++;
} else if (*filename) {
error_report("unrecognized serial USB option %s", filename);
return NULL;
}
if (!*filename) {
error_report("character device specification needed");
return NULL;
}

snprintf(label, sizeof(label), "usbserial%d", index++);
cdrv = qemu_chr_new(label, filename);
if (!cdrv)
return NULL;

dev = usb_create(bus, "usb-serial");
qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);

return dev;
}

static USBDevice *usb_braille_init(USBBus *bus, const char *unused)
{
USBDevice *dev;
Expand Down Expand Up @@ -624,7 +595,6 @@ static void usb_serial_register_types(void)
{
type_register_static(&usb_serial_dev_type_info);
type_register_static(&serial_info);
usb_legacy_register("usb-serial", "serial", usb_serial_init);
type_register_static(&braille_info);
usb_legacy_register("usb-braille", "braille", usb_braille_init);
}
Expand Down
Loading

0 comments on commit d45091e

Please sign in to comment.