2 Main file for SerMode shell Debug1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellDebug1CommandsLib.h"
11 #include <Library/ShellLib.h>
12 #include <Protocol/SerialIo.h>
15 Display information about a serial device by it's handle.
17 If HandleValid is FALSE, do all devices.
19 @param[in] HandleIdx The handle index for the device.
20 @param[in] HandleValid TRUE if HandleIdx is valid.
22 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
23 @retval SHELL_SUCCESS The operation was successful.
28 IN BOOLEAN HandleValid
31 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
38 SHELL_STATUS ShellStatus
;
43 ShellStatus
= SHELL_SUCCESS
;
45 Status
= gBS
->LocateHandleBuffer (ByProtocol
, &gEfiSerialIoProtocolGuid
, NULL
, &NoHandles
, &Handles
);
46 if (EFI_ERROR (Status
)) {
47 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_NO_FOUND
), gShellDebug1HiiHandle
, L
"sermode");
48 return SHELL_INVALID_PARAMETER
;
51 for (Index
= 0; Index
< NoHandles
; Index
++) {
53 if (ConvertHandleIndexToHandle(HandleIdx
) != Handles
[Index
]) {
58 Status
= gBS
->HandleProtocol (Handles
[Index
], &gEfiSerialIoProtocolGuid
, (VOID
**)&SerialIo
);
59 if (!EFI_ERROR (Status
)) {
60 switch (SerialIo
->Mode
->Parity
) {
96 switch (SerialIo
->Mode
->StopBits
) {
99 StopBits
= L
"Default";
112 case OneFiveStopBits
:
119 StopBits
= L
"Unknown";
125 STRING_TOKEN (STR_SERMODE_DISPLAY
),
126 gShellDebug1HiiHandle
,
127 ConvertHandleToHandleIndex (Handles
[Index
]),
129 SerialIo
->Mode
->BaudRate
,
131 SerialIo
->Mode
->DataBits
,
135 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_NO_FOUND
), gShellDebug1HiiHandle
, L
"sermode");
136 ShellStatus
= SHELL_NOT_FOUND
;
145 if (Index
== NoHandles
) {
146 if ((NoHandles
!= 0 && HandleValid
) || 0 == NoHandles
) {
147 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_NOT_FOUND
), gShellDebug1HiiHandle
, L
"sermode");
148 ShellStatus
= SHELL_NOT_FOUND
;
156 Function for 'sermode' command.
158 @param[in] ImageHandle Handle to the Image (NULL if Internal).
159 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
163 ShellCommandRunSerMode (
164 IN EFI_HANDLE ImageHandle
,
165 IN EFI_SYSTEM_TABLE
*SystemTable
169 SHELL_STATUS ShellStatus
;
173 EFI_PARITY_TYPE Parity
;
174 EFI_STOP_BITS_TYPE StopBits
;
179 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
181 CHAR16
*ProblemParam
;
185 ShellStatus
= SHELL_SUCCESS
;
187 Parity
= DefaultParity
;
193 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
194 if (EFI_ERROR(Status
)) {
195 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
196 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"sermode", ProblemParam
);
197 FreePool(ProblemParam
);
198 ShellStatus
= SHELL_INVALID_PARAMETER
;
203 if (ShellCommandLineGetCount(Package
) < 6 && ShellCommandLineGetCount(Package
) > 2) {
204 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
, L
"sermode");
205 ShellStatus
= SHELL_INVALID_PARAMETER
;
206 } else if (ShellCommandLineGetCount(Package
) > 6) {
207 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"sermode");
208 ShellStatus
= SHELL_INVALID_PARAMETER
;
210 Temp
= ShellCommandLineGetRawValue(Package
, 1);
212 Status
= ShellConvertStringToUint64(Temp
, &Intermediate
, TRUE
, FALSE
);
213 HandleIdx
= (UINTN
)Intermediate
;
214 Temp
= ShellCommandLineGetRawValue(Package
, 2);
216 ShellStatus
= DisplaySettings (HandleIdx
, TRUE
);
220 ShellStatus
= DisplaySettings (0, FALSE
);
223 Temp
= ShellCommandLineGetRawValue(Package
, 2);
225 BaudRate
= ShellStrToUintn(Temp
);
230 Temp
= ShellCommandLineGetRawValue(Package
, 3);
231 if (Temp
== NULL
|| StrLen(Temp
)>1) {
232 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"sermode", Temp
);
233 ShellStatus
= SHELL_INVALID_PARAMETER
;
238 Parity
= DefaultParity
;
258 Parity
= SpaceParity
;
261 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"sermode", Temp
);
262 ShellStatus
= SHELL_INVALID_PARAMETER
;
266 Temp
= ShellCommandLineGetRawValue(Package
, 4);
268 DataBits
= ShellStrToUintn(Temp
);
271 // make sure this is some number not in the list below.
281 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"sermode", Temp
);
282 ShellStatus
= SHELL_INVALID_PARAMETER
;
285 Temp
= ShellCommandLineGetRawValue(Package
, 5);
286 Value
= ShellStrToUintn(Temp
);
289 StopBits
= DefaultStopBits
;
293 StopBits
= OneStopBit
;
297 StopBits
= TwoStopBits
;
301 StopBits
= OneFiveStopBits
;
305 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"sermode", Temp
);
306 ShellStatus
= SHELL_INVALID_PARAMETER
;
309 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiSerialIoProtocolGuid
, NULL
, &NoHandles
, &Handles
);
310 if (EFI_ERROR (Status
)) {
311 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_NO_FOUND
), gShellDebug1HiiHandle
, L
"sermode");
312 ShellStatus
= SHELL_INVALID_PARAMETER
;
316 for (Index
= 0; Index
< NoHandles
; Index
++) {
317 if (ConvertHandleIndexToHandle (HandleIdx
) != Handles
[Index
]) {
321 Status
= gBS
->HandleProtocol (Handles
[Index
], &gEfiSerialIoProtocolGuid
, (VOID
**)&SerialIo
);
322 if (!EFI_ERROR (Status
)) {
323 Status
= SerialIo
->SetAttributes (
326 SerialIo
->Mode
->ReceiveFifoDepth
,
327 SerialIo
->Mode
->Timeout
,
332 if (EFI_ERROR (Status
)) {
333 if (Status
== EFI_INVALID_PARAMETER
) {
334 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_SET_UNSUPPORTED
), gShellDebug1HiiHandle
, L
"sermode", ConvertHandleToHandleIndex(Handles
[Index
]));
335 ShellStatus
= SHELL_UNSUPPORTED
;
336 } else if (Status
== EFI_DEVICE_ERROR
) {
337 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_SET_DEV_ERROR
), gShellDebug1HiiHandle
, L
"sermode", ConvertHandleToHandleIndex(Handles
[Index
]));
338 ShellStatus
= SHELL_ACCESS_DENIED
;
340 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_SET_FAIL
), gShellDebug1HiiHandle
, L
"sermode", ConvertHandleToHandleIndex(Handles
[Index
]));
341 ShellStatus
= SHELL_ACCESS_DENIED
;
344 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_SET_HANDLE
), gShellDebug1HiiHandle
, ConvertHandleToHandleIndex(Handles
[Index
]));
352 if (ShellStatus
== SHELL_SUCCESS
&& Index
== NoHandles
) {
353 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SERMODE_BAD_HANDLE
), gShellDebug1HiiHandle
, L
"sermode", HandleIdx
);
354 ShellStatus
= SHELL_INVALID_PARAMETER
;
358 if (Package
!= NULL
) {
359 ShellCommandLineFreeVarList (Package
);
361 if (Handles
!= NULL
) {