xref: /illumos-gate/usr/src/common/smbios/smb_error.c (revision 064d431a)
184ab085aSmws /*
284ab085aSmws  * CDDL HEADER START
384ab085aSmws  *
484ab085aSmws  * The contents of this file are subject to the terms of the
584ab085aSmws  * Common Development and Distribution License, Version 1.0 only
684ab085aSmws  * (the "License").  You may not use this file except in compliance
784ab085aSmws  * with the License.
884ab085aSmws  *
984ab085aSmws  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1084ab085aSmws  * or http://www.opensolaris.org/os/licensing.
1184ab085aSmws  * See the License for the specific language governing permissions
1284ab085aSmws  * and limitations under the License.
1384ab085aSmws  *
1484ab085aSmws  * When distributing Covered Code, include this CDDL HEADER in each
1584ab085aSmws  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1684ab085aSmws  * If applicable, add the following below this CDDL HEADER, with the
1784ab085aSmws  * fields enclosed by brackets "[]" replaced with your own identifying
1884ab085aSmws  * information: Portions Copyright [yyyy] [name of copyright owner]
1984ab085aSmws  *
2084ab085aSmws  * CDDL HEADER END
2184ab085aSmws  */
2284ab085aSmws 
2384ab085aSmws /*
2484ab085aSmws  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
2584ab085aSmws  * Use is subject to license terms.
26*064d431aSRobert Mustacchi  *
27*064d431aSRobert Mustacchi  * Copyright 2024 Oxide Computer Company
2884ab085aSmws  */
2984ab085aSmws 
3084ab085aSmws #include <sys/smbios_impl.h>
3184ab085aSmws 
3284ab085aSmws static const char *const _smb_errlist[] = {
3384ab085aSmws 	"System does not export an SMBIOS table",	/* ESMB_NOTFOUND */
3484ab085aSmws 	"Failed to map SMBIOS table",			/* ESMB_MAPDEV */
3584ab085aSmws 	"Failed to locate specified structure",		/* ESMB_NOENT */
3684ab085aSmws 	"Failed to allocate memory",			/* ESMB_NOMEM */
3784ab085aSmws 	"Failed to read SMBIOS entry point",		/* ESMB_NOHDR */
3884ab085aSmws 	"Failed to read SMBIOS structure table",	/* ESMB_NOSTAB */
3984ab085aSmws 	"Generic info not available for structure",	/* ESMB_NOINFO */
4084ab085aSmws 	"Structure table is shorter than expected",	/* ESMB_SHORT */
4184ab085aSmws 	"SMBIOS data structure is corrupted",		/* ESMB_CORRUPT */
4284ab085aSmws 	"Requested library version is not supported",	/* ESMB_VERSION */
4384ab085aSmws 	"Structure type is not supported by this BIOS",	/* ESMB_NOTSUP */
4484ab085aSmws 	"Header is not a valid SMBIOS entry point",	/* ESMB_HEADER */
4584ab085aSmws 	"SMBIOS format is too old for processing",	/* ESMB_OLD */
4684ab085aSmws 	"SMBIOS format is new and not yet supported",	/* ESMB_NEW */
4784ab085aSmws 	"SMBIOS header checksum mismatch",		/* ESMB_CKSUM */
4884ab085aSmws 	"Invalid argument specified in library call",	/* ESMB_INVAL */
4984ab085aSmws 	"Structure is not of the expected type",	/* ESMB_TYPE */
50*064d431aSRobert Mustacchi 	"Unknown SMBIOS error",				/* ESMB_UNKNOWN */
51*064d431aSRobert Mustacchi 	"Invalid requested value"			/* ESMB_REQVAL */
5284ab085aSmws };
5384ab085aSmws 
54*064d431aSRobert Mustacchi static const size_t _smb_nerr = ARRAY_SIZE(_smb_errlist);
5584ab085aSmws 
5684ab085aSmws const char *
smbios_errmsg(int error)5784ab085aSmws smbios_errmsg(int error)
5884ab085aSmws {
5984ab085aSmws 	const char *str;
6084ab085aSmws 
6184ab085aSmws 	if (error >= ESMB_BASE && (error - ESMB_BASE) < _smb_nerr)
6284ab085aSmws 		str = _smb_errlist[error - ESMB_BASE];
6384ab085aSmws 	else
6484ab085aSmws 		str = smb_strerror(error);
6584ab085aSmws 
66*064d431aSRobert Mustacchi 	return (str != NULL ? str : "Unknown error");
6784ab085aSmws }
6884ab085aSmws 
6984ab085aSmws int
smbios_errno(smbios_hdl_t * shp)7084ab085aSmws smbios_errno(smbios_hdl_t *shp)
7184ab085aSmws {
7284ab085aSmws 	return (shp->sh_err);
7384ab085aSmws }
7484ab085aSmws 
7584ab085aSmws int
smb_set_errno(smbios_hdl_t * shp,int error)7684ab085aSmws smb_set_errno(smbios_hdl_t *shp, int error)
7784ab085aSmws {
7884ab085aSmws 	shp->sh_err = error;
7984ab085aSmws 	return (SMB_ERR);
8084ab085aSmws }
81