1 // Copyright 2017 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <stdint.h> 8 #include <zircon/device/device.h> 9 #include <zircon/device/ioctl-wrapper.h> 10 #include <zircon/device/ioctl.h> 11 #include <zircon/types.h> 12 13 // A PTY (pseudoterminal) emulates terminal devices, with a 14 // "server" side (which represents the keyboard+monitor side 15 // of the terminal and is obtained by opening /dev/misc/ptmx) 16 // and a number of "client" sides which are obtained by doing 17 // an open_at(server_pty_fd, "0", O_RDWR) or 18 // open_at(client_0_fd, "#", O_RDWR). 19 // 20 // Client PTYs are identified by the unsigned number used in 21 // the open_at(). The first Client PTY *must* be 0, and it is 22 // the only Client PTY that is allowed to create additional 23 // Client PTYs, receive Events, etc. It is the Controlling PTY. 24 25 // IOCTLs allowed on Client PTYs 26 // ----------------------------- 27 28 // Clear and/or Set PTY Features 29 // in: pty_clr_set_t change 30 // out: uint32_t features 31 #define IOCTL_PTY_CLR_SET_FEATURE \ 32 IOCTL(IOCTL_KIND_DEFAULT, IOCTL_FAMILY_PTY, 0x00) 33 34 typedef struct { 35 uint32_t clr; 36 uint32_t set; 37 } pty_clr_set_t; 38 39 // When Feature Raw is enabled, OOB Events like ^c, ^z, etc 40 // are not generated. Instead the character is read from the 41 // read() input path. 42 #define PTY_FEATURE_RAW 1 43 44 // Obtain the window size (in character cells) 45 // in: none 46 // out: pty_window_size_t 47 #define IOCTL_PTY_GET_WINDOW_SIZE \ 48 IOCTL(IOCTL_KIND_DEFAULT, IOCTL_FAMILY_PTY, 0x01) 49 50 typedef struct { 51 uint32_t width; 52 uint32_t height; 53 } pty_window_size_t; 54 55 // IOCTLs allowed on the Controlling PTY 56 // ------------------------------------- 57 58 // Select which Client PTY receives input. 59 // Reads will simply block on non-active PTYs. 60 // 61 // in: uint32_t client_pty_id 62 // out: none 63 #define IOCTL_PTY_MAKE_ACTIVE \ 64 IOCTL(IOCTL_KIND_DEFAULT, IOCTL_FAMILY_PTY, 0x10) 65 66 // Returns pending OOB events, simultaneously clearing them 67 // 68 // in: none 69 // out: uint32_t events 70 #define IOCTL_PTY_READ_EVENTS \ 71 IOCTL(IOCTL_KIND_DEFAULT, IOCTL_FAMILY_PTY, 0x13) 72 73 #define PTY_EVENT_HANGUP (1u) // no active client 74 #define PTY_EVENT_INTERRUPT (2u) // ^c 75 #define PTY_EVENT_SUSPEND (4u) // ^z 76 #define PTY_EVENT_MASK (7u) // all events 77 78 // When an event is pending, this signal is asserted 79 // On the Controlling Client PTY 80 #define PTY_SIGNAL_EVENT DEVICE_SIGNAL_OOB 81 82 // IOCTLs allowed on the Server PTY 83 // -------------------------------- 84 85 // Sets the window size 86 // 87 // in: pty_window_size_t 88 // out: none 89 #define IOCTL_PTY_SET_WINDOW_SIZE \ 90 IOCTL(IOCTL_KIND_DEFAULT, IOCTL_FAMILY_PTY, 0x20) 91 92 IOCTL_WRAPPER_IN(ioctl_pty_clr_set_feature, IOCTL_PTY_CLR_SET_FEATURE, pty_clr_set_t); 93 IOCTL_WRAPPER_OUT(ioctl_pty_get_window_size, IOCTL_PTY_GET_WINDOW_SIZE, pty_window_size_t); 94 95 IOCTL_WRAPPER_IN(ioctl_pty_make_active, IOCTL_PTY_MAKE_ACTIVE, uint32_t); 96 IOCTL_WRAPPER_OUT(ioctl_pty_read_events, IOCTL_PTY_READ_EVENTS, uint32_t); 97 98 IOCTL_WRAPPER_IN(ioctl_pty_set_window_size, IOCTL_PTY_SET_WINDOW_SIZE, pty_window_size_t); 99