1#ifndef QEMU_CHAR_H
2#define QEMU_CHAR_H
3
4#include "qemu-common.h"
5#include "qemu/option.h"
6#include "qemu/main-loop.h"
7#include "qemu/bitmap.h"
8#include "qom/object.h"
9
10#define IAC_EOR 239
11#define IAC_SE 240
12#define IAC_NOP 241
13#define IAC_BREAK 243
14#define IAC_IP 244
15#define IAC_SB 250
16#define IAC 255
17
18
19typedef struct CharBackend CharBackend;
20
21typedef enum {
22 CHR_EVENT_BREAK,
23 CHR_EVENT_OPENED,
24 CHR_EVENT_MUX_IN,
25 CHR_EVENT_MUX_OUT,
26 CHR_EVENT_CLOSED
27} QEMUChrEvent;
28
29#define CHR_READ_BUF_LEN 4096
30
31typedef enum {
32
33
34
35
36 QEMU_CHAR_FEATURE_RECONNECTABLE,
37
38
39 QEMU_CHAR_FEATURE_FD_PASS,
40
41 QEMU_CHAR_FEATURE_REPLAY,
42
43 QEMU_CHAR_FEATURE_LAST,
44} ChardevFeature;
45
46#define qemu_chr_replay(chr) qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY)
47
48struct Chardev {
49 Object parent_obj;
50
51 QemuMutex chr_write_lock;
52 CharBackend *be;
53 char *label;
54 char *filename;
55 int logfd;
56 int be_open;
57 GSource *gsource;
58 GMainContext *gcontext;
59 DECLARE_BITMAP(features, QEMU_CHAR_FEATURE_LAST);
60};
61
62
63
64
65
66
67
68
69
70
71
72
73Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
74 Error **errp);
75
76
77
78
79
80
81
82
83
84void qemu_chr_parse_common(QemuOpts *opts, ChardevCommon *backend);
85
86
87
88
89
90
91
92
93ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts,
94 Error **errp);
95
96
97
98
99
100
101
102
103
104
105
106Chardev *qemu_chr_new(const char *label, const char *filename);
107
108
109
110
111
112
113
114
115void qemu_chr_change(QemuOpts *opts, Error **errp);
116
117
118
119
120
121
122void qemu_chr_cleanup(void);
123
124
125
126
127
128
129
130
131
132
133
134
135
136Chardev *qemu_chr_new_noreplay(const char *label, const char *filename);
137
138
139
140
141
142
143
144
145
146
147
148int qemu_chr_be_can_write(Chardev *s);
149
150
151
152
153
154
155
156
157
158
159
160void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len);
161
162
163
164
165
166
167
168
169
170void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len);
171
172
173
174
175
176
177
178
179void qemu_chr_be_update_read_handlers(Chardev *s,
180 GMainContext *context);
181
182
183
184
185
186
187
188
189void qemu_chr_be_event(Chardev *s, int event);
190
191int qemu_chr_add_client(Chardev *s, int fd);
192Chardev *qemu_chr_find(const char *name);
193
194bool qemu_chr_has_feature(Chardev *chr,
195 ChardevFeature feature);
196void qemu_chr_set_feature(Chardev *chr,
197 ChardevFeature feature);
198QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
199int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all);
200#define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true)
201int qemu_chr_wait_connected(Chardev *chr, Error **errp);
202
203#define TYPE_CHARDEV "chardev"
204#define CHARDEV(obj) OBJECT_CHECK(Chardev, (obj), TYPE_CHARDEV)
205#define CHARDEV_CLASS(klass) \
206 OBJECT_CLASS_CHECK(ChardevClass, (klass), TYPE_CHARDEV)
207#define CHARDEV_GET_CLASS(obj) \
208 OBJECT_GET_CLASS(ChardevClass, (obj), TYPE_CHARDEV)
209
210#define TYPE_CHARDEV_NULL "chardev-null"
211#define TYPE_CHARDEV_MUX "chardev-mux"
212#define TYPE_CHARDEV_RINGBUF "chardev-ringbuf"
213#define TYPE_CHARDEV_PTY "chardev-pty"
214#define TYPE_CHARDEV_CONSOLE "chardev-console"
215#define TYPE_CHARDEV_STDIO "chardev-stdio"
216#define TYPE_CHARDEV_PIPE "chardev-pipe"
217#define TYPE_CHARDEV_MEMORY "chardev-memory"
218#define TYPE_CHARDEV_PARALLEL "chardev-parallel"
219#define TYPE_CHARDEV_FILE "chardev-file"
220#define TYPE_CHARDEV_SERIAL "chardev-serial"
221#define TYPE_CHARDEV_SOCKET "chardev-socket"
222#define TYPE_CHARDEV_UDP "chardev-udp"
223
224#define CHARDEV_IS_RINGBUF(chr) \
225 object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_RINGBUF)
226#define CHARDEV_IS_PTY(chr) \
227 object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_PTY)
228
229typedef struct ChardevClass {
230 ObjectClass parent_class;
231
232 bool internal;
233 void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);
234
235 void (*open)(Chardev *chr, ChardevBackend *backend,
236 bool *be_opened, Error **errp);
237
238 int (*chr_write)(Chardev *s, const uint8_t *buf, int len);
239 int (*chr_sync_read)(Chardev *s, const uint8_t *buf, int len);
240 GSource *(*chr_add_watch)(Chardev *s, GIOCondition cond);
241 void (*chr_update_read_handler)(Chardev *s);
242 int (*chr_ioctl)(Chardev *s, int cmd, void *arg);
243 int (*get_msgfds)(Chardev *s, int* fds, int num);
244 int (*set_msgfds)(Chardev *s, int *fds, int num);
245 int (*chr_add_client)(Chardev *chr, int fd);
246 int (*chr_wait_connected)(Chardev *chr, Error **errp);
247 void (*chr_disconnect)(Chardev *chr);
248 void (*chr_accept_input)(Chardev *chr);
249 void (*chr_set_echo)(Chardev *chr, bool echo);
250 void (*chr_set_fe_open)(Chardev *chr, int fe_open);
251 void (*chr_set_blocking)(Chardev *chr, bool blocking);
252} ChardevClass;
253
254Chardev *qemu_chardev_new(const char *id, const char *typename,
255 ChardevBackend *backend, Error **errp);
256
257extern int term_escape_char;
258
259
260void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
261
262#endif
263