1*385cc6b4SJerry Jelinek /******************************************************************************
2*385cc6b4SJerry Jelinek *
3*385cc6b4SJerry Jelinek * Module Name: utascii - Utility ascii functions
4*385cc6b4SJerry Jelinek *
5*385cc6b4SJerry Jelinek *****************************************************************************/
6*385cc6b4SJerry Jelinek
7*385cc6b4SJerry Jelinek /*
8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9*385cc6b4SJerry Jelinek * All rights reserved.
10*385cc6b4SJerry Jelinek *
11*385cc6b4SJerry Jelinek * Redistribution and use in source and binary forms, with or without
12*385cc6b4SJerry Jelinek * modification, are permitted provided that the following conditions
13*385cc6b4SJerry Jelinek * are met:
14*385cc6b4SJerry Jelinek * 1. Redistributions of source code must retain the above copyright
15*385cc6b4SJerry Jelinek * notice, this list of conditions, and the following disclaimer,
16*385cc6b4SJerry Jelinek * without modification.
17*385cc6b4SJerry Jelinek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*385cc6b4SJerry Jelinek * substantially similar to the "NO WARRANTY" disclaimer below
19*385cc6b4SJerry Jelinek * ("Disclaimer") and any redistribution must be conditioned upon
20*385cc6b4SJerry Jelinek * including a substantially similar Disclaimer requirement for further
21*385cc6b4SJerry Jelinek * binary redistribution.
22*385cc6b4SJerry Jelinek * 3. Neither the names of the above-listed copyright holders nor the names
23*385cc6b4SJerry Jelinek * of any contributors may be used to endorse or promote products derived
24*385cc6b4SJerry Jelinek * from this software without specific prior written permission.
25*385cc6b4SJerry Jelinek *
26*385cc6b4SJerry Jelinek * Alternatively, this software may be distributed under the terms of the
27*385cc6b4SJerry Jelinek * GNU General Public License ("GPL") version 2 as published by the Free
28*385cc6b4SJerry Jelinek * Software Foundation.
29*385cc6b4SJerry Jelinek *
30*385cc6b4SJerry Jelinek * NO WARRANTY
31*385cc6b4SJerry Jelinek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*385cc6b4SJerry Jelinek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*385cc6b4SJerry Jelinek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*385cc6b4SJerry Jelinek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*385cc6b4SJerry Jelinek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*385cc6b4SJerry Jelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*385cc6b4SJerry Jelinek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*385cc6b4SJerry Jelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*385cc6b4SJerry Jelinek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*385cc6b4SJerry Jelinek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*385cc6b4SJerry Jelinek * POSSIBILITY OF SUCH DAMAGES.
42*385cc6b4SJerry Jelinek */
43*385cc6b4SJerry Jelinek
44*385cc6b4SJerry Jelinek #include "acpi.h"
45*385cc6b4SJerry Jelinek #include "accommon.h"
46*385cc6b4SJerry Jelinek
47*385cc6b4SJerry Jelinek
48*385cc6b4SJerry Jelinek /*******************************************************************************
49*385cc6b4SJerry Jelinek *
50*385cc6b4SJerry Jelinek * FUNCTION: AcpiUtValidNameseg
51*385cc6b4SJerry Jelinek *
52*385cc6b4SJerry Jelinek * PARAMETERS: Name - The name or table signature to be examined.
53*385cc6b4SJerry Jelinek * Four characters, does not have to be a
54*385cc6b4SJerry Jelinek * NULL terminated string.
55*385cc6b4SJerry Jelinek *
56*385cc6b4SJerry Jelinek * RETURN: TRUE if signature is has 4 valid ACPI characters
57*385cc6b4SJerry Jelinek *
58*385cc6b4SJerry Jelinek * DESCRIPTION: Validate an ACPI table signature.
59*385cc6b4SJerry Jelinek *
60*385cc6b4SJerry Jelinek ******************************************************************************/
61*385cc6b4SJerry Jelinek
62*385cc6b4SJerry Jelinek BOOLEAN
AcpiUtValidNameseg(char * Name)63*385cc6b4SJerry Jelinek AcpiUtValidNameseg (
64*385cc6b4SJerry Jelinek char *Name)
65*385cc6b4SJerry Jelinek {
66*385cc6b4SJerry Jelinek UINT32 i;
67*385cc6b4SJerry Jelinek
68*385cc6b4SJerry Jelinek
69*385cc6b4SJerry Jelinek /* Validate each character in the signature */
70*385cc6b4SJerry Jelinek
71*385cc6b4SJerry Jelinek for (i = 0; i < ACPI_NAME_SIZE; i++)
72*385cc6b4SJerry Jelinek {
73*385cc6b4SJerry Jelinek if (!AcpiUtValidNameChar (Name[i], i))
74*385cc6b4SJerry Jelinek {
75*385cc6b4SJerry Jelinek return (FALSE);
76*385cc6b4SJerry Jelinek }
77*385cc6b4SJerry Jelinek }
78*385cc6b4SJerry Jelinek
79*385cc6b4SJerry Jelinek return (TRUE);
80*385cc6b4SJerry Jelinek }
81*385cc6b4SJerry Jelinek
82*385cc6b4SJerry Jelinek
83*385cc6b4SJerry Jelinek /*******************************************************************************
84*385cc6b4SJerry Jelinek *
85*385cc6b4SJerry Jelinek * FUNCTION: AcpiUtValidNameChar
86*385cc6b4SJerry Jelinek *
87*385cc6b4SJerry Jelinek * PARAMETERS: Char - The character to be examined
88*385cc6b4SJerry Jelinek * Position - Byte position (0-3)
89*385cc6b4SJerry Jelinek *
90*385cc6b4SJerry Jelinek * RETURN: TRUE if the character is valid, FALSE otherwise
91*385cc6b4SJerry Jelinek *
92*385cc6b4SJerry Jelinek * DESCRIPTION: Check for a valid ACPI character. Must be one of:
93*385cc6b4SJerry Jelinek * 1) Upper case alpha
94*385cc6b4SJerry Jelinek * 2) numeric
95*385cc6b4SJerry Jelinek * 3) underscore
96*385cc6b4SJerry Jelinek *
97*385cc6b4SJerry Jelinek * We allow a '!' as the last character because of the ASF! table
98*385cc6b4SJerry Jelinek *
99*385cc6b4SJerry Jelinek ******************************************************************************/
100*385cc6b4SJerry Jelinek
101*385cc6b4SJerry Jelinek BOOLEAN
AcpiUtValidNameChar(char Character,UINT32 Position)102*385cc6b4SJerry Jelinek AcpiUtValidNameChar (
103*385cc6b4SJerry Jelinek char Character,
104*385cc6b4SJerry Jelinek UINT32 Position)
105*385cc6b4SJerry Jelinek {
106*385cc6b4SJerry Jelinek
107*385cc6b4SJerry Jelinek if (!((Character >= 'A' && Character <= 'Z') ||
108*385cc6b4SJerry Jelinek (Character >= '0' && Character <= '9') ||
109*385cc6b4SJerry Jelinek (Character == '_')))
110*385cc6b4SJerry Jelinek {
111*385cc6b4SJerry Jelinek /* Allow a '!' in the last position */
112*385cc6b4SJerry Jelinek
113*385cc6b4SJerry Jelinek if (Character == '!' && Position == 3)
114*385cc6b4SJerry Jelinek {
115*385cc6b4SJerry Jelinek return (TRUE);
116*385cc6b4SJerry Jelinek }
117*385cc6b4SJerry Jelinek
118*385cc6b4SJerry Jelinek return (FALSE);
119*385cc6b4SJerry Jelinek }
120*385cc6b4SJerry Jelinek
121*385cc6b4SJerry Jelinek return (TRUE);
122*385cc6b4SJerry Jelinek }
123*385cc6b4SJerry Jelinek
124*385cc6b4SJerry Jelinek
125*385cc6b4SJerry Jelinek /*******************************************************************************
126*385cc6b4SJerry Jelinek *
127*385cc6b4SJerry Jelinek * FUNCTION: AcpiUtCheckAndRepairAscii
128*385cc6b4SJerry Jelinek *
129*385cc6b4SJerry Jelinek * PARAMETERS: Name - Ascii string
130*385cc6b4SJerry Jelinek * Count - Number of characters to check
131*385cc6b4SJerry Jelinek *
132*385cc6b4SJerry Jelinek * RETURN: None
133*385cc6b4SJerry Jelinek *
134*385cc6b4SJerry Jelinek * DESCRIPTION: Ensure that the requested number of characters are printable
135*385cc6b4SJerry Jelinek * Ascii characters. Sets non-printable and null chars to <space>.
136*385cc6b4SJerry Jelinek *
137*385cc6b4SJerry Jelinek ******************************************************************************/
138*385cc6b4SJerry Jelinek
139*385cc6b4SJerry Jelinek void
AcpiUtCheckAndRepairAscii(UINT8 * Name,char * RepairedName,UINT32 Count)140*385cc6b4SJerry Jelinek AcpiUtCheckAndRepairAscii (
141*385cc6b4SJerry Jelinek UINT8 *Name,
142*385cc6b4SJerry Jelinek char *RepairedName,
143*385cc6b4SJerry Jelinek UINT32 Count)
144*385cc6b4SJerry Jelinek {
145*385cc6b4SJerry Jelinek UINT32 i;
146*385cc6b4SJerry Jelinek
147*385cc6b4SJerry Jelinek
148*385cc6b4SJerry Jelinek for (i = 0; i < Count; i++)
149*385cc6b4SJerry Jelinek {
150*385cc6b4SJerry Jelinek RepairedName[i] = (char) Name[i];
151*385cc6b4SJerry Jelinek
152*385cc6b4SJerry Jelinek if (!Name[i])
153*385cc6b4SJerry Jelinek {
154*385cc6b4SJerry Jelinek return;
155*385cc6b4SJerry Jelinek }
156*385cc6b4SJerry Jelinek if (!isprint (Name[i]))
157*385cc6b4SJerry Jelinek {
158*385cc6b4SJerry Jelinek RepairedName[i] = ' ';
159*385cc6b4SJerry Jelinek }
160*385cc6b4SJerry Jelinek }
161*385cc6b4SJerry Jelinek }
162