xref: /qemu/backends/cryptodev-hmp-cmds.c (revision 370ed600)
1 /*
2  * HMP commands related to cryptodev
3  *
4  * Copyright (c) 2023 Bytedance.Inc
5  *
6  * Authors:
7  *    zhenwei pi<pizhenwei@bytedance.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or
10  * (at your option) any later version.
11  */
12 
13 #include "qemu/osdep.h"
14 #include "monitor/hmp.h"
15 #include "monitor/monitor.h"
16 #include "qapi/qapi-commands-cryptodev.h"
17 #include "qapi/qmp/qdict.h"
18 
19 
20 void hmp_info_cryptodev(Monitor *mon, const QDict *qdict)
21 {
22     QCryptodevInfoList *il;
23     QCryptodevBackendServiceTypeList *sl;
24     QCryptodevBackendClientList *cl;
25 
26     for (il = qmp_query_cryptodev(NULL); il; il = il->next) {
27         g_autofree char *services = NULL;
28         QCryptodevInfo *info = il->value;
29         char *tmp_services;
30 
31         /* build a string like 'service=[akcipher|mac|hash|cipher]' */
32         for (sl = info->service; sl; sl = sl->next) {
33             const char *service = QCryptodevBackendServiceType_str(sl->value);
34 
35             if (!services) {
36                 services = g_strdup(service);
37             } else {
38                 tmp_services = g_strjoin("|", services, service, NULL);
39                 g_free(services);
40                 services = tmp_services;
41             }
42         }
43         monitor_printf(mon, "%s: service=[%s]\n", info->id, services);
44 
45         for (cl = info->client; cl; cl = cl->next) {
46             QCryptodevBackendClient *client = cl->value;
47             monitor_printf(mon, "    queue %" PRIu32 ": type=%s\n",
48                            client->queue,
49                            QCryptodevBackendType_str(client->type));
50         }
51     }
52 
53     qapi_free_QCryptodevInfoList(il);
54 }
55