Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: utascii - Utility ascii functions
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 
0013 /*******************************************************************************
0014  *
0015  * FUNCTION:    acpi_ut_valid_nameseg
0016  *
0017  * PARAMETERS:  name            - The name or table signature to be examined.
0018  *                                Four characters, does not have to be a
0019  *                                NULL terminated string.
0020  *
0021  * RETURN:      TRUE if signature is has 4 valid ACPI characters
0022  *
0023  * DESCRIPTION: Validate an ACPI table signature.
0024  *
0025  ******************************************************************************/
0026 
0027 u8 acpi_ut_valid_nameseg(char *name)
0028 {
0029     u32 i;
0030 
0031     /* Validate each character in the signature */
0032 
0033     for (i = 0; i < ACPI_NAMESEG_SIZE; i++) {
0034         if (!acpi_ut_valid_name_char(name[i], i)) {
0035             return (FALSE);
0036         }
0037     }
0038 
0039     return (TRUE);
0040 }
0041 
0042 /*******************************************************************************
0043  *
0044  * FUNCTION:    acpi_ut_valid_name_char
0045  *
0046  * PARAMETERS:  char            - The character to be examined
0047  *              position        - Byte position (0-3)
0048  *
0049  * RETURN:      TRUE if the character is valid, FALSE otherwise
0050  *
0051  * DESCRIPTION: Check for a valid ACPI character. Must be one of:
0052  *              1) Upper case alpha
0053  *              2) numeric
0054  *              3) underscore
0055  *
0056  *              We allow a '!' as the last character because of the ASF! table
0057  *
0058  ******************************************************************************/
0059 
0060 u8 acpi_ut_valid_name_char(char character, u32 position)
0061 {
0062 
0063     if (!((character >= 'A' && character <= 'Z') ||
0064           (character >= '0' && character <= '9') || (character == '_'))) {
0065 
0066         /* Allow a '!' in the last position */
0067 
0068         if (character == '!' && position == 3) {
0069             return (TRUE);
0070         }
0071 
0072         return (FALSE);
0073     }
0074 
0075     return (TRUE);
0076 }
0077 
0078 /*******************************************************************************
0079  *
0080  * FUNCTION:    acpi_ut_check_and_repair_ascii
0081  *
0082  * PARAMETERS:  name                - Ascii string
0083  *              count               - Number of characters to check
0084  *
0085  * RETURN:      None
0086  *
0087  * DESCRIPTION: Ensure that the requested number of characters are printable
0088  *              Ascii characters. Sets non-printable and null chars to <space>.
0089  *
0090  ******************************************************************************/
0091 
0092 void acpi_ut_check_and_repair_ascii(u8 *name, char *repaired_name, u32 count)
0093 {
0094     u32 i;
0095 
0096     for (i = 0; i < count; i++) {
0097         repaired_name[i] = (char)name[i];
0098 
0099         if (!name[i]) {
0100             return;
0101         }
0102         if (!isprint(name[i])) {
0103             repaired_name[i] = ' ';
0104         }
0105     }
0106 }