]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c
2 "Terminal" Control functions for Interactive IO.
4 Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include <Library/BaseMemoryLib.h>
16 #include <LibConfig.h>
19 #include <sys/termios.h>
20 #include <Device/IIO.h>
23 /** Get input baud rate.
25 Extracts the input baud rate from the termios structure pointed to by the
28 @param[in] pTermios A pointer to the termios structure from which to extract
31 @return The value of the input speed is returned exactly as it is contained
32 in the termios structure, without interpretation.
36 const struct termios
*pTermios
39 return pTermios
->c_ispeed
;
42 /** Get output baud rate.
44 Extracts the output baud rate from the termios structure pointed to by the
47 @param[in] pTermios A pointer to the termios structure from which to extract
50 @return The value of the output speed is returned exactly as it is contained
51 in the termios structure, without interpretation.
55 const struct termios
*pTermios
58 return pTermios
->c_ospeed
;
61 /** Set input baud rate.
63 Replaces the input baud rate, in the termios structure pointed to by the
64 pTermios argument, with the value of NewSpeed.
66 @param[out] pTermios A pointer to the termios structure into which to set
68 @param[in] NewSpeed The new input baud rate.
70 @retval 0 The operation completed successfully.
71 @retval -1 An error occured and errno is set to indicate the error.
72 * EINVAL - The value of NewSpeed is outside the range of
73 possible speed values as specified in <sys/termios.h>.
77 struct termios
*pTermios
,
83 if(NewSpeed
< B921600
) {
84 pTermios
->c_ispeed
= NewSpeed
;
94 /** Set output baud rate.
96 Replaces the output baud rate, in the termios structure pointed to by the
97 pTermios argument, with the value of NewSpeed.
99 @param[out] pTermios A pointer to the termios structure into which to set
100 the output baud rate.
101 @param[in] NewSpeed The new output baud rate.
103 @retval 0 The operation completed successfully.
104 @retval -1 An error occured and errno is set to indicate the error.
105 * EINVAL - The value of NewSpeed is outside the range of
106 possible speed values as specified in <sys/termios.h>.
110 struct termios
*pTermios
,
116 if(NewSpeed
< B921600
) {
117 pTermios
->c_ospeed
= NewSpeed
;
127 /** Get the parameters associated with an interactive IO device.
129 Get the parameters associated with the device referred to by
130 fd and store them into the termios structure referenced by pTermios.
132 @param[in] fd The file descriptor for an open interactive IO device.
133 @param[out] pTermios A pointer to a termios structure into which to store
134 attributes of the interactive IO device.
136 @retval 0 The operation completed successfully.
137 @retval -1 An error occured and errno is set to indicate the error.
138 * EBADF - The fd argument is not a valid file descriptor.
139 * ENOTTY - The file associated with fd is not an interactive IO device.
144 struct termios
*pTermios
149 struct __filedes
*filp
;
150 struct termios
*Termio
;
153 if(ValidateFD( fd
, VALID_OPEN
)) {
154 filp
= &gMD
->fdarray
[fd
];
156 if((filp
->f_iflags
& _S_ITTY
) != 0) {
157 // fd is for a TTY or "Interactive IO" device
158 IIO
= (cIIO
*)filp
->devdata
;
159 Termio
= &IIO
->Termio
;
160 (void)CopyMem((void *)pTermios
, (const void *)Termio
, sizeof(struct termios
));
174 /** Set the parameters associated with an interactive IO device.
176 Set the parameters associated with the device referred to by
177 fd to the values in the termios structure referenced by pTermios.
179 Behavior is modified by the value of the OptAct parameter:
180 * TCSANOW: The change shall occur immediately.
181 * TCSADRAIN: The change shall occur after all output written to fd is
182 transmitted. This action should be used when changing parameters which
184 * TCSAFLUSH: The change shall occur after all output written to fd is
185 transmitted, and all input so far received but not read shall be
186 discarded before the change is made.
188 @param[in] fd The file descriptor for an open interactive IO device.
189 @param[in] OptAct Currently has no effect.
190 @param[in] pTermios A pointer to a termios structure into which to retrieve
191 attributes to set in the interactive IO device.
193 @retval 0 The operation completed successfully.
194 @retval -1 An error occured and errno is set to indicate the error.
195 * EBADF - The fd argument is not a valid file descriptor.
196 * ENOTTY - The file associated with fd is not an interactive IO device.
201 int OptAct
, // Currently ignored
202 const struct termios
*pTermios
207 struct __filedes
*filp
;
208 struct termios
*Termio
;
211 if(ValidateFD( fd
, VALID_OPEN
)) {
212 filp
= &gMD
->fdarray
[fd
];
214 if((filp
->f_iflags
& _S_ITTY
) != 0) {
215 // fd is for a TTY or "Interactive IO" device
216 IIO
= (cIIO
*)filp
->devdata
;
217 Termio
= &IIO
->Termio
;
218 (void)CopyMem((void *)Termio
, (const void *)pTermios
, sizeof(struct termios
));
232 /** Transmit pending output.
234 Function is not yet implemented for UEFI.
236 @param[in] fd Ignored
238 @retval -1 This function is not yet supported. errno is set to ENOTSUP.
247 /** Suspend or restart the transmission or reception of data.
249 This function will suspend or resume transmission or reception of data on
250 the file referred to by fd, depending on the value of Action.
252 Function is not yet implemented for UEFI.
254 @param[in] fd Ignored
255 @param[in] Action Ignored
257 @retval -1 This function is not yet supported. errno is set to ENOTSUP.
268 /** Discard non-transmitted output data, non-read input data, or both.
270 Function is not yet implemented for UEFI.
272 @param[in] fd Ignored
273 @param[in] QueueSelector Ignored
275 @retval -1 This function is not yet supported. errno is set to ENOTSUP.