1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 *
27 * Copyright 2024 Oxide Computer Company
28 */
29
30 #include <sys/smbios_impl.h>
31
32 static const char *const _smb_errlist[] = {
33 "System does not export an SMBIOS table", /* ESMB_NOTFOUND */
34 "Failed to map SMBIOS table", /* ESMB_MAPDEV */
35 "Failed to locate specified structure", /* ESMB_NOENT */
36 "Failed to allocate memory", /* ESMB_NOMEM */
37 "Failed to read SMBIOS entry point", /* ESMB_NOHDR */
38 "Failed to read SMBIOS structure table", /* ESMB_NOSTAB */
39 "Generic info not available for structure", /* ESMB_NOINFO */
40 "Structure table is shorter than expected", /* ESMB_SHORT */
41 "SMBIOS data structure is corrupted", /* ESMB_CORRUPT */
42 "Requested library version is not supported", /* ESMB_VERSION */
43 "Structure type is not supported by this BIOS", /* ESMB_NOTSUP */
44 "Header is not a valid SMBIOS entry point", /* ESMB_HEADER */
45 "SMBIOS format is too old for processing", /* ESMB_OLD */
46 "SMBIOS format is new and not yet supported", /* ESMB_NEW */
47 "SMBIOS header checksum mismatch", /* ESMB_CKSUM */
48 "Invalid argument specified in library call", /* ESMB_INVAL */
49 "Structure is not of the expected type", /* ESMB_TYPE */
50 "Unknown SMBIOS error", /* ESMB_UNKNOWN */
51 "Invalid requested value" /* ESMB_REQVAL */
52 };
53
54 static const size_t _smb_nerr = ARRAY_SIZE(_smb_errlist);
55
56 const char *
smbios_errmsg(int error)57 smbios_errmsg(int error)
58 {
59 const char *str;
60
61 if (error >= ESMB_BASE && (error - ESMB_BASE) < _smb_nerr)
62 str = _smb_errlist[error - ESMB_BASE];
63 else
64 str = smb_strerror(error);
65
66 return (str != NULL ? str : "Unknown error");
67 }
68
69 int
smbios_errno(smbios_hdl_t * shp)70 smbios_errno(smbios_hdl_t *shp)
71 {
72 return (shp->sh_err);
73 }
74
75 int
smb_set_errno(smbios_hdl_t * shp,int error)76 smb_set_errno(smbios_hdl_t *shp, int error)
77 {
78 shp->sh_err = error;
79 return (SMB_ERR);
80 }
81