/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <alloca.h>
#include <assert.h>
#include <errno.h>
#include <libintl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <wchar.h>
#include <wctype.h>
#include "fru_tag.h"
#include "libfrup.h"
#include "libfrureg.h"
#define HEAD_ITER 0
typedef struct
{
char *data;
{ 0x00, "OK"},
{ 0x04, "DEEMED FAULTY"},
{ 0x08, "FRU DETECTED"},
{ 0x0c, "FRU DETECTED, DEEMED FAULTY"},
{ 0x10, "PROXIED FAULT"},
{ 0x14, "DEEMED FAULTY. Also PROXIED FAULT"},
{ 0x18, "FRU DETECTED. Also PROXIED FAULT"},
{ 0x1c, "FRU DETECTED, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0x20, "SUSPECT"},
{ 0x24, "SUSPECT, DEEMED FAULTY"},
{ 0x28, "SUSPECT, FRU DETECTED"},
{ 0x2c, "SUSPECT, FRU DETECTED, DEEMED FAULTY"},
{ 0x30, "SUSPECT. Also PROXIED FAULT"},
{ 0x34, "SUSPECT, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0x38, "SUSPECT, FRU DETECTED. Also PROXIED FAULT"},
{ 0x3c, "SUSPECT, FRU DETECTED, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0x40, "MAINTENANCE REQUIRED"},
{ 0x44, "MAINTENANCE REQUIRED, DEEMED FAULTY"},
{ 0x48, "MAINTENANCE REQUIRED, FRU DETECTED"},
{ 0x4c, "MAINTENANCE REQUIRED, FRU DETECTED, DEEMED FAULTY"},
{ 0x50, "MAINTENANCE REQUIRED. Also PROXIED FAULT"},
{ 0x54, "MAINTENANCE REQUIRED, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0x58, "MAINTENANCE REQUIRED, FRU DETECTED. Also PROXIED FAULT"},
{ 0x5c, "MAINTENANCE REQUIRED, FRU DETECTED, DEEMED FAULTY. \
Also PROXIED FAULT"},
{ 0x60, "MAINTENANCE REQUIRED, SUSPECT"},
{ 0x64, "MAINTENANCE REQUIRED, SUSPECT, DEEMED FAULTY"},
{ 0x68, "MAINTENANCE REQUIRED, SUSPECT, FRU DETECTED"},
{ 0x6c, "MAINTENANCE REQUIRED, SUSPECT, FRU DETECTED, DEEMED FAULTY"},
{ 0x70, "MAINTENANCE REQUIRED, SUSPECT. Also PROXIED FAULT"},
{ 0x74, "MAINTENANCE REQUIRED, SUSPECT, DEEMED FAULTY.\
Also PROXIED FAULT"},
{ 0x78, "MAINTENANCE REQUIRED, SUSPECT, FRU DETECTED. \
Also PROXIED FAULT"},
{ 0x7c, "MAINTENANCE REQUIRED, SUSPECT, FRU DETECTED, \
DEEMED FAULTY. Also PROXIED FAULT"},
{ 0x80, "DISABLED"},
{ 0x84, "DISABLED, DEEMED FAULTY"},
{ 0x88, "DISABLED, FRU DETECTED"},
{ 0x8c, "DISABLED, FRU DETECTED, DEEMED FAULTY"},
{ 0x90, "DISABLED. Also PROXIED FAULT"},
{ 0x94, "DISABLED, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0x98, "DISABLED, FRU DETECTED. Also PROXIED FAULT"},
{ 0x9c, "DISABLED, FRU DETECTED, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0xa0, "DISABLED, SUSPECT"},
{ 0xa4, "DISABLED, SUSPECT, DEEMED FAULTY"},
{ 0xa8, "DISABLED, SUSPECT, FRU DETECTED"},
{ 0xac, "DISABLED, SUSPECT, FRU DETECTED, DEEMED FAULTY"},
{ 0xb0, "DISABLED, SUSPECT. Also PROXIED FAULT"},
{ 0xb4, "DISABLED, SUSPECT, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0xb8, "DISABLED, SUSPECT, FRU DETECTED. Also PROXIED FAULT"},
{ 0xbc, "DISABLED, SUSPECT, FRU DETECTED, \
DEEMED FAULTY. Also PROXIED FAULT"},
{ 0xc0, "DISABLED, MAINTENANCE REQUIRED"},
{ 0xc4, "DISABLED, MAINTENANCE REQUIRED, DEEMED FAULTY"},
{ 0xc8, "DISABLED, MAINTENANCE REQUIRED, FRU DETECTED"},
{ 0xcc, "DISABLED, MAINTENANCE REQUIRED, FRU DETECTED, DEEMED FAULTY"},
{ 0xd0, "DISABLED, MAINTENANCE REQUIRED. Also PROXIED FAULT"},
{ 0xd4, "DISABLED, MAINTENANCE REQUIRED, \
DEEMED FAULTY. Also PROXIED FAULT"},
{ 0xd8, "DISABLED, MAINTENANCE REQUIRED, \
FRU DETECTED. Also PROXIED FAULT"},
{ 0xdc, "DISABLED, MAINTENANCE REQUIRED, FRU DETECTED, \
DEEMED FAULTY. Also PROXIED FAULT"},
{ 0xe0, "DISABLED, MAINTENANCE REQUIRED, SUSPECT"},
{ 0xe4, "DISABLED, MAINTENANCE REQUIRED, SUSPECT, DEEMED FAULTY"},
{ 0xe8, "DISABLED, MAINTENANCE REQUIRED, SUSPECT, FRU DETECTED"},
{ 0xec, "DISABLED, MAINTENANCE REQUIRED, SUSPECT, \
FRU DETECTED, DEEMED FAULTY"},
{ 0xf0, "DISABLED, MAINTENANCE REQUIRED, SUSPECT. Also PROXIED FAULT"},
{ 0xf4, "DISABLED, MAINTENANCE REQUIRED, SUSPECT, \
DEEMED FAULTY. Also PROXIED FAULT"},
{ 0xf8, "DISABLED, MAINTENANCE REQUIRED, SUSPECT, \
FRU DETECTED. Also PROXIED FAULT"},
{ 0xfc, "DISABLED, MAINTENANCE REQUIRED, SUSPECT, \
FRU DETECTED, DEEMED FAULTY. Also PROXIED FAULT"},
{ 0xff, "RETIRED"}
};
void **end_args);
const char *parent_path, int indent);
int iterglobal = 0;
int Fault_Install_DataR_flag = 0;
int Power_On_DataR_flag = 0;
int spd_memtype = 0;
int spd_revision = 0;
/*
* Definition for data elements found in devices but not found in
* the system's version of libfrureg
*/
-1,
-1,
-1,
-1,
0,
NULL,
0,
};
/*
* Write message to standard error and possibly the error log buffer
*/
static void
{
/* make relevant output appear before error message */
exit(1);
}
}
/*
* Write message to standard output
*/
static void
{
exit(1);
}
}
/*
* Safe wrapper for putchar()
*/
static void
voidputchar(int c)
{
exit(1);
}
}
/*
* Safe wrapper for puts()
*/
static void
voidputs(const char *s)
{
exit(1);
}
}
/*
* XML-safe wrapper for putchar(): quotes XML-special characters
*/
static void
xputchar(int c)
{
switch (c) {
case '<':
break;
case '>':
break;
case '&':
break;
case '"':
break;
default:
c = putchar(c);
break;
}
if (c == EOF) {
exit(1);
}
}
/*
* XML-safe analog of puts(): quotes XML-special characters
*/
static void
xputs(const char *s)
{
char c;
for (/* */; ((c = *s) != 0); s++)
xputchar(c);
}
/*
* Output the XML DTD derived from the registry provided by libfrureg
*/
int
output_dtd(void)
{
char **element;
unsigned int i, j, num_elements = 0;
(num_elements == 0)) {
return (1);
}
return (1);
}
/*
* Output the DTD preamble
*/
output("<!ELEMENT FRUID_XML_Tree (Parameter*, "
"(Fru | Location | Container)*,\n"
" Parameter*, ErrorLog?, Parameter*)>\n"
"<!ATTLIST FRUID_XML_Tree>\n"
"\n"
"<!ELEMENT Parameter EMPTY>\n"
"<!ATTLIST Parameter type CDATA #REQUIRED>\n"
"<!ATTLIST Parameter name CDATA #REQUIRED>\n"
"<!ATTLIST Parameter value CDATA #REQUIRED>\n"
"\n"
"<!ELEMENT Fru (Fru | Location | Container)*>\n"
"<!ATTLIST Fru name CDATA #REQUIRED>\n"
"\n"
"<!ELEMENT Location (Fru | Location | Container)*>\n"
"<!ATTLIST Location\n"
" name CDATA #IMPLIED\n"
" value CDATA #IMPLIED\n"
">\n"
"\n"
"<!ELEMENT Container (ContainerData?, "
"(Fru | Location | Container)*)>\n"
"<!ATTLIST Container name CDATA #REQUIRED>\n"
"<!ATTLIST Container imagefile CDATA #IMPLIED>\n"
"\n"
"<!ELEMENT ContainerData (Segment*)>\n"
"<!ATTLIST ContainerData>\n"
"\n"
"<!ATTLIST Segment name CDATA #REQUIRED>\n"
"\n"
"<!ELEMENT Index EMPTY>\n"
"<!ATTLIST Index value CDATA #REQUIRED>\n"
"\n"
"<!ELEMENT ErrorLog (#PCDATA)>\n"
"<!ATTLIST ErrorLog>\n"
"\n");
/*
* Output the definition for each element
*/
for (i = 0; i < num_elements; i++) {
/* Prevent incompatible duplicate defn. from FRUID Registry. */
"definition for \"%s\"\n"),
element[i]);
return (1);
}
else
output("<!ELEMENT %s (Index_%s*)>\n"
"<!ATTLIST Index_%s>\n"
"<!ELEMENT Index_%s (%s",
output(")>\n");
output("<!ELEMENT %s EMPTY>\n"
"<!ATTLIST %s value CDATA #REQUIRED>\n",
output("<!-- %s valid enumeration values\n");
output("\t\"");
output("\"\n");
}
output("-->\n");
}
}
else
output("\n");
}
/* Provide for returning the tag for an "unknown" element */
output("<!ATTLIST UNKNOWN tag CDATA \"UNKNOWN\">\n\n");
/*
* List all data elements as possible members of "Segment"
*/
output("<!ELEMENT Segment ((UNKNOWN");
for (i = 0; i < num_elements; i++) {
}
output(")*)>\n");
return (0);
}
/*
* Function to convert bcd to binary to correct the SPD_Manufacturer_Week
*
*/
{
while (newval > 0) {
newval >>= 4;
}
while (tmpval > 0) {
tmpval >>= 4;
}
}
/*
* Checking UTF-8 printable charecter
*/
{
int i, status = 0;
status = 1;
}
}
if (status) {
}
return (status);
}
/*
* Safely pretty-print the value of a field
*/
static void
{
int i, valueint;
const char *parent_path;
case FDTYPE_Binary:
case FDISP_Binary:
for (i = 0; i < def->payloadLen; i++)
output("%c%c%c%c%c%c%c%c",
return;
case FDISP_Octal:
case FDISP_Decimal:
value = 0;
valueint = 0;
if ((value != 0) &&
if (spd_memtype && spd_revision) {
spd_memtype = 0;
spd_revision = 0;
}
return;
}
if ((value != 0) &&
"%llo" : "%lld (%lld degrees C)",
else
return;
case FDISP_Time:
errmsg = "time value too large for formatting";
break;
}
timefield = 0;
if (timefield == 0) {
errmsg = "No Value Recorded";
break;
}
errmsg = "cannot convert time value";
break;
}
== 0) {
errmsg = "formatted time would overflow buffer";
break;
}
return;
}
break;
case FDTYPE_ASCII:
if (!xml) {
if (FMAmessageR == 0)
elem_name = "FMA_Event_DataR";
else if (FMAmessageR == 1)
elem_name = "FMA_MessageR";
def->payloadLen);
new_def =
(elem_name);
"/Status_EventsR[%d]/Message(FMA)",
parent_path = path;
output("\n");
return;
}
}
}
return;
}
safeputchar(field[i]);
return;
case FDTYPE_Enumeration:
value = 0;
- def->payloadLen),
"FMA Message R") == 0)
FMAmessageR = 1;
else
"FMA Event Data R") == 0)
FMAmessageR = 0;
}
"SPD_Fundamental_Memory_Type") == 0) {
"DDR II SDRAM") == 0)
spd_memtype = 1;
}
return;
}
errmsg = "unrecognized value";
break;
}
/* If nothing matched above, print the field in hex */
case FDISP_MSGID:
if (isprint(first_byte)) {
i++)
safeputchar(field[i]);
}
break;
case FDISP_UUID:
for (i = 0; i < def->payloadLen; i++) {
if ((i == 4) || (i == 6) ||
(i == 8) || (i == 10))
output("-");
}
break;
default:
int status_length = \
sizeof (Status_CurrentR_status) / \
sizeof (*(Status_CurrentR_status));
i = 0;
do {
if (Status_CurrentR_status[i].value == \
*(field))
break;
i++;
} while (i < status_length);
if (i < status_length)
else
break;
}
"SPD_Data_Revision_Code") == 0) {
value = 0;
valueint = 0;
spd_revision = 1;
}
for (i = 0; i < def->payloadLen; i++)
break;
}
/* Safely print any error message associated with the field */
if (errmsg) {
output(" (");
output(")");
}
}
}
/*
* Recursively print the contents of a data element
*/
static void
const char *parent_path, int indent)
{
char *path;
int bytes = 0, i;
}
/*
* Construct the path, or, for XML, the name, for the current
* data element
*/
if ((def->iterationCount == 0) &&
if (xml) {
}
else
path = "Index";
}
else
path = (char *)parent_path;
} else {
if (xml)
else {
}
}
if ((Fault_Install_DataR_flag) &&
int cnt;
if (timefield == 0) {
(void) sprintf(timestring,
"00000000 (No Value Recorded)\"");
} else {
(void) sprintf(timestring,
"cannot convert time value");
if (strftime(timestring,
(void) sprintf(timestring,
"formatted time would overflow buffer");
}
if (xml) {
/*CSTYLED*/
output(":");
}
/*CSTYLED*/
output("\"/>\n");
/*CSTYLED*/
/*CSTYLED*/
/*CSTYLED*/
/*CSTYLED*/
output("\"/>\n");
} else {
output(":");
}
output("\n");
output("\n");
}
return;
} else if ((Power_On_DataR_flag) && (
int cnt;
if (timefield == 0) {
(void) sprintf(timestring,
"00000000 (No Value Recorded)");
} else {
(void) sprintf(timestring,
"cannot convert time value");
if (strftime(timestring,
(void) sprintf(timestring,
"formatted time would overflow buffer");
}
if (xml) {
/*CSTYLED*/
/*CSTYLED*/
output("\"/>\n");
} else {
output("\n");
}
Power_On_DataR_flag = 0;
return;
}
/*
* Handle the various categories of data elements: iteration,
* record, and field
*/
if (def->iterationCount) {
/*
* Make a new element definition to describe the components
* of the iteration
*/
newdef.iterationCount = 0;
/*
* Validate the contents of the iteration control bytes
*/
valid = 0;
"(should be less than %d)\n"),
}
valid = 0;
"(should not be greater than %d)\n"),
}
valid = 0;
"(should equal %d)\n"),
}
if (valid) {
} else {
head = 0;
}
if (xml)
else
num);
/*
* Print each component of the iteration
*/
n < num;
iterglobal = n;
indent);
}
if (xml)
else
/*
* Print each component of the record
*/
}
} else if (xml) {
/*
* Base case: print the field formatted for XML
*/
? "%*s<UNKNOWN tag=\"%s\" value=\""
: "%*s<%s value=\"");
/*CSTYLED*/
const char *parent_path;
if (FMAmessageR == 0)
elem_name = "FMA_Event_DataR";
else if (FMAmessageR == 1)
elem_name = "FMA_MessageR";
"/Status_EventsR[%d]/Message(FMA)", iterglobal);
parent_path = path;
FMAmessageR = -1;
}
}
} else {
/*
* Base case: print the field
*/
output("\n");
}
}
/*
* Print the contents of a packet (i.e., a tagged data element)
*/
/* ARGSUSED */
static int
{
/*
* Build a definition for unrecognized tags (e.g., not in libfrureg)
*/
if ((tag_type == -1) ||
if (tag_type == -1)
else
}
/*
* Print the defined element
*/
return (FRU_SUCCESS);
}
/*
* Print a segment's name and the contents of each data element in the segment
*/
static int
{
char *name;
int status;
name = "";
}
if (xml)
else
return (FRU_SUCCESS);
}
/* Iterate over the packets in the segment, printing the contents */
!= FRU_SUCCESS) {
}
return (FRU_SUCCESS);
}
/* ARGSUSED */
static void
{
}
/*
* Close the XML element for a "location" node
*/
/* ARGSUSED */
static void
void *args)
{
}
/*
* Close the XML element for a "fru" node
*/
/* ARGSUSED */
static void
{
}
/*
* Close the XML element for a "container" node
*/
/* ARGSUSED */
static void
void *args)
{
}
/*
* Introduce a node in XML and set the appropriate node-closing function
*/
/* ARGSUSED */
static void
{
switch (fru_type) {
case FRU_NODE_FRU:
*end_node = end_fru_xml;
break;
case FRU_NODE_CONTAINER:
break;
default:
break;
}
}
/*
* Print node info and, where appropriate, node contents
*/
/* ARGSUSED */
static fru_errno_t
{
int status;
}
if (containers_only) {
if (fru_type != FRU_NODE_CONTAINER)
return (FRU_SUCCESS);
}
/* Introduce the node */
if (list_only)
return (FRU_SUCCESS);
/* Print the contents of each packet in each segment of a container */
if (fru_type == FRU_NODE_CONTAINER) {
if ((status =
NULL))
!= FRU_SUCCESS) {
}
}
return (FRU_SUCCESS);
}
/*
* Process the node if its path matches the search path in "args"
*/
/* ARGSUSED */
static fru_errno_t
{
int status;
return (FRU_SUCCESS);
}
/*
* Write the trailer required for well-formed DTD-compliant XML
*/
static void
{
errno = 0;
char c;
output("<ErrorLog>\n");
if (!errno)
xputchar(c);
output("</ErrorLog>\n");
}
if (errno) {
/*NOTREACHED*/
}
output("</FRUID_XML_Tree>\n");
}
/*
* Print available FRU ID information
*/
int
int xml_flag)
{
/* Copy parameter flags to global flags */
/* Help arrange for correct, efficient interleaving of output */
/* Initialize for XML--or not */
if (xml) {
"Error creating error log file: %s\n",
return (1);
}
/* Output the XML preamble */
output("<?xml version=\"1.0\" ?>\n"
"<!--\n"
" Copyright 2000-2002 Sun Microsystems, Inc. "
"All rights reserved.\n"
" Use is subject to license terms.\n"
"-->\n\n"
"<!DOCTYPE FRUID_XML_Tree SYSTEM \"prtfrureg.dtd\">\n\n"
"<FRUID_XML_Tree>\n");
/* Arrange to always properly terminate XML */
if (atexit(terminate_xml))
} else
/* Get the root node */
"infrastructure to provide FRUID data\n"
"Please use the platform SP to access the FRUID "
"information\n"));
return (1);
} else if (status != FRU_SUCCESS) {
return (1);
}
/* Process the tree */
if (searchpath == NULL) {
} else {
(void *)searchpath);
if (status == FRU_WALK_TERMINATE) {
} else if (status == FRU_SUCCESS) {
return (1);
}
}
if (status != FRU_SUCCESS)
}