Skip to content

Commit

Permalink
Refactor ProviderValueAsAscii() (#48)
Browse files Browse the repository at this point in the history
## Description

Refactor ProviderValueAsAscii() and remove following macros to make it can allocate buffer with right size for each setting.
Fix #43

```
#define ENABLED_STRING_SIZE                (9)
#define ASSET_TAG_STRING_MAX_SIZE          (22)
#define SECURE_BOOT_ENUM_STRING_SIZE       (20)
#define SYSTEM_PASSWORD_STATE_STRING_SIZE  (30)
#define USB_PORT_STATE_STRING_SIZE         (20)
```

- [x] Impacts functionality?
  - **Functionality** - Does the change ultimately impact how firmware functions?
  - Examples: Add a new library, publish a new PPI, update an algorithm, ...
- [ ] Impacts security?
  - **Security** - Does the change have a direct security impact on an application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
  - **Breaking change** - Will anyone consuming this change experience a break
    in build or boot behavior?
  - Examples: Add a new library class, move a module to a different repo, call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
  - **Documentation** - Does the change contain explicit documentation additions
    outside direct code modifications (and comments)?
  - Examples: Update readme file, add feature readme file, link to documentation
    on an a separate Web page, ...

## How This Was Tested

Tested with SEMM tool. No regression seen.

## Integration Instructions

N/A
  • Loading branch information
wenbhou authored Mar 10, 2023
1 parent 9694a42 commit b0f6333
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 87 deletions.
61 changes: 61 additions & 0 deletions DfciPkg/Include/DfciSystemSettingStrings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/** @file
DfciSystemSettingStrings.h
These are the setting strings.
Copyright (C) Microsoft Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef __DFCI_SETTING_STRINGS_H__
#define __DFCI_SETTING_STRINGS_H__

//
// DFCI Setting Type
//
#define DFCI_STR_SETTING_TYPE_ENABLE "ENABLE/DISABLE TYPE"
#define DFCI_STR_SETTING_TYPE_SECUREBOOTKEYENUM "SECURE BOOT KEY ENUM TYPE"
#define DFCI_STR_SETTING_TYPE_PASSWORD "PASSWORD TYPE"
#define DFCI_STR_SETTING_TYPE_USBPORTENUM "USB PORT STATE TYPE"
#define DFCI_STR_SETTING_TYPE_STRING "STRING TYPE"
#define DFCI_STR_SETTING_TYPE_BINARY "BINARY TYPE"
#define DFCI_STR_SETTING_TYPE_CERT "CERT TYPE"

//
// Enable/Disable
//
#define DFCI_STR_ENABLED "Enabled"
#define DFCI_STR_DISABLED "Disabled"

//
// Secure Boot Key
//
#define DFCI_STR_SECURE_BOOT_KEY_MS_ONLY "MsOnly"
#define DFCI_STR_SECURE_BOOT_KEY_MS_3RD_PARTY "MsPlus3rdParty"
#define DFCI_STR_SECURE_BOOT_KEY_NONE "None"
#define DFCI_STR_SECURE_BOOT_KEY_CUSTOM "Custom"

//
// System Password
//
#define DFCI_STR_SYSTEM_PASSWORD_SET "System Password Set"
#define DFCI_STR_SYSTEM_PASSWORD_NOT_SET "No System Password"

//
// USB Port State
//
#define DFCI_STR_USB_PORT_ENABLED "UsbPortEnabled"
#define DFCI_STR_USB_PORT_HW_DISABLED "UsbPortHwDisabled"
#define DFCI_STR_USB_PORT_DATA_DISABLED "UsbPortDataDisabled"
#define DFCI_STR_USB_PORT_AUTHENTICATED "UsbPortAuthenticated"

//
// Misc
//
#define DFCI_STR_INCONSISTENT "Inconsistent"
#define DFCI_STR_UNKNOWN "Unknown"
#define DFCI_STR_UNSUPPORTED_VALUE "UnsupportedValue"
#define DFCI_STR_CERT_NOT_AVAILABLE "No Cert information available"

#endif // __DFCI_SETTING_STRINGS_H__
1 change: 1 addition & 0 deletions DfciPkg/SettingsManager/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#include <XmlTypes.h>
#include <DfciSystemSettingTypes.h>
#include <DfciSystemSettingStrings.h>

#include <Guid/DfciInternalVariableGuid.h>
#include <Guid/DfciDeviceIdVariables.h>
Expand Down
22 changes: 11 additions & 11 deletions DfciPkg/SettingsManager/SettingsManagerCurrentSettingXml.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ CreateXmlStringFromCurrentSettings (
case DFCI_SETTING_TYPE_ENABLE:
switch (Value) {
case ENABLE_FALSE:
ReturnValue = "Disabled";
ReturnValue = DFCI_STR_DISABLED;
break;

case ENABLE_TRUE:
ReturnValue = "Enabled";
ReturnValue = DFCI_STR_ENABLED;
break;

case ENABLE_INCONSISTENT:
ReturnValue = "Inconsistent";
ReturnValue = DFCI_STR_INCONSISTENT;
break;

default:
ReturnValue = "Unknown";
ReturnValue = DFCI_STR_UNKNOWN;
break;
}

Expand All @@ -196,35 +196,35 @@ CreateXmlStringFromCurrentSettings (
case DFCI_SETTING_TYPE_USBPORTENUM:
switch (Value) {
case DfciUsbPortHwDisabled:
ReturnValue = "UsbPortHwDisabled";
ReturnValue = DFCI_STR_USB_PORT_HW_DISABLED;
break;

case DfciUsbPortEnabled:
ReturnValue = "UsbPortEnabled";
ReturnValue = DFCI_STR_USB_PORT_ENABLED;
break;

case DfciUsbPortDataDisabled:
ReturnValue = "UsbPortDataDisabled";
ReturnValue = DFCI_STR_USB_PORT_DATA_DISABLED;
break;

case DfciUsbPortAuthenticated:
ReturnValue = "UsbPortAuthenticated";
ReturnValue = DFCI_STR_USB_PORT_AUTHENTICATED;
break;

case ENABLE_INCONSISTENT:
ReturnValue = "Inconsistent";
ReturnValue = DFCI_STR_INCONSISTENT;
break;

default:
ReturnValue = "UnsupportedValue";
ReturnValue = DFCI_STR_UNSUPPORTED_VALUE;
break;
}

break;

default:
DEBUG ((DEBUG_ERROR, "%a: Group entries for type(%d) not supported\n", __FUNCTION__, GroupType));
ReturnValue = "UnsupportedValue";
ReturnValue = DFCI_STR_UNSUPPORTED_VALUE;
break;
}
}
Expand Down
Loading

0 comments on commit b0f6333

Please sign in to comment.