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