From: John Hodge Date: Mon, 18 Nov 2013 06:35:23 +0000 (+0800) Subject: Usermode/libposix - termios and ioctl updates for dropbear testing X-Git-Tag: rel0.15~95 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b78819e65fd03a34712fc641f86fa5d9f9a4d6c7;p=tpg%2Facess2.git Usermode/libposix - termios and ioctl updates for dropbear testing --- diff --git a/Usermode/Libraries/libposix.so_src/fcntl.c b/Usermode/Libraries/libposix.so_src/fcntl.c index 431c2cbb..180a644a 100644 --- a/Usermode/Libraries/libposix.so_src/fcntl.c +++ b/Usermode/Libraries/libposix.so_src/fcntl.c @@ -44,7 +44,7 @@ int fcntl(int fd, int cmd, ...) // TODO: Extra flags for F_SETFL ret = _SysFDFlags(fd, mask, a_flags); - _SysDebug("fcntl(%i, F_SETFL, %li) = %i", fd, p_flags, ret); + _SysDebug("fcntl(%i, F_SETFL, 0x%lx) = Acess 0x%x", fd, p_flags, ret); if(ret != -1) ret = 0; diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h index e4807ec8..403f5a04 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/ioctl.h @@ -10,5 +10,7 @@ extern int ioctl(int d, int request, ...); +// ioctl numbers in termios + #endif diff --git a/Usermode/Libraries/libposix.so_src/sys_ioctl.c b/Usermode/Libraries/libposix.so_src/sys_ioctl.c index 56871bc1..866cb800 100644 --- a/Usermode/Libraries/libposix.so_src/sys_ioctl.c +++ b/Usermode/Libraries/libposix.so_src/sys_ioctl.c @@ -7,11 +7,18 @@ */ #include #include +#include // DRV_TYPE_* +#include #include +#include // TIOC* +#include // === CODE === int ioctl(int fd, int request, ...) { + va_list args; + va_start(args, request); + if( fd < 0 ) { errno = EBADF; return -1; @@ -24,21 +31,55 @@ int ioctl(int fd, int request, ...) // #1. Get device type (IOCtl 0) int devtype = _SysIOCtl(fd, 0, NULL); - + switch(devtype) { // 0: Normal file (no ioctls we care about) case 0: + _SysDebug("ioctl(%i, %i, ...) (File)", fd, request); + return -1; // 1: Has the ident set of ioctls, nothing else case 1: + _SysDebug("ioctl(%i, %i, ...) (Misc Dev)", fd, request); return -1; + // TODO: Terminals + case DRV_TYPE_TERMINAL: + switch(request) + { + case TIOCGWINSZ: { + struct winsize *ws = va_arg(args, struct winsize*); + _SysDebug("ioctl(%i, TIOCGWINSZ, %p", fd, ws); + struct ptydims dims; + _SysIOCtl(fd, PTY_IOCTL_GETDIMS, &dims); + ws->ws_col = dims.W; + ws->ws_row = dims.H; + ws->ws_xpixel = dims.PW; + ws->ws_ypixel = dims.PH; + return 0; } + case TIOCSWINSZ: { + const struct winsize *ws = va_arg(args, const struct winsize*); + _SysDebug("ioctl(%i, TIOCSWINSZ, %p", fd, ws); + struct ptydims dims; + dims.W = ws->ws_col; + dims.H = ws->ws_row; + dims.PW = ws->ws_xpixel; + dims.PH = ws->ws_ypixel; + _SysIOCtl(fd, PTY_IOCTL_SETDIMS, &dims); + return 0; } + default: + _SysDebug("ioctl(%i, TIOC? %i, ...)", fd, request); + break; + } + return -1; // NFI default: + _SysDebug("ioctl(%i, %i, ...) (DevType %i)", fd, request, devtype); return -1; } + va_end(args); return 0; } diff --git a/Usermode/Libraries/libposix.so_src/termios.c b/Usermode/Libraries/libposix.so_src/termios.c index 32fa9e16..d73de57b 100644 --- a/Usermode/Libraries/libposix.so_src/termios.c +++ b/Usermode/Libraries/libposix.so_src/termios.c @@ -59,6 +59,8 @@ int tcsetattr(int fd, int optional_actions, const struct termios *termios_p) errno = EINVAL; return -1; } + _SysDebug("*termios_p = {%x,%x,%x,%x}", + termios_p->c_iflag, termios_p->c_oflag, termios_p->c_cflag, termios_p->c_lflag); // Double-check `fd` describes a terminal if( _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) { @@ -73,8 +75,7 @@ int tcsetattr(int fd, int optional_actions, const struct termios *termios_p) if(termios_p->c_lflag & ECHO) mode.InputMode |= PTYIMODE_ECHO; - _SysDebug("*termios_p = {%x,%x,%x,%x}", - termios_p->c_iflag, termios_p->c_oflag, termios_p->c_cflag, termios_p->c_lflag); + _SysIOCtl(fd, PTY_IOCTL_SETMODE, &mode); return 0; }