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