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