]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
MdePkg: Update CpuSleep to use ARMv7 instruction.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / TimeDate.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for time, timezone, and date shell level 2 and shell level 3 functions.\r
3\r
b54fd049 4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
a405b86d 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellLevel2CommandsLib.h"\r
16\r
b54fd049 17/**\r
18 Determine if String is a valid representation for a time or date.\r
19\r
20 @param[in] String The pointer to the string to test.\r
21 @param[in] Char The delimeter character.\r
22 @param[in] Min The minimum value allowed.\r
23 @param[in] Max The maximum value allowed.\r
24 @param[in] MinusOk Whether negative numbers are permitted.\r
a405b86d 25\r
b54fd049 26 @retval TRUE String is a valid representation.\r
27 @retval FALSE String is invalid.\r
28**/\r
a405b86d 29BOOLEAN\r
30EFIAPI\r
31InternalIsTimeLikeString (\r
32 IN CONST CHAR16 *String,\r
33 IN CONST CHAR16 Char,\r
34 IN CONST UINTN Min,\r
35 IN CONST UINTN Max,\r
36 IN CONST BOOLEAN MinusOk\r
37 )\r
38{\r
39 UINTN Count;\r
40 Count = 0;\r
41\r
42 if (MinusOk) {\r
43 //\r
44 // A single minus is ok.\r
45 //\r
46 if (*String == L'-') {\r
47 String++;\r
48 }\r
49 }\r
50\r
51 //\r
52 // the first char must be numeric.\r
53 //\r
54 if (!ShellIsDecimalDigitCharacter(*String)) {\r
55 return (FALSE);\r
56 }\r
57 //\r
58 // loop through the characters and use the lib function\r
59 //\r
60 for ( ; String != NULL && *String != CHAR_NULL ; String++){\r
61 if (*String == Char) {\r
62 Count++;\r
63 if (Count > Max) {\r
64 return (FALSE);\r
65 }\r
66 continue;\r
67 }\r
68 if (!ShellIsDecimalDigitCharacter(*String)) {\r
69 return (FALSE);\r
70 }\r
71 }\r
72 if (Count < Min) {\r
73 return (FALSE);\r
74 }\r
75 return (TRUE);\r
76}\r
77\r
b54fd049 78/**\r
79 Verify that the DateString is valid and if so set that as the current \r
80 date.\r
81\r
82 @param[in] DateString The pointer to a string representation of the date.\r
83\r
84 @retval SHELL_INVALID_PARAMETER DateString was NULL.\r
85 @retval SHELL_INVALID_PARAMETER DateString was mis-formatted.\r
86 @retval SHELL_SUCCESS The operation was successful.\r
87**/\r
a405b86d 88SHELL_STATUS\r
89EFIAPI\r
90CheckAndSetDate (\r
91 IN CONST CHAR16 *DateString\r
92 )\r
93{\r
94 EFI_TIME TheTime;\r
95 EFI_STATUS Status;\r
b54fd049 96 CHAR16 *DateStringCopy;\r
97 CHAR16 *Walker;\r
98 CHAR16 *Walker1;\r
a405b86d 99\r
100 if (!InternalIsTimeLikeString(DateString, L'/', 2, 2, FALSE)) {\r
101 return (SHELL_INVALID_PARAMETER);\r
102 }\r
103\r
104 Status = gRT->GetTime(&TheTime, NULL);\r
35f26e73 105 if (EFI_ERROR(Status)) {\r
106 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
107 return (SHELL_DEVICE_ERROR);\r
108 }\r
a405b86d 109\r
b54fd049 110 DateStringCopy = NULL;\r
111 DateStringCopy = StrnCatGrow(&DateStringCopy, NULL, DateString, 0);\r
112 if (DateStringCopy == NULL) {\r
113 return (SHELL_OUT_OF_RESOURCES);\r
114 }\r
115 Walker = DateStringCopy;\r
a405b86d 116\r
117 TheTime.Month = 0xFF;\r
118 TheTime.Day = 0xFF;\r
119 TheTime.Year = 0xFFFF;\r
120\r
b54fd049 121 Walker1 = StrStr(Walker, L"/");\r
122 if (Walker1 != NULL && *Walker1 == L'/') {\r
123 *Walker1 = CHAR_NULL;\r
124 }\r
125\r
126 TheTime.Month = (UINT8)ShellStrToUintn (Walker);\r
127 if (Walker1 != NULL) {\r
128 Walker = Walker1 + 1;\r
129 }\r
33c031ee 130 Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL;\r
b54fd049 131 if (Walker1 != NULL && *Walker1 == L'/') {\r
132 *Walker1 = CHAR_NULL;\r
a405b86d 133 }\r
134 if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
b54fd049 135 TheTime.Day = (UINT8)ShellStrToUintn (Walker);\r
136 if (Walker1 != NULL) {\r
137 Walker = Walker1 + 1;\r
138 }\r
33c031ee 139 Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL;\r
b54fd049 140 if (Walker1 != NULL && *Walker1 == L'/') {\r
141 *Walker1 = CHAR_NULL;\r
a405b86d 142 }\r
143 if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
b54fd049 144 TheTime.Year = (UINT16)ShellStrToUintn (Walker);\r
a405b86d 145 }\r
146 }\r
147\r
148 if (TheTime.Year < 100) {\r
149 if (TheTime.Year >= 98) {\r
150 TheTime.Year = (UINT16)(1900 + TheTime.Year);\r
151 } else {\r
152 TheTime.Year = (UINT16)(2000 + TheTime.Year);\r
153 }\r
154 }\r
155\r
156 Status = gRT->SetTime(&TheTime);\r
157\r
158 if (!EFI_ERROR(Status)){\r
159 return (SHELL_SUCCESS);\r
160 }\r
161 return (SHELL_INVALID_PARAMETER);\r
162}\r
163\r
164/**\r
165 Function for 'date' command.\r
166\r
167 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
168 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
169**/\r
170SHELL_STATUS\r
171EFIAPI\r
172ShellCommandRunDate (\r
173 IN EFI_HANDLE ImageHandle,\r
174 IN EFI_SYSTEM_TABLE *SystemTable\r
175 )\r
176{\r
177 EFI_STATUS Status;\r
178 LIST_ENTRY *Package;\r
179 EFI_TIME TheTime;\r
180 CHAR16 *ProblemParam;\r
181 SHELL_STATUS ShellStatus;\r
182\r
183 ShellStatus = SHELL_SUCCESS;\r
184 ProblemParam = NULL;\r
185\r
186 //\r
187 // initialize the shell lib (we must be in non-auto-init...)\r
188 //\r
189 Status = ShellInitialize();\r
190 ASSERT_EFI_ERROR(Status);\r
191\r
192 //\r
193 // parse the command line\r
194 //\r
195 Status = ShellCommandLineParse (SfoParamList, &Package, &ProblemParam, TRUE);\r
196 if (EFI_ERROR(Status)) {\r
197 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
198 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r
199 FreePool(ProblemParam);\r
200 ShellStatus = SHELL_INVALID_PARAMETER;\r
201 } else {\r
202 ASSERT(FALSE);\r
203 }\r
204 } else {\r
205 //\r
206 // check for "-?"\r
207 //\r
208 if (ShellCommandLineGetFlag(Package, L"-?")) {\r
209 ASSERT(FALSE);\r
210 } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r
211 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r
212 ShellStatus = SHELL_INVALID_PARAMETER;\r
213 } else {\r
214 //\r
215 // If there are 0 value parameters, then print the current date\r
216 // else If there are any value paramerers, then print error\r
217 //\r
218 if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r
219 //\r
220 // get the current date\r
221 //\r
222 Status = gRT->GetTime(&TheTime, NULL);\r
223 ASSERT_EFI_ERROR(Status);\r
224\r
225 //\r
226 // ShellPrintEx the date in SFO or regular format\r
227 //\r
228 if (ShellCommandLineGetFlag(Package, L"-sfo")) {\r
229 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);\r
230 } else {\r
231 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);\r
232 }\r
233 } else {\r
234 if (PcdGet8(PcdShellSupportLevel) == 2) {\r
235 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r
236 ShellStatus = SHELL_INVALID_PARAMETER;\r
237 } else {\r
238 //\r
239 // perform level 3 operation here.\r
240 //\r
241 ShellStatus = CheckAndSetDate(ShellCommandLineGetRawValue(Package, 1));\r
242 if (ShellStatus != SHELL_SUCCESS) {\r
243 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r
244 ShellStatus = SHELL_INVALID_PARAMETER;\r
245 }\r
246 }\r
247 }\r
248 }\r
249 }\r
250 //\r
251 // free the command line package\r
252 //\r
253 ShellCommandLineFreeVarList (Package);\r
254\r
255 //\r
256 // return the status\r
257 //\r
258 return (ShellStatus);\r
259}\r
260\r
261//\r
262// Note "-tz" is invalid for this (non-interactive) version of 'time'.\r
263//\r
264STATIC CONST SHELL_PARAM_ITEM TimeParamList2[] = {\r
265 {L"-d", TypeValue},\r
266 {NULL, TypeMax}\r
267 };\r
268\r
269STATIC CONST SHELL_PARAM_ITEM TimeParamList3[] = {\r
270 {L"-d", TypeValue},\r
271 {L"-tz", TypeValue},\r
272 {NULL, TypeMax}\r
273 };\r
274\r
b54fd049 275/**\r
276 Verify that the TimeString is valid and if so set that as the current \r
277 time.\r
278\r
279 @param[in] TimeString The pointer to a string representation of the time.\r
280 @param[in] Tz The value to set for TimeZone.\r
281 @param[in] Daylight The value to set for Daylight.\r
282\r
283 @retval SHELL_INVALID_PARAMETER TimeString was NULL.\r
284 @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.\r
285 @retval SHELL_SUCCESS The operation was successful.\r
286**/\r
a405b86d 287SHELL_STATUS\r
288EFIAPI\r
289CheckAndSetTime (\r
290 IN CONST CHAR16 *TimeString,\r
291 IN CONST INT16 Tz,\r
292 IN CONST UINT8 Daylight\r
293 )\r
294{\r
295 EFI_TIME TheTime;\r
296 EFI_STATUS Status;\r
b54fd049 297 CHAR16 *TimeStringCopy;\r
298 CHAR16 *Walker1;\r
299 CHAR16 *Walker2;\r
a405b86d 300\r
301 if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) {\r
302 return (SHELL_INVALID_PARAMETER);\r
303 }\r
f20076da 304 if (Daylight != 0xFF &&((Daylight & (EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT)) != Daylight)) {\r
0841f3af 305 return (SHELL_INVALID_PARAMETER);\r
306 }\r
a405b86d 307\r
308 Status = gRT->GetTime(&TheTime, NULL);\r
309 ASSERT_EFI_ERROR(Status);\r
310\r
311 if (TimeString != NULL) {\r
0841f3af 312 TimeStringCopy = NULL;\r
313 TimeStringCopy = StrnCatGrow(&TimeStringCopy, NULL, TimeString, 0);\r
b54fd049 314 Walker1 = TimeStringCopy;\r
a405b86d 315 TheTime.Hour = 0xFF;\r
316 TheTime.Minute = 0xFF;\r
317\r
33c031ee 318 Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL;\r
b54fd049 319 if (Walker2 != NULL && *Walker2 == L':') {\r
320 *Walker2 = CHAR_NULL;\r
a405b86d 321 }\r
b54fd049 322 TheTime.Hour = (UINT8)ShellStrToUintn (Walker1);\r
323 if (Walker2 != NULL) {\r
324 Walker1 = Walker2 + 1;\r
325 }\r
33c031ee 326 Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL;\r
b54fd049 327 if (Walker2 != NULL && *Walker2 == L':') {\r
328 *Walker2 = CHAR_NULL;\r
329 }\r
330 if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {\r
331 TheTime.Minute = (UINT8)ShellStrToUintn (Walker1);\r
332 if (Walker2 != NULL) {\r
333 Walker1 = Walker2 + 1;\r
a405b86d 334 }\r
b54fd049 335 if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {\r
336 TheTime.Second = (UINT8)ShellStrToUintn (Walker1);\r
a405b86d 337 }\r
338 }\r
0841f3af 339 SHELL_FREE_NON_NULL(TimeStringCopy);\r
a405b86d 340 }\r
341\r
b54fd049 342\r
343 if ((Tz >= -1440 && Tz <= 1440)||(Tz == 0x7FF)) {\r
a405b86d 344 TheTime.TimeZone = Tz;\r
345 }\r
0841f3af 346\r
f20076da 347 if (Daylight != 0xFF) {\r
348 TheTime.Daylight = Daylight;\r
349 }\r
0841f3af 350\r
a405b86d 351 Status = gRT->SetTime(&TheTime);\r
352\r
353 if (!EFI_ERROR(Status)){\r
354 return (SHELL_SUCCESS);\r
355 }\r
356\r
357 return (SHELL_INVALID_PARAMETER);\r
358}\r
359\r
360/**\r
361 Function for 'time' command.\r
362\r
363 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
364 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
365**/\r
366SHELL_STATUS\r
367EFIAPI\r
368ShellCommandRunTime (\r
369 IN EFI_HANDLE ImageHandle,\r
370 IN EFI_SYSTEM_TABLE *SystemTable\r
371 )\r
372{\r
373 EFI_STATUS Status;\r
374 LIST_ENTRY *Package;\r
375 CHAR16 *Message;\r
376 EFI_TIME TheTime;\r
377 CHAR16 *ProblemParam;\r
378 SHELL_STATUS ShellStatus;\r
379 INT16 Tz;\r
380 UINT8 Daylight;\r
381 CONST CHAR16 *TempLocation;\r
382 UINTN TzMinutes;\r
383\r
384 ShellStatus = SHELL_SUCCESS;\r
385 ProblemParam = NULL;\r
386\r
387 //\r
388 // Initialize variables\r
389 //\r
390 Message = NULL;\r
391\r
392 //\r
393 // initialize the shell lib (we must be in non-auto-init...)\r
394 //\r
395 Status = ShellInitialize();\r
396 ASSERT_EFI_ERROR(Status);\r
397\r
398 //\r
399 // parse the command line\r
400 //\r
401 if (PcdGet8(PcdShellSupportLevel) == 2) {\r
402 Status = ShellCommandLineParseEx (TimeParamList2, &Package, &ProblemParam, TRUE, TRUE);\r
403 } else {\r
404 ASSERT(PcdGet8(PcdShellSupportLevel) == 3);\r
405 Status = ShellCommandLineParseEx (TimeParamList3, &Package, &ProblemParam, TRUE, TRUE);\r
406 }\r
407 if (EFI_ERROR(Status)) {\r
408 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
409 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r
410 FreePool(ProblemParam);\r
411 ShellStatus = SHELL_INVALID_PARAMETER;\r
412 } else {\r
413 ASSERT(FALSE);\r
414 }\r
415 } else {\r
416 //\r
417 // check for "-?"\r
418 //\r
419 Status = gRT->GetTime(&TheTime, NULL);\r
420 ASSERT_EFI_ERROR(Status);\r
421 if (ShellCommandLineGetFlag(Package, L"-?")) {\r
422 ASSERT(FALSE);\r
423 } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r
424 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r
425 ShellStatus = SHELL_INVALID_PARAMETER;\r
426 } else {\r
427 //\r
428 // If there are no parameters, then print the current time\r
429 //\r
430 if (ShellCommandLineGetRawValue(Package, 1) == NULL\r
431 && !ShellCommandLineGetFlag(Package, L"-d")\r
432 && !ShellCommandLineGetFlag(Package, L"-tz")) {\r
433 //\r
434 // ShellPrintEx the current time\r
435 //\r
2e8e9ed5 436 if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
a405b86d 437 TzMinutes = 0;\r
438 } else {\r
b54fd049 439 TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
a405b86d 440 }\r
441\r
442 ShellPrintHiiEx (\r
443 -1,\r
444 -1,\r
445 NULL,\r
446 STRING_TOKEN (STR_TIME_FORMAT),\r
447 gShellLevel2HiiHandle,\r
448 TheTime.Hour,\r
449 TheTime.Minute,\r
450 TheTime.Second,\r
2e8e9ed5 451 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
452 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
a405b86d 453 TzMinutes\r
454 );\r
455 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);\r
456 } else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) {\r
2e8e9ed5 457 if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
a405b86d 458 TzMinutes = 0;\r
459 } else {\r
b54fd049 460 TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
a405b86d 461 }\r
462\r
463 ShellPrintHiiEx (\r
464 -1,\r
465 -1,\r
466 NULL,\r
467 STRING_TOKEN (STR_TIME_FORMAT),\r
468 gShellLevel2HiiHandle,\r
469 TheTime.Hour,\r
470 TheTime.Minute,\r
471 TheTime.Second,\r
2e8e9ed5 472 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
473 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
a405b86d 474 TzMinutes\r
475 );\r
476 switch (TheTime.Daylight) {\r
0841f3af 477 case 0:\r
478 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST0), gShellLevel2HiiHandle);\r
479 break;\r
a405b86d 480 case EFI_TIME_ADJUST_DAYLIGHT:\r
b54fd049 481 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST1), gShellLevel2HiiHandle);\r
a405b86d 482 break;\r
483 case EFI_TIME_IN_DAYLIGHT:\r
b54fd049 484 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST2), gShellLevel2HiiHandle);\r
485 break;\r
486 case EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT:\r
487 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST3), gShellLevel2HiiHandle);\r
a405b86d 488 break;\r
489 default:\r
490 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight);\r
491 }\r
492 } else {\r
493 if (PcdGet8(PcdShellSupportLevel) == 2) {\r
494 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r
495 ShellStatus = SHELL_INVALID_PARAMETER;\r
496 } else {\r
497 //\r
498 // perform level 3 operation here.\r
499 //\r
500 if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {\r
501 if (TempLocation[0] == L'-') {\r
b54fd049 502 Tz = (INT16)(0 - ShellStrToUintn(++TempLocation));\r
a405b86d 503 } else {\r
b54fd049 504 Tz = (INT16)ShellStrToUintn(TempLocation);\r
a405b86d 505 }\r
2e8e9ed5 506 if (!(Tz >= -1440 && Tz <= 1440) && Tz != EFI_UNSPECIFIED_TIMEZONE) {\r
0841f3af 507 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-tz");\r
a405b86d 508 ShellStatus = SHELL_INVALID_PARAMETER;\r
509 }\r
510 } else {\r
511 //\r
512 // intentionally out of bounds value will prevent changing it...\r
513 //\r
514 Tz = 1441;\r
515 }\r
516 TempLocation = ShellCommandLineGetValue(Package, L"-d");\r
517 if (TempLocation != NULL) {\r
b54fd049 518 Daylight = (UINT8)ShellStrToUintn(TempLocation);\r
a405b86d 519 if (Daylight != 0 && Daylight != 1 && Daylight != 3) {\r
0841f3af 520 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-d");\r
a405b86d 521 ShellStatus = SHELL_INVALID_PARAMETER;\r
522 }\r
523 } else {\r
524 //\r
525 // invalid = will not use\r
526 //\r
527 Daylight = 0xFF;\r
528 }\r
529 if (ShellStatus == SHELL_SUCCESS) {\r
530 ShellStatus = CheckAndSetTime(ShellCommandLineGetRawValue(Package, 1), Tz, Daylight);\r
531 if (ShellStatus != SHELL_SUCCESS) {\r
532 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r
533 ShellStatus = SHELL_INVALID_PARAMETER;\r
534 }\r
535 }\r
536 }\r
537 }\r
538 }\r
539 }\r
540\r
541 //\r
542 // free the command line package\r
543 //\r
544 ShellCommandLineFreeVarList (Package);\r
545\r
546 //\r
547 // return the status\r
548 //\r
549 return (ShellStatus);\r
550}\r
551\r
552typedef struct {\r
553 INT16 TimeZone;\r
554 EFI_STRING_ID StringId;\r
555} TIME_ZONE_ITEM;\r
556\r
557STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2[] = {\r
558 {L"-l", TypeFlag},\r
559 {L"-f", TypeFlag},\r
560 {NULL, TypeMax}\r
561 };\r
562STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3[] = {\r
563 {L"-l", TypeFlag},\r
564 {L"-f", TypeFlag},\r
565 {L"-s", TypeValue},\r
566 {NULL, TypeMax}\r
567 };\r
568\r
569 STATIC CONST TIME_ZONE_ITEM TimeZoneList[] = {\r
570 {720, STRING_TOKEN (STR_TIMEZONE_M12)},\r
571 {660, STRING_TOKEN (STR_TIMEZONE_M11)},\r
572 {600, STRING_TOKEN (STR_TIMEZONE_M10)},\r
573 {540, STRING_TOKEN (STR_TIMEZONE_M9)},\r
574 {480, STRING_TOKEN (STR_TIMEZONE_M8)},\r
575 {420, STRING_TOKEN (STR_TIMEZONE_M7)},\r
576 {360, STRING_TOKEN (STR_TIMEZONE_M6)},\r
577 {300, STRING_TOKEN (STR_TIMEZONE_M5)},\r
578 {270, STRING_TOKEN (STR_TIMEZONE_M430)},\r
579 {240, STRING_TOKEN (STR_TIMEZONE_M4)},\r
580 {210, STRING_TOKEN (STR_TIMEZONE_M330)},\r
581 {180, STRING_TOKEN (STR_TIMEZONE_M3)},\r
582 {120, STRING_TOKEN (STR_TIMEZONE_M2)},\r
583 {60 , STRING_TOKEN (STR_TIMEZONE_M1)},\r
584 {0 , STRING_TOKEN (STR_TIMEZONE_0)},\r
585 {-60 , STRING_TOKEN (STR_TIMEZONE_P1)},\r
586 {-120 , STRING_TOKEN (STR_TIMEZONE_P2)},\r
587 {-180 , STRING_TOKEN (STR_TIMEZONE_P3)},\r
588 {-210 , STRING_TOKEN (STR_TIMEZONE_P330)},\r
589 {-240 , STRING_TOKEN (STR_TIMEZONE_P4)},\r
590 {-270 , STRING_TOKEN (STR_TIMEZONE_P430)},\r
591 {-300 , STRING_TOKEN (STR_TIMEZONE_P5)},\r
592 {-330 , STRING_TOKEN (STR_TIMEZONE_P530)},\r
593 {-345 , STRING_TOKEN (STR_TIMEZONE_P545)},\r
594 {-360 , STRING_TOKEN (STR_TIMEZONE_P6)},\r
595 {-390 , STRING_TOKEN (STR_TIMEZONE_P630)},\r
596 {-420 , STRING_TOKEN (STR_TIMEZONE_P7)},\r
597 {-480 , STRING_TOKEN (STR_TIMEZONE_P8)},\r
598 {-540 , STRING_TOKEN (STR_TIMEZONE_P9)},\r
599 {-570 , STRING_TOKEN (STR_TIMEZONE_P930)},\r
600 {-600 , STRING_TOKEN (STR_TIMEZONE_P10)},\r
601 {-660 , STRING_TOKEN (STR_TIMEZONE_P11)},\r
602 {-720 , STRING_TOKEN (STR_TIMEZONE_P12)},\r
603 {-780 , STRING_TOKEN (STR_TIMEZONE_P13)},\r
604 {-840 , STRING_TOKEN (STR_TIMEZONE_P14)}\r
b54fd049 605};\r
606\r
607/**\r
608 Verify that the TimeZoneString is valid and if so set that as the current \r
609 timezone.\r
a405b86d 610\r
b54fd049 611 @param[in] TimeZoneString The pointer to a string representation of the timezone.\r
612\r
613 @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.\r
614 @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.\r
615 @retval SHELL_SUCCESS The operation was successful.\r
616**/\r
a405b86d 617SHELL_STATUS\r
618EFIAPI\r
619CheckAndSetTimeZone (\r
620 IN CONST CHAR16 *TimeZoneString\r
621 )\r
622{\r
623 EFI_TIME TheTime;\r
624 EFI_STATUS Status;\r
b54fd049 625 CHAR16 *TimeZoneCopy;\r
626 CHAR16 *Walker;\r
627 CHAR16 *Walker2;\r
a405b86d 628 UINTN LoopVar;\r
629\r
630 if (TimeZoneString == NULL) {\r
631 return (SHELL_INVALID_PARAMETER);\r
632 }\r
633\r
634 if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) {\r
635 return (SHELL_INVALID_PARAMETER);\r
636 }\r
637\r
638 Status = gRT->GetTime(&TheTime, NULL);\r
639 ASSERT_EFI_ERROR(Status);\r
640\r
b54fd049 641 TimeZoneCopy = NULL;\r
642 TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0);\r
643 Walker = TimeZoneCopy;\r
644 Walker2 = StrStr(Walker, L":");\r
645 if (Walker2 != NULL && *Walker2 == L':') {\r
646 *Walker2 = CHAR_NULL;\r
647 }\r
a405b86d 648 if (*Walker == L'-') {\r
b54fd049 649 TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60);\r
a405b86d 650 } else {\r
b54fd049 651 TheTime.TimeZone = (INT16)((ShellStrToUintn (Walker)) * -60);\r
a405b86d 652 }\r
b54fd049 653 if (Walker2 != NULL) {\r
654 Walker = Walker2 + 1;\r
a405b86d 655 }\r
656 if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
657 if (TheTime.TimeZone < 0) {\r
b54fd049 658 TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)ShellStrToUintn (Walker));\r
a405b86d 659 } else {\r
b54fd049 660 TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)ShellStrToUintn (Walker));\r
a405b86d 661 }\r
662 }\r
663\r
664 Status = EFI_INVALID_PARAMETER;\r
665\r
666 for ( LoopVar = 0\r
667 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])\r
668 ; LoopVar++\r
669 ){\r
670 if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {\r
671 Status = gRT->SetTime(&TheTime);\r
672 break;\r
673 }\r
674 }\r
675\r
b54fd049 676 FreePool(TimeZoneCopy);\r
677\r
a405b86d 678 if (!EFI_ERROR(Status)){\r
679 return (SHELL_SUCCESS);\r
680 }\r
681 return (SHELL_INVALID_PARAMETER);\r
682}\r
683\r
684\r
685/**\r
686 Function for 'timezone' command.\r
687\r
688 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
689 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
690**/\r
691SHELL_STATUS\r
692EFIAPI\r
693ShellCommandRunTimeZone (\r
694 IN EFI_HANDLE ImageHandle,\r
695 IN EFI_SYSTEM_TABLE *SystemTable\r
696 )\r
697{\r
698 //\r
699 // non interactive\r
700 //\r
701 EFI_STATUS Status;\r
702 LIST_ENTRY *Package;\r
703 CHAR16 *ProblemParam;\r
704 SHELL_STATUS ShellStatus;\r
705 UINT8 LoopVar;\r
706 EFI_TIME TheTime;\r
707 BOOLEAN Found;\r
708 UINTN TzMinutes;\r
709\r
710 ShellStatus = SHELL_SUCCESS;\r
711 ProblemParam = NULL;\r
712\r
713 //\r
714 // initialize the shell lib (we must be in non-auto-init...)\r
715 //\r
716 Status = ShellInitialize();\r
717 ASSERT_EFI_ERROR(Status);\r
718\r
719 //\r
720 // parse the command line\r
721 //\r
722 if (PcdGet8(PcdShellSupportLevel) == 2) {\r
723 Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, FALSE);\r
724 } else {\r
725 ASSERT(PcdGet8(PcdShellSupportLevel) == 3);\r
726 Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, FALSE, TRUE);\r
727 }\r
728 if (EFI_ERROR(Status)) {\r
729 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
730 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r
731 FreePool(ProblemParam);\r
732 ShellStatus = SHELL_INVALID_PARAMETER;\r
733 } else {\r
734 ASSERT(FALSE);\r
735 }\r
736 } else {\r
737 //\r
738 // check for "-?"\r
739 //\r
740 if (ShellCommandLineGetCount(Package) > 1) {\r
741 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r
742 ShellStatus = SHELL_INVALID_PARAMETER;\r
743 } else if (ShellCommandLineGetFlag(Package, L"-?")) {\r
744 ASSERT(FALSE);\r
745 } else if (ShellCommandLineGetFlag(Package, L"-s")) {\r
746 if ((ShellCommandLineGetFlag(Package, L"-l")) || (ShellCommandLineGetFlag(Package, L"-f"))) {\r
747 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-l or -f");\r
748 ShellStatus = SHELL_INVALID_PARAMETER;\r
749 } else {\r
750 ASSERT(PcdGet8(PcdShellSupportLevel) == 3);\r
751 if (ShellCommandLineGetValue(Package, L"-s") == NULL) {\r
752 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-s");\r
753 ShellStatus = SHELL_INVALID_PARAMETER;\r
754 } else {\r
755 //\r
756 // Set the time zone\r
757 //\r
758 ShellStatus = CheckAndSetTimeZone(ShellCommandLineGetValue(Package, L"-s"));\r
759 if (ShellStatus != SHELL_SUCCESS) {\r
760 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-s"));\r
761 ShellStatus = SHELL_INVALID_PARAMETER;\r
762 }\r
763 }\r
764 }\r
765 } else if (ShellCommandLineGetFlag(Package, L"-l")) {\r
766 //\r
767 // Print a list of all time zones\r
768 //\r
769 for ( LoopVar = 0\r
770 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])\r
771 ; LoopVar++\r
772 ){\r
773 ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);\r
774 }\r
775 } else {\r
776 //\r
777 // Get Current Time Zone Info\r
778 //\r
779 Status = gRT->GetTime(&TheTime, NULL);\r
780 ASSERT_EFI_ERROR(Status);\r
781\r
2e8e9ed5 782 if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
a405b86d 783 Found = FALSE;\r
784 for ( LoopVar = 0\r
785 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])\r
786 ; LoopVar++\r
787 ){\r
788 if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {\r
789 if (ShellCommandLineGetFlag(Package, L"-f")) {\r
790 //\r
791 // Print all info about current time zone\r
792 //\r
793 ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);\r
794 } else {\r
795 //\r
796 // Print basic info only\r
797 //\r
2e8e9ed5 798 if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
a405b86d 799 TzMinutes = 0;\r
800 } else {\r
b54fd049 801 TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
a405b86d 802 }\r
803\r
804 ShellPrintHiiEx (\r
805 -1,\r
806 -1,\r
807 NULL,\r
808 STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
809 gShellLevel2HiiHandle,\r
2e8e9ed5 810 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
811 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
a405b86d 812 TzMinutes);\r
813 }\r
814 Found = TRUE;\r
815 break;\r
816 }\r
817 }\r
818 if (!Found) {\r
819 //\r
820 // Print basic info only\r
821 //\r
2e8e9ed5 822 if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
a405b86d 823 TzMinutes = 0;\r
824 } else {\r
b54fd049 825 TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
a405b86d 826 }\r
827 ShellPrintHiiEx (\r
828 -1,\r
829 -1,\r
830 NULL,\r
831 STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
832 gShellLevel2HiiHandle,\r
2e8e9ed5 833 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
834 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
a405b86d 835 TzMinutes);\r
836 if (ShellCommandLineGetFlag(Package, L"-f")) {\r
837 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);\r
838 }\r
839 }\r
840 } else {\r
841 //\r
2e8e9ed5 842 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime()\r
a405b86d 843 //\r
844 }\r
845 }\r
846 }\r
847\r
848 //\r
849 // free the command line package\r
850 //\r
851 ShellCommandLineFreeVarList (Package);\r
852\r
853 return (ShellStatus);\r
854}\r