1 /*++ 2 Copyright (c) 2004, Intel Corporation. All rights reserved.<BR> 3 This program and the accompanying materials 4 are licensed and made available under the terms and conditions of the BSD License 5 which accompanies this distribution. The full text of the license may be found at 6 http://opensource.org/licenses/bsd-license.php 7 8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 11 Module Name: 12 IfrOpCodeCreation.c 13 14 Abstract: 15 16 Library Routines to create IFR independent of string data - assume tokens already exist 17 Primarily to be used for exporting op-codes at a label in pre-defined forms. 18 19 Revision History: 20 21 --*/ 22 23 #include "IfrLibrary.h" 24 25 EFI_STATUS 26 CreateSubTitleOpCode ( 27 IN STRING_REF StringToken, 28 IN OUT VOID *FormBuffer 29 ) 30 /*++ 31 32 Routine Description: 33 34 Create a SubTitle opcode independent of string creation 35 This is used primarily by users who need to create just one particular valid op-code and the string 36 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 37 location to pre-defined forms in HII) 38 39 Arguments: 40 41 StringToken - StringToken of the subtitle 42 43 FormBuffer - Output of subtitle as a form 44 45 Returns: 46 47 EFI_SUCCESS - Subtitle created to be a form 48 49 --*/ 50 { 51 EFI_IFR_SUBTITLE Subtitle; 52 53 Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP; 54 Subtitle.Header.Length = (UINT8) sizeof (EFI_IFR_SUBTITLE); 55 Subtitle.SubTitle = StringToken; 56 57 EfiCopyMem (FormBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE)); 58 return EFI_SUCCESS; 59 } 60 61 62 EFI_STATUS 63 CreateTextOpCode ( 64 IN STRING_REF StringToken, 65 IN STRING_REF StringTokenTwo, 66 IN STRING_REF StringTokenThree, 67 IN UINT8 Flags, 68 IN UINT16 Key, 69 IN OUT VOID *FormBuffer 70 ) 71 /*++ 72 73 Routine Description: 74 75 Create a Text opcode independent of string creation 76 This is used primarily by users who need to create just one particular valid op-code and the string 77 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 78 location to pre-defined forms in HII) 79 80 Arguments: 81 82 StringToken - First string token of the text 83 84 StringTokenTwo - Second string token of the text 85 86 StringTokenThree - Help string token of the text 87 88 Flags - Flag of the text 89 90 Key - Key of the text 91 92 FormBuffer - Output of text as a form 93 94 Returns: 95 96 EFI_SUCCESS - Text created to be a form 97 98 --*/ 99 { 100 EFI_IFR_TEXT Text; 101 102 Text.Header.OpCode = EFI_IFR_TEXT_OP; 103 Text.Header.Length = (UINT8) sizeof (EFI_IFR_TEXT); 104 Text.Text = StringToken; 105 106 Text.TextTwo = StringTokenTwo; 107 Text.Help = StringTokenThree; 108 Text.Flags = Flags; 109 Text.Key = Key; 110 111 EfiCopyMem (FormBuffer, &Text, sizeof (EFI_IFR_TEXT)); 112 113 return EFI_SUCCESS; 114 } 115 116 117 EFI_STATUS 118 CreateGotoOpCode ( 119 IN UINT16 FormId, 120 IN STRING_REF StringToken, 121 IN STRING_REF StringTokenTwo, 122 IN UINT8 Flags, 123 IN UINT16 Key, 124 IN OUT VOID *FormBuffer 125 ) 126 /*++ 127 128 Routine Description: 129 130 Create a hyperlink opcode independent of string creation 131 This is used primarily by users who need to create just one particular valid op-code and the string 132 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 133 location to pre-defined forms in HII) 134 135 Arguments: 136 137 FormId - Form ID of the hyperlink 138 139 StringToken - Prompt string token of the hyperlink 140 141 StringTokenTwo - Help string token of the hyperlink 142 143 Flags - Flags of the hyperlink 144 145 Key - Key of the hyperlink 146 147 FormBuffer - Output of hyperlink as a form 148 149 Returns: 150 151 EFI_SUCCESS - Hyperlink created to be a form 152 153 --*/ 154 { 155 EFI_IFR_REF Hyperlink; 156 157 Hyperlink.Header.OpCode = EFI_IFR_REF_OP; 158 Hyperlink.Header.Length = (UINT8) sizeof (EFI_IFR_REF); 159 Hyperlink.FormId = FormId; 160 Hyperlink.Prompt = StringToken; 161 Hyperlink.Help = StringTokenTwo; 162 Hyperlink.Key = Key; 163 Hyperlink.Flags = Flags; 164 165 EfiCopyMem (FormBuffer, &Hyperlink, sizeof (EFI_IFR_REF)); 166 167 return EFI_SUCCESS; 168 } 169 170 171 EFI_STATUS 172 CreateOneOfOpCode ( 173 IN UINT16 QuestionId, 174 IN UINT8 DataWidth, 175 IN STRING_REF PromptToken, 176 IN STRING_REF HelpToken, 177 IN IFR_OPTION *OptionsList, 178 IN UINTN OptionCount, 179 IN OUT VOID *FormBuffer 180 ) 181 /*++ 182 183 Routine Description: 184 185 Create a one-of opcode with a set of option op-codes to choose from independent of string creation. 186 This is used primarily by users who need to create just one particular valid op-code and the string 187 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 188 location to pre-defined forms in HII) 189 190 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken 191 has been filled in since this routine will not generate StringToken values. 192 193 Arguments: 194 195 QuestionId - Question ID of the one-of box 196 197 DataWidth - DataWidth of the one-of box 198 199 PromptToken - Prompt string token of the one-of box 200 201 HelpToken - Help string token of the one-of box 202 203 OptionsList - Each string in it is an option of the one-of box 204 205 OptionCount - Option string count 206 207 FormBuffer - Output of One-Of box as a form 208 209 Returns: 210 211 EFI_SUCCESS - One-Of box created to be a form 212 213 EFI_DEVICE_ERROR - DataWidth > 2 214 215 --*/ 216 { 217 UINTN Index; 218 EFI_IFR_ONE_OF OneOf; 219 EFI_IFR_ONE_OF_OPTION OneOfOption; 220 EFI_IFR_END_ONE_OF EndOneOf; 221 UINT8 *LocalBuffer; 222 223 // 224 // We do not create op-code storage widths for one-of in excess of 16 bits for now 225 // 226 if (DataWidth > 2) { 227 return EFI_DEVICE_ERROR; 228 } 229 230 OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP; 231 OneOf.Header.Length = (UINT8) sizeof (EFI_IFR_ONE_OF); 232 OneOf.QuestionId = QuestionId; 233 OneOf.Width = DataWidth; 234 OneOf.Prompt = PromptToken; 235 236 OneOf.Help = HelpToken; 237 238 LocalBuffer = (UINT8 *) FormBuffer; 239 240 EfiCopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF)); 241 242 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF)); 243 244 for (Index = 0; Index < OptionCount; Index++) { 245 OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP; 246 OneOfOption.Header.Length = (UINT8) sizeof (EFI_IFR_ONE_OF_OPTION); 247 248 OneOfOption.Option = OptionsList[Index].StringToken; 249 OneOfOption.Value = OptionsList[Index].Value; 250 OneOfOption.Flags = OptionsList[Index].Flags; 251 OneOfOption.Key = OptionsList[Index].Key; 252 253 EfiCopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION)); 254 255 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION)); 256 } 257 258 EndOneOf.Header.Length = (UINT8) sizeof (EFI_IFR_END_ONE_OF); 259 EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP; 260 261 EfiCopyMem (LocalBuffer, &EndOneOf, sizeof (EFI_IFR_END_ONE_OF)); 262 263 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF)); 264 265 return EFI_SUCCESS; 266 } 267 268 EFI_STATUS 269 CreateOrderedListOpCode ( 270 IN UINT16 QuestionId, 271 IN UINT8 MaxEntries, 272 IN STRING_REF PromptToken, 273 IN STRING_REF HelpToken, 274 IN IFR_OPTION *OptionsList, 275 IN UINTN OptionCount, 276 IN OUT VOID *FormBuffer 277 ) 278 /*++ 279 280 Routine Description: 281 282 Create a ordered list opcode with a set of option op-codes to choose from independent of string creation. 283 This is used primarily by users who need to create just one particular valid op-code and the string 284 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 285 location to pre-defined forms in HII) 286 287 OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken 288 has been filled in since this routine will not generate StringToken values. 289 290 Arguments: 291 292 QuestionId - Question ID of the ordered list 293 294 MaxEntries - MaxEntries of the ordered list 295 296 PromptToken - Prompt string token of the ordered list 297 298 HelpToken - Help string token of the ordered list 299 300 OptionsList - Each string in it is an option of the ordered list 301 302 OptionCount - Option string count 303 304 FormBuffer - Output of ordered list as a form 305 306 Returns: 307 308 EFI_SUCCESS - Ordered list created to be a form 309 310 --*/ 311 { 312 UINTN Index; 313 EFI_IFR_ORDERED_LIST OrderedList; 314 EFI_IFR_ONE_OF_OPTION OrderedListOption; 315 EFI_IFR_END_ONE_OF EndOrderedList; 316 UINT8 *LocalBuffer; 317 318 OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP; 319 OrderedList.Header.Length = (UINT8) sizeof (EFI_IFR_ORDERED_LIST); 320 OrderedList.QuestionId = QuestionId; 321 OrderedList.MaxEntries = MaxEntries; 322 OrderedList.Prompt = PromptToken; 323 324 OrderedList.Help = HelpToken; 325 326 LocalBuffer = (UINT8 *) FormBuffer; 327 328 EfiCopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST)); 329 330 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ORDERED_LIST)); 331 332 for (Index = 0; Index < OptionCount; Index++) { 333 OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP; 334 OrderedListOption.Header.Length = (UINT8) sizeof (EFI_IFR_ONE_OF_OPTION); 335 336 OrderedListOption.Option = OptionsList[Index].StringToken; 337 OrderedListOption.Value = OptionsList[Index].Value; 338 OrderedListOption.Flags = OptionsList[Index].Flags; 339 OrderedListOption.Key = OptionsList[Index].Key; 340 341 EfiCopyMem (LocalBuffer, &OrderedListOption, sizeof (EFI_IFR_ONE_OF_OPTION)); 342 343 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION)); 344 } 345 346 EndOrderedList.Header.Length = (UINT8) sizeof (EFI_IFR_END_ONE_OF); 347 EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP; 348 349 EfiCopyMem (LocalBuffer, &EndOrderedList, sizeof (EFI_IFR_END_ONE_OF)); 350 351 LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF)); 352 353 return EFI_SUCCESS; 354 } 355 356 EFI_STATUS 357 CreateCheckBoxOpCode ( 358 IN UINT16 QuestionId, 359 IN UINT8 DataWidth, 360 IN STRING_REF PromptToken, 361 IN STRING_REF HelpToken, 362 IN UINT8 Flags, 363 IN UINT16 Key, 364 IN OUT VOID *FormBuffer 365 ) 366 /*++ 367 368 Routine Description: 369 370 Create a checkbox opcode independent of string creation 371 This is used primarily by users who need to create just one particular valid op-code and the string 372 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 373 location to pre-defined forms in HII) 374 375 Arguments: 376 377 QuestionId - Question ID of the check box 378 379 DataWidth - DataWidth of the check box 380 381 PromptToken - Prompt string token of the check box 382 383 HelpToken - Help string token of the check box 384 385 Flags - Flags of the check box 386 387 Key - Key of the check box 388 389 FormBuffer - Output of the check box as a form 390 391 Returns: 392 393 EFI_SUCCESS - Checkbox created to be a form 394 395 EFI_DEVICE_ERROR - DataWidth > 1 396 397 --*/ 398 { 399 EFI_IFR_CHECK_BOX CheckBox; 400 401 // 402 // We do not create op-code storage widths for checkbox in excess of 8 bits for now 403 // 404 if (DataWidth > 1) { 405 return EFI_DEVICE_ERROR; 406 } 407 408 CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP; 409 CheckBox.Header.Length = (UINT8) sizeof (EFI_IFR_CHECK_BOX); 410 CheckBox.QuestionId = QuestionId; 411 CheckBox.Width = DataWidth; 412 CheckBox.Prompt = PromptToken; 413 414 CheckBox.Help = HelpToken; 415 CheckBox.Flags = Flags; 416 CheckBox.Key = Key; 417 418 EfiCopyMem (FormBuffer, &CheckBox, sizeof (EFI_IFR_CHECK_BOX)); 419 420 return EFI_SUCCESS; 421 } 422 423 424 EFI_STATUS 425 CreateNumericOpCode ( 426 IN UINT16 QuestionId, 427 IN UINT8 DataWidth, 428 IN STRING_REF PromptToken, 429 IN STRING_REF HelpToken, 430 IN UINT16 Minimum, 431 IN UINT16 Maximum, 432 IN UINT16 Step, 433 IN UINT16 Default, 434 IN UINT8 Flags, 435 IN UINT16 Key, 436 IN OUT VOID *FormBuffer 437 ) 438 /*++ 439 440 Routine Description: 441 442 Create a numeric opcode independent of string creation 443 This is used primarily by users who need to create just one particular valid op-code and the string 444 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 445 location to pre-defined forms in HII) 446 447 Arguments: 448 449 QuestionId - Question ID of the numeric 450 451 DataWidth - DataWidth of the numeric 452 453 PromptToken - Prompt string token of the numeric 454 455 HelpToken - Help string token of the numeric 456 457 Minimum - Minumun boundary of the numeric 458 459 Maximum - Maximum boundary of the numeric 460 461 Step - Step of the numeric 462 463 Default - Default value of the numeric 464 465 Flags - Flags of the numeric 466 467 Key - Key of the numeric 468 469 FormBuffer - Output of the numeric as a form 470 471 Returns: 472 473 EFI_SUCCESS - The numeric created to be a form. 474 475 EFI_DEVICE_ERROR - DataWidth > 2 476 477 --*/ 478 { 479 EFI_IFR_NUMERIC Numeric; 480 481 // 482 // We do not create op-code storage widths for numerics in excess of 16 bits for now 483 // 484 if (DataWidth > 2) { 485 return EFI_DEVICE_ERROR; 486 } 487 488 Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP; 489 Numeric.Header.Length = (UINT8) sizeof (EFI_IFR_NUMERIC); 490 Numeric.QuestionId = QuestionId; 491 Numeric.Width = DataWidth; 492 Numeric.Prompt = PromptToken; 493 494 Numeric.Help = HelpToken; 495 Numeric.Minimum = Minimum; 496 Numeric.Maximum = Maximum; 497 Numeric.Step = Step; 498 Numeric.Default = Default; 499 Numeric.Flags = Flags; 500 Numeric.Key = Key; 501 502 EfiCopyMem (FormBuffer, &Numeric, sizeof (EFI_IFR_NUMERIC)); 503 504 return EFI_SUCCESS; 505 } 506 507 508 EFI_STATUS 509 CreateStringOpCode ( 510 IN UINT16 QuestionId, 511 IN UINT8 DataWidth, 512 IN STRING_REF PromptToken, 513 IN STRING_REF HelpToken, 514 IN UINT8 MinSize, 515 IN UINT8 MaxSize, 516 IN UINT8 Flags, 517 IN UINT16 Key, 518 IN OUT VOID *FormBuffer 519 ) 520 /*++ 521 522 Routine Description: 523 524 Create a numeric opcode independent of string creation 525 This is used primarily by users who need to create just one particular valid op-code and the string 526 data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label 527 location to pre-defined forms in HII) 528 529 Arguments: 530 531 QuestionId - Question ID of the string 532 533 DataWidth - DataWidth of the string 534 535 PromptToken - Prompt token of the string 536 537 HelpToken - Help token of the string 538 539 MinSize - Min size boundary of the string 540 541 MaxSize - Max size boundary of the string 542 543 Flags - Flags of the string 544 545 Key - Key of the string 546 547 FormBuffer - Output of the string as a form 548 549 Returns: 550 551 EFI_SUCCESS - String created to be a form. 552 553 --*/ 554 { 555 EFI_IFR_STRING String; 556 557 String.Header.OpCode = EFI_IFR_STRING_OP; 558 String.Header.Length = (UINT8) sizeof (EFI_IFR_STRING); 559 String.QuestionId = QuestionId; 560 String.Width = DataWidth; 561 String.Prompt = PromptToken; 562 563 String.Help = HelpToken; 564 String.MinSize = MinSize; 565 String.MaxSize = MaxSize; 566 String.Flags = Flags; 567 String.Key = Key; 568 569 EfiCopyMem (FormBuffer, &String, sizeof (EFI_IFR_STRING)); 570 571 return EFI_SUCCESS; 572 } 573 574 575 EFI_STATUS 576 CreateBannerOpCode ( 577 IN UINT16 Title, 578 IN UINT16 LineNumber, 579 IN UINT8 Alignment, 580 IN OUT VOID *FormBuffer 581 ) 582 /*++ 583 584 Routine Description: 585 586 Create a banner opcode. This is primarily used by the FrontPage implementation from BDS. 587 588 Arguments: 589 590 Title - Title of the banner 591 592 LineNumber - LineNumber of the banner 593 594 Alignment - Alignment of the banner 595 596 FormBuffer - Output of banner as a form 597 598 Returns: 599 600 EFI_SUCCESS - Banner created to be a form. 601 602 --*/ 603 { 604 EFI_IFR_BANNER Banner; 605 606 Banner.Header.OpCode = EFI_IFR_BANNER_OP; 607 Banner.Header.Length = (UINT8) sizeof (EFI_IFR_BANNER); 608 EfiCopyMem (&Banner.Title, &Title, sizeof (UINT16)); 609 EfiCopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16)); 610 Banner.Alignment = Alignment; 611 612 EfiCopyMem (FormBuffer, &Banner, sizeof (EFI_IFR_BANNER)); 613 614 return EFI_SUCCESS; 615 } 616