1 /** @file
2   Main file for NULL named library for level 3 shell command functions.
3 
4   (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
5   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
6   This program and the accompanying materials
7   are licensed and made available under the terms and conditions of the BSD License
8   which accompanies this distribution.  The full text of the license may be found at
9   http://opensource.org/licenses/bsd-license.php
10 
11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 #include "UefiShellLevel3CommandsLib.h"
16 
17 CONST CHAR16 gShellLevel3FileName[] = L"ShellCommands";
18 EFI_HANDLE gShellLevel3HiiHandle = NULL;
19 
20 /**
21   return the filename to get help from is not using HII.
22 
23   @retval The filename.
24 **/
25 CONST CHAR16*
26 EFIAPI
ShellCommandGetManFileNameLevel3(VOID)27 ShellCommandGetManFileNameLevel3 (
28   VOID
29   )
30 {
31   return (gShellLevel3FileName);
32 }
33 
34 /**
35   Constructor for the Shell Level 3 Commands library.
36 
37   Install the handlers for level 3 UEFI Shell 2.0 commands.
38 
39   @param ImageHandle    the image handle of the process
40   @param SystemTable    the EFI System Table pointer
41 
42   @retval EFI_SUCCESS        the shell command handlers were installed sucessfully
43   @retval EFI_UNSUPPORTED    the shell level required was not found.
44 **/
45 EFI_STATUS
46 EFIAPI
ShellLevel3CommandsLibConstructor(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)47 ShellLevel3CommandsLibConstructor (
48   IN EFI_HANDLE        ImageHandle,
49   IN EFI_SYSTEM_TABLE  *SystemTable
50   )
51 {
52   gShellLevel3HiiHandle = NULL;
53   //
54   // if shell level is less than 3 do nothing
55   //
56   if (PcdGet8(PcdShellSupportLevel) < 3) {
57     return (EFI_SUCCESS);
58   }
59 
60   gShellLevel3HiiHandle = HiiAddPackages (&gShellLevel3HiiGuid, gImageHandle, UefiShellLevel3CommandsLibStrings, NULL);
61   if (gShellLevel3HiiHandle == NULL) {
62     return (EFI_DEVICE_ERROR);
63   }
64   //
65   // install our shell command handlers that are always installed
66   //
67   // Note: that Time, Timezone, and Date are part of level 2 library
68   //
69   ShellCommandRegisterCommandName(L"type",    ShellCommandRunType   , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_TYPE));
70   ShellCommandRegisterCommandName(L"touch",   ShellCommandRunTouch  , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_TOUCH));
71   ShellCommandRegisterCommandName(L"ver",     ShellCommandRunVer    , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_VER));
72   ShellCommandRegisterCommandName(L"alias",   ShellCommandRunAlias  , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_ALIAS));
73   ShellCommandRegisterCommandName(L"cls",     ShellCommandRunCls    , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_CLS));
74   ShellCommandRegisterCommandName(L"echo",    ShellCommandRunEcho   , ShellCommandGetManFileNameLevel3, 3, L"", FALSE, gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_ECHO));
75   ShellCommandRegisterCommandName(L"pause",   ShellCommandRunPause  , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_PAUSE));
76   ShellCommandRegisterCommandName(L"getmtc",  ShellCommandRunGetMtc , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_GETMTC));
77   ShellCommandRegisterCommandName(L"help",    ShellCommandRunHelp   , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_HELP));
78 
79   ShellCommandRegisterAlias(L"type", L"cat");
80 
81   return (EFI_SUCCESS);
82 }
83 
84 /**
85   Destructor for the library.  free any resources.
86 
87   @param ImageHandle            The image handle of the process.
88   @param SystemTable            The EFI System Table pointer.
89 **/
90 EFI_STATUS
91 EFIAPI
ShellLevel3CommandsLibDestructor(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)92 ShellLevel3CommandsLibDestructor (
93   IN EFI_HANDLE        ImageHandle,
94   IN EFI_SYSTEM_TABLE  *SystemTable
95   )
96 {
97   if (gShellLevel3HiiHandle != NULL) {
98     HiiRemovePackages(gShellLevel3HiiHandle);
99   }
100   return (EFI_SUCCESS);
101 }
102