1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _CONSOLE_H 33 #define _CONSOLE_H 34 35 #include "sys/ioctl.h" 36 #include "los_config.h" 37 #ifdef LOSCFG_FS_VFS 38 #include "termios.h" 39 #ifdef LOSCFG_NET_TELNET 40 #include "telnet_dev.h" 41 #endif 42 #include "virtual_serial.h" 43 #include "los_cir_buf.h" 44 #endif 45 46 #ifdef __cplusplus 47 #if __cplusplus 48 extern "C" { 49 #endif /* __cplusplus */ 50 #endif /* __cplusplus */ 51 52 #ifdef LOSCFG_FS_VFS 53 54 /* Define two fixed console id for Console ID. */ 55 #define CONSOLE_SERIAL 1 56 #define CONSOLE_TELNET 2 57 58 #define LOSCFG_PLATFORM_CONSOLE 59 #define STDIN 0 60 #define STDOUT 1 61 #define STDERR 2 62 63 #define CONSOLE "/dev/console" 64 #define CONSOLE_NAMELEN 16 65 #define CONSOLE_RD_BLOCK 1 66 #define CONSOLE_RD_NONBLOCK 0 67 #define CONSOLE_SHELL_KEY_EVENT 0x112 68 #define CONSOLE_SHELL_EXITED 0x400 69 #define CONSOLE_FIFO_SIZE 0x400 70 #define CONSOLE_NUM 2 71 72 #define CONSOLE_CIRCBUF_SIZE 0x400 73 74 typedef struct { 75 CirBuf cirBufCB; /* Circular buffer CB */ 76 EVENT_CB_S sendEvent; /* Inform telnet send task */ 77 } CirBufSendCB; 78 79 typedef struct { 80 UINT32 consoleID; 81 UINT32 consoleType; 82 UINT32 consoleSem; 83 UINT32 consoleMask; 84 struct Vnode *devVnode; 85 CHAR *name; 86 INT32 fd; 87 UINT32 refCount; 88 UINT32 shellEntryId; 89 INT32 pgrpId; 90 BOOL isNonBlock; 91 #ifdef LOSCFG_SHELL 92 VOID *shellHandle; 93 #endif 94 UINT32 sendTaskID; 95 CirBufSendCB *cirBufSendCB; 96 UINT8 fifo[CONSOLE_FIFO_SIZE]; 97 UINT32 fifoOut; 98 UINT32 fifoIn; 99 UINT32 currentLen; 100 struct termios consoleTermios; 101 } CONSOLE_CB; 102 103 extern INT32 system_console_init(const CHAR *deviceName); 104 extern INT32 system_console_deinit(const CHAR *deviceName); 105 extern BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB); 106 extern BOOL SetSerialBlock(const CONSOLE_CB *consoleCB); 107 extern BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB); 108 extern BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB); 109 extern CONSOLE_CB *OsGetConsoleByID(INT32 consoleID); 110 extern CONSOLE_CB *OsGetConsoleByTaskID(UINT32 taskID); 111 extern INT32 ConsoleTaskReg(INT32 consoleID, UINT32 taskID); 112 extern INT32 ConsoleUpdateFd(VOID); 113 extern BOOL ConsoleEnable(VOID); 114 extern BOOL is_nonblock(const CONSOLE_CB *consoleCB); 115 extern BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB); 116 extern INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops); 117 extern INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops); 118 extern INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR *buffer, size_t bufLen); 119 extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen); 120 extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds); 121 extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg); 122 extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops); 123 #ifdef LOSCFG_KERNEL_SMP 124 extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID); 125 extern VOID OsWakeConsoleSendTask(VOID); 126 #endif 127 extern VOID KillPgrp(UINT16 consoleId); 128 129 /* console ioctl */ 130 #define CONSOLE_IOC_MAGIC 'c' 131 #define CONSOLE_CMD_RD_BLOCK_SERIAL _IO(CONSOLE_IOC_MAGIC, 1) 132 #define CONSOLE_CMD_RD_BLOCK_TELNET _IO(CONSOLE_IOC_MAGIC, 2) 133 #define CONSOLE_CONTROL_RIGHTS_CAPTURE _IO(CONSOLE_IOC_MAGIC, 3) 134 #define CONSOLE_CONTROL_RIGHTS_RELEASE _IO(CONSOLE_IOC_MAGIC, 4) 135 #define CONSOLE_CONTROL_CAPTURE_LINE _IO(CONSOLE_IOC_MAGIC, 5) 136 #define CONSOLE_CONTROL_CAPTURE_CHAR _IO(CONSOLE_IOC_MAGIC, 6) 137 #define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7) 138 139 #endif 140 141 #ifdef __cplusplus 142 #if __cplusplus 143 } 144 #endif /* __cplusplus */ 145 #endif /* __cplusplus */ 146 147 #endif /* _CONSOLE_H */ 148