aboutsummaryrefslogtreecommitdiff
path: root/hw/usb/ccid-card-emulated.c
diff options
context:
space:
mode:
authorMao Zhongyi <maozy.fnst@cn.fujitsu.com>2018-01-25 14:14:30 -0300
committerGerd Hoffmann <kraxel@redhat.com>2018-01-26 07:59:33 +0100
commitcc847bfd16d894fd8c1a2ce25f31772f6cdbbc74 (patch)
tree3b7c74e4164cc7d1c15bda1fd13c33fa9f42dade /hw/usb/ccid-card-emulated.c
parent395b95395934785ca86baafd314d0c31b307d16d (diff)
hw/usb/ccid: Make ccid_card_init() take an error parameter
Replace init() of CCIDCardClass with realize, then convert ccid_card_init(), ccid_card_initfn() and it's callbacks to take an Error** in ordor to report the error more clearly. Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 20180125171432.13554-2-f4bug@amsat.org [PMD: fixed s->card assignation in ccid_card_realize()] Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb/ccid-card-emulated.c')
-rw-r--r--hw/usb/ccid-card-emulated.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
index e646eb243b..daefd9f8f4 100644
--- a/hw/usb/ccid-card-emulated.c
+++ b/hw/usb/ccid-card-emulated.c
@@ -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 {\
@@ -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);
@@ -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;
@@ -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;
@@ -505,11 +506,11 @@ 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?*/
@@ -517,34 +518,33 @@ static int emulated_initfn(CCIDCardState *base)
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)
@@ -581,7 +581,7 @@ 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->realize = emulated_realize;
cc->exitfn = emulated_exitfn;
cc->get_atr = emulated_get_atr;
cc->apdu_from_guest = emulated_apdu_from_guest;